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 ethrelay catchup and test challenge invalid block #254

Merged
merged 24 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
74 changes: 30 additions & 44 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ steps:

label: "build all rust contracts"
agents:
- "queue=bridge"
- "queue=medium"

- command: |
source ~/.cargo/env
Expand Down Expand Up @@ -117,57 +117,43 @@ steps:

- label: "e2e test"
command: |
source ~/.nvm/nvm.sh
source ~/.cargo/env
source ~/.yarn/yarn.sh

if [[ ! -d ~/go ]]; then
wget -q -O - https://raw.githubusercontent.com/canha/golang-tools-install-script/master/goinstall.sh | bash
fi
source ci/e2e_ci_prepare_env.sh
source ci/e2e_ci_prepare_log.sh
ci/e2e.sh

artifact_paths:
- "logs/**/*.log"
timeout: 40

agents:
- "queue=default"

export GOROOT=~/.go
export GOPATH=~/go
export PATH=$$GOPATH/bin:$$GOROOT/bin:$$PATH
npm i -g ganache-cli
git submodule update --init --recursive
- label: "test challege with near watchdog"
command: |
source ci/e2e_ci_prepare_env.sh
source ci/e2e_ci_prepare_log.sh
ci/test_challenge.sh

artifact_paths:
- "logs/**/*.log"
timeout: 40

agents:
- "queue=default"

# hard link pm2 logs to current dir, so buildkite can pick up them as artifacts
mkdir -p ~/.rainbow/logs/eth-relay
mkdir -p ~/.rainbow/logs/near-relay
mkdir -p ~/.rainbow/logs/ganache
touch eth-relay-out.log
touch eth-relay-err.log
touch near-relay-out.log
touch near-relay-err.log
touch ganache-out.log
touch ganache-err.log
if [[ ! -f ~/.rainbow/logs/eth-relay/out.log ]]; then
ln eth-relay-out.log ~/.rainbow/logs/eth-relay/out.log
ln eth-relay-err.log ~/.rainbow/logs/eth-relay/err.log
ln near-relay-out.log ~/.rainbow/logs/near-relay/out.log
ln near-relay-err.log ~/.rainbow/logs/near-relay/err.log
ln ganache-out.log ~/.rainbow/logs/ganache/out.log
ln ganache-err.log ~/.rainbow/logs/ganache/err.log
fi

cd environment/vendor/ethashproof
./build.sh
cd -
rustup default stable
rustup target add wasm32-unknown-unknown
cd environment
yarn
node index.js clean
cd ..
ci/e2e.sh
- label: "test ethrelay catchup"
command: |
source ci/e2e_ci_prepare_env.sh
source ci/e2e_ci_prepare_log.sh
ci/test_ethrelay_catchup.sh

artifact_paths:
- "*.log"
- "logs/**/*.log"
timeout: 40

agents:
- "queue=default"

- command: |
source ~/.nvm/nvm.sh
source ~/.yarn/yarn.sh
Expand Down
4 changes: 2 additions & 2 deletions ci/e2e.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash
# This test launch all commands and tranfer tokens
# If run locally, you need a manually `node index.js clean`, `npm i -g ganache-cli`

set -exuo pipefail

Expand All @@ -9,6 +8,7 @@ ROOT_DIR=$CI_DIR/..

cd $ROOT_DIR/environment
yarn
node index.js clean
if [ -n "${LOCAL_CORE_SRC+x}" ]; then
node index.js prepare --core-src "$LOCAL_CORE_SRC"
else
Expand All @@ -28,7 +28,7 @@ done
node index.js init-near-contracts
node index.js init-eth-ed25519
# Use short lockup time for tests
node index.js init-eth-client --eth-client-lock-eth-amount 1e18 --eth-client-lock-duration 10
node index.js init-eth-client --eth-client-lock-eth-amount 1e18 --eth-client-lock-duration 30
node index.js init-eth-prover
node index.js init-eth-erc20
node index.js init-eth-locker
Expand Down
12 changes: 12 additions & 0 deletions ci/e2e_ci_prepare_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file should be sourced when run e2e test on ci
source ~/.nvm/nvm.sh
source ~/.cargo/env
source ~/.yarn/yarn.sh

