From d1d517a9b74b7136933342370cddfb8a1d5ca48e Mon Sep 17 00:00:00 2001 From: Phil Salant Date: Wed, 11 Sep 2019 01:15:18 -0400 Subject: [PATCH] linters: enable scopelint (#3963) * Pin range scope vars * Don't disable scopelint This PR repairs linter errors seen when running the following commands: golangci-lint run --no-config --disable-all=true --enable=scopelint Contributes to #3262 --- .golangci.yml | 1 - blockchain/v0/reactor_test.go | 4 ++++ blockchain/v1/peer_test.go | 2 ++ blockchain/v1/pool_test.go | 9 +++++++++ blockchain/v1/reactor_fsm_test.go | 4 ++++ blockchain/v1/reactor_test.go | 4 ++++ consensus/reactor_test.go | 7 +++++++ consensus/replay_test.go | 1 + consensus/wal_test.go | 2 ++ crypto/merkle/rfc6962_test.go | 1 + crypto/multisig/bitarray/compact_bit_array_test.go | 5 +++++ crypto/secp256k1/secp256k1_internal_test.go | 1 + crypto/secp256k1/secp256k1_test.go | 1 + evidence/reactor_test.go | 1 + libs/common/bit_array_test.go | 1 + libs/common/bytes_test.go | 1 + libs/flowrate/io_test.go | 2 ++ libs/log/filter_test.go | 1 + p2p/conn/secret_connection_test.go | 2 ++ p2p/netaddress_test.go | 1 + rpc/lib/client/http_client.go | 1 + rpc/lib/server/handlers.go | 1 + scripts/privValUpgrade_test.go | 1 + state/execution_test.go | 2 ++ state/store_test.go | 1 + state/txindex/kv/kv_test.go | 2 ++ store/store_test.go | 2 ++ types/block_test.go | 7 +++++++ types/event_bus_test.go | 1 + types/evidence_test.go | 1 + types/part_set_test.go | 2 ++ types/proposal_test.go | 1 + types/vote_test.go | 1 + 33 files changed, 73 insertions(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 690cc3f69..8b7fbd7ec 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -13,7 +13,6 @@ linters: - lll - gochecknoglobals - gochecknoinits - - scopelint - stylecheck # linters-settings: # govet: diff --git a/blockchain/v0/reactor_test.go b/blockchain/v0/reactor_test.go index 1ba43400e..0a88dbd74 100644 --- a/blockchain/v0/reactor_test.go +++ b/blockchain/v0/reactor_test.go @@ -258,6 +258,7 @@ func TestBcBlockRequestMessageValidateBasic(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { request := bcBlockRequestMessage{Height: tc.requestHeight} assert.Equal(t, tc.expectErr, request.ValidateBasic() != nil, "Validate Basic had an unexpected result") @@ -277,6 +278,7 @@ func TestBcNoBlockResponseMessageValidateBasic(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { nonResponse := bcNoBlockResponseMessage{Height: tc.nonResponseHeight} assert.Equal(t, tc.expectErr, nonResponse.ValidateBasic() != nil, "Validate Basic had an unexpected result") @@ -296,6 +298,7 @@ func TestBcStatusRequestMessageValidateBasic(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { request := bcStatusRequestMessage{Height: tc.requestHeight} assert.Equal(t, tc.expectErr, request.ValidateBasic() != nil, "Validate Basic had an unexpected result") @@ -315,6 +318,7 @@ func TestBcStatusResponseMessageValidateBasic(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { response := bcStatusResponseMessage{Height: tc.responseHeight} assert.Equal(t, tc.expectErr, response.ValidateBasic() != nil, "Validate Basic had an unexpected result") diff --git a/blockchain/v1/peer_test.go b/blockchain/v1/peer_test.go index 3c19e4efd..c35419790 100644 --- a/blockchain/v1/peer_test.go +++ b/blockchain/v1/peer_test.go @@ -125,6 +125,7 @@ func TestPeerGetAndRemoveBlock(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { // try to get the block b, err := peer.BlockAtHeight(tt.height) @@ -167,6 +168,7 @@ func TestPeerAddBlock(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { // try to get the block err := peer.AddBlock(makeSmallBlock(int(tt.height)), 10) diff --git a/blockchain/v1/pool_test.go b/blockchain/v1/pool_test.go index 5af51148f..5530ecd41 100644 --- a/blockchain/v1/pool_test.go +++ b/blockchain/v1/pool_test.go @@ -159,6 +159,7 @@ func TestBlockPoolUpdatePeer(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { pool := tt.pool err := pool.UpdatePeer(tt.args.id, tt.args.height) @@ -232,6 +233,7 @@ func TestBlockPoolRemovePeer(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { tt.pool.RemovePeer(tt.args.peerID, tt.args.err) assertBlockPoolEquivalent(t, tt.poolWanted, tt.pool) @@ -272,6 +274,7 @@ func TestBlockPoolRemoveShortPeers(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { pool := tt.pool pool.removeShortPeers() @@ -317,6 +320,7 @@ func TestBlockPoolSendRequestBatch(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { resetPoolTestResults() @@ -421,6 +425,7 @@ func TestBlockPoolAddBlock(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { err := tt.pool.AddBlock(tt.args.peerID, tt.args.block, tt.args.blockSize) assert.Equal(t, tt.errWanted, err) @@ -473,6 +478,7 @@ func TestBlockPoolFirstTwoBlocksAndPeers(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { pool := tt.pool gotFirst, gotSecond, err := pool.FirstTwoBlocksAndPeers() @@ -544,6 +550,7 @@ func TestBlockPoolInvalidateFirstTwoBlocks(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { tt.pool.InvalidateFirstTwoBlocks(errNoPeerResponse) assertBlockPoolEquivalent(t, tt.poolWanted, tt.pool) @@ -584,6 +591,7 @@ func TestProcessedCurrentHeightBlock(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { tt.pool.ProcessedCurrentHeightBlock() assertBlockPoolEquivalent(t, tt.poolWanted, tt.pool) @@ -642,6 +650,7 @@ func TestRemovePeerAtCurrentHeight(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { tt.pool.RemovePeerAtCurrentHeights(errNoPeerResponse) assertBlockPoolEquivalent(t, tt.poolWanted, tt.pool) diff --git a/blockchain/v1/reactor_fsm_test.go b/blockchain/v1/reactor_fsm_test.go index 548d3e7fe..7dff5bbaf 100644 --- a/blockchain/v1/reactor_fsm_test.go +++ b/blockchain/v1/reactor_fsm_test.go @@ -211,6 +211,7 @@ type testFields struct { func executeFSMTests(t *testing.T, tests []testFields, matchRespToReq bool) { for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { // Create test reactor testBcR := newTestReactor(tt.startingHeight) @@ -220,6 +221,7 @@ func executeFSMTests(t *testing.T, tests []testFields, matchRespToReq bool) { } for _, step := range tt.steps { + step := step assert.Equal(t, step.currentState, testBcR.fsm.state.name) var heightBefore int64 @@ -862,6 +864,7 @@ func TestFSMCorrectTransitionSequences(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { // Create test reactor testBcR := newTestReactor(tt.startingHeight) @@ -871,6 +874,7 @@ func TestFSMCorrectTransitionSequences(t *testing.T) { } for _, step := range tt.steps { + step := step assert.Equal(t, step.currentState, testBcR.fsm.state.name) oldNumStatusRequests := testBcR.numStatusRequests diff --git a/blockchain/v1/reactor_test.go b/blockchain/v1/reactor_test.go index 9599b7a8a..00f7b0968 100644 --- a/blockchain/v1/reactor_test.go +++ b/blockchain/v1/reactor_test.go @@ -329,6 +329,7 @@ func TestBcBlockRequestMessageValidateBasic(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { request := bcBlockRequestMessage{Height: tc.requestHeight} assert.Equal(t, tc.expectErr, request.ValidateBasic() != nil, "Validate Basic had an unexpected result") @@ -348,6 +349,7 @@ func TestBcNoBlockResponseMessageValidateBasic(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { nonResponse := bcNoBlockResponseMessage{Height: tc.nonResponseHeight} assert.Equal(t, tc.expectErr, nonResponse.ValidateBasic() != nil, "Validate Basic had an unexpected result") @@ -367,6 +369,7 @@ func TestBcStatusRequestMessageValidateBasic(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { request := bcStatusRequestMessage{Height: tc.requestHeight} assert.Equal(t, tc.expectErr, request.ValidateBasic() != nil, "Validate Basic had an unexpected result") @@ -386,6 +389,7 @@ func TestBcStatusResponseMessageValidateBasic(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { response := bcStatusResponseMessage{Height: tc.responseHeight} assert.Equal(t, tc.expectErr, response.ValidateBasic() != nil, "Validate Basic had an unexpected result") diff --git a/consensus/reactor_test.go b/consensus/reactor_test.go index 0c76f7b4d..168f07924 100644 --- a/consensus/reactor_test.go +++ b/consensus/reactor_test.go @@ -656,6 +656,7 @@ func TestNewRoundStepMessageValidateBasic(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { message := NewRoundStepMessage{ Height: tc.messageHeight, @@ -685,6 +686,7 @@ func TestNewValidBlockMessageValidateBasic(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { message := NewValidBlockMessage{ Height: tc.messageHeight, @@ -715,6 +717,7 @@ func TestProposalPOLMessageValidateBasic(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { message := ProposalPOLMessage{ Height: tc.messageHeight, @@ -742,6 +745,7 @@ func TestBlockPartMessageValidateBasic(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { message := BlockPartMessage{ Height: tc.messageHeight, @@ -781,6 +785,7 @@ func TestHasVoteMessageValidateBasic(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { message := HasVoteMessage{ Height: tc.messageHeight, @@ -825,6 +830,7 @@ func TestVoteSetMaj23MessageValidateBasic(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { message := VoteSetMaj23Message{ Height: tc.messageHeight, @@ -871,6 +877,7 @@ func TestVoteSetBitsMessageValidateBasic(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { message := VoteSetBitsMessage{ Height: tc.messageHeight, diff --git a/consensus/replay_test.go b/consensus/replay_test.go index 5b454248d..b308e4946 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -123,6 +123,7 @@ func TestWALCrash(t *testing.T) { } for i, tc := range testCases { + tc := tc consensusReplayConfig := ResetConfig(fmt.Sprintf("%s_%d", t.Name(), i)) t.Run(tc.name, func(t *testing.T) { crashWALandCheckLiveness(t, consensusReplayConfig, tc.initFn, tc.heightToStop) diff --git a/consensus/wal_test.go b/consensus/wal_test.go index 5cb73fb7f..82d912f3a 100644 --- a/consensus/wal_test.go +++ b/consensus/wal_test.go @@ -86,6 +86,8 @@ func TestWALEncoderDecoder(t *testing.T) { b := new(bytes.Buffer) for _, msg := range msgs { + msg := msg + b.Reset() enc := NewWALEncoder(b) diff --git a/crypto/merkle/rfc6962_test.go b/crypto/merkle/rfc6962_test.go index 52eab4228..e2fe7f617 100644 --- a/crypto/merkle/rfc6962_test.go +++ b/crypto/merkle/rfc6962_test.go @@ -56,6 +56,7 @@ func TestRFC6962Hasher(t *testing.T) { got: innerHash([]byte("N123"), []byte("N456")), }, } { + tc := tc t.Run(tc.desc, func(t *testing.T) { wantBytes, err := hex.DecodeString(tc.want) if err != nil { diff --git a/crypto/multisig/bitarray/compact_bit_array_test.go b/crypto/multisig/bitarray/compact_bit_array_test.go index 70c0544d9..369945ff3 100644 --- a/crypto/multisig/bitarray/compact_bit_array_test.go +++ b/crypto/multisig/bitarray/compact_bit_array_test.go @@ -72,6 +72,7 @@ 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) @@ -131,6 +132,7 @@ func TestCompactMarshalUnmarshal(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.bA.String(), func(t *testing.T) { bz := tc.bA.CompactMarshal() @@ -165,12 +167,15 @@ 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) require.NoError(t, err) for i := 0; i < len(tc.bAIndex); i++ { + require.Equal(t, tc.trueValueIndex[i], bA.NumTrueBitsBefore(tc.bAIndex[i]), "tc %d, i %d", tcIndex, i) } }) diff --git a/crypto/secp256k1/secp256k1_internal_test.go b/crypto/secp256k1/secp256k1_internal_test.go index 305f12020..3103413f8 100644 --- a/crypto/secp256k1/secp256k1_internal_test.go +++ b/crypto/secp256k1/secp256k1_internal_test.go @@ -29,6 +29,7 @@ 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/secp256k1/secp256k1_test.go b/crypto/secp256k1/secp256k1_test.go index 2488b5399..aaf8f8112 100644 --- a/crypto/secp256k1/secp256k1_test.go +++ b/crypto/secp256k1/secp256k1_test.go @@ -100,6 +100,7 @@ func TestGenPrivKeySecp256k1(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.GenPrivKeySecp256k1(tt.secret) require.NotNil(t, gotPrivKey) diff --git a/evidence/reactor_test.go b/evidence/reactor_test.go index 9603e6680..006978b3b 100644 --- a/evidence/reactor_test.go +++ b/evidence/reactor_test.go @@ -203,6 +203,7 @@ func TestEvidenceListMessageValidationBasic(t *testing.T) { }, true}, } for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { evListMsg := &EvidenceListMessage{} n := 3 diff --git a/libs/common/bit_array_test.go b/libs/common/bit_array_test.go index 09ec8af25..acf745cc8 100644 --- a/libs/common/bit_array_test.go +++ b/libs/common/bit_array_test.go @@ -232,6 +232,7 @@ 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) diff --git a/libs/common/bytes_test.go b/libs/common/bytes_test.go index 9e11988f2..49c8cacb9 100644 --- a/libs/common/bytes_test.go +++ b/libs/common/bytes_test.go @@ -40,6 +40,7 @@ func TestJSONMarshal(t *testing.T) { } for i, tc := range cases { + tc := tc t.Run(fmt.Sprintf("Case %d", i), func(t *testing.T) { ts := TestStruct{B1: tc.input, B2: tc.input} diff --git a/libs/flowrate/io_test.go b/libs/flowrate/io_test.go index ab2c7121f..d482a7b72 100644 --- a/libs/flowrate/io_test.go +++ b/libs/flowrate/io_test.go @@ -89,6 +89,7 @@ func TestReader(t *testing.T) { {false, start, _300ms, 0, 20, 3, 0, 0, 67, 100, 0, 0, 0}, } for i, s := range status { + s := s if !statusesAreEqual(&s, &want[i]) { t.Errorf("r.Status(%v)\nexpected: %v\ngot : %v", i, want[i], s) } @@ -143,6 +144,7 @@ func TestWriter(t *testing.T) { {true, start, _500ms, _100ms, 100, 5, 200, 200, 200, 200, 0, 0, 100000}, } for i, s := range status { + s := s if !statusesAreEqual(&s, &want[i]) { t.Errorf("w.Status(%v)\nexpected: %v\ngot : %v\n", i, want[i], s) } diff --git a/libs/log/filter_test.go b/libs/log/filter_test.go index f9957f043..cf4dc7495 100644 --- a/libs/log/filter_test.go +++ b/libs/log/filter_test.go @@ -55,6 +55,7 @@ func TestVariousLevels(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.name, func(t *testing.T) { var buf bytes.Buffer logger := log.NewFilter(log.NewTMJSONLogger(&buf), tc.allowed) diff --git a/p2p/conn/secret_connection_test.go b/p2p/conn/secret_connection_test.go index 4eefa799d..0b7cc00c3 100644 --- a/p2p/conn/secret_connection_test.go +++ b/p2p/conn/secret_connection_test.go @@ -110,6 +110,7 @@ func TestShareLowOrderPubkey(t *testing.T) { // all blacklisted low order points: for _, remLowOrderPubKey := range blacklist { + remLowOrderPubKey := remLowOrderPubKey _, _ = cmn.Parallel( func(_ int) (val interface{}, err error, abort bool) { _, err = shareEphPubKey(fooConn, locEphPub) @@ -135,6 +136,7 @@ func TestShareLowOrderPubkey(t *testing.T) { func TestComputeDHFailsOnLowOrder(t *testing.T) { _, locPrivKey := genEphKeys() for _, remLowOrderPubKey := range blacklist { + remLowOrderPubKey := remLowOrderPubKey shared, err := computeDHSecret(&remLowOrderPubKey, locPrivKey) assert.Error(t, err) diff --git a/p2p/netaddress_test.go b/p2p/netaddress_test.go index e7d82cd77..a3dd40f30 100644 --- a/p2p/netaddress_test.go +++ b/p2p/netaddress_test.go @@ -67,6 +67,7 @@ func TestNewNetAddressString(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.name, func(t *testing.T) { addr, err := NewNetAddressString(tc.addr) if tc.correct { diff --git a/rpc/lib/client/http_client.go b/rpc/lib/client/http_client.go index 28f51191f..963da30b8 100644 --- a/rpc/lib/client/http_client.go +++ b/rpc/lib/client/http_client.go @@ -394,6 +394,7 @@ func unmarshalResponseBytesArray(cdc *amino.Codec, responseBytes []byte, expecte } for i, response := range responses { + response := response // From the JSON-RPC 2.0 spec: // id: It MUST be the same as the value of the id member in the Request Object. if err := validateResponseID(&response, expectedID); err != nil { diff --git a/rpc/lib/server/handlers.go b/rpc/lib/server/handlers.go index 70baa489f..cb7346769 100644 --- a/rpc/lib/server/handlers.go +++ b/rpc/lib/server/handlers.go @@ -129,6 +129,7 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc, cdc *amino.Codec, logger lo } for _, request := range requests { + request := request // A Notification is a Request object without an "id" member. // The Server MUST NOT reply to a Notification, including those that are within a batch request. if request.ID == types.JSONRPCStringID("") { diff --git a/scripts/privValUpgrade_test.go b/scripts/privValUpgrade_test.go index bac4d315f..7caf38798 100644 --- a/scripts/privValUpgrade_test.go +++ b/scripts/privValUpgrade_test.go @@ -75,6 +75,7 @@ func TestLoadAndUpgrade(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { // need to re-write the file everytime because upgrading renames it err := ioutil.WriteFile(oldFilePath, []byte(oldPrivvalContent), 0600) diff --git a/state/execution_test.go b/state/execution_test.go index 38301df73..02d13b353 100644 --- a/state/execution_test.go +++ b/state/execution_test.go @@ -210,6 +210,7 @@ func TestValidateValidatorUpdates(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.name, func(t *testing.T) { err := sm.ValidateValidatorUpdates(tc.abciUpdates, tc.validatorParams) if tc.shouldErr { @@ -275,6 +276,7 @@ func TestUpdateValidators(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.name, func(t *testing.T) { updates, err := types.PB2TM.ValidatorUpdates(tc.abciUpdates) assert.NoError(t, err) diff --git a/state/store_test.go b/state/store_test.go index 4549e8f89..0a190446e 100644 --- a/state/store_test.go +++ b/state/store_test.go @@ -70,6 +70,7 @@ func BenchmarkLoadValidators(b *testing.B) { sm.SaveState(stateDB, state) for i := 10; i < 10000000000; i *= 10 { // 10, 100, 1000, ... + i := i sm.SaveValidatorsInfo(stateDB, int64(i), state.LastHeightValidatorsChanged, state.NextValidators) b.Run(fmt.Sprintf("height=%d", i), func(b *testing.B) { diff --git a/state/txindex/kv/kv_test.go b/state/txindex/kv/kv_test.go index a0c833e49..189a9da61 100644 --- a/state/txindex/kv/kv_test.go +++ b/state/txindex/kv/kv_test.go @@ -118,6 +118,7 @@ func TestTxSearch(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.q, func(t *testing.T) { results, err := indexer.Search(query.MustParse(tc.q)) assert.NoError(t, err) @@ -191,6 +192,7 @@ func TestTxSearchDeprecatedIndexing(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.q, func(t *testing.T) { results, err := indexer.Search(query.MustParse(tc.q)) require.NoError(t, err) diff --git a/store/store_test.go b/store/store_test.go index 0122a44ac..fd148f7b9 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -84,6 +84,7 @@ func TestNewBlockStore(t *testing.T) { } for i, tt := range panicCausers { + tt := tt // Expecting a panic here on trying to parse an invalid blockStore _, _, panicErr := doFn(func() (interface{}, error) { db.Set(blockStoreKey, tt.data) @@ -253,6 +254,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) { } for i, tuple := range tuples { + tuple := tuple bs, db := freshBlockStore() // SaveBlock res, err, panicErr := doFn(func() (interface{}, error) { diff --git a/types/block_test.go b/types/block_test.go index 716229bbc..71c6e9ea0 100644 --- a/types/block_test.go +++ b/types/block_test.go @@ -83,6 +83,8 @@ func TestBlockValidateBasic(t *testing.T) { }, true}, } for i, tc := range testCases { + tc := tc + i := i t.Run(tc.testName, func(t *testing.T) { block := MakeBlock(h, txs, commit, evList) block.ProposerAddress = valSet.GetProposer().Address @@ -228,6 +230,7 @@ func TestCommitValidateBasic(t *testing.T) { {"Incorrect round", func(com *Commit) { com.Precommits[0].Round = 100 }, true}, } for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { com := randCommit() tc.malleateCommit(com) @@ -302,6 +305,7 @@ func TestBlockMaxDataBytes(t *testing.T) { } for i, tc := range testCases { + tc := tc if tc.panics { assert.Panics(t, func() { MaxDataBytes(tc.maxBytes, tc.valsCount, tc.evidenceCount) @@ -330,6 +334,7 @@ func TestBlockMaxDataBytesUnknownEvidence(t *testing.T) { } for i, tc := range testCases { + tc := tc if tc.panics { assert.Panics(t, func() { MaxDataBytesUnknownEvidence(tc.maxBytes, tc.valsCount) @@ -406,6 +411,7 @@ func TestSignedHeaderValidateBasic(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { sh := SignedHeader{ Header: tc.shHeader, @@ -445,6 +451,7 @@ func TestBlockIDValidateBasic(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { blockID := BlockID{ Hash: tc.blockIDHash, diff --git a/types/event_bus_test.go b/types/event_bus_test.go index 45590217f..f7631b6d5 100644 --- a/types/event_bus_test.go +++ b/types/event_bus_test.go @@ -338,6 +338,7 @@ func BenchmarkEventBus(b *testing.B) { } for _, bm := range benchmarks { + bm := bm b.Run(bm.name, func(b *testing.B) { benchmarkEventBus(bm.numClients, bm.randQueries, bm.randEvents, b) }) diff --git a/types/evidence_test.go b/types/evidence_test.go index fc97ae409..3c943e38f 100644 --- a/types/evidence_test.go +++ b/types/evidence_test.go @@ -146,6 +146,7 @@ func TestDuplicateVoteEvidenceValidation(t *testing.T) { }, true}, } for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { ev := &DuplicateVoteEvidence{ PubKey: secp256k1.GenPrivKey().PubKey(), diff --git a/types/part_set_test.go b/types/part_set_test.go index daa2fa5c5..37aacea75 100644 --- a/types/part_set_test.go +++ b/types/part_set_test.go @@ -95,6 +95,7 @@ func TestPartSetHeaderValidateBasic(t *testing.T) { {"Invalid Hash", func(psHeader *PartSetHeader) { psHeader.Hash = make([]byte, 1) }, true}, } for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { data := cmn.RandBytes(testPartSize * 100) ps := NewPartSetFromData(data, testPartSize) @@ -117,6 +118,7 @@ func TestPartValidateBasic(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { data := cmn.RandBytes(testPartSize * 100) ps := NewPartSetFromData(data, testPartSize) diff --git a/types/proposal_test.go b/types/proposal_test.go index f1c048e1d..3a1368072 100644 --- a/types/proposal_test.go +++ b/types/proposal_test.go @@ -127,6 +127,7 @@ func TestProposalValidateBasic(t *testing.T) { blockID := makeBlockID(tmhash.Sum([]byte("blockhash")), math.MaxInt64, tmhash.Sum([]byte("partshash"))) for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { prop := NewProposal( 4, 2, 2, diff --git a/types/vote_test.go b/types/vote_test.go index b6eb1f586..42a6bbd9f 100644 --- a/types/vote_test.go +++ b/types/vote_test.go @@ -285,6 +285,7 @@ func TestVoteValidateBasic(t *testing.T) { {"Too big Signature", func(v *Vote) { v.Signature = make([]byte, MaxSignatureSize+1) }, true}, } for _, tc := range testCases { + tc := tc t.Run(tc.testName, func(t *testing.T) { vote := examplePrecommit() err := privVal.SignVote("test_chain_id", vote)