From 39912d2ab9dfb18732269f3dfdbde60e321315bb Mon Sep 17 00:00:00 2001 From: dung Date: Thu, 14 Sep 2023 02:57:58 +0700 Subject: [PATCH 1/9] rebind loop variable in genesis_test.go --- modules/apps/transfer/simulation/genesis_test.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/apps/transfer/simulation/genesis_test.go b/modules/apps/transfer/simulation/genesis_test.go index 7d56fedd8c0..2066124a070 100644 --- a/modules/apps/transfer/simulation/genesis_test.go +++ b/modules/apps/transfer/simulation/genesis_test.go @@ -59,12 +59,16 @@ func TestRandomizedGenState1(t *testing.T) { r := rand.New(s) // all these tests will panic tests := []struct { + name string simState module.SimulationState panicMsg string }{ { // panic => reason: incomplete initialization of the simState - module.SimulationState{}, "invalid memory address or nil pointer dereference"}, + "nil pointer dereference", + module.SimulationState{}, + "invalid memory address or nil pointer dereference"}, { // panic => reason: incomplete initialization of the simState + "assignment to entry in nil map", module.SimulationState{ AppParams: make(simtypes.AppParams), Cdc: cdc, @@ -72,8 +76,9 @@ func TestRandomizedGenState1(t *testing.T) { }, "assignment to entry in nil map"}, } - for _, tt := range tests { - tt := tt - require.Panicsf(t, func() { simulation.RandomizedGenState(&tt.simState) }, tt.panicMsg) + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + require.Panicsf(t, func() { simulation.RandomizedGenState(&tc.simState) }, tc.panicMsg) + }) } } From 456ab16b338c98b4cfd7c042a431f3f59336c0c1 Mon Sep 17 00:00:00 2001 From: dung Date: Thu, 14 Sep 2023 03:04:03 +0700 Subject: [PATCH 2/9] nits --- modules/apps/transfer/simulation/genesis_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/apps/transfer/simulation/genesis_test.go b/modules/apps/transfer/simulation/genesis_test.go index 2066124a070..7a086bfed03 100644 --- a/modules/apps/transfer/simulation/genesis_test.go +++ b/modules/apps/transfer/simulation/genesis_test.go @@ -77,6 +77,7 @@ func TestRandomizedGenState1(t *testing.T) { } for _, tc := range tests { + tc := tc t.Run(tc.name, func(t *testing.T) { require.Panicsf(t, func() { simulation.RandomizedGenState(&tc.simState) }, tc.panicMsg) }) From 8f51e3b86fef7896b4ccb937e5112ef80257d0ee Mon Sep 17 00:00:00 2001 From: dung Date: Thu, 14 Sep 2023 03:40:52 +0700 Subject: [PATCH 3/9] rebind loop variable and wrap the actual test logic inside a suite.Run --- .../controller/ibc_middleware_test.go | 8 ++ .../controller/keeper/grpc_query_test.go | 2 + .../controller/keeper/handshake_test.go | 2 + .../controller/keeper/keeper_test.go | 1 + .../controller/keeper/migrations_test.go | 4 + .../controller/keeper/msg_server_test.go | 48 ++++---- .../controller/keeper/relay_test.go | 2 + .../controller/types/msgs_test.go | 6 + .../genesis/types/genesis_test.go | 6 + .../host/ibc_module_test.go | 2 + .../host/keeper/migrations_test.go | 2 + .../host/types/msgs_test.go | 4 + .../types/account_test.go | 4 + .../types/packet_test.go | 4 + modules/apps/29-fee/keeper/grpc_query_test.go | 20 ++++ modules/apps/29-fee/keeper/msg_server_test.go | 4 + modules/apps/29-fee/types/fee_test.go | 2 + modules/apps/29-fee/types/genesis_test.go | 2 + modules/apps/29-fee/types/keys_test.go | 10 ++ modules/apps/29-fee/types/msgs_test.go | 8 ++ modules/apps/callbacks/fee_transfer_test.go | 4 + modules/apps/callbacks/ica_test.go | 4 + modules/apps/callbacks/transfer_test.go | 19 ++- .../apps/callbacks/types/callbacks_test.go | 9 +- modules/apps/transfer/ibc_module_test.go | 21 ++-- .../apps/transfer/keeper/grpc_query_test.go | 33 +++--- .../apps/transfer/keeper/migrations_test.go | 4 + .../apps/transfer/keeper/msg_server_test.go | 2 + modules/apps/transfer/keeper/relay_test.go | 2 + modules/apps/transfer/types/msgs_test.go | 6 + modules/apps/transfer/types/packet_test.go | 4 + modules/apps/transfer/types/trace_test.go | 12 ++ .../types/transfer_authorization_test.go | 4 + modules/capability/simulation/decoder_test.go | 4 +- modules/capability/simulation/genesis_test.go | 3 +- .../core/02-client/keeper/grpc_query_test.go | 14 +++ modules/core/02-client/keeper/keeper_test.go | 16 ++- modules/core/02-client/types/client_test.go | 1 + modules/core/02-client/types/codec_test.go | 8 ++ modules/core/02-client/types/height_test.go | 29 ++--- modules/core/02-client/types/msgs_test.go | 40 ++++--- modules/core/02-client/types/params_test.go | 3 + modules/core/02-client/types/proposal_test.go | 3 +- .../03-connection/keeper/grpc_query_test.go | 10 ++ modules/core/03-connection/types/keys_test.go | 23 ++-- modules/core/03-connection/types/msgs_test.go | 12 ++ .../core/03-connection/types/params_test.go | 2 + .../core/03-connection/types/version_test.go | 12 ++ .../core/04-channel/keeper/grpc_query_test.go | 28 +++++ modules/core/04-channel/types/keys_test.go | 1 + modules/core/04-channel/types/packet_test.go | 2 + .../core/23-commitment/types/utils_test.go | 2 + modules/core/24-host/parse_test.go | 3 + modules/core/24-host/validate_test.go | 6 + modules/core/genesis_test.go | 4 + .../06-solomachine/client_state_test.go | 30 ++--- .../07-tendermint/client_state_test.go | 86 ++++++++------ .../07-tendermint/consensus_state_test.go | 20 ++-- .../07-tendermint/misbehaviour_test.go | 18 +-- .../07-tendermint/update_test.go | 36 +++--- .../07-tendermint/upgrade_test.go | 110 +++++++++--------- .../09-localhost/client_state_test.go | 36 +++--- 62 files changed, 572 insertions(+), 255 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go b/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go index 44529049826..3394c1af332 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go @@ -489,6 +489,8 @@ func (suite *InterchainAccountsTestSuite) TestOnChanCloseConfirm() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { suite.SetupTest() // reset isNilApp = false @@ -619,6 +621,8 @@ func (suite *InterchainAccountsTestSuite) TestOnAcknowledgementPacket() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.msg, func() { suite.SetupTest() // reset isNilApp = false @@ -712,6 +716,8 @@ func (suite *InterchainAccountsTestSuite) TestOnTimeoutPacket() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.msg, func() { suite.SetupTest() // reset isNilApp = false @@ -775,6 +781,8 @@ func (suite *InterchainAccountsTestSuite) TestSingleHostMultipleControllers() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.msg, func() { suite.SetupTest() // reset diff --git a/modules/apps/27-interchain-accounts/controller/keeper/grpc_query_test.go b/modules/apps/27-interchain-accounts/controller/keeper/grpc_query_test.go index e11cae837c7..64cac88dc08 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/grpc_query_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/grpc_query_test.go @@ -42,6 +42,8 @@ func (suite *KeeperTestSuite) TestQueryInterchainAccount() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { suite.SetupTest() diff --git a/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go b/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go index 0b849c06fe9..29ebf75dec1 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go @@ -443,6 +443,8 @@ func (suite *KeeperTestSuite) TestOnChanCloseConfirm() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { suite.SetupTest() // reset diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go index 22e01d1a697..b19551400a9 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go @@ -257,6 +257,7 @@ func (suite *KeeperTestSuite) TestSetAndGetParams() { for _, tc := range testCases { tc := tc + suite.Run(tc.name, func() { suite.SetupTest() // reset ctx := suite.chainA.GetContext() diff --git a/modules/apps/27-interchain-accounts/controller/keeper/migrations_test.go b/modules/apps/27-interchain-accounts/controller/keeper/migrations_test.go index a966f17cad0..dbb7dc746a5 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/migrations_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/migrations_test.go @@ -44,6 +44,8 @@ func (suite *KeeperTestSuite) TestAssertChannelCapabilityMigrations() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { suite.SetupTest() @@ -93,6 +95,8 @@ func (suite *KeeperTestSuite) TestMigratorMigrateParams() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("case %s", tc.msg), func() { suite.SetupTest() // reset diff --git a/modules/apps/27-interchain-accounts/controller/keeper/msg_server_test.go b/modules/apps/27-interchain-accounts/controller/keeper/msg_server_test.go index dfc8c4a3dbc..4518a4c3825 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/msg_server_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/msg_server_test.go @@ -67,32 +67,37 @@ func (suite *KeeperTestSuite) TestRegisterInterchainAccount_MsgServer() { } for _, tc := range testCases { - suite.SetupTest() + tc := tc - path := NewICAPath(suite.chainA, suite.chainB) - suite.coordinator.SetupConnections(path) + suite.Run(tc.name, func() { + suite.SetupTest() - msg = types.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, ibctesting.TestAccAddress, "") + path := NewICAPath(suite.chainA, suite.chainB) + suite.coordinator.SetupConnections(path) - tc.malleate() + msg = types.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, ibctesting.TestAccAddress, "") - ctx := suite.chainA.GetContext() - msgServer := keeper.NewMsgServerImpl(&suite.chainA.GetSimApp().ICAControllerKeeper) - res, err := msgServer.RegisterInterchainAccount(ctx, msg) + tc.malleate() + + ctx := suite.chainA.GetContext() + msgServer := keeper.NewMsgServerImpl(&suite.chainA.GetSimApp().ICAControllerKeeper) + res, err := msgServer.RegisterInterchainAccount(ctx, msg) + + if tc.expPass { + suite.Require().NoError(err) + suite.Require().NotNil(res) + suite.Require().Equal(expectedChannelID, res.ChannelId) + + events := ctx.EventManager().Events() + suite.Require().Len(events, 2) + suite.Require().Equal(events[0].Type, channeltypes.EventTypeChannelOpenInit) + suite.Require().Equal(events[1].Type, sdk.EventTypeMessage) + } else { + suite.Require().Error(err) + suite.Require().Nil(res) + } + }) - if tc.expPass { - suite.Require().NoError(err) - suite.Require().NotNil(res) - suite.Require().Equal(expectedChannelID, res.ChannelId) - - events := ctx.EventManager().Events() - suite.Require().Len(events, 2) - suite.Require().Equal(events[0].Type, channeltypes.EventTypeChannelOpenInit) - suite.Require().Equal(events[1].Type, sdk.EventTypeMessage) - } else { - suite.Require().Error(err) - suite.Require().Nil(res) - } } } @@ -239,6 +244,7 @@ func (suite *KeeperTestSuite) TestUpdateParams() { for _, tc := range testCases { tc := tc + suite.Run(tc.name, func() { suite.SetupTest() _, err := suite.chainA.GetSimApp().ICAControllerKeeper.UpdateParams(suite.chainA.GetContext(), tc.msg) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/relay_test.go b/modules/apps/27-interchain-accounts/controller/keeper/relay_test.go index 53515409bbe..872c041b4c4 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/relay_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/relay_test.go @@ -182,6 +182,8 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacket() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.msg, func() { suite.SetupTest() // reset diff --git a/modules/apps/27-interchain-accounts/controller/types/msgs_test.go b/modules/apps/27-interchain-accounts/controller/types/msgs_test.go index 37ca92b9b96..13ef2c9ae1a 100644 --- a/modules/apps/27-interchain-accounts/controller/types/msgs_test.go +++ b/modules/apps/27-interchain-accounts/controller/types/msgs_test.go @@ -67,6 +67,7 @@ func TestMsgRegisterInterchainAccountValidateBasic(t *testing.T) { } for i, tc := range testCases { + i, tc := i, tc msg = types.NewMsgRegisterInterchainAccount( ibctesting.FirstConnectionID, @@ -137,6 +138,7 @@ func TestMsgSendTxValidateBasic(t *testing.T) { } for i, tc := range testCases { + i, tc := i, tc msgBankSend := &banktypes.MsgSend{ FromAddress: ibctesting.TestAccAddress, @@ -214,6 +216,8 @@ func TestMsgUpdateParamsValidateBasic(t *testing.T) { } for i, tc := range testCases { + i, tc := i, tc + err := tc.msg.ValidateBasic() if tc.expPass { require.NoError(t, err, "valid test case %d failed: %s", i, tc.name) @@ -235,6 +239,8 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) { } for _, tc := range testCases { + tc := tc + msg := types.MsgUpdateParams{ Signer: tc.address.String(), Params: types.DefaultParams(), diff --git a/modules/apps/27-interchain-accounts/genesis/types/genesis_test.go b/modules/apps/27-interchain-accounts/genesis/types/genesis_test.go index 731e9443999..33bcfac6b06 100644 --- a/modules/apps/27-interchain-accounts/genesis/types/genesis_test.go +++ b/modules/apps/27-interchain-accounts/genesis/types/genesis_test.go @@ -65,6 +65,8 @@ func (suite *GenesisTypesTestSuite) TestValidateGenesisState() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { genesisState = *genesistypes.DefaultGenesis() @@ -188,6 +190,8 @@ func (suite *GenesisTypesTestSuite) TestValidateControllerGenesisState() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { genesisState = genesistypes.DefaultControllerGenesis() @@ -311,6 +315,8 @@ func (suite *GenesisTypesTestSuite) TestValidateHostGenesisState() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { genesisState = genesistypes.DefaultHostGenesis() diff --git a/modules/apps/27-interchain-accounts/host/ibc_module_test.go b/modules/apps/27-interchain-accounts/host/ibc_module_test.go index 48c85deb215..6405c5e148a 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module_test.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module_test.go @@ -362,6 +362,8 @@ func (suite *InterchainAccountsTestSuite) TestOnChanCloseConfirm() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { suite.SetupTest() // reset diff --git a/modules/apps/27-interchain-accounts/host/keeper/migrations_test.go b/modules/apps/27-interchain-accounts/host/keeper/migrations_test.go index bf1bf101123..e47e40f100f 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/migrations_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/migrations_test.go @@ -25,6 +25,8 @@ func (suite *KeeperTestSuite) TestMigratorMigrateParams() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("case %s", tc.msg), func() { suite.SetupTest() // reset diff --git a/modules/apps/27-interchain-accounts/host/types/msgs_test.go b/modules/apps/27-interchain-accounts/host/types/msgs_test.go index a5660ce4e71..1170f82b895 100644 --- a/modules/apps/27-interchain-accounts/host/types/msgs_test.go +++ b/modules/apps/27-interchain-accounts/host/types/msgs_test.go @@ -37,6 +37,8 @@ func TestMsgUpdateParamsValidateBasic(t *testing.T) { } for _, tc := range testCases { + tc := tc + err := tc.msg.ValidateBasic() if tc.expPass { require.NoError(t, err) @@ -57,6 +59,8 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) { } for _, tc := range testCases { + tc := tc + msg := types.NewMsgUpdateParams(tc.address.String(), types.DefaultParams()) if tc.expPass { require.Equal(t, []sdk.AccAddress{tc.address}, msg.GetSigners()) diff --git a/modules/apps/27-interchain-accounts/types/account_test.go b/modules/apps/27-interchain-accounts/types/account_test.go index a8851a3d443..2130a46edf4 100644 --- a/modules/apps/27-interchain-accounts/types/account_test.go +++ b/modules/apps/27-interchain-accounts/types/account_test.go @@ -85,6 +85,8 @@ func (suite *TypesTestSuite) TestValidateAccountAddress() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { err := types.ValidateAccountAddress(tc.address) @@ -135,6 +137,8 @@ func (suite *TypesTestSuite) TestGenesisAccountValidate() { } for _, tc := range testCases { + tc := tc + err := tc.acc.Validate() if tc.expPass { diff --git a/modules/apps/27-interchain-accounts/types/packet_test.go b/modules/apps/27-interchain-accounts/types/packet_test.go index 59356f50f1b..c8bbec6ced8 100644 --- a/modules/apps/27-interchain-accounts/types/packet_test.go +++ b/modules/apps/27-interchain-accounts/types/packet_test.go @@ -110,6 +110,8 @@ func (suite *TypesTestSuite) TestGetPacketSender() { } for _, tc := range testCases { + tc := tc + packetData := types.InterchainAccountPacketData{} suite.Require().Equal(tc.expSender, packetData.GetPacketSender(tc.srcPortID)) } @@ -176,6 +178,8 @@ func (suite *TypesTestSuite) TestPacketDataProvider() { } for _, tc := range testCases { + tc := tc + customData := tc.packetData.GetCustomPacketData("src_callback") suite.Require().Equal(tc.expCustomData, customData) } diff --git a/modules/apps/29-fee/keeper/grpc_query_test.go b/modules/apps/29-fee/keeper/grpc_query_test.go index c8fb680ba63..13c87a04135 100644 --- a/modules/apps/29-fee/keeper/grpc_query_test.go +++ b/modules/apps/29-fee/keeper/grpc_query_test.go @@ -70,6 +70,8 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPackets() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { suite.SetupTest() // reset @@ -123,6 +125,8 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPacket() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { suite.SetupTest() // reset @@ -222,6 +226,8 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPacketsForChannel() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -287,6 +293,8 @@ func (suite *KeeperTestSuite) TestQueryTotalRecvFees() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { suite.SetupTest() // reset @@ -353,6 +361,8 @@ func (suite *KeeperTestSuite) TestQueryTotalAckFees() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { suite.SetupTest() // reset @@ -419,6 +429,8 @@ func (suite *KeeperTestSuite) TestQueryTotalTimeoutFees() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { suite.SetupTest() // reset @@ -492,6 +504,8 @@ func (suite *KeeperTestSuite) TestQueryPayee() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { suite.SetupTest() // reset @@ -562,6 +576,8 @@ func (suite *KeeperTestSuite) TestQueryCounterpartyPayee() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { suite.SetupTest() // reset @@ -674,6 +690,8 @@ func (suite *KeeperTestSuite) TestQueryFeeEnabledChannels() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { suite.SetupTest() // reset @@ -745,6 +763,8 @@ func (suite *KeeperTestSuite) TestQueryFeeEnabledChannel() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { suite.SetupTest() // reset expEnabled = true diff --git a/modules/apps/29-fee/keeper/msg_server_test.go b/modules/apps/29-fee/keeper/msg_server_test.go index dd4a0e4e7a2..a12de519b3e 100644 --- a/modules/apps/29-fee/keeper/msg_server_test.go +++ b/modules/apps/29-fee/keeper/msg_server_test.go @@ -58,6 +58,8 @@ func (suite *KeeperTestSuite) TestRegisterPayee() { } for _, tc := range testCases { + tc := tc + suite.SetupTest() suite.coordinator.Setup(suite.path) @@ -131,6 +133,8 @@ func (suite *KeeperTestSuite) TestRegisterCounterpartyPayee() { } for _, tc := range testCases { + tc := tc + suite.SetupTest() suite.coordinator.Setup(suite.path) // setup channel diff --git a/modules/apps/29-fee/types/fee_test.go b/modules/apps/29-fee/types/fee_test.go index 99e45da8709..fe4e2b24d95 100644 --- a/modules/apps/29-fee/types/fee_test.go +++ b/modules/apps/29-fee/types/fee_test.go @@ -125,6 +125,8 @@ func TestPacketFeeValidation(t *testing.T) { } for _, tc := range testCases { + tc := tc + fee := types.NewFee(defaultRecvFee, defaultAckFee, defaultTimeoutFee) packetFee = types.NewPacketFee(fee, defaultAccAddress, nil) diff --git a/modules/apps/29-fee/types/genesis_test.go b/modules/apps/29-fee/types/genesis_test.go index 8741de1c90a..d23e4298ea7 100644 --- a/modules/apps/29-fee/types/genesis_test.go +++ b/modules/apps/29-fee/types/genesis_test.go @@ -133,6 +133,8 @@ func TestValidateGenesis(t *testing.T) { } for _, tc := range testCases { + tc := tc + genState = &types.GenesisState{ IdentifiedFees: []types.IdentifiedPacketFees{ { diff --git a/modules/apps/29-fee/types/keys_test.go b/modules/apps/29-fee/types/keys_test.go index 7c74ea62860..6efc5383f06 100644 --- a/modules/apps/29-fee/types/keys_test.go +++ b/modules/apps/29-fee/types/keys_test.go @@ -37,6 +37,8 @@ func TestParseKeyPayee(t *testing.T) { } for _, tc := range testCases { + tc := tc + address, channelID, err := types.ParseKeyPayeeAddress(tc.key) if tc.expPass { @@ -88,6 +90,8 @@ func TestParseKeyFeeEnabled(t *testing.T) { } for _, tc := range testCases { + tc := tc + portID, channelID, err := types.ParseKeyFeeEnabled(tc.key) if tc.expPass { @@ -126,6 +130,8 @@ func TestParseKeyFeesInEscrow(t *testing.T) { } for _, tc := range testCases { + tc := tc + packetID, err := types.ParseKeyFeesInEscrow(tc.key) if tc.expPass { @@ -161,6 +167,8 @@ func TestParseKeyForwardRelayerAddress(t *testing.T) { } for _, tc := range testCases { + tc := tc + packetID, err := types.ParseKeyRelayerAddressForAsyncAck(tc.key) if tc.expPass { @@ -193,6 +201,8 @@ func TestParseKeyCounterpartyPayee(t *testing.T) { } for _, tc := range testCases { + tc := tc + address, channelID, err := types.ParseKeyCounterpartyPayee(tc.key) if tc.expPass { diff --git a/modules/apps/29-fee/types/msgs_test.go b/modules/apps/29-fee/types/msgs_test.go index 1029744e77b..4c59160cb1e 100644 --- a/modules/apps/29-fee/types/msgs_test.go +++ b/modules/apps/29-fee/types/msgs_test.go @@ -66,6 +66,8 @@ func TestMsgRegisterPayeeValidation(t *testing.T) { } for i, tc := range testCases { + tc := tc + relayerAddr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) payeeAddr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) @@ -140,6 +142,8 @@ func TestMsgRegisterCountepartyPayeeValidation(t *testing.T) { } for i, tc := range testCases { + i, tc := i, tc + msg = types.NewMsgRegisterCounterpartyPayee(ibctesting.MockPort, ibctesting.FirstChannelID, defaultAccAddress, defaultAccAddress) tc.malleate() @@ -211,6 +215,8 @@ func TestMsgPayPacketFeeValidation(t *testing.T) { } for _, tc := range testCases { + tc := tc + fee := types.NewFee(defaultRecvFee, defaultAckFee, defaultTimeoutFee) msg = types.NewMsgPayPacketFee(fee, ibctesting.MockFeePort, ibctesting.FirstChannelID, defaultAccAddress, nil) @@ -340,6 +346,8 @@ func TestMsgPayPacketFeeAsyncValidation(t *testing.T) { } for _, tc := range testCases { + tc := tc + packetID := channeltypes.NewPacketID(ibctesting.MockFeePort, ibctesting.FirstChannelID, 1) fee := types.NewFee(defaultRecvFee, defaultAckFee, defaultTimeoutFee) packetFee := types.NewPacketFee(fee, defaultAccAddress, nil) diff --git a/modules/apps/callbacks/fee_transfer_test.go b/modules/apps/callbacks/fee_transfer_test.go index ee22326f6af..2b8694cdc86 100644 --- a/modules/apps/callbacks/fee_transfer_test.go +++ b/modules/apps/callbacks/fee_transfer_test.go @@ -107,6 +107,8 @@ func (s *CallbacksTestSuite) TestIncentivizedTransferCallbacks() { } for _, tc := range testCases { + tc := tc + s.Run(tc.name, func() { s.SetupFeeTransferTest() @@ -177,6 +179,8 @@ func (s *CallbacksTestSuite) TestIncentivizedTransferTimeoutCallbacks() { } for _, tc := range testCases { + tc := tc + s.Run(tc.name, func() { s.SetupFeeTransferTest() diff --git a/modules/apps/callbacks/ica_test.go b/modules/apps/callbacks/ica_test.go index 4612dba0d3d..e9e1cd0d2b3 100644 --- a/modules/apps/callbacks/ica_test.go +++ b/modules/apps/callbacks/ica_test.go @@ -78,6 +78,8 @@ func (s *CallbacksTestSuite) TestICACallbacks() { } for _, tc := range testCases { + tc := tc + s.Run(tc.name, func() { icaAddr := s.SetupICATest() @@ -128,6 +130,8 @@ func (s *CallbacksTestSuite) TestICATimeoutCallbacks() { } for _, tc := range testCases { + tc := tc + s.Run(tc.name, func() { icaAddr := s.SetupICATest() diff --git a/modules/apps/callbacks/transfer_test.go b/modules/apps/callbacks/transfer_test.go index 2f5a1e832bd..4d288e96bbc 100644 --- a/modules/apps/callbacks/transfer_test.go +++ b/modules/apps/callbacks/transfer_test.go @@ -102,10 +102,13 @@ func (s *CallbacksTestSuite) TestTransferCallbacks() { } for _, tc := range testCases { - s.SetupTransferTest() + tc := tc + s.Run(tc.name, func() { + s.SetupTransferTest() - s.ExecuteTransfer(tc.transferMemo) - s.AssertHasExecutedExpectedCallback(tc.expCallback, tc.expSuccess) + s.ExecuteTransfer(tc.transferMemo) + s.AssertHasExecutedExpectedCallback(tc.expCallback, tc.expSuccess) + }) } } @@ -161,10 +164,14 @@ func (s *CallbacksTestSuite) TestTransferTimeoutCallbacks() { } for _, tc := range testCases { - s.SetupTransferTest() + tc := tc + s.Run(tc.name, func() { + s.SetupTransferTest() + + s.ExecuteTransferTimeout(tc.transferMemo) + s.AssertHasExecutedExpectedCallback(tc.expCallback, tc.expSuccess) + }) - s.ExecuteTransferTimeout(tc.transferMemo) - s.AssertHasExecutedExpectedCallback(tc.expCallback, tc.expSuccess) } } diff --git a/modules/apps/callbacks/types/callbacks_test.go b/modules/apps/callbacks/types/callbacks_test.go index 80df864a708..ccb983a31a8 100644 --- a/modules/apps/callbacks/types/callbacks_test.go +++ b/modules/apps/callbacks/types/callbacks_test.go @@ -571,8 +571,11 @@ func (s *CallbacksTypesTestSuite) TestUserDefinedGasLimit() { } for _, tc := range testCases { - callbackData, ok := tc.packetData.GetCustomPacketData(types.SourceCallbackKey).(map[string]interface{}) - s.Require().Equal(ok, callbackData != nil) - s.Require().Equal(tc.expUserGas, types.GetUserDefinedGasLimit(callbackData), tc.name) + tc := tc + s.Run(tc.name, func() { + callbackData, ok := tc.packetData.GetCustomPacketData(types.SourceCallbackKey).(map[string]interface{}) + s.Require().Equal(ok, callbackData != nil) + s.Require().Equal(tc.expUserGas, types.GetUserDefinedGasLimit(callbackData), tc.name) + }) } } diff --git a/modules/apps/transfer/ibc_module_test.go b/modules/apps/transfer/ibc_module_test.go index 7f3b8666f35..81255a32670 100644 --- a/modules/apps/transfer/ibc_module_test.go +++ b/modules/apps/transfer/ibc_module_test.go @@ -294,16 +294,19 @@ func (suite *TransferTestSuite) TestPacketDataUnmarshalerInterface() { } for _, tc := range testCases { - tc.malleate() + tc := tc + suite.Run(tc.name, func() { + tc.malleate() - packetData, err := transfer.IBCModule{}.UnmarshalPacketData(data) + packetData, err := transfer.IBCModule{}.UnmarshalPacketData(data) - if tc.expPass { - suite.Require().NoError(err) - suite.Require().Equal(expPacketData, packetData) - } else { - suite.Require().Error(err) - suite.Require().Nil(packetData) - } + if tc.expPass { + suite.Require().NoError(err) + suite.Require().Equal(expPacketData, packetData) + } else { + suite.Require().Error(err) + suite.Require().Nil(packetData) + } + }) } } diff --git a/modules/apps/transfer/keeper/grpc_query_test.go b/modules/apps/transfer/keeper/grpc_query_test.go index 7cf2b3bc203..897e8fd0604 100644 --- a/modules/apps/transfer/keeper/grpc_query_test.go +++ b/modules/apps/transfer/keeper/grpc_query_test.go @@ -73,20 +73,23 @@ func (suite *KeeperTestSuite) TestQueryDenomTrace() { for _, tc := range testCases { suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { - suite.SetupTest() // reset + tc := tc + suite.Run(tc.msg, func() { + suite.SetupTest() // reset - tc.malleate() - ctx := suite.chainA.GetContext() + tc.malleate() + ctx := suite.chainA.GetContext() - res, err := suite.chainA.GetSimApp().TransferKeeper.DenomTrace(ctx, req) + res, err := suite.chainA.GetSimApp().TransferKeeper.DenomTrace(ctx, req) - if tc.expPass { - suite.Require().NoError(err) - suite.Require().NotNil(res) - suite.Require().Equal(&expTrace, res.DenomTrace) - } else { - suite.Require().Error(err) - } + if tc.expPass { + suite.Require().NoError(err) + suite.Require().NotNil(res) + suite.Require().Equal(&expTrace, res.DenomTrace) + } else { + suite.Require().Error(err) + } + }) }) } } @@ -132,7 +135,8 @@ func (suite *KeeperTestSuite) TestQueryDenomTraces() { } for _, tc := range testCases { - suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { + tc := tc + suite.Run(tc.msg, func() { suite.SetupTest() // reset tc.malleate() @@ -200,7 +204,8 @@ func (suite *KeeperTestSuite) TestQueryDenomHash() { } for _, tc := range testCases { - suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { + tc := tc + suite.Run(tc.msg, func() { suite.SetupTest() // reset req = &types.QueryDenomHashRequest{ @@ -245,6 +250,7 @@ func (suite *KeeperTestSuite) TestEscrowAddress() { } for _, tc := range testCases { + tc := tc suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -341,6 +347,7 @@ func (suite *KeeperTestSuite) TestTotalEscrowForDenom() { } for _, tc := range testCases { + tc := tc suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset diff --git a/modules/apps/transfer/keeper/migrations_test.go b/modules/apps/transfer/keeper/migrations_test.go index 2f308f994d1..ed9cd943775 100644 --- a/modules/apps/transfer/keeper/migrations_test.go +++ b/modules/apps/transfer/keeper/migrations_test.go @@ -31,6 +31,7 @@ func (suite *KeeperTestSuite) TestMigratorMigrateParams() { } for _, tc := range testCases { + tc := tc suite.Run(fmt.Sprintf("case %s", tc.msg), func() { suite.SetupTest() // reset @@ -130,6 +131,7 @@ func (suite *KeeperTestSuite) TestMigratorMigrateTraces() { } for _, tc := range testCases { + tc := tc suite.Run(fmt.Sprintf("case %s", tc.msg), func() { suite.SetupTest() // reset @@ -218,6 +220,8 @@ func (suite *KeeperTestSuite) TestMigrateTotalEscrowForDenom() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset diff --git a/modules/apps/transfer/keeper/msg_server_test.go b/modules/apps/transfer/keeper/msg_server_test.go index 7606bbdc727..0cda061f1eb 100644 --- a/modules/apps/transfer/keeper/msg_server_test.go +++ b/modules/apps/transfer/keeper/msg_server_test.go @@ -83,6 +83,8 @@ func (suite *KeeperTestSuite) TestMsgTransfer() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { suite.SetupTest() diff --git a/modules/apps/transfer/keeper/relay_test.go b/modules/apps/transfer/keeper/relay_test.go index 620ee5aad0b..1606bc1b543 100644 --- a/modules/apps/transfer/keeper/relay_test.go +++ b/modules/apps/transfer/keeper/relay_test.go @@ -109,6 +109,8 @@ func (suite *KeeperTestSuite) TestSendTransfer() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { suite.SetupTest() // reset diff --git a/modules/apps/transfer/types/msgs_test.go b/modules/apps/transfer/types/msgs_test.go index 9ecac27a903..3afae766edb 100644 --- a/modules/apps/transfer/types/msgs_test.go +++ b/modules/apps/transfer/types/msgs_test.go @@ -69,6 +69,8 @@ func TestMsgTransferValidation(t *testing.T) { } for i, tc := range testCases { + tc := tc + err := tc.msg.ValidateBasic() if tc.expPass { require.NoError(t, err, "valid test case %d failed: %s", i, tc.name) @@ -101,6 +103,8 @@ func TestMsgUpdateParamsValidateBasic(t *testing.T) { } for i, tc := range testCases { + tc := tc + err := tc.msg.ValidateBasic() if tc.expPass { require.NoError(t, err, "valid test case %d failed: %s", i, tc.name) @@ -122,6 +126,8 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) { } for _, tc := range testCases { + tc := tc + msg := types.MsgUpdateParams{ Signer: tc.address.String(), Params: types.DefaultParams(), diff --git a/modules/apps/transfer/types/packet_test.go b/modules/apps/transfer/types/packet_test.go index 480452b783a..bd7b1054ea6 100644 --- a/modules/apps/transfer/types/packet_test.go +++ b/modules/apps/transfer/types/packet_test.go @@ -36,6 +36,8 @@ func TestFungibleTokenPacketDataValidateBasic(t *testing.T) { } for i, tc := range testCases { + tc := tc + err := tc.packetData.ValidateBasic() if tc.expPass { require.NoError(t, err, "valid test case %d failed: %v", i, err) @@ -126,6 +128,8 @@ func (suite *TypesTestSuite) TestPacketDataProvider() { } for _, tc := range testCases { + tc := tc + customData := tc.packetData.GetCustomPacketData("src_callback") suite.Require().Equal(tc.expCustomData, customData) } diff --git a/modules/apps/transfer/types/trace_test.go b/modules/apps/transfer/types/trace_test.go index c4a9e5e5f68..828cac53304 100644 --- a/modules/apps/transfer/types/trace_test.go +++ b/modules/apps/transfer/types/trace_test.go @@ -39,6 +39,8 @@ func TestParseDenomTrace(t *testing.T) { } for _, tc := range testCases { + tc := tc + trace := types.ParseDenomTrace(tc.denom) require.Equal(t, tc.expTrace, trace, tc.name) } @@ -55,6 +57,8 @@ func TestDenomTrace_IBCDenom(t *testing.T) { } for _, tc := range testCases { + tc := tc + denom := tc.trace.IBCDenom() require.Equal(t, tc.expDenom, denom, tc.name) } @@ -79,6 +83,8 @@ func TestDenomTrace_Validate(t *testing.T) { } for _, tc := range testCases { + tc := tc + err := tc.trace.Validate() if tc.expError { require.Error(t, err, tc.name) @@ -108,6 +114,8 @@ func TestTraces_Validate(t *testing.T) { } for _, tc := range testCases { + tc := tc + err := tc.traces.Validate() if tc.expError { require.Error(t, err, tc.name) @@ -136,6 +144,8 @@ func TestValidatePrefixedDenom(t *testing.T) { } for _, tc := range testCases { + tc := tc + err := types.ValidatePrefixedDenom(tc.denom) if tc.expError { require.Error(t, err, tc.name) @@ -164,6 +174,8 @@ func TestValidateIBCDenom(t *testing.T) { } for _, tc := range testCases { + tc := tc + err := types.ValidateIBCDenom(tc.denom) if tc.expError { require.Error(t, err, tc.name) diff --git a/modules/apps/transfer/types/transfer_authorization_test.go b/modules/apps/transfer/types/transfer_authorization_test.go index 3cdb6dc831b..fdc877340e8 100644 --- a/modules/apps/transfer/types/transfer_authorization_test.go +++ b/modules/apps/transfer/types/transfer_authorization_test.go @@ -159,6 +159,8 @@ func (suite *TypesTestSuite) TestTransferAuthorizationAccept() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { suite.SetupTest() @@ -305,6 +307,8 @@ func (suite *TypesTestSuite) TestTransferAuthorizationValidateBasic() { } for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { transferAuthz = types.TransferAuthorization{ Allocations: []types.Allocation{ diff --git a/modules/capability/simulation/decoder_test.go b/modules/capability/simulation/decoder_test.go index 4db124a3f3a..7885105846a 100644 --- a/modules/capability/simulation/decoder_test.go +++ b/modules/capability/simulation/decoder_test.go @@ -48,8 +48,8 @@ func TestDecodeStore(t *testing.T) { {"other", ""}, } - for i, tt := range tests { - i, tt := i, tt + for i, tc := range tests { + i, tc := i, tc t.Run(tt.name, func(t *testing.T) { switch i { case len(tests) - 1: diff --git a/modules/capability/simulation/genesis_test.go b/modules/capability/simulation/genesis_test.go index d912ce35d23..7dd552fc4a0 100644 --- a/modules/capability/simulation/genesis_test.go +++ b/modules/capability/simulation/genesis_test.go @@ -68,7 +68,8 @@ func TestRandomizedGenState1(t *testing.T) { }, "assignment to entry in nil map"}, } - for _, tt := range tests { + for _, tc := range tests { + tc := tc require.Panicsf(t, func() { simulation.RandomizedGenState(&tt.simState) }, tt.panicMsg) } } diff --git a/modules/core/02-client/keeper/grpc_query_test.go b/modules/core/02-client/keeper/grpc_query_test.go index c736b54d042..231d000a257 100644 --- a/modules/core/02-client/keeper/grpc_query_test.go +++ b/modules/core/02-client/keeper/grpc_query_test.go @@ -65,6 +65,8 @@ func (suite *KeeperTestSuite) TestQueryClientState() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -158,6 +160,8 @@ func (suite *KeeperTestSuite) TestQueryClientStates() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -269,6 +273,8 @@ func (suite *KeeperTestSuite) TestQueryConsensusState() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -369,6 +375,8 @@ func (suite *KeeperTestSuite) TestQueryConsensusStates() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -460,6 +468,8 @@ func (suite *KeeperTestSuite) TestQueryConsensusStateHeights() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -561,6 +571,8 @@ func (suite *KeeperTestSuite) TestQueryClientStatus() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -623,6 +635,8 @@ func (suite *KeeperTestSuite) TestQueryUpgradedConsensusStates() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset diff --git a/modules/core/02-client/keeper/keeper_test.go b/modules/core/02-client/keeper/keeper_test.go index b000ee79650..eef0caa7163 100644 --- a/modules/core/02-client/keeper/keeper_test.go +++ b/modules/core/02-client/keeper/keeper_test.go @@ -213,12 +213,16 @@ func (suite *KeeperTestSuite) TestValidateSelfClient() { } for _, tc := range testCases { - err := suite.chainA.App.GetIBCKeeper().ClientKeeper.ValidateSelfClient(suite.chainA.GetContext(), tc.clientState) - if tc.expPass { - suite.Require().NoError(err, "expected valid client for case: %s", tc.name) - } else { - suite.Require().Error(err, "expected invalid client for case: %s", tc.name) - } + tc := tc + + suite.Run(tc.name, func() { + err := suite.chainA.App.GetIBCKeeper().ClientKeeper.ValidateSelfClient(suite.chainA.GetContext(), tc.clientState) + if tc.expPass { + suite.Require().NoError(err, "expected valid client for case: %s", tc.name) + } else { + suite.Require().Error(err, "expected invalid client for case: %s", tc.name) + } + }) } } diff --git a/modules/core/02-client/types/client_test.go b/modules/core/02-client/types/client_test.go index ac240f37576..0d05946b3d4 100644 --- a/modules/core/02-client/types/client_test.go +++ b/modules/core/02-client/types/client_test.go @@ -73,6 +73,7 @@ func TestValidateClientType(t *testing.T) { } for _, tc := range testCases { + tc := tc err := types.ValidateClientType(tc.clientType) diff --git a/modules/core/02-client/types/codec_test.go b/modules/core/02-client/types/codec_test.go index 89e5b6c34df..f176b0b83ff 100644 --- a/modules/core/02-client/types/codec_test.go +++ b/modules/core/02-client/types/codec_test.go @@ -42,6 +42,7 @@ func (suite *TypesTestSuite) TestPackClientState() { testCasesAny := []caseAny{} for _, tc := range testCases { + tc := tc protoAny, err := types.PackClientState(tc.clientState) if tc.expPass { suite.Require().NoError(err, tc.name) @@ -53,6 +54,8 @@ func (suite *TypesTestSuite) TestPackClientState() { } for i, tc := range testCasesAny { + i, tc := i, tc + cs, err := types.UnpackClientState(tc.any) if tc.expPass { suite.Require().NoError(err, tc.name) @@ -89,6 +92,7 @@ func (suite *TypesTestSuite) TestPackConsensusState() { testCasesAny := []caseAny{} for _, tc := range testCases { + tc := tc protoAny, err := types.PackConsensusState(tc.consensusState) if tc.expPass { suite.Require().NoError(err, tc.name) @@ -99,6 +103,8 @@ func (suite *TypesTestSuite) TestPackConsensusState() { } for i, tc := range testCasesAny { + tc := tc + cs, err := types.UnpackConsensusState(tc.any) if tc.expPass { suite.Require().NoError(err, tc.name) @@ -135,6 +141,7 @@ func (suite *TypesTestSuite) TestPackClientMessage() { testCasesAny := []caseAny{} for _, tc := range testCases { + tc := tc protoAny, err := types.PackClientMessage(tc.clientMessage) if tc.expPass { suite.Require().NoError(err, tc.name) @@ -146,6 +153,7 @@ func (suite *TypesTestSuite) TestPackClientMessage() { } for i, tc := range testCasesAny { + tc := tc cs, err := types.UnpackClientMessage(tc.any) if tc.expPass { suite.Require().NoError(err, tc.name) diff --git a/modules/core/02-client/types/height_test.go b/modules/core/02-client/types/height_test.go index dafbf755d41..141b0acce9e 100644 --- a/modules/core/02-client/types/height_test.go +++ b/modules/core/02-client/types/height_test.go @@ -30,19 +30,22 @@ func TestCompareHeights(t *testing.T) { } for i, tc := range testCases { - compare := tc.height1.Compare(tc.height2) - - switch tc.compareSign { - case -1: - require.True(t, compare == -1, "case %d: %s should return negative value on comparison, got: %d", - i, tc.name, compare) - case 0: - require.True(t, compare == 0, "case %d: %s should return zero on comparison, got: %d", - i, tc.name, compare) - case 1: - require.True(t, compare == 1, "case %d: %s should return positive value on comparison, got: %d", - i, tc.name, compare) - } + t, tc := t, tc + t.Run(tc.name, func(t *testing.T) { + compare := tc.height1.Compare(tc.height2) + + switch tc.compareSign { + case -1: + require.True(t, compare == -1, "case %d: %s should return negative value on comparison, got: %d", + i, tc.name, compare) + case 0: + require.True(t, compare == 0, "case %d: %s should return zero on comparison, got: %d", + i, tc.name, compare) + case 1: + require.True(t, compare == 1, "case %d: %s should return positive value on comparison, got: %d", + i, tc.name, compare) + } + }) } } diff --git a/modules/core/02-client/types/msgs_test.go b/modules/core/02-client/types/msgs_test.go index eda16a705e0..40bd64ce6ce 100644 --- a/modules/core/02-client/types/msgs_test.go +++ b/modules/core/02-client/types/msgs_test.go @@ -644,12 +644,15 @@ func (suite *TypesTestSuite) TestMsgUpdateParamsValidateBasic() { } for _, tc := range testCases { - err := tc.msg.ValidateBasic() - if tc.expPass { - suite.Require().NoError(err, "valid case %s failed", tc.name) - } else { - suite.Require().Error(err, "invalid case %s passed", tc.name) - } + tc := tc + suite.Run(tc.name, func() { + err := tc.msg.ValidateBasic() + if tc.expPass { + suite.Require().NoError(err, "valid case %s failed", tc.name) + } else { + suite.Require().Error(err, "invalid case %s passed", tc.name) + } + }) } } @@ -665,16 +668,19 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) { } for _, tc := range testCases { - msg := types.MsgUpdateParams{ - Signer: tc.address.String(), - Params: types.DefaultParams(), - } - if tc.expPass { - require.Equal(t, []sdk.AccAddress{tc.address}, msg.GetSigners()) - } else { - require.Panics(t, func() { - msg.GetSigners() - }) - } + tc := tc + t.Run(tc.name, func(t *testing.T) { + msg := types.MsgUpdateParams{ + Signer: tc.address.String(), + Params: types.DefaultParams(), + } + if tc.expPass { + require.Equal(t, []sdk.AccAddress{tc.address}, msg.GetSigners()) + } else { + require.Panics(t, func() { + msg.GetSigners() + }) + } + }) } } diff --git a/modules/core/02-client/types/params_test.go b/modules/core/02-client/types/params_test.go index 767e4adf495..404118c0528 100644 --- a/modules/core/02-client/types/params_test.go +++ b/modules/core/02-client/types/params_test.go @@ -22,6 +22,7 @@ func TestIsAllowedClient(t *testing.T) { } for _, tc := range testCases { + tc := tc require.Equal(t, tc.expPass, tc.params.IsAllowedClient(tc.clientType), tc.name) } } @@ -38,6 +39,8 @@ func TestValidateParams(t *testing.T) { } for _, tc := range testCases { + tc := tc + err := tc.params.Validate() if tc.expPass { require.NoError(t, err, tc.name) diff --git a/modules/core/02-client/types/proposal_test.go b/modules/core/02-client/types/proposal_test.go index 73904b37f2e..6a922aa793d 100644 --- a/modules/core/02-client/types/proposal_test.go +++ b/modules/core/02-client/types/proposal_test.go @@ -56,7 +56,7 @@ func (suite *TypesTestSuite) TestValidateBasic() { } for _, tc := range testCases { - + tc := tc err := tc.proposal.ValidateBasic() if tc.expPass { @@ -163,6 +163,7 @@ func (suite *TypesTestSuite) TestUpgradeProposalValidateBasic() { } for _, tc := range testCases { + tc := tc tc.malleate() diff --git a/modules/core/03-connection/keeper/grpc_query_test.go b/modules/core/03-connection/keeper/grpc_query_test.go index 3a89c071e54..9654f8bb8dd 100644 --- a/modules/core/03-connection/keeper/grpc_query_test.go +++ b/modules/core/03-connection/keeper/grpc_query_test.go @@ -66,6 +66,8 @@ func (suite *KeeperTestSuite) TestQueryConnection() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -156,6 +158,8 @@ func (suite *KeeperTestSuite) TestQueryConnections() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -234,6 +238,8 @@ func (suite *KeeperTestSuite) TestQueryClientConnections() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -321,6 +327,8 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -420,6 +428,8 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset diff --git a/modules/core/03-connection/types/keys_test.go b/modules/core/03-connection/types/keys_test.go index 9daf816fbda..075dd85a0af 100644 --- a/modules/core/03-connection/types/keys_test.go +++ b/modules/core/03-connection/types/keys_test.go @@ -33,17 +33,20 @@ func TestParseConnectionSequence(t *testing.T) { } for _, tc := range testCases { + tc := tc - seq, err := types.ParseConnectionSequence(tc.connectionID) - valid := types.IsValidConnectionID(tc.connectionID) - require.Equal(t, tc.expSeq, seq) + t.Run(tc.name, func(t *testing.T) { + seq, err := types.ParseConnectionSequence(tc.connectionID) + valid := types.IsValidConnectionID(tc.connectionID) + require.Equal(t, tc.expSeq, seq) - if tc.expPass { - require.NoError(t, err, tc.name) - require.True(t, valid) - } else { - require.Error(t, err, tc.name) - require.False(t, valid) - } + if tc.expPass { + require.NoError(t, err, tc.name) + require.True(t, valid) + } else { + require.Error(t, err, tc.name) + require.False(t, valid) + } + }) } } diff --git a/modules/core/03-connection/types/msgs_test.go b/modules/core/03-connection/types/msgs_test.go index 6ded23088f1..ba26c117c0e 100644 --- a/modules/core/03-connection/types/msgs_test.go +++ b/modules/core/03-connection/types/msgs_test.go @@ -104,6 +104,8 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenInit() { } for _, tc := range testCases { + tc := tc + err := tc.msg.ValidateBasic() if tc.expPass { suite.Require().NoError(err, tc.name) @@ -159,6 +161,8 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenTry() { } for _, tc := range testCases { + tc := tc + err := tc.msg.ValidateBasic() if tc.expPass { suite.Require().NoError(err, tc.name) @@ -205,6 +209,8 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenAck() { } for _, tc := range testCases { + tc := tc + err := tc.msg.ValidateBasic() if tc.expPass { suite.Require().NoError(err, tc.name) @@ -227,6 +233,8 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenConfirm() { } for _, tc := range testCases { + tc := tc + err := tc.msg.ValidateBasic() if tc.expPass { suite.Require().NoError(err, tc.name) @@ -262,6 +270,8 @@ func (suite *MsgTestSuite) TestMsgUpdateParamsValidateBasic() { } for _, tc := range testCases { + tc := tc + err := tc.msg.ValidateBasic() if tc.expPass { suite.Require().NoError(err, "valid case %s failed", tc.name) @@ -283,6 +293,8 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) { } for _, tc := range testCases { + tc := tc + msg := types.MsgUpdateParams{ Signer: tc.address.String(), Params: types.DefaultParams(), diff --git a/modules/core/03-connection/types/params_test.go b/modules/core/03-connection/types/params_test.go index a8f8e5f1374..b9f8bf31afb 100644 --- a/modules/core/03-connection/types/params_test.go +++ b/modules/core/03-connection/types/params_test.go @@ -20,6 +20,8 @@ func TestValidateParams(t *testing.T) { } for _, tc := range testCases { + tc := tc + err := tc.params.Validate() if tc.expPass { require.NoError(t, err, tc.name) diff --git a/modules/core/03-connection/types/version_test.go b/modules/core/03-connection/types/version_test.go index 319c4d653ef..dbdb655b79e 100644 --- a/modules/core/03-connection/types/version_test.go +++ b/modules/core/03-connection/types/version_test.go @@ -22,6 +22,8 @@ func TestValidateVersion(t *testing.T) { } for i, tc := range testCases { + t, tc := t, tc + err := types.ValidateVersion(tc.version) if tc.expPass { @@ -56,6 +58,8 @@ func TestIsSupportedVersion(t *testing.T) { } for _, tc := range testCases { + tc := tc + require.Equal(t, tc.expPass, types.IsSupportedVersion(types.GetCompatibleVersions(), tc.version)) } } @@ -77,6 +81,8 @@ func TestFindSupportedVersion(t *testing.T) { } for i, tc := range testCases { + tc := tc + version, found := types.FindSupportedVersion(tc.version, tc.supportedVersions) if tc.expFound { require.Equal(t, tc.expVersion.GetIdentifier(), version.GetIdentifier(), "test case %d: %s", i, tc.name) @@ -105,6 +111,8 @@ func TestPickVersion(t *testing.T) { } for i, tc := range testCases { + i, tc := i, tc + version, err := types.PickVersion(tc.supportedVersions, tc.counterpartyVersions) if tc.expPass { @@ -132,6 +140,8 @@ func TestVerifyProposedVersion(t *testing.T) { } for i, tc := range testCases { + i, tc := i, tc + err := tc.supportedVersion.VerifyProposedVersion(tc.proposedVersion) if tc.expPass { @@ -158,6 +168,8 @@ func TestVerifySupportedFeature(t *testing.T) { } for i, tc := range testCases { + i, tc := i, tc + supported := types.VerifySupportedFeature(tc.version, tc.feature) require.Equal(t, tc.expPass, supported, "test case %d: %s", i, tc.name) diff --git a/modules/core/04-channel/keeper/grpc_query_test.go b/modules/core/04-channel/keeper/grpc_query_test.go index 725b6d1655a..b860d33a50f 100644 --- a/modules/core/04-channel/keeper/grpc_query_test.go +++ b/modules/core/04-channel/keeper/grpc_query_test.go @@ -85,6 +85,8 @@ func (suite *KeeperTestSuite) TestQueryChannel() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -181,6 +183,8 @@ func (suite *KeeperTestSuite) TestQueryChannels() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -298,6 +302,8 @@ func (suite *KeeperTestSuite) TestQueryConnectionChannels() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -423,6 +429,8 @@ func (suite *KeeperTestSuite) TestQueryChannelClientState() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -564,6 +572,8 @@ func (suite *KeeperTestSuite) TestQueryChannelConsensusState() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -671,6 +681,8 @@ func (suite *KeeperTestSuite) TestQueryPacketCommitment() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -764,6 +776,8 @@ func (suite *KeeperTestSuite) TestQueryPacketCommitments() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -869,6 +883,8 @@ func (suite *KeeperTestSuite) TestQueryPacketReceipt() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -969,6 +985,8 @@ func (suite *KeeperTestSuite) TestQueryPacketAcknowledgement() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -1089,6 +1107,8 @@ func (suite *KeeperTestSuite) TestQueryPacketAcknowledgements() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -1318,6 +1338,8 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedPackets() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -1450,6 +1472,8 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedAcks() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -1552,6 +1576,8 @@ func (suite *KeeperTestSuite) TestQueryNextSequenceReceive() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset @@ -1654,6 +1680,8 @@ func (suite *KeeperTestSuite) TestQueryNextSequenceSend() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset diff --git a/modules/core/04-channel/types/keys_test.go b/modules/core/04-channel/types/keys_test.go index 04ccddb34f1..47885d3c9a4 100644 --- a/modules/core/04-channel/types/keys_test.go +++ b/modules/core/04-channel/types/keys_test.go @@ -31,6 +31,7 @@ func TestParseChannelSequence(t *testing.T) { } for _, tc := range testCases { + tc := tc seq, err := types.ParseChannelSequence(tc.channelID) valid := types.IsValidChannelID(tc.channelID) diff --git a/modules/core/04-channel/types/packet_test.go b/modules/core/04-channel/types/packet_test.go index f83c06c1ec2..0bbcc641b25 100644 --- a/modules/core/04-channel/types/packet_test.go +++ b/modules/core/04-channel/types/packet_test.go @@ -44,6 +44,8 @@ func TestPacketValidateBasic(t *testing.T) { } for i, tc := range testCases { + tc := tc + err := tc.packet.ValidateBasic() if tc.expPass { require.NoError(t, err, "Msg %d failed: %s", i, tc.errMsg) diff --git a/modules/core/23-commitment/types/utils_test.go b/modules/core/23-commitment/types/utils_test.go index ab7ff41b67a..0cd24b66323 100644 --- a/modules/core/23-commitment/types/utils_test.go +++ b/modules/core/23-commitment/types/utils_test.go @@ -84,6 +84,8 @@ func (suite *MerkleTestSuite) TestConvertProofs() { } for _, tc := range testcases { + tc := tc + tc.malleate() proof, err := types.ConvertProofs(proofOps) diff --git a/modules/core/24-host/parse_test.go b/modules/core/24-host/parse_test.go index 817ad117030..8932ab29a21 100644 --- a/modules/core/24-host/parse_test.go +++ b/modules/core/24-host/parse_test.go @@ -37,6 +37,7 @@ func TestParseIdentifier(t *testing.T) { } for _, tc := range testCases { + tc := tc seq, err := host.ParseIdentifier(tc.identifier, tc.prefix) require.Equal(t, tc.expSeq, seq) @@ -65,6 +66,8 @@ func TestMustParseClientStatePath(t *testing.T) { } for _, tc := range testCases { + tc := tc + if tc.expPass { require.NotPanics(t, func() { clientID := host.MustParseClientStatePath(tc.path) diff --git a/modules/core/24-host/validate_test.go b/modules/core/24-host/validate_test.go index e75ce9334bd..c7e96275642 100644 --- a/modules/core/24-host/validate_test.go +++ b/modules/core/24-host/validate_test.go @@ -34,6 +34,7 @@ func TestDefaultIdentifierValidator(t *testing.T) { } for _, tc := range testCases { + tc := tc err := ClientIdentifierValidator(tc.id) err1 := ConnectionIdentifierValidator(tc.id) @@ -70,6 +71,7 @@ func TestPortIdentifierValidator(t *testing.T) { } for _, tc := range testCases { + tc := tc err := PortIdentifierValidator(tc.id) if tc.expPass { @@ -103,6 +105,8 @@ func TestPathValidator(t *testing.T) { } for _, tc := range testCases { + tc := tc + f := NewPathValidator(func(path string) error { return nil }) @@ -139,6 +143,8 @@ func TestCustomPathValidator(t *testing.T) { } for _, tc := range testCases { + tc := tc + err := validateFn(tc.id) if tc.expPass { require.NoError(t, err, tc.msg) diff --git a/modules/core/genesis_test.go b/modules/core/genesis_test.go index d801119ab24..3f6515573c7 100644 --- a/modules/core/genesis_test.go +++ b/modules/core/genesis_test.go @@ -306,6 +306,8 @@ func (suite *IBCTestSuite) TestInitGenesis() { } for _, tc := range testCases { + tc := tc + app := simapp.Setup(suite.T(), false) suite.NotPanics(func() { @@ -332,6 +334,8 @@ func (suite *IBCTestSuite) TestExportGenesis() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() diff --git a/modules/light-clients/06-solomachine/client_state_test.go b/modules/light-clients/06-solomachine/client_state_test.go index 549d8f9f7e1..396075614c4 100644 --- a/modules/light-clients/06-solomachine/client_state_test.go +++ b/modules/light-clients/06-solomachine/client_state_test.go @@ -126,21 +126,25 @@ func (suite *SoloMachineTestSuite) TestInitialize() { } for _, tc := range testCases { - suite.SetupTest() + tc := tc - store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), "solomachine") - err := sm.ClientState().Initialize( - suite.chainA.GetContext(), suite.chainA.Codec, - store, tc.consState, - ) + suite.Run(tc.name, func() { + suite.SetupTest() - if tc.expPass { - suite.Require().NoError(err, "valid testcase: %s failed", tc.name) - suite.Require().True(store.Has(host.ClientStateKey())) - } else { - suite.Require().Error(err, "invalid testcase: %s passed", tc.name) - suite.Require().False(store.Has(host.ClientStateKey())) - } + store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), "solomachine") + err := sm.ClientState().Initialize( + suite.chainA.GetContext(), suite.chainA.Codec, + store, tc.consState, + ) + + if tc.expPass { + suite.Require().NoError(err, "valid testcase: %s failed", tc.name) + suite.Require().True(store.Has(host.ClientStateKey())) + } else { + suite.Require().Error(err, "invalid testcase: %s passed", tc.name) + suite.Require().False(store.Has(host.ClientStateKey())) + } + }) } } } diff --git a/modules/light-clients/07-tendermint/client_state_test.go b/modules/light-clients/07-tendermint/client_state_test.go index 2f233117ee1..1f2e0aa1199 100644 --- a/modules/light-clients/07-tendermint/client_state_test.go +++ b/modules/light-clients/07-tendermint/client_state_test.go @@ -52,16 +52,22 @@ func (suite *TendermintTestSuite) TestStatus() { } for _, tc := range testCases { - path = ibctesting.NewPath(suite.chainA, suite.chainB) - suite.coordinator.SetupClients(path) + tc := tc + suite.Run(tc.name, func() { + suite.SetupTest() + + path = ibctesting.NewPath(suite.chainA, suite.chainB) + suite.coordinator.SetupClients(path) - clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) - clientState = path.EndpointA.GetClientState().(*ibctm.ClientState) + clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) + clientState = path.EndpointA.GetClientState().(*ibctm.ClientState) - tc.malleate() + tc.malleate() - status := clientState.Status(suite.chainA.GetContext(), clientStore, suite.chainA.App.AppCodec()) - suite.Require().Equal(tc.expStatus, status) + status := clientState.Status(suite.chainA.GetContext(), clientStore, suite.chainA.App.AppCodec()) + suite.Require().Equal(tc.expStatus, status) + + }) } } @@ -166,12 +172,15 @@ func (suite *TendermintTestSuite) TestValidate() { } for _, tc := range testCases { - err := tc.clientState.Validate() - if tc.expPass { - suite.Require().NoError(err, tc.name) - } else { - suite.Require().Error(err, tc.name) - } + tc := tc + suite.Run(tc.name, func() { + err := tc.clientState.Validate() + if tc.expPass { + suite.Require().NoError(err, tc.name) + } else { + suite.Require().Error(err, tc.name) + } + }) } } @@ -194,30 +203,33 @@ func (suite *TendermintTestSuite) TestInitialize() { } for _, tc := range testCases { - suite.SetupTest() - path := ibctesting.NewPath(suite.chainA, suite.chainB) - - tmConfig, ok := path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig) - suite.Require().True(ok) - - clientState := ibctm.NewClientState( - path.EndpointB.Chain.ChainID, - tmConfig.TrustLevel, tmConfig.TrustingPeriod, tmConfig.UnbondingPeriod, tmConfig.MaxClockDrift, - suite.chainB.LastHeader.GetTrustedHeight(), commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath, - ) - - store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) - err := clientState.Initialize(suite.chainA.GetContext(), suite.chainA.Codec, store, tc.consensusState) - - if tc.expPass { - suite.Require().NoError(err, "valid case returned an error") - suite.Require().True(store.Has(host.ClientStateKey())) - suite.Require().True(store.Has(host.ConsensusStateKey(suite.chainB.LastHeader.GetTrustedHeight()))) - } else { - suite.Require().Error(err, "invalid case didn't return an error") - suite.Require().False(store.Has(host.ClientStateKey())) - suite.Require().False(store.Has(host.ConsensusStateKey(suite.chainB.LastHeader.GetTrustedHeight()))) - } + tc := tc + suite.Run(tc.name, func() { + suite.SetupTest() + path := ibctesting.NewPath(suite.chainA, suite.chainB) + + tmConfig, ok := path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig) + suite.Require().True(ok) + + clientState := ibctm.NewClientState( + path.EndpointB.Chain.ChainID, + tmConfig.TrustLevel, tmConfig.TrustingPeriod, tmConfig.UnbondingPeriod, tmConfig.MaxClockDrift, + suite.chainB.LastHeader.GetTrustedHeight(), commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath, + ) + + store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) + err := clientState.Initialize(suite.chainA.GetContext(), suite.chainA.Codec, store, tc.consensusState) + + if tc.expPass { + suite.Require().NoError(err, "valid case returned an error") + suite.Require().True(store.Has(host.ClientStateKey())) + suite.Require().True(store.Has(host.ConsensusStateKey(suite.chainB.LastHeader.GetTrustedHeight()))) + } else { + suite.Require().Error(err, "invalid case didn't return an error") + suite.Require().False(store.Has(host.ClientStateKey())) + suite.Require().False(store.Has(host.ConsensusStateKey(suite.chainB.LastHeader.GetTrustedHeight()))) + } + }) } } diff --git a/modules/light-clients/07-tendermint/consensus_state_test.go b/modules/light-clients/07-tendermint/consensus_state_test.go index 6518bc8c686..4a637c4bca7 100644 --- a/modules/light-clients/07-tendermint/consensus_state_test.go +++ b/modules/light-clients/07-tendermint/consensus_state_test.go @@ -74,15 +74,17 @@ func (suite *TendermintTestSuite) TestConsensusStateValidateBasic() { for i, tc := range testCases { tc := tc - // check just to increase coverage - suite.Require().Equal(exported.Tendermint, tc.consensusState.ClientType()) - suite.Require().Equal(tc.consensusState.GetRoot(), tc.consensusState.Root) + suite.Run(tc.msg, func() { + // check just to increase coverage + suite.Require().Equal(exported.Tendermint, tc.consensusState.ClientType()) + suite.Require().Equal(tc.consensusState.GetRoot(), tc.consensusState.Root) - err := tc.consensusState.ValidateBasic() - if tc.expectPass { - suite.Require().NoError(err, "valid test case %d failed: %s", i, tc.msg) - } else { - suite.Require().Error(err, "invalid test case %d passed: %s", i, tc.msg) - } + err := tc.consensusState.ValidateBasic() + if tc.expectPass { + suite.Require().NoError(err, "valid test case %d failed: %s", i, tc.msg) + } else { + suite.Require().Error(err, "invalid test case %d passed: %s", i, tc.msg) + } + }) } } diff --git a/modules/light-clients/07-tendermint/misbehaviour_test.go b/modules/light-clients/07-tendermint/misbehaviour_test.go index 20c0f2c9502..c4ceb9e4c0a 100644 --- a/modules/light-clients/07-tendermint/misbehaviour_test.go +++ b/modules/light-clients/07-tendermint/misbehaviour_test.go @@ -224,13 +224,15 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() { for i, tc := range testCases { tc := tc - err := tc.malleateMisbehaviour(tc.misbehaviour) - suite.Require().NoError(err) - - if tc.expPass { - suite.Require().NoError(tc.misbehaviour.ValidateBasic(), "valid test case %d failed: %s", i, tc.name) - } else { - suite.Require().Error(tc.misbehaviour.ValidateBasic(), "invalid test case %d passed: %s", i, tc.name) - } + suite.Run(tc.name, func() { + err := tc.malleateMisbehaviour(tc.misbehaviour) + suite.Require().NoError(err) + + if tc.expPass { + suite.Require().NoError(tc.misbehaviour.ValidateBasic(), "valid test case %d failed: %s", i, tc.name) + } else { + suite.Require().Error(tc.misbehaviour.ValidateBasic(), "invalid test case %d passed: %s", i, tc.name) + } + }) } } diff --git a/modules/light-clients/07-tendermint/update_test.go b/modules/light-clients/07-tendermint/update_test.go index 13f067a5c98..d6b8de6e091 100644 --- a/modules/light-clients/07-tendermint/update_test.go +++ b/modules/light-clients/07-tendermint/update_test.go @@ -277,30 +277,32 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { for _, tc := range testCases { tc := tc - suite.SetupTest() - path = ibctesting.NewPath(suite.chainA, suite.chainB) + suite.Run(tc.name, func() { + suite.SetupTest() + path = ibctesting.NewPath(suite.chainA, suite.chainB) - err := path.EndpointA.CreateClient() - suite.Require().NoError(err) + err := path.EndpointA.CreateClient() + suite.Require().NoError(err) - // ensure counterparty state is committed - suite.coordinator.CommitBlock(suite.chainB) - header, err = path.EndpointA.Chain.ConstructUpdateTMClientHeader(path.EndpointA.Counterparty.Chain, path.EndpointA.ClientID) - suite.Require().NoError(err) + // ensure counterparty state is committed + suite.coordinator.CommitBlock(suite.chainB) + header, err = path.EndpointA.Chain.ConstructUpdateTMClientHeader(path.EndpointA.Counterparty.Chain, path.EndpointA.ClientID) + suite.Require().NoError(err) - tc.malleate() + tc.malleate() - clientState := path.EndpointA.GetClientState() + clientState := path.EndpointA.GetClientState() - clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) + clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) - err = clientState.VerifyClientMessage(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, header) + err = clientState.VerifyClientMessage(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, header) - if tc.expPass { - suite.Require().NoError(err, tc.name) - } else { - suite.Require().Error(err) - } + if tc.expPass { + suite.Require().NoError(err, tc.name) + } else { + suite.Require().Error(err) + } + }) } } diff --git a/modules/light-clients/07-tendermint/upgrade_test.go b/modules/light-clients/07-tendermint/upgrade_test.go index 290380e54fa..9cedda0b206 100644 --- a/modules/light-clients/07-tendermint/upgrade_test.go +++ b/modules/light-clients/07-tendermint/upgrade_test.go @@ -428,59 +428,61 @@ func (suite *TendermintTestSuite) TestVerifyUpgrade() { for _, tc := range testCases { tc := tc - // reset suite - suite.SetupTest() - path = ibctesting.NewPath(suite.chainA, suite.chainB) - - suite.coordinator.SetupClients(path) - - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) - revisionNumber := clienttypes.ParseChainID(clientState.ChainId) - - var err error - newChainID, err = clienttypes.SetRevisionNumber(clientState.ChainId, revisionNumber+1) - suite.Require().NoError(err) - - upgradedClient = ibctm.NewClientState(newChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod+trustingPeriod, maxClockDrift, clienttypes.NewHeight(revisionNumber+1, clientState.GetLatestHeight().GetRevisionHeight()+1), commitmenttypes.GetSDKSpecs(), upgradePath) - upgradedClient = upgradedClient.ZeroCustomFields() - upgradedClientBz, err = clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), upgradedClient) - suite.Require().NoError(err) - - upgradedConsState = &ibctm.ConsensusState{ - NextValidatorsHash: []byte("nextValsHash"), - } - upgradedConsStateBz, err = clienttypes.MarshalConsensusState(suite.chainA.App.AppCodec(), upgradedConsState) - suite.Require().NoError(err) - - tc.setup() - - cs := suite.chainA.GetClientState(path.EndpointA.ClientID) - clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) - - // Call ZeroCustomFields on upgraded clients to clear any client-chosen parameters in test-case upgradedClient - upgradedClient = upgradedClient.ZeroCustomFields() - - err = cs.VerifyUpgradeAndUpdateState( - suite.chainA.GetContext(), - suite.cdc, - clientStore, - upgradedClient, - upgradedConsState, - proofUpgradedClient, - proofUpgradedConsState, - ) - - if tc.expPass { - suite.Require().NoError(err, "verify upgrade failed on valid case: %s", tc.name) - - clientState := suite.chainA.GetClientState(path.EndpointA.ClientID) - suite.Require().NotNil(clientState, "verify upgrade failed on valid case: %s", tc.name) - - consensusState, found := suite.chainA.GetConsensusState(path.EndpointA.ClientID, clientState.GetLatestHeight()) - suite.Require().NotNil(consensusState, "verify upgrade failed on valid case: %s", tc.name) - suite.Require().True(found) - } else { - suite.Require().Error(err, "verify upgrade passed on invalid case: %s", tc.name) - } + suite.Run(tc.name, func() { + // reset suite + suite.SetupTest() + path = ibctesting.NewPath(suite.chainA, suite.chainB) + + suite.coordinator.SetupClients(path) + + clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + revisionNumber := clienttypes.ParseChainID(clientState.ChainId) + + var err error + newChainID, err = clienttypes.SetRevisionNumber(clientState.ChainId, revisionNumber+1) + suite.Require().NoError(err) + + upgradedClient = ibctm.NewClientState(newChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod+trustingPeriod, maxClockDrift, clienttypes.NewHeight(revisionNumber+1, clientState.GetLatestHeight().GetRevisionHeight()+1), commitmenttypes.GetSDKSpecs(), upgradePath) + upgradedClient = upgradedClient.ZeroCustomFields() + upgradedClientBz, err = clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), upgradedClient) + suite.Require().NoError(err) + + upgradedConsState = &ibctm.ConsensusState{ + NextValidatorsHash: []byte("nextValsHash"), + } + upgradedConsStateBz, err = clienttypes.MarshalConsensusState(suite.chainA.App.AppCodec(), upgradedConsState) + suite.Require().NoError(err) + + tc.setup() + + cs := suite.chainA.GetClientState(path.EndpointA.ClientID) + clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) + + // Call ZeroCustomFields on upgraded clients to clear any client-chosen parameters in test-case upgradedClient + upgradedClient = upgradedClient.ZeroCustomFields() + + err = cs.VerifyUpgradeAndUpdateState( + suite.chainA.GetContext(), + suite.cdc, + clientStore, + upgradedClient, + upgradedConsState, + proofUpgradedClient, + proofUpgradedConsState, + ) + + if tc.expPass { + suite.Require().NoError(err, "verify upgrade failed on valid case: %s", tc.name) + + clientState := suite.chainA.GetClientState(path.EndpointA.ClientID) + suite.Require().NotNil(clientState, "verify upgrade failed on valid case: %s", tc.name) + + consensusState, found := suite.chainA.GetConsensusState(path.EndpointA.ClientID, clientState.GetLatestHeight()) + suite.Require().NotNil(consensusState, "verify upgrade failed on valid case: %s", tc.name) + suite.Require().True(found) + } else { + suite.Require().Error(err, "verify upgrade passed on invalid case: %s", tc.name) + } + }) } } diff --git a/modules/light-clients/09-localhost/client_state_test.go b/modules/light-clients/09-localhost/client_state_test.go index 78825cb1d12..d1059fac5e2 100644 --- a/modules/light-clients/09-localhost/client_state_test.go +++ b/modules/light-clients/09-localhost/client_state_test.go @@ -64,12 +64,15 @@ func (suite *LocalhostTestSuite) TestValidate() { } for _, tc := range testCases { - err := tc.clientState.Validate() - if tc.expPass { - suite.Require().NoError(err, tc.name) - } else { - suite.Require().Error(err, tc.name) - } + tc := tc + suite.Run(tc.name, func() { + err := tc.clientState.Validate() + if tc.expPass { + suite.Require().NoError(err, tc.name) + } else { + suite.Require().Error(err, tc.name) + } + }) } } @@ -92,18 +95,21 @@ func (suite *LocalhostTestSuite) TestInitialize() { } for _, tc := range testCases { - suite.SetupTest() + tc := tc + suite.Run(tc.name, func() { + clientState := localhost.NewClientState(clienttypes.NewHeight(3, 10)) + clientStore := suite.chain.GetSimApp().GetIBCKeeper().ClientKeeper.ClientStore(suite.chain.GetContext(), exported.LocalhostClientID) - clientState := localhost.NewClientState(clienttypes.NewHeight(3, 10)) - clientStore := suite.chain.GetSimApp().GetIBCKeeper().ClientKeeper.ClientStore(suite.chain.GetContext(), exported.LocalhostClientID) + err := clientState.Initialize(suite.chain.GetContext(), suite.chain.Codec, clientStore, tc.consState) - err := clientState.Initialize(suite.chain.GetContext(), suite.chain.Codec, clientStore, tc.consState) + if tc.expPass { + suite.Require().NoError(err, "valid testcase: %s failed", tc.name) + } else { + suite.Require().Error(err, "invalid testcase: %s passed", tc.name) + } + }) + suite.SetupTest() - if tc.expPass { - suite.Require().NoError(err, "valid testcase: %s failed", tc.name) - } else { - suite.Require().Error(err, "invalid testcase: %s passed", tc.name) - } } } From 8453e74e33b34251bd41709b19e67a415824cf84 Mon Sep 17 00:00:00 2001 From: dung Date: Thu, 14 Sep 2023 07:38:11 +0700 Subject: [PATCH 4/9] nits --- modules/capability/simulation/decoder_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/capability/simulation/decoder_test.go b/modules/capability/simulation/decoder_test.go index 7885105846a..e6b9889ea10 100644 --- a/modules/capability/simulation/decoder_test.go +++ b/modules/capability/simulation/decoder_test.go @@ -50,12 +50,12 @@ func TestDecodeStore(t *testing.T) { for i, tc := range tests { i, tc := i, tc - t.Run(tt.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { switch i { case len(tests) - 1: require.Panics(t, func() { dec(kvPairs.Pairs[i], kvPairs.Pairs[i]) }, tt.name) default: - require.Equal(t, tt.expectedLog, dec(kvPairs.Pairs[i], kvPairs.Pairs[i]), tt.name) + require.Equal(t, tc.expectedLog, dec(kvPairs.Pairs[i], kvPairs.Pairs[i]), tt.name) } }) } From 74fd85e483ae38e0fc996fc082520f5730e98d8f Mon Sep 17 00:00:00 2001 From: dung Date: Thu, 14 Sep 2023 07:41:43 +0700 Subject: [PATCH 5/9] linting --- modules/apps/transfer/simulation/genesis_test.go | 7 +++++-- modules/light-clients/07-tendermint/client_state_test.go | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/apps/transfer/simulation/genesis_test.go b/modules/apps/transfer/simulation/genesis_test.go index 7a086bfed03..d5c413d135c 100644 --- a/modules/apps/transfer/simulation/genesis_test.go +++ b/modules/apps/transfer/simulation/genesis_test.go @@ -66,14 +66,17 @@ func TestRandomizedGenState1(t *testing.T) { { // panic => reason: incomplete initialization of the simState "nil pointer dereference", module.SimulationState{}, - "invalid memory address or nil pointer dereference"}, + "invalid memory address or nil pointer dereference", + }, { // panic => reason: incomplete initialization of the simState "assignment to entry in nil map", module.SimulationState{ AppParams: make(simtypes.AppParams), Cdc: cdc, Rand: r, - }, "assignment to entry in nil map"}, + }, + "assignment to entry in nil map", + }, } for _, tc := range tests { diff --git a/modules/light-clients/07-tendermint/client_state_test.go b/modules/light-clients/07-tendermint/client_state_test.go index 1f2e0aa1199..10413f1228e 100644 --- a/modules/light-clients/07-tendermint/client_state_test.go +++ b/modules/light-clients/07-tendermint/client_state_test.go @@ -66,7 +66,6 @@ func (suite *TendermintTestSuite) TestStatus() { status := clientState.Status(suite.chainA.GetContext(), clientStore, suite.chainA.App.AppCodec()) suite.Require().Equal(tc.expStatus, status) - }) } From a4fc741fb6e92e84497cb9187ec8ab2f167c6465 Mon Sep 17 00:00:00 2001 From: dung Date: Thu, 14 Sep 2023 22:39:03 +0700 Subject: [PATCH 6/9] fix variable name in capability test --- modules/capability/simulation/decoder_test.go | 4 ++-- modules/capability/simulation/genesis_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/capability/simulation/decoder_test.go b/modules/capability/simulation/decoder_test.go index e6b9889ea10..c47ce7dc9bc 100644 --- a/modules/capability/simulation/decoder_test.go +++ b/modules/capability/simulation/decoder_test.go @@ -53,9 +53,9 @@ func TestDecodeStore(t *testing.T) { t.Run(tc.name, func(t *testing.T) { switch i { case len(tests) - 1: - require.Panics(t, func() { dec(kvPairs.Pairs[i], kvPairs.Pairs[i]) }, tt.name) + require.Panics(t, func() { dec(kvPairs.Pairs[i], kvPairs.Pairs[i]) }, tc.name) default: - require.Equal(t, tc.expectedLog, dec(kvPairs.Pairs[i], kvPairs.Pairs[i]), tt.name) + require.Equal(t, tc.expectedLog, dec(kvPairs.Pairs[i], kvPairs.Pairs[i]), tc.name) } }) } diff --git a/modules/capability/simulation/genesis_test.go b/modules/capability/simulation/genesis_test.go index 7dd552fc4a0..b4176fe25d5 100644 --- a/modules/capability/simulation/genesis_test.go +++ b/modules/capability/simulation/genesis_test.go @@ -70,6 +70,6 @@ func TestRandomizedGenState1(t *testing.T) { for _, tc := range tests { tc := tc - require.Panicsf(t, func() { simulation.RandomizedGenState(&tt.simState) }, tt.panicMsg) + require.Panicsf(t, func() { simulation.RandomizedGenState(&tc.simState) }, tc.panicMsg) } } From 367067c286bbd5f7467b68b2e7a4d308d988094a Mon Sep 17 00:00:00 2001 From: nguyen <144610611+trinitys7@users.noreply.github.com> Date: Thu, 21 Sep 2023 01:17:25 +0700 Subject: [PATCH 7/9] Update modules/core/02-client/types/height_test.go Co-authored-by: Damian Nolan --- modules/core/02-client/types/height_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/02-client/types/height_test.go b/modules/core/02-client/types/height_test.go index 141b0acce9e..162b26d2b05 100644 --- a/modules/core/02-client/types/height_test.go +++ b/modules/core/02-client/types/height_test.go @@ -30,7 +30,7 @@ func TestCompareHeights(t *testing.T) { } for i, tc := range testCases { - t, tc := t, tc + i, tc := i, tc t.Run(tc.name, func(t *testing.T) { compare := tc.height1.Compare(tc.height2) From 3fb8ea28005a65cbc7c9d8fbb152b6cc1b5e5f97 Mon Sep 17 00:00:00 2001 From: nguyen <144610611+trinitys7@users.noreply.github.com> Date: Thu, 21 Sep 2023 01:17:36 +0700 Subject: [PATCH 8/9] Update modules/core/03-connection/types/version_test.go Co-authored-by: Damian Nolan --- modules/core/03-connection/types/version_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/03-connection/types/version_test.go b/modules/core/03-connection/types/version_test.go index dbdb655b79e..79a841fdb50 100644 --- a/modules/core/03-connection/types/version_test.go +++ b/modules/core/03-connection/types/version_test.go @@ -22,7 +22,7 @@ func TestValidateVersion(t *testing.T) { } for i, tc := range testCases { - t, tc := t, tc + i, tc := i, tc err := types.ValidateVersion(tc.version) From 2c4e971aafaa27e4f7ed2acd695058ecc934c645 Mon Sep 17 00:00:00 2001 From: trinitys7 Date: Thu, 21 Sep 2023 01:56:36 +0700 Subject: [PATCH 9/9] nits: fix duplicated suite.Run() --- .../apps/transfer/keeper/grpc_query_test.go | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/modules/apps/transfer/keeper/grpc_query_test.go b/modules/apps/transfer/keeper/grpc_query_test.go index 897e8fd0604..9bc4606c093 100644 --- a/modules/apps/transfer/keeper/grpc_query_test.go +++ b/modules/apps/transfer/keeper/grpc_query_test.go @@ -74,22 +74,20 @@ func (suite *KeeperTestSuite) TestQueryDenomTrace() { for _, tc := range testCases { suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { tc := tc - suite.Run(tc.msg, func() { - suite.SetupTest() // reset + suite.SetupTest() // reset - tc.malleate() - ctx := suite.chainA.GetContext() + tc.malleate() + ctx := suite.chainA.GetContext() - res, err := suite.chainA.GetSimApp().TransferKeeper.DenomTrace(ctx, req) + res, err := suite.chainA.GetSimApp().TransferKeeper.DenomTrace(ctx, req) - if tc.expPass { - suite.Require().NoError(err) - suite.Require().NotNil(res) - suite.Require().Equal(&expTrace, res.DenomTrace) - } else { - suite.Require().Error(err) - } - }) + if tc.expPass { + suite.Require().NoError(err) + suite.Require().NotNil(res) + suite.Require().Equal(&expTrace, res.DenomTrace) + } else { + suite.Require().Error(err) + } }) } }