Skip to content

Commit

Permalink
Update E2E infra to support more than 2 chains (#6524)
Browse files Browse the repository at this point in the history
* wip: adding additional function to return all chains associated with a test

* chore: existing tests passing

* chore: replace chain spec references with chain spec list indexing

* chore: refactor SetupChainsRelayerAndChannel to construct interchain based on arbitrary number of chains

* chore: add basic test to verify 3 chain setup

* chore: add e2e build flag

* chore: corrected proposal id init

* chore: fix build errors

* chore: extract setup fn into testsuite package for re-use

* chore: fix chain construction error

* chore: addressing PR feedback
  • Loading branch information
chatton committed Jun 12, 2024
1 parent 3c4d8b3 commit 2b887d7
Show file tree
Hide file tree
Showing 5 changed files with 292 additions and 103 deletions.
93 changes: 93 additions & 0 deletions e2e/tests/transfer/forwarding_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//go:build !test_e2e

package transfer

import (
"context"
"testing"

testifysuite "github.com/stretchr/testify/suite"

"github.com/cosmos/ibc-go/e2e/testsuite"
"github.com/cosmos/ibc-go/e2e/testsuite/query"
"github.com/cosmos/ibc-go/e2e/testvalues"
)

func TestTransferForwardingTestSuite(t *testing.T) {
testifysuite.Run(t, new(TransferForwardingTestSuite))
}

type TransferForwardingTestSuite struct {
testsuite.E2ETestSuite
}

// TODO: replace this with actual tests https://github.com/cosmos/ibc-go/issues/6578
// this test verifies that three chains can be set up, and the relayer will relay
// packets between them as configured in the newInterchain function.
func (s *TransferForwardingTestSuite) TestThreeChainSetup() {
ctx := context.TODO()
t := s.T()

// TODO: note the ThreeChainSetup fn needs to be passed to TransferChannelOptions since it calls
// GetChains which will requires those settings. We should be able to update the function to accept
// the chain version rather than calling GetChains.
// https://github.com/cosmos/ibc-go/issues/6577
relayer, channelA := s.SetupChainsRelayerAndChannel(ctx, s.TransferChannelOptions(testsuite.ThreeChainSetup()), testsuite.ThreeChainSetup())
chains := s.GetAllChains()

chainA, chainB, chainC := chains[0], chains[1], chains[2]

chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)
chainAAddress := chainAWallet.FormattedAddress()
chainADenom := chainA.Config().Denom

chainBWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount)
chainBAddress := chainBWallet.FormattedAddress()
chainBDenom := chainB.Config().Denom

chainCWallet := s.CreateUserOnChainC(ctx, testvalues.StartingTokenAmount)
chainCAddress := chainCWallet.FormattedAddress()

t.Run("IBC transfer from A to B", func(t *testing.T) {
transferTxResp := s.Transfer(ctx, chainA, chainAWallet, channelA.PortID, channelA.ChannelID, testvalues.DefaultTransferCoins(chainADenom), chainAAddress, chainBAddress, s.GetTimeoutHeight(ctx, chainB), 0, "")
s.AssertTxSuccess(transferTxResp)
})

chainBChannels, err := relayer.GetChannels(ctx, s.GetRelayerExecReporter(), chainB.Config().ChainID)
s.Require().NoError(err)
// channel between A and B and channel between B and C
s.Require().Len(chainBChannels, 2)

chainBtoCChannel := chainBChannels[0]

t.Run("IBC transfer from B to C", func(t *testing.T) {
transferTxResp := s.Transfer(ctx, chainB, chainBWallet, chainBtoCChannel.PortID, chainBtoCChannel.ChannelID, testvalues.DefaultTransferCoins(chainBDenom), chainBAddress, chainCAddress, s.GetTimeoutHeight(ctx, chainC), 0, "")
s.AssertTxSuccess(transferTxResp)
})

t.Run("start relayer", func(t *testing.T) {
s.StartRelayer(relayer)
})

