Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: run linter on CI #79

Merged
merged 9 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@ jobs:

- uses: actions/setup-go@v3
with:
go-version: "1.19"
go-version: "1.20"

- name: Tidy go.mod
run: go mod tidy

- name: Check diff
run: git diff --exit-code

- name: Install golangci-lint
run: go install github.com/golangci/golangci-lint/cmd/[email protected]

- name: Lint
run: make lint

- name: Build
run: make build

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ format-tools:
go install github.com/daixiang0/[email protected]

lint: format-tools
golangci-lint run --tests=false
golangci-lint run --tests=false --timeout=180s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "./tests/system/vendor*" -not -path "*.git*" -not -path "*_test.go" | xargs gofumpt -d

format: format-tools
Expand Down
19 changes: 10 additions & 9 deletions app/ante_handler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package teritori

import (
"cosmossdk.io/errors"
"cosmossdk.io/math"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types"
Expand Down Expand Up @@ -62,7 +63,7 @@ func (min MinCommissionDecorator) AnteHandle(
// commission set below 5%
c := msg.Commission
if c.Rate.LT(minCommissionRate) {
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "commission can't be lower than 5%")
return errors.Wrap(sdkerrors.ErrUnauthorized, "commission can't be lower than 5%")
}
case *stakingtypes.MsgEditValidator:
// if commission rate is nil, it means only
Expand All @@ -71,7 +72,7 @@ func (min MinCommissionDecorator) AnteHandle(
break
}
if msg.CommissionRate.LT(minCommissionRate) {
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "commission can't be lower than 5%")
return errors.Wrap(sdkerrors.ErrUnauthorized, "commission can't be lower than 5%")
}
case *stakingtypes.MsgDelegate:
val, err := min.getValidator(ctx, msg.ValidatorAddress)
Expand All @@ -81,7 +82,7 @@ func (min MinCommissionDecorator) AnteHandle(

projectedVotingPower := min.CalculateDelegateProjectedVotingPower(ctx, val, sdk.NewDecFromInt(msg.Amount.Amount))
if projectedVotingPower.GTE(maxVotingPower) {
return sdkerrors.Wrapf(
return errors.Wrapf(
sdkerrors.ErrInvalidRequest,
"This validator has a voting power of %s%%. Delegations not allowed to a validator whose post-delegation voting power is more than %s%%. Please delegate to a validator with less bonded tokens", projectedVotingPower, maxVotingPower)
}
Expand All @@ -102,7 +103,7 @@ func (min MinCommissionDecorator) AnteHandle(

projectedVotingPower := min.CalculateRedelegateProjectedVotingPower(ctx, dstVal, delegateAmount)
if projectedVotingPower.GTE(maxVotingPower) {
return sdkerrors.Wrapf(
return errors.Wrapf(
sdkerrors.ErrInvalidRequest,
"This validator has a voting power of %s%%. Delegations not allowed to a validator whose post-delegation voting power is more than %s%%. Please redelegate to a validator with less bonded tokens", projectedVotingPower, maxVotingPower)
}
Expand All @@ -116,7 +117,7 @@ func (min MinCommissionDecorator) AnteHandle(
var innerMsg sdk.Msg
err := min.cdc.UnpackAny(v, &innerMsg)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "cannot unmarshal authz exec msgs")
return errors.Wrapf(sdkerrors.ErrUnauthorized, "cannot unmarshal authz exec msgs")
}

err = validMsg(innerMsg)
Expand Down Expand Up @@ -150,7 +151,7 @@ func (min MinCommissionDecorator) AnteHandle(
func (min MinCommissionDecorator) getValidator(ctx sdk.Context, bech32ValAddr string) (stakingtypes.Validator, error) {
valAddr, err := sdk.ValAddressFromBech32(bech32ValAddr)
if err != nil {
return stakingtypes.Validator{}, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, bech32ValAddr)
return stakingtypes.Validator{}, errors.Wrap(sdkerrors.ErrInvalidAddress, bech32ValAddr)
}

val, found := min.sk.GetValidator(ctx, valAddr)
Expand Down Expand Up @@ -198,15 +199,15 @@ func (min MinCommissionDecorator) CalculateRedelegateProjectedVotingPower(ctx sd
// signer.
func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if options.AccountKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder")
return nil, errors.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder")
}

if options.BankKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder")
return nil, errors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder")
}

if options.SignModeHandler == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
return nil, errors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}

var sigGasConsumer = options.SigGasConsumer
Expand Down
41 changes: 21 additions & 20 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ import (
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/cosmos/cosmos-sdk/x/group"
groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper"
Expand Down Expand Up @@ -159,23 +158,23 @@ var (

// GetEnabledProposals parses the ProposalsEnabled / EnableSpecificProposals values to
// produce a list of enabled proposals to pass into wasmd app.
func GetEnabledProposals() []wasm.ProposalType {
func GetEnabledProposals() []wasmtypes.ProposalType {
if EnableSpecificProposals == "" {
if ProposalsEnabled == "true" {
return wasm.EnableAllProposals
return wasmtypes.EnableAllProposals
}
return wasm.DisableAllProposals
return wasmtypes.DisableAllProposals
}
chunks := strings.Split(EnableSpecificProposals, ",")
proposals, err := wasm.ConvertToProposals(chunks)
proposals, err := wasmtypes.ConvertToProposals(chunks)
if err != nil {
panic(err)
}
return proposals
}

func GetWasmOpts(appOpts servertypes.AppOptions) []wasm.Option {
var wasmOpts []wasm.Option
func GetWasmOpts(appOpts servertypes.AppOptions) []wasmkeeper.Option {
var wasmOpts []wasmkeeper.Option
if cast.ToBool(appOpts.Get("telemetry.enabled")) {
wasmOpts = append(wasmOpts, wasmkeeper.WithVMCacheMetrics(prometheus.DefaultRegisterer))
}
Expand Down Expand Up @@ -323,7 +322,7 @@ func NewTeritoriApp(
ibcfeetypes.StoreKey,
icahosttypes.StoreKey,
airdroptypes.StoreKey,
wasm.StoreKey,
wasmtypes.StoreKey,
consensusparamtypes.StoreKey,
intertxtypes.StoreKey,
crisistypes.StoreKey,
Expand Down Expand Up @@ -363,7 +362,7 @@ func NewTeritoriApp(
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)

scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasm.ModuleName)
scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasmtypes.ModuleName)

// add keepers
app.AccountKeeper = authkeeper.NewAccountKeeper(
Expand Down Expand Up @@ -574,9 +573,9 @@ func NewTeritoriApp(
// if we want to allow any custom callbacks
availableCapabilities := "iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2"
wasmOpts := GetWasmOpts(appOpts)
app.WasmKeeper = wasm.NewKeeper(
app.WasmKeeper = wasmkeeper.NewKeeper(
appCodec,
keys[wasm.StoreKey],
keys[wasmtypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
Expand All @@ -598,8 +597,10 @@ func NewTeritoriApp(
// register wasm gov proposal types
enabledProposals := GetEnabledProposals()
if len(enabledProposals) != 0 {
govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.WasmKeeper, enabledProposals))
govRouter.AddRoute(wasmtypes.RouterKey, wasmkeeper.NewWasmProposalHandler(app.WasmKeeper, enabledProposals)) //nolint:staticcheck
}
// Set legacy router for backwards compatibility with gov v1beta1
app.GovKeeper.SetLegacyRouter(govRouter)

var wasmStack ibcporttypes.IBCModule
wasmStack = wasm.NewIBCHandler(app.WasmKeeper, app.IBCKeeper.ChannelKeeper, app.IBCFeeKeeper)
Expand All @@ -611,7 +612,7 @@ func NewTeritoriApp(
AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).
AddRoute(ibctransfertypes.ModuleName, transferIBCModule).
AddRoute(intertxtypes.ModuleName, icaControllerStack).
AddRoute(wasm.ModuleName, wasmStack)
AddRoute(wasmtypes.ModuleName, wasmStack)
app.IBCKeeper.SetRouter(ibcRouter)

app.GovKeeper = *govKeeper.SetHooks(
Expand Down Expand Up @@ -650,7 +651,7 @@ func NewTeritoriApp(
groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
transferModule,
icaModule,
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasm.ModuleName)),
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
packetforwardModule,
interTxModule,
Expand Down Expand Up @@ -684,7 +685,7 @@ func NewTeritoriApp(
icatypes.ModuleName,
packetforwardtypes.ModuleName,
airdroptypes.ModuleName,
wasm.ModuleName,
wasmtypes.ModuleName,
intertxtypes.ModuleName,
)
app.mm.SetOrderEndBlockers(
Expand All @@ -711,7 +712,7 @@ func NewTeritoriApp(
feegrant.ModuleName,
authz.ModuleName,
airdroptypes.ModuleName,
wasm.ModuleName,
wasmtypes.ModuleName,
intertxtypes.ModuleName,
)

Expand Down Expand Up @@ -744,7 +745,7 @@ func NewTeritoriApp(
authz.ModuleName,
packetforwardtypes.ModuleName,
airdroptypes.ModuleName,
wasm.ModuleName,
wasmtypes.ModuleName,
intertxtypes.ModuleName,
)

Expand Down Expand Up @@ -784,7 +785,7 @@ func NewTeritoriApp(
BankKeeper: app.BankKeeper,
AirdropKeeper: &app.AirdropKeeper,
IBCKeeper: app.IBCKeeper,
TxCounterStoreKey: keys[wasm.StoreKey],
TxCounterStoreKey: keys[wasmtypes.StoreKey],
WasmConfig: wasmConfig,
Cdc: appCodec,
},
Expand Down Expand Up @@ -1027,11 +1028,11 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(minttypes.ModuleName)
paramsKeeper.Subspace(distrtypes.ModuleName)
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable())
paramsKeeper.Subspace(govtypes.ModuleName)
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibcexported.ModuleName)
paramsKeeper.Subspace(wasm.ModuleName)
paramsKeeper.Subspace(wasmtypes.ModuleName)
paramsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable())
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
Expand Down
13 changes: 7 additions & 6 deletions app/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package teritori
import (
"fmt"

"cosmossdk.io/errors"
airdropkeeper "github.com/TERITORI/teritori-chain/x/airdrop/keeper"
airdroptypes "github.com/TERITORI/teritori-chain/x/airdrop/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -34,7 +35,7 @@ func NewDeductFeeDecorator(ak ante.AccountKeeper, bk types.BankKeeper, fk ante.F
func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
feeTx, ok := tx.(sdk.FeeTx)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
return ctx, errors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
}

if addr := dfd.ak.GetModuleAddress(types.FeeCollectorName); addr == nil {
Expand All @@ -51,12 +52,12 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo
// this works with only when feegrant enabled.
if feeGranter != nil {
if dfd.feegrantKeeper == nil {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "fee grants are not enabled")
return ctx, errors.Wrap(sdkerrors.ErrInvalidRequest, "fee grants are not enabled")
} else if !feeGranter.Equals(feePayer) {
err := dfd.feegrantKeeper.UseGrantedFees(ctx, feeGranter, feePayer, fee, tx.GetMsgs())

if err != nil {
return ctx, sdkerrors.Wrapf(err, "%s not allowed to pay fees from %s", feeGranter, feePayer)
return ctx, errors.Wrapf(err, "%s not allowed to pay fees from %s", feeGranter, feePayer)
}
}

Expand Down Expand Up @@ -85,7 +86,7 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo

deductFeesFromAcc := dfd.ak.GetAccount(ctx, deductFeesFrom)
if deductFeesFromAcc == nil {
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "fee payer address: %s does not exist", deductFeesFrom)
return ctx, errors.Wrapf(sdkerrors.ErrUnknownAddress, "fee payer address: %s does not exist", deductFeesFrom)
}

// deduct the fees
Expand All @@ -107,12 +108,12 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo
// DeductFees deducts fees from the given account.
func DeductFees(bankKeeper types.BankKeeper, ctx sdk.Context, acc types.AccountI, fees sdk.Coins) error {
if !fees.IsValid() {
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "invalid fee amount: %s", fees)
return errors.Wrapf(sdkerrors.ErrInsufficientFee, "invalid fee amount: %s", fees)
}

err := bankKeeper.SendCoinsFromAccountToModule(ctx, acc.GetAddress(), types.FeeCollectorName, fees)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
return errors.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
}

return nil
Expand Down
5 changes: 2 additions & 3 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keepers

import (
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
airdropkeeper "github.com/TERITORI/teritori-chain/x/airdrop/keeper"
intertxkeeper "github.com/TERITORI/teritori-chain/x/intertx/keeper"
mintkeeper "github.com/TERITORI/teritori-chain/x/mint/keeper"
Expand All @@ -26,8 +27,6 @@ import (
ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"

"github.com/CosmWasm/wasmd/x/wasm"

// unnamed import of statik for swagger UI support
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
)
Expand Down Expand Up @@ -67,6 +66,6 @@ type AppKeepers struct {
ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper
ScopedInterTxKeeper capabilitykeeper.ScopedKeeper

WasmKeeper wasm.Keeper
WasmKeeper wasmkeeper.Keeper
ScopedWasmKeeper capabilitykeeper.ScopedKeeper
}
3 changes: 1 addition & 2 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

sdkmath "cosmossdk.io/math"
"github.com/CosmWasm/wasmd/x/wasm"
dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/crypto/secp256k1"
Expand All @@ -26,7 +25,7 @@ import (
)

// InitNewApp initiate a new TeritoriApp object
func InitNewApp(opts ...wasm.Option) *TeritoriApp {
func InitNewApp() *TeritoriApp {
db := dbm.NewMemDB()
appOptions := make(simtestutil.AppOptionsMap, 0)
appOptions[flags.FlagHome] = DefaultNodeHome
Expand Down
4 changes: 2 additions & 2 deletions app/upgrades/v200/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package v200
import (
"reflect"

"github.com/CosmWasm/wasmd/x/wasm"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/TERITORI/teritori-chain/app/keepers"
minttypes "github.com/TERITORI/teritori-chain/x/mint/types"
Expand All @@ -21,6 +20,7 @@ import (
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

//nolint:all
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
Expand Down Expand Up @@ -48,7 +48,7 @@ func CreateUpgradeHandler(
keyTable = govv1.ParamKeyTable()
case distrtypes.ModuleName:
keyTable = distrtypes.ParamKeyTable()
case wasm.ModuleName:
case wasmtypes.ModuleName:
keyTable = wasmtypes.ParamKeyTable()
case minttypes.ModuleName:
keyTable = minttypes.ParamKeyTable()
Expand Down
Loading