aboutsummaryrefslogtreecommitdiffstats
path: root/test/run_test.sh
blob: 1f19caa6a454071cc37192c5d60cfe1de125ef78 (plain) (blame)
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
#!/bin/bash

BOOTNODE_FLAGS="--bootnodes enode://0478aa13c91aa0db8e93b668313b7eb0532fbdb24f64772375373b14dbe326c238ad09ab4469f6442c9a9753f1275aeec2e531912c14a958ed1feb4ae7e227ef@127.0.0.1:30301"
GENESIS="genesis.json"

GDEX="../build/bin/gdex"
BOOTNODE="../build/bin/bootnode"


CONTINUE=false
IGNORELOG=false
while [[ $# -gt 0 ]]; do
  case "$1" in
    --continue)
    CONTINUE=true
    ;;
    --ignore-log)
    IGNORELOG=true
    ;;
  esac
  shift
done


if [ ! -e "$BOOTNODE" ]; then
  echo "Building bootnode for the first time ..."
  go build -o $BOOTNODE ../cmd/bootnode
fi

# Start bootnode.
$BOOTNODE -nodekey keystore/bootnode.key --verbosity=9 > bootnode.log 2>&1 &

# Kill all previous instances.
pkill -9 -f gdex

logsdir=$PWD/log-$(date '+%Y-%m-%d-%H:%M:%S')
mkdir $logsdir

if [ -e log-latest ]; then
  rm -f log-previous
  mv log-latest log-previous
fi

rm -f log-latest
ln -s $logsdir log-latest

python << __FILE__
import re
import time

with open('$GENESIS', 'r') as f:
  data = f.read()

with open('$GENESIS', 'w') as f:
  dMoment = int(time.time()) + 15
  f.write(re.sub('"dMoment": [0-9]+,', '"dMoment": %d,' % dMoment, data))
__FILE__

# A standalone RPC server for accepting RPC requests.
datadir=$PWD/Dexon.rpc
if ! $CONTINUE; then
  rm -rf $datadir
  $GDEX --datadir=$datadir init ${GENESIS}
fi
$GDEX \
  ${BOOTNODE_FLAGS} \
  --verbosity=3 \
  --gcmode=archive \
  --datadir=$datadir --nodekey=keystore/rpc.key \
  --rpc --rpcapi=eth,net,web3,debug \
  --rpcaddr=0.0.0.0 --rpcport=8545 \
  --ws --wsapi=eth,net,web3,debug \
  --wsaddr=0.0.0.0 --wsport=8546  \
  --wsorigins='*' --rpcvhosts='*' --rpccorsdomain="*" \
  > $logsdir/gdex.rpc.log 2>&1 &

NUM_NODES=$(cat ${GENESIS} | grep 'DEXON Test Node' | wc -l)

# Nodes
for i in $(seq 0 $(($NUM_NODES - 1))); do
  datadir=$PWD/Dexon.$i

  if ! $CONTINUE; then
    rm -rf $datadir
    $GDEX --datadir=$datadir init ${GENESIS}
  fi
  $GDEX \
    ${BOOTNODE_FLAGS} \
    --bp \
    --verbosity=4 \
    --gcmode=archive \
    --datadir=$datadir --nodekey=keystore/test$i.key \
    --port=$((30305 + $i)) \
    --recovery.network-rpc="https://rinkeby.infura.io" \
    --rpc --rpcapi=eth,net,web3,debug \
    --rpcaddr=0.0.0.0 --rpcport=$((8547 + $i * 2)) \
    --ws --wsapi=eth,net,web3,debug \
    --wsaddr=0.0.0.0 --wsport=$((8548 + $i * 2)) \
    --wsorigins='*' --rpcvhosts='*' --rpccorsdomain="*" \
    --pprof --pprofaddr=localhost --pprofport=$((6060 + $i)) \
    > $logsdir/gdex.$i.log 2>&1 &
done

if ! $IGNORELOG; then
  tail -f $logsdir/gdex.*.log
fi