diff --git a/.golangci.yml b/.golangci.yml index de978f68af..fb4b6d6a57 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -27,6 +27,7 @@ linters: - revive - stylecheck - typecheck + - thelper - unconvert - unused @@ -59,6 +60,9 @@ issues: - 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 diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index e4579c5b23..ea7c9f5ed6 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -59,6 +59,7 @@ type ( ) func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite { + t.Helper() cdc := codectestutil.CodecOptions{}.NewCodec() baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) @@ -86,6 +87,7 @@ func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite } func NewBaseAppSuiteWithSnapshots(t *testing.T, cfg SnapshotsConfig, opts ...func(*baseapp.BaseApp)) *BaseAppSuite { + t.Helper() snapshotTimeout := 1 * time.Minute snapshotStore, err := snapshots.NewStore(dbm.NewMemDB(), testutil.GetTempDir(t)) require.NoError(t, err) @@ -232,6 +234,7 @@ func TestSetLoader(t *testing.T) { } initStore := func(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { + t.Helper() rs := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing)) @@ -252,6 +255,7 @@ func TestSetLoader(t *testing.T) { } checkStore := func(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte) { + t.Helper() rs := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningDefault)) diff --git a/baseapp/grpcrouter_test.go b/baseapp/grpcrouter_test.go index b98231b653..593125c692 100644 --- a/baseapp/grpcrouter_test.go +++ b/baseapp/grpcrouter_test.go @@ -118,6 +118,7 @@ func TestQueryDataRaces_uniqueConnectionsToSameHandler(t *testing.T) { } func testQueryDataRacesSameHandler(t *testing.T, makeClientConn func(*baseapp.GRPCQueryRouter) *baseapp.QueryServiceTestHelper) { + t.Helper() t.Parallel() qr := baseapp.NewGRPCQueryRouter() diff --git a/baseapp/utils_test.go b/baseapp/utils_test.go index 4c5f23e255..efa670af5b 100644 --- a/baseapp/utils_test.go +++ b/baseapp/utils_test.go @@ -160,6 +160,7 @@ func incrementCounter(ctx context.Context, deliverKey []byte, msg sdk.Msg, ) (*baseapptestutil.MsgCreateCounterResponse, error) { + t.Helper() sdkCtx := sdk.UnwrapSDKContext(ctx) store := sdkCtx.KVStore(capKey) @@ -202,6 +203,7 @@ func counterEvent(evType string, msgCount int64) sdk.Events { } func anteHandlerTxTest(t *testing.T, capKey storetypes.StoreKey, storeKey []byte) sdk.AnteHandler { + t.Helper() return func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) { store := ctx.KVStore(capKey) counter, failOnAnte := parseTxMemo(t, tx) @@ -225,6 +227,7 @@ func anteHandlerTxTest(t *testing.T, capKey storetypes.StoreKey, storeKey []byte } func incrementingCounter(t *testing.T, store storetypes.KVStore, counterKey []byte, counter int64) (*sdk.Result, error) { + t.Helper() storedCounter := getIntFromStore(t, store, counterKey) require.Equal(t, storedCounter, counter) setIntOnStore(store, counterKey, counter+1) @@ -275,6 +278,7 @@ func (ps paramStore) Get(_ context.Context) (cmtproto.ConsensusParams, error) { } func setTxSignature(t *testing.T, builder client.TxBuilder, nonce uint64) { + t.Helper() privKey := secp256k1.GenPrivKeyFromSecret([]byte("test")) pubKey := privKey.PubKey() err := builder.SetSignatures( @@ -288,6 +292,7 @@ func setTxSignature(t *testing.T, builder client.TxBuilder, nonce uint64) { } func testLoadVersionHelper(t *testing.T, app *baseapp.BaseApp, expectedHeight int64, expectedID storetypes.CommitID) { + t.Helper() lastHeight := app.LastBlockHeight() lastID := app.LastCommitID() require.Equal(t, expectedHeight, lastHeight) @@ -309,6 +314,7 @@ func getFinalizeBlockStateCtx(app *baseapp.BaseApp) sdk.Context { } func parseTxMemo(t *testing.T, tx sdk.Tx) (counter int64, failOnAnte bool) { + t.Helper() txWithMemo, ok := tx.(sdk.TxWithMemo) require.True(t, ok) @@ -324,6 +330,7 @@ func parseTxMemo(t *testing.T, tx sdk.Tx) (counter int64, failOnAnte bool) { } func newTxCounter(t *testing.T, cfg client.TxConfig, counter int64, msgCounters ...int64) signing.Tx { + t.Helper() _, _, addr := testdata.KeyTestPubAddr() msgs := make([]sdk.Msg, 0, len(msgCounters)) for _, c := range msgCounters { @@ -340,6 +347,7 @@ func newTxCounter(t *testing.T, cfg client.TxConfig, counter int64, msgCounters } func getIntFromStore(t *testing.T, store storetypes.KVStore, key []byte) int64 { + t.Helper() bz := store.Get(key) if len(bz) == 0 { return 0 @@ -352,6 +360,7 @@ func getIntFromStore(t *testing.T, store storetypes.KVStore, key []byte) int64 { } func setFailOnAnte(t *testing.T, cfg client.TxConfig, tx signing.Tx, failOnAnte bool) signing.Tx { + t.Helper() builder := cfg.NewTxBuilder() builder.SetMsgs(tx.GetMsgs()...) diff --git a/client/config/config_test.go b/client/config/config_test.go index 42248b194b..0caf5d9777 100644 --- a/client/config/config_test.go +++ b/client/config/config_test.go @@ -24,6 +24,7 @@ const ( // initClientContext initiates client Context for tests func initClientContext(t *testing.T, envVar string) (client.Context, func()) { + t.Helper() home := t.TempDir() chainID := "test-chain" clientCtx := client.Context{}. diff --git a/client/keys/list_test.go b/client/keys/list_test.go index 9fd0b70fb2..354ea1b12a 100644 --- a/client/keys/list_test.go +++ b/client/keys/list_test.go @@ -20,6 +20,7 @@ import ( ) func cleanupKeys(t *testing.T, kb keyring.Keyring, keys ...string) func() { + t.Helper() return func() { for _, k := range keys { if err := kb.Delete(k); err != nil { diff --git a/client/tx/aux_builder_test.go b/client/tx/aux_builder_test.go index 9a967192e5..98f33c25a9 100644 --- a/client/tx/aux_builder_test.go +++ b/client/tx/aux_builder_test.go @@ -234,6 +234,7 @@ func TestAuxTxBuilder(t *testing.T) { // checkCorrectData that the auxSignerData's content matches the inputs we gave. func checkCorrectData(t *testing.T, cdc codec.Codec, auxSignerData typestx.AuxSignerData, signMode signing.SignMode) { + t.Helper() pkAny, err := codectypes.NewAnyWithValue(pub1) require.NoError(t, err) msgAny, err := codectypes.NewAnyWithValue(msg1) diff --git a/client/v2/autocli/common_test.go b/client/v2/autocli/common_test.go index 0e9eb59b0e..7f9eb92e26 100644 --- a/client/v2/autocli/common_test.go +++ b/client/v2/autocli/common_test.go @@ -20,6 +20,7 @@ import ( ) func testExecCommon(t *testing.T, buildModuleCommand func(string, *Builder) (*cobra.Command, error), args ...string) *testClientConn { + t.Helper() server := grpc.NewServer() testpb.RegisterQueryServer(server, &testEchoServer{}) reflectionv2alpha1.RegisterReflectionServiceServer(server, &testReflectionServer{}) @@ -70,6 +71,7 @@ func testExecCommon(t *testing.T, buildModuleCommand func(string, *Builder) (*co } func testExecCommonWithErr(t *testing.T, expectedErr string, buildModuleCommand func(string, *Builder) (*cobra.Command, error), args ...string) { + t.Helper() server := grpc.NewServer() testpb.RegisterQueryServer(server, &testEchoServer{}) reflectionv2alpha1.RegisterReflectionServiceServer(server, &testReflectionServer{}) diff --git a/client/v2/internal/strcase/kebab_test.go b/client/v2/internal/strcase/kebab_test.go index 1c82f3ab3b..120b98472b 100644 --- a/client/v2/internal/strcase/kebab_test.go +++ b/client/v2/internal/strcase/kebab_test.go @@ -8,7 +8,8 @@ import ( "cosmossdk.io/client/v2/internal/strcase" ) -func toKebab(t testing.TB) { +func toKebab(tb testing.TB) { + tb.Helper() cases := [][]string{ {"testCase", "test-case"}, {"TestCase", "test-case"}, @@ -28,7 +29,7 @@ func toKebab(t testing.TB) { in := i[0] out := i[1] result := strcase.ToKebab(in) - assert.Equal(t, out, result, "ToKebab(%s) = %s, want %s", in, result, out) + assert.Equal(tb, out, result, "ToKebab(%s) = %s, want %s", in, result, out) } } diff --git a/codec/codec_common_test.go b/codec/codec_common_test.go index de5552dd02..3280d2c195 100644 --- a/codec/codec_common_test.go +++ b/codec/codec_common_test.go @@ -92,6 +92,7 @@ func testMarshaling(t *testing.T, cdc interface { codec.JSONCodec }, ) { + t.Helper() any, err := types.NewAnyWithValue(&testdata.Dog{Name: "rufus"}) require.NoError(t, err) diff --git a/codec/unknownproto/benchmarks_test.go b/codec/unknownproto/benchmarks_test.go index 0cf44b4e76..114e4e688f 100644 --- a/codec/unknownproto/benchmarks_test.go +++ b/codec/unknownproto/benchmarks_test.go @@ -51,6 +51,7 @@ func BenchmarkRejectUnknownFields_parallel(b *testing.B) { } func benchmarkRejectUnknownFields(b *testing.B, parallel bool) { + b.Helper() b.ReportAllocs() if !parallel { @@ -89,6 +90,7 @@ func BenchmarkProtoUnmarshal_parallel(b *testing.B) { } func benchmarkProtoUnmarshal(b *testing.B, parallel bool) { + b.Helper() b.ReportAllocs() if !parallel { diff --git a/collections/genesis_test.go b/collections/genesis_test.go index 3d7fd3c549..34fb60e141 100644 --- a/collections/genesis_test.go +++ b/collections/genesis_test.go @@ -91,6 +91,7 @@ type testFixture struct { } func initFixture(t *testing.T) *testFixture { + t.Helper() sk, ctx := deps() schemaBuilder := NewSchemaBuilder(sk) m := NewMap(schemaBuilder, NewPrefix(1), "map", StringKey, Uint64Value) @@ -110,6 +111,7 @@ func initFixture(t *testing.T) *testFixture { } func createTestGenesisSource(t *testing.T) appmodule.GenesisSource { + t.Helper() expectedOrder := []string{"item", "key_set", "map", "sequence"} currentIndex := 0 return func(field string) (io.ReadCloser, error) { @@ -149,6 +151,7 @@ func (b *bufCloser) Close() error { } func newBufCloser(t *testing.T, str string) *bufCloser { + t.Helper() b := &bufCloser{ Buffer: bytes.NewBufferString(str), closed: false, diff --git a/core/genesis/source_test.go b/core/genesis/source_test.go index 3efdfb4d54..cff1a3bde4 100644 --- a/core/genesis/source_test.go +++ b/core/genesis/source_test.go @@ -24,6 +24,7 @@ func TestSource(t *testing.T) { } func expectJSON(t *testing.T, source appmodule.GenesisSource, field, contents string) { + t.Helper() r, err := source(field) require.NoError(t, err) bz, err := io.ReadAll(r) diff --git a/crypto/hd/fundraiser_test.go b/crypto/hd/fundraiser_test.go index 654ac56258..d19239ef3d 100644 --- a/crypto/hd/fundraiser_test.go +++ b/crypto/hd/fundraiser_test.go @@ -29,6 +29,7 @@ func TestFullFundraiserPath(t *testing.T) { } func initFundraiserTestVectors(t *testing.T) []addrData { + t.Helper() // NOTE: atom fundraiser address // var hdPath string = "m/44'/118'/0'/0/0" var hdToAddrTable []addrData diff --git a/crypto/keyring/keyring_test.go b/crypto/keyring/keyring_test.go index c94c0462d5..9031fa4d06 100644 --- a/crypto/keyring/keyring_test.go +++ b/crypto/keyring/keyring_test.go @@ -1979,6 +1979,7 @@ func TestChangeBcrypt(t *testing.T) { } func requireEqualRenamedKey(t *testing.T, key, mnemonic *Record, nameMatch bool) { + t.Helper() if nameMatch { require.Equal(t, key.Name, mnemonic.Name) } @@ -1997,6 +1998,7 @@ func requireEqualRenamedKey(t *testing.T, key, mnemonic *Record, nameMatch bool) } func newKeyring(t *testing.T, name string) Keyring { + t.Helper() cdc := getCodec() kr, err := New(name, "test", t.TempDir(), nil, cdc) require.NoError(t, err) @@ -2004,12 +2006,14 @@ func newKeyring(t *testing.T, name string) Keyring { } func newKeyRecord(t *testing.T, kr Keyring, name string) *Record { + t.Helper() k, _, err := kr.NewMnemonic(name, English, sdk.FullFundraiserPath, DefaultBIP39Passphrase, hd.Secp256k1) require.NoError(t, err) return k } func assertKeysExist(t *testing.T, kr Keyring, names ...string) { + t.Helper() for _, n := range names { _, err := kr.Key(n) require.NoError(t, err) diff --git a/crypto/keys/secp256k1/internal/secp256k1/secp256_test.go b/crypto/keys/secp256k1/internal/secp256k1/secp256_test.go index 080f885640..a234683fcb 100644 --- a/crypto/keys/secp256k1/internal/secp256k1/secp256_test.go +++ b/crypto/keys/secp256k1/internal/secp256k1/secp256_test.go @@ -51,6 +51,7 @@ func randSig() []byte { // tests for malleability // highest bit of signature ECDSA s value must be 0, in the 33th byte func compactSigCheck(t *testing.T, sig []byte) { + t.Helper() b := int(sig[32]) if b < 0 { t.Errorf("highest bit is negative: %d", b) @@ -148,6 +149,7 @@ func TestRandomMessagesWithRandomKeys(t *testing.T) { } func signAndRecoverWithRandomMessages(t *testing.T, keys func() ([]byte, []byte)) { + t.Helper() for i := 0; i < TestCount; i++ { pubkey1, seckey := keys() msg := csprngEntropy(32) diff --git a/crypto/ledger/encode_test.go b/crypto/ledger/encode_test.go index b5b06d04f3..bda1f52ed2 100644 --- a/crypto/ledger/encode_test.go +++ b/crypto/ledger/encode_test.go @@ -10,6 +10,7 @@ import ( ) func checkAminoJSON(t *testing.T, src, dst interface{}, isNil bool) { + t.Helper() // Marshal to JSON bytes. js, err := cdc.MarshalJSON(src) require.Nil(t, err, "%+v", err) diff --git a/math/dec.go b/math/dec.go index d92b0042f3..e7bcec3435 100644 --- a/math/dec.go +++ b/math/dec.go @@ -909,10 +909,12 @@ func LegacyMaxDec(d1, d2 LegacyDec) LegacyDec { // intended to be used with require/assert: require.True(DecEq(...)) func LegacyDecEq(t *testing.T, exp, got LegacyDec) (*testing.T, bool, string, string, string) { + t.Helper() return t, exp.Equal(got), "expected:\t%v\ngot:\t\t%v", exp.String(), got.String() } func LegacyDecApproxEq(t *testing.T, d1, d2, tol LegacyDec) (*testing.T, bool, string, string, string) { + t.Helper() diff := d1.Sub(d2).Abs() return t, diff.LTE(tol), "expected |d1 - d2| <:\t%v\ngot |d1 - d2| = \t\t%v", tol.String(), diff.String() } diff --git a/math/int.go b/math/int.go index b40b39a342..13495ba75a 100644 --- a/math/int.go +++ b/math/int.go @@ -513,6 +513,7 @@ func (i *Int) UnmarshalAmino(bz []byte) error { return i.Unmarshal(bz) } // intended to be used with require/assert: require.True(IntEq(...)) func IntEq(t *testing.T, exp, got Int) (*testing.T, bool, string, string, string) { + t.Helper() return t, exp.Equal(got), "expected:\t%v\ngot:\t\t%v", exp.String(), got.String() } diff --git a/orm/encoding/ormfield/codec_test.go b/orm/encoding/ormfield/codec_test.go index b9e00281d4..53950cda19 100644 --- a/orm/encoding/ormfield/codec_test.go +++ b/orm/encoding/ormfield/codec_test.go @@ -21,6 +21,7 @@ func TestCodec(t *testing.T) { } func testCodec(t *testing.T, spec testutil.TestFieldSpec) { + t.Helper() t.Run(fmt.Sprintf("%s %v", spec.FieldName, false), func(t *testing.T) { testCodecNT(t, spec.FieldName, spec.Gen, false) }) @@ -30,6 +31,7 @@ func testCodec(t *testing.T, spec testutil.TestFieldSpec) { } func testCodecNT(t *testing.T, fname protoreflect.Name, generator *rapid.Generator[any], nonTerminal bool) { + t.Helper() cdc, err := testutil.MakeTestCodec(fname, nonTerminal) assert.NilError(t, err) rapid.Check(t, func(t *rapid.T) { diff --git a/orm/encoding/ormfield/duration_test.go b/orm/encoding/ormfield/duration_test.go index 0e0d1d1217..474f5db52c 100644 --- a/orm/encoding/ormfield/duration_test.go +++ b/orm/encoding/ormfield/duration_test.go @@ -275,6 +275,7 @@ func TestDurationCompare(t *testing.T) { } func encodeValue(t *testing.T, cdc ormfield.Codec, val protoreflect.Value) []byte { + t.Helper() buf := &bytes.Buffer{} assert.NilError(t, cdc.Encode(val, buf)) return buf.Bytes() diff --git a/orm/internal/testkv/leveldb.go b/orm/internal/testkv/leveldb.go index c75d643bd2..71b069c9c7 100644 --- a/orm/internal/testkv/leveldb.go +++ b/orm/internal/testkv/leveldb.go @@ -9,9 +9,10 @@ import ( "cosmossdk.io/orm/model/ormtable" ) -func NewGoLevelDBBackend(t testing.TB) ormtable.Backend { - db, err := dbm.NewGoLevelDB("test", t.TempDir(), nil) - assert.NilError(t, err) +func NewGoLevelDBBackend(tb testing.TB) ormtable.Backend { + tb.Helper() + db, err := dbm.NewGoLevelDB("test", tb.TempDir(), nil) + assert.NilError(tb, err) return ormtable.NewBackend(ormtable.BackendOptions{ CommitmentStore: db, }) diff --git a/orm/model/ormdb/module_test.go b/orm/model/ormdb/module_test.go index 937f76de17..06b5866792 100644 --- a/orm/model/ormdb/module_test.go +++ b/orm/model/ormdb/module_test.go @@ -259,6 +259,7 @@ func TestModuleDB(t *testing.T) { } func runSimpleBankTests(t *testing.T, k Keeper, ctx context.Context) { + t.Helper() // mint coins denom := "foo" acct1 := "bob" diff --git a/orm/model/ormtable/auto_increment_test.go b/orm/model/ormtable/auto_increment_test.go index db7e6f4a09..faddf6df85 100644 --- a/orm/model/ormtable/auto_increment_test.go +++ b/orm/model/ormtable/auto_increment_test.go @@ -43,6 +43,7 @@ func TestAutoIncrementScenario(t *testing.T) { } func runAutoIncrementScenario(t *testing.T, table ormtable.AutoIncrementTable, ctx context.Context) { + t.Helper() store, err := testpb.NewExampleAutoIncrementTableTable(table) assert.NilError(t, err) diff --git a/orm/model/ormtable/bench_test.go b/orm/model/ormtable/bench_test.go index 810e41135e..bd706ea5ad 100644 --- a/orm/model/ormtable/bench_test.go +++ b/orm/model/ormtable/bench_test.go @@ -16,20 +16,23 @@ import ( "cosmossdk.io/orm/types/kv" ) -func initBalanceTable(t testing.TB) testpb.BalanceTable { +func initBalanceTable(tb testing.TB) testpb.BalanceTable { + tb.Helper() table, err := ormtable.Build(ormtable.Options{ MessageType: (&testpb.Balance{}).ProtoReflect().Type(), }) - assert.NilError(t, err) + assert.NilError(tb, err) balanceTable, err := testpb.NewBalanceTable(table) - assert.NilError(t, err) + assert.NilError(tb, err) return balanceTable } func BenchmarkMemory(b *testing.B) { + b.Helper() bench(b, func(tb testing.TB) ormtable.Backend { + tb.Helper() return ormtest.NewMemoryBackend() }) } @@ -39,6 +42,7 @@ func BenchmarkLevelDB(b *testing.B) { } func bench(b *testing.B, newBackend func(testing.TB) ormtable.Backend) { + b.Helper() b.Run("insert", func(b *testing.B) { b.StopTimer() ctx := ormtable.WrapContextDefault(newBackend(b)) @@ -69,6 +73,7 @@ func bench(b *testing.B, newBackend func(testing.TB) ormtable.Backend) { } func benchInsert(b *testing.B, ctx context.Context) { + b.Helper() balanceTable := initBalanceTable(b) for i := 0; i < b.N; i++ { assert.NilError(b, balanceTable.Insert(ctx, &testpb.Balance{ @@ -80,6 +85,7 @@ func benchInsert(b *testing.B, ctx context.Context) { } func benchUpdate(b *testing.B, ctx context.Context) { + b.Helper() balanceTable := initBalanceTable(b) for i := 0; i < b.N; i++ { assert.NilError(b, balanceTable.Update(ctx, &testpb.Balance{ @@ -91,6 +97,7 @@ func benchUpdate(b *testing.B, ctx context.Context) { } func benchGet(b *testing.B, ctx context.Context) { + b.Helper() balanceTable := initBalanceTable(b) for i := 0; i < b.N; i++ { balance, err := balanceTable.Get(ctx, fmt.Sprintf("acct%d", i), "bar") @@ -100,6 +107,7 @@ func benchGet(b *testing.B, ctx context.Context) { } func benchDelete(b *testing.B, ctx context.Context) { + b.Helper() balanceTable := initBalanceTable(b) for i := 0; i < b.N; i++ { assert.NilError(b, balanceTable.Delete(ctx, &testpb.Balance{ @@ -242,6 +250,7 @@ func BenchmarkManualInsertLevelDB(b *testing.B) { } func benchManual(b *testing.B, newStore func() (dbm.DB, error)) { + b.Helper() b.Run("insert", func(b *testing.B) { b.StopTimer() store, err := newStore() @@ -276,6 +285,7 @@ func benchManual(b *testing.B, newStore func() (dbm.DB, error)) { } func benchManualInsert(b *testing.B, store kv.Store) { + b.Helper() for i := 0; i < b.N; i++ { assert.NilError(b, insertBalance(store, &testpb.Balance{ Address: fmt.Sprintf("acct%d", i), @@ -286,6 +296,7 @@ func benchManualInsert(b *testing.B, store kv.Store) { } func benchManualUpdate(b *testing.B, store kv.Store) { + b.Helper() for i := 0; i < b.N; i++ { assert.NilError(b, updateBalance(store, &testpb.Balance{ Address: fmt.Sprintf("acct%d", i), @@ -296,6 +307,7 @@ func benchManualUpdate(b *testing.B, store kv.Store) { } func benchManualDelete(b *testing.B, store kv.Store) { + b.Helper() for i := 0; i < b.N; i++ { assert.NilError(b, deleteBalance(store, &testpb.Balance{ Address: fmt.Sprintf("acct%d", i), @@ -305,6 +317,7 @@ func benchManualDelete(b *testing.B, store kv.Store) { } func benchManualGet(b *testing.B, store kv.Store) { + b.Helper() for i := 0; i < b.N; i++ { balance, err := getBalance(store, fmt.Sprintf("acct%d", i), "bar") assert.NilError(b, err) diff --git a/orm/model/ormtable/table_test.go b/orm/model/ormtable/table_test.go index 34a8824b0a..1a5e34755b 100644 --- a/orm/model/ormtable/table_test.go +++ b/orm/model/ormtable/table_test.go @@ -97,6 +97,7 @@ func TestPaginationLimitCountTotal(t *testing.T) { // check that the ormkv.Entry's decode and encode to the same bytes func checkEncodeDecodeEntries(t *testing.T, table ormtable.Table, store kv.ReadonlyStore) { + t.Helper() it, err := store.Iterator(nil, nil) assert.NilError(t, err) for it.Valid() { @@ -113,6 +114,7 @@ func checkEncodeDecodeEntries(t *testing.T, table ormtable.Table, store kv.Reado } func runTestScenario(t *testing.T, table ormtable.Table, backend ormtable.Backend) { + t.Helper() ctx := ormtable.WrapContextDefault(backend) store, err := testpb.NewExampleTableTable(table) assert.NilError(t, err) @@ -461,6 +463,7 @@ func TestRandomTableData(t *testing.T) { } func testTable(t *testing.T, tableData *TableData) { + t.Helper() for _, index := range tableData.table.Indexes() { indexModel := &IndexModel{ TableData: tableData, @@ -475,6 +478,7 @@ func testTable(t *testing.T, tableData *TableData) { } func testUniqueIndex(t *testing.T, model *IndexModel) { + t.Helper() index := model.index.(ormtable.UniqueIndex) t.Logf("testing unique index %T %s", index, index.Fields()) for i := 0; i < len(model.data); i++ { @@ -497,6 +501,7 @@ func testUniqueIndex(t *testing.T, model *IndexModel) { } func testIndex(t *testing.T, model *IndexModel) { + t.Helper() index := model.index if index.IsFullyOrdered() { t.Logf("testing index %T %s", index, index.Fields()) diff --git a/server/api/server_test.go b/server/api/server_test.go index 34b51bf489..0484277b80 100644 --- a/server/api/server_test.go +++ b/server/api/server_test.go @@ -244,6 +244,7 @@ func (s *GRPCWebTestSuite) makeGrpcRequest( } func readTrailersFromBytes(t *testing.T, dataBytes []byte) Trailer { + t.Helper() bufferReader := bytes.NewBuffer(dataBytes) tp := textproto.NewReader(bufio.NewReader(bufferReader)) diff --git a/server/export_test.go b/server/export_test.go index d1dad66aaa..f7c0124f90 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -93,6 +93,7 @@ func (s *ExportSystem) Run(args ...string) cmdtest.RunResult { // MustRun wraps (*cmdtest.System).MustRunC, providing e's context. func (s *ExportSystem) MustRun(t *testing.T, args ...string) cmdtest.RunResult { + t.Helper() return s.sys.MustRunC(t, s.Ctx, args...) } diff --git a/server/util_test.go b/server/util_test.go index 0f60877508..6f9a91ceed 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -254,6 +254,7 @@ type precedenceCommon struct { } func newPrecedenceCommon(t *testing.T) precedenceCommon { + t.Helper() retval := precedenceCommon{} // Determine the env. var. name based off the executable name @@ -295,6 +296,7 @@ func newPrecedenceCommon(t *testing.T) precedenceCommon { } func (v precedenceCommon) setAll(t *testing.T, setFlag, setEnvVar, setConfigFile *string) { + t.Helper() if setFlag != nil { if err := v.cmd.Flags().Set(v.flagName, *setFlag); err != nil { t.Fatalf("Failed setting flag %q", v.flagName) diff --git a/store/cachekv/benchmark_test.go b/store/cachekv/benchmark_test.go index 8ec1097d9d..158549b4bd 100644 --- a/store/cachekv/benchmark_test.go +++ b/store/cachekv/benchmark_test.go @@ -13,6 +13,7 @@ import ( ) func DoBenchmarkDeepCacheStack(b *testing.B, depth int) { + b.Helper() db := dbm.NewMemDB() initialStore := cachekv.NewStore(dbadapter.Store{DB: db}) diff --git a/store/cachekv/internal/btree_test.go b/store/cachekv/internal/btree_test.go index 97b3843086..06437997f6 100644 --- a/store/cachekv/internal/btree_test.go +++ b/store/cachekv/internal/btree_test.go @@ -183,6 +183,7 @@ func TestDBIterator(t *testing.T) { } func verifyIterator(t *testing.T, itr types.Iterator, expected []int64, msg string) { + t.Helper() i := 0 for itr.Valid() { key := itr.Key() diff --git a/store/cachekv/store_bench_test.go b/store/cachekv/store_bench_test.go index d047c4398c..8f15855e09 100644 --- a/store/cachekv/store_bench_test.go +++ b/store/cachekv/store_bench_test.go @@ -15,6 +15,7 @@ const defaultValueSizeBz = 1 << 12 // This benchmark measures the time of iterator.Next() when the parent store is blank func benchmarkBlankParentIteratorNext(b *testing.B, keysize int) { + b.Helper() mem := dbadapter.Store{DB: dbm.NewMemDB()} kvstore := cachekv.NewStore(mem) // Use a singleton for value, to not waste time computing it @@ -44,6 +45,7 @@ func benchmarkBlankParentIteratorNext(b *testing.B, keysize int) { // Benchmark setting New keys to a store, where the new keys are in sequence. func benchmarkBlankParentAppend(b *testing.B, keysize int) { + b.Helper() mem := dbadapter.Store{DB: dbm.NewMemDB()} kvstore := cachekv.NewStore(mem) @@ -66,6 +68,7 @@ func benchmarkBlankParentAppend(b *testing.B, keysize int) { // Benchmark setting New keys to a store, where the new keys are random. // the speed of this function does not depend on the values in the parent store func benchmarkRandomSet(b *testing.B, keysize int) { + b.Helper() mem := dbadapter.Store{DB: dbm.NewMemDB()} kvstore := cachekv.NewStore(mem) @@ -96,6 +99,7 @@ func benchmarkRandomSet(b *testing.B, keysize int) { // We essentially are benchmarking the cacheKV iterator creation & iteration times // with the number of entries deleted in the parent. func benchmarkIteratorOnParentWithManyDeletes(b *testing.B, numDeletes int) { + b.Helper() mem := dbadapter.Store{DB: dbm.NewMemDB()} // Use a singleton for value, to not waste time computing it diff --git a/store/cachekv/store_test.go b/store/cachekv/store_test.go index 994a5fdafc..3c56223554 100644 --- a/store/cachekv/store_test.go +++ b/store/cachekv/store_test.go @@ -466,6 +466,7 @@ func randInt(n int) int { // useful for replaying a error case if we find one func doOp(t *testing.T, st types.CacheKVStore, truth dbm.DB, op int, args ...int) { + t.Helper() switch op { case opSet: k := args[0] @@ -491,6 +492,7 @@ func doOp(t *testing.T, st types.CacheKVStore, truth dbm.DB, op int, args ...int } func doRandomOp(t *testing.T, st types.CacheKVStore, truth dbm.DB, maxKey int) { + t.Helper() r := randInt(totalOps) switch r { case opSet: @@ -520,6 +522,7 @@ func doRandomOp(t *testing.T, st types.CacheKVStore, truth dbm.DB, maxKey int) { // iterate over whole domain func assertIterateDomain(t *testing.T, st types.KVStore, expectedN int) { + t.Helper() itr := st.Iterator(nil, nil) i := 0 for ; itr.Valid(); itr.Next() { @@ -533,6 +536,7 @@ func assertIterateDomain(t *testing.T, st types.KVStore, expectedN int) { } func assertIterateDomainCheck(t *testing.T, st types.KVStore, mem dbm.DB, r []keyRange) { + t.Helper() // iterate over each and check they match the other itr := st.Iterator(nil, nil) itr2, err := mem.Iterator(nil, nil) // ground truth @@ -566,6 +570,7 @@ func assertIterateDomainCheck(t *testing.T, st types.KVStore, mem dbm.DB, r []ke } func assertIterateDomainCompare(t *testing.T, st types.KVStore, mem dbm.DB) { + t.Helper() // iterate over each and check they match the other itr := st.Iterator(nil, nil) itr2, err := mem.Iterator(nil, nil) // ground truth @@ -577,6 +582,7 @@ func assertIterateDomainCompare(t *testing.T, st types.KVStore, mem dbm.DB) { } func checkIterators(t *testing.T, itr, itr2 types.Iterator) { + t.Helper() for ; itr.Valid(); itr.Next() { require.True(t, itr2.Valid()) k, v := itr.Key(), itr.Value() @@ -592,6 +598,7 @@ func checkIterators(t *testing.T, itr, itr2 types.Iterator) { //-------------------------------------------------------- func setRange(t *testing.T, st types.KVStore, mem dbm.DB, start, end int) { + t.Helper() for i := start; i < end; i++ { st.Set(keyFmt(i), valFmt(i)) err := mem.Set(keyFmt(i), valFmt(i)) @@ -600,6 +607,7 @@ func setRange(t *testing.T, st types.KVStore, mem dbm.DB, start, end int) { } func deleteRange(t *testing.T, st types.KVStore, mem dbm.DB, start, end int) { + t.Helper() for i := start; i < end; i++ { st.Delete(keyFmt(i)) err := mem.Delete(keyFmt(i)) diff --git a/store/iavl/store_test.go b/store/iavl/store_test.go index 19895a0cc8..cecf74778b 100644 --- a/store/iavl/store_test.go +++ b/store/iavl/store_test.go @@ -35,6 +35,7 @@ func randBytes(numBytes int) []byte { // make a tree with data from above and save it func newAlohaTree(t *testing.T, db dbm.DB) (*iavl.MutableTree, types.CommitID) { + t.Helper() tree := iavl.NewMutableTree(db, cacheSize, false, log.NewNopLogger()) for k, v := range treeData { @@ -294,6 +295,7 @@ func TestIAVLReverseIterator(t *testing.T) { iavlStore.Set([]byte{0x01}, []byte("1")) testReverseIterator := func(t *testing.T, start, end []byte, expected []string) { + t.Helper() iter := iavlStore.ReverseIterator(start, end) var i int for i = 0; iter.Valid(); iter.Next() { diff --git a/store/prefix/store_test.go b/store/prefix/store_test.go index bbfe14c241..9121e1f554 100644 --- a/store/prefix/store_test.go +++ b/store/prefix/store_test.go @@ -29,6 +29,7 @@ type kvpair struct { } func genRandomKVPairs(t *testing.T) []kvpair { + t.Helper() kvps := make([]kvpair, 20) for i := 0; i < 20; i++ { @@ -44,6 +45,7 @@ func genRandomKVPairs(t *testing.T) []kvpair { } func setRandomKVPairs(t *testing.T, store types.KVStore) []kvpair { + t.Helper() kvps := genRandomKVPairs(t) for _, kvp := range kvps { store.Set(kvp.key, kvp.value) @@ -52,6 +54,7 @@ func setRandomKVPairs(t *testing.T, store types.KVStore) []kvpair { } func testPrefixStore(t *testing.T, baseStore types.KVStore, prefix []byte) { + t.Helper() prefixStore := NewStore(baseStore, prefix) prefixPrefixStore := NewStore(prefixStore, []byte("prefix")) @@ -252,33 +255,39 @@ func mockStoreWithStuff() types.KVStore { } func checkValue(t *testing.T, store types.KVStore, key, expected []byte) { + t.Helper() bz := store.Get(key) require.Equal(t, expected, bz) } func checkValid(t *testing.T, itr types.Iterator, expected bool) { + t.Helper() valid := itr.Valid() require.Equal(t, expected, valid) } func checkNext(t *testing.T, itr types.Iterator, expected bool) { + t.Helper() itr.Next() valid := itr.Valid() require.Equal(t, expected, valid) } func checkDomain(t *testing.T, itr types.Iterator, start, end []byte) { + t.Helper() ds, de := itr.Domain() require.Equal(t, start, ds) require.Equal(t, end, de) } func checkItem(t *testing.T, itr types.Iterator, key, value []byte) { + t.Helper() require.Exactly(t, key, itr.Key()) require.Exactly(t, value, itr.Value()) } func checkInvalid(t *testing.T, itr types.Iterator) { + t.Helper() checkValid(t, itr, false) checkKeyPanics(t, itr) checkValuePanics(t, itr) @@ -286,14 +295,17 @@ func checkInvalid(t *testing.T, itr types.Iterator) { } func checkKeyPanics(t *testing.T, itr types.Iterator) { + t.Helper() require.Panics(t, func() { itr.Key() }) } func checkValuePanics(t *testing.T, itr types.Iterator) { + t.Helper() require.Panics(t, func() { itr.Value() }) } func checkNextPanics(t *testing.T, itr types.Iterator) { + t.Helper() require.Panics(t, func() { itr.Next() }) } diff --git a/store/rootmulti/snapshot_test.go b/store/rootmulti/snapshot_test.go index 620b5bd385..723391e2bb 100644 --- a/store/rootmulti/snapshot_test.go +++ b/store/rootmulti/snapshot_test.go @@ -93,6 +93,7 @@ func newMultiStoreWithMixedMountsAndBasicData(db dbm.DB) *rootmulti.Store { } func assertStoresEqual(t *testing.T, expect, actual types.CommitKVStore, msgAndArgs ...interface{}) { + t.Helper() assert.Equal(t, expect.LastCommitID(), actual.LastCommitID()) expectIter := expect.Iterator(nil, nil) expectMap := map[string][]byte{} @@ -226,6 +227,7 @@ func TestMultistoreSnapshotRestore(t *testing.T) { } func benchmarkMultistoreSnapshot(b *testing.B, stores uint8, storeKeys uint64) { + b.Helper() b.Skip("Noisy with slow setup time, please see https://github.com/cosmos/cosmos-sdk/issues/8855.") b.ReportAllocs() @@ -261,6 +263,7 @@ func benchmarkMultistoreSnapshot(b *testing.B, stores uint8, storeKeys uint64) { } func benchmarkMultistoreSnapshotRestore(b *testing.B, stores uint8, storeKeys uint64) { + b.Helper() b.Skip("Noisy with slow setup time, please see https://github.com/cosmos/cosmos-sdk/issues/8855.") b.ReportAllocs() diff --git a/store/rootmulti/store_test.go b/store/rootmulti/store_test.go index 720bed9421..34854fe83c 100644 --- a/store/rootmulti/store_test.go +++ b/store/rootmulti/store_test.go @@ -820,26 +820,27 @@ func unmountStore(rootStore *Store, storeKeyName string) { } func checkStore(t *testing.T, store *Store, expect, got types.CommitID) { + t.Helper() require.Equal(t, expect, got) require.Equal(t, expect, store.LastCommitID()) } -func checkContains(t testing.TB, info []types.StoreInfo, wanted []string) { - t.Helper() +func checkContains(tb testing.TB, info []types.StoreInfo, wanted []string) { + tb.Helper() for _, want := range wanted { - checkHas(t, info, want) + checkHas(tb, info, want) } } -func checkHas(t testing.TB, info []types.StoreInfo, want string) { - t.Helper() +func checkHas(tb testing.TB, info []types.StoreInfo, want string) { + tb.Helper() for _, i := range info { if i.Name == want { return } } - t.Fatalf("storeInfo doesn't contain %s", want) + tb.Fatalf("storeInfo doesn't contain %s", want) } func getExpectedCommitID(store *Store, ver int64) types.CommitID { diff --git a/store/snapshots/helpers_test.go b/store/snapshots/helpers_test.go index 9bbb2f0114..d337b53ab7 100644 --- a/store/snapshots/helpers_test.go +++ b/store/snapshots/helpers_test.go @@ -206,6 +206,7 @@ func (m *mockErrorSnapshotter) SetSnapshotInterval(snapshotInterval uint64) { // setupBusyManager creates a manager with an empty store that is busy creating a snapshot at height 1. // The snapshot will complete when the returned closer is called. func setupBusyManager(t *testing.T) *snapshots.Manager { + t.Helper() store, err := snapshots.NewStore(db.NewMemDB(), t.TempDir()) require.NoError(t, err) hung := newHungSnapshotter() @@ -323,14 +324,14 @@ func (s *extSnapshotter) RestoreExtension(height uint64, format uint32, payloadR } // GetTempDir returns a writable temporary director for the test to use. -func GetTempDir(t testing.TB) string { - t.Helper() +func GetTempDir(tb testing.TB) string { + tb.Helper() // os.MkDir() is used instead of testing.T.TempDir() // see https://github.com/cosmos/cosmos-sdk/pull/8475 and // https://github.com/cosmos/cosmos-sdk/pull/10341 for // this change's rationale. tempdir, err := os.MkdirTemp("", "") - require.NoError(t, err) - t.Cleanup(func() { _ = os.RemoveAll(tempdir) }) + require.NoError(tb, err) + tb.Cleanup(func() { _ = os.RemoveAll(tempdir) }) return tempdir } diff --git a/store/snapshots/store_test.go b/store/snapshots/store_test.go index 2fe1d656d8..f4ff0ef74d 100644 --- a/store/snapshots/store_test.go +++ b/store/snapshots/store_test.go @@ -16,6 +16,7 @@ import ( ) func setupStore(t *testing.T) *snapshots.Store { + t.Helper() store, err := snapshots.NewStore(db.NewMemDB(), GetTempDir(t)) require.NoError(t, err) diff --git a/store/types/iterator_test.go b/store/types/iterator_test.go index 8984c3931b..a804b092c8 100644 --- a/store/types/iterator_test.go +++ b/store/types/iterator_test.go @@ -13,6 +13,7 @@ import ( ) func newMemTestKVStore(t *testing.T) types.KVStore { + t.Helper() db := dbm.NewMemDB() store, err := iavl.LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), types.CommitID{}, iavl.DefaultIAVLCacheSize, false, metrics.NewNoOpMetrics()) require.NoError(t, err) diff --git a/tests/integration/auth/migrations/v2/store_test.go b/tests/integration/auth/migrations/v2/store_test.go index e3273e8466..e47419d291 100644 --- a/tests/integration/auth/migrations/v2/store_test.go +++ b/tests/integration/auth/migrations/v2/store_test.go @@ -712,7 +712,7 @@ func TestMigrateVestingAccounts(t *testing.T) { } } -func trackingCorrected(ctx sdk.Context, t *testing.T, ak keeper.AccountKeeper, addr sdk.AccAddress, expDelVesting, expDelFree sdk.Coins) { +func trackingCorrected(ctx sdk.Context, t *testing.T, ak keeper.AccountKeeper, addr sdk.AccAddress, expDelVesting, expDelFree sdk.Coins) { //nolint:thelper // false positive t.Helper() baseAccount := ak.GetAccount(ctx, addr) vDA, ok := baseAccount.(exported.VestingAccount) @@ -769,6 +769,7 @@ func dirtyTrackingFields(ctx sdk.Context, vesting exported.VestingAccount, accou } func createValidator(t *testing.T, ctx sdk.Context, bankKeeper bankkeeper.Keeper, stakingKeeper *stakingkeeper.Keeper, powers int64) (sdk.AccAddress, sdk.ValAddress) { + t.Helper() valTokens := sdk.TokensFromConsensusPower(powers, sdk.DefaultPowerReduction) addrs := simtestutil.AddTestAddrsIncremental(bankKeeper, stakingKeeper, ctx, 1, valTokens) valAddrs := simtestutil.ConvertAddrsToValAddrs(addrs) diff --git a/tests/integration/bank/app_test.go b/tests/integration/bank/app_test.go index 4922222ad5..da860ca21e 100644 --- a/tests/integration/bank/app_test.go +++ b/tests/integration/bank/app_test.go @@ -103,6 +103,7 @@ type suite struct { } func createTestSuite(t *testing.T, genesisAccounts []authtypes.GenesisAccount) suite { + t.Helper() res := suite{} var genAccounts []simtestutil.GenesisAccount @@ -137,6 +138,7 @@ func createTestSuite(t *testing.T, genesisAccounts []authtypes.GenesisAccount) s // CheckBalance checks the balance of an account. func checkBalance(t *testing.T, baseApp *baseapp.BaseApp, addr sdk.AccAddress, balances sdk.Coins, keeper bankkeeper.Keeper) { + t.Helper() ctxCheck := baseApp.NewContext(true) keeperBalances := keeper.GetAllBalances(ctxCheck, addr) require.True(t, balances.Equal(keeperBalances)) diff --git a/tests/integration/bank/keeper/deterministic_test.go b/tests/integration/bank/keeper/deterministic_test.go index 2b5a623817..3537065483 100644 --- a/tests/integration/bank/keeper/deterministic_test.go +++ b/tests/integration/bank/keeper/deterministic_test.go @@ -63,6 +63,7 @@ type deterministicFixture struct { } func initDeterministicFixture(t *testing.T) *deterministicFixture { + t.Helper() keys := storetypes.NewKVStoreKeys(authtypes.StoreKey, banktypes.StoreKey) cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, bank.AppModuleBasic{}).Codec diff --git a/tests/integration/distribution/keeper/msg_server_test.go b/tests/integration/distribution/keeper/msg_server_test.go index e8545ea0c4..3315e2f7a6 100644 --- a/tests/integration/distribution/keeper/msg_server_test.go +++ b/tests/integration/distribution/keeper/msg_server_test.go @@ -58,13 +58,14 @@ type fixture struct { valAddr sdk.ValAddress } -func initFixture(t testing.TB) *fixture { +func initFixture(tb testing.TB) *fixture { + tb.Helper() keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, distrtypes.StoreKey, stakingtypes.StoreKey, ) cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, distribution.AppModuleBasic{}).Codec - logger := log.NewTestLogger(t) + logger := log.NewTestLogger(tb) cms := integration.CreateMultiStore(keys, logger) newCtx := sdk.NewContext(cms, types.Header{}, true, logger) diff --git a/tests/integration/evidence/keeper/infraction_test.go b/tests/integration/evidence/keeper/infraction_test.go index 8aaad0bae5..65346b1661 100644 --- a/tests/integration/evidence/keeper/infraction_test.go +++ b/tests/integration/evidence/keeper/infraction_test.go @@ -79,13 +79,14 @@ type fixture struct { stakingKeeper *stakingkeeper.Keeper } -func initFixture(t testing.TB) *fixture { +func initFixture(tb testing.TB) *fixture { + tb.Helper() keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, paramtypes.StoreKey, consensusparamtypes.StoreKey, evidencetypes.StoreKey, stakingtypes.StoreKey, slashingtypes.StoreKey, ) cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, evidence.AppModuleBasic{}).Codec - logger := log.NewTestLogger(t) + logger := log.NewTestLogger(tb) cms := integration.CreateMultiStore(keys, logger) newCtx := sdk.NewContext(cms, cmtproto.Header{}, true, logger) @@ -150,10 +151,10 @@ func initFixture(t testing.TB) *fixture { evidencetypes.RegisterMsgServer(integrationApp.MsgServiceRouter(), keeper.NewMsgServerImpl(*evidenceKeeper)) evidencetypes.RegisterQueryServer(integrationApp.QueryHelper(), keeper.NewQuerier(evidenceKeeper)) - assert.NilError(t, slashingKeeper.SetParams(sdkCtx, testutil.TestParams())) + assert.NilError(tb, slashingKeeper.SetParams(sdkCtx, testutil.TestParams())) // set default staking params - assert.NilError(t, stakingKeeper.SetParams(sdkCtx, stakingtypes.DefaultParams())) + assert.NilError(tb, stakingKeeper.SetParams(sdkCtx, stakingtypes.DefaultParams())) return &fixture{ app: integrationApp, diff --git a/tests/integration/gov/common_test.go b/tests/integration/gov/common_test.go index 3ade7cde3c..b97480f478 100644 --- a/tests/integration/gov/common_test.go +++ b/tests/integration/gov/common_test.go @@ -24,6 +24,7 @@ var ( // mkTestLegacyContent creates a MsgExecLegacyContent for testing purposes. func mkTestLegacyContent(t *testing.T) *v1.MsgExecLegacyContent { + t.Helper() msgContent, err := v1.NewLegacyContent(TestProposal, authtypes.NewModuleAddress(types.ModuleName).String()) assert.NilError(t, err) diff --git a/tests/integration/gov/genesis_test.go b/tests/integration/gov/genesis_test.go index ecf82c02f8..0b353f4896 100644 --- a/tests/integration/gov/genesis_test.go +++ b/tests/integration/gov/genesis_test.go @@ -189,6 +189,7 @@ func TestImportExportQueues(t *testing.T) { } func clearDB(t *testing.T, db *dbm.MemDB) { + t.Helper() iter, err := db.Iterator(nil, nil) assert.NilError(t, err) defer iter.Close() diff --git a/tests/integration/gov/keeper/common_test.go b/tests/integration/gov/keeper/common_test.go index 215ca0ed9b..4db7f97047 100644 --- a/tests/integration/gov/keeper/common_test.go +++ b/tests/integration/gov/keeper/common_test.go @@ -36,6 +36,7 @@ func getTestProposal() []sdk.Msg { } func createValidators(t *testing.T, f *fixture, powers []int64) ([]sdk.AccAddress, []sdk.ValAddress) { + t.Helper() addrs := simtestutil.AddTestAddrsIncremental(f.bankKeeper, f.stakingKeeper, f.ctx, 5, math.NewInt(30000000)) valAddrs := simtestutil.ConvertAddrsToValAddrs(addrs) pks := simtestutil.CreateTestPubKeys(5) diff --git a/tests/integration/gov/keeper/keeper_test.go b/tests/integration/gov/keeper/keeper_test.go index e3e4a54dc9..65e993ff8d 100644 --- a/tests/integration/gov/keeper/keeper_test.go +++ b/tests/integration/gov/keeper/keeper_test.go @@ -48,13 +48,14 @@ type fixture struct { govKeeper *keeper.Keeper } -func initFixture(t testing.TB) *fixture { +func initFixture(tb testing.TB) *fixture { + tb.Helper() keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, distrtypes.StoreKey, stakingtypes.StoreKey, types.StoreKey, ) cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, bank.AppModuleBasic{}, gov.AppModuleBasic{}).Codec - logger := log.NewTestLogger(t) + logger := log.NewTestLogger(tb) cms := integration.CreateMultiStore(keys, logger) newCtx := sdk.NewContext(cms, cmtproto.Header{}, true, logger) @@ -118,12 +119,12 @@ func initFixture(t testing.TB) *fixture { authority.String(), ) err := govKeeper.ProposalID.Set(newCtx, 1) - assert.NilError(t, err) + assert.NilError(tb, err) govRouter := v1beta1.NewRouter() govRouter.AddRoute(types.RouterKey, v1beta1.ProposalHandler) govKeeper.SetLegacyRouter(govRouter) err = govKeeper.Params.Set(newCtx, v1.DefaultParams()) - assert.NilError(t, err) + assert.NilError(tb, err) authModule := auth.NewAppModule(cdc, accountKeeper, authsims.RandomGenesisAccounts, nil) bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper, nil) diff --git a/tests/integration/slashing/keeper/keeper_test.go b/tests/integration/slashing/keeper/keeper_test.go index 46ebdeae52..0f30d6c0fc 100644 --- a/tests/integration/slashing/keeper/keeper_test.go +++ b/tests/integration/slashing/keeper/keeper_test.go @@ -50,13 +50,14 @@ type fixture struct { valAddrs []sdk.ValAddress } -func initFixture(t testing.TB) *fixture { +func initFixture(tb testing.TB) *fixture { + tb.Helper() keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, slashingtypes.StoreKey, stakingtypes.StoreKey, ) cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}).Codec - logger := log.NewTestLogger(t) + logger := log.NewTestLogger(tb) cms := integration.CreateMultiStore(keys, logger) newCtx := sdk.NewContext(cms, cmtproto.Header{}, true, logger) diff --git a/tests/integration/staking/keeper/common_test.go b/tests/integration/staking/keeper/common_test.go index 9f244b4cf8..7d71b3362f 100644 --- a/tests/integration/staking/keeper/common_test.go +++ b/tests/integration/staking/keeper/common_test.go @@ -53,6 +53,7 @@ func init() { // intended to be used with require/assert: require.True(ValEq(...)) func ValEq(t *testing.T, exp, got types.Validator) (*testing.T, bool, string, types.Validator, types.Validator) { + t.Helper() return t, exp.MinEqual(&got), "expected:\n%v\ngot:\n%v", exp, got } @@ -65,6 +66,7 @@ func generateAddresses(f *fixture, numAddrs int) ([]sdk.AccAddress, []sdk.ValAdd } func createValidators(t *testing.T, f *fixture, powers []int64) ([]sdk.AccAddress, []sdk.ValAddress, []types.Validator) { + t.Helper() addrs := simtestutil.AddTestAddrsIncremental(f.bankKeeper, f.stakingKeeper, f.sdkCtx, 5, f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 300)) valAddrs := simtestutil.ConvertAddrsToValAddrs(addrs) pks := simtestutil.CreateTestPubKeys(5) @@ -91,13 +93,14 @@ func createValidators(t *testing.T, f *fixture, powers []int64) ([]sdk.AccAddres return addrs, valAddrs, vals } -func initFixture(t testing.TB) *fixture { +func initFixture(tb testing.TB) *fixture { + tb.Helper() keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, types.StoreKey, ) cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, staking.AppModuleBasic{}).Codec - logger := log.NewTestLogger(t) + logger := log.NewTestLogger(tb) cms := integration.CreateMultiStore(keys, logger) newCtx := sdk.NewContext(cms, cmtprototypes.Header{}, true, logger) @@ -153,7 +156,7 @@ func initFixture(t testing.TB) *fixture { types.RegisterQueryServer(integrationApp.QueryHelper(), stakingkeeper.NewQuerier(stakingKeeper)) // set default staking params - assert.NilError(t, stakingKeeper.SetParams(sdkCtx, types.DefaultParams())) + assert.NilError(tb, stakingKeeper.SetParams(sdkCtx, types.DefaultParams())) f := fixture{ app: integrationApp, diff --git a/tests/integration/staking/keeper/determinstic_test.go b/tests/integration/staking/keeper/determinstic_test.go index 81bd863709..6760ddf240 100644 --- a/tests/integration/staking/keeper/determinstic_test.go +++ b/tests/integration/staking/keeper/determinstic_test.go @@ -65,6 +65,7 @@ type deterministicFixture struct { } func initDeterministicFixture(t *testing.T) *deterministicFixture { + t.Helper() keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, ) @@ -185,7 +186,8 @@ func bondTypeGenerator() *rapid.Generator[stakingtypes.BondStatus] { } // createValidator creates a validator with random values. -func createValidator(rt *rapid.T, f *deterministicFixture, t *testing.T) stakingtypes.Validator { +func createValidator(t *testing.T, rt *rapid.T, f *deterministicFixture) stakingtypes.Validator { + t.Helper() pubkey := pubKeyGenerator().Draw(rt, "pubkey") pubkeyAny, err := codectypes.NewAnyWithValue(&pubkey) assert.NilError(t, err) @@ -215,21 +217,24 @@ func createValidator(rt *rapid.T, f *deterministicFixture, t *testing.T) staking } // createAndSetValidatorWithStatus creates a validator with random values but with given status and sets to the state -func createAndSetValidatorWithStatus(rt *rapid.T, f *deterministicFixture, t *testing.T, status stakingtypes.BondStatus) stakingtypes.Validator { - val := createValidator(rt, f, t) +func createAndSetValidatorWithStatus(t *testing.T, rt *rapid.T, f *deterministicFixture, status stakingtypes.BondStatus) stakingtypes.Validator { + t.Helper() + val := createValidator(t, rt, f) val.Status = status - setValidator(f, t, val) + setValidator(t, f, val) return val } // createAndSetValidator creates a validator with random values and sets to the state -func createAndSetValidator(rt *rapid.T, f *deterministicFixture, t *testing.T) stakingtypes.Validator { - val := createValidator(rt, f, t) - setValidator(f, t, val) +func createAndSetValidator(t *testing.T, rt *rapid.T, f *deterministicFixture) stakingtypes.Validator { + t.Helper() + val := createValidator(t, rt, f) + setValidator(t, f, val) return val } -func setValidator(f *deterministicFixture, t *testing.T, validator stakingtypes.Validator) { +func setValidator(t *testing.T, f *deterministicFixture, validator stakingtypes.Validator) { + t.Helper() assert.NilError(t, f.stakingKeeper.SetValidator(f.ctx, validator)) assert.NilError(t, f.stakingKeeper.SetValidatorByPowerIndex(f.ctx, validator)) assert.NilError(t, f.stakingKeeper.SetValidatorByConsAddr(f.ctx, validator)) @@ -244,7 +249,8 @@ func setValidator(f *deterministicFixture, t *testing.T, validator stakingtypes. } // getStaticValidator creates a validator with hard-coded values and sets to the state. -func getStaticValidator(f *deterministicFixture, t *testing.T) stakingtypes.Validator { +func getStaticValidator(t *testing.T, f *deterministicFixture) stakingtypes.Validator { + t.Helper() pubkey := ed25519.PubKey{Key: []byte{24, 179, 242, 2, 151, 3, 34, 6, 1, 11, 0, 194, 202, 201, 77, 1, 167, 40, 249, 115, 32, 97, 18, 1, 1, 127, 255, 103, 13, 1, 34, 1}} pubkeyAny, err := codectypes.NewAnyWithValue(&pubkey) assert.NilError(t, err) @@ -273,12 +279,13 @@ func getStaticValidator(f *deterministicFixture, t *testing.T) stakingtypes.Vali MinSelfDelegation: math.NewInt(10), } - setValidator(f, t, validator) + setValidator(t, f, validator) return validator } // getStaticValidator2 creates a validator with hard-coded values and sets to the state. -func getStaticValidator2(f *deterministicFixture, t *testing.T) stakingtypes.Validator { +func getStaticValidator2(t *testing.T, f *deterministicFixture) stakingtypes.Validator { + t.Helper() pubkey := ed25519.PubKey{Key: []byte{40, 249, 115, 32, 97, 18, 1, 1, 127, 255, 103, 13, 1, 34, 1, 24, 179, 242, 2, 151, 3, 34, 6, 1, 11, 0, 194, 202, 201, 77, 1, 167}} pubkeyAny, err := codectypes.NewAnyWithValue(&pubkey) assert.NilError(t, err) @@ -306,19 +313,21 @@ func getStaticValidator2(f *deterministicFixture, t *testing.T) stakingtypes.Val ), MinSelfDelegation: math.NewInt(1), } - setValidator(f, t, validator) + setValidator(t, f, validator) return validator } // createDelegationAndDelegate funds the delegator account with a random delegation in range 100-1000 and delegates. -func createDelegationAndDelegate(rt *rapid.T, f *deterministicFixture, t *testing.T, delegator sdk.AccAddress, validator stakingtypes.Validator) (newShares math.LegacyDec, err error) { +func createDelegationAndDelegate(t *testing.T, rt *rapid.T, f *deterministicFixture, delegator sdk.AccAddress, validator stakingtypes.Validator) (newShares math.LegacyDec, err error) { + t.Helper() amt := f.stakingKeeper.TokensFromConsensusPower(f.ctx, rapid.Int64Range(100, 1000).Draw(rt, "amount")) - return fundAccountAndDelegate(f, t, delegator, validator, amt) + return fundAccountAndDelegate(t, f, delegator, validator, amt) } // fundAccountAndDelegate funds the delegator account with the specified delegation and delegates. -func fundAccountAndDelegate(f *deterministicFixture, t *testing.T, delegator sdk.AccAddress, validator stakingtypes.Validator, amt math.Int) (newShares math.LegacyDec, err error) { +func fundAccountAndDelegate(t *testing.T, f *deterministicFixture, delegator sdk.AccAddress, validator stakingtypes.Validator, amt math.Int) (newShares math.LegacyDec, err error) { + t.Helper() coins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, amt)) assert.NilError(t, f.bankKeeper.MintCoins(f.ctx, minttypes.ModuleName, coins)) @@ -333,7 +342,7 @@ func TestGRPCValidator(t *testing.T) { f := initDeterministicFixture(t) rapid.Check(t, func(rt *rapid.T) { - val := createAndSetValidator(rt, f, t) + val := createAndSetValidator(t, rt, f) req := &stakingtypes.QueryValidatorRequest{ ValidatorAddr: val.OperatorAddress, } @@ -342,7 +351,7 @@ func TestGRPCValidator(t *testing.T) { }) f = initDeterministicFixture(t) // reset - val := getStaticValidator(f, t) + val := getStaticValidator(t, f) req := &stakingtypes.QueryValidatorRequest{ ValidatorAddr: val.OperatorAddress, } @@ -358,7 +367,7 @@ func TestGRPCValidators(t *testing.T) { rapid.Check(t, func(rt *rapid.T) { valsCount := rapid.IntRange(1, 3).Draw(rt, "num-validators") for i := 0; i < valsCount; i++ { - createAndSetValidator(rt, f, t) + createAndSetValidator(t, rt, f) } req := &stakingtypes.QueryValidatorsRequest{ @@ -370,8 +379,8 @@ func TestGRPCValidators(t *testing.T) { }) f = initDeterministicFixture(t) // reset - getStaticValidator(f, t) - getStaticValidator2(f, t) + getStaticValidator(t, f) + getStaticValidator2(t, f) testdata.DeterministicIterations(f.ctx, t, &stakingtypes.QueryValidatorsRequest{}, f.queryClient.Validators, 2862, false) } @@ -381,12 +390,12 @@ func TestGRPCValidatorDelegations(t *testing.T) { f := initDeterministicFixture(t) rapid.Check(t, func(rt *rapid.T) { - validator := createAndSetValidatorWithStatus(rt, f, t, stakingtypes.Bonded) + validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded) numDels := rapid.IntRange(1, 5).Draw(rt, "num-dels") for i := 0; i < numDels; i++ { delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator") - _, err := createDelegationAndDelegate(rt, f, t, delegator, validator) + _, err := createDelegationAndDelegate(t, rt, f, delegator, validator) assert.NilError(t, err) } @@ -400,12 +409,12 @@ func TestGRPCValidatorDelegations(t *testing.T) { f = initDeterministicFixture(t) // reset - validator := getStaticValidator(f, t) + validator := getStaticValidator(t, f) - _, err := fundAccountAndDelegate(f, t, delegatorAddr1, validator, f.amt1) + _, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1) assert.NilError(t, err) - _, err = fundAccountAndDelegate(f, t, delegatorAddr2, validator, f.amt2) + _, err = fundAccountAndDelegate(t, f, delegatorAddr2, validator, f.amt2) assert.NilError(t, err) req := &stakingtypes.QueryValidatorDelegationsRequest{ @@ -420,12 +429,12 @@ func TestGRPCValidatorUnbondingDelegations(t *testing.T) { f := initDeterministicFixture(t) rapid.Check(t, func(rt *rapid.T) { - validator := createAndSetValidatorWithStatus(rt, f, t, stakingtypes.Bonded) + validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded) numDels := rapid.IntRange(1, 3).Draw(rt, "num-dels") for i := 0; i < numDels; i++ { delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator") - shares, err := createDelegationAndDelegate(rt, f, t, delegator, validator) + shares, err := createDelegationAndDelegate(t, rt, f, delegator, validator) assert.NilError(t, err) _, _, err = f.stakingKeeper.Undelegate(f.ctx, delegator, validator.GetOperator(), shares) @@ -442,14 +451,14 @@ func TestGRPCValidatorUnbondingDelegations(t *testing.T) { f = initDeterministicFixture(t) // reset - validator := getStaticValidator(f, t) - shares1, err := fundAccountAndDelegate(f, t, delegatorAddr1, validator, f.amt1) + validator := getStaticValidator(t, f) + shares1, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1) assert.NilError(t, err) _, _, err = f.stakingKeeper.Undelegate(f.ctx, delegatorAddr1, validatorAddr1, shares1) assert.NilError(t, err) - shares2, err := fundAccountAndDelegate(f, t, delegatorAddr2, validator, f.amt2) + shares2, err := fundAccountAndDelegate(t, f, delegatorAddr2, validator, f.amt2) assert.NilError(t, err) _, _, err = f.stakingKeeper.Undelegate(f.ctx, delegatorAddr2, validatorAddr1, shares2) @@ -467,9 +476,9 @@ func TestGRPCDelegation(t *testing.T) { f := initDeterministicFixture(t) rapid.Check(t, func(rt *rapid.T) { - validator := createAndSetValidatorWithStatus(rt, f, t, stakingtypes.Bonded) + validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded) delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator") - _, err := createDelegationAndDelegate(rt, f, t, delegator, validator) + _, err := createDelegationAndDelegate(t, rt, f, delegator, validator) assert.NilError(t, err) req := &stakingtypes.QueryDelegationRequest{ @@ -482,8 +491,8 @@ func TestGRPCDelegation(t *testing.T) { f = initDeterministicFixture(t) // reset - validator := getStaticValidator(f, t) - _, err := fundAccountAndDelegate(f, t, delegatorAddr1, validator, f.amt1) + validator := getStaticValidator(t, f) + _, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1) assert.NilError(t, err) req := &stakingtypes.QueryDelegationRequest{ @@ -499,9 +508,9 @@ func TestGRPCUnbondingDelegation(t *testing.T) { f := initDeterministicFixture(t) rapid.Check(t, func(rt *rapid.T) { - validator := createAndSetValidatorWithStatus(rt, f, t, stakingtypes.Bonded) + validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded) delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator") - shares, err := createDelegationAndDelegate(rt, f, t, delegator, validator) + shares, err := createDelegationAndDelegate(t, rt, f, delegator, validator) assert.NilError(t, err) _, _, err = f.stakingKeeper.Undelegate(f.ctx, delegator, validator.GetOperator(), shares) @@ -516,9 +525,9 @@ func TestGRPCUnbondingDelegation(t *testing.T) { }) f = initDeterministicFixture(t) // reset - validator := getStaticValidator(f, t) + validator := getStaticValidator(t, f) - shares1, err := fundAccountAndDelegate(f, t, delegatorAddr1, validator, f.amt1) + shares1, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1) assert.NilError(t, err) _, _, err = f.stakingKeeper.Undelegate(f.ctx, delegatorAddr1, validatorAddr1, shares1) @@ -541,8 +550,8 @@ func TestGRPCDelegatorDelegations(t *testing.T) { delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator") for i := 0; i < numVals; i++ { - validator := createAndSetValidatorWithStatus(rt, f, t, stakingtypes.Bonded) - _, err := createDelegationAndDelegate(rt, f, t, delegator, validator) + validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded) + _, err := createDelegationAndDelegate(t, rt, f, delegator, validator) assert.NilError(t, err) } @@ -556,8 +565,8 @@ func TestGRPCDelegatorDelegations(t *testing.T) { f = initDeterministicFixture(t) // reset - validator := getStaticValidator(f, t) - _, err := fundAccountAndDelegate(f, t, delegatorAddr1, validator, f.amt1) + validator := getStaticValidator(t, f) + _, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1) assert.NilError(t, err) req := &stakingtypes.QueryDelegatorDelegationsRequest{ @@ -572,10 +581,10 @@ func TestGRPCDelegatorValidator(t *testing.T) { f := initDeterministicFixture(t) rapid.Check(t, func(rt *rapid.T) { - validator := createAndSetValidatorWithStatus(rt, f, t, stakingtypes.Bonded) + validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded) delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator") - _, err := createDelegationAndDelegate(rt, f, t, delegator, validator) + _, err := createDelegationAndDelegate(t, rt, f, delegator, validator) assert.NilError(t, err) req := &stakingtypes.QueryDelegatorValidatorRequest{ @@ -588,8 +597,8 @@ func TestGRPCDelegatorValidator(t *testing.T) { f = initDeterministicFixture(t) // reset - validator := getStaticValidator(f, t) - _, err := fundAccountAndDelegate(f, t, delegatorAddr1, validator, f.amt1) + validator := getStaticValidator(t, f) + _, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1) assert.NilError(t, err) @@ -610,8 +619,8 @@ func TestGRPCDelegatorUnbondingDelegations(t *testing.T) { delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator") for i := 0; i < numVals; i++ { - validator := createAndSetValidatorWithStatus(rt, f, t, stakingtypes.Bonded) - shares, err := createDelegationAndDelegate(rt, f, t, delegator, validator) + validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded) + shares, err := createDelegationAndDelegate(t, rt, f, delegator, validator) assert.NilError(t, err) _, _, err = f.stakingKeeper.Undelegate(f.ctx, delegator, validator.GetOperator(), shares) @@ -628,8 +637,8 @@ func TestGRPCDelegatorUnbondingDelegations(t *testing.T) { f = initDeterministicFixture(t) // reset - validator := getStaticValidator(f, t) - shares1, err := fundAccountAndDelegate(f, t, delegatorAddr1, validator, f.amt1) + validator := getStaticValidator(t, f) + shares1, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1) assert.NilError(t, err) _, _, err = f.stakingKeeper.Undelegate(f.ctx, delegatorAddr1, validatorAddr1, shares1) @@ -650,7 +659,7 @@ func TestGRPCHistoricalInfo(t *testing.T) { numVals := rapid.IntRange(1, 5).Draw(rt, "num-vals") vals := make(stakingtypes.Validators, 0, numVals) for i := 0; i < numVals; i++ { - validator := createAndSetValidatorWithStatus(rt, f, t, stakingtypes.Bonded) + validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded) vals = append(vals, validator) } @@ -676,7 +685,7 @@ func TestGRPCHistoricalInfo(t *testing.T) { f = initDeterministicFixture(t) // reset - validator := getStaticValidator(f, t) + validator := getStaticValidator(t, f) historicalInfo := stakingtypes.HistoricalInfo{ Header: cmtproto.Header{}, @@ -707,8 +716,8 @@ func TestGRPCDelegatorValidators(t *testing.T) { delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator") for i := 0; i < numVals; i++ { - validator := createAndSetValidatorWithStatus(rt, f, t, stakingtypes.Bonded) - _, err := createDelegationAndDelegate(rt, f, t, delegator, validator) + validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded) + _, err := createDelegationAndDelegate(t, rt, f, delegator, validator) assert.NilError(t, err) } @@ -722,9 +731,9 @@ func TestGRPCDelegatorValidators(t *testing.T) { f = initDeterministicFixture(t) // reset - validator := getStaticValidator(f, t) + validator := getStaticValidator(t, f) - _, err := fundAccountAndDelegate(f, t, delegatorAddr1, validator, f.amt1) + _, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1) assert.NilError(t, err) req := &stakingtypes.QueryDelegatorValidatorsRequest{DelegatorAddr: delegator1} @@ -736,13 +745,13 @@ func TestGRPCPool(t *testing.T) { f := initDeterministicFixture(t) rapid.Check(t, func(rt *rapid.T) { - createAndSetValidator(rt, f, t) + createAndSetValidator(t, rt, f) testdata.DeterministicIterations(f.ctx, t, &stakingtypes.QueryPoolRequest{}, f.queryClient.Pool, 0, true) }) f = initDeterministicFixture(t) // reset - getStaticValidator(f, t) + getStaticValidator(t, f) testdata.DeterministicIterations(f.ctx, t, &stakingtypes.QueryPoolRequest{}, f.queryClient.Pool, 6242, false) } @@ -751,18 +760,18 @@ func TestGRPCRedelegations(t *testing.T) { f := initDeterministicFixture(t) rapid.Check(t, func(rt *rapid.T) { - validator := createAndSetValidatorWithStatus(rt, f, t, stakingtypes.Bonded) + validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded) srcValAddr, err := sdk.ValAddressFromBech32(validator.OperatorAddress) assert.NilError(t, err) - validator2 := createAndSetValidatorWithStatus(rt, f, t, stakingtypes.Bonded) + validator2 := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded) dstValAddr, err := sdk.ValAddressFromBech32(validator2.OperatorAddress) assert.NilError(t, err) numDels := rapid.IntRange(1, 5).Draw(rt, "num-dels") delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator") - shares, err := createDelegationAndDelegate(rt, f, t, delegator, validator) + shares, err := createDelegationAndDelegate(t, rt, f, delegator, validator) assert.NilError(t, err) _, err = f.stakingKeeper.BeginRedelegation(f.ctx, delegator, srcValAddr, dstValAddr, shares) @@ -793,10 +802,10 @@ func TestGRPCRedelegations(t *testing.T) { }) f = initDeterministicFixture(t) // reset - validator := getStaticValidator(f, t) - _ = getStaticValidator2(f, t) + validator := getStaticValidator(t, f) + _ = getStaticValidator2(t, f) - shares, err := fundAccountAndDelegate(f, t, delegatorAddr1, validator, f.amt1) + shares, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1) assert.NilError(t, err) _, err = f.stakingKeeper.BeginRedelegation(f.ctx, delegatorAddr1, validatorAddr1, validatorAddr2, shares) diff --git a/tests/integration/staking/keeper/genesis_test.go b/tests/integration/staking/keeper/genesis_test.go index 46f655b89c..8884318b02 100644 --- a/tests/integration/staking/keeper/genesis_test.go +++ b/tests/integration/staking/keeper/genesis_test.go @@ -18,6 +18,7 @@ import ( ) func bootstrapGenesisTest(t *testing.T, numAddrs int) (*fixture, []sdk.AccAddress) { + t.Helper() t.Parallel() f := initFixture(t) diff --git a/tests/integration/staking/keeper/grpc_query_test.go b/tests/integration/staking/keeper/grpc_query_test.go index 830f710de3..a5edf2c04f 100644 --- a/tests/integration/staking/keeper/grpc_query_test.go +++ b/tests/integration/staking/keeper/grpc_query_test.go @@ -17,6 +17,7 @@ import ( ) func createValidatorAccs(t *testing.T, f *fixture) ([]sdk.AccAddress, []types.Validator) { + t.Helper() addrs, _, validators := createValidators(&testing.T{}, f, []int64{9, 8, 7}) header := cmtproto.Header{ ChainID: "HelloChain", diff --git a/tests/integration/staking/keeper/slash_test.go b/tests/integration/staking/keeper/slash_test.go index 2d6aec0840..6335b24a70 100644 --- a/tests/integration/staking/keeper/slash_test.go +++ b/tests/integration/staking/keeper/slash_test.go @@ -19,6 +19,7 @@ import ( // bootstrapSlashTest creates 3 validators and bootstrap the app. func bootstrapSlashTest(t *testing.T, power int64) (*fixture, []sdk.AccAddress, []sdk.ValAddress) { + t.Helper() t.Parallel() f := initFixture(t) diff --git a/tests/integration/staking/keeper/unbonding_test.go b/tests/integration/staking/keeper/unbonding_test.go index 2448fa6e08..3b514420e8 100644 --- a/tests/integration/staking/keeper/unbonding_test.go +++ b/tests/integration/staking/keeper/unbonding_test.go @@ -19,6 +19,7 @@ import ( // SetupUnbondingTests creates two validators and setup mocked staking hooks for testing unbonding func SetupUnbondingTests(t *testing.T, f *fixture, hookCalled *bool, ubdeID *uint64) (bondDenom string, addrDels []sdk.AccAddress, addrVals []sdk.ValAddress) { + t.Helper() // setup hooks mockCtrl := gomock.NewController(t) mockStackingHooks := testutil.NewMockStakingHooks(mockCtrl) @@ -92,6 +93,7 @@ func doUnbondingDelegation( addrVals []sdk.ValAddress, hookCalled *bool, ) (completionTime time.Time, bondedAmt, notBondedAmt math.Int) { + t.Helper() // UNDELEGATE // Save original bonded and unbonded amounts bondedAmt1 := bankKeeper.GetBalance(ctx, stakingKeeper.GetBondedPool(ctx).GetAddress(), bondDenom).Amount @@ -129,6 +131,7 @@ func doRedelegation( addrVals []sdk.ValAddress, hookCalled *bool, ) (completionTime time.Time) { + t.Helper() var err error completionTime, err = stakingKeeper.BeginRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1], math.LegacyNewDec(1)) assert.NilError(t, err) @@ -152,6 +155,7 @@ func doValidatorUnbonding( addrVal sdk.ValAddress, hookCalled *bool, ) (validator types.Validator) { + t.Helper() validator, found := stakingKeeper.GetValidator(ctx, addrVal) assert.Assert(t, found) // Check that status is bonded diff --git a/tests/integration/staking/keeper/validator_test.go b/tests/integration/staking/keeper/validator_test.go index 8cc3925619..2fb75e10ac 100644 --- a/tests/integration/staking/keeper/validator_test.go +++ b/tests/integration/staking/keeper/validator_test.go @@ -18,19 +18,21 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking/types" ) -func newMonikerValidator(t testing.TB, operator sdk.ValAddress, pubKey cryptotypes.PubKey, moniker string) types.Validator { +func newMonikerValidator(tb testing.TB, operator sdk.ValAddress, pubKey cryptotypes.PubKey, moniker string) types.Validator { + tb.Helper() v, err := types.NewValidator(operator, pubKey, types.Description{Moniker: moniker}) - assert.NilError(t, err) + assert.NilError(tb, err) return v } -func bootstrapValidatorTest(t testing.TB, power int64, numAddrs int) (*fixture, []sdk.AccAddress, []sdk.ValAddress) { - f := initFixture(t) +func bootstrapValidatorTest(tb testing.TB, power int64, numAddrs int) (*fixture, []sdk.AccAddress, []sdk.ValAddress) { + tb.Helper() + f := initFixture(tb) addrDels, addrVals := generateAddresses(f, numAddrs) bondDenom, err := f.stakingKeeper.BondDenom(f.sdkCtx) - assert.NilError(t, err) + assert.NilError(tb, err) amt := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, power) totalSupply := sdk.NewCoins(sdk.NewCoin(bondDenom, amt.MulRaw(int64(len(addrDels))))) @@ -40,18 +42,19 @@ func bootstrapValidatorTest(t testing.TB, power int64, numAddrs int) (*fixture, // set bonded pool supply f.accountKeeper.SetModuleAccount(f.sdkCtx, notBondedPool) - assert.NilError(t, banktestutil.FundModuleAccount(f.sdkCtx, f.bankKeeper, notBondedPool.GetName(), totalSupply)) + assert.NilError(tb, banktestutil.FundModuleAccount(f.sdkCtx, f.bankKeeper, notBondedPool.GetName(), totalSupply)) return f, addrDels, addrVals } -func initValidators(t testing.TB, power int64, numAddrs int, powers []int64) (*fixture, []sdk.AccAddress, []sdk.ValAddress, []types.Validator) { - f, addrs, valAddrs := bootstrapValidatorTest(t, power, numAddrs) +func initValidators(tb testing.TB, power int64, numAddrs int, powers []int64) (*fixture, []sdk.AccAddress, []sdk.ValAddress, []types.Validator) { + tb.Helper() + f, addrs, valAddrs := bootstrapValidatorTest(tb, power, numAddrs) pks := simtestutil.CreateTestPubKeys(numAddrs) vs := make([]types.Validator, len(powers)) for i, power := range powers { - vs[i] = testutil.NewValidator(t, sdk.ValAddress(addrs[i]), pks[i]) + vs[i] = testutil.NewValidator(tb, sdk.ValAddress(addrs[i]), pks[i]) tokens := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, power) vs[i], _ = vs[i].AddTokensFromDel(tokens) } @@ -844,6 +847,7 @@ func TestApplyAndReturnValidatorSetUpdatesBondTransition(t *testing.T) { } func applyValidatorSetUpdates(t *testing.T, ctx sdk.Context, k *keeper.Keeper, expectedUpdatesLen int) []abci.ValidatorUpdate { + t.Helper() updates, err := k.ApplyAndReturnValidatorSetUpdates(ctx) assert.NilError(t, err) if expectedUpdatesLen >= 0 { diff --git a/tests/integration/tx/aminojson/aminojson_test.go b/tests/integration/tx/aminojson/aminojson_test.go index 485b2ee36e..3d9cc5e34d 100644 --- a/tests/integration/tx/aminojson/aminojson_test.go +++ b/tests/integration/tx/aminojson/aminojson_test.go @@ -192,6 +192,7 @@ func TestAminoJSON_Equivalence(t *testing.T) { } func newAny(t *testing.T, msg proto.Message) *anypb.Any { + t.Helper() bz, err := proto.Marshal(msg) require.NoError(t, err) typeName := fmt.Sprintf("/%s", msg.ProtoReflect().Descriptor().FullName()) diff --git a/testutil/account.go b/testutil/account.go index 8a1ba33681..a50890e89b 100644 --- a/testutil/account.go +++ b/testutil/account.go @@ -17,6 +17,7 @@ type TestAccount struct { } func CreateKeyringAccounts(t *testing.T, kr keyring.Keyring, num int) []TestAccount { + t.Helper() accounts := make([]TestAccount, num) for i := range accounts { record, _, err := kr.NewMnemonic( diff --git a/testutil/context.go b/testutil/context.go index e54ae2a548..399778ee5a 100644 --- a/testutil/context.go +++ b/testutil/context.go @@ -37,13 +37,14 @@ type TestContext struct { CMS store.CommitMultiStore } -func DefaultContextWithDB(t testing.TB, key, tkey storetypes.StoreKey) TestContext { +func DefaultContextWithDB(tb testing.TB, key, tkey storetypes.StoreKey) TestContext { + tb.Helper() db := dbm.NewMemDB() cms := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) cms.MountStoreWithDB(key, storetypes.StoreTypeIAVL, db) cms.MountStoreWithDB(tkey, storetypes.StoreTypeTransient, db) err := cms.LoadLatestVersion() - assert.NoError(t, err) + assert.NoError(tb, err) ctx := sdk.NewContext(cms, cmtproto.Header{Time: time.Now()}, false, log.NewNopLogger()) diff --git a/testutil/ioutil.go b/testutil/ioutil.go index ef33eaa441..4413c16e21 100644 --- a/testutil/ioutil.go +++ b/testutil/ioutil.go @@ -52,36 +52,36 @@ func ApplyMockIODiscardOutErr(c *cobra.Command) BufferReader { // Write the given string to a new temporary file. // Returns an open file for the test to use. -func WriteToNewTempFile(t testing.TB, s string) *os.File { - t.Helper() +func WriteToNewTempFile(tb testing.TB, s string) *os.File { + tb.Helper() - fp := TempFile(t) + fp := TempFile(tb) _, err := fp.WriteString(s) - require.Nil(t, err) + require.Nil(tb, err) return fp } // TempFile returns a writable temporary file for the test to use. -func TempFile(t testing.TB) *os.File { - t.Helper() +func TempFile(tb testing.TB) *os.File { + tb.Helper() - fp, err := os.CreateTemp(GetTempDir(t), "") - require.NoError(t, err) + fp, err := os.CreateTemp(GetTempDir(tb), "") + require.NoError(tb, err) return fp } // GetTempDir returns a writable temporary director for the test to use. -func GetTempDir(t testing.TB) string { - t.Helper() +func GetTempDir(tb testing.TB) string { + tb.Helper() // os.MkDir() is used instead of testing.T.TempDir() // see https://github.com/cosmos/cosmos-sdk/pull/8475 and // https://github.com/cosmos/cosmos-sdk/pull/10341 for // this change's rationale. tempdir, err := os.MkdirTemp("", "") - require.NoError(t, err) - t.Cleanup(func() { _ = os.RemoveAll(tempdir) }) + require.NoError(tb, err) + tb.Cleanup(func() { _ = os.RemoveAll(tempdir) }) return tempdir } diff --git a/testutil/sims/simulation_helpers.go b/testutil/sims/simulation_helpers.go index eee7bb74a5..1d4cbec470 100644 --- a/testutil/sims/simulation_helpers.go +++ b/testutil/sims/simulation_helpers.go @@ -71,8 +71,7 @@ func SimulationOperations(app runtime.AppI, cdc codec.JSONCodec, config simtypes } } - //nolint:staticcheck // used for legacy testing - simState.LegacyProposalContents = app.SimulationManager().GetProposalContents(simState) + simState.LegacyProposalContents = app.SimulationManager().GetProposalContents(simState) //nolint:staticcheck // we're testing the old way here simState.ProposalMsgs = app.SimulationManager().GetProposalMsgs(simState) return app.SimulationManager().WeightedOperations(simState) } diff --git a/testutil/sims/simulation_helpers_test.go b/testutil/sims/simulation_helpers_test.go index 67eef0d1a0..e9c6c31dc1 100644 --- a/testutil/sims/simulation_helpers_test.go +++ b/testutil/sims/simulation_helpers_test.go @@ -110,6 +110,7 @@ func checkDiffResults(t *testing.T, store1, store2 storetypes.KVStore, noDiff bo } func initTestStores(t *testing.T) (storetypes.KVStore, storetypes.KVStore) { + t.Helper() db := dbm.NewMemDB() ms := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) diff --git a/testutil/sims/tx_helpers.go b/testutil/sims/tx_helpers.go index 55ac8a79a4..9c8244c347 100644 --- a/testutil/sims/tx_helpers.go +++ b/testutil/sims/tx_helpers.go @@ -96,6 +96,7 @@ func SignCheckDeliver( t *testing.T, txCfg client.TxConfig, app *baseapp.BaseApp, header types.Header, msgs []sdk.Msg, chainID string, accNums, accSeqs []uint64, expSimPass, expPass bool, priv ...cryptotypes.PrivKey, ) (sdk.GasInfo, *sdk.Result, error) { + t.Helper() tx, err := GenSignedMockTx( rand.New(rand.NewSource(time.Now().UnixNano())), txCfg, diff --git a/tools/confix/cmd/mutate_test.go b/tools/confix/cmd/mutate_test.go index 377b1df86c..2aec22cc67 100644 --- a/tools/confix/cmd/mutate_test.go +++ b/tools/confix/cmd/mutate_test.go @@ -17,6 +17,7 @@ import ( // initClientContext initiates client Context for tests func initClientContext(t *testing.T) (client.Context, func()) { + t.Helper() home := t.TempDir() chainID := "test-chain" clientCtx := client.Context{}. diff --git a/tools/confix/upgrade_test.go b/tools/confix/upgrade_test.go index e3f8f094ec..3a6cbafee6 100644 --- a/tools/confix/upgrade_test.go +++ b/tools/confix/upgrade_test.go @@ -10,6 +10,7 @@ import ( ) func mustReadConfig(t *testing.T, path string) []byte { + t.Helper() f, err := os.ReadFile(path) if err != nil { t.Fatalf("failed to open file: %v", err) diff --git a/tools/cosmovisor/args_test.go b/tools/cosmovisor/args_test.go index d74c09eae8..34522d260a 100644 --- a/tools/cosmovisor/args_test.go +++ b/tools/cosmovisor/args_test.go @@ -119,7 +119,7 @@ func (s *argsTestSuite) clearEnv() *cosmovisorEnv { // setEnv sets environment variables to the values provided. // If t is not nil, and there's a problem, the test will fail immediately. // If t is nil, problems will just be logged using s.T(). -func (s *argsTestSuite) setEnv(t *testing.T, env *cosmovisorEnv) { +func (s *argsTestSuite) setEnv(t *testing.T, env *cosmovisorEnv) { //nolint:thelper // false positive if t == nil { s.T().Logf("Restoring environment variables.") } diff --git a/tools/cosmovisor/cmd/cosmovisor/init_test.go b/tools/cosmovisor/cmd/cosmovisor/init_test.go index 89f39d0d8c..d4d08e7b6a 100644 --- a/tools/cosmovisor/cmd/cosmovisor/init_test.go +++ b/tools/cosmovisor/cmd/cosmovisor/init_test.go @@ -82,7 +82,7 @@ func (s *InitTestSuite) clearEnv() *cosmovisorInitEnv { // setEnv sets environment variables to the values provided. // If t is not nil, and there's a problem, the test will fail immediately. // If t is nil, problems will just be logged using s.T(). -func (s *InitTestSuite) setEnv(t *testing.T, env *cosmovisorInitEnv) { +func (s *InitTestSuite) setEnv(t *testing.T, env *cosmovisorInitEnv) { //nolint:thelper // false psotive if t == nil { s.T().Logf("Restoring environment variables.") } diff --git a/types/address/hash_test.go b/types/address/hash_test.go index f124f5ada0..d097d93f49 100644 --- a/types/address/hash_test.go +++ b/types/address/hash_test.go @@ -115,6 +115,7 @@ func (a addrMock) Address() []byte { } func (a addrMock) AddressWithLen(t *testing.T) []byte { + t.Helper() addr, err := LengthPrefix(a.Addr) assert.NoError(t, err) return addr diff --git a/types/address_test.go b/types/address_test.go index c17f3bc533..4cded9e20e 100644 --- a/types/address_test.go +++ b/types/address_test.go @@ -17,7 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/bech32/legacybech32" //nolint:staticcheck // we do old keys, they're keys after all. + "github.com/cosmos/cosmos-sdk/types/bech32/legacybech32" //nolint:staticcheck // we're using this to support the legacy way of dealing with bech32 ) type addressTestSuite struct { diff --git a/types/coin_benchmark_test.go b/types/coin_benchmark_test.go index 955578cf67..188208d048 100644 --- a/types/coin_benchmark_test.go +++ b/types/coin_benchmark_test.go @@ -15,6 +15,7 @@ func BenchmarkCoinsAdditionIntersect(b *testing.B) { b.ReportAllocs() benchmarkingFunc := func(numCoinsA, numCoinsB int) func(b *testing.B) { return func(b *testing.B) { + b.Helper() b.ReportAllocs() coinsA := Coins(make([]Coin, numCoinsA)) coinsB := Coins(make([]Coin, numCoinsB)) @@ -46,6 +47,7 @@ func BenchmarkCoinsAdditionNoIntersect(b *testing.B) { b.ReportAllocs() benchmarkingFunc := func(numCoinsA, numCoinsB int) func(b *testing.B) { return func(b *testing.B) { + b.Helper() b.ReportAllocs() coinsA := Coins(make([]Coin, numCoinsA)) coinsB := Coins(make([]Coin, numCoinsB)) @@ -80,6 +82,7 @@ func BenchmarkSumOfCoinAdds(b *testing.B) { // already in the sum, and (coinsPerAdd - numIntersectingCoins) that are new denoms. benchmarkingFunc := func(numAdds, coinsPerAdd, numIntersectingCoins int, sumFn func([]Coins) Coins) func(b *testing.B) { return func(b *testing.B) { + b.Helper() b.ReportAllocs() addCoins := make([]Coins, numAdds) nonIntersectingCoins := coinsPerAdd - numIntersectingCoins diff --git a/x/auth/ante/sigverify_test.go b/x/auth/ante/sigverify_test.go index af5d472abb..d61dd2a244 100644 --- a/x/auth/ante/sigverify_test.go +++ b/x/auth/ante/sigverify_test.go @@ -265,6 +265,7 @@ func TestSigIntegration(t *testing.T) { } func runSigDecorators(t *testing.T, params types.Params, _ bool, privs ...cryptotypes.PrivKey) (storetypes.Gas, error) { + t.Helper() suite := SetupTestSuite(t, true) suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() diff --git a/x/auth/ante/testutil_test.go b/x/auth/ante/testutil_test.go index e33e6db93f..022ded1b28 100644 --- a/x/auth/ante/testutil_test.go +++ b/x/auth/ante/testutil_test.go @@ -56,6 +56,7 @@ type AnteTestSuite struct { // SetupTest setups a new test, with new app, context, and anteHandler. func SetupTestSuite(t *testing.T, isCheckTx bool) *AnteTestSuite { + t.Helper() suite := &AnteTestSuite{} ctrl := gomock.NewController(t) suite.bankKeeper = authtestutil.NewMockBankKeeper(ctrl) @@ -156,6 +157,7 @@ func (t TestCaseArgs) WithAccountsInfo(accs []TestAccount) TestCaseArgs { // DeliverMsgs constructs a tx and runs it through the ante handler. This is used to set the context for a test case, for // example to test for replay protection. func (suite *AnteTestSuite) DeliverMsgs(t *testing.T, privs []cryptotypes.PrivKey, msgs []sdk.Msg, feeAmount sdk.Coins, gasLimit uint64, accNums, accSeqs []uint64, chainID string, simulate bool) (sdk.Context, error) { + t.Helper() require.NoError(t, suite.txBuilder.SetMsgs(msgs...)) suite.txBuilder.SetFeeAmount(feeAmount) suite.txBuilder.SetGasLimit(gasLimit) @@ -169,6 +171,7 @@ func (suite *AnteTestSuite) DeliverMsgs(t *testing.T, privs []cryptotypes.PrivKe } func (suite *AnteTestSuite) RunTestCase(t *testing.T, tc TestCase, args TestCaseArgs) { + t.Helper() require.NoError(t, suite.txBuilder.SetMsgs(args.msgs...)) suite.txBuilder.SetFeeAmount(args.feeAmount) suite.txBuilder.SetGasLimit(args.gasLimit) diff --git a/x/auth/testutil/util.go b/x/auth/testutil/util.go index b144a7f5d8..c17d7aa580 100644 --- a/x/auth/testutil/util.go +++ b/x/auth/testutil/util.go @@ -7,6 +7,7 @@ import ( ) func AssertError(t *testing.T, err, expectedErr error, expectedErrMsg string) { + t.Helper() switch { case expectedErr != nil: require.ErrorIs(t, err, expectedErr) diff --git a/x/auth/tx/aux_test.go b/x/auth/tx/aux_test.go index 1ee64ff773..70c5ce5c85 100644 --- a/x/auth/tx/aux_test.go +++ b/x/auth/tx/aux_test.go @@ -192,6 +192,7 @@ func TestBuilderWithAux(t *testing.T) { } func makeTipperTxBuilder(t *testing.T) (clienttx.AuxTxBuilder, []byte) { + t.Helper() tipperBuilder := clienttx.NewAuxTxBuilder() tipperBuilder.SetAddress(tipperAddr.String()) tipperBuilder.SetAccountNumber(1) diff --git a/x/auth/tx/legacy_amino_json_test.go b/x/auth/tx/legacy_amino_json_test.go index dce51e06fe..f8f4c72ad6 100644 --- a/x/auth/tx/legacy_amino_json_test.go +++ b/x/auth/tx/legacy_amino_json_test.go @@ -33,6 +33,7 @@ var ( ) func buildTx(t *testing.T, bldr *wrapper) { + t.Helper() bldr.SetFeeAmount(coins) bldr.SetGasLimit(gas) bldr.SetMemo(memo) diff --git a/x/bank/keeper/genesis_test.go b/x/bank/keeper/genesis_test.go index a1058e6963..0a15f4cb2a 100644 --- a/x/bank/keeper/genesis_test.go +++ b/x/bank/keeper/genesis_test.go @@ -40,7 +40,7 @@ func (suite *KeeperTestSuite) TestExportGenesis() { exportGenesis := suite.bankKeeper.ExportGenesis(ctx) - suite.Require().Len(exportGenesis.Params.SendEnabled, 0) //nolint:staticcheck // SA1019: types.DefaultParams().SendEnabled is deprecated: Use DefaultSendEnabled instead. (staticcheck) + suite.Require().Len(exportGenesis.Params.SendEnabled, 0) //nolint:staticcheck // we're testing the old way here suite.Require().Equal(types.DefaultParams().DefaultSendEnabled, exportGenesis.Params.DefaultSendEnabled) suite.Require().Equal(expTotalSupply, exportGenesis.Supply) suite.Require().Subset(exportGenesis.Balances, expectedBalances) diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index bf2c9ae122..5ed09a85f6 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -1862,10 +1862,10 @@ func (suite *KeeperTestSuite) TestMigrator_Migrate3to4() { require.NoError(migrator.Migrate3to4(ctx)) newParams := bankKeeper.GetParams(ctx) - require.Len(newParams.SendEnabled, 0) //nolint:staticcheck // SA1019: banktypes.Params.SendEnabled is deprecated: Use bankkeeper.IsSendEnabledDenom instead. + require.Len(newParams.SendEnabled, 0) //nolint:staticcheck // we're testing the old way here require.Equal(def, newParams.DefaultSendEnabled) - for _, se := range params.SendEnabled { //nolint:staticcheck // SA1019: banktypes.Params.SendEnabled is deprecated: Use bankkeeper.IsSendEnabledDenom instead. + for _, se := range params.SendEnabled { actual := bankKeeper.IsSendEnabledDenom(ctx, se.Denom) require.Equal(se.Enabled, actual, se.Denom) } @@ -1878,7 +1878,7 @@ func (suite *KeeperTestSuite) TestSetParams() { require := suite.Require() params := banktypes.NewParams(true) - params.SendEnabled = []*banktypes.SendEnabled{ //nolint:staticcheck // SA1019: banktypes.Params.SendEnabled is deprecated: Use bankkeeper.IsSendEnabledDenom instead. + params.SendEnabled = []*banktypes.SendEnabled{ {Denom: "paramscointrue", Enabled: true}, {Denom: "paramscoinfalse", Enabled: false}, } @@ -1887,7 +1887,7 @@ func (suite *KeeperTestSuite) TestSetParams() { suite.Run("stored params are as expected", func() { actual := bankKeeper.GetParams(ctx) require.True(actual.DefaultSendEnabled, "DefaultSendEnabled") - require.Len(actual.SendEnabled, 0, "SendEnabled") //nolint:staticcheck // SA1019: banktypes.Params.SendEnabled is deprecated: Use bankkeeper.IsSendEnabledDenom instead. + require.Len(actual.SendEnabled, 0, "SendEnabled") //nolint:staticcheck // we're testing the old way here }) suite.Run("send enabled params converted to store", func() { diff --git a/x/bank/keeper/send.go b/x/bank/keeper/send.go index c334a96412..d0440b9174 100644 --- a/x/bank/keeper/send.go +++ b/x/bank/keeper/send.go @@ -105,8 +105,8 @@ func (k BaseSendKeeper) SetParams(ctx context.Context, params types.Params) erro // Normally SendEnabled is deprecated but we still support it for backwards // compatibility. Using params.Validate() would fail due to the SendEnabled // deprecation. - if len(params.SendEnabled) > 0 { //nolint:staticcheck // SA1019: params.SendEnabled is deprecated - k.SetAllSendEnabled(ctx, params.SendEnabled) //nolint:staticcheck // SA1019: params.SendEnabled is deprecated + if len(params.SendEnabled) > 0 { + k.SetAllSendEnabled(ctx, params.SendEnabled) // override params without SendEnabled params = types.NewParams(params.DefaultSendEnabled) diff --git a/x/bank/migrations/v3/store_test.go b/x/bank/migrations/v3/store_test.go index a8184f75b4..3ef94ae2cd 100644 --- a/x/bank/migrations/v3/store_test.go +++ b/x/bank/migrations/v3/store_test.go @@ -126,6 +126,7 @@ func TestMigrateDenomMetaData(t *testing.T) { } func assertMetaDataEqual(t *testing.T, expected, actual types.Metadata) { + t.Helper() require.Equal(t, expected.GetBase(), actual.GetBase()) require.Equal(t, expected.GetDisplay(), actual.GetDisplay()) require.Equal(t, expected.GetDescription(), actual.GetDescription()) diff --git a/x/bank/simulation/genesis_test.go b/x/bank/simulation/genesis_test.go index de0ad2226d..4f4ec400f0 100644 --- a/x/bank/simulation/genesis_test.go +++ b/x/bank/simulation/genesis_test.go @@ -44,7 +44,7 @@ func TestRandomizedGenState(t *testing.T) { simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &bankGenesis) assert.Equal(t, true, bankGenesis.Params.GetDefaultSendEnabled(), "Params.GetDefaultSendEnabled") - assert.Len(t, bankGenesis.Params.GetSendEnabled(), 0, "Params.GetSendEnabled") //nolint:staticcheck // we're testing deprecated code here + assert.Len(t, bankGenesis.Params.GetSendEnabled(), 0, "Params.GetSendEnabled") //nolint:staticcheck // we're testing the old way here if assert.Len(t, bankGenesis.Balances, 3) { assert.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", bankGenesis.Balances[2].Address, "Balances[2] address") assert.Equal(t, "1000stake", bankGenesis.Balances[2].GetCoins().String(), "Balances[2] coins") diff --git a/x/bank/simulation/proposals_test.go b/x/bank/simulation/proposals_test.go index 0dcc42b02c..70371278c1 100644 --- a/x/bank/simulation/proposals_test.go +++ b/x/bank/simulation/proposals_test.go @@ -37,6 +37,6 @@ func TestProposalMsgs(t *testing.T) { assert.Assert(t, ok) assert.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority) - assert.Assert(t, len(msgUpdateParams.Params.SendEnabled) == 0) //nolint:staticcheck // we're testing deprecated code here + assert.Assert(t, len(msgUpdateParams.Params.SendEnabled) == 0) //nolint:staticcheck // we're testing the old way here assert.Equal(t, true, msgUpdateParams.Params.DefaultSendEnabled) } diff --git a/x/bank/types/balance_test.go b/x/bank/types/balance_test.go index 4f735e5954..a1063b7730 100644 --- a/x/bank/types/balance_test.go +++ b/x/bank/types/balance_test.go @@ -191,6 +191,7 @@ func BenchmarkSanitizeBalances1000(b *testing.B) { } func benchmarkSanitizeBalances(b *testing.B, nAddresses int) { + b.Helper() b.ReportAllocs() tokens := sdk.TokensFromConsensusPower(81, sdk.DefaultPowerReduction) coin := sdk.NewCoin("benchcoin", tokens) diff --git a/x/circuit/ante/circuit_test.go b/x/circuit/ante/circuit_test.go index 54fbbebeb4..594892652b 100644 --- a/x/circuit/ante/circuit_test.go +++ b/x/circuit/ante/circuit_test.go @@ -39,6 +39,7 @@ func (m MockCircuitBreaker) IsAllowed(ctx context.Context, typeURL string) (bool } func initFixture(t *testing.T) *fixture { + t.Helper() mockStoreKey := storetypes.NewKVStoreKey("test") encCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, bank.AppModuleBasic{}) mockclientCtx := client.Context{}. diff --git a/x/circuit/keeper/keeper_test.go b/x/circuit/keeper/keeper_test.go index f9f42b9b35..628d681e45 100644 --- a/x/circuit/keeper/keeper_test.go +++ b/x/circuit/keeper/keeper_test.go @@ -39,6 +39,7 @@ type fixture struct { } func initFixture(t *testing.T) *fixture { + t.Helper() encCfg := moduletestutil.MakeTestEncodingConfig(circuit.AppModuleBasic{}) ac := addresscodec.NewBech32Codec("cosmos") mockStoreKey := storetypes.NewKVStoreKey("test") diff --git a/x/feegrant/keeper/genesis_test.go b/x/feegrant/keeper/genesis_test.go index 776a51e287..ff0c2f9c21 100644 --- a/x/feegrant/keeper/genesis_test.go +++ b/x/feegrant/keeper/genesis_test.go @@ -39,6 +39,7 @@ type genesisFixture struct { } func initFixture(t *testing.T) *genesisFixture { + t.Helper() key := storetypes.NewKVStoreKey(feegrant.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) diff --git a/x/gov/abci_test.go b/x/gov/abci_test.go index 6fff0ecb03..8e4e7ef071 100644 --- a/x/gov/abci_test.go +++ b/x/gov/abci_test.go @@ -602,6 +602,7 @@ func TestExpeditedProposal_PassAndConversionToRegular(t *testing.T) { } func createValidators(t *testing.T, stakingMsgSvr stakingtypes.MsgServer, ctx sdk.Context, addrs []sdk.ValAddress, powerAmt []int64) { + t.Helper() require.True(t, len(addrs) <= len(pubkeys), "Not enough pubkeys specified at top of file.") for i := 0; i < len(addrs); i++ { @@ -629,6 +630,7 @@ func getDepositMultiplier(expedited bool) int64 { } func checkActiveProposalsQueue(t *testing.T, ctx sdk.Context, k *keeper.Keeper, invalid bool) { + t.Helper() err := k.ActiveProposalsQueue.Walk(ctx, collections.NewPrefixUntilPairRange[time.Time, uint64](ctx.BlockTime()), func(key collections.Pair[time.Time, uint64], value uint64) (stop bool, err error) { return false, err }) @@ -640,6 +642,7 @@ func checkActiveProposalsQueue(t *testing.T, ctx sdk.Context, k *keeper.Keeper, } func checkInactiveProposalsQueue(t *testing.T, ctx sdk.Context, k *keeper.Keeper, invalid bool) { + t.Helper() err := k.InactiveProposalsQueue.Walk(ctx, collections.NewPrefixUntilPairRange[time.Time, uint64](ctx.BlockTime()), func(key collections.Pair[time.Time, uint64], value uint64) (stop bool, err error) { return false, err }) diff --git a/x/gov/client/cli/util_test.go b/x/gov/client/cli/util_test.go index 956ea66960..683c319886 100644 --- a/x/gov/client/cli/util_test.go +++ b/x/gov/client/cli/util_test.go @@ -214,6 +214,7 @@ func TestParseSubmitProposal(t *testing.T) { } func getCommandHelp(t *testing.T, cmd *cobra.Command) string { + t.Helper() // Create a pipe, so we can capture the help sent to stdout. reader, writer, err := os.Pipe() require.NoError(t, err, "creating os.Pipe()") diff --git a/x/gov/common_test.go b/x/gov/common_test.go index 3edd473d92..fcca0590bc 100644 --- a/x/gov/common_test.go +++ b/x/gov/common_test.go @@ -45,6 +45,7 @@ var ( // mkTestLegacyContent creates a MsgExecLegacyContent for testing purposes. func mkTestLegacyContent(t *testing.T) *v1.MsgExecLegacyContent { + t.Helper() msgContent, err := v1.NewLegacyContent(TestProposal, authtypes.NewModuleAddress(types.ModuleName).String()) require.NoError(t, err) @@ -113,6 +114,7 @@ type suite struct { } func createTestSuite(t *testing.T) suite { + t.Helper() res := suite{} app, err := simtestutil.SetupWithConfiguration( diff --git a/x/gov/keeper/common_test.go b/x/gov/keeper/common_test.go index 3850ede817..6d240a135e 100644 --- a/x/gov/keeper/common_test.go +++ b/x/gov/keeper/common_test.go @@ -64,6 +64,7 @@ func setupGovKeeper(t *testing.T) ( moduletestutil.TestEncodingConfig, sdk.Context, ) { + t.Helper() key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) diff --git a/x/gov/migrations/v3/store_test.go b/x/gov/migrations/v3/store_test.go index 0808246127..1bd37b66f6 100644 --- a/x/gov/migrations/v3/store_test.go +++ b/x/gov/migrations/v3/store_test.go @@ -76,6 +76,7 @@ func TestMigrateStore(t *testing.T) { } func compareProps(t *testing.T, oldProp v1beta1.Proposal, newProp v1.Proposal) { + t.Helper() require.Equal(t, oldProp.ProposalId, newProp.Id) require.Equal(t, oldProp.TotalDeposit.String(), sdk.Coins(newProp.TotalDeposit).String()) require.Equal(t, oldProp.Status.String(), newProp.Status.String()) diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index ea88bca877..e0201f2b1d 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -405,6 +405,7 @@ type suite struct { // returns context and an app with updated mint keeper func createTestSuite(t *testing.T, isCheckTx bool) (suite, sdk.Context) { + t.Helper() res := suite{} app, err := simtestutil.Setup( @@ -435,6 +436,7 @@ func getTestingAccounts( accountKeeper authkeeper.AccountKeeper, bankKeeper bankkeeper.Keeper, stakingKeeper *stakingkeeper.Keeper, ctx sdk.Context, n int, ) []simtypes.Account { + t.Helper() accounts := simtypes.RandomAccounts(r, n) initAmt := stakingKeeper.TokensFromConsensusPower(ctx, 200) diff --git a/x/group/internal/orm/orm_scenario_test.go b/x/group/internal/orm/orm_scenario_test.go index f93fd76775..e613b8937a 100644 --- a/x/group/internal/orm/orm_scenario_test.go +++ b/x/group/internal/orm/orm_scenario_test.go @@ -396,6 +396,7 @@ func TestExportImportStatePrimaryKeyTable(t *testing.T) { } func assertIndex(t *testing.T, store storetypes.KVStore, index Index, v testdata.TableModel, searchKey interface{}) { + t.Helper() it, err := index.Get(store, searchKey) require.NoError(t, err) @@ -407,6 +408,7 @@ func assertIndex(t *testing.T, store storetypes.KVStore, index Index, v testdata } func first(t *testing.T, it Iterator) ([]byte, testdata.TableModel) { + t.Helper() var loaded testdata.TableModel key, err := First(it, &loaded) require.NoError(t, err) diff --git a/x/group/keeper/grpc_query_test.go b/x/group/keeper/grpc_query_test.go index f5e7b07a13..f73ab33e63 100644 --- a/x/group/keeper/grpc_query_test.go +++ b/x/group/keeper/grpc_query_test.go @@ -26,6 +26,7 @@ import ( ) func initKeeper(t *testing.T) (types.Context, groupkeeper.Keeper, []types.AccAddress, group.QueryClient) { + t.Helper() var ( groupKeeper groupkeeper.Keeper interfaceRegistry codectypes.InterfaceRegistry diff --git a/x/simulation/mock_cometbft.go b/x/simulation/mock_cometbft.go index 80ef32282c..336108adc0 100644 --- a/x/simulation/mock_cometbft.go +++ b/x/simulation/mock_cometbft.go @@ -85,6 +85,7 @@ func updateValidators( updates []abci.ValidatorUpdate, event func(route, op, evResult string), ) map[string]mockValidator { + tb.Helper() for _, update := range updates { str := fmt.Sprintf("%X", update.PubKey.GetEd25519()) diff --git a/x/simulation/simulate.go b/x/simulation/simulate.go index 4ee83ea8d6..3a118dde71 100644 --- a/x/simulation/simulate.go +++ b/x/simulation/simulate.go @@ -65,6 +65,7 @@ func SimulateFromSeed( config simulation.Config, cdc codec.JSONCodec, ) (stopEarly bool, exportedParams Params, err error) { + tb.Helper() // in case we have to end early, don't os.Exit so that we can run cleanup code. testingMode, _, b := getTestingMode(tb) @@ -142,8 +143,8 @@ func SimulateFromSeed( logWriter := NewLogWriter(testingMode) blockSimulator := createBlockSimulator( - testingMode, tb, + testingMode, w, params, eventStats.Tally, @@ -193,13 +194,13 @@ func SimulateFromSeed( // run queued operations; ignores block size if block size is too small numQueuedOpsRan, futureOps := runQueuedOperations( - operationQueue, int(blockHeight), tb, r, app, ctx, accs, logWriter, + tb, operationQueue, int(blockHeight), r, app, ctx, accs, logWriter, eventStats.Tally, config.Lean, config.ChainID, ) - numQueuedTimeOpsRan, timeFutureOps := runQueuedTimeOperations( + numQueuedTimeOpsRan, timeFutureOps := runQueuedTimeOperations(tb, timeOperationQueue, int(blockHeight), blockTime, - tb, r, app, ctx, accs, logWriter, eventStats.Tally, + r, app, ctx, accs, logWriter, eventStats.Tally, config.Lean, config.ChainID, ) @@ -285,11 +286,12 @@ type blockSimFn func( // Returns a function to simulate blocks. Written like this to avoid constant // parameters being passed everytime, to minimize memory overhead. -func createBlockSimulator(testingMode bool, tb testing.TB, w io.Writer, params Params, +func createBlockSimulator(tb testing.TB, testingMode bool, w io.Writer, params Params, event func(route, op, evResult string), ops WeightedOperations, operationQueue OperationQueue, timeOperationQueue []simulation.FutureOperation, logWriter LogWriter, config simulation.Config, ) blockSimFn { + tb.Helper() lastBlockSizeState := 0 // state for [4 * uniform distribution] blocksize := 0 selectOp := ops.getSelectOpFn() @@ -352,11 +354,12 @@ Comment: %s`, } } -func runQueuedOperations(queueOps map[int][]simulation.Operation, - height int, tb testing.TB, r *rand.Rand, app *baseapp.BaseApp, +func runQueuedOperations(tb testing.TB, queueOps map[int][]simulation.Operation, + height int, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simulation.Account, logWriter LogWriter, event func(route, op, evResult string), lean bool, chainID string, ) (numOpsRan int, allFutureOps []simulation.FutureOperation) { + tb.Helper() queuedOp, ok := queueOps[height] if !ok { return 0, nil @@ -388,12 +391,13 @@ func runQueuedOperations(queueOps map[int][]simulation.Operation, return numOpsRan, allFutureOps } -func runQueuedTimeOperations(queueOps []simulation.FutureOperation, - height int, currentTime time.Time, tb testing.TB, r *rand.Rand, +func runQueuedTimeOperations(tb testing.TB, queueOps []simulation.FutureOperation, + height int, currentTime time.Time, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simulation.Account, logWriter LogWriter, event func(route, op, evResult string), lean bool, chainID string, ) (numOpsRan int, allFutureOps []simulation.FutureOperation) { + tb.Helper() // Keep all future operations allFutureOps = make([]simulation.FutureOperation, 0) diff --git a/x/simulation/util.go b/x/simulation/util.go index 263a7340b0..e9bc2335df 100644 --- a/x/simulation/util.go +++ b/x/simulation/util.go @@ -15,6 +15,7 @@ import ( ) func getTestingMode(tb testing.TB) (testingMode bool, t *testing.T, b *testing.B) { + tb.Helper() testingMode = false if _t, ok := tb.(*testing.T); ok { diff --git a/x/staking/bench_test.go b/x/staking/bench_test.go index 6f8461f11c..3d61ee4922 100644 --- a/x/staking/bench_test.go +++ b/x/staking/bench_test.go @@ -25,6 +25,7 @@ func BenchmarkValidateGenesis400Validators(b *testing.B) { } func benchmarkValidateGenesis(b *testing.B, n int) { + b.Helper() b.ReportAllocs() validators := make([]types.Validator, 0, n) diff --git a/x/staking/migrations/v4/migrations_test.go b/x/staking/migrations/v4/migrations_test.go index 90fa7f1ec9..3c702a3c5f 100644 --- a/x/staking/migrations/v4/migrations_test.go +++ b/x/staking/migrations/v4/migrations_test.go @@ -99,6 +99,7 @@ func TestMigrate(t *testing.T) { // createOldStateUnbonding will create the ubd entries with duplicate heights // 10 duplicate heights and 10 unique ubd with creation height func createOldStateUnbonding(t *testing.T, creationHeight int64, valAddr sdk.ValAddress, accAddr sdk.AccAddress, cdc codec.BinaryCodec, store storetypes.KVStore) error { + t.Helper() unbondBalance := math.NewInt(100) completionTime := time.Now() ubdEntries := make([]types.UnbondingDelegationEntry, 0, 10) @@ -131,6 +132,7 @@ func createOldStateUnbonding(t *testing.T, creationHeight int64, valAddr sdk.Val } func getUBD(t *testing.T, accAddr sdk.AccAddress, valAddr sdk.ValAddress, store storetypes.KVStore, cdc codec.BinaryCodec) types.UnbondingDelegation { + t.Helper() // get the unbonding delegations var ubdRes types.UnbondingDelegation ubdbz := store.Get(getUBDKey(accAddr, valAddr)) diff --git a/x/staking/testutil/helpers.go b/x/staking/testutil/helpers.go index cfe9c0cc3e..7ed64e4613 100644 --- a/x/staking/testutil/helpers.go +++ b/x/staking/testutil/helpers.go @@ -30,6 +30,7 @@ type Helper struct { // NewHelper creates a new instance of Helper. func NewHelper(t *testing.T, ctx sdk.Context, k *keeper.Keeper) *Helper { + t.Helper() return &Helper{t, keeper.NewMsgServerImpl(k), k, ctx, ZeroCommission(), sdk.DefaultBondDenom} } diff --git a/x/staking/testutil/validator.go b/x/staking/testutil/validator.go index 216d2fa31f..fccecba487 100644 --- a/x/staking/testutil/validator.go +++ b/x/staking/testutil/validator.go @@ -11,8 +11,9 @@ import ( ) // NewValidator is a testing helper method to create validators in tests -func NewValidator(t testing.TB, operator sdk.ValAddress, pubKey cryptotypes.PubKey) types.Validator { +func NewValidator(tb testing.TB, operator sdk.ValAddress, pubKey cryptotypes.PubKey) types.Validator { + tb.Helper() v, err := types.NewValidator(operator, pubKey, types.Description{}) - require.NoError(t, err) + require.NoError(tb, err) return v } diff --git a/x/staking/types/historical_info_test.go b/x/staking/types/historical_info_test.go index d186a415d2..142780146f 100644 --- a/x/staking/types/historical_info_test.go +++ b/x/staking/types/historical_info_test.go @@ -20,6 +20,7 @@ var header = cmtproto.Header{ } func createValidators(t *testing.T) []types.Validator { + t.Helper() return []types.Validator{ newValidator(t, valAddr1, pk1), newValidator(t, valAddr2, pk2), diff --git a/x/staking/types/validator_test.go b/x/staking/types/validator_test.go index 537a468ca0..cbc16bb8ee 100644 --- a/x/staking/types/validator_test.go +++ b/x/staking/types/validator_test.go @@ -345,6 +345,7 @@ func mkValidator(tokens int64, shares math.LegacyDec) types.Validator { // Creates a new validators and asserts the error check. func newValidator(t *testing.T, operator sdk.ValAddress, pubKey cryptotypes.PubKey) types.Validator { + t.Helper() v, err := types.NewValidator(operator, pubKey, types.Description{}) require.NoError(t, err) return v diff --git a/x/tx/signing/aminojson/bench_test.go b/x/tx/signing/aminojson/bench_test.go index 9ccc11ddcf..49f9302d4b 100644 --- a/x/tx/signing/aminojson/bench_test.go +++ b/x/tx/signing/aminojson/bench_test.go @@ -40,6 +40,7 @@ func BenchmarkAminoJSONDefaultSort(b *testing.B) { } func benchmarkAminoJSON(b *testing.B, addNaiveSort bool) { + b.Helper() enc := aminojson.NewEncoder(aminojson.EncoderOptions{DoNotSortFields: addNaiveSort}) b.ReportAllocs() b.ResetTimer() @@ -54,6 +55,7 @@ func benchmarkAminoJSON(b *testing.B, addNaiveSort bool) { } func runAminoJSON(b *testing.B, enc aminojson.Encoder, addNaiveSort bool) []byte { + b.Helper() bz, err := enc.Marshal(msg) if err != nil { b.Fatal(err) diff --git a/x/tx/signing/aminojson/json_marshal_test.go b/x/tx/signing/aminojson/json_marshal_test.go index 08d4263cd2..4c2d6d35d9 100644 --- a/x/tx/signing/aminojson/json_marshal_test.go +++ b/x/tx/signing/aminojson/json_marshal_test.go @@ -117,12 +117,13 @@ func TestAminoJSON(t *testing.T) { require.Equal(t, string(sortedBz), string(encodedDefaultBz)) } -func naiveSortedJSON(t testing.TB, jsonToSort []byte) []byte { +func naiveSortedJSON(tb testing.TB, jsonToSort []byte) []byte { + tb.Helper() var c interface{} err := json.Unmarshal(jsonToSort, &c) - assert.NilError(t, err) + assert.NilError(tb, err) sortedBz, err := json.Marshal(c) - assert.NilError(t, err) + assert.NilError(tb, err) return sortedBz } diff --git a/x/tx/signing/textual/coins_test.go b/x/tx/signing/textual/coins_test.go index cc30c4cd73..ea139bd451 100644 --- a/x/tx/signing/textual/coins_test.go +++ b/x/tx/signing/textual/coins_test.go @@ -66,6 +66,7 @@ func TestCoinsJSONTestcases(t *testing.T) { // rendering, so we lose initial Coins ordering. Instead, we just check // set equality using a map. func checkCoinsEqual(t *testing.T, l1, l2 protoreflect.List) { + t.Helper() require.Equal(t, l1.Len(), l2.Len()) coinsMap := make(map[string]*basev1beta1.Coin, l1.Len()) @@ -85,6 +86,7 @@ func checkCoinsEqual(t *testing.T, l1, l2 protoreflect.List) { } func checkCoinEqual(t *testing.T, coin, coin1 *basev1beta1.Coin) { + t.Helper() require.Equal(t, coin1.Denom, coin.Denom) v, ok := math.NewIntFromString(coin.Amount) require.True(t, ok) diff --git a/x/tx/signing/textual/dec_test.go b/x/tx/signing/textual/dec_test.go index defb6d9cc5..f8c7b3ebe2 100644 --- a/x/tx/signing/textual/dec_test.go +++ b/x/tx/signing/textual/dec_test.go @@ -38,6 +38,7 @@ func TestDecJSONTestcases(t *testing.T) { } func checkDecTest(t *testing.T, r textual.ValueRenderer, pv protoreflect.Value, expected string) { + t.Helper() screens, err := r.Format(context.Background(), pv) require.NoError(t, err) require.Len(t, screens, 1) diff --git a/x/tx/signing/textual/int_test.go b/x/tx/signing/textual/int_test.go index 2767a2430c..100ec30971 100644 --- a/x/tx/signing/textual/int_test.go +++ b/x/tx/signing/textual/int_test.go @@ -78,6 +78,7 @@ func TestIntJSONTestcases(t *testing.T) { // checkNumberTest checks that the output of a number value renderer // matches the expected string. Only use it to test numbers. func checkNumberTest(t *testing.T, r textual.ValueRenderer, pv protoreflect.Value, expected string) { + t.Helper() screens, err := r.Format(context.Background(), pv) require.NoError(t, err) require.Len(t, screens, 1) diff --git a/x/tx/signing/textual/timestamp_test.go b/x/tx/signing/textual/timestamp_test.go index c3f047401e..65d2a99a93 100644 --- a/x/tx/signing/textual/timestamp_test.go +++ b/x/tx/signing/textual/timestamp_test.go @@ -43,6 +43,7 @@ func TestTimestampJsonTestcasesExtraneousNanos(t *testing.T) { } func testTimestampJSONTestcases(t *testing.T, raw []byte) { + t.Helper() var testcases []timestampJSONTest err := json.Unmarshal(raw, &testcases) require.NoError(t, err) diff --git a/x/tx/signing/textual/tx_test.go b/x/tx/signing/textual/tx_test.go index f12b0d0138..47acb0a8be 100644 --- a/x/tx/signing/textual/tx_test.go +++ b/x/tx/signing/textual/tx_test.go @@ -117,6 +117,7 @@ func TestTxJSONTestcases(t *testing.T) { // createTextualData creates a Textual data give then JSON // test case. func createTextualData(t *testing.T, jsonTx txJSONTestTx, jsonSignerData json.RawMessage) (*txv1beta1.TxBody, []byte, *txv1beta1.AuthInfo, []byte, signing.SignerData) { + t.Helper() body := &txv1beta1.TxBody{} authInfo := &txv1beta1.AuthInfo{} protoSignerData := &textualpb.SignerData{} diff --git a/x/upgrade/abci_test.go b/x/upgrade/abci_test.go index f7f895a8c0..f013081d47 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -45,6 +45,7 @@ type TestSuite struct { var s TestSuite func setupTest(t *testing.T, height int64, skip map[int64]bool) *TestSuite { + t.Helper() s.encCfg = moduletestutil.MakeTestEncodingConfig(upgrade.AppModuleBasic{}) key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) @@ -103,6 +104,7 @@ func TestCanOverwriteScheduleUpgrade(t *testing.T) { } func VerifyDoUpgrade(t *testing.T) { + t.Helper() t.Log("Verify that a panic happens at the upgrade height") newCtx := s.ctx.WithHeaderInfo(header.Info{Height: s.ctx.HeaderInfo().Height + 1, Time: time.Now()}) @@ -121,6 +123,7 @@ func VerifyDoUpgrade(t *testing.T) { } func VerifyDoUpgradeWithCtx(t *testing.T, newCtx sdk.Context, proposalName string) { + t.Helper() t.Log("Verify that a panic happens at the upgrade height") err := s.module.BeginBlock(newCtx) @@ -171,6 +174,7 @@ func TestHaltIfTooNew(t *testing.T) { } func VerifyCleared(t *testing.T, newCtx sdk.Context) { + t.Helper() t.Log("Verify that the upgrade plan has been cleared") _, err := s.keeper.GetUpgradePlan(newCtx) require.ErrorIs(t, err, types.ErrNoUpgradePlanFound) @@ -213,6 +217,7 @@ func TestPlanStringer(t *testing.T) { } func VerifyNotDone(t *testing.T, newCtx sdk.Context, name string) { + t.Helper() t.Log("Verify that upgrade was not done") height, err := s.keeper.GetDoneHeight(newCtx, name) require.Zero(t, height) @@ -220,6 +225,7 @@ func VerifyNotDone(t *testing.T, newCtx sdk.Context, name string) { } func VerifyDone(t *testing.T, newCtx sdk.Context, name string) { + t.Helper() t.Log("Verify that the upgrade plan has been executed") height, err := s.keeper.GetDoneHeight(newCtx, name) require.NotZero(t, height) @@ -227,6 +233,7 @@ func VerifyDone(t *testing.T, newCtx sdk.Context, name string) { } func VerifySet(t *testing.T, skipUpgradeHeights map[int64]bool) { + t.Helper() t.Log("Verify if the skip upgrade has been set") for k := range skipUpgradeHeights { diff --git a/x/upgrade/plan/downloader_test.go b/x/upgrade/plan/downloader_test.go index 7768b30c16..16ef29585d 100644 --- a/x/upgrade/plan/downloader_test.go +++ b/x/upgrade/plan/downloader_test.go @@ -109,6 +109,7 @@ func (s *DownloaderTestSuite) saveSrcTestFile(f *TestFile) string { // requireFileExistsAndIsExecutable requires that the given file exists and is executable. func requireFileExistsAndIsExecutable(t *testing.T, path string) { + t.Helper() info, err := os.Stat(path) require.NoError(t, err, "stat error") perm := info.Mode().Perm() @@ -120,6 +121,7 @@ func requireFileExistsAndIsExecutable(t *testing.T, path string) { // requireFileEquals requires that the contents of the file at the given path // is equal to the contents of the given TestFile. func requireFileEquals(t *testing.T, path string, tf *TestFile) { + t.Helper() file, err := os.ReadFile(path) require.NoError(t, err, "reading file") require.Equal(t, string(tf.Contents), string(file), "file contents") @@ -127,6 +129,7 @@ func requireFileEquals(t *testing.T, path string, tf *TestFile) { // makeFileUrl converts the given path to a URL with the correct checksum query parameter. func makeFileURL(t *testing.T, path string) string { + t.Helper() f, err := os.Open(path) require.NoError(t, err, "opening file") defer f.Close() diff --git a/x/upgrade/plan/info_test.go b/x/upgrade/plan/info_test.go index b9b89e369e..c74b4e4843 100644 --- a/x/upgrade/plan/info_test.go +++ b/x/upgrade/plan/info_test.go @@ -47,11 +47,13 @@ func (s *InfoTestSuite) TestParseInfo() { } makeInfoStrFuncString := func(val string) func(t *testing.T) string { return func(t *testing.T) string { + t.Helper() return val } } makeInfoStrFuncURL := func(file string) func(t *testing.T) string { return func(t *testing.T) string { + t.Helper() return makeFileURL(t, file) } } diff --git a/x/upgrade/types/storeloader_test.go b/x/upgrade/types/storeloader_test.go index 4ed04a49d8..be18a05708 100644 --- a/x/upgrade/types/storeloader_test.go +++ b/x/upgrade/types/storeloader_test.go @@ -26,6 +26,7 @@ func useUpgradeLoader(height int64, upgrades *storetypes.StoreUpgrades) func(*ba } func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { + t.Helper() rs := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing)) key := storetypes.NewKVStoreKey(storeKey) @@ -43,6 +44,7 @@ func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { } func checkStore(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte) { + t.Helper() rs := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing)) key := storetypes.NewKVStoreKey(storeKey)