From edc61117f5164b6a336357c7999e96b9e1f3090a Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Wed, 5 Jun 2024 11:45:07 -0700 Subject: [PATCH] load addresses from yaml, fix ssh host keygen --- Dockerfile-localnet | 10 +- cmd/zetae2e/config/config.go | 32 ++--- cmd/zetae2e/config/contracts.go | 123 +++++++++--------- cmd/zetae2e/config/localnet.yml | 50 +++---- .../orchestrator/Dockerfile.fastbuild | 8 +- .../localnet/orchestrator/start-zetae2e.sh | 8 +- contrib/localnet/scripts/start-zetacored.sh | 28 ++-- e2e/config/config.go | 81 +++++++----- e2e/runner/runner.go | 2 +- e2e/runner/setup_evm.go | 8 +- 10 files changed, 190 insertions(+), 160 deletions(-) diff --git a/Dockerfile-localnet b/Dockerfile-localnet index ee16e6282b..07e8c41c6f 100644 --- a/Dockerfile-localnet +++ b/Dockerfile-localnet @@ -28,7 +28,7 @@ RUN go install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@v1.5.0 FROM golang:1.20.14-bookworm AS base-runtime RUN apt update && \ - apt install -yq jq curl tmux python3 openssh-server iputils-ping iproute2 && \ + apt install -yq jq yq curl tmux python3 openssh-server iputils-ping iproute2 && \ rm -rf /var/lib/apt/lists/* RUN ssh-keygen -A && \ @@ -45,13 +45,15 @@ ENV PATH /root/.zetacored/cosmovisor/current/bin/:/root/.zetaclientd/upgrades/cu COPY contrib/localnet/scripts /root COPY contrib/localnet/preparams /root/preparams -COPY contrib/localnet/ssh_config /root/.ssh/config +COPY contrib/localnet/ssh_config /etc/ssh/ssh_config.d/localnet COPY contrib/localnet/zetacored /root/zetacored COPY contrib/localnet/tss /root/tss +COPY cmd/zetae2e/config/localnet.yml /root/config.yml -RUN chmod 755 /root/*.sh +RUN chmod 755 /root/*.sh && \ + chmod 744 /etc/ssh/ssh_config.d/localnet -WORKDIR /usr/local/bin +WORKDIR /root EXPOSE 22 FROM base-runtime AS latest-runtime diff --git a/cmd/zetae2e/config/config.go b/cmd/zetae2e/config/config.go index 57c72f095f..71724f2b6f 100644 --- a/cmd/zetae2e/config/config.go +++ b/cmd/zetae2e/config/config.go @@ -88,23 +88,23 @@ func RunnerFromConfig( // ExportContractsFromRunner export contracts from the runner to config using a source config func ExportContractsFromRunner(r *runner.E2ERunner, conf config.Config) config.Config { // copy contracts from deployer runner - conf.Contracts.EVM.ZetaEthAddress = r.ZetaEthAddr.Hex() - conf.Contracts.EVM.ConnectorEthAddr = r.ConnectorEthAddr.Hex() - conf.Contracts.EVM.CustodyAddr = r.ERC20CustodyAddr.Hex() - conf.Contracts.EVM.ERC20 = r.ERC20Addr.Hex() - conf.Contracts.EVM.TestDappAddr = r.EvmTestDAppAddr.Hex() + conf.Contracts.EVM.ZetaEthAddress = config.DoubleQuotedString(r.ZetaEthAddr.Hex()) + conf.Contracts.EVM.ConnectorEthAddr = config.DoubleQuotedString(r.ConnectorEthAddr.Hex()) + conf.Contracts.EVM.CustodyAddr = config.DoubleQuotedString(r.ERC20CustodyAddr.Hex()) + conf.Contracts.EVM.ERC20 = config.DoubleQuotedString(r.ERC20Addr.Hex()) + conf.Contracts.EVM.TestDappAddr = config.DoubleQuotedString(r.EvmTestDAppAddr.Hex()) - conf.Contracts.ZEVM.SystemContractAddr = r.SystemContractAddr.Hex() - conf.Contracts.ZEVM.ETHZRC20Addr = r.ETHZRC20Addr.Hex() - conf.Contracts.ZEVM.ERC20ZRC20Addr = r.ERC20ZRC20Addr.Hex() - conf.Contracts.ZEVM.BTCZRC20Addr = r.BTCZRC20Addr.Hex() - conf.Contracts.ZEVM.UniswapFactoryAddr = r.UniswapV2FactoryAddr.Hex() - conf.Contracts.ZEVM.UniswapRouterAddr = r.UniswapV2RouterAddr.Hex() - conf.Contracts.ZEVM.ConnectorZEVMAddr = r.ConnectorZEVMAddr.Hex() - conf.Contracts.ZEVM.WZetaAddr = r.WZetaAddr.Hex() - conf.Contracts.ZEVM.ZEVMSwapAppAddr = r.ZEVMSwapAppAddr.Hex() - conf.Contracts.ZEVM.ContextAppAddr = r.ContextAppAddr.Hex() - conf.Contracts.ZEVM.TestDappAddr = r.ZevmTestDAppAddr.Hex() + conf.Contracts.ZEVM.SystemContractAddr = config.DoubleQuotedString(r.SystemContractAddr.Hex()) + conf.Contracts.ZEVM.ETHZRC20Addr = config.DoubleQuotedString(r.ETHZRC20Addr.Hex()) + conf.Contracts.ZEVM.ERC20ZRC20Addr = config.DoubleQuotedString(r.ERC20ZRC20Addr.Hex()) + conf.Contracts.ZEVM.BTCZRC20Addr = config.DoubleQuotedString(r.BTCZRC20Addr.Hex()) + conf.Contracts.ZEVM.UniswapFactoryAddr = config.DoubleQuotedString(r.UniswapV2FactoryAddr.Hex()) + conf.Contracts.ZEVM.UniswapRouterAddr = config.DoubleQuotedString(r.UniswapV2RouterAddr.Hex()) + conf.Contracts.ZEVM.ConnectorZEVMAddr = config.DoubleQuotedString(r.ConnectorZEVMAddr.Hex()) + conf.Contracts.ZEVM.WZetaAddr = config.DoubleQuotedString(r.WZetaAddr.Hex()) + conf.Contracts.ZEVM.ZEVMSwapAppAddr = config.DoubleQuotedString(r.ZEVMSwapAppAddr.Hex()) + conf.Contracts.ZEVM.ContextAppAddr = config.DoubleQuotedString(r.ContextAppAddr.Hex()) + conf.Contracts.ZEVM.TestDappAddr = config.DoubleQuotedString(r.ZevmTestDAppAddr.Hex()) return conf } diff --git a/cmd/zetae2e/config/contracts.go b/cmd/zetae2e/config/contracts.go index a47b39ef4e..03aad60ed7 100644 --- a/cmd/zetae2e/config/contracts.go +++ b/cmd/zetae2e/config/contracts.go @@ -3,7 +3,6 @@ package config import ( "fmt" - ethcommon "github.com/ethereum/go-ethereum/common" "github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/erc20custody.sol" zetaeth "github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/zeta.eth.sol" zetaconnectoreth "github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/zetaconnector.eth.sol" @@ -27,168 +26,172 @@ func setContractsFromConfig(r *runner.E2ERunner, conf config.Config) error { // set EVM contracts if c := conf.Contracts.EVM.ZetaEthAddress; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid ZetaEthAddress: %s", c) + r.ZetaEthAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid ZetaEthAddress: %w", err) } - r.ZetaEthAddr = ethcommon.HexToAddress(c) r.ZetaEth, err = zetaeth.NewZetaEth(r.ZetaEthAddr, r.EVMClient) if err != nil { return err } } + if c := conf.Contracts.EVM.ConnectorEthAddr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid ConnectorEthAddr: %s", c) + r.ConnectorEthAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid ConnectorEthAddr: %w", err) } - r.ConnectorEthAddr = ethcommon.HexToAddress(c) r.ConnectorEth, err = zetaconnectoreth.NewZetaConnectorEth(r.ConnectorEthAddr, r.EVMClient) if err != nil { return err } } + if c := conf.Contracts.EVM.CustodyAddr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid CustodyAddr: %s", c) + r.ERC20CustodyAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid CustodyAddr: %w", err) } - r.ERC20CustodyAddr = ethcommon.HexToAddress(c) r.ERC20Custody, err = erc20custody.NewERC20Custody(r.ERC20CustodyAddr, r.EVMClient) if err != nil { return err } } + if c := conf.Contracts.EVM.ERC20; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid ERC20: %s", c) + r.ERC20Addr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid ERC20: %w", err) } - r.ERC20Addr = ethcommon.HexToAddress(c) r.ERC20, err = erc20.NewERC20(r.ERC20Addr, r.EVMClient) if err != nil { return err } } - // set Zevm contracts + // set ZEVM contracts if c := conf.Contracts.ZEVM.SystemContractAddr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid SystemContractAddr: %s", c) + r.SystemContractAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid SystemContractAddr: %w", err) } - r.SystemContractAddr = ethcommon.HexToAddress(c) r.SystemContract, err = systemcontract.NewSystemContract(r.SystemContractAddr, r.ZEVMClient) if err != nil { return err } } + if c := conf.Contracts.ZEVM.ETHZRC20Addr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid ETHZRC20Addr: %s", c) + r.ETHZRC20Addr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid ETHZRC20Addr: %w", err) } - r.ETHZRC20Addr = ethcommon.HexToAddress(c) r.ETHZRC20, err = zrc20.NewZRC20(r.ETHZRC20Addr, r.ZEVMClient) if err != nil { return err } } + if c := conf.Contracts.ZEVM.ERC20ZRC20Addr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid ERC20ZRC20Addr: %s", c) + r.ERC20ZRC20Addr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid ERC20ZRC20Addr: %w", err) } - r.ERC20ZRC20Addr = ethcommon.HexToAddress(c) r.ERC20ZRC20, err = zrc20.NewZRC20(r.ERC20ZRC20Addr, r.ZEVMClient) if err != nil { return err } } + if c := conf.Contracts.ZEVM.BTCZRC20Addr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid BTCZRC20Addr: %s", c) - } - r.BTCZRC20Addr = ethcommon.HexToAddress(c) - r.BTCZRC20, err = zrc20.NewZRC20(r.BTCZRC20Addr, r.ZEVMClient) + r.BTCZRC20Addr, err = c.AsEVMAddress() if err != nil { - return err - } - } - if c := conf.Contracts.ZEVM.ERC20ZRC20Addr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid ERC20ZRC20Addr: %s", c) + return fmt.Errorf("invalid BTCZRC20Addr: %w", err) } - r.ERC20ZRC20Addr = ethcommon.HexToAddress(c) - r.ERC20ZRC20, err = zrc20.NewZRC20(r.ERC20ZRC20Addr, r.ZEVMClient) + r.BTCZRC20, err = zrc20.NewZRC20(r.BTCZRC20Addr, r.ZEVMClient) if err != nil { return err } } + if c := conf.Contracts.ZEVM.UniswapFactoryAddr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid UniswapFactoryAddr: %s", c) + r.UniswapV2FactoryAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid UniswapFactoryAddr: %w", err) } - r.UniswapV2FactoryAddr = ethcommon.HexToAddress(c) r.UniswapV2Factory, err = uniswapv2factory.NewUniswapV2Factory(r.UniswapV2FactoryAddr, r.ZEVMClient) if err != nil { return err } } + if c := conf.Contracts.ZEVM.UniswapRouterAddr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid UniswapRouterAddr: %s", c) + r.UniswapV2RouterAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid UniswapRouterAddr: %w", err) } - r.UniswapV2RouterAddr = ethcommon.HexToAddress(c) r.UniswapV2Router, err = uniswapv2router.NewUniswapV2Router02(r.UniswapV2RouterAddr, r.ZEVMClient) if err != nil { return err } } + if c := conf.Contracts.ZEVM.ConnectorZEVMAddr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid ConnectorZEVMAddr: %s", c) + r.ConnectorZEVMAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid ConnectorZEVMAddr: %w", err) } - r.ConnectorZEVMAddr = ethcommon.HexToAddress(c) r.ConnectorZEVM, err = connectorzevm.NewZetaConnectorZEVM(r.ConnectorZEVMAddr, r.ZEVMClient) if err != nil { return err } } + if c := conf.Contracts.ZEVM.WZetaAddr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid WZetaAddr: %s", c) + r.WZetaAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid WZetaAddr: %w", err) } - r.WZetaAddr = ethcommon.HexToAddress(c) r.WZeta, err = wzeta.NewWETH9(r.WZetaAddr, r.ZEVMClient) if err != nil { return err } } + if c := conf.Contracts.ZEVM.ZEVMSwapAppAddr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid ZEVMSwapAppAddr: %s", c) + r.ZEVMSwapAppAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid ZEVMSwapAppAddr: %w", err) } - r.ZEVMSwapAppAddr = ethcommon.HexToAddress(c) r.ZEVMSwapApp, err = zevmswap.NewZEVMSwapApp(r.ZEVMSwapAppAddr, r.ZEVMClient) if err != nil { return err } } + if c := conf.Contracts.ZEVM.ContextAppAddr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid ContextAppAddr: %s", c) + r.ContextAppAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid ContextAppAddr: %w", err) } - r.ContextAppAddr = ethcommon.HexToAddress(c) r.ContextApp, err = contextapp.NewContextApp(r.ContextAppAddr, r.ZEVMClient) if err != nil { return err } } + if c := conf.Contracts.ZEVM.TestDappAddr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid ZevmTestDappAddr: %s", c) + r.ZevmTestDAppAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid ZevmTestDappAddr: %w", err) } - r.ZevmTestDAppAddr = ethcommon.HexToAddress(c) } + if c := conf.Contracts.EVM.TestDappAddr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid EvmTestDappAddr: %s", c) + r.EvmTestDAppAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid EvmTestDappAddr: %w", err) } - r.EvmTestDAppAddr = ethcommon.HexToAddress(c) } return nil diff --git a/cmd/zetae2e/config/localnet.yml b/cmd/zetae2e/config/localnet.yml index cc16456f12..79c9c8c990 100644 --- a/cmd/zetae2e/config/localnet.yml +++ b/cmd/zetae2e/config/localnet.yml @@ -1,38 +1,38 @@ zeta_chain_id: "athens_101-1" accounts: deployer: - bech32_address: zeta1fxlsqfxvxtrnas4ac7spymcu9r3m4fen3sle3d - evm_address: 0x49bF0024Cc32C73ec2BDc7A0126f1c28E3baA733 - private_key: e79da36bffce4258079404273284bf5c7e0ee744f8d537cc7d76e85f124259bb + bech32_address: "zeta1n8tfvy6s4glmp8r4steuja5zrgfalvr0nfr99q" + evm_address: "0x99d6961350aA3fb09C7582F3C976821A13DFb06f" + private_key: "263c595c5b703631d8e489ca95b6dad8a460e710df6b47d31b2e00abbbbeed53" additional_accounts: user_erc20: - bech32_address: zeta149uwgfqpcx0ac582ef2wwnqq6u8j5sfpjh9evc - evm_address: 0xa978E42401c19fdC50eAcA54E74c00d70f2A4121 - private_key: b4ccebf1759b50fd9cc207e34d56a3483236d59b1fff3a113a5d8fecd8eed4f0 + bech32_address: "zeta1m2kcpr459cwgzv4hv2vak6rz89umh5humxme6a" + evm_address: "0xdaAd808eB42E1C8132b76299DB68623979bBd2FC" + private_key: "73c026bf56ed085c8dbd3e0f3c0ae0daedd8d688d82b716aff75b53d281ad5d7" user_zeta_test: - bech32_address: zeta1930fvyrh5d2tmjkd45vvhecqemsep5x3stpeg6 - evm_address: 0x2c5E961077A354bdcaCdAd18cbe700CeE190d0d1 - private_key: abc4bc5148bb53aba8497811a535d6fcafaaee192ef48ebc45b6b8f07b3c3176 + bech32_address: "zeta12ztczzt6j4znwf32tvqcqspah5s3qg8fkwx2wx" + evm_address: "0x509781097A954537262a5B0180403dbd211020e9" + private_key: "eea9972997087dfc1a024ba066777f7a40348a6c1f0fb901d409f5846ef44fdf" user_zevm_mp_test: - bech32_address: zeta10dcylj5qwf2hhnctcx6hdxdlw7svts9wdgsvh4 - evm_address: 0x7B704fcA8072557bCF0bc1B57699Bf77a0c5C0Ae - private_key: 32b356b6dc1e6e7c8c95ad60701498dcbe38201e5e3411b3f3896e6441e1efc9 + bech32_address: "zeta1wlutj5p2hr23p6z4vhp7jnt7cxxkd8rnfczrvc" + evm_address: "0x77f8b9502Ab8D510E85565c3E94D7ec18D669c73" + private_key: "93e4c38cd1689c6be87f9d5011cdd231ab968472bb1483ecbca5fb1db8a0e4af" user_bitcoin: - bech32_address: zeta1yu27pntgex05gc0kqu2k7dtmp9zg8xqhpe0uc2 - evm_address: 0x2715e0cD68c99F4461f607156f357B0944839817 - private_key: 89233cf4ae1246d3818931791715a5445fc2e704463730e151c55a38df2479fc + bech32_address: "zeta1fltrg8z7k9wt7dygu68680le9vh96kzvxcpqfn" + evm_address: "0x4fD6341C5eB15CbF3488e68FA3bFf92b2E5d584C" + private_key: "0be8b14808b52c3ca85113b5472fe76eb2566bddcaf900de453218cc4e7fa182" user_ether: - bech32_address: zeta1uqmx23pxfm5626lhmrlqw4ud36vyptsdf8x20d - evm_address: 0xe0366544264EE9a56Bf7D8Fe07578d8e9840AE0d - private_key: b278b31e4add702f2462400fe9da2386908462a7ee69b81e3feeeb3f6679ac24 + bech32_address: "zeta1vprcujr05nx5jywv24a5vpnlxly84crlxzngdh" + evm_address: "0x60478e486Fa4Cd4911CC557b46067f37c87Ae07f" + private_key: "916d769389df042d7b8fabe3487fc762e7ac0cbf57e3b5d6a8c9d97b763e2adc" user_misc: - bech32_address: zeta1peejc609gn74wn9xghc7tklsspkghhd3udmg05 - evm_address: 0x0e732c69e544fd574cA645f1E5DbF0806C8bDdb1 - private_key: 497c5d1abb1d08052c75b51d7854815a2e6382e0d1f423e70ec1f9873371d7e0 + bech32_address: "zeta16mq0g7r27pevqnwx6qc6zvvd69sxfhfn08easj" + evm_address: "0xd6c0f4786Af072c04dc6d031a1318dd16064dD33" + private_key: "cb84dcec621aecde27c9f3187eb86bb8f600da9d3df4c7dcbe0db8d3091e4f10" user_admin: - bech32_address: zeta1efqph3qvk68tj5vldy0acvnvgq7kpca4y22xen - evm_address: 0xcA401bC40CB68eb9519F691FdC326c403D60e3B5 - private_key: 73871482c14868071fbbbdc83e56c9c2c4047a4649ada35658eb01dfca5502e9 + bech32_address: "zeta1rpnxskyhppzwrn3awhqu3wxfey2kd5mnelgkuv" + evm_address: "0x18666858970844e1ce3D75C1C8B8C9c91566D373" + private_key: "4eb834f11c6ad5038e79756f82f74b83a0c8dee7c1cfbb16878ecabeae5efbab" rpcs: zevm: "http://zetacore0:8545" evm: "http://eth:8545" @@ -61,4 +61,4 @@ contracts: 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 +fungible_admin_mnemonic: "raccoon foot earn can napkin parade verb bench mind deal crunch gorilla" diff --git a/contrib/localnet/orchestrator/Dockerfile.fastbuild b/contrib/localnet/orchestrator/Dockerfile.fastbuild index 8b31f801fd..984fedfc36 100644 --- a/contrib/localnet/orchestrator/Dockerfile.fastbuild +++ b/contrib/localnet/orchestrator/Dockerfile.fastbuild @@ -1,9 +1,9 @@ FROM zetanode:latest as zeta FROM ethereum/client-go:v1.10.26 as geth -FROM golang:1.20.14-bookworm as orchestrator +FROM golang:1.20.14-bookworm as orchestrator RUN apt update && \ - apt install -yq jq curl tmux python3 openssh-server iputils-ping iproute2 && \ + apt install -yq jq yq curl tmux python3 openssh-server iputils-ping iproute2 && \ rm -rf /var/lib/apt/lists/* COPY --from=geth /usr/local/bin/geth /usr/local/bin/ @@ -11,6 +11,8 @@ COPY --from=zeta /usr/local/bin/zetacored /usr/local/bin/zetaclientd /usr/local/ COPY contrib/localnet/orchestrator/start-zetae2e.sh /work/ COPY cmd/zetae2e/config/localnet.yml /work/config.yml -RUN chmod +x /work/*.sh +COPY contrib/localnet/ssh_config /etc/ssh/ssh_config.d/localnet +RUN chmod +x /work/*.sh && \ + chmod 744 /etc/ssh/ssh_config.d/localnet WORKDIR /work diff --git a/contrib/localnet/orchestrator/start-zetae2e.sh b/contrib/localnet/orchestrator/start-zetae2e.sh index 628a8d99fd..395225fc61 100644 --- a/contrib/localnet/orchestrator/start-zetae2e.sh +++ b/contrib/localnet/orchestrator/start-zetae2e.sh @@ -50,7 +50,7 @@ echo "funding zeta tester address ${address} with 10000 Ether" geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 # unlock zevm message passing tester accounts -address=$(yq -r '.additional_accounts.zevm_mp_test.evm_address' config.yml) +address=$(yq -r '.additional_accounts.user_zevm_mp_test.evm_address' config.yml) echo "funding zevm mp tester address ${address} with 10000 Ether" geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 @@ -70,14 +70,10 @@ echo "funding misc tester address ${address} with 10000 Ether" geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 # unlock admin erc20 tests accounts -address=$(yq -r '.additional_accounts.admin.evm_address' config.yml) +address=$(yq -r '.additional_accounts.user_admin.evm_address' config.yml) echo "funding admin tester address ${address} with 10000 Ether" geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 -# unlock the TSS account -echo "funding TSS address 0xF421292cb0d3c97b90EEEADfcD660B893592c6A2 with 10000 Ether" -geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0xF421292cb0d3c97b90EEEADfcD660B893592c6A2", value: web3.toWei(10000,"ether")})' attach http://eth:8545 - ### Run zetae2e command depending on the option passed if [ "$OPTION" == "upgrade" ]; then diff --git a/contrib/localnet/scripts/start-zetacored.sh b/contrib/localnet/scripts/start-zetacored.sh index 278ecd778b..7866ccb57e 100755 --- a/contrib/localnet/scripts/start-zetacored.sh +++ b/contrib/localnet/scripts/start-zetacored.sh @@ -218,24 +218,32 @@ then cat $HOME/.zetacored/config/genesis.json | jq '.app_state["gov"]["params"]["voting_period"]="100s"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json fi -# set admin account - zetacored add-genesis-account zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk 100000000000000000000000000azeta + set -x + 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 +# set admin account + address=$(yq -r '.additional_accounts.user_admin.bech32_address' config.yml) + zetacored add-genesis-account "$address" 100000000000000000000000000azeta + cat $HOME/.zetacored/config/genesis.json | jq --arg address "$address" '.app_state["authority"]["policies"]["items"][0]["address"] = $address' > $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 --arg address "$address" '.app_state["authority"]["policies"]["items"][1]["address"] = $address' > $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 --arg address "$address" '.app_state["authority"]["policies"]["items"][2]["address"] = $address' > $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 - zetacored add-genesis-account zeta1uhznv7uzyjq84s3q056suc8pkme85lkvhrz3dd 100000000000000000000000000azeta + address=$(yq -r '.accounts.deployer.bech32_address' config.yml) + zetacored add-genesis-account "$address" 100000000000000000000000000azeta # erc20 tester - zetacored add-genesis-account zeta1datate7xmwm4uk032f9rmcu0cwy7ch7kg6y6zv 100000000000000000000000000azeta + address=$(yq -r '.additional_accounts.user_erc20.bech32_address' config.yml) + zetacored add-genesis-account "$address" 100000000000000000000000000azeta # zeta tester - zetacored add-genesis-account zeta1tnp0hvsq4y5mxuhrq9h3jfwulxywpq0ads0rer 100000000000000000000000000azeta + address=$(yq -r '.additional_accounts.user_zeta_test.bech32_address' config.yml) + zetacored add-genesis-account "$address" 100000000000000000000000000azeta # bitcoin tester - zetacored add-genesis-account zeta19q7czqysah6qg0n4y3l2a08gfzqxydla492v80 100000000000000000000000000azeta + address=$(yq -r '.additional_accounts.user_bitcoin.bech32_address' config.yml) + zetacored add-genesis-account "$address" 100000000000000000000000000azeta # ethers tester - zetacored add-genesis-account zeta134rakuus43xn63yucgxhn88ywj8ewcv6ezn2ga 100000000000000000000000000azeta + address=$(yq -r '.additional_accounts.user_ether.bech32_address' config.yml) + zetacored add-genesis-account "$address" 100000000000000000000000000azeta # 3. Copy the genesis.json to all the nodes .And use it to create a gentx for every node zetacored gentx operator 1000000000000000000000azeta --chain-id=$CHAINID --keyring-backend=$KEYRING --gas-prices 20000000000azeta diff --git a/e2e/config/config.go b/e2e/config/config.go index 834c14f66e..8ad66fb1c8 100644 --- a/e2e/config/config.go +++ b/e2e/config/config.go @@ -12,9 +12,32 @@ import ( ethcommon "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) +// DoubleQuotedString forces a string to be double quoted when marshaling to yaml. +// This is required because of https://github.com/go-yaml/yaml/issues/847 +type DoubleQuotedString string + +func (s DoubleQuotedString) MarshalYAML() (interface{}, error) { + return yaml.Node{ + Value: string(s), + Kind: yaml.ScalarNode, + Style: yaml.DoubleQuotedStyle, + }, nil +} + +func (s DoubleQuotedString) String() string { + return string(s) +} + +func (s DoubleQuotedString) AsEVMAddress() (ethcommon.Address, error) { + if !ethcommon.IsHexAddress(string(s)) { + return ethcommon.Address{}, fmt.Errorf("invalid evm address: %s", string(s)) + } + return ethcommon.HexToAddress(string(s)), nil +} + // Config contains the configuration for the e2e test type Config struct { Accounts Accounts `yaml:"accounts"` @@ -27,13 +50,9 @@ type Config struct { // Account contains configuration for an account type Account struct { - RawBech32Address string `yaml:"bech32_address"` - // hex encoded EVM style address - // - // WARN: this will not be double quoted because of https://github.com/go-yaml/yaml/issues/847 - // and you may run into issues loading it in non-golang applications - RawEVMAddress string `yaml:"evm_address"` - RawPrivateKey string `yaml:"private_key"` + RawBech32Address DoubleQuotedString `yaml:"bech32_address"` + RawEVMAddress DoubleQuotedString `yaml:"evm_address"` + RawPrivateKey DoubleQuotedString `yaml:"private_key"` } // Accounts are the required accounts to run any e2e test @@ -79,26 +98,26 @@ type Contracts struct { // EVM contains the addresses of predeployed contracts on the EVM chain type EVM struct { - ZetaEthAddress string `yaml:"zeta_eth"` - ConnectorEthAddr string `yaml:"connector_eth"` - CustodyAddr string `yaml:"custody"` - ERC20 string `yaml:"erc20"` - TestDappAddr string `yaml:"test_dapp"` + ZetaEthAddress DoubleQuotedString `yaml:"zeta_eth"` + ConnectorEthAddr DoubleQuotedString `yaml:"connector_eth"` + CustodyAddr DoubleQuotedString `yaml:"custody"` + ERC20 DoubleQuotedString `yaml:"erc20"` + TestDappAddr DoubleQuotedString `yaml:"test_dapp"` } // ZEVM contains the addresses of predeployed contracts on the zEVM chain type ZEVM struct { - SystemContractAddr string `yaml:"system_contract"` - ETHZRC20Addr string `yaml:"eth_zrc20"` - ERC20ZRC20Addr string `yaml:"erc20_zrc20"` - BTCZRC20Addr string `yaml:"btc_zrc20"` - UniswapFactoryAddr string `yaml:"uniswap_factory"` - UniswapRouterAddr string `yaml:"uniswap_router"` - ConnectorZEVMAddr string `yaml:"connector_zevm"` - WZetaAddr string `yaml:"wzeta"` - ZEVMSwapAppAddr string `yaml:"zevm_swap_app"` - ContextAppAddr string `yaml:"context_app"` - TestDappAddr string `yaml:"test_dapp"` + SystemContractAddr DoubleQuotedString `yaml:"system_contract"` + ETHZRC20Addr DoubleQuotedString `yaml:"eth_zrc20"` + ERC20ZRC20Addr DoubleQuotedString `yaml:"erc20_zrc20"` + BTCZRC20Addr DoubleQuotedString `yaml:"btc_zrc20"` + UniswapFactoryAddr DoubleQuotedString `yaml:"uniswap_factory"` + UniswapRouterAddr DoubleQuotedString `yaml:"uniswap_router"` + ConnectorZEVMAddr DoubleQuotedString `yaml:"connector_zevm"` + WZetaAddr DoubleQuotedString `yaml:"wzeta"` + ZEVMSwapAppAddr DoubleQuotedString `yaml:"zevm_swap_app"` + ContextAppAddr DoubleQuotedString `yaml:"context_app"` + TestDappAddr DoubleQuotedString `yaml:"test_dapp"` } // DefaultConfig returns the default config using values for localnet testing @@ -245,11 +264,11 @@ func (c *Config) GenerateKeys() error { } func (a Account) EVMAddress() ethcommon.Address { - return ethcommon.HexToAddress(a.RawEVMAddress) + return ethcommon.HexToAddress(a.RawEVMAddress.String()) } func (a Account) PrivateKey() (*ecdsa.PrivateKey, error) { - return crypto.HexToECDSA(a.RawPrivateKey) + return crypto.HexToECDSA(a.RawPrivateKey.String()) } // Validate that the address and the private key specified in the @@ -260,14 +279,14 @@ func (a Account) Validate() error { return fmt.Errorf("invalid private key: %w", err) } privateKeyAddress := crypto.PubkeyToAddress(privateKey.PublicKey) - if a.RawEVMAddress != privateKeyAddress.Hex() { + if a.RawEVMAddress.String() != privateKeyAddress.Hex() { return fmt.Errorf( "address derived from private key (%s) does not match configured address (%s)", privateKeyAddress, a.RawEVMAddress, ) } - _, bech32Data, err := bech32.DecodeAndConvert(a.RawBech32Address) + _, bech32Data, err := bech32.DecodeAndConvert(a.RawBech32Address.String()) if err != nil { return fmt.Errorf("decoding bech32 address: %w", err) } @@ -320,8 +339,8 @@ func generateAccount() (Account, error) { } return Account{ - RawEVMAddress: evmAddress.String(), - RawPrivateKey: encodedPrivateKey, - RawBech32Address: bech32Address, + RawEVMAddress: DoubleQuotedString(evmAddress.String()), + RawPrivateKey: DoubleQuotedString(encodedPrivateKey), + RawBech32Address: DoubleQuotedString(bech32Address), }, nil } diff --git a/e2e/runner/runner.go b/e2e/runner/runner.go index c81a742571..eab3c50b3a 100644 --- a/e2e/runner/runner.go +++ b/e2e/runner/runner.go @@ -142,7 +142,7 @@ func NewE2ERunner( DeployerAccount: account, DeployerAddress: account.EVMAddress(), - DeployerPrivateKey: account.RawPrivateKey, + DeployerPrivateKey: account.RawPrivateKey.String(), FungibleAdminMnemonic: fungibleAdminMnemonic, ZEVMClient: zevmClient, diff --git a/e2e/runner/setup_evm.go b/e2e/runner/setup_evm.go index 2bc0aeb70d..41b2603a12 100644 --- a/e2e/runner/setup_evm.go +++ b/e2e/runner/setup_evm.go @@ -28,14 +28,14 @@ func (runner *E2ERunner) SetEVMContractsFromConfig() { } // Set ZetaEthAddr - runner.ZetaEthAddr = ethcommon.HexToAddress(conf.Contracts.EVM.ZetaEthAddress) + runner.ZetaEthAddr = ethcommon.HexToAddress(conf.Contracts.EVM.ZetaEthAddress.String()) runner.ZetaEth, err = zetaeth.NewZetaEth(runner.ZetaEthAddr, runner.EVMClient) if err != nil { panic(err) } // Set ConnectorEthAddr - runner.ConnectorEthAddr = ethcommon.HexToAddress(conf.Contracts.EVM.ConnectorEthAddr) + runner.ConnectorEthAddr = ethcommon.HexToAddress(conf.Contracts.EVM.ConnectorEthAddr.String()) runner.ConnectorEth, err = zetaconnectoreth.NewZetaConnectorEth(runner.ConnectorEthAddr, runner.EVMClient) if err != nil { panic(err) @@ -84,7 +84,7 @@ func (runner *E2ERunner) SetupEVM(contractsDeployed bool, whitelistERC20 bool) { } runner.ZetaEth = ZetaEth runner.ZetaEthAddr = zetaEthAddr - conf.Contracts.EVM.ZetaEthAddress = zetaEthAddr.String() + conf.Contracts.EVM.ZetaEthAddress = config.DoubleQuotedString(zetaEthAddr.String()) runner.Logger.Info("ZetaEth contract address: %s, tx hash: %s", zetaEthAddr.Hex(), zetaEthAddr.Hash().Hex()) runner.Logger.Info("Deploying ZetaConnectorEth contract") @@ -101,7 +101,7 @@ func (runner *E2ERunner) SetupEVM(contractsDeployed bool, whitelistERC20 bool) { } runner.ConnectorEth = ConnectorEth runner.ConnectorEthAddr = connectorEthAddr - conf.Contracts.EVM.ConnectorEthAddr = connectorEthAddr.String() + conf.Contracts.EVM.ConnectorEthAddr = config.DoubleQuotedString(connectorEthAddr.String()) runner.Logger.Info( "ZetaConnectorEth contract address: %s, tx hash: %s",