Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hygiene :rebind loop variable and wrap the actual test logic inside in suite.Run() #4658

Merged
merged 14 commits into from
Sep 22, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,8 @@ func (suite *InterchainAccountsTestSuite) TestOnChanCloseConfirm() {
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
suite.SetupTest() // reset
isNilApp = false
Expand Down Expand Up @@ -619,6 +621,8 @@ func (suite *InterchainAccountsTestSuite) TestOnAcknowledgementPacket() {
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.msg, func() {
suite.SetupTest() // reset
isNilApp = false
Expand Down Expand Up @@ -712,6 +716,8 @@ func (suite *InterchainAccountsTestSuite) TestOnTimeoutPacket() {
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.msg, func() {
suite.SetupTest() // reset
isNilApp = false
Expand Down Expand Up @@ -775,6 +781,8 @@ func (suite *InterchainAccountsTestSuite) TestSingleHostMultipleControllers() {
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.msg, func() {
suite.SetupTest() // reset

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func (suite *KeeperTestSuite) TestQueryInterchainAccount() {
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
suite.SetupTest()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ func (suite *KeeperTestSuite) TestOnChanCloseConfirm() {
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
suite.SetupTest() // reset

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ func (suite *KeeperTestSuite) TestAssertChannelCapabilityMigrations() {
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
suite.SetupTest()

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacket() {
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.msg, func() {
suite.SetupTest() // reset

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func TestMsgRegisterInterchainAccountValidateBasic(t *testing.T) {
}

for i, tc := range testCases {
i, tc := i, tc

msg = types.NewMsgRegisterInterchainAccount(
ibctesting.FirstConnectionID,
Expand Down Expand Up @@ -137,6 +138,7 @@ func TestMsgSendTxValidateBasic(t *testing.T) {
}

for i, tc := range testCases {
i, tc := i, tc

msgBankSend := &banktypes.MsgSend{
FromAddress: ibctesting.TestAccAddress,
Expand Down Expand Up @@ -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)
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func (suite *GenesisTypesTestSuite) TestValidateGenesisState() {
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
genesisState = *genesistypes.DefaultGenesis()

Expand Down Expand Up @@ -188,6 +190,8 @@ func (suite *GenesisTypesTestSuite) TestValidateControllerGenesisState() {
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
genesisState = genesistypes.DefaultControllerGenesis()

Expand Down Expand Up @@ -311,6 +315,8 @@ func (suite *GenesisTypesTestSuite) TestValidateHostGenesisState() {
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
genesisState = genesistypes.DefaultHostGenesis()

Expand Down
2 changes: 2 additions & 0 deletions modules/apps/27-interchain-accounts/host/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ func (suite *InterchainAccountsTestSuite) TestOnChanCloseConfirm() {
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
suite.SetupTest() // reset

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions modules/apps/27-interchain-accounts/host/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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())
Expand Down
4 changes: 4 additions & 0 deletions modules/apps/27-interchain-accounts/types/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func (suite *TypesTestSuite) TestValidateAccountAddress() {
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
err := types.ValidateAccountAddress(tc.address)

Expand Down Expand Up @@ -135,6 +137,8 @@ func (suite *TypesTestSuite) TestGenesisAccountValidate() {
}

for _, tc := range testCases {
tc := tc

err := tc.acc.Validate()

if tc.expPass {
Expand Down
4 changes: 4 additions & 0 deletions modules/apps/27-interchain-accounts/types/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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)
}
Expand Down
20 changes: 20 additions & 0 deletions modules/apps/29-fee/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPackets() {
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
suite.SetupTest() // reset

Expand Down Expand Up @@ -123,6 +125,8 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPacket() {
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
suite.SetupTest() // reset

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -287,6 +293,8 @@ func (suite *KeeperTestSuite) TestQueryTotalRecvFees() {
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
suite.SetupTest() // reset

Expand Down Expand Up @@ -353,6 +361,8 @@ func (suite *KeeperTestSuite) TestQueryTotalAckFees() {
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
suite.SetupTest() // reset

Expand Down Expand Up @@ -419,6 +429,8 @@ func (suite *KeeperTestSuite) TestQueryTotalTimeoutFees() {
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
suite.SetupTest() // reset

Expand Down Expand Up @@ -492,6 +504,8 @@ func (suite *KeeperTestSuite) TestQueryPayee() {
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
suite.SetupTest() // reset

Expand Down Expand Up @@ -562,6 +576,8 @@ func (suite *KeeperTestSuite) TestQueryCounterpartyPayee() {
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
suite.SetupTest() // reset

Expand Down Expand Up @@ -674,6 +690,8 @@ func (suite *KeeperTestSuite) TestQueryFeeEnabledChannels() {
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
suite.SetupTest() // reset

Expand Down Expand Up @@ -745,6 +763,8 @@ func (suite *KeeperTestSuite) TestQueryFeeEnabledChannel() {
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
suite.SetupTest() // reset
expEnabled = true
Expand Down
4 changes: 4 additions & 0 deletions modules/apps/29-fee/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func (suite *KeeperTestSuite) TestRegisterPayee() {
}

for _, tc := range testCases {
tc := tc

suite.SetupTest()
suite.coordinator.Setup(suite.path)

Expand Down Expand Up @@ -131,6 +133,8 @@ func (suite *KeeperTestSuite) TestRegisterCounterpartyPayee() {
}

for _, tc := range testCases {
tc := tc

suite.SetupTest()
suite.coordinator.Setup(suite.path) // setup channel

Expand Down
Loading