Skip to content
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: support withdraws, calls and reverts with Gateway contract #2666

Merged
merged 32 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
634dd91
add v2 zevm inbound
lumtis Aug 8, 2024
1e08033
refactor abi in signers
lumtis Aug 8, 2024
99cdcf5
outbound for gas withdraw
lumtis Aug 9, 2024
5340077
fix withdraw
lumtis Aug 9, 2024
3d4b03c
gateway execute parse
lumtis Aug 9, 2024
1be6f6f
add support for withdraw and call
lumtis Aug 9, 2024
0ac8d95
erc20 withdraw and withdraw and call
lumtis Aug 9, 2024
f2288b7
implement erc20 withdraw e2e tests
lumtis Aug 9, 2024
a5ec5ab
test withdraw and call
lumtis Aug 9, 2024
ec88dd9
reading inbound for no assset call
lumtis Aug 9, 2024
17e084e
simple call implementation
lumtis Aug 10, 2024
4a977fb
initialize revert
lumtis Aug 11, 2024
f5e3ce9
fix the tests
lumtis Aug 13, 2024
0df1c6d
upgrade smart contracts to latest version
lumtis Aug 13, 2024
052bcb2
small fix smart contract call
lumtis Aug 13, 2024
8d1f0f0
revert tests skeleton
lumtis Aug 13, 2024
0da87ab
fix test
lumtis Aug 13, 2024
43467c4
implement revert tests
lumtis Aug 13, 2024
a2164a5
add revert support
lumtis Aug 13, 2024
a3e4f69
fix revert tests
lumtis Aug 14, 2024
0aa504f
make generate
lumtis Aug 14, 2024
5ff7d21
add support for revert gas limit
lumtis Aug 15, 2024
6621fe7
fix tests
lumtis Aug 15, 2024
cc3eb22
add liquidity test
lumtis Aug 15, 2024
fc67bba
fix liquidity test
lumtis Aug 15, 2024
02e04be
Update proto/zetachain/zetacore/pkg/coin/coin.proto
lumtis Aug 15, 2024
f90bfc4
Update x/crosschain/types/revert_options.go
lumtis Aug 15, 2024
113258a
Update x/crosschain/types/revert_options.go
lumtis Aug 15, 2024
ff75b88
Borja comments
lumtis Aug 15, 2024
9cdcfa9
Stefan comments
lumtis Aug 15, 2024
b28089c
dmitry review
lumtis Aug 15, 2024
c5868af
fix unit tests
lumtis Aug 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 54 additions & 8 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
}
noError(deployerRunner.FundEmissionsPool())

deployerRunner.MintERC20OnEvm(10000)
deployerRunner.MintERC20OnEvm(1000000)

