Skip to content

Commit

Permalink
test(e2e): add gateway upgrade in upgrade test (#2932)
Browse files Browse the repository at this point in the history
* add gateway upgrade

* change reference

* add v2 setup for all tests

* test v2 in light upgrade

* refactor setup to use custody v2 directly
  • Loading branch information
lumtis authored Oct 1, 2024
1 parent 77486d7 commit 2e13c04
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,12 @@ start-v2-test: zetanode
ifdef UPGRADE_TEST_FROM_SOURCE
zetanode-upgrade: zetanode
@echo "Building zetanode-upgrade from source"
$(DOCKER) build -t zetanode:old -f Dockerfile-localnet --target old-runtime-source --build-arg OLD_VERSION='release/v19' .
$(DOCKER) build -t zetanode:old -f Dockerfile-localnet --target old-runtime-source --build-arg OLD_VERSION='release/v20' .
.PHONY: zetanode-upgrade
else
zetanode-upgrade: zetanode
@echo "Building zetanode-upgrade from binaries"
$(DOCKER) build -t zetanode:old -f Dockerfile-localnet --target old-runtime --build-arg OLD_VERSION='https://github.com/zeta-chain/node/releases/download/v19.1.1' .
$(DOCKER) build -t zetanode:old -f Dockerfile-localnet --target old-runtime --build-arg OLD_VERSION='https://github.com/zeta-chain/node/releases/download/v20.0.2' .
.PHONY: zetanode-upgrade
endif

Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* [2874](https://github.com/zeta-chain/node/pull/2874) - add support for multiple runs for precompile tests
* [2895](https://github.com/zeta-chain/node/pull/2895) - add e2e test for bitcoin deposit and call
* [2894](https://github.com/zeta-chain/node/pull/2894) - increase gas limit for TSS vote tx
* [2932](https://github.com/zeta-chain/node/pull/2932) - add gateway upgrade as part of the upgrade test

### Fixes

Expand Down
29 changes: 18 additions & 11 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const (
flagTestV2Migration = "test-v2-migration"
flagSkipTrackerCheck = "skip-tracker-check"
flagSkipPrecompiles = "skip-precompiles"
flagUpgradeGateways = "upgrade-gateways"
)

var (
Expand Down Expand Up @@ -83,6 +84,7 @@ func NewLocalCmd() *cobra.Command {
cmd.Flags().Bool(flagTestV2Migration, false, "set to true to run tests for v2 contracts migration test")
cmd.Flags().Bool(flagSkipTrackerCheck, false, "set to true to skip tracker check at the end of the tests")
cmd.Flags().Bool(flagSkipPrecompiles, false, "set to true to skip stateful precompiled contracts test")
cmd.Flags().Bool(flagUpgradeGateways, false, "set to true to upgrade gateways during setup for ZEVM and EVM")

return cmd
}
Expand Down Expand Up @@ -112,6 +114,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
testV2 = must(cmd.Flags().GetBool(flagTestV2))
testV2Migration = must(cmd.Flags().GetBool(flagTestV2Migration))
skipPrecompiles = must(cmd.Flags().GetBool(flagSkipPrecompiles))
upgradeGateways = must(cmd.Flags().GetBool(flagUpgradeGateways))
)

logger := runner.NewLogger(verbose, color.FgWhite, "setup")
Expand Down Expand Up @@ -202,21 +205,26 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
logger.Print("⚙️ setting up networks")
startTime := time.Now()

// TODO: merge v1 and v2 together
// https://github.com/zeta-chain/node/issues/2627

deployerRunner.SetupEVM(contractsDeployed, true)

if testV2 {
deployerRunner.SetupEVMV2()
}
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()
}
// NOTE: v2 (gateway) setup called here because system contract needs to be set first, then gateway, then zrc20
deployerRunner.SetZEVMContractsV2()

deployerRunner.SetZEVMZRC20s()

// Update the chain params to use v2 contract for ERC20Custody
// TODO: this function should be removed and the chain params should be directly set to use v2 contract
// https://github.com/zeta-chain/node/issues/2627
deployerRunner.UpdateChainParamsV2Contracts()
deployerRunner.ERC20CustodyAddr = deployerRunner.ERC20CustodyV2Addr

if testSolana {
deployerRunner.SetSolanaContracts(conf.AdditionalAccounts.UserSolana.SolanaPrivateKey.String())
}
Expand Down Expand Up @@ -404,10 +412,9 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
eg.Go(tonTestRoutine(conf, deployerRunner, verbose, tonTests...))
}

if testV2 {
// update the ERC20 custody contract for v2 tests
// note: not run in testV2Migration because it is already run in the migration process
deployerRunner.UpdateChainParamsV2Contracts()
// upgrade gateways
if upgradeGateways {
deployerRunner.UpgradeGateways()
}

if testV2 || testV2Migration {
Expand Down
4 changes: 2 additions & 2 deletions contrib/localnet/orchestrator/start-zetae2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ if [ "$LOCALNET_MODE" == "upgrade" ]; then
# When the upgrade height is greater than 100 for upgrade test, the Bitcoin tests have been run once, therefore the Bitcoin wallet is already set up
# Use light flag to skip advanced tests
if [ "$UPGRADE_HEIGHT" -lt 100 ]; then
zetae2e local $E2E_ARGS --skip-setup --config "$deployed_config_path" --light ${COMMON_ARGS}
zetae2e local $E2E_ARGS --skip-setup --config "$deployed_config_path" --light --test-v2 --upgrade-gateways ${COMMON_ARGS}
else
zetae2e local $E2E_ARGS --skip-setup --config "$deployed_config_path" --skip-bitcoin-setup --light ${COMMON_ARGS}
zetae2e local $E2E_ARGS --skip-setup --config "$deployed_config_path" --skip-bitcoin-setup --light --test-v2 --upgrade-gateways ${COMMON_ARGS}
fi

ZETAE2E_EXIT_CODE=$?
Expand Down
55 changes: 55 additions & 0 deletions e2e/runner/v2_gateway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package runner

import (
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"
"github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayevm.sol"
"github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayzevm.sol"

"github.com/zeta-chain/node/e2e/utils"
)

// UpgradeGateways upgrades the GatewayEVM and GatewayZEVM contracts
// It deploy new gateway contract implementation with the current imported artifacts and upgrade the gateway contract
func (r *E2ERunner) UpgradeGateways() {
r.UpgradeGatewayZEVM()
r.UpgradeGatewayEVM()
}

// UpgradeGatewayZEVM upgrades the GatewayZEVM contract
func (r *E2ERunner) UpgradeGatewayZEVM() {
ensureTxReceipt := func(tx *ethtypes.Transaction, failMessage string) {
receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)
r.requireTxSuccessful(receipt, failMessage+" tx hash: "+tx.Hash().Hex())
}

r.Logger.Info("Upgrading Gateway ZEVM contract")
// Deploy the new gateway contract implementation
newImplementationAddress, txDeploy, _, err := gatewayzevm.DeployGatewayZEVM(r.ZEVMAuth, r.ZEVMClient)
require.NoError(r, err)
ensureTxReceipt(txDeploy, "New GatewayZEVM implementation deployment failed")

// Upgrade
txUpgrade, err := r.GatewayZEVM.UpgradeToAndCall(r.ZEVMAuth, newImplementationAddress, []byte{})
require.NoError(r, err)
ensureTxReceipt(txUpgrade, "GatewayZEVM upgrade failed")
}

// UpgradeGatewayEVM upgrades the GatewayEVM contract
func (r *E2ERunner) UpgradeGatewayEVM() {
ensureTxReceipt := func(tx *ethtypes.Transaction, failMessage string) {
receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout)
r.requireTxSuccessful(receipt, failMessage+" tx hash: "+tx.Hash().Hex())
}

r.Logger.Info("Upgrading Gateway EVM contract")
// Deploy the new gateway contract implementation
newImplementationAddress, txDeploy, _, err := gatewayevm.DeployGatewayEVM(r.EVMAuth, r.EVMClient)
require.NoError(r, err)
ensureTxReceipt(txDeploy, "New GatewayEVM implementation deployment failed")

// Upgrade
txUpgrade, err := r.GatewayEVM.UpgradeToAndCall(r.EVMAuth, newImplementationAddress, []byte{})
require.NoError(r, err)
ensureTxReceipt(txUpgrade, "GatewayEVM upgrade failed")
}

0 comments on commit 2e13c04

Please sign in to comment.