From a84cb32d45ff9fa65b221c553654338f67eec2b8 Mon Sep 17 00:00:00 2001 From: Matthew Lam Date: Thu, 31 Aug 2023 23:09:23 +0000 Subject: [PATCH] sending teleporter message from a to b --- messages/teleporter/message_test.go | 9 +--- messages/teleporter/utils.go | 8 +++ tests/e2e/e2e_test.go | 80 ++++++++++++++++++----------- 3 files changed, 58 insertions(+), 39 deletions(-) diff --git a/messages/teleporter/message_test.go b/messages/teleporter/message_test.go index 62740217..e71e6772 100644 --- a/messages/teleporter/message_test.go +++ b/messages/teleporter/message_test.go @@ -33,17 +33,10 @@ func testTeleporterMessage(messageID int64) TeleporterMessage { return m } -// Pack the SendCrossChainMessage event type. PackEvent is documented as not supporting struct types, so this should be used -// with caution. Here, we only use it for testing purposes. In a real setting, the Teleporter contract should pack the event. -func packTeleporterMessage(destinationChainID common.Hash, message TeleporterMessage) ([]byte, error) { - _, hashes, err := EVMTeleporterContractABI.PackEvent("SendCrossChainMessage", destinationChainID, message.MessageID, message) - return hashes, err -} - func TestPackUnpackTeleporterMessage(t *testing.T) { message := testTeleporterMessage(4) - b, err := packTeleporterMessage(common.HexToHash("0x03"), message) + b, err := PackTeleporterMessage(common.HexToHash("0x03"), message) if err != nil { t.Errorf("failed to pack teleporter message: %v", err) t.FailNow() diff --git a/messages/teleporter/utils.go b/messages/teleporter/utils.go index 5b66648f..bc3e5081 100644 --- a/messages/teleporter/utils.go +++ b/messages/teleporter/utils.go @@ -9,6 +9,7 @@ import ( "github.com/ava-labs/avalanchego/utils/math" "github.com/ava-labs/awm-relayer/utils" + "github.com/ethereum/go-ethereum/common" ) const ( @@ -47,3 +48,10 @@ func CalculateReceiveMessageGasLimit(numSigners int, executionRequiredGasLimit * return res, nil } + +// Pack the SendCrossChainMessage event type. PackEvent is documented as not supporting struct types, so this should be used +// with caution. Here, we only use it for testing purposes. In a real setting, the Teleporter contract should pack the event. +func PackTeleporterMessage(destinationChainID common.Hash, message TeleporterMessage) ([]byte, error) { + _, hashes, err := EVMTeleporterContractABI.PackEvent("SendCrossChainMessage", destinationChainID, message.MessageID, message) + return hashes, err +} diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 0ff145d0..ed58210b 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -17,6 +17,7 @@ import ( "github.com/ava-labs/avalanchego/utils/logging" avalancheWarp "github.com/ava-labs/avalanchego/vms/platformvm/warp" "github.com/ava-labs/awm-relayer/config" + "github.com/ava-labs/awm-relayer/messages/teleporter" "github.com/ava-labs/subnet-evm/core/types" "github.com/ava-labs/subnet-evm/ethclient" "github.com/ava-labs/subnet-evm/interfaces" @@ -40,6 +41,15 @@ var ( warpChainConfigPath string relayerConfigPath string teleporterContractAddress = common.HexToAddress("27aE10273D17Cd7e80de8580A51f476960626e5f") + teleporterMessage = teleporter.TeleporterMessage{ + MessageID: big.NewInt(1), + SenderAddress: common.HexToAddress("0x0123456789abcdef0123456789abcdef01234567"), + DestinationAddress: common.HexToAddress("0x0123456789abcdef0123456789abcdef01234567"), + RequiredGasLimit: big.NewInt(1), + AllowedRelayerAddresses: []common.Address{}, + Receipts: []teleporter.TeleporterMessageReceipt{}, + Message: []byte{1, 2, 3, 4}, + } ) func TestE2E(t *testing.T) { @@ -141,18 +151,18 @@ var _ = ginkgo.AfterSuite(func() { var _ = ginkgo.Describe("[Relayer]", ginkgo.Ordered, func() { log.Info("Got to ginkgo describe") var ( - subnetA, subnetB ids.ID - blockchainIDA, blockchainIDB ids.ID - chainAURIs, chainBURIs []string - fundedKey *ecdsa.PrivateKey - fundedAddress common.Address - err error - unsignedWarpMsg *avalancheWarp.UnsignedMessage - unsignedWarpMessageID ids.ID - signedWarpMsg *avalancheWarp.Message + subnetA, subnetB ids.ID + blockchainIDA, blockchainIDB ids.ID + chainAURIs, chainBURIs []string + fundedKey *ecdsa.PrivateKey + fundedAddress common.Address + err error + unsignedWarpMsg *avalancheWarp.UnsignedMessage + unsignedWarpMessageID ids.ID + // signedWarpMsg *avalancheWarp.Message chainAWSClient, chainBWSClient ethclient.Client chainID = big.NewInt(99999) - payload = []byte{1, 2, 3} + payload = []byte{} txSigner = types.LatestSignerForChainID(chainID) ) @@ -278,14 +288,22 @@ var _ = ginkgo.Describe("[Relayer]", ginkgo.Ordered, func() { gomega.Expect(err).Should(gomega.BeNil()) log.Info("Subscribing to new heads") - newHeads := make(chan *types.Header, 10) - sub, err := chainAWSClient.SubscribeNewHead(ctx, newHeads) + // newHeadsA := make(chan *types.Header, 10) + // sub, err := chainAWSClient.SubscribeNewHead(ctx, newHeadsA) + // gomega.Expect(err).Should(gomega.BeNil()) + // defer sub.Unsubscribe() + + newHeadsB := make(chan *types.Header, 10) + sub, err := chainBWSClient.SubscribeNewHead(ctx, newHeadsB) gomega.Expect(err).Should(gomega.BeNil()) defer sub.Unsubscribe() startingNonce, err := chainAWSClient.NonceAt(ctx, fundedAddress, nil) gomega.Expect(err).Should(gomega.BeNil()) + payload, err = teleporter.PackTeleporterMessage(common.Hash(blockchainIDB), teleporterMessage) + gomega.Expect(err).Should(gomega.BeNil()) + packedInput, err := warp.PackSendWarpMessage(warp.SendWarpMessageInput{ DestinationChainID: common.Hash(blockchainIDB), DestinationAddress: fundedAddress, @@ -304,16 +322,16 @@ var _ = ginkgo.Describe("[Relayer]", ginkgo.Ordered, func() { }) signedTx, err := types.SignTx(tx, txSigner, fundedKey) gomega.Expect(err).Should(gomega.BeNil()) - log.Info("Sending sendWarpMessage transaction", "txHash", signedTx.Hash()) + log.Info("Sending sendWarpMessage transaction", "destinationChainID", blockchainIDB, "txHash", signedTx.Hash()) err = chainAWSClient.SendTransaction(ctx, signedTx) gomega.Expect(err).Should(gomega.BeNil()) log.Info("Waiting for new block confirmation") - newHead := <-newHeads + newHead := <-newHeadsB blockHash := newHead.Hash() log.Info("Fetching relevant warp logs from the newly produced block") - logs, err := chainAWSClient.FilterLogs(ctx, interfaces.FilterQuery{ + logs, err := chainBWSClient.FilterLogs(ctx, interfaces.FilterQuery{ BlockHash: &blockHash, Addresses: []common.Address{warp.Module.Address}, }) @@ -335,22 +353,22 @@ var _ = ginkgo.Describe("[Relayer]", ginkgo.Ordered, func() { // Loop over each client on chain A to ensure they all have time to accept the block. // Note: if we did not confirm this here, the next stage could be racy since it assumes every node // has accepted the block. - for i, uri := range chainAURIs { - chainAWSURI := toWebsocketURI(uri, blockchainIDA.String()) - log.Info("Creating ethclient for blockchainA", "wsURI", chainAWSURI) - client, err := ethclient.Dial(chainAWSURI) - gomega.Expect(err).Should(gomega.BeNil()) - - // Loop until each node has advanced to >= the height of the block that emitted the warp log - for { - block, err := client.BlockByNumber(ctx, nil) - gomega.Expect(err).Should(gomega.BeNil()) - if block.NumberU64() >= newHead.Number.Uint64() { - log.Info("client accepted the block containing SendWarpMessage", "client", i, "height", block.NumberU64()) - break - } - } - } + // for i, uri := range chainAURIs { + // chainAWSURI := toWebsocketURI(uri, blockchainIDA.String()) + // log.Info("Creating ethclient for blockchainA", "wsURI", chainAWSURI) + // client, err := ethclient.Dial(chainAWSURI) + // gomega.Expect(err).Should(gomega.BeNil()) + + // // Loop until each node has advanced to >= the height of the block that emitted the warp log + // for { + // block, err := client.BlockByNumber(ctx, nil) + // gomega.Expect(err).Should(gomega.BeNil()) + // if block.NumberU64() >= newHead.Number.Uint64() { + // log.Info("client accepted the block containing SendWarpMessage", "client", i, "height", block.NumberU64()) + // break + // } + // } + // } }) })