From da096b08c396d9a67d3ec0f0ebf3e5dffefd6563 Mon Sep 17 00:00:00 2001 From: Dmitry S <11892559+swift1337@users.noreply.github.com> Date: Tue, 3 Sep 2024 17:38:12 +0300 Subject: [PATCH 1/2] Improve start-zetae2e.sh --- .../localnet/orchestrator/start-zetae2e.sh | 107 ++++++++++-------- 1 file changed, 62 insertions(+), 45 deletions(-) diff --git a/contrib/localnet/orchestrator/start-zetae2e.sh b/contrib/localnet/orchestrator/start-zetae2e.sh index 2dfdb123ba..c3d0c1dcde 100644 --- a/contrib/localnet/orchestrator/start-zetae2e.sh +++ b/contrib/localnet/orchestrator/start-zetae2e.sh @@ -1,5 +1,7 @@ #!/bin/bash +# shellcheck disable=SC2317 + # The script run the zetae2e CLI to run local end-to-end tests # First argument is the command to run the local e2e # A second optional argument can be passed and can have the following value: @@ -24,6 +26,49 @@ get_zetacored_version() { exit 1 } +# Reads unquoted string value from config by its path +# Usage: config_str +config_str() { + yq -r "$1" config.yml +} + +# Sends Ether to the given address on ZetaChain +# Usage: fund_zevm
[comment] +fund_zevm() { + local address=$1 + local ether=$2 + local comment=${3:-} + + if [ -z "$comment" ]; then + echo "funding zevm address $address with $ether eth" + else + echo "funding zevm address $address ($comment) with $ether eth" + fi + + geth --exec \ + "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(${ether}, 'ether')})" \ + attach http://eth:8545 > /dev/null; +} + +# Combines fund_zevm with config_str +# Usage: fund_zevm_from_config [comment] +fund_zevm_from_config() { + local config_key=$1 + local ether=$2 + local comment=${3:-} + + # Fetch the address from the config file using config_str + # shellcheck disable=SC2155 + local address=$(config_str "$config_key") + if [ -z "$address" ]; then + echo "Error: Address not found for key $config_key" + return 1 + fi + + # Call fund_zevm with the fetched address, ether amount, and optional comment + fund_zevm "$address" "$ether" "$comment" +} + # Wait for authorized_keys file to exist (generated by zetacore0) while [ ! -f ~/.ssh/authorized_keys ]; do echo "Waiting for authorized_keys file to exist..." @@ -42,85 +87,57 @@ sleep 2 ### Create the accounts and fund them with Ether on local Ethereum network # unlock the default account account -address=$(yq -r '.default_account.evm_address' config.yml) -echo "funding deployer address ${address} with 10000 Ether" -geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 > /dev/null +fund_zevm_from_config '.default_account.evm_address' 10000 "deployer" # unlock erc20 tester accounts -address=$(yq -r '.additional_accounts.user_erc20.evm_address' config.yml) -echo "funding erc20 address ${address} with 10000 Ether" -geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 > /dev/null +fund_zevm_from_config '.additional_accounts.user_erc20.evm_address' 10000 "ERC20 tester" # unlock zeta tester accounts -address=$(yq -r '.additional_accounts.user_zeta_test.evm_address' config.yml) -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 > /dev/null +fund_zevm_from_config '.additional_accounts.user_zeta_test.evm_address' 10000 "zeta tester" # unlock zevm message passing tester accounts -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 > /dev/null +fund_zevm_from_config '.additional_accounts.user_zevm_mp_test.evm_address' 10000 "zevm mp tester" # unlock bitcoin tester accounts -address=$(yq -r '.additional_accounts.user_bitcoin.evm_address' config.yml) -echo "funding bitcoin tester address ${address} with 10000 Ether" -geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 > /dev/null +fund_zevm_from_config '.additional_accounts.user_bitcoin.evm_address' 10000 "bitcoin tester" # unlock solana tester accounts -address=$(yq -r '.additional_accounts.user_solana.evm_address' config.yml) -echo "funding solana tester address ${address} with 10000 Ether" -geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 > /dev/null +fund_zevm_from_config '.additional_accounts.user_solana.evm_address' 10000 "solana tester" # unlock ethers tester accounts -address=$(yq -r '.additional_accounts.user_ether.evm_address' config.yml) -echo "funding ether tester address ${address} with 10000 Ether" -geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 > /dev/null +fund_zevm_from_config '.additional_accounts.user_ether.evm_address' 10000 "ether tester" # unlock miscellaneous tests accounts -address=$(yq -r '.additional_accounts.user_misc.evm_address' config.yml) -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 > /dev/null +fund_zevm_from_config '.additional_accounts.user_misc.evm_address' 10000 "misc tester" # unlock admin erc20 tests accounts -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 > /dev/null +fund_zevm_from_config '.additional_accounts.user_admin.evm_address' 10000 "admin tester" # unlock migration tests accounts -address=$(yq -r '.additional_accounts.user_migration.evm_address' config.yml) -echo "funding migration tester address ${address} with 10000 Ether" -geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 > /dev/null +fund_zevm_from_config '.additional_accounts.user_migration.evm_address' 10000 "migration tester" # unlock v2 ethers tests accounts -address=$(yq -r '.additional_accounts.user_v2_ether.evm_address' config.yml) -echo "funding v2 ethers tester address ${address} with 10000 Ether" -geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 > /dev/null +fund_zevm_from_config '.additional_accounts.user_v2_ether.evm_address' 10000 "V2 ethers tester" # unlock v2 erc20 tests accounts -address=$(yq -r '.additional_accounts.user_v2_erc20.evm_address' config.yml) -echo "funding v2 erc20 tester address ${address} with 10000 Ether" -geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 > /dev/null +fund_zevm_from_config '.additional_accounts.user_v2_erc20.evm_address' 10000 "V2 ERC20 tester" # unlock v2 ethers revert tests accounts -address=$(yq -r '.additional_accounts.user_v2_ether_revert.evm_address' config.yml) -echo "funding v2 ethers revert tester address ${address} with 10000 Ether" -geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 > /dev/null +fund_zevm_from_config '.additional_accounts.user_v2_ether_revert.evm_address' 10000 "V2 ethers revert tester" # unlock v2 erc20 revert tests accounts -address=$(yq -r '.additional_accounts.user_v2_erc20_revert.evm_address' config.yml) -echo "funding v2 erc20 revert tester address ${address} with 10000 Ether" -geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 > /dev/null +fund_zevm_from_config '.additional_accounts.user_v2_erc20_revert.evm_address' 10000 "V2 ERC20 revert tester" # unlock local solana relayer accounts if host solana > /dev/null; then - solana_url=$(yq -r '.rpcs.solana' config.yml) + solana_url=$(config_str '.rpcs.solana') solana config set --url "$solana_url" > /dev/null - relayer=$(yq -r '.observer_relayer_accounts.relayer_accounts[0].solana_address' config.yml) + relayer=$(config_str '.observer_relayer_accounts.relayer_accounts[0].solana_address') echo "funding solana relayer address ${relayer} with 100 SOL" solana airdrop 100 "$relayer" > /dev/null - relayer=$(yq -r '.observer_relayer_accounts.relayer_accounts[1].solana_address' config.yml) + relayer=$(config_str '.observer_relayer_accounts.relayer_accounts[1].solana_address') echo "funding solana relayer address ${relayer} with 100 SOL" solana airdrop 100 "$relayer" > /dev/null fi From 81012ce40b36eb6ad8f67799e1cb14ab033ae9d7 Mon Sep 17 00:00:00 2001 From: Dmitry S <11892559+swift1337@users.noreply.github.com> Date: Tue, 3 Sep 2024 18:37:16 +0300 Subject: [PATCH 2/2] Fix typo --- .../localnet/orchestrator/start-zetae2e.sh | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/contrib/localnet/orchestrator/start-zetae2e.sh b/contrib/localnet/orchestrator/start-zetae2e.sh index c3d0c1dcde..0e3eda7e54 100644 --- a/contrib/localnet/orchestrator/start-zetae2e.sh +++ b/contrib/localnet/orchestrator/start-zetae2e.sh @@ -32,17 +32,17 @@ config_str() { yq -r "$1" config.yml } -# Sends Ether to the given address on ZetaChain -# Usage: fund_zevm
[comment] -fund_zevm() { +# Sends Ether to the given address on Ethereum localnet +# Usage: fund_eth
[comment] +fund_eth() { local address=$1 local ether=$2 local comment=${3:-} if [ -z "$comment" ]; then - echo "funding zevm address $address with $ether eth" + echo "funding eth address $address with $ether eth" else - echo "funding zevm address $address ($comment) with $ether eth" + echo "funding eth address $address ($comment) with $ether eth" fi geth --exec \ @@ -50,9 +50,9 @@ fund_zevm() { attach http://eth:8545 > /dev/null; } -# Combines fund_zevm with config_str -# Usage: fund_zevm_from_config [comment] -fund_zevm_from_config() { +# Combines fund_eth with config_str +# Usage: fund_eth_from_config [comment] +fund_eth_from_config() { local config_key=$1 local ether=$2 local comment=${3:-} @@ -65,8 +65,8 @@ fund_zevm_from_config() { return 1 fi - # Call fund_zevm with the fetched address, ether amount, and optional comment - fund_zevm "$address" "$ether" "$comment" + # Call fund_eth with the fetched address, ether amount, and optional comment + fund_eth "$address" "$ether" "$comment" } # Wait for authorized_keys file to exist (generated by zetacore0) @@ -87,46 +87,46 @@ sleep 2 ### Create the accounts and fund them with Ether on local Ethereum network # unlock the default account account -fund_zevm_from_config '.default_account.evm_address' 10000 "deployer" +fund_eth_from_config '.default_account.evm_address' 10000 "deployer" # unlock erc20 tester accounts -fund_zevm_from_config '.additional_accounts.user_erc20.evm_address' 10000 "ERC20 tester" +fund_eth_from_config '.additional_accounts.user_erc20.evm_address' 10000 "ERC20 tester" # unlock zeta tester accounts -fund_zevm_from_config '.additional_accounts.user_zeta_test.evm_address' 10000 "zeta tester" +fund_eth_from_config '.additional_accounts.user_zeta_test.evm_address' 10000 "zeta tester" # unlock zevm message passing tester accounts -fund_zevm_from_config '.additional_accounts.user_zevm_mp_test.evm_address' 10000 "zevm mp tester" +fund_eth_from_config '.additional_accounts.user_zevm_mp_test.evm_address' 10000 "zevm mp tester" # unlock bitcoin tester accounts -fund_zevm_from_config '.additional_accounts.user_bitcoin.evm_address' 10000 "bitcoin tester" +fund_eth_from_config '.additional_accounts.user_bitcoin.evm_address' 10000 "bitcoin tester" # unlock solana tester accounts -fund_zevm_from_config '.additional_accounts.user_solana.evm_address' 10000 "solana tester" +fund_eth_from_config '.additional_accounts.user_solana.evm_address' 10000 "solana tester" # unlock ethers tester accounts -fund_zevm_from_config '.additional_accounts.user_ether.evm_address' 10000 "ether tester" +fund_eth_from_config '.additional_accounts.user_ether.evm_address' 10000 "ether tester" # unlock miscellaneous tests accounts -fund_zevm_from_config '.additional_accounts.user_misc.evm_address' 10000 "misc tester" +fund_eth_from_config '.additional_accounts.user_misc.evm_address' 10000 "misc tester" # unlock admin erc20 tests accounts -fund_zevm_from_config '.additional_accounts.user_admin.evm_address' 10000 "admin tester" +fund_eth_from_config '.additional_accounts.user_admin.evm_address' 10000 "admin tester" # unlock migration tests accounts -fund_zevm_from_config '.additional_accounts.user_migration.evm_address' 10000 "migration tester" +fund_eth_from_config '.additional_accounts.user_migration.evm_address' 10000 "migration tester" # unlock v2 ethers tests accounts -fund_zevm_from_config '.additional_accounts.user_v2_ether.evm_address' 10000 "V2 ethers tester" +fund_eth_from_config '.additional_accounts.user_v2_ether.evm_address' 10000 "V2 ethers tester" # unlock v2 erc20 tests accounts -fund_zevm_from_config '.additional_accounts.user_v2_erc20.evm_address' 10000 "V2 ERC20 tester" +fund_eth_from_config '.additional_accounts.user_v2_erc20.evm_address' 10000 "V2 ERC20 tester" # unlock v2 ethers revert tests accounts -fund_zevm_from_config '.additional_accounts.user_v2_ether_revert.evm_address' 10000 "V2 ethers revert tester" +fund_eth_from_config '.additional_accounts.user_v2_ether_revert.evm_address' 10000 "V2 ethers revert tester" # unlock v2 erc20 revert tests accounts -fund_zevm_from_config '.additional_accounts.user_v2_erc20_revert.evm_address' 10000 "V2 ERC20 revert tester" +fund_eth_from_config '.additional_accounts.user_v2_erc20_revert.evm_address' 10000 "V2 ERC20 revert tester" # unlock local solana relayer accounts if host solana > /dev/null; then