Skip to content

Commit

Permalink
feat: added cosmos <-> cosmos setup
Browse files Browse the repository at this point in the history
  • Loading branch information
srdtrk committed Jan 15, 2025
1 parent 620f42f commit 9dbb128
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 10 deletions.
8 changes: 4 additions & 4 deletions e2e/interchaintestv8/cosmos_relayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,21 +219,21 @@ func (s *CosmosRelayerTestSuite) TestRelayerInfo() {
ctx := context.Background()
s.SetupSuite(ctx)

s.Run("Chain A to B Relayer Info", func() {
s.Require().True(s.Run("Verify Chain A to Chain B Relayer Info", func() {
info, err := s.AtoBRelayerClient.Info(context.Background(), &relayertypes.InfoRequest{})
s.Require().NoError(err)
s.Require().NotNil(info)
s.Require().Equal(s.SimdA.Config().ChainID, info.SourceChain.ChainId)
s.Require().Equal(s.SimdB.Config().ChainID, info.TargetChain.ChainId)
})
}))

s.Run("Chain B to A Relayer Info", func() {
s.Require().True(s.Run("Verify Chain B to Chain A Relayer Info", func() {
info, err := s.BtoARelayerClient.Info(context.Background(), &relayertypes.InfoRequest{})
s.Require().NoError(err)
s.Require().NotNil(info)
s.Require().Equal(s.SimdB.Config().ChainID, info.SourceChain.ChainId)
s.Require().Equal(s.SimdA.Config().ChainID, info.TargetChain.ChainId)
})
}))
}

