From 2146e4f1a2e007d788dfae018af15e52d8e658ee Mon Sep 17 00:00:00 2001 From: skosito Date: Tue, 15 Oct 2024 16:41:36 +0100 Subject: [PATCH] fix: fix admin e2e tests and bump protocol contracts (#3006) * bump protocol contracts * fix build and e2e tests * upgrade custody in upgrade tests * PR comments * fmt --- cmd/zetae2e/local/local.go | 12 +++--- .../localnet/orchestrator/start-zetae2e.sh | 4 +- e2e/runner/v2_setup_evm.go | 41 +++++++++++++------ e2e/runner/{v2_gateway.go => v2_upgrade.go} | 27 ++++++++++-- go.mod | 2 +- go.sum | 4 +- 6 files changed, 63 insertions(+), 27 deletions(-) rename e2e/runner/{v2_gateway.go => v2_upgrade.go} (62%) diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index 588a74e367..2d404ba391 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -46,7 +46,7 @@ const ( flagTestV2Migration = "test-v2-migration" flagSkipTrackerCheck = "skip-tracker-check" flagSkipPrecompiles = "skip-precompiles" - flagUpgradeGateways = "upgrade-gateways" + flagUpgradeContracts = "upgrade-contracts" ) var ( @@ -84,7 +84,8 @@ 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") + cmd.Flags(). + Bool(flagUpgradeContracts, false, "set to true to upgrade Gateways and ERC20Custody contracts during setup for ZEVM and EVM") return cmd } @@ -114,7 +115,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)) + upgradeContracts = must(cmd.Flags().GetBool(flagUpgradeContracts)) ) logger := runner.NewLogger(verbose, color.FgWhite, "setup") @@ -413,9 +414,8 @@ func localE2ETest(cmd *cobra.Command, _ []string) { eg.Go(tonTestRoutine(conf, deployerRunner, verbose, tonTests...)) } - // upgrade gateways - if upgradeGateways { - deployerRunner.UpgradeGateways() + if upgradeContracts { + deployerRunner.UpgradeGatewaysAndERC20Custody() } if testV2 || testV2Migration { diff --git a/contrib/localnet/orchestrator/start-zetae2e.sh b/contrib/localnet/orchestrator/start-zetae2e.sh index e7374216f3..33f0d4e956 100644 --- a/contrib/localnet/orchestrator/start-zetae2e.sh +++ b/contrib/localnet/orchestrator/start-zetae2e.sh @@ -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 --test-v2 --upgrade-gateways ${COMMON_ARGS} + zetae2e local $E2E_ARGS --skip-setup --config "$deployed_config_path" --light --test-v2 --upgrade-contracts ${COMMON_ARGS} else - zetae2e local $E2E_ARGS --skip-setup --config "$deployed_config_path" --skip-bitcoin-setup --light --test-v2 --upgrade-gateways ${COMMON_ARGS} + zetae2e local $E2E_ARGS --skip-setup --config "$deployed_config_path" --skip-bitcoin-setup --light --test-v2 --upgrade-contracts ${COMMON_ARGS} fi ZETAE2E_EXIT_CODE=$? diff --git a/e2e/runner/v2_setup_evm.go b/e2e/runner/v2_setup_evm.go index 37f6423f29..5b8e686d9b 100644 --- a/e2e/runner/v2_setup_evm.go +++ b/e2e/runner/v2_setup_evm.go @@ -48,8 +48,8 @@ func (r *E2ERunner) SetupEVMV2() { initializerData, err := gatewayEVMABI.Pack("initialize", r.TSSAddress, r.ZetaEthAddr, r.Account.EVMAddress()) require.NoError(r, err) - // Deploy the proxy contract - proxyAddress, txProxy, _, err := erc1967proxy.DeployERC1967Proxy( + // Deploy gateway proxy contract + gatewayProxyAddress, gatewayProxyTx, _, err := erc1967proxy.DeployERC1967Proxy( r.EVMAuth, r.EVMClient, gatewayEVMAddr, @@ -57,33 +57,47 @@ func (r *E2ERunner) SetupEVMV2() { ) require.NoError(r, err) - r.GatewayEVMAddr = proxyAddress - r.GatewayEVM, err = gatewayevm.NewGatewayEVM(proxyAddress, r.EVMClient) + r.GatewayEVMAddr = gatewayProxyAddress + r.GatewayEVM, err = gatewayevm.NewGatewayEVM(gatewayProxyAddress, r.EVMClient) require.NoError(r, err) r.Logger.Info("Gateway EVM contract address: %s, tx hash: %s", gatewayEVMAddr.Hex(), txGateway.Hash().Hex()) + // Deploy erc20custody proxy contract r.Logger.Info("Deploying ERC20Custody contract") - erc20CustodyNewAddr, txCustody, erc20CustodyNew, err := erc20custodyv2.DeployERC20Custody( + erc20CustodyAddr, txCustody, _, err := erc20custodyv2.DeployERC20Custody(r.EVMAuth, r.EVMClient) + require.NoError(r, err) + + ensureTxReceipt(txCustody, "ERC20Custody deployment failed") + + erc20CustodyABI, err := erc20custodyv2.ERC20CustodyMetaData.GetAbi() + require.NoError(r, err) + + // Encode the initializer data + initializerData, err = erc20CustodyABI.Pack("initialize", r.GatewayEVMAddr, r.TSSAddress, r.Account.EVMAddress()) + require.NoError(r, err) + + // Deploy erc20custody proxy contract + erc20CustodyProxyAddress, erc20ProxyTx, _, err := erc1967proxy.DeployERC1967Proxy( r.EVMAuth, r.EVMClient, - r.GatewayEVMAddr, - r.TSSAddress, - r.Account.EVMAddress(), + erc20CustodyAddr, + initializerData, ) require.NoError(r, err) - r.ERC20CustodyV2Addr = erc20CustodyNewAddr - r.ERC20CustodyV2 = erc20CustodyNew + r.ERC20CustodyV2Addr = erc20CustodyProxyAddress + r.ERC20CustodyV2, err = erc20custodyv2.NewERC20Custody(erc20CustodyProxyAddress, r.EVMClient) + require.NoError(r, err) r.Logger.Info( "ERC20CustodyV2 contract address: %s, tx hash: %s", - erc20CustodyNewAddr.Hex(), + erc20CustodyAddr.Hex(), txCustody.Hash().Hex(), ) ensureTxReceipt(txCustody, "ERC20CustodyV2 deployment failed") // set custody contract in gateway - txSetCustody, err := r.GatewayEVM.SetCustody(r.EVMAuth, erc20CustodyNewAddr) + txSetCustody, err := r.GatewayEVM.SetCustody(r.EVMAuth, erc20CustodyProxyAddress) require.NoError(r, err) // deploy test dapp v2 @@ -96,7 +110,8 @@ func (r *E2ERunner) SetupEVMV2() { // check contract deployment receipt ensureTxReceipt(txDonation, "EVM donation tx failed") - ensureTxReceipt(txProxy, "Gateway proxy deployment failed") + ensureTxReceipt(gatewayProxyTx, "Gateway proxy deployment failed") + ensureTxReceipt(erc20ProxyTx, "ERC20Custody proxy deployment failed") ensureTxReceipt(txSetCustody, "Set custody in Gateway failed") ensureTxReceipt(txTestDAppV2, "TestDAppV2 deployment failed") diff --git a/e2e/runner/v2_gateway.go b/e2e/runner/v2_upgrade.go similarity index 62% rename from e2e/runner/v2_gateway.go rename to e2e/runner/v2_upgrade.go index 2bede9e3fe..eb5af7f860 100644 --- a/e2e/runner/v2_gateway.go +++ b/e2e/runner/v2_upgrade.go @@ -3,17 +3,19 @@ package runner import ( ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/stretchr/testify/require" + "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/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() { +// UpgradeGatewaysAndERC20Custody upgrades gateways and ERC20Custody contracts +// It deploys new contract implementation with the current imported artifacts and upgrades the contract +func (r *E2ERunner) UpgradeGatewaysAndERC20Custody() { r.UpgradeGatewayZEVM() r.UpgradeGatewayEVM() + r.UpgradeERC20Custody() } // UpgradeGatewayZEVM upgrades the GatewayZEVM contract @@ -53,3 +55,22 @@ func (r *E2ERunner) UpgradeGatewayEVM() { require.NoError(r, err) ensureTxReceipt(txUpgrade, "GatewayEVM upgrade failed") } + +// UpgradeERC20CustodyZEVM upgrades the ERC20Custody contract +func (r *E2ERunner) UpgradeERC20Custody() { + 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 ERC20Custody contract") + // Deploy the new erc20Custody contract implementation + newImplementationAddress, txDeploy, _, err := erc20custody.DeployERC20Custody(r.EVMAuth, r.EVMClient) + require.NoError(r, err) + ensureTxReceipt(txDeploy, "New ERC20Custody implementation deployment failed") + + // Upgrade + txUpgrade, err := r.ERC20CustodyV2.UpgradeToAndCall(r.EVMAuth, newImplementationAddress, []byte{}) + require.NoError(r, err) + ensureTxReceipt(txUpgrade, "ERC20Custody upgrade failed") +} diff --git a/go.mod b/go.mod index 23dae42fae..cb746a49bf 100644 --- a/go.mod +++ b/go.mod @@ -59,7 +59,7 @@ require ( github.com/stretchr/testify v1.9.0 github.com/zeta-chain/ethermint v0.0.0-20241010181243-044e22bdb7e7 github.com/zeta-chain/keystone/keys v0.0.0-20240826165841-3874f358c138 - github.com/zeta-chain/protocol-contracts v1.0.2-athens3.0.20241009160411-475acfac26ef + github.com/zeta-chain/protocol-contracts v1.0.2-athens3.0.20241014093550-f7f6d9fd971a gitlab.com/thorchain/tss/go-tss v1.6.5 go.nhat.io/grpcmock v0.25.0 golang.org/x/crypto v0.23.0 diff --git a/go.sum b/go.sum index f5be31056c..8842365a96 100644 --- a/go.sum +++ b/go.sum @@ -4208,8 +4208,8 @@ github.com/zeta-chain/go-tss v0.0.0-20240916173049-89fee4b0ae7f h1:XqUvw9a3EnDa2 github.com/zeta-chain/go-tss v0.0.0-20240916173049-89fee4b0ae7f/go.mod h1:B1FDE6kHs8hozKSX1/iXgCdvlFbS6+FeAupoBHDK0Cc= github.com/zeta-chain/keystone/keys v0.0.0-20240826165841-3874f358c138 h1:vck/FcIIpFOvpBUm0NO17jbEtmSz/W/a5Y4jRuSJl6I= github.com/zeta-chain/keystone/keys v0.0.0-20240826165841-3874f358c138/go.mod h1:U494OsZTWsU75hqoriZgMdSsgSGP1mUL1jX+wN/Aez8= -github.com/zeta-chain/protocol-contracts v1.0.2-athens3.0.20241009160411-475acfac26ef h1:tfF31iib7rTeBLGrvWMbW2HM6omkzPDjsX8QM2VY6a4= -github.com/zeta-chain/protocol-contracts v1.0.2-athens3.0.20241009160411-475acfac26ef/go.mod h1:SjT7QirtJE8stnAe1SlNOanxtfSfijJm3MGJ+Ax7w7w= +github.com/zeta-chain/protocol-contracts v1.0.2-athens3.0.20241014093550-f7f6d9fd971a h1:xsup+oupCrBtZT/jEaBGcL3k6KUlXWR7iXw/3RHBIpU= +github.com/zeta-chain/protocol-contracts v1.0.2-athens3.0.20241014093550-f7f6d9fd971a/go.mod h1:SjT7QirtJE8stnAe1SlNOanxtfSfijJm3MGJ+Ax7w7w= github.com/zeta-chain/tss-lib v0.0.0-20240916163010-2e6b438bd901 h1:9whtN5fjYHfk4yXIuAsYP2EHxImwDWDVUOnZJ2pfL3w= github.com/zeta-chain/tss-lib v0.0.0-20240916163010-2e6b438bd901/go.mod h1:d2iTC62s9JwKiCMPhcDDXbIZmuzAyJ4lwso0H5QyRbk= github.com/zondax/hid v0.9.1/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM=