-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathganache-cli.sh
executable file
·62 lines (51 loc) · 1.59 KB
/
ganache-cli.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
#!/usr/bin/env bash
# Exit script as soon as a command fails.
set -o errexit
# get_script_dir () {
# SOURCE="${BASH_SOURCE[0]}"
# # While $SOURCE is a symlink, resolve it
# while [ -h "$SOURCE" ]; do
# DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
# SOURCE="$( readlink "$SOURCE" )"
# # If $SOURCE was a relative symlink (so no "/" as prefix, need to resolve it relative to the symlink base directory
# [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
# done
# DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
# echo "$DIR/node_modules/.bin"
# }
if [ "$SOLIDITY_COVERAGE" = true ]; then
testrpc_port=8555
else
testrpc_port=8545
fi
testrpc_running() {
nc -z localhost "$testrpc_port"
}
start_testrpc() {
if [ "$SOLIDITY_COVERAGE" = true ]; then
testrpc-sc -i 16 --gasLimit 0xfffffffffff --port "$testrpc_port" >/dev/null &
elif [ "$TRUFFLE_TEST" = true ]; then
ganache-cli -i 15 --gasLimit 50000000 --port "$testrpc_port" >/dev/null &
fi
testrpc_pid=$!
}
if testrpc_running; then
echo "Killing testrpc instance at port $testrpc_port"
# TODO: Fails when multiple processes are open (should check for each)
kill -9 "$(lsof -i:"$testrpc_port" -t)"
fi
echo "Starting our own testrpc instance at port $testrpc_port"
start_testrpc
sleep 5
# Exit error mode so the testrpc instance always gets killed
set +e
result=0
if [ "$SOLIDITY_COVERAGE" = true ]; then
solidity-coverage "$@"
result=$?
elif [ "$TRUFFLE_TEST" = true ]; then
truffle test --network development "$@" | grep -v 'Compiling'
result=$?
fi
kill -9 $testrpc_pid
exit $result