From d94a8d159b41c41ae77df7e1a91ee5c75b564455 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 3 May 2022 18:48:35 +0100 Subject: [PATCH] Uses child or parent app correctly in tests --- x/ccv/child/keeper/genesis_test.go | 20 +++---- x/ccv/child/keeper/keeper_test.go | 75 ++++++++++++++------------- x/ccv/child/keeper/params_test.go | 24 ++++----- x/ccv/child/keeper/relay_test.go | 38 +++++++------- x/ccv/child/keeper/validators_test.go | 4 +- x/ccv/parent/keeper/genesis_test.go | 9 ++-- x/ccv/parent/keeper/keeper_test.go | 5 +- x/ccv/parent/parent_test.go | 21 ++++---- x/ccv/parent/unbonding_hook_test.go | 3 +- 9 files changed, 102 insertions(+), 97 deletions(-) diff --git a/x/ccv/child/keeper/genesis_test.go b/x/ccv/child/keeper/genesis_test.go index 76c4245461..e138eb8e39 100644 --- a/x/ccv/child/keeper/genesis_test.go +++ b/x/ccv/child/keeper/genesis_test.go @@ -7,32 +7,32 @@ import ( clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" - parentApp "github.com/cosmos/interchain-security/app_parent" childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" parenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" "github.com/cosmos/interchain-security/x/ccv/types" + childApp "github.com/cosmos/interchain-security/app_child" abci "github.com/tendermint/tendermint/abci/types" tmtypes "github.com/tendermint/tendermint/types" ) func (suite *KeeperTestSuite) TestGenesis() { - genesis := suite.childChain.App.(*parentApp.App).ChildKeeper.ExportGenesis(suite.childChain.GetContext()) + genesis := suite.childChain.App.(*childApp.App).ChildKeeper.ExportGenesis(suite.childChain.GetContext()) suite.Require().Equal(suite.parentClient, genesis.ParentClientState) suite.Require().Equal(suite.parentConsState, genesis.ParentConsensusState) suite.Require().NotPanics(func() { - suite.childChain.App.(*parentApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), genesis) + suite.childChain.App.(*childApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), genesis) // reset suite to reset parent client suite.SetupTest() }) ctx := suite.childChain.GetContext() - portId := suite.childChain.App.(*parentApp.App).ChildKeeper.GetPort(ctx) + portId := suite.childChain.App.(*childApp.App).ChildKeeper.GetPort(ctx) suite.Require().Equal(childtypes.PortID, portId) - clientId, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentClient(ctx) + clientId, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentClient(ctx) suite.Require().True(ok) clientState, ok := suite.childChain.App.GetIBCKeeper().ClientKeeper.GetClientState(ctx, clientId) suite.Require().True(ok) @@ -62,25 +62,25 @@ func (suite *KeeperTestSuite) TestGenesis() { ) packet := channeltypes.NewPacket(pd.GetBytes(), 1, parenttypes.PortID, suite.path.EndpointB.ChannelID, childtypes.PortID, suite.path.EndpointA.ChannelID, clienttypes.NewHeight(1, 0), 0) - suite.childChain.App.(*parentApp.App).ChildKeeper.OnRecvPacket(suite.childChain.GetContext(), packet, pd) + suite.childChain.App.(*childApp.App).ChildKeeper.OnRecvPacket(suite.childChain.GetContext(), packet, pd) // mocking the fact that child chain validators should be parent chain validators // TODO: Fix testing suite so we can initialize both chains with the same validator set valUpdates := tmtypes.TM2PB.ValidatorUpdates(suite.parentChain.Vals) - restartGenesis := suite.childChain.App.(*parentApp.App).ChildKeeper.ExportGenesis(suite.childChain.GetContext()) + restartGenesis := suite.childChain.App.(*childApp.App).ChildKeeper.ExportGenesis(suite.childChain.GetContext()) restartGenesis.InitialValSet = valUpdates // ensure reset genesis is set correctly parentChannel := suite.path.EndpointA.ChannelID suite.Require().Equal(parentChannel, restartGenesis.ParentChannelId) - unbondingTime := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.childChain.GetContext(), 1) + unbondingTime := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.childChain.GetContext(), 1) suite.Require().Equal(uint64(origTime.Add(childtypes.UnbondingTime).UnixNano()), unbondingTime, "unbonding time is not set correctly in genesis") - unbondingPacket, err := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingPacket(suite.childChain.GetContext(), 1) + unbondingPacket, err := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingPacket(suite.childChain.GetContext(), 1) suite.Require().NoError(err) suite.Require().Equal(&packet, unbondingPacket, "unbonding packet is not set correctly in genesis") suite.Require().NotPanics(func() { - suite.childChain.App.(*parentApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), restartGenesis) + suite.childChain.App.(*childApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), restartGenesis) }) } diff --git a/x/ccv/child/keeper/keeper_test.go b/x/ccv/child/keeper/keeper_test.go index d3086b0e83..9ef38abe98 100644 --- a/x/ccv/child/keeper/keeper_test.go +++ b/x/ccv/child/keeper/keeper_test.go @@ -12,6 +12,7 @@ import ( commitmenttypes "github.com/cosmos/ibc-go/v3/modules/core/23-commitment/types" ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" + childApp "github.com/cosmos/interchain-security/app_child" parentApp "github.com/cosmos/interchain-security/app_parent" "github.com/cosmos/interchain-security/testutil/simapp" "github.com/cosmos/interchain-security/x/ccv/child/types" @@ -63,7 +64,7 @@ func (suite *KeeperTestSuite) SetupTest() { params := childtypes.DefaultParams() params.Enabled = true childGenesis := types.NewInitialGenesisState(suite.parentClient, suite.parentConsState, valUpdates, params) - suite.childChain.App.(*parentApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) + suite.childChain.App.(*childApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) suite.ctx = suite.childChain.GetContext() @@ -74,7 +75,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.path.EndpointB.ChannelConfig.Version = ccv.Version suite.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED suite.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - parentClient, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentClient(suite.ctx) + parentClient, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentClient(suite.ctx) if !ok { panic("must already have parent client on child chain") } @@ -96,7 +97,7 @@ func (suite *KeeperTestSuite) SetupCCVChannel() { } func (suite *KeeperTestSuite) TestParentClient() { - parentClient, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentClient(suite.ctx) + parentClient, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentClient(suite.ctx) suite.Require().True(ok) clientState, ok := suite.childChain.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.ctx, parentClient) @@ -104,10 +105,10 @@ func (suite *KeeperTestSuite) TestParentClient() { } func (suite *KeeperTestSuite) TestParentChannel() { - _, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentChannel(suite.ctx) + _, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentChannel(suite.ctx) suite.Require().False(ok) - suite.childChain.App.(*parentApp.App).ChildKeeper.SetParentChannel(suite.ctx, "channelID") - channelID, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentChannel(suite.ctx) + suite.childChain.App.(*childApp.App).ChildKeeper.SetParentChannel(suite.ctx, "channelID") + channelID, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentChannel(suite.ctx) suite.Require().True(ok) suite.Require().Equal("channelID", channelID) } @@ -133,34 +134,34 @@ func (suite *KeeperTestSuite) TestPendingChanges() { nil, ) - suite.childChain.App.(*parentApp.App).ChildKeeper.SetPendingChanges(suite.ctx, pd) - gotPd, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetPendingChanges(suite.ctx) + suite.childChain.App.(*childApp.App).ChildKeeper.SetPendingChanges(suite.ctx, pd) + gotPd, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetPendingChanges(suite.ctx) suite.Require().True(ok) suite.Require().Equal(&pd, gotPd, "packet data in store does not equal packet data set") - suite.childChain.App.(*parentApp.App).ChildKeeper.DeletePendingChanges(suite.ctx) - gotPd, ok = suite.childChain.App.(*parentApp.App).ChildKeeper.GetPendingChanges(suite.ctx) + suite.childChain.App.(*childApp.App).ChildKeeper.DeletePendingChanges(suite.ctx) + gotPd, ok = suite.childChain.App.(*childApp.App).ChildKeeper.GetPendingChanges(suite.ctx) suite.Require().False(ok) suite.Require().Nil(gotPd, "got non-nil pending changes after Delete") } func (suite *KeeperTestSuite) TestUnbondingTime() { - suite.childChain.App.(*parentApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 1, 10) - suite.childChain.App.(*parentApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 2, 25) - suite.childChain.App.(*parentApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 5, 15) - suite.childChain.App.(*parentApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 6, 40) + suite.childChain.App.(*childApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 1, 10) + suite.childChain.App.(*childApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 2, 25) + suite.childChain.App.(*childApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 5, 15) + suite.childChain.App.(*childApp.App).ChildKeeper.SetUnbondingTime(suite.ctx, 6, 40) - suite.childChain.App.(*parentApp.App).ChildKeeper.DeleteUnbondingTime(suite.ctx, 6) + suite.childChain.App.(*childApp.App).ChildKeeper.DeleteUnbondingTime(suite.ctx, 6) - suite.Require().Equal(uint64(10), suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 1)) - suite.Require().Equal(uint64(25), suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 2)) - suite.Require().Equal(uint64(15), suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 5)) - suite.Require().Equal(uint64(0), suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 3)) - suite.Require().Equal(uint64(0), suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 6)) + suite.Require().Equal(uint64(10), suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 1)) + suite.Require().Equal(uint64(25), suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 2)) + suite.Require().Equal(uint64(15), suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 5)) + suite.Require().Equal(uint64(0), suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 3)) + suite.Require().Equal(uint64(0), suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 6)) orderedTimes := [][]uint64{{1, 10}, {2, 25}, {5, 15}} i := 0 - suite.childChain.App.(*parentApp.App).ChildKeeper.IterateUnbondingTime(suite.ctx, func(seq, time uint64) bool { + suite.childChain.App.(*childApp.App).ChildKeeper.IterateUnbondingTime(suite.ctx, func(seq, time uint64) bool { // require that we iterate through unbonding time in order of sequence suite.Require().Equal(orderedTimes[i][0], seq) suite.Require().Equal(orderedTimes[i][1], time) @@ -192,22 +193,22 @@ func (suite *KeeperTestSuite) TestUnbondingPacket() { ) packet := channeltypes.NewPacket(pd.GetBytes(), uint64(i), "parent", "channel-1", "child", "channel-1", clienttypes.NewHeight(1, 0), 0) - suite.childChain.App.(*parentApp.App).ChildKeeper.SetUnbondingPacket(suite.ctx, uint64(i), packet) + suite.childChain.App.(*childApp.App).ChildKeeper.SetUnbondingPacket(suite.ctx, uint64(i), packet) } // ensure that packets are iterated by sequence i := 0 - suite.childChain.App.(*parentApp.App).ChildKeeper.IterateUnbondingPacket(suite.ctx, func(seq uint64, packet channeltypes.Packet) bool { + suite.childChain.App.(*childApp.App).ChildKeeper.IterateUnbondingPacket(suite.ctx, func(seq uint64, packet channeltypes.Packet) bool { suite.Require().Equal(uint64(i), seq) - gotPacket, err := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, seq) + gotPacket, err := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, seq) suite.Require().NoError(err) suite.Require().Equal(&packet, gotPacket, "packet from get and iteration do not match") i++ return false }) - suite.childChain.App.(*parentApp.App).ChildKeeper.DeleteUnbondingPacket(suite.ctx, 0) - gotPacket, err := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 0) + suite.childChain.App.(*childApp.App).ChildKeeper.DeleteUnbondingPacket(suite.ctx, 0) + gotPacket, err := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 0) suite.Require().Error(err) suite.Require().Nil(gotPacket, "packet is not nil after delete") } @@ -230,7 +231,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to INITIALIZING - suite.childChain.App.(*parentApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.childChain.App.(*childApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID} }, @@ -246,7 +247,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to validating - suite.childChain.App.(*parentApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.VALIDATING) + suite.childChain.App.(*childApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.VALIDATING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID} }, @@ -261,7 +262,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to INITIALIZING - suite.childChain.App.(*parentApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.childChain.App.(*childApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID, "connection-2"} }, @@ -271,7 +272,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { name: "connection does not exist", setup: func(suite *KeeperTestSuite) { // set channel status to INITIALIZING - suite.childChain.App.(*parentApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.childChain.App.(*childApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{"connection-dne"} }, @@ -289,7 +290,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { suite.coordinator.CreateConnections(suite.path) // set channel status to INITIALIZING - suite.childChain.App.(*parentApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) + suite.childChain.App.(*childApp.App).ChildKeeper.SetChannelStatus(suite.ctx, channelID, ccv.INITIALIZING) // set connection hops to be connection hop from path endpoint connectionHops = []string{suite.path.EndpointA.ConnectionID} }, @@ -305,7 +306,7 @@ func (suite *KeeperTestSuite) TestVerifyParentChain() { tc.setup(suite) // Verify ParentChain on child chain using path returned by setup - err := suite.childChain.App.(*parentApp.App).ChildKeeper.VerifyParentChain(suite.ctx, channelID, connectionHops) + err := suite.childChain.App.(*childApp.App).ChildKeeper.VerifyParentChain(suite.ctx, channelID, connectionHops) if tc.expError { suite.Require().Error(err, "invalid case did not return error") @@ -324,7 +325,7 @@ func (suite *KeeperTestSuite) TestValidatorDowntime() { suite.SetupCCVChannel() suite.SendEmptyVSCPacket() - app, ctx := suite.childChain.App.(*parentApp.App), suite.childChain.GetContext() + app, ctx := suite.childChain.App.(*childApp.App), suite.childChain.GetContext() channelID := suite.path.EndpointA.ChannelID // pick a cross-chain validator @@ -392,7 +393,7 @@ func (suite *KeeperTestSuite) TestValidatorDowntime() { func (suite *KeeperTestSuite) TestPendingSlashRequestsLogic() { suite.SetupCCVChannel() - app := suite.childChain.App.(*parentApp.App) + app := suite.childChain.App.(*childApp.App) ctx := suite.childChain.GetContext() channelID := suite.path.EndpointA.ChannelID @@ -457,7 +458,7 @@ func (suite *KeeperTestSuite) TestPendingSlashRequestsLogic() { } func (suite *KeeperTestSuite) TestCrossChainValidator() { - app := suite.childChain.App.(*parentApp.App) + app := suite.childChain.App.(*childApp.App) ctx := suite.childChain.GetContext() // should return false @@ -484,7 +485,7 @@ func (suite *KeeperTestSuite) TestCrossChainValidator() { } func (suite *KeeperTestSuite) TestPendingSlashRequests() { - childKeeper := suite.childChain.App.(*parentApp.App).ChildKeeper + childKeeper := suite.childChain.App.(*childApp.App).ChildKeeper ctx := suite.childChain.GetContext() // prepare test setup by storing 10 pending slash requests @@ -521,7 +522,7 @@ func (suite *KeeperTestSuite) TestPendingSlashRequests() { // to ensure that the channel gets established func (suite *KeeperTestSuite) SendEmptyVSCPacket() { - childKeeper := suite.childChain.App.(*parentApp.App).ChildKeeper + childKeeper := suite.childChain.App.(*childApp.App).ChildKeeper parentKeeper := suite.parentChain.App.(*parentApp.App).ParentKeeper oldBlockTime := suite.parentChain.GetContext().BlockTime() diff --git a/x/ccv/child/keeper/params_test.go b/x/ccv/child/keeper/params_test.go index 1325bb8517..b2f92ef164 100644 --- a/x/ccv/child/keeper/params_test.go +++ b/x/ccv/child/keeper/params_test.go @@ -1,7 +1,7 @@ package keeper_test import ( - parentApp "github.com/cosmos/interchain-security/app_parent" + childApp "github.com/cosmos/interchain-security/app_child" "github.com/cosmos/interchain-security/x/ccv/child/types" ) @@ -9,35 +9,35 @@ func (suite *KeeperTestSuite) TestParams() { // suite setup initializes genesis expParams := types.NewParams(true, 1000, "", "", "0") // these are the default params - params := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParams(suite.childChain.GetContext()) + params := suite.childChain.App.(*childApp.App).ChildKeeper.GetParams(suite.childChain.GetContext()) suite.Require().Equal(expParams, params) newParams := types.NewParams(false, 1000, "abc", "def", "0.6") - suite.childChain.App.(*parentApp.App).ChildKeeper.SetParams(suite.childChain.GetContext(), newParams) - params = suite.childChain.App.(*parentApp.App).ChildKeeper.GetParams(suite.childChain.GetContext()) + suite.childChain.App.(*childApp.App).ChildKeeper.SetParams(suite.childChain.GetContext(), newParams) + params = suite.childChain.App.(*childApp.App).ChildKeeper.GetParams(suite.childChain.GetContext()) suite.Require().Equal(newParams, params) - suite.childChain.App.(*parentApp.App).ChildKeeper. + suite.childChain.App.(*childApp.App).ChildKeeper. SetBlocksPerDistributionTransmission(suite.childChain.GetContext(), 10) - gotBPDT := suite.childChain.App.(*parentApp.App).ChildKeeper. + gotBPDT := suite.childChain.App.(*childApp.App).ChildKeeper. GetBlocksPerDistributionTransmission(suite.childChain.GetContext()) suite.Require().Equal(gotBPDT, int64(10)) - suite.childChain.App.(*parentApp.App).ChildKeeper. + suite.childChain.App.(*childApp.App).ChildKeeper. SetDistributionTransmissionChannel(suite.childChain.GetContext(), "foobarbaz") - gotChan := suite.childChain.App.(*parentApp.App).ChildKeeper. + gotChan := suite.childChain.App.(*childApp.App).ChildKeeper. GetDistributionTransmissionChannel(suite.childChain.GetContext()) suite.Require().Equal(gotChan, "foobarbaz") - suite.childChain.App.(*parentApp.App).ChildKeeper. + suite.childChain.App.(*childApp.App).ChildKeeper. SetProviderFeePoolAddrStr(suite.childChain.GetContext(), "foobar") - gotAddr := suite.childChain.App.(*parentApp.App).ChildKeeper. + gotAddr := suite.childChain.App.(*childApp.App).ChildKeeper. GetProviderFeePoolAddrStr(suite.childChain.GetContext()) suite.Require().Equal(gotAddr, "foobar") - suite.childChain.App.(*parentApp.App).ChildKeeper. + suite.childChain.App.(*childApp.App).ChildKeeper. SetConsumerRedistributeFrac(suite.childChain.GetContext(), "0.75") - gotFrac := suite.childChain.App.(*parentApp.App).ChildKeeper. + gotFrac := suite.childChain.App.(*childApp.App).ChildKeeper. GetConsumerRedistributeFrac(suite.childChain.GetContext()) suite.Require().Equal(gotFrac, "0.75") } diff --git a/x/ccv/child/keeper/relay_test.go b/x/ccv/child/keeper/relay_test.go index c69c2a6723..aeda3eba7e 100644 --- a/x/ccv/child/keeper/relay_test.go +++ b/x/ccv/child/keeper/relay_test.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" - parentApp "github.com/cosmos/interchain-security/app_parent" + childApp "github.com/cosmos/interchain-security/app_child" childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" parenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" "github.com/cosmos/interchain-security/x/ccv/types" @@ -117,22 +117,22 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { } for _, tc := range testCases { - ack := suite.childChain.App.(*parentApp.App).ChildKeeper.OnRecvPacket(suite.ctx, tc.packet, tc.newChanges) + ack := suite.childChain.App.(*childApp.App).ChildKeeper.OnRecvPacket(suite.ctx, tc.packet, tc.newChanges) if tc.expErrorAck { suite.Require().NotNil(ack, "invalid test case: %s did not return ack", tc.name) suite.Require().False(ack.Success(), "invalid test case: %s did not return an Error Acknowledgment") } else { suite.Require().Nil(ack, "successful packet must send ack asynchronously. case: %s", tc.name) - suite.Require().Equal(ccv.VALIDATING, suite.childChain.App.(*parentApp.App).ChildKeeper.GetChannelStatus(suite.ctx, suite.path.EndpointA.ChannelID), + suite.Require().Equal(ccv.VALIDATING, suite.childChain.App.(*childApp.App).ChildKeeper.GetChannelStatus(suite.ctx, suite.path.EndpointA.ChannelID), "channel status is not valdidating after receive packet for valid test case: %s", tc.name) - parentChannel, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentChannel(suite.ctx) + parentChannel, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentChannel(suite.ctx) suite.Require().True(ok) suite.Require().Equal(tc.packet.DestinationChannel, parentChannel, "parent channel is not destination channel on successful receive for valid test case: %s", tc.name) // Check that pending changes are accumulated and stored correctly - actualPendingChanges, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetPendingChanges(suite.ctx) + actualPendingChanges, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetPendingChanges(suite.ctx) suite.Require().True(ok) // Sort to avoid dumb inequalities sort.SliceStable(actualPendingChanges.ValidatorUpdates, func(i, j int) bool { @@ -144,9 +144,9 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { suite.Require().Equal(tc.expectedPendingChanges, *actualPendingChanges, "pending changes not equal to expected changes after successful packet receive. case: %s", tc.name) expectedTime := uint64(suite.ctx.BlockTime().Add(childtypes.UnbondingTime).UnixNano()) - unbondingTime := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, tc.packet.Sequence) + unbondingTime := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, tc.packet.Sequence) suite.Require().Equal(expectedTime, unbondingTime, "unbonding time has unexpected value for case: %s", tc.name) - unbondingPacket, err := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, tc.packet.Sequence) + unbondingPacket, err := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, tc.packet.Sequence) suite.Require().NoError(err) suite.Require().Equal(&tc.packet, unbondingPacket, "packet is not added to unbonding queue after successful receive. case: %s", tc.name) } @@ -183,7 +183,7 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { // send first packet packet := channeltypes.NewPacket(pd.GetBytes(), 1, parenttypes.PortID, suite.path.EndpointB.ChannelID, childtypes.PortID, suite.path.EndpointA.ChannelID, clienttypes.NewHeight(1, 0), 0) - ack := suite.childChain.App.(*parentApp.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) + ack := suite.childChain.App.(*childApp.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) suite.Require().Nil(ack) // update time and send second packet @@ -191,7 +191,7 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { pd.ValidatorUpdates[0].Power = 15 packet.Data = pd.GetBytes() packet.Sequence = 2 - ack = suite.childChain.App.(*parentApp.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) + ack = suite.childChain.App.(*childApp.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) suite.Require().Nil(ack) // update time and send third packet @@ -199,25 +199,25 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { pd.ValidatorUpdates[1].Power = 40 packet.Data = pd.GetBytes() packet.Sequence = 3 - ack = suite.childChain.App.(*parentApp.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) + ack = suite.childChain.App.(*childApp.App).ChildKeeper.OnRecvPacket(suite.ctx, packet, pd) suite.Require().Nil(ack) // move ctx time forward such that first two packets are unbonded but third is not. suite.ctx = suite.ctx.WithBlockTime(origTime.Add(childtypes.UnbondingTime).Add(3 * time.Hour)) - suite.childChain.App.(*parentApp.App).ChildKeeper.UnbondMaturePackets(suite.ctx) + suite.childChain.App.(*childApp.App).ChildKeeper.UnbondMaturePackets(suite.ctx) // ensure first two packets are unbonded and acknowledgement is written // unbonded time is deleted - time1 := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 1) - time2 := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 2) + time1 := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 1) + time2 := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 2) suite.Require().Equal(uint64(0), time1, "unbonding time not deleted for mature packet 1") suite.Require().Equal(uint64(0), time2, "unbonding time not deleted for mature packet 2") // unbonded packets are deleted - _, err = suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 1) + _, err = suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 1) suite.Require().Error(err, "retrieved unbonding packet for matured packet 1") - _, err = suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 2) + _, err = suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 2) suite.Require().Error(err, "retrieved unbonding packet for matured packet 1") expectedWriteAckBytes := channeltypes.CommitAcknowledgement(channeltypes.NewResultAcknowledgement([]byte{byte(1)}).Acknowledgement()) @@ -231,9 +231,9 @@ func (suite *KeeperTestSuite) TestUnbondMaturePackets() { suite.Require().Equal(expectedWriteAckBytes, ackBytes2, "did not write successful ack for matue packet 1") // ensure that third packet did not get ack written and is still in store - time3 := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 3) + time3 := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingTime(suite.ctx, 3) suite.Require().True(time3 > uint64(suite.ctx.BlockTime().UnixNano()), "Unbonding time for packet 3 is not after current time") - packet3, err := suite.childChain.App.(*parentApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 3) + packet3, err := suite.childChain.App.(*childApp.App).ChildKeeper.GetUnbondingPacket(suite.ctx, 3) suite.Require().NoError(err, "retrieving unbonding packet 3 returned error") suite.Require().Equal(&packet, packet3, "unbonding packet 3 has unexpected value") @@ -254,12 +254,12 @@ func (suite *KeeperTestSuite) TestOnAcknowledgement() { ack := channeltypes.NewResultAcknowledgement([]byte{1}) // expect no error - err := suite.childChain.App.(*parentApp.App).ChildKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) + err := suite.childChain.App.(*childApp.App).ChildKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) suite.Nil(err) // expect an error ack = channeltypes.NewErrorAcknowledgement("error") - err = suite.childChain.App.(*parentApp.App).ChildKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) + err = suite.childChain.App.(*childApp.App).ChildKeeper.OnAcknowledgementPacket(suite.ctx, packet, packetData, ack) suite.NotNil(err) } diff --git a/x/ccv/child/keeper/validators_test.go b/x/ccv/child/keeper/validators_test.go index 83528c6ca7..441dff1b91 100644 --- a/x/ccv/child/keeper/validators_test.go +++ b/x/ccv/child/keeper/validators_test.go @@ -1,14 +1,14 @@ package keeper_test import ( - parentApp "github.com/cosmos/interchain-security/app_parent" + childApp "github.com/cosmos/interchain-security/app_child" "github.com/cosmos/interchain-security/x/ccv/child/types" abci "github.com/tendermint/tendermint/abci/types" tmtypes "github.com/tendermint/tendermint/types" ) func (k KeeperTestSuite) TestApplyCCValidatorChanges() { - childKeeper := k.childChain.App.(*parentApp.App).ChildKeeper + childKeeper := k.childChain.App.(*childApp.App).ChildKeeper ctx := k.ctx // utility functions diff --git a/x/ccv/parent/keeper/genesis_test.go b/x/ccv/parent/keeper/genesis_test.go index 560b5a2b10..a9219efc89 100644 --- a/x/ccv/parent/keeper/genesis_test.go +++ b/x/ccv/parent/keeper/genesis_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "fmt" + childApp "github.com/cosmos/interchain-security/app_child" parentApp "github.com/cosmos/interchain-security/app_parent" "github.com/cosmos/interchain-security/x/ccv/types" ) @@ -18,20 +19,20 @@ func (suite *KeeperTestSuite) TestGenesis() { genState := suite.parentChain.App.(*parentApp.App).ParentKeeper.ExportGenesis(suite.parentChain.GetContext()) - suite.childChain.App.(*parentApp.App).ParentKeeper.InitGenesis(suite.childChain.GetContext(), genState) + suite.childChain.App.(*childApp.App).ParentKeeper.InitGenesis(suite.childChain.GetContext(), genState) ctx = suite.childChain.GetContext() for i := 0; i < 4; i++ { expectedChainId := fmt.Sprintf("chainid-%d", i) expectedChannelId := fmt.Sprintf("channelid-%d", i) - channelID, channelOk := suite.childChain.App.(*parentApp.App).ParentKeeper.GetChainToChannel(ctx, expectedChainId) - chainID, chainOk := suite.childChain.App.(*parentApp.App).ParentKeeper.GetChannelToChain(ctx, expectedChannelId) + channelID, channelOk := suite.childChain.App.(*childApp.App).ParentKeeper.GetChainToChannel(ctx, expectedChainId) + chainID, chainOk := suite.childChain.App.(*childApp.App).ParentKeeper.GetChannelToChain(ctx, expectedChannelId) suite.Require().True(channelOk) suite.Require().True(chainOk) suite.Require().Equal(expectedChainId, chainID, "did not store correct chain id for given channel id") suite.Require().Equal(expectedChannelId, channelID, "did not store correct channel id for given chain id") - status := suite.childChain.App.(*parentApp.App).ParentKeeper.GetChannelStatus(ctx, channelID) + status := suite.childChain.App.(*childApp.App).ParentKeeper.GetChannelStatus(ctx, channelID) suite.Require().Equal(types.Status(i), status, "status is unexpected for given channel id: %s", channelID) } } diff --git a/x/ccv/parent/keeper/keeper_test.go b/x/ccv/parent/keeper/keeper_test.go index 696e3a49a2..556332fed6 100644 --- a/x/ccv/parent/keeper/keeper_test.go +++ b/x/ccv/parent/keeper/keeper_test.go @@ -11,6 +11,7 @@ import ( ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" + childApp "github.com/cosmos/interchain-security/app_child" parentApp "github.com/cosmos/interchain-security/app_parent" "github.com/cosmos/interchain-security/testutil/simapp" childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" @@ -65,7 +66,7 @@ func (suite *KeeperTestSuite) SetupTest() { params := childtypes.DefaultParams() params.Enabled = true childGenesis := childtypes.NewInitialGenesisState(suite.parentClient, suite.parentConsState, valUpdates, params) - suite.childChain.App.(*parentApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) + suite.childChain.App.(*childApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) suite.ctx = suite.parentChain.GetContext() @@ -76,7 +77,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.path.EndpointB.ChannelConfig.Version = types.Version suite.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED suite.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - parentClient, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) + parentClient, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) if !ok { panic("must already have parent client on child chain") } diff --git a/x/ccv/parent/parent_test.go b/x/ccv/parent/parent_test.go index 18d7ff03c0..4718b337c3 100644 --- a/x/ccv/parent/parent_test.go +++ b/x/ccv/parent/parent_test.go @@ -22,6 +22,7 @@ import ( ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" + childApp "github.com/cosmos/interchain-security/app_child" parentApp "github.com/cosmos/interchain-security/app_parent" "github.com/cosmos/interchain-security/testutil/simapp" childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" @@ -85,7 +86,7 @@ func (suite *ParentTestSuite) SetupTest() { "0.5", // 50% ) childGenesis := childtypes.NewInitialGenesisState(suite.parentClient, suite.parentConsState, valUpdates, params) - suite.childChain.App.(*parentApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) + suite.childChain.App.(*childApp.App).ChildKeeper.InitGenesis(suite.childChain.GetContext(), childGenesis) suite.ctx = suite.parentChain.GetContext() @@ -96,7 +97,7 @@ func (suite *ParentTestSuite) SetupTest() { suite.path.EndpointB.ChannelConfig.Version = types.Version suite.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED suite.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - parentClient, ok := suite.childChain.App.(*parentApp.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) + parentClient, ok := suite.childChain.App.(*childApp.App).ChildKeeper.GetParentClient(suite.childChain.GetContext()) if !ok { panic("must already have parent client on child chain") } @@ -133,7 +134,7 @@ func (suite *ParentTestSuite) SetupCCVChannel() { suite.transferPath.EndpointB.ConnectionID = suite.path.EndpointB.ConnectionID // INIT step for transfer path has already been called during CCV channel setup - suite.transferPath.EndpointA.ChannelID = suite.childChain.App.(*parentApp.App). + suite.transferPath.EndpointA.ChannelID = suite.childChain.App.(*childApp.App). ChildKeeper.GetDistributionTransmissionChannel(suite.childChain.GetContext()) // Complete TRY, ACK, CONFIRM for transfer path @@ -209,7 +210,7 @@ func (s *ParentTestSuite) TestPacketRoundtrip() { // - End consumer unbonding period childCtx := s.childCtx().WithBlockTime(origTime.Add(childtypes.UnbondingTime).Add(3 * time.Hour)) // TODO: why doesn't this work: s.childChain.App.EndBlock(abci.RequestEndBlock{}) - err = s.childChain.App.(*parentApp.App).ChildKeeper.UnbondMaturePackets(childCtx) + err = s.childChain.App.(*childApp.App).ChildKeeper.UnbondMaturePackets(childCtx) s.Require().NoError(err) // commit child chain and update parent chain client @@ -244,7 +245,7 @@ func (s *ParentTestSuite) TestSendDowntimePacket() { parentStakingKeeper := s.parentChain.App.GetStakingKeeper() parentSlashingKeeper := s.parentChain.App.(*parentApp.App).SlashingKeeper - childKeeper := s.childChain.App.(*parentApp.App).ChildKeeper + childKeeper := s.childChain.App.(*childApp.App).ChildKeeper // get a cross-chain validator address, pubkey and balance tmVals := s.childChain.Vals.Validators @@ -287,7 +288,7 @@ func (s *ParentTestSuite) TestSendDowntimePacket() { s.Require().NoError(err) // Set outstanding slashing flag - s.childChain.App.(*parentApp.App).ChildKeeper.SetOutstandingDowntime(s.childCtx(), consAddr) + s.childChain.App.(*childApp.App).ChildKeeper.SetOutstandingDowntime(s.childCtx(), consAddr) // save next VSC packet info oldBlockTime = s.parentCtx().BlockTime() @@ -351,7 +352,7 @@ func (s *ParentTestSuite) TestSendDowntimePacket() { s.Require().True(valSignInfo.JailedUntil.After(s.parentCtx().BlockHeader().Time)) // check that the outstanding slashing flag is reset on the child - pFlag := s.childChain.App.(*parentApp.App).ChildKeeper.OutstandingDowntime(s.childCtx(), consAddr) + pFlag := s.childChain.App.(*childApp.App).ChildKeeper.OutstandingDowntime(s.childCtx(), consAddr) s.Require().False(pFlag) // check that slashing packet gets acknowledged @@ -555,7 +556,7 @@ func (s *ParentTestSuite) TestHandleConsumerDowntimeErrors() { func (s *ParentTestSuite) TestslashingPacketAcknowldgement() { parentKeeper := s.parentChain.App.(*parentApp.App).ParentKeeper - childKeeper := s.childChain.App.(*parentApp.App).ChildKeeper + childKeeper := s.childChain.App.(*childApp.App).ChildKeeper packet := channeltypes.NewPacket([]byte{}, 1, childtypes.PortID, s.path.EndpointA.ChannelID, parenttypes.PortID, "wrongchannel", clienttypes.Height{}, 0) @@ -612,7 +613,7 @@ func (s *ParentTestSuite) UpdateChildHistInfo(changes []abci.ValidatorUpdate) { func (s *ParentTestSuite) DisableConsumerDistribution() { cChain := s.childChain - cApp := cChain.App.(*parentApp.App) + cApp := cChain.App.(*childApp.App) for i, moduleName := range cApp.MM.OrderBeginBlockers { if moduleName == distrtypes.ModuleName { cApp.MM.OrderBeginBlockers = append(cApp.MM.OrderBeginBlockers[:i], cApp.MM.OrderBeginBlockers[i+1:]...) @@ -650,7 +651,7 @@ func (s *ParentTestSuite) TestDistribution() { // s.transferPath.EndpointB == Provider Chain pChain, cChain := s.parentChain, s.childChain - pApp, cApp := pChain.App.(*parentApp.App), cChain.App.(*parentApp.App) + pApp, cApp := pChain.App.(*parentApp.App), cChain.App.(*childApp.App) cKeep := cApp.ChildKeeper // Get the receiving fee pool on the provider chain diff --git a/x/ccv/parent/unbonding_hook_test.go b/x/ccv/parent/unbonding_hook_test.go index fc42cc5667..629d2a8fc8 100644 --- a/x/ccv/parent/unbonding_hook_test.go +++ b/x/ccv/parent/unbonding_hook_test.go @@ -11,6 +11,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" + childApp "github.com/cosmos/interchain-security/app_child" parentApp "github.com/cosmos/interchain-security/app_parent" childtypes "github.com/cosmos/interchain-security/x/ccv/child/types" parenttypes "github.com/cosmos/interchain-security/x/ccv/parent/types" @@ -204,7 +205,7 @@ func endChildUnbondingPeriod(s *ParentTestSuite, origTime time.Time) { // - End consumer unbonding period childCtx := s.childCtx().WithBlockTime(origTime.Add(childtypes.UnbondingTime).Add(3 * time.Hour)) // s.childChain.App.EndBlock(abci.RequestEndBlock{}) // <- this doesn't work because we can't modify the ctx - err := s.childChain.App.(*parentApp.App).ChildKeeper.UnbondMaturePackets(childCtx) + err := s.childChain.App.(*childApp.App).ChildKeeper.UnbondMaturePackets(childCtx) s.Require().NoError(err) }