if [[ ! -d ~/go ]]; then
wget -q -O - https://raw.githubusercontent.com/canha/golang-tools-install-script/master/goinstall.sh | bash
fi

export GOROOT=~/.go
export GOPATH=~/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
5 changes: 5 additions & 0 deletions ci/e2e_ci_prepare_log.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function finish {
cp -r ~/.rainbow/logs .
}
trap finish ERR
trap finish EXIT
66 changes: 66 additions & 0 deletions ci/test_challenge.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash
# This test launch all commands, submit a invalid block and challenge

set -exuo pipefail

CI_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/tmp/ganache.out 2>&1 && pwd )"
ROOT_DIR=$CI_DIR/..

cd $ROOT_DIR/environment
yarn
node index.js clean
if [ -n "${LOCAL_CORE_SRC+x}" ]; then
node index.js prepare --core-src "$LOCAL_CORE_SRC"
else
node index.js prepare
fi
node index.js start near-node
# First start pm2 daemon
yarn run pm2 ping
node index.js start ganache
# Wait for the local node to start
while ! curl localhost:3030; do
sleep 1
done

while ! curl localhost:9545; do
sleep 1
done

node index.js init-near-contracts
node index.js init-eth-ed25519
# Use short lockup time for tests
node index.js init-eth-client --eth-client-lock-eth-amount 1e18 --eth-client-lock-duration 60
node index.js init-eth-prover
node index.js init-eth-erc20
node index.js init-eth-locker
node index.js init-near-fun-token

sleep 5
yarn run pm2 list
node index.js start near-relay --eth-master-sk 0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501201
sleep 5
yarn run pm2 list
node index.js start eth-relay
sleep 5
yarn run pm2 list
node index.js start near-watchdog
sleep 5
yarn run pm2 list

sleep 30
ailisp marked this conversation as resolved.
Show resolved Hide resolved
node index.js stop near-relay
node index.js DANGER submit_invalid_near_block
sleep 30
node index.js start near-relay

node index.js transfer-eth-erc20-to-near --amount 1000 \
--eth-sender-sk 0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501200 \
--near-receiver-account rainbow_bridge_eth_on_near_prover --near-master-account rainbow_bridge_eth_on_near_prover \
2>&1 | tee -a /tmp/eth2neartransfer.out
grep "Balance of rainbow_bridge_eth_on_near_prover after the transfer is 1000" /tmp/eth2neartransfer.out
node index.js transfer-eth-erc20-from-near --amount 1 --near-sender-account rainbow_bridge_eth_on_near_prover \
--near-sender-sk ed25519:3D4YudUQRE39Lc4JHghuB5WM8kbgDDa34mnrEP5DdTApVH81af7e2dWgNPEaiQfdJnZq1CNPp5im4Rg5b733oiMP \
--eth-receiver-address 0xEC8bE1A5630364292E56D01129E8ee8A9578d7D8 \
2>&1 | tee -a /tmp/near2ethtransfer.out
grep "after the transfer: 1" /tmp/near2ethtransfer.out
57 changes: 57 additions & 0 deletions ci/test_ethrelay_catchup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
# This test launch all commands, but postpone start eth-relay late to test it catch fast

set -exuo pipefail

CI_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/tmp/ganache.out 2>&1 && pwd )"
ROOT_DIR=$CI_DIR/..

cd $ROOT_DIR/environment
yarn
node index.js clean
if [ -n "${LOCAL_CORE_SRC+x}" ]; then
node index.js prepare --core-src "$LOCAL_CORE_SRC"
else
node index.js prepare
fi
node index.js start near-node
export GANACHE_BLOCK_TIME=3
node index.js start ganache
# Wait for the local node to start
while ! curl localhost:3030; do
sleep 1
done

while ! curl localhost:9545; do
sleep 1
done

