Skip to content

Commit

Permalink
finalize tests & app go: tests are passing
Browse files Browse the repository at this point in the history
  • Loading branch information
quasisamurai committed Sep 5, 2024
1 parent 1969117 commit ae40a29
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 150 deletions.
2 changes: 0 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1710,8 +1710,6 @@ func (app *App) WireICS20PreWasmKeeper(

app.PFMKeeper.SetTransferKeeper(app.TransferKeeper.Keeper)

// app.RawIcs20TransferAppModule = transfer.NewAppModule(*appKeepers.TransferKeeper) ??

// Packet Forward Middleware
// Initialize packet forward middleware router
var ibcStack ibcporttypes.IBCModule = packetforward.NewIBCMiddleware(
Expand Down
55 changes: 50 additions & 5 deletions testutil/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,19 @@ type IBCConnectionTestSuite struct {
ChainProvider *ibctesting.TestChain
ChainA *ibctesting.TestChain
ChainB *ibctesting.TestChain
ChainC *ibctesting.TestChain

ProviderApp e2e.ProviderApp
ChainAApp e2e.ConsumerApp
ChainBApp e2e.ConsumerApp

CCVPathA *ibctesting.Path
CCVPathB *ibctesting.Path
Path *ibctesting.Path
TransferPath *ibctesting.Path
ChainCApp e2e.ConsumerApp

CCVPathA *ibctesting.Path
CCVPathB *ibctesting.Path
CCVPathC *ibctesting.Path
Path *ibctesting.Path
TransferPath *ibctesting.Path
TransferPathAC *ibctesting.Path
}

func GetTestConsumerAdditionProp(chain *ibctesting.TestChain) *providertypes.ConsumerAdditionProposal { //nolint:staticcheck
Expand Down Expand Up @@ -140,34 +144,41 @@ func (suite *IBCConnectionTestSuite) SetupTest() {
suite.ChainProvider = suite.Coordinator.GetChain(ibctesting.GetChainID(1))
suite.ChainA = suite.Coordinator.GetChain(ibctesting.GetChainID(2))
suite.ChainB = suite.Coordinator.GetChain(ibctesting.GetChainID(3))
suite.ChainC = suite.Coordinator.GetChain(ibctesting.GetChainID(4))
suite.ProviderApp = suite.ChainProvider.App.(*appProvider.App)
suite.ChainAApp = suite.ChainA.App.(*app.App)
suite.ChainBApp = suite.ChainB.App.(*app.App)
suite.ChainCApp = suite.ChainC.App.(*app.App)

providerKeeper := suite.ProviderApp.GetProviderKeeper()
consumerKeeperA := suite.ChainAApp.GetConsumerKeeper()
consumerKeeperB := suite.ChainBApp.GetConsumerKeeper()
consumerKeeperC := suite.ChainCApp.GetConsumerKeeper()

// valsets must match
providerValUpdates := cmttypes.TM2PB.ValidatorUpdates(suite.ChainProvider.Vals)
consumerAValUpdates := cmttypes.TM2PB.ValidatorUpdates(suite.ChainA.Vals)
consumerBValUpdates := cmttypes.TM2PB.ValidatorUpdates(suite.ChainB.Vals)
consumerCValUpdates := cmttypes.TM2PB.ValidatorUpdates(suite.ChainB.Vals)
suite.Require().True(len(providerValUpdates) == len(consumerAValUpdates), "initial valset not matching")
suite.Require().True(len(providerValUpdates) == len(consumerBValUpdates), "initial valset not matching")

for i := 0; i < len(providerValUpdates); i++ {
addr1, _ := ccv.TMCryptoPublicKeyToConsAddr(providerValUpdates[i].PubKey)
addr2, _ := ccv.TMCryptoPublicKeyToConsAddr(consumerAValUpdates[i].PubKey)
addr3, _ := ccv.TMCryptoPublicKeyToConsAddr(consumerBValUpdates[i].PubKey)
addr4, _ := ccv.TMCryptoPublicKeyToConsAddr(consumerCValUpdates[i].PubKey)
suite.Require().True(bytes.Equal(addr1, addr2), "validator mismatch")
suite.Require().True(bytes.Equal(addr1, addr3), "validator mismatch")
suite.Require().True(bytes.Equal(addr1, addr4), "validator mismatch")
}

ct := suite.ChainProvider.GetContext()
// move chains to the next block
suite.ChainProvider.NextBlock()
suite.ChainA.NextBlock()
suite.ChainB.NextBlock()
suite.ChainC.NextBlock()

// create consumer client on provider chain and set as consumer client for consumer chainID in provider keeper.
prop1 := GetTestConsumerAdditionProp(suite.ChainA)
Expand All @@ -184,6 +195,13 @@ func (suite *IBCConnectionTestSuite) SetupTest() {
)
suite.Require().NoError(err)

prop3 := GetTestConsumerAdditionProp(suite.ChainC)
err = providerKeeper.CreateConsumerClient(
ct,
prop3,
)
suite.Require().NoError(err)

// move provider to next block to commit the state
suite.ChainProvider.NextBlock()

Expand Down Expand Up @@ -215,11 +233,27 @@ func (suite *IBCConnectionTestSuite) SetupTest() {
}
consumerKeeperB.InitGenesis(suite.ChainB.GetContext(), &genesisStateB)

// initialize the consumer chain with the genesis state stored on the provider
consumerGenesisC, found := providerKeeper.GetConsumerGenesis(
suite.ChainProvider.GetContext(),
suite.ChainC.ChainID,
)
suite.Require().True(found, "consumer genesis not found")

genesisStateC := consumertypes.GenesisState{
Params: consumerGenesisC.Params,
Provider: consumerGenesisC.Provider,
NewChain: consumerGenesisC.NewChain,
}
consumerKeeperC.InitGenesis(suite.ChainC.GetContext(), &genesisStateC)

// create paths for the CCV channel
suite.CCVPathA = ibctesting.NewPath(suite.ChainA, suite.ChainProvider)
suite.CCVPathB = ibctesting.NewPath(suite.ChainB, suite.ChainProvider)
suite.CCVPathC = ibctesting.NewPath(suite.ChainC, suite.ChainProvider)
SetupCCVPath(suite.CCVPathA, suite)
SetupCCVPath(suite.CCVPathB, suite)
SetupCCVPath(suite.CCVPathC, suite)

suite.SetupCCVChannels()

Expand All @@ -235,6 +269,13 @@ func (suite *IBCConnectionTestSuite) ConfigureTransferChannel() {
suite.Require().NoError(err)
}

func (suite *IBCConnectionTestSuite) ConfigureTransferChannelAC() {
suite.TransferPathAC = NewTransferPath(suite.ChainA, suite.ChainC, suite.ChainProvider)
suite.Coordinator.SetupConnections(suite.TransferPathAC)
err := SetupTransferPath(suite.TransferPathAC)
suite.Require().NoError(err)
}

func (suite *IBCConnectionTestSuite) FundAcc(acc sdk.AccAddress, amounts sdk.Coins) {
bankKeeper := suite.GetNeutronZoneApp(suite.ChainA).BankKeeper
err := bankKeeper.MintCoins(suite.ChainA.GetContext(), tokenfactorytypes.ModuleName, amounts)
Expand Down Expand Up @@ -327,6 +368,10 @@ func NewProviderConsumerCoordinator(t *testing.T) *ibctesting.Coordinator {
coordinator.Chains[chainID] = ibctesting.NewTestChainWithValSet(t, coordinator,
chainID, providerChain.Vals, providerChain.Signers)

chainID = ibctesting.GetChainID(4)
coordinator.Chains[chainID] = ibctesting.NewTestChainWithValSet(t, coordinator,
chainID, providerChain.Vals, providerChain.Signers)

return coordinator
}

Expand Down
Loading

0 comments on commit ae40a29

Please sign in to comment.