Skip to content

Commit

Permalink
fix: fix admin e2e tests and bump protocol contracts (#3006)
Browse files Browse the repository at this point in the history
* bump protocol contracts

* fix build and e2e tests

* upgrade custody in upgrade tests

* PR comments

* fmt
  • Loading branch information
skosito authored Oct 15, 2024
1 parent 09e8c3a commit 2146e4f
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 27 deletions.
12 changes: 6 additions & 6 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const (
flagTestV2Migration = "test-v2-migration"
flagSkipTrackerCheck = "skip-tracker-check"
flagSkipPrecompiles = "skip-precompiles"
flagUpgradeGateways = "upgrade-gateways"
flagUpgradeContracts = "upgrade-contracts"
)

var (
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
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 --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=$?
Expand Down
41 changes: 28 additions & 13 deletions e2e/runner/v2_setup_evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,42 +48,56 @@ 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,
initializerData,
)
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
Expand All @@ -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")

Expand Down
27 changes: 24 additions & 3 deletions e2e/runner/v2_gateway.go → e2e/runner/v2_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 2146e4f

Please sign in to comment.