From 8aa19f3e8c7f4b2e68d71b43b276caee7c9fd06c 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 1/2] 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` (cherry picked from commit d60e44aa61e82ace2b375fae1646faa7c245fde5) # Conflicts: # .golangci.yml # CHANGELOG.md # Makefile # server/oc_cmds_test.go # server/util_test.go # x/foundation/client/testutil/tx.go --- .golangci.yml | 62 +++++++++++++ CHANGELOG.md | 31 +++++++ Makefile | 4 + 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/oc_cmds_test.go | 9 ++ server/pruning_test.go | 2 - server/start.go | 2 +- server/util.go | 2 +- server/util_test.go | 42 +++++++-- 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/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/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/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/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 | 86 ++++++++++++++----- 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/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/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/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/types/authz_test.go | 1 - x/token/client/testutil/query.go | 10 --- x/token/client/testutil/tx.go | 22 ----- x/token/msgs_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 - 193 files changed, 315 insertions(+), 628 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 915dac203e..488a4851ac 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,4 +1,5 @@ run: +<<<<<<< HEAD tests: false # # timeout for analysis, e.g. 30s, 5m, default is 1m # timeout: 5m @@ -31,6 +32,63 @@ linters: - nolintlint issues: +======= + tests: true + timeout: 15m + allow-parallel-runners: true + build-tags: + - ledger + - goleveldb + - test_ledger_mock + +output: + sort-results: true + +linters: + disable-all: true + enable: + - errcheck + - gosimple + - govet + - ineffassign + - staticcheck + - unused + - dogsled + - gosec + - gci + - gofumpt + - goconst + - gocritic + - nakedret + - nolintlint + - revive + - misspell + - stylecheck + - typecheck + - thelper + - unconvert + - 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/* +>>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) exclude-rules: - text: "Use of weak random number generator" linters: @@ -59,7 +117,11 @@ issues: linters-settings: dogsled: +<<<<<<< HEAD max-blank-identifiers: 3 +======= + max-blank-identifiers: 6 +>>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) nolintlint: allow-unused: false require-explanation: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 522b49fd5c..5248d414d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,37 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/fswap) [\#1415](https://github.com/Finschia/finschia-sdk/pull/1415) add more testcases for fswap module ### Bug Fixes +<<<<<<< HEAD +======= +* chore(deps) [\#1141](https://github.com/Finschia/finschia-sdk/pull/1141) Bump github.com/cosmos/ledger-cosmos-go from 0.12.2 to 0.13.2 to fix ledger signing issue +* (x/auth, x/slashing) [\#1179](https://github.com/Finschia/finschia-sdk/pull/1179) modify missing changes of converting to tendermint +* (x/auth) [#1274](https://github.com/Finschia/finschia-sdk/pull/1274) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking. +* (x/collection) [\#1276](https://github.com/Finschia/finschia-sdk/pull/1276) eliminates potential risk for Insufficient Sanity Check of tokenID in Genesis +* (x/foundation) [\#1277](https://github.com/Finschia/finschia-sdk/pull/1277) add init logic of foundation module accounts to InitGenesis in order to eliminate potential panic +* (x/collection, x/token) [\#1288](https://github.com/Finschia/finschia-sdk/pull/1288) use accAddress to compare in validatebasic function in collection & token modules +* (x/collection) [\#1268](https://github.com/Finschia/finschia-sdk/pull/1268) export x/collection params into genesis +* (x/collection) [\#1294](https://github.com/Finschia/finschia-sdk/pull/1294) reject NFT coins on FT APIs +* (sec) [\#1302](https://github.com/Finschia/finschia-sdk/pull/1302) remove map iteration non-determinism with keys + sorting +* (client) [\#1303](https://github.com/Finschia/finschia-sdk/pull/1303) fix possible overflow in BuildUnsignedTx +* (types) [\#1299](https://github.com/Finschia/finschia-sdk/pull/1299) add missing nil checks +* (x/staking) [\#1301](https://github.com/Finschia/finschia-sdk/pull/1301) Use bytes instead of string comparison in delete validator queue (backport cosmos/cosmos-sdk#12303) +* (x/gov) [\#1304](https://github.com/Finschia/finschia-sdk/pull/1304) fetch a failed proposal tally from proposal.FinalTallyResult in the gprc query +* (x/staking) [\#1306](https://github.com/Finschia/finschia-sdk/pull/1306) add validation for potential slashing evasion during re-delegation +* (client/keys) [#1312](https://github.com/Finschia/finschia-sdk/pull/1312) ignore error when key not found in `keys delete` +* (store) [\#1310](https://github.com/Finschia/finschia-sdk/pull/1310) fix app-hash mismatch if upgrade migration commit is interrupted(backport cosmos/cosmos-sdk#13530) +* (types) [\#1313](https://github.com/Finschia/finschia-sdk/pull/1313) fix correctly coalesce coins even with repeated denominations(backport cosmos/cosmos-sdk#13265) +* (x/crypto) [\#1316](https://github.com/Finschia/finschia-sdk/pull/1316) error if incorrect ledger public key (backport cosmos/cosmos-sdk#14460, cosmos/cosmos-sdk#19691) +* (x/auth) [#1319](https://github.com/Finschia/finschia-sdk/pull/1319) prevent signing from wrong key in multisig +* (x/mint, x/slashing) [\#1323](https://github.com/Finschia/finschia-sdk/pull/1323) add missing nil check for params validation +* (x/server) [\#1337](https://github.com/Finschia/finschia-sdk/pull/1337) fix panic when defining minimum gas config as `100stake;100uatom`. Use a `,` delimiter instead of `;`. Fixes the server config getter to use the correct delimiter (backport cosmos/cosmos-sdk#18537) +* (x/fbridge) [\#1361](https://github.com/Finschia/finschia-sdk/pull/1361) Fixes fbridge auth checking bug +* (x/fswap) [\#1365](https://github.com/Finschia/finschia-sdk/pull/1365) fix update swap keys for possibly overlapped keys(`(hello,world) should be different to (hel,loworld)`) +* (x/fswap, x/fbridge) [\#1378](https://github.com/Finschia/finschia-sdk/pull/1378) Fix bug where amino is not supported in fswap and fbridge +* (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 +>>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) ### Removed diff --git a/Makefile b/Makefile index 2f9eb0198f..7bb1376fa7 100644 --- a/Makefile +++ b/Makefile @@ -354,7 +354,11 @@ lint: golangci-lint find . -name '*.go' -type f -not -path "*.git*" | xargs gofmt -d -s golangci-lint: +<<<<<<< HEAD @go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.2 +======= + @go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59 +>>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) 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 028282be22..af6b3c09fa 100644 --- a/baseapp/abci_test.go +++ b/baseapp/abci_test.go @@ -112,8 +112,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 24cfc03426..af9eeb3ca8 100644 --- a/baseapp/deliver_tx_test.go +++ b/baseapp/deliver_tx_test.go @@ -51,7 +51,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, @@ -96,7 +95,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) @@ -1839,7 +1837,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 8a39ae13df..f8dde7a16d 100644 --- a/client/config/cmd.go +++ b/client/config/cmd.go @@ -31,7 +31,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) { @@ -60,7 +60,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: @@ -84,7 +84,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 46a1dadc89..a333785fd1 100644 --- a/client/config/config_test.go +++ b/client/config/config_test.go @@ -84,7 +84,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 68d300de32..e5c85e1f3d 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 4895cfd000..a894e119e8 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 dd0bb56298..8f5ddcfa3a 100644 --- a/client/keys/add_test.go +++ b/client/keys/add_test.go @@ -302,7 +302,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 ebaf4ca2f9..7346be3ec6 100644 --- a/client/keys/list_test.go +++ b/client/keys/list_test.go @@ -53,7 +53,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 3543f36373..0bb93b16eb 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 ff73324b39..d6a2ea59ce 100644 --- a/client/keys/show_test.go +++ b/client/keys/show_test.go @@ -176,7 +176,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) @@ -202,7 +201,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 c54c785c50..d85dfe8cee 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 bfd9107f8f..f4be861a4a 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 689a6f5adc..89839d1075 100644 --- a/codec/codec_common_test.go +++ b/codec/codec_common_test.go @@ -117,7 +117,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 44c490f101..7ae75aae82 100644 --- a/codec/unknownproto/unknown_fields_test.go +++ b/codec/unknownproto/unknown_fields_test.go @@ -224,7 +224,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 { @@ -281,7 +280,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 { @@ -484,7 +482,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 { @@ -635,7 +632,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 9520da54c6..3462820322 100644 --- a/crypto/armor.go +++ b/crypto/armor.go @@ -86,7 +86,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 882835e50c..be9cf09b04 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 a38f57ba8a..72ecaca9ed 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 b3e4497fb3..1cca0551e1 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 7cbe5949f7..79fe0a0ac9 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 7e593d77ba..2c46e5975d 100644 --- a/crypto/keys/secp256k1/secp256k1_test.go +++ b/crypto/keys/secp256k1/secp256k1_test.go @@ -127,7 +127,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 f1127e3475..fc42a13f2c 100644 --- a/crypto/ledger/ledger_mock.go +++ b/crypto/ledger/ledger_mock.go @@ -74,7 +74,7 @@ func (mock LedgerSECP256K1Mock) GetAddressPubKeySECP256K1(derivationPath []uint3 // re-serialize in the 33-byte compressed format cmp, err := btcec.ParsePubKey(pk[:], btcec.S256()) 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 d93bd24a4b..bcbeb89078 100644 --- a/crypto/ledger/ledger_secp256k1.go +++ b/crypto/ledger/ledger_secp256k1.go @@ -239,13 +239,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 := btcec.ParsePubKey(publicKey, btcec.S256()) 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) @@ -269,7 +269,7 @@ func getPubKeyAddrSafe(device SECP256K1, path hd.BIP44Params, hrp string) (types // re-serialize in the 33-byte compressed format cmp, err := btcec.ParsePubKey(publicKey, btcec.S256()) 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 c809dfd1fc..d8cfd9949c 100644 --- a/crypto/types/compact_bit_array_test.go +++ b/crypto/types/compact_bit_array_test.go @@ -58,7 +58,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) @@ -102,7 +101,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) @@ -162,7 +160,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() @@ -208,8 +205,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) @@ -282,7 +277,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 6d39e482d7..a681c4d771 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 := octypes.GenesisDocFromFile(serverCtx.Config.GenesisFile()) diff --git a/server/grpc/gogoreflection/serverreflection.go b/server/grpc/gogoreflection/serverreflection.go index 7576ba5f63..cfea02836d 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" @@ -202,12 +203,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 } @@ -216,11 +217,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 } @@ -380,7 +381,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/oc_cmds_test.go b/server/oc_cmds_test.go index 5d05eb7ab2..742233e4ec 100644 --- a/server/oc_cmds_test.go +++ b/server/oc_cmds_test.go @@ -3,6 +3,7 @@ package server import ( "bytes" "context" + "errors" "fmt" "io/ioutil" "os" @@ -32,7 +33,11 @@ func TestShowValidator(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) +<<<<<<< HEAD:server/oc_cmds_test.go if err := testCommon.cmd.ExecuteContext(ctx); err != cancelledInPreRun { +======= + if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { +>>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)):server/tm_cmds_test.go t.Fatalf("function failed with [%T] %v", err, err) } @@ -53,7 +58,11 @@ func TestShowValidatorWithKMS(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) +<<<<<<< HEAD:server/oc_cmds_test.go if err := testCommon.cmd.ExecuteContext(ctx); err != cancelledInPreRun { +======= + if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { +>>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)):server/tm_cmds_test.go t.Fatalf("function failed with [%T] %v", err, err) } 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 ce0530949e..dbdde60cf1 100644 --- a/server/start.go +++ b/server/start.go @@ -214,7 +214,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/util.go b/server/util.go index 74c163335e..15839c239c 100644 --- a/server/util.go +++ b/server/util.go @@ -210,7 +210,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 7899c7947f..a271591de3 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -39,7 +39,11 @@ func TestInterceptConfigsPreRunHandlerCreatesConfigFilesWhenMissing(t *testing.T serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) +<<<<<<< HEAD if err := cmd.ExecuteContext(ctx); err != cancelledInPreRun { +======= + if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { +>>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -116,7 +120,11 @@ func TestInterceptConfigsPreRunHandlerReadsConfigToml(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) +<<<<<<< HEAD if err := cmd.ExecuteContext(ctx); err != cancelledInPreRun { +======= + if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { +>>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -153,7 +161,11 @@ func TestInterceptConfigsPreRunHandlerReadsAppToml(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) +<<<<<<< HEAD if err := cmd.ExecuteContext(ctx); err != cancelledInPreRun { +======= + if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { +>>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -181,7 +193,11 @@ func TestInterceptConfigsPreRunHandlerReadsFlags(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) +<<<<<<< HEAD if err := cmd.ExecuteContext(ctx); err != cancelledInPreRun { +======= + if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { +>>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -206,17 +222,17 @@ func TestInterceptConfigsPreRunHandlerReadsEnvVars(t *testing.T) { basename = strings.ReplaceAll(basename, ".", "_") // This is added by ostracon 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) +<<<<<<< HEAD if err := cmd.ExecuteContext(ctx); err != cancelledInPreRun { +======= + if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { +>>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -320,7 +336,11 @@ func TestInterceptConfigsPreRunHandlerPrecedenceFlag(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) +<<<<<<< HEAD if err := testCommon.cmd.ExecuteContext(ctx); err != cancelledInPreRun { +======= + if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { +>>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -336,7 +356,11 @@ func TestInterceptConfigsPreRunHandlerPrecedenceEnvVar(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) +<<<<<<< HEAD if err := testCommon.cmd.ExecuteContext(ctx); err != cancelledInPreRun { +======= + if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { +>>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -352,7 +376,11 @@ func TestInterceptConfigsPreRunHandlerPrecedenceConfigFile(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) +<<<<<<< HEAD if err := testCommon.cmd.ExecuteContext(ctx); err != cancelledInPreRun { +======= + if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { +>>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -368,7 +396,11 @@ func TestInterceptConfigsPreRunHandlerPrecedenceConfigDefault(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) +<<<<<<< HEAD if err := testCommon.cmd.ExecuteContext(ctx); err != cancelledInPreRun { +======= + if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { +>>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } diff --git a/simapp/genesis_account_test.go b/simapp/genesis_account_test.go index 94c12000dd..2bf3997285 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 0501939e3f..79fdc75cb6 100644 --- a/simapp/simd/cmd/genaccounts_test.go +++ b/simapp/simd/cmd/genaccounts_test.go @@ -66,7 +66,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 8ac22f33d3..7e778c69d4 100644 --- a/simapp/simd/cmd/root_test.go +++ b/simapp/simd/cmd/root_test.go @@ -76,7 +76,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 21965edd80..ee02dbd808 100644 --- a/snapshots/helpers_test.go +++ b/snapshots/helpers_test.go @@ -111,7 +111,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 133889fd4b..7f53fc9352 100644 --- a/store/iavl/store_test.go +++ b/store/iavl/store_test.go @@ -648,8 +648,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 49fe681df5..5f4ea194e9 100644 --- a/store/rootmulti/snapshot_test.go +++ b/store/rootmulti/snapshot_test.go @@ -132,7 +132,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() { @@ -167,7 +166,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 fe3e1d20c9..80371f2d88 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -470,7 +470,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) } } @@ -745,7 +745,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 @@ -784,7 +784,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 0d457402b0..5b3798f904 100644 --- a/store/rootmulti/store_test.go +++ b/store/rootmulti/store_test.go @@ -510,8 +510,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 0f6582baff..12678a6788 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 32a6af3d79..26323c162e 100644 --- a/types/address_test.go +++ b/types/address_test.go @@ -381,7 +381,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 { @@ -414,7 +413,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 cc106e99bf..c9847aec44 100644 --- a/types/context_test.go +++ b/types/context_test.go @@ -197,7 +197,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 3ebdb5c727..145b1e160f 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 f033dd4088..22a5510116 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 33c8ada40d..e3cd2da019 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 996e9c34e5..a71dcafb14 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 a13e19aa0a..6573292871 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 ac5f6d5e7a..b1bbdc73ee 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 f163eb1bdf..74a2cdd66a 100644 --- a/x/auth/client/testutil/suite.go +++ b/x/auth/client/testutil/suite.go @@ -332,7 +332,6 @@ func (s *IntegrationTestSuite) TestCLIQueryTxCmdByHash() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := authcli.QueryTxCmd() clientCtx := val.ClientCtx @@ -448,7 +447,6 @@ func (s *IntegrationTestSuite) TestCLIQueryTxCmdByEvents() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := authcli.QueryTxCmd() clientCtx := val.ClientCtx @@ -527,7 +525,6 @@ func (s *IntegrationTestSuite) TestCLIQueryTxsCmdByEvents() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := authcli.QueryTxsByEventsCmd() clientCtx := val.ClientCtx @@ -1167,7 +1164,6 @@ func (s *IntegrationTestSuite) TestGetAccountCmd() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { clientCtx := val.ClientCtx @@ -1206,7 +1202,6 @@ func (s *IntegrationTestSuite) TestGetAccountsCmd() { } for name, tc := range testCases { - tc := tc s.Run(name, func() { cmd := authcli.GetAccountsCmd() clientCtx := val.ClientCtx @@ -1246,7 +1241,6 @@ func (s *IntegrationTestSuite) TestQueryModuleAccountByNameCmd() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { clientCtx := val.ClientCtx @@ -1275,7 +1269,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) @@ -1336,7 +1330,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 5a4ada8a6a..1e71ef7579 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 097b0f9d59..83930ae56b 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 9368449927..8a44c24714 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) @@ -243,7 +242,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 { @@ -281,7 +279,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 904e4dc93b..31f7bbf3ef 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 0327d2cf9a..07d407698d 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 6f2c393f5a..b9395d64e2 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() @@ -145,7 +144,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 8581130957..a3fc4a4dbc 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/simulation/decoder_test.go b/x/authz/simulation/decoder_test.go index 20239cb545..771fa2c2d9 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 9688f3f105..cbe734cc3a 100644 --- a/x/bank/client/testutil/suite.go +++ b/x/bank/client/testutil/suite.go @@ -146,8 +146,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) @@ -226,8 +224,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryTotalSupply() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryTotalSupply() clientCtx := val.ClientCtx @@ -368,8 +364,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDenomsMetadata() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdDenomsMetadata() clientCtx := val.ClientCtx @@ -476,8 +470,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/types/balance_test.go b/x/bank/types/balance_test.go index 9261395751..3524a55cd1 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 9501659767..fc8e748c42 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/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 592567c363..47b957bd25 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 e9f09eb000..704af163ea 100644 --- a/x/collection/msgs_test.go +++ b/x/collection/msgs_test.go @@ -1991,7 +1991,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 bfde2566d6..f82a089a43 100644 --- a/x/distribution/client/testutil/suite.go +++ b/x/distribution/client/testutil/suite.go @@ -87,8 +87,6 @@ withdraw_addr_enabled: true`, } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryParams() clientCtx := val.ClientCtx @@ -146,8 +144,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorOutstandingRewards() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryValidatorOutstandingRewards() clientCtx := val.ClientCtx @@ -209,8 +205,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorCommission() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryValidatorCommission() clientCtx := val.ClientCtx @@ -288,8 +282,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorSlashes() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryValidatorSlashes() clientCtx := val.ClientCtx @@ -389,8 +381,6 @@ total: } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryDelegatorRewards() clientCtx := val.ClientCtx @@ -432,8 +422,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryCommunityPool() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryCommunityPool() clientCtx := val.ClientCtx @@ -493,8 +481,6 @@ func (s *IntegrationTestSuite) TestNewWithdrawRewardsCmd() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { clientCtx := val.ClientCtx @@ -545,8 +531,6 @@ func (s *IntegrationTestSuite) TestNewWithdrawAllRewardsCmd() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.NewWithdrawAllRewardsCmd() clientCtx := val.ClientCtx @@ -600,8 +584,6 @@ func (s *IntegrationTestSuite) TestNewSetWithdrawAddrCmd() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.NewSetWithdrawAddrCmd() clientCtx := val.ClientCtx @@ -655,8 +637,6 @@ func (s *IntegrationTestSuite) TestNewFundCommunityPoolCmd() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.NewFundCommunityPoolCmd() clientCtx := val.ClientCtx @@ -728,8 +708,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/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 839dca4f30..eac7f06c4b 100644 --- a/x/feegrant/client/testutil/suite.go +++ b/x/feegrant/client/testutil/suite.go @@ -169,8 +169,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) @@ -235,8 +233,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) @@ -291,8 +287,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) @@ -584,8 +578,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) @@ -691,8 +683,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) @@ -830,8 +820,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) @@ -925,8 +913,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 459fe04e6d..b79343b933 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 c0a9c190bf..ea0c9883aa 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 3f9fedc58e..7dc3af1aff 100644 --- a/x/foundation/client/testutil/grpc.go +++ b/x/foundation/client/testutil/grpc.go @@ -35,7 +35,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 3677af29f6..403f748bf3 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 36f7169dc6..f352b9c1a8 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...)) @@ -420,6 +404,70 @@ func (s *IntegrationTestSuite) TestNewTxCmdExec() { } } +<<<<<<< HEAD +======= +func (s *IntegrationTestSuite) TestNewTxCmdUpdateCensorship() { + val := s.network.Validators[0] + commonArgs := []string{ + fmt.Sprintf("--%s", flags.FlagGenerateOnly), + } + + testCases := map[string]struct { + args []string + valid bool + }{ + "valid transaction": { + []string{ + s.authority.String(), + foundation.ReceiveFromTreasuryAuthorization{}.MsgTypeURL(), + foundation.CensorshipAuthorityGovernance.String(), + }, + true, + }, + "valid abbreviation": { + []string{ + s.authority.String(), + foundation.ReceiveFromTreasuryAuthorization{}.MsgTypeURL(), + "governance", + }, + true, + }, + "wrong number of args": { + []string{ + s.authority.String(), + foundation.ReceiveFromTreasuryAuthorization{}.MsgTypeURL(), + foundation.CensorshipAuthorityGovernance.String(), + "extra", + }, + false, + }, + "invalid new authority": { + []string{ + s.authority.String(), + foundation.ReceiveFromTreasuryAuthorization{}.MsgTypeURL(), + "invalid-new-authority", + }, + false, + }, + } + + for name, tc := range testCases { + s.Run(name, func() { + cmd := cli.NewTxCmdUpdateCensorship() + out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) + if !tc.valid { + s.Require().Error(err) + return + } + s.Require().NoError(err) + + var res txtypes.Tx + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out) + }) + } +} + +>>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) func (s *IntegrationTestSuite) TestNewTxCmdLeaveFoundation() { val := s.network.Validators[0] commonArgs := []string{ @@ -449,8 +497,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...)) @@ -502,8 +548,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...)) @@ -549,8 +593,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/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 f4298c53fb..6c210f2a1c 100644 --- a/x/foundation/msgs_test.go +++ b/x/foundation/msgs_test.go @@ -712,8 +712,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"))) }) @@ -777,8 +775,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()}, @@ -823,8 +819,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(), @@ -866,8 +860,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 61a487ed64..b9182b0f88 100644 --- a/x/genutil/client/cli/init_test.go +++ b/x/genutil/client/cli/init_test.go @@ -54,7 +54,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 afd035a1a0..e517ebd531 100644 --- a/x/genutil/client/testutil/helpers.go +++ b/x/genutil/client/testutil/helpers.go @@ -46,7 +46,7 @@ func CreateDefaultTendermintConfig(rootDir string) (*ostcfg.Config, error) { ostcfg.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 2a22f1f13b..2ad25289fe 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 a42c39e9ea..786d370350 100644 --- a/x/gov/client/testutil/suite.go +++ b/x/gov/client/testutil/suite.go @@ -109,8 +109,6 @@ voting_params: } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryParams() clientCtx := val.ClientCtx @@ -157,8 +155,6 @@ func (s *IntegrationTestSuite) TestCmdParam() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryParam() clientCtx := val.ClientCtx @@ -199,8 +195,6 @@ func (s *IntegrationTestSuite) TestCmdProposer() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryProposer() clientCtx := val.ClientCtx @@ -254,8 +248,6 @@ func (s *IntegrationTestSuite) TestCmdTally() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryTally() clientCtx := val.ClientCtx @@ -345,8 +337,6 @@ func (s *IntegrationTestSuite) TestNewCmdSubmitProposal() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.NewCmdSubmitProposal() clientCtx := val.ClientCtx @@ -393,8 +383,6 @@ func (s *IntegrationTestSuite) TestCmdGetProposal() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryProposal() clientCtx := val.ClientCtx @@ -446,8 +434,6 @@ func (s *IntegrationTestSuite) TestCmdGetProposals() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryProposals() clientCtx := val.ClientCtx @@ -492,7 +478,6 @@ func (s *IntegrationTestSuite) TestCmdQueryDeposits() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryDeposits() clientCtx := val.ClientCtx @@ -548,7 +533,6 @@ func (s *IntegrationTestSuite) TestCmdQueryDeposit() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryDeposit() clientCtx := val.ClientCtx @@ -626,7 +610,6 @@ func (s *IntegrationTestSuite) TestNewCmdDeposit() { } for _, tc := range testCases { - tc := tc var resp sdk.TxResponse s.Run(tc.name, func() { @@ -677,7 +660,6 @@ func (s *IntegrationTestSuite) TestCmdQueryVotes() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryVotes() clientCtx := val.ClientCtx @@ -752,7 +734,6 @@ func (s *IntegrationTestSuite) TestCmdQueryVote() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryVote() clientCtx := val.ClientCtx @@ -817,7 +798,6 @@ func (s *IntegrationTestSuite) TestNewCmdVote() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.NewCmdVote() clientCtx := val.ClientCtx @@ -901,7 +881,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 b638febf48..7646c772ab 100644 --- a/x/gov/client/utils/query_test.go +++ b/x/gov/client/utils/query_test.go @@ -161,8 +161,6 @@ func TestGetPaginatedVotes(t *testing.T) { }, }, } { - tc := tc - t.Run(tc.description, func(t *testing.T) { marshalled := make([]octypes.Tx, len(tc.msgs)) cli := TxSearchMock{txs: marshalled, txConfig: encCfg.TxConfig} diff --git a/x/gov/genesis_test.go b/x/gov/genesis_test.go index ea96276e62..22e8a933fb 100644 --- a/x/gov/genesis_test.go +++ b/x/gov/genesis_test.go @@ -106,7 +106,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 a92a19bdb6..778813faa5 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 cac387370a..86d1db3686 100644 --- a/x/gov/keeper/querier_test.go +++ b/x/gov/keeper/querier_test.go @@ -374,7 +374,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/operations.go b/x/gov/simulation/operations.go index e2ffb9724b..0c3ab1f773 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -59,7 +59,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 56dd2ecb56..eb07ba0dac 100644 --- a/x/gov/types/proposal.go +++ b/x/gov/types/proposal.go @@ -169,12 +169,18 @@ func (status *ProposalStatus) Unmarshal(data []byte) error { // Format implements the fmt.Formatter interface. // nolint: errcheck 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 eaf8188d9b..0bfa9cccb5 100644 --- a/x/mint/client/testutil/grpc.go +++ b/x/mint/client/testutil/grpc.go @@ -54,7 +54,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 fd3d0f86fc..d29a523783 100644 --- a/x/mint/client/testutil/suite.go +++ b/x/mint/client/testutil/suite.go @@ -82,8 +82,6 @@ mint_denom: stake`, } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryParams() clientCtx := val.ClientCtx @@ -116,8 +114,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryInflation() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryInflation() clientCtx := val.ClientCtx @@ -150,8 +146,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/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 3d885d52d4..f891472971 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 cc9c6df606..ab4231f097 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 4eaa3b69bc..54b9938838 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 eebb9818dd..313582c79e 100644 --- a/x/params/types/subspace_test.go +++ b/x/params/types/subspace_test.go @@ -185,7 +185,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 04261a153b..d46e01e60e 100644 --- a/x/simulation/operation.go +++ b/x/simulation/operation.go @@ -79,7 +79,6 @@ func queueOperations(queuedOps OperationQueue, queuedTimeOps []simulation.Future } 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 c2ccdf929e..549ce52c94 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/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 0110d667a7..92f345c474 100644 --- a/x/staking/client/cli/tx_test.go +++ b/x/staking/client/cli/tx_test.go @@ -82,7 +82,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 556275a938..a820966417 100644 --- a/x/staking/client/testutil/suite.go +++ b/x/staking/client/testutil/suite.go @@ -190,8 +190,6 @@ func (s *IntegrationTestSuite) TestNewCreateValidatorCmd() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.NewCreateValidatorCmd() clientCtx := val.ClientCtx @@ -245,7 +243,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidator() { }, } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryValidator() clientCtx := val.ClientCtx @@ -286,8 +283,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidators() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.GetCmdQueryValidators() clientCtx := val.ClientCtx @@ -352,7 +347,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDelegation() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryDelegation() clientCtx := val.ClientCtx @@ -408,7 +402,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDelegations() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryDelegations() clientCtx := val.ClientCtx @@ -464,7 +457,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorDelegations() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryDelegations() clientCtx := val.ClientCtx @@ -508,7 +500,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryUnbondingDelegations() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryUnbondingDelegations() clientCtx := val.ClientCtx @@ -567,7 +558,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryUnbondingDelegation() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryUnbondingDelegation() clientCtx := val.ClientCtx @@ -616,7 +606,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorUnbondingDelegations() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryValidatorUnbondingDelegations() clientCtx := val.ClientCtx @@ -665,7 +654,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryRedelegations() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryRedelegations() clientCtx := val.ClientCtx @@ -741,7 +729,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryRedelegation() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryRedelegation() clientCtx := val.ClientCtx @@ -793,7 +780,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorRedelegations() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryValidatorRedelegations() clientCtx := val.ClientCtx @@ -844,7 +830,6 @@ func (s *IntegrationTestSuite) TestGetCmdQueryHistoricalInfo() { } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryHistoricalInfo() clientCtx := val.ClientCtx @@ -886,7 +871,6 @@ unbonding_time: 1814400s`, }, } for _, tc := range testCases { - tc := tc s.Run(tc.name, func() { cmd := cli.GetCmdQueryParams() clientCtx := val.ClientCtx @@ -923,7 +907,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 @@ -1030,8 +1013,6 @@ func (s *IntegrationTestSuite) TestNewEditValidatorCmd() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.NewEditValidatorCmd() clientCtx := val.ClientCtx @@ -1112,8 +1093,6 @@ func (s *IntegrationTestSuite) TestNewDelegateCmd() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.NewDelegateCmd() clientCtx := val.ClientCtx @@ -1198,8 +1177,6 @@ func (s *IntegrationTestSuite) TestNewRedelegateCmd() { } for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { cmd := cli.NewRedelegateCmd() clientCtx := val.ClientCtx @@ -1265,8 +1242,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 f9d10be53e..52f459744f 100644 --- a/x/staking/handler_test.go +++ b/x/staking/handler_test.go @@ -888,7 +888,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) } @@ -935,7 +935,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) } @@ -975,7 +975,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) } @@ -1023,7 +1023,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 e87f208da2..79a9806f4b 100644 --- a/x/staking/keeper/delegation_test.go +++ b/x/staking/keeper/delegation_test.go @@ -349,7 +349,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 85918ab795..18916bb650 100644 --- a/x/staking/keeper/slash.go +++ b/x/staking/keeper/slash.go @@ -273,7 +273,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 6bc9e36cff..b7723ca7ad 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 7e215029f4..825d873271 100644 --- a/x/staking/simulation/decoder_test.go +++ b/x/staking/simulation/decoder_test.go @@ -67,7 +67,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/types/authz_test.go b/x/staking/types/authz_test.go index 1bc5094c6c..d863afc1f6 100644 --- a/x/staking/types/authz_test.go +++ b/x/staking/types/authz_test.go @@ -266,7 +266,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/token/client/testutil/query.go b/x/token/client/testutil/query.go index 8f957d4a2f..f28c626923 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 34e4c41212..612d822abb 100644 --- a/x/token/msgs_test.go +++ b/x/token/msgs_test.go @@ -1014,8 +1014,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/keeper_test.go b/x/upgrade/keeper/keeper_test.go index fa7e909f51..3e205df206 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -130,8 +130,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 42b7770f13..acaea64267 100644 --- a/x/upgrade/types/plan_test.go +++ b/x/upgrade/types/plan_test.go @@ -45,7 +45,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) @@ -91,7 +90,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 { @@ -140,7 +138,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 429baf50c0..23b2b2c208 100644 --- a/x/upgrade/types/storeloader_test.go +++ b/x/upgrade/types/storeloader_test.go @@ -109,7 +109,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() From 89312029148382a708ad804abb0e60a71465d59f Mon Sep 17 00:00:00 2001 From: Jayden Lee <41176085+tkxkd0159@users.noreply.github.com> Date: Wed, 19 Jun 2024 00:12:54 +0900 Subject: [PATCH 2/2] Fix conflicts --- .golangci.yml | 133 ++++++++++++++++++++--------- CHANGELOG.md | 35 +------- Makefile | 4 - server/oc_cmds_test.go | 9 -- server/util_test.go | 42 ++------- x/foundation/client/testutil/tx.go | 86 +++++-------------- 6 files changed, 123 insertions(+), 186 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 488a4851ac..b3fe2395a8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,38 +1,4 @@ run: -<<<<<<< HEAD - tests: false -# # timeout for analysis, e.g. 30s, 5m, default is 1m -# timeout: 5m - -linters: - disable-all: false - enable: - - gofmt - - goconst - - goimports - - gosec - - gosimple - - govet - - ineffassign - - misspell - - nakedret - - prealloc - - staticcheck - - stylecheck - - typecheck - - unconvert - - unused - - unparam - - misspell - disable: - - gocritic - - errcheck - - interfacer - - wsl - - nolintlint - -issues: -======= tests: true timeout: 15m allow-parallel-runners: true @@ -88,7 +54,6 @@ issues: - ".*\\.pb\\.gw\\.go$" - ".*\\.pulsar\\.go$" - crypto/keys/secp256k1/internal/* ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) exclude-rules: - text: "Use of weak random number generator" linters: @@ -112,17 +77,105 @@ issues: text: "SA1019: token." linters: - staticcheck + - path: "legacy" + text: "SA1019:" + linters: + - staticcheck + - text: "SA1019: codec.NewAminoCodec is deprecated" # TODO remove once migration path is set out + linters: + - staticcheck + - text: "SA1019: legacybech32.MustMarshalPubKey" # TODO remove once ready to remove from the sdk + linters: + - staticcheck + - text: "SA1019: legacybech32.MarshalPubKey" # TODO remove once ready to remove from the sdk + linters: + - staticcheck + - text: "SA1019: legacybech32.UnmarshalPubKey" # TODO remove once ready to remove from the sdk + linters: + - staticcheck + - text: "SA1019: params.SendEnabled is deprecated" # TODO remove once ready to remove from the sdk + linters: + - staticcheck + - text: "SA1019: \"github.com/golang/protobuf/proto\" is deprecated" # TODO remove once ready to remove from the sdk + linters: + - staticcheck + - text: "SA1019: vote.Option is deprecated" # TODO remove once ready to remove from the sdk + linters: + - staticcheck + - text: "SA1019: types.QueryNextAccountNumberRequest is deprecated" # TODO remove once ready to remove from the sdk + linters: + - staticcheck + - text: "leading space" + linters: + - nolintlint + - path: _test\.go + linters: + - goconst max-issues-per-linter: 10000 max-same-issues: 10000 linters-settings: + gci: + custom-order: true + sections: + - standard # Standard section: captures all standard packages. + - default # Default section: contains all imports that could not be matched to another section type. + - prefix(github.com/Finschia/finschia-sdk) + revive: + rules: + - name: redefines-builtin-id + disabled: true + + gosec: + includes: + # - G101 # Look for hard coded credentials + - G102 # Bind to all interfaces + - G103 # Audit the use of unsafe block + - G104 # Audit errors not checked + - G106 # Audit the use of ssh.InsecureIgnoreHostKey + - G107 # Url provided to HTTP request as taint input + - G108 # Profiling endpoint automatically exposed on /debug/pprof + - G109 # Potential Integer overflow made by strconv.Atoi result conversion to int16/32 + - G110 # Potential DoS vulnerability via decompression bomb + - G111 # Potential directory traversal + - G112 # Potential slowloris attack + - G113 # Usage of Rat.SetString in math/big with an overflow (CVE-2022-23772) + - G114 # Use of net/http serve function that has no support for setting timeouts + - G201 # SQL query construction using format string + - G202 # SQL query construction using string concatenation + - G203 # Use of unescaped data in HTML templates + - G204 # Audit use of command execution + - G301 # Poor file permissions used when creating a directory + - G302 # Poor file permissions used with chmod + - G303 # Creating tempfile using a predictable path + - G304 # File path provided as taint input + - G305 # File traversal when extracting zip/tar archive + - G306 # Poor file permissions used when writing to a new file + - G307 # Deferring a method which returns an error + - G401 # Detect the usage of DES, RC4, MD5 or SHA1 + - G402 # Look for bad TLS connection settings + - G403 # Ensure minimum RSA key length of 2048 bits + - G404 # Insecure random number source (rand) + - G501 # Import blocklist: crypto/md5 + - G502 # Import blocklist: crypto/des + - G503 # Import blocklist: crypto/rc4 + - G504 # Import blocklist: net/http/cgi + - G505 # Import blocklist: crypto/sha1 + - G601 # Implicit memory aliasing of items from a range statement + misspell: + locale: US + gofumpt: + extra-rules: true dogsled: -<<<<<<< HEAD - max-blank-identifiers: 3 -======= max-blank-identifiers: 6 ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) nolintlint: allow-unused: false require-explanation: false - require-specific: false \ No newline at end of file + require-specific: false + gosimple: + checks: ["all"] + gocritic: + disabled-checks: + - regexpMust + - appendAssign + - ifElseChain \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 5248d414d7..6ebb44697c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,39 +42,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements * (x/fswap) [\#1415](https://github.com/Finschia/finschia-sdk/pull/1415) add more testcases for fswap module - +* (style) [\#1426](https://github.com/Finschia/finschia-sdk/pull/1426) Improve code quality with new linters + ### Bug Fixes -<<<<<<< HEAD -======= -* chore(deps) [\#1141](https://github.com/Finschia/finschia-sdk/pull/1141) Bump github.com/cosmos/ledger-cosmos-go from 0.12.2 to 0.13.2 to fix ledger signing issue -* (x/auth, x/slashing) [\#1179](https://github.com/Finschia/finschia-sdk/pull/1179) modify missing changes of converting to tendermint -* (x/auth) [#1274](https://github.com/Finschia/finschia-sdk/pull/1274) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking. -* (x/collection) [\#1276](https://github.com/Finschia/finschia-sdk/pull/1276) eliminates potential risk for Insufficient Sanity Check of tokenID in Genesis -* (x/foundation) [\#1277](https://github.com/Finschia/finschia-sdk/pull/1277) add init logic of foundation module accounts to InitGenesis in order to eliminate potential panic -* (x/collection, x/token) [\#1288](https://github.com/Finschia/finschia-sdk/pull/1288) use accAddress to compare in validatebasic function in collection & token modules -* (x/collection) [\#1268](https://github.com/Finschia/finschia-sdk/pull/1268) export x/collection params into genesis -* (x/collection) [\#1294](https://github.com/Finschia/finschia-sdk/pull/1294) reject NFT coins on FT APIs -* (sec) [\#1302](https://github.com/Finschia/finschia-sdk/pull/1302) remove map iteration non-determinism with keys + sorting -* (client) [\#1303](https://github.com/Finschia/finschia-sdk/pull/1303) fix possible overflow in BuildUnsignedTx -* (types) [\#1299](https://github.com/Finschia/finschia-sdk/pull/1299) add missing nil checks -* (x/staking) [\#1301](https://github.com/Finschia/finschia-sdk/pull/1301) Use bytes instead of string comparison in delete validator queue (backport cosmos/cosmos-sdk#12303) -* (x/gov) [\#1304](https://github.com/Finschia/finschia-sdk/pull/1304) fetch a failed proposal tally from proposal.FinalTallyResult in the gprc query -* (x/staking) [\#1306](https://github.com/Finschia/finschia-sdk/pull/1306) add validation for potential slashing evasion during re-delegation -* (client/keys) [#1312](https://github.com/Finschia/finschia-sdk/pull/1312) ignore error when key not found in `keys delete` -* (store) [\#1310](https://github.com/Finschia/finschia-sdk/pull/1310) fix app-hash mismatch if upgrade migration commit is interrupted(backport cosmos/cosmos-sdk#13530) -* (types) [\#1313](https://github.com/Finschia/finschia-sdk/pull/1313) fix correctly coalesce coins even with repeated denominations(backport cosmos/cosmos-sdk#13265) -* (x/crypto) [\#1316](https://github.com/Finschia/finschia-sdk/pull/1316) error if incorrect ledger public key (backport cosmos/cosmos-sdk#14460, cosmos/cosmos-sdk#19691) -* (x/auth) [#1319](https://github.com/Finschia/finschia-sdk/pull/1319) prevent signing from wrong key in multisig -* (x/mint, x/slashing) [\#1323](https://github.com/Finschia/finschia-sdk/pull/1323) add missing nil check for params validation -* (x/server) [\#1337](https://github.com/Finschia/finschia-sdk/pull/1337) fix panic when defining minimum gas config as `100stake;100uatom`. Use a `,` delimiter instead of `;`. Fixes the server config getter to use the correct delimiter (backport cosmos/cosmos-sdk#18537) -* (x/fbridge) [\#1361](https://github.com/Finschia/finschia-sdk/pull/1361) Fixes fbridge auth checking bug -* (x/fswap) [\#1365](https://github.com/Finschia/finschia-sdk/pull/1365) fix update swap keys for possibly overlapped keys(`(hello,world) should be different to (hel,loworld)`) -* (x/fswap, x/fbridge) [\#1378](https://github.com/Finschia/finschia-sdk/pull/1378) Fix bug where amino is not supported in fswap and fbridge -* (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 ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) ### Removed @@ -88,4 +58,5 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Build, CI * (build, ci) [\#1410](https://github.com/Finschia/finschia-sdk/pull/1410) Bump Go from 1.20 to 1.22 * (build) [\#1413](https://github.com/Finschia/finschia-sdk/pull/1413) Update outdated dependencies for v0.49.x + ### Document Updates diff --git a/Makefile b/Makefile index 7bb1376fa7..8d8539b4a7 100644 --- a/Makefile +++ b/Makefile @@ -354,11 +354,7 @@ lint: golangci-lint find . -name '*.go' -type f -not -path "*.git*" | xargs gofmt -d -s golangci-lint: -<<<<<<< HEAD - @go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.2 -======= @go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59 ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) lint-fix: golangci-lint golangci-lint run --fix --out-format=tab --issues-exit-code=0 diff --git a/server/oc_cmds_test.go b/server/oc_cmds_test.go index 742233e4ec..5d05eb7ab2 100644 --- a/server/oc_cmds_test.go +++ b/server/oc_cmds_test.go @@ -3,7 +3,6 @@ package server import ( "bytes" "context" - "errors" "fmt" "io/ioutil" "os" @@ -33,11 +32,7 @@ func TestShowValidator(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) -<<<<<<< HEAD:server/oc_cmds_test.go if err := testCommon.cmd.ExecuteContext(ctx); err != cancelledInPreRun { -======= - if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)):server/tm_cmds_test.go t.Fatalf("function failed with [%T] %v", err, err) } @@ -58,11 +53,7 @@ func TestShowValidatorWithKMS(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) -<<<<<<< HEAD:server/oc_cmds_test.go if err := testCommon.cmd.ExecuteContext(ctx); err != cancelledInPreRun { -======= - if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)):server/tm_cmds_test.go t.Fatalf("function failed with [%T] %v", err, err) } diff --git a/server/util_test.go b/server/util_test.go index a271591de3..7899c7947f 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -39,11 +39,7 @@ func TestInterceptConfigsPreRunHandlerCreatesConfigFilesWhenMissing(t *testing.T serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) -<<<<<<< HEAD if err := cmd.ExecuteContext(ctx); err != cancelledInPreRun { -======= - if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -120,11 +116,7 @@ func TestInterceptConfigsPreRunHandlerReadsConfigToml(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) -<<<<<<< HEAD if err := cmd.ExecuteContext(ctx); err != cancelledInPreRun { -======= - if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -161,11 +153,7 @@ func TestInterceptConfigsPreRunHandlerReadsAppToml(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) -<<<<<<< HEAD if err := cmd.ExecuteContext(ctx); err != cancelledInPreRun { -======= - if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -193,11 +181,7 @@ func TestInterceptConfigsPreRunHandlerReadsFlags(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) -<<<<<<< HEAD if err := cmd.ExecuteContext(ctx); err != cancelledInPreRun { -======= - if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -222,17 +206,17 @@ func TestInterceptConfigsPreRunHandlerReadsEnvVars(t *testing.T) { basename = strings.ReplaceAll(basename, ".", "_") // This is added by ostracon envVarName := fmt.Sprintf("%s_RPC_LADDR", strings.ToUpper(basename)) - t.Setenv(envVarName, testAddr) + os.Setenv(envVarName, testAddr) + t.Cleanup(func() { + os.Unsetenv(envVarName) + }) + cmd.PreRunE = preRunETestImpl serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) -<<<<<<< HEAD if err := cmd.ExecuteContext(ctx); err != cancelledInPreRun { -======= - if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -336,11 +320,7 @@ func TestInterceptConfigsPreRunHandlerPrecedenceFlag(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) -<<<<<<< HEAD if err := testCommon.cmd.ExecuteContext(ctx); err != cancelledInPreRun { -======= - if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -356,11 +336,7 @@ func TestInterceptConfigsPreRunHandlerPrecedenceEnvVar(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) -<<<<<<< HEAD if err := testCommon.cmd.ExecuteContext(ctx); err != cancelledInPreRun { -======= - if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -376,11 +352,7 @@ func TestInterceptConfigsPreRunHandlerPrecedenceConfigFile(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) -<<<<<<< HEAD if err := testCommon.cmd.ExecuteContext(ctx); err != cancelledInPreRun { -======= - if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -396,11 +368,7 @@ func TestInterceptConfigsPreRunHandlerPrecedenceConfigDefault(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) -<<<<<<< HEAD if err := testCommon.cmd.ExecuteContext(ctx); err != cancelledInPreRun { -======= - if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } diff --git a/x/foundation/client/testutil/tx.go b/x/foundation/client/testutil/tx.go index f352b9c1a8..36f7169dc6 100644 --- a/x/foundation/client/testutil/tx.go +++ b/x/foundation/client/testutil/tx.go @@ -44,6 +44,8 @@ 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...)) @@ -90,6 +92,8 @@ 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...)) @@ -134,6 +138,8 @@ 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...)) @@ -192,6 +198,8 @@ 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...)) @@ -241,6 +249,8 @@ 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...)) @@ -289,6 +299,8 @@ 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...)) @@ -341,6 +353,8 @@ 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...)) @@ -388,6 +402,8 @@ 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...)) @@ -404,70 +420,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdExec() { } } -<<<<<<< HEAD -======= -func (s *IntegrationTestSuite) TestNewTxCmdUpdateCensorship() { - val := s.network.Validators[0] - commonArgs := []string{ - fmt.Sprintf("--%s", flags.FlagGenerateOnly), - } - - testCases := map[string]struct { - args []string - valid bool - }{ - "valid transaction": { - []string{ - s.authority.String(), - foundation.ReceiveFromTreasuryAuthorization{}.MsgTypeURL(), - foundation.CensorshipAuthorityGovernance.String(), - }, - true, - }, - "valid abbreviation": { - []string{ - s.authority.String(), - foundation.ReceiveFromTreasuryAuthorization{}.MsgTypeURL(), - "governance", - }, - true, - }, - "wrong number of args": { - []string{ - s.authority.String(), - foundation.ReceiveFromTreasuryAuthorization{}.MsgTypeURL(), - foundation.CensorshipAuthorityGovernance.String(), - "extra", - }, - false, - }, - "invalid new authority": { - []string{ - s.authority.String(), - foundation.ReceiveFromTreasuryAuthorization{}.MsgTypeURL(), - "invalid-new-authority", - }, - false, - }, - } - - for name, tc := range testCases { - s.Run(name, func() { - cmd := cli.NewTxCmdUpdateCensorship() - out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) - if !tc.valid { - s.Require().Error(err) - return - } - s.Require().NoError(err) - - var res txtypes.Tx - s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out) - }) - } -} - ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) func (s *IntegrationTestSuite) TestNewTxCmdLeaveFoundation() { val := s.network.Validators[0] commonArgs := []string{ @@ -497,6 +449,8 @@ 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...)) @@ -548,6 +502,8 @@ 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...)) @@ -593,6 +549,8 @@ 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...))