node index.js init-near-contracts
node index.js init-eth-ed25519
# Use short lockup time for tests
node index.js init-eth-client --eth-client-lock-eth-amount 1e18 --eth-client-lock-duration 10
node index.js init-eth-prover
node index.js init-eth-erc20
node index.js init-eth-locker
node index.js init-near-fun-token
# First start pm2 daemon
yarn run pm2 ping
sleep 5
yarn run pm2 list
node index.js start near-relay --eth-master-sk 0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501201
sleep 5
yarn run pm2 list
sleep 100
node index.js start eth-relay
sleep 5
yarn run pm2 list
node index.js transfer-eth-erc20-to-near --amount 1000 \
--eth-sender-sk 0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501200 \
--near-receiver-account rainbow_bridge_eth_on_near_prover --near-master-account rainbow_bridge_eth_on_near_prover \
2>&1 | tee -a /tmp/eth2neartransfer.out
grep "Balance of rainbow_bridge_eth_on_near_prover after the transfer is 1000" /tmp/eth2neartransfer.out
node index.js transfer-eth-erc20-from-near --amount 1 --near-sender-account rainbow_bridge_eth_on_near_prover \
--near-sender-sk ed25519:3D4YudUQRE39Lc4JHghuB5WM8kbgDDa34mnrEP5DdTApVH81af7e2dWgNPEaiQfdJnZq1CNPp5im4Rg5b733oiMP \
--eth-receiver-address 0xEC8bE1A5630364292E56D01129E8ee8A9578d7D8 \
2>&1 | tee -a /tmp/near2ethtransfer.out
grep "after the transfer: 1" /tmp/near2ethtransfer.out
12 changes: 12 additions & 0 deletions environment/commands/danger-submit-invalid-near-block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const ProcessManager = require('pm2')
const { Near2EthRelay } = require('../lib/near2eth-relay')

class DangerSubmitInvalidNearBlock {
static async execute() {
const relay = new Near2EthRelay()
await relay.initialize()
await relay.DANGER_submitInvalidNearBlock()
}
}

exports.DangerSubmitInvalidNearBlock = DangerSubmitInvalidNearBlock
49 changes: 27 additions & 22 deletions environment/commands/stop/all.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
const ProcessManager = require('pm2-promise');
const ProcessManager = require('pm2-promise')

const { StopLocalNearNodeCommand } = require('./near.js');
const { StopLocalNearNodeCommand } = require('./near.js')

async function stop(serviceName) {
try {
await ProcessManager.delete(serviceName);
console.log(serviceName, 'successfully stopped...');
} catch (err) {
if (!err.message.includes('process or namespace not found')) {
console.log(serviceName, 'error stopping the process due to:', err);
} else {
console.log(serviceName, 'already stopped');
}
};
try {
await ProcessManager.delete(serviceName)
console.log(serviceName, 'successfully stopped...')
} catch (err) {
if (!err.message.includes('process or namespace not found')) {
console.log(serviceName, 'error stopping the process due to:', err)
} else {
console.log(serviceName, 'already stopped')
}
}
}

class StopAllCommands {
static async execute() {
console.log('Stopping all processes...');

StopLocalNearNodeCommand.execute();
for (const serviceName of ['ganache', 'eth-relay', 'near-relay', 'near-watchdog']) {
await stop(serviceName);
}
static async execute() {
console.log('Stopping all processes...')

console.log('Stopping all processes done');
await ProcessManager.disconnect();
StopLocalNearNodeCommand.execute()
for (const serviceName of [
'ganache',
'eth-relay',
'near-relay',
'near-watchdog',
]) {
await stop(serviceName)
}

console.log('Stopping all processes done')
await ProcessManager.disconnect()
}
}

exports.StopAllCommands = StopAllCommands;
exports.StopAllCommands = StopAllCommands
20 changes: 10 additions & 10 deletions environment/commands/stop/near.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const { execSync } = require('child_process');
const { execSync } = require('child_process')

class StopLocalNearNodeCommand {
static execute() {
console.log('Stopping local near node...');
const command = 'python3 ~/.rainbow/nearup/main.py stop';
try {
execSync(command);
} catch (err) {
console.log('Error stopping local near node', err);
}
static execute() {
console.log('Stopping local near node...')
const command = 'python3 ~/.rainbow/nearup/main.py stop'
try {
execSync(command)
} catch (err) {
console.log('Error stopping local near node', err)
}
}
}

exports.StopLocalNearNodeCommand = StopLocalNearNodeCommand;
exports.StopLocalNearNodeCommand = StopLocalNearNodeCommand
Loading