Skip to content

Commit

Permalink
Add bridge testing environment (#737)
Browse files Browse the repository at this point in the history
* add bridge testing environment

* change artifact directory to be inside tmp

* Check NodeJS version

* Check for go version
  • Loading branch information
ParthDesai authored Nov 4, 2024
1 parent 94b94cc commit c564220
Show file tree
Hide file tree
Showing 20 changed files with 1,045 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
**/.yarn
test/tsconfig.json

# Test data
tmp

# Spec/Wasm build directory
**/build/

Expand Down
68 changes: 68 additions & 0 deletions test/configs/zombieDancelightBridge.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"settings": {
"timeout": 1000,
"provider": "native"
},
"relaychain": {
"chain": "dancelight-local",
"default_command": "../target/release/tanssi-relay",
"default_args": [
"--no-hardware-benchmarks",
"-lparachain=debug",
"--database=paritydb",
"--enable-offchain-indexing true"
],
"genesis": {
"runtimeGenesis": {
"patch": {
"configuration": {
"config": {
"async_backing_params": {
"allowed_ancestry_len": 2,
"max_candidate_depth": 3
},
"scheduler_params": {
"scheduling_lookahead": 2,
"num_cores": 4
}
}
}
}
}
},
"nodes": [
{
"name": "alice",
"ws_port": "9947",
"validator": true
},
{
"name": "bob",
"validator": true
}
]
},
"parachains": [
{
"id": 2000,
"chain": "dev",
"collators": [
{
"name": "FullNode-2000",
"validator": false,
"command": "../target/release/container-chain-simple-node",
"args": ["--no-hardware-benchmarks", "--database=paritydb", "--wasmtime-precompiled=wasm"],
"ws_port": 9949,
"p2p_port": 33049
}
]
}
],
"types": {
"Header": {
"number": "u64",
"parent_hash": "Hash",
"post_state": "Hash"
}
}
}
21 changes: 21 additions & 0 deletions test/moonwall.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,27 @@
}
]
},
{
"name": "zombie_tanssi_relay_eth_bridge",
"timeout": 600000,
"envVars": ["RUST_BACKTRACE=1"],
"testFileDir": ["suites/zombie-tanssi-relay-eth-bridge"],
"runScripts": ["bridge-build-artifacts.sh"],
"foundation": {
"type": "zombie",
"zombieSpec": {
"configPath": "./configs/zombieDancelightBridge.json",
"skipBlockCheck": ["Tanssi-relay"]
}
},
"connections": [
{
"name": "Tanssi-relay",
"type": "polkadotJs",
"endpoints": ["ws://127.0.0.1:9947"]
}
]
},
{
"name": "zombie_data_preservers",
"testFileDir": ["suites/data-preservers"],
Expand Down
15 changes: 15 additions & 0 deletions test/scripts/bridge-build-artifacts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Exit on any error
set -e

bridge_scripts=$(realpath ./scripts/bridge)
source $bridge_scripts/set-env.sh

check_tool

# Install sszgen
GOBIN=$output_bin_dir go install github.com/ferranbt/fastssz/[email protected]

$bridge_scripts/build-ethereum-node.sh
$bridge_scripts/build-relayer.sh
26 changes: 26 additions & 0 deletions test/scripts/bridge/assets/beacon-relay.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"source": {
"beacon": {
"endpoint": "http://127.0.0.1:9596",
"stateEndpoint": "http://127.0.0.1:9596",
"spec": {
"syncCommitteeSize": 512,
"slotsInEpoch": 32,
"epochsPerSyncCommitteePeriod": 256,
"denebForkedEpoch": 0
},
"datastore": {
"location": "",
"maxEntries": 100
}
}
},
"sink": {
"parachain": {
"endpoint": "",
"maxWatchedExtrinsics": 8,
"headerRedundancy": 20
},
"updateSlotInterval": 30
}
}
19 changes: 19 additions & 0 deletions test/scripts/bridge/assets/beefy-relay.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"source": {
"polkadot": {
"endpoint": ""
},
"fast-forward-depth": 20,
"update-period": 0
},
"sink": {
"ethereum": {
"endpoint": "ws://127.0.0.1:8546",
"gas-limit": null
},
"descendants-until-final": 3,
"contracts": {
"BeefyClient": null
}
}
}
61 changes: 61 additions & 0 deletions test/scripts/bridge/assets/genesis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"config": {
"chainId": 11155111,
"homesteadBlock": 0,
"eip150Block": 0,
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"muirGlacierBlock": 0,
"berlinBlock": 0,
"londonBlock": 0,
"ethash": {},
"terminalTotalDifficulty": 0,
"ShanghaiTime": 0,
"CancunTime": null,
"terminalTotalDifficultyPassed": true
},
"difficulty": "0x9FFE0",
"gasLimit": "80000000",
"alloc": {
"90A987B944Cb1dCcE5564e5FDeCD7a54D3de27Fe": {
"balance": "10000000000000000000000"
},
"Be68fC2d8249eb60bfCf0e71D5A0d2F2e292c4eD": {
"balance": "100000000000000000000"
},
"89b4AB1eF20763630df9743ACF155865600daFF2": {
"balance": "100000000000000000000"
},
"04E00e6D2e9Ea1E2AF553De02A5172120BFA5c3e": {
"balance": "100000000000000000000"
},
"a255dC78C1510e2c1332fBAC2de848058f479CEE": {
"balance": "100000000000000000000"
},
"ACbd24742b87c34dED607FB87b22401B2Ede167E": {
"balance": "100000000000000000000"
},
"01F6749035e02205768f97e6f1d394Fb6769EC20": {
"balance": "100000000000000000000"
},
"8b66D5499F52D6F1857084A61743dFCB9a712859": {
"balance": "100000000000000000000"
},
"13e16C4e5787f878f98a610EB321170512b134D4": {
"balance": "100000000000000000000"
},
"eEBFA6B9242A19f91a0463291A937a20e3355681": {
"balance": "100000000000000000000"
},
"87D987206180B8f3807Dd90455606eEa85cdB87a": {
"balance": "100000000000000000000"
},
"0xACbd24742b87c34dED607FB87b22401B2Ede167E": {
"balance": "100000000000000000000"
}
}
}
1 change: 1 addition & 0 deletions test/scripts/bridge/assets/jwtsecret
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xdc6457099f127cf0bac78de8b297df04951281909db4f58b43def7c7151e765d
14 changes: 14 additions & 0 deletions test/scripts/bridge/build-eth-contracts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# Exit on any error
set -e

