From d60e44aa61e82ace2b375fae1646faa7c245fde5 Mon Sep 17 00:00:00 2001 From: Jaeseung Lee <41176085+tkxkd0159@users.noreply.github.com> Date: Tue, 18 Jun 2024 23:53:10 +0900 Subject: [PATCH] style: Improve code quality with new linters (#1414) * Use golangci-lint v1.59 * Bump golangci-lint ci from 1.55 to 1.59 * Add useful linters * Apply copyloopvar * Apply errchkjson, tenv * Apply `wastedassign` * Apply `errorlint` --- .github/workflows/lint.yml | 2 +- .golangci.yml | 52 +++++++++++-------- CHANGELOG.md | 1 + Makefile | 2 +- baseapp/abci_test.go | 2 - baseapp/deliver_tx_test.go | 3 -- client/cmd_test.go | 2 - client/config/cmd.go | 6 +-- client/config/config.go | 10 ++-- client/config/config_test.go | 1 - client/debug/main.go | 2 +- client/flags/flags_test.go | 2 - client/grpc/tmservice/service_test.go | 4 -- client/keys/add_ledger_test.go | 1 - client/keys/add_test.go | 1 - client/keys/codec_test.go | 2 - client/keys/list_test.go | 1 - client/keys/parse_test.go | 1 - client/keys/show.go | 4 +- client/keys/show_test.go | 2 - client/tx/tx_test.go | 11 ++-- client/utils_test.go | 1 - codec/amino_codec_test.go | 2 - codec/codec_common_test.go | 1 - codec/proto_codec_test.go | 2 - codec/unknownproto/unit_helpers_test.go | 1 - codec/unknownproto/unknown_fields_test.go | 4 -- crypto/armor.go | 2 +- crypto/hd/hdpath_test.go | 4 -- crypto/keyring/keyring.go | 12 ++--- crypto/keyring/signing_algorithms_test.go | 1 - crypto/keys/multisig/codec.go | 1 - .../keys/secp256k1/secp256k1_internal_test.go | 1 - crypto/keys/secp256k1/secp256k1_test.go | 1 - crypto/ledger/ledger_mock.go | 2 +- crypto/ledger/ledger_secp256k1.go | 6 +-- crypto/types/compact_bit_array_test.go | 6 --- server/export.go | 2 +- .../grpc/gogoreflection/serverreflection.go | 11 ++-- server/pruning_test.go | 2 - server/start.go | 2 +- server/tm_cmds_test.go | 5 +- server/util.go | 2 +- server/util_test.go | 24 ++++----- simapp/genesis_account_test.go | 1 - simapp/sim_bench_test.go | 1 - simapp/simd/cmd/genaccounts_test.go | 1 - simapp/simd/cmd/root_test.go | 1 - simapp/simd/main.go | 7 +-- simapp/utils_test.go | 1 - snapshots/chunk.go | 3 +- snapshots/helpers_test.go | 2 +- store/cachekv/search_test.go | 2 - store/iavl/store_test.go | 2 - store/rootmulti/snapshot_test.go | 2 - store/rootmulti/store.go | 6 +-- store/rootmulti/store_test.go | 2 - store/types/gas_test.go | 1 - store/types/iterator_test.go | 1 - store/types/store_test.go | 1 - types/address/store_key_test.go | 1 - types/address_test.go | 2 - types/coin_test.go | 6 --- types/context_test.go | 1 - types/dec_coin.go | 2 +- types/dec_coin_test.go | 7 --- types/decimal.go | 8 ++- types/decimal_internal_test.go | 1 - types/decimal_test.go | 1 - types/errors/abci_test.go | 1 - types/events_test.go | 1 - types/int.go | 2 +- types/int_test.go | 1 - types/simulation/account_test.go | 3 -- types/simulation/rand_util_test.go | 3 -- types/uint.go | 4 +- types/uint_test.go | 2 - types/utils_test.go | 2 - x/auth/ante/basic_test.go | 2 - x/auth/ante/sigverify.go | 6 +-- x/auth/client/testutil/suite.go | 9 +--- x/auth/client/tx.go | 4 +- x/auth/client/tx_test.go | 3 +- x/auth/legacy/v043/store_test.go | 1 - x/auth/simulation/decoder_test.go | 1 - x/auth/tx/encode_decode_test.go | 3 -- x/auth/tx/service_test.go | 2 - x/auth/types/account_test.go | 3 -- x/auth/types/params_test.go | 1 - x/auth/types/permissions_test.go | 1 - x/auth/vesting/client/testutil/suite.go | 2 - x/auth/vesting/handler_test.go | 2 - x/auth/vesting/types/vesting_account_test.go | 2 - x/authz/client/testutil/grpc.go | 2 - x/authz/client/testutil/query.go | 4 -- x/authz/client/testutil/tx.go | 8 --- x/authz/keeper/grpc_query_test.go | 4 -- x/authz/simulation/decoder_test.go | 1 - x/bank/client/testutil/grpc.go | 3 -- x/bank/client/testutil/suite.go | 8 --- x/bank/keeper/genesis.go | 2 +- x/bank/keeper/genesis_test.go | 1 - x/bank/keeper/keeper.go | 8 +-- x/bank/simulation/genesis_test.go | 2 - x/bank/types/balance_test.go | 2 - x/bank/types/genesis_test.go | 1 - x/bank/types/key_test.go | 1 - x/bank/types/metadata_test.go | 2 - x/bank/types/params_test.go | 1 - x/bankplus/keeper/keeper_test.go | 1 - x/capability/simulation/decoder_test.go | 1 - x/capability/simulation/genesis_test.go | 2 - x/capability/types/genesis_test.go | 1 - x/collection/client/testutil/query.go | 32 ------------ x/collection/client/testutil/tx.go | 44 ---------------- x/collection/msgs_test.go | 1 - x/crisis/client/testsuite/suite.go | 2 - x/crisis/handler_test.go | 1 - x/distribution/client/common/common_test.go | 1 - x/distribution/client/testutil/grpc.go | 8 --- x/distribution/client/testutil/suite.go | 22 -------- x/distribution/keeper/allocation_test.go | 4 +- x/distribution/legacy/v043/store_test.go | 1 - x/distribution/simulation/decoder_test.go | 1 - x/distribution/simulation/genesis_test.go | 2 - x/distribution/types/params_internal_test.go | 1 - x/evidence/client/testutil/suite.go | 2 - x/evidence/simulation/decoder_test.go | 1 - x/evidence/types/evidence_test.go | 1 - x/fbridge/keeper/transfer.go | 2 +- x/fbridge/types/msgs_test.go | 1 - x/feegrant/client/testutil/suite.go | 14 ----- x/feegrant/grant_test.go | 1 - x/feegrant/keeper/genesis_test.go | 1 - x/feegrant/keeper/keeper_test.go | 2 - x/feegrant/simulation/decoder_test.go | 1 - x/feegrant/types/grant_test.go | 1 - x/foundation/client/testutil/grpc.go | 1 - x/foundation/client/testutil/query.go | 24 --------- x/foundation/client/testutil/tx.go | 24 --------- x/foundation/genesis_test.go | 2 - x/foundation/keeper/internal/keeper_test.go | 1 - x/foundation/keeper/internal/proposal.go | 2 - x/foundation/msgs_test.go | 8 --- x/fswap/client/testutil/grpc.go | 4 -- x/fswap/client/testutil/query.go | 8 --- x/fswap/client/testutil/tx.go | 6 --- x/fswap/types/msgs_test.go | 1 - x/genutil/client/cli/init_test.go | 1 - x/genutil/client/testutil/helpers.go | 2 +- x/genutil/client/testutil/migrate.go | 1 - x/genutil/client/testutil/suite.go | 2 - x/genutil/client/testutil/validate_genesis.go | 1 - x/genutil/utils_test.go | 1 - x/gov/client/cli/query.go | 10 ++-- x/gov/client/testutil/grpc.go | 8 --- x/gov/client/testutil/suite.go | 21 -------- x/gov/client/utils/query_test.go | 2 - x/gov/genesis_test.go | 2 +- x/gov/keeper/deposit_test.go | 2 +- x/gov/keeper/querier_test.go | 1 - x/gov/legacy/v043/store_test.go | 1 - x/gov/simulation/decoder_test.go | 1 - x/gov/simulation/genesis_test.go | 2 - x/gov/simulation/operations.go | 1 - x/gov/types/proposal.go | 10 +++- x/gov/types/vote.go | 15 ++++-- x/mint/client/testutil/grpc.go | 1 - x/mint/client/testutil/suite.go | 6 --- x/mint/simulation/decoder_test.go | 1 - x/mint/simulation/genesis_test.go | 2 - x/params/client/testutil/grpc.go | 1 - x/params/client/testutil/suite.go | 2 - x/params/keeper/keeper_test.go | 7 --- x/params/proposal_handler_test.go | 1 - x/params/types/subspace.go | 2 +- x/params/types/subspace_test.go | 1 - x/simulation/operation.go | 1 - x/slashing/client/testutil/grpc.go | 2 - x/slashing/client/testutil/suite.go | 6 --- x/slashing/legacy/v043/store_test.go | 1 - x/slashing/simulation/decoder_test.go | 1 - x/slashing/simulation/genesis_test.go | 2 - x/staking/client/cli/query.go | 2 +- x/staking/client/cli/tx.go | 2 +- x/staking/client/cli/tx_test.go | 1 - x/staking/client/testutil/grpc.go | 14 ----- x/staking/client/testutil/suite.go | 25 --------- x/staking/genesis_test.go | 1 - x/staking/handler_test.go | 8 +-- x/staking/keeper/delegation_test.go | 2 +- x/staking/keeper/slash.go | 2 +- x/staking/legacy/v043/store_test.go | 1 - x/staking/simulation/decoder_test.go | 1 - x/staking/simulation/genesis_test.go | 2 - x/staking/types/authz_test.go | 1 - x/staking/types/msg_test.go | 2 - x/token/client/testutil/query.go | 10 ---- x/token/client/testutil/tx.go | 22 -------- x/token/msgs_test.go | 2 - x/upgrade/keeper/grpc_query_test.go | 2 - x/upgrade/keeper/keeper_test.go | 2 - x/upgrade/types/plan_test.go | 3 -- x/upgrade/types/proposal_test.go | 2 - x/upgrade/types/storeloader_test.go | 1 - 205 files changed, 155 insertions(+), 688 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 04d347826d..831ddeb22f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -30,7 +30,7 @@ jobs: - uses: golangci/golangci-lint-action@v6 with: # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.55 + version: v1.59 args: --timeout 10m github-token: ${{ secrets.GITHUB_TOKEN }} if: env.GIT_DIFF diff --git a/.golangci.yml b/.golangci.yml index 96c08da061..19a9ce33b0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,47 +1,59 @@ run: tests: true timeout: 15m - sort-results: true allow-parallel-runners: true - exclude-dir: testutil/testdata - skip-files: - - server/grpc/gogoreflection/fix_registration.go - - "fix_registration.go" - - ".*\\.pb\\.go$" - - ".*\\.pb\\.gw\\.go$" - - ".*\\.pulsar\\.go$" - - crypto/keys/secp256k1/internal/* build-tags: - ledger - goleveldb - test_ledger_mock +output: + sort-results: true + linters: disable-all: true enable: - errcheck - - dogsled - - exportloopref - - goconst - - gocritic - - gci - - gofumpt - - gosec - gosimple - govet - ineffassign - - misspell + - staticcheck + - unused + - dogsled + - gosec + - gci + - gofumpt + - goconst + - gocritic - nakedret - nolintlint - - staticcheck - revive + - misspell - stylecheck - typecheck - thelper - unconvert - - unused + - asasalint + - asciicheck + - bidichk + - bodyclose + - copyloopvar + - errchkjson + - errorlint + - tenv + - wastedassign + - fatcontext issues: + exclude-dirs: + - "testdata$" + exclude-files: + - server/grpc/gogoreflection/fix_registration.go + - "fix_registration.go" + - ".*\\.pb\\.go$" + - ".*\\.pb\\.gw\\.go$" + - ".*\\.pulsar\\.go$" + - crypto/keys/secp256k1/internal/* exclude-rules: - text: "Use of weak random number generator" linters: @@ -156,8 +168,6 @@ linters-settings: extra-rules: true dogsled: max-blank-identifiers: 6 - maligned: - suggest-new: true nolintlint: allow-unused: false require-explanation: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c0b77352f..697867f8bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -97,6 +97,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/fswap) [\#1379](https://github.com/Finschia/finschia-sdk/pull/1379) add missing router registration * (x/fswap) [\#1385](https://github.com/Finschia/finschia-sdk/pull/1385) add accidentally deleted event emissions(EventSetSwap, EventAddDenomMetadata) * (x/fswap) [\#1392](https://github.com/Finschia/finschia-sdk/pull/1392) fix dummy denom coin data for test in fswap +* (style) [\#1414](https://github.com/Finschia/finschia-sdk/pull/1414) improve code quality with new linters ### Removed diff --git a/Makefile b/Makefile index b1e4a18d7b..f42e8e834b 100644 --- a/Makefile +++ b/Makefile @@ -342,7 +342,7 @@ lint: golangci-lint find . -name '*.go' -type f -not -path "*.git*" | xargs gofmt -d -s golangci-lint: - @go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2 + @go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59 lint-fix: golangci-lint golangci-lint run --fix --out-format=tab --issues-exit-code=0 diff --git a/baseapp/abci_test.go b/baseapp/abci_test.go index 9b3f5cd661..addd1545a0 100644 --- a/baseapp/abci_test.go +++ b/baseapp/abci_test.go @@ -110,8 +110,6 @@ func TestGetBlockRentionHeight(t *testing.T) { } for name, tc := range testCases { - tc := tc - tc.bapp.SetParamStore(¶mStore{db: dbm.NewMemDB()}) tc.bapp.InitChain(abci.RequestInitChain{ ConsensusParams: &abci.ConsensusParams{ diff --git a/baseapp/deliver_tx_test.go b/baseapp/deliver_tx_test.go index 3194728e7d..ce907120ad 100644 --- a/baseapp/deliver_tx_test.go +++ b/baseapp/deliver_tx_test.go @@ -49,7 +49,6 @@ func TestLoadSnapshotChunk(t *testing.T) { "Zero chunk": {2, 1, 0, false}, } for name, tc := range testcases { - tc := tc t.Run(name, func(t *testing.T) { resp := app.LoadSnapshotChunk(abci.RequestLoadSnapshotChunk{ Height: tc.height, @@ -94,7 +93,6 @@ func TestOfferSnapshot_Errors(t *testing.T) { }, abci.ResponseOfferSnapshot_REJECT}, } for name, tc := range testcases { - tc := tc t.Run(name, func(t *testing.T) { resp := app.OfferSnapshot(abci.RequestOfferSnapshot{Snapshot: tc.snapshot}) assert.Equal(t, tc.result, resp.Result) @@ -1819,7 +1817,6 @@ func TestSetLoader(t *testing.T) { v := []byte("value") for name, tc := range cases { - tc := tc t.Run(name, func(t *testing.T) { // prepare a db with some data db := dbm.NewMemDB() diff --git a/client/cmd_test.go b/client/cmd_test.go index d3bfcfd9f9..54ec9a41ef 100644 --- a/client/cmd_test.go +++ b/client/cmd_test.go @@ -94,8 +94,6 @@ func TestSetCmdClientContextHandler(t *testing.T) { } for _, tc := range testCases { - tc := tc - t.Run(tc.name, func(t *testing.T) { ctx := context.WithValue(context.Background(), client.ClientContextKey, &client.Context{}) diff --git a/client/config/cmd.go b/client/config/cmd.go index 1aa00b44bd..5e43193687 100644 --- a/client/config/cmd.go +++ b/client/config/cmd.go @@ -30,7 +30,7 @@ func runConfigCmd(cmd *cobra.Command, args []string) error { conf, err := getClientConfig(configPath, clientCtx.Viper) if err != nil { - return fmt.Errorf("couldn't get client config: %v", err) + return fmt.Errorf("couldn't get client config: %w", err) } switch len(args) { @@ -59,7 +59,7 @@ func runConfigCmd(cmd *cobra.Command, args []string) error { cmd.Println(conf.BroadcastMode) default: err := errUnknownConfigKey(key) - return fmt.Errorf("couldn't get the value for the key: %v, error: %v", key, err) + return fmt.Errorf("couldn't get the value for the key: %v, error: %w", key, err) } case 2: @@ -83,7 +83,7 @@ func runConfigCmd(cmd *cobra.Command, args []string) error { confFile := filepath.Join(configPath, "client.toml") if err := writeConfigToFile(confFile, conf); err != nil { - return fmt.Errorf("could not write client config to the file: %v", err) + return fmt.Errorf("could not write client config to the file: %w", err) } default: diff --git a/client/config/config.go b/client/config/config.go index bfc4c92d78..c98ab9840b 100644 --- a/client/config/config.go +++ b/client/config/config.go @@ -59,17 +59,17 @@ func ReadFromClientConfig(ctx client.Context) (client.Context, error) { // if config.toml file does not exist we create it and write default ClientConfig values into it. if _, err := os.Stat(configFilePath); os.IsNotExist(err) { if err := ensureConfigPath(configPath); err != nil { - return ctx, fmt.Errorf("couldn't make client config: %v", err) + return ctx, fmt.Errorf("couldn't make client config: %w", err) } if err := writeConfigToFile(configFilePath, conf); err != nil { - return ctx, fmt.Errorf("could not write client config to the file: %v", err) + return ctx, fmt.Errorf("could not write client config to the file: %w", err) } } conf, err := getClientConfig(configPath, ctx.Viper) if err != nil { - return ctx, fmt.Errorf("couldn't get client config: %v", err) + return ctx, fmt.Errorf("couldn't get client config: %w", err) } // we need to update KeyringDir field on Client Context first cause it is used in NewKeyringFromBackend ctx = ctx.WithOutputFormat(conf.Output). @@ -78,7 +78,7 @@ func ReadFromClientConfig(ctx client.Context) (client.Context, error) { keyring, err := client.NewKeyringFromBackend(ctx, conf.KeyringBackend) if err != nil { - return ctx, fmt.Errorf("couldn't get key ring: %v", err) + return ctx, fmt.Errorf("couldn't get key ring: %w", err) } ctx = ctx.WithKeyring(keyring) @@ -86,7 +86,7 @@ func ReadFromClientConfig(ctx client.Context) (client.Context, error) { // https://github.com/cosmos/cosmos-sdk/issues/8986 client, err := client.NewClientFromNode(conf.Node) if err != nil { - return ctx, fmt.Errorf("couldn't get client from nodeURI: %v", err) + return ctx, fmt.Errorf("couldn't get client from nodeURI: %w", err) } ctx = ctx.WithNodeURI(conf.Node). diff --git a/client/config/config_test.go b/client/config/config_test.go index d766a800f1..e7b46274c6 100644 --- a/client/config/config_test.go +++ b/client/config/config_test.go @@ -88,7 +88,6 @@ func TestConfigCmdEnvFlag(t *testing.T) { } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { clientCtx, cleanup := initClientContext(t, tc.envVar) defer func() { diff --git a/client/debug/main.go b/client/debug/main.go index 163aa87f8f..1b443b5d49 100644 --- a/client/debug/main.go +++ b/client/debug/main.go @@ -84,7 +84,7 @@ $ %s debug addr link19wgf6ymq2ur6r59st95e04e49m69z4al4fc982 addr, err3 = sdk.ValAddressFromBech32(addrString) if err3 != nil { - return fmt.Errorf("expected hex or bech32. Got errors: hex: %v, bech32 acc: %v, bech32 val: %v", err, err2, err3) + return fmt.Errorf("expected hex or bech32. Got errors: hex: %w, bech32 acc: %w, bech32 val: %w", err, err2, err3) } } } diff --git a/client/flags/flags_test.go b/client/flags/flags_test.go index f86ff64a58..54aa591e0d 100644 --- a/client/flags/flags_test.go +++ b/client/flags/flags_test.go @@ -23,8 +23,6 @@ func TestParseGasSetting(t *testing.T) { } for _, tc := range testCases { - tc := tc - t.Run(tc.name, func(t *testing.T) { gs, err := flags.ParseGasSetting(tc.input) diff --git a/client/grpc/tmservice/service_test.go b/client/grpc/tmservice/service_test.go index ff5d1189c3..c05e86a135 100644 --- a/client/grpc/tmservice/service_test.go +++ b/client/grpc/tmservice/service_test.go @@ -146,7 +146,6 @@ func (s *IntegrationTestSuite) TestLatestValidatorSet_GRPC() { {"with pagination", &tmservice.GetLatestValidatorSetRequest{Pagination: &qtypes.PageRequest{Offset: 0, Limit: uint64(len(vals))}}, false, ""}, } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { grpcRes, err := s.queryClient.GetLatestValidatorSet(context.Background(), tc.req) if tc.expErr { @@ -177,7 +176,6 @@ func (s *IntegrationTestSuite) TestLatestValidatorSet_GRPCGateway() { {"with pagination", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest?pagination.offset=0&pagination.limit=2", vals[0].APIAddress), false, ""}, } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { res, err := rest.GetRequest(tc.url) s.Require().NoError(err) @@ -210,7 +208,6 @@ func (s *IntegrationTestSuite) TestValidatorSetByHeight_GRPC() { {"with pagination", &tmservice.GetValidatorSetByHeightRequest{Height: 1, Pagination: &qtypes.PageRequest{Offset: 0, Limit: 1}}, false, ""}, } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { grpcRes, err := s.queryClient.GetValidatorSetByHeight(context.Background(), tc.req) if tc.expErr { @@ -239,7 +236,6 @@ func (s *IntegrationTestSuite) TestValidatorSetByHeight_GRPCGateway() { {"with pagination", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d?pagination.offset=0&pagination.limit=2", vals[0].APIAddress, 1), false, ""}, } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { res, err := rest.GetRequest(tc.url) s.Require().NoError(err) diff --git a/client/keys/add_ledger_test.go b/client/keys/add_ledger_test.go index 31685d1ee9..2ade0ab508 100644 --- a/client/keys/add_ledger_test.go +++ b/client/keys/add_ledger_test.go @@ -154,7 +154,6 @@ func Test_runAddCmdLedgerDryRun(t *testing.T) { }, } for _, tt := range testData { - tt := tt t.Run(tt.name, func(t *testing.T) { cmd := AddKeyCommand() cmd.Flags().AddFlagSet(Commands("home").PersistentFlags()) diff --git a/client/keys/add_test.go b/client/keys/add_test.go index 67233b3263..6aafc1f0ab 100644 --- a/client/keys/add_test.go +++ b/client/keys/add_test.go @@ -307,7 +307,6 @@ func Test_runAddCmdDryRun(t *testing.T) { }, } for _, tt := range testData { - tt := tt t.Run(tt.name, func(t *testing.T) { cmd := AddKeyCommand() cmd.Flags().AddFlagSet(Commands("home").PersistentFlags()) diff --git a/client/keys/codec_test.go b/client/keys/codec_test.go index 7d91884a13..eb4a5abc0c 100644 --- a/client/keys/codec_test.go +++ b/client/keys/codec_test.go @@ -56,7 +56,6 @@ func TestMarshalJSON(t *testing.T) { {"empty object", args{data.Keys[3]}, data.JSON[3], false}, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { got, err := keys.MarshalJSON(tt.args.o) require.Equal(t, tt.wantErr, err != nil) @@ -86,7 +85,6 @@ func TestUnmarshalJSON(t *testing.T) { {"empty object", args{data.JSON[3], &data.Answers[3]}, false}, } for idx, tt := range tests { - idx, tt := idx, tt t.Run(tt.name, func(t *testing.T) { err := keys.UnmarshalJSON(tt.args.bz, tt.args.ptr) require.Equal(t, tt.wantErr, err != nil) diff --git a/client/keys/list_test.go b/client/keys/list_test.go index 6a0d4fdf18..9f7184602e 100644 --- a/client/keys/list_test.go +++ b/client/keys/list_test.go @@ -47,7 +47,6 @@ func Test_runListCmd(t *testing.T) { {"keybase: w/key", kbHome2, false}, } for _, tt := range testData { - tt := tt t.Run(tt.name, func(t *testing.T) { cmd.SetArgs([]string{ fmt.Sprintf("--%s=%s", flags.FlagHome, tt.kbDir), diff --git a/client/keys/parse_test.go b/client/keys/parse_test.go index 5f8fd6022b..fe8c26d099 100644 --- a/client/keys/parse_test.go +++ b/client/keys/parse_test.go @@ -25,7 +25,6 @@ func TestParseKey(t *testing.T) { {"hex", []string{hexstr}, false}, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { require.Equal(t, tt.wantErr, doParseKey(ParseKeyStringCommand(), config, tt.args) != nil) }) diff --git a/client/keys/show.go b/client/keys/show.go index 3106510413..f401c46004 100644 --- a/client/keys/show.go +++ b/client/keys/show.go @@ -62,7 +62,7 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) { if len(args) == 1 { info, err = fetchKey(clientCtx.Keyring, args[0]) if err != nil { - return fmt.Errorf("%s is not a valid name or address: %v", args[0], err) + return fmt.Errorf("%s is not a valid name or address: %w", args[0], err) } if info.GetType() == keyring.TypeMulti { info, err = keyring.NewMultiInfo(info.GetName(), info.GetPubKey()) @@ -75,7 +75,7 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) { for i, keyref := range args { info, err := fetchKey(clientCtx.Keyring, keyref) if err != nil { - return fmt.Errorf("%s is not a valid name or address: %v", keyref, err) + return fmt.Errorf("%s is not a valid name or address: %w", keyref, err) } pks[i] = info.GetPubKey() diff --git a/client/keys/show_test.go b/client/keys/show_test.go index 56394b10bb..05d945bdda 100644 --- a/client/keys/show_test.go +++ b/client/keys/show_test.go @@ -178,7 +178,6 @@ func Test_validateMultisigThreshold(t *testing.T) { {"1-2", args{2, 1}, true}, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { if err := validateMultisigThreshold(tt.args.k, tt.args.nKeys); (err != nil) != tt.wantErr { t.Errorf("validateMultisigThreshold() error = %v, wantErr %v", err, tt.wantErr) @@ -204,7 +203,6 @@ func Test_getBechKeyOut(t *testing.T) { {"cons", args{sdk.PrefixConsensus}, keyring.MkConsKeyOutput, false}, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { got, err := getBechKeyOut(tt.args.bechPrefix) if tt.wantErr { diff --git a/client/tx/tx_test.go b/client/tx/tx_test.go index b9eb969055..cabeab29f2 100644 --- a/client/tx/tx_test.go +++ b/client/tx/tx_test.go @@ -71,23 +71,22 @@ func TestCalculateGas(t *testing.T) { } for _, tc := range testCases { - stc := tc txCfg := NewTestTxConfig() txf := tx.Factory{}. WithChainID("test-chain"). WithTxConfig(txCfg).WithSignMode(txCfg.SignModeHandler().DefaultMode()) - t.Run(stc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { mockClientCtx := mockContext{ gasUsed: tc.args.mockGasUsed, wantErr: tc.args.mockWantErr, } - simRes, gotAdjusted, err := tx.CalculateGas(mockClientCtx, txf.WithGasAdjustment(stc.args.adjustment)) - if stc.expPass { + simRes, gotAdjusted, err := tx.CalculateGas(mockClientCtx, txf.WithGasAdjustment(tc.args.adjustment)) + if tc.expPass { require.NoError(t, err) - require.Equal(t, simRes.GasInfo.GasUsed, stc.wantEstimate) - require.Equal(t, gotAdjusted, stc.wantAdjusted) + require.Equal(t, simRes.GasInfo.GasUsed, tc.wantEstimate) + require.Equal(t, gotAdjusted, tc.wantAdjusted) require.NotNil(t, simRes.Result) } else { require.Error(t, err) diff --git a/client/utils_test.go b/client/utils_test.go index 840af06fff..a0381f787d 100644 --- a/client/utils_test.go +++ b/client/utils_test.go @@ -70,7 +70,6 @@ func TestPaginate(t *testing.T) { } for i, tc := range testCases { - i, tc := i, tc t.Run(tc.name, func(t *testing.T) { start, end := client.Paginate(tc.numObjs, tc.page, tc.limit, tc.defLimit) require.Equal(t, tc.expectedStart, start, "invalid result; test case #%d", i) diff --git a/codec/amino_codec_test.go b/codec/amino_codec_test.go index 2e305a0686..7ecc75ce51 100644 --- a/codec/amino_codec_test.go +++ b/codec/amino_codec_test.go @@ -74,8 +74,6 @@ func TestAminoCodecMarshalJSONIndent(t *testing.T) { } for _, tc := range testCases { - tc := tc - t.Run(tc.name, func(t *testing.T) { cdc := codec.NewAminoCodec(createTestCodec()) bz, err := cdc.MarshalJSONIndent(tc.input, "", " ") diff --git a/codec/codec_common_test.go b/codec/codec_common_test.go index dc08f0fb24..ec3eefb424 100644 --- a/codec/codec_common_test.go +++ b/codec/codec_common_test.go @@ -119,7 +119,6 @@ func testMarshaling(t *testing.T, cdc codec.Codec) { } for _, tc := range testCases { - tc := tc m1 := mustMarshaler{cdc.Marshal, cdc.MustMarshal, cdc.Unmarshal, cdc.MustUnmarshal} m2 := mustMarshaler{cdc.MarshalLengthPrefixed, cdc.MustMarshalLengthPrefixed, cdc.UnmarshalLengthPrefixed, cdc.MustUnmarshalLengthPrefixed} m3 := mustMarshaler{ diff --git a/codec/proto_codec_test.go b/codec/proto_codec_test.go index 8e653b0d1a..ba26ddfc3e 100644 --- a/codec/proto_codec_test.go +++ b/codec/proto_codec_test.go @@ -58,8 +58,6 @@ func TestProtoCodecUnmarshalLengthPrefixedChecks(t *testing.T) { } for _, falseSize := range falseSizes { - falseSize := falseSize - t.Run(fmt.Sprintf("ByMarshaling falseSize=%d", falseSize), func(t *testing.T) { lpm := &lyingProtoMarshaler{ ProtoMarshaler: &testdata.Cat{Lives: 9, Moniker: "glowing"}, diff --git a/codec/unknownproto/unit_helpers_test.go b/codec/unknownproto/unit_helpers_test.go index 9c408a6d1f..b156422489 100644 --- a/codec/unknownproto/unit_helpers_test.go +++ b/codec/unknownproto/unit_helpers_test.go @@ -22,7 +22,6 @@ func TestWireTypeToString(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(fmt.Sprintf("wireType=%d", tt.typ), func(t *testing.T) { if g, w := wireTypeToString(tt.typ), tt.want; g != w { t.Fatalf("Mismatch:\nGot: %q\nWant: %q\n", g, w) diff --git a/codec/unknownproto/unknown_fields_test.go b/codec/unknownproto/unknown_fields_test.go index 9b14c77287..8f9a9af7f7 100644 --- a/codec/unknownproto/unknown_fields_test.go +++ b/codec/unknownproto/unknown_fields_test.go @@ -223,7 +223,6 @@ func TestRejectUnknownFieldsRepeated(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { protoBlob, err := proto.Marshal(tt.in) if err != nil { @@ -280,7 +279,6 @@ func TestRejectUnknownFields_allowUnknownNonCriticals(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { blob, err := proto.Marshal(tt.in) if err != nil { @@ -483,7 +481,6 @@ func TestRejectUnknownFieldsNested(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { protoBlob, err := proto.Marshal(tt.in) if err != nil { @@ -634,7 +631,6 @@ func TestRejectUnknownFieldsFlat(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { blob, err := proto.Marshal(tt.in) if err != nil { diff --git a/crypto/armor.go b/crypto/armor.go index e88944bfa6..172ffd63b6 100644 --- a/crypto/armor.go +++ b/crypto/armor.go @@ -87,7 +87,7 @@ func UnarmorInfoBytes(armorStr string) ([]byte, error) { func UnarmorPubKeyBytes(armorStr string) (bz []byte, algo string, err error) { bz, header, err := unarmorBytes(armorStr, blockTypePubKey) if err != nil { - return nil, "", fmt.Errorf("couldn't unarmor bytes: %v", err) + return nil, "", fmt.Errorf("couldn't unarmor bytes: %w", err) } switch header[headerVersion] { diff --git a/crypto/hd/hdpath_test.go b/crypto/hd/hdpath_test.go index 86b0388235..4fcc46220c 100644 --- a/crypto/hd/hdpath_test.go +++ b/crypto/hd/hdpath_test.go @@ -107,9 +107,7 @@ func TestCreateHDPath(t *testing.T) { {"m/44'/114'/1'/1/0", args{114, 1, 1}, hd.BIP44Params{Purpose: 44, CoinType: 114, Account: 1, AddressIndex: 1}}, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { - tt := tt require.Equal(t, tt.want, *hd.CreateHDPath(tt.args.coinType, tt.args.account, tt.args.index)) }) } @@ -170,7 +168,6 @@ func TestDeriveHDPathRange(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.path, func(t *testing.T) { master, ch := hd.ComputeMastersFromSeed(seed) _, err := hd.DerivePrivateKeyForPath(master, ch, tt.path) @@ -297,7 +294,6 @@ func TestDerivePrivateKeyForPathDoNotCrash(t *testing.T) { } for _, path := range paths { - path := path t.Run(path, func(t *testing.T) { _, _ = hd.DerivePrivateKeyForPath([32]byte{}, [32]byte{}, path) }) diff --git a/crypto/keyring/keyring.go b/crypto/keyring/keyring.go index fa89682961..0f41dc3da1 100644 --- a/crypto/keyring/keyring.go +++ b/crypto/keyring/keyring.go @@ -463,7 +463,7 @@ func (ks keystore) KeyByAddress(address sdk.Address) (Info, error) { } func wrapKeyNotFound(err error, msg string) error { - if err == keyring.ErrKeyNotFound { + if errors.Is(err, keyring.ErrKeyNotFound) { return sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, msg) } return err @@ -691,7 +691,7 @@ func newFileBackendKeyringConfig(name, dir string, buf io.Reader) keyring.Config func newRealPrompt(dir string, buf io.Reader) func(string) (string, error) { return func(prompt string) (string, error) { - keyhashStored := false + var keyhashStored bool keyhashFilePath := filepath.Join(dir, "keyhash") var keyhash []byte @@ -702,7 +702,7 @@ func newRealPrompt(dir string, buf io.Reader) func(string) (string, error) { case err == nil: keyhash, err = os.ReadFile(keyhashFilePath) if err != nil { - return "", fmt.Errorf("failed to read %s: %v", keyhashFilePath, err) + return "", fmt.Errorf("failed to read %s: %w", keyhashFilePath, err) } keyhashStored = true @@ -711,7 +711,7 @@ func newRealPrompt(dir string, buf io.Reader) func(string) (string, error) { keyhashStored = false default: - return "", fmt.Errorf("failed to open %s: %v", keyhashFilePath, err) + return "", fmt.Errorf("failed to open %s: %w", keyhashFilePath, err) } failureCounter := 0 @@ -820,13 +820,13 @@ func (ks keystore) writeInfo(info Info) error { func (ks keystore) existsInDb(info Info) (bool, error) { if _, err := ks.db.Get(addrHexKeyAsString(info.GetAddress())); err == nil { return true, nil // address lookup succeeds - info exists - } else if err != keyring.ErrKeyNotFound { + } else if !errors.Is(err, keyring.ErrKeyNotFound) { return false, err // received unexpected error - returns error } if _, err := ks.db.Get(infoKey(info.GetName())); err == nil { return true, nil // uid lookup succeeds - info exists - } else if err != keyring.ErrKeyNotFound { + } else if !errors.Is(err, keyring.ErrKeyNotFound) { return false, err // received unexpected error - returns } diff --git a/crypto/keyring/signing_algorithms_test.go b/crypto/keyring/signing_algorithms_test.go index 7259e45ce8..e4c549d65a 100644 --- a/crypto/keyring/signing_algorithms_test.go +++ b/crypto/keyring/signing_algorithms_test.go @@ -35,7 +35,6 @@ func TestNewSigningAlgoByString(t *testing.T) { list := SigningAlgoList{hd.Secp256k1} for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { algorithm, err := NewSigningAlgoFromString(tt.algoStr, list) if tt.isSupported { diff --git a/crypto/keys/multisig/codec.go b/crypto/keys/multisig/codec.go index 2153acfb79..7a18b51aed 100644 --- a/crypto/keys/multisig/codec.go +++ b/crypto/keys/multisig/codec.go @@ -15,7 +15,6 @@ const ( PubKeyAminoRoute = "tendermint/PubKeyMultisigThreshold" ) -// nolint // Deprecated: Amino is being deprecated in the SDK. But even if you need to // use Amino for some reason, please use `codec/legacy.Cdc` instead. var AminoCdc = codec.NewLegacyAmino() diff --git a/crypto/keys/secp256k1/secp256k1_internal_test.go b/crypto/keys/secp256k1/secp256k1_internal_test.go index 539420d00e..b2360d7552 100644 --- a/crypto/keys/secp256k1/secp256k1_internal_test.go +++ b/crypto/keys/secp256k1/secp256k1_internal_test.go @@ -27,7 +27,6 @@ func Test_genPrivKey(t *testing.T) { {"valid because 0 < 1 < N", validOne, false}, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { if tt.shouldPanic { require.Panics(t, func() { diff --git a/crypto/keys/secp256k1/secp256k1_test.go b/crypto/keys/secp256k1/secp256k1_test.go index 86b1b2f5e8..2face47179 100644 --- a/crypto/keys/secp256k1/secp256k1_test.go +++ b/crypto/keys/secp256k1/secp256k1_test.go @@ -255,7 +255,6 @@ func TestGenPrivKeyFromSecret(t *testing.T) { {"another seed used in cosmos tests #3", []byte("")}, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { gotPrivKey := secp256k1.GenPrivKeyFromSecret(tt.secret) require.NotNil(t, gotPrivKey) diff --git a/crypto/ledger/ledger_mock.go b/crypto/ledger/ledger_mock.go index f65bc69e40..526e8c8048 100644 --- a/crypto/ledger/ledger_mock.go +++ b/crypto/ledger/ledger_mock.go @@ -72,7 +72,7 @@ func (mock LedgerSECP256K1Mock) GetAddressPubKeySECP256K1(derivationPath []uint3 // re-serialize in the 33-byte compressed format cmp, err := secp.ParsePubKey(pk) if err != nil { - return nil, "", fmt.Errorf("error parsing public key: %v", err) + return nil, "", fmt.Errorf("error parsing public key: %w", err) } compressedPublicKey := make([]byte, csecp256k1.PubKeySize) diff --git a/crypto/ledger/ledger_secp256k1.go b/crypto/ledger/ledger_secp256k1.go index f6f65589ec..d90b504333 100644 --- a/crypto/ledger/ledger_secp256k1.go +++ b/crypto/ledger/ledger_secp256k1.go @@ -258,13 +258,13 @@ func sign(device SECP256K1, pkl PrivKeyLedgerSecp256k1, msg []byte) ([]byte, err func getPubKeyUnsafe(device SECP256K1, path hd.BIP44Params) (types.PubKey, error) { publicKey, err := device.GetPublicKeySECP256K1(path.DerivationPath()) if err != nil { - return nil, fmt.Errorf("please open Cosmos app on the Ledger device - error: %v", err) + return nil, fmt.Errorf("please open Cosmos app on the Ledger device - error: %w", err) } // re-serialize in the 33-byte compressed format cmp, err := secp.ParsePubKey(publicKey) if err != nil { - return nil, fmt.Errorf("error parsing public key: %v", err) + return nil, fmt.Errorf("error parsing public key: %w", err) } compressedPublicKey := make([]byte, secp256k1.PubKeySize) @@ -288,7 +288,7 @@ func getPubKeyAddrSafe(device SECP256K1, path hd.BIP44Params, hrp string) (types // re-serialize in the 33-byte compressed format cmp, err := secp.ParsePubKey(publicKey) if err != nil { - return nil, "", fmt.Errorf("error parsing public key: %v", err) + return nil, "", fmt.Errorf("error parsing public key: %w", err) } compressedPublicKey := make([]byte, secp256k1.PubKeySize) diff --git a/crypto/types/compact_bit_array_test.go b/crypto/types/compact_bit_array_test.go index e3a84832a9..8a0a8f93bc 100644 --- a/crypto/types/compact_bit_array_test.go +++ b/crypto/types/compact_bit_array_test.go @@ -57,7 +57,6 @@ func TestBitArrayEqual(t *testing.T) { {name: "different should not be equal", b1: big1, b2: big2, eq: false}, } for _, tc := range cases { - tc := tc t.Run(tc.name, func(t *testing.T) { eq := tc.b1.Equal(tc.b2) require.Equal(t, tc.eq, eq) @@ -101,7 +100,6 @@ func TestJSONMarshalUnmarshal(t *testing.T) { } for _, tc := range testCases { - tc := tc t.Run(tc.bA.String(), func(t *testing.T) { bz, err := json.Marshal(tc.bA) require.NoError(t, err) @@ -161,7 +159,6 @@ func TestCompactMarshalUnmarshal(t *testing.T) { } for _, tc := range testCases { - tc := tc t.Run(tc.bA.String(), func(t *testing.T) { bz := tc.bA.CompactMarshal() @@ -207,8 +204,6 @@ func TestCompactBitArrayNumOfTrueBitsBefore(t *testing.T) { {`"______________xx"`, []int{14, 15}, []int{0, 1}}, } for tcIndex, tc := range testCases { - tc := tc - tcIndex := tcIndex t.Run(tc.marshalledBA, func(t *testing.T) { var bA *CompactBitArray err := json.Unmarshal([]byte(tc.marshalledBA), &bA) @@ -281,7 +276,6 @@ func TestNewCompactBitArrayCrashWithLimits(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(fmt.Sprintf("%d", tt.in), func(t *testing.T) { got := NewCompactBitArray(tt.in) if g := got != nil; g != tt.mustPass { diff --git a/server/export.go b/server/export.go index 8824be663e..c02e42adb6 100644 --- a/server/export.go +++ b/server/export.go @@ -69,7 +69,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com exported, err := appExporter(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs, serverCtx.Viper) if err != nil { - return fmt.Errorf("error exporting state: %v", err) + return fmt.Errorf("error exporting state: %w", err) } doc, err := tmtypes.GenesisDocFromFile(serverCtx.Config.GenesisFile()) diff --git a/server/grpc/gogoreflection/serverreflection.go b/server/grpc/gogoreflection/serverreflection.go index 3ce667d9fe..1937870ca0 100644 --- a/server/grpc/gogoreflection/serverreflection.go +++ b/server/grpc/gogoreflection/serverreflection.go @@ -39,6 +39,7 @@ package gogoreflection // import "google.golang.org/grpc/reflection" import ( "bytes" "compress/gzip" + "errors" "fmt" "io" "log" @@ -201,12 +202,12 @@ func (s *serverReflectionServer) fileDescForType(st reflect.Type) (*dpb.FileDesc func decodeFileDesc(enc []byte) (*dpb.FileDescriptorProto, error) { raw, err := decompress(enc) if err != nil { - return nil, fmt.Errorf("failed to decompress enc: %v", err) + return nil, fmt.Errorf("failed to decompress enc: %w", err) } fd := new(dpb.FileDescriptorProto) if err := proto.Unmarshal(raw, fd); err != nil { - return nil, fmt.Errorf("bad descriptor: %v", err) + return nil, fmt.Errorf("bad descriptor: %w", err) } return fd, nil } @@ -215,11 +216,11 @@ func decodeFileDesc(enc []byte) (*dpb.FileDescriptorProto, error) { func decompress(b []byte) ([]byte, error) { r, err := gzip.NewReader(bytes.NewReader(b)) if err != nil { - return nil, fmt.Errorf("bad gzipped descriptor: %v", err) + return nil, fmt.Errorf("bad gzipped descriptor: %w", err) } out, err := io.ReadAll(r) if err != nil { - return nil, fmt.Errorf("bad gzipped descriptor: %v", err) + return nil, fmt.Errorf("bad gzipped descriptor: %w", err) } return out, nil } @@ -379,7 +380,7 @@ func (s *serverReflectionServer) ServerReflectionInfo(stream rpb.ServerReflectio sentFileDescriptors := make(map[string]bool) for { in, err := stream.Recv() - if err == io.EOF { + if errors.Is(err, io.EOF) { return nil } if err != nil { diff --git a/server/pruning_test.go b/server/pruning_test.go index 9c462379ad..adf098face 100644 --- a/server/pruning_test.go +++ b/server/pruning_test.go @@ -54,8 +54,6 @@ func TestGetPruningOptionsFromFlags(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(j *testing.T) { viper.Reset() viper.SetDefault(FlagPruning, types.PruningOptionDefault) diff --git a/server/start.go b/server/start.go index ceca66df62..54484f4d4c 100644 --- a/server/start.go +++ b/server/start.go @@ -210,7 +210,7 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. func startStandAlone(svrCtx *Context, svrCfg serverconfig.Config, clientCtx client.Context, app types.Application, tmetrics *telemetry.Metrics) error { svr, err := server.NewServer(svrCtx.Viper.GetString(flagAddress), svrCtx.Viper.GetString(flagTransport), app) if err != nil { - return fmt.Errorf("error creating listener: %v", err) + return fmt.Errorf("error creating listener: %w", err) } svr.SetLogger(svrCtx.Logger.With("module", "abci-server")) diff --git a/server/tm_cmds_test.go b/server/tm_cmds_test.go index efb67fb7fc..8dfb6eccfb 100644 --- a/server/tm_cmds_test.go +++ b/server/tm_cmds_test.go @@ -3,6 +3,7 @@ package server import ( "bytes" "context" + "errors" "fmt" "os" "testing" @@ -27,7 +28,7 @@ func TestShowValidator(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) - if err := testCommon.cmd.ExecuteContext(ctx); err != errCancelledInPreRun { + if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } @@ -52,7 +53,7 @@ func TestShowValidatorWithInefficientKMSAddress(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) - if err := testCommon.cmd.ExecuteContext(ctx); err != errCancelledInPreRun { + if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } diff --git a/server/util.go b/server/util.go index 735b994a81..40a5cdd38b 100644 --- a/server/util.go +++ b/server/util.go @@ -205,7 +205,7 @@ func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customCo tmcfg.EnsureRoot(rootDir) if err = conf.ValidateBasic(); err != nil { - return nil, fmt.Errorf("error in config file: %v", err) + return nil, fmt.Errorf("error in config file: %w", err) } conf.RPC.PprofListenAddress = "localhost:6060" diff --git a/server/util_test.go b/server/util_test.go index 02931b6183..60024c5df6 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -39,7 +39,7 @@ func TestInterceptConfigsPreRunHandlerCreatesConfigFilesWhenMissing(t *testing.T serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) - if err := cmd.ExecuteContext(ctx); err != errCancelledInPreRun { + if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } @@ -116,7 +116,7 @@ func TestInterceptConfigsPreRunHandlerReadsConfigToml(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) - if err := cmd.ExecuteContext(ctx); err != errCancelledInPreRun { + if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } @@ -153,7 +153,7 @@ func TestInterceptConfigsPreRunHandlerReadsAppToml(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) - if err := cmd.ExecuteContext(ctx); err != errCancelledInPreRun { + if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } @@ -181,7 +181,7 @@ func TestInterceptConfigsPreRunHandlerReadsFlags(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) - if err := cmd.ExecuteContext(ctx); err != errCancelledInPreRun { + if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } @@ -206,17 +206,13 @@ func TestInterceptConfigsPreRunHandlerReadsEnvVars(t *testing.T) { basename = strings.ReplaceAll(basename, ".", "_") // This is added by tendermint envVarName := fmt.Sprintf("%s_RPC_LADDR", strings.ToUpper(basename)) - os.Setenv(envVarName, testAddr) - t.Cleanup(func() { - os.Unsetenv(envVarName) - }) - + t.Setenv(envVarName, testAddr) cmd.PreRunE = preRunETestImpl serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) - if err := cmd.ExecuteContext(ctx); err != errCancelledInPreRun { + if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } @@ -322,7 +318,7 @@ func TestInterceptConfigsPreRunHandlerPrecedenceFlag(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) - if err := testCommon.cmd.ExecuteContext(ctx); err != errCancelledInPreRun { + if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } @@ -338,7 +334,7 @@ func TestInterceptConfigsPreRunHandlerPrecedenceEnvVar(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) - if err := testCommon.cmd.ExecuteContext(ctx); err != errCancelledInPreRun { + if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } @@ -354,7 +350,7 @@ func TestInterceptConfigsPreRunHandlerPrecedenceConfigFile(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) - if err := testCommon.cmd.ExecuteContext(ctx); err != errCancelledInPreRun { + if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } @@ -370,7 +366,7 @@ func TestInterceptConfigsPreRunHandlerPrecedenceConfigDefault(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) - if err := testCommon.cmd.ExecuteContext(ctx); err != errCancelledInPreRun { + if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } diff --git a/simapp/genesis_account_test.go b/simapp/genesis_account_test.go index 1100e49459..7d9f82af1d 100644 --- a/simapp/genesis_account_test.go +++ b/simapp/genesis_account_test.go @@ -80,7 +80,6 @@ func TestSimGenesisAccountValidate(t *testing.T) { } for _, tc := range testCases { - tc := tc t.Run(tc.name, func(t *testing.T) { require.Equal(t, tc.wantErr, tc.sga.Validate() != nil) }) diff --git a/simapp/sim_bench_test.go b/simapp/sim_bench_test.go index 7f8451637f..f4666c8876 100644 --- a/simapp/sim_bench_test.go +++ b/simapp/sim_bench_test.go @@ -117,7 +117,6 @@ func BenchmarkInvariants(b *testing.B) { // NOTE: We use the crisis keeper as it has all the invariants registered with // their respective metadata which makes it useful for testing/benchmarking. for _, cr := range app.CrisisKeeper.Routes() { - cr := cr b.Run(fmt.Sprintf("%s/%s", cr.ModuleName, cr.Route), func(b *testing.B) { if res, stop := cr.Invar(ctx); stop { b.Fatalf( diff --git a/simapp/simd/cmd/genaccounts_test.go b/simapp/simd/cmd/genaccounts_test.go index 154a4e0abe..0d14c40ce6 100644 --- a/simapp/simd/cmd/genaccounts_test.go +++ b/simapp/simd/cmd/genaccounts_test.go @@ -65,7 +65,6 @@ func TestAddGenesisAccountCmd(t *testing.T) { } for _, tc := range tests { - tc := tc t.Run(tc.name, func(t *testing.T) { home := t.TempDir() logger := log.NewNopLogger() diff --git a/simapp/simd/cmd/root_test.go b/simapp/simd/cmd/root_test.go index d45a66e6cb..7575084313 100644 --- a/simapp/simd/cmd/root_test.go +++ b/simapp/simd/cmd/root_test.go @@ -75,7 +75,6 @@ func TestAppExport(t *testing.T) { } for _, tc := range tests { - tc := tc t.Run(tc.name, func(t *testing.T) { exported, err := a.appExport(logger, db, nil, tc.height, false, []string{}, ctx.Viper) if tc.expectErr { diff --git a/simapp/simd/main.go b/simapp/simd/main.go index 6220cc701f..2dfddc3292 100644 --- a/simapp/simd/main.go +++ b/simapp/simd/main.go @@ -1,6 +1,7 @@ package main import ( + "errors" "os" "github.com/Finschia/finschia-sdk/server" @@ -13,10 +14,10 @@ func main() { rootCmd, _ := cmd.NewRootCmd() if err := svrcmd.Execute(rootCmd, simapp.DefaultNodeHome); err != nil { - switch e := err.(type) { - case server.ErrorCode: + var e server.ErrorCode + switch { + case errors.As(err, &e): os.Exit(e.Code) - default: os.Exit(1) } diff --git a/simapp/utils_test.go b/simapp/utils_test.go index c63716dfa1..f1e3f32cfa 100644 --- a/simapp/utils_test.go +++ b/simapp/utils_test.go @@ -69,7 +69,6 @@ func TestGetSimulationLog(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.store, func(t *testing.T) { require.Equal(t, tt.expectedLog, GetSimulationLog(tt.store, decoders, tt.kvPairs, tt.kvPairs), tt.store) }) diff --git a/snapshots/chunk.go b/snapshots/chunk.go index 7e1239ec8c..f9b1692b0f 100644 --- a/snapshots/chunk.go +++ b/snapshots/chunk.go @@ -1,6 +1,7 @@ package snapshots import ( + "errors" "io" sdkerrors "github.com/Finschia/finschia-sdk/types/errors" @@ -144,7 +145,7 @@ func (r *ChunkReader) Read(p []byte) (int, error) { } } n, err := r.reader.Read(p) - if err == io.EOF { + if errors.Is(err, io.EOF) { err = r.reader.Close() r.reader = nil if err != nil { diff --git a/snapshots/helpers_test.go b/snapshots/helpers_test.go index 12d0be6bfc..84983f73b6 100644 --- a/snapshots/helpers_test.go +++ b/snapshots/helpers_test.go @@ -116,7 +116,7 @@ func (m *mockSnapshotter) Restore( for { item := &snapshottypes.SnapshotItem{} err := protoReader.ReadMsg(item) - if err == io.EOF { + if errors.Is(err, io.EOF) { break } else if err != nil { return snapshottypes.SnapshotItem{}, sdkerrors.Wrap(err, "invalid protobuf message") diff --git a/store/cachekv/search_test.go b/store/cachekv/search_test.go index 41321c076e..aedc066903 100644 --- a/store/cachekv/search_test.go +++ b/store/cachekv/search_test.go @@ -60,7 +60,6 @@ func TestFindStartIndex(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { body := tt.sortedL got := findStartIndex(body, tt.query) @@ -129,7 +128,6 @@ func TestFindEndIndex(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { body := tt.sortedL got := findEndIndex(body, tt.query) diff --git a/store/iavl/store_test.go b/store/iavl/store_test.go index fcdcbc50da..bd23462e78 100644 --- a/store/iavl/store_test.go +++ b/store/iavl/store_test.go @@ -656,8 +656,6 @@ func TestSetInitialVersion(t *testing.T) { } for _, tc := range testCases { - tc := tc - t.Run(tc.name, func(t *testing.T) { db := dbm.NewMemDB() store := tc.storeFn(db) diff --git a/store/rootmulti/snapshot_test.go b/store/rootmulti/snapshot_test.go index 14d0374fee..29b07f4c74 100644 --- a/store/rootmulti/snapshot_test.go +++ b/store/rootmulti/snapshot_test.go @@ -142,7 +142,6 @@ func TestMultistoreSnapshot_Checksum(t *testing.T) { }}, } for _, tc := range testcases { - tc := tc t.Run(fmt.Sprintf("Format %v", tc.format), func(t *testing.T) { ch := make(chan io.ReadCloser) go func() { @@ -177,7 +176,6 @@ func TestMultistoreSnapshot_Errors(t *testing.T) { "unknown height": {9, nil}, } for name, tc := range testcases { - tc := tc t.Run(name, func(t *testing.T) { err := store.Snapshot(tc.height, nil) require.Error(t, err) diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index 61063a0da0..615379b640 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -469,7 +469,7 @@ func (rs *Store) PruneStores(clearStorePruningHeihgts bool, pruningHeights []int store = rs.GetCommitKVStore(key) if err := store.(*iavl.Store).DeleteVersions(pruningHeights...); err != nil { - if errCause := errors.Cause(err); errCause != nil && errCause != iavltree.ErrVersionDoesNotExist { + if errCause := errors.Cause(err); errCause != nil && !errors.Is(errCause, iavltree.ErrVersionDoesNotExist) { panic(err) } } @@ -744,7 +744,7 @@ func (rs *Store) Snapshot(height uint64, protoWriter protoio.Writer) error { for { node, err := exporter.Next() - if err == iavltree.ExportDone { + if errors.Is(err, iavltree.ExportDone) { break } else if err != nil { return err @@ -783,7 +783,7 @@ loop: for { snapshotItem = snapshottypes.SnapshotItem{} err := protoReader.ReadMsg(&snapshotItem) - if err == io.EOF { + if errors.Is(err, io.EOF) { break } else if err != nil { return snapshottypes.SnapshotItem{}, sdkerrors.Wrap(err, "invalid protobuf message") diff --git a/store/rootmulti/store_test.go b/store/rootmulti/store_test.go index 944075c803..39714a49a4 100644 --- a/store/rootmulti/store_test.go +++ b/store/rootmulti/store_test.go @@ -506,8 +506,6 @@ func TestMultiStore_Pruning(t *testing.T) { } for _, tc := range testCases { - tc := tc - t.Run(tc.name, func(t *testing.T) { db := dbm.NewMemDB() ms := newMultiStoreWithMounts(db, tc.po) diff --git a/store/types/gas_test.go b/store/types/gas_test.go index 8a02df4cfa..80ca8adf9e 100644 --- a/store/types/gas_test.go +++ b/store/types/gas_test.go @@ -44,7 +44,6 @@ func TestGasMeter(t *testing.T) { used := uint64(0) for unum, usage := range tc.usage { - usage := usage used += usage require.NotPanics(t, func() { meter.ConsumeGas(usage, "") }, "Not exceeded limit but panicked. tc #%d, usage #%d", tcnum, unum) require.Equal(t, used, meter.GasConsumed(), "Gas consumption not match. tc #%d, usage #%d", tcnum, unum) diff --git a/store/types/iterator_test.go b/store/types/iterator_test.go index 9e3be06fe3..65e70306d8 100644 --- a/store/types/iterator_test.go +++ b/store/types/iterator_test.go @@ -83,7 +83,6 @@ func TestPaginatedIterator(t *testing.T) { reverse: true, }, } { - tc := tc t.Run(tc.desc, func(t *testing.T) { var iter types.Iterator if tc.reverse { diff --git a/store/types/store_test.go b/store/types/store_test.go index 8dac7f5394..ff9765dbe8 100644 --- a/store/types/store_test.go +++ b/store/types/store_test.go @@ -47,7 +47,6 @@ func TestStoreUpgrades(t *testing.T) { } for name, tc := range cases { - tc := tc t.Run(name, func(t *testing.T) { for _, d := range tc.expectDelete { assert.Equal(t, tc.upgrades.IsDeleted(d.key), d.delete) diff --git a/types/address/store_key_test.go b/types/address/store_key_test.go index ca3b4d8ec2..6f04121baf 100644 --- a/types/address/store_key_test.go +++ b/types/address/store_key_test.go @@ -32,7 +32,6 @@ func (suite *StoreKeySuite) TestLengthPrefix() { } for _, tt := range tests { - tt := tt suite.Run(tt.name, func() { storeKey, err := address.LengthPrefix(tt.addr) if tt.expErr { diff --git a/types/address_test.go b/types/address_test.go index 61bf36318e..cbd09dbfa6 100644 --- a/types/address_test.go +++ b/types/address_test.go @@ -392,7 +392,6 @@ func (s *addressTestSuite) TestBech32ifyAddressBytes() { {"20-byte address", args{"prefixb", addr20byte}, "prefixb1qqqsyqcyq5rqwzqfpg9scrgwpugpzysnrujsuw", false}, } for _, tt := range tests { - tt := tt s.T().Run(tt.name, func(t *testing.T) { got, err := types.Bech32ifyAddressBytes(tt.args.prefix, tt.args.bs) if (err != nil) != tt.wantErr { @@ -425,7 +424,6 @@ func (s *addressTestSuite) TestMustBech32ifyAddressBytes() { {"20-byte address", args{"prefixb", addr20byte}, "prefixb1qqqsyqcyq5rqwzqfpg9scrgwpugpzysnrujsuw", false}, } for _, tt := range tests { - tt := tt s.T().Run(tt.name, func(t *testing.T) { if tt.wantPanic { require.Panics(t, func() { types.MustBech32ifyAddressBytes(tt.args.prefix, tt.args.bs) }) diff --git a/types/coin_test.go b/types/coin_test.go index 4af7a46e00..d64a51131c 100644 --- a/types/coin_test.go +++ b/types/coin_test.go @@ -135,7 +135,6 @@ func (s *coinTestSuite) TestAddCoin() { } for tcIndex, tc := range cases { - tc := tc if tc.shouldPanic { s.Require().Panics(func() { tc.inputOne.Add(tc.inputTwo) }) } else { @@ -175,7 +174,6 @@ func (s *coinTestSuite) TestSubCoin() { } for tcIndex, tc := range cases { - tc := tc if tc.shouldPanic { s.Require().Panics(func() { tc.inputOne.Sub(tc.inputTwo) }) } else { @@ -230,7 +228,6 @@ func (s *coinTestSuite) TestIsGTECoin() { } for tcIndex, tc := range cases { - tc := tc if tc.panics { s.Require().Panics(func() { tc.inputOne.IsGTE(tc.inputTwo) }) } else { @@ -256,7 +253,6 @@ func (s *coinTestSuite) TestIsLTCoin() { } for tcIndex, tc := range cases { - tc := tc if tc.panics { s.Require().Panics(func() { tc.inputOne.IsLT(tc.inputTwo) }) } else { @@ -485,7 +481,6 @@ func (s *coinTestSuite) TestSubCoins() { assert := s.Assert() for i, tc := range testCases { - tc := tc if tc.shouldPanic { assert.Panics(func() { tc.inputOne.Sub(tc.inputTwo) }) } else { @@ -1065,7 +1060,6 @@ func (s *coinTestSuite) TestCoinValidate() { } for _, tc := range testCases { - tc := tc t := s.T() t.Run(tc.name, func(t *testing.T) { err := tc.coin.Validate() diff --git a/types/context_test.go b/types/context_test.go index 5688cfe61f..4530cf92eb 100644 --- a/types/context_test.go +++ b/types/context_test.go @@ -191,7 +191,6 @@ func (s *contextTestSuite) TestContextHeaderClone() { } for name, tc := range cases { - tc := tc s.T().Run(name, func(t *testing.T) { ctx := types.NewContext(nil, tc.h, false, nil) s.Require().Equal(tc.h.Height, ctx.BlockHeight()) diff --git a/types/dec_coin.go b/types/dec_coin.go index 86b53f1607..9c8e6cf47d 100644 --- a/types/dec_coin.go +++ b/types/dec_coin.go @@ -630,7 +630,7 @@ func ParseDecCoin(coinStr string) (coin DecCoin, err error) { } if err := ValidateDenom(denomStr); err != nil { - return DecCoin{}, fmt.Errorf("invalid denom cannot contain upper case characters or spaces: %s", err) + return DecCoin{}, fmt.Errorf("invalid denom cannot contain upper case characters or spaces: %w", err) } return NewDecCoinFromDec(denomStr, amount), nil diff --git a/types/dec_coin_test.go b/types/dec_coin_test.go index 71673f9815..bb9addef5e 100644 --- a/types/dec_coin_test.go +++ b/types/dec_coin_test.go @@ -187,7 +187,6 @@ func (s *decCoinTestSuite) TestIsValid() { } for _, tc := range tests { - tc := tc if tc.expectPass { s.Require().True(tc.coin.IsValid(), tc.msg) } else { @@ -222,7 +221,6 @@ func (s *decCoinTestSuite) TestSubDecCoin() { decCoin := sdk.NewDecCoin("mytoken", sdk.NewInt(10)) for _, tc := range tests { - tc := tc if tc.expectPass { equal := tc.coin.Sub(decCoin) s.Require().Equal(equal, decCoin, tc.msg) @@ -258,7 +256,6 @@ func (s *decCoinTestSuite) TestSubDecCoins() { decCoins := sdk.NewDecCoinsFromCoins(sdk.NewCoin("btc", sdk.NewInt(10)), sdk.NewCoin("eth", sdk.NewInt(15)), sdk.NewCoin("mytoken", sdk.NewInt(5))) for _, tc := range tests { - tc := tc if tc.expectPass { equal := tc.coins.Sub(decCoins) s.Require().Equal(equal, decCoins, tc.msg) @@ -500,7 +497,6 @@ func (s *decCoinTestSuite) TestDecCoinsQuoDecTruncate() { } for i, tc := range testCases { - tc := tc if tc.panics { s.Require().Panics(func() { tc.coins.QuoDecTruncate(tc.input) }) } else { @@ -537,7 +533,6 @@ func (s *decCoinTestSuite) TestNewDecCoinsWithIsValid() { } for _, tc := range tests { - tc := tc if tc.expectPass { s.Require().True(tc.coin.IsValid(), tc.msg) } else { @@ -564,7 +559,6 @@ func (s *decCoinTestSuite) TestNewDecCoinsWithZeroCoins() { } for _, tc := range tests { - tc := tc s.Require().Equal(sdk.NewDecCoinsFromCoins(tc.coins...).Len(), tc.expectLength) } } @@ -596,7 +590,6 @@ func (s *decCoinTestSuite) TestDecCoins_AddDecCoinWithIsValid() { } for _, tc := range tests { - tc := tc if tc.expectPass { s.Require().True(tc.coin.IsValid(), tc.msg) } else { diff --git a/types/decimal.go b/types/decimal.go index 8be1f3820f..c1d056e9a6 100644 --- a/types/decimal.go +++ b/types/decimal.go @@ -671,7 +671,11 @@ var nilJSON []byte func init() { empty := new(big.Int) bz, _ := empty.MarshalText() - nilJSON, _ = json.Marshal(string(bz)) + var err error + nilJSON, err = json.Marshal(string(bz)) + if err != nil { + panic(err) + } } // MarshalJSON marshals the decimal @@ -740,7 +744,7 @@ func (d *Dec) MarshalTo(data []byte) (n int, err error) { // Unmarshal implements the gogo proto custom type interface. func (d *Dec) Unmarshal(data []byte) error { if len(data) == 0 { - d = nil + d = nil //nolint: wastedassign return nil } diff --git a/types/decimal_internal_test.go b/types/decimal_internal_test.go index 9aa31affe1..23805998b1 100644 --- a/types/decimal_internal_test.go +++ b/types/decimal_internal_test.go @@ -67,7 +67,6 @@ func (s *decimalInternalTestSuite) TestDecMarshalJSON() { {"12340Int", NewDec(12340), "\"12340.000000000000000000\"", false}, } for _, tt := range tests { - tt := tt s.T().Run(tt.name, func(t *testing.T) { got, err := tt.d.MarshalJSON() if (err != nil) != tt.wantErr { diff --git a/types/decimal_test.go b/types/decimal_test.go index 6c1e50ab4d..8c49a3c066 100644 --- a/types/decimal_test.go +++ b/types/decimal_test.go @@ -236,7 +236,6 @@ func (s *decimalTestSuite) TestArithmetic() { } for tcIndex, tc := range tests { - tc := tc resAdd := tc.d1.Add(tc.d2) resSub := tc.d1.Sub(tc.d2) resMul := tc.d1.Mul(tc.d2) diff --git a/types/errors/abci_test.go b/types/errors/abci_test.go index 13e7c8455c..c886e3917c 100644 --- a/types/errors/abci_test.go +++ b/types/errors/abci_test.go @@ -181,7 +181,6 @@ func (s *abciTestSuite) TestABCIInfoSerializeErr() { }, } for msg, spec := range specs { - spec := spec _, _, log := ABCIInfo(spec.src, spec.debug) s.Require().Equal(spec.exp, log, msg) } diff --git a/types/events_test.go b/types/events_test.go index 45513e6fd9..334846981e 100644 --- a/types/events_test.go +++ b/types/events_test.go @@ -247,7 +247,6 @@ func (s *eventsTestSuite) TestMarkEventsToIndex() { } for name, tc := range testCases { - tc := tc s.T().Run(name, func(_ *testing.T) { s.Require().Equal(tc.expected, sdk.MarkEventsToIndex(tc.events, tc.indexSet)) }) diff --git a/types/int.go b/types/int.go index b18be80776..a79da3456f 100644 --- a/types/int.go +++ b/types/int.go @@ -403,7 +403,7 @@ func (i *Int) MarshalTo(data []byte) (n int, err error) { // Unmarshal implements the gogo proto custom type interface. func (i *Int) Unmarshal(data []byte) error { if len(data) == 0 { - i = nil + i = nil //nolint: wastedassign return nil } diff --git a/types/int_test.go b/types/int_test.go index bdf7a62eca..59513f258c 100644 --- a/types/int_test.go +++ b/types/int_test.go @@ -404,7 +404,6 @@ func TestRoundTripMarshalToInt(t *testing.T) { } for _, value := range values { - value := value t.Run(fmt.Sprintf("%d", value), func(t *testing.T) { t.Parallel() diff --git a/types/simulation/account_test.go b/types/simulation/account_test.go index 210a8b9c8b..fa3229ca14 100644 --- a/types/simulation/account_test.go +++ b/types/simulation/account_test.go @@ -24,7 +24,6 @@ func TestRandomAccounts(t *testing.T) { {"100-accounts", 100, 100}, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { got := simulation.RandomAccounts(r, tt.n) require.Equal(t, tt.want, len(got)) @@ -65,8 +64,6 @@ func TestRandomFees(t *testing.T) { {"0 coins", sdk.NewCoins(sdk.NewInt64Coin("aaa", 10), sdk.NewInt64Coin("bbb", 5)), false, false}, } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := simulation.RandomFees(r, sdk.Context{}, tt.spendableCoins) if (err != nil) != tt.wantErr { diff --git a/types/simulation/rand_util_test.go b/types/simulation/rand_util_test.go index d46f481fda..860bfb172f 100644 --- a/types/simulation/rand_util_test.go +++ b/types/simulation/rand_util_test.go @@ -23,7 +23,6 @@ func TestRandSubsetCoins(t *testing.T) { {"seed=99", rand.New(rand.NewSource(99)), mustParseCoins("100stake,2testtoken")}, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { got := simulation.RandSubsetCoins(tt.r, tt.coins) gotStringRep := got.String() @@ -46,8 +45,6 @@ func TestRandStringOfLength(t *testing.T) { {"1_000_000-size", 1_000_000, 1_000_000}, } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got := simulation.RandStringOfLength(r, tt.n) require.Equal(t, tt.want, len(got)) diff --git a/types/uint.go b/types/uint.go index 5e59780e76..4eeb3cd9ec 100644 --- a/types/uint.go +++ b/types/uint.go @@ -22,7 +22,7 @@ func (u Uint) BigInt() *big.Int { func NewUintFromBigInt(i *big.Int) Uint { u, err := checkNewUint(i) if err != nil { - panic(fmt.Errorf("overflow: %s", err)) + panic(fmt.Errorf("overflow: %w", err)) } return u } @@ -178,7 +178,7 @@ func (u *Uint) MarshalTo(data []byte) (n int, err error) { // Unmarshal implements the gogo proto custom type interface. func (u *Uint) Unmarshal(data []byte) error { if len(data) == 0 { - u = nil + u = nil //nolint: wastedassign return nil } diff --git a/types/uint_test.go b/types/uint_test.go index 796dd2b428..dd46e16ae9 100644 --- a/types/uint_test.go +++ b/types/uint_test.go @@ -216,7 +216,6 @@ func (s *uintTestSuite) TestSafeSub() { } for i, tc := range testCases { - tc := tc if tc.panic { s.Require().Panics(func() { tc.x.Sub(tc.y) }) continue @@ -304,7 +303,6 @@ func TestRoundTripMarshalToUint(t *testing.T) { } for _, value := range values { - value := value t.Run(fmt.Sprintf("%d", value), func(t *testing.T) { t.Parallel() diff --git a/types/utils_test.go b/types/utils_test.go index 253db8e696..391dc4eb71 100644 --- a/types/utils_test.go +++ b/types/utils_test.go @@ -54,7 +54,6 @@ func (s *utilsTestSuite) TestSortJSON() { } for tcIndex, tc := range cases { - tc := tc got, err := sdk.SortJSON([]byte(tc.unsortedJSON)) if tc.wantErr { s.Require().NotNil(err, "tc #%d", tcIndex) @@ -79,7 +78,6 @@ func (s *utilsTestSuite) TestTimeFormatAndParse() { {"2011-01-10T23:10:05.758230235Z", "2011-01-10T23:10:05.758230235", true}, } for _, tc := range cases { - tc := tc timeFromRFC, err := time.Parse(time.RFC3339Nano, tc.RFC3339NanoStr) s.Require().Nil(err) timeFromSDKFormat, err := time.Parse(sdk.SortableTimeFormat, tc.SDKSortableTimeStr) diff --git a/x/auth/ante/basic_test.go b/x/auth/ante/basic_test.go index 995b3efe9b..5ac84f506a 100644 --- a/x/auth/ante/basic_test.go +++ b/x/auth/ante/basic_test.go @@ -198,8 +198,6 @@ func (suite *AnteTestSuite) TestTxHeightTimeoutDecorator() { } for _, tc := range testCases { - tc := tc - suite.Run(tc.name, func() { suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index d168be7eec..49529ac348 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -308,11 +308,11 @@ func (svd *SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu if !simulate { if !genesis { sigKey := fmt.Sprintf("%d:%d", signerData.AccountNumber, signerData.Sequence) - // TODO could we use `tx.(*wrapper).getBodyBytes()` instead of `ctx.TxBytes()`? + // TODO: could we use `tx.(*wrapper).getBodyBytes()` instead of `ctx.TxBytes()`? txHash := sha256.Sum256(ctx.TxBytes()) - stored := false + var stored bool - // TODO(duong2): Does this really improve performance? + // TODO: Does this really improve performance? stored, err = svd.verifySignatureWithCache(ctx, pubKey, signerData, sig.Data, tx, sigKey, txHash[:]) if stored { diff --git a/x/auth/client/testutil/suite.go b/x/auth/client/testutil/suite.go index 41a3a599fa..5bdf11122a 100644 --- a/x/auth/client/testutil/suite.go +++ b/x/auth/client/testutil/suite.go @@ -331,7 +331,6 @@ func (s *IntegrationTestSuite) TestCLIQueryTxCmdByHash() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := authcli.QueryTxCmd() clientCtx := val.ClientCtx @@ -447,7 +446,6 @@ func (s *IntegrationTestSuite) TestCLIQueryTxCmdByEvents() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := authcli.QueryTxCmd() clientCtx := val.ClientCtx @@ -526,7 +524,6 @@ func (s *IntegrationTestSuite) TestCLIQueryTxsCmdByEvents() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := authcli.QueryTxsByEventsCmd() clientCtx := val.ClientCtx @@ -1166,7 +1163,6 @@ func (s *IntegrationTestSuite) TestGetAccountCmd() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { clientCtx := val.ClientCtx @@ -1205,7 +1201,6 @@ func (s *IntegrationTestSuite) TestGetAccountsCmd() { } for name, tc := range testCases { - tc := tc s.Run(name, func() { cmd := authcli.GetAccountsCmd() clientCtx := val.ClientCtx @@ -1245,7 +1240,6 @@ func (s *IntegrationTestSuite) TestQueryModuleAccountByNameCmd() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { clientCtx := val.ClientCtx @@ -1274,7 +1268,7 @@ func (s *IntegrationTestSuite) TestQueryModuleAccountByNameCmd() { func TestGetBroadcastCommandOfflineFlag(t *testing.T) { clientCtx := client.Context{}.WithOffline(true) - clientCtx = clientCtx.WithTxConfig(simapp.MakeTestEncodingConfig().TxConfig) //nolint:staticcheck + _ = clientCtx.WithTxConfig(simapp.MakeTestEncodingConfig().TxConfig) cmd := authcli.GetBroadcastCommand() _ = testutil.ApplyMockIODiscardOutErr(cmd) @@ -1335,7 +1329,6 @@ func (s *IntegrationTestSuite) TestQueryParamsCmd() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := authcli.QueryParamsCmd() clientCtx := val.ClientCtx diff --git a/x/auth/client/tx.go b/x/auth/client/tx.go index 9f4690f639..2f45549e45 100644 --- a/x/auth/client/tx.go +++ b/x/auth/client/tx.go @@ -52,7 +52,7 @@ func SignTx(txFactory tx.Factory, clientCtx client.Context, name string, txBuild addr := sdk.AccAddress(info.GetPubKey().Address()) if !isTxSigner(addr, txBuilder.GetTx().GetSigners()) { - return fmt.Errorf("%s: %s", sdkerrors.ErrorInvalidSigner, name) + return fmt.Errorf("%w: %s", sdkerrors.ErrorInvalidSigner, name) } if !offline { txFactory, err = populateAccountFromState(txFactory, clientCtx, addr) @@ -79,7 +79,7 @@ func SignTxWithSignerAddress(txFactory tx.Factory, clientCtx client.Context, add // check whether the address is a signer if !isTxSigner(addr, txBuilder.GetTx().GetSigners()) { - return fmt.Errorf("%s: %s", sdkerrors.ErrorInvalidSigner, name) + return fmt.Errorf("%w: %s", sdkerrors.ErrorInvalidSigner, name) } if !offline { diff --git a/x/auth/client/tx_test.go b/x/auth/client/tx_test.go index de086fe19b..2a027753cf 100644 --- a/x/auth/client/tx_test.go +++ b/x/auth/client/tx_test.go @@ -39,7 +39,7 @@ func TestParseQueryResponse(t *testing.T) { require.Equal(t, 10, int(res.GasInfo.GasUsed)) require.NotNil(t, res.Result) - res, err = authclient.ParseQueryResponse([]byte("fuzzy")) + _, err = authclient.ParseQueryResponse([]byte("fuzzy")) require.Error(t, err) } @@ -123,7 +123,6 @@ func TestBatchScanner_Scan(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { scanner, i := authclient.NewBatchScanner(clientCtx.TxConfig, strings.NewReader(tt.batch)), 0 for scanner.Scan() { diff --git a/x/auth/legacy/v043/store_test.go b/x/auth/legacy/v043/store_test.go index 2d72024791..1ed227a9d7 100644 --- a/x/auth/legacy/v043/store_test.go +++ b/x/auth/legacy/v043/store_test.go @@ -537,7 +537,6 @@ func TestMigrateVestingAccounts(t *testing.T) { } for _, tc := range testCases { - tc := tc t.Run(tc.name, func(t *testing.T) { app := simapp.Setup(false) ctx := app.BaseApp.NewContext(false, tmproto.Header{ diff --git a/x/auth/simulation/decoder_test.go b/x/auth/simulation/decoder_test.go index d4a5bc353a..7b8bcee89c 100644 --- a/x/auth/simulation/decoder_test.go +++ b/x/auth/simulation/decoder_test.go @@ -57,7 +57,6 @@ func TestDecodeStore(t *testing.T) { } for i, tt := range tests { - i, tt := i, tt t.Run(tt.name, func(t *testing.T) { switch i { case len(tests) - 1: diff --git a/x/auth/tx/encode_decode_test.go b/x/auth/tx/encode_decode_test.go index 9c546cdb5e..4eab9a3fed 100644 --- a/x/auth/tx/encode_decode_test.go +++ b/x/auth/tx/encode_decode_test.go @@ -101,7 +101,6 @@ func TestUnknownFields(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { bodyBz, err := tt.body.Marshal() require.NoError(t, err) @@ -244,7 +243,6 @@ func TestRejectNonADR027(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { _, err = decoder(tt.txBz) if tt.shouldErr { @@ -282,7 +280,6 @@ func TestVarintMinLength(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(fmt.Sprintf("test %d", tt.n), func(t *testing.T) { l1 := varintMinLength(tt.n) buf := make([]byte, binary.MaxVarintLen64) diff --git a/x/auth/tx/service_test.go b/x/auth/tx/service_test.go index 8089f74fee..0b65b2d2cd 100644 --- a/x/auth/tx/service_test.go +++ b/x/auth/tx/service_test.go @@ -135,7 +135,6 @@ func (s *IntegrationTestSuite) TestSimulateTx_GRPC() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { // Broadcast the tx via gRPC via the validator's clientCtx (which goes // through Tendermint). @@ -457,7 +456,6 @@ func (s *IntegrationTestSuite) TestBroadcastTx_GRPC() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { // Broadcast the tx via gRPC via the validator's clientCtx (which goes // through Tendermint). diff --git a/x/auth/types/account_test.go b/x/auth/types/account_test.go index a90a633051..8f4b1cc9af 100644 --- a/x/auth/types/account_test.go +++ b/x/auth/types/account_test.go @@ -104,8 +104,6 @@ func TestGenesisAccountValidate(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { require.Equal(t, tt.expErr, tt.acc.Validate() != nil) }) @@ -170,7 +168,6 @@ func TestValidate(t *testing.T) { }, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { err := tt.acc.Validate() require.Equal(t, tt.expErr, err) diff --git a/x/auth/types/params_test.go b/x/auth/types/params_test.go index b4bbce8ba0..aeb5c48d6a 100644 --- a/x/auth/types/params_test.go +++ b/x/auth/types/params_test.go @@ -37,7 +37,6 @@ func TestParams_Validate(t *testing.T) { types.DefaultSigVerifyCostED25519, types.DefaultSigVerifyCostSecp256k1), fmt.Errorf("invalid tx size cost per byte: 0")}, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { got := tt.params.Validate() if tt.wantErr == nil { diff --git a/x/auth/types/permissions_test.go b/x/auth/types/permissions_test.go index de5c256457..78133007da 100644 --- a/x/auth/types/permissions_test.go +++ b/x/auth/types/permissions_test.go @@ -41,7 +41,6 @@ func TestValidatePermissions(t *testing.T) { } for i, tc := range cases { - i, tc := i, tc t.Run(tc.name, func(t *testing.T) { err := validatePermissions(tc.permissions...) if tc.expectPass { diff --git a/x/auth/vesting/client/testutil/suite.go b/x/auth/vesting/client/testutil/suite.go index 7f8be8d668..a486b5ee84 100644 --- a/x/auth/vesting/client/testutil/suite.go +++ b/x/auth/vesting/client/testutil/suite.go @@ -112,8 +112,6 @@ func (s *IntegrationTestSuite) TestNewMsgCreateVestingAccountCmd() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { clientCtx := val.ClientCtx diff --git a/x/auth/vesting/handler_test.go b/x/auth/vesting/handler_test.go index 9bd3c2ca6b..ceaa19e6e9 100644 --- a/x/auth/vesting/handler_test.go +++ b/x/auth/vesting/handler_test.go @@ -62,8 +62,6 @@ func (suite *HandlerTestSuite) TestMsgCreateVestingAccount() { } for _, tc := range testCases { - tc := tc - suite.Run(tc.name, func() { res, err := suite.handler(ctx, tc.msg) if tc.expectErr { diff --git a/x/auth/vesting/types/vesting_account_test.go b/x/auth/vesting/types/vesting_account_test.go index 26cbbcdeb7..40e48bbf4c 100644 --- a/x/auth/vesting/types/vesting_account_test.go +++ b/x/auth/vesting/types/vesting_account_test.go @@ -728,8 +728,6 @@ func TestGenesisAccountValidate(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { require.Equal(t, tt.expErr, tt.acc.Validate() != nil) }) diff --git a/x/authz/client/testutil/grpc.go b/x/authz/client/testutil/grpc.go index 7b5bbb6adf..43cbca59cd 100644 --- a/x/authz/client/testutil/grpc.go +++ b/x/authz/client/testutil/grpc.go @@ -60,7 +60,6 @@ func (s *IntegrationTestSuite) TestQueryGrantGRPC() { }, } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, _ := rest.GetRequest(tc.url) require := s.Require() @@ -146,7 +145,6 @@ func (s *IntegrationTestSuite) TestQueryGrantsGRPC() { }, } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { tc.preRun() resp, _ := rest.GetRequest(tc.url) diff --git a/x/authz/client/testutil/query.go b/x/authz/client/testutil/query.go index 07ffb10315..698c832d6d 100644 --- a/x/authz/client/testutil/query.go +++ b/x/authz/client/testutil/query.go @@ -73,8 +73,6 @@ func (s *IntegrationTestSuite) TestQueryAuthorizations() { }, } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryGrants() clientCtx := val.ClientCtx @@ -165,8 +163,6 @@ func (s *IntegrationTestSuite) TestQueryAuthorization() { }, } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryGrants() clientCtx := val.ClientCtx diff --git a/x/authz/client/testutil/tx.go b/x/authz/client/testutil/tx.go index fdf3d150b4..831e26e6d8 100644 --- a/x/authz/client/testutil/tx.go +++ b/x/authz/client/testutil/tx.go @@ -311,7 +311,6 @@ func (s *IntegrationTestSuite) TestCLITxGrantAuthorization() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { clientCtx := val.ClientCtx out, err := ExecGrant( @@ -464,7 +463,6 @@ func (s *IntegrationTestSuite) TestCmdRevokeAuthorizations() { }, } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.NewCmdRevokeAuthorization() clientCtx := val.ClientCtx @@ -606,7 +604,6 @@ func (s *IntegrationTestSuite) TestNewExecGenericAuthorized() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.NewCmdExecAuthorization() clientCtx := val.ClientCtx @@ -691,7 +688,6 @@ func (s *IntegrationTestSuite) TestNewExecGrantAuthorized() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.NewCmdExecAuthorization() clientCtx := val.ClientCtx @@ -787,7 +783,6 @@ func (s *IntegrationTestSuite) TestExecDelegateAuthorization() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.NewCmdExecAuthorization() clientCtx := val.ClientCtx @@ -864,7 +859,6 @@ func (s *IntegrationTestSuite) TestExecDelegateAuthorization() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.NewCmdExecAuthorization() clientCtx := val.ClientCtx @@ -1008,7 +1002,6 @@ func (s *IntegrationTestSuite) TestExecUndelegateAuthorization() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.NewCmdExecAuthorization() clientCtx := val.ClientCtx @@ -1087,7 +1080,6 @@ func (s *IntegrationTestSuite) TestExecUndelegateAuthorization() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.NewCmdExecAuthorization() clientCtx := val.ClientCtx diff --git a/x/authz/keeper/grpc_query_test.go b/x/authz/keeper/grpc_query_test.go index efc5b1226a..a65c48e83b 100644 --- a/x/authz/keeper/grpc_query_test.go +++ b/x/authz/keeper/grpc_query_test.go @@ -228,8 +228,6 @@ func (suite *TestSuite) TestGRPCQueryGranterGrants() { } for _, tc := range testCases { - tc := tc - suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { tc.preRun() result, err := queryClient.GranterGrants(gocontext.Background(), &tc.request) @@ -315,8 +313,6 @@ func (suite *TestSuite) TestGRPCQueryGranteeGrants() { } for _, tc := range testCases { - tc := tc - suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { tc.preRun() result, err := queryClient.GranteeGrants(gocontext.Background(), &tc.request) diff --git a/x/authz/simulation/decoder_test.go b/x/authz/simulation/decoder_test.go index fc43ef917d..244a9722c4 100644 --- a/x/authz/simulation/decoder_test.go +++ b/x/authz/simulation/decoder_test.go @@ -41,7 +41,6 @@ func TestDecodeStore(t *testing.T) { } for i, tt := range tests { - i, tt := i, tt t.Run(tt.name, func(t *testing.T) { if tt.expectErr { require.Panics(t, func() { dec(kvPairs.Pairs[i], kvPairs.Pairs[i]) }, tt.name) diff --git a/x/bank/client/testutil/grpc.go b/x/bank/client/testutil/grpc.go index 3d9651eff9..d3b418dc27 100644 --- a/x/bank/client/testutil/grpc.go +++ b/x/bank/client/testutil/grpc.go @@ -88,7 +88,6 @@ func (s *IntegrationTestSuite) TestTotalSupplyGRPCHandler() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers) s.Require().NoError(err) @@ -209,7 +208,6 @@ func (s *IntegrationTestSuite) TestDenomMetadataGRPCHandler() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers) s.Require().NoError(err) @@ -273,7 +271,6 @@ func (s *IntegrationTestSuite) TestBalancesGRPCHandler() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := rest.GetRequest(tc.url) s.Require().NoError(err) diff --git a/x/bank/client/testutil/suite.go b/x/bank/client/testutil/suite.go index 6358107cdf..abab55d41c 100644 --- a/x/bank/client/testutil/suite.go +++ b/x/bank/client/testutil/suite.go @@ -145,8 +145,6 @@ func (s *IntegrationTestSuite) TestGetBalancesCmd() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetBalancesCmd() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, tc.args) @@ -225,8 +223,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryTotalSupply() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryTotalSupply() clientCtx := val.ClientCtx @@ -367,8 +363,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDenomsMetadata() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdDenomsMetadata() clientCtx := val.ClientCtx @@ -475,8 +469,6 @@ func (s *IntegrationTestSuite) TestNewSendTxCmd() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { clientCtx := val.ClientCtx diff --git a/x/bank/keeper/genesis.go b/x/bank/keeper/genesis.go index fe680e04ee..065bd8d37b 100644 --- a/x/bank/keeper/genesis.go +++ b/x/bank/keeper/genesis.go @@ -42,7 +42,7 @@ func (k BaseKeeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) { func (k BaseKeeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { totalSupply, _, err := k.GetPaginatedTotalSupply(ctx, &query.PageRequest{Limit: query.MaxLimit}) if err != nil { - panic(fmt.Errorf("unable to fetch total supply %v", err)) + panic(fmt.Errorf("unable to fetch total supply: %w", err)) } return types.NewGenesisState( diff --git a/x/bank/keeper/genesis_test.go b/x/bank/keeper/genesis_test.go index 4c5c6ea86b..36aee9a1a9 100644 --- a/x/bank/keeper/genesis_test.go +++ b/x/bank/keeper/genesis_test.go @@ -99,7 +99,6 @@ func (suite *IntegrationTestSuite) TestTotalSupply() { } for _, tc := range testcases { - tc := tc suite.Run(tc.name, func() { if tc.expPanic { suite.PanicsWithError(tc.expPanicMsg, func() { suite.app.BankKeeper.InitGenesis(suite.ctx, tc.genesis) }) diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index 3e004a1e31..e66d63f267 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -72,7 +72,7 @@ func (k BaseKeeper) GetPaginatedTotalSupply(ctx sdk.Context, pagination *query.P var amount sdk.Int err := amount.Unmarshal(value) if err != nil { - return fmt.Errorf("unable to convert amount string to Int %v", err) + return fmt.Errorf("unable to convert amount string to Int: %w", err) } // `Add` omits the 0 coins addition to the `supply`. @@ -231,7 +231,7 @@ func (k BaseKeeper) GetSupply(ctx sdk.Context, denom string) sdk.Coin { var amount sdk.Int err := amount.Unmarshal(bz) if err != nil { - panic(fmt.Errorf("unable to unmarshal supply value %v", err)) + panic(fmt.Errorf("unable to unmarshal supply value: %w", err)) } return sdk.Coin{ @@ -466,7 +466,7 @@ func (k BaseKeeper) BurnCoins(ctx sdk.Context, moduleName string, amounts sdk.Co func (k BaseKeeper) setSupply(ctx sdk.Context, coin sdk.Coin) { intBytes, err := coin.Amount.Marshal() if err != nil { - panic(fmt.Errorf("unable to marshal amount value %v", err)) + panic(fmt.Errorf("unable to marshal amount value: %w", err)) } store := ctx.KVStore(k.storeKey) @@ -528,7 +528,7 @@ func (k BaseViewKeeper) IterateTotalSupply(ctx sdk.Context, cb func(sdk.Coin) bo var amount sdk.Int err := amount.Unmarshal(iterator.Value()) if err != nil { - panic(fmt.Errorf("unable to unmarshal supply value %v", err)) + panic(fmt.Errorf("unable to unmarshal supply value: %w", err)) } balance := sdk.Coin{ diff --git a/x/bank/simulation/genesis_test.go b/x/bank/simulation/genesis_test.go index 40d9afe119..efbdf4cf42 100644 --- a/x/bank/simulation/genesis_test.go +++ b/x/bank/simulation/genesis_test.go @@ -70,8 +70,6 @@ func TestRandomizedGenState1(t *testing.T) { } for _, tt := range tests { - tt := tt - require.Panicsf(t, func() { simulation.RandomizedGenState(&tt.simState) }, tt.panicMsg) } } diff --git a/x/bank/types/balance_test.go b/x/bank/types/balance_test.go index b18a0f7b13..7080371306 100644 --- a/x/bank/types/balance_test.go +++ b/x/bank/types/balance_test.go @@ -102,7 +102,6 @@ func TestBalanceValidate(t *testing.T) { } for _, tc := range testCases { - tc := tc t.Run(tc.name, func(t *testing.T) { err := tc.balance.Validate() @@ -126,7 +125,6 @@ func TestBalance_GetAddress(t *testing.T) { {"valid address", "link1vy0ga0klndqy92ceqehfkvgmn4t94ete4mhemy", false}, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { b := bank.Balance{Address: tt.Address} if tt.wantPanic { diff --git a/x/bank/types/genesis_test.go b/x/bank/types/genesis_test.go index d5588245b2..637306464a 100644 --- a/x/bank/types/genesis_test.go +++ b/x/bank/types/genesis_test.go @@ -143,7 +143,6 @@ func TestGenesisStateValidate(t *testing.T) { } for _, tc := range testCases { - tc := tc t.Run(tc.name, func(t *testing.T) { err := tc.genesisState.Validate() diff --git a/x/bank/types/key_test.go b/x/bank/types/key_test.go index 54a2ee64a9..193001f4f5 100644 --- a/x/bank/types/key_test.go +++ b/x/bank/types/key_test.go @@ -39,7 +39,6 @@ func TestAddressFromBalancesStore(t *testing.T) { } for _, tc := range tests { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() addr, err := types.AddressFromBalancesStore(tc.key) diff --git a/x/bank/types/metadata_test.go b/x/bank/types/metadata_test.go index 1201e0473b..d895a0226d 100644 --- a/x/bank/types/metadata_test.go +++ b/x/bank/types/metadata_test.go @@ -216,7 +216,6 @@ func TestMetadataValidate(t *testing.T) { } for _, tc := range testCases { - tc := tc t.Run(tc.name, func(t *testing.T) { err := tc.metadata.Validate() @@ -258,7 +257,6 @@ func TestMarshalJSONMetaData(t *testing.T) { } for _, tc := range testCases { - tc := tc t.Run(tc.name, func(t *testing.T) { bz, err := cdc.MarshalJSON(tc.input) require.NoError(t, err) diff --git a/x/bank/types/params_test.go b/x/bank/types/params_test.go index 0962d125c1..1ca04f6474 100644 --- a/x/bank/types/params_test.go +++ b/x/bank/types/params_test.go @@ -29,7 +29,6 @@ func Test_validateSendEnabledParam(t *testing.T) { {"invalid denom send disabled", args{*NewSendEnabled("0FOO", false)}, true}, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { require.Equal(t, tt.wantErr, validateSendEnabled(tt.args.i) != nil) }) diff --git a/x/bankplus/keeper/keeper_test.go b/x/bankplus/keeper/keeper_test.go index 3486106a61..37f271d7c7 100644 --- a/x/bankplus/keeper/keeper_test.go +++ b/x/bankplus/keeper/keeper_test.go @@ -294,7 +294,6 @@ func (suite *IntegrationTestSuite) TestInputOutputCoins() { } for name, tc := range tcs { - tc := tc suite.T().Run(name, func(t *testing.T) { if tc.err != nil { suite.EqualError(targetKeeper(tc.deactMultiSend).InputOutputCoins(ctx, input, output), tc.err.Error()) diff --git a/x/capability/simulation/decoder_test.go b/x/capability/simulation/decoder_test.go index d12e8b5044..ce87e508e6 100644 --- a/x/capability/simulation/decoder_test.go +++ b/x/capability/simulation/decoder_test.go @@ -47,7 +47,6 @@ func TestDecodeStore(t *testing.T) { } for i, tt := range tests { - i, tt := i, tt t.Run(tt.name, func(t *testing.T) { switch i { case len(tests) - 1: diff --git a/x/capability/simulation/genesis_test.go b/x/capability/simulation/genesis_test.go index ab49833f1d..46b2687b50 100644 --- a/x/capability/simulation/genesis_test.go +++ b/x/capability/simulation/genesis_test.go @@ -66,8 +66,6 @@ func TestRandomizedGenState1(t *testing.T) { } for _, tt := range tests { - tt := tt - require.Panicsf(t, func() { simulation.RandomizedGenState(&tt.simState) }, tt.panicMsg) } } diff --git a/x/capability/types/genesis_test.go b/x/capability/types/genesis_test.go index 5208a2b590..41525fb827 100644 --- a/x/capability/types/genesis_test.go +++ b/x/capability/types/genesis_test.go @@ -112,7 +112,6 @@ func TestValidateGenesis(t *testing.T) { } for _, tc := range testCases { - tc := tc genState := DefaultGenesis() tc.malleate(genState) err := genState.Validate() diff --git a/x/collection/client/testutil/query.go b/x/collection/client/testutil/query.go index 0ca3c830b0..4c01a95320 100644 --- a/x/collection/client/testutil/query.go +++ b/x/collection/client/testutil/query.go @@ -65,8 +65,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdBalance() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdBalances() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -141,8 +139,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdFTSupply() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdFTSupply() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -217,8 +213,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdFTMinted() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdFTMinted() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -293,8 +287,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdFTBurnt() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdFTBurnt() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -368,8 +360,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdNFTSupply() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdNFTSupply() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -443,8 +433,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdNFTMinted() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdNFTMinted() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -518,8 +506,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdNFTBurnt() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdNFTBurnt() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -573,8 +559,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdContract() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdContract() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -643,8 +627,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdTokenType() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdTokenType() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -719,8 +701,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdToken() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdToken() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -793,8 +773,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdRoot() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdRoot() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -865,8 +843,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdParent() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdParent() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -941,8 +917,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdChildren() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdChildren() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -1020,8 +994,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdGranteeGrants() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdGranteeGrants() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -1082,8 +1054,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdIsOperatorFor() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdIsOperatorFor() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -1142,8 +1112,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdHoldersByOperator() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdHoldersByOperator() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) diff --git a/x/collection/client/testutil/tx.go b/x/collection/client/testutil/tx.go index a0aee34cde..b7c18d0e0a 100644 --- a/x/collection/client/testutil/tx.go +++ b/x/collection/client/testutil/tx.go @@ -71,8 +71,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdSendFT() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdSendFT() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -155,8 +153,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdOperatorSendFT() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdOperatorSendFT() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -234,8 +230,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdSendNFT() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdSendNFT() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -318,8 +312,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdOperatorSendNFT() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdOperatorSendNFT() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -374,8 +366,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdCreateContract() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdCreateContract() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -441,8 +431,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdIssueFT() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdIssueFT() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -502,8 +490,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdIssueNFT() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdIssueNFT() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -575,8 +561,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdMintFT() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdMintFT() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -645,8 +629,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdMintNFT() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdMintNFT() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -711,8 +693,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdBurnFT() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdBurnFT() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -781,8 +761,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdOperatorBurnFT() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdOperatorBurnFT() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -847,8 +825,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdBurnNFT() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdBurnNFT() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -917,8 +893,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdOperatorOperatorBurnNFT() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdOperatorBurnNFT() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -994,8 +968,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdModify() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdModify() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -1065,8 +1037,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdAttach() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdAttach() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -1131,8 +1101,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdDetach() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdDetach() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -1206,8 +1174,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdOperatorAttach() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdOperatorAttach() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -1276,8 +1242,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdOperatorDetach() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdOperatorDetach() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -1336,8 +1300,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdGrantPermission() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdGrantPermission() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -1393,8 +1355,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdRevokePermission() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdRevokePermission() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -1450,8 +1410,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdAuthorizeOperator() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdAuthorizeOperator() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -1507,8 +1465,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdRevokeOperator() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdRevokeOperator() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) diff --git a/x/collection/msgs_test.go b/x/collection/msgs_test.go index 04de79a91c..3a094d899d 100644 --- a/x/collection/msgs_test.go +++ b/x/collection/msgs_test.go @@ -2067,7 +2067,6 @@ func TestAminoJSON(t *testing.T) { } for name, tc := range testCase { - tc := tc t.Run(name, func(t *testing.T) { tx.Msgs = []sdk.Msg{tc.msg} require.Equal(t, collection.RouterKey, tc.msg.Route()) diff --git a/x/crisis/client/testsuite/suite.go b/x/crisis/client/testsuite/suite.go index 8ac29d8ad3..75c06177c4 100644 --- a/x/crisis/client/testsuite/suite.go +++ b/x/crisis/client/testsuite/suite.go @@ -83,8 +83,6 @@ func (s *IntegrationTestSuite) TestNewMsgVerifyInvariantTxCmd() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.NewMsgVerifyInvariantTxCmd() clientCtx := val.ClientCtx diff --git a/x/crisis/handler_test.go b/x/crisis/handler_test.go index c174ce536c..dc646d5338 100644 --- a/x/crisis/handler_test.go +++ b/x/crisis/handler_test.go @@ -58,7 +58,6 @@ func TestHandleMsgVerifyInvariant(t *testing.T) { } for _, tc := range cases { - tc := tc t.Run(tc.name, func(t *testing.T) { h := crisis.NewHandler(app.CrisisKeeper) diff --git a/x/distribution/client/common/common_test.go b/x/distribution/client/common/common_test.go index f81db2b6d4..168cb16fd5 100644 --- a/x/distribution/client/common/common_test.go +++ b/x/distribution/client/common/common_test.go @@ -30,7 +30,6 @@ func TestQueryDelegationRewardsAddrValidation(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { _, _, err := QueryDelegationRewards(clientCtx, tt.args.delAddr, tt.args.valAddr) require.True(t, err != nil, tt.wantErr) diff --git a/x/distribution/client/testutil/grpc.go b/x/distribution/client/testutil/grpc.go index 76fc652c15..ceaf4627a1 100644 --- a/x/distribution/client/testutil/grpc.go +++ b/x/distribution/client/testutil/grpc.go @@ -56,7 +56,6 @@ func (s *GRPCQueryTestSuite) TestQueryParamsGRPC() { } for _, tc := range testCases { - tc := tc resp, err := rest.GetRequest(tc.url) s.Run(tc.name, func() { s.Require().NoError(err) @@ -106,7 +105,6 @@ func (s *GRPCQueryTestSuite) TestQueryOutstandingRewardsGRPC() { } for _, tc := range testCases { - tc := tc resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers) s.Run(tc.name, func() { if tc.expErr { @@ -160,7 +158,6 @@ func (s *GRPCQueryTestSuite) TestQueryValidatorCommissionGRPC() { } for _, tc := range testCases { - tc := tc resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers) s.Run(tc.name, func() { if tc.expErr { @@ -218,7 +215,6 @@ func (s *GRPCQueryTestSuite) TestQuerySlashesGRPC() { } for _, tc := range testCases { - tc := tc resp, err := rest.GetRequest(tc.url) s.Run(tc.name, func() { @@ -294,7 +290,6 @@ func (s *GRPCQueryTestSuite) TestQueryDelegatorRewardsGRPC() { } for _, tc := range testCases { - tc := tc resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers) s.Run(tc.name, func() { @@ -346,7 +341,6 @@ func (s *GRPCQueryTestSuite) TestQueryDelegatorValidatorsGRPC() { } for _, tc := range testCases { - tc := tc resp, err := rest.GetRequest(tc.url) s.Run(tc.name, func() { @@ -398,7 +392,6 @@ func (s *GRPCQueryTestSuite) TestQueryWithdrawAddressGRPC() { } for _, tc := range testCases { - tc := tc resp, err := rest.GetRequest(tc.url) s.Run(tc.name, func() { @@ -443,7 +436,6 @@ func (s *GRPCQueryTestSuite) TestQueryValidatorCommunityPoolGRPC() { } for _, tc := range testCases { - tc := tc resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers) s.Run(tc.name, func() { diff --git a/x/distribution/client/testutil/suite.go b/x/distribution/client/testutil/suite.go index 4f9513580a..1e10b432be 100644 --- a/x/distribution/client/testutil/suite.go +++ b/x/distribution/client/testutil/suite.go @@ -86,8 +86,6 @@ withdraw_addr_enabled: true`, } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryParams() clientCtx := val.ClientCtx @@ -145,8 +143,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorOutstandingRewards() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryValidatorOutstandingRewards() clientCtx := val.ClientCtx @@ -208,8 +204,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorCommission() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryValidatorCommission() clientCtx := val.ClientCtx @@ -287,8 +281,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorSlashes() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryValidatorSlashes() clientCtx := val.ClientCtx @@ -388,8 +380,6 @@ total: } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryDelegatorRewards() clientCtx := val.ClientCtx @@ -431,8 +421,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryCommunityPool() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryCommunityPool() clientCtx := val.ClientCtx @@ -492,8 +480,6 @@ func (s *IntegrationTestSuite) TestNewWithdrawRewardsCmd() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { clientCtx := val.ClientCtx @@ -544,8 +530,6 @@ func (s *IntegrationTestSuite) TestNewWithdrawAllRewardsCmd() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.NewWithdrawAllRewardsCmd() clientCtx := val.ClientCtx @@ -599,8 +583,6 @@ func (s *IntegrationTestSuite) TestNewSetWithdrawAddrCmd() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.NewSetWithdrawAddrCmd() clientCtx := val.ClientCtx @@ -654,8 +636,6 @@ func (s *IntegrationTestSuite) TestNewFundCommunityPoolCmd() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.NewFundCommunityPoolCmd() clientCtx := val.ClientCtx @@ -727,8 +707,6 @@ func (s *IntegrationTestSuite) TestGetCmdSubmitProposal() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdSubmitProposal() clientCtx := val.ClientCtx diff --git a/x/distribution/keeper/allocation_test.go b/x/distribution/keeper/allocation_test.go index 62bc93f4bf..28c8e7869c 100644 --- a/x/distribution/keeper/allocation_test.go +++ b/x/distribution/keeper/allocation_test.go @@ -142,7 +142,7 @@ func TestAllocateTokensTruncation(t *testing.T) { Address: valConsPk2.Address(), Power: 10, } - abciValС := abci.Validator{ + abciValC := abci.Validator{ Address: valConsPk3.Address(), Power: 10, } @@ -177,7 +177,7 @@ func TestAllocateTokensTruncation(t *testing.T) { SignedLastBlock: true, }, { - Validator: abciValС, + Validator: abciValC, SignedLastBlock: true, }, } diff --git a/x/distribution/legacy/v043/store_test.go b/x/distribution/legacy/v043/store_test.go index fff87528a9..4c8ff1d522 100644 --- a/x/distribution/legacy/v043/store_test.go +++ b/x/distribution/legacy/v043/store_test.go @@ -88,7 +88,6 @@ func TestStoreMigration(t *testing.T) { // Make sure the new keys are set and old keys are deleted. for _, tc := range testCases { - tc := tc t.Run(tc.name, func(t *testing.T) { if !bytes.Equal(tc.oldKey, tc.newKey) { require.Nil(t, store.Get(tc.oldKey)) diff --git a/x/distribution/simulation/decoder_test.go b/x/distribution/simulation/decoder_test.go index f37bb4fab8..841aaf5f17 100644 --- a/x/distribution/simulation/decoder_test.go +++ b/x/distribution/simulation/decoder_test.go @@ -66,7 +66,6 @@ func TestDecodeDistributionStore(t *testing.T) { {"other", ""}, } for i, tt := range tests { - i, tt := i, tt t.Run(tt.name, func(t *testing.T) { switch i { case len(tests) - 1: diff --git a/x/distribution/simulation/genesis_test.go b/x/distribution/simulation/genesis_test.go index 8db6652da6..1724ef5fa9 100644 --- a/x/distribution/simulation/genesis_test.go +++ b/x/distribution/simulation/genesis_test.go @@ -76,8 +76,6 @@ func TestRandomizedGenState1(t *testing.T) { } for _, tt := range tests { - tt := tt - require.Panicsf(t, func() { simulation.RandomizedGenState(&tt.simState) }, tt.panicMsg) } } diff --git a/x/distribution/types/params_internal_test.go b/x/distribution/types/params_internal_test.go index 234a79fbd1..152845f00c 100644 --- a/x/distribution/types/params_internal_test.go +++ b/x/distribution/types/params_internal_test.go @@ -24,7 +24,6 @@ func Test_validateAuxFuncs(t *testing.T) { {"two dec", args{sdk.NewDec(2)}, true}, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { require.Equal(t, tt.wantErr, validateCommunityTax(tt.args.i) != nil) require.Equal(t, tt.wantErr, validateBaseProposerReward(tt.args.i) != nil) diff --git a/x/evidence/client/testutil/suite.go b/x/evidence/client/testutil/suite.go index 3fdba740e9..80e2ce89b4 100644 --- a/x/evidence/client/testutil/suite.go +++ b/x/evidence/client/testutil/suite.go @@ -56,8 +56,6 @@ func (s *IntegrationTestSuite) TestGetQueryCmd() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.GetQueryCmd() clientCtx := val.ClientCtx diff --git a/x/evidence/simulation/decoder_test.go b/x/evidence/simulation/decoder_test.go index 3e18656b6c..eeca030223 100644 --- a/x/evidence/simulation/decoder_test.go +++ b/x/evidence/simulation/decoder_test.go @@ -52,7 +52,6 @@ func TestDecodeStore(t *testing.T) { } for i, tt := range tests { - i, tt := i, tt t.Run(tt.name, func(t *testing.T) { switch i { case len(tests) - 1: diff --git a/x/evidence/types/evidence_test.go b/x/evidence/types/evidence_test.go index 696600d0ad..c7a0be8e53 100644 --- a/x/evidence/types/evidence_test.go +++ b/x/evidence/types/evidence_test.go @@ -52,7 +52,6 @@ func TestEquivocationValidateBasic(t *testing.T) { } for _, tc := range testCases { - tc := tc t.Run(tc.name, func(t *testing.T) { require.Equal(t, tc.expectErr, tc.e.ValidateBasic() != nil) }) diff --git a/x/fbridge/keeper/transfer.go b/x/fbridge/keeper/transfer.go index 333fa72f23..2eabb45cb5 100644 --- a/x/fbridge/keeper/transfer.go +++ b/x/fbridge/keeper/transfer.go @@ -27,7 +27,7 @@ func (k Keeper) handleBridgeTransfer(ctx sdk.Context, sender sdk.AccAddress, amo } if err := k.bankKeeper.BurnCoins(ctx, types.ModuleName, token); err != nil { - panic(fmt.Errorf("cannot burn coins after a successful send to a module account: %s", err)) + panic(fmt.Errorf("cannot burn coins after a successful send to a module account: %w", err)) } seq := k.GetNextSequence(ctx) diff --git a/x/fbridge/types/msgs_test.go b/x/fbridge/types/msgs_test.go index 87166e0ad4..b339c7d592 100644 --- a/x/fbridge/types/msgs_test.go +++ b/x/fbridge/types/msgs_test.go @@ -137,7 +137,6 @@ func TestAminoJSON(t *testing.T) { } for name, tc := range testCase { - tc := tc t.Run(name, func(t *testing.T) { tx.Msgs = []sdk.Msg{tc.msg} require.Equal(t, fbridgetypes.RouterKey, tc.msg.Route()) diff --git a/x/feegrant/client/testutil/suite.go b/x/feegrant/client/testutil/suite.go index cac943e7b7..3e75a99d2d 100644 --- a/x/feegrant/client/testutil/suite.go +++ b/x/feegrant/client/testutil/suite.go @@ -168,8 +168,6 @@ func (s *IntegrationTestSuite) TestCmdGetFeeGrant() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryFeeGrant() out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) @@ -234,8 +232,6 @@ func (s *IntegrationTestSuite) TestCmdGetFeeGrantsByGrantee() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryFeeGrantsByGrantee() out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) @@ -290,8 +286,6 @@ func (s *IntegrationTestSuite) TestCmdGetFeeGrantsByGranter() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryFeeGrantsByGranter() out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) @@ -583,8 +577,6 @@ func (s *IntegrationTestSuite) TestNewCmdFeeGrant() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.NewCmdFeeGrant() out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) @@ -690,8 +682,6 @@ func (s *IntegrationTestSuite) TestNewCmdRevokeFeegrant() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.NewCmdRevokeFeegrant() out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) @@ -829,8 +819,6 @@ func (s *IntegrationTestSuite) TestFilteredFeeAllowance() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.NewCmdFeeGrant() out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) @@ -924,8 +912,6 @@ func (s *IntegrationTestSuite) TestFilteredFeeAllowance() { } for _, tc := range cases { - tc := tc - s.Run(tc.name, func() { out, err := tc.malleate() s.Require().NoError(err) diff --git a/x/feegrant/grant_test.go b/x/feegrant/grant_test.go index 2368c77d3d..af0f1873c9 100644 --- a/x/feegrant/grant_test.go +++ b/x/feegrant/grant_test.go @@ -73,7 +73,6 @@ func TestGrant(t *testing.T) { } for name, tc := range cases { - tc := tc t.Run(name, func(t *testing.T) { grant, err := feegrant.NewGrant(tc.granter, tc.grantee, &feegrant.BasicAllowance{ SpendLimit: tc.limit, diff --git a/x/feegrant/keeper/genesis_test.go b/x/feegrant/keeper/genesis_test.go index ea2731cb4b..9f659bf30c 100644 --- a/x/feegrant/keeper/genesis_test.go +++ b/x/feegrant/keeper/genesis_test.go @@ -100,7 +100,6 @@ func (suite *GenesisTestSuite) TestInitGenesis() { } for _, tc := range testCases { - tc := tc suite.Run(tc.name, func() { err := suite.keeper.InitGenesis(suite.ctx, &feegrant.GenesisState{Allowances: tc.feeAllowances}) suite.Require().Error(err) diff --git a/x/feegrant/keeper/keeper_test.go b/x/feegrant/keeper/keeper_test.go index 5851f8e978..b6f843a6c7 100644 --- a/x/feegrant/keeper/keeper_test.go +++ b/x/feegrant/keeper/keeper_test.go @@ -120,7 +120,6 @@ func (suite *KeeperTestSuite) TestKeeperCrud() { } for name, tc := range cases { - tc := tc suite.Run(name, func() { allow, _ := suite.keeper.GetAllowance(suite.sdkCtx, tc.granter, tc.grantee) @@ -196,7 +195,6 @@ func (suite *KeeperTestSuite) TestUseGrantedFee() { } for name, tc := range cases { - tc := tc suite.Run(name, func() { err := suite.keeper.GrantAllowance(suite.sdkCtx, suite.addrs[0], suite.addrs[1], future) suite.Require().NoError(err) diff --git a/x/feegrant/simulation/decoder_test.go b/x/feegrant/simulation/decoder_test.go index 989387f831..c13e75111f 100644 --- a/x/feegrant/simulation/decoder_test.go +++ b/x/feegrant/simulation/decoder_test.go @@ -49,7 +49,6 @@ func TestDecodeStore(t *testing.T) { } for i, tt := range tests { - i, tt := i, tt t.Run(tt.name, func(t *testing.T) { switch i { case len(tests) - 1: diff --git a/x/feegrant/types/grant_test.go b/x/feegrant/types/grant_test.go index 687fe37351..2831eb09ec 100644 --- a/x/feegrant/types/grant_test.go +++ b/x/feegrant/types/grant_test.go @@ -71,7 +71,6 @@ func TestGrant(t *testing.T) { } for name, tc := range cases { - tc := tc t.Run(name, func(t *testing.T) { grant, err := feegrant.NewGrant(tc.granter, tc.grantee, &feegrant.BasicAllowance{ SpendLimit: tc.limit, diff --git a/x/foundation/client/testutil/grpc.go b/x/foundation/client/testutil/grpc.go index 7f16e5675f..b0103983ef 100644 --- a/x/foundation/client/testutil/grpc.go +++ b/x/foundation/client/testutil/grpc.go @@ -34,7 +34,6 @@ func (s *IntegrationTestSuite) TestGRPCParams() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := rest.GetRequest(tc.url) s.Require().NoError(err) diff --git a/x/foundation/client/testutil/query.go b/x/foundation/client/testutil/query.go index a7d16e38d2..0703d382ee 100644 --- a/x/foundation/client/testutil/query.go +++ b/x/foundation/client/testutil/query.go @@ -44,8 +44,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdParams() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdParams() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -86,8 +84,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdTreasury() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdTreasury() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -127,8 +123,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdFoundationInfo() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdFoundationInfo() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -184,8 +178,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdMember() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdMember() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -226,8 +218,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdMembers() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdMembers() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -276,8 +266,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdProposal() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdProposal() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -317,8 +305,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdProposals() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdProposals() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -377,8 +363,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdVote() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdVote() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -427,8 +411,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdVotes() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdVotes() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -477,8 +459,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdTallyResult() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdTallyResult() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -521,8 +501,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdCensorships() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdCensorships() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -586,8 +564,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdGrants() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdGrants() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) diff --git a/x/foundation/client/testutil/tx.go b/x/foundation/client/testutil/tx.go index ccc283cb8c..b73acc158e 100644 --- a/x/foundation/client/testutil/tx.go +++ b/x/foundation/client/testutil/tx.go @@ -44,8 +44,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdFundTreasury() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdFundTreasury() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -92,8 +90,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdWithdrawFromTreasury() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdWithdrawFromTreasury() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -138,8 +134,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdUpdateMembers() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdUpdateMembers() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -198,8 +192,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdUpdateDecisionPolicy() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdUpdateDecisionPolicy() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -249,8 +241,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdSubmitProposal() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdSubmitProposal() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -299,8 +289,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdWithdrawProposal() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdWithdrawProposal() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -353,8 +341,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdVote() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdVote() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -402,8 +388,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdExec() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdExec() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -466,8 +450,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdUpdateCensorship() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdUpdateCensorship() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -512,8 +494,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdLeaveFoundation() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdLeaveFoundation() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -565,8 +545,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdGrant() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdGrant() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -612,8 +590,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdRevoke() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdRevoke() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) diff --git a/x/foundation/genesis_test.go b/x/foundation/genesis_test.go index ba0807f6b6..6da5692ffa 100644 --- a/x/foundation/genesis_test.go +++ b/x/foundation/genesis_test.go @@ -407,8 +407,6 @@ func TestValidateGenesis(t *testing.T) { } for name, tc := range testCases { - tc := tc - t.Run(name, func(t *testing.T) { var unmarshalled foundation.GenesisState err := cdc.UnmarshalJSON(tc.raw, &unmarshalled) diff --git a/x/foundation/keeper/internal/keeper_test.go b/x/foundation/keeper/internal/keeper_test.go index 1b81a82a20..de255389b1 100644 --- a/x/foundation/keeper/internal/keeper_test.go +++ b/x/foundation/keeper/internal/keeper_test.go @@ -278,7 +278,6 @@ func TestNewKeeper(t *testing.T) { } for name, tc := range testCases { - tc := tc t.Run(name, func(t *testing.T) { newKeeper := func() keeper.Keeper { app := simapp.Setup(false) diff --git a/x/foundation/keeper/internal/proposal.go b/x/foundation/keeper/internal/proposal.go index 2003e83f07..0495f45769 100644 --- a/x/foundation/keeper/internal/proposal.go +++ b/x/foundation/keeper/internal/proposal.go @@ -180,8 +180,6 @@ func (k Keeper) UpdateTallyOfVPEndProposals(ctx sdk.Context) { }) for _, proposal := range proposals { - proposal := proposal - if proposal.Status == foundation.PROPOSAL_STATUS_ABORTED || proposal.Status == foundation.PROPOSAL_STATUS_WITHDRAWN { k.pruneProposal(ctx, proposal) continue diff --git a/x/foundation/msgs_test.go b/x/foundation/msgs_test.go index ff79d17620..4480243dfc 100644 --- a/x/foundation/msgs_test.go +++ b/x/foundation/msgs_test.go @@ -713,8 +713,6 @@ func TestAminoJSON(t *testing.T) { } for name, tc := range testCases { - tc := tc - t.Run(name, func(t *testing.T) { require.Equal(t, tc.expected, string(legacytx.StdSignBytes("foo", 1, 1, 1, legacytx.StdFee{}, []sdk.Msg{tc.msg}, "memo"))) }) @@ -778,8 +776,6 @@ func TestMsgSubmitProposalAminoJSON(t *testing.T) { } for name, tc := range testCases { - tc := tc - t.Run(name, func(t *testing.T) { proposalMsg := &foundation.MsgSubmitProposal{ Proposers: []string{proposer.String()}, @@ -824,8 +820,6 @@ func TestMsgUpdateDecisionPolicyAminoJson(t *testing.T) { } for name, tc := range testCases { - tc := tc - t.Run(name, func(t *testing.T) { policyMsg := &foundation.MsgUpdateDecisionPolicy{ Authority: authority.String(), @@ -867,8 +861,6 @@ func TestMsgGrantAminoJson(t *testing.T) { } for name, tc := range testCases { - tc := tc - t.Run(name, func(t *testing.T) { grantMsg := &foundation.MsgGrant{ Authority: operator.String(), diff --git a/x/fswap/client/testutil/grpc.go b/x/fswap/client/testutil/grpc.go index 74e81b200a..1443f03401 100644 --- a/x/fswap/client/testutil/grpc.go +++ b/x/fswap/client/testutil/grpc.go @@ -52,7 +52,6 @@ func (s *IntegrationTestSuite) TestGRPCQuerySwap() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := rest.GetRequest(tc.url) s.Require().NoError(err) @@ -91,7 +90,6 @@ func (s *IntegrationTestSuite) TestGRPCQuerySwaps() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := rest.GetRequest(tc.url) s.Require().NoError(err) @@ -148,7 +146,6 @@ func (s *IntegrationTestSuite) TestGRPCQuerySwapped() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := testutil.GetRequestWithHeaders(tc.url, map[string]string{ grpctypes.GRPCBlockHeightHeader: "1", @@ -206,7 +203,6 @@ func (s *IntegrationTestSuite) TestGRPCQueryTotalSwappableAmount() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := testutil.GetRequestWithHeaders(tc.url, map[string]string{ grpctypes.GRPCBlockHeightHeader: "1", diff --git a/x/fswap/client/testutil/query.go b/x/fswap/client/testutil/query.go index 4e4004f8b5..ff124613f4 100644 --- a/x/fswap/client/testutil/query.go +++ b/x/fswap/client/testutil/query.go @@ -55,8 +55,6 @@ func (s *IntegrationTestSuite) TestCmdQuerySwapped() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.CmdQuerySwapped() out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) @@ -117,8 +115,6 @@ func (s *IntegrationTestSuite) TestCmdQueryTotalSwappableAmount() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.CmdQueryTotalSwappableAmount() out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) @@ -179,8 +175,6 @@ func (s *IntegrationTestSuite) TestCmdQuerySwap() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.CmdQuerySwap() out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) @@ -227,8 +221,6 @@ func (s *IntegrationTestSuite) TestCmdQuerySwaps() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.CmdQuerySwaps() out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) diff --git a/x/fswap/client/testutil/tx.go b/x/fswap/client/testutil/tx.go index 31fd363446..73628fa037 100644 --- a/x/fswap/client/testutil/tx.go +++ b/x/fswap/client/testutil/tx.go @@ -74,8 +74,6 @@ func (s *IntegrationTestSuite) TestCmdTxMsgSwap() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.CmdTxMsgSwap() bz, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, append(tc.args, commonArgs...)) @@ -141,8 +139,6 @@ func (s *IntegrationTestSuite) TestCmdTxMsgSwapAll() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.CmdTxMsgSwapAll() bz, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, append(tc.args, commonArgs...)) @@ -279,8 +275,6 @@ func (s *IntegrationTestSuite) TestMsgSetSwap() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.CmdMsgSetSwap() bz, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, append(tc.args, commonArgs...)) diff --git a/x/fswap/types/msgs_test.go b/x/fswap/types/msgs_test.go index d6091af476..c4516e1ef0 100644 --- a/x/fswap/types/msgs_test.go +++ b/x/fswap/types/msgs_test.go @@ -77,7 +77,6 @@ func TestAminoJSON(t *testing.T) { } for name, tc := range testCase { - tc := tc t.Run(name, func(t *testing.T) { tx.Msgs = []sdk.Msg{tc.msg} require.Equal(t, fswaptypes.RouterKey, tc.msg.Route()) diff --git a/x/genutil/client/cli/init_test.go b/x/genutil/client/cli/init_test.go index 5cc05093a1..91059db031 100644 --- a/x/genutil/client/cli/init_test.go +++ b/x/genutil/client/cli/init_test.go @@ -53,7 +53,6 @@ func TestInitCmd(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { home := t.TempDir() logger := log.NewNopLogger() diff --git a/x/genutil/client/testutil/helpers.go b/x/genutil/client/testutil/helpers.go index 80d88dae25..3fcbafd11b 100644 --- a/x/genutil/client/testutil/helpers.go +++ b/x/genutil/client/testutil/helpers.go @@ -46,7 +46,7 @@ func CreateDefaultTendermintConfig(rootDir string) (*tmcfg.Config, error) { tmcfg.EnsureRoot(rootDir) if err := conf.ValidateBasic(); err != nil { - return nil, fmt.Errorf("error in config file: %v", err) + return nil, fmt.Errorf("error in config file: %w", err) } return conf, nil diff --git a/x/genutil/client/testutil/migrate.go b/x/genutil/client/testutil/migrate.go index 62a035ca54..9c84cf12c4 100644 --- a/x/genutil/client/testutil/migrate.go +++ b/x/genutil/client/testutil/migrate.go @@ -37,7 +37,6 @@ func (s *IntegrationTestSuite) TestMigrateGenesis() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { genesisFile := testutil.WriteToNewTempFile(s.T(), tc.genesis) jsonOutput, err := clitestutil.ExecTestCLICmd(val0.ClientCtx, cli.MigrateGenesisCmd(), []string{tc.target, genesisFile.Name()}) diff --git a/x/genutil/client/testutil/suite.go b/x/genutil/client/testutil/suite.go index 051820015d..14f668b105 100644 --- a/x/genutil/client/testutil/suite.go +++ b/x/genutil/client/testutil/suite.go @@ -96,8 +96,6 @@ func (s *IntegrationTestSuite) TestGenTxCmd() { } for _, tc := range tests { - tc := tc - dir := s.T().TempDir() genTxFile := filepath.Join(dir, "myTx") tc.args = append(tc.args, fmt.Sprintf("--%s=%s", flags.FlagOutputDocument, genTxFile)) diff --git a/x/genutil/client/testutil/validate_genesis.go b/x/genutil/client/testutil/validate_genesis.go index 32181a95db..73cedc9753 100644 --- a/x/genutil/client/testutil/validate_genesis.go +++ b/x/genutil/client/testutil/validate_genesis.go @@ -87,7 +87,6 @@ func (s *IntegrationTestSuite) TestValidateGenesis() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { genesisFile := testutil.WriteToNewTempFile(s.T(), tc.genesis) _, err := clitestutil.ExecTestCLICmd(val0.ClientCtx, cli.ValidateGenesisCmd(nil), []string{genesisFile.Name()}) diff --git a/x/genutil/utils_test.go b/x/genutil/utils_test.go index b406ed3e98..198bf70386 100644 --- a/x/genutil/utils_test.go +++ b/x/genutil/utils_test.go @@ -49,7 +49,6 @@ func TestInitializeNodeValidatorFilesFromMnemonic(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { _, _, err := InitializeNodeValidatorFilesFromMnemonic(cfg, tt.mnemonic) diff --git a/x/gov/client/cli/query.go b/x/gov/client/cli/query.go index 252f7a3aa4..e789aa9e2b 100644 --- a/x/gov/client/cli/query.go +++ b/x/gov/client/cli/query.go @@ -214,7 +214,7 @@ $ %s query gov vote 1 link1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk &types.QueryProposalRequest{ProposalId: proposalID}, ) if err != nil { - return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err) + return fmt.Errorf("failed to fetch proposal-id %d: %w", proposalID, err) } voterAddr, err := sdk.AccAddressFromBech32(args[1]) @@ -288,7 +288,7 @@ $ %[1]s query gov votes 1 --page=2 --limit=100 &types.QueryProposalRequest{ProposalId: proposalID}, ) if err != nil { - return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err) + return fmt.Errorf("failed to fetch proposal-id %d: %w", proposalID, err) } propStatus := proposalRes.GetProposal().Status @@ -369,7 +369,7 @@ $ %s query gov deposit 1 link1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk &types.QueryProposalRequest{ProposalId: proposalID}, ) if err != nil { - return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err) + return fmt.Errorf("failed to fetch proposal-id %d: %w", proposalID, err) } depositorAddr, err := sdk.AccAddressFromBech32(args[1]) @@ -442,7 +442,7 @@ $ %s query gov deposits 1 &types.QueryProposalRequest{ProposalId: proposalID}, ) if err != nil { - return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err) + return fmt.Errorf("failed to fetch proposal-id %d: %w", proposalID, err) } propStatus := proposalRes.GetProposal().Status @@ -520,7 +520,7 @@ $ %s query gov tally 1 &types.QueryProposalRequest{ProposalId: proposalID}, ) if err != nil { - return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err) + return fmt.Errorf("failed to fetch proposal-id %d: %w", proposalID, err) } // Query store diff --git a/x/gov/client/testutil/grpc.go b/x/gov/client/testutil/grpc.go index e97273afdf..e421b48126 100644 --- a/x/gov/client/testutil/grpc.go +++ b/x/gov/client/testutil/grpc.go @@ -38,7 +38,6 @@ func (s *IntegrationTestSuite) TestGetProposalGRPC() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := rest.GetRequest(tc.url) s.Require().NoError(err) @@ -92,7 +91,6 @@ func (s *IntegrationTestSuite) TestGetProposalsGRPC() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers) s.Require().NoError(err) @@ -159,7 +157,6 @@ func (s *IntegrationTestSuite) TestGetProposalVoteGRPC() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := rest.GetRequest(tc.url) s.Require().NoError(err) @@ -203,7 +200,6 @@ func (s *IntegrationTestSuite) TestGetProposalVotesGRPC() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := rest.GetRequest(tc.url) s.Require().NoError(err) @@ -252,7 +248,6 @@ func (s *IntegrationTestSuite) TestGetProposalDepositGRPC() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := rest.GetRequest(tc.url) s.Require().NoError(err) @@ -291,7 +286,6 @@ func (s *IntegrationTestSuite) TestGetProposalDepositsGRPC() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := rest.GetRequest(tc.url) s.Require().NoError(err) @@ -336,7 +330,6 @@ func (s *IntegrationTestSuite) TestGetTallyGRPC() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := rest.GetRequest(tc.url) s.Require().NoError(err) @@ -399,7 +392,6 @@ func (s *IntegrationTestSuite) TestGetParamsGRPC() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := rest.GetRequest(tc.url) s.Require().NoError(err) diff --git a/x/gov/client/testutil/suite.go b/x/gov/client/testutil/suite.go index b9be407318..0ff0055da4 100644 --- a/x/gov/client/testutil/suite.go +++ b/x/gov/client/testutil/suite.go @@ -108,8 +108,6 @@ voting_params: } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryParams() clientCtx := val.ClientCtx @@ -156,8 +154,6 @@ func (s *IntegrationTestSuite) TestCmdParam() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryParam() clientCtx := val.ClientCtx @@ -198,8 +194,6 @@ func (s *IntegrationTestSuite) TestCmdProposer() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryProposer() clientCtx := val.ClientCtx @@ -253,8 +247,6 @@ func (s *IntegrationTestSuite) TestCmdTally() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryTally() clientCtx := val.ClientCtx @@ -344,8 +336,6 @@ func (s *IntegrationTestSuite) TestNewCmdSubmitProposal() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.NewCmdSubmitProposal() clientCtx := val.ClientCtx @@ -392,8 +382,6 @@ func (s *IntegrationTestSuite) TestCmdGetProposal() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryProposal() clientCtx := val.ClientCtx @@ -445,8 +433,6 @@ func (s *IntegrationTestSuite) TestCmdGetProposals() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryProposals() clientCtx := val.ClientCtx @@ -491,7 +477,6 @@ func (s *IntegrationTestSuite) TestCmdQueryDeposits() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryDeposits() clientCtx := val.ClientCtx @@ -547,7 +532,6 @@ func (s *IntegrationTestSuite) TestCmdQueryDeposit() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryDeposit() clientCtx := val.ClientCtx @@ -625,7 +609,6 @@ func (s *IntegrationTestSuite) TestNewCmdDeposit() { } for _, tc := range testCases { - tc := tc var resp sdk.TxResponse s.Run(tc.name, func() { @@ -676,7 +659,6 @@ func (s *IntegrationTestSuite) TestCmdQueryVotes() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryVotes() clientCtx := val.ClientCtx @@ -751,7 +733,6 @@ func (s *IntegrationTestSuite) TestCmdQueryVote() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryVote() clientCtx := val.ClientCtx @@ -816,7 +797,6 @@ func (s *IntegrationTestSuite) TestNewCmdVote() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.NewCmdVote() clientCtx := val.ClientCtx @@ -900,7 +880,6 @@ func (s *IntegrationTestSuite) TestNewCmdWeightedVote() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.NewCmdWeightedVote() clientCtx := val.ClientCtx diff --git a/x/gov/client/utils/query_test.go b/x/gov/client/utils/query_test.go index 8510ee48de..09f8d582e6 100644 --- a/x/gov/client/utils/query_test.go +++ b/x/gov/client/utils/query_test.go @@ -160,8 +160,6 @@ func TestGetPaginatedVotes(t *testing.T) { }, }, } { - tc := tc - t.Run(tc.description, func(t *testing.T) { marshaled := make([]tmtypes.Tx, len(tc.msgs)) cli := TxSearchMock{txs: marshaled, txConfig: encCfg.TxConfig} diff --git a/x/gov/genesis_test.go b/x/gov/genesis_test.go index 9564284dee..d4484baf2f 100644 --- a/x/gov/genesis_test.go +++ b/x/gov/genesis_test.go @@ -104,7 +104,7 @@ func TestImportExportQueues(t *testing.T) { // Run the endblocker. Check to make sure that proposal1 is removed from state, and proposal2 is finished VotingPeriod. gov.EndBlocker(ctx2, app2.GovKeeper) - proposal1, ok = app2.GovKeeper.GetProposal(ctx2, proposalID1) + _, ok = app2.GovKeeper.GetProposal(ctx2, proposalID1) require.False(t, ok) proposal2, ok = app2.GovKeeper.GetProposal(ctx2, proposalID2) diff --git a/x/gov/keeper/deposit_test.go b/x/gov/keeper/deposit_test.go index 65cf29e116..df26ab6fb9 100644 --- a/x/gov/keeper/deposit_test.go +++ b/x/gov/keeper/deposit_test.go @@ -96,7 +96,7 @@ func TestDeposits(t *testing.T) { require.True(t, found) require.Equal(t, fourStake, deposit.Amount) app.GovKeeper.RefundDeposits(ctx, proposalID) - deposit, found = app.GovKeeper.GetDeposit(ctx, proposalID, TestAddrs[1]) + _, found = app.GovKeeper.GetDeposit(ctx, proposalID, TestAddrs[1]) require.False(t, found) require.Equal(t, addr0Initial, app.BankKeeper.GetAllBalances(ctx, TestAddrs[0])) require.Equal(t, addr1Initial, app.BankKeeper.GetAllBalances(ctx, TestAddrs[1])) diff --git a/x/gov/keeper/querier_test.go b/x/gov/keeper/querier_test.go index 3debd3da85..befef0d18f 100644 --- a/x/gov/keeper/querier_test.go +++ b/x/gov/keeper/querier_test.go @@ -380,7 +380,6 @@ func TestPaginatedVotesQuery(t *testing.T) { page: -1, }, } { - tc := tc t.Run(tc.description, func(t *testing.T) { votes := getQueriedVotes(t, ctx, legacyQuerierCdc, querier, proposal.ProposalId, tc.page, tc.limit) require.Equal(t, len(tc.votes), len(votes)) diff --git a/x/gov/legacy/v043/store_test.go b/x/gov/legacy/v043/store_test.go index 6f7f0c9876..a9bbe4368c 100644 --- a/x/gov/legacy/v043/store_test.go +++ b/x/gov/legacy/v043/store_test.go @@ -80,7 +80,6 @@ func TestMigrateStore(t *testing.T) { // Make sure the new keys are set and old keys are deleted. for _, tc := range testCases { - tc := tc t.Run(tc.name, func(t *testing.T) { if !bytes.Equal(tc.oldKey, tc.newKey) { require.Nil(t, store.Get(tc.oldKey)) diff --git a/x/gov/simulation/decoder_test.go b/x/gov/simulation/decoder_test.go index 049e0f4a6f..2629b5409b 100644 --- a/x/gov/simulation/decoder_test.go +++ b/x/gov/simulation/decoder_test.go @@ -81,7 +81,6 @@ func TestDecodeStore(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { if tt.wantPanic { require.Panics(t, func() { dec(tt.kvA, tt.kvB) }, tt.name) diff --git a/x/gov/simulation/genesis_test.go b/x/gov/simulation/genesis_test.go index 2e0fc7217f..5602c79b5f 100644 --- a/x/gov/simulation/genesis_test.go +++ b/x/gov/simulation/genesis_test.go @@ -79,8 +79,6 @@ func TestRandomizedGenState1(t *testing.T) { } for _, tt := range tests { - tt := tt - require.Panicsf(t, func() { simulation.RandomizedGenState(&tt.simState) }, tt.panicMsg) } } diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index 6ba9e985f3..bde953d6f2 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -58,7 +58,6 @@ func WeightedOperations( var wProposalOps simulation.WeightedOperations for _, wContent := range wContents { - wContent := wContent // pin variable var weight int appParams.GetOrGenerate(cdc, wContent.AppParamsKey(), &weight, nil, func(_ *rand.Rand) { weight = wContent.DefaultWeight() }) diff --git a/x/gov/types/proposal.go b/x/gov/types/proposal.go index 2104ef6842..2fe7840537 100644 --- a/x/gov/types/proposal.go +++ b/x/gov/types/proposal.go @@ -168,12 +168,18 @@ func (status *ProposalStatus) Unmarshal(data []byte) error { // Format implements the fmt.Formatter interface. func (status ProposalStatus) Format(s fmt.State, verb rune) { + var err error + switch verb { case 's': - s.Write([]byte(status.String())) + _, err = s.Write([]byte(status.String())) default: // TODO: Do this conversion more directly - s.Write([]byte(fmt.Sprintf("%v", byte(status)))) + _, err = s.Write([]byte(fmt.Sprintf("%v", byte(status)))) + } + + if err != nil { + panic(err) } } diff --git a/x/gov/types/vote.go b/x/gov/types/vote.go index ba2c6e6972..e722bced7b 100644 --- a/x/gov/types/vote.go +++ b/x/gov/types/vote.go @@ -62,7 +62,10 @@ func NewNonSplitVoteOption(option VoteOption) WeightedVoteOptions { } func (v WeightedVoteOption) String() string { - out, _ := json.Marshal(v) + out, err := json.Marshal(v) + if err != nil { + panic(err) + } return string(out) } @@ -141,10 +144,16 @@ func (vo *VoteOption) Unmarshal(data []byte) error { // Format implements the fmt.Formatter interface. func (vo VoteOption) Format(s fmt.State, verb rune) { + var err error + switch verb { case 's': - s.Write([]byte(vo.String())) + _, err = s.Write([]byte(vo.String())) default: - s.Write([]byte(fmt.Sprintf("%v", byte(vo)))) + _, err = s.Write([]byte(fmt.Sprintf("%v", byte(vo)))) + } + + if err != nil { + panic(err) } } diff --git a/x/mint/client/testutil/grpc.go b/x/mint/client/testutil/grpc.go index aa3cf59c51..52ead8c536 100644 --- a/x/mint/client/testutil/grpc.go +++ b/x/mint/client/testutil/grpc.go @@ -53,7 +53,6 @@ func (s *IntegrationTestSuite) TestQueryGRPC() { }, } for _, tc := range testCases { - tc := tc resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers) s.Run(tc.name, func() { s.Require().NoError(err) diff --git a/x/mint/client/testutil/suite.go b/x/mint/client/testutil/suite.go index a8a78637dd..9e7b6c21bb 100644 --- a/x/mint/client/testutil/suite.go +++ b/x/mint/client/testutil/suite.go @@ -81,8 +81,6 @@ mint_denom: stake`, } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryParams() clientCtx := val.ClientCtx @@ -115,8 +113,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryInflation() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryInflation() clientCtx := val.ClientCtx @@ -149,8 +145,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryAnnualProvisions() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryAnnualProvisions() clientCtx := val.ClientCtx diff --git a/x/mint/simulation/decoder_test.go b/x/mint/simulation/decoder_test.go index 8fb33000db..790313a374 100644 --- a/x/mint/simulation/decoder_test.go +++ b/x/mint/simulation/decoder_test.go @@ -34,7 +34,6 @@ func TestDecodeStore(t *testing.T) { } for i, tt := range tests { - i, tt := i, tt t.Run(tt.name, func(t *testing.T) { switch i { case len(tests) - 1: diff --git a/x/mint/simulation/genesis_test.go b/x/mint/simulation/genesis_test.go index 621426ad80..84101358c4 100644 --- a/x/mint/simulation/genesis_test.go +++ b/x/mint/simulation/genesis_test.go @@ -79,8 +79,6 @@ func TestRandomizedGenState1(t *testing.T) { } for _, tt := range tests { - tt := tt - require.Panicsf(t, func() { simulation.RandomizedGenState(&tt.simState) }, tt.panicMsg) } } diff --git a/x/params/client/testutil/grpc.go b/x/params/client/testutil/grpc.go index 64cde94976..9f00b3921c 100644 --- a/x/params/client/testutil/grpc.go +++ b/x/params/client/testutil/grpc.go @@ -80,7 +80,6 @@ func (s *IntegrationTestSuite) TestQueryParamsGRPC() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers) s.Require().NoError(err) diff --git a/x/params/client/testutil/suite.go b/x/params/client/testutil/suite.go index 74953d16b2..45558544f5 100644 --- a/x/params/client/testutil/suite.go +++ b/x/params/client/testutil/suite.go @@ -66,8 +66,6 @@ value: "100"`, } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.NewQuerySubspaceParamsCmd() clientCtx := val.ClientCtx diff --git a/x/params/keeper/keeper_test.go b/x/params/keeper/keeper_test.go index c4ae41351f..6285d5fb1a 100644 --- a/x/params/keeper/keeper_test.go +++ b/x/params/keeper/keeper_test.go @@ -83,13 +83,11 @@ func TestKeeper(t *testing.T) { // Set params for i, kv := range kvs { - kv := kv require.NotPanics(t, func() { space.Set(ctx, []byte(kv.key), kv.param) }, "space.Set panics, tc #%d", i) } // Test space.Get for i, kv := range kvs { - i, kv := i, kv var param int64 require.NotPanics(t, func() { space.Get(ctx, []byte(kv.key), ¶m) }, "space.Get panics, tc #%d", i) require.Equal(t, kv.param, param, "stored param not equal, tc #%d", i) @@ -116,20 +114,17 @@ func TestKeeper(t *testing.T) { // Test invalid space.Get for i, kv := range kvs { - kv := kv var param bool require.Panics(t, func() { space.Get(ctx, []byte(kv.key), ¶m) }, "invalid space.Get not panics, tc #%d", i) } // Test invalid space.Set for i, kv := range kvs { - kv := kv require.Panics(t, func() { space.Set(ctx, []byte(kv.key), true) }, "invalid space.Set not panics, tc #%d", i) } // Test GetSubspace for i, kv := range kvs { - i, kv := i, kv var gparam, param int64 gspace, ok := keeper.GetSubspace("test") require.True(t, ok, "cannot retrieve subspace, tc #%d", i) @@ -191,13 +186,11 @@ func TestSubspace(t *testing.T) { // Test space.Set for i, kv := range kvs { - i, kv := i, kv require.NotPanics(t, func() { space.Set(ctx, []byte(kv.key), kv.param) }, "space.Set panics, tc #%d", i) } // Test space.Get, space.GetIfExists for i, kv := range kvs { - i, kv := i, kv require.NotPanics(t, func() { space.GetIfExists(ctx, []byte("invalid"), kv.ptr) }, "space.GetIfExists panics when no value exists, tc #%d", i) require.Equal(t, kv.zero, indirect(kv.ptr), "space.GetIfExists unmarshalls when no value exists, tc #%d", i) require.Panics(t, func() { space.Get(ctx, []byte("invalid"), kv.ptr) }, "invalid space.Get not panics when no value exists, tc #%d", i) diff --git a/x/params/proposal_handler_test.go b/x/params/proposal_handler_test.go index 81f42547e2..9162fea2f3 100644 --- a/x/params/proposal_handler_test.go +++ b/x/params/proposal_handler_test.go @@ -77,7 +77,6 @@ func (suite *HandlerTestSuite) TestProposalHandler() { } for _, tc := range testCases { - tc := tc suite.Run(tc.name, func() { err := suite.govHandler(suite.ctx, tc.proposal) if tc.expErr { diff --git a/x/params/types/subspace.go b/x/params/types/subspace.go index 12bc0c2355..3e974ad3e2 100644 --- a/x/params/types/subspace.go +++ b/x/params/types/subspace.go @@ -82,7 +82,7 @@ func (s Subspace) Validate(ctx sdk.Context, key []byte, value interface{}) error } if err := attr.vfn(value); err != nil { - return fmt.Errorf("invalid parameter value: %s", err) + return fmt.Errorf("invalid parameter value: %w", err) } return nil diff --git a/x/params/types/subspace_test.go b/x/params/types/subspace_test.go index 1882f47b58..887246afa3 100644 --- a/x/params/types/subspace_test.go +++ b/x/params/types/subspace_test.go @@ -184,7 +184,6 @@ func (suite *SubspaceTestSuite) TestSetParamSet() { } for _, tc := range testCases { - tc := tc suite.Run(tc.name, func() { suite.Require().Panics(func() { suite.ss.SetParamSet(suite.ctx, tc.ps) diff --git a/x/simulation/operation.go b/x/simulation/operation.go index 82547c3891..433518f3dd 100644 --- a/x/simulation/operation.go +++ b/x/simulation/operation.go @@ -79,7 +79,6 @@ func queueOperations(queuedOps OperationQueue, queuedTimeOps, futureOps []simula } for _, futureOp := range futureOps { - futureOp := futureOp if futureOp.BlockHeight != 0 { if val, ok := queuedOps[futureOp.BlockHeight]; ok { queuedOps[futureOp.BlockHeight] = append(val, futureOp.Op) diff --git a/x/slashing/client/testutil/grpc.go b/x/slashing/client/testutil/grpc.go index a56583e355..245b4023b8 100644 --- a/x/slashing/client/testutil/grpc.go +++ b/x/slashing/client/testutil/grpc.go @@ -83,8 +83,6 @@ func (s *IntegrationTestSuite) TestGRPCQueries() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers) s.Require().NoError(err) diff --git a/x/slashing/client/testutil/suite.go b/x/slashing/client/testutil/suite.go index 718e84e5a7..885ee616ad 100644 --- a/x/slashing/client/testutil/suite.go +++ b/x/slashing/client/testutil/suite.go @@ -85,8 +85,6 @@ tombstoned: false`, sdk.ConsAddress(val.PubKey.Address())), } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQuerySigningInfo() clientCtx := val.ClientCtx @@ -127,8 +125,6 @@ slash_fraction_downtime: "0.010000000000000000"`, } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryParams() clientCtx := val.ClientCtx @@ -162,8 +158,6 @@ func (s *IntegrationTestSuite) TestNewUnjailTxCmd() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.NewUnjailTxCmd() clientCtx := val.ClientCtx diff --git a/x/slashing/legacy/v043/store_test.go b/x/slashing/legacy/v043/store_test.go index 69df9372c1..318bc16bd5 100644 --- a/x/slashing/legacy/v043/store_test.go +++ b/x/slashing/legacy/v043/store_test.go @@ -57,7 +57,6 @@ func TestStoreMigration(t *testing.T) { // Make sure the new keys are set and old keys are deleted. for _, tc := range testCases { - tc := tc t.Run(tc.name, func(t *testing.T) { if !bytes.Equal(tc.oldKey, tc.newKey) { require.Nil(t, store.Get(tc.oldKey)) diff --git a/x/slashing/simulation/decoder_test.go b/x/slashing/simulation/decoder_test.go index 9d5794a590..892fda56d8 100644 --- a/x/slashing/simulation/decoder_test.go +++ b/x/slashing/simulation/decoder_test.go @@ -53,7 +53,6 @@ func TestDecodeStore(t *testing.T) { {"other", "", true}, } for i, tt := range tests { - i, tt := i, tt t.Run(tt.name, func(t *testing.T) { if tt.panics { require.Panics(t, func() { dec(kvPairs.Pairs[i], kvPairs.Pairs[i]) }, tt.name) diff --git a/x/slashing/simulation/genesis_test.go b/x/slashing/simulation/genesis_test.go index e63bc3c14c..c5d3615b94 100644 --- a/x/slashing/simulation/genesis_test.go +++ b/x/slashing/simulation/genesis_test.go @@ -78,8 +78,6 @@ func TestRandomizedGenState1(t *testing.T) { } for _, tt := range tests { - tt := tt - require.Panicsf(t, func() { simulation.RandomizedGenState(&tt.simState) }, tt.panicMsg) } } diff --git a/x/staking/client/cli/query.go b/x/staking/client/cli/query.go index 3638881217..eb7c35c894 100644 --- a/x/staking/client/cli/query.go +++ b/x/staking/client/cli/query.go @@ -655,7 +655,7 @@ $ %s query staking historical-info 5 height, err := strconv.ParseInt(args[0], 10, 64) if err != nil || height < 0 { - return fmt.Errorf("height argument provided must be a non-negative-integer: %v", err) + return fmt.Errorf("height argument provided must be a non-negative-integer: %w", err) } params := &types.QueryHistoricalInfoRequest{Height: height} diff --git a/x/staking/client/cli/tx.go b/x/staking/client/cli/tx.go index 994adcb740..64a693de93 100644 --- a/x/staking/client/cli/tx.go +++ b/x/staking/client/cli/tx.go @@ -111,7 +111,7 @@ func NewEditValidatorCmd() *cobra.Command { if commissionRate != "" { rate, err := sdk.NewDecFromStr(commissionRate) if err != nil { - return fmt.Errorf("invalid new commission rate: %v", err) + return fmt.Errorf("invalid new commission rate: %w", err) } newRate = &rate diff --git a/x/staking/client/cli/tx_test.go b/x/staking/client/cli/tx_test.go index e326e4490b..9153d126d5 100644 --- a/x/staking/client/cli/tx_test.go +++ b/x/staking/client/cli/tx_test.go @@ -85,7 +85,6 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) { } for _, tc := range tests { - tc := tc t.Run(tc.name, func(t *testing.T) { fs, _ := CreateValidatorMsgFlagSet(ip) fs.String(flags.FlagName, "", "name of private key with which to sign the gentx") diff --git a/x/staking/client/testutil/grpc.go b/x/staking/client/testutil/grpc.go index 690443ffa7..03062377c8 100644 --- a/x/staking/client/testutil/grpc.go +++ b/x/staking/client/testutil/grpc.go @@ -43,7 +43,6 @@ func (s *IntegrationTestSuite) TestGRPCQueryValidatorsHandler() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := rest.GetRequest(tc.url) s.Require().NoError(err) @@ -91,7 +90,6 @@ func (s *IntegrationTestSuite) TestGRPCQueryValidator() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := rest.GetRequest(tc.url) s.Require().NoError(err) @@ -156,7 +154,6 @@ func (s *IntegrationTestSuite) TestGRPCQueryValidatorDelegations() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers) s.Require().NoError(err) @@ -200,7 +197,6 @@ func (s *IntegrationTestSuite) TestGRPCQueryValidatorUnbondingDelegations() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := rest.GetRequest(tc.url) s.Require().NoError(err) @@ -279,7 +275,6 @@ func (s *IntegrationTestSuite) TestGRPCQueryDelegation() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := rest.GetRequest(tc.url) s.Require().NoError(err) @@ -333,7 +328,6 @@ func (s *IntegrationTestSuite) TestGRPCQueryUnbondingDelegation() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := rest.GetRequest(tc.url) s.Require().NoError(err) @@ -418,7 +412,6 @@ func (s *IntegrationTestSuite) TestGRPCQueryDelegatorDelegations() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers) s.Require().NoError(err) @@ -466,7 +459,6 @@ func (s *IntegrationTestSuite) TestGRPCQueryDelegatorUnbondingDelegations() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := rest.GetRequest(tc.url) s.Require().NoError(err) @@ -528,7 +520,6 @@ func (s *IntegrationTestSuite) TestGRPCQueryRedelegations() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := rest.GetRequest(tc.url) s.Require().NoError(err) @@ -577,7 +568,6 @@ func (s *IntegrationTestSuite) TestGRPCQueryDelegatorValidators() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := rest.GetRequest(tc.url) s.Require().NoError(err) @@ -634,7 +624,6 @@ func (s *IntegrationTestSuite) TestGRPCQueryDelegatorValidator() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := rest.GetRequest(tc.url) s.Require().NoError(err) @@ -680,7 +669,6 @@ func (s *IntegrationTestSuite) TestGRPCQueryHistoricalInfo() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { resp, err := rest.GetRequest(tc.url) s.Require().NoError(err) @@ -720,7 +708,6 @@ func (s *IntegrationTestSuite) TestGRPCQueryParams() { } for _, tc := range testCases { - tc := tc resp, err := rest.GetRequest(tc.url) s.Run(tc.name, func() { s.Require().NoError(err) @@ -758,7 +745,6 @@ func (s *IntegrationTestSuite) TestGRPCQueryPool() { } for _, tc := range testCases { - tc := tc resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers) s.Run(tc.name, func() { s.Require().NoError(err) diff --git a/x/staking/client/testutil/suite.go b/x/staking/client/testutil/suite.go index 3109c95bf9..353a55dd30 100644 --- a/x/staking/client/testutil/suite.go +++ b/x/staking/client/testutil/suite.go @@ -189,8 +189,6 @@ func (s *IntegrationTestSuite) TestNewCreateValidatorCmd() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.NewCreateValidatorCmd() clientCtx := val.ClientCtx @@ -244,7 +242,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidator() { }, } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryValidator() clientCtx := val.ClientCtx @@ -285,8 +282,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidators() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryValidators() clientCtx := val.ClientCtx @@ -351,7 +346,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDelegation() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryDelegation() clientCtx := val.ClientCtx @@ -407,7 +401,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDelegations() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryDelegations() clientCtx := val.ClientCtx @@ -463,7 +456,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorDelegations() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryDelegations() clientCtx := val.ClientCtx @@ -507,7 +499,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryUnbondingDelegations() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryUnbondingDelegations() clientCtx := val.ClientCtx @@ -566,7 +557,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryUnbondingDelegation() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryUnbondingDelegation() clientCtx := val.ClientCtx @@ -615,7 +605,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorUnbondingDelegations() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryValidatorUnbondingDelegations() clientCtx := val.ClientCtx @@ -664,7 +653,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryRedelegations() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryRedelegations() clientCtx := val.ClientCtx @@ -740,7 +728,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryRedelegation() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryRedelegation() clientCtx := val.ClientCtx @@ -792,7 +779,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorRedelegations() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryValidatorRedelegations() clientCtx := val.ClientCtx @@ -843,7 +829,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryHistoricalInfo() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryHistoricalInfo() clientCtx := val.ClientCtx @@ -885,7 +870,6 @@ unbonding_time: 1814400s`, }, } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryParams() clientCtx := val.ClientCtx @@ -922,7 +906,6 @@ not_bonded_tokens: "0"`, cli.DefaultTokens.Mul(sdk.NewInt(2)).String()), }, } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryPool() clientCtx := val.ClientCtx @@ -1029,8 +1012,6 @@ func (s *IntegrationTestSuite) TestNewEditValidatorCmd() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.NewEditValidatorCmd() clientCtx := val.ClientCtx @@ -1111,8 +1092,6 @@ func (s *IntegrationTestSuite) TestNewDelegateCmd() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.NewDelegateCmd() clientCtx := val.ClientCtx @@ -1197,8 +1176,6 @@ func (s *IntegrationTestSuite) TestNewRedelegateCmd() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.NewRedelegateCmd() clientCtx := val.ClientCtx @@ -1264,8 +1241,6 @@ func (s *IntegrationTestSuite) TestNewUnbondCmd() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.NewUnbondCmd() clientCtx := val.ClientCtx diff --git a/x/staking/genesis_test.go b/x/staking/genesis_test.go index c61257a448..afcf3db100 100644 --- a/x/staking/genesis_test.go +++ b/x/staking/genesis_test.go @@ -230,7 +230,6 @@ func TestValidateGenesis(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { genesisState := types.DefaultGenesisState() tt.mutate(genesisState) diff --git a/x/staking/handler_test.go b/x/staking/handler_test.go index a969caf040..993c4d9b4f 100644 --- a/x/staking/handler_test.go +++ b/x/staking/handler_test.go @@ -893,7 +893,7 @@ func TestMultipleRedelegationAtSameTime(t *testing.T) { // move forward in time, should complete both redelegations ctx = tstaking.TurnBlockTimeDiff(1 * time.Second) - rd, found = app.StakingKeeper.GetRedelegation(ctx, selfDelAddr, valAddr, valAddr2) + _, found = app.StakingKeeper.GetRedelegation(ctx, selfDelAddr, valAddr, valAddr2) require.False(t, found) } @@ -940,7 +940,7 @@ func TestMultipleRedelegationAtUniqueTimes(t *testing.T) { // move forward in time, should complete the second redelegation ctx = tstaking.TurnBlockTimeDiff(5 * time.Second) - rd, found = app.StakingKeeper.GetRedelegation(ctx, selfDelAddr, valAddr, valAddr2) + _, found = app.StakingKeeper.GetRedelegation(ctx, selfDelAddr, valAddr, valAddr2) require.False(t, found) } @@ -980,7 +980,7 @@ func TestMultipleUnbondingDelegationAtSameTime(t *testing.T) { // move forwaubd in time, should complete both ubds ctx = tstaking.TurnBlockTimeDiff(1 * time.Second) - ubd, found = app.StakingKeeper.GetUnbondingDelegation(ctx, selfDelAddr, valAddr) + _, found = app.StakingKeeper.GetUnbondingDelegation(ctx, selfDelAddr, valAddr) require.False(t, found) } @@ -1028,7 +1028,7 @@ func TestMultipleUnbondingDelegationAtUniqueTimes(t *testing.T) { // move forwaubd in time, should complete the second redelegation ctx = tstaking.TurnBlockTimeDiff(5 * time.Second) - ubd, found = app.StakingKeeper.GetUnbondingDelegation(ctx, selfDelAddr, valAddr) + _, found = app.StakingKeeper.GetUnbondingDelegation(ctx, selfDelAddr, valAddr) require.False(t, found) } diff --git a/x/staking/keeper/delegation_test.go b/x/staking/keeper/delegation_test.go index ca609e9c11..f81fa3d399 100644 --- a/x/staking/keeper/delegation_test.go +++ b/x/staking/keeper/delegation_test.go @@ -350,7 +350,7 @@ func TestUndelegateSelfDelegationBelowMinSelfDelegation(t *testing.T) { require.NoError(t, simapp.FundModuleAccount(app, ctx, bondedPool.GetName(), delCoins)) app.AccountKeeper.SetModuleAccount(ctx, bondedPool) - validator = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validator, true) + _ = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validator, true) delegation := types.NewDelegation(addrDels[0], addrVals[0], issuedShares) app.StakingKeeper.SetDelegation(ctx, delegation) diff --git a/x/staking/keeper/slash.go b/x/staking/keeper/slash.go index 904c9c5898..b4b5b229b5 100644 --- a/x/staking/keeper/slash.go +++ b/x/staking/keeper/slash.go @@ -310,7 +310,7 @@ func (k Keeper) SlashRedelegation(ctx sdk.Context, srcValidator types.Validator, tokensToBurn, err := k.Unbond(ctx, delegatorAddress, valDstAddr, sharesToUnbond) if err != nil { - panic(fmt.Errorf("error unbonding delegator: %v", err)) + panic(fmt.Errorf("error unbonding delegator: %w", err)) } dstValidator, found := k.GetValidator(ctx, valDstAddr) diff --git a/x/staking/legacy/v043/store_test.go b/x/staking/legacy/v043/store_test.go index cbc917103d..bad5fba9ba 100644 --- a/x/staking/legacy/v043/store_test.go +++ b/x/staking/legacy/v043/store_test.go @@ -127,7 +127,6 @@ func TestStoreMigration(t *testing.T) { // Make sure the new keys are set and old keys are deleted. for _, tc := range testCases { - tc := tc t.Run(tc.name, func(t *testing.T) { if !bytes.Equal(tc.oldKey, tc.newKey) { require.Nil(t, store.Get(tc.oldKey)) diff --git a/x/staking/simulation/decoder_test.go b/x/staking/simulation/decoder_test.go index cc4a936deb..bc486e7c88 100644 --- a/x/staking/simulation/decoder_test.go +++ b/x/staking/simulation/decoder_test.go @@ -57,7 +57,6 @@ func TestDecodeStore(t *testing.T) { {"other", ""}, } for i, tt := range tests { - i, tt := i, tt t.Run(tt.name, func(t *testing.T) { switch i { case len(tests) - 1: diff --git a/x/staking/simulation/genesis_test.go b/x/staking/simulation/genesis_test.go index 40ea16a9a2..c80a3a8a9d 100644 --- a/x/staking/simulation/genesis_test.go +++ b/x/staking/simulation/genesis_test.go @@ -101,8 +101,6 @@ func TestRandomizedGenState1(t *testing.T) { } for _, tt := range tests { - tt := tt - require.Panicsf(t, func() { simulation.RandomizedGenState(&tt.simState) }, tt.panicMsg) } } diff --git a/x/staking/types/authz_test.go b/x/staking/types/authz_test.go index a722adf6f6..1063dce831 100644 --- a/x/staking/types/authz_test.go +++ b/x/staking/types/authz_test.go @@ -267,7 +267,6 @@ func TestAuthzAuthorizations(t *testing.T) { } for _, tc := range testCases { - tc := tc t.Run(tc.msg, func(t *testing.T) { delAuth, err := stakingtypes.NewStakeAuthorization(tc.allowed, tc.denied, tc.msgType, tc.limit) require.NoError(t, err) diff --git a/x/staking/types/msg_test.go b/x/staking/types/msg_test.go index 328c0b4102..9929819d6b 100644 --- a/x/staking/types/msg_test.go +++ b/x/staking/types/msg_test.go @@ -105,8 +105,6 @@ func TestMsgEditValidator(t *testing.T) { } for _, tc := range tests { - tc := tc - description := types.NewDescription(tc.moniker, tc.identity, tc.website, tc.securityContact, tc.details) newRate := sdk.ZeroDec() diff --git a/x/token/client/testutil/query.go b/x/token/client/testutil/query.go index e8ba981d8a..df87b16d6b 100644 --- a/x/token/client/testutil/query.go +++ b/x/token/client/testutil/query.go @@ -62,8 +62,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdBalance() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdBalance() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -117,8 +115,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdToken() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdContract() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -192,8 +188,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdGranteeGrants() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdGranteeGrants() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -254,8 +248,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdIsOperatorFor() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdIsOperatorFor() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -314,8 +306,6 @@ func (s *IntegrationTestSuite) TestNewQueryCmdHoldersByOperator() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewQueryCmdHoldersByOperator() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) diff --git a/x/token/client/testutil/tx.go b/x/token/client/testutil/tx.go index e3e6746321..662606d97a 100644 --- a/x/token/client/testutil/tx.go +++ b/x/token/client/testutil/tx.go @@ -62,8 +62,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdSend() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdSend() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -136,8 +134,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdOperatorSend() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdOperatorSend() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -194,8 +190,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdAuthorizeOperator() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdAuthorizeOperator() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -252,8 +246,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdRevokeOperator() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdRevokeOperator() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -318,8 +310,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdIssue() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdIssue() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -379,8 +369,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdGrantPermission() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdGrantPermission() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -437,8 +425,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdRevokePermission() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdRevokePermission() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -498,8 +484,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdMint() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdMint() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -556,8 +540,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdBurn() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdBurn() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -617,8 +599,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdOperatorBurn() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdOperatorBurn() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -678,8 +658,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdModify() { } for name, tc := range testCases { - tc := tc - s.Run(name, func() { cmd := cli.NewTxCmdModify() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) diff --git a/x/token/msgs_test.go b/x/token/msgs_test.go index 9fe3dd4549..2a4ba5aeab 100644 --- a/x/token/msgs_test.go +++ b/x/token/msgs_test.go @@ -1026,8 +1026,6 @@ func TestAminoJSON(t *testing.T) { } for name, tc := range testCases { - tc := tc - t.Run(name, func(t *testing.T) { tx.Msgs = []sdk.Msg{tc.msg} require.Equal(t, token.RouterKey, tc.msg.Route()) diff --git a/x/upgrade/keeper/grpc_query_test.go b/x/upgrade/keeper/grpc_query_test.go index 5c3c500f07..56a7087ca5 100644 --- a/x/upgrade/keeper/grpc_query_test.go +++ b/x/upgrade/keeper/grpc_query_test.go @@ -174,8 +174,6 @@ func (suite *UpgradeTestSuite) TestModuleVersions() { mv := suite.app.UpgradeKeeper.GetModuleVersions(suite.ctx) for _, tc := range testCases { - tc := tc - suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset diff --git a/x/upgrade/keeper/keeper_test.go b/x/upgrade/keeper/keeper_test.go index 6558b0a893..56b97db97d 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -131,8 +131,6 @@ func (s *KeeperTestSuite) TestScheduleUpgrade() { } for _, tc := range cases { - tc := tc - s.Run(tc.name, func() { // reset suite s.SetupTest() diff --git a/x/upgrade/types/plan_test.go b/x/upgrade/types/plan_test.go index 484a7ac5b0..37727ab45d 100644 --- a/x/upgrade/types/plan_test.go +++ b/x/upgrade/types/plan_test.go @@ -44,7 +44,6 @@ func TestPlanString(t *testing.T) { } for name, tc := range cases { - tc := tc // copy to local variable for scopelint t.Run(name, func(t *testing.T) { s := tc.p.String() require.Equal(t, tc.expect, s) @@ -90,7 +89,6 @@ func TestPlanValid(t *testing.T) { } for name, tc := range cases { - tc := tc // copy to local variable for scopelint t.Run(name, func(t *testing.T) { err := tc.p.ValidateBasic() if tc.valid { @@ -139,7 +137,6 @@ func TestShouldExecute(t *testing.T) { } for name, tc := range cases { - tc := tc // copy to local variable for scopelint t.Run(name, func(t *testing.T) { ctx := sdk.NewContext(nil, tmproto.Header{Height: tc.ctxHeight, Time: tc.ctxTime}, false, log.NewNopLogger()) should := tc.p.ShouldExecute(ctx) diff --git a/x/upgrade/types/proposal_test.go b/x/upgrade/types/proposal_test.go index 6a576265c9..174a427200 100644 --- a/x/upgrade/types/proposal_test.go +++ b/x/upgrade/types/proposal_test.go @@ -49,7 +49,6 @@ func TestContentAccessors(t *testing.T) { types.RegisterLegacyAminoCodec(cdc) for name, tc := range cases { - tc := tc // copy to local variable for scopelint t.Run(name, func(t *testing.T) { assert.Equal(t, tc.title, tc.p.GetTitle()) assert.Equal(t, tc.desc, tc.p.GetDescription()) @@ -72,7 +71,6 @@ func TestContentAccessors(t *testing.T) { assert.Equal(t, "upgrade", unwrap.Prop.ProposalRoute()) assert.Equal(t, tc.str, unwrap.Prop.String()) }) - } } diff --git a/x/upgrade/types/storeloader_test.go b/x/upgrade/types/storeloader_test.go index 50d9dcf066..6bb64d7e3b 100644 --- a/x/upgrade/types/storeloader_test.go +++ b/x/upgrade/types/storeloader_test.go @@ -110,7 +110,6 @@ func TestSetLoader(t *testing.T) { v := []byte("value") for name, tc := range cases { - tc := tc t.Run(name, func(t *testing.T) { // prepare a db with some data db := dbm.NewMemDB()