From 9dbb1285e6cc1f12a41e5dab46da362f6437c914 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Wed, 15 Jan 2025 16:44:07 +0800 Subject: [PATCH] feat: added cosmos <-> cosmos setup --- e2e/interchaintestv8/cosmos_relayer_test.go | 8 +- e2e/interchaintestv8/multichain_test.go | 140 +++++++++++++++++- .../relayer/multichain_config.go | 14 ++ .../relayer/multichain_config.tmpl | 18 +++ 4 files changed, 170 insertions(+), 10 deletions(-) diff --git a/e2e/interchaintestv8/cosmos_relayer_test.go b/e2e/interchaintestv8/cosmos_relayer_test.go index e0dcf10e..5aa251f2 100644 --- a/e2e/interchaintestv8/cosmos_relayer_test.go +++ b/e2e/interchaintestv8/cosmos_relayer_test.go @@ -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() { diff --git a/e2e/interchaintestv8/multichain_test.go b/e2e/interchaintestv8/multichain_test.go index aacbc1a1..2fa697e1 100644 --- a/e2e/interchaintestv8/multichain_test.go +++ b/e2e/interchaintestv8/multichain_test.go @@ -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" @@ -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 @@ -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() { @@ -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, @@ -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) })) } @@ -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() { diff --git a/e2e/interchaintestv8/relayer/multichain_config.go b/e2e/interchaintestv8/relayer/multichain_config.go index 5bd7a518..c137581e 100644 --- a/e2e/interchaintestv8/relayer/multichain_config.go +++ b/e2e/interchaintestv8/relayer/multichain_config.go @@ -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 @@ -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) +} diff --git a/e2e/interchaintestv8/relayer/multichain_config.tmpl b/e2e/interchaintestv8/relayer/multichain_config.tmpl index e2495f1b..45546db3 100644 --- a/e2e/interchaintestv8/relayer/multichain_config.tmpl +++ b/e2e/interchaintestv8/relayer/multichain_config.tmpl @@ -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 }}" + } } ] }