-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: authenticated zevm -> evm call and e2e tests #2904
base: develop
Are you sure you want to change the base?
Changes from all commits
8a93aa3
af8d86c
0cd7cb2
914d151
9d1471f
10ea638
d6786dc
6b711dc
614df83
fbb0c21
9557a57
07a83a1
3610f17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,11 @@ func startV2Tests(eg *errgroup.Group, conf config.Config, deployerRunner *runner | |
e2etests.TestV2ETHDepositAndCallName, | ||
e2etests.TestV2ETHWithdrawName, | ||
e2etests.TestV2ETHWithdrawAndCallName, | ||
e2etests.TestV2ETHWithdrawAndAuthenticatedCallName, | ||
e2etests.TestV2ETHWithdrawAndAuthenticatedCallThroughContractName, | ||
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be refactored in a further PR but I think we set these as the standard withdraw test and rename the current withdraw tests into |
||
e2etests.TestV2ZEVMToEVMCallName, | ||
e2etests.TestV2ZEVMToEVMAuthenticatedCallName, | ||
e2etests.TestV2ZEVMToEVMAuthenticatedCallThroughContractName, | ||
e2etests.TestV2EVMToZEVMCallName, | ||
)) | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,60 @@ | ||||||||||||||||||||||||||||
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 payloadMessageAuthenticatedWithdrawETH = "this is a test ETH withdraw and authenticated call payload" | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
func TestV2ETHWithdrawAndAuthenticatedCall(r *runner.E2ERunner, args []string) { | ||||||||||||||||||||||||||||
require.Len(r, args, 1) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
previousGasLimit := r.ZEVMAuth.GasLimit | ||||||||||||||||||||||||||||
r.ZEVMAuth.GasLimit = 10000000 | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Define Gas Limit as a Constant for Clarity The gas limit is set directly to Apply this diff to define and use a constant: +const highGasLimit = 10000000
func TestV2ETHWithdrawAndAuthenticatedCall(r *runner.E2ERunner, args []string) {
require.Len(r, args, 1)
previousGasLimit := r.ZEVMAuth.GasLimit
- r.ZEVMAuth.GasLimit = 10000000
+ r.ZEVMAuth.GasLimit = highGasLimit
defer func() {
r.ZEVMAuth.GasLimit = previousGasLimit
}()
|
||||||||||||||||||||||||||||
defer func() { | ||||||||||||||||||||||||||||
r.ZEVMAuth.GasLimit = previousGasLimit | ||||||||||||||||||||||||||||
}() | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
amount, ok := big.NewInt(0).SetString(args[0], 10) | ||||||||||||||||||||||||||||
require.True(r, ok, "Invalid amount specified for TestV2ETHWithdrawAndCall") | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
r.AssertTestDAppEVMCalled(false, payloadMessageAuthenticatedWithdrawETH, amount) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
r.ApproveETHZRC20(r.GatewayZEVMAddr) | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle Errors from The call to Apply this diff to handle the error: - r.ApproveETHZRC20(r.GatewayZEVMAddr)
+ err := r.ApproveETHZRC20(r.GatewayZEVMAddr)
+ require.NoError(r, err, "Failed to approve ETH ZRC20") Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
// 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.V2ETHWithdrawAndAuthenticatedCall( | ||||||||||||||||||||||||||||
r.TestDAppV2EVMAddr, | ||||||||||||||||||||||||||||
amount, | ||||||||||||||||||||||||||||
[]byte(payloadMessageAuthenticatedWithdrawETH), | ||||||||||||||||||||||||||||
gatewayzevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)}, | ||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||
Comment on lines
+39
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check for Errors in The function Apply this diff to incorporate error handling: - tx = r.V2ETHWithdrawAndAuthenticatedCall(
+ tx, err = r.V2ETHWithdrawAndAuthenticatedCall(
r.TestDAppV2EVMAddr,
amount,
[]byte(payloadMessageAuthenticatedWithdrawETH),
gatewayzevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)},
)
+ require.NoError(r, err, "Failed to perform V2 ETH withdraw and authenticated call") Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
// 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, payloadMessageAuthenticatedWithdrawETH, 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) | ||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,84 @@ | ||||||
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") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update error message to reflect the correct function name. The error message references Apply this diff to correct the error message: - require.True(r, ok, "Invalid amount specified for TestV2ETHWithdrawAndCall")
+ require.True(r, ok, "Invalid amount specified for TestV2ETHWithdrawAndAuthenticatedCallThroughContract") Committable suggestion
Suggested change
|
||||||
|
||||||
// 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)}) | ||||||
Comment on lines
+49
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle potential errors returned by The function Apply this diff to handle the error: - tx = r.V2ETHWithdrawAndAuthenticatedCallThroughContract(gatewayCaller, r.TestDAppV2EVMAddr,
+ tx, err = r.V2ETHWithdrawAndAuthenticatedCallThroughContract(gatewayCaller, r.TestDAppV2EVMAddr,
amount,
[]byte(payloadMessageAuthenticatedWithdrawETHThroughContract),
testgatewayzevmcaller.RevertOptions{OnRevertGasLimit: big.NewInt(0)})
+
+ require.NoError(r, err)
|
||||||
|
||||||
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) | ||||||
Comment on lines
+81
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for The function Apply this diff to handle potential errors: - cctx = utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout)
+ cctx, err := utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout)
+ require.NoError(r, err)
|
||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,51 @@ | ||||||
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 payloadMessageEVMAuthenticatedCall = "this is a test EVM authenticated call payload" | ||||||
|
||||||
func TestV2ZEVMToEVMAuthenticatedCall(r *runner.E2ERunner, args []string) { | ||||||
require.Len(r, args, 0) | ||||||
|
||||||
r.AssertTestDAppEVMCalled(false, payloadMessageEVMAuthenticatedCall, big.NewInt(0)) | ||||||
|
||||||
// necessary approval for fee payment | ||||||
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 authenticated call | ||||||
tx = r.V2ZEVMToEMVAuthenticatedCall( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct the function name The function name appears to have a typo. Changing Apply this diff to correct the function name: -tx = r.V2ZEVMToEMVAuthenticatedCall(
+tx = r.V2ZEVMToEVMAuthenticatedCall( Committable suggestion
Suggested change
|
||||||
r.TestDAppV2EVMAddr, | ||||||
[]byte(payloadMessageEVMAuthenticatedCall), | ||||||
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, "call") | ||||||
require.Equal(r, crosschaintypes.CctxStatus_OutboundMined, cctx.CctxStatus.Status) | ||||||
|
||||||
// check the payload was received on the contract | ||||||
r.AssertTestDAppEVMCalled(true, payloadMessageEVMAuthenticatedCall, big.NewInt(0)) | ||||||
|
||||||
// check expected sender was used | ||||||
senderForMsg, err := r.TestDAppV2EVM.SenderWithMessage(&bind.CallOpts{}, []byte(payloadMessageEVMAuthenticatedCall)) | ||||||
require.NoError(r, err) | ||||||
require.Equal(r, r.ZEVMAuth.From, senderForMsg) | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"integrate authenticated calls smart contract functionality into protocol"