diff --git a/.golangci.yml b/.golangci.yml index 54497acc41..21c604ffcc 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,5 +1,7 @@ run: - tests: false + tests: true + # timeout for analysis, e.g. 30s, 5m, default is 1m + timeout: 5m linters: disable-all: true @@ -8,53 +10,57 @@ linters: - depguard - dogsled - errcheck + - exportloopref - goconst - gocritic - - gofmt - - goimports - - revive + - gofumpt - gosec - gosimple - govet - ineffassign - misspell - nakedret - - prealloc - - exportloopref + - nolintlint + - revive - staticcheck - stylecheck - typecheck - unconvert + - unparam - unused issues: exclude-rules: + - text: "simtypes" + linters: + - staticcheck - text: "Use of weak random number generator" linters: - gosec - text: "ST1003:" linters: - stylecheck + # FIXME: Disabled until golangci-lint updates stylecheck with this fix: + # https://github.com/dominikh/go-tools/issues/389 + - text: "ST1016:" + linters: + - stylecheck + - path: "migrations" + text: "SA1019:" + linters: + - staticcheck + + max-issues-per-linter: 10000 + max-same-issues: 10000 linters-settings: dogsled: max-blank-identifiers: 3 - errcheck: - # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`; - # default is false: such cases aren't reported by default. - check-blank: true maligned: # print struct with more effective memory layout or not, false by default suggest-new: true - golint: - # minimal confidence for issues, default is 0.8 - min-confidence: 0 - prealloc: - # XXX: we don't recommend using this linter before doing performance profiling. - # For most programs usage of prealloc will be a premature optimization. - - # Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them. - # True by default. - simple: false - range-loops: true # Report preallocation suggestions on range loops, true by default - for-loops: true # Report preallocation suggestions on for loops, false by default + nolintlint: + allow-unused: false + allow-leading-space: true + require-explanation: false + require-specific: false diff --git a/app/app.go b/app/app.go index a519f3afd8..55a4d0af73 100644 --- a/app/app.go +++ b/app/app.go @@ -247,7 +247,7 @@ var ( // WasmApp extended ABCI application type WasmApp struct { *baseapp.BaseApp - legacyAmino *codec.LegacyAmino //nolint:staticcheck + legacyAmino *codec.LegacyAmino appCodec codec.Codec txConfig client.TxConfig interfaceRegistry types.InterfaceRegistry @@ -911,7 +911,7 @@ func (app *WasmApp) LoadHeight(height int64) error { // // NOTE: This is solely to be used for testing purposes as it may be desirable // for modules to register their own custom testing types. -func (app *WasmApp) LegacyAmino() *codec.LegacyAmino { //nolint:staticcheck +func (app *WasmApp) LegacyAmino() *codec.LegacyAmino { return app.legacyAmino } diff --git a/app/app_test.go b/app/app_test.go index b24de3c59f..dbcae4ee34 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -1,12 +1,10 @@ package app import ( - "encoding/json" "os" "testing" dbm "github.com/cometbft/cometbft-db" - abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/log" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" @@ -16,7 +14,7 @@ import ( "github.com/CosmWasm/wasmd/x/wasm" ) -var emptyWasmOpts []wasm.Option = nil +var emptyWasmOpts []wasm.Option func TestWasmdExport(t *testing.T) { db := dbm.NewMemDB() @@ -85,22 +83,3 @@ func TestGetEnabledProposals(t *testing.T) { }) } } - -func setGenesis(gapp *WasmApp) error { - genesisState := NewDefaultGenesisState(gapp.appCodec) - stateBytes, err := json.MarshalIndent(genesisState, "", " ") - if err != nil { - return err - } - - // Initialize the chain - gapp.InitChain( - abci.RequestInitChain{ - Validators: []abci.ValidatorUpdate{}, - AppStateBytes: stateBytes, - }, - ) - - gapp.Commit() - return nil -} diff --git a/app/export.go b/app/export.go index db77b8476e..74c69db60c 100644 --- a/app/export.go +++ b/app/export.go @@ -72,7 +72,7 @@ func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [ // withdraw all validator commission app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { - _, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator()) //nolint:errcheck + _, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator()) return false }) diff --git a/app/upgrades.go b/app/upgrades.go index d84a4c0447..01aa076a44 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -44,7 +44,7 @@ func (app WasmApp) RegisterUpgradeHandlers() { case banktypes.ModuleName: keyTable = banktypes.ParamKeyTable() //nolint:staticcheck case stakingtypes.ModuleName: - keyTable = stakingtypes.ParamKeyTable() //nolint:staticcheck + keyTable = stakingtypes.ParamKeyTable() case minttypes.ModuleName: keyTable = minttypes.ParamKeyTable() //nolint:staticcheck case distrtypes.ModuleName: @@ -57,11 +57,11 @@ func (app WasmApp) RegisterUpgradeHandlers() { keyTable = crisistypes.ParamKeyTable() //nolint:staticcheck // ibc types case ibctransfertypes.ModuleName: - keyTable = ibctransfertypes.ParamKeyTable() //nolint:staticcheck + keyTable = ibctransfertypes.ParamKeyTable() case icahosttypes.SubModuleName: - keyTable = icahosttypes.ParamKeyTable() //nolint:staticcheck + keyTable = icahosttypes.ParamKeyTable() case icacontrollertypes.SubModuleName: - keyTable = icacontrollertypes.ParamKeyTable() //nolint:staticcheck + keyTable = icacontrollertypes.ParamKeyTable() // wasm case wasmtypes.ModuleName: keyTable = wasmtypes.ParamKeyTable() //nolint:staticcheck diff --git a/benchmarks/app_test.go b/benchmarks/app_test.go index 6fa22f4fc4..df0ee91327 100644 --- a/benchmarks/app_test.go +++ b/benchmarks/app_test.go @@ -34,7 +34,7 @@ import ( cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" ) -func setup(db dbm.DB, withGenesis bool, invCheckPeriod uint, opts ...wasm.Option) (*app.WasmApp, app.GenesisState) { +func setup(db dbm.DB, withGenesis bool, invCheckPeriod uint, opts ...wasm.Option) (*app.WasmApp, app.GenesisState) { //nolint:unparam wasmApp := app.NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, wasm.EnableAllProposals, simtestutil.EmptyAppOptions{}, nil) if withGenesis { @@ -182,7 +182,7 @@ func InitializeWasmApp(b testing.TB, db dbm.DB, numAccounts int) AppInfo { 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) - _, res, err := wasmApp.SimDeliver(txGen.TxEncoder(), storeTx) + _, _, err = wasmApp.SimDeliver(txGen.TxEncoder(), storeTx) require.NoError(b, err) codeID := uint64(1) @@ -216,13 +216,13 @@ 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) - _, res, err = wasmApp.SimDeliver(txGen.TxEncoder(), initTx) + _, res, err := wasmApp.SimDeliver(txGen.TxEncoder(), initTx) require.NoError(b, err) // TODO: parse contract address better evt := res.Events[len(res.Events)-1] attr := evt.Attributes[0] - contractAddr := string(attr.Value) + contractAddr := attr.Value wasmApp.EndBlock(abci.RequestEndBlock{Height: height}) wasmApp.Commit() @@ -259,7 +259,7 @@ func GenSequenceOfTxs(b testing.TB, info *AppInfo, msgGen func(*AppInfo) ([]sdk. info.MinterKey, ) require.NoError(b, err) - info.SeqNum += 1 + info.SeqNum++ } return txs diff --git a/tests/e2e/gov_test.go b/tests/e2e/gov_test.go index 75119447da..5ce967da24 100644 --- a/tests/e2e/gov_test.go +++ b/tests/e2e/gov_test.go @@ -105,7 +105,7 @@ func TestGovVoteByContract(t *testing.T) { // with other delegators voted yes _, err = chain.SendMsgs(v1.NewMsgVote(chain.SenderAccount.GetAddress(), propID, v1.VoteOption_VOTE_OPTION_YES, "")) - require.NoError(t, gotErr) + require.NoError(t, err) // when contract votes spec.vote.ProposalId = propID diff --git a/tests/e2e/grants_test.go b/tests/e2e/grants_test.go index 775cd20692..2a6ed79357 100644 --- a/tests/e2e/grants_test.go +++ b/tests/e2e/grants_test.go @@ -5,6 +5,7 @@ import ( "testing" "time" + 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" @@ -49,7 +50,7 @@ func TestGrants(t *testing.T) { filter types.ContractAuthzFilterX transferAmount sdk.Coin senderKey cryptotypes.PrivKey - expErr *sdkerrors.Error + expErr *errorsmod.Error }{ "in limits and filter": { limit: types.NewMaxFundsLimit(myAmount), diff --git a/tests/e2e/ica_test.go b/tests/e2e/ica_test.go index f3dc2eef37..3ac2fdb88c 100644 --- a/tests/e2e/ica_test.go +++ b/tests/e2e/ica_test.go @@ -79,7 +79,7 @@ func TestICA(t *testing.T) { } relativeTimeout := uint64(time.Minute.Nanoseconds()) // note this is in nanoseconds msgSendTx := icacontrollertypes.NewMsgSendTx(ownerAddr.String(), path.EndpointA.ConnectionID, relativeTimeout, payloadPacket) - res, err = controllerChain.SendMsgs(msgSendTx) + _, err = controllerChain.SendMsgs(msgSendTx) require.NoError(t, err) assert.Equal(t, 1, len(controllerChain.PendingSendPackets)) diff --git a/x/wasm/alias.go b/x/wasm/alias.go index 8af3fc1e06..762e021a4f 100644 --- a/x/wasm/alias.go +++ b/x/wasm/alias.go @@ -1,4 +1,4 @@ -// nolint +//nolint // autogenerated code using github.com/rigelrozanski/multitool // aliases generated for the following subdirectories: // ALIASGEN: github.com/Cosmwasm/wasmd/x/wasm/types diff --git a/x/wasm/client/cli/gov_tx.go b/x/wasm/client/cli/gov_tx.go index 59b2181c84..e2cf4a2b63 100644 --- a/x/wasm/client/cli/gov_tx.go +++ b/x/wasm/client/cli/gov_tx.go @@ -538,7 +538,7 @@ func ProposalUpdateContractAdminCmd() *cobra.Command { return err } - src, err := parseUpdateContractAdminArgs(args, clientCtx) + src := parseUpdateContractAdminArgs(args, clientCtx) if err != nil { return err } diff --git a/x/wasm/client/cli/new_tx.go b/x/wasm/client/cli/new_tx.go index f15319c097..e186ea97de 100644 --- a/x/wasm/client/cli/new_tx.go +++ b/x/wasm/client/cli/new_tx.go @@ -71,7 +71,7 @@ func UpdateContractAdminCmd() *cobra.Command { return err } - msg, err := parseUpdateContractAdminArgs(args, clientCtx) + msg := parseUpdateContractAdminArgs(args, clientCtx) if err != nil { return err } @@ -86,13 +86,13 @@ func UpdateContractAdminCmd() *cobra.Command { return cmd } -func parseUpdateContractAdminArgs(args []string, cliCtx client.Context) (types.MsgUpdateAdmin, error) { +func parseUpdateContractAdminArgs(args []string, cliCtx client.Context) types.MsgUpdateAdmin { msg := types.MsgUpdateAdmin{ Sender: cliCtx.GetFromAddress().String(), Contract: args[0], NewAdmin: args[1], } - return msg, nil + return msg } // ClearContractAdminCmd clears an admin for a contract diff --git a/x/wasm/genesis_test.go b/x/wasm/genesis_test.go index b0adaa559b..45afedaad9 100644 --- a/x/wasm/genesis_test.go +++ b/x/wasm/genesis_test.go @@ -82,7 +82,8 @@ func TestInitGenesis(t *testing.T) { q2 := newData.grpcQueryRouter // initialize new app with genstate - InitGenesis(newData.ctx, &newData.keeper, *genState) + _, err = InitGenesis(newData.ctx, &newData.keeper, *genState) + require.NoError(t, err) // run same checks again on newdata, to make sure it was reinitialized correctly assertCodeList(t, q2, newData.ctx, 1, data.encConf.Marshaler) diff --git a/x/wasm/ibctesting/wasm.go b/x/wasm/ibctesting/wasm.go index 1eba869574..53bd7dc573 100644 --- a/x/wasm/ibctesting/wasm.go +++ b/x/wasm/ibctesting/wasm.go @@ -13,7 +13,7 @@ import ( abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/rand" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/golang/protobuf/proto" //nolint + "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/x/wasm/types" diff --git a/x/wasm/keeper/ante_test.go b/x/wasm/keeper/ante_test.go index f5a98016f7..90e7ae42fe 100644 --- a/x/wasm/keeper/ante_test.go +++ b/x/wasm/keeper/ante_test.go @@ -113,7 +113,7 @@ func TestCountTxDecorator(t *testing.T) { func TestLimitSimulationGasDecorator(t *testing.T) { var ( hundred sdk.Gas = 100 - zero sdk.Gas = 0 + zero sdk.Gas = 0 //nolint:revive // leave the zero for clarity ) specs := map[string]struct { customLimit *sdk.Gas @@ -169,12 +169,14 @@ func TestLimitSimulationGasDecorator(t *testing.T) { if spec.expErr != nil { require.PanicsWithValue(t, spec.expErr, func() { ante := keeper.NewLimitSimulationGasDecorator(spec.customLimit) - ante.AnteHandle(ctx, nil, spec.simulation, nextAnte) + _, err := ante.AnteHandle(ctx, nil, spec.simulation, nextAnte) + require.NoError(t, err) }) return } ante := keeper.NewLimitSimulationGasDecorator(spec.customLimit) - ante.AnteHandle(ctx, nil, spec.simulation, nextAnte) + _, err := ante.AnteHandle(ctx, nil, spec.simulation, nextAnte) + require.NoError(t, err) }) } } diff --git a/x/wasm/keeper/events_test.go b/x/wasm/keeper/events_test.go index d35c88ecf0..b305df4204 100644 --- a/x/wasm/keeper/events_test.go +++ b/x/wasm/keeper/events_test.go @@ -280,7 +280,7 @@ func hasWasmModuleEvent(ctx sdk.Context, contractAddr sdk.AccAddress) bool { for _, e := range ctx.EventManager().Events() { if e.Type == types.WasmModuleEventType { for _, a := range e.Attributes { - if string(a.Key) == types.AttributeKeyContractAddr && string(a.Value) == contractAddr.String() { + if a.Key == types.AttributeKeyContractAddr && a.Value == contractAddr.String() { return true } } diff --git a/x/wasm/keeper/gas_register_test.go b/x/wasm/keeper/gas_register_test.go index 03f6cdd863..bf8dcd773d 100644 --- a/x/wasm/keeper/gas_register_test.go +++ b/x/wasm/keeper/gas_register_test.go @@ -84,12 +84,12 @@ func TestNewContractInstanceCosts(t *testing.T) { "big msg - unpinned": { srcLen: math.MaxUint32, srcConfig: DefaultGasRegisterConfig(), - exp: sdk.Gas(DefaultContractMessageDataCost*math.MaxUint32 + DefaultInstanceCost), + exp: DefaultContractMessageDataCost*math.MaxUint32 + DefaultInstanceCost, }, "empty msg - unpinned": { srcLen: 0, srcConfig: DefaultGasRegisterConfig(), - exp: sdk.Gas(DefaultInstanceCost), + exp: DefaultInstanceCost, }, "negative len": { @@ -131,7 +131,7 @@ func TestContractInstanceCosts(t *testing.T) { srcLen: math.MaxUint32, srcConfig: DefaultGasRegisterConfig(), pinned: true, - exp: sdk.Gas(DefaultContractMessageDataCost * math.MaxUint32), + exp: DefaultContractMessageDataCost * math.MaxUint32, }, "empty msg - pinned": { srcLen: 0, @@ -147,12 +147,12 @@ func TestContractInstanceCosts(t *testing.T) { "big msg - unpinned": { srcLen: math.MaxUint32, srcConfig: DefaultGasRegisterConfig(), - exp: sdk.Gas(DefaultContractMessageDataCost*math.MaxUint32 + DefaultInstanceCost), + exp: DefaultContractMessageDataCost*math.MaxUint32 + DefaultInstanceCost, }, "empty msg - unpinned": { srcLen: 0, srcConfig: DefaultGasRegisterConfig(), - exp: sdk.Gas(DefaultInstanceCost), + exp: DefaultInstanceCost, }, "negative len": { @@ -196,7 +196,7 @@ func TestReplyCost(t *testing.T) { }, srcConfig: DefaultGasRegisterConfig(), pinned: true, - exp: sdk.Gas(3*DefaultEventAttributeDataCost + DefaultPerAttributeCost + DefaultContractMessageDataCost), // 3 == len("foo") + exp: 3*DefaultEventAttributeDataCost + DefaultPerAttributeCost + DefaultContractMessageDataCost, // 3 == len("foo") }, "subcall response with events - pinned": { src: wasmvmtypes.Reply{ @@ -210,7 +210,7 @@ func TestReplyCost(t *testing.T) { }, srcConfig: DefaultGasRegisterConfig(), pinned: true, - exp: sdk.Gas(3*DefaultEventAttributeDataCost + DefaultPerAttributeCost), // 3 == len("foo") + exp: 3*DefaultEventAttributeDataCost + DefaultPerAttributeCost, // 3 == len("foo") }, "subcall response with events exceeds free tier- pinned": { src: wasmvmtypes.Reply{ @@ -224,7 +224,7 @@ func TestReplyCost(t *testing.T) { }, srcConfig: DefaultGasRegisterConfig(), pinned: true, - exp: sdk.Gas((3+6)*DefaultEventAttributeDataCost + DefaultPerAttributeCost), // 3 == len("foo"), 6 == len("myData") + exp: (3+6)*DefaultEventAttributeDataCost + DefaultPerAttributeCost, // 3 == len("foo"), 6 == len("myData") }, "subcall response error - pinned": { src: wasmvmtypes.Reply{ @@ -248,7 +248,7 @@ func TestReplyCost(t *testing.T) { }, }, srcConfig: DefaultGasRegisterConfig(), - exp: sdk.Gas(DefaultInstanceCost + 3*DefaultEventAttributeDataCost + DefaultPerAttributeCost + DefaultContractMessageDataCost), + exp: DefaultInstanceCost + 3*DefaultEventAttributeDataCost + DefaultPerAttributeCost + DefaultContractMessageDataCost, }, "subcall response with events - unpinned": { src: wasmvmtypes.Reply{ @@ -261,7 +261,7 @@ func TestReplyCost(t *testing.T) { }, }, srcConfig: DefaultGasRegisterConfig(), - exp: sdk.Gas(DefaultInstanceCost + 3*DefaultEventAttributeDataCost + DefaultPerAttributeCost), + exp: DefaultInstanceCost + 3*DefaultEventAttributeDataCost + DefaultPerAttributeCost, }, "subcall response with events exceeds free tier- unpinned": { src: wasmvmtypes.Reply{ @@ -274,7 +274,7 @@ func TestReplyCost(t *testing.T) { }, }, srcConfig: DefaultGasRegisterConfig(), - exp: sdk.Gas(DefaultInstanceCost + (3+6)*DefaultEventAttributeDataCost + DefaultPerAttributeCost), // 3 == len("foo"), 6 == len("myData") + exp: DefaultInstanceCost + (3+6)*DefaultEventAttributeDataCost + DefaultPerAttributeCost, // 3 == len("foo"), 6 == len("myData") }, "subcall response error - unpinned": { src: wasmvmtypes.Reply{ @@ -283,7 +283,7 @@ func TestReplyCost(t *testing.T) { }, }, srcConfig: DefaultGasRegisterConfig(), - exp: sdk.Gas(DefaultInstanceCost + 3*DefaultContractMessageDataCost), + exp: DefaultInstanceCost + 3*DefaultContractMessageDataCost, }, "subcall response with empty events": { src: wasmvmtypes.Reply{ diff --git a/x/wasm/keeper/genesis_test.go b/x/wasm/keeper/genesis_test.go index 7334b4bc68..d5722fd868 100644 --- a/x/wasm/keeper/genesis_test.go +++ b/x/wasm/keeper/genesis_test.go @@ -30,7 +30,6 @@ import ( "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/x/wasm/types" - wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types" ) const firstCodeID = 1 @@ -45,7 +44,8 @@ func TestGenesisExportImport(t *testing.T) { // store some test data f := fuzz.New().Funcs(ModelFuzzers...) - wasmKeeper.SetParams(srcCtx, types.DefaultParams()) + err = wasmKeeper.SetParams(srcCtx, types.DefaultParams()) + require.NoError(t, err) for i := 0; i < 25; i++ { var ( @@ -68,7 +68,8 @@ func TestGenesisExportImport(t *testing.T) { codeID, _, err := contractKeeper.Create(srcCtx, creatorAddr, wasmCode, &codeInfo.InstantiateConfig) require.NoError(t, err) if pinned { - contractKeeper.PinCode(srcCtx, codeID) + err = contractKeeper.PinCode(srcCtx, codeID) + require.NoError(t, err) } if contractExtension { anyTime := time.Now().UTC() @@ -76,7 +77,8 @@ func TestGenesisExportImport(t *testing.T) { f.NilChance(0).Fuzz(&nestedType) myExtension, err := v1beta1.NewProposal(&nestedType, 1, anyTime, anyTime) require.NoError(t, err) - contract.SetExtension(&myExtension) + err = contract.SetExtension(&myExtension) + require.NoError(t, err) } contract.CodeID = codeID @@ -88,7 +90,8 @@ func TestGenesisExportImport(t *testing.T) { } var wasmParams types.Params f.NilChance(0).Fuzz(&wasmParams) - wasmKeeper.SetParams(srcCtx, wasmParams) + err = wasmKeeper.SetParams(srcCtx, wasmParams) + require.NoError(t, err) // export exportedState := ExportGenesis(srcCtx, wasmKeeper) @@ -109,7 +112,7 @@ func TestGenesisExportImport(t *testing.T) { dstKeeper, dstCtx := setupKeeper(t) // reset contract code index in source DB for comparison with dest DB - wasmKeeper.IterateContractInfo(srcCtx, func(address sdk.AccAddress, info wasmTypes.ContractInfo) bool { + wasmKeeper.IterateContractInfo(srcCtx, func(address sdk.AccAddress, info types.ContractInfo) bool { creatorAddress := sdk.MustAccAddressFromBech32(info.Creator) history := wasmKeeper.GetContractHistory(srcCtx, address) @@ -119,10 +122,11 @@ func TestGenesisExportImport(t *testing.T) { }) // re-import - var importState wasmTypes.GenesisState + var importState types.GenesisState err = dstKeeper.cdc.UnmarshalJSON(exportedGenesis, &importState) require.NoError(t, err) - InitGenesis(dstCtx, dstKeeper, importState) + _, err = InitGenesis(dstCtx, dstKeeper, importState) + require.NoError(t, err) // compare whole DB @@ -147,7 +151,7 @@ func TestGenesisInit(t *testing.T) { wasmCode, err := os.ReadFile("./testdata/hackatom.wasm") require.NoError(t, err) - myCodeInfo := wasmTypes.CodeInfoFixture(wasmTypes.WithSHA256CodeHash(wasmCode)) + myCodeInfo := types.CodeInfoFixture(types.WithSHA256CodeHash(wasmCode)) specs := map[string]struct { src types.GenesisState expSuccess bool @@ -209,7 +213,7 @@ func TestGenesisInit(t *testing.T) { "prevent code hash mismatch": {src: types.GenesisState{ Codes: []types.Code{{ CodeID: firstCodeID, - CodeInfo: wasmTypes.CodeInfoFixture(func(i *wasmTypes.CodeInfo) { i.CodeHash = make([]byte, sha256.Size) }), + CodeInfo: types.CodeInfoFixture(func(i *types.CodeInfo) { i.CodeHash = make([]byte, sha256.Size) }), CodeBytes: wasmCode, }}, Params: types.DefaultParams(), @@ -258,7 +262,7 @@ func TestGenesisInit(t *testing.T) { Contracts: []types.Contract{ { ContractAddress: BuildContractAddressClassic(1, 1).String(), - ContractInfo: types.ContractInfoFixture(func(c *wasmTypes.ContractInfo) { c.CodeID = 1 }, types.RandCreatedFields), + ContractInfo: types.ContractInfoFixture(func(c *types.ContractInfo) { c.CodeID = 1 }, types.RandCreatedFields), ContractCodeHistory: []types.ContractCodeHistoryEntry{ { Operation: types.ContractCodeHistoryOperationTypeMigrate, @@ -287,7 +291,7 @@ func TestGenesisInit(t *testing.T) { Contracts: []types.Contract{ { ContractAddress: BuildContractAddressClassic(1, 1).String(), - ContractInfo: types.ContractInfoFixture(func(c *wasmTypes.ContractInfo) { c.CodeID = 1 }, types.RandCreatedFields), + ContractInfo: types.ContractInfoFixture(func(c *types.ContractInfo) { c.CodeID = 1 }, types.RandCreatedFields), ContractCodeHistory: []types.ContractCodeHistoryEntry{ { Operation: types.ContractCodeHistoryOperationTypeMigrate, @@ -298,7 +302,7 @@ func TestGenesisInit(t *testing.T) { }, }, { ContractAddress: BuildContractAddressClassic(1, 2).String(), - ContractInfo: types.ContractInfoFixture(func(c *wasmTypes.ContractInfo) { c.CodeID = 1 }, types.RandCreatedFields), + ContractInfo: types.ContractInfoFixture(func(c *types.ContractInfo) { c.CodeID = 1 }, types.RandCreatedFields), ContractCodeHistory: []types.ContractCodeHistoryEntry{ { Operation: types.ContractCodeHistoryOperationTypeMigrate, @@ -322,7 +326,7 @@ func TestGenesisInit(t *testing.T) { Contracts: []types.Contract{ { ContractAddress: BuildContractAddressClassic(1, 1).String(), - ContractInfo: types.ContractInfoFixture(func(c *wasmTypes.ContractInfo) { c.CodeID = 1 }, types.RandCreatedFields), + ContractInfo: types.ContractInfoFixture(func(c *types.ContractInfo) { c.CodeID = 1 }, types.RandCreatedFields), ContractCodeHistory: []types.ContractCodeHistoryEntry{ { Operation: types.ContractCodeHistoryOperationTypeMigrate, @@ -346,7 +350,7 @@ func TestGenesisInit(t *testing.T) { Contracts: []types.Contract{ { ContractAddress: BuildContractAddressClassic(1, 1).String(), - ContractInfo: types.ContractInfoFixture(func(c *wasmTypes.ContractInfo) { c.CodeID = 1 }, types.RandCreatedFields), + ContractInfo: types.ContractInfoFixture(func(c *types.ContractInfo) { c.CodeID = 1 }, types.RandCreatedFields), ContractCodeHistory: []types.ContractCodeHistoryEntry{ { Operation: types.ContractCodeHistoryOperationTypeMigrate, @@ -357,7 +361,7 @@ func TestGenesisInit(t *testing.T) { }, }, { ContractAddress: BuildContractAddressClassic(1, 1).String(), - ContractInfo: types.ContractInfoFixture(func(c *wasmTypes.ContractInfo) { c.CodeID = 1 }, types.RandCreatedFields), + ContractInfo: types.ContractInfoFixture(func(c *types.ContractInfo) { c.CodeID = 1 }, types.RandCreatedFields), ContractCodeHistory: []types.ContractCodeHistoryEntry{ { Operation: types.ContractCodeHistoryOperationTypeMigrate, @@ -381,7 +385,7 @@ func TestGenesisInit(t *testing.T) { Contracts: []types.Contract{ { ContractAddress: BuildContractAddressClassic(1, 1).String(), - ContractInfo: types.ContractInfoFixture(func(c *wasmTypes.ContractInfo) { c.CodeID = 1 }, types.RandCreatedFields), + ContractInfo: types.ContractInfoFixture(func(c *types.ContractInfo) { c.CodeID = 1 }, types.RandCreatedFields), ContractState: []types.Model{ { Key: []byte{0x1}, @@ -437,7 +441,7 @@ func TestGenesisInit(t *testing.T) { Contracts: []types.Contract{ { ContractAddress: BuildContractAddressClassic(1, 1).String(), - ContractInfo: types.ContractInfoFixture(func(c *wasmTypes.ContractInfo) { c.CodeID = 1 }, types.RandCreatedFields), + ContractInfo: types.ContractInfoFixture(func(c *types.ContractInfo) { c.CodeID = 1 }, types.RandCreatedFields), ContractCodeHistory: []types.ContractCodeHistoryEntry{ { Operation: types.ContractCodeHistoryOperationTypeMigrate, @@ -547,7 +551,7 @@ func TestImportContractWithCodeHistoryPreserved(t *testing.T) { enc64 := base64.StdEncoding.EncodeToString genesisStr := fmt.Sprintf(genesisTemplate, enc64(wasmCodeHash[:]), enc64(wasmCode)) - var importState wasmTypes.GenesisState + var importState types.GenesisState err = keeper.cdc.UnmarshalJSON([]byte(genesisStr), &importState) require.NoError(t, err) require.NoError(t, importState.ValidateBasic(), genesisStr) @@ -570,7 +574,7 @@ func TestImportContractWithCodeHistoryPreserved(t *testing.T) { expCodeInfo := types.CodeInfo{ CodeHash: wasmCodeHash[:], Creator: codeCreatorAddr, - InstantiateConfig: wasmTypes.AccessConfig{ + InstantiateConfig: types.AccessConfig{ Permission: types.AccessTypeOnlyAddress, Address: codeCreatorAddr, }, @@ -624,7 +628,7 @@ func setupKeeper(t *testing.T) (*Keeper, sdk.Context) { require.NoError(t, err) t.Cleanup(func() { os.RemoveAll(tempDir) }) - keyWasm := sdk.NewKVStoreKey(wasmTypes.StoreKey) + keyWasm := sdk.NewKVStoreKey(types.StoreKey) db := dbm.NewMemDB() ms := store.NewCommitMultiStore(db) @@ -645,7 +649,7 @@ func setupKeeper(t *testing.T) (*Keeper, sdk.Context) { // also registering gov interfaces for nested Any type v1beta1.RegisterInterfaces(encodingConfig.InterfaceRegistry) - wasmConfig := wasmTypes.DefaultWasmConfig() + wasmConfig := types.DefaultWasmConfig() srcKeeper := NewKeeper( encodingConfig.Marshaler, @@ -671,7 +675,6 @@ func setupKeeper(t *testing.T) (*Keeper, sdk.Context) { type StakingKeeperMock struct { err error validatorUpdate []abci.ValidatorUpdate - expCalls int gotCalls int } @@ -680,18 +683,14 @@ func (s *StakingKeeperMock) ApplyAndReturnValidatorSetUpdates(_ sdk.Context) ([] return s.validatorUpdate, s.err } -func (s *StakingKeeperMock) verifyCalls(t *testing.T) { - assert.Equal(t, s.expCalls, s.gotCalls, "number calls") -} - var _ MessageRouter = &MockMsgHandler{} type MockMsgHandler struct { result *sdk.Result err error - expCalls int + expCalls int //nolint:unused gotCalls int - expMsg sdk.Msg + expMsg sdk.Msg //nolint:unused gotMsg sdk.Msg } @@ -704,11 +703,3 @@ func (m *MockMsgHandler) Handle(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, erro m.gotMsg = msg return m.result, m.err } - -func (m *MockMsgHandler) verifyCalls(t *testing.T) { - if m == nil { - return - } - assert.Equal(t, m.expMsg, m.gotMsg, "message param") - assert.Equal(t, m.expCalls, m.gotCalls, "number calls") -} diff --git a/x/wasm/keeper/handler_plugin_encoders_test.go b/x/wasm/keeper/handler_plugin_encoders_test.go index 64127190be..d27d6654f4 100644 --- a/x/wasm/keeper/handler_plugin_encoders_test.go +++ b/x/wasm/keeper/handler_plugin_encoders_test.go @@ -11,10 +11,10 @@ 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/golang/protobuf/proto" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -543,10 +543,10 @@ func TestEncoding(t *testing.T) { if tc.expError { assert.Error(t, err) return - } else { - require.NoError(t, err) - assert.Equal(t, tc.output, res) } + require.NoError(t, err) + assert.Equal(t, tc.output, res) + // and valid sdk message for _, v := range res { gotErr := v.ValidateBasic() @@ -778,10 +778,10 @@ func TestEncodeGovMsg(t *testing.T) { if tc.expError { assert.Error(t, gotEncErr) return - } else { - require.NoError(t, gotEncErr) - assert.Equal(t, tc.output, res) } + require.NoError(t, gotEncErr) + assert.Equal(t, tc.output, res) + // and valid sdk message for _, v := range res { gotErr := v.ValidateBasic() diff --git a/x/wasm/keeper/handler_plugin_test.go b/x/wasm/keeper/handler_plugin_test.go index 13fe6eaf41..fbfb13a521 100644 --- a/x/wasm/keeper/handler_plugin_test.go +++ b/x/wasm/keeper/handler_plugin_test.go @@ -4,6 +4,7 @@ import ( "encoding/json" "testing" + errorsmod "cosmossdk.io/errors" "github.com/cometbft/cometbft/libs/log" wasmvm "github.com/CosmWasm/wasmvm" @@ -41,7 +42,7 @@ func TestMessageHandlerChainDispatch(t *testing.T) { myMsg := wasmvmtypes.CosmosMsg{Custom: []byte(`{}`)} specs := map[string]struct { handlers []Messenger - expErr *sdkerrors.Error + expErr *errorsmod.Error expEvents []sdk.Event }{ "single handler": { @@ -121,7 +122,7 @@ func TestSDKMessageHandlerDispatch(t *testing.T) { specs := map[string]struct { srcRoute MessageRouter srcEncoder CustomEncoder - expErr *sdkerrors.Error + expErr *errorsmod.Error expMsgDispatched int }{ "all good": { @@ -266,7 +267,7 @@ func TestIBCRawPacketHandler(t *testing.T) { chanKeeper types.ChannelKeeper capKeeper types.CapabilityKeeper expPacketSent *CapturedPacket - expErr *sdkerrors.Error + expErr *errorsmod.Error }{ "all good": { srcMsg: wasmvmtypes.SendPacketMsg{ diff --git a/x/wasm/keeper/keeper_test.go b/x/wasm/keeper/keeper_test.go index 37a30a70af..c3046fd420 100644 --- a/x/wasm/keeper/keeper_test.go +++ b/x/wasm/keeper/keeper_test.go @@ -11,6 +11,7 @@ import ( "testing" "time" + errorsmod "cosmossdk.io/errors" abci "github.com/cometbft/cometbft/abci/types" wasmvm "github.com/CosmWasm/wasmvm" @@ -123,10 +124,11 @@ func TestCreateStoresInstantiatePermission(t *testing.T) { t.Run(msg, func(t *testing.T) { ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) accKeeper, keeper, bankKeeper := keepers.AccountKeeper, keepers.ContractKeeper, keepers.BankKeeper - keepers.WasmKeeper.SetParams(ctx, types.Params{ + err := keepers.WasmKeeper.SetParams(ctx, types.Params{ CodeUploadAccess: types.AllowEverybody, InstantiateDefaultPermission: spec.srcPermission, }) + require.NoError(t, err) fundAccounts(t, ctx, accKeeper, bankKeeper, myAddr, deposit) codeID, _, err := keeper.Create(ctx, myAddr, hackatomWasm, nil) @@ -148,7 +150,7 @@ func TestCreateWithParamPermissions(t *testing.T) { specs := map[string]struct { policy AuthorizationPolicy chainUpload types.AccessConfig - expError *sdkerrors.Error + expError *errorsmod.Error }{ "default": { policy: DefaultAuthorizationPolicy{}, @@ -181,9 +183,10 @@ func TestCreateWithParamPermissions(t *testing.T) { t.Run(msg, func(t *testing.T) { params := types.DefaultParams() params.CodeUploadAccess = spec.chainUpload - keepers.WasmKeeper.SetParams(ctx, params) + err := keepers.WasmKeeper.SetParams(ctx, params) + require.NoError(t, err) keeper := NewPermissionedKeeper(keepers.WasmKeeper, spec.policy) - _, _, err := keeper.Create(ctx, creator, hackatomWasm, nil) + _, _, err = keeper.Create(ctx, creator, hackatomWasm, nil) require.True(t, spec.expError.Is(err), err) if spec.expError != nil { return @@ -212,7 +215,7 @@ func TestEnforceValidPermissionsOnCreate(t *testing.T) { // grantedPermission is set iff no error grantedPermission types.AccessConfig // expError is nil iff the request is allowed - expError *sdkerrors.Error + expError *errorsmod.Error }{ "override everybody": { defaultPermssion: types.AccessTypeEverybody, @@ -259,7 +262,8 @@ func TestEnforceValidPermissionsOnCreate(t *testing.T) { t.Run(msg, func(t *testing.T) { params := types.DefaultParams() params.InstantiateDefaultPermission = spec.defaultPermssion - keeper.SetParams(ctx, params) + err := keeper.SetParams(ctx, params) + require.NoError(t, err) codeID, _, err := contractKeeper.Create(ctx, creator, hackatomWasm, spec.requestedPermission) require.True(t, spec.expError.Is(err), err) if spec.expError == nil { @@ -511,7 +515,7 @@ func TestInstantiateWithPermissions(t *testing.T) { specs := map[string]struct { srcPermission types.AccessConfig srcActor sdk.AccAddress - expError *sdkerrors.Error + expError *errorsmod.Error }{ "default": { srcPermission: types.DefaultUploadAccess, @@ -838,7 +842,7 @@ func TestExecute(t *testing.T) { // unauthorized - trialCtx so we don't change state trialCtx := ctx.WithMultiStore(ctx.MultiStore().CacheWrap().(sdk.MultiStore)) - res, err := keepers.ContractKeeper.Execute(trialCtx, addr, creator, []byte(`{"release":{}}`), nil) + _, err = keepers.ContractKeeper.Execute(trialCtx, addr, creator, []byte(`{"release":{}}`), nil) require.Error(t, err) require.True(t, errors.Is(err, types.ErrExecuteFailed)) require.Equal(t, "Unauthorized: execute wasm contract failed", err.Error()) @@ -848,8 +852,8 @@ func TestExecute(t *testing.T) { gasBefore := ctx.GasMeter().GasConsumed() em := sdk.NewEventManager() // when - res, err = keepers.ContractKeeper.Execute(ctx.WithEventManager(em), addr, fred, []byte(`{"release":{}}`), topUp) - diff := time.Now().Sub(start) + res, err := keepers.ContractKeeper.Execute(ctx.WithEventManager(em), addr, fred, []byte(`{"release":{}}`), topUp) + diff := time.Since(start) require.NoError(t, err) require.NotNil(t, res) @@ -938,7 +942,8 @@ func TestExecuteWithDeposit(t *testing.T) { ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) accKeeper, bankKeeper, keeper := keepers.AccountKeeper, keepers.BankKeeper, keepers.ContractKeeper if spec.newBankParams != nil { - bankKeeper.SetParams(ctx, *spec.newBankParams) + err := bankKeeper.SetParams(ctx, *spec.newBankParams) + require.NoError(t, err) } if spec.fundAddr { fundAccounts(t, ctx, accKeeper, bankKeeper, spec.srcActor, sdk.NewCoins(sdk.NewInt64Coin("denom", 200))) @@ -1052,7 +1057,7 @@ func TestExecuteWithCpuLoop(t *testing.T) { }() // this should throw out of gas exception (panic) - _, err = keepers.ContractKeeper.Execute(ctx, addr, fred, []byte(`{"cpu_loop":{}}`), nil) + _, _ = keepers.ContractKeeper.Execute(ctx, addr, fred, []byte(`{"cpu_loop":{}}`), nil) require.True(t, false, "We must panic before this line") } @@ -1094,7 +1099,7 @@ func TestExecuteWithStorageLoop(t *testing.T) { }() // this should throw out of gas exception (panic) - _, err = keepers.ContractKeeper.Execute(ctx, addr, fred, []byte(`{"storage_loop":{}}`), nil) + _, _ = keepers.ContractKeeper.Execute(ctx, addr, fred, []byte(`{"storage_loop":{}}`), nil) require.True(t, false, "We must panic before this line") } @@ -1138,7 +1143,7 @@ func TestMigrate(t *testing.T) { fromCodeID uint64 toCodeID uint64 migrateMsg []byte - expErr *sdkerrors.Error + expErr *errorsmod.Error expVerifier sdk.AccAddress expIBCPort bool initMsg []byte @@ -1572,7 +1577,7 @@ func prettyEvents(t *testing.T, events sdk.Events) string { for i, e := range events { attr := make([]map[string]string, len(e.Attributes)) for j, a := range e.Attributes { - attr[j] = map[string]string{string(a.Key): string(a.Value)} + attr[j] = map[string]string{a.Key: a.Value} } r[i] = prettyEvent{Type: e.Type, Attr: attr} } @@ -1611,7 +1616,7 @@ func TestUpdateContractAdmin(t *testing.T) { newAdmin sdk.AccAddress overrideContractAddr sdk.AccAddress caller sdk.AccAddress - expErr *sdkerrors.Error + expErr *errorsmod.Error }{ "all good with admin set": { instAdmin: fred, @@ -1680,7 +1685,7 @@ func TestClearContractAdmin(t *testing.T) { instAdmin sdk.AccAddress overrideContractAddr sdk.AccAddress caller sdk.AccAddress - expErr *sdkerrors.Error + expErr *errorsmod.Error }{ "all good when called by proper admin": { instAdmin: fred, @@ -2147,7 +2152,8 @@ func TestSetAccessConfig(t *testing.T) { newParams := types.DefaultParams() newParams.InstantiateDefaultPermission = spec.chainPermission - k.SetParams(ctx, newParams) + err := k.SetParams(ctx, newParams) + require.NoError(t, err) k.storeCodeInfo(ctx, codeID, types.NewCodeInfo(nil, creatorAddr, types.AllowNobody)) // when @@ -2199,7 +2205,7 @@ func TestCoinBurnerPruneBalances(t *testing.T) { setupAcc func(t *testing.T, ctx sdk.Context) authtypes.AccountI expBalances sdk.Coins expHandled bool - expErr *sdkerrors.Error + expErr *errorsmod.Error }{ "vesting account - all removed": { setupAcc: func(t *testing.T, ctx sdk.Context) authtypes.AccountI { return myVestingAccount }, @@ -2277,8 +2283,9 @@ func TestIteratorContractByCreator(t *testing.T) { mockAddress3 := keepers.Faucet.NewFundedRandomAccount(parentCtx, topUp...) contract1ID, _, err := keeper.Create(parentCtx, creator, hackatomWasm, nil) - contract2ID, _, err := keeper.Create(parentCtx, creator, hackatomWasm, nil) + require.NoError(t, err) + contract2ID, _, err := keeper.Create(parentCtx, creator, hackatomWasm, nil) require.NoError(t, err) initMsgBz := HackatomExampleInitMsg{ @@ -2404,7 +2411,7 @@ func TestSetContractAdmin(t *testing.T) { func attrsToStringMap(attrs []abci.EventAttribute) map[string]string { r := make(map[string]string, len(attrs)) for _, v := range attrs { - r[string(v.Key)] = string(v.Value) + r[v.Key] = v.Value } return r } diff --git a/x/wasm/keeper/migrations_integration_test.go b/x/wasm/keeper/migrations_integration_test.go index 68ec878459..5a824f8284 100644 --- a/x/wasm/keeper/migrations_integration_test.go +++ b/x/wasm/keeper/migrations_integration_test.go @@ -18,7 +18,7 @@ import ( func TestModuleMigrations(t *testing.T) { wasmApp := app.Setup(t) - upgradeHandler := func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + upgradeHandler := func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { //nolint:unparam return wasmApp.ModuleManager.RunMigrations(ctx, wasmApp.Configurator(), fromVM) } @@ -55,7 +55,8 @@ func TestModuleMigrations(t *testing.T) { fromVM := wasmApp.UpgradeKeeper.GetModuleVersionMap(ctx) fromVM[wasm.ModuleName] = spec.startVersion - upgradeHandler(ctx, upgradetypes.Plan{Name: "testing"}, fromVM) + _, err := upgradeHandler(ctx, upgradetypes.Plan{Name: "testing"}, fromVM) + require.NoError(t, err) // when gotVM, err := wasmApp.ModuleManager.RunMigrations(ctx, wasmApp.Configurator(), fromVM) diff --git a/x/wasm/keeper/msg_dispatcher_test.go b/x/wasm/keeper/msg_dispatcher_test.go index 9461964340..73e5db5b06 100644 --- a/x/wasm/keeper/msg_dispatcher_test.go +++ b/x/wasm/keeper/msg_dispatcher_test.go @@ -394,15 +394,20 @@ func TestDispatchSubmessages(t *testing.T) { WithGasMeter(sdk.NewGasMeter(100)). WithEventManager(em).WithLogger(log.TestingLogger()) d := NewMessageDispatcher(spec.msgHandler, spec.replyer) + + // run the test gotData, gotErr := d.DispatchSubmessages(ctx, RandomAccountAddress(t), "any_port", spec.msgs) if spec.expErr { require.Error(t, gotErr) assert.Empty(t, em.Events()) return - } else { - require.NoError(t, gotErr) - assert.Equal(t, spec.expData, gotData) } + + // if we don't expect an error, we should get no error + require.NoError(t, gotErr) + assert.Equal(t, spec.expData, gotData) + + // ensure the commits are what we expect assert.Equal(t, spec.expCommits, mockStore.Committed) if len(spec.expEvents) == 0 { assert.Empty(t, em.Events()) diff --git a/x/wasm/keeper/msg_server_integration_test.go b/x/wasm/keeper/msg_server_integration_test.go index 9e6765608e..ea426646cb 100644 --- a/x/wasm/keeper/msg_server_integration_test.go +++ b/x/wasm/keeper/msg_server_integration_test.go @@ -120,7 +120,8 @@ func TestUpdateParams(t *testing.T) { } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { - wasmApp.WasmKeeper.SetParams(ctx, types.DefaultParams()) + err := wasmApp.WasmKeeper.SetParams(ctx, types.DefaultParams()) + require.NoError(t, err) // when rsp, err := wasmApp.MsgServiceRouter().Handler(&spec.src)(ctx, &spec.src) diff --git a/x/wasm/keeper/options_test.go b/x/wasm/keeper/options_test.go index 903e0615ff..d64e4a3f35 100644 --- a/x/wasm/keeper/options_test.go +++ b/x/wasm/keeper/options_test.go @@ -72,7 +72,7 @@ func TestConstructorOptions(t *testing.T) { "api costs": { srcOpt: WithAPICosts(1, 2), verify: func(t *testing.T, k Keeper) { - t.Cleanup(setApiDefaults) + t.Cleanup(setAPIDefaults) assert.Equal(t, uint64(1), costHumanize) assert.Equal(t, uint64(2), costCanonical) }, @@ -108,7 +108,7 @@ func TestConstructorOptions(t *testing.T) { } } -func setApiDefaults() { +func setAPIDefaults() { costHumanize = DefaultGasCostHumanAddress * DefaultGasMultiplier costCanonical = DefaultGasCostCanonicalAddress * DefaultGasMultiplier } diff --git a/x/wasm/keeper/proposal_integration_test.go b/x/wasm/keeper/proposal_integration_test.go index fc05c054d8..3e77954c02 100644 --- a/x/wasm/keeper/proposal_integration_test.go +++ b/x/wasm/keeper/proposal_integration_test.go @@ -21,13 +21,16 @@ import ( "github.com/CosmWasm/wasmd/x/wasm/types" ) +const myTestLabel = "testing" + func TestStoreCodeProposal(t *testing.T) { parentCtx, keepers := CreateTestInput(t, false, "staking") wasmKeeper := keepers.WasmKeeper - wasmKeeper.SetParams(parentCtx, types.Params{ + err := wasmKeeper.SetParams(parentCtx, types.Params{ CodeUploadAccess: types.AllowNobody, InstantiateDefaultPermission: types.AccessTypeNobody, }) + require.NoError(t, err) rawWasmCode, err := os.ReadFile("./testdata/hackatom.wasm") require.NoError(t, err) gzippedWasmCode, err := os.ReadFile("./testdata/hackatom.wasm.gzip") @@ -120,10 +123,11 @@ func submitLegacyProposal(t *testing.T, ctx sdk.Context, content v1beta1.Content func TestInstantiateProposal(t *testing.T) { ctx, keepers := CreateTestInput(t, false, "staking") wasmKeeper := keepers.WasmKeeper - wasmKeeper.SetParams(ctx, types.Params{ + err := wasmKeeper.SetParams(ctx, types.Params{ CodeUploadAccess: types.AllowNobody, InstantiateDefaultPermission: types.AccessTypeNobody, }) + require.NoError(t, err) wasmCode, err := os.ReadFile("./testdata/hackatom.wasm") require.NoError(t, err) @@ -141,7 +145,7 @@ func TestInstantiateProposal(t *testing.T) { p.CodeID = firstCodeID p.RunAs = oneAddress.String() p.Admin = otherAddress.String() - p.Label = "testing" + p.Label = myTestLabel }) em := sdk.NewEventManager() @@ -157,7 +161,7 @@ func TestInstantiateProposal(t *testing.T) { assert.Equal(t, uint64(1), cInfo.CodeID) assert.Equal(t, oneAddress.String(), cInfo.Creator) assert.Equal(t, otherAddress.String(), cInfo.Admin) - assert.Equal(t, "testing", cInfo.Label) + assert.Equal(t, myTestLabel, cInfo.Label) expHistory := []types.ContractCodeHistoryEntry{{ Operation: types.ContractCodeHistoryOperationTypeInit, CodeID: src.CodeID, @@ -177,10 +181,11 @@ func TestInstantiateProposal(t *testing.T) { func TestInstantiate2Proposal(t *testing.T) { ctx, keepers := CreateTestInput(t, false, "staking") wasmKeeper := keepers.WasmKeeper - wasmKeeper.SetParams(ctx, types.Params{ + err := wasmKeeper.SetParams(ctx, types.Params{ CodeUploadAccess: types.AllowNobody, InstantiateDefaultPermission: types.AccessTypeNobody, }) + require.NoError(t, err) wasmCode, err := os.ReadFile("./testdata/hackatom.wasm") require.NoError(t, err) @@ -192,8 +197,8 @@ func TestInstantiate2Proposal(t *testing.T) { var ( oneAddress sdk.AccAddress = bytes.Repeat([]byte{0x1}, types.ContractAddrLen) otherAddress sdk.AccAddress = bytes.Repeat([]byte{0x2}, types.ContractAddrLen) - label string = "label" - salt []byte = []byte("mySalt") + label = "label" + salt = []byte("mySalt") ) src := types.InstantiateContract2ProposalFixture(func(p *types.InstantiateContract2Proposal) { p.CodeID = firstCodeID @@ -235,10 +240,11 @@ func TestInstantiate2Proposal(t *testing.T) { func TestInstantiateProposal_NoAdmin(t *testing.T) { ctx, keepers := CreateTestInput(t, false, "staking") wasmKeeper := keepers.WasmKeeper - wasmKeeper.SetParams(ctx, types.Params{ + err := wasmKeeper.SetParams(ctx, types.Params{ CodeUploadAccess: types.AllowNobody, InstantiateDefaultPermission: types.AccessTypeNobody, }) + require.NoError(t, err) wasmCode, err := os.ReadFile("./testdata/hackatom.wasm") require.NoError(t, err) @@ -268,7 +274,7 @@ func TestInstantiateProposal_NoAdmin(t *testing.T) { p.CodeID = firstCodeID p.RunAs = oneAddress.String() p.Admin = spec.srcAdmin - p.Label = "testing" + p.Label = myTestLabel }) govAuthority := keepers.AccountKeeper.GetModuleAddress(govtypes.ModuleName).String() msgServer := govkeeper.NewMsgServerImpl(keepers.GovKeeper) @@ -293,7 +299,7 @@ func TestInstantiateProposal_NoAdmin(t *testing.T) { assert.Equal(t, uint64(1), cInfo.CodeID) assert.Equal(t, oneAddress.String(), cInfo.Creator) assert.Equal(t, "", cInfo.Admin) - assert.Equal(t, "testing", cInfo.Label) + assert.Equal(t, myTestLabel, cInfo.Label) expHistory := []types.ContractCodeHistoryEntry{{ Operation: types.ContractCodeHistoryOperationTypeInit, CodeID: src.CodeID, @@ -315,10 +321,11 @@ func TestInstantiateProposal_NoAdmin(t *testing.T) { func TestStoreAndInstantiateContractProposal(t *testing.T) { ctx, keepers := CreateTestInput(t, false, "staking") wasmKeeper := keepers.WasmKeeper - wasmKeeper.SetParams(ctx, types.Params{ + err := wasmKeeper.SetParams(ctx, types.Params{ CodeUploadAccess: types.AllowNobody, InstantiateDefaultPermission: types.AccessTypeNobody, }) + require.NoError(t, err) wasmCode, err := os.ReadFile("./testdata/hackatom.wasm") require.NoError(t, err) @@ -335,7 +342,7 @@ func TestStoreAndInstantiateContractProposal(t *testing.T) { p.WASMByteCode = wasmCode p.RunAs = oneAddress.String() p.Admin = otherAddress.String() - p.Label = "testing" + p.Label = myTestLabel p.CodeHash = checksum }) em := sdk.NewEventManager() @@ -351,7 +358,7 @@ func TestStoreAndInstantiateContractProposal(t *testing.T) { require.NotNil(t, cInfo) assert.Equal(t, oneAddress.String(), cInfo.Creator) assert.Equal(t, otherAddress.String(), cInfo.Admin) - assert.Equal(t, "testing", cInfo.Label) + assert.Equal(t, myTestLabel, cInfo.Label) expHistory := []types.ContractCodeHistoryEntry{{ Operation: types.ContractCodeHistoryOperationTypeInit, CodeID: cInfo.CodeID, @@ -373,10 +380,11 @@ func TestStoreAndInstantiateContractProposal(t *testing.T) { func TestMigrateProposal(t *testing.T) { ctx, keepers := CreateTestInput(t, false, "staking") wasmKeeper := keepers.WasmKeeper - wasmKeeper.SetParams(ctx, types.Params{ + err := wasmKeeper.SetParams(ctx, types.Params{ CodeUploadAccess: types.AllowNobody, InstantiateDefaultPermission: types.AccessTypeNobody, }) + require.NoError(t, err) wasmCode, err := os.ReadFile("./testdata/hackatom.wasm") require.NoError(t, err) @@ -392,7 +400,7 @@ func TestMigrateProposal(t *testing.T) { ) contractInfo := types.ContractInfoFixture(func(c *types.ContractInfo) { - c.Label = "testing" + c.Label = myTestLabel c.Admin = anyAddress.String() c.Created = types.NewAbsoluteTxPosition(ctx) }) @@ -429,7 +437,7 @@ func TestMigrateProposal(t *testing.T) { require.NotNil(t, cInfo) assert.Equal(t, uint64(2), cInfo.CodeID) assert.Equal(t, anyAddress.String(), cInfo.Admin) - assert.Equal(t, "testing", cInfo.Label) + assert.Equal(t, myTestLabel, cInfo.Label) expHistory := []types.ContractCodeHistoryEntry{{ Operation: types.ContractCodeHistoryOperationTypeInit, CodeID: firstCodeID, @@ -446,7 +454,7 @@ func TestMigrateProposal(t *testing.T) { assert.Equal(t, types.EventTypeMigrate, em.Events()[0].Type) require.Equal(t, types.EventTypeGovContractResult, em.Events()[1].Type) require.Len(t, em.Events()[1].Attributes, 1) - assert.Equal(t, types.AttributeKeyResultDataHex, string(em.Events()[1].Attributes[0].Key)) + assert.Equal(t, types.AttributeKeyResultDataHex, em.Events()[1].Attributes[0].Key) } func TestExecuteProposal(t *testing.T) { @@ -475,8 +483,6 @@ func TestExecuteProposal(t *testing.T) { RunAs: exampleContract.BeneficiaryAddr.String(), } - em := sdk.NewEventManager() - // fails on store - this doesn't have permission govAuthority := keepers.AccountKeeper.GetModuleAddress(govtypes.ModuleName).String() msgServer := govkeeper.NewMsgServerImpl(keepers.GovKeeper) @@ -495,7 +501,7 @@ func TestExecuteProposal(t *testing.T) { RunAs: exampleContract.VerifierAddr.String(), } - em = sdk.NewEventManager() + em := sdk.NewEventManager() // when mustSubmitAndExecuteLegacyProposal(t, ctx.WithEventManager(em), src, exampleContract.BeneficiaryAddr.String(), keepers) @@ -612,10 +618,11 @@ func TestAdminProposals(t *testing.T) { t.Run(msg, func(t *testing.T) { ctx, keepers := CreateTestInput(t, false, "staking") wasmKeeper := keepers.WasmKeeper - wasmKeeper.SetParams(ctx, types.Params{ + err := wasmKeeper.SetParams(ctx, types.Params{ CodeUploadAccess: types.AllowNobody, InstantiateDefaultPermission: types.AccessTypeNobody, }) + require.NoError(t, err) codeInfo := types.CodeInfoFixture(types.WithSHA256CodeHash(wasmCode)) require.NoError(t, wasmKeeper.importCode(ctx, 1, codeInfo, wasmCode)) diff --git a/x/wasm/keeper/querier_test.go b/x/wasm/keeper/querier_test.go index ae44f54e48..82a28b06e8 100644 --- a/x/wasm/keeper/querier_test.go +++ b/x/wasm/keeper/querier_test.go @@ -9,6 +9,7 @@ import ( "testing" "time" + errorsmod "cosmossdk.io/errors" wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/cometbft/cometbft/libs/log" @@ -42,7 +43,7 @@ func TestQueryAllContractState(t *testing.T) { srcQuery *types.QueryAllContractStateRequest expModelContains []types.Model expModelContainsNot []types.Model - expErr *sdkErrors.Error + expErr *errorsmod.Error }{ "query all": { srcQuery: &types.QueryAllContractStateRequest{Address: contractAddr.String()}, @@ -167,7 +168,7 @@ func TestQuerySmartContractPanics(t *testing.T) { specs := map[string]struct { doInContract func() - expErr *sdkErrors.Error + expErr *errorsmod.Error }{ "out of gas": { doInContract: func() { @@ -216,7 +217,7 @@ func TestQueryRawContractState(t *testing.T) { specs := map[string]struct { srcQuery *types.QueryRawContractStateRequest expData []byte - expErr *sdkErrors.Error + expErr *errorsmod.Error }{ "query raw key": { srcQuery: &types.QueryRawContractStateRequest{Address: contractAddr, QueryData: []byte("foo")}, @@ -553,7 +554,8 @@ func TestQueryContractInfo(t *testing.T) { myExt, err := govv1beta1.NewProposal(&govv1beta1.TextProposal{Title: "foo", Description: "bar"}, 1, anyDate, anyDate) require.NoError(t, err) myExt.TotalDeposit = nil - info.SetExtension(&myExt) + err = info.SetExtension(&myExt) + require.NoError(t, err) } specs := map[string]struct { src *types.QueryContractInfoRequest @@ -612,7 +614,7 @@ func TestQueryPinnedCodes(t *testing.T) { specs := map[string]struct { srcQuery *types.QueryPinnedCodesRequest expCodeIDs []uint64 - expErr *sdkErrors.Error + expErr *errorsmod.Error }{ "query all": { srcQuery: &types.QueryPinnedCodesRequest{}, @@ -671,10 +673,11 @@ func TestQueryParams(t *testing.T) { require.Equal(t, paramsResponse.Params.CodeUploadAccess, defaultParams.CodeUploadAccess) require.Equal(t, paramsResponse.Params.InstantiateDefaultPermission, defaultParams.InstantiateDefaultPermission) - keeper.SetParams(ctx, types.Params{ + err = keeper.SetParams(ctx, types.Params{ CodeUploadAccess: types.AllowNobody, InstantiateDefaultPermission: types.AccessTypeNobody, }) + require.NoError(t, err) paramsResponse, err = q.Params(sdk.WrapSDKContext(ctx), &types.QueryParamsRequest{}) require.NoError(t, err) @@ -694,19 +697,19 @@ func TestQueryCodeInfo(t *testing.T) { anyAddress, err := sdk.AccAddressFromBech32("cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz") require.NoError(t, err) specs := map[string]struct { - codeId uint64 + codeID uint64 accessConfig types.AccessConfig }{ "everybody": { - codeId: 1, + codeID: 1, accessConfig: types.AllowEverybody, }, "nobody": { - codeId: 10, + codeID: 10, accessConfig: types.AllowNobody, }, "with_address": { - codeId: 20, + codeID: 20, accessConfig: types.AccessTypeOnlyAddress.With(anyAddress), }, } @@ -714,19 +717,19 @@ func TestQueryCodeInfo(t *testing.T) { t.Run(msg, func(t *testing.T) { codeInfo := types.CodeInfoFixture(types.WithSHA256CodeHash(wasmCode)) codeInfo.InstantiateConfig = spec.accessConfig - require.NoError(t, keeper.importCode(ctx, spec.codeId, + require.NoError(t, keeper.importCode(ctx, spec.codeID, codeInfo, wasmCode), ) q := Querier(keeper) got, err := q.Code(sdk.WrapSDKContext(ctx), &types.QueryCodeRequest{ - CodeId: spec.codeId, + CodeId: spec.codeID, }) require.NoError(t, err) expectedResponse := &types.QueryCodeResponse{ CodeInfoResponse: &types.CodeInfoResponse{ - CodeID: spec.codeId, + CodeID: spec.codeID, Creator: codeInfo.Creator, DataHash: codeInfo.CodeHash, InstantiatePermission: spec.accessConfig, @@ -756,22 +759,22 @@ func TestQueryCodeInfoList(t *testing.T) { codes := []struct { name string - codeId uint64 + codeID uint64 codeInfo types.CodeInfo }{ { name: "everybody", - codeId: 1, + codeID: 1, codeInfo: codeInfoWithConfig(types.AllowEverybody), }, { - codeId: 10, + codeID: 10, name: "nobody", codeInfo: codeInfoWithConfig(types.AllowNobody), }, { name: "with_address", - codeId: 20, + codeID: 20, codeInfo: codeInfoWithConfig(types.AccessTypeOnlyAddress.With(anyAddress)), }, } @@ -779,14 +782,14 @@ func TestQueryCodeInfoList(t *testing.T) { allCodesResponse := make([]types.CodeInfoResponse, 0) for _, code := range codes { t.Run(fmt.Sprintf("import_%s", code.name), func(t *testing.T) { - require.NoError(t, keeper.importCode(ctx, code.codeId, + require.NoError(t, keeper.importCode(ctx, code.codeID, code.codeInfo, wasmCode), ) }) allCodesResponse = append(allCodesResponse, types.CodeInfoResponse{ - CodeID: code.codeId, + CodeID: code.codeID, Creator: code.codeInfo.Creator, DataHash: code.codeInfo.CodeHash, InstantiatePermission: code.codeInfo.InstantiateConfig, diff --git a/x/wasm/keeper/query_plugins_test.go b/x/wasm/keeper/query_plugins_test.go index cf08693699..f70ba587d8 100644 --- a/x/wasm/keeper/query_plugins_test.go +++ b/x/wasm/keeper/query_plugins_test.go @@ -16,7 +16,6 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "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" @@ -90,8 +89,8 @@ func TestIBCQuerier(t *testing.T) { srcQuery *wasmvmtypes.IBCQuery wasmKeeper *mockWasmQueryKeeper channelKeeper *wasmtesting.MockChannelKeeper - expJsonResult string - expErr *sdkerrors.Error + expJSONResult string + expErr *errorsmod.Error }{ "query port id": { srcQuery: &wasmvmtypes.IBCQuery{ @@ -103,7 +102,7 @@ func TestIBCQuerier(t *testing.T) { }, }, channelKeeper: &wasmtesting.MockChannelKeeper{}, - expJsonResult: `{"port_id":"myIBCPortID"}`, + expJSONResult: `{"port_id":"myIBCPortID"}`, }, "query list channels - all": { srcQuery: &wasmvmtypes.IBCQuery{ @@ -112,7 +111,7 @@ func TestIBCQuerier(t *testing.T) { channelKeeper: &wasmtesting.MockChannelKeeper{ IterateChannelsFn: wasmtesting.MockChannelKeeperIterator(myExampleChannels), }, - expJsonResult: `{ + expJSONResult: `{ "channels": [ { "endpoint": { @@ -152,7 +151,7 @@ func TestIBCQuerier(t *testing.T) { channelKeeper: &wasmtesting.MockChannelKeeper{ IterateChannelsFn: wasmtesting.MockChannelKeeperIterator(myExampleChannels), }, - expJsonResult: `{ + expJSONResult: `{ "channels": [ { "endpoint": { @@ -179,7 +178,7 @@ func TestIBCQuerier(t *testing.T) { channelKeeper: &wasmtesting.MockChannelKeeper{ IterateChannelsFn: wasmtesting.MockChannelKeeperIterator(myExampleChannels), }, - expJsonResult: `{"channels": []}`, + expJSONResult: `{"channels": []}`, }, "query channel": { srcQuery: &wasmvmtypes.IBCQuery{ @@ -202,7 +201,7 @@ func TestIBCQuerier(t *testing.T) { }, true }, }, - expJsonResult: `{ + expJSONResult: `{ "channel": { "endpoint": { "port_id": "myQueryPortID", @@ -243,7 +242,7 @@ func TestIBCQuerier(t *testing.T) { }, true }, }, - expJsonResult: `{ + expJSONResult: `{ "channel": { "endpoint": { "port_id": "myLoadedPortID", @@ -279,7 +278,7 @@ func TestIBCQuerier(t *testing.T) { }, true }, }, - expJsonResult: "{}", + expJSONResult: "{}", }, "query channel in closed state": { srcQuery: &wasmvmtypes.IBCQuery{ @@ -302,7 +301,7 @@ func TestIBCQuerier(t *testing.T) { }, true }, }, - expJsonResult: "{}", + expJSONResult: "{}", }, "query channel - empty result": { srcQuery: &wasmvmtypes.IBCQuery{ @@ -316,7 +315,7 @@ func TestIBCQuerier(t *testing.T) { return channeltypes.Channel{}, false }, }, - expJsonResult: "{}", + expJSONResult: "{}", }, } for name, spec := range specs { @@ -327,7 +326,7 @@ func TestIBCQuerier(t *testing.T) { if spec.expErr != nil { return } - assert.JSONEq(t, spec.expJsonResult, string(gotResult), string(gotResult)) + assert.JSONEq(t, spec.expJSONResult, string(gotResult), string(gotResult)) }) } } @@ -567,7 +566,8 @@ func TestQueryErrors(t *testing.T) { func TestAcceptListStargateQuerier(t *testing.T) { wasmApp := app.SetupWithEmptyStore(t) ctx := wasmApp.NewUncachedContext(false, tmproto.Header{ChainID: "foo", Height: 1, Time: time.Now()}) - wasmApp.StakingKeeper.SetParams(ctx, stakingtypes.DefaultParams()) + err := wasmApp.StakingKeeper.SetParams(ctx, stakingtypes.DefaultParams()) + require.NoError(t, err) addrs := app.AddTestAddrsIncremental(wasmApp, ctx, 2, sdk.NewInt(1_000_000)) accepted := keeper.AcceptedStargateQueries{ diff --git a/x/wasm/keeper/recurse_test.go b/x/wasm/keeper/recurse_test.go index 5bfb20bdec..73647df5fe 100644 --- a/x/wasm/keeper/recurse_test.go +++ b/x/wasm/keeper/recurse_test.go @@ -38,7 +38,7 @@ type recurseResponse struct { // number os wasm queries called from a contract var totalWasmQueryCounter int -func initRecurseContract(t *testing.T) (contract sdk.AccAddress, creator sdk.AccAddress, ctx sdk.Context, keeper *Keeper) { +func initRecurseContract(t *testing.T) (contract sdk.AccAddress, creator sdk.AccAddress, ctx sdk.Context, keeper *Keeper) { //nolint:unparam 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 9f299a4465..4587a3458d 100644 --- a/x/wasm/keeper/reflect_test.go +++ b/x/wasm/keeper/reflect_test.go @@ -15,7 +15,7 @@ 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/golang/protobuf/proto" + "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -332,7 +332,7 @@ func TestReflectTotalSupplyQuery(t *testing.T) { Chain: &testdata.ChainQuery{ Request: &wasmvmtypes.QueryRequest{ Bank: &wasmvmtypes.BankQuery{ - Supply: &wasmvmtypes.SupplyQuery{spec.denom}, + Supply: &wasmvmtypes.SupplyQuery{Denom: spec.denom}, }, }, }, @@ -374,6 +374,8 @@ func TestReflectInvalidStargateQuery(t *testing.T) { Address: creator.String(), } protoQueryBin, err := proto.Marshal(&protoQuery) + require.NoError(t, err) + protoRequest := wasmvmtypes.QueryRequest{ Stargate: &wasmvmtypes.StargateQuery{ Path: "/cosmos.bank.v1beta1.Query/AllBalances", @@ -599,7 +601,7 @@ func toReflectRawMsg(cdc codec.Codec, msg sdk.Msg) (wasmvmtypes.CosmosMsg, error if err != nil { return wasmvmtypes.CosmosMsg{}, errorsmod.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } - customMsg, err := json.Marshal(reflectCustomMsg{ + customMsg, _ := json.Marshal(reflectCustomMsg{ Raw: rawBz, }) res := wasmvmtypes.CosmosMsg{ @@ -652,19 +654,10 @@ type customQueryResponse struct { Msg string `json:"msg"` } -// these are the return values from contract -> go depending on type of query -type ownerResponse struct { - Owner string `json:"owner"` -} - type capitalizedResponse struct { Text string `json:"text"` } -type chainResponse struct { - Data []byte `json:"data"` -} - // reflectPlugins needs to be registered in test setup to handle custom query callbacks func reflectPlugins() *QueryPlugins { return &QueryPlugins{ diff --git a/x/wasm/keeper/staking_test.go b/x/wasm/keeper/staking_test.go index 8e341da584..86f9cadc02 100644 --- a/x/wasm/keeper/staking_test.go +++ b/x/wasm/keeper/staking_test.go @@ -14,7 +14,6 @@ import ( distributionkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" "github.com/cosmos/cosmos-sdk/x/staking" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/cosmos/cosmos-sdk/x/staking/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -29,7 +28,7 @@ type StakingInitMsg struct { Decimals uint8 `json:"decimals"` Validator sdk.ValAddress `json:"validator"` ExitTax sdk.Dec `json:"exit_tax"` - // MinWithdrawal is uint128 encoded as a string (use sdk.Int?) + // MinWithdrawal is uint128 encoded as a string (use math.Int?) MinWithdrawl string `json:"min_withdrawal"` } @@ -87,7 +86,7 @@ type InvestmentResponse struct { Owner sdk.AccAddress `json:"owner"` Validator sdk.ValAddress `json:"validator"` ExitTax sdk.Dec `json:"exit_tax"` - // MinWithdrawl is uint128 encoded as a string (use sdk.Int?) + // MinWithdrawl is uint128 encoded as a string (use math.Int?) MinWithdrawl string `json:"min_withdrawal"` } @@ -655,10 +654,10 @@ func addValidator(t *testing.T, ctx sdk.Context, stakingKeeper *stakingkeeper.Ke pkAny, err := codectypes.NewAnyWithValue(pubKey) require.NoError(t, err) msg := &stakingtypes.MsgCreateValidator{ - Description: types.Description{ + Description: stakingtypes.Description{ Moniker: "Validator power", }, - Commission: types.CommissionRates{ + Commission: stakingtypes.CommissionRates{ Rate: sdk.MustNewDecFromStr("0.1"), MaxRate: sdk.MustNewDecFromStr("0.2"), MaxChangeRate: sdk.MustNewDecFromStr("0.01"), diff --git a/x/wasm/keeper/submsg_test.go b/x/wasm/keeper/submsg_test.go index f4828c3d3d..f2c9d7d9c2 100644 --- a/x/wasm/keeper/submsg_test.go +++ b/x/wasm/keeper/submsg_test.go @@ -501,7 +501,7 @@ func TestDispatchSubMsgConditionalReplyOn(t *testing.T) { }, } - var id uint64 = 0 + var id uint64 for name, tc := range cases { id++ t.Run(name, func(t *testing.T) { diff --git a/x/wasm/keeper/test_common.go b/x/wasm/keeper/test_common.go index bb0baba623..4586045a80 100644 --- a/x/wasm/keeper/test_common.go +++ b/x/wasm/keeper/test_common.go @@ -287,7 +287,7 @@ func createTestInput( case banktypes.ModuleName: keyTable = banktypes.ParamKeyTable() //nolint:staticcheck case stakingtypes.ModuleName: - keyTable = stakingtypes.ParamKeyTable() //nolint:staticcheck + keyTable = stakingtypes.ParamKeyTable() case minttypes.ModuleName: keyTable = minttypes.ParamKeyTable() //nolint:staticcheck case distributiontypes.ModuleName: @@ -300,11 +300,11 @@ func createTestInput( keyTable = crisistypes.ParamKeyTable() //nolint:staticcheck // ibc types case ibctransfertypes.ModuleName: - keyTable = ibctransfertypes.ParamKeyTable() //nolint:staticcheck + keyTable = ibctransfertypes.ParamKeyTable() case icahosttypes.SubModuleName: - keyTable = icahosttypes.ParamKeyTable() //nolint:staticcheck + keyTable = icahosttypes.ParamKeyTable() case icacontrollertypes.SubModuleName: - keyTable = icacontrollertypes.ParamKeyTable() //nolint:staticcheck + keyTable = icacontrollertypes.ParamKeyTable() // wasm case types.ModuleName: keyTable = types.ParamKeyTable() //nolint:staticcheck @@ -804,7 +804,7 @@ var keyCounter uint64 // we need to make this deterministic (same every test run), as encoded address size and thus gas cost, // depends on the actual bytes (due to ugly CanonicalAddress encoding) -func keyPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) { +func keyPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) { //nolint:unparam keyCounter++ seed := make([]byte, 8) binary.BigEndian.PutUint64(seed, keyCounter) diff --git a/x/wasm/migrations/v1/store_test.go b/x/wasm/migrations/v1/store_test.go index 114d5d0b79..857d0810a6 100644 --- a/x/wasm/migrations/v1/store_test.go +++ b/x/wasm/migrations/v1/store_test.go @@ -35,10 +35,17 @@ func TestMigrate1To2(t *testing.T) { // create with no balance is also legal gotContractAddr1, _, err := keepers.ContractKeeper.Instantiate(ctx.WithEventManager(em), example.CodeID, creator, nil, initMsgBz, "demo contract 1", nil) + require.NoError(t, err) ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + + // create with no balance is also legal gotContractAddr2, _, err := keepers.ContractKeeper.Instantiate(ctx.WithEventManager(em), example.CodeID, creator, nil, initMsgBz, "demo contract 1", nil) + require.NoError(t, err) ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + + // create with no balance is also legal gotContractAddr3, _, err := keepers.ContractKeeper.Instantiate(ctx.WithEventManager(em), example.CodeID, creator, nil, initMsgBz, "demo contract 1", nil) + require.NoError(t, err) info1 := wasmKeeper.GetContractInfo(ctx, gotContractAddr1) info2 := wasmKeeper.GetContractInfo(ctx, gotContractAddr2) @@ -50,7 +57,7 @@ func TestMigrate1To2(t *testing.T) { ctx.KVStore(keepers.WasmStoreKey).Delete(types.GetContractByCreatorSecondaryIndexKey(creator, info3.Created.Bytes(), gotContractAddr3)) // migrator - keeper.NewMigrator(*wasmKeeper, nil).Migrate1to2(ctx) + err = keeper.NewMigrator(*wasmKeeper, nil).Migrate1to2(ctx) require.NoError(t, err) // check new store diff --git a/x/wasm/module.go b/x/wasm/module.go index 6bf49b3d73..b92fce647a 100644 --- a/x/wasm/module.go +++ b/x/wasm/module.go @@ -47,7 +47,7 @@ const ( // AppModuleBasic defines the basic application module used by the wasm module. type AppModuleBasic struct{} -func (b AppModuleBasic) RegisterLegacyAminoCodec(amino *codec.LegacyAmino) { //nolint:staticcheck +func (b AppModuleBasic) RegisterLegacyAminoCodec(amino *codec.LegacyAmino) { RegisterCodec(amino) } @@ -210,7 +210,7 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { // ProposalContents doesn't return any content functions for governance proposals. // -//nolint:staticcheck + func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { return simulation.ProposalContents(am.bankKeeper, am.keeper) } diff --git a/x/wasm/module_test.go b/x/wasm/module_test.go index 9419712f12..012588c808 100644 --- a/x/wasm/module_test.go +++ b/x/wasm/module_test.go @@ -79,7 +79,7 @@ func setupTest(t *testing.T) testData { return data } -func keyPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) { +func keyPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) { //nolint:unparam key := ed25519.GenPrivKey() pub := key.PubKey() addr := sdk.AccAddress(pub.Address()) @@ -381,7 +381,7 @@ func TestHandleExecuteEscrow(t *testing.T) { } h := data.msgServiceRouter.Handler(msg) - res, err := h(data.ctx, msg) + _, err := h(data.ctx, msg) require.NoError(t, err) _, _, bob := keyPubAddr() @@ -400,7 +400,7 @@ func TestHandleExecuteEscrow(t *testing.T) { Label: "testing", } h = data.msgServiceRouter.Handler(&initCmd) - res, err = h(data.ctx, &initCmd) + res, err := h(data.ctx, &initCmd) require.NoError(t, err) contractBech32Addr := parseInitResponse(t, res.Data) require.Equal(t, "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr", contractBech32Addr) @@ -544,13 +544,13 @@ func prettyAttrs(attrs []abci.EventAttribute) []sdk.Attribute { } func prettyAttr(attr abci.EventAttribute) sdk.Attribute { - return sdk.NewAttribute(string(attr.Key), string(attr.Value)) + return sdk.NewAttribute(attr.Key, attr.Value) } func assertAttribute(t *testing.T, key string, value string, attr abci.EventAttribute) { t.Helper() - assert.Equal(t, key, string(attr.Key), prettyAttr(attr)) - assert.Equal(t, value, string(attr.Value), prettyAttr(attr)) + assert.Equal(t, key, attr.Key, prettyAttr(attr)) + assert.Equal(t, value, attr.Value, prettyAttr(attr)) } func assertCodeList(t *testing.T, q *baseapp.GRPCQueryRouter, ctx sdk.Context, expectedNum int, marshaler codec.Codec) { @@ -571,7 +571,7 @@ func assertCodeList(t *testing.T, q *baseapp.GRPCQueryRouter, ctx sdk.Context, e assert.Equal(t, expectedNum, len(res.CodeInfos)) } -func assertCodeBytes(t *testing.T, q *baseapp.GRPCQueryRouter, ctx sdk.Context, codeID uint64, expectedBytes []byte, marshaler codec.Codec) { +func assertCodeBytes(t *testing.T, q *baseapp.GRPCQueryRouter, ctx sdk.Context, codeID uint64, expectedBytes []byte, marshaler codec.Codec) { //nolint:unparam t.Helper() bz, err := marshaler.Marshal(&types.QueryCodeRequest{CodeId: codeID}) require.NoError(t, err) @@ -591,7 +591,7 @@ func assertCodeBytes(t *testing.T, q *baseapp.GRPCQueryRouter, ctx sdk.Context, assert.Equal(t, expectedBytes, rsp.Data) } -func assertContractList(t *testing.T, q *baseapp.GRPCQueryRouter, ctx sdk.Context, codeID uint64, expContractAddrs []string, marshaler codec.Codec) { +func assertContractList(t *testing.T, q *baseapp.GRPCQueryRouter, ctx sdk.Context, codeID uint64, expContractAddrs []string, marshaler codec.Codec) { //nolint:unparam t.Helper() bz, err := marshaler.Marshal(&types.QueryContractsByCodeRequest{CodeId: codeID}) require.NoError(t, err) @@ -610,7 +610,7 @@ func assertContractList(t *testing.T, q *baseapp.GRPCQueryRouter, ctx sdk.Contex require.NoError(t, marshaler.Unmarshal(bz, &rsp)) hasAddrs := make([]string, len(rsp.Contracts)) - for i, r := range rsp.Contracts { + for i, r := range rsp.Contracts { //nolint:gosimple hasAddrs[i] = r } assert.Equal(t, expContractAddrs, hasAddrs) @@ -634,7 +634,7 @@ func assertContractState(t *testing.T, q *baseapp.GRPCQueryRouter, ctx sdk.Conte assert.Equal(t, expectedBz, rsp.Data) } -func assertContractInfo(t *testing.T, q *baseapp.GRPCQueryRouter, ctx sdk.Context, contractBech32Addr string, codeID uint64, creator sdk.AccAddress, marshaler codec.Codec) { +func assertContractInfo(t *testing.T, q *baseapp.GRPCQueryRouter, ctx sdk.Context, contractBech32Addr string, codeID uint64, creator sdk.AccAddress, marshaler codec.Codec) { //nolint:unparam t.Helper() bz, err := marshaler.Marshal(&types.QueryContractInfoRequest{Address: contractBech32Addr}) require.NoError(t, err) diff --git a/x/wasm/relay_pingpong_test.go b/x/wasm/relay_pingpong_test.go index dcae028f7c..1968bb46dd 100644 --- a/x/wasm/relay_pingpong_test.go +++ b/x/wasm/relay_pingpong_test.go @@ -10,7 +10,6 @@ import ( wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" - "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/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" @@ -199,20 +198,6 @@ var ( // store keys maxValueKey = []byte("max-value") ) -func (p player) loadEndpoints(store prefix.Store, channelID string) *connectedChannelsModel { - var counterparties []connectedChannelsModel - if bz := store.Get(ibcEndpointsKey); bz != nil { - require.NoError(p.t, json.Unmarshal(bz, &counterparties)) - } - for _, v := range counterparties { - if v.Our.ChannelID == channelID { - return &v - } - } - p.t.Fatalf("no counterparty found for channel %q", channelID) - return nil -} - func (p player) storeEndpoint(store wasmvm.KVStore, channel wasmvmtypes.IBCChannel) { var counterparties []connectedChannelsModel if b := store.Get(ibcEndpointsKey); b != nil { @@ -339,7 +324,7 @@ func counterParty(s string) string { // hit is ibc packet payload type hit map[string]uint64 -func NewHit(player string, count uint64) hit { +func NewHit(player string, count uint64) hit { //nolint:revive // no need to make this public return map[string]uint64{ player: count, } diff --git a/x/wasm/relay_test.go b/x/wasm/relay_test.go index 4a25d0b89f..f94f759964 100644 --- a/x/wasm/relay_test.go +++ b/x/wasm/relay_test.go @@ -7,6 +7,7 @@ import ( "time" 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" @@ -33,8 +34,8 @@ func TestFromIBCTransferToContract(t *testing.T) { specs := map[string]struct { contract wasmtesting.IBCContractCallbacks setupContract func(t *testing.T, contract wasmtesting.IBCContractCallbacks, chain *wasmibctesting.TestChain) - expChainABalanceDiff sdk.Int - expChainBBalanceDiff sdk.Int + expChainABalanceDiff math.Int + expChainBBalanceDiff math.Int }{ "ack": { contract: &ackReceiverContract{}, @@ -600,7 +601,7 @@ func (s *sendEmulatedIBCTransferContract) Execute(code wasmvm.Checksum, env wasm return &wasmvmtypes.Response{Messages: []wasmvmtypes.SubMsg{{ReplyOn: wasmvmtypes.ReplyNever, Msg: wasmvmtypes.CosmosMsg{IBC: ibcMsg}}}}, 0, nil } -func (c *sendEmulatedIBCTransferContract) IBCPacketTimeout(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCPacketTimeoutMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) { +func (s *sendEmulatedIBCTransferContract) IBCPacketTimeout(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCPacketTimeoutMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) { packet := msg.Packet var data ibctransfertypes.FungibleTokenPacketData @@ -626,14 +627,13 @@ var _ wasmtesting.IBCContractCallbacks = &closeChannelContract{} type closeChannelContract struct { contractStub - t *testing.T } func (c *closeChannelContract) IBCChannelClose(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelCloseMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) { return &wasmvmtypes.IBCBasicResponse{}, 1, nil } -func (s *closeChannelContract) Execute(code 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) { +func (c *closeChannelContract) Execute(code 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) { var in closeIBCChannel if err := json.Unmarshal(executeMsg, &in); err != nil { return nil, 0, err diff --git a/x/wasm/simulation/proposals.go b/x/wasm/simulation/proposals.go index 6c53f3acf7..fe6017e593 100644 --- a/x/wasm/simulation/proposals.go +++ b/x/wasm/simulation/proposals.go @@ -26,7 +26,6 @@ const ( WeightStoreAndInstantiateContractProposal = "weight_store_and_instantiate_contract_proposal" ) -//nolint:staticcheck func ProposalContents(bk BankKeeper, wasmKeeper WasmKeeper) []simtypes.WeightedProposalContent { return []simtypes.WeightedProposalContent{ // simulation.NewWeightedProposalContent( @@ -125,7 +124,7 @@ func ProposalContents(bk BankKeeper, wasmKeeper WasmKeeper) []simtypes.WeightedP // Current problem: out of gas (defaul gaswanted config of gov SimulateMsgSubmitProposal is 10_000_000) // but this proposal may need more than it // -//nolint:staticcheck + func SimulateStoreCodeProposal(wasmKeeper WasmKeeper) simtypes.ContentSimulatorFn { return func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content { simAccount, _ := simtypes.RandomAcc(r, accs) @@ -150,7 +149,7 @@ func SimulateStoreCodeProposal(wasmKeeper WasmKeeper) simtypes.ContentSimulatorF // Simulate instantiate contract proposal // -//nolint:staticcheck + func SimulateInstantiateContractProposal(bk BankKeeper, wasmKeeper WasmKeeper, codeSelector CodeIDSelector) simtypes.ContentSimulatorFn { return func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content { simAccount, _ := simtypes.RandomAcc(r, accs) @@ -177,7 +176,7 @@ func SimulateInstantiateContractProposal(bk BankKeeper, wasmKeeper WasmKeeper, c // Simulate execute contract proposal // -//nolint:staticcheck + func SimulateExecuteContractProposal( bk BankKeeper, wasmKeeper WasmKeeper, @@ -239,7 +238,7 @@ func DefaultSimulateUpdateAdminProposalContractSelector( // Simulate update admin contract proposal // -//nolint:staticcheck + func SimulateUpdateAdminProposal(wasmKeeper WasmKeeper, contractSelector UpdateAdminContractSelector) simtypes.ContentSimulatorFn { return func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content { simAccount, _ := simtypes.RandomAcc(r, accs) @@ -273,7 +272,7 @@ func DefaultSimulateContractSelector( // Simulate clear admin proposal // -//nolint:staticcheck + func SimulateClearAdminProposal(wasmKeeper WasmKeeper, contractSelector ClearAdminContractSelector) simtypes.ContentSimulatorFn { return func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content { ctAddress := contractSelector(ctx, wasmKeeper) @@ -293,7 +292,7 @@ type MigrateContractProposalContractSelector func(sdk.Context, WasmKeeper) sdk.A // Simulate migrate contract proposal // -//nolint:staticcheck + func SimulateMigrateContractProposal(wasmKeeper WasmKeeper, contractSelector MigrateContractProposalContractSelector, codeSelector CodeIDSelector) simtypes.ContentSimulatorFn { return func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content { ctAddress := contractSelector(ctx, wasmKeeper) @@ -320,7 +319,7 @@ type SudoContractProposalContractSelector func(sdk.Context, WasmKeeper) sdk.AccA // Simulate sudo contract proposal // -//nolint:staticcheck + func SimulateSudoContractProposal(wasmKeeper WasmKeeper, contractSelector SudoContractProposalContractSelector) simtypes.ContentSimulatorFn { return func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content { ctAddress := contractSelector(ctx, wasmKeeper) @@ -339,7 +338,7 @@ func SimulateSudoContractProposal(wasmKeeper WasmKeeper, contractSelector SudoCo // Simulate pin contract proposal // -//nolint:staticcheck + func SimulatePinContractProposal(wasmKeeper WasmKeeper, codeSelector CodeIDSelector) simtypes.ContentSimulatorFn { return func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content { codeID := codeSelector(ctx, wasmKeeper) @@ -357,7 +356,7 @@ func SimulatePinContractProposal(wasmKeeper WasmKeeper, codeSelector CodeIDSelec // Simulate unpin contract proposal // -//nolint:staticcheck + func SimulateUnpinContractProposal(wasmKeeper WasmKeeper, codeSelector CodeIDSelector) simtypes.ContentSimulatorFn { return func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content { codeID := codeSelector(ctx, wasmKeeper) @@ -375,7 +374,7 @@ func SimulateUnpinContractProposal(wasmKeeper WasmKeeper, codeSelector CodeIDSel // Simulate update instantiate config proposal // -//nolint:staticcheck + func SimulateUpdateInstantiateConfigProposal(wasmKeeper WasmKeeper, codeSelector CodeIDSelector) simtypes.ContentSimulatorFn { return func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content { codeID := codeSelector(ctx, wasmKeeper) @@ -400,7 +399,6 @@ func SimulateUpdateInstantiateConfigProposal(wasmKeeper WasmKeeper, codeSelector } } -//nolint:staticcheck func SimulateStoreAndInstantiateContractProposal(wasmKeeper WasmKeeper) simtypes.ContentSimulatorFn { return func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content { simAccount, _ := simtypes.RandomAcc(r, accs) diff --git a/x/wasm/types/authz_test.go b/x/wasm/types/authz_test.go index 06747693fc..79d279b258 100644 --- a/x/wasm/types/authz_test.go +++ b/x/wasm/types/authz_test.go @@ -4,6 +4,7 @@ import ( "math" "testing" + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authztypes "github.com/cosmos/cosmos-sdk/x/authz" @@ -539,7 +540,7 @@ func TestAcceptGrantedMessage(t *testing.T) { auth authztypes.Authorization msg sdk.Msg expResult authztypes.AcceptResponse - expErr *sdkerrors.Error + expErr *errorsmod.Error }{ "accepted and updated - contract execution": { auth: NewContractExecutionAuthorization(mustGrant(myContractAddr, NewMaxCallsLimit(2), NewAllowAllMessagesFilter())), diff --git a/x/wasm/types/codec.go b/x/wasm/types/codec.go index 29da4391b2..d486ea60e2 100644 --- a/x/wasm/types/codec.go +++ b/x/wasm/types/codec.go @@ -14,7 +14,7 @@ import ( ) // RegisterLegacyAminoCodec registers the account types and interface -func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { //nolint:staticcheck +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&MsgStoreCode{}, "wasm/MsgStoreCode", nil) cdc.RegisterConcrete(&MsgInstantiateContract{}, "wasm/MsgInstantiateContract", nil) cdc.RegisterConcrete(&MsgInstantiateContract2{}, "wasm/MsgInstantiateContract2", nil) diff --git a/x/wasm/types/errors_test.go b/x/wasm/types/errors_test.go index 76a1c0239c..495f5e828b 100644 --- a/x/wasm/types/errors_test.go +++ b/x/wasm/types/errors_test.go @@ -4,8 +4,8 @@ import ( "errors" "testing" + errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -17,7 +17,7 @@ func TestWasmVMFlavouredError(t *testing.T) { }{ "IsOf": { exec: func(t *testing.T) { - assert.True(t, sdkerrors.IsOf(myErr, myErr.sdkErr)) + assert.True(t, errorsmod.IsOf(myErr, myErr.sdkErr)) assert.Equal(t, myErr.sdkErr, myErr.Unwrap()) }, }, @@ -65,7 +65,7 @@ func TestWasmVMFlavouredError(t *testing.T) { }, "abci info": { exec: func(t *testing.T) { - codespace, code, log := sdkerrors.ABCIInfo(myErr, false) + codespace, code, log := errorsmod.ABCIInfo(myErr, false) assert.Equal(t, DefaultCodespace, codespace) assert.Equal(t, uint32(28), code) assert.Equal(t, "no such code", log) @@ -73,7 +73,7 @@ func TestWasmVMFlavouredError(t *testing.T) { }, "abci info - wrapped": { exec: func(t *testing.T) { - codespace, code, log := sdkerrors.ABCIInfo(myErr.Wrap("my description"), false) + codespace, code, log := errorsmod.ABCIInfo(myErr.Wrap("my description"), false) assert.Equal(t, DefaultCodespace, codespace) assert.Equal(t, uint32(28), code) assert.Equal(t, "my description: no such code", log) diff --git a/x/wasm/types/genesis_test.go b/x/wasm/types/genesis_test.go index 7cb28a98f0..258528c999 100644 --- a/x/wasm/types/genesis_test.go +++ b/x/wasm/types/genesis_test.go @@ -14,6 +14,8 @@ import ( "github.com/stretchr/testify/require" ) +const invalidAddress = "invalid address" + func TestValidateGenesisState(t *testing.T) { specs := map[string]struct { srcMutator func(*GenesisState) @@ -36,7 +38,7 @@ func TestValidateGenesisState(t *testing.T) { }, "contract invalid": { srcMutator: func(s *GenesisState) { - s.Contracts[0].ContractAddress = "invalid" + s.Contracts[0].ContractAddress = invalidAddress }, expError: true, }, @@ -118,13 +120,13 @@ func TestContractValidateBasic(t *testing.T) { "all good": {srcMutator: func(_ *Contract) {}}, "contract address invalid": { srcMutator: func(c *Contract) { - c.ContractAddress = "invalid" + c.ContractAddress = invalidAddress }, expError: true, }, "contract info invalid": { srcMutator: func(c *Contract) { - c.ContractInfo.Creator = "invalid" + c.ContractInfo.Creator = invalidAddress }, expError: true, }, diff --git a/x/wasm/types/json_matching_test.go b/x/wasm/types/json_matching_test.go index 01d2d3efd3..286fde3969 100644 --- a/x/wasm/types/json_matching_test.go +++ b/x/wasm/types/json_matching_test.go @@ -81,11 +81,11 @@ func TestIsJSONObjectWithTopLevelKey(t *testing.T) { expResult: false, }, // not supported: https://github.com/golang/go/issues/24415 - //"errors for duplicate key": { + // "errors for duplicate key": { // src: []byte(`{"claim": "foo", "claim":"bar"}`), // allowedKeys: []string{"claim"}, // expErr: ErrNotAJSONObject, - //}, + // }, // Not one top-level key "false for no top-level key": { diff --git a/x/wasm/types/keys.go b/x/wasm/types/keys.go index ec4f4082a9..4f605872d6 100644 --- a/x/wasm/types/keys.go +++ b/x/wasm/types/keys.go @@ -22,7 +22,6 @@ const ( RouterKey = ModuleName ) -// nolint var ( CodeKeyPrefix = []byte{0x01} ContractKeyPrefix = []byte{0x02} diff --git a/x/wasm/types/keys_test.go b/x/wasm/types/keys_test.go index 3db6bbadfe..a5cbce7358 100644 --- a/x/wasm/types/keys_test.go +++ b/x/wasm/types/keys_test.go @@ -123,6 +123,7 @@ func TestGetContractByCreatorSecondaryIndexKey(t *testing.T) { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, } + assert.Equal(t, exp, got) // test that creator is contract addresses of 32 length contractAddr = bytes.Repeat([]byte{4}, 32) diff --git a/x/wasm/types/proposal_test.go b/x/wasm/types/proposal_test.go index 901bd1a47a..8952f8cf93 100644 --- a/x/wasm/types/proposal_test.go +++ b/x/wasm/types/proposal_test.go @@ -94,10 +94,7 @@ func TestValidateProposalCommons(t *testing.T) { } func TestValidateStoreCodeProposal(t *testing.T) { - var ( - anyAddress sdk.AccAddress = bytes.Repeat([]byte{0x0}, ContractAddrLen) - invalidAddress = "invalid address" - ) + var anyAddress sdk.AccAddress = bytes.Repeat([]byte{0x0}, ContractAddrLen) specs := map[string]struct { src *StoreCodeProposal @@ -187,8 +184,6 @@ func TestValidateStoreCodeProposal(t *testing.T) { } func TestValidateInstantiateContractProposal(t *testing.T) { - invalidAddress := "invalid address" - specs := map[string]struct { src *InstantiateContractProposal expErr bool @@ -280,8 +275,6 @@ func TestValidateInstantiateContractProposal(t *testing.T) { } func TestValidateInstantiateContract2Proposal(t *testing.T) { - invalidAddress := "invalid address" - specs := map[string]struct { src *InstantiateContract2Proposal expErr bool @@ -379,10 +372,7 @@ func TestValidateInstantiateContract2Proposal(t *testing.T) { } func TestValidateStoreAndInstantiateContractProposal(t *testing.T) { - var ( - anyAddress sdk.AccAddress = bytes.Repeat([]byte{0x0}, ContractAddrLen) - invalidAddress = "invalid address" - ) + var anyAddress sdk.AccAddress = bytes.Repeat([]byte{0x0}, ContractAddrLen) specs := map[string]struct { src *StoreAndInstantiateContractProposal @@ -577,8 +567,6 @@ func TestValidateMigrateContractProposal(t *testing.T) { } func TestValidateSudoContractProposal(t *testing.T) { - invalidAddress := "invalid address" - specs := map[string]struct { src *SudoContractProposal expErr bool @@ -630,8 +618,6 @@ func TestValidateSudoContractProposal(t *testing.T) { } func TestValidateExecuteContractProposal(t *testing.T) { - invalidAddress := "invalid address" - specs := map[string]struct { src *ExecuteContractProposal expErr bool @@ -689,8 +675,6 @@ func TestValidateExecuteContractProposal(t *testing.T) { } func TestValidateUpdateAdminProposal(t *testing.T) { - invalidAddress := "invalid address" - specs := map[string]struct { src *UpdateAdminProposal expErr bool @@ -742,8 +726,6 @@ func TestValidateUpdateAdminProposal(t *testing.T) { } func TestValidateClearAdminProposal(t *testing.T) { - invalidAddress := "invalid address" - specs := map[string]struct { src *ClearAdminProposal expErr bool diff --git a/x/wasm/types/query.pb.gw.go b/x/wasm/types/query.pb.gw.go index 32f3fd25cd..8a6dd28a79 100644 --- a/x/wasm/types/query.pb.gw.go +++ b/x/wasm/types/query.pb.gw.go @@ -14,7 +14,7 @@ import ( "net/http" "github.com/golang/protobuf/descriptor" - "github.com/golang/protobuf/proto" + "github.com/cosmos/gogoproto/proto" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/grpc-ecosystem/grpc-gateway/utilities" "google.golang.org/grpc" diff --git a/x/wasm/types/types_test.go b/x/wasm/types/types_test.go index 6450078504..d4a84999fe 100644 --- a/x/wasm/types/types_test.go +++ b/x/wasm/types/types_test.go @@ -10,7 +10,6 @@ import ( wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/cometbft/cometbft/libs/rand" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" @@ -33,7 +32,7 @@ func TestContractInfoValidateBasic(t *testing.T) { expError: true, }, "creator not an address": { - srcMutator: func(c *ContractInfo) { c.Creator = "invalid address" }, + srcMutator: func(c *ContractInfo) { c.Creator = invalidAddress }, expError: true, }, "admin empty": { @@ -41,7 +40,7 @@ func TestContractInfoValidateBasic(t *testing.T) { expError: false, }, "admin not an address": { - srcMutator: func(c *ContractInfo) { c.Admin = "invalid address" }, + srcMutator: func(c *ContractInfo) { c.Admin = invalidAddress }, expError: true, }, "label empty": { @@ -102,7 +101,7 @@ func TestCodeInfoValidateBasic(t *testing.T) { expError: true, }, "creator not an address": { - srcMutator: func(c *CodeInfo) { c.Creator = "invalid address" }, + srcMutator: func(c *CodeInfo) { c.Creator = invalidAddress }, expError: true, }, "Instantiate config invalid": { @@ -186,7 +185,7 @@ func TestContractInfoMarshalUnmarshal(t *testing.T) { err = src.SetExtension(&myExtension) require.NoError(t, err) - interfaceRegistry := types.NewInterfaceRegistry() + interfaceRegistry := codectypes.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) RegisterInterfaces(interfaceRegistry) // register proposal as extension type @@ -228,7 +227,8 @@ func TestContractInfoReadExtension(t *testing.T) { }{ "all good": { setup: func(i *ContractInfo) { - i.SetExtension(&myExtension) + err = i.SetExtension(&myExtension) + require.NoError(t, err) }, param: func() ContractInfoExtension { return &v1beta1.Proposal{} @@ -245,7 +245,8 @@ func TestContractInfoReadExtension(t *testing.T) { }, "nil argument value": { setup: func(i *ContractInfo) { - i.SetExtension(&myExtension) + err = i.SetExtension(&myExtension) + require.NoError(t, err) }, param: func() ContractInfoExtension { return nil @@ -254,7 +255,8 @@ func TestContractInfoReadExtension(t *testing.T) { }, "non matching types": { setup: func(i *ContractInfo) { - i.SetExtension(&myExtension) + err = i.SetExtension(&myExtension) + require.NoError(t, err) }, param: func() ContractInfoExtension { return &v1beta1.TextProposal{}