diff --git a/.travis.yml b/.travis.yml index 2e5865241..c133a8639 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,9 +9,11 @@ node_js: - '10' env: - ETHBRIDGE=1 + - ETHRELAY=1 - NEARBRIDGE=1 - NEARBRIDGE_LINT=1 - NEARBRIDGE_COVERAGE=1 + - NEARRELAY=1 script: - if [ $ETHBRIDGE == "1" ]; then cd ./ethbridge; @@ -21,6 +23,18 @@ script: rustup target add wasm32-unknown-unknown --toolchain stable; ./test.sh; fi + - if [ $ETHRELAY == "1" ]; then + cd ./ethbridge; + sh <(curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs) -y && export PATH=$PATH:~/.cargo/bin; + rustup toolchain install stable; + rustup default stable; + rustup target add wasm32-unknown-unknown --toolchain stable; + ./build.sh; + cd ../ethrelay/ethashproof; + ./build.sh; + cd ..; + yarn && yarn run test; + fi - if [ $NEARBRIDGE == "1" ]; then cd ./nearbridge; yarn; @@ -37,3 +51,13 @@ script: yarn; yarn run coverage && cat coverage/lcov.info | coveralls; fi + - if [ $NEARRELAY == "1" ]; then + cd ./ethbridge; + sh <(curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs) -y && export PATH=$PATH:~/.cargo/bin; + rustup toolchain install stable; + rustup default stable; + rustup target add wasm32-unknown-unknown --toolchain stable; + ./build.sh; + cd ../nearrelay; + yarn && yarn run test; + fi diff --git a/ethrelay/index.js b/ethrelay/index.js index 49d291594..1a2fdae3b 100644 --- a/ethrelay/index.js +++ b/ethrelay/index.js @@ -37,15 +37,6 @@ function subscribeOnBlocksRangesFrom(web3, block_number, handler) { }); } -function arrayPrefixU32Length(array) { - return [ - Math.trunc(array.length) % 256, - Math.trunc(array.length / 256) % 256, - Math.trunc(array.length / 256 / 256) % 256, - Math.trunc(array.length / 256 / 256 / 256) % 256, - ].concat(...array); -} - const hexToBuffer = (hex) => Buffer.from(Web3.utils.hexToBytes(hex)); const readerToHex = (len) => (reader) => Web3.utils.bytesToHex(reader.read_fixed_array(len)); @@ -341,16 +332,15 @@ class EthBridgeContract extends Contract { (async function () { - const web3 = new Web3("wss://mainnet.infura.io/ws/v3/b5f870422ee5454fb11937e947154cd2"); + const web3 = new Web3(process.env.ETHEREUM_NODE_URL); const near = await nearlib.connect({ - nodeUrl: 'http://localhost:3030', //'https://rpc.nearprotocol.com', - networkId: 'local', // TODO: detect automatically + nodeUrl: process.env.NEAR_NODE_URL, // 'https://rpc.nearprotocol.com', + networkId: process.env.NEAR_NODE_NETWORK_ID, // TODO: detect automatically deps: { keyStore: new nearlib.keyStores.UnencryptedFileSystemKeyStore(__dirname + '/neardev') } }); - const account = new nearlib.Account(near.connection, 'ethbridge'); const ethBridgeContract = new EthBridgeContract(account, 'ethbridge'); diff --git a/ethrelay/package.json b/ethrelay/package.json index c55e35aee..a0e9a4d6f 100644 --- a/ethrelay/package.json +++ b/ethrelay/package.json @@ -4,13 +4,15 @@ "description": "Ethereum >> Near relay", "main": "index.js", "scripts": { - "start": "scripts/start.sh" + "test": "scripts/run_localnet.sh", + "start": "scripts/run_testnet.sh" }, "author": "", "license": "MIT", "dependencies": { "near-shell": "^0.20.1", "nearlib": "^0.21.0", + "ganache-cli": "^6.9.0", "web3": "^1.2.4" } } diff --git a/ethrelay/scripts/run_localnet.sh b/ethrelay/scripts/run_localnet.sh new file mode 100755 index 000000000..0409709b3 --- /dev/null +++ b/ethrelay/scripts/run_localnet.sh @@ -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" diff --git a/ethrelay/scripts/run_testnet.sh b/ethrelay/scripts/run_testnet.sh new file mode 100755 index 000000000..1fbeaa753 --- /dev/null +++ b/ethrelay/scripts/run_testnet.sh @@ -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" diff --git a/ethrelay/scripts/start.sh b/ethrelay/scripts/start.sh deleted file mode 100755 index 23e5965eb..000000000 --- a/ethrelay/scripts/start.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/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 - -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 -} - -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" - sleep 10 -} - -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 - -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" - -node "$DIR/../index.js" diff --git a/ethrelay/yarn.lock b/ethrelay/yarn.lock index 5af8bb23b..0c0875ccc 100644 --- a/ethrelay/yarn.lock +++ b/ethrelay/yarn.lock @@ -346,7 +346,7 @@ ansi-regex@^5.0.0: resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.0.tgz#388539f55179bf39339c81af30a654d69f87cb75" integrity sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg== -ansi-styles@^3.2.1: +ansi-styles@^3.2.0, ansi-styles@^3.2.1: version "3.2.1" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d" integrity sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA== @@ -710,6 +710,11 @@ buffer-fill@^1.0.0: resolved "https://registry.yarnpkg.com/buffer-fill/-/buffer-fill-1.0.0.tgz#f8f78b76789888ef39f205cd637f68e702122b2c" integrity sha1-+PeLdniYiO858gXNY39o5wISKyw= +buffer-from@^1.0.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef" + integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A== + buffer-to-arraybuffer@^0.0.5: version "0.0.5" resolved "https://registry.yarnpkg.com/buffer-to-arraybuffer/-/buffer-to-arraybuffer-0.0.5.tgz#6064a40fa76eb43c723aba9ef8f6e1216d10511a" @@ -838,6 +843,15 @@ cli-boxes@^2.2.0: resolved "https://registry.yarnpkg.com/cli-boxes/-/cli-boxes-2.2.0.tgz#538ecae8f9c6ca508e3c3c95b453fe93cb4c168d" integrity sha512-gpaBrMAizVEANOpfZp/EEUixTXDyGt7DFzdK5hU+UbWt/J0lB0w20ncZj59Z9a93xHb9u12zF5BS6i9RKbtg4w== +cliui@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/cliui/-/cliui-5.0.0.tgz#deefcfdb2e800784aa34f46fa08e06851c7bbbc5" + integrity sha512-PYeGSEmmHM6zvoef2w8TPzlrnNpXIjTipYK780YswmIP9vjxmd6Y2a3CB2Ks6/AU8NHjZugXvo8w3oWM2qnwXA== + dependencies: + string-width "^3.1.0" + strip-ansi "^5.2.0" + wrap-ansi "^5.1.0" + cliui@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/cliui/-/cliui-6.0.0.tgz#511d702c0c4e41ca156d7d0e96021f23e13225b1" @@ -1429,6 +1443,19 @@ ethereumjs-tx@^2.1.1: ethereumjs-common "^1.3.1" ethereumjs-util "^6.0.0" +ethereumjs-util@6.1.0: + version "6.1.0" + resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-6.1.0.tgz#e9c51e5549e8ebd757a339cc00f5380507e799c8" + integrity sha512-URESKMFbDeJxnAxPppnk2fN6Y3BIatn9fwn76Lm8bQlt+s52TpG8dN9M66MLPuRAiAOIqL3dfwqWJf0sd0fL0Q== + dependencies: + bn.js "^4.11.0" + create-hash "^1.1.2" + ethjs-util "0.1.6" + keccak "^1.0.2" + rlp "^2.0.0" + safe-buffer "^5.1.1" + secp256k1 "^3.0.1" + ethereumjs-util@^6.0.0: version "6.2.0" resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-6.2.0.tgz#23ec79b2488a7d041242f01e25f24e5ad0357960" @@ -1767,6 +1794,15 @@ function-bind@^1.1.1: resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== +ganache-cli@^6.9.0: + version "6.9.1" + resolved "https://registry.yarnpkg.com/ganache-cli/-/ganache-cli-6.9.1.tgz#1e13eee098fb9f19b031a191ec3f62ae926ea8b3" + integrity sha512-VPBumkNUZzXDRQwVOby5YyQpd5t1clkr06xMgB28lZdEIn5ht1GMwUskOTFOAxdkQ4J12IWP0gdeacVRGowqbA== + dependencies: + ethereumjs-util "6.1.0" + source-map-support "0.5.12" + yargs "13.2.4" + gensync@^1.0.0-beta.1: version "1.0.0-beta.1" resolved "https://registry.yarnpkg.com/gensync/-/gensync-1.0.0-beta.1.tgz#58f4361ff987e5ff6e1e7a210827aa371eaac269" @@ -2123,6 +2159,11 @@ invariant@^2.2.4: dependencies: loose-envify "^1.0.0" +invert-kv@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-2.0.0.tgz#7393f5afa59ec9ff5f67a27620d11c226e3eec02" + integrity sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA== + ipaddr.js@1.9.0: version "1.9.0" resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.9.0.tgz#37df74e430a0e47550fe54a2defe30d8acd95f65" @@ -2543,6 +2584,16 @@ jsprim@^1.2.2: json-schema "0.2.3" verror "1.10.0" +keccak@^1.0.2: + version "1.4.0" + resolved "https://registry.yarnpkg.com/keccak/-/keccak-1.4.0.tgz#572f8a6dbee8e7b3aa421550f9e6408ca2186f80" + integrity sha512-eZVaCpblK5formjPjeTBik7TAg+pqnDrMHIffSvi9Lh7PQgM1+hSzakUeZFCk9DVVG0dacZJuaz2ntwlzZUIBw== + dependencies: + bindings "^1.2.1" + inherits "^2.0.3" + nan "^2.2.1" + safe-buffer "^5.1.0" + keccak@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/keccak/-/keccak-2.0.0.tgz#7456ea5023284271e6f362b4397e8df4d2bb994c" @@ -2591,6 +2642,13 @@ latest-version@^5.0.0: dependencies: package-json "^6.3.0" +lcid@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/lcid/-/lcid-2.0.0.tgz#6ef5d2df60e52f82eb228a4c373e8d1f397253cf" + integrity sha512-avPEb8P8EGnwXKClwsNUgryVjllcRqtMYa49NTsbQagYuT1DcXnl1915oxWjoyGrXR6zH/Y0Zc96xWsPcoDKeA== + dependencies: + invert-kv "^2.0.0" + load-json-file@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-4.0.0.tgz#2f5f45ab91e33216234fd53adab668eb4ec0993b" @@ -2664,6 +2722,13 @@ makeerror@1.0.x: dependencies: tmpl "1.0.x" +map-age-cleaner@^0.1.1: + version "0.1.3" + resolved "https://registry.yarnpkg.com/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz#7d583a7306434c055fe474b0f45078e6e1b4b92a" + integrity sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w== + dependencies: + p-defer "^1.0.0" + map-cache@^0.2.2: version "0.2.2" resolved "https://registry.yarnpkg.com/map-cache/-/map-cache-0.2.2.tgz#c32abd0bd6525d9b051645bb4f26ac5dc98a0dbf" @@ -2690,6 +2755,15 @@ media-typer@0.3.0: resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748" integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g= +mem@^4.0.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/mem/-/mem-4.3.0.tgz#461af497bc4ae09608cdb2e60eefb69bff744178" + integrity sha512-qX2bG48pTqYRVmDB37rn/6PT7LcR8T7oAX3bf99u1Tt1nzxYfxkgqDwUwolPlXweM0XzBOBFzSx4kfp7KP1s/w== + dependencies: + map-age-cleaner "^0.1.1" + mimic-fn "^2.0.0" + p-is-promise "^2.0.0" + merge-descriptors@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61" @@ -2749,6 +2823,11 @@ mime@1.6.0: resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1" integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg== +mimic-fn@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b" + integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg== + mimic-response@^1.0.0, mimic-response@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-1.0.1.tgz#4923538878eef42063cb8a3e3b0798781487ab1b" @@ -3094,6 +3173,15 @@ once@^1.3.0, once@^1.3.1, once@^1.4.0: dependencies: wrappy "1" +os-locale@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/os-locale/-/os-locale-3.1.0.tgz#a802a6ee17f24c10483ab9935719cef4ed16bf1a" + integrity sha512-Z8l3R4wYWM40/52Z+S265okfFj8Kt2cC2MKY+xNi3kFs+XGI7WXu/I309QQQYbRW4ijiZ+yxs9pqEhJh0DqW3Q== + dependencies: + execa "^1.0.0" + lcid "^2.0.0" + mem "^4.0.0" + p-cancelable@^0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/p-cancelable/-/p-cancelable-0.3.0.tgz#b9e123800bcebb7ac13a479be195b507b98d30fa" @@ -3104,11 +3192,21 @@ p-cancelable@^1.0.0: resolved "https://registry.yarnpkg.com/p-cancelable/-/p-cancelable-1.1.0.tgz#d078d15a3af409220c886f1d9a0ca2e441ab26cc" integrity sha512-s73XxOZ4zpt1edZYZzvhqFa6uvQc1vwUa0K0BdtIZgQMAJj9IbebH+JkgKZc9h+B05PKHLOTl4ajG1BmNrVZlw== +p-defer@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/p-defer/-/p-defer-1.0.0.tgz#9f6eb182f6c9aa8cd743004a7d4f96b196b0fb0c" + integrity sha1-n26xgvbJqozXQwBKfU+WsZaw+ww= + p-finally@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae" integrity sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4= +p-is-promise@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/p-is-promise/-/p-is-promise-2.1.0.tgz#918cebaea248a62cf7ffab8e3bca8c5f882fc42e" + integrity sha512-Y3W0wlRPK8ZMRbNq97l4M5otioeA5lm1z7bkNkxCka8HSPjR0xRWmpCmc9utiaLP9Jb1eD8BgeIxTW4AIF45Pg== + p-limit@^2.0.0, p-limit@^2.2.0: version "2.2.2" resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.2.2.tgz#61279b67721f5287aa1c13a9a7fbbc48c9291b1e" @@ -3561,7 +3659,7 @@ ripemd160@^2.0.0, ripemd160@^2.0.1: hash-base "^3.0.0" inherits "^2.0.1" -rlp@^2.2.3: +rlp@^2.0.0, rlp@^2.2.3: version "2.2.4" resolved "https://registry.yarnpkg.com/rlp/-/rlp-2.2.4.tgz#d6b0e1659e9285fc509a5d169a9bd06f704951c1" integrity sha512-fdq2yYCWpAQBhwkZv+Z8o/Z4sPmYm1CUq6P7n6lVTOdb949CnqA0sndXal5C1NleSVSZm6q5F3iEbauyVln/iw== @@ -3813,6 +3911,14 @@ source-map-resolve@^0.5.0: source-map-url "^0.4.0" urix "^0.1.0" +source-map-support@0.5.12: + version "0.5.12" + resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.12.tgz#b4f3b10d51857a5af0138d3ce8003b201613d599" + integrity sha512-4h2Pbvyy15EE02G+JOZpUCmqWJuqrs+sEkzewTm++BPi7Hvn/HwcqLAcNxYAyI0x13CpPPn+kMjl+hplXMHITQ== + dependencies: + buffer-from "^1.0.0" + source-map "^0.6.0" + source-map-url@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3" @@ -3899,7 +4005,7 @@ strict-uri-encode@^1.0.0: resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz#279b225df1d582b1f54e65addd4352e18faa0713" integrity sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM= -string-width@^3.0.0: +string-width@^3.0.0, string-width@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/string-width/-/string-width-3.1.0.tgz#22767be21b62af1081574306f69ac51b62203961" integrity sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w== @@ -3940,7 +4046,7 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -strip-ansi@^5.1.0: +strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0: version "5.2.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae" integrity sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA== @@ -4634,6 +4740,15 @@ widest-line@^3.1.0: dependencies: string-width "^4.0.0" +wrap-ansi@^5.1.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-5.1.0.tgz#1fd1f67235d5b6d0fee781056001bfb694c03b09" + integrity sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q== + dependencies: + ansi-styles "^3.2.0" + string-width "^3.0.0" + strip-ansi "^5.0.0" + wrap-ansi@^6.2.0: version "6.2.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-6.2.0.tgz#e9393ba07102e6c91a3b221478f0257cd2856e53" @@ -4743,6 +4858,14 @@ yallist@^3.0.0, yallist@^3.0.3: resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd" integrity sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g== +yargs-parser@^13.1.0: + version "13.1.1" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-13.1.1.tgz#d26058532aa06d365fe091f6a1fc06b2f7e5eca0" + integrity sha512-oVAVsHz6uFrg3XQheFII8ESO2ssAf9luWuAd6Wexsu4F3OtIW0o8IribPXYrD4WC24LWtPrJlGy87y5udK+dxQ== + dependencies: + camelcase "^5.0.0" + decamelize "^1.2.0" + yargs-parser@^16.1.0: version "16.1.0" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-16.1.0.tgz#73747d53ae187e7b8dbe333f95714c76ea00ecf1" @@ -4751,6 +4874,23 @@ yargs-parser@^16.1.0: camelcase "^5.0.0" decamelize "^1.2.0" +yargs@13.2.4: + version "13.2.4" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-13.2.4.tgz#0b562b794016eb9651b98bd37acf364aa5d6dc83" + integrity sha512-HG/DWAJa1PAnHT9JAhNa8AbAv3FPaiLzioSjCcmuXXhP8MlpHO5vwls4g4j6n30Z74GVQj8Xa62dWVx1QCGklg== + dependencies: + cliui "^5.0.0" + find-up "^3.0.0" + get-caller-file "^2.0.1" + os-locale "^3.1.0" + require-directory "^2.1.1" + require-main-filename "^2.0.0" + set-blocking "^2.0.0" + string-width "^3.0.0" + which-module "^2.0.0" + y18n "^4.0.0" + yargs-parser "^13.1.0" + yargs@^15.0.1: version "15.1.0" resolved "https://registry.yarnpkg.com/yargs/-/yargs-15.1.0.tgz#e111381f5830e863a89550bd4b136bb6a5f37219" diff --git a/nearrelay/index.js b/nearrelay/index.js index d3b7e4562..211143a82 100644 --- a/nearrelay/index.js +++ b/nearrelay/index.js @@ -33,8 +33,8 @@ function subscribeOnBlocksRangesFrom(web3, block_number, handler) { const web3 = new Web3("http://localhost:9545"); const near = await nearlib.connect({ - nodeUrl: 'http://localhost:3030', //'https://rpc.nearprotocol.com', - networkId: 'local', // TODO: detect automatically + nodeUrl: process.env.NEAR_NODE_URL, //'https://rpc.nearprotocol.com', + networkId: process.env.NEAR_NODE_NETWORK_ID, // TODO: detect automatically deps: { keyStore: new nearlib.keyStores.UnencryptedFileSystemKeyStore(__dirname + '/neardev') } diff --git a/nearrelay/package.json b/nearrelay/package.json index 9eabc1d9d..73e980471 100644 --- a/nearrelay/package.json +++ b/nearrelay/package.json @@ -4,7 +4,8 @@ "description": "Ethereum >> Near relay", "main": "index.js", "scripts": { - "start": "scripts/start.sh" + "test": "scripts/run_localnet.sh", + "start": "scripts/run_testnet.sh" }, "author": "", "license": "MIT", diff --git a/nearrelay/scripts/prepare.sh b/nearrelay/scripts/prepare.sh index 93fcb79c2..839b7f278 100755 --- a/nearrelay/scripts/prepare.sh +++ b/nearrelay/scripts/prepare.sh @@ -3,4 +3,4 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" rm -rf "$DIR/.near" -cargo run --package near --bin near -- --home "$DIR/.near" init --chain-id= --test-seed=ethrelay --account-id=ethrelay --fast +cargo run --package near --bin near -- --home "$DIR/.near" init --chain-id= --test-seed=nearrelay --account-id=nearrelay --fast diff --git a/nearrelay/scripts/start.sh b/nearrelay/scripts/run_localnet.sh similarity index 93% rename from nearrelay/scripts/start.sh rename to nearrelay/scripts/run_localnet.sh index 9689ef2f0..58d2912e4 100755 --- a/nearrelay/scripts/start.sh +++ b/nearrelay/scripts/run_localnet.sh @@ -76,4 +76,8 @@ else start_ganache fi -NEAR_BRIDGE_OWNER_PRIVATE_KEY=0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501200 node "$DIR/../index.js" +NEAR_BRIDGE_OWNER_PRIVATE_KEY=0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501200 \ + NEAR_NODE_URL="http://localhost:3030" \ + NEAR_NODE_NETWORK_ID=local \ + ETHEREUM_NODE_URL="http://localhost:9545" \ + node "$DIR/../index.js" diff --git a/nearrelay/scripts/run_testnet.sh b/nearrelay/scripts/run_testnet.sh new file mode 100755 index 000000000..02447a5d5 --- /dev/null +++ b/nearrelay/scripts/run_testnet.sh @@ -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=nearrelay --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 NearRelay +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"