Skip to content

Commit

Permalink
Uses child or parent app correctly in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel committed May 3, 2022
1 parent f21435d commit d94a8d1
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 97 deletions.
20 changes: 10 additions & 10 deletions x/ccv/child/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
})
}
75 changes: 38 additions & 37 deletions x/ccv/child/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()

Expand All @@ -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")
}
Expand All @@ -96,18 +97,18 @@ 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)
suite.Require().Equal(suite.parentClient, clientState, "stored client state does not match genesis parent client")
}

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)
}
Expand All @@ -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)
Expand Down Expand Up @@ -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")
}
Expand All @@ -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}
},
Expand All @@ -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}
},
Expand All @@ -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"}
},
Expand All @@ -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"}
},
Expand All @@ -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}
},
Expand All @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
24 changes: 12 additions & 12 deletions x/ccv/child/keeper/params_test.go
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
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"
)

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")
}
Loading

0 comments on commit d94a8d1

Please sign in to comment.