diff --git a/cmd/zetae2e/README.md b/cmd/zetae2e/README.md index c57863e7cf..8fe737d3e8 100644 --- a/cmd/zetae2e/README.md +++ b/cmd/zetae2e/README.md @@ -25,8 +25,9 @@ This is an example of config for interaction with Athens3: ```go zeta_chain_id: "athens_7001-1" accounts: - evm_address: "" - evm_priv_key: "" + deployer: + address: "" + private_key: "" rpcs: zevm: ", generally using port 8545" evm: ", generally using port 8545" @@ -102,8 +103,9 @@ Testing a gas token requires the following values to be defined in the config: ```go zeta_chain_id accounts: - evm_address - evm_priv_key + deployer: + address + private_key rpcs: zevm evm @@ -129,8 +131,9 @@ Testing ZRC20 requires the same config as for the gas tokens, but must include t ```go zeta_chain_id accounts: - evm_address - evm_priv_key + deployer: + address + private_key rpcs: zevm evm @@ -150,8 +153,9 @@ The following values must be set in the config in order to test Bitcoin function ```go zeta_chain_id accounts: - evm_address - evm_priv_key + deployer: + address + private_key rpcs: zevm bitcoin: diff --git a/cmd/zetae2e/balances.go b/cmd/zetae2e/balances.go index 18c40190e1..cf52b65f40 100644 --- a/cmd/zetae2e/balances.go +++ b/cmd/zetae2e/balances.go @@ -59,7 +59,7 @@ func runBalances(cmd *cobra.Command, args []string) error { "e2e", cancel, conf, - config.Deployer, + conf.Accounts.Deployer, utils.FungibleAdminName, // placeholder value, not used conf.FungibleAdminMnemonic, // placeholder value, not used logger, diff --git a/cmd/zetae2e/bitcoin_address.go b/cmd/zetae2e/bitcoin_address.go index 332bd67422..ced469dda0 100644 --- a/cmd/zetae2e/bitcoin_address.go +++ b/cmd/zetae2e/bitcoin_address.go @@ -59,7 +59,7 @@ func runBitcoinAddress(cmd *cobra.Command, args []string) error { "e2e", cancel, conf, - config.UserBitcoin, + conf.Accounts.UserBitcoin, utils.FungibleAdminName, // placeholder value, not used conf.FungibleAdminMnemonic, // placeholder value, not used logger, diff --git a/cmd/zetae2e/config/clients.go b/cmd/zetae2e/config/clients.go index 7c5dc47723..f0856748e1 100644 --- a/cmd/zetae2e/config/clients.go +++ b/cmd/zetae2e/config/clients.go @@ -20,7 +20,7 @@ import ( ) // getClientsFromConfig get clients from config -func getClientsFromConfig(ctx context.Context, conf config.Config, accountName config.AccountName) ( +func getClientsFromConfig(ctx context.Context, conf config.Config, account config.Account) ( *rpcclient.Client, *ethclient.Client, *bind.TransactOpts, @@ -34,11 +34,10 @@ func getClientsFromConfig(ctx context.Context, conf config.Config, accountName c *bind.TransactOpts, error, ) { - evmPrivKey, err := conf.Accounts[accountName].PrivateKey() + evmPrivKey, err := account.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, + "failed to get evm private key: %w", err, ) } diff --git a/cmd/zetae2e/config/config.go b/cmd/zetae2e/config/config.go index 579e40eea9..57c72f095f 100644 --- a/cmd/zetae2e/config/config.go +++ b/cmd/zetae2e/config/config.go @@ -15,7 +15,7 @@ func RunnerFromConfig( name string, ctxCancel context.CancelFunc, conf config.Config, - account config.AccountName, + account config.Account, zetaUserName string, zetaUserMnemonic string, logger *runner.Logger, @@ -52,8 +52,7 @@ func RunnerFromConfig( ctx, name, ctxCancel, - conf.Accounts[account].Address(), - conf.Accounts[account].RawPrivateKey, + account, zetaUserMnemonic, evmClient, zevmClient, diff --git a/cmd/zetae2e/config/config_test.go b/cmd/zetae2e/config/config_test.go index 2986d86fbb..fbbfb80ce6 100644 --- a/cmd/zetae2e/config/config_test.go +++ b/cmd/zetae2e/config/config_test.go @@ -8,9 +8,33 @@ import ( "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) +func TestReadConfig(t *testing.T) { + tests := []struct { + name string + filePath string + expectNoError bool + expectNotEmpty bool + }{ + { + name: "ReadLocalnetConfig", + filePath: "localnet.yml", + expectNoError: true, + expectNotEmpty: true, + }, + { + name: "ReadLocalConfig", + filePath: "local.yml", + expectNoError: true, + expectNotEmpty: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + conf, err := config.ReadConfig(tt.filePath) + require.NoError(t, err) + require.NotEmpty(t, conf.Accounts.Deployer.RawAddress) + require.NotEmpty(t, conf.Accounts.Deployer.RawPrivateKey) + }) + } } diff --git a/cmd/zetae2e/config/local.yml b/cmd/zetae2e/config/local.yml index de78236646..73dd2d6c3c 100644 --- a/cmd/zetae2e/config/local.yml +++ b/cmd/zetae2e/config/local.yml @@ -3,27 +3,6 @@ accounts: 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" @@ -50,5 +29,4 @@ contracts: zeta_eth: "0x733aB8b06DDDEf27Eaa72294B0d7c9cEF7f12db9" connector_eth: "0xD28D6A0b8189305551a0A8bd247a6ECa9CE781Ca" custody: "0xff3135df4F2775f4091b81f4c7B6359CfA07862a" - erc20: "0xbD1e64A22B9F92D9Ce81aA9B4b0fFacd80215564" -fungible_admin_mnemonic: "snow grace federal cupboard arrive fancy gym lady uniform rotate exercise either leave alien grass" \ No newline at end of file + erc20: "0xbD1e64A22B9F92D9Ce81aA9B4b0fFacd80215564" \ No newline at end of file diff --git a/cmd/zetae2e/config/localnet.yml b/cmd/zetae2e/config/localnet.yml new file mode 100644 index 0000000000..3560d9b0ba --- /dev/null +++ b/cmd/zetae2e/config/localnet.yml @@ -0,0 +1,55 @@ +zeta_chain_id: "athens_101-1" +accounts: + 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://zetacore0:8545" + evm: "http://eth:8545" + bitcoin: + host: "bitcoin:18443" + user: "smoketest" + pass: "123" + http_post_mode: true + disable_tls: true + params: regnet + zetacore_grpc: "zetacore0:9090" + zetacore_rpc: "http://zetacore0:26657" +# these values will all be replaced when running the e2e tests without --skip-setup +contracts: + zevm: + system_contract: "0x91d18e54DAf4F677cB28167158d6dd21F6aB3921" + eth_zrc20: "0x13A0c5930C028511Dc02665E7285134B6d11A5f4" + erc20_zrc20: "0x48f80608B672DC30DC7e3dbBd0343c5F02C738Eb" + btc_zrc20: "0xd97B1de3619ed2c6BEb3860147E30cA8A7dC9891" + uniswap_factory: "0x9fd96203f7b22bCF72d9DCb40ff98302376cE09c" + uniswap_router: "0x2ca7d64A7EFE2D62A725E2B35Cf7230D6677FfEe" + connector_zevm: "0x239e96c8f17C85c30100AC26F635Ea15f23E9c67" + wzeta: "0x5F0b1a82749cb4E2278EC87F8BF6B618dC71a8bf" + evm: + zeta_eth: "0x733aB8b06DDDEf27Eaa72294B0d7c9cEF7f12db9" + connector_eth: "0xD28D6A0b8189305551a0A8bd247a6ECa9CE781Ca" + custody: "0xff3135df4F2775f4091b81f4c7B6359CfA07862a" + erc20: "0xbD1e64A22B9F92D9Ce81aA9B4b0fFacd80215564" +fungible_admin_mnemonic: "snow grace federal cupboard arrive fancy gym lady uniform rotate exercise either leave alien grass" \ No newline at end of file diff --git a/cmd/zetae2e/local/admin.go b/cmd/zetae2e/local/admin.go index a244f5b2e2..2fbbffbe56 100644 --- a/cmd/zetae2e/local/admin.go +++ b/cmd/zetae2e/local/admin.go @@ -36,7 +36,7 @@ func adminTestRoutine( "admin", conf, deployerRunner, - config.UserAdmin, + conf.Accounts.UserAdmin, runner.NewLogger(verbose, color.FgHiGreen, "admin"), ) if err != nil { @@ -46,10 +46,9 @@ 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 + userAdminAddress := conf.Accounts.UserAdmin.Address() txZetaSend := deployerRunner.SendZetaOnEvm(userAdminAddress, 20_500_000_000) txERC20Send := deployerRunner.SendERC20OnEvm(userAdminAddress, 1000) adminRunner.WaitForTxReceiptOnEvm(txZetaSend) diff --git a/cmd/zetae2e/local/bitcoin.go b/cmd/zetae2e/local/bitcoin.go index 2fd430b327..487661b625 100644 --- a/cmd/zetae2e/local/bitcoin.go +++ b/cmd/zetae2e/local/bitcoin.go @@ -39,7 +39,7 @@ func bitcoinTestRoutine( "bitcoin", conf, deployerRunner, - config.UserBitcoin, + conf.Accounts.UserBitcoin, runner.NewLogger(verbose, color.FgYellow, "bitcoin"), ) if err != nil { @@ -49,9 +49,8 @@ func bitcoinTestRoutine( bitcoinRunner.Logger.Print("🏃 starting Bitcoin tests") startTime := time.Now() - userBitcoinAddress := conf.Accounts[config.UserBitcoin].Address() - // funding the account + userBitcoinAddress := conf.Accounts.UserBitcoin.Address() txERC20Send := deployerRunner.SendERC20OnEvm(userBitcoinAddress, 1000) bitcoinRunner.WaitForTxReceiptOnEvm(txERC20Send) diff --git a/cmd/zetae2e/local/config.go b/cmd/zetae2e/local/config.go index 98ece83ac0..f8683f7278 100644 --- a/cmd/zetae2e/local/config.go +++ b/cmd/zetae2e/local/config.go @@ -1,6 +1,7 @@ package local import ( + "fmt" "path/filepath" sdk "github.com/cosmos/cosmos-sdk/types" @@ -19,7 +20,7 @@ func GetConfig(cmd *cobra.Command) (config.Config, error) { // use default config if no config file is specified if configFile == "" { - return config.DefaultConfig(), nil + return config.Config{}, fmt.Errorf("--%s is a required parameter", FlagConfigFile) } configFile, err = filepath.Abs(configFile) diff --git a/cmd/zetae2e/local/erc20.go b/cmd/zetae2e/local/erc20.go index fe6b058f65..618682ef84 100644 --- a/cmd/zetae2e/local/erc20.go +++ b/cmd/zetae2e/local/erc20.go @@ -37,7 +37,7 @@ func erc20TestRoutine( "erc20", conf, deployerRunner, - config.UserERC20, + conf.Accounts.UserERC20, runner.NewLogger(verbose, color.FgGreen, "erc20"), ) if err != nil { @@ -47,9 +47,8 @@ func erc20TestRoutine( erc20Runner.Logger.Print("🏃 starting erc20 tests") startTime := time.Now() - userERC20Address := conf.Accounts[config.UserERC20].Address() - // funding the account + userERC20Address := conf.Accounts.UserERC20.Address() txERC20Send := deployerRunner.SendERC20OnEvm(userERC20Address, 10) erc20Runner.WaitForTxReceiptOnEvm(txERC20Send) diff --git a/cmd/zetae2e/local/ethereum.go b/cmd/zetae2e/local/ethereum.go index ecee9e903b..88fc81b7af 100644 --- a/cmd/zetae2e/local/ethereum.go +++ b/cmd/zetae2e/local/ethereum.go @@ -38,7 +38,7 @@ func ethereumTestRoutine( "ether", conf, deployerRunner, - config.UserEther, + conf.Accounts.UserEther, runner.NewLogger(verbose, color.FgMagenta, "ether"), ) if err != nil { diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index 15489bef3b..dbdb8ac062 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -172,7 +172,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) { "deployer", cancel, conf, - config.Deployer, + conf.Accounts.Deployer, utils.FungibleAdminName, conf.FungibleAdminMnemonic, logger, diff --git a/cmd/zetae2e/local/misc.go b/cmd/zetae2e/local/misc.go index 2cf0939681..e51df2065b 100644 --- a/cmd/zetae2e/local/misc.go +++ b/cmd/zetae2e/local/misc.go @@ -37,7 +37,7 @@ func miscTestRoutine( "misc", conf, deployerRunner, - config.UserMisc, + conf.Accounts.UserMisc, runner.NewLogger(verbose, color.FgCyan, "misc"), ) if err != nil { @@ -47,9 +47,8 @@ func miscTestRoutine( miscRunner.Logger.Print("🏃 starting miscellaneous tests") startTime := time.Now() - userMiscAddress := conf.Accounts[config.UserMisc].Address() - // funding the account + userMiscAddress := conf.Accounts.UserMisc.Address() txZetaSend := deployerRunner.SendZetaOnEvm(userMiscAddress, 1000) miscRunner.WaitForTxReceiptOnEvm(txZetaSend) diff --git a/cmd/zetae2e/local/performance.go b/cmd/zetae2e/local/performance.go index cafde8164a..3a7c0ab5a5 100644 --- a/cmd/zetae2e/local/performance.go +++ b/cmd/zetae2e/local/performance.go @@ -40,7 +40,7 @@ func ethereumDepositPerformanceRoutine( "ether", conf, deployerRunner, - config.UserERC20, + conf.Accounts.UserERC20, runner.NewLogger(verbose, color.FgHiMagenta, "perf_eth_deposit"), ) if err != nil { @@ -93,7 +93,7 @@ func ethereumWithdrawPerformanceRoutine( "ether", conf, deployerRunner, - config.UserEther, + conf.Accounts.UserEther, runner.NewLogger(verbose, color.FgHiBlue, "perf_eth_withdraw"), ) if err != nil { diff --git a/cmd/zetae2e/local/test_runner.go b/cmd/zetae2e/local/test_runner.go index 021cd1279f..eaf30e6416 100644 --- a/cmd/zetae2e/local/test_runner.go +++ b/cmd/zetae2e/local/test_runner.go @@ -13,7 +13,7 @@ func initTestRunner( name string, conf config.Config, deployerRunner *runner.E2ERunner, - accountName config.AccountName, + account config.Account, logger *runner.Logger, ) (*runner.E2ERunner, error) { // initialize runner for test @@ -22,7 +22,7 @@ func initTestRunner( name, deployerRunner.CtxCancel, conf, - accountName, + account, utils.FungibleAdminName, conf.FungibleAdminMnemonic, logger, diff --git a/cmd/zetae2e/local/zeta.go b/cmd/zetae2e/local/zeta.go index 054903ada6..a26ee78e92 100644 --- a/cmd/zetae2e/local/zeta.go +++ b/cmd/zetae2e/local/zeta.go @@ -37,7 +37,7 @@ func zetaTestRoutine( "zeta", conf, deployerRunner, - config.UserZetaTest, + conf.Accounts.UserZetaTest, runner.NewLogger(verbose, color.FgBlue, "zeta"), ) if err != nil { @@ -47,9 +47,8 @@ func zetaTestRoutine( zetaRunner.Logger.Print("🏃 starting Zeta tests") startTime := time.Now() - userZetaTestAddress := conf.Accounts[config.UserZetaTest].Address() - // funding the account + userZetaTestAddress := conf.Accounts.UserZetaTest.Address() txZetaSend := deployerRunner.SendZetaOnEvm(userZetaTestAddress, 1000) zetaRunner.WaitForTxReceiptOnEvm(txZetaSend) diff --git a/cmd/zetae2e/local/zevm_mp.go b/cmd/zetae2e/local/zevm_mp.go index 0a6c3ed565..bae918a717 100644 --- a/cmd/zetae2e/local/zevm_mp.go +++ b/cmd/zetae2e/local/zevm_mp.go @@ -37,7 +37,7 @@ func zevmMPTestRoutine( "zevm_mp", conf, deployerRunner, - config.UserZEVMMPTest, + conf.Accounts.UserZEVMMPTest, runner.NewLogger(verbose, color.FgHiRed, "zevm_mp"), ) if err != nil { @@ -47,9 +47,8 @@ func zevmMPTestRoutine( zevmMPRunner.Logger.Print("🏃 starting ZEVM Message Passing tests") startTime := time.Now() - userZEVMMPTestAddress := conf.Accounts[config.UserZEVMMPTest].Address() - // funding the account + userZEVMMPTestAddress := conf.Accounts.UserZEVMMPTest.Address() txZetaSend := deployerRunner.SendZetaOnEvm(userZEVMMPTestAddress, 1000) zevmMPRunner.WaitForTxReceiptOnEvm(txZetaSend) diff --git a/cmd/zetae2e/run.go b/cmd/zetae2e/run.go index f92a95cbf9..566488853b 100644 --- a/cmd/zetae2e/run.go +++ b/cmd/zetae2e/run.go @@ -82,7 +82,7 @@ func runE2ETest(cmd *cobra.Command, args []string) error { "e2e", cancel, conf, - config.Deployer, + conf.Accounts.Deployer, utils.FungibleAdminName, // placeholder value, not used conf.FungibleAdminMnemonic, // placeholder value, not used logger, diff --git a/cmd/zetae2e/setup_bitcoin.go b/cmd/zetae2e/setup_bitcoin.go index 688cc864e7..f4c470309a 100644 --- a/cmd/zetae2e/setup_bitcoin.go +++ b/cmd/zetae2e/setup_bitcoin.go @@ -47,7 +47,7 @@ func runSetupBitcoin(_ *cobra.Command, args []string) error { "e2e", cancel, conf, - config.Deployer, + conf.Accounts.Deployer, utils.FungibleAdminName, // placeholder value, not used conf.FungibleAdminMnemonic, // placeholder value, not used logger, diff --git a/cmd/zetae2e/show_tss.go b/cmd/zetae2e/show_tss.go index 1412960a12..e52454141b 100644 --- a/cmd/zetae2e/show_tss.go +++ b/cmd/zetae2e/show_tss.go @@ -47,7 +47,7 @@ func runShowTSS(_ *cobra.Command, args []string) error { "tss", cancel, conf, - config.Deployer, + conf.Accounts.Deployer, utils.FungibleAdminName, // placeholder value, not used conf.FungibleAdminMnemonic, // placeholder value, not used logger, diff --git a/cmd/zetae2e/stress.go b/cmd/zetae2e/stress.go index edc09e560c..262c9e4fa8 100644 --- a/cmd/zetae2e/stress.go +++ b/cmd/zetae2e/stress.go @@ -20,7 +20,6 @@ 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" crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" @@ -92,8 +91,7 @@ func StressTest(cmd *cobra.Command, _ []string) { panic(err) } - deployerAddress := conf.Accounts[config.Deployer].Address() - + deployerAddress := conf.Accounts.Deployer.Address() bal, err := evmClient.BalanceAt(context.TODO(), deployerAddress, nil) if err != nil { panic(err) @@ -143,7 +141,7 @@ func StressTest(cmd *cobra.Command, _ []string) { "deployer", cancel, conf, - config.Deployer, + conf.Accounts.Deployer, utils.FungibleAdminName, conf.FungibleAdminMnemonic, logger, diff --git a/contrib/localnet/orchestrator/Dockerfile.fastbuild b/contrib/localnet/orchestrator/Dockerfile.fastbuild index 2ef5520c64..8b31f801fd 100644 --- a/contrib/localnet/orchestrator/Dockerfile.fastbuild +++ b/contrib/localnet/orchestrator/Dockerfile.fastbuild @@ -10,6 +10,7 @@ COPY --from=geth /usr/local/bin/geth /usr/local/bin/ COPY --from=zeta /usr/local/bin/zetacored /usr/local/bin/zetaclientd /usr/local/bin/zetae2e /usr/local/bin/ COPY contrib/localnet/orchestrator/start-zetae2e.sh /work/ +COPY cmd/zetae2e/config/localnet.yml /work/config.yml RUN chmod +x /work/*.sh WORKDIR /work diff --git a/contrib/localnet/orchestrator/start-zetae2e.sh b/contrib/localnet/orchestrator/start-zetae2e.sh index a297be595b..7adf124a4e 100644 --- a/contrib/localnet/orchestrator/start-zetae2e.sh +++ b/contrib/localnet/orchestrator/start-zetae2e.sh @@ -80,7 +80,7 @@ if [ "$OPTION" == "upgrade" ]; then UPGRADE_HEIGHT=${3:-225} if [[ ! -f deployed.yml ]]; then - zetae2e "$ZETAE2E_CMD" --setup-only --config-out deployed.yml --skip-header-proof + zetae2e "$ZETAE2E_CMD" --setup-only --config config.yml --config-out deployed.yml --skip-header-proof if [ $? -ne 0 ]; then echo "e2e setup failed" exit 1 @@ -156,7 +156,7 @@ else echo "running e2e setup..." if [[ ! -f deployed.yml ]]; then - zetae2e $ZETAE2E_CMD --setup-only --config-out deployed.yml + zetae2e $ZETAE2E_CMD --setup-only --config config.yml --config-out deployed.yml if [ $? -ne 0 ]; then echo "e2e setup failed" exit 1 diff --git a/e2e/config/config.go b/e2e/config/config.go index 13d7088b9b..e702eb56e8 100644 --- a/e2e/config/config.go +++ b/e2e/config/config.go @@ -14,11 +14,11 @@ import ( // Config contains the configuration for the e2e test type Config struct { - Accounts map[AccountName]Account `yaml:"accounts"` - RPCs RPCs `yaml:"rpcs"` - Contracts Contracts `yaml:"contracts"` - ZetaChainID string `yaml:"zeta_chain_id"` - FungibleAdminMnemonic string `yaml:"fungible_admin_mnemonic"` + Accounts Accounts `yaml:"accounts"` + RPCs RPCs `yaml:"rpcs"` + Contracts Contracts `yaml:"contracts"` + ZetaChainID string `yaml:"zeta_chain_id"` + FungibleAdminMnemonic string `yaml:"fungible_admin_mnemonic"` } // Account contains configuration for an account @@ -27,6 +27,17 @@ type Account struct { RawPrivateKey string `yaml:"private_key"` } +type Accounts struct { + Deployer Account `yaml:"deployer"` + UserERC20 Account `yaml:"user_erc20"` + UserZetaTest Account `yaml:"user_zeta_test"` + UserZEVMMPTest Account `yaml:"user_zevm_mp_test"` + UserBitcoin Account `yaml:"user_bitcoin"` + UserEther Account `yaml:"user_ether"` + UserMisc Account `yaml:"user_misc"` + UserAdmin Account `yaml:"user_admin"` +} + // RPCs contains the configuration for the RPC endpoints type RPCs struct { Zevm string `yaml:"zevm"` @@ -141,6 +152,21 @@ func WriteConfig(file string, config Config) error { return nil } +// AsSlice gets all accounts as a slice rather than a +// struct +func (a Accounts) AsSlice() []Account { + return []Account{ + a.Deployer, + a.UserERC20, + a.UserZetaTest, + a.UserZEVMMPTest, + a.UserBitcoin, + a.UserEther, + a.UserMisc, + a.UserAdmin, + } +} + // Validate validates the config func (c Config) Validate() error { if c.RPCs.Bitcoin.Params != Mainnet && @@ -148,21 +174,15 @@ func (c Config) Validate() error { c.RPCs.Bitcoin.Params != Regnet { return errors.New("invalid bitcoin params") } - // validate that the address and the private key specified in the - // config actually match - for accountType, account := range c.Accounts { - privateKey, err := account.PrivateKey() - if err != nil { - return fmt.Errorf("invalid private key for %s: %w", accountType, err) + + accounts := c.Accounts.AsSlice() + for i, account := range accounts { + if account.RawAddress == "" { + continue } - privateKeyAddress := crypto.PubkeyToAddress(privateKey.PublicKey).Hex() - if account.RawAddress != privateKeyAddress { - return fmt.Errorf( - "%s: address derived from private key (%s) does not match configured address (%s)", - accountType, - privateKeyAddress, - account.RawAddress, - ) + err := account.Validate() + if err != nil { + return fmt.Errorf("validating account %d: %w", i, err) } } return nil @@ -176,6 +196,24 @@ func (a Account) PrivateKey() (*ecdsa.PrivateKey, error) { return crypto.HexToECDSA(a.RawPrivateKey) } +// Validate that the address and the private key specified in the +// config actually match +func (a Account) Validate() error { + privateKey, err := a.PrivateKey() + if err != nil { + return fmt.Errorf("invalid private key: %w", err) + } + privateKeyAddress := crypto.PubkeyToAddress(privateKey.PublicKey).Hex() + if a.RawAddress != privateKeyAddress { + return fmt.Errorf( + "address derived from private key (%s) does not match configured address (%s)", + privateKeyAddress, + a.RawAddress, + ) + } + return nil +} + // BitcoinNetworkType is a custom type to represent allowed network types type BitcoinNetworkType string @@ -199,16 +237,3 @@ func (bnt BitcoinNetworkType) GetParams() (chaincfg.Params, error) { return chaincfg.Params{}, fmt.Errorf("invalid bitcoin params %s", bnt) } } - -type AccountName string - -const ( - Deployer AccountName = "deployer" - UserERC20 AccountName = "user_erc_20" - UserZetaTest AccountName = "user_zeta_test" - UserZEVMMPTest AccountName = "user_zevm_mp" - UserBitcoin AccountName = "user_bitcoin" - UserEther AccountName = "user_ether" - UserMisc AccountName = "user_misc" - UserAdmin AccountName = "user_admin" -) diff --git a/e2e/config/config_test.go b/e2e/config/config_test.go new file mode 100644 index 0000000000..d2d8a32e72 --- /dev/null +++ b/e2e/config/config_test.go @@ -0,0 +1,32 @@ +package config + +import ( + "reflect" + "testing" + + "github.com/stretchr/testify/require" +) + +// TestAccountsSlicesSynced ensures than if any new accounts are added the +// AccountsSlice() function is updated +func TestConfigAccountsSliceSynced(t *testing.T) { + accountsType := reflect.TypeOf(Accounts{}) + numberOfAccounts := accountsType.NumField() + + require.Greater(t, numberOfAccounts, 0) + + require.Len(t, Config{}.Accounts.AsSlice(), numberOfAccounts) +} + +func TestConfigInvalidAccount(t *testing.T) { + conf := Config{ + Accounts: Accounts{ + Deployer: Account{ + RawAddress: "asdf", + RawPrivateKey: "asdf", + }, + }, + } + err := conf.Validate() + require.Error(t, err) +} diff --git a/e2e/e2etests/test_migrate_chain_support.go b/e2e/e2etests/test_migrate_chain_support.go index 4d0435623d..183e1b72a4 100644 --- a/e2e/e2etests/test_migrate_chain_support.go +++ b/e2e/e2etests/test_migrate_chain_support.go @@ -236,8 +236,7 @@ func configureEVM2(r *runner.E2ERunner) (*runner.E2ERunner, error) { r.Ctx, "admin-evm2", r.CtxCancel, - r.DeployerAddress, - r.DeployerPrivateKey, + r.DeployerAccount, r.FungibleAdminMnemonic, r.EVMClient, r.ZEVMClient, diff --git a/e2e/runner/runner.go b/e2e/runner/runner.go index d8df023057..dc5c931ad0 100644 --- a/e2e/runner/runner.go +++ b/e2e/runner/runner.go @@ -23,6 +23,7 @@ import ( "github.com/zeta-chain/protocol-contracts/pkg/uniswap/v2-core/contracts/uniswapv2factory.sol" uniswapv2router "github.com/zeta-chain/protocol-contracts/pkg/uniswap/v2-periphery/contracts/uniswapv2router02.sol" + "github.com/zeta-chain/zetacore/e2e/config" "github.com/zeta-chain/zetacore/e2e/contracts/contextapp" "github.com/zeta-chain/zetacore/e2e/contracts/erc20" "github.com/zeta-chain/zetacore/e2e/contracts/zevmswap" @@ -38,6 +39,7 @@ import ( // It also provides some helper functions type E2ERunner struct { // accounts + DeployerAccount config.Account DeployerAddress ethcommon.Address DeployerPrivateKey string TSSAddress ethcommon.Address @@ -117,8 +119,7 @@ func NewE2ERunner( ctx context.Context, name string, ctxCancel context.CancelFunc, - deployerAddress ethcommon.Address, - deployerPrivateKey string, + account config.Account, fungibleAdminMnemonic string, evmClient *ethclient.Client, zevmClient *ethclient.Client, @@ -139,8 +140,9 @@ func NewE2ERunner( Ctx: ctx, CtxCancel: ctxCancel, - DeployerAddress: deployerAddress, - DeployerPrivateKey: deployerPrivateKey, + DeployerAccount: account, + DeployerAddress: account.Address(), + DeployerPrivateKey: account.RawPrivateKey, FungibleAdminMnemonic: fungibleAdminMnemonic, ZEVMClient: zevmClient,