chainBIBCToken := testsuite.GetIBCToken(chainADenom, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID)
t.Run("packets are relayed from A to B", func(t *testing.T) {
s.AssertPacketRelayed(ctx, chainA, channelA.PortID, channelA.ChannelID, 1)

actualBalance, err := query.Balance(ctx, chainB, chainBAddress, chainBIBCToken.IBCDenom())
s.Require().NoError(err)

expected := testvalues.IBCTransferAmount
s.Require().Equal(expected, actualBalance.Int64())
})

chainCIBCToken := testsuite.GetIBCToken(chainBDenom, chainBtoCChannel.Counterparty.PortID, chainBtoCChannel.Counterparty.ChannelID)
t.Run("packets are relayed from B to C", func(t *testing.T) {
s.AssertPacketRelayed(ctx, chainB, chainBtoCChannel.PortID, chainBtoCChannel.ChannelID, 1)

actualBalance, err := query.Balance(ctx, chainC, chainCAddress, chainCIBCToken.IBCDenom())
s.Require().NoError(err)

expected := testvalues.IBCTransferAmount
s.Require().Equal(expected, actualBalance.Int64())
})
}
2 changes: 1 addition & 1 deletion e2e/tests/upgrades/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (s *GenesisTestSuite) TestIBCGenesis() {
appTomlOverrides["halt-height"] = haltHeight
configFileOverrides["config/app.toml"] = appTomlOverrides
chainOpts := func(options *testsuite.ChainOptions) {
options.ChainASpec.ConfigFileOverrides = configFileOverrides
options.ChainSpecs[0].ConfigFileOverrides = configFileOverrides
}

// create chains with specified chain configuration options
Expand Down
60 changes: 30 additions & 30 deletions e2e/tests/wasm/grandpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,11 +710,11 @@ func getConfigOverrides() map[string]any {
func (s *GrandpaTestSuite) GetGrandpaTestChains() (ibc.Chain, ibc.Chain) {
return s.GetChains(func(options *testsuite.ChainOptions) {
// configure chain A (polkadot)
options.ChainASpec.ChainName = composable
options.ChainASpec.Type = "polkadot"
options.ChainASpec.ChainID = "rococo-local"
options.ChainASpec.Name = "composable"
options.ChainASpec.Images = []ibc.DockerImage{
options.ChainSpecs[0].ChainName = composable
options.ChainSpecs[0].Type = "polkadot"
options.ChainSpecs[0].ChainID = "rococo-local"
options.ChainSpecs[0].Name = "composable"
options.ChainSpecs[0].Images = []ibc.DockerImage{
// TODO: https://github.com/cosmos/ibc-go/issues/4965
{
Repository: "ghcr.io/misko9/polkadot-node",
Expand All @@ -727,37 +727,37 @@ func (s *GrandpaTestSuite) GetGrandpaTestChains() (ibc.Chain, ibc.Chain) {
UidGid: "1000:1000",
},
}
options.ChainASpec.Bin = "polkadot"
options.ChainASpec.Bech32Prefix = composable
options.ChainASpec.Denom = "uDOT"
options.ChainASpec.GasPrices = ""
options.ChainASpec.GasAdjustment = 0
options.ChainASpec.TrustingPeriod = ""
options.ChainASpec.CoinType = "354"
options.ChainSpecs[0].Bin = "polkadot"
options.ChainSpecs[0].Bech32Prefix = composable
options.ChainSpecs[0].Denom = "uDOT"
options.ChainSpecs[0].GasPrices = ""
options.ChainSpecs[0].GasAdjustment = 0
options.ChainSpecs[0].TrustingPeriod = ""
options.ChainSpecs[0].CoinType = "354"

// these values are set by default for our cosmos chains, we need to explicitly remove them here.
options.ChainASpec.ModifyGenesis = nil
options.ChainASpec.ConfigFileOverrides = nil
options.ChainASpec.EncodingConfig = nil
options.ChainSpecs[0].ModifyGenesis = nil
options.ChainSpecs[0].ConfigFileOverrides = nil
options.ChainSpecs[0].EncodingConfig = nil

// configure chain B (cosmos)
options.ChainBSpec.ChainName = simd // Set chain name so that a suffix with a "dash" is not appended (required for hyperspace)
options.ChainBSpec.Type = "cosmos"
options.ChainBSpec.Name = "simd"
options.ChainBSpec.ChainID = simd
options.ChainBSpec.Bin = simd
options.ChainBSpec.Bech32Prefix = "cosmos"
options.ChainSpecs[1].ChainName = simd // Set chain name so that a suffix with a "dash" is not appended (required for hyperspace)
options.ChainSpecs[1].Type = "cosmos"
options.ChainSpecs[1].Name = "simd"
options.ChainSpecs[1].ChainID = simd
options.ChainSpecs[1].Bin = simd
options.ChainSpecs[1].Bech32Prefix = "cosmos"

// TODO: hyperspace relayer assumes a denom of "stake", hard code this here right now.
// https://github.com/cosmos/ibc-go/issues/4964
options.ChainBSpec.Denom = "stake"
options.ChainBSpec.GasPrices = "0.00stake"
options.ChainBSpec.GasAdjustment = 1
options.ChainBSpec.TrustingPeriod = "504h"
options.ChainBSpec.CoinType = "118"

options.ChainBSpec.ChainConfig.NoHostMount = false
options.ChainBSpec.ConfigFileOverrides = getConfigOverrides()
options.ChainBSpec.EncodingConfig = testsuite.SDKEncodingConfig()
options.ChainSpecs[1].Denom = "stake"
options.ChainSpecs[1].GasPrices = "0.00stake"
options.ChainSpecs[1].GasAdjustment = 1
options.ChainSpecs[1].TrustingPeriod = "504h"
options.ChainSpecs[1].CoinType = "118"

options.ChainSpecs[1].ChainConfig.NoHostMount = false
options.ChainSpecs[1].ConfigFileOverrides = getConfigOverrides()
options.ChainSpecs[1].EncodingConfig = testsuite.SDKEncodingConfig()
})
}
28 changes: 15 additions & 13 deletions e2e/testsuite/testconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const (
)

// defaultChainNames contains the default name for chainA and chainB.
var defaultChainNames = []string{"simapp-a", "simapp-b"}
var defaultChainNames = []string{"simapp-a", "simapp-b", "simapp-c"}

func getChainImage(binary string) string {
if binary == "" {
Expand Down Expand Up @@ -525,8 +525,7 @@ func IsFork() bool {
// created for the tests. They can be modified by passing ChainOptionConfiguration
// to E2ETestSuite.GetChains.
type ChainOptions struct {
ChainASpec *interchaintest.ChainSpec
ChainBSpec *interchaintest.ChainSpec
ChainSpecs []*interchaintest.ChainSpec
SkipPathCreation bool
}

Expand All @@ -544,17 +543,20 @@ func DefaultChainOptions() ChainOptions {
chainAVal, chainAFn := getValidatorsAndFullNodes(0)
chainBVal, chainBFn := getValidatorsAndFullNodes(1)

chainASpec := &interchaintest.ChainSpec{
ChainConfig: chainACfg,
NumFullNodes: &chainAFn,
NumValidators: &chainAVal,
}

chainBSpec := &interchaintest.ChainSpec{
ChainConfig: chainBCfg,
NumFullNodes: &chainBFn,
NumValidators: &chainBVal,
}

return ChainOptions{
ChainASpec: &interchaintest.ChainSpec{
ChainConfig: chainACfg,
NumFullNodes: &chainAFn,
NumValidators: &chainAVal,
},
ChainBSpec: &interchaintest.ChainSpec{
ChainConfig: chainBCfg,
NumFullNodes: &chainBFn,
NumValidators: &chainBVal,
},
ChainSpecs: []*interchaintest.ChainSpec{chainASpec, chainBSpec},
}
}

Expand Down
Loading

0 comments on commit 2b887d7

Please sign in to comment.