-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scripts to run relays in testnets
- Loading branch information
Showing
12 changed files
with
320 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/usr/bin/env bash | ||
|
||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
|
||
# Exit script as soon as a command fails. | ||
set -o errexit | ||
|
||
# Executes cleanup function at script exit. | ||
trap cleanup EXIT | ||
|
||
waitport() { | ||
while ! nc -z localhost $1 ; do sleep 1 ; done | ||
} | ||
|
||
cleanup() { | ||
# Kill the nearnode instance that we started (if we started one and if it's still running). | ||
if [ -n "$node_started" ]; then | ||
docker kill nearcore watchtower > /dev/null & | ||
fi | ||
|
||
# Kill the ganache instance that we started (if we started one and if it's still running). | ||
if [ -n "$ganache_pid" ] && ps -p $ganache_pid > /dev/null; then | ||
kill $ganache_pid | ||
fi | ||
} | ||
|
||
nearnode_port=24567 | ||
|
||
nearnode_running() { | ||
nc -z localhost "$nearnode_port" | ||
} | ||
|
||
start_nearnode() { | ||
echo "ethrelay" | "$DIR/start_localnet.py" --home "$DIR/.near" --image "nearprotocol/nearcore:ethdenver" | ||
waitport $nearnode_port | ||
} | ||
|
||
if nearnode_running; then | ||
echo "Using existing nearnode instance" | ||
else | ||
echo "Starting our own nearnode instance" | ||
rm -rf "$DIR/.near" | ||
start_nearnode | ||
node_started=1 | ||
fi | ||
|
||
ganache_port=9545 | ||
|
||
ganache_running() { | ||
nc -z localhost "$ganache_port" | ||
} | ||
|
||
start_ganache() { | ||
local accounts=( | ||
--account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501200,1000000000000000000000000" | ||
--account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501201,1000000000000000000000000" | ||
--account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501202,1000000000000000000000000" | ||
--account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501203,1000000000000000000000000" | ||
--account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501204,1000000000000000000000000" | ||
--account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501205,1000000000000000000000000" | ||
--account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501206,1000000000000000000000000" | ||
--account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501207,1000000000000000000000000" | ||
--account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501208,1000000000000000000000000" | ||
--account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501209,1000000000000000000000000" | ||
) | ||
|
||
yarn run ganache-cli --blockTime 12 --gasLimit 10000000 -p "$ganache_port" "${accounts[@]}" > /dev/null & | ||
ganache_pid=$! | ||
waitport $ganache_port | ||
} | ||
|
||
if ganache_running; then | ||
echo "Using existing ganache instance" | ||
else | ||
echo "Starting our own ganache instance" | ||
start_ganache | ||
fi | ||
|
||
NODE_URL="http://localhost:3030" | ||
|
||
echo "Creating account for smart contract:" | ||
NODE_ENV=local yarn run near --nodeUrl=$NODE_URL --homeDir "$DIR/.near" --keyPath "$DIR/.near/validator_key.json" create_account ethbridge --masterAccount=ethrelay --initialBalance 100000000 || echo "Skip creating ethbridge accout" | ||
echo "Deploying smart contract:" | ||
NODE_ENV=local yarn run near --nodeUrl=$NODE_URL --homeDir "$DIR/.near" --keyPath "$DIR/.near/validator_key.json" deploy --contractName ethbridge --wasmFile "$DIR/../../ethbridge/res/eth_bridge.wasm" || echo "Skip deploying ethbridge smart contract" | ||
|
||
NEAR_NODE_URL="http://localhost:3030" \ | ||
NEAR_NODE_NETWORK_ID=local \ | ||
ETHEREUM_NODE_URL="ws://localhost:$ganache_port" \ | ||
node "$DIR/../index.js" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Exit script as soon as a command fails. | ||
set -o errexit | ||
|
||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
NODE_URL="https://rpc.nearprotocol.com" | ||
|
||
echo "Creating account for smart contract:" | ||
NODE_ENV=local yarn run near --nodeUrl=$NODE_URL --homeDir "$DIR/.near" --keyPath "$DIR/.near/validator_key.json" create_account ethbridge --masterAccount=ethrelay --initialBalance 100000000 || echo "Skip creating ethbridge accout" | ||
echo "Deploying smart contract:" | ||
NODE_ENV=local yarn run near --nodeUrl=$NODE_URL --homeDir "$DIR/.near" --keyPath "$DIR/.near/validator_key.json" deploy --contractName ethbridge --wasmFile "$DIR/../../ethbridge/res/eth_bridge.wasm" || echo "Skip deploying ethbridge smart contract" | ||
|
||
# Successfully stop after 5m | ||
{ sleep 5m && kill -l 0 $$ && echo "Successfully worked for 5m, stopped" } & | ||
|
||
# Launch EthRelay | ||
NEAR_NODE_URL="https://rpc.nearprotocol.com" \ | ||
NEAR_NODE_NETWORK_ID=local \ | ||
ETHEREUM_NODE_URL="wss://ropsten.infura.io/ws/v3/b5f870422ee5454fb11937e947154cd2" \ | ||
node "$DIR/../index.js" |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.