|
1 |
| -#!/bin/bash |
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Exit script as soon as a command fails. |
| 4 | +set -o errexit |
2 | 5 |
|
3 | 6 | # Executes cleanup function at script exit.
|
4 | 7 | trap cleanup EXIT
|
5 | 8 |
|
6 | 9 | cleanup() {
|
7 |
| - # Kill the testrpc instance that we started (if we started one). |
8 |
| - if [ -n "$testrpc_pid" ]; then |
| 10 | + # Kill the testrpc instance that we started (if we started one and if it's still running). |
| 11 | + if [ -n "$testrpc_pid" ] && ps -p $testrpc_pid > /dev/null; then |
9 | 12 | kill -9 $testrpc_pid
|
10 | 13 | fi
|
11 | 14 | }
|
12 | 15 |
|
| 16 | +testrpc_port=8545 |
| 17 | + |
13 | 18 | testrpc_running() {
|
14 |
| - nc -z localhost 8545 |
| 19 | + nc -z localhost "$testrpc_port" |
| 20 | +} |
| 21 | + |
| 22 | +start_testrpc() { |
| 23 | + # We define 10 accounts with balance 1M ether, needed for high-value tests. |
| 24 | + local accounts=( |
| 25 | + --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501200,1000000000000000000000000" |
| 26 | + --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501201,1000000000000000000000000" |
| 27 | + --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501202,1000000000000000000000000" |
| 28 | + --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501203,1000000000000000000000000" |
| 29 | + --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501204,1000000000000000000000000" |
| 30 | + --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501205,1000000000000000000000000" |
| 31 | + --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501206,1000000000000000000000000" |
| 32 | + --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501207,1000000000000000000000000" |
| 33 | + --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501208,1000000000000000000000000" |
| 34 | + --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501209,1000000000000000000000000" |
| 35 | + --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501210,1000000000000000000000000" |
| 36 | + ) |
| 37 | + |
| 38 | + node_modules/.bin/testrpc --gasLimit 0xfffffffffff "${accounts[@]}" > /dev/null & |
| 39 | + |
| 40 | + testrpc_pid=$! |
15 | 41 | }
|
16 | 42 |
|
17 | 43 | if testrpc_running; then
|
18 | 44 | echo "Using existing testrpc instance"
|
19 | 45 | else
|
20 |
| - echo "Starting our own testrpc node instance" |
21 |
| - |
22 |
| - testrpc \ |
23 |
| - --account="0xe8280389ca1303a2712a874707fdd5d8ae0437fab9918f845d26fd9919af5a92,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \ |
24 |
| - --account="0xed095a912033d26dc444d2675b33414f0561af170d58c33f394db8812c87a764,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \ |
25 |
| - --account="0xf5556ca108835f04cd7d29b4ac66f139dc12b61396b147674631ce25e6e80b9b,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \ |
26 |
| - --account="0xd1bea55dd05b35be047e409617bc6010b0363f22893b871ceef2adf8e97b9eb9,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \ |
27 |
| - --account="0xfc452929dc8ffd956ebab936ed0f56d71a8c537b0393ea9da4807836942045c5,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \ |
28 |
| - --account="0x12b8b2fe49596ab7f439d324797f4b5457b5bd34e9860b08828e4b01af228d93,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \ |
29 |
| - --account="0x2ed88e3846387d0ae4cca96637df48c201c86079be64d0a17bf492058db6c6eb,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \ |
30 |
| - --account="0x8c6690649d0b31790fceddd6a59decf2b03686bed940a9b85e8105c5e82f7a86,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \ |
31 |
| - --account="0xf809d1a2969bec37e7c14628717092befa82156fb2ebf935ac5420bc522f0d29,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \ |
32 |
| - --account="0x38062255973f02f1b320d8c7762dd286946b3e366f73076995dc859a6346c2ec,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \ |
33 |
| - --account="0x35b5042e809eab0db3252bad02b67436f64453072128ee91c1d4605de70b27c1,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \ |
34 |
| - --gasLimit 6000000 \ |
35 |
| - > /dev/null & |
36 |
| - testrpc_pid=$! |
| 46 | + echo "Starting our own testrpc instance" |
| 47 | + start_testrpc |
37 | 48 | fi
|
38 | 49 |
|
39 |
| -./node_modules/.bin/truffle compile |
40 |
| -./node_modules/.bin/truffle test $@ |
| 50 | +node_modules/.bin/truffle test "$@" |
0 commit comments