From 4f0d18a18a03901ddf749fbf062d4b2468cad357 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Wed, 10 Jul 2024 12:10:38 -0400 Subject: [PATCH] seperate policy accounts for each policy type --- cmd/zetae2e/local/local.go | 4 ++-- e2e/e2etests/test_erc20_deposit_refund.go | 4 ++-- .../test_eth_deposit_liquidity_cap.go | 8 +++---- e2e/e2etests/test_migrate_chain_support.go | 22 +++++++++---------- e2e/e2etests/test_pause_zrc20.go | 8 +++---- e2e/e2etests/test_rate_limiter.go | 4 ++-- .../test_update_bytecode_connector.go | 4 ++-- e2e/e2etests/test_update_bytecode_zrc20.go | 4 ++-- e2e/runner/setup_zeta.go | 6 ++--- e2e/txserver/zeta_tx_server.go | 13 +++++++++++ e2e/utils/zetacore.go | 4 ++++ 11 files changed, 48 insertions(+), 33 deletions(-) diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index 7e00f9ba5b..62356162ce 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -126,8 +126,8 @@ func localE2ETest(cmd *cobra.Command, _ []string) { zetaTxServer, err := txserver.NewZetaTxServer( conf.RPCs.ZetaCoreRPC, - []string{utils.FungibleAdminName}, - []string{conf.AdditionalAccounts.UserFungibleAdmin.RawPrivateKey.String()}, + []string{utils.EmergencyPolicyName, utils.OperationalPolicyName, utils.AdminPolicyName}, + []string{conf.PolicyAccounts.EmergencyPolicyAccount.RawPrivateKey.String(), conf.PolicyAccounts.OperationalPolicyAccount.RawPrivateKey.String(), conf.PolicyAccounts.AdminPolicyAccount.RawPrivateKey.String()}, conf.ZetaChainID, ) noError(err) diff --git a/e2e/e2etests/test_erc20_deposit_refund.go b/e2e/e2etests/test_erc20_deposit_refund.go index 5e8d1173ef..949b16d989 100644 --- a/e2e/e2etests/test_erc20_deposit_refund.go +++ b/e2e/e2etests/test_erc20_deposit_refund.go @@ -36,9 +36,9 @@ func TestERC20DepositAndCallRefund(r *runner.E2ERunner, _ []string) { r.Logger.CCTX(*cctx, "deposit") r.Logger.Info("Refunding the cctx via admin") - msg := types.NewMsgRefundAbortedCCTX(r.ZetaTxServer.GetAccountAddress(0), cctx.Index, r.EVMAddress().String()) + msg := types.NewMsgRefundAbortedCCTX(r.ZetaTxServer.MustGetAccountAddressFromName(utils.OperationalPolicyName), cctx.Index, r.EVMAddress().String()) - _, err = r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msg) + _, err = r.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, msg) require.NoError(r, err) // Check that the erc20 in the aborted cctx was refunded on ZetaChain diff --git a/e2e/e2etests/test_eth_deposit_liquidity_cap.go b/e2e/e2etests/test_eth_deposit_liquidity_cap.go index 2f03c7a568..7e1ea55a70 100644 --- a/e2e/e2etests/test_eth_deposit_liquidity_cap.go +++ b/e2e/e2etests/test_eth_deposit_liquidity_cap.go @@ -25,11 +25,11 @@ func TestDepositEtherLiquidityCap(r *runner.E2ERunner, args []string) { amountLessThanCap := liquidityCapArg.BigInt().Div(liquidityCapArg.BigInt(), big.NewInt(10)) // 1/10 of the cap amountMoreThanCap := liquidityCapArg.BigInt().Mul(liquidityCapArg.BigInt(), big.NewInt(10)) // 10 times the cap msg := fungibletypes.NewMsgUpdateZRC20LiquidityCap( - r.ZetaTxServer.GetAccountAddress(0), + r.ZetaTxServer.MustGetAccountAddressFromName(utils.OperationalPolicyName), r.ETHZRC20Addr.Hex(), liquidityCap, ) - res, err := r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msg) + res, err := r.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, msg) require.NoError(r, err) r.Logger.Info("set liquidity cap tx hash: %s", res.TxHash) @@ -69,12 +69,12 @@ func TestDepositEtherLiquidityCap(r *runner.E2ERunner, args []string) { r.Logger.Info("Removing the liquidity cap") msg = fungibletypes.NewMsgUpdateZRC20LiquidityCap( - r.ZetaTxServer.GetAccountAddress(0), + r.ZetaTxServer.MustGetAccountAddressFromName(utils.OperationalPolicyName), r.ETHZRC20Addr.Hex(), math.ZeroUint(), ) - res, err = r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msg) + res, err = r.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, msg) require.NoError(r, err) r.Logger.Info("remove liquidity cap tx hash: %s", res.TxHash) diff --git a/e2e/e2etests/test_migrate_chain_support.go b/e2e/e2etests/test_migrate_chain_support.go index 07f49a5815..ba0b7f3b9b 100644 --- a/e2e/e2etests/test_migrate_chain_support.go +++ b/e2e/e2etests/test_migrate_chain_support.go @@ -58,19 +58,17 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) { // update the chain params to set up the chain chainParams := getNewEVMChainParams(newRunner) - adminAddr, err := newRunner.ZetaTxServer.GetAccountAddressFromName(utils.FungibleAdminName) - require.NoError(r, err) - _, err = newRunner.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, observertypes.NewMsgUpdateChainParams( - adminAddr, + _, err = newRunner.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, observertypes.NewMsgUpdateChainParams( + r.ZetaTxServer.MustGetAccountAddressFromName(utils.OperationalPolicyName), chainParams, )) require.NoError(r, err) // setup the gas token require.NoError(r, err) - _, err = newRunner.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, fungibletypes.NewMsgDeployFungibleCoinZRC20( - adminAddr, + _, err = newRunner.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, fungibletypes.NewMsgDeployFungibleCoinZRC20( + r.ZetaTxServer.MustGetAccountAddressFromName(utils.OperationalPolicyName), "", chainParams.ChainId, 18, @@ -95,8 +93,8 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) { newRunner.ETHZRC20 = ethZRC20 // set the chain nonces for the new chain - _, err = r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, observertypes.NewMsgResetChainNonces( - adminAddr, + _, err = r.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, observertypes.NewMsgResetChainNonces( + r.ZetaTxServer.MustGetAccountAddressFromName(utils.OperationalPolicyName), chainParams.ChainId, 0, 0, @@ -106,8 +104,8 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) { // deactivate the previous chain chainParams = observertypes.GetDefaultGoerliLocalnetChainParams() chainParams.IsSupported = false - _, err = newRunner.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, observertypes.NewMsgUpdateChainParams( - adminAddr, + _, err = newRunner.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, observertypes.NewMsgUpdateChainParams( + r.ZetaTxServer.MustGetAccountAddressFromName(utils.OperationalPolicyName), chainParams, )) require.NoError(r, err) @@ -155,8 +153,8 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) { // whitelist erc20 zrc20 newRunner.Logger.Info("whitelisting ERC20 on new network") - res, err := newRunner.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, crosschaintypes.NewMsgWhitelistERC20( - adminAddr, + res, err := newRunner.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, crosschaintypes.NewMsgWhitelistERC20( + r.ZetaTxServer.MustGetAccountAddressFromName(utils.OperationalPolicyName), newRunner.ERC20Addr.Hex(), chains.Sepolia.ChainId, "USDT", diff --git a/e2e/e2etests/test_pause_zrc20.go b/e2e/e2etests/test_pause_zrc20.go index 1495a7ac60..c1924d85cf 100644 --- a/e2e/e2etests/test_pause_zrc20.go +++ b/e2e/e2etests/test_pause_zrc20.go @@ -35,10 +35,10 @@ func TestPauseZRC20(r *runner.E2ERunner, _ []string) { // Pause ETH ZRC20 r.Logger.Info("Pausing ETH") msgPause := fungibletypes.NewMsgPauseZRC20( - r.ZetaTxServer.GetAccountAddress(0), + r.ZetaTxServer.MustGetAccountAddressFromName(utils.EmergencyPolicyName), []string{r.ETHZRC20Addr.Hex()}, ) - res, err := r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msgPause) + res, err := r.ZetaTxServer.BroadcastTx(utils.EmergencyPolicyName, msgPause) require.NoError(r, err) r.Logger.Info("pause zrc20 tx hash: %s", res.TxHash) @@ -106,10 +106,10 @@ func TestPauseZRC20(r *runner.E2ERunner, _ []string) { // Unpause ETH ZRC20 r.Logger.Info("Unpausing ETH") msgUnpause := fungibletypes.NewMsgUnpauseZRC20( - r.ZetaTxServer.GetAccountAddress(0), + r.ZetaTxServer.MustGetAccountAddressFromName(utils.OperationalPolicyName), []string{r.ETHZRC20Addr.Hex()}, ) - res, err = r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msgUnpause) + res, err = r.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, msgUnpause) require.NoError(r, err) r.Logger.Info("unpause zrc20 tx hash: %s", res.TxHash) diff --git a/e2e/e2etests/test_rate_limiter.go b/e2e/e2etests/test_rate_limiter.go index 739d7821dc..af8221f23f 100644 --- a/e2e/e2etests/test_rate_limiter.go +++ b/e2e/e2etests/test_rate_limiter.go @@ -167,11 +167,11 @@ func waitForWithdrawMined( // setupRateLimiterFlags sets up the rate limiter flags with flags defined in the test func setupRateLimiterFlags(r *runner.E2ERunner, flags crosschaintypes.RateLimiterFlags) error { - adminAddr, err := r.ZetaTxServer.GetAccountAddressFromName(utils.FungibleAdminName) + adminAddr, err := r.ZetaTxServer.GetAccountAddressFromName(utils.OperationalPolicyName) if err != nil { return err } - _, err = r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, crosschaintypes.NewMsgUpdateRateLimiterFlags( + _, err = r.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, crosschaintypes.NewMsgUpdateRateLimiterFlags( adminAddr, flags, )) diff --git a/e2e/e2etests/test_update_bytecode_connector.go b/e2e/e2etests/test_update_bytecode_connector.go index 73786f2971..c370cf6a33 100644 --- a/e2e/e2etests/test_update_bytecode_connector.go +++ b/e2e/e2etests/test_update_bytecode_connector.go @@ -46,11 +46,11 @@ func TestUpdateBytecodeConnector(r *runner.E2ERunner, _ []string) { r.Logger.Info("Updating the bytecode of the Connector") msg := fungibletypes.NewMsgUpdateContractBytecode( - r.ZetaTxServer.GetAccountAddress(0), + r.ZetaTxServer.MustGetAccountAddressFromName(utils.AdminPolicyName), r.ConnectorZEVMAddr.Hex(), codeHashRes.CodeHash, ) - res, err := r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msg) + res, err := r.ZetaTxServer.BroadcastTx(utils.AdminPolicyName, msg) require.NoError(r, err) r.Logger.Info("Update connector bytecode tx hash: %s", res.TxHash) diff --git a/e2e/e2etests/test_update_bytecode_zrc20.go b/e2e/e2etests/test_update_bytecode_zrc20.go index 8205b88d9c..04e234b6ae 100644 --- a/e2e/e2etests/test_update_bytecode_zrc20.go +++ b/e2e/e2etests/test_update_bytecode_zrc20.go @@ -68,11 +68,11 @@ func TestUpdateBytecodeZRC20(r *runner.E2ERunner, _ []string) { r.Logger.Info("Updating the bytecode of the ZRC20") msg := fungibletypes.NewMsgUpdateContractBytecode( - r.ZetaTxServer.GetAccountAddress(0), + r.ZetaTxServer.MustGetAccountAddressFromName(utils.AdminPolicyName), r.ETHZRC20Addr.Hex(), codeHashRes.CodeHash, ) - res, err := r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msg) + res, err := r.ZetaTxServer.BroadcastTx(utils.AdminPolicyName, msg) require.NoError(r, err) r.Logger.Info("Update zrc20 bytecode tx hash: %s", res.TxHash) diff --git a/e2e/runner/setup_zeta.go b/e2e/runner/setup_zeta.go index ef3acbd64b..859f83d3e4 100644 --- a/e2e/runner/setup_zeta.go +++ b/e2e/runner/setup_zeta.go @@ -75,7 +75,7 @@ func (r *E2ERunner) SetZEVMContracts() { // deploy system contracts and ZRC20 contracts on ZetaChain uniswapV2FactoryAddr, uniswapV2RouterAddr, zevmConnectorAddr, wzetaAddr, erc20zrc20Addr, err := r.ZetaTxServer.DeploySystemContractsAndZRC20( - e2eutils.FungibleAdminName, + e2eutils.OperationalPolicyName, r.ERC20Addr.Hex(), ) require.NoError(r, err) @@ -209,12 +209,12 @@ func (r *E2ERunner) SetupBTCZRC20() { func (r *E2ERunner) EnableHeaderVerification(chainIDList []int64) error { r.Logger.Print("⚙️ enabling verification flags for block headers") - return r.ZetaTxServer.EnableHeaderVerification(e2eutils.FungibleAdminName, chainIDList) + return r.ZetaTxServer.EnableHeaderVerification(e2eutils.OperationalPolicyName, chainIDList) } // FundEmissionsPool funds the emissions pool on ZetaChain with the same value as used originally on mainnet (20M ZETA) func (r *E2ERunner) FundEmissionsPool() error { r.Logger.Print("⚙️ funding the emissions pool on ZetaChain with 20M ZETA (%s)", txserver.EmissionsPoolAddress) - return r.ZetaTxServer.FundEmissionsPool(e2eutils.FungibleAdminName, EmissionsPoolFunding) + return r.ZetaTxServer.FundEmissionsPool(e2eutils.OperationalPolicyName, EmissionsPoolFunding) } diff --git a/e2e/txserver/zeta_tx_server.go b/e2e/txserver/zeta_tx_server.go index 5c4c5e80af..c0119eadec 100644 --- a/e2e/txserver/zeta_tx_server.go +++ b/e2e/txserver/zeta_tx_server.go @@ -153,6 +153,19 @@ func (zts ZetaTxServer) GetAccountAddressFromName(name string) (string, error) { return addr.String(), nil } +// GetAccountAddressFromName returns the account address from the given name +func (zts ZetaTxServer) MustGetAccountAddressFromName(name string) string { + acc, err := zts.clientCtx.Keyring.Key(name) + if err != nil { + panic(err) + } + addr, err := acc.GetAddress() + if err != nil { + panic(err) + } + return addr.String() +} + // GetAllAccountAddress returns all account addresses func (zts ZetaTxServer) GetAllAccountAddress() []string { return zts.address diff --git a/e2e/utils/zetacore.go b/e2e/utils/zetacore.go index cbba05de75..89f5c81042 100644 --- a/e2e/utils/zetacore.go +++ b/e2e/utils/zetacore.go @@ -18,6 +18,10 @@ type CCTXClient = crosschaintypes.QueryClient const ( FungibleAdminName = "fungibleadmin" + EmergencyPolicyName = "emergency" + AdminPolicyName = "admin" + OperationalPolicyName = "operational" + DefaultCctxTimeout = 4 * time.Minute )