-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdev-ganache.bash
More file actions
executable file
·177 lines (131 loc) · 4.42 KB
/
dev-ganache.bash
File metadata and controls
executable file
·177 lines (131 loc) · 4.42 KB
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
174
175
176
177
#!/usr/bin/env bash
# ---------------------------------------------------------------------------- #
major="${BASH_VERSINFO[0]}"
minor="${BASH_VERSINFO[1]}"
if (( major < 4 || (major == 4 && minor < 3) )); then
>&2 echo "Bash 4.3 or above is required."
exit 1
fi
set -o errexit -o pipefail -o nounset
# get script directory
script_dir="$( cd "$( dirname "$0" )" && pwd )"
# load utilities
source "${script_dir}/common.bash"
# ---------------------------------------------------------------------------- #
# print help
if (( $# == 0 )); then
>&2 printf "\
Usage: $0 [options...] <venv_dir>
Runs a development Create-React-App server and a development Django
server locally with a SQLite database, and uses a local Ganache test
network.
This script creates a Python venv at <venv_dir> and installs all
dependencies there. All database and Ganache network state is also
stored there.
A TuiChain Ethereum master account is generated and used to deploy the
controller contract. Five user accounts are also generated. A mock
ERC-20 contract mimicking the actual Dai contract is deployed in the
test network. All accounts are credited with 100 ether and 100 000 Dai.
This script is idempotent: if any of the steps was already run on the
same <venv_dir>, they are not repeated, and all database and network
state is maintained between runs.
Options:
--frontend @<hash_or_branch>
--frontend <local_dir>
If the argument starts with @, use the frontend component at the
commit with the given (full) hash or at the given branch of its
repo. Otherwise use the component in the given local directory.
(default is branch main)
--backend @<hash_or_branch>
--backend <local_dir>
If the argument starts with @, use the backend component at the
commit with the given (full) hash or at the given branch of its
repo. Otherwise use the component in the given local directory.
(default is branch main)
--blockchain @<hash_or_branch>
--blockchain <local_dir>
If the argument starts with @, use the blockchain component at the
commit with the given (full) hash or at the given branch of its
repo. Otherwise use the component in the given local directory.
(default is branch main)
--no-populate
Don't populate the application state with test data.
--ganache-verbose
Log requests sent to Ganache.
"
exit 2
fi
# parse arguments
while (( $# > 0 )); do
case "$1" in
--frontend)
__ensure_option_has_value "$@"
frontend_dir="$2"
shift
shift
;;
--backend)
__ensure_option_has_value "$@"
backend_dir="$2"
shift
shift
;;
--blockchain)
__ensure_option_has_value "$@"
blockchain_dir="$2"
shift
shift
;;
--no-populate)
no_populate=1
shift
;;
--ganache-verbose)
ganache_verbose=1
shift
;;
-*)
__bad_usage "Unknown option $1"
;;
*)
if [[ -z "${venv_dir+x}" ]]; then
venv_dir="$1"
shift
else
__bad_usage "Unexpected argument $1"
fi
;;
esac
done
[[ ! -z "${venv_dir+x}" ]] || __bad_usage "Missing argument <venv_dir>"
num_user_accounts=5
# ---------------------------------------------------------------------------- #
function __set_up_ethereum_network()
{
# install Ganache
if ! npx ganache-cli --help > /dev/null 2>&1; then
__log "Installing Ganache..."
npm install --silent ganache-cli
fi
# start Ganache
local accounts
accounts=( ${keys[@]/#/0x} )
accounts=( ${accounts[@]/%/,100000000000000000000} )
__log "Starting Ganache test network..."
[[ -z "${ganache_verbose:-}" ]] &&
ganache_quiet='/dev/null' ||
ganache_quiet='/dev/stdout'
npx ganache-cli \
--accounts 0 \
${accounts[@]/#/--account } \
--db ganache \
--port 8545 \
--keepAliveTimeout 100000000 \
--secure \
> "${ganache_quiet}" \
&
while ! nc -z localhost 8545 > /dev/null 2>&1; do sleep 1; done
network_url=http://localhost:8545/
}
__do_things "Local Ganache test network" : __set_up_ethereum_network
# ---------------------------------------------------------------------------- #