Skip to content

Commit

Permalink
refactor(e2e): move addresses and private keys to config
Browse files Browse the repository at this point in the history
  • Loading branch information
gartnera committed Jun 3, 2024
1 parent f4366ad commit d2cb7a3
Show file tree
Hide file tree
Showing 22 changed files with 161 additions and 186 deletions.
17 changes: 3 additions & 14 deletions cmd/zetae2e/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ package main

import (
"context"
"errors"

ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/fatih/color"
"github.com/spf13/cobra"

"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"
Expand Down Expand Up @@ -56,23 +53,15 @@ func runBalances(cmd *cobra.Command, args []string) error {
// initialize context
ctx, cancel := context.WithCancel(context.Background())

// get EVM address from config
evmAddr := conf.Accounts.EVMAddress
if !ethcommon.IsHexAddress(evmAddr) {
cancel()
return errors.New("invalid EVM address")
}

// initialize deployer runner with config
r, err := zetae2econfig.RunnerFromConfig(
ctx,
"e2e",
cancel,
conf,
ethcommon.HexToAddress(evmAddr),
conf.Accounts.EVMPrivKey,
utils.FungibleAdminName, // placeholder value, not used
local.FungibleAdminMnemonic, // placeholder value, not used
config.Deployer,
utils.FungibleAdminName, // placeholder value, not used
conf.FungibleAdminMnemonic, // placeholder value, not used
logger,
)
if err != nil {
Expand Down
17 changes: 3 additions & 14 deletions cmd/zetae2e/bitcoin_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ package main

import (
"context"
"errors"

ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/fatih/color"
"github.com/spf13/cobra"

"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"
Expand Down Expand Up @@ -56,23 +53,15 @@ func runBitcoinAddress(cmd *cobra.Command, args []string) error {
// initialize context
ctx, cancel := context.WithCancel(context.Background())

// get EVM address from config
evmAddr := conf.Accounts.EVMAddress
if !ethcommon.IsHexAddress(evmAddr) {
cancel()
return errors.New("invalid EVM address")
}

// initialize deployer runner with config
r, err := zetae2econfig.RunnerFromConfig(
ctx,
"e2e",
cancel,
conf,
ethcommon.HexToAddress(evmAddr),
conf.Accounts.EVMPrivKey,
utils.FungibleAdminName, // placeholder value, not used
local.FungibleAdminMnemonic, // placeholder value, not used
config.UserBitcoin,
utils.FungibleAdminName, // placeholder value, not used
conf.FungibleAdminMnemonic, // placeholder value, not used
logger,
)
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions cmd/zetae2e/config/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package config

import (
"context"
"crypto/ecdsa"
"fmt"

"github.com/btcsuite/btcd/rpcclient"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"google.golang.org/grpc"

Expand All @@ -20,7 +20,7 @@ import (
)

// getClientsFromConfig get clients from config
func getClientsFromConfig(ctx context.Context, conf config.Config, evmPrivKey string) (
func getClientsFromConfig(ctx context.Context, conf config.Config, accountName config.AccountName) (
*rpcclient.Client,
*ethclient.Client,
*bind.TransactOpts,
Expand All @@ -34,6 +34,10 @@ func getClientsFromConfig(ctx context.Context, conf config.Config, evmPrivKey st
*bind.TransactOpts,
error,
) {
evmPrivKey, err := conf.Accounts[accountName].PrivateKey()
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get evm private key for %s: %w", accountName, err)
}
btcRPCClient, err := getBtcClient(conf.RPCs.Bitcoin)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get btc client: %w", err)
Expand Down Expand Up @@ -91,7 +95,7 @@ func getBtcClient(rpcConf config.BitcoinRPC) (*rpcclient.Client, error) {
}

// getEVMClient get evm client
func getEVMClient(ctx context.Context, rpc, privKey string) (*ethclient.Client, *bind.TransactOpts, error) {
func getEVMClient(ctx context.Context, rpc string, privateKey *ecdsa.PrivateKey) (*ethclient.Client, *bind.TransactOpts, error) {
evmClient, err := ethclient.Dial(rpc)
if err != nil {
return nil, nil, fmt.Errorf("failed to dial evm client: %w", err)
Expand All @@ -101,11 +105,7 @@ func getEVMClient(ctx context.Context, rpc, privKey string) (*ethclient.Client,
if err != nil {
return nil, nil, fmt.Errorf("failed to get chain id: %w", err)
}
deployerPrivkey, err := crypto.HexToECDSA(privKey)
if err != nil {
return nil, nil, fmt.Errorf("failed to get deployer privkey: %w", err)
}
evmAuth, err := bind.NewKeyedTransactorWithChainID(deployerPrivkey, chainid)
evmAuth, err := bind.NewKeyedTransactorWithChainID(privateKey, chainid)
if err != nil {
return nil, nil, fmt.Errorf("failed to get keyed transactor: %w", err)
}
Expand Down
11 changes: 4 additions & 7 deletions cmd/zetae2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"context"
"fmt"

ethcommon "github.com/ethereum/go-ethereum/common"

"github.com/zeta-chain/zetacore/e2e/config"
"github.com/zeta-chain/zetacore/e2e/runner"
"github.com/zeta-chain/zetacore/e2e/txserver"
Expand All @@ -17,8 +15,7 @@ func RunnerFromConfig(
name string,
ctxCancel context.CancelFunc,
conf config.Config,
evmUserAddr ethcommon.Address,
evmUserPrivKey string,
account config.AccountName,
zetaUserName string,
zetaUserMnemonic string,
logger *runner.Logger,
Expand All @@ -35,7 +32,7 @@ func RunnerFromConfig(
lightClient,
zevmClient,
zevmAuth,
err := getClientsFromConfig(ctx, conf, evmUserPrivKey)
err := getClientsFromConfig(ctx, conf, account)
if err != nil {
return nil, fmt.Errorf("failed to get clients from config: %w", err)
}
Expand All @@ -55,8 +52,8 @@ func RunnerFromConfig(
ctx,
name,
ctxCancel,
evmUserAddr,
evmUserPrivKey,
conf.Accounts[account].Address(),
conf.Accounts[account].RawPrivateKey,
zetaUserMnemonic,
evmClient,
zevmClient,
Expand Down
15 changes: 15 additions & 0 deletions cmd/zetae2e/config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package config

import (
"testing"

"github.com/stretchr/testify/require"
"github.com/zeta-chain/zetacore/e2e/config"
)

// test that the local config can be read, parsed, and validated
func TestReadLocalConfig(t *testing.T) {
config, err := config.ReadConfig("local.yml")
require.NoError(t, err)
require.Greater(t, len(config.Accounts), 0)
}
29 changes: 26 additions & 3 deletions cmd/zetae2e/config/local.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
zeta_chain_id: "athens_7001-1"
accounts:
evm_address: "0xE5C5367B8224807Ac2207d350E60e1b6F27a7ecC"
evm_priv_key: "d87baf7bf6dc560a252596678c12e41f7d1682837f05b29d411bc3f78ae2c263"
deployer:
address: "0xE5C5367B8224807Ac2207d350E60e1b6F27a7ecC"
private_key: "d87baf7bf6dc560a252596678c12e41f7d1682837f05b29d411bc3f78ae2c263"
user_erc20:
address: "0x6F57D5E7c6DBb75e59F1524a3dE38Fc389ec5Fd6"
private_key: "fda3be1b1517bdf48615bdadacc1e6463d2865868dc8077d2cdcfa4709a16894"
user_zeta_test:
address: "0x5cC2fBb200A929B372e3016F1925DcF988E081fd"
private_key: "729a6cdc5c925242e7df92fdeeb94dadbf2d0b9950d4db8f034ab27a3b114ba7"
user_zevm_mp_test:
address: "0x8Ae229198eCE3c889C07DB648Ec7C30E6051592c"
private_key: "105460aebf71b10bfdb710ef5aa6d2932ee6ff6fc317ac9c24e0979903b10a5d"
user_bitcoin:
address: "0x283d810090EdF4043E75247eAeBcE848806237fD"
private_key: "7bb523963ee2c78570fb6113d886a4184d42565e8847f1cb639f5f5e2ef5b37a"
user_ether:
address: "0x8D47Db7390AC4D3D449Cc20D799ce4748F97619A"
private_key: "098e74a1c2261fa3c1b8cfca8ef2b4ff96c73ce36710d208d1f6535aef42545d"
user_misc:
address: "0x90126d02E41c9eB2a10cfc43aAb3BD3460523Cdf"
private_key: "853c0945b8035a501b1161df65a17a0a20fc848bda8975a8b4e9222cc6f84cd4"
user_admin:
address: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
private_key: "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
rpcs:
zevm: "http://0.0.0.0:9545"
evm: "http://0.0.0.0:8545"
Expand All @@ -28,4 +50,5 @@ contracts:
zeta_eth: "0x733aB8b06DDDEf27Eaa72294B0d7c9cEF7f12db9"
connector_eth: "0xD28D6A0b8189305551a0A8bd247a6ECa9CE781Ca"
custody: "0xff3135df4F2775f4091b81f4c7B6359CfA07862a"
erc20: "0xbD1e64A22B9F92D9Ce81aA9B4b0fFacd80215564"
erc20: "0xbD1e64A22B9F92D9Ce81aA9B4b0fFacd80215564"
fungible_admin_mnemonic: "snow grace federal cupboard arrive fancy gym lady uniform rotate exercise either leave alien grass"
42 changes: 0 additions & 42 deletions cmd/zetae2e/local/accounts.go

This file was deleted.

9 changes: 5 additions & 4 deletions cmd/zetae2e/local/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ func adminTestRoutine(
"admin",
conf,
deployerRunner,
UserAdminAddress,
UserAdminPrivateKey,
config.UserAdmin,
runner.NewLogger(verbose, color.FgHiGreen, "admin"),
)
if err != nil {
Expand All @@ -47,10 +46,12 @@ func adminTestRoutine(
adminRunner.Logger.Print("🏃 starting admin tests")
startTime := time.Now()

userAdminAddress := conf.Accounts[config.UserAdmin].Address()

// funding the account
// we transfer around the total supply of Zeta to the admin for the chain migration test
txZetaSend := deployerRunner.SendZetaOnEvm(UserAdminAddress, 20_500_000_000)
txERC20Send := deployerRunner.SendERC20OnEvm(UserAdminAddress, 1000)
txZetaSend := deployerRunner.SendZetaOnEvm(userAdminAddress, 20_500_000_000)
txERC20Send := deployerRunner.SendERC20OnEvm(userAdminAddress, 1000)
adminRunner.WaitForTxReceiptOnEvm(txZetaSend)
adminRunner.WaitForTxReceiptOnEvm(txERC20Send)

Expand Down
7 changes: 4 additions & 3 deletions cmd/zetae2e/local/bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ func bitcoinTestRoutine(
"bitcoin",
conf,
deployerRunner,
UserBitcoinAddress,
UserBitcoinPrivateKey,
config.UserBitcoin,
runner.NewLogger(verbose, color.FgYellow, "bitcoin"),
)
if err != nil {
Expand All @@ -50,8 +49,10 @@ func bitcoinTestRoutine(
bitcoinRunner.Logger.Print("🏃 starting Bitcoin tests")
startTime := time.Now()

userBitcoinAddress := conf.Accounts[config.UserBitcoin].Address()

// funding the account
txERC20Send := deployerRunner.SendERC20OnEvm(UserBitcoinAddress, 1000)
txERC20Send := deployerRunner.SendERC20OnEvm(userBitcoinAddress, 1000)
bitcoinRunner.WaitForTxReceiptOnEvm(txERC20Send)

// depositing the necessary tokens on ZetaChain
Expand Down
7 changes: 4 additions & 3 deletions cmd/zetae2e/local/erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ func erc20TestRoutine(
"erc20",
conf,
deployerRunner,
UserERC20Address,
UserERC20PrivateKey,
config.UserERC20,
runner.NewLogger(verbose, color.FgGreen, "erc20"),
)
if err != nil {
Expand All @@ -48,8 +47,10 @@ func erc20TestRoutine(
erc20Runner.Logger.Print("🏃 starting erc20 tests")
startTime := time.Now()

userERC20Address := conf.Accounts[config.UserERC20].Address()

// funding the account
txERC20Send := deployerRunner.SendERC20OnEvm(UserERC20Address, 10)
txERC20Send := deployerRunner.SendERC20OnEvm(userERC20Address, 10)
erc20Runner.WaitForTxReceiptOnEvm(txERC20Send)

// depositing the necessary tokens on ZetaChain
Expand Down
3 changes: 1 addition & 2 deletions cmd/zetae2e/local/ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ func ethereumTestRoutine(
"ether",
conf,
deployerRunner,
UserEtherAddress,
UserEtherPrivateKey,
config.UserEther,
runner.NewLogger(verbose, color.FgMagenta, "ether"),
)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,9 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
"deployer",
cancel,
conf,
DeployerAddress,
DeployerPrivateKey,
config.Deployer,
utils.FungibleAdminName,
FungibleAdminMnemonic,
conf.FungibleAdminMnemonic,
logger,
)
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions cmd/zetae2e/local/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ func miscTestRoutine(
"misc",
conf,
deployerRunner,
UserMiscAddress,
UserMiscPrivateKey,
config.UserMisc,
runner.NewLogger(verbose, color.FgCyan, "misc"),
)
if err != nil {
Expand All @@ -48,8 +47,10 @@ func miscTestRoutine(
miscRunner.Logger.Print("🏃 starting miscellaneous tests")
startTime := time.Now()

userMiscAddress := conf.Accounts[config.UserMisc].Address()

// funding the account
txZetaSend := deployerRunner.SendZetaOnEvm(UserMiscAddress, 1000)
txZetaSend := deployerRunner.SendZetaOnEvm(userMiscAddress, 1000)
miscRunner.WaitForTxReceiptOnEvm(txZetaSend)

// depositing the necessary tokens on ZetaChain
Expand Down
Loading

0 comments on commit d2cb7a3

Please sign in to comment.