From 8627f85275761e69cfb2a535c0e9f48a065485a4 Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Mon, 31 Jul 2023 21:53:20 +0800 Subject: [PATCH] style: lint wasmd in the same manner as cosmos-sdk (#1537) * golangci-lint run ./... --fix * linting completed * use the CosmWasm repo as part of the gci config --- .golangci.yml | 115 ++++++++-- app/ante.go | 6 +- app/app.go | 58 ++--- app/app_test.go | 5 +- app/export.go | 4 +- app/sim_test.go | 8 +- app/test_helpers.go | 25 ++- app/test_support.go | 3 +- app/upgrades.go | 7 +- benchmarks/app_test.go | 47 ++-- benchmarks/bench_test.go | 7 +- cmd/wasmd/root.go | 15 +- cmd/wasmd/testnet.go | 9 +- tests/e2e/gov_test.go | 5 +- tests/e2e/grants_test.go | 6 +- tests/e2e/group_test.go | 8 +- tests/e2e/ibc_fees_test.go | 5 +- tests/e2e/ica_test.go | 10 +- tests/e2e/reflect_helper.go | 7 +- x/wasm/alias.go | 2 +- x/wasm/client/cli/gov_tx.go | 9 +- x/wasm/client/cli/new_tx.go | 4 +- x/wasm/client/cli/query.go | 5 +- x/wasm/client/cli/tx.go | 11 +- x/wasm/client/cli/tx_test.go | 3 +- x/wasm/client/cli/utils.go | 4 +- x/wasm/common_test.go | 8 +- x/wasm/genesis_test.go | 3 +- x/wasm/ibc.go | 8 +- x/wasm/ibc_integration_test.go | 11 +- x/wasm/ibc_reflect_test.go | 6 +- x/wasm/ibc_test.go | 5 +- x/wasm/ibctesting/chain.go | 33 +-- x/wasm/ibctesting/coordinator.go | 2 + x/wasm/ibctesting/endpoint.go | 5 +- x/wasm/ibctesting/event_utils.go | 4 +- x/wasm/ibctesting/faucet.go | 4 +- x/wasm/ibctesting/path.go | 3 +- x/wasm/ibctesting/wasm.go | 8 +- x/wasm/ioutils/ioutil_test.go | 1 - x/wasm/keeper/addresses.go | 2 +- x/wasm/keeper/addresses_test.go | 3 +- x/wasm/keeper/ante_test.go | 12 +- x/wasm/keeper/api.go | 1 + x/wasm/keeper/authz_policy_test.go | 3 +- x/wasm/keeper/bench_test.go | 3 +- x/wasm/keeper/contract_keeper.go | 12 +- x/wasm/keeper/contract_keeper_test.go | 9 +- x/wasm/keeper/events.go | 3 +- x/wasm/keeper/events_test.go | 3 +- x/wasm/keeper/gas_register.go | 6 +- x/wasm/keeper/gas_register_test.go | 7 +- x/wasm/keeper/genesis.go | 4 +- x/wasm/keeper/genesis_test.go | 19 +- x/wasm/keeper/handler_plugin.go | 7 +- x/wasm/keeper/handler_plugin_encoders.go | 13 +- x/wasm/keeper/handler_plugin_encoders_test.go | 13 +- x/wasm/keeper/handler_plugin_test.go | 15 +- x/wasm/keeper/ibc.go | 4 +- x/wasm/keeper/ibc_test.go | 4 +- x/wasm/keeper/keeper.go | 15 +- x/wasm/keeper/keeper_cgo.go | 4 +- x/wasm/keeper/keeper_test.go | 18 +- x/wasm/keeper/migrations.go | 3 +- x/wasm/keeper/migrations_integration_test.go | 10 +- x/wasm/keeper/msg_dispatcher.go | 4 +- x/wasm/keeper/msg_dispatcher_test.go | 3 +- x/wasm/keeper/msg_server.go | 1 + x/wasm/keeper/msg_server_integration_test.go | 6 +- x/wasm/keeper/msg_server_test.go | 3 +- x/wasm/keeper/options.go | 3 +- x/wasm/keeper/options_test.go | 17 +- x/wasm/keeper/proposal_integration_test.go | 7 +- x/wasm/keeper/querier.go | 18 +- x/wasm/keeper/querier_test.go | 12 +- x/wasm/keeper/query_plugins.go | 10 +- x/wasm/keeper/query_plugins_test.go | 27 +-- x/wasm/keeper/recurse_test.go | 9 +- x/wasm/keeper/reflect_test.go | 13 +- x/wasm/keeper/relay.go | 3 +- x/wasm/keeper/relay_test.go | 3 +- x/wasm/keeper/snapshotter.go | 4 +- x/wasm/keeper/snapshotter_integration_test.go | 10 +- x/wasm/keeper/staking_test.go | 14 +- x/wasm/keeper/submsg_test.go | 17 +- x/wasm/keeper/test_common.go | 203 +++++++++++------- x/wasm/keeper/test_fuzz.go | 3 +- x/wasm/keeper/wasmtesting/extension_mocks.go | 4 +- x/wasm/keeper/wasmtesting/gas_register.go | 1 + x/wasm/keeper/wasmtesting/messenger.go | 1 + x/wasm/keeper/wasmtesting/mock_engine.go | 6 +- x/wasm/keeper/wasmtesting/mock_keepers.go | 9 +- x/wasm/keeper/wasmtesting/msg_dispatcher.go | 1 + x/wasm/keeper/wasmtesting/query_handler.go | 1 + x/wasm/migrations/v1/store_test.go | 4 +- x/wasm/migrations/v3/store_test.go | 12 +- x/wasm/module.go | 14 +- x/wasm/module_test.go | 13 +- x/wasm/relay_pingpong_test.go | 11 +- x/wasm/relay_test.go | 14 +- x/wasm/simulation/operations.go | 5 +- x/wasm/types/authz.go | 8 +- x/wasm/types/authz_policy.go | 2 +- x/wasm/types/authz_test.go | 27 ++- x/wasm/types/errors.go | 3 +- x/wasm/types/errors_test.go | 12 +- x/wasm/types/events.go | 5 +- x/wasm/types/expected_keepers.go | 8 +- x/wasm/types/exported_keepers.go | 11 +- x/wasm/types/genesis.go | 1 + x/wasm/types/genesis_test.go | 5 +- x/wasm/types/iavl_range_test.go | 5 +- x/wasm/types/json_matching_test.go | 1 - x/wasm/types/keys.go | 2 +- x/wasm/types/params.go | 6 +- x/wasm/types/params_test.go | 5 +- x/wasm/types/proposal.go | 1 + x/wasm/types/proposal_test.go | 5 +- x/wasm/types/test_fixtures.go | 1 + x/wasm/types/tx.go | 1 + x/wasm/types/tx_test.go | 5 +- x/wasm/types/types.go | 6 +- x/wasm/types/types_test.go | 5 +- x/wasm/types/validation.go | 3 +- x/wasm/types/wasmer_engine.go | 1 + 125 files changed, 801 insertions(+), 496 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 227c0c4d..3ab634ed 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,17 +1,24 @@ run: tests: true - # timeout for analysis, e.g. 30s, 5m, default is 1m - timeout: 5m + timeout: 15m + sort-results: true + allow-parallel-runners: true + exclude-dir: testutil/testdata + skip-files: + - server/grpc/gogoreflection/fix_registration.go + - ".*\\.pb\\.go$" + - ".*\\.pb\\.gw\\.\\.go$" + - ".*\\.pulsar\\.go$" linters: disable-all: true enable: - - bodyclose - - dogsled - errcheck + - dogsled - exportloopref - goconst - gocritic + - gci - gofumpt - gosec - gosimple @@ -20,42 +27,122 @@ linters: - misspell - nakedret - nolintlint - - revive - staticcheck + - revive - stylecheck - typecheck + - thelper - unconvert - - unparam - unused issues: exclude-rules: - - text: "Use of weak random number generator" + - text: 'Use of weak random number generator' linters: - gosec - - text: "ST1003:" + - text: 'ST1003:' linters: - stylecheck # FIXME: Disabled until golangci-lint updates stylecheck with this fix: # https://github.com/dominikh/go-tools/issues/389 - - text: "ST1016:" + - text: 'ST1016:' linters: - stylecheck - - path: "migrations" - text: "SA1019:" + - path: 'migrations' + text: 'SA1019:' linters: - staticcheck - + - text: 'SA1019: codec.NewAminoCodec is deprecated' # TODO remove once migration path is set out + linters: + - staticcheck + - text: 'SA1019: legacybech32.MustMarshalPubKey' # TODO remove once ready to remove from the sdk + linters: + - staticcheck + - text: 'SA1019: legacybech32.MarshalPubKey' # TODO remove once ready to remove from the sdk + linters: + - staticcheck + - text: 'SA1019: legacybech32.UnmarshalPubKey' # TODO remove once ready to remove from the sdk + linters: + - staticcheck + - text: 'SA1019: params.SendEnabled is deprecated' # TODO remove once ready to remove from the sdk + linters: + - staticcheck + - text: 'leading space' + linters: + - nolintlint max-issues-per-linter: 10000 max-same-issues: 10000 linters-settings: + gci: + custom-order: true + sections: + - standard # Standard section: captures all standard packages. + - default # Default section: contains all imports that could not be matched to another section type. + - prefix(cosmossdk.io) + - prefix(github.com/cosmos/cosmos-sdk) + - prefix(github.com/CosmWasm/wasmd) revive: - # When set to false, ignores files with "GENERATED" header, similar to golint - ignore-generated-header: true + rules: + - name: redefines-builtin-id + disabled: true + gosec: + # To select a subset of rules to run. + # Available rules: https://github.com/securego/gosec#available-rules + # Default: [] - means include all rules + includes: + # - G101 # Look for hard coded credentials + - G102 # Bind to all interfaces + - G103 # Audit the use of unsafe block + - G104 # Audit errors not checked + - G106 # Audit the use of ssh.InsecureIgnoreHostKey + - G107 # Url provided to HTTP request as taint input + - G108 # Profiling endpoint automatically exposed on /debug/pprof + - G109 # Potential Integer overflow made by strconv.Atoi result conversion to int16/32 + - G110 # Potential DoS vulnerability via decompression bomb + - G111 # Potential directory traversal + - G112 # Potential slowloris attack + - G113 # Usage of Rat.SetString in math/big with an overflow (CVE-2022-23772) + - G114 # Use of net/http serve function that has no support for setting timeouts + - G201 # SQL query construction using format string + - G202 # SQL query construction using string concatenation + - G203 # Use of unescaped data in HTML templates + - G204 # Audit use of command execution + - G301 # Poor file permissions used when creating a directory + - G302 # Poor file permissions used with chmod + - G303 # Creating tempfile using a predictable path + - G304 # File path provided as taint input + - G305 # File traversal when extracting zip/tar archive + - G306 # Poor file permissions used when writing to a new file + - G307 # Deferring a method which returns an error + - G401 # Detect the usage of DES, RC4, MD5 or SHA1 + - G402 # Look for bad TLS connection settings + - G403 # Ensure minimum RSA key length of 2048 bits + - G404 # Insecure random number source (rand) + - G501 # Import blocklist: crypto/md5 + - G502 # Import blocklist: crypto/des + - G503 # Import blocklist: crypto/rc4 + - G504 # Import blocklist: net/http/cgi + - G505 # Import blocklist: crypto/sha1 + - G601 # Implicit memory aliasing of items from a range statement + misspell: + locale: US + gofumpt: + extra-rules: true + dogsled: + max-blank-identifiers: 6 + maligned: + suggest-new: true nolintlint: allow-unused: false allow-leading-space: true require-explanation: false require-specific: false + gosimple: + checks: ['all'] + gocritic: + disabled-checks: + - regexpMust + - appendAssign + - ifElseChain diff --git a/app/ante.go b/app/ante.go index e408372f..844d2bdc 100644 --- a/app/ante.go +++ b/app/ante.go @@ -1,13 +1,15 @@ package app import ( + ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante" + "github.com/cosmos/ibc-go/v7/modules/core/keeper" + errorsmod "cosmossdk.io/errors" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/ante" - ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante" - "github.com/cosmos/ibc-go/v7/modules/core/keeper" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types" diff --git a/app/app.go b/app/app.go index 4d46e1c9..8da2b76d 100644 --- a/app/app.go +++ b/app/app.go @@ -8,14 +8,38 @@ import ( "path/filepath" "strings" - autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" - dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/log" tmos "github.com/cometbft/cometbft/libs/os" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts" + icacontroller "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller" + icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper" + icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" + icahost "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host" + icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" + icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" + icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" + ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee" + ibcfeekeeper "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper" + ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" + transfer "github.com/cosmos/ibc-go/v7/modules/apps/transfer" + ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper" + ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + ibc "github.com/cosmos/ibc-go/v7/modules/core" + ibcclient "github.com/cosmos/ibc-go/v7/modules/core/02-client" + ibcclientclient "github.com/cosmos/ibc-go/v7/modules/core/02-client/client" + ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" + ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" + ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" + ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" + "github.com/spf13/cast" + + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -70,6 +94,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" "github.com/cosmos/cosmos-sdk/x/gov" + 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" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" @@ -97,31 +122,6 @@ import ( upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts" - icacontroller "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller" - icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper" - icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" - icahost "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host" - icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" - icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" - icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" - ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee" - ibcfeekeeper "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper" - ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" - transfer "github.com/cosmos/ibc-go/v7/modules/apps/transfer" - ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper" - ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" - ibc "github.com/cosmos/ibc-go/v7/modules/core" - ibcclient "github.com/cosmos/ibc-go/v7/modules/core/02-client" - ibcclientclient "github.com/cosmos/ibc-go/v7/modules/core/02-client/client" - ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" - ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" - ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" - ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" - "github.com/spf13/cast" - - govclient "github.com/cosmos/cosmos-sdk/x/gov/client" "github.com/CosmWasm/wasmd/x/wasm" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" @@ -607,7 +607,7 @@ func NewWasmApp( // The gov proposal types can be individually enabled if len(enabledProposals) != 0 { - govRouter.AddRoute(wasmtypes.RouterKey, wasmkeeper.NewWasmProposalHandler(app.WasmKeeper, enabledProposals)) //nolint:staticcheck + govRouter.AddRoute(wasmtypes.RouterKey, wasmkeeper.NewWasmProposalHandler(app.WasmKeeper, enabledProposals)) //nolint:staticcheck // we still need this despite the deprecation of the gov handler } // Set legacy router for backwards compatibility with gov v1beta1 app.GovKeeper.SetLegacyRouter(govRouter) diff --git a/app/app_test.go b/app/app_test.go index 3f724c59..d83f38fe 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -6,11 +6,12 @@ import ( dbm "github.com/cometbft/cometbft-db" "github.com/cometbft/cometbft/libs/log" - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" + sdk "github.com/cosmos/cosmos-sdk/types" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/app/export.go b/app/export.go index 74c69db6..f7232cc2 100644 --- a/app/export.go +++ b/app/export.go @@ -16,7 +16,7 @@ import ( // ExportAppStateAndValidators exports the state of the application for a genesis // file. -func (app *WasmApp) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddrs []string, modulesToExport []string) (servertypes.ExportedApp, error) { +func (app *WasmApp) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddrs, modulesToExport []string) (servertypes.ExportedApp, error) { // as if they could withdraw from the start of the next block ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) @@ -46,7 +46,7 @@ func (app *WasmApp) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedA // prepare for fresh start at zero height // NOTE zero height genesis is a temporary feature which will be deprecated // -// in favour of export at a block height +// in favor of export at a block height func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) { applyAllowedAddrs := false diff --git a/app/sim_test.go b/app/sim_test.go index f9c5136f..6a69743b 100644 --- a/app/sim_test.go +++ b/app/sim_test.go @@ -8,12 +8,12 @@ import ( "strings" "testing" - wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" @@ -35,7 +35,8 @@ import ( simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/stretchr/testify/require" + + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" ) // SimAppChainID hardcoded chainID for simulation @@ -255,6 +256,7 @@ func TestAppSimulationAfterImport(t *testing.T) { } func setupSimulationApp(t *testing.T, msg string) (simtypes.Config, dbm.DB, simtestutil.AppOptionsMap, *WasmApp) { + t.Helper() config := simcli.NewConfigFromFlags() config.ChainID = SimAppChainID diff --git a/app/test_helpers.go b/app/test_helpers.go index 9945cece..530a643c 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -9,14 +9,16 @@ import ( "testing" "time" - "cosmossdk.io/math" - dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" tmjson "github.com/cometbft/cometbft/libs/json" "github.com/cometbft/cometbft/libs/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" tmtypes "github.com/cometbft/cometbft/types" + "github.com/stretchr/testify/require" + + "cosmossdk.io/math" + bam "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -40,7 +42,6 @@ import ( minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/stretchr/testify/require" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" @@ -54,16 +55,17 @@ type SetupOptions struct { WasmOpts []wasmkeeper.Option } -func setup(t testing.TB, chainID string, withGenesis bool, invCheckPeriod uint, opts ...wasmkeeper.Option) (*WasmApp, GenesisState) { +func setup(tb testing.TB, chainID string, withGenesis bool, invCheckPeriod uint, opts ...wasmkeeper.Option) (*WasmApp, GenesisState) { + tb.Helper() db := dbm.NewMemDB() - nodeHome := t.TempDir() + nodeHome := tb.TempDir() snapshotDir := filepath.Join(nodeHome, "data", "snapshots") snapshotDB, err := dbm.NewDB("metadata", dbm.GoLevelDBBackend, snapshotDir) - require.NoError(t, err) - t.Cleanup(func() { snapshotDB.Close() }) + require.NoError(tb, err) + tb.Cleanup(func() { snapshotDB.Close() }) snapshotStore, err := snapshots.NewStore(snapshotDB, snapshotDir) - require.NoError(t, err) + require.NoError(tb, err) appOptions := make(simtestutil.AppOptionsMap, 0) appOptions[flags.FlagHome] = nodeHome // ensure unique folder @@ -196,8 +198,10 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs } // SetupWithEmptyStore set up a wasmd app instance with empty DB -func SetupWithEmptyStore(t testing.TB) *WasmApp { - app, _ := setup(t, "testing", false, 0) +func SetupWithEmptyStore(tb testing.TB) *WasmApp { + tb.Helper() + + app, _ := setup(tb, "testing", false, 0) return app } @@ -307,6 +311,7 @@ func SignAndDeliverWithoutCommit( t *testing.T, txCfg client.TxConfig, app *bam.BaseApp, msgs []sdk.Msg, fees sdk.Coins, chainID string, accNums, accSeqs []uint64, priv ...cryptotypes.PrivKey, ) (sdk.GasInfo, *sdk.Result, error) { + t.Helper() tx, err := simtestutil.GenSignedMockTx( rand.New(rand.NewSource(time.Now().UnixNano())), txCfg, diff --git a/app/test_support.go b/app/test_support.go index 8cf73c21..ac9cd286 100644 --- a/app/test_support.go +++ b/app/test_support.go @@ -1,12 +1,13 @@ package app import ( + ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" + "github.com/cosmos/cosmos-sdk/baseapp" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" ) diff --git a/app/upgrades.go b/app/upgrades.go index 01aa076a..775e28bf 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -1,6 +1,10 @@ package app import ( + icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" + icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" + ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + "github.com/cosmos/cosmos-sdk/baseapp" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -17,9 +21,6 @@ import ( slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" - icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" - ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/benchmarks/app_test.go b/benchmarks/app_test.go index 590e90de..21e0450e 100644 --- a/benchmarks/app_test.go +++ b/benchmarks/app_test.go @@ -7,9 +7,6 @@ import ( "testing" "time" - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" - dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/log" @@ -18,20 +15,20 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/client" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/testutil/mock" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/CosmWasm/wasmd/app" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" ) func setup(db dbm.DB, withGenesis bool, invCheckPeriod uint, opts ...wasmkeeper.Option) (*app.WasmApp, app.GenesisState) { //nolint:unparam @@ -45,14 +42,16 @@ func setup(db dbm.DB, withGenesis bool, invCheckPeriod uint, opts ...wasmkeeper. // SetupWithGenesisAccountsAndValSet initializes a new WasmApp with the provided genesis // accounts and possible balances. -func SetupWithGenesisAccountsAndValSet(b testing.TB, db dbm.DB, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *app.WasmApp { +func SetupWithGenesisAccountsAndValSet(tb testing.TB, db dbm.DB, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *app.WasmApp { + tb.Helper() + wasmApp, genesisState := setup(db, true, 0) authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs) appCodec := wasmApp.AppCodec() privVal := mock.NewPV() pubKey, err := privVal.GetPubKey() - require.NoError(b, err) + require.NoError(tb, err) genesisState[authtypes.ModuleName] = appCodec.MustMarshalJSON(authGenesis) @@ -136,7 +135,9 @@ type AppInfo struct { TxConfig client.TxConfig } -func InitializeWasmApp(b testing.TB, db dbm.DB, numAccounts int) AppInfo { +func InitializeWasmApp(tb testing.TB, db dbm.DB, numAccounts int) AppInfo { + tb.Helper() + // constants minter := secp256k1.GenPrivKey() addr := sdk.AccAddress(minter.PubKey().Address()) @@ -165,7 +166,7 @@ func InitializeWasmApp(b testing.TB, db dbm.DB, numAccounts int) AppInfo { Coins: sdk.NewCoins(sdk.NewInt64Coin(denom, 100000000000)), } } - wasmApp := SetupWithGenesisAccountsAndValSet(b, db, genAccs, bals...) + wasmApp := SetupWithGenesisAccountsAndValSet(tb, db, genAccs, bals...) // add wasm contract height := int64(2) @@ -174,16 +175,16 @@ func InitializeWasmApp(b testing.TB, db dbm.DB, numAccounts int) AppInfo { // upload the code cw20Code, err := os.ReadFile("./testdata/cw20_base.wasm") - require.NoError(b, err) + require.NoError(tb, err) storeMsg := wasmtypes.MsgStoreCode{ Sender: addr.String(), WASMByteCode: cw20Code, } r := rand.New(rand.NewSource(time.Now().UnixNano())) storeTx, err := simtestutil.GenSignedMockTx(r, txGen, []sdk.Msg{&storeMsg}, nil, 55123123, "", []uint64{0}, []uint64{0}, minter) - require.NoError(b, err) + require.NoError(tb, err) _, _, err = wasmApp.SimDeliver(txGen.TxEncoder(), storeTx) - require.NoError(b, err) + require.NoError(tb, err) codeID := uint64(1) // instantiate the contract @@ -205,7 +206,7 @@ func InitializeWasmApp(b testing.TB, db dbm.DB, numAccounts int) AppInfo { InitialBalances: initialBalances, } initBz, err := json.Marshal(init) - require.NoError(b, err) + require.NoError(tb, err) initMsg := wasmtypes.MsgInstantiateContract{ Sender: addr.String(), Admin: addr.String(), @@ -215,9 +216,9 @@ func InitializeWasmApp(b testing.TB, db dbm.DB, numAccounts int) AppInfo { } gasWanted := 500000 + 10000*uint64(numAccounts) initTx, err := simtestutil.GenSignedMockTx(r, txGen, []sdk.Msg{&initMsg}, nil, gasWanted, "", []uint64{0}, []uint64{1}, minter) - require.NoError(b, err) + require.NoError(tb, err) _, res, err := wasmApp.SimDeliver(txGen.TxEncoder(), initTx) - require.NoError(b, err) + require.NoError(tb, err) // TODO: parse contract address better evt := res.Events[len(res.Events)-1] @@ -239,14 +240,16 @@ func InitializeWasmApp(b testing.TB, db dbm.DB, numAccounts int) AppInfo { } } -func GenSequenceOfTxs(b testing.TB, info *AppInfo, msgGen func(*AppInfo) ([]sdk.Msg, error), numToGenerate int) []sdk.Tx { +func GenSequenceOfTxs(tb testing.TB, info *AppInfo, msgGen func(*AppInfo) ([]sdk.Msg, error), numToGenerate int) []sdk.Tx { + tb.Helper() + fees := sdk.Coins{sdk.NewInt64Coin(info.Denom, 0)} txs := make([]sdk.Tx, numToGenerate) r := rand.New(rand.NewSource(time.Now().UnixNano())) for i := 0; i < numToGenerate; i++ { msgs, err := msgGen(info) - require.NoError(b, err) + require.NoError(tb, err) txs[i], err = simtestutil.GenSignedMockTx( r, info.TxConfig, @@ -258,7 +261,7 @@ func GenSequenceOfTxs(b testing.TB, info *AppInfo, msgGen func(*AppInfo) ([]sdk. []uint64{info.SeqNum}, info.MinterKey, ) - require.NoError(b, err) + require.NoError(tb, err) info.SeqNum++ } diff --git a/benchmarks/bench_test.go b/benchmarks/bench_test.go index c917e91d..003fd11b 100644 --- a/benchmarks/bench_test.go +++ b/benchmarks/bench_test.go @@ -5,12 +5,11 @@ import ( "testing" "time" - "github.com/stretchr/testify/require" - "github.com/syndtr/goleveldb/leveldb/opt" - dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/stretchr/testify/require" + "github.com/syndtr/goleveldb/leveldb/opt" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" @@ -154,6 +153,7 @@ func cw20TransferMsg(info *AppInfo) ([]sdk.Msg, error) { func buildTxFromMsg(builder func(info *AppInfo) ([]sdk.Msg, error)) func(b *testing.B, info *AppInfo) []sdk.Tx { return func(b *testing.B, info *AppInfo) []sdk.Tx { + b.Helper() return GenSequenceOfTxs(b, info, builder, b.N) } } @@ -163,6 +163,7 @@ func buildMemDB(_ *testing.B) dbm.DB { } func buildLevelDB(b *testing.B) dbm.DB { + b.Helper() levelDB, err := dbm.NewGoLevelDBWithOpts("testing", b.TempDir(), &opt.Options{BlockCacher: opt.NoCacher}) require.NoError(b, err) return levelDB diff --git a/cmd/wasmd/root.go b/cmd/wasmd/root.go index d71f7413..2ab0d2bd 100644 --- a/cmd/wasmd/root.go +++ b/cmd/wasmd/root.go @@ -5,12 +5,16 @@ import ( "io" "os" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - - rosettaCmd "cosmossdk.io/tools/rosetta/cmd" dbm "github.com/cometbft/cometbft-db" tmcfg "github.com/cometbft/cometbft/config" "github.com/cometbft/cometbft/libs/log" + "github.com/prometheus/client_golang/prometheus" + "github.com/spf13/cast" + "github.com/spf13/cobra" + "github.com/spf13/viper" + + rosettaCmd "cosmossdk.io/tools/rosetta/cmd" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" "github.com/cosmos/cosmos-sdk/client/debug" @@ -25,12 +29,9 @@ import ( "github.com/cosmos/cosmos-sdk/version" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/crisis" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" - "github.com/prometheus/client_golang/prometheus" - "github.com/spf13/cast" - "github.com/spf13/cobra" - "github.com/spf13/viper" "github.com/CosmWasm/wasmd/app" "github.com/CosmWasm/wasmd/app/params" diff --git a/cmd/wasmd/testnet.go b/cmd/wasmd/testnet.go index f8ad31f4..c1d8dfd0 100644 --- a/cmd/wasmd/testnet.go +++ b/cmd/wasmd/testnet.go @@ -11,10 +11,6 @@ import ( "path/filepath" "time" - "github.com/cosmos/cosmos-sdk/version" - - "github.com/CosmWasm/wasmd/app" - tmconfig "github.com/cometbft/cometbft/config" tmrand "github.com/cometbft/cometbft/libs/rand" "github.com/cometbft/cometbft/types" @@ -36,11 +32,14 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/version" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + "github.com/CosmWasm/wasmd/app" ) var ( @@ -522,7 +521,7 @@ func calculateIP(ip string, i int) (string, error) { return ipv4.String(), nil } -func writeFile(name string, dir string, contents []byte) error { +func writeFile(name, dir string, contents []byte) error { file := filepath.Join(dir, name) if err := os.MkdirAll(dir, 0o755); err != nil { diff --git a/tests/e2e/gov_test.go b/tests/e2e/gov_test.go index 1db5eca9..33b7fd34 100644 --- a/tests/e2e/gov_test.go +++ b/tests/e2e/gov_test.go @@ -5,12 +5,13 @@ import ( "time" wasmvmtypes "github.com/CosmWasm/wasmvm/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/app" "github.com/CosmWasm/wasmd/tests/e2e" diff --git a/tests/e2e/grants_test.go b/tests/e2e/grants_test.go index 2a6ed793..45a4b32b 100644 --- a/tests/e2e/grants_test.go +++ b/tests/e2e/grants_test.go @@ -5,14 +5,16 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/authz" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/tests/e2e" "github.com/CosmWasm/wasmd/x/wasm/ibctesting" diff --git a/tests/e2e/group_test.go b/tests/e2e/group_test.go index 5fefc200..8708c126 100644 --- a/tests/e2e/group_test.go +++ b/tests/e2e/group_test.go @@ -4,18 +4,18 @@ import ( "testing" "time" - "github.com/CosmWasm/wasmd/x/wasm/types" - "github.com/cometbft/cometbft/libs/rand" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/group" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/tests/e2e" "github.com/CosmWasm/wasmd/x/wasm/ibctesting" + "github.com/CosmWasm/wasmd/x/wasm/types" ) func TestGroupWithContract(t *testing.T) { diff --git a/tests/e2e/ibc_fees_test.go b/tests/e2e/ibc_fees_test.go index 8c8ca4fa..66e320ad 100644 --- a/tests/e2e/ibc_fees_test.go +++ b/tests/e2e/ibc_fees_test.go @@ -7,8 +7,6 @@ import ( "testing" "time" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" @@ -17,6 +15,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + "github.com/CosmWasm/wasmd/app" wasmibctesting "github.com/CosmWasm/wasmd/x/wasm/ibctesting" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" diff --git a/tests/e2e/ica_test.go b/tests/e2e/ica_test.go index 4234b023..d72617b2 100644 --- a/tests/e2e/ica_test.go +++ b/tests/e2e/ica_test.go @@ -5,11 +5,6 @@ import ( "testing" "time" - "github.com/CosmWasm/wasmd/app" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/gogoproto/proto" icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" hosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" @@ -19,6 +14,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + + "github.com/CosmWasm/wasmd/app" wasmibctesting "github.com/CosmWasm/wasmd/x/wasm/ibctesting" ) diff --git a/tests/e2e/reflect_helper.go b/tests/e2e/reflect_helper.go index c2ebcadb..26cb2798 100644 --- a/tests/e2e/reflect_helper.go +++ b/tests/e2e/reflect_helper.go @@ -5,9 +5,10 @@ import ( "testing" wasmvmtypes "github.com/CosmWasm/wasmvm/types" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/x/wasm/ibctesting" "github.com/CosmWasm/wasmd/x/wasm/keeper/testdata" @@ -16,6 +17,7 @@ import ( // InstantiateReflectContract store and instantiate a reflect contract instance func InstantiateReflectContract(t *testing.T, chain *ibctesting.TestChain) sdk.AccAddress { + t.Helper() codeID := chain.StoreCodeFile("../../x/wasm/keeper/testdata/reflect_1_1.wasm").CodeID contractAddr := chain.InstantiateContract(codeID, []byte(`{}`)) require.NotEmpty(t, contractAddr) @@ -24,6 +26,7 @@ func InstantiateReflectContract(t *testing.T, chain *ibctesting.TestChain) sdk.A // MustExecViaReflectContract submit execute message to send payload to reflect contract func MustExecViaReflectContract(t *testing.T, chain *ibctesting.TestChain, contractAddr sdk.AccAddress, msgs ...wasmvmtypes.CosmosMsg) *sdk.Result { + t.Helper() rsp, err := ExecViaReflectContract(t, chain, contractAddr, msgs) require.NoError(t, err) return rsp @@ -35,6 +38,7 @@ type sdkMessageType interface { } func MustExecViaStargateReflectContract[T sdkMessageType](t *testing.T, chain *ibctesting.TestChain, contractAddr sdk.AccAddress, msgs ...T) *sdk.Result { + t.Helper() vmMsgs := make([]wasmvmtypes.CosmosMsg, len(msgs)) for i, m := range msgs { bz, err := chain.Codec.Marshal(m) @@ -53,6 +57,7 @@ func MustExecViaStargateReflectContract[T sdkMessageType](t *testing.T, chain *i // ExecViaReflectContract submit execute message to send payload to reflect contract func ExecViaReflectContract(t *testing.T, chain *ibctesting.TestChain, contractAddr sdk.AccAddress, msgs []wasmvmtypes.CosmosMsg) (*sdk.Result, error) { + t.Helper() require.NotEmpty(t, msgs) reflectSend := testdata.ReflectHandleMsg{ Reflect: &testdata.ReflectPayload{Msgs: msgs}, diff --git a/x/wasm/alias.go b/x/wasm/alias.go index 4d22eae1..c843c0e9 100644 --- a/x/wasm/alias.go +++ b/x/wasm/alias.go @@ -99,7 +99,7 @@ var ( // Deprecated: Do not use. TestHandler = keeper.TestHandler // Deprecated: Do not use. - NewWasmProposalHandler = keeper.NewWasmProposalHandler //nolint:staticcheck + NewWasmProposalHandler = keeper.NewWasmProposalHandler //nolint:staticcheck // we still require this alias despite the deprecation // Deprecated: Do not use. NewQuerier = keeper.Querier // Deprecated: Do not use. diff --git a/x/wasm/client/cli/gov_tx.go b/x/wasm/client/cli/gov_tx.go index 0a46ac6e..8344fbe6 100644 --- a/x/wasm/client/cli/gov_tx.go +++ b/x/wasm/client/cli/gov_tx.go @@ -8,6 +8,11 @@ import ( "strings" wasmvm "github.com/CosmWasm/wasmvm" + "github.com/docker/distribution/reference" + "github.com/pkg/errors" + "github.com/spf13/cobra" + flag "github.com/spf13/pflag" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" @@ -16,10 +21,6 @@ import ( "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/gov/client/cli" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - "github.com/docker/distribution/reference" - "github.com/pkg/errors" - "github.com/spf13/cobra" - flag "github.com/spf13/pflag" "github.com/CosmWasm/wasmd/x/wasm/ioutils" "github.com/CosmWasm/wasmd/x/wasm/types" diff --git a/x/wasm/client/cli/new_tx.go b/x/wasm/client/cli/new_tx.go index 16b9b1ba..2a76fb82 100644 --- a/x/wasm/client/cli/new_tx.go +++ b/x/wasm/client/cli/new_tx.go @@ -3,11 +3,13 @@ package cli import ( "strconv" + "github.com/spf13/cobra" + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/spf13/cobra" "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/client/cli/query.go b/x/wasm/client/cli/query.go index 30537372..01394915 100644 --- a/x/wasm/client/cli/query.go +++ b/x/wasm/client/cli/query.go @@ -11,11 +11,12 @@ import ( "strconv" wasmvm "github.com/CosmWasm/wasmvm" + "github.com/spf13/cobra" + flag "github.com/spf13/pflag" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/spf13/cobra" - flag "github.com/spf13/pflag" "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/types" diff --git a/x/wasm/client/cli/tx.go b/x/wasm/client/cli/tx.go index 4edd317b..5e66492a 100644 --- a/x/wasm/client/cli/tx.go +++ b/x/wasm/client/cli/tx.go @@ -8,6 +8,9 @@ import ( "strconv" "time" + "github.com/spf13/cobra" + flag "github.com/spf13/pflag" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" @@ -15,8 +18,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/authz" - "github.com/spf13/cobra" - flag "github.com/spf13/pflag" "github.com/CosmWasm/wasmd/x/wasm/ioutils" "github.com/CosmWasm/wasmd/x/wasm/types" @@ -43,7 +44,7 @@ const ( flagMaxCalls = "max-calls" flagMaxFunds = "max-funds" flagAllowAllMsgs = "allow-all-messages" - flagNoTokenTransfer = "no-token-transfer" //nolint:gosec + flagNoTokenTransfer = "no-token-transfer" flagAuthority = "authority" ) @@ -102,7 +103,7 @@ func StoreCodeCmd() *cobra.Command { } // Prepares MsgStoreCode object from flags with gzipped wasm byte code field -func parseStoreCodeArgs(file string, sender string, flags *flag.FlagSet) (types.MsgStoreCode, error) { +func parseStoreCodeArgs(file, sender string, flags *flag.FlagSet) (types.MsgStoreCode, error) { wasm, err := os.ReadFile(file) if err != nil { return types.MsgStoreCode{}, err @@ -393,7 +394,7 @@ func ExecuteContractCmd() *cobra.Command { return cmd } -func parseExecuteArgs(contractAddr string, execMsg string, sender sdk.AccAddress, flags *flag.FlagSet) (types.MsgExecuteContract, error) { +func parseExecuteArgs(contractAddr, execMsg string, sender sdk.AccAddress, flags *flag.FlagSet) (types.MsgExecuteContract, error) { amountStr, err := flags.GetString(flagAmount) if err != nil { return types.MsgExecuteContract{}, fmt.Errorf("amount: %s", err) diff --git a/x/wasm/client/cli/tx_test.go b/x/wasm/client/cli/tx_test.go index 04f80fc2..44f9f846 100644 --- a/x/wasm/client/cli/tx_test.go +++ b/x/wasm/client/cli/tx_test.go @@ -4,10 +4,11 @@ import ( "encoding/hex" "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/CosmWasm/wasmd/x/wasm/ioutils" "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/client/cli/utils.go b/x/wasm/client/cli/utils.go index 963b8f94..f6c0c6bf 100644 --- a/x/wasm/client/cli/utils.go +++ b/x/wasm/client/cli/utils.go @@ -4,10 +4,10 @@ import ( "os" "path/filepath" - "github.com/cosmos/cosmos-sdk/server" + tmcmd "github.com/cometbft/cometbft/cmd/cometbft/commands" "github.com/spf13/cobra" - tmcmd "github.com/cometbft/cometbft/cmd/cometbft/commands" + "github.com/cosmos/cosmos-sdk/server" ) // ExtendUnsafeResetAllCmd - also clear wasm dir diff --git a/x/wasm/common_test.go b/x/wasm/common_test.go index 9b26c41b..202770aa 100644 --- a/x/wasm/common_test.go +++ b/x/wasm/common_test.go @@ -3,9 +3,10 @@ package wasm import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -13,13 +14,15 @@ const firstCodeID = 1 // ensure store code returns the expected response func assertStoreCodeResponse(t *testing.T, data []byte, expected uint64) { + t.Helper() var pStoreResp types.MsgStoreCodeResponse require.NoError(t, pStoreResp.Unmarshal(data)) require.Equal(t, pStoreResp.CodeID, expected) } // ensure execution returns the expected data -func assertExecuteResponse(t *testing.T, data []byte, expected []byte) { +func assertExecuteResponse(t *testing.T, data, expected []byte) { + t.Helper() var pExecResp types.MsgExecuteContractResponse require.NoError(t, pExecResp.Unmarshal(data)) require.Equal(t, pExecResp.Data, expected) @@ -27,6 +30,7 @@ func assertExecuteResponse(t *testing.T, data []byte, expected []byte) { // ensures this returns a valid bech32 address and returns it func parseInitResponse(t *testing.T, data []byte) string { + t.Helper() var pInstResp types.MsgInstantiateContractResponse require.NoError(t, pInstResp.Unmarshal(data)) require.NotEmpty(t, pInstResp.Address) diff --git a/x/wasm/genesis_test.go b/x/wasm/genesis_test.go index 3910e550..dd47d1ca 100644 --- a/x/wasm/genesis_test.go +++ b/x/wasm/genesis_test.go @@ -4,9 +4,10 @@ import ( "encoding/json" "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/ibc.go b/x/wasm/ibc.go index 314cc79e..4cd6f8fd 100644 --- a/x/wasm/ibc.go +++ b/x/wasm/ibc.go @@ -3,15 +3,17 @@ package wasm import ( "math" - errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" - sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/ibc_integration_test.go b/x/wasm/ibc_integration_test.go index 97030f44..0f3eaa80 100644 --- a/x/wasm/ibc_integration_test.go +++ b/x/wasm/ibc_integration_test.go @@ -3,12 +3,6 @@ package wasm_test import ( "testing" - "github.com/CosmWasm/wasmd/app" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/CosmWasm/wasmd/x/wasm/types" - wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" @@ -17,9 +11,13 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/CosmWasm/wasmd/app" wasmibctesting "github.com/CosmWasm/wasmd/x/wasm/ibctesting" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" + "github.com/CosmWasm/wasmd/x/wasm/types" ) func TestOnChanOpenInitVersion(t *testing.T) { @@ -245,6 +243,7 @@ func NewCaptureAckTestContractEngine() *captureAckTestContractEngine { // SubmitIBCPacket starts an IBC packet transfer on given chain and captures the ack returned func (x *captureAckTestContractEngine) SubmitIBCPacket(t *testing.T, path *wasmibctesting.Path, chainA *wasmibctesting.TestChain, senderContractAddr sdk.AccAddress, packetData []byte) *[]byte { + t.Helper() // prepare a bridge to send an ibc packet by an ordinary wasm execute message x.MockWasmer.ExecuteFn = func(codeID wasmvm.Checksum, env wasmvmtypes.Env, info wasmvmtypes.MessageInfo, executeMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { return &wasmvmtypes.Response{ diff --git a/x/wasm/ibc_reflect_test.go b/x/wasm/ibc_reflect_test.go index efb47e7e..7151b271 100644 --- a/x/wasm/ibc_reflect_test.go +++ b/x/wasm/ibc_reflect_test.go @@ -3,12 +3,10 @@ package wasm_test import ( "testing" - "github.com/stretchr/testify/assert" - + wasmvmtypes "github.com/CosmWasm/wasmvm/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ibctesting "github.com/cosmos/ibc-go/v7/testing" - - wasmvmtypes "github.com/CosmWasm/wasmvm/types" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" wasmibctesting "github.com/CosmWasm/wasmd/x/wasm/ibctesting" diff --git a/x/wasm/ibc_test.go b/x/wasm/ibc_test.go index 97289675..f25622c8 100644 --- a/x/wasm/ibc_test.go +++ b/x/wasm/ibc_test.go @@ -6,14 +6,15 @@ import ( wasmvmtypes "github.com/CosmWasm/wasmvm/types" abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/rand" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/ibctesting/chain.go b/x/wasm/ibctesting/chain.go index 101798c2..504e82f2 100644 --- a/x/wasm/ibctesting/chain.go +++ b/x/wasm/ibctesting/chain.go @@ -5,15 +5,27 @@ import ( "testing" "time" - errorsmod "cosmossdk.io/errors" - "cosmossdk.io/math" - abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/crypto/tmhash" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" tmprotoversion "github.com/cometbft/cometbft/proto/tendermint/version" tmtypes "github.com/cometbft/cometbft/types" tmversion "github.com/cometbft/cometbft/version" + clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" + host "github.com/cosmos/ibc-go/v7/modules/core/24-host" + "github.com/cosmos/ibc-go/v7/modules/core/exported" + ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" + "github.com/cosmos/ibc-go/v7/modules/core/types" + ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" + ibctesting "github.com/cosmos/ibc-go/v7/testing" + "github.com/cosmos/ibc-go/v7/testing/mock" + "github.com/stretchr/testify/require" + + errorsmod "cosmossdk.io/errors" + "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" @@ -30,17 +42,6 @@ import ( stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/cosmos/cosmos-sdk/x/staking/testutil" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" - commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" - host "github.com/cosmos/ibc-go/v7/modules/core/24-host" - "github.com/cosmos/ibc-go/v7/modules/core/exported" - ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" - "github.com/cosmos/ibc-go/v7/modules/core/types" - ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" - ibctesting "github.com/cosmos/ibc-go/v7/testing" - "github.com/cosmos/ibc-go/v7/testing/mock" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/app" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" @@ -117,18 +118,21 @@ type ChainAppFactory func(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs [] // DefaultWasmAppFactory instantiates and sets up the default wasmd app func DefaultWasmAppFactory(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, chainID string, opts []wasmkeeper.Option, balances ...banktypes.Balance) ChainApp { + t.Helper() return app.SetupWithGenesisValSet(t, valSet, genAccs, chainID, opts, balances...) } // NewDefaultTestChain initializes a new test chain with a default of 4 validators // Use this function if the tests do not need custom control over the validator set func NewDefaultTestChain(t *testing.T, coord *Coordinator, chainID string, opts ...wasmkeeper.Option) *TestChain { + t.Helper() return NewTestChain(t, coord, DefaultWasmAppFactory, chainID, opts...) } // NewTestChain initializes a new test chain with a default of 4 validators // Use this function if the tests do not need custom control over the validator set func NewTestChain(t *testing.T, coord *Coordinator, appFactory ChainAppFactory, chainID string, opts ...wasmkeeper.Option) *TestChain { + t.Helper() // generate validators private/public key var ( validatorsPerChain = 4 @@ -168,6 +172,7 @@ func NewTestChain(t *testing.T, coord *Coordinator, appFactory ChainAppFactory, // CONTRACT: Validator array must be provided in the order expected by Tendermint. // i.e. sorted first by power and then lexicographically by address. func NewTestChainWithValSet(t *testing.T, coord *Coordinator, appFactory ChainAppFactory, chainID string, valSet *tmtypes.ValidatorSet, signers map[string]tmtypes.PrivValidator, opts ...wasmkeeper.Option) *TestChain { + t.Helper() genAccs := []authtypes.GenesisAccount{} genBals := []banktypes.Balance{} senderAccs := []SenderAccount{} diff --git a/x/wasm/ibctesting/coordinator.go b/x/wasm/ibctesting/coordinator.go index 4c7428a3..b5000d73 100644 --- a/x/wasm/ibctesting/coordinator.go +++ b/x/wasm/ibctesting/coordinator.go @@ -30,11 +30,13 @@ type Coordinator struct { // NewCoordinator initializes Coordinator with n default wasm TestChain instances func NewCoordinator(t *testing.T, n int, opts ...[]wasmkeeper.Option) *Coordinator { + t.Helper() return NewCoordinatorX(t, n, DefaultWasmAppFactory, opts...) } // NewCoordinatorX initializes Coordinator with N TestChain instances using the given app factory func NewCoordinatorX(t *testing.T, n int, appFactory ChainAppFactory, opts ...[]wasmkeeper.Option) *Coordinator { + t.Helper() chains := make(map[string]*TestChain) coord := &Coordinator{ t: t, diff --git a/x/wasm/ibctesting/endpoint.go b/x/wasm/ibctesting/endpoint.go index 726aca22..2e22ec80 100644 --- a/x/wasm/ibctesting/endpoint.go +++ b/x/wasm/ibctesting/endpoint.go @@ -4,8 +4,6 @@ import ( "fmt" "strings" - "github.com/cosmos/cosmos-sdk/baseapp" - sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -15,6 +13,9 @@ import ( ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" ibctesting "github.com/cosmos/ibc-go/v7/testing" "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/baseapp" + sdk "github.com/cosmos/cosmos-sdk/types" ) // Endpoint is a which represents a channel endpoint and its associated diff --git a/x/wasm/ibctesting/event_utils.go b/x/wasm/ibctesting/event_utils.go index 3ca72f8b..71df2784 100644 --- a/x/wasm/ibctesting/event_utils.go +++ b/x/wasm/ibctesting/event_utils.go @@ -6,11 +6,11 @@ import ( "strconv" "strings" - sdk "github.com/cosmos/cosmos-sdk/types" - abci "github.com/cometbft/cometbft/abci/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + + sdk "github.com/cosmos/cosmos-sdk/types" ) func GetSendPackets(evts []abci.Event) []channeltypes.Packet { diff --git a/x/wasm/ibctesting/faucet.go b/x/wasm/ibctesting/faucet.go index d36feceb..55914990 100644 --- a/x/wasm/ibctesting/faucet.go +++ b/x/wasm/ibctesting/faucet.go @@ -1,11 +1,13 @@ package ibctesting import ( + "github.com/stretchr/testify/require" + "cosmossdk.io/math" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/app" ) diff --git a/x/wasm/ibctesting/path.go b/x/wasm/ibctesting/path.go index 5c39e361..fe0ace44 100644 --- a/x/wasm/ibctesting/path.go +++ b/x/wasm/ibctesting/path.go @@ -4,9 +4,10 @@ import ( "bytes" "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ibctesting "github.com/cosmos/ibc-go/v7/testing" + + sdk "github.com/cosmos/cosmos-sdk/types" ) // Path contains two endpoints representing two chains connected over IBC diff --git a/x/wasm/ibctesting/wasm.go b/x/wasm/ibctesting/wasm.go index 24f61350..3939967e 100644 --- a/x/wasm/ibctesting/wasm.go +++ b/x/wasm/ibctesting/wasm.go @@ -8,14 +8,14 @@ import ( "os" "strings" - ibctesting "github.com/cosmos/ibc-go/v7/testing" - abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/rand" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/gogoproto/proto" + ibctesting "github.com/cosmos/ibc-go/v7/testing" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -117,7 +117,7 @@ func (chain *TestChain) RawQuery(contractAddr string, queryData []byte) ([]byte, // SmartQuery This will serialize the query message and submit it to the contract. // The response is parsed into the provided interface. // Usage: SmartQuery(addr, QueryMsg{Foo: 1}, &response) -func (chain *TestChain) SmartQuery(contractAddr string, queryMsg interface{}, response interface{}) error { +func (chain *TestChain) SmartQuery(contractAddr string, queryMsg, response interface{}) error { msg, err := json.Marshal(queryMsg) if err != nil { return err diff --git a/x/wasm/ioutils/ioutil_test.go b/x/wasm/ioutils/ioutil_test.go index 3cd1b5c2..0490aa07 100644 --- a/x/wasm/ioutils/ioutil_test.go +++ b/x/wasm/ioutils/ioutil_test.go @@ -9,7 +9,6 @@ import ( "testing" "github.com/cometbft/cometbft/libs/rand" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/x/wasm/keeper/addresses.go b/x/wasm/keeper/addresses.go index 67eabb44..92d0f2e3 100644 --- a/x/wasm/keeper/addresses.go +++ b/x/wasm/keeper/addresses.go @@ -22,7 +22,7 @@ func (k Keeper) ClassicAddressGenerator() AddressGenerator { } // PredicableAddressGenerator generates a predictable contract address -func PredicableAddressGenerator(creator sdk.AccAddress, salt []byte, msg []byte, fixMsg bool) AddressGenerator { +func PredicableAddressGenerator(creator sdk.AccAddress, salt, msg []byte, fixMsg bool) AddressGenerator { return func(ctx sdk.Context, _ uint64, checksum []byte) sdk.AccAddress { if !fixMsg { // clear msg to not be included in the address generation msg = []byte{} diff --git a/x/wasm/keeper/addresses_test.go b/x/wasm/keeper/addresses_test.go index 399c3e7b..84f3e54b 100644 --- a/x/wasm/keeper/addresses_test.go +++ b/x/wasm/keeper/addresses_test.go @@ -6,8 +6,9 @@ import ( "testing" tmbytes "github.com/cometbft/cometbft/libs/bytes" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" ) func TestBuildContractAddress(t *testing.T) { diff --git a/x/wasm/keeper/ante_test.go b/x/wasm/keeper/ante_test.go index 1ac74642..df586426 100644 --- a/x/wasm/keeper/ante_test.go +++ b/x/wasm/keeper/ante_test.go @@ -7,11 +7,12 @@ import ( dbm "github.com/cometbft/cometbft-db" "github.com/cometbft/cometbft/libs/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/store" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/types" @@ -32,7 +33,9 @@ func TestCountTxDecorator(t *testing.T) { expErr bool }{ "no initial counter set": { - setupDB: func(t *testing.T, ctx sdk.Context) {}, + setupDB: func(t *testing.T, ctx sdk.Context) { + t.Helper() + }, nextAssertAnte: func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) { gotCounter, ok := types.TXCounter(ctx) require.True(t, ok) @@ -45,6 +48,7 @@ func TestCountTxDecorator(t *testing.T) { }, "persistent counter incremented - big endian": { setupDB: func(t *testing.T, ctx sdk.Context) { + t.Helper() bz := []byte{0, 0, 0, 0, 0, 0, 0, myCurrentBlockHeight, 1, 0, 0, 2} ctx.MultiStore().GetKVStore(keyWasm).Set(types.TXCounterPrefix, bz) }, @@ -60,6 +64,7 @@ func TestCountTxDecorator(t *testing.T) { }, "old height counter replaced": { setupDB: func(t *testing.T, ctx sdk.Context) { + t.Helper() previousHeight := byte(myCurrentBlockHeight - 1) bz := []byte{0, 0, 0, 0, 0, 0, 0, previousHeight, 0, 0, 0, 1} ctx.MultiStore().GetKVStore(keyWasm).Set(types.TXCounterPrefix, bz) @@ -76,6 +81,7 @@ func TestCountTxDecorator(t *testing.T) { }, "simulation not persisted": { setupDB: func(t *testing.T, ctx sdk.Context) { + t.Helper() }, simulate: true, nextAssertAnte: func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) { diff --git a/x/wasm/keeper/api.go b/x/wasm/keeper/api.go index 88f3b828..c9fc65ae 100644 --- a/x/wasm/keeper/api.go +++ b/x/wasm/keeper/api.go @@ -3,6 +3,7 @@ package keeper import ( wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" + sdk "github.com/cosmos/cosmos-sdk/types" ) diff --git a/x/wasm/keeper/authz_policy_test.go b/x/wasm/keeper/authz_policy_test.go index 2230620d..4d918e51 100644 --- a/x/wasm/keeper/authz_policy_test.go +++ b/x/wasm/keeper/authz_policy_test.go @@ -3,9 +3,10 @@ package keeper import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/keeper/bench_test.go b/x/wasm/keeper/bench_test.go index ff0240af..500d97cc 100644 --- a/x/wasm/keeper/bench_test.go +++ b/x/wasm/keeper/bench_test.go @@ -5,9 +5,10 @@ import ( "testing" dbm "github.com/cometbft/cometbft-db" - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/keeper/contract_keeper.go b/x/wasm/keeper/contract_keeper.go index bebe8a7e..2cd48297 100644 --- a/x/wasm/keeper/contract_keeper.go +++ b/x/wasm/keeper/contract_keeper.go @@ -23,11 +23,11 @@ type decoratedKeeper interface { authZ types.AuthorizationPolicy, ) (sdk.AccAddress, []byte, error) - migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, newCodeID uint64, msg []byte, authZ types.AuthorizationPolicy) ([]byte, error) + migrate(ctx sdk.Context, contractAddress, caller sdk.AccAddress, newCodeID uint64, msg []byte, authZ types.AuthorizationPolicy) ([]byte, error) setContractAdmin(ctx sdk.Context, contractAddress, caller, newAdmin sdk.AccAddress, authZ types.AuthorizationPolicy) error pinCode(ctx sdk.Context, codeID uint64) error unpinCode(ctx sdk.Context, codeID uint64) error - execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) ([]byte, error) + execute(ctx sdk.Context, contractAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) ([]byte, error) Sudo(ctx sdk.Context, contractAddress sdk.AccAddress, msg []byte) ([]byte, error) setContractInfoExtension(ctx sdk.Context, contract sdk.AccAddress, extra types.ContractInfoExtension) error setAccessConfig(ctx sdk.Context, codeID uint64, caller sdk.AccAddress, newConfig types.AccessConfig, autz types.AuthorizationPolicy) error @@ -91,11 +91,11 @@ func (p PermissionedKeeper) Instantiate2( ) } -func (p PermissionedKeeper) Execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) ([]byte, error) { +func (p PermissionedKeeper) Execute(ctx sdk.Context, contractAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) ([]byte, error) { return p.nested.execute(ctx, contractAddress, caller, msg, coins) } -func (p PermissionedKeeper) Migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, newCodeID uint64, msg []byte) ([]byte, error) { +func (p PermissionedKeeper) Migrate(ctx sdk.Context, contractAddress, caller sdk.AccAddress, newCodeID uint64, msg []byte) ([]byte, error) { return p.nested.migrate(ctx, contractAddress, caller, newCodeID, msg, p.authZPolicy) } @@ -103,11 +103,11 @@ func (p PermissionedKeeper) Sudo(ctx sdk.Context, contractAddress sdk.AccAddress return p.nested.Sudo(ctx, contractAddress, msg) } -func (p PermissionedKeeper) UpdateContractAdmin(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, newAdmin sdk.AccAddress) error { +func (p PermissionedKeeper) UpdateContractAdmin(ctx sdk.Context, contractAddress, caller, newAdmin sdk.AccAddress) error { return p.nested.setContractAdmin(ctx, contractAddress, caller, newAdmin, p.authZPolicy) } -func (p PermissionedKeeper) ClearContractAdmin(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress) error { +func (p PermissionedKeeper) ClearContractAdmin(ctx sdk.Context, contractAddress, caller sdk.AccAddress) error { return p.nested.setContractAdmin(ctx, contractAddress, caller, nil, p.authZPolicy) } diff --git a/x/wasm/keeper/contract_keeper_test.go b/x/wasm/keeper/contract_keeper_test.go index 46ec4f65..37dd1dd8 100644 --- a/x/wasm/keeper/contract_keeper_test.go +++ b/x/wasm/keeper/contract_keeper_test.go @@ -7,12 +7,12 @@ import ( "strings" "testing" - "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" - - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -37,6 +37,7 @@ func TestInstantiate2(t *testing.T) { ) // create instances for duplicate checks exampleContract := func(t *testing.T, ctx sdk.Context, fixMsg bool) { + t.Helper() _, _, err := keepers.ContractKeeper.Instantiate2( ctx, example.CodeID, @@ -51,9 +52,11 @@ func TestInstantiate2(t *testing.T) { require.NoError(t, err) } exampleWithFixMsg := func(t *testing.T, ctx sdk.Context) { + t.Helper() exampleContract(t, ctx, true) } exampleWithoutFixMsg := func(t *testing.T, ctx sdk.Context) { + t.Helper() exampleContract(t, ctx, false) } specs := map[string]struct { diff --git a/x/wasm/keeper/events.go b/x/wasm/keeper/events.go index 06807f1c..ef738b10 100644 --- a/x/wasm/keeper/events.go +++ b/x/wasm/keeper/events.go @@ -4,9 +4,10 @@ import ( "fmt" "strings" + wasmvmtypes "github.com/CosmWasm/wasmvm/types" + errorsmod "cosmossdk.io/errors" - wasmvmtypes "github.com/CosmWasm/wasmvm/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/CosmWasm/wasmd/x/wasm/types" diff --git a/x/wasm/keeper/events_test.go b/x/wasm/keeper/events_test.go index b305df42..b091eb45 100644 --- a/x/wasm/keeper/events_test.go +++ b/x/wasm/keeper/events_test.go @@ -5,9 +5,10 @@ import ( "testing" wasmvmtypes "github.com/CosmWasm/wasmvm/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/keeper/gas_register.go b/x/wasm/keeper/gas_register.go index ad97b30c..b8879ed3 100644 --- a/x/wasm/keeper/gas_register.go +++ b/x/wasm/keeper/gas_register.go @@ -1,8 +1,10 @@ package keeper import ( - errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" + + errorsmod "cosmossdk.io/errors" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -230,7 +232,7 @@ func (g WasmGasRegister) eventAttributeCosts(attrs []wasmvmtypes.EventAttribute, } // apply free tier -func calcWithFreeTier(storedBytes uint64, freeTier uint64) (uint64, uint64) { +func calcWithFreeTier(storedBytes, freeTier uint64) (uint64, uint64) { if storedBytes <= freeTier { return 0, freeTier - storedBytes } diff --git a/x/wasm/keeper/gas_register_test.go b/x/wasm/keeper/gas_register_test.go index bf8dcd77..521ff17c 100644 --- a/x/wasm/keeper/gas_register_test.go +++ b/x/wasm/keeper/gas_register_test.go @@ -5,12 +5,13 @@ import ( "strings" "testing" - "github.com/CosmWasm/wasmd/x/wasm/types" - wasmvmtypes "github.com/CosmWasm/wasmvm/types" + "github.com/stretchr/testify/assert" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + + "github.com/CosmWasm/wasmd/x/wasm/types" ) func TestCompileCosts(t *testing.T) { diff --git a/x/wasm/keeper/genesis.go b/x/wasm/keeper/genesis.go index 60f5d993..59ab3b4c 100644 --- a/x/wasm/keeper/genesis.go +++ b/x/wasm/keeper/genesis.go @@ -1,8 +1,10 @@ package keeper import ( - errorsmod "cosmossdk.io/errors" abci "github.com/cometbft/cometbft/abci/types" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/CosmWasm/wasmd/x/wasm/types" diff --git a/x/wasm/keeper/genesis_test.go b/x/wasm/keeper/genesis_test.go index bf7e1b8b..034d975e 100644 --- a/x/wasm/keeper/genesis_test.go +++ b/x/wasm/keeper/genesis_test.go @@ -9,26 +9,25 @@ import ( "testing" "time" - abci "github.com/cometbft/cometbft/abci/types" - - "github.com/cosmos/cosmos-sdk/baseapp" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - wasmvm "github.com/CosmWasm/wasmvm" dbm "github.com/cometbft/cometbft-db" + abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + fuzz "github.com/google/gofuzz" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/store" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - fuzz "github.com/google/gofuzz" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/keeper/handler_plugin.go b/x/wasm/keeper/handler_plugin.go index 3e38e09f..e812411c 100644 --- a/x/wasm/keeper/handler_plugin.go +++ b/x/wasm/keeper/handler_plugin.go @@ -4,15 +4,16 @@ import ( "errors" "fmt" + wasmvmtypes "github.com/CosmWasm/wasmvm/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + host "github.com/cosmos/ibc-go/v7/modules/core/24-host" + errorsmod "cosmossdk.io/errors" - wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/cosmos/cosmos-sdk/baseapp" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" - host "github.com/cosmos/ibc-go/v7/modules/core/24-host" "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/keeper/handler_plugin_encoders.go b/x/wasm/keeper/handler_plugin_encoders.go index 984815cd..5e07ac7e 100644 --- a/x/wasm/keeper/handler_plugin_encoders.go +++ b/x/wasm/keeper/handler_plugin_encoders.go @@ -4,19 +4,20 @@ import ( "encoding/json" "fmt" - errorsmod "cosmossdk.io/errors" - v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - wasmvmtypes "github.com/CosmWasm/wasmvm/types" + ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + + errorsmod "cosmossdk.io/errors" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" - ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/keeper/handler_plugin_encoders_test.go b/x/wasm/keeper/handler_plugin_encoders_test.go index c4417f5d..5fa745d6 100644 --- a/x/wasm/keeper/handler_plugin_encoders_test.go +++ b/x/wasm/keeper/handler_plugin_encoders_test.go @@ -4,6 +4,13 @@ import ( "testing" wasmvmtypes "github.com/CosmWasm/wasmvm/types" + "github.com/cosmos/gogoproto/proto" + ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -11,12 +18,6 @@ import ( v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/cosmos/gogoproto/proto" - ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" - clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" "github.com/CosmWasm/wasmd/x/wasm/types" diff --git a/x/wasm/keeper/handler_plugin_test.go b/x/wasm/keeper/handler_plugin_test.go index beea6daf..09661722 100644 --- a/x/wasm/keeper/handler_plugin_test.go +++ b/x/wasm/keeper/handler_plugin_test.go @@ -4,20 +4,21 @@ import ( "encoding/json" "testing" - errorsmod "cosmossdk.io/errors" - wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/cometbft/cometbft/libs/log" + clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" - clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" "github.com/CosmWasm/wasmd/x/wasm/types" @@ -237,7 +238,7 @@ func TestIBCRawPacketHandler(t *testing.T) { var capturedPacket *CapturedPacket capturePacketsSenderMock := &wasmtesting.MockIBCPacketSender{ - SendPacketFn: func(ctx sdk.Context, channelCap *capabilitytypes.Capability, sourcePort string, sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) (uint64, error) { + SendPacketFn: func(ctx sdk.Context, channelCap *capabilitytypes.Capability, sourcePort, sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) (uint64, error) { capturedPacket = &CapturedPacket{ sourcePort: sourcePort, sourceChannel: sourceChannel, diff --git a/x/wasm/keeper/ibc.go b/x/wasm/keeper/ibc.go index 30eb3487..ac31dfac 100644 --- a/x/wasm/keeper/ibc.go +++ b/x/wasm/keeper/ibc.go @@ -3,10 +3,12 @@ package keeper import ( "strings" + host "github.com/cosmos/ibc-go/v7/modules/core/24-host" + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" - host "github.com/cosmos/ibc-go/v7/modules/core/24-host" "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/keeper/ibc_test.go b/x/wasm/keeper/ibc_test.go index 063dfb7f..01ed35b3 100644 --- a/x/wasm/keeper/ibc_test.go +++ b/x/wasm/keeper/ibc_test.go @@ -4,10 +4,10 @@ import ( "fmt" "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" ) func TestDontBindPortNonIBCContract(t *testing.T) { diff --git a/x/wasm/keeper/keeper.go b/x/wasm/keeper/keeper.go index 17f3f9e0..8b7eb0ef 100644 --- a/x/wasm/keeper/keeper.go +++ b/x/wasm/keeper/keeper.go @@ -11,14 +11,15 @@ import ( "strings" "time" - errorsmod "cosmossdk.io/errors" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/cometbft/cometbft/libs/log" + + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -46,7 +47,7 @@ type WasmVMQueryHandler interface { type CoinTransferrer interface { // TransferCoins sends the coin amounts from the source to the destination with rules applied. - TransferCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error + TransferCoins(ctx sdk.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error } // AccountPruner handles the balances and data cleanup for accounts that are pruned on contract instantiate. @@ -360,7 +361,7 @@ func (k Keeper) instantiate( } // Execute executes the contract instance -func (k Keeper) execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) ([]byte, error) { +func (k Keeper) execute(ctx sdk.Context, contractAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) ([]byte, error) { defer telemetry.MeasureSince(time.Now(), "wasm", "contract", "execute") contractInfo, codeInfo, prefixStore, err := k.contractInstance(ctx, contractAddress) if err != nil { @@ -1125,7 +1126,7 @@ func (k Keeper) QueryGasLimit() sdk.Gas { return k.queryGasLimit } -// BankCoinTransferrer replicates the cosmos-sdk behaviour as in +// BankCoinTransferrer replicates the cosmos-sdk behavior as in // https://github.com/cosmos/cosmos-sdk/blob/v0.41.4/x/bank/keeper/msg_server.go#L26 type BankCoinTransferrer struct { keeper types.BankKeeper @@ -1139,7 +1140,7 @@ func NewBankCoinTransferrer(keeper types.BankKeeper) BankCoinTransferrer { // TransferCoins transfers coins from source to destination account when coin send was enabled for them and the recipient // is not in the blocked address list. -func (c BankCoinTransferrer) TransferCoins(parentCtx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amount sdk.Coins) error { +func (c BankCoinTransferrer) TransferCoins(parentCtx sdk.Context, fromAddr, toAddr sdk.AccAddress, amount sdk.Coins) error { em := sdk.NewEventManager() ctx := parentCtx.WithEventManager(em) if err := c.keeper.IsSendEnabledCoins(ctx, amount...); err != nil { diff --git a/x/wasm/keeper/keeper_cgo.go b/x/wasm/keeper/keeper_cgo.go index 166f9b89..30d9e86e 100644 --- a/x/wasm/keeper/keeper_cgo.go +++ b/x/wasm/keeper/keeper_cgo.go @@ -5,10 +5,10 @@ package keeper import ( "path/filepath" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - wasmvm "github.com/CosmWasm/wasmvm" + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/keeper/keeper_test.go b/x/wasm/keeper/keeper_test.go index 8b289d31..bc2b58ed 100644 --- a/x/wasm/keeper/keeper_test.go +++ b/x/wasm/keeper/keeper_test.go @@ -12,13 +12,17 @@ import ( "testing" "time" - errorsmod "cosmossdk.io/errors" - wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/rand" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + fuzz "github.com/google/gofuzz" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" stypes "github.com/cosmos/cosmos-sdk/store/types" @@ -30,9 +34,6 @@ import ( vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - fuzz "github.com/google/gofuzz" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" "github.com/CosmWasm/wasmd/x/wasm/types" @@ -2226,12 +2227,16 @@ func TestCoinBurnerPruneBalances(t *testing.T) { expErr *errorsmod.Error }{ "vesting account - all removed": { - setupAcc: func(t *testing.T, ctx sdk.Context) authtypes.AccountI { return myVestingAccount }, + setupAcc: func(t *testing.T, ctx sdk.Context) authtypes.AccountI { + t.Helper() + return myVestingAccount + }, expBalances: sdk.NewCoins(), expHandled: true, }, "vesting account with other tokens - only original denoms removed": { setupAcc: func(t *testing.T, ctx sdk.Context) authtypes.AccountI { + t.Helper() keepers.Faucet.Fund(ctx, vestingAddr, sdk.NewCoin("other", sdk.NewInt(2))) return myVestingAccount }, @@ -2240,6 +2245,7 @@ func TestCoinBurnerPruneBalances(t *testing.T) { }, "non vesting account - not handled": { setupAcc: func(t *testing.T, ctx sdk.Context) authtypes.AccountI { + t.Helper() return &authtypes.BaseAccount{Address: myVestingAccount.GetAddress().String()} }, expBalances: sdk.NewCoins(sdk.NewCoin("denom", sdk.NewInt(100))), diff --git a/x/wasm/keeper/migrations.go b/x/wasm/keeper/migrations.go index 8bf0f96c..a7209035 100644 --- a/x/wasm/keeper/migrations.go +++ b/x/wasm/keeper/migrations.go @@ -3,11 +3,10 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/CosmWasm/wasmd/x/wasm/exported" v1 "github.com/CosmWasm/wasmd/x/wasm/migrations/v1" v2 "github.com/CosmWasm/wasmd/x/wasm/migrations/v2" v3 "github.com/CosmWasm/wasmd/x/wasm/migrations/v3" - - "github.com/CosmWasm/wasmd/x/wasm/exported" ) // Migrator is a struct for handling in-place store migrations. diff --git a/x/wasm/keeper/migrations_integration_test.go b/x/wasm/keeper/migrations_integration_test.go index ca8414ba..5cd5a782 100644 --- a/x/wasm/keeper/migrations_integration_test.go +++ b/x/wasm/keeper/migrations_integration_test.go @@ -3,16 +3,16 @@ package keeper_test import ( "testing" - "github.com/CosmWasm/wasmd/x/wasm/types" - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/CosmWasm/wasmd/app" + "github.com/CosmWasm/wasmd/x/wasm/types" ) func TestModuleMigrations(t *testing.T) { diff --git a/x/wasm/keeper/msg_dispatcher.go b/x/wasm/keeper/msg_dispatcher.go index e3a16a3b..9520e000 100644 --- a/x/wasm/keeper/msg_dispatcher.go +++ b/x/wasm/keeper/msg_dispatcher.go @@ -5,9 +5,11 @@ import ( "sort" "strings" - errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" abci "github.com/cometbft/cometbft/abci/types" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" diff --git a/x/wasm/keeper/msg_dispatcher_test.go b/x/wasm/keeper/msg_dispatcher_test.go index 73e5db5b..f9bc676c 100644 --- a/x/wasm/keeper/msg_dispatcher_test.go +++ b/x/wasm/keeper/msg_dispatcher_test.go @@ -8,10 +8,11 @@ import ( wasmvmtypes "github.com/CosmWasm/wasmvm/types" abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/log" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" ) diff --git a/x/wasm/keeper/msg_server.go b/x/wasm/keeper/msg_server.go index ace3059d..369ef2e5 100644 --- a/x/wasm/keeper/msg_server.go +++ b/x/wasm/keeper/msg_server.go @@ -4,6 +4,7 @@ import ( "context" errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/CosmWasm/wasmd/x/wasm/types" diff --git a/x/wasm/keeper/msg_server_integration_test.go b/x/wasm/keeper/msg_server_integration_test.go index e4b3ed6b..fcc1410b 100644 --- a/x/wasm/keeper/msg_server_integration_test.go +++ b/x/wasm/keeper/msg_server_integration_test.go @@ -8,13 +8,13 @@ import ( wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" - "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdk "github.com/cosmos/cosmos-sdk/types" - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/testutil/testdata" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/CosmWasm/wasmd/app" "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/types" diff --git a/x/wasm/keeper/msg_server_test.go b/x/wasm/keeper/msg_server_test.go index 6a064e50..61d05f65 100644 --- a/x/wasm/keeper/msg_server_test.go +++ b/x/wasm/keeper/msg_server_test.go @@ -5,9 +5,10 @@ import ( "github.com/cometbft/cometbft/libs/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/stretchr/testify/assert" + "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/keeper/options.go b/x/wasm/keeper/options.go index a79253e7..bef44458 100644 --- a/x/wasm/keeper/options.go +++ b/x/wasm/keeper/options.go @@ -4,9 +4,10 @@ import ( "fmt" "reflect" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/prometheus/client_golang/prometheus" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/keeper/options_test.go b/x/wasm/keeper/options_test.go index fe6640b3..91aae5b0 100644 --- a/x/wasm/keeper/options_test.go +++ b/x/wasm/keeper/options_test.go @@ -5,14 +5,14 @@ import ( "testing" wasmvm "github.com/CosmWasm/wasmvm" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" "github.com/CosmWasm/wasmd/x/wasm/types" @@ -27,6 +27,7 @@ func TestConstructorOptions(t *testing.T) { "wasm engine": { srcOpt: WithWasmEngine(&wasmtesting.MockWasmer{}), verify: func(t *testing.T, k Keeper) { + t.Helper() assert.IsType(t, &wasmtesting.MockWasmer{}, k.wasmVM) }, }, @@ -36,6 +37,7 @@ func TestConstructorOptions(t *testing.T) { return &wasmtesting.MockWasmer{} }), verify: func(t *testing.T, k Keeper) { + t.Helper() assert.IsType(t, &wasmtesting.MockWasmer{}, k.wasmVM) }, isPostOpt: true, @@ -43,12 +45,14 @@ func TestConstructorOptions(t *testing.T) { "message handler": { srcOpt: WithMessageHandler(&wasmtesting.MockMessageHandler{}), verify: func(t *testing.T, k Keeper) { + t.Helper() assert.IsType(t, &wasmtesting.MockMessageHandler{}, k.messenger) }, }, "query plugins": { srcOpt: WithQueryHandler(&wasmtesting.MockQueryHandler{}), verify: func(t *testing.T, k Keeper) { + t.Helper() assert.IsType(t, &wasmtesting.MockQueryHandler{}, k.wasmVMQueryHandler) }, }, @@ -58,6 +62,7 @@ func TestConstructorOptions(t *testing.T) { return &wasmtesting.MockMessageHandler{} }), verify: func(t *testing.T, k Keeper) { + t.Helper() assert.IsType(t, &wasmtesting.MockMessageHandler{}, k.messenger) }, isPostOpt: true, @@ -68,6 +73,7 @@ func TestConstructorOptions(t *testing.T) { return &wasmtesting.MockQueryHandler{} }), verify: func(t *testing.T, k Keeper) { + t.Helper() assert.IsType(t, &wasmtesting.MockQueryHandler{}, k.wasmVMQueryHandler) }, isPostOpt: true, @@ -75,18 +81,21 @@ func TestConstructorOptions(t *testing.T) { "coin transferrer": { srcOpt: WithCoinTransferrer(&wasmtesting.MockCoinTransferrer{}), verify: func(t *testing.T, k Keeper) { + t.Helper() assert.IsType(t, &wasmtesting.MockCoinTransferrer{}, k.bank) }, }, "costs": { srcOpt: WithGasRegister(&wasmtesting.MockGasRegister{}), verify: func(t *testing.T, k Keeper) { + t.Helper() assert.IsType(t, &wasmtesting.MockGasRegister{}, k.gasRegister) }, }, "api costs": { srcOpt: WithAPICosts(1, 2), verify: func(t *testing.T, k Keeper) { + t.Helper() t.Cleanup(setAPIDefaults) assert.Equal(t, uint64(1), costHumanize) assert.Equal(t, uint64(2), costCanonical) @@ -95,12 +104,14 @@ func TestConstructorOptions(t *testing.T) { "max recursion query limit": { srcOpt: WithMaxQueryStackSize(1), verify: func(t *testing.T, k Keeper) { + t.Helper() assert.IsType(t, uint32(1), k.maxQueryStackSize) }, }, "accepted account types": { srcOpt: WithAcceptedAccountTypesOnContractInstantiation(&authtypes.BaseAccount{}, &vestingtypes.ContinuousVestingAccount{}), verify: func(t *testing.T, k Keeper) { + t.Helper() exp := map[reflect.Type]struct{}{ reflect.TypeOf(&authtypes.BaseAccount{}): {}, reflect.TypeOf(&vestingtypes.ContinuousVestingAccount{}): {}, @@ -111,12 +122,14 @@ func TestConstructorOptions(t *testing.T) { "account pruner": { srcOpt: WithAccountPruner(VestingCoinBurner{}), verify: func(t *testing.T, k Keeper) { + t.Helper() assert.Equal(t, VestingCoinBurner{}, k.accountPruner) }, }, "gov propagation": { srcOpt: WitGovSubMsgAuthZPropagated(types.AuthZActionInstantiate, types.AuthZActionMigrateContract), verify: func(t *testing.T, k Keeper) { + t.Helper() exp := map[types.AuthorizationPolicyAction]struct{}{ types.AuthZActionInstantiate: {}, types.AuthZActionMigrateContract: {}, diff --git a/x/wasm/keeper/proposal_integration_test.go b/x/wasm/keeper/proposal_integration_test.go index acfa30a4..d21dbd73 100644 --- a/x/wasm/keeper/proposal_integration_test.go +++ b/x/wasm/keeper/proposal_integration_test.go @@ -9,13 +9,14 @@ import ( "testing" wasmvm "github.com/CosmWasm/wasmvm" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" "github.com/CosmWasm/wasmd/x/wasm/types" @@ -100,7 +101,7 @@ func mustSubmitAndExecuteLegacyProposal(t *testing.T, ctx sdk.Context, content v } // does not fail on submit proposal -func submitLegacyProposal(t *testing.T, ctx sdk.Context, content v1beta1.Content, myActorAddress string, govAuthority string, msgServer v1.MsgServer) (*v1.MsgExecLegacyContent, error) { +func submitLegacyProposal(t *testing.T, ctx sdk.Context, content v1beta1.Content, myActorAddress, govAuthority string, msgServer v1.MsgServer) (*v1.MsgExecLegacyContent, error) { t.Helper() contentMsg, err := v1.NewLegacyContent(content, govAuthority) require.NoError(t, err) diff --git a/x/wasm/keeper/querier.go b/x/wasm/keeper/querier.go index 0d31364d..d953c37e 100644 --- a/x/wasm/keeper/querier.go +++ b/x/wasm/keeper/querier.go @@ -5,15 +5,17 @@ import ( "encoding/binary" "runtime/debug" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -64,7 +66,7 @@ func (q GrpcQuerier) ContractHistory(c context.Context, req *types.QueryContract r := make([]types.ContractCodeHistoryEntry, 0) prefixStore := prefix.NewStore(ctx.KVStore(q.storeKey), types.GetContractCodeHistoryElementPrefix(contractAddr)) - pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) { + pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key, value []byte, accumulate bool) (bool, error) { if accumulate { var e types.ContractCodeHistoryEntry if err := q.cdc.Unmarshal(value, &e); err != nil { @@ -95,7 +97,7 @@ func (q GrpcQuerier) ContractsByCode(c context.Context, req *types.QueryContract r := make([]string, 0) prefixStore := prefix.NewStore(ctx.KVStore(q.storeKey), types.GetContractByCodeIDSecondaryIndexPrefix(req.CodeId)) - pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) { + pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key, value []byte, accumulate bool) (bool, error) { if accumulate { var contractAddr sdk.AccAddress = key[types.AbsoluteTxPositionLen:] r = append(r, contractAddr.String()) @@ -127,7 +129,7 @@ func (q GrpcQuerier) AllContractState(c context.Context, req *types.QueryAllCont r := make([]types.Model, 0) prefixStore := prefix.NewStore(ctx.KVStore(q.storeKey), types.GetContractStorePrefix(contractAddr)) - pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) { + pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key, value []byte, accumulate bool) (bool, error) { if accumulate { r = append(r, types.Model{ Key: key, @@ -235,7 +237,7 @@ func (q GrpcQuerier) Codes(c context.Context, req *types.QueryCodesRequest) (*ty ctx := sdk.UnwrapSDKContext(c) r := make([]types.CodeInfoResponse, 0) prefixStore := prefix.NewStore(ctx.KVStore(q.storeKey), types.CodeKeyPrefix) - pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) { + pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key, value []byte, accumulate bool) (bool, error) { if accumulate { var c types.CodeInfo if err := q.cdc.Unmarshal(value, &c); err != nil { @@ -300,7 +302,7 @@ func (q GrpcQuerier) PinnedCodes(c context.Context, req *types.QueryPinnedCodesR r := make([]uint64, 0) prefixStore := prefix.NewStore(ctx.KVStore(q.storeKey), types.PinnedCodeIndexPrefix) - pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key []byte, _ []byte, accumulate bool) (bool, error) { + pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key, _ []byte, accumulate bool) (bool, error) { if accumulate { r = append(r, sdk.BigEndianToUint64(key)) } @@ -334,7 +336,7 @@ func (q GrpcQuerier) ContractsByCreator(c context.Context, req *types.QueryContr return nil, err } prefixStore := prefix.NewStore(ctx.KVStore(q.storeKey), types.GetContractsByCreatorPrefix(creatorAddress)) - pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key []byte, _ []byte, accumulate bool) (bool, error) { + pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key, _ []byte, accumulate bool) (bool, error) { if accumulate { accAddres := sdk.AccAddress(key[types.AbsoluteTxPositionLen:]) contracts = append(contracts, accAddres.String()) diff --git a/x/wasm/keeper/querier_test.go b/x/wasm/keeper/querier_test.go index 4326bf83..8fd64159 100644 --- a/x/wasm/keeper/querier_test.go +++ b/x/wasm/keeper/querier_test.go @@ -9,19 +9,21 @@ import ( "testing" "time" - errorsmod "cosmossdk.io/errors" wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/cometbft/cometbft/libs/log" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkErrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/types/query" - govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkErrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/types/query" + govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/keeper/query_plugins.go b/x/wasm/keeper/query_plugins.go index eba5cbff..9ce72d84 100644 --- a/x/wasm/keeper/query_plugins.go +++ b/x/wasm/keeper/query_plugins.go @@ -5,9 +5,12 @@ import ( "errors" "fmt" - errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" abci "github.com/cometbft/cometbft/abci/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -16,7 +19,6 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -322,7 +324,7 @@ type AcceptedStargateQueries map[string]codec.ProtoMarshaler // All arguments must be non nil. // // Warning: Chains need to test and maintain their accept list carefully. -// There were critical consensus breaking issues in the past with non-deterministic behaviour in the SDK. +// There were critical consensus breaking issues in the past with non-deterministic behavior in the SDK. // // This queries can be set via WithQueryPlugins option in the wasm keeper constructor: // WithQueryPlugins(&QueryPlugins{Stargate: AcceptListStargateQuerier(acceptList, queryRouter, codec)}) @@ -673,7 +675,7 @@ func ConvertSdkDenomUnitsToWasmDenomUnits(denomUnits []*banktypes.DenomUnit) []w // ConvertProtoToJSONMarshal unmarshals the given bytes into a proto message and then marshals it to json. // This is done so that clients calling stargate queries do not need to define their own proto unmarshalers, -// being able to use response directly by json marshalling, which is supported in cosmwasm. +// being able to use response directly by json marshaling, which is supported in cosmwasm. func ConvertProtoToJSONMarshal(cdc codec.Codec, protoResponse codec.ProtoMarshaler, bz []byte) ([]byte, error) { // unmarshal binary into stargate response data structure err := cdc.Unmarshal(bz, protoResponse) diff --git a/x/wasm/keeper/query_plugins_test.go b/x/wasm/keeper/query_plugins_test.go index c7b240b5..7f4eceeb 100644 --- a/x/wasm/keeper/query_plugins_test.go +++ b/x/wasm/keeper/query_plugins_test.go @@ -8,27 +8,28 @@ import ( "testing" "time" - "github.com/cometbft/cometbft/libs/rand" - "github.com/cosmos/cosmos-sdk/types/address" - distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - - errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" dbm "github.com/cometbft/cometbft-db" + "github.com/cometbft/cometbft/libs/rand" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/cosmos/gogoproto/proto" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/types/query" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/cosmos/gogoproto/proto" - channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/app" "github.com/CosmWasm/wasmd/x/wasm/keeper" @@ -933,7 +934,7 @@ func TestConvertProtoToJSONMarshal(t *testing.T) { expectedError bool }{ { - name: "successful conversion from proto response to json marshalled response", + name: "successful conversion from proto response to json marshaled response", queryPath: "/cosmos.bank.v1beta1.Query/AllBalances", originalResponse: "0a090a036261721202333012050a03666f6f", protoResponseStruct: &banktypes.QueryAllBalancesResponse{}, @@ -966,7 +967,7 @@ func TestConvertProtoToJSONMarshal(t *testing.T) { } require.NoError(t, err) - // check response by json marshalling proto response into json response manually + // check response by json marshaling proto response into json response manually jsonMarshalExpectedResponse, err := appCodec.MarshalJSON(tc.expectedProtoResponse) require.NoError(t, err) require.JSONEq(t, string(jsonMarshalledResponse), string(jsonMarshalExpectedResponse)) @@ -999,7 +1000,7 @@ func TestResetProtoMarshalerAfterJsonMarshal(t *testing.T) { require.Equal(t, expected, response) } -// TestDeterministicJsonMarshal tests that we get deterministic JSON marshalled response upon +// TestDeterministicJsonMarshal tests that we get deterministic JSON marshaled response upon // proto struct update in the state machine. func TestDeterministicJsonMarshal(t *testing.T) { testCases := []struct { @@ -1063,7 +1064,7 @@ func TestDeterministicJsonMarshal(t *testing.T) { jsonMarshalledUpdatedBz, err := keeper.ConvertProtoToJSONMarshal(appCodec, tc.responseProtoStruct, newVersionBz) require.NoError(t, err) - // json marshalled bytes should be the same since we use the same proto struct for unmarshalling + // json marshaled bytes should be the same since we use the same proto struct for unmarshalling require.Equal(t, jsonMarshalledOriginalBz, jsonMarshalledUpdatedBz) // raw build also make same result diff --git a/x/wasm/keeper/recurse_test.go b/x/wasm/keeper/recurse_test.go index cab895b1..4b2e22ff 100644 --- a/x/wasm/keeper/recurse_test.go +++ b/x/wasm/keeper/recurse_test.go @@ -4,15 +4,14 @@ import ( "encoding/json" "testing" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - - "github.com/CosmWasm/wasmd/x/wasm/types" - wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/CosmWasm/wasmd/x/wasm/types" ) type Recurse struct { @@ -25,6 +24,7 @@ type recurseWrapper struct { } func buildRecurseQuery(t *testing.T, msg Recurse) []byte { + t.Helper() wrapper := recurseWrapper{Recurse: msg} bz, err := json.Marshal(wrapper) require.NoError(t, err) @@ -39,6 +39,7 @@ type recurseResponse struct { var totalWasmQueryCounter int func initRecurseContract(t *testing.T) (contract sdk.AccAddress, ctx sdk.Context, keeper *Keeper) { + t.Helper() countingQuerierDec := func(realWasmQuerier WasmVMQueryHandler) WasmVMQueryHandler { return WasmVMQueryHandlerFn(func(ctx sdk.Context, caller sdk.AccAddress, request wasmvmtypes.QueryRequest) ([]byte, error) { totalWasmQueryCounter++ diff --git a/x/wasm/keeper/reflect_test.go b/x/wasm/keeper/reflect_test.go index a641ffe1..d3093f25 100644 --- a/x/wasm/keeper/reflect_test.go +++ b/x/wasm/keeper/reflect_test.go @@ -7,8 +7,13 @@ import ( "strings" "testing" - errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" + "github.com/cosmos/gogoproto/proto" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -16,9 +21,6 @@ import ( authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/cosmos/gogoproto/proto" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/x/wasm/keeper/testdata" "github.com/CosmWasm/wasmd/x/wasm/types" @@ -27,12 +29,14 @@ import ( // ReflectInitMsg is {} func buildReflectQuery(t *testing.T, query *testdata.ReflectQueryMsg) []byte { + t.Helper() bz, err := json.Marshal(query) require.NoError(t, err) return bz } func mustParse(t *testing.T, data []byte, res interface{}) { + t.Helper() err := json.Unmarshal(data, res) require.NoError(t, err) } @@ -686,6 +690,7 @@ func TestQueryDenomsIntegration(t *testing.T) { } func checkAccount(t *testing.T, ctx sdk.Context, accKeeper authkeeper.AccountKeeper, bankKeeper bankkeeper.Keeper, addr sdk.AccAddress, expected sdk.Coins) { + t.Helper() acct := accKeeper.GetAccount(ctx, addr) if expected == nil { assert.Nil(t, acct) diff --git a/x/wasm/keeper/relay.go b/x/wasm/keeper/relay.go index 4aaeee95..209218b8 100644 --- a/x/wasm/keeper/relay.go +++ b/x/wasm/keeper/relay.go @@ -3,11 +3,12 @@ package keeper import ( "time" + wasmvmtypes "github.com/CosmWasm/wasmvm/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" errorsmod "cosmossdk.io/errors" - wasmvmtypes "github.com/CosmWasm/wasmvm/types" + "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/wasm/keeper/relay_test.go b/x/wasm/keeper/relay_test.go index ade43a1e..a2bb9a5f 100644 --- a/x/wasm/keeper/relay_test.go +++ b/x/wasm/keeper/relay_test.go @@ -8,10 +8,11 @@ import ( wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/keeper/snapshotter.go b/x/wasm/keeper/snapshotter.go index ca442391..d527d44b 100644 --- a/x/wasm/keeper/snapshotter.go +++ b/x/wasm/keeper/snapshotter.go @@ -5,9 +5,11 @@ import ( "io" "math" - errorsmod "cosmossdk.io/errors" "github.com/cometbft/cometbft/libs/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + + errorsmod "cosmossdk.io/errors" + snapshot "github.com/cosmos/cosmos-sdk/snapshots/types" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/wasm/keeper/snapshotter_integration_test.go b/x/wasm/keeper/snapshotter_integration_test.go index dacbef09..d93d7822 100644 --- a/x/wasm/keeper/snapshotter_integration_test.go +++ b/x/wasm/keeper/snapshotter_integration_test.go @@ -5,23 +5,22 @@ import ( "testing" "time" - "github.com/CosmWasm/wasmd/x/wasm/types" - - "github.com/stretchr/testify/assert" - wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" tmtypes "github.com/cometbft/cometbft/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/app" "github.com/CosmWasm/wasmd/x/wasm/keeper" + "github.com/CosmWasm/wasmd/x/wasm/types" ) func TestSnapshotter(t *testing.T) { @@ -112,6 +111,7 @@ func TestSnapshotter(t *testing.T) { } func newWasmExampleApp(t *testing.T) (*app.WasmApp, sdk.AccAddress) { + t.Helper() senderPrivKey := ed25519.GenPrivKey() pubKey, err := cryptocodec.ToTmPubKeyInterface(senderPrivKey.PubKey()) require.NoError(t, err) diff --git a/x/wasm/keeper/staking_test.go b/x/wasm/keeper/staking_test.go index 224cc90c..891cae15 100644 --- a/x/wasm/keeper/staking_test.go +++ b/x/wasm/keeper/staking_test.go @@ -6,6 +6,9 @@ import ( "testing" wasmvmtypes "github.com/CosmWasm/wasmvm/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" @@ -15,8 +18,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/x/wasm/keeper/testdata" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" @@ -166,6 +167,7 @@ type initInfo struct { } func initializeStaking(t *testing.T) initInfo { + t.Helper() ctx, k := CreateTestInput(t, false, AvailableCapabilities) accKeeper, stakingKeeper, keeper, bankKeeper := k.AccountKeeper, k.StakingKeeper, k.WasmKeeper, k.BankKeeper @@ -645,6 +647,7 @@ func TestQueryStakingPlugin(t *testing.T) { // adds a few validators and returns a list of validators that are registered func addValidator(t *testing.T, ctx sdk.Context, stakingKeeper *stakingkeeper.Keeper, faucet *TestFaucet, value sdk.Coin) sdk.ValAddress { + t.Helper() owner := faucet.NewFundedRandomAccount(ctx, value) privKey := secp256k1.GenPrivKey() @@ -693,7 +696,8 @@ func setValidatorRewards(ctx sdk.Context, stakingKeeper *stakingkeeper.Keeper, d distKeeper.AllocateTokensToValidator(ctx, vali, payout) } -func assertBalance(t *testing.T, ctx sdk.Context, keeper Keeper, contract sdk.AccAddress, addr sdk.AccAddress, expected string) { +func assertBalance(t *testing.T, ctx sdk.Context, keeper Keeper, contract, addr sdk.AccAddress, expected string) { + t.Helper() query := StakingQueryMsg{ Balance: &addressQuery{ Address: addr, @@ -709,7 +713,8 @@ func assertBalance(t *testing.T, ctx sdk.Context, keeper Keeper, contract sdk.Ac assert.Equal(t, expected, balance.Balance) } -func assertClaims(t *testing.T, ctx sdk.Context, keeper Keeper, contract sdk.AccAddress, addr sdk.AccAddress, expected string) { +func assertClaims(t *testing.T, ctx sdk.Context, keeper Keeper, contract, addr sdk.AccAddress, expected string) { + t.Helper() query := StakingQueryMsg{ Claims: &addressQuery{ Address: addr, @@ -726,6 +731,7 @@ func assertClaims(t *testing.T, ctx sdk.Context, keeper Keeper, contract sdk.Acc } func assertSupply(t *testing.T, ctx sdk.Context, keeper Keeper, contract sdk.AccAddress, expectedIssued string, expectedBonded sdk.Coin) { + t.Helper() query := StakingQueryMsg{Investment: &struct{}{}} queryBz, err := json.Marshal(query) require.NoError(t, err) diff --git a/x/wasm/keeper/submsg_test.go b/x/wasm/keeper/submsg_test.go index f7a075f3..6b5dd569 100644 --- a/x/wasm/keeper/submsg_test.go +++ b/x/wasm/keeper/submsg_test.go @@ -7,19 +7,18 @@ import ( "strconv" "testing" - errorsmod "cosmossdk.io/errors" - wasmvm "github.com/CosmWasm/wasmvm" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - - "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" - wasmvmtypes "github.com/CosmWasm/wasmvm/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/CosmWasm/wasmd/x/wasm/keeper/testdata" + "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -194,12 +193,14 @@ func TestDispatchSubMsgErrorHandling(t *testing.T) { assertReturnedEvents := func(expectedEvents int) assertion { return func(t *testing.T, ctx sdk.Context, contract, emptyAccount string, response wasmvmtypes.SubMsgResult) { + t.Helper() require.Len(t, response.Ok.Events, expectedEvents) } } assertGasUsed := func(minGas, maxGas uint64) assertion { return func(t *testing.T, ctx sdk.Context, contract, emptyAccount string, response wasmvmtypes.SubMsgResult) { + t.Helper() gasUsed := ctx.GasMeter().GasConsumed() assert.True(t, gasUsed >= minGas, "Used %d gas (less than expected %d)", gasUsed, minGas) assert.True(t, gasUsed <= maxGas, "Used %d gas (more than expected %d)", gasUsed, maxGas) @@ -208,11 +209,13 @@ func TestDispatchSubMsgErrorHandling(t *testing.T) { assertErrorString := func(shouldContain string) assertion { return func(t *testing.T, ctx sdk.Context, contract, emptyAccount string, response wasmvmtypes.SubMsgResult) { + t.Helper() assert.Contains(t, response.Err, shouldContain) } } assertGotContractAddr := func(t *testing.T, ctx sdk.Context, contract, emptyAccount string, response wasmvmtypes.SubMsgResult) { + t.Helper() // should get the events emitted on new contract event := response.Ok.Events[0] require.Equal(t, event.Type, "instantiate") diff --git a/x/wasm/keeper/test_common.go b/x/wasm/keeper/test_common.go index 7f2d8cd0..db7861d5 100644 --- a/x/wasm/keeper/test_common.go +++ b/x/wasm/keeper/test_common.go @@ -9,19 +9,23 @@ import ( "testing" "time" - "github.com/CosmWasm/wasmd/x/wasm/keeper/testdata" - - icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" - icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" - - errorsmod "cosmossdk.io/errors" - dbm "github.com/cometbft/cometbft-db" "github.com/cometbft/cometbft/crypto" "github.com/cometbft/cometbft/crypto/ed25519" "github.com/cometbft/cometbft/libs/log" "github.com/cometbft/cometbft/libs/rand" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" + icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" + "github.com/cosmos/ibc-go/v7/modules/apps/transfer" + ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + ibc "github.com/cosmos/ibc-go/v7/modules/core" + ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" + ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" + "github.com/stretchr/testify/require" + + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/std" @@ -72,14 +76,9 @@ import ( upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - "github.com/cosmos/ibc-go/v7/modules/apps/transfer" - ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" - ibc "github.com/cosmos/ibc-go/v7/modules/core" - ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" - ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" - "github.com/stretchr/testify/require" wasmappparams "github.com/CosmWasm/wasmd/app/params" + "github.com/CosmWasm/wasmd/x/wasm/keeper/testdata" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -106,8 +105,10 @@ var moduleBasics = module.NewBasicManager( vesting.AppModuleBasic{}, ) -func MakeTestCodec(t testing.TB) codec.Codec { - return MakeEncodingConfig(t).Marshaler +func MakeTestCodec(tb testing.TB) codec.Codec { + tb.Helper() + + return MakeEncodingConfig(tb).Marshaler } func MakeEncodingConfig(_ testing.TB) wasmappparams.EncodingConfig { @@ -144,9 +145,11 @@ type TestFaucet struct { minterModuleName string } -func NewTestFaucet(t testing.TB, ctx sdk.Context, bankKeeper bankkeeper.Keeper, minterModuleName string, initialAmount ...sdk.Coin) *TestFaucet { - require.NotEmpty(t, initialAmount) - r := &TestFaucet{t: t, bankKeeper: bankKeeper, minterModuleName: minterModuleName} +func NewTestFaucet(tb testing.TB, ctx sdk.Context, bankKeeper bankkeeper.Keeper, minterModuleName string, initialAmount ...sdk.Coin) *TestFaucet { + tb.Helper() + + require.NotEmpty(tb, initialAmount) + r := &TestFaucet{t: tb, bankKeeper: bankKeeper, minterModuleName: minterModuleName} _, addr := keyPubAddr() r.sender = addr r.Mint(ctx, addr, initialAmount...) @@ -200,26 +203,32 @@ type TestKeepers struct { } // CreateDefaultTestInput common settings for CreateTestInput -func CreateDefaultTestInput(t testing.TB) (sdk.Context, TestKeepers) { - return CreateTestInput(t, false, "staking") +func CreateDefaultTestInput(tb testing.TB) (sdk.Context, TestKeepers) { + tb.Helper() + + return CreateTestInput(tb, false, "staking") } // CreateTestInput encoders can be nil to accept the defaults, or set it to override some of the message handlers (like default) -func CreateTestInput(t testing.TB, isCheckTx bool, availableCapabilities string, opts ...Option) (sdk.Context, TestKeepers) { +func CreateTestInput(tb testing.TB, isCheckTx bool, availableCapabilities string, opts ...Option) (sdk.Context, TestKeepers) { + tb.Helper() + // Load default wasm config - return createTestInput(t, isCheckTx, availableCapabilities, types.DefaultWasmConfig(), dbm.NewMemDB(), opts...) + return createTestInput(tb, isCheckTx, availableCapabilities, types.DefaultWasmConfig(), dbm.NewMemDB(), opts...) } // encoders can be nil to accept the defaults, or set it to override some of the message handlers (like default) func createTestInput( - t testing.TB, + tb testing.TB, isCheckTx bool, availableCapabilities string, wasmConfig types.WasmConfig, db dbm.DB, opts ...Option, ) (sdk.Context, TestKeepers) { - tempDir := t.TempDir() + tb.Helper() + + tempDir := tb.TempDir() keys := sdk.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, @@ -243,7 +252,7 @@ func createTestInput( ms.MountStoreWithDB(v, storetypes.StoreTypeMemory, db) } - require.NoError(t, ms.LoadLatestVersion()) + require.NoError(tb, ms.LoadLatestVersion()) ctx := sdk.NewContext(ms, tmproto.Header{ Height: 1234567, @@ -251,7 +260,7 @@ func createTestInput( }, isCheckTx, log.NewNopLogger()) ctx = types.WithTXCounter(ctx, 0) - encodingConfig := MakeEncodingConfig(t) + encodingConfig := MakeEncodingConfig(tb) appCodec, legacyAmino := encodingConfig.Marshaler, encodingConfig.Amino paramsKeeper := paramskeeper.NewKeeper( @@ -278,7 +287,7 @@ func createTestInput( } subspace := func(m string) paramstypes.Subspace { r, ok := paramsKeeper.GetSubspace(m) - require.True(t, ok) + require.True(tb, ok) var keyTable paramstypes.KeyTable switch r.Name() { @@ -340,7 +349,7 @@ func createTestInput( blockedAddrs[authtypes.NewModuleAddress(acc).String()] = true } - require.NoError(t, accountKeeper.SetParams(ctx, authtypes.DefaultParams())) + require.NoError(tb, accountKeeper.SetParams(ctx, authtypes.DefaultParams())) bankKeeper := bankkeeper.NewBaseKeeper( appCodec, @@ -349,7 +358,7 @@ func createTestInput( blockedAddrs, authtypes.NewModuleAddress(banktypes.ModuleName).String(), ) - require.NoError(t, bankKeeper.SetParams(ctx, banktypes.DefaultParams())) + require.NoError(tb, bankKeeper.SetParams(ctx, banktypes.DefaultParams())) stakingKeeper := stakingkeeper.NewKeeper( appCodec, @@ -359,7 +368,7 @@ func createTestInput( authtypes.NewModuleAddress(stakingtypes.ModuleName).String(), ) stakingtypes.DefaultParams() - require.NoError(t, stakingKeeper.SetParams(ctx, TestingStakeParams)) + require.NoError(tb, stakingKeeper.SetParams(ctx, TestingStakeParams)) distKeeper := distributionkeeper.NewKeeper( appCodec, @@ -370,7 +379,7 @@ func createTestInput( authtypes.FeeCollectorName, authtypes.NewModuleAddress(distributiontypes.ModuleName).String(), ) - require.NoError(t, distKeeper.SetParams(ctx, distributiontypes.DefaultParams())) + require.NoError(tb, distKeeper.SetParams(ctx, distributiontypes.DefaultParams())) stakingKeeper.SetHooks(distKeeper.Hooks()) // set genesis items required for distribution @@ -385,7 +394,7 @@ func createTestInput( authtypes.NewModuleAddress(upgradetypes.ModuleName).String(), ) - faucet := NewTestFaucet(t, ctx, bankKeeper, minttypes.ModuleName, sdk.NewCoin("stake", sdk.NewInt(100_000_000_000))) + faucet := NewTestFaucet(tb, ctx, bankKeeper, minttypes.ModuleName, sdk.NewCoin("stake", sdk.NewInt(100_000_000_000))) // set some funds ot pay out validatores, based on code from: // https://github.com/cosmos/cosmos-sdk/blob/fea231556aee4d549d7551a6190389c4328194eb/x/distribution/keeper/keeper_test.go#L50-L57 @@ -438,7 +447,7 @@ func createTestInput( authtypes.NewModuleAddress(govtypes.ModuleName).String(), opts..., ) - require.NoError(t, keeper.SetParams(ctx, types.DefaultParams())) + require.NoError(tb, keeper.SetParams(ctx, types.DefaultParams())) // add wasm handler so we can loop-back (contracts calling contracts) contractKeeper := NewDefaultPermissionKeeper(&keeper) @@ -458,7 +467,7 @@ func createTestInput( govtypes.DefaultConfig(), authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) - require.NoError(t, govKeeper.SetParams(ctx, govv1.DefaultParams())) + require.NoError(tb, govKeeper.SetParams(ctx, govv1.DefaultParams())) govKeeper.SetLegacyRouter(govRouter) govKeeper.SetProposalID(ctx, 1) @@ -586,8 +595,10 @@ func DeterministicAccountAddress(_ testing.TB, v byte) sdk.AccAddress { return bytes.Repeat([]byte{v}, address.Len) } -func RandomBech32AccountAddress(t testing.TB) string { - return RandomAccountAddress(t).String() +func RandomBech32AccountAddress(tb testing.TB) string { + tb.Helper() + + return RandomAccountAddress(tb).String() } type ExampleContract struct { @@ -598,35 +609,47 @@ type ExampleContract struct { Checksum []byte } -func StoreHackatomExampleContract(t testing.TB, ctx sdk.Context, keepers TestKeepers) ExampleContract { - return StoreExampleContractWasm(t, ctx, keepers, testdata.HackatomContractWasm()) +func StoreHackatomExampleContract(tb testing.TB, ctx sdk.Context, keepers TestKeepers) ExampleContract { + tb.Helper() + + return StoreExampleContractWasm(tb, ctx, keepers, testdata.HackatomContractWasm()) } -func StoreBurnerExampleContract(t testing.TB, ctx sdk.Context, keepers TestKeepers) ExampleContract { - return StoreExampleContractWasm(t, ctx, keepers, testdata.BurnerContractWasm()) +func StoreBurnerExampleContract(tb testing.TB, ctx sdk.Context, keepers TestKeepers) ExampleContract { + tb.Helper() + + return StoreExampleContractWasm(tb, ctx, keepers, testdata.BurnerContractWasm()) } -func StoreIBCReflectContract(t testing.TB, ctx sdk.Context, keepers TestKeepers) ExampleContract { - return StoreExampleContractWasm(t, ctx, keepers, testdata.IBCReflectContractWasm()) +func StoreIBCReflectContract(tb testing.TB, ctx sdk.Context, keepers TestKeepers) ExampleContract { + tb.Helper() + + return StoreExampleContractWasm(tb, ctx, keepers, testdata.IBCReflectContractWasm()) } -func StoreReflectContract(t testing.TB, ctx sdk.Context, keepers TestKeepers) ExampleContract { - return StoreExampleContractWasm(t, ctx, keepers, testdata.ReflectContractWasm()) +func StoreReflectContract(tb testing.TB, ctx sdk.Context, keepers TestKeepers) ExampleContract { + tb.Helper() + + return StoreExampleContractWasm(tb, ctx, keepers, testdata.ReflectContractWasm()) } -func StoreExampleContract(t testing.TB, ctx sdk.Context, keepers TestKeepers, wasmFile string) ExampleContract { +func StoreExampleContract(tb testing.TB, ctx sdk.Context, keepers TestKeepers, wasmFile string) ExampleContract { + tb.Helper() + wasmCode, err := os.ReadFile(wasmFile) - require.NoError(t, err) - return StoreExampleContractWasm(t, ctx, keepers, wasmCode) + require.NoError(tb, err) + return StoreExampleContractWasm(tb, ctx, keepers, wasmCode) } -func StoreExampleContractWasm(t testing.TB, ctx sdk.Context, keepers TestKeepers, wasmCode []byte) ExampleContract { +func StoreExampleContractWasm(tb testing.TB, ctx sdk.Context, keepers TestKeepers, wasmCode []byte) ExampleContract { + tb.Helper() + anyAmount := sdk.NewCoins(sdk.NewInt64Coin("denom", 1000)) creator, creatorAddr := keyPubAddr() - fundAccounts(t, ctx, keepers.AccountKeeper, keepers.BankKeeper, creatorAddr, anyAmount) + fundAccounts(tb, ctx, keepers.AccountKeeper, keepers.BankKeeper, creatorAddr, anyAmount) codeID, _, err := keepers.ContractKeeper.Create(ctx, creatorAddr, wasmCode, nil) - require.NoError(t, err) + require.NoError(tb, err) hash := keepers.WasmKeeper.GetCodeInfo(ctx, codeID).CodeHash return ExampleContract{anyAmount, creator, creatorAddr, codeID, hash} } @@ -639,11 +662,11 @@ type ExampleContractInstance struct { } // SeedNewContractInstance sets the mock wasmerEngine in keeper and calls store + instantiate to init the contract's metadata -func SeedNewContractInstance(t testing.TB, ctx sdk.Context, keepers TestKeepers, mock types.WasmerEngine) ExampleContractInstance { - t.Helper() - exampleContract := StoreRandomContract(t, ctx, keepers, mock) +func SeedNewContractInstance(tb testing.TB, ctx sdk.Context, keepers TestKeepers, mock types.WasmerEngine) ExampleContractInstance { + tb.Helper() + exampleContract := StoreRandomContract(tb, ctx, keepers, mock) contractAddr, _, err := keepers.ContractKeeper.Instantiate(ctx, exampleContract.CodeID, exampleContract.CreatorAddr, exampleContract.CreatorAddr, []byte(`{}`), "", nil) - require.NoError(t, err) + require.NoError(tb, err) return ExampleContractInstance{ ExampleContract: exampleContract, Contract: contractAddr, @@ -651,24 +674,26 @@ func SeedNewContractInstance(t testing.TB, ctx sdk.Context, keepers TestKeepers, } // StoreRandomContract sets the mock wasmerEngine in keeper and calls store -func StoreRandomContract(t testing.TB, ctx sdk.Context, keepers TestKeepers, mock types.WasmerEngine) ExampleContract { - return StoreRandomContractWithAccessConfig(t, ctx, keepers, mock, nil) +func StoreRandomContract(tb testing.TB, ctx sdk.Context, keepers TestKeepers, mock types.WasmerEngine) ExampleContract { + tb.Helper() + + return StoreRandomContractWithAccessConfig(tb, ctx, keepers, mock, nil) } func StoreRandomContractWithAccessConfig( - t testing.TB, ctx sdk.Context, + tb testing.TB, ctx sdk.Context, keepers TestKeepers, mock types.WasmerEngine, cfg *types.AccessConfig, ) ExampleContract { - t.Helper() + tb.Helper() anyAmount := sdk.NewCoins(sdk.NewInt64Coin("denom", 1000)) creator, creatorAddr := keyPubAddr() - fundAccounts(t, ctx, keepers.AccountKeeper, keepers.BankKeeper, creatorAddr, anyAmount) + fundAccounts(tb, ctx, keepers.AccountKeeper, keepers.BankKeeper, creatorAddr, anyAmount) keepers.WasmKeeper.wasmVM = mock - wasmCode := append(wasmIdent, rand.Bytes(10)...) //nolint:gocritic + wasmCode := append(wasmIdent, rand.Bytes(10)...) codeID, checksum, err := keepers.ContractKeeper.Create(ctx, creatorAddr, wasmCode, cfg) - require.NoError(t, err) + require.NoError(tb, err) exampleContract := ExampleContract{InitialAmount: anyAmount, Creator: creator, CreatorAddr: creatorAddr, CodeID: codeID, Checksum: checksum} return exampleContract } @@ -685,23 +710,25 @@ type HackatomExampleInstance struct { } // InstantiateHackatomExampleContract load and instantiate the "./testdata/hackatom.wasm" contract -func InstantiateHackatomExampleContract(t testing.TB, ctx sdk.Context, keepers TestKeepers) HackatomExampleInstance { - contract := StoreHackatomExampleContract(t, ctx, keepers) +func InstantiateHackatomExampleContract(tb testing.TB, ctx sdk.Context, keepers TestKeepers) HackatomExampleInstance { + tb.Helper() + + contract := StoreHackatomExampleContract(tb, ctx, keepers) verifier, verifierAddr := keyPubAddr() - fundAccounts(t, ctx, keepers.AccountKeeper, keepers.BankKeeper, verifierAddr, contract.InitialAmount) + fundAccounts(tb, ctx, keepers.AccountKeeper, keepers.BankKeeper, verifierAddr, contract.InitialAmount) beneficiary, beneficiaryAddr := keyPubAddr() initMsgBz := HackatomExampleInitMsg{ Verifier: verifierAddr, Beneficiary: beneficiaryAddr, - }.GetBytes(t) + }.GetBytes(tb) initialAmount := sdk.NewCoins(sdk.NewInt64Coin("denom", 100)) adminAddr := contract.CreatorAddr label := "demo contract to query" contractAddr, _, err := keepers.ContractKeeper.Instantiate(ctx, contract.CodeID, contract.CreatorAddr, adminAddr, initMsgBz, label, initialAmount) - require.NoError(t, err) + require.NoError(tb, err) return HackatomExampleInstance{ ExampleContract: contract, Contract: contractAddr, @@ -722,13 +749,15 @@ type ExampleInstance struct { } // InstantiateReflectExampleContract load and instantiate the "./testdata/reflect.wasm" contract -func InstantiateReflectExampleContract(t testing.TB, ctx sdk.Context, keepers TestKeepers) ExampleInstance { - example := StoreReflectContract(t, ctx, keepers) +func InstantiateReflectExampleContract(tb testing.TB, ctx sdk.Context, keepers TestKeepers) ExampleInstance { + tb.Helper() + + example := StoreReflectContract(tb, ctx, keepers) initialAmount := sdk.NewCoins(sdk.NewInt64Coin("denom", 100)) label := "demo contract to query" contractAddr, _, err := keepers.ContractKeeper.Instantiate(ctx, example.CodeID, example.CreatorAddr, example.CreatorAddr, []byte("{}"), label, initialAmount) - require.NoError(t, err) + require.NoError(tb, err) return ExampleInstance{ ExampleContract: example, Contract: contractAddr, @@ -742,9 +771,11 @@ type HackatomExampleInitMsg struct { Beneficiary sdk.AccAddress `json:"beneficiary"` } -func (m HackatomExampleInitMsg) GetBytes(t testing.TB) []byte { +func (m HackatomExampleInitMsg) GetBytes(tb testing.TB) []byte { + tb.Helper() + initMsgBz, err := json.Marshal(m) - require.NoError(t, err) + require.NoError(tb, err) return initMsgBz } @@ -756,17 +787,19 @@ type IBCReflectExampleInstance struct { } // InstantiateIBCReflectContract load and instantiate the "./testdata/ibc_reflect.wasm" contract -func InstantiateIBCReflectContract(t testing.TB, ctx sdk.Context, keepers TestKeepers) IBCReflectExampleInstance { - reflectID := StoreReflectContract(t, ctx, keepers).CodeID - ibcReflectID := StoreIBCReflectContract(t, ctx, keepers).CodeID +func InstantiateIBCReflectContract(tb testing.TB, ctx sdk.Context, keepers TestKeepers) IBCReflectExampleInstance { + tb.Helper() + + reflectID := StoreReflectContract(tb, ctx, keepers).CodeID + ibcReflectID := StoreIBCReflectContract(tb, ctx, keepers).CodeID initMsgBz := IBCReflectInitMsg{ ReflectCodeID: reflectID, - }.GetBytes(t) - adminAddr := RandomAccountAddress(t) + }.GetBytes(tb) + adminAddr := RandomAccountAddress(tb) contractAddr, _, err := keepers.ContractKeeper.Instantiate(ctx, ibcReflectID, adminAddr, adminAddr, initMsgBz, "ibc-reflect-factory", nil) - require.NoError(t, err) + require.NoError(tb, err) return IBCReflectExampleInstance{ Admin: adminAddr, Contract: contractAddr, @@ -779,9 +812,11 @@ type IBCReflectInitMsg struct { ReflectCodeID uint64 `json:"reflect_code_id"` } -func (m IBCReflectInitMsg) GetBytes(t testing.TB) []byte { +func (m IBCReflectInitMsg) GetBytes(tb testing.TB) []byte { + tb.Helper() + initMsgBz, err := json.Marshal(m) - require.NoError(t, err) + require.NoError(tb, err) return initMsgBz } @@ -789,16 +824,18 @@ type BurnerExampleInitMsg struct { Payout sdk.AccAddress `json:"payout"` } -func (m BurnerExampleInitMsg) GetBytes(t testing.TB) []byte { +func (m BurnerExampleInitMsg) GetBytes(tb testing.TB) []byte { + tb.Helper() initMsgBz, err := json.Marshal(m) - require.NoError(t, err) + require.NoError(tb, err) return initMsgBz } -func fundAccounts(t testing.TB, ctx sdk.Context, am authkeeper.AccountKeeper, bank bankkeeper.Keeper, addr sdk.AccAddress, coins sdk.Coins) { +func fundAccounts(tb testing.TB, ctx sdk.Context, am authkeeper.AccountKeeper, bank bankkeeper.Keeper, addr sdk.AccAddress, coins sdk.Coins) { + tb.Helper() acc := am.NewAccountWithAddress(ctx, addr) am.SetAccount(ctx, acc) - NewTestFaucet(t, ctx, bank, minttypes.ModuleName, coins...).Fund(ctx, addr, coins...) + NewTestFaucet(tb, ctx, bank, minttypes.ModuleName, coins...).Fund(ctx, addr, coins...) } var keyCounter uint64 diff --git a/x/wasm/keeper/test_fuzz.go b/x/wasm/keeper/test_fuzz.go index 2b15a26b..7bd3e9bb 100644 --- a/x/wasm/keeper/test_fuzz.go +++ b/x/wasm/keeper/test_fuzz.go @@ -4,9 +4,10 @@ import ( "encoding/json" tmBytes "github.com/cometbft/cometbft/libs/bytes" - sdk "github.com/cosmos/cosmos-sdk/types" fuzz "github.com/google/gofuzz" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/keeper/wasmtesting/extension_mocks.go b/x/wasm/keeper/wasmtesting/extension_mocks.go index 562d9e74..3ab14c9a 100644 --- a/x/wasm/keeper/wasmtesting/extension_mocks.go +++ b/x/wasm/keeper/wasmtesting/extension_mocks.go @@ -6,10 +6,10 @@ import ( ) type MockCoinTransferrer struct { - TransferCoinsFn func(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error + TransferCoinsFn func(ctx sdk.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error } -func (m *MockCoinTransferrer) TransferCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error { +func (m *MockCoinTransferrer) TransferCoins(ctx sdk.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error { if m.TransferCoinsFn == nil { panic("not expected to be called") } diff --git a/x/wasm/keeper/wasmtesting/gas_register.go b/x/wasm/keeper/wasmtesting/gas_register.go index 516cd5fb..d0f718af 100644 --- a/x/wasm/keeper/wasmtesting/gas_register.go +++ b/x/wasm/keeper/wasmtesting/gas_register.go @@ -2,6 +2,7 @@ package wasmtesting import ( wasmvmtypes "github.com/CosmWasm/wasmvm/types" + sdk "github.com/cosmos/cosmos-sdk/types" ) diff --git a/x/wasm/keeper/wasmtesting/messenger.go b/x/wasm/keeper/wasmtesting/messenger.go index dbafda38..8f613cf6 100644 --- a/x/wasm/keeper/wasmtesting/messenger.go +++ b/x/wasm/keeper/wasmtesting/messenger.go @@ -4,6 +4,7 @@ import ( "errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" + sdk "github.com/cosmos/cosmos-sdk/types" ) diff --git a/x/wasm/keeper/wasmtesting/mock_engine.go b/x/wasm/keeper/wasmtesting/mock_engine.go index af10d40b..4036d6e0 100644 --- a/x/wasm/keeper/wasmtesting/mock_engine.go +++ b/x/wasm/keeper/wasmtesting/mock_engine.go @@ -3,12 +3,12 @@ package wasmtesting import ( "bytes" - errorsmod "cosmossdk.io/errors" - wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/cometbft/cometbft/libs/rand" + errorsmod "cosmossdk.io/errors" + "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -211,7 +211,7 @@ func SelfCallingInstMockWasmer(executeCalled *bool) *MockWasmer { } // IBCContractCallbacks defines the methods from wasmvm to interact with the wasm contract. -// A mock contract would implement the interface to fully simulate a wasm contract's behaviour. +// A mock contract would implement the interface to fully simulate a wasm contract's behavior. type IBCContractCallbacks interface { IBCChannelOpen( codeID wasmvm.Checksum, diff --git a/x/wasm/keeper/wasmtesting/mock_keepers.go b/x/wasm/keeper/wasmtesting/mock_keepers.go index b5e68869..f4058697 100644 --- a/x/wasm/keeper/wasmtesting/mock_keepers.go +++ b/x/wasm/keeper/wasmtesting/mock_keepers.go @@ -1,11 +1,12 @@ package wasmtesting import ( - sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + sdk "github.com/cosmos/cosmos-sdk/types" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -61,10 +62,10 @@ func (m *MockChannelKeeper) SetChannel(ctx sdk.Context, portID, channelID string } type MockIBCPacketSender struct { - SendPacketFn func(ctx sdk.Context, channelCap *capabilitytypes.Capability, sourcePort string, sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) (uint64, error) + SendPacketFn func(ctx sdk.Context, channelCap *capabilitytypes.Capability, sourcePort, sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) (uint64, error) } -func (m *MockIBCPacketSender) SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, sourcePort string, sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) (uint64, error) { +func (m *MockIBCPacketSender) SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, sourcePort, sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) (uint64, error) { if m.SendPacketFn == nil { panic("not supposed to be called!") } diff --git a/x/wasm/keeper/wasmtesting/msg_dispatcher.go b/x/wasm/keeper/wasmtesting/msg_dispatcher.go index a6600941..4d016f47 100644 --- a/x/wasm/keeper/wasmtesting/msg_dispatcher.go +++ b/x/wasm/keeper/wasmtesting/msg_dispatcher.go @@ -2,6 +2,7 @@ package wasmtesting import ( wasmvmtypes "github.com/CosmWasm/wasmvm/types" + sdk "github.com/cosmos/cosmos-sdk/types" ) diff --git a/x/wasm/keeper/wasmtesting/query_handler.go b/x/wasm/keeper/wasmtesting/query_handler.go index 52cf97d3..e70495b5 100644 --- a/x/wasm/keeper/wasmtesting/query_handler.go +++ b/x/wasm/keeper/wasmtesting/query_handler.go @@ -2,6 +2,7 @@ package wasmtesting import ( wasmvmtypes "github.com/CosmWasm/wasmvm/types" + sdk "github.com/cosmos/cosmos-sdk/types" ) diff --git a/x/wasm/migrations/v1/store_test.go b/x/wasm/migrations/v1/store_test.go index 857d0810..7afec80b 100644 --- a/x/wasm/migrations/v1/store_test.go +++ b/x/wasm/migrations/v1/store_test.go @@ -5,12 +5,12 @@ import ( "encoding/json" "testing" - "github.com/CosmWasm/wasmd/x/wasm/keeper" + "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" - "github.com/stretchr/testify/require" + "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/migrations/v3/store_test.go b/x/wasm/migrations/v3/store_test.go index 17fe5b24..81598838 100644 --- a/x/wasm/migrations/v3/store_test.go +++ b/x/wasm/migrations/v3/store_test.go @@ -4,17 +4,17 @@ import ( "bytes" "testing" - "github.com/CosmWasm/wasmd/x/wasm" - "github.com/CosmWasm/wasmd/x/wasm/keeper" - "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" - v3 "github.com/CosmWasm/wasmd/x/wasm/migrations/v3" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/CosmWasm/wasmd/x/wasm" + "github.com/CosmWasm/wasmd/x/wasm/keeper" + "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" + v3 "github.com/CosmWasm/wasmd/x/wasm/migrations/v3" "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/module.go b/x/wasm/module.go index 79b331b7..5caf74e5 100644 --- a/x/wasm/module.go +++ b/x/wasm/module.go @@ -7,12 +7,15 @@ import ( "runtime/debug" "strings" + wasmvm "github.com/CosmWasm/wasmvm" + abci "github.com/cometbft/cometbft/abci/types" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cast" + "github.com/spf13/cobra" + "cosmossdk.io/core/appmodule" "github.com/cosmos/cosmos-sdk/baseapp" - - wasmvm "github.com/CosmWasm/wasmvm" - abci "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -21,9 +24,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cast" - "github.com/spf13/cobra" "github.com/CosmWasm/wasmd/x/wasm/client/cli" "github.com/CosmWasm/wasmd/x/wasm/exported" @@ -42,7 +42,7 @@ const ( flagWasmMemoryCacheSize = "wasm.memory_cache_size" flagWasmQueryGasLimit = "wasm.query_gas_limit" flagWasmSimulationGasLimit = "wasm.simulation_gas_limit" - flagWasmSkipWasmVMVersionCheck = "wasm.skip_wasmvm_version_check" //nolint:gosec + flagWasmSkipWasmVMVersionCheck = "wasm.skip_wasmvm_version_check" ) // AppModuleBasic defines the basic application module used by the wasm module. diff --git a/x/wasm/module_test.go b/x/wasm/module_test.go index 10e05507..376aeab8 100644 --- a/x/wasm/module_test.go +++ b/x/wasm/module_test.go @@ -7,21 +7,21 @@ import ( "strings" "testing" - servertypes "github.com/cosmos/cosmos-sdk/server/types" - "github.com/spf13/viper" - abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/crypto/ed25519" + "github.com/spf13/viper" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" + servertypes "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/types/module" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/app/params" "github.com/CosmWasm/wasmd/x/wasm/exported" @@ -56,6 +56,7 @@ type testData struct { } func setupTest(t *testing.T) testData { + t.Helper() ctx, keepers := keeper.CreateTestInput(t, false, "iterator,staking,stargate,cosmwasm_1_1") encConf := keeper.MakeEncodingConfig(t) queryRouter := baseapp.NewGRPCQueryRouter() @@ -546,7 +547,7 @@ func prettyAttr(attr abci.EventAttribute) sdk.Attribute { return sdk.NewAttribute(attr.Key, attr.Value) } -func assertAttribute(t *testing.T, key string, value string, attr abci.EventAttribute) { +func assertAttribute(t *testing.T, key, value string, attr abci.EventAttribute) { t.Helper() assert.Equal(t, key, attr.Key, prettyAttr(attr)) assert.Equal(t, value, attr.Value, prettyAttr(attr)) diff --git a/x/wasm/relay_pingpong_test.go b/x/wasm/relay_pingpong_test.go index 4ae022b1..ea8bd75e 100644 --- a/x/wasm/relay_pingpong_test.go +++ b/x/wasm/relay_pingpong_test.go @@ -5,19 +5,18 @@ import ( "fmt" "testing" - app2 "github.com/CosmWasm/wasmd/app" - - ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" - ibctesting "github.com/cosmos/ibc-go/v7/testing" - wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" - sdk "github.com/cosmos/cosmos-sdk/types" + ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + ibctesting "github.com/cosmos/ibc-go/v7/testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + + app2 "github.com/CosmWasm/wasmd/app" wasmibctesting "github.com/CosmWasm/wasmd/x/wasm/ibctesting" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" diff --git a/x/wasm/relay_test.go b/x/wasm/relay_test.go index 81698f5a..f3dc9b32 100644 --- a/x/wasm/relay_test.go +++ b/x/wasm/relay_test.go @@ -6,13 +6,8 @@ import ( "testing" "time" - "github.com/CosmWasm/wasmd/app" - - errorsmod "cosmossdk.io/errors" - "cosmossdk.io/math" wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" - sdk "github.com/cosmos/cosmos-sdk/types" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -20,6 +15,12 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + errorsmod "cosmossdk.io/errors" + "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/CosmWasm/wasmd/app" wasmibctesting "github.com/CosmWasm/wasmd/x/wasm/ibctesting" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" @@ -45,6 +46,7 @@ func TestFromIBCTransferToContract(t *testing.T) { "ack": { contract: &ackReceiverContract{}, setupContract: func(t *testing.T, contract wasmtesting.IBCContractCallbacks, chain *wasmibctesting.TestChain) { + t.Helper() c := contract.(*ackReceiverContract) c.t = t c.chain = chain @@ -57,6 +59,7 @@ func TestFromIBCTransferToContract(t *testing.T) { "nack": { contract: &nackReceiverContract{}, setupContract: func(t *testing.T, contract wasmtesting.IBCContractCallbacks, chain *wasmibctesting.TestChain) { + t.Helper() c := contract.(*nackReceiverContract) c.t = t }, @@ -68,6 +71,7 @@ func TestFromIBCTransferToContract(t *testing.T) { "error": { contract: &errorReceiverContract{}, setupContract: func(t *testing.T, contract wasmtesting.IBCContractCallbacks, chain *wasmibctesting.TestChain) { + t.Helper() c := contract.(*errorReceiverContract) c.t = t }, diff --git a/x/wasm/simulation/operations.go b/x/wasm/simulation/operations.go index ea5860b3..6e937bad 100644 --- a/x/wasm/simulation/operations.go +++ b/x/wasm/simulation/operations.go @@ -5,9 +5,10 @@ import ( "math/rand" "os" + wasmvmtypes "github.com/CosmWasm/wasmvm/types" + errorsmod "cosmossdk.io/errors" - wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -25,7 +26,7 @@ import ( // Simulation operation weights constants // -//nolint:gosec + const ( OpWeightMsgStoreCode = "op_weight_msg_store_code" OpWeightMsgInstantiateContract = "op_weight_msg_instantiate_contract" diff --git a/x/wasm/types/authz.go b/x/wasm/types/authz.go index 96920887..1d06d7aa 100644 --- a/x/wasm/types/authz.go +++ b/x/wasm/types/authz.go @@ -3,12 +3,14 @@ package types import ( "strings" + "github.com/cosmos/gogoproto/proto" + errorsmod "cosmossdk.io/errors" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authztypes "github.com/cosmos/cosmos-sdk/x/authz" - "github.com/cosmos/gogoproto/proto" ) const gasDeserializationCostPerByte = uint64(1) @@ -166,8 +168,8 @@ func AcceptGrantedMessage[T AuthzableWasmMsg](ctx sdk.Context, grants []Contract // finally do limit state updates in result switch { case result.DeleteLimit: - updatedGrants := append(grants[0:i], grants[i+1:]...) //nolint:gocritic - if len(updatedGrants) == 0 { // remove when empty + updatedGrants := append(grants[0:i], grants[i+1:]...) + if len(updatedGrants) == 0 { // remove when empty return authztypes.AcceptResponse{Accept: true, Delete: true}, nil } newAuthz := factory.NewAuthz(updatedGrants) diff --git a/x/wasm/types/authz_policy.go b/x/wasm/types/authz_policy.go index 8e812f2b..335f315d 100644 --- a/x/wasm/types/authz_policy.go +++ b/x/wasm/types/authz_policy.go @@ -11,7 +11,7 @@ type ChainAccessConfigs struct { } // NewChainAccessConfigs constructor -func NewChainAccessConfigs(upload AccessConfig, instantiate AccessConfig) ChainAccessConfigs { +func NewChainAccessConfigs(upload, instantiate AccessConfig) ChainAccessConfigs { return ChainAccessConfigs{Upload: upload, Instantiate: instantiate} } diff --git a/x/wasm/types/authz_test.go b/x/wasm/types/authz_test.go index 79d279b2..b02abea9 100644 --- a/x/wasm/types/authz_test.go +++ b/x/wasm/types/authz_test.go @@ -4,13 +4,14 @@ import ( "math" "testing" - errorsmod "cosmossdk.io/errors" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - authztypes "github.com/cosmos/cosmos-sdk/x/authz" - - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + authztypes "github.com/cosmos/cosmos-sdk/x/authz" ) func TestContractAuthzFilterValidate(t *testing.T) { @@ -396,17 +397,20 @@ func TestValidateContractGrant(t *testing.T) { }{ "all good": { setup: func(t *testing.T) ContractGrant { + t.Helper() return mustGrant(randBytes(ContractAddrLen), NewMaxCallsLimit(1), NewAllowAllMessagesFilter()) }, }, "invalid address": { setup: func(t *testing.T) ContractGrant { + t.Helper() return mustGrant([]byte{}, NewMaxCallsLimit(1), NewAllowAllMessagesFilter()) }, expErr: true, }, "invalid limit": { setup: func(t *testing.T) ContractGrant { + t.Helper() return mustGrant(randBytes(ContractAddrLen), NewMaxCallsLimit(0), NewAllowAllMessagesFilter()) }, expErr: true, @@ -414,12 +418,14 @@ func TestValidateContractGrant(t *testing.T) { "invalid filter ": { setup: func(t *testing.T) ContractGrant { + t.Helper() return mustGrant(randBytes(ContractAddrLen), NewMaxCallsLimit(1), NewAcceptedMessageKeysFilter()) }, expErr: true, }, "empty limit": { setup: func(t *testing.T) ContractGrant { + t.Helper() r := mustGrant(randBytes(ContractAddrLen), NewMaxCallsLimit(0), NewAllowAllMessagesFilter()) r.Limit = nil return r @@ -429,6 +435,7 @@ func TestValidateContractGrant(t *testing.T) { "empty filter ": { setup: func(t *testing.T) ContractGrant { + t.Helper() r := mustGrant(randBytes(ContractAddrLen), NewMaxCallsLimit(1), NewAcceptedMessageKeysFilter()) r.Filter = nil return r @@ -437,6 +444,7 @@ func TestValidateContractGrant(t *testing.T) { }, "wrong limit type": { setup: func(t *testing.T) ContractGrant { + t.Helper() r := mustGrant(randBytes(ContractAddrLen), NewMaxCallsLimit(0), NewAllowAllMessagesFilter()) r.Limit = r.Filter return r @@ -446,6 +454,7 @@ func TestValidateContractGrant(t *testing.T) { "wrong filter type": { setup: func(t *testing.T) ContractGrant { + t.Helper() r := mustGrant(randBytes(ContractAddrLen), NewMaxCallsLimit(1), NewAcceptedMessageKeysFilter()) r.Filter = r.Limit return r @@ -478,44 +487,52 @@ func TestValidateContractAuthorization(t *testing.T) { }{ "contract execution": { setup: func(t *testing.T) validatable { + t.Helper() return NewContractMigrationAuthorization(*validGrant) }, }, "contract execution - duplicate grants": { setup: func(t *testing.T) validatable { + t.Helper() return NewContractMigrationAuthorization(*validGrant, *validGrant) }, }, "contract execution - invalid grant": { setup: func(t *testing.T) validatable { + t.Helper() return NewContractMigrationAuthorization(*validGrant, *invalidGrant) }, expErr: true, }, "contract execution - empty grants": { setup: func(t *testing.T) validatable { + t.Helper() return NewContractMigrationAuthorization() }, expErr: true, }, "contract migration": { setup: func(t *testing.T) validatable { + t.Helper() return NewContractMigrationAuthorization(*validGrant) }, }, "contract migration - duplicate grants": { setup: func(t *testing.T) validatable { + t.Helper() return NewContractMigrationAuthorization(*validGrant, *validGrant) }, }, "contract migration - invalid grant": { setup: func(t *testing.T) validatable { + t.Helper() return NewContractMigrationAuthorization(*validGrant, *invalidGrant) }, expErr: true, }, "contract migration - empty grant": { setup: func(t *testing.T) validatable { + t.Helper() return NewContractMigrationAuthorization() }, expErr: true, diff --git a/x/wasm/types/errors.go b/x/wasm/types/errors.go index 378c25d6..58aa5caf 100644 --- a/x/wasm/types/errors.go +++ b/x/wasm/types/errors.go @@ -1,8 +1,9 @@ package types import ( - errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" + + errorsmod "cosmossdk.io/errors" ) // Codes for wasm contract errors diff --git a/x/wasm/types/errors_test.go b/x/wasm/types/errors_test.go index 495f5e82..5e1034f6 100644 --- a/x/wasm/types/errors_test.go +++ b/x/wasm/types/errors_test.go @@ -4,10 +4,11 @@ import ( "errors" "testing" - errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + errorsmod "cosmossdk.io/errors" ) func TestWasmVMFlavouredError(t *testing.T) { @@ -17,22 +18,26 @@ func TestWasmVMFlavouredError(t *testing.T) { }{ "IsOf": { exec: func(t *testing.T) { + t.Helper() assert.True(t, errorsmod.IsOf(myErr, myErr.sdkErr)) assert.Equal(t, myErr.sdkErr, myErr.Unwrap()) }, }, "unwrapped": { exec: func(t *testing.T) { + t.Helper() assert.Equal(t, myErr.sdkErr, myErr.Unwrap()) }, }, "caused": { exec: func(t *testing.T) { + t.Helper() assert.Equal(t, myErr.sdkErr, myErr.Cause()) }, }, "wrapped supports WasmVMErrorable": { exec: func(t *testing.T) { + t.Helper() var wasmvmErr WasmVMErrorable require.True(t, errors.As(myErr.Wrap("my description"), &wasmvmErr)) gotErr := wasmvmErr.ToWasmVMError() @@ -41,6 +46,7 @@ func TestWasmVMFlavouredError(t *testing.T) { }, "wrappedf supports WasmVMErrorable": { exec: func(t *testing.T) { + t.Helper() var wasmvmErr WasmVMErrorable require.True(t, errors.As(myErr.Wrapf("my description: %d", 1), &wasmvmErr)) gotErr := wasmvmErr.ToWasmVMError() @@ -49,6 +55,7 @@ func TestWasmVMFlavouredError(t *testing.T) { }, "supports WasmVMErrorable": { exec: func(t *testing.T) { + t.Helper() var wasmvmErr WasmVMErrorable require.True(t, errors.As(myErr, &wasmvmErr)) gotErr := wasmvmErr.ToWasmVMError() @@ -57,6 +64,7 @@ func TestWasmVMFlavouredError(t *testing.T) { }, "fallback to sdk error when wasmvm error unset": { exec: func(t *testing.T) { + t.Helper() var wasmvmErr WasmVMErrorable require.True(t, errors.As(WasmVMFlavouredError{sdkErr: ErrEmpty}, &wasmvmErr)) gotErr := wasmvmErr.ToWasmVMError() @@ -65,6 +73,7 @@ func TestWasmVMFlavouredError(t *testing.T) { }, "abci info": { exec: func(t *testing.T) { + t.Helper() codespace, code, log := errorsmod.ABCIInfo(myErr, false) assert.Equal(t, DefaultCodespace, codespace) assert.Equal(t, uint32(28), code) @@ -73,6 +82,7 @@ func TestWasmVMFlavouredError(t *testing.T) { }, "abci info - wrapped": { exec: func(t *testing.T) { + t.Helper() codespace, code, log := errorsmod.ABCIInfo(myErr.Wrap("my description"), false) assert.Equal(t, DefaultCodespace, codespace) assert.Equal(t, uint32(28), code) diff --git a/x/wasm/types/events.go b/x/wasm/types/events.go index 7034b37b..ea6060bd 100644 --- a/x/wasm/types/events.go +++ b/x/wasm/types/events.go @@ -3,8 +3,9 @@ package types import ( "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" + + sdk "github.com/cosmos/cosmos-sdk/types" ) const ( @@ -28,7 +29,7 @@ const ( // add new types to IsAcceptedEventOnRecvPacketErrorAck ) -// EmitAcknowledgementEvent emits an event signalling a successful or failed acknowledgement and including the error +// EmitAcknowledgementEvent emits an event signaling a successful or failed acknowledgement and including the error // details if any. func EmitAcknowledgementEvent(ctx sdk.Context, contractAddr sdk.AccAddress, ack exported.Acknowledgement, err error) { success := err == nil && (ack == nil || ack.Success()) diff --git a/x/wasm/types/expected_keepers.go b/x/wasm/types/expected_keepers.go index 19e5f50a..36fa6edc 100644 --- a/x/wasm/types/expected_keepers.go +++ b/x/wasm/types/expected_keepers.go @@ -4,6 +4,9 @@ import ( "context" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -11,9 +14,6 @@ import ( capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" - channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" - ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" ) // BankViewKeeper defines a subset of methods implemented by the cosmos-sdk bank keeper @@ -37,7 +37,7 @@ type BankKeeper interface { Burner IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) error BlockedAddr(addr sdk.AccAddress) bool - SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error + SendCoins(ctx sdk.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error } // AccountKeeper defines a subset of methods implemented by the cosmos-sdk account keeper diff --git a/x/wasm/types/exported_keepers.go b/x/wasm/types/exported_keepers.go index 4fa5c6ac..a77d823a 100644 --- a/x/wasm/types/exported_keepers.go +++ b/x/wasm/types/exported_keepers.go @@ -2,9 +2,10 @@ package types import ( wasmvmtypes "github.com/CosmWasm/wasmvm/types" + ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" + sdk "github.com/cosmos/cosmos-sdk/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" - ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" ) // ViewKeeper provides read only operations @@ -53,19 +54,19 @@ type ContractOpsKeeper interface { ) (sdk.AccAddress, []byte, error) // Execute executes the contract instance - Execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) ([]byte, error) + Execute(ctx sdk.Context, contractAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) ([]byte, error) // Migrate allows to upgrade a contract to a new code with data migration. - Migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, newCodeID uint64, msg []byte) ([]byte, error) + Migrate(ctx sdk.Context, contractAddress, caller sdk.AccAddress, newCodeID uint64, msg []byte) ([]byte, error) // Sudo allows to call privileged entry point of a contract. Sudo(ctx sdk.Context, contractAddress sdk.AccAddress, msg []byte) ([]byte, error) // UpdateContractAdmin sets the admin value on the ContractInfo. It must be a valid address (use ClearContractAdmin to remove it) - UpdateContractAdmin(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, newAdmin sdk.AccAddress) error + UpdateContractAdmin(ctx sdk.Context, contractAddress, caller, newAdmin sdk.AccAddress) error // ClearContractAdmin sets the admin value on the ContractInfo to nil, to disable further migrations/ updates. - ClearContractAdmin(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress) error + ClearContractAdmin(ctx sdk.Context, contractAddress, caller sdk.AccAddress) error // PinCode pins the wasm contract in wasmvm cache PinCode(ctx sdk.Context, codeID uint64) error diff --git a/x/wasm/types/genesis.go b/x/wasm/types/genesis.go index 8a5a1569..1a53c4a3 100644 --- a/x/wasm/types/genesis.go +++ b/x/wasm/types/genesis.go @@ -2,6 +2,7 @@ package types import ( errorsmod "cosmossdk.io/errors" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" ) diff --git a/x/wasm/types/genesis_test.go b/x/wasm/types/genesis_test.go index 258528c9..9eaf14f6 100644 --- a/x/wasm/types/genesis_test.go +++ b/x/wasm/types/genesis_test.go @@ -6,12 +6,13 @@ import ( "time" "github.com/cometbft/cometbft/libs/rand" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) const invalidAddress = "invalid address" diff --git a/x/wasm/types/iavl_range_test.go b/x/wasm/types/iavl_range_test.go index fd3297b4..85607dab 100644 --- a/x/wasm/types/iavl_range_test.go +++ b/x/wasm/types/iavl_range_test.go @@ -4,10 +4,11 @@ import ( "testing" dbm "github.com/cometbft/cometbft-db" - "github.com/cosmos/cosmos-sdk/store" - "github.com/cosmos/cosmos-sdk/store/iavl" iavl2 "github.com/cosmos/iavl" "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/store" + "github.com/cosmos/cosmos-sdk/store/iavl" ) // This is modeled close to diff --git a/x/wasm/types/json_matching_test.go b/x/wasm/types/json_matching_test.go index 286fde39..18bb40b0 100644 --- a/x/wasm/types/json_matching_test.go +++ b/x/wasm/types/json_matching_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - // sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/stretchr/testify/require" ) diff --git a/x/wasm/types/keys.go b/x/wasm/types/keys.go index 4f605872..6a2e8a9a 100644 --- a/x/wasm/types/keys.go +++ b/x/wasm/types/keys.go @@ -84,7 +84,7 @@ func GetContractByCodeIDSecondaryIndexPrefix(codeID uint64) []byte { } // GetContractByCreatorSecondaryIndexKey returns the key for the second index: `` -func GetContractByCreatorSecondaryIndexKey(bz []byte, position []byte, contractAddr sdk.AccAddress) []byte { +func GetContractByCreatorSecondaryIndexKey(bz, position []byte, contractAddr sdk.AccAddress) []byte { prefixBytes := GetContractsByCreatorPrefix(bz) lenPrefixBytes := len(prefixBytes) r := make([]byte, lenPrefixBytes+AbsoluteTxPositionLen+len(contractAddr)) diff --git a/x/wasm/types/params.go b/x/wasm/types/params.go index c653142a..9793ee68 100644 --- a/x/wasm/types/params.go +++ b/x/wasm/types/params.go @@ -4,11 +4,13 @@ import ( "encoding/json" "fmt" - errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/gogoproto/jsonpb" "github.com/pkg/errors" "gopkg.in/yaml.v2" + + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" ) var AllAccessTypes = []AccessType{ diff --git a/x/wasm/types/params_test.go b/x/wasm/types/params_test.go index 7534e5d6..2a275000 100644 --- a/x/wasm/types/params_test.go +++ b/x/wasm/types/params_test.go @@ -5,11 +5,12 @@ import ( "encoding/json" "testing" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestValidateParams(t *testing.T) { diff --git a/x/wasm/types/proposal.go b/x/wasm/types/proposal.go index 468f45b1..9c85a08d 100644 --- a/x/wasm/types/proposal.go +++ b/x/wasm/types/proposal.go @@ -7,6 +7,7 @@ import ( "strings" errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" diff --git a/x/wasm/types/proposal_test.go b/x/wasm/types/proposal_test.go index a139d478..5268adaa 100644 --- a/x/wasm/types/proposal_test.go +++ b/x/wasm/types/proposal_test.go @@ -6,11 +6,12 @@ import ( "strings" "testing" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) func TestValidateProposalCommons(t *testing.T) { diff --git a/x/wasm/types/test_fixtures.go b/x/wasm/types/test_fixtures.go index 715cfb95..7f021813 100644 --- a/x/wasm/types/test_fixtures.go +++ b/x/wasm/types/test_fixtures.go @@ -8,6 +8,7 @@ import ( "math/rand" wasmvm "github.com/CosmWasm/wasmvm" + sdk "github.com/cosmos/cosmos-sdk/types" ) diff --git a/x/wasm/types/tx.go b/x/wasm/types/tx.go index ba8acce1..99fe2c62 100644 --- a/x/wasm/types/tx.go +++ b/x/wasm/types/tx.go @@ -7,6 +7,7 @@ import ( "strings" errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) diff --git a/x/wasm/types/tx_test.go b/x/wasm/types/tx_test.go index 67395109..9bd8858c 100644 --- a/x/wasm/types/tx_test.go +++ b/x/wasm/types/tx_test.go @@ -5,10 +5,11 @@ import ( "strings" "testing" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) const ( diff --git a/x/wasm/types/types.go b/x/wasm/types/types.go index 04300ff6..fdf390cf 100644 --- a/x/wasm/types/types.go +++ b/x/wasm/types/types.go @@ -4,12 +4,14 @@ import ( "fmt" "reflect" - errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" + "github.com/cosmos/gogoproto/proto" + + errorsmod "cosmossdk.io/errors" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/gogoproto/proto" ) const ( diff --git a/x/wasm/types/types_test.go b/x/wasm/types/types_test.go index 45fd5df7..0734937e 100644 --- a/x/wasm/types/types_test.go +++ b/x/wasm/types/types_test.go @@ -9,12 +9,13 @@ import ( wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/cometbft/cometbft/libs/rand" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestContractInfoValidateBasic(t *testing.T) { diff --git a/x/wasm/types/validation.go b/x/wasm/types/validation.go index b954c4f8..7282c01e 100644 --- a/x/wasm/types/validation.go +++ b/x/wasm/types/validation.go @@ -5,8 +5,9 @@ import ( "net/url" "strings" - errorsmod "cosmossdk.io/errors" "github.com/docker/distribution/reference" + + errorsmod "cosmossdk.io/errors" ) // MaxSaltSize is the longest salt that can be used when instantiating a contract diff --git a/x/wasm/types/wasmer_engine.go b/x/wasm/types/wasmer_engine.go index 18d4060a..f72ae201 100644 --- a/x/wasm/types/wasmer_engine.go +++ b/x/wasm/types/wasmer_engine.go @@ -3,6 +3,7 @@ package types import ( wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" + sdk "github.com/cosmos/cosmos-sdk/types" )