Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(e2e): add functions for funding zevm accounts instart-zetae2e.sh #2816

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 62 additions & 45 deletions contrib/localnet/orchestrator/start-zetae2e.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

# shellcheck disable=SC2317
swift1337 marked this conversation as resolved.
Show resolved Hide resolved

# 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:
Expand All @@ -24,6 +26,49 @@ get_zetacored_version() {
exit 1
}

# Reads unquoted string value from config by its path
# Usage: config_str <path>
config_str() {
yq -r "$1" config.yml
}

# Sends Ether to the given address on ZetaChain
# Usage: fund_zevm <address> <ether> [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 <config-key> <ether> [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..."
Expand All @@ -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"
swift1337 marked this conversation as resolved.
Show resolved Hide resolved

# 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
Expand Down
Loading