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: integrate Protocol Contracts v2 #2594

Merged
merged 37 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
54db7f3
update protocol contracts package
lumtis Jul 26, 2024
1b39785
update config and runner
lumtis Jul 26, 2024
c83c263
init contract deploy
lumtis Jul 26, 2024
a6694b1
add erc1967proxy in contracts
lumtis Jul 29, 2024
00241f2
fix gateway evm deploy
lumtis Jul 30, 2024
054016a
zevm setuip
lumtis Jul 30, 2024
f9572ef
format
lumtis Jul 30, 2024
dc52ad7
Merge branch 'develop' into feat/contract-v2-2
lumtis Jul 30, 2024
da88f46
update version
lumtis Jul 31, 2024
33c4428
update v1 import path
lumtis Jul 31, 2024
ba30025
reorganize import v2
lumtis Jul 31, 2024
9a0e367
fix import
lumtis Jul 31, 2024
026a9b7
update new version
lumtis Jul 31, 2024
53337e6
add custody setup
lumtis Jul 31, 2024
ba5a7d0
feat(E2E): add body for smart contract V2 tests (#2609)
lumtis Jul 31, 2024
37b09fa
update system contracts
lumtis Aug 1, 2024
0c3e5ff
Merge branch 'develop' into feat/contract-v2-2
lumtis Aug 1, 2024
5a9e339
feat: implement gas token deposit with protocol contract v2 (#2616)
lumtis Aug 6, 2024
e158344
feat: withdraw SOL from ZEVM to Solana (#2560)
ws4charlie Aug 1, 2024
d21147f
feat: detect memo in btc txn from OP_RETURN and inscription (#2533)
bitSmiley Aug 2, 2024
ebf100d
refactor(zetaclient)!: improve AppContext (#2568)
swift1337 Aug 2, 2024
d1d3a45
fix(`crosschain`): set sender for ERC20 whitelist admin CCTX inbound …
lumtis Aug 5, 2024
ef554d4
fix(ci): Update golang cross compile to 1.22.4 (#2635)
CryptoFewka Aug 6, 2024
2642ac9
Added goreleaser check (#2636)
CharlieMc0 Aug 6, 2024
fa9713c
update solidity version
lumtis Aug 6, 2024
0a596a9
conflicts
lumtis Aug 6, 2024
39a3ca7
feat: integrate Smart Contract V2 `depositAndCall` for ETH and ERC20 …
lumtis Aug 8, 2024
e900a96
feat: support withdraws, calls and reverts with Gateway contract (#2666)
lumtis Aug 16, 2024
cdfcb34
changelogs
lumtis Aug 16, 2024
5dc63ff
conflicts
lumtis Aug 16, 2024
4838739
fix unit test
lumtis Aug 16, 2024
e18bf2c
tentative fix for upgrade
lumtis Aug 16, 2024
1faed35
fix gateway zero address
lumtis Aug 16, 2024
4d6ea41
Merge branch 'develop' into feat/contract-v2-2
lumtis Aug 16, 2024
c8a19a1
fix admin test
lumtis Aug 16, 2024
71a608e
add back admin tests
lumtis Aug 16, 2024
c13c70b
v2 conditional matric
lumtis Aug 16, 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
12 changes: 12 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ on:
type: boolean
required: false
default: false
v2-test:
type: boolean
required: false
default: false

concurrency:
group: e2e-${{ github.head_ref || github.sha }}
Expand All @@ -69,6 +73,7 @@ jobs:
STATEFUL_DATA_TESTS: ${{ steps.matrix-conditionals.outputs.STATEFUL_DATA_TESTS }}
TSS_MIGRATION_TESTS: ${{ steps.matrix-conditionals.outputs.TSS_MIGRATION_TESTS }}
SOLANA_TESTS: ${{ steps.matrix-conditionals.outputs.SOLANA_TESTS }}
V2_TESTS: ${{ steps.matrix-conditionals.outputs.V2_TESTS }}
steps:
# use api rather than event context to avoid race conditions (label added after push)
- id: matrix-conditionals
Expand All @@ -92,6 +97,7 @@ jobs:
core.setOutput('STATEFUL_DATA_TESTS', labels.includes('STATEFUL_DATA_TESTS'));
core.setOutput('TSS_MIGRATION_TESTS', labels.includes('TSS_MIGRATION_TESTS'));
core.setOutput('SOLANA_TESTS', labels.includes('SOLANA_TESTS'));
core.setOutput('V2_TESTS', labels.includes('V2_TESTS')); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627)
lumtis marked this conversation as resolved.
Show resolved Hide resolved
} else if (context.eventName === 'merge_group') {
core.setOutput('DEFAULT_TESTS', true);
core.setOutput('UPGRADE_LIGHT_TESTS', true);
Expand All @@ -105,6 +111,7 @@ jobs:
core.setOutput('ADMIN_TESTS', true);
core.setOutput('PERFORMANCE_TESTS', true);
core.setOutput('STATEFUL_DATA_TESTS', true);
core.setOutput('V2_TESTS', true); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627)
} else if (context.eventName === 'schedule') {
core.setOutput('DEFAULT_TESTS', true);
core.setOutput('UPGRADE_TESTS', true);
Expand All @@ -115,6 +122,7 @@ jobs:
core.setOutput('STATEFUL_DATA_TESTS', true);
core.setOutput('TSS_MIGRATION_TESTS', true);
core.setOutput('SOLANA_TESTS', true);
core.setOutput('V2_TESTS', true); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627)
} else if (context.eventName === 'workflow_dispatch') {
core.setOutput('DEFAULT_TESTS', context.payload.inputs['default-test']);
core.setOutput('UPGRADE_TESTS', context.payload.inputs['upgrade-test']);
Expand All @@ -125,6 +133,7 @@ jobs:
core.setOutput('STATEFUL_DATA_TESTS', context.payload.inputs['stateful-data-test']);
core.setOutput('TSS_MIGRATION_TESTS', context.payload.inputs['tss-migration-test']);
core.setOutput('SOLANA_TESTS', context.payload.inputs['solana-test']);
core.setOutput('V2_TESTS', context.payload.inputs['v2-test']); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627)
}

e2e:
Expand Down Expand Up @@ -162,6 +171,9 @@ jobs:
- make-target: "start-solana-test"
runs-on: ubuntu-20.04
run: ${{ needs.matrix-conditionals.outputs.SOLANA_TESTS == 'true' }}
- make-target: "start-v2-test"
runs-on: ubuntu-20.04
run: ${{ needs.matrix-conditionals.outputs.V2_TESTS == 'true' }}
name: ${{ matrix.make-target }}
uses: ./.github/workflows/reusable-e2e.yml
with:
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ start-solana-test: zetanode solana
export E2E_ARGS="--skip-regular --test-solana" && \
cd contrib/localnet/ && $(DOCKER_COMPOSE) --profile solana -f docker-compose.yml up -d

start-v2-test: zetanode
@echo "--> Starting e2e smart contracts v2 test"
export E2E_ARGS="--skip-regular --test-v2" && \
cd contrib/localnet/ && $(DOCKER_COMPOSE) -f docker-compose.yml up -d

###############################################################################
### Upgrade Tests ###
###############################################################################
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* [2578](https://github.com/zeta-chain/node/pull/2578) - add Gateway address in protocol contract list
* [2630](https://github.com/zeta-chain/node/pull/2630) - implement `MsgMigrateERC20CustodyFunds` to migrate the funds from the ERC20Custody to a new contracts (to be used for the new ERC20Custody contract for smart contract V2)
* [2578](https://github.com/zeta-chain/node/pull/2578) - Add Gateway address in protocol contract list
* [2594](https://github.com/zeta-chain/node/pull/2594) - Integrate Protocol Contracts V2 in the protocol
* [2634](https://github.com/zeta-chain/node/pull/2634) - add support for EIP-1559 gas fees
* [2597](https://github.com/zeta-chain/node/pull/2597) - Add generic rpc metrics to zetaclient
* [2538](https://github.com/zeta-chain/node/pull/2538) - add background worker routines to shutdown zetaclientd when needed for tss migration
Expand Down
8 changes: 8 additions & 0 deletions cmd/zetae2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,13 @@ func ExportContractsFromRunner(r *runner.E2ERunner, conf config.Config) config.C
conf.Contracts.ZEVM.ContextAppAddr = config.DoubleQuotedString(r.ContextAppAddr.Hex())
conf.Contracts.ZEVM.TestDappAddr = config.DoubleQuotedString(r.ZevmTestDAppAddr.Hex())

// v2
conf.Contracts.EVM.Gateway = config.DoubleQuotedString(r.GatewayEVMAddr.Hex())
conf.Contracts.EVM.ERC20CustodyNew = config.DoubleQuotedString(r.ERC20CustodyV2Addr.Hex())
conf.Contracts.EVM.TestDAppV2Addr = config.DoubleQuotedString(r.TestDAppV2EVMAddr.Hex())

conf.Contracts.ZEVM.Gateway = config.DoubleQuotedString(r.GatewayZEVMAddr.Hex())
conf.Contracts.ZEVM.TestDAppV2Addr = config.DoubleQuotedString(r.TestDAppV2ZEVMAddr.Hex())

return conf
}
79 changes: 70 additions & 9 deletions cmd/zetae2e/config/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ import (
"fmt"

"github.com/gagliardetto/solana-go"
"github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/erc20custody.sol"
zetaeth "github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/zeta.eth.sol"
zetaconnectoreth "github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/zetaconnector.eth.sol"
"github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/systemcontract.sol"
"github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/wzeta.sol"
connectorzevm "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/zetaconnectorzevm.sol"
"github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/zrc20.sol"
"github.com/zeta-chain/protocol-contracts/pkg/uniswap/v2-core/contracts/uniswapv2factory.sol"
uniswapv2router "github.com/zeta-chain/protocol-contracts/pkg/uniswap/v2-periphery/contracts/uniswapv2router02.sol"
"github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/evm/erc20custody.sol"
zetaeth "github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/evm/zeta.eth.sol"
zetaconnectoreth "github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/evm/zetaconnector.eth.sol"
"github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/zevm/systemcontract.sol"
"github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/zevm/wzeta.sol"
connectorzevm "github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/zevm/zetaconnectorzevm.sol"
"github.com/zeta-chain/protocol-contracts/v1/pkg/uniswap/v2-core/contracts/uniswapv2factory.sol"
uniswapv2router "github.com/zeta-chain/protocol-contracts/v1/pkg/uniswap/v2-periphery/contracts/uniswapv2router02.sol"
erc20custodyv2 "github.com/zeta-chain/protocol-contracts/v2/pkg/erc20custody.sol"
"github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayevm.sol"
"github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayzevm.sol"
"github.com/zeta-chain/protocol-contracts/v2/pkg/zrc20.sol"

"github.com/zeta-chain/zetacore/e2e/config"
"github.com/zeta-chain/zetacore/e2e/contracts/contextapp"
"github.com/zeta-chain/zetacore/e2e/contracts/erc20"
"github.com/zeta-chain/zetacore/e2e/contracts/zevmswap"
"github.com/zeta-chain/zetacore/e2e/runner"
"github.com/zeta-chain/zetacore/pkg/contracts/testdappv2"
)

// setContractsFromConfig get EVM contracts from config
Expand Down Expand Up @@ -211,5 +215,62 @@ func setContractsFromConfig(r *runner.E2ERunner, conf config.Config) error {
}
}

// v2 contracts

if c := conf.Contracts.EVM.Gateway; c != "" {
r.GatewayEVMAddr, err = c.AsEVMAddress()
if err != nil {
return fmt.Errorf("invalid GatewayAddr: %w", err)
}
r.GatewayEVM, err = gatewayevm.NewGatewayEVM(r.GatewayEVMAddr, r.EVMClient)
if err != nil {
return err
}
}

if c := conf.Contracts.EVM.ERC20CustodyNew; c != "" {
r.ERC20CustodyV2Addr, err = c.AsEVMAddress()
if err != nil {
return fmt.Errorf("invalid ERC20CustodyV2Addr: %w", err)
}
r.ERC20CustodyV2, err = erc20custodyv2.NewERC20Custody(r.ERC20CustodyV2Addr, r.EVMClient)
if err != nil {
return err
}
}

if c := conf.Contracts.EVM.TestDAppV2Addr; c != "" {
r.TestDAppV2EVMAddr, err = c.AsEVMAddress()
if err != nil {
return fmt.Errorf("invalid TestDAppV2Addr: %w", err)
}
r.TestDAppV2EVM, err = testdappv2.NewTestDAppV2(r.TestDAppV2EVMAddr, r.EVMClient)
if err != nil {
return err
}
}

if c := conf.Contracts.ZEVM.Gateway; c != "" {
r.GatewayZEVMAddr, err = c.AsEVMAddress()
if err != nil {
return fmt.Errorf("invalid GatewayAddr: %w", err)
}
r.GatewayZEVM, err = gatewayzevm.NewGatewayZEVM(r.GatewayZEVMAddr, r.ZEVMClient)
if err != nil {
return err
}
}

if c := conf.Contracts.ZEVM.TestDAppV2Addr; c != "" {
r.TestDAppV2ZEVMAddr, err = c.AsEVMAddress()
if err != nil {
return fmt.Errorf("invalid TestDAppV2Addr: %w", err)
}
r.TestDAppV2ZEVM, err = testdappv2.NewTestDAppV2(r.TestDAppV2ZEVMAddr, r.EVMClient)
if err != nil {
return err
}
}

return nil
}
4 changes: 3 additions & 1 deletion cmd/zetae2e/config/local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ contracts:
connector_zevm: "0x239e96c8f17C85c30100AC26F635Ea15f23E9c67"
wzeta: "0x5F0b1a82749cb4E2278EC87F8BF6B618dC71a8bf"
test_dapp: "0xA8D5060feb6B456e886F023709A2795373691E63"
gateway: "0xa825eAa55b497AF892faca73a3797046C10B7c23"
evm:
zeta_eth: "0x733aB8b06DDDEf27Eaa72294B0d7c9cEF7f12db9"
connector_eth: "0xD28D6A0b8189305551a0A8bd247a6ECa9CE781Ca"
custody: "0xff3135df4F2775f4091b81f4c7B6359CfA07862a"
erc20: "0xbD1e64A22B9F92D9Ce81aA9B4b0fFacd80215564"
test_dapp: "0xBFF76e77D56B3C1202107f059425D56f0AEF87Ed"
test_dapp: "0xBFF76e77D56B3C1202107f059425D56f0AEF87Ed"
gateway: "0xF0deebCB0E9C829519C4baa794c5445171973826"
80 changes: 78 additions & 2 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const (
flagTestTSSMigration = "test-tss-migration"
flagSkipBitcoinSetup = "skip-bitcoin-setup"
flagSkipHeaderProof = "skip-header-proof"
flagTestV2 = "test-v2"
flagSkipTrackerCheck = "skip-tracker-check"
)

Expand Down Expand Up @@ -74,6 +75,7 @@ func NewLocalCmd() *cobra.Command {
cmd.Flags().Bool(flagSkipBitcoinSetup, false, "set to true to skip bitcoin wallet setup")
cmd.Flags().Bool(flagSkipHeaderProof, false, "set to true to skip header proof tests")
cmd.Flags().Bool(flagTestTSSMigration, false, "set to true to include a migration test at the end")
cmd.Flags().Bool(flagTestV2, false, "set to true to run tests for v2 contracts")
cmd.Flags().Bool(flagSkipTrackerCheck, false, "set to true to skip tracker check at the end of the tests")

return cmd
Expand All @@ -98,6 +100,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
skipHeaderProof = must(cmd.Flags().GetBool(flagSkipHeaderProof))
skipTrackerCheck = must(cmd.Flags().GetBool(flagSkipTrackerCheck))
testTSSMigration = must(cmd.Flags().GetBool(flagTestTSSMigration))
testV2 = must(cmd.Flags().GetBool(flagTestV2))
)

logger := runner.NewLogger(verbose, color.FgWhite, "setup")
Expand Down Expand Up @@ -185,13 +188,26 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
startTime := time.Now()

deployerRunner.SetupEVM(contractsDeployed, true)
deployerRunner.SetZEVMContracts()

if testV2 {
deployerRunner.SetupEVMV2()
}

deployerRunner.SetZEVMSystemContracts()

if testV2 {
// NOTE: v2 (gateway) setup called here because system contract needs to be set first, then gateway, then zrc20
deployerRunner.SetZEVMContractsV2()
}

deployerRunner.SetZEVMZRC20s()

if testSolana {
deployerRunner.SetSolanaContracts(conf.AdditionalAccounts.UserSolana.SolanaPrivateKey.String())
}
noError(deployerRunner.FundEmissionsPool())

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

logger.Print("✅ setup completed in %s", time.Since(startTime))
}
Expand Down Expand Up @@ -335,6 +351,66 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
}
eg.Go(solanaTestRoutine(conf, deployerRunner, verbose, solanaTests...))
}
if testV2 {
// 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.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,
))

// 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
txPriorityErrCh := make(chan error, 1)
Expand Down
67 changes: 67 additions & 0 deletions cmd/zetae2e/local/v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package local

import (
"fmt"
"time"

"github.com/fatih/color"

"github.com/zeta-chain/zetacore/e2e/config"
"github.com/zeta-chain/zetacore/e2e/e2etests"
"github.com/zeta-chain/zetacore/e2e/runner"
)

// erc20TestRoutine runs v2 related e2e tests
// TODO: this routine will be broken down in the future and will replace most current tests
// we keep a single routine for v2 for simplicity
// 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) {
name = "v2-" + name

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

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

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

// run erc20 test
testsToRun, err := v2Runner.GetE2ETestsToRunByName(
e2etests.AllE2ETests,
testNames...,
)
if err != nil {
return fmt.Errorf("%s tests failed: %v", name, err)
}

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

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

return err
}
}
Loading
Loading