-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
188 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
e2e/e2etests/test_v2_eth_withdraw_and_authenticated_call_through_contract.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package e2etests | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/zeta-chain/node/e2e/runner" | ||
"github.com/zeta-chain/node/e2e/utils" | ||
testgatewayzevmcaller "github.com/zeta-chain/node/pkg/contracts/testgatewayzevmcaller" | ||
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types" | ||
) | ||
|
||
const payloadMessageAuthenticatedWithdrawETHThroughContract = "this is a test ETH withdraw and authenticated call payload through contract" | ||
|
||
func TestV2ETHWithdrawAndAuthenticatedCallThroughContract(r *runner.E2ERunner, args []string) { | ||
require.Len(r, args, 1) | ||
|
||
previousGasLimit := r.ZEVMAuth.GasLimit | ||
r.ZEVMAuth.GasLimit = 10000000 | ||
defer func() { | ||
r.ZEVMAuth.GasLimit = previousGasLimit | ||
}() | ||
|
||
amount, ok := big.NewInt(0).SetString(args[0], 10) | ||
require.True(r, ok, "Invalid amount specified for TestV2ETHWithdrawAndCall") | ||
|
||
// deploy caller contract and send it gas zrc20 to pay gas fee | ||
gatewayCallerAddr, tx, gatewayCaller, err := testgatewayzevmcaller.DeployTestGatewayZEVMCaller(r.ZEVMAuth, r.ZEVMClient, r.GatewayZEVMAddr, r.WZetaAddr) | ||
require.NoError(r, err) | ||
utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) | ||
|
||
tx, err = r.ETHZRC20.Transfer(r.ZEVMAuth, gatewayCallerAddr, big.NewInt(100000000000000000)) | ||
require.NoError(r, err) | ||
utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) | ||
|
||
// set expected sender | ||
tx, err = r.TestDAppV2EVM.SetExpectedOnCallSender(r.EVMAuth, gatewayCallerAddr) | ||
require.NoError(r, err) | ||
utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) | ||
|
||
// perform the authenticated call | ||
tx = r.V2ETHWithdrawAndAuthenticatedCallThroughContract(gatewayCaller, r.TestDAppV2EVMAddr, | ||
amount, | ||
[]byte(payloadMessageAuthenticatedWithdrawETHThroughContract), | ||
testgatewayzevmcaller.RevertOptions{OnRevertGasLimit: big.NewInt(0)}) | ||
|
||
utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) | ||
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, payloadMessageAuthenticatedWithdrawETHThroughContract, amount) | ||
|
||
// check expected sender was used | ||
senderForMsg, err := r.TestDAppV2EVM.SenderWithMessage(&bind.CallOpts{}, []byte(payloadMessageAuthenticatedWithdrawETHThroughContract)) | ||
require.NoError(r, err) | ||
require.Equal(r, gatewayCallerAddr, senderForMsg) | ||
|
||
// set expected sender to wrong one | ||
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) | ||
|
||
// repeat authenticated call through contract, should revert because of wrong sender | ||
tx = r.V2ETHWithdrawAndAuthenticatedCallThroughContract(gatewayCaller, r.TestDAppV2EVMAddr, | ||
amount, | ||
[]byte(payloadMessageAuthenticatedWithdrawETHThroughContract), | ||
testgatewayzevmcaller.RevertOptions{OnRevertGasLimit: big.NewInt(0)}) | ||
|
||
utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) | ||
cctx = utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout) | ||
r.Logger.CCTX(*cctx, "withdraw") | ||
require.Equal(r, crosschaintypes.CctxStatus_Reverted, cctx.CctxStatus.Status) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
e2e/e2etests/test_v2_zevm_to_evm_authenticated_call_through_contract.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package e2etests | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/zeta-chain/node/e2e/runner" | ||
"github.com/zeta-chain/node/e2e/utils" | ||
testgatewayzevmcaller "github.com/zeta-chain/node/pkg/contracts/testgatewayzevmcaller" | ||
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types" | ||
) | ||
|
||
const payloadMessageEVMAuthenticatedCallThroughContract = "this is a test EVM authenticated call payload through contract" | ||
|
||
func TestV2ZEVMToEVMAuthenticatedCallThroughContract(r *runner.E2ERunner, args []string) { | ||
require.Len(r, args, 0) | ||
|
||
r.AssertTestDAppEVMCalled(false, payloadMessageEVMAuthenticatedCallThroughContract, big.NewInt(0)) | ||
|
||
// deploy caller contract and send it gas zrc20 to pay gas fee | ||
gatewayCallerAddr, tx, gatewayCaller, err := testgatewayzevmcaller.DeployTestGatewayZEVMCaller(r.ZEVMAuth, r.ZEVMClient, r.GatewayZEVMAddr, r.WZetaAddr) | ||
require.NoError(r, err) | ||
utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) | ||
|
||
tx, err = r.ETHZRC20.Transfer(r.ZEVMAuth, gatewayCallerAddr, big.NewInt(100000000000000000)) | ||
require.NoError(r, err) | ||
utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) | ||
|
||
// set expected sender | ||
tx, err = r.TestDAppV2EVM.SetExpectedOnCallSender(r.EVMAuth, gatewayCallerAddr) | ||
require.NoError(r, err) | ||
utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) | ||
|
||
// perform the authenticated call | ||
tx = r.V2ZEVMToEMVAuthenticatedCallThroughContract(gatewayCaller, r.TestDAppV2EVMAddr, []byte(payloadMessageEVMAuthenticatedCallThroughContract), testgatewayzevmcaller.RevertOptions{ | ||
OnRevertGasLimit: big.NewInt(0), | ||
}) | ||
utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) | ||
cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout) | ||
r.Logger.CCTX(*cctx, "call") | ||
require.Equal(r, crosschaintypes.CctxStatus_OutboundMined, cctx.CctxStatus.Status) | ||
|
||
r.AssertTestDAppEVMCalled(true, payloadMessageEVMAuthenticatedCallThroughContract, big.NewInt(0)) | ||
|
||
// check expected sender was used | ||
senderForMsg, err := r.TestDAppV2EVM.SenderWithMessage(&bind.CallOpts{}, []byte(payloadMessageEVMAuthenticatedCallThroughContract)) | ||
require.NoError(r, err) | ||
require.Equal(r, gatewayCallerAddr, senderForMsg) | ||
|
||
// set expected sender to wrong one | ||
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) | ||
|
||
// repeat authenticated call through contract, should revert because of wrong sender | ||
tx = r.V2ZEVMToEMVAuthenticatedCallThroughContract(gatewayCaller, r.TestDAppV2EVMAddr, []byte(payloadMessageEVMAuthenticatedCallThroughContract), testgatewayzevmcaller.RevertOptions{ | ||
OnRevertGasLimit: big.NewInt(0), | ||
}) | ||
utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) | ||
cctx = utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout) | ||
r.Logger.CCTX(*cctx, "call") | ||
require.Equal(r, crosschaintypes.CctxStatus_Reverted, cctx.CctxStatus.Status) | ||
} |