func (s *CosmosRelayerTestSuite) TestICS20RecvAndAckPacket() {
Expand Down
140 changes: 134 additions & 6 deletions e2e/interchaintestv8/multichain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ import (
sdkmath "cosmossdk.io/math"
banktypes "cosmossdk.io/x/bank/types"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"

transfertypes "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"
commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types"
commitmenttypesv2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2"
ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported"
ibctm "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint"
ibctesting "github.com/cosmos/ibc-go/v9/testing"

"github.com/strangelove-ventures/interchaintest/v9/ibc"
Expand Down Expand Up @@ -69,10 +72,12 @@ type MultichainTestSuite struct {
ibcStoreContract *ibcstore.Contract
escrowContractAddr ethcommon.Address

EthToChainARelayerClient relayertypes.RelayerServiceClient
ChainAToEthRelayerClient relayertypes.RelayerServiceClient
EthToChainBRelayerClient relayertypes.RelayerServiceClient
ChainBToEthRelayerClient relayertypes.RelayerServiceClient
EthToChainARelayerClient relayertypes.RelayerServiceClient
ChainAToEthRelayerClient relayertypes.RelayerServiceClient
EthToChainBRelayerClient relayertypes.RelayerServiceClient
ChainBToEthRelayerClient relayertypes.RelayerServiceClient
ChainAToChainBRelayerClient relayertypes.RelayerServiceClient
ChainBToChainARelayerClient relayertypes.RelayerServiceClient

SimdARelayerSubmitter ibc.Wallet
SimdBRelayerSubmitter ibc.Wallet
Expand Down Expand Up @@ -294,6 +299,105 @@ func (s *MultichainTestSuite) SetupSuite(ctx context.Context, proofType operator
s.Require().NoError(err)
}))

s.Require().True(s.Run("Create Light Client of Chain A on Chain B", func() {
simdAHeader, err := s.FetchCosmosHeader(ctx, simdA)
s.Require().NoError(err)

var (
clientStateAny *codectypes.Any
consensusStateAny *codectypes.Any
)
s.Require().True(s.Run("Construct the client and consensus state", func() {
tmConfig := ibctesting.NewTendermintConfig()
revision := clienttypes.ParseChainID(simdAHeader.ChainID)
height := clienttypes.NewHeight(revision, uint64(simdAHeader.Height))

clientState := ibctm.NewClientState(
simdAHeader.ChainID,
tmConfig.TrustLevel, tmConfig.TrustingPeriod, tmConfig.UnbondingPeriod, tmConfig.MaxClockDrift,
height, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath,
)
clientStateAny, err = codectypes.NewAnyWithValue(clientState)
s.Require().NoError(err)

consensusState := ibctm.NewConsensusState(simdAHeader.Time, commitmenttypes.NewMerkleRoot([]byte(ibctm.SentinelRoot)), simdAHeader.ValidatorsHash)
consensusStateAny, err = codectypes.NewAnyWithValue(consensusState)
s.Require().NoError(err)
}))

_, err = s.BroadcastMessages(ctx, simdB, s.SimdBRelayerSubmitter, 200_000, &clienttypes.MsgCreateClient{
ClientState: clientStateAny,
ConsensusState: consensusStateAny,
Signer: s.SimdBRelayerSubmitter.FormattedAddress(),
})
s.Require().NoError(err)
}))

s.Require().True(s.Run("Create Light Client of Chain B on Chain A", func() {
simdBHeader, err := s.FetchCosmosHeader(ctx, simdB)
s.Require().NoError(err)

var (
clientStateAny *codectypes.Any
consensusStateAny *codectypes.Any
)
s.Require().True(s.Run("Construct the client and consensus state", func() {
tmConfig := ibctesting.NewTendermintConfig()
revision := clienttypes.ParseChainID(simdBHeader.ChainID)
height := clienttypes.NewHeight(revision, uint64(simdBHeader.Height))

clientState := ibctm.NewClientState(
simdBHeader.ChainID,
tmConfig.TrustLevel, tmConfig.TrustingPeriod, tmConfig.UnbondingPeriod, tmConfig.MaxClockDrift,
height, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath,
)
clientStateAny, err = codectypes.NewAnyWithValue(clientState)
s.Require().NoError(err)

consensusState := ibctm.NewConsensusState(simdBHeader.Time, commitmenttypes.NewMerkleRoot([]byte(ibctm.SentinelRoot)), simdBHeader.ValidatorsHash)
consensusStateAny, err = codectypes.NewAnyWithValue(consensusState)
s.Require().NoError(err)
}))

_, err = s.BroadcastMessages(ctx, simdA, s.SimdARelayerSubmitter, 200_000, &clienttypes.MsgCreateClient{
ClientState: clientStateAny,
ConsensusState: consensusStateAny,
Signer: s.SimdARelayerSubmitter.FormattedAddress(),
})
s.Require().NoError(err)
}))

s.Require().True(s.Run("Create Channel and register counterparty on Chain A", func() {
merklePathPrefix := commitmenttypesv2.NewMerklePath([]byte(ibcexported.StoreKey), []byte(""))

// We can do this because we know what the counterparty channel ID will be
_, err := s.BroadcastMessages(ctx, simdA, s.SimdARelayerSubmitter, 200_000, &channeltypesv2.MsgCreateChannel{
ClientId: ibctesting.FirstClientID,
MerklePathPrefix: merklePathPrefix,
Signer: s.SimdARelayerSubmitter.FormattedAddress(),
}, &channeltypesv2.MsgRegisterCounterparty{
ChannelId: ibctesting.SecondChannelID,
CounterpartyChannelId: ibctesting.SecondChannelID,
Signer: s.SimdARelayerSubmitter.FormattedAddress(),
})
s.Require().NoError(err)
}))

s.Require().True(s.Run("Create Channel and register counterparty on Chain B", func() {
merklePathPrefix := commitmenttypesv2.NewMerklePath([]byte(ibcexported.StoreKey), []byte(""))

_, err := s.BroadcastMessages(ctx, simdB, s.SimdBRelayerSubmitter, 200_000, &channeltypesv2.MsgCreateChannel{
ClientId: ibctesting.FirstClientID,
MerklePathPrefix: merklePathPrefix,
Signer: s.SimdBRelayerSubmitter.FormattedAddress(),
}, &channeltypesv2.MsgRegisterCounterparty{
ChannelId: ibctesting.SecondChannelID,
CounterpartyChannelId: ibctesting.SecondChannelID,
Signer: s.SimdBRelayerSubmitter.FormattedAddress(),
})
s.Require().NoError(err)
}))

var relayerProcess *os.Process
var configInfo relayer.MultichainConfigInfo
s.Require().True(s.Run("Start Relayer", func() {
Expand All @@ -306,10 +410,12 @@ func (s *MultichainTestSuite) SetupSuite(ctx context.Context, proofType operator
configInfo = relayer.MultichainConfigInfo{
EthToChainAPort: 3000,
ChainAToEthPort: 3001,
ChainATmRPC: simdA.GetHostRPCAddress(),
ChainASignerAddress: s.SimdARelayerSubmitter.FormattedAddress(),
EthToChainBPort: 3002,
ChainBToEthPort: 3003,
ChainAToChainBPort: 3004,
ChainBToChainAPort: 3005,
ChainATmRPC: simdA.GetHostRPCAddress(),
ChainASignerAddress: s.SimdARelayerSubmitter.FormattedAddress(),
ChainBTmRPC: simdB.GetHostRPCAddress(),
ChainBSignerAddress: s.SimdBRelayerSubmitter.FormattedAddress(),
ICS26Address: s.contractAddresses.Ics26Router,
Expand Down Expand Up @@ -352,6 +458,12 @@ func (s *MultichainTestSuite) SetupSuite(ctx context.Context, proofType operator

s.ChainBToEthRelayerClient, err = relayer.GetGRPCClient(configInfo.ChainBToEthGRPCAddress())
s.Require().NoError(err)

s.ChainAToChainBRelayerClient, err = relayer.GetGRPCClient(configInfo.ChainAToChainBGRPCAddress())
s.Require().NoError(err)

s.ChainBToChainARelayerClient, err = relayer.GetGRPCClient(configInfo.ChainBToChainAGRPCAddress())
s.Require().NoError(err)
}))
}

Expand Down Expand Up @@ -494,6 +606,22 @@ func (s *MultichainTestSuite) TestDeploy_Groth16() {
s.Require().Equal(eth.ChainID.String(), info.SourceChain.ChainId)
s.Require().Equal(simdB.Config().ChainID, info.TargetChain.ChainId)
}))

s.Require().True(s.Run("Verify Chain A to Chain B Relayer Info", func() {
info, err := s.ChainAToChainBRelayerClient.Info(context.Background(), &relayertypes.InfoRequest{})
s.Require().NoError(err)
s.Require().NotNil(info)
s.Require().Equal(simdA.Config().ChainID, info.SourceChain.ChainId)
s.Require().Equal(simdB.Config().ChainID, info.TargetChain.ChainId)
}))

s.Require().True(s.Run("Verify Chain B to Chain A Relayer Info", func() {
info, err := s.ChainBToChainARelayerClient.Info(context.Background(), &relayertypes.InfoRequest{})
s.Require().NoError(err)
s.Require().NotNil(info)
s.Require().Equal(simdB.Config().ChainID, info.SourceChain.ChainId)
s.Require().Equal(simdA.Config().ChainID, info.TargetChain.ChainId)
}))
}

