Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Fix: e2e setup for goerli network & Refactor: move initialization to …
Browse files Browse the repository at this point in the history
…nix hook (paritytech#777)

* Refactor: move to initialize hook & some cleanup

* Fix husky

* Update foundry libs with submodule

* env for goerli

* Fix for production deployment

* Suppress error temporarily when init BeefyClient for
foundry-rs/foundry#3880

* More refactor for comments

* For goerli e2e setup

* Fix: for both local&goerli setup

* More fixes

* Fix for comments

* Cleanup

* Improve e2e scripts

* Fix for comments
  • Loading branch information
yrong authored Feb 24, 2023
1 parent 0a44cf4 commit 44e8864
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 1,756 deletions.
10 changes: 10 additions & 0 deletions core/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

echo "Hack SLOTS_IN_EPOCH in lodestar"
(cd packages/test && ./scripts/hack-ethereum.sh)

echo "Install husky hook"
(cd .. && ./core/node_modules/.bin/husky install)

echo "Initialize foundry libraries"
(cd packages/contracts && (forge install||true))
4 changes: 2 additions & 2 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"name": "@snowbridge/core",
"private": true,
"engines": {
"node": "v18.13.0",
"node": "v18.12.1",
"pnpm": "7.14.2"
},
"scripts": {
"preinstall": "npx only-allow pnpm",
"postinstall": "cd .. && husky install && cd core/packages/test && ./scripts/hack-ethereum.sh",
"postinstall": "./init.sh",
"build": "turbo run build",
"test": "turbo run test",
"lint": "turbo run lint",
Expand Down
9 changes: 5 additions & 4 deletions core/packages/contracts/.envrc-example
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
source_up_if_exists

export PRIVATE_KEY=0x4e9444a6efd6d42725a250b650a781da2737ea308c839eaccb0f7f3dbd2fea77
export RANDAO_COMMIT_DELAY=3
export RANDAO_COMMIT_EXP=8
export PARAID=1000
## Config only for foundry test
# export PRIVATE_KEY=0x4e9444a6efd6d42725a250b650a781da2737ea308c839eaccb0f7f3dbd2fea77
# export RANDAO_COMMIT_DELAY=3
# export RANDAO_COMMIT_EXP=8
# export PARAID=1000
1 change: 0 additions & 1 deletion core/packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"seedrandom": "^3.0.5",
"solc": "^0.7.6",
"solhint": "^3.3.7",
"solidity-bytes-utils": "^0.1.2",
"solidity-coverage": "^0.8.2",
"solidity-docgen": "^0.5.10",
"temp": "^0.9.1",
Expand Down
3 changes: 2 additions & 1 deletion core/packages/contracts/scripts/generateContractInfo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require("fs");
const path = require("path");
const DeployInfoFile = "./broadcast/Deploy.sol/15/run-latest.json";
const NetworkId = process.env.ETH_NETWORK_ID || 15;
const DeployInfoFile = `./broadcast/Deploy.sol/${NetworkId}/run-latest.json`;
const BuildInfoDir = "./out";
const DestFile =
process.argv.length >= 3 ? process.argv[2] : "/tmp/snowbridge/contracts.json";
Expand Down
17 changes: 9 additions & 8 deletions core/packages/test/.envrc-example
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ source_up_if_exists
# export POLKADOT_BIN= # Relaychain binary, default value: $POLKADOT_DIR/target/release/polkadot
# export BEEFY_START_BLOCK= # Start block to configure beefy client, default value: 15
# export RELAYCHAIN_ENDPOINT= # Relaychain endpoint, default value: ws://localhost:9944
# export PARACHAIN_RUNTIME= # Runtime type of parachain should be one of snowbase|snowblink|snowbridge

## Run E2E on Ropsten
## Run E2E on Goerli

# export INFURA_PROJECT_ID= # Your Infura project id
# export ETH_NETWORK=ropsten
# export ETH_NETWORK_ID=3
# export ETH_NETWORK=goerli
# export ETH_NETWORK_ID=5

# export ETH_RPC_ENDPOINT=https://ropsten.infura.io/v3
# export ETH_WS_ENDPOINT=wss://ropsten.infura.io/ws/v3
# export ETH_RPC_ENDPOINT=https://goerli.infura.io/v3
# export ETH_WS_ENDPOINT=wss://goerli.infura.io/ws/v3
# export BEACON_HTTP_ENDPOINT=https://lodestar-goerli.chainsafe.io
# export ETH_GAS_LIMIT=0 # For real network just uncomment and set as 0 here

# export BEACON_HTTP_ENDPOINT=https://lodestar-ropsten.chainsafe.io

# export ROPSTEN_PRIVATE_KEY= # Your deployment account private key
# export DEPLOYER_ETH_KEY= # Your private key to deploy contracts
# export BEEFY_RELAY_ETH_KEY= # Your Beefy relayer account private key
# export PARACHAIN_RELAY_ETH_KEY= # Your Parachain relayer account private key
# export E2E_TEST_ETH_KEY= # Your E2E test account private key
2 changes: 1 addition & 1 deletion core/packages/test/config/beefy-relay.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"sink": {
"ethereum": {
"endpoint": "ws://127.0.0.1:8546",
"gas-limit": 5000000
"gas-limit": null
},
"start-block": 0,
"descendants-until-final": 3,
Expand Down
144 changes: 0 additions & 144 deletions core/packages/test/config/launch-config.json

This file was deleted.

48 changes: 24 additions & 24 deletions core/packages/test/config/parachain-relay.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"source": {
"ethereum": {
"endpoint": "ws://127.0.0.1:8546"
},
"polkadot": {
"endpoint": "ws://127.0.0.1:9944"
},
"parachain": {
"endpoint": "ws://127.0.0.1:11144"
},
"contracts": {
"BeefyClient": null,
"BasicInboundChannel": null
},
"beefy-activation-block": 0,
"basicChannelSourceIDs": []
"source": {
"ethereum": {
"endpoint": "ws://127.0.0.1:8546"
},
"sink": {
"ethereum": {
"endpoint": "ws://127.0.0.1:8546",
"gas-limit": 5000000
},
"contracts": {
"BasicInboundChannel": null
}
"polkadot": {
"endpoint": "ws://127.0.0.1:9944"
},
"parachain": {
"endpoint": "ws://127.0.0.1:11144"
},
"contracts": {
"BeefyClient": null,
"BasicInboundChannel": null
},
"beefy-activation-block": 0,
"basicChannelSourceIDs": []
},
"sink": {
"ethereum": {
"endpoint": "ws://127.0.0.1:8546",
"gas-limit": null
},
"contracts": {
"BasicInboundChannel": null
}
}
}
24 changes: 7 additions & 17 deletions core/packages/test/scripts/build-binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,17 @@ build_relaychain() {

rebuild_relaychain(){
pushd $parachain_dir
mkdir -p $relaychain_dir
cargo install \
--git https://github.com/paritytech/polkadot \
--tag "$relaychain_version" polkadot \
--locked \
--root .cargo
mkdir -p "$(dirname "$relaychain_bin")"
cp "$parachain_dir"/.cargo/bin/polkadot "$relaychain_bin" || true
--root $relaychain_dir #add version path to root to avoid recompiling when switch between versions
popd
}

build_parachain()
{
if [ "$eth_network" != "localhost" ]; then
parachain_runtime="snowblink"
fi

echo "Runtime is $parachain_runtime"

echo "Building snowbridge parachain"
Expand Down Expand Up @@ -66,19 +61,14 @@ build_relayer()
cp $relay_bin "$output_bin_dir"
}

build_e2e_test() {
echo "Building tests"
pushd "$core_dir"
pnpm install
popd
pushd "$contract_dir"
popd
}

install_binary() {
echo "Building and installing binaries."
build_relaychain
build_parachain
build_relayer
build_e2e_test
}

if [ -z "${from_start_services:-}" ]; then
echo "build binaries only!"
install_binary
fi
8 changes: 6 additions & 2 deletions core/packages/test/scripts/configure-contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ configure_contracts()
current_root=$(sed -e 's/^"//' -e 's/"$//' <<< $current_root)
next_root=$(sed -e 's/^"//' -e 's/"$//' <<< $next_root)

echo "Transact call to initialize BeefyClient"
# sometimes sending transact with cast will fail on the goerli network
# temporarily resolved by manually setting --gas-price and --gas-limit
cast send $(address_for BeefyClient) \
"initialize(uint64,(uint128,uint128,bytes32),(uint128,uint128,bytes32))" \
--rpc-url $eth_endpoint_http \
--private-key $PRIVATE_KEY \
$beefy_start_block \($current_id,$current_length,$current_root\) \($next_id,$next_length,$next_root\)

$beefy_start_block \
\($current_id,$current_length,$current_root\) \
\($next_id,$next_length,$next_root\) || true # "|| true" can be removed once https://github.com/foundry-rs/foundry/pull/4010 has been released
popd
}

Expand Down
6 changes: 3 additions & 3 deletions core/packages/test/scripts/deploy-ethereum.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ start_geth() {
--authrpc.jwtsecret config/jwtsecret \
--unlock 0xBe68fC2d8249eb60bfCf0e71D5A0d2F2e292c4eD,0x89b4AB1eF20763630df9743ACF155865600daFF2 \
--password /dev/null \
--rpc.gascap 100000000 \
--rpc.gascap 0 \
--ws.origins "*" \
--trace "$ethereum_data_dir/trace" \
--gcmode archive \
--miner.gasprice=0 \
--syncmode=full \
> "$output_dir/geth.log" 2>&1 &
fi
Expand Down Expand Up @@ -63,7 +62,8 @@ start_lodestar() {
deploy_contracts()
{
pushd "$contract_dir"
forge script --rpc-url $eth_endpoint_http contracts/deploy/foundry/Deploy.sol:DeployScript --broadcast -vvv
forge script --rpc-url $eth_endpoint_http contracts/deploy/foundry/Deploy.sol:DeployScript \
--broadcast -vvv || true # "|| true" can be removed once https://github.com/foundry-rs/foundry/pull/4010 has been released
node scripts/generateContractInfo.js "$output_dir/contracts.json"
popd
echo "Exported contract artifacts: $output_dir/contracts.json"
Expand Down
Loading

0 comments on commit 44e8864

Please sign in to comment.