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

test(e2e): add testing for external chain migration #1900

Merged
merged 40 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
795da39
init
lumtis Mar 14, 2024
69946f5
add migration logic
lumtis Mar 15, 2024
a356637
go import
lumtis Mar 15, 2024
0f51980
test logic v1
lumtis Mar 15, 2024
22bc8fc
temporary utility to reset nonces
lumtis Mar 19, 2024
302ffe5
complete test with restart
lumtis Mar 19, 2024
ddb7845
hack for setting nonces
lumtis Mar 19, 2024
0388a30
use ganache
lumtis Mar 19, 2024
537ae68
manually produce blocks for e2e test
kingpinXD Mar 20, 2024
3bd7ac6
add erc20 withdraw with lower amount of 0.01
kingpinXD Mar 20, 2024
5ae0a4b
comment failing erc20 withdraw
kingpinXD Mar 20, 2024
0edb592
use new tx format
lumtis Mar 20, 2024
7d43613
conflict
lumtis Mar 20, 2024
b58d432
remove produce block
lumtis Mar 20, 2024
91f19c4
automatic block mining anvil
lumtis Mar 20, 2024
828939a
add Dockerfile for anvil localnet
lumtis Mar 20, 2024
fb2ad23
remove chain nonce hack
lumtis Mar 20, 2024
7886779
Reset chain nonces
skosito Mar 19, 2024
ffb532c
add the reset chain nonce message
lumtis Mar 20, 2024
b08692f
various fixes for Zeta
lumtis Mar 20, 2024
28533b6
make generage
lumtis Mar 20, 2024
f34ad21
remove reset message
lumtis Mar 22, 2024
43c747a
conflicts
lumtis Mar 22, 2024
42e8747
rename restart script files
lumtis Mar 25, 2024
e076288
add anvil docker image
lumtis Mar 25, 2024
75a89ac
add test erc20 whitelist
lumtis Mar 25, 2024
cbfa5f7
make lint
lumtis Mar 25, 2024
0f10ccb
fix comment
lumtis Mar 25, 2024
25ec0bc
fix some unit tests
kevinssgh Mar 25, 2024
911b99f
add tests back
lumtis Mar 25, 2024
d3beb31
update changeog
lumtis Mar 25, 2024
6a73711
Merge branch 'develop' into e2e-new-chain-support
lumtis Mar 26, 2024
11dbf72
remove bg
lumtis Mar 27, 2024
52e440b
conflicts
lumtis Apr 3, 2024
41f1386
revert back legacy tx
lumtis Apr 3, 2024
5d93e26
disable chain migration test
lumtis Apr 3, 2024
1af1b4f
fix test file
lumtis Apr 3, 2024
bd909a4
Merge branch 'develop' into e2e-new-chain-support
lumtis Apr 3, 2024
00ed796
move timeout check location
lumtis Apr 3, 2024
59325b2
Merge branch 'develop' into e2e-new-chain-support
lumtis Apr 4, 2024
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
9 changes: 0 additions & 9 deletions Dockerfile-localnet
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,12 @@ RUN ssh-keygen -b 2048 -t rsa -f /root/.ssh/localtest.pem -q -N ""
WORKDIR /go/delivery/zeta-node
COPY go.mod .
COPY go.sum .
#RUN --mount=type=cache,target=/root/.cache/go-build \
# go mod download
RUN go mod download
COPY . .

#RUN --mount=type=cache,target=/root/.cache/go-build \
# make install
#RUN --mount=type=cache,target=/root/.cache/go-build \
# make install-zetae2e
RUN make install
RUN make install-zetae2e
#
#FROM golang:1.20-alpine