func (s *MultichainTestSuite) TestTransferCosmosToEthToCosmos_Groth16() {
Expand Down
14 changes: 14 additions & 0 deletions e2e/interchaintestv8/relayer/multichain_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ type MultichainConfigInfo struct {
EthToChainBPort uint64
// gRPC port for the Chain B to Eth relayer module
ChainBToEthPort uint64
// gRPC port for the Chain A to Chain B relayer module
ChainAToChainBPort uint64
// gRPC port for the Chain B to Chain A relayer module
ChainBToChainAPort uint64
// Chain A tendermint RPC URL
ChainATmRPC string
// Chain B tendermint RPC URL
Expand Down Expand Up @@ -71,3 +75,13 @@ func (c *MultichainConfigInfo) EthToChainBGRPCAddress() string {
func (c *MultichainConfigInfo) ChainBToEthGRPCAddress() string {
return fmt.Sprintf("127.0.0.1:%d", c.ChainBToEthPort)
}

// ChainAToChainBGRPCAddress returns the address for the chain A to chain B relayer gRPC server.
func (c *MultichainConfigInfo) ChainAToChainBGRPCAddress() string {
return fmt.Sprintf("127.0.0.1:%d", c.ChainAToChainBPort)
}

// ChainBToChainAGRPCAddress returns the address for the chain B to chain A relayer gRPC server.
func (c *MultichainConfigInfo) ChainBToChainAGRPCAddress() string {
return fmt.Sprintf("127.0.0.1:%d", c.ChainBToChainAPort)
}
18 changes: 18 additions & 0 deletions e2e/interchaintestv8/relayer/multichain_config.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@
"eth_rpc_url": "{{ .EthRPC }}",
"sp1_private_key": "{{ .SP1PrivateKey }}"
}
},
{
"name": "cosmos_to_cosmos",
"port": {{ .ChainAToChainBPort }},
"config": {
"src_rpc_url": "{{ .ChainATmRPC }}",
"target_rpc_url": "{{ .ChainBTmRPC }}",
"signer_address": "{{ .ChainBSignerAddress }}"
}
},
{
"name": "cosmos_to_cosmos",
"port": {{ .ChainBToChainAPort }},
"config": {
"src_rpc_url": "{{ .ChainBTmRPC }}",
"target_rpc_url": "{{ .ChainATmRPC }}",
"signer_address": "{{ .ChainASignerAddress }}"
}
}
]
}

0 comments on commit 9dbb128

Please sign in to comment.