-
Notifications
You must be signed in to change notification settings - Fork 62
/
e2e_test.sh
executable file
·173 lines (140 loc) · 4.77 KB
/
e2e_test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
# To run this script locally set LOOM_BIN env var to point at the loom binary you wish to run the
# tests with.
set -exo pipefail
# Loom build to use for tests when running on Jenkins, this build will be automatically downloaded.
BUILD_NUMBER=653
# These can be toggled via the options below, only useful when running the script locally.
LOOM_INIT_ONLY=false
DEBUG_LOOM=false
# Scripts options:
# -i / --init - Reinitializes the DAppChain for a fresh test run.
# --debug-node - Doesn't reinitialize or start the DAppChain (only Ganache), useful when you want to
# launch the DAppChain node manually via the debugger.
while [[ "$#" > 0 ]]; do case $1 in
-i|--init) LOOM_INIT_ONLY=true; shift;;
--debug-node) DEBUG_LOOM=true; shift;;
*) echo "Unknown parameter: $1"; shift; shift;;
esac; done
echo "Only reinitializing DAppChain? $LOOM_INIT_ONLY"
echo "Skipping launching of DAppChain node? $DEBUG_LOOM"
# Spins up a Ganache node & a DAppChain node
function start_chains {
cd $REPO_ROOT/server
npm run --silent migrate:dev
sleep 1
ganache_pid=`cat ganache.pid`
echo 'Launched ganache' $ganache_pid
if [[ "$DEBUG_LOOM" == false ]]; then
cd $LOOM_DIR
$LOOM_BIN run > loom.log 2>&1 &
loom_pid=$!
echo "Launched Loom - Log(loom.log) Pid(${loom_pid})"
fi
# Wait for Ganache & Loom to spin up
sleep 10
}
# Stops the Ganache node & the DAppChain node
function stop_chains {
echo "exiting ganache-pid(${ganache_pid})"
kill -9 "${ganache_pid}" &> /dev/null
if [[ "$DEBUG_LOOM" == false ]]; then
echo "exiting loom-pid(${loom_pid})"
kill -9 "${loom_pid}" &> /dev/null
echo "killing ${LOOM_DIR}/contracts/hostileoperator.1.0.0"
pkill -f "${LOOM_DIR}/contracts/hostileoperator.1.0.0" || true
fi
}
function init_honest_dappchain {
cd $LOOM_DIR
rm -rf app.db
rm -rf chaindata
cp $REPO_ROOT/loom_test/loom-test.yml $LOOM_DIR/loom.yml
cp $REPO_ROOT/loom_test/eth.key $LOOM_DIR/eth.key
cp $REPO_ROOT/loom_test/test.key $LOOM_DIR/test.key
cp $REPO_ROOT/loom_test/oracle.key $LOOM_DIR/oracle.key
$LOOM_BIN init -f
cp $REPO_ROOT/loom_test/honest.genesis.json $LOOM_DIR/genesis.json
echo 'Loom DAppChain initialized in ' $LOOM_DIR
}
function init_hostile_dappchain {
cd $LOOM_DIR
rm -rf app.db
rm -rf chaindata
cp $REPO_ROOT/loom_test/loom-hostile-test.yml $LOOM_DIR/loom.yml
$LOOM_BIN init -f
echo 'Hostile Loom DAppChain initialized in ' $LOOM_DIR
cd $REPO_ROOT/loom_test
rm -rf $LOOM_DIR/contracts; true
mkdir $LOOM_DIR/contracts
cp contracts/hostileoperator.1.0.0 $LOOM_DIR/contracts/hostileoperator.1.0.0
cp hostile.genesis.json $LOOM_DIR/genesis.json
}
function cleanup {
stop_chains
}
function download_dappchain {
cd $LOOM_DIR
if [[ "`uname`" == 'Darwin' ]]; then
wget https://private.delegatecall.com/loom/osx/build-$BUILD_NUMBER/loom
else
wget https://private.delegatecall.com/loom/linux/build-$BUILD_NUMBER/loom
fi
chmod +x loom
export LOOM_BIN=`pwd`/loom
}
if [[ "$IS_JENKINS_ENV" == true ]]; then
# Kill off any plugins that weren't killed off by older builds
pkill -f "hostileoperator.1.0.0" || true
pkill -f loom || true
pkill -f ganache || true
fi
# BUILD_TAG is usually only set by Jenkins, so when running locally just hardcode some value
if [[ -z "$BUILD_TAG" ]]; then
BUILD_TAG=123
fi
# REPO_ROOT is set in jenkins.sh, if the script is executed directly just use cwd
if [[ -z "$REPO_ROOT" ]]; then
REPO_ROOT=`pwd`
fi
LOOM_DIR=`pwd`/tmp/loom-plasma-$BUILD_TAG
if [[ "$DEBUG_LOOM" == false ]]; then
rm -rf $LOOM_DIR; true
fi
mkdir -p $LOOM_DIR
if [[ "$IS_JENKINS_ENV" == true ]]; then
download_dappchain
fi
echo "REPO_ROOT=(${REPO_ROOT})"
echo "GOPATH=(${GOPATH})"
if [[ "$DEBUG_LOOM" == false ]]; then
init_honest_dappchain
fi
if [[ "$LOOM_INIT_ONLY" == true ]]; then
exit
fi
trap cleanup EXIT
start_chains
# Run first set of Go tests against the built-in Plasma Cash contract
cd $REPO_ROOT/loom_test
./plasmacash_tester
./plasmacash_challenge_after_tester
stop_chains
# Wait for Ganache & Loom to stop
sleep 10
# Reset the DAppChain and deploy a hostile/dumb Plasma Cash contract for the Go challenge tests
init_hostile_dappchain
start_chains
cd $REPO_ROOT/loom_test
./plasmacash_tester -hostile
./plasmacash_challenge_after_tester -hostile
./plasmacash_challenge_between_tester -hostile
./plasmacash_challenge_before_tester -hostile
./plasmacash_respond_challenge_before_tester -hostile
# Wait for Ganache & Loom to stop
sleep 10
# If the script gets this far then nothing failed and we can wipe out the working dir since we
# probably wont't need the logs.
if [[ $LOOM_DIR ]]; then
rm -rf $LOOM_DIR
fi