Skip to content

Commit

Permalink
e2e test wip
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Oct 17, 2024
1 parent dbe4ab3 commit e0a6e42
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/zetae2e/local/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func startV2Tests(eg *errgroup.Group, conf config.Config, deployerRunner *runner
e2etests.TestV2ERC20DepositAndCallName,
e2etests.TestV2ERC20WithdrawName,
e2etests.TestV2ERC20WithdrawAndArbitraryCallName,
e2etests.TestV2ERC20WithdrawAndCallName,
))

// Test revert cases for gas token workflow
Expand Down
9 changes: 9 additions & 0 deletions e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ const (
TestV2ERC20DepositAndCallRevertWithCallName = "v2_erc20_deposit_and_call_revert_with_call"
TestV2ERC20WithdrawName = "v2_erc20_withdraw"
TestV2ERC20WithdrawAndArbitraryCallName = "v2_erc20_withdraw_and_arbitrary_call"
TestV2ERC20WithdrawAndCallName = "v2_erc20_withdraw_and_call"
TestV2ERC20WithdrawAndCallRevertName = "v2_erc20_withdraw_and_call_revert"
TestV2ERC20WithdrawAndCallRevertWithCallName = "v2_erc20_withdraw_and_call_revert_with_call"
TestV2ZEVMToEVMArbitraryCallName = "v2_zevm_to_evm_arbitrary_call"
Expand Down Expand Up @@ -842,6 +843,14 @@ var AllE2ETests = []runner.E2ETest{
},
TestV2ERC20WithdrawAndArbitraryCall,
),
runner.NewE2ETest(
TestV2ERC20WithdrawAndCallName,
"withdraw ERC20 from ZEVM and authenticated call a contract using V2 contract",
[]runner.ArgDefinition{
{Description: "amount", DefaultValue: "1000"},
},
TestV2ERC20WithdrawAndCall,
),
runner.NewE2ETest(
TestV2ERC20WithdrawAndCallRevertName,
"withdraw ERC20 from ZEVM and call a contract using V2 contract that reverts",
Expand Down
55 changes: 55 additions & 0 deletions e2e/e2etests/test_v2_erc20_withdraw_and_call.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package e2etests

import (
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/stretchr/testify/require"
"github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayzevm.sol"

"github.com/zeta-chain/node/e2e/runner"
"github.com/zeta-chain/node/e2e/utils"
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
)

const payloadMessageWithdrawAuthenticatedCallERC20 = "this is a test ERC20 withdraw and authenticated call payload"

func TestV2ERC20WithdrawAndCall(r *runner.E2ERunner, args []string) {
require.Len(r, args, 1)

amount, ok := big.NewInt(0).SetString(args[0], 10)
require.True(r, ok, "Invalid amount specified for TestV2ERC20WithdrawAndCall")

r.AssertTestDAppEVMCalled(false, payloadMessageWithdrawAuthenticatedCallERC20, amount)

r.ApproveERC20ZRC20(r.GatewayZEVMAddr)
r.ApproveETHZRC20(r.GatewayZEVMAddr)

// set expected sender
tx, err := r.TestDAppV2EVM.SetExpectedOnCallSender(r.EVMAuth, r.ZEVMAuth.From)
require.NoError(r, err)
utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout)

// perform the withdraw
tx = r.V2ERC20WithdrawAndCall(
r.TestDAppV2EVMAddr,
amount,
r.EncodeERC20Call(r.ERC20Addr, amount, payloadMessageWithdrawAuthenticatedCallERC20),
gatewayzevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)},
)

// wait for the cctx to be mined
cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout)
r.Logger.CCTX(*cctx, "withdraw")
require.Equal(r, crosschaintypes.CctxStatus_OutboundMined, cctx.CctxStatus.Status)

r.AssertTestDAppEVMCalled(true, payloadMessageWithdrawAuthenticatedCallERC20, amount)

// check expected sender was used
senderForMsg, err := r.TestDAppV2EVM.SenderWithMessage(
&bind.CallOpts{},
[]byte(payloadMessageAuthenticatedWithdrawETH),
)
require.NoError(r, err)
require.Equal(r, r.ZEVMAuth.From, senderForMsg)
}

0 comments on commit e0a6e42

Please sign in to comment.