scripts_path="$(realpath ./scripts/bridge)"

source $scripts_path/set-env.sh

echo "Building contracts"

pushd $contract_dir
forge build
popd
60 changes: 60 additions & 0 deletions test/scripts/bridge/build-ethereum-node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

# Exit on any error
set -e

scripts_path="$(realpath ./scripts/bridge)"

source $scripts_path/set-env.sh

echo "Building lodestar Snowfork fork"


set_slot_time() {
local new_value=$1
echo "Hack lodestar for faster slot time"
local preset_mainnet_config_file="$artifacts_dir/lodestar/packages/config/src/chainConfig/configs/mainnet.ts"
if [[ "$(uname)" == "Darwin" && -z "${IN_NIX_SHELL:-}" ]]; then
gsed -i "s/SECONDS_PER_SLOT: .*/SECONDS_PER_SLOT: $new_value,/g" $preset_mainnet_config_file
else
sed -i "s/SECONDS_PER_SLOT: .*/SECONDS_PER_SLOT: $new_value,/g" $preset_mainnet_config_file
fi
}

echo "Downloading lodestar"

if [ -d "$lodestar_dir" ];
then
echo "Lodestar seems to be already downloaded. Skipping downloading again"
else
git clone https://github.com/ChainSafe/lodestar $lodestar_dir
pushd $lodestar_dir
git fetch && git checkout $LODESTAR_TAG
set_slot_time 1
popd
fi

echo "Building lodestar"
pushd $lodestar_dir
yarn install && yarn run build
popd


echo "Downloading geth"

if [ -d "$geth_dir" ];
then
echo "Geth seems to be already downloaded. Skipping downloading"
else
git clone https://github.com/ethereum/go-ethereum.git $geth_dir
pushd $geth_dir
git fetch && git checkout $GETH_TAG
popd
fi

echo "Building Geth"
pushd $geth_dir
GOBIN=$output_bin_dir go install ./cmd/geth
GOBIN=$output_bin_dir go install ./cmd/abigen
popd

35 changes: 35 additions & 0 deletions test/scripts/bridge/build-relayer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# Exit on any error
set -e

scripts_path="$(realpath ./scripts/bridge)"

source $scripts_path/set-env.sh

# Can be done independently put relayer binary in output directory

echo "Checkout Snowbridge relayer"

if [ -d "$relayer_root_dir" ];
then
echo "Relayer seems to be already setup. Skipping git fetch"
else
git clone https://github.com/Snowfork/snowbridge $relayer_root_dir
pushd $relayer_root_dir
git fetch && git checkout $RELAYER_TAG
popd
fi

$scripts_path/build-eth-contracts.sh

echo "Building Relayer"
pushd $relayer_root_dir
cd relayer && mage build
popd


pushd $test_helpers_dir
pnpm install node-gyp
pnpm install
popd
45 changes: 45 additions & 0 deletions test/scripts/bridge/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash

set -e

scripts_path="$(realpath ./scripts/bridge)"
source $scripts_path/set-env.sh

if [ -z "${1}" ]; then
echo "No arguments supplied. You can supply: o (removes output dir), ol (removes output and log dir), ole (removes output, log and ethereum_data dir), olep (removes output, log, ethereum_data dir and terminate any leftover processes)"
exit 1
fi

if [ $1 = "o" ]; then
rm -rf $output_dir
elif [ $1 = "ol" ]; then
rm -rf $logs_dir
rm -rf $output_dir
elif [ $1 = "ole" ]; then
rm -rf $logs_dir
rm -rf $output_dir
rm -rf $ethereum_data_dir
elif [ $1 = "olep" ]; then
rm -rf $logs_dir
rm -rf $output_dir
rm -rf $ethereum_data_dir

beacon_relay=""
beefy_relay=""

# Source daemons.pid if it exists
source $artifacts_dir/daemons.pid 2> /dev/null || true

# Using interrupt instead of kill signal for process to cleanup
kill -s INT $beacon_relay 2> /dev/null || true
kill -s INT $beefy_relay 2> /dev/null || true

# Brute force to remove other process spawned by lodestar and geth, if any
echo "Warning: Terminating any process containing lodestar or geth word in the full command line (executable + argument)"
pkill -f "lodestar"
pkill -f "geth"

# Always remove this to prevent us for terminating any other process for which the PID was reused
rm $artifacts_dir/daemons.pid 2> /dev/null || true
fi

Loading

0 comments on commit c564220

Please sign in to comment.