#RUN apk --no-cache add openssh jq tmux vim curl bash
RUN ssh-keygen -A
WORKDIR /root

Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* [1805](https://github.com/zeta-chain/node/pull/1805) - add admin and performance test and fix upgrade test
* [1879](https://github.com/zeta-chain/node/pull/1879) - full coverage for messages in types packages
* [1899](https://github.com/zeta-chain/node/pull/1899) - add empty test files so packages are included in coverage
* [1900](https://github.com/zeta-chain/node/pull/1900) - add testing for external chain migration
* [1903](https://github.com/zeta-chain/node/pull/1903) - common package tests

### Fixes
Expand Down
5 changes: 3 additions & 2 deletions cmd/zetae2e/local/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ var (
UserMiscPrivateKey = "853c0945b8035a501b1161df65a17a0a20fc848bda8975a8b4e9222cc6f84cd4" // #nosec G101 - used for testing

// UserAdminAddress is the address of the account for testing admin function features
UserAdminAddress = ethcommon.HexToAddress("0xcC8487562AAc220ea4406196Ee902C7c076966af")
UserAdminPrivateKey = "95409f1f0e974871cc26ba98ffd31f613aa1287d40c0aea6a87475fc3521d083" // #nosec G101 - used for testing
// NOTE: this is the default account using Anvil
UserAdminAddress = ethcommon.HexToAddress("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266")
UserAdminPrivateKey = "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" // #nosec G101 - used for testing

FungibleAdminMnemonic = "snow grace federal cupboard arrive fancy gym lady uniform rotate exercise either leave alien grass" // #nosec G101 - used for testing
)
5 changes: 3 additions & 2 deletions cmd/zetae2e/local/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func adminTestRoutine(
deployerRunner,
UserAdminAddress,
UserAdminPrivateKey,
runner.NewLogger(verbose, color.FgGreen, "admin"),
runner.NewLogger(verbose, color.FgHiGreen, "admin"),
)
if err != nil {
return err
Expand All @@ -48,7 +48,8 @@ func adminTestRoutine(
startTime := time.Now()

// funding the account
txZetaSend := deployerRunner.SendZetaOnEvm(UserAdminAddress, 1000)
// 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)
adminRunner.WaitForTxReceiptOnEvm(txZetaSend)
adminRunner.WaitForTxReceiptOnEvm(txERC20Send)
Expand Down
3 changes: 2 additions & 1 deletion cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
if !skipSetup {
logger.Print("⚙️ setting up networks")
startTime := time.Now()
deployerRunner.SetupEVM(contractsDeployed)
deployerRunner.SetupEVM(contractsDeployed, true)
deployerRunner.SetZEVMContracts()

// NOTE: this method return an error so we handle it and panic if it occurs unlike other method that panics directly
Expand Down Expand Up @@ -285,6 +285,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
e2etests.TestPauseZRC20Name,
e2etests.TestUpdateBytecodeName,
e2etests.TestDepositEtherLiquidityCapName,
e2etests.TestMigrateChainSupportName,
))
}
if testPerformance {
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetae2e/stress.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func StressTest(cmd *cobra.Command, _ []string) {
panic(err)
}

e2eTest.SetupEVM(stressTestArgs.contractsDeployed)
e2eTest.SetupEVM(stressTestArgs.contractsDeployed, true)

// If stress test is running on local docker environment
if stressTestArgs.network == "LOCAL" {
Expand Down
11 changes: 11 additions & 0 deletions contrib/localnet/anvil/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This Dockerfile is used to build a Docker image for Anvil, a localnet for testing purposes.
# Currently we directly set the chain ID to 11155111 and expose the default Anvil port specifically for the chain migration test.

# Start from the latest Rust image as Anvil is built with Rust
FROM ghcr.io/foundry-rs/foundry:latest

# Expose the default Anvil port
EXPOSE 8545

# Run Anvil with specified chain ID and a prefunded account when the container starts
ENTRYPOINT ["anvil", "--host", "0.0.0.0", "--chain-id", "11155111"]
17 changes: 17 additions & 0 deletions contrib/localnet/docker-compose-admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,25 @@ version: "3"

# This docker-compose file overrides the orchestrator service to specify the flag to test the admin functions
# and skip the regular tests
# it also adds another local Ethereum network to test EVM chain migration and use the additional-evm flag

services:
orchestrator:
entrypoint: ["/work/start-zetae2e.sh", "local --skip-regular --test-admin"]

eth2:
build:
context: ./anvil
container_name: eth2
hostname: eth2
ports:
- "8546:8545"
networks:
mynetwork:
ipv4_address: 172.20.0.102

zetaclient0:
entrypoint: [ "/root/start-zetaclientd.sh", "additional-evm" ]

zetaclient1:
entrypoint: [ "/root/start-zetaclientd.sh", "additional-evm" ]
1 change: 1 addition & 0 deletions contrib/localnet/orchestrator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ COPY --from=zeta /root/.ssh/localtest.pem /root/.ssh/localtest.pem

COPY contrib/localnet/orchestrator/start-zetae2e.sh /work/
COPY contrib/localnet/orchestrator/restart-zetaclientd.sh /work/
COPY contrib/localnet/orchestrator/restart-zetaclientd-at-upgrade.sh /work/
RUN chmod +x /work/*.sh

ENV GOPATH /go
Expand Down
1 change: 1 addition & 0 deletions contrib/localnet/orchestrator/Dockerfile.fastbuild
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ COPY --from=zeta /root/.ssh/localtest.pem /root/.ssh/localtest.pem

COPY contrib/localnet/orchestrator/start-zetae2e.sh /work/
COPY contrib/localnet/orchestrator/restart-zetaclientd.sh /work/
COPY contrib/localnet/orchestrator/restart-zetaclientd-at-upgrade.sh /work/
RUN chmod +x /work/*.sh

COPY --from=zeta /usr/local/bin/zetae2e /usr/local/bin/
Expand Down
50 changes: 50 additions & 0 deletions contrib/localnet/orchestrator/restart-zetaclientd-at-upgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

# This script is used to restart zetaclientd after an upgrade
# It waits for the upgrade height to be reached and then restarts the zetaclientd on all nodes in the network
# It interacts with the network using the zetaclientd binary

clibuilder()
{
echo ""
echo "Usage: $0 -u UPGRADE_HEIGHT"
echo -e "\t-u Height of upgrade, should match governance proposal"
echo -e "\t-n Number of clients in the network"
exit 1 # Exit script after printing help
}

while getopts "u:n:" opt
do
case "$opt" in
u ) UPGRADE_HEIGHT="$OPTARG" ;;
n ) NUM_OF_NODES="$OPTARG" ;;
? ) clibuilder ;; # Print cliBuilder in case parameter is non-existent
esac
done

# generate client list
START=0
END=$((NUM_OF_NODES-1))
CLIENT_LIST=()
for i in $(eval echo "{$START..$END}")
do
CLIENT_LIST+=("zetaclient$i")
done

echo "$UPGRADE_HEIGHT"

CURRENT_HEIGHT=0

while [[ $CURRENT_HEIGHT -lt $UPGRADE_HEIGHT ]]
do
CURRENT_HEIGHT=$(curl -s zetacore0:26657/status | jq '.result.sync_info.latest_block_height' | tr -d '"')
echo current height is "$CURRENT_HEIGHT", waiting for "$UPGRADE_HEIGHT"
sleep 5
done

echo upgrade height reached, restarting zetaclients

for NODE in "${CLIENT_LIST[@]}"; do
ssh -o "StrictHostKeyChecking no" "$NODE" -i ~/.ssh/localtest.pem killall zetaclientd
ssh -o "StrictHostKeyChecking no" "$NODE" -i ~/.ssh/localtest.pem "$GOPATH/bin/new/zetaclientd start < /root/password.file > $HOME/zetaclient.log 2>&1 &"
done
51 changes: 6 additions & 45 deletions contrib/localnet/orchestrator/restart-zetaclientd.sh
Original file line number Diff line number Diff line change
@@ -1,50 +1,11 @@
#!/bin/bash

# This script is used to restart zetaclientd after an upgrade
# It waits for the upgrade height to be reached and then restarts the zetaclientd on all nodes in the network
# It interacts with the network using the zetaclientd binary
# This script immediately restarts the zetaclientd on zetaclient0 and zetaclient1 containers in the network

clibuilder()
{
echo ""
echo "Usage: $0 -u UPGRADE_HEIGHT"
echo -e "\t-u Height of upgrade, should match governance proposal"
echo -e "\t-n Number of clients in the network"
exit 1 # Exit script after printing help
}
echo restarting zetaclients

while getopts "u:n:" opt
do
case "$opt" in
u ) UPGRADE_HEIGHT="$OPTARG" ;;
n ) NUM_OF_NODES="$OPTARG" ;;
? ) clibuilder ;; # Print cliBuilder in case parameter is non-existent
esac
done
ssh -o "StrictHostKeyChecking no" "zetaclient0" -i ~/.ssh/localtest.pem killall zetaclientd
ssh -o "StrictHostKeyChecking no" "zetaclient1" -i ~/.ssh/localtest.pem killall zetaclientd
ssh -o "StrictHostKeyChecking no" "zetaclient0" -i ~/.ssh/localtest.pem "/usr/local/bin/zetaclientd start < /root/password.file > $HOME/zetaclient.log 2>&1 &"
ssh -o "StrictHostKeyChecking no" "zetaclient1" -i ~/.ssh/localtest.pem "/usr/local/bin/zetaclientd start < /root/password.file > $HOME/zetaclient.log 2>&1 &"

# generate client list
START=0
END=$((NUM_OF_NODES-1))
CLIENT_LIST=()
for i in $(eval echo "{$START..$END}")
do
CLIENT_LIST+=("zetaclient$i")
done

echo "$UPGRADE_HEIGHT"

CURRENT_HEIGHT=0

while [[ $CURRENT_HEIGHT -lt $UPGRADE_HEIGHT ]]
do
CURRENT_HEIGHT=$(curl -s zetacore0:26657/status | jq '.result.sync_info.latest_block_height' | tr -d '"')
echo current height is "$CURRENT_HEIGHT", waiting for "$UPGRADE_HEIGHT"
sleep 5
done

echo upgrade height reached, restarting zetaclients

for NODE in "${CLIENT_LIST[@]}"; do
ssh -o "StrictHostKeyChecking no" "$NODE" -i ~/.ssh/localtest.pem killall zetaclientd
ssh -o "StrictHostKeyChecking no" "$NODE" -i ~/.ssh/localtest.pem "$GOPATH/bin/new/zetaclientd start < /root/password.file > $HOME/zetaclient.log 2>&1 &"
done
8 changes: 4 additions & 4 deletions contrib/localnet/orchestrator/start-zetae2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0x8D47Db7390AC4D3D449
echo "funding deployer address 0x90126d02E41c9eB2a10cfc43aAb3BD3460523Cdf with 100 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0x90126d02E41c9eB2a10cfc43aAb3BD3460523Cdf", value: web3.toWei(100,"ether")})' attach http://eth:8545

# unlock advanced erc20 tests accounts
echo "funding deployer address 0xcC8487562AAc220ea4406196Ee902C7c076966af with 100 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0xcC8487562AAc220ea4406196Ee902C7c076966af", value: web3.toWei(100,"ether")})' attach http://eth:8545
# unlock admin erc20 tests accounts
echo "funding deployer address 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 with 100 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", value: web3.toWei(100,"ether")})' attach http://eth:8545

# unlock the TSS account
echo "funding TSS address 0xF421292cb0d3c97b90EEEADfcD660B893592c6A2 with 100 Ether"
Expand Down Expand Up @@ -74,7 +74,7 @@ if [ "$OPTION" == "upgrade" ]; then
echo "E2E setup passed, waiting for upgrade height..."

# Restart zetaclients at upgrade height
/work/restart-zetaclientd.sh -u "$UPGRADE_HEIGHT" -n 2
/work/restart-zetaclientd-at-upgrade.sh -u "$UPGRADE_HEIGHT" -n 2

echo "waiting 10 seconds for node to restart..."

Expand Down
28 changes: 25 additions & 3 deletions contrib/localnet/scripts/start-zetaclientd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
HOSTNAME=$(hostname)
OPTION=$1

# sepolia is used in chain migration tests, this functions set the sepolia endpoint in the zetaclient_config.json
set_sepolia_endpoint() {
jq '.EVMChainConfigs."11155111".Endpoint = "http://eth2:8545"' /root/.zetacored/config/zetaclient_config.json > tmp.json && mv tmp.json /root/.zetacored/config/zetaclient_config.json
}

# read HOTKEY_BACKEND env var for hotkey keyring backend and set default to test
BACKEND="test"
if [ "$HOTKEY_BACKEND" == "file" ]; then
Expand All @@ -30,6 +35,14 @@ then
rm ~/.tss/*
MYIP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
zetaclientd init --zetacore-url zetacore0 --chain-id athens_101-1 --operator "$operatorAddress" --log-format=text --public-ip "$MYIP" --keyring-backend "$BACKEND"

# check if the option is additional-evm
# in this case, the additional evm is represented with the sepolia chain, we set manually the eth2 endpoint to the sepolia chain (11155111 -> http://eth2:8545)
# in /root/.zetacored/config/zetaclient_config.json
if [ "$OPTION" == "additional-evm" ]; then
set_sepolia_endpoint
fi

zetaclientd start < /root/password.file
else
num=$(echo $HOSTNAME | tr -dc '0-9')
Expand All @@ -42,11 +55,20 @@ else
done
rm ~/.tss/*
zetaclientd init --peer /ip4/172.20.0.21/tcp/6668/p2p/"$SEED" --zetacore-url "$node" --chain-id athens_101-1 --operator "$operatorAddress" --log-format=text --public-ip "$MYIP" --log-level 1 --keyring-backend "$BACKEND"

# check if the option is additional-evm
# in this case, the additional evm is represented with the sepolia chain, we set manually the eth2 endpoint to the sepolia chain (11155111 -> http://eth2:8545)
# in /root/.zetacored/config/zetaclient_config.json
if [ "$OPTION" == "additional-evm" ]; then
set_sepolia_endpoint
fi

zetaclientd start < /root/password.file
fi

if [ "$OPTION" == "background" ]; then
# check if the option is background
# in this case, we tail the zetaclientd log file
#if [ "$OPTION" == "background" ]; then
lumtis marked this conversation as resolved.
Show resolved Hide resolved
sleep 3
tail -f $HOME/zetaclient.log
fi

#fi
1 change: 0 additions & 1 deletion docs/spec/observer/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ message MsgAddBlockHeader {
## MsgResetChainNonces

ResetChainNonces handles resetting chain nonces
Authorized: admin policy group 2 (admin update)

```proto
message MsgResetChainNonces {
Expand Down
17 changes: 13 additions & 4 deletions e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ const (
TestCrosschainSwapName = "crosschain_swap"
TestMessagePassingRevertFailName = "message_passing_revert_fail"
TestMessagePassingRevertSuccessName = "message_passing_revert_success"
TestPauseZRC20Name = "pause_zrc20"
TestERC20DepositAndCallRefundName = "erc20_deposit_and_call_refund"
TestUpdateBytecodeName = "update_bytecode"
TestEtherDepositAndCallName = "eth_deposit_and_call"
TestDepositEtherLiquidityCapName = "deposit_eth_liquidity_cap"
TestMyTestName = "my_test"

TestERC20WithdrawName = "erc20_withdraw"
TestERC20DepositName = "erc20_deposit"
// #nosec G101: Potential hardcoded credentials (gosec), not a credential
TestERC20DepositRestrictedName = "erc20_deposit_restricted"

TestERC20DepositRestrictedName = "erc20_deposit_restricted" // #nosec G101: Potential hardcoded credentials (gosec), not a credential
TestEtherDepositName = "eth_deposit"
TestEtherWithdrawName = "eth_withdraw"
TestEtherWithdrawRestrictedName = "eth_withdraw_restricted"
Expand All @@ -45,6 +43,11 @@ const (
TestStressBTCWithdrawName = "stress_btc_withdraw"
TestStressEtherDepositName = "stress_eth_deposit"
TestStressBTCDepositName = "stress_btc_deposit"

// Admin test
TestMigrateChainSupportName = "migrate_chain_support"
TestPauseZRC20Name = "pause_zrc20"
TestUpdateBytecodeName = "update_bytecode"
)

// AllE2ETests is an ordered list of all e2e tests
Expand Down Expand Up @@ -315,4 +318,10 @@ var AllE2ETests = []runner.E2ETest{
},
TestBitcoinWithdrawRestricted,
),
runner.NewE2ETest(
TestMigrateChainSupportName,
"migrate the evm chain from goerli to sepolia",
[]runner.ArgDefinition{},
TestMigrateChainSupport,
),
}
4 changes: 4 additions & 0 deletions e2e/e2etests/test_eth_withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (

// TestEtherWithdraw tests the withdraw of ether
func TestEtherWithdraw(r *runner.E2ERunner, args []string) {
r.Logger.Info("TestEtherWithdraw")

approvedAmount := big.NewInt(1e18)
if len(args) != 1 {
panic("TestEtherWithdraw requires exactly one argument for the withdrawal amount.")
Expand Down Expand Up @@ -59,6 +61,8 @@ func TestEtherWithdraw(r *runner.E2ERunner, args []string) {
if cctx.CctxStatus.Status != crosschaintypes.CctxStatus_OutboundMined {
panic("cctx status is not outbound mined")
}

r.Logger.Info("TestEtherWithdraw completed")
}

// TestEtherWithdrawRestricted tests the withdrawal to a restricted receiver address
Expand Down
Loading
Loading