diff --git a/cmd/zetae2e/config/config.go b/cmd/zetae2e/config/config.go index 2b2bdecc38..b358f2b280 100644 --- a/cmd/zetae2e/config/config.go +++ b/cmd/zetae2e/config/config.go @@ -104,7 +104,7 @@ func ExportContractsFromRunner(r *runner.E2ERunner, conf config.Config) config.C conf.Contracts.ZEVM.WZetaAddr = r.WZetaAddr.Hex() conf.Contracts.ZEVM.ZEVMSwapAppAddr = r.ZEVMSwapAppAddr.Hex() conf.Contracts.ZEVM.ContextAppAddr = r.ContextAppAddr.Hex() - conf.Contracts.ZEVM.TestDappAddr = r.TestDAppAddr.Hex() + conf.Contracts.ZEVM.TestDappAddr = r.EvmTestDAppAddr.Hex() return conf } diff --git a/cmd/zetae2e/config/contracts.go b/cmd/zetae2e/config/contracts.go index 003103bb81..a4f05f0058 100644 --- a/cmd/zetae2e/config/contracts.go +++ b/cmd/zetae2e/config/contracts.go @@ -181,7 +181,7 @@ func setContractsFromConfig(r *runner.E2ERunner, conf config.Config) error { if !ethcommon.IsHexAddress(c) { return fmt.Errorf("invalid TestDappAddr: %s", c) } - r.TestDAppAddr = ethcommon.HexToAddress(c) + r.EvmTestDAppAddr = ethcommon.HexToAddress(c) } return nil diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index d3ddca09a7..04d927af96 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -243,6 +243,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) { zetaTests := []string{ e2etests.TestZetaWithdrawName, e2etests.TestMessagePassingName, + e2etests.TestMessagePassingZEVMName, e2etests.TestMessagePassingRevertFailName, e2etests.TestMessagePassingRevertSuccessName, } diff --git a/e2e/e2etests/e2etests.go b/e2e/e2etests/e2etests.go index 404616535f..9fe3d5bdf4 100644 --- a/e2e/e2etests/e2etests.go +++ b/e2e/e2etests/e2etests.go @@ -25,6 +25,7 @@ const ( TestCrosschainSwapName = "crosschain_swap" TestMessagePassingRevertFailName = "message_passing_revert_fail" TestMessagePassingRevertSuccessName = "message_passing_revert_success" + TestMessagePassingZEVMName = "message_passing_zevm" TestERC20DepositAndCallRefundName = "erc20_deposit_and_call_refund" TestEtherDepositAndCallName = "eth_deposit_and_call" TestDepositEtherLiquidityCapName = "deposit_eth_liquidity_cap" @@ -211,6 +212,22 @@ var AllE2ETests = []runner.E2ETest{ }, TestMessagePassingRevertSuccess, ), + runner.NewE2ETest( + TestMessagePassingZEVMName, + "evm->zevm message passing", + []runner.ArgDefinition{ + runner.ArgDefinition{Description: "amount in azeta", DefaultValue: "10000000000000000000"}, + }, + TestMessagePassingZEVM, + ), + runner.NewE2ETest( + TestMessagePassingName, + "evm->evm message passing contract call", + []runner.ArgDefinition{ + runner.ArgDefinition{Description: "amount in azeta", DefaultValue: "10000000000000000000"}, + }, + TestMessagePassing, + ), runner.NewE2ETest( TestPauseZRC20Name, "pausing ZRC20 on ZetaChain", diff --git a/e2e/e2etests/test_message_passing.go b/e2e/e2etests/test_message_passing.go index c01c2a92ac..b17aff8f6b 100644 --- a/e2e/e2etests/test_message_passing.go +++ b/e2e/e2etests/test_message_passing.go @@ -190,7 +190,7 @@ func TestMessagePassingRevertSuccess(r *runner.E2ERunner, args []string) { auth := r.EVMAuth - tx, err := r.ZetaEth.Approve(auth, r.TestDAppAddr, amount) + tx, err := r.ZetaEth.Approve(auth, r.EvmTestDAppAddr, amount) if err != nil { panic(err) } @@ -202,8 +202,8 @@ func TestMessagePassingRevertSuccess(r *runner.E2ERunner, args []string) { } r.Logger.Info("Approve tx receipt: %d", receipt.Status) - r.Logger.Info("Calling TestDApp.SendHello on contract address %s", r.TestDAppAddr.Hex()) - testDApp, err := testdapp.NewTestDApp(r.TestDAppAddr, r.EVMClient) + r.Logger.Info("Calling TestDApp.SendHello on contract address %s", r.EvmTestDAppAddr.Hex()) + testDApp, err := testdapp.NewTestDApp(r.EvmTestDAppAddr, r.EVMClient) if err != nil { panic(err) } @@ -216,7 +216,7 @@ func TestMessagePassingRevertSuccess(r *runner.E2ERunner, args []string) { } r.Logger.Info("$$$ Before: SUPPLY OF AZETA: %d", res2.Amount.Amount) - tx, err = testDApp.SendHelloWorld(auth, r.TestDAppAddr, chainID, amount, true) + tx, err = testDApp.SendHelloWorld(auth, r.EvmTestDAppAddr, chainID, amount, true) if err != nil { panic(err) } diff --git a/e2e/e2etests/test_message_passing_zevm.go b/e2e/e2etests/test_message_passing_zevm.go new file mode 100644 index 0000000000..92ccb6dfdc --- /dev/null +++ b/e2e/e2etests/test_message_passing_zevm.go @@ -0,0 +1,65 @@ +package e2etests + +import ( + "fmt" + "math/big" + + "github.com/zeta-chain/zetacore/e2e/contracts/testdapp" + "github.com/zeta-chain/zetacore/e2e/runner" + "github.com/zeta-chain/zetacore/e2e/utils" + cctxtypes "github.com/zeta-chain/zetacore/x/crosschain/types" +) + +func TestMessagePassingZEVM(r *runner.E2ERunner, args []string) { + if len(args) != 1 { + panic("TestMessagePassing requires exactly one argument for the amount.") + } + + amount, ok := big.NewInt(0).SetString(args[0], 10) + if !ok { + panic("Invalid amount specified for TestMessagePassing.") + } + + zEVMChainID, err := r.ZEVMClient.ChainID(r.Ctx) + if err != nil { + panic(err) + } + destinationAddress := r.ZevmTestDAppAddr + + //Use TestDapp to call the Send function on the EVM connector to create a message + auth := r.EVMAuth + + tx, err := r.ZetaEth.Approve(auth, r.EvmTestDAppAddr, amount) + if err != nil { + panic(err) + } + r.Logger.Info("Approve tx hash: %s", tx.Hash().Hex()) + + receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) + if receipt.Status != 1 { + panic("tx failed") + } + r.Logger.Info("Approve tx receipt: %d", receipt.Status) + + testDAppEVM, err := testdapp.NewTestDApp(r.EvmTestDAppAddr, r.EVMClient) + if err != nil { + panic(err) + } + + tx, err = testDAppEVM.SendHelloWorld(auth, destinationAddress, zEVMChainID, amount, false) + if err != nil { + panic(err) + } + r.Logger.Info("TestDApp.SendHello tx hash: %s", tx.Hash().Hex()) + receipt = utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) + + r.Logger.Print(fmt.Sprintf("Waiting for cctx , intx : %s", receipt.TxHash.String())) + + // New inbound message picked up by zeta-clients and voted on by observers to initiate a contract call on zEVM + cctx := utils.WaitCctxMinedByInTxHash(r.Ctx, receipt.TxHash.String(), r.CctxClient, r.Logger, r.CctxTimeout) + if cctx.CctxStatus.Status != cctxtypes.CctxStatus_OutboundMined { + panic("expected cctx to be outbound_mined") + } + r.Logger.Print("🔄 Cctx mined by outbound chain zevm", cctx.Index) + +} diff --git a/e2e/runner/runner.go b/e2e/runner/runner.go index 1d9038c516..f36aa2c310 100644 --- a/e2e/runner/runner.go +++ b/e2e/runner/runner.go @@ -71,6 +71,7 @@ type E2ERunner struct { ERC20Custody *erc20custody.ERC20Custody ERC20Addr ethcommon.Address ERC20 *erc20.ERC20 + EvmTestDAppAddr ethcommon.Address // contracts zevm ERC20ZRC20Addr ethcommon.Address @@ -87,13 +88,13 @@ type E2ERunner struct { ConnectorZEVM *connectorzevm.ZetaConnectorZEVM WZetaAddr ethcommon.Address WZeta *wzeta.WETH9 - TestDAppAddr ethcommon.Address ZEVMSwapAppAddr ethcommon.Address ZEVMSwapApp *zevmswap.ZEVMSwapApp ContextAppAddr ethcommon.Address ContextApp *contextapp.ContextApp SystemContractAddr ethcommon.Address SystemContract *systemcontract.SystemContract + ZevmTestDAppAddr ethcommon.Address // config CctxTimeout time.Duration @@ -175,10 +176,11 @@ func (runner *E2ERunner) CopyAddressesFrom(other *E2ERunner) (err error) { runner.UniswapV2RouterAddr = other.UniswapV2RouterAddr runner.ConnectorZEVMAddr = other.ConnectorZEVMAddr runner.WZetaAddr = other.WZetaAddr - runner.TestDAppAddr = other.TestDAppAddr + runner.EvmTestDAppAddr = other.EvmTestDAppAddr runner.ZEVMSwapAppAddr = other.ZEVMSwapAppAddr runner.ContextAppAddr = other.ContextAppAddr runner.SystemContractAddr = other.SystemContractAddr + runner.ZevmTestDAppAddr = other.ZevmTestDAppAddr // create instances of contracts runner.ZetaEth, err = zetaeth.NewZetaEth(runner.ZetaEthAddr, runner.EVMClient) @@ -268,7 +270,7 @@ func (runner *E2ERunner) PrintContractAddresses() { runner.Logger.Print("ZEVMSwapApp: %s", runner.ZEVMSwapAppAddr.Hex()) runner.Logger.Print("ContextApp: %s", runner.ContextAppAddr.Hex()) - runner.Logger.Print("TestDapp: %s", runner.TestDAppAddr.Hex()) + runner.Logger.Print("TestDappZEVM: %s", runner.ZevmTestDAppAddr.Hex()) // evm contracts runner.Logger.Print(" --- 📜EVM contracts ---") @@ -276,4 +278,5 @@ func (runner *E2ERunner) PrintContractAddresses() { runner.Logger.Print("ConnectorEth: %s", runner.ConnectorEthAddr.Hex()) runner.Logger.Print("ERC20Custody: %s", runner.ERC20CustodyAddr.Hex()) runner.Logger.Print("ERC20: %s", runner.ERC20Addr.Hex()) + runner.Logger.Print("TestDappEVM: %s", runner.EvmTestDAppAddr.Hex()) } diff --git a/e2e/runner/setup_evm.go b/e2e/runner/setup_evm.go index 8e76ac7409..01188c759a 100644 --- a/e2e/runner/setup_evm.go +++ b/e2e/runner/setup_evm.go @@ -131,7 +131,7 @@ func (runner *E2ERunner) SetupEVM(contractsDeployed bool, whitelistERC20 bool) { if err != nil { panic(err) } - runner.TestDAppAddr = appAddr + runner.EvmTestDAppAddr = appAddr runner.Logger.Info("TestDApp contract address: %s, tx hash: %s", appAddr.Hex(), txApp.Hash().Hex()) // check contract deployment receipt diff --git a/e2e/runner/setup_zeta.go b/e2e/runner/setup_zeta.go index 31fc50785d..95a967814b 100644 --- a/e2e/runner/setup_zeta.go +++ b/e2e/runner/setup_zeta.go @@ -14,6 +14,7 @@ import ( "github.com/zeta-chain/protocol-contracts/pkg/uniswap/v2-core/contracts/uniswapv2factory.sol" uniswapv2router "github.com/zeta-chain/protocol-contracts/pkg/uniswap/v2-periphery/contracts/uniswapv2router02.sol" "github.com/zeta-chain/zetacore/e2e/contracts/contextapp" + "github.com/zeta-chain/zetacore/e2e/contracts/testdapp" "github.com/zeta-chain/zetacore/e2e/contracts/zevmswap" "github.com/zeta-chain/zetacore/e2e/txserver" e2eutils "github.com/zeta-chain/zetacore/e2e/utils" @@ -141,6 +142,14 @@ func (runner *E2ERunner) SetZEVMContracts() { runner.SetupETHZRC20() runner.SetupBTCZRC20() + // deploy TestDApp contract on zEVM + appAddr, txApp, _, err := testdapp.DeployTestDApp(runner.ZEVMAuth, runner.ZEVMClient, runner.ConnectorZEVMAddr, runner.WZetaAddr) + if err != nil { + panic(err) + } + runner.ZevmTestDAppAddr = appAddr + runner.Logger.Info("TestDApp Zevm contract address: %s, tx hash: %s", appAddr.Hex(), txApp.Hash().Hex()) + // deploy ZEVMSwapApp and ContextApp zevmSwapAppAddr, txZEVMSwapApp, zevmSwapApp, err := zevmswap.DeployZEVMSwapApp( runner.ZEVMAuth, @@ -170,6 +179,7 @@ func (runner *E2ERunner) SetZEVMContracts() { } runner.ContextAppAddr = contextAppAddr runner.ContextApp = contextApp + } // SetupETHZRC20 sets up the ETH ZRC20 in the runner from the values queried from the chain diff --git a/x/crosschain/keeper/evm_hooks.go b/x/crosschain/keeper/evm_hooks.go index a22d295c2d..0841bd9359 100644 --- a/x/crosschain/keeper/evm_hooks.go +++ b/x/crosschain/keeper/evm_hooks.go @@ -224,7 +224,8 @@ func (k Keeper) ProcessZetaSentEvent(ctx sdk.Context, event *connectorzevm.ZetaC return fmt.Errorf("ProcessZetaSentEvent: failed to convert chainID: %s", err.Error()) } amount := math.NewUintFromBigInt(event.ZetaValueAndGas) - + // TODO : check encoding and decoding of message + messageString := string(event.Message[:]) // Bump gasLimit by event index (which is very unlikely to be larger than 1000) to always have different ZetaSent events msgs. msg := types.NewMsgVoteOnObservedInboundTx( "", @@ -233,7 +234,7 @@ func (k Keeper) ProcessZetaSentEvent(ctx sdk.Context, event *connectorzevm.ZetaC txOrigin, toAddr, receiverChain.ChainId, amount, - "", + messageString, event.Raw.TxHash.String(), event.Raw.BlockNumber, 90000,