logger.Print("✅ setup completed in %s", time.Since(startTime))
}
Expand Down Expand Up @@ -338,18 +338,64 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
eg.Go(solanaTestRoutine(conf, deployerRunner, verbose, solanaTests...))
}
if testV2 {
eg.Go(v2TestRoutine(conf, deployerRunner, verbose,
// update the ERC20 custody contract for v2 tests
deployerRunner.UpdateChainParamsERC20CustodyContract()

//// Test happy paths for gas token workflow
eg.Go(v2TestRoutine(conf, "eth", conf.AdditionalAccounts.UserEther, color.FgHiGreen, deployerRunner, verbose,
e2etests.TestV2ETHDepositName,
e2etests.TestV2ETHDepositAndCallName,
//e2etests.TestV2ETHWithdrawName,
//e2etests.TestV2ETHWithdrawAndCallName,
e2etests.TestV2ETHWithdrawName,
e2etests.TestV2ETHWithdrawAndCallName,
e2etests.TestV2ZEVMToEVMCallName,
e2etests.TestV2EVMToZEVMCallName,
))

//// Test happy paths for erc20 token workflow
eg.Go(v2TestRoutine(conf, "erc20", conf.AdditionalAccounts.UserERC20, color.FgHiBlue, deployerRunner, verbose,
e2etests.TestV2ETHDepositName, // necessary to pay fees on ZEVM
e2etests.TestV2ERC20DepositName,
e2etests.TestV2ERC20DepositAndCallName,
//e2etests.TestV2ERC20WithdrawName,
//e2etests.TestV2ERC20WithdrawAndCallName,
//e2etests.TestV2ZEVMToEVMCallName,
//e2etests.TestV2EVMToZEVMCallName,
e2etests.TestV2ERC20WithdrawName,
e2etests.TestV2ERC20WithdrawAndCallName,
))

// Test revert cases for gas token workflow
eg.Go(
v2TestRoutine(
conf,
"eth-revert",
conf.AdditionalAccounts.UserZetaTest,
color.FgHiYellow,
deployerRunner,
verbose,
e2etests.TestV2ETHDepositName, // necessary to pay fees on ZEVM and withdraw
e2etests.TestV2ETHDepositAndCallRevertName,
e2etests.TestV2ETHDepositAndCallRevertWithCallName,
e2etests.TestV2ETHWithdrawAndCallRevertName,
e2etests.TestV2ETHWithdrawAndCallRevertWithCallName,
),
)

// Test revert cases for erc20 token workflow
eg.Go(
v2TestRoutine(
conf,
"erc20-revert",
conf.AdditionalAccounts.UserBitcoin,
color.FgHiRed,
deployerRunner,
verbose,
e2etests.TestV2ETHDepositName, // necessary to pay fees on ZEVM
e2etests.TestV2ERC20DepositName, // necessary to have assets to withdraw
e2etests.TestOperationAddLiquidityETHName, // liquidity with gas and ERC20 are necessary for reverts
e2etests.TestOperationAddLiquidityERC20Name,
e2etests.TestV2ERC20DepositAndCallRevertName,
e2etests.TestV2ERC20DepositAndCallRevertWithCallName,
e2etests.TestV2ERC20WithdrawAndCallRevertName,
e2etests.TestV2ERC20WithdrawAndCallRevertWithCallName,
),
)
}

// while tests are executed, monitor blocks in parallel to check if system txs are on top and they have biggest priority
Expand Down
20 changes: 12 additions & 8 deletions cmd/zetae2e/local/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,34 @@ import (
// https://github.com/zeta-chain/node/issues/2554
func v2TestRoutine(
conf config.Config,
name string,
account config.Account,
color color.Attribute,
deployerRunner *runner.E2ERunner,
verbose bool,
testNames ...string,
) func() error {
return func() (err error) {
account := conf.AdditionalAccounts.UserERC20
name = "v2-" + name

// initialize runner for erc20 test
v2Runner, err := initTestRunner(
"v2",
name,
conf,
deployerRunner,
account,
runner.NewLogger(verbose, color.FgHiYellow, "v2"),
runner.NewLogger(verbose, color, name),
runner.WithZetaTxServer(deployerRunner.ZetaTxServer),
)
if err != nil {
return err
}

v2Runner.Logger.Print("🏃 starting v2 tests")
v2Runner.Logger.Print("🏃 starting %s tests", name)
startTime := time.Now()

// funding the account
txERC20Send := deployerRunner.SendERC20OnEvm(account.EVMAddress(), 10)
txERC20Send := deployerRunner.SendERC20OnEvm(account.EVMAddress(), 10000)
v2Runner.WaitForTxReceiptOnEvm(txERC20Send)

// run erc20 test
Expand All @@ -49,14 +53,14 @@ func v2TestRoutine(
testNames...,
)
if err != nil {
return fmt.Errorf("v2 tests failed: %v", err)
return fmt.Errorf("%s tests failed: %v", name, err)
}

if err := v2Runner.RunE2ETests(testsToRun); err != nil {
return fmt.Errorf("v2 tests failed: %v", err)
return fmt.Errorf("%s tests failed: %v", name, err)
}

v2Runner.Logger.Print("🍾 v2 tests completed in %s", time.Since(startTime).String())
v2Runner.Logger.Print("🍾 %s tests completed in %s", name, time.Since(startTime).String())

return err
}
Expand Down
21 changes: 20 additions & 1 deletion docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57071,11 +57071,13 @@ definitions:
- Gas
- ERC20
- Cmd
- NoAssetCall
default: Zeta
title: |-
- Gas: Ether, BNB, Matic, Klay, BTC, etc
- ERC20: ERC20 token
- Cmd: not a real coin, rather a command
- Cmd: no asset, used for admin command
- NoAssetCall: no asset, used for contract call
crosschainCctxStatus:
type: string
enum:
Expand Down Expand Up @@ -57123,6 +57125,8 @@ definitions:
$ref: '#/definitions/crosschainOutboundParams'
protocol_contract_version:
$ref: '#/definitions/crosschainProtocolContractVersion'
revert_options:
$ref: '#/definitions/crosschainRevertOptions'
crosschainGasPrice:
type: object
properties:
Expand Down Expand Up @@ -57548,6 +57552,21 @@ definitions:
type: object
$ref: '#/definitions/crosschainConversion'
title: conversion in azeta per token
crosschainRevertOptions:
type: object
properties:
revert_address:
type: string
call_on_revert:
type: boolean
abort_address:
type: string
revert_message:
type: string
format: byte
revert_gas_limit:
type: string
title: RevertOptions represents the options for reverting a cctx
crosschainTxFinalizationStatus:
type: string
enum:
Expand Down
1 change: 1 addition & 0 deletions docs/spec/crosschain/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ message MsgVoteInbound {
string asset = 14;
uint64 event_index = 15;
ProtocolContractVersion protocol_contract_version = 16;
RevertOptions revert_options = 17;
}
```

Expand Down
128 changes: 110 additions & 18 deletions e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,32 @@ const (
/*
V2 smart contract tests
*/
TestV2ETHDepositName = "v2_eth_deposit"
TestV2ETHDepositAndCallName = "v2_eth_deposit_and_call"
TestV2ETHWithdrawName = "v2_eth_withdraw"
TestV2ETHWithdrawAndCallName = "v2_eth_withdraw_and_call"
TestV2ERC20DepositName = "v2_erc20_deposit"
TestV2ERC20DepositAndCallName = "v2_erc20_deposit_and_call"
TestV2ERC20WithdrawName = "v2_erc20_withdraw"
TestV2ERC20WithdrawAndCallName = "v2_erc20_withdraw_and_call"
TestV2ZEVMToEVMCallName = "v2_zevm_to_evm_call"
TestV2EVMToZEVMCallName = "v2_evm_to_zevm_call"
TestV2ETHDepositName = "v2_eth_deposit"
TestV2ETHDepositAndCallName = "v2_eth_deposit_and_call"
TestV2ETHDepositAndCallRevertName = "v2_eth_deposit_and_call_revert"
TestV2ETHDepositAndCallRevertWithCallName = "v2_eth_deposit_and_call_revert_with_call"
TestV2ETHWithdrawName = "v2_eth_withdraw"
TestV2ETHWithdrawAndCallName = "v2_eth_withdraw_and_call"
TestV2ETHWithdrawAndCallRevertName = "v2_eth_withdraw_and_call_revert"
TestV2ETHWithdrawAndCallRevertWithCallName = "v2_eth_withdraw_and_call_revert_with_call"
TestV2ERC20DepositName = "v2_erc20_deposit"
TestV2ERC20DepositAndCallName = "v2_erc20_deposit_and_call"
TestV2ERC20DepositAndCallRevertName = "v2_erc20_deposit_and_call_revert"
TestV2ERC20DepositAndCallRevertWithCallName = "v2_erc20_deposit_and_call_revert_with_call"
TestV2ERC20WithdrawName = "v2_erc20_withdraw"
TestV2ERC20WithdrawAndCallName = "v2_erc20_withdraw_and_call"
TestV2ERC20WithdrawAndCallRevertName = "v2_erc20_withdraw_and_call_revert"
TestV2ERC20WithdrawAndCallRevertWithCallName = "v2_erc20_withdraw_and_call_revert_with_call"
TestV2ZEVMToEVMCallName = "v2_zevm_to_evm_call"
TestV2EVMToZEVMCallName = "v2_evm_to_zevm_call"

/*
Special tests
Operational tests
Not used to test functionalities but do various interactions with the netwoks
*/
TestDeploy = "deploy"
TestDeploy = "deploy"
TestOperationAddLiquidityETHName = "add_liquidity_eth"
TestOperationAddLiquidityERC20Name = "add_liquidity_erc20"
)

// AllE2ETests is an ordered list of all e2e tests
Expand Down Expand Up @@ -586,14 +596,20 @@ var AllE2ETests = []runner.E2ETest{
[]runner.ArgDefinition{},
TestCriticalAdminTransactions,
),
runner.NewE2ETest(
TestMigrateTSSName,
"migrate TSS funds",
[]runner.ArgDefinition{},
TestMigrateTSS,
),
/*
V2 smart contract tests
*/
runner.NewE2ETest(
TestV2ETHDepositName,
"deposit Ether into ZEVM using V2 contract",
[]runner.ArgDefinition{
{Description: "amount in wei", DefaultValue: "10000000000000000"},
{Description: "amount in wei", DefaultValue: "100000000000000000000"},
},
TestV2ETHDeposit,
),
Expand All @@ -605,6 +621,22 @@ var AllE2ETests = []runner.E2ETest{
},
TestV2ETHDepositAndCall,
),
runner.NewE2ETest(
TestV2ETHDepositAndCallRevertName,
"deposit Ether into ZEVM and call a contract using V2 contract that reverts",
[]runner.ArgDefinition{
{Description: "amount in wei", DefaultValue: "10000000000000000"},
},
TestV2ETHDepositAndCallRevert,
),
runner.NewE2ETest(
TestV2ETHDepositAndCallRevertWithCallName,
"deposit Ether into ZEVM and call a contract using V2 contract that reverts with a onRevert call",
[]runner.ArgDefinition{
{Description: "amount in wei", DefaultValue: "10000000000000000"},
},
TestV2ETHDepositAndCallRevertWithCall,
),
runner.NewE2ETest(
TestV2ETHWithdrawName,
"withdraw Ether from ZEVM using V2 contract",
Expand All @@ -621,11 +653,27 @@ var AllE2ETests = []runner.E2ETest{
},
TestV2ETHWithdrawAndCall,
),
runner.NewE2ETest(
TestV2ETHWithdrawAndCallRevertName,
"withdraw Ether from ZEVM and call a contract using V2 contract that reverts",
[]runner.ArgDefinition{
{Description: "amount in wei", DefaultValue: "100000"},
},
TestV2ETHWithdrawAndCallRevert,
),
runner.NewE2ETest(
TestV2ETHWithdrawAndCallRevertWithCallName,
"withdraw Ether from ZEVM and call a contract using V2 contract that reverts with a onRevert call",
[]runner.ArgDefinition{
{Description: "amount in wei", DefaultValue: "100000"},
},
TestV2ETHWithdrawAndCallRevertWithCall,
),
runner.NewE2ETest(
TestV2ERC20DepositName,
"deposit ERC20 into ZEVM using V2 contract",
[]runner.ArgDefinition{
{Description: "amount", DefaultValue: "100000"},
{Description: "amount", DefaultValue: "100000000000000000000"},
},
TestV2ERC20Deposit,
),
Expand All @@ -637,6 +685,22 @@ var AllE2ETests = []runner.E2ETest{
},
TestV2ERC20DepositAndCall,
),
runner.NewE2ETest(
TestV2ERC20DepositAndCallRevertName,
"deposit ERC20 into ZEVM and call a contract using V2 contract that reverts",
[]runner.ArgDefinition{
{Description: "amount", DefaultValue: "10000000000000000000"},
},
TestV2ERC20DepositAndCallRevert,
),
runner.NewE2ETest(
TestV2ERC20DepositAndCallRevertWithCallName,
"deposit ERC20 into ZEVM and call a contract using V2 contract that reverts with a onRevert call",
[]runner.ArgDefinition{
{Description: "amount", DefaultValue: "10000000000000000000"},
},
TestV2ERC20DepositAndCallRevertWithCall,
),
runner.NewE2ETest(
TestV2ERC20WithdrawName,
"withdraw ERC20 from ZEVM using V2 contract",
Expand All @@ -653,6 +717,22 @@ var AllE2ETests = []runner.E2ETest{
},
TestV2ERC20WithdrawAndCall,
),
runner.NewE2ETest(
TestV2ERC20WithdrawAndCallRevertName,
"withdraw ERC20 from ZEVM and call a contract using V2 contract that reverts",
[]runner.ArgDefinition{
{Description: "amount", DefaultValue: "1000"},
},
TestV2ERC20WithdrawAndCallRevert,
),
runner.NewE2ETest(
TestV2ERC20WithdrawAndCallRevertWithCallName,
"withdraw ERC20 from ZEVM and call a contract using V2 contract that reverts with a onRevert call",
[]runner.ArgDefinition{
{Description: "amount", DefaultValue: "1000"},
},
TestV2ERC20WithdrawAndCallRevertWithCall,
),
runner.NewE2ETest(
TestV2ZEVMToEVMCallName,
"zevm -> evm call using V2 contract",
Expand All @@ -677,9 +757,21 @@ var AllE2ETests = []runner.E2ETest{
TestDeployContract,
),
runner.NewE2ETest(
TestMigrateTSSName,
"migrate TSS funds",
[]runner.ArgDefinition{},
TestMigrateTSS,
TestOperationAddLiquidityETHName,
"add liquidity to the ZETA/ETH pool",
[]runner.ArgDefinition{
{Description: "amountZETA", DefaultValue: "50000000000000000000"},
{Description: "amountETH", DefaultValue: "50000000000000000000"},
},
TestOperationAddLiquidityETH,
),
runner.NewE2ETest(
TestOperationAddLiquidityERC20Name,
"add liquidity to the ZETA/ERC20 pool",
[]runner.ArgDefinition{
{Description: "amountZETA", DefaultValue: "50000000000000000000"},
{Description: "amountERC20", DefaultValue: "50000000000000000000"},
},
TestOperationAddLiquidityERC20,
),
}
Loading
Loading