Skip to content

Commit

Permalink
refactor(e2e): use private key rather than mnemonic in admin tests (#…
Browse files Browse the repository at this point in the history
…2350)

* refactor(e2e): use private key rather than pnemonic admin tests

* move TestERC20DepositAndCallRefund back to erc20 test routine
  • Loading branch information
gartnera authored Jun 19, 2024
1 parent 38e1753 commit 3c4ea97
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 86 deletions.
4 changes: 0 additions & 4 deletions cmd/zetae2e/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import (

"github.com/zeta-chain/zetacore/app"
zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config"
"github.com/zeta-chain/zetacore/cmd/zetae2e/local"
"github.com/zeta-chain/zetacore/e2e/config"
"github.com/zeta-chain/zetacore/e2e/runner"
"github.com/zeta-chain/zetacore/e2e/utils"
)

const flagSkipBTC = "skip-btc"
Expand Down Expand Up @@ -71,8 +69,6 @@ func runBalances(cmd *cobra.Command, args []string) error {
conf,
ethcommon.HexToAddress(evmAddr),
conf.Accounts.EVMPrivKey,
utils.FungibleAdminName, // placeholder value, not used
local.FungibleAdminMnemonic, // placeholder value, not used
logger,
)
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions cmd/zetae2e/bitcoin_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import (

"github.com/zeta-chain/zetacore/app"
zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config"
"github.com/zeta-chain/zetacore/cmd/zetae2e/local"
"github.com/zeta-chain/zetacore/e2e/config"
"github.com/zeta-chain/zetacore/e2e/runner"
"github.com/zeta-chain/zetacore/e2e/utils"
)

