-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: integrate authenticated calls smart contract functionality into…
… protocol (#2904) * e2e tests and modifications for authenticated call * extend test with sender check and revert case * separate tests into separate files * cleanup * withdraw and call support and tests * bump protocol contracts * split tests into separate files * small cleanup * fmt * generate * lint * changelog * PR comments * fix case in proto * bump vote inbound gas limit in zetaclient * fix test * generate * fixing tests * call options non empty * generate * test fix * rename gateway caller * pr comments rename tests * PR comment * generate * tests * update tests fixes * tests fixes * fix * test fix
- Loading branch information
Showing
71 changed files
with
2,620 additions
and
478 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
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
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,40 @@ | ||
package e2etests | ||
|
||
import ( | ||
"math/big" | ||
|
||
"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 payloadMessageWithdrawETH = "this is a test ETH withdraw and call payload" | ||
|
||
func TestV2ETHWithdrawAndArbitraryCall(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 TestV2ETHWithdrawAndCall") | ||
|
||
r.AssertTestDAppEVMCalled(false, payloadMessageWithdrawETH, amount) | ||
|
||
r.ApproveETHZRC20(r.GatewayZEVMAddr) | ||
|
||
// perform the withdraw | ||
tx := r.V2ETHWithdrawAndCall( | ||
r.TestDAppV2EVMAddr, | ||
amount, | ||
r.EncodeGasCall(payloadMessageWithdrawETH), | ||
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, payloadMessageWithdrawETH, amount) | ||
} |
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
84 changes: 84 additions & 0 deletions
84
e2e/e2etests/test_v2_eth_withdraw_and_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,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" | ||
gatewayzevmcaller "github.com/zeta-chain/node/pkg/contracts/gatewayzevmcaller" | ||
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types" | ||
) | ||
|
||
const payloadMessageAuthenticatedWithdrawETHThroughContract = "this is a test ETH withdraw and authenticated call payload through contract" | ||
|
||
func TestV2ETHWithdrawAndCallThroughContract(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 := gatewayzevmcaller.DeployGatewayZEVMCaller( | ||
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), | ||
gatewayzevmcaller.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), | ||
gatewayzevmcaller.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package e2etests | ||
|
||
import ( | ||
"math/big" | ||
|
||
"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 payloadMessageEVMCall = "this is a test EVM call payload" | ||
|
||
func TestV2ZEVMToEVMArbitraryCall(r *runner.E2ERunner, args []string) { | ||
require.Len(r, args, 0) | ||
|
||
r.AssertTestDAppEVMCalled(false, payloadMessageEVMCall, big.NewInt(0)) | ||
|
||
// Necessary approval for fee payment | ||
r.ApproveETHZRC20(r.GatewayZEVMAddr) | ||
|
||
// perform the call | ||
tx := r.V2ZEVMToEMVCall(r.TestDAppV2EVMAddr, r.EncodeSimpleCall(payloadMessageEVMCall), 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, payloadMessageEVMCall, big.NewInt(0)) | ||
} |
Oops, something went wrong.