Merge
This commit is contained in:
27
eth/test/README.md
Normal file
27
eth/test/README.md
Normal file
@ -0,0 +1,27 @@
|
||||
= Integration tests for eth protocol and blockpool
|
||||
|
||||
This is a simple suite of tests to fire up a local test node with peers to test blockchain synchronisation and download.
|
||||
The scripts call ethereum (assumed to be compiled in go-ethereum root).
|
||||
|
||||
To run a test:
|
||||
|
||||
. run.sh 00 02
|
||||
|
||||
Without arguments, all tests are run.
|
||||
|
||||
Peers are launched with preloaded imported chains. In order to prevent them from synchronizing with each other they are set with `-dial=false` and `-maxpeer 1` options. They log into `/tmp/eth.test/nodes/XX` where XX is the last two digits of their port.
|
||||
|
||||
Chains to import can be bootstrapped by letting nodes mine for some time. This is done with
|
||||
|
||||
. bootstrap.sh
|
||||
|
||||
Only the relative timing and forks matter so they should work if the bootstrap script is rerun.
|
||||
The reference blockchain of tests are soft links to these import chains and check at the end of a test run.
|
||||
|
||||
Connecting to peers and exporting blockchain is scripted with JS files executed by the JSRE, see `tests/XX.sh`.
|
||||
|
||||
Each test is set with a timeout. This may vary on different computers so adjust sensibly.
|
||||
If you kill a test before it completes, do not forget to kill all the background processes, since they will impact the result. Use:
|
||||
|
||||
killall ethereum
|
||||
|
9
eth/test/bootstrap.sh
Normal file
9
eth/test/bootstrap.sh
Normal file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
# bootstrap chains - used to regenerate tests/chains/*.chain
|
||||
|
||||
mkdir -p chains
|
||||
bash ./mine.sh 00 10
|
||||
bash ./mine.sh 01 5 00
|
||||
bash ./mine.sh 02 10 00
|
||||
bash ./mine.sh 03 5 02
|
||||
bash ./mine.sh 04 10 02
|
BIN
eth/test/chains/00.chain
Executable file
BIN
eth/test/chains/00.chain
Executable file
Binary file not shown.
BIN
eth/test/chains/01.chain
Executable file
BIN
eth/test/chains/01.chain
Executable file
Binary file not shown.
BIN
eth/test/chains/02.chain
Executable file
BIN
eth/test/chains/02.chain
Executable file
Binary file not shown.
BIN
eth/test/chains/03.chain
Executable file
BIN
eth/test/chains/03.chain
Executable file
Binary file not shown.
BIN
eth/test/chains/04.chain
Executable file
BIN
eth/test/chains/04.chain
Executable file
Binary file not shown.
20
eth/test/mine.sh
Normal file
20
eth/test/mine.sh
Normal file
@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
# bash ./mine.sh node_id timeout(sec) [basechain]
|
||||
ETH=../../ethereum
|
||||
MINE="$ETH -datadir tmp/nodes/$1 -seed=false -port '' -shh=false -id test$1"
|
||||
rm -rf tmp/nodes/$1
|
||||
echo "Creating chain $1..."
|
||||
if [[ "" != "$3" ]]; then
|
||||
CHAIN="chains/$3.chain"
|
||||
CHAINARG="-chain $CHAIN"
|
||||
$MINE -mine $CHAINARG -loglevel 3 | grep 'importing'
|
||||
fi
|
||||
$MINE -mine -loglevel 0 &
|
||||
PID=$!
|
||||
sleep $2
|
||||
kill $PID
|
||||
$MINE -loglevel 3 <(echo "eth.export(\"chains/$1.chain\")") > /tmp/eth.test/mine.tmp &
|
||||
PID=$!
|
||||
sleep 1
|
||||
kill $PID
|
||||
cat /tmp/eth.test/mine.tmp | grep 'exporting'
|
53
eth/test/run.sh
Normal file
53
eth/test/run.sh
Normal file
@ -0,0 +1,53 @@
|
||||
#!/bin/bash
|
||||
# bash run.sh (testid0 testid1 ...)
|
||||
# runs tests tests/testid0.sh tests/testid1.sh ...
|
||||
# without arguments, it runs all tests
|
||||
|
||||
. tests/common.sh
|
||||
|
||||
TESTS=
|
||||
|
||||
if [ "$#" -eq 0 ]; then
|
||||
for NAME in tests/??.sh; do
|
||||
i=`basename $NAME .sh`
|
||||
TESTS="$TESTS $i"
|
||||
done
|
||||
else
|
||||
TESTS=$@
|
||||
fi
|
||||
|
||||
ETH=../../ethereum
|
||||
DIR="/tmp/eth.test/nodes"
|
||||
TIMEOUT=10
|
||||
|
||||
mkdir -p $DIR/js
|
||||
|
||||
echo "running tests $TESTS"
|
||||
for NAME in $TESTS; do
|
||||
PIDS=
|
||||
CHAIN="tests/$NAME.chain"
|
||||
JSFILE="$DIR/js/$NAME.js"
|
||||
CHAIN_TEST="$DIR/$NAME/chain"
|
||||
|
||||
echo "RUN: test $NAME"
|
||||
cat tests/common.js > $JSFILE
|
||||
. tests/$NAME.sh
|
||||
sleep $TIMEOUT
|
||||
echo "timeout after $TIMEOUT seconds: killing $PIDS"
|
||||
kill $PIDS
|
||||
if [ -r "$CHAIN" ]; then
|
||||
if diff $CHAIN $CHAIN_TEST >/dev/null ; then
|
||||
echo "chain ok: $CHAIN=$CHAIN_TEST"
|
||||
else
|
||||
echo "FAIL: chains differ: expected $CHAIN ; got $CHAIN_TEST"
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
ERRORS=$DIR/errors
|
||||
if [ -r "$ERRORS" ]; then
|
||||
echo "FAIL: "
|
||||
cat $ERRORS
|
||||
else
|
||||
echo PASS
|
||||
fi
|
||||
done
|
1
eth/test/tests/00.chain
Symbolic link
1
eth/test/tests/00.chain
Symbolic link
@ -0,0 +1 @@
|
||||
../chains/01.chain
|
13
eth/test/tests/00.sh
Normal file
13
eth/test/tests/00.sh
Normal file
@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
TIMEOUT=4
|
||||
|
||||
cat >> $JSFILE <<EOF
|
||||
eth.addPeer("localhost:30311");
|
||||
sleep(1000)
|
||||
eth.export("$CHAIN_TEST");
|
||||
EOF
|
||||
|
||||
peer 11 01
|
||||
test_node $NAME "" -loglevel 5 $JSFILE
|
||||
|
1
eth/test/tests/01.chain
Symbolic link
1
eth/test/tests/01.chain
Symbolic link
@ -0,0 +1 @@
|
||||
../chains/02.chain
|
18
eth/test/tests/01.sh
Normal file
18
eth/test/tests/01.sh
Normal file
@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
TIMEOUT=5
|
||||
|
||||
cat >> $JSFILE <<EOF
|
||||
eth.addPeer("localhost:30311");
|
||||
log("added peer localhost:30311");
|
||||
sleep(1000);
|
||||
log("added peer localhost:30312");
|
||||
eth.addPeer("localhost:30312");
|
||||
sleep(3000);
|
||||
eth.export("$CHAIN_TEST");
|
||||
EOF
|
||||
|
||||
peer 11 01
|
||||
peer 12 02
|
||||
test_node $NAME "" -loglevel 5 $JSFILE
|
||||
|
1
eth/test/tests/02.chain
Symbolic link
1
eth/test/tests/02.chain
Symbolic link
@ -0,0 +1 @@
|
||||
../chains/01.chain
|
19
eth/test/tests/02.sh
Normal file
19
eth/test/tests/02.sh
Normal file
@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
TIMEOUT=6
|
||||
|
||||
cat >> $JSFILE <<EOF
|
||||
eth.addPeer("localhost:30311");
|
||||
sleep(200);
|
||||
eth.addPeer("localhost:30312");
|
||||
sleep(3000);
|
||||
eth.export("$CHAIN_TEST");
|
||||
EOF
|
||||
|
||||
peer 11 01
|
||||
peer 12 02
|
||||
P13ID=$PID
|
||||
test_node $NAME "" -loglevel 5 $JSFILE
|
||||
sleep 0.5
|
||||
kill $P13ID
|
||||
|
1
eth/test/tests/03.chain
Symbolic link
1
eth/test/tests/03.chain
Symbolic link
@ -0,0 +1 @@
|
||||
../chains/12k.chain
|
14
eth/test/tests/03.sh
Normal file
14
eth/test/tests/03.sh
Normal file
@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
TIMEOUT=35
|
||||
|
||||
cat >> $JSFILE <<EOF
|
||||
eth.addPeer("localhost:30311");
|
||||
sleep(30000);
|
||||
eth.export("$CHAIN_TEST");
|
||||
EOF
|
||||
|
||||
peer 11 12k
|
||||
sleep 2
|
||||
test_node $NAME "" -loglevel 5 $JSFILE
|
||||
|
17
eth/test/tests/04.sh
Normal file
17
eth/test/tests/04.sh
Normal file
@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
TIMEOUT=15
|
||||
|
||||
cat >> $JSFILE <<EOF
|
||||
eth.addPeer("localhost:30311");
|
||||
sleep(200);
|
||||
eth.addPeer("localhost:30312");
|
||||
sleep(13000);
|
||||
eth.export("$CHAIN_TEST");
|
||||
EOF
|
||||
|
||||
peer 11 01 -mine
|
||||
peer 12 02
|
||||
test_node $NAME "" -loglevel 5 $JSFILE
|
||||
sleep 6
|
||||
cat $DIR/$NAME/debug.log | grep 'best peer'
|
20
eth/test/tests/05.sh
Normal file
20
eth/test/tests/05.sh
Normal file
@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
TIMEOUT=60
|
||||
|
||||
cat >> $JSFILE <<EOF
|
||||
eth.addPeer("localhost:30311");
|
||||
sleep(200);
|
||||
eth.addPeer("localhost:30312");
|
||||
eth.addPeer("localhost:30313");
|
||||
eth.addPeer("localhost:30314");
|
||||
sleep(3000);
|
||||
eth.export("$CHAIN_TEST");
|
||||
EOF
|
||||
|
||||
peer 11 01 -mine
|
||||
peer 12 02 -mine
|
||||
peer 13 03
|
||||
peer 14 04
|
||||
test_node $NAME "" -loglevel 5 $JSFILE
|
||||
|
9
eth/test/tests/common.js
Normal file
9
eth/test/tests/common.js
Normal file
@ -0,0 +1,9 @@
|
||||
function log(text) {
|
||||
console.log("[JS TEST SCRIPT] " + text);
|
||||
}
|
||||
|
||||
function sleep(seconds) {
|
||||
var now = new Date().getTime();
|
||||
while(new Date().getTime() < now + seconds){}
|
||||
}
|
||||
|
20
eth/test/tests/common.sh
Normal file
20
eth/test/tests/common.sh
Normal file
@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
# launched by run.sh
|
||||
function test_node {
|
||||
rm -rf $DIR/$1
|
||||
ARGS="-datadir $DIR/$1 -debug debug -seed=false -shh=false -id test$1"
|
||||
if [ "" != "$2" ]; then
|
||||
chain="chains/$2.chain"
|
||||
echo "import chain $chain"
|
||||
$ETH $ARGS -loglevel 3 -chain $chain | grep CLI |grep import
|
||||
fi
|
||||
echo "starting test node $1 with extra args ${@:3}"
|
||||
$ETH $ARGS -port 303$1 ${@:3} &
|
||||
PID=$!
|
||||
PIDS="$PIDS $PID"
|
||||
}
|
||||
|
||||
function peer {
|
||||
test_node $@ -loglevel 5 -logfile debug.log -maxpeer 1 -dial=false
|
||||
}
|
Reference in New Issue
Block a user