const flagPrivKey = "privkey"
Expand Down Expand Up @@ -71,8 +69,6 @@ func runBitcoinAddress(cmd *cobra.Command, args []string) error {
conf,
ethcommon.HexToAddress(evmAddr),
conf.Accounts.EVMPrivKey,
utils.FungibleAdminName, // placeholder value, not used
local.FungibleAdminMnemonic, // placeholder value, not used
logger,
)
if err != nil {
Expand Down
17 changes: 2 additions & 15 deletions cmd/zetae2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

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

// RunnerFromConfig create test runner from config
Expand All @@ -19,9 +18,8 @@ func RunnerFromConfig(
conf config.Config,
evmUserAddr ethcommon.Address,
evmUserPrivKey string,
zetaUserName string,
zetaUserMnemonic string,
logger *runner.Logger,
opts ...runner.E2ERunnerOption,
) (*runner.E2ERunner, error) {
// initialize clients
btcRPCClient,
Expand All @@ -39,16 +37,6 @@ func RunnerFromConfig(
if err != nil {
return nil, fmt.Errorf("failed to get clients from config: %w", err)
}
// initialize client to send messages to ZetaChain
zetaTxServer, err := txserver.NewZetaTxServer(
conf.RPCs.ZetaCoreRPC,
[]string{zetaUserName},
[]string{zetaUserMnemonic},
conf.ZetaChainID,
)
if err != nil {
return nil, fmt.Errorf("failed to initialize ZetaChain tx server: %w", err)
}

// initialize E2E test runner
newRunner := runner.NewE2ERunner(
Expand All @@ -57,11 +45,9 @@ func RunnerFromConfig(
ctxCancel,
evmUserAddr,
evmUserPrivKey,
zetaUserMnemonic,
evmClient,
zevmClient,
cctxClient,
zetaTxServer,
fungibleClient,
authClient,
bankClient,
Expand All @@ -71,6 +57,7 @@ func RunnerFromConfig(
zevmAuth,
btcRPCClient,
logger,
opts...,
)

// set contracts
Expand Down
4 changes: 3 additions & 1 deletion cmd/zetae2e/local/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ var (
UserAdminAddress = ethcommon.HexToAddress("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266")
UserAdminPrivateKey = "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" // #nosec G101 - used for testing

FungibleAdminMnemonic = "snow grace federal cupboard arrive fancy gym lady uniform rotate exercise either leave alien grass" // #nosec G101 - used for testing
// FungibleAdminAddress is the address of the account for testing the fungible admin functions
UserFungibleAdminAddress = ethcommon.HexToAddress("0x8305C114Ea73cAc4A88f39A173803F94741b9055")
UserFungibleAdminPrivateKey = "d88d09a7d6849c15a36eb6931f9dd616091a63e9849a2cc86f309ba11fb8fec5" // #nosec G101 - used for testing
)
1 change: 1 addition & 0 deletions cmd/zetae2e/local/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func adminTestRoutine(
UserAdminAddress,
UserAdminPrivateKey,
runner.NewLogger(verbose, color.FgHiGreen, "admin"),
runner.WithZetaTxServer(deployerRunner.ZetaTxServer),
)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions cmd/zetae2e/local/erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func erc20TestRoutine(
UserERC20Address,
UserERC20PrivateKey,
runner.NewLogger(verbose, color.FgGreen, "erc20"),
runner.WithZetaTxServer(deployerRunner.ZetaTxServer),
)
if err != nil {
return err
Expand Down
15 changes: 13 additions & 2 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package local

import (
"context"
"fmt"
"os"
"path/filepath"
"time"
Expand All @@ -14,6 +15,7 @@ import (
"github.com/zeta-chain/zetacore/e2e/config"
"github.com/zeta-chain/zetacore/e2e/e2etests"
"github.com/zeta-chain/zetacore/e2e/runner"
"github.com/zeta-chain/zetacore/e2e/txserver"
"github.com/zeta-chain/zetacore/e2e/utils"
"github.com/zeta-chain/zetacore/pkg/chains"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
Expand Down Expand Up @@ -166,6 +168,16 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
time.Sleep(70 * time.Second)
}

zetaTxServer, err := txserver.NewZetaTxServer(
conf.RPCs.ZetaCoreRPC,
[]string{utils.FungibleAdminName},
[]string{UserFungibleAdminPrivateKey},
conf.ZetaChainID,
)
if err != nil {
panic(fmt.Errorf("failed to initialize ZetaChain tx server: %w", err))
}

// initialize deployer runner with config
deployerRunner, err := zetae2econfig.RunnerFromConfig(
ctx,
Expand All @@ -174,9 +186,8 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
conf,
DeployerAddress,
DeployerPrivateKey,
utils.FungibleAdminName,
FungibleAdminMnemonic,
logger,
runner.WithZetaTxServer(zetaTxServer),
)
if err != nil {
panic(err)
Expand Down
5 changes: 2 additions & 3 deletions cmd/zetae2e/local/test_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config"
"github.com/zeta-chain/zetacore/e2e/config"
"github.com/zeta-chain/zetacore/e2e/runner"
"github.com/zeta-chain/zetacore/e2e/utils"
)

// initTestRunner initializes a runner form tests
Expand All @@ -18,6 +17,7 @@ func initTestRunner(
userAddress ethcommon.Address,
userPrivKey string,
logger *runner.Logger,
opts ...runner.E2ERunnerOption,
) (*runner.E2ERunner, error) {
// initialize runner for test
testRunner, err := zetae2econfig.RunnerFromConfig(
Expand All @@ -27,9 +27,8 @@ func initTestRunner(
conf,
userAddress,
userPrivKey,
utils.FungibleAdminName,
FungibleAdminMnemonic,
logger,
opts...,
)
if err != nil {
return nil, err
Expand Down
4 changes: 0 additions & 4 deletions cmd/zetae2e/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ import (

"github.com/zeta-chain/zetacore/app"
zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config"
"github.com/zeta-chain/zetacore/cmd/zetae2e/local"
"github.com/zeta-chain/zetacore/e2e/config"
"github.com/zeta-chain/zetacore/e2e/e2etests"
"github.com/zeta-chain/zetacore/e2e/runner"
"github.com/zeta-chain/zetacore/e2e/utils"
)

const flagVerbose = "verbose"
Expand Down Expand Up @@ -93,8 +91,6 @@ func runE2ETest(cmd *cobra.Command, args []string) error {
conf,
ethcommon.HexToAddress(evmAddr),
conf.Accounts.EVMPrivKey,
utils.FungibleAdminName, // placeholder value, not used
local.FungibleAdminMnemonic, // placeholder value, not used
logger,
)
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions cmd/zetae2e/setup_bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import (

"github.com/zeta-chain/zetacore/app"
zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config"
"github.com/zeta-chain/zetacore/cmd/zetae2e/local"
"github.com/zeta-chain/zetacore/e2e/config"
"github.com/zeta-chain/zetacore/e2e/runner"
"github.com/zeta-chain/zetacore/e2e/utils"
)

// NewSetupBitcoinCmd sets up bitcoin wallet for e2e tests
Expand Down Expand Up @@ -58,8 +56,6 @@ func runSetupBitcoin(_ *cobra.Command, args []string) error {
conf,
ethcommon.HexToAddress(evmAddr),
conf.Accounts.EVMPrivKey,
utils.FungibleAdminName, // placeholder value, not used
local.FungibleAdminMnemonic, // placeholder value, not used
logger,
)
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions cmd/zetae2e/show_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import (

"github.com/zeta-chain/zetacore/app"
zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config"
"github.com/zeta-chain/zetacore/cmd/zetae2e/local"
"github.com/zeta-chain/zetacore/e2e/config"
"github.com/zeta-chain/zetacore/e2e/runner"
"github.com/zeta-chain/zetacore/e2e/utils"
)

// NewShowTSSCmd returns the show TSS command
Expand Down Expand Up @@ -59,8 +57,6 @@ func runShowTSS(_ *cobra.Command, args []string) error {
conf,
ethcommon.HexToAddress(evmAddr),
conf.Accounts.EVMPrivKey,
utils.FungibleAdminName, // placeholder value, not used
local.FungibleAdminMnemonic, // placeholder value, not used
logger,
)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions cmd/zetae2e/stress.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ func StressTest(cmd *cobra.Command, _ []string) {
conf,
local.DeployerAddress,
local.DeployerPrivateKey,
utils.FungibleAdminName,
local.FungibleAdminMnemonic,
logger,
)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion contrib/localnet/docker-compose-admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ services:
context: ./anvil
container_name: eth2
hostname: eth2
platform: linux/amd64
ports:
- "8546:8545"
networks:
Expand All @@ -23,4 +24,4 @@ services:
entrypoint: [ "/root/start-zetaclientd.sh", "additional-evm" ]

zetaclient1:
entrypoint: [ "/root/start-zetaclientd.sh", "additional-evm" ]
entrypoint: [ "/root/start-zetaclientd.sh", "additional-evm" ]
8 changes: 4 additions & 4 deletions contrib/localnet/scripts/start-zetacored.sh
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ then
fi

# set admin account
zetacored add-genesis-account zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk 100000000000000000000000000azeta
zetacored add-genesis-account zeta1svzuz982w09vf2y08xsh8qplj36phyz466krj3 100000000000000000000000000azeta
zetacored add-genesis-account zeta1n0rn6sne54hv7w2uu93fl48ncyqz97d3kty6sh 100000000000000000000000000azeta # Funds the localnet_gov_admin account
cat $HOME/.zetacored/config/genesis.json | jq '.app_state["authority"]["policies"]["items"][0]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json
cat $HOME/.zetacored/config/genesis.json | jq '.app_state["authority"]["policies"]["items"][1]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json
cat $HOME/.zetacored/config/genesis.json | jq '.app_state["authority"]["policies"]["items"][2]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json
cat $HOME/.zetacored/config/genesis.json | jq '.app_state["authority"]["policies"]["items"][0]["address"]="zeta1svzuz982w09vf2y08xsh8qplj36phyz466krj3"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json
cat $HOME/.zetacored/config/genesis.json | jq '.app_state["authority"]["policies"]["items"][1]["address"]="zeta1svzuz982w09vf2y08xsh8qplj36phyz466krj3"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json
cat $HOME/.zetacored/config/genesis.json | jq '.app_state["authority"]["policies"]["items"][2]["address"]="zeta1svzuz982w09vf2y08xsh8qplj36phyz466krj3"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json

# give balance to runner accounts to deploy contracts directly on zEVM
# deployer
Expand Down
14 changes: 7 additions & 7 deletions e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ const (
TestERC20DepositName = "erc20_deposit"
TestMultipleERC20DepositName = "erc20_multiple_deposit"
TestMultipleERC20WithdrawsName = "erc20_multiple_withdraw"
TestERC20DepositAndCallRefundName = "erc20_deposit_and_call_refund"
TestERC20DepositRestrictedName = "erc20_deposit_restricted" // #nosec G101: Potential hardcoded credentials (gosec), not a credential
TestERC20DepositAndCallRefundName = "erc20_deposit_and_call_refund"

/*
Bitcoin tests
Expand Down Expand Up @@ -307,12 +307,6 @@ var AllE2ETests = []runner.E2ETest{
},
TestMultipleERC20Withdraws,
),
runner.NewE2ETest(
TestERC20DepositAndCallRefundName,
"deposit a non-gas ZRC20 into ZEVM and call a contract that reverts",
[]runner.ArgDefinition{},
TestERC20DepositAndCallRefund,
),
runner.NewE2ETest(
TestERC20DepositRestrictedName,
"deposit ERC20 into ZEVM restricted address",
Expand All @@ -321,6 +315,12 @@ var AllE2ETests = []runner.E2ETest{
},
TestERC20DepositRestricted,
),
runner.NewE2ETest(
TestERC20DepositAndCallRefundName,
"deposit a non-gas ZRC20 into ZEVM and call a contract that reverts",
[]runner.ArgDefinition{},
TestERC20DepositAndCallRefund,
),
/*
Bitcoin tests
*/
Expand Down
3 changes: 1 addition & 2 deletions e2e/e2etests/test_migrate_chain_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,9 @@ func configureEVM2(r *runner.E2ERunner) (*runner.E2ERunner, error) {
r.CtxCancel,
r.DeployerAddress,
r.DeployerPrivateKey,
r.FungibleAdminMnemonic,
r.EVMClient,
r.ZEVMClient,
r.CctxClient,
r.ZetaTxServer,
r.FungibleClient,
r.AuthClient,
r.BankClient,
Expand All @@ -252,6 +250,7 @@ func configureEVM2(r *runner.E2ERunner) (*runner.E2ERunner, error) {
r.ZEVMAuth,
r.BtcRPCClient,
runner.NewLogger(true, color.FgHiYellow, "admin-evm2"),
runner.WithZetaTxServer(r.ZetaTxServer),
)

// All existing fields of the runner are the same except for the RPC URL and client for EVM
Expand Down
Loading

0 comments on commit 3c4ea97

Please sign in to comment.