Skip to content

Commit

Permalink
add e2e test for revert
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Apr 15, 2024
1 parent b1678ec commit 8878984
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
1 change: 1 addition & 0 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
}
zetaTests := []string{
e2etests.TestMessagePassingZEVMName,
e2etests.TestMessagePassingZEVMRevertName,
e2etests.TestZetaWithdrawName,
e2etests.TestMessagePassingName,
e2etests.TestMessagePassingRevertFailName,
Expand Down
11 changes: 10 additions & 1 deletion e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
TestMessagePassingRevertFailName = "message_passing_revert_fail"
TestMessagePassingRevertSuccessName = "message_passing_revert_success"
TestMessagePassingZEVMName = "message_passing_zevm"
TestMessagePassingZEVMRevertName = "message_passing_revert_zevm"
TestERC20DepositAndCallRefundName = "erc20_deposit_and_call_refund"
TestEtherDepositAndCallName = "eth_deposit_and_call"
TestDepositEtherLiquidityCapName = "deposit_eth_liquidity_cap"
Expand Down Expand Up @@ -214,12 +215,20 @@ var AllE2ETests = []runner.E2ETest{
),
runner.NewE2ETest(
TestMessagePassingZEVMName,
"evm->zevm message passing",
"evm -> zevm message passing contract call ",
[]runner.ArgDefinition{
runner.ArgDefinition{Description: "amount in azeta", DefaultValue: "10000000000000000000"},
},
TestMessagePassingZEVM,
),
runner.NewE2ETest(
TestMessagePassingZEVMRevertName,
"evm -> zevm message passing and revert back to evm",
[]runner.ArgDefinition{
runner.ArgDefinition{Description: "amount in azeta", DefaultValue: "10000000000000000000"},
},
TestMessagePassingZEVMRevert,
),
runner.NewE2ETest(
TestMessagePassingName,
"evm->evm message passing contract call",
Expand Down
57 changes: 54 additions & 3 deletions e2e/e2etests/test_message_passing_zevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,64 @@ func TestMessagePassingZEVM(r *runner.E2ERunner, args []string) {
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)
r.Logger.Print(fmt.Sprintf("🔄 Cctx mined for contract call chain zevm %s", cctx.Index))
}

func TestMessagePassingZEVMRevert(r *runner.E2ERunner, args []string) {

if len(args) != 1 {
panic("TestMessagePassingRevert requires exactly one argument for the amount.")
}

amount, ok := big.NewInt(0).SetString(args[0], 10)
if !ok {
panic("Invalid amount specified for TestMessagePassingRevert.")
}

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, true)
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("🔄 Revert tx intx : %d", receipt.TxHash.String()))

Check failure on line 108 in e2e/e2etests/test_message_passing_zevm.go

View workflow job for this annotation

GitHub Actions / lint

printf: fmt.Sprintf format %d has arg receipt.TxHash.String() of wrong type string (govet)

Check failure on line 108 in e2e/e2etests/test_message_passing_zevm.go

View workflow job for this annotation

GitHub Actions / build-and-test

fmt.Sprintf format %d has arg receipt.TxHash.String() of wrong type string

Check failure on line 108 in e2e/e2etests/test_message_passing_zevm.go

View workflow job for this annotation

GitHub Actions / build-and-test

fmt.Sprintf format %d has arg receipt.TxHash.String() of wrong type 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_Reverted {
panic("expected cctx to be outbound_mined")
}
r.Logger.Print(fmt.Sprintf("🔄 Cctx mined for revert contract call chain zevm %s", cctx.Index))
}

0 comments on commit 8878984

Please sign in to comment.