-
Notifications
You must be signed in to change notification settings - Fork 8
/
setup.sh
executable file
·370 lines (324 loc) · 13.9 KB
/
setup.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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
#!/bin/sh
# This script prepares the test environment as follows:
# - A solc binary path is queried from the user to use for compilation
# - A settings.cfg.sh file is created that can be source'd by the
# framework scripts to obtain the environment variables $SOLC_BINARY_PATH
# and an updated $PATH including fast-solc-js
#
# Arguments:
# --use-defaults - use default values instead of interactive questions
# --solc-path=<path> - path to solc binary
# --nodejs-path=<path> - path to directory containing npm/node to use
#
# If ./builddeps exists, dependencies will be used from it if available:
# ./builddeps/go.tgz - go installation package
# ./builddeps/go-ethereum - cloned geth repository
# ./builddeps/solc - solc binary
GENERATED_SETTINGS_FILE="settings.cfg.sh"
# Cleanup in case of reinstallation
rm -rf go-ethereum
rm -rf test-env-truffle/node_modules
verify_solc_path() {
if ! test -x "$SELECTED_COMPILER"; then
return 1
else
return 0
fi
}
verify_nodejs_path() {
NODE_BIN_FILE_PATH_NODE=`realpath "$SELECTED_NODE_DIR/node"`
NODE_BIN_FILE_PATH_NPM=`realpath "$SELECTED_NODE_DIR/npm"`
if ! test -x "$NODE_BIN_FILE_PATH_NODE" || ! test -x "$NODE_BIN_FILE_PATH_NPM"; then
return 1
else
return 0
fi
}
while test "$#" != 0; do
arg_part_one=`echo $1 | awk -F'=' '{print $1}'`
arg_part_two=`echo $1 | awk -F'=' '{print $2}'`
if test "$arg_part_one" = --use-defaults; then
USE_DEFAULTS=yes
elif test "$arg_part_one" = --solc-path; then
SELECTED_COMPILER="$arg_part_two"
if ! verify_solc_path "$SELECTED_COMPILER"; then
echo "Error: $SELECTED_COMPILER does not appear to be an executable binary file"
exit 1
fi
elif test "$arg_part_one" = --nodejs-path; then
SELECTED_NODE_DIR="$arg_part_two"
echo SELECTED_NODE_DIr = "$SELECTED_NODE_DIR"
if ! verify_nodejs_path; then
echo Error: "$SELECTED_NODE_DIR" does not contain executable node and npm binaries
exit 1
fi
else
echo Invalid argument. Available arguments:
echo " --use-defaults - use default values instead of interactive questions"
echo " --solc-path=<path> - path to solc binary"
echo " --nodejs-path=<path> - path to directory containing npm/node to use (must be >v10)"
exit 1
fi
shift
done
echo Starting test framework setup ...
echo Building soltix...
CURDIR=`pwd`
LOGDIR="$PWD/_setup-logs"
if ! test -d "$LOGDIR"; then
mkdir "$LOGDIR"
fi
BUILDLOG="$LOGDIR"/build.log
if ! cd soltix || ! mvn install >"$BUILDLOG" 2>&1; then
cat "$BUILDLOG"
echo
echo "Error: Could not build soltix. This could indicate that one of the following is missing:"
echo " General build tools - sudo apt-get install build-essential"
echo " Java SDK 8+ - sudo apt-get install openjdk-8-jdk"
echo " Maven - sudo apt-get install maven"
echo "See also Dockerfile for dependencies installation."
echo "See also log output in $BUILDLOG or above"
exit 1
fi
cd "$CURDIR"
echo Building tools...
cd tools/coordinator
if ! mvn install >/dev/null 2>&1; then
echo Error: cannot build coordination tools for cloud processing
echo Proceeding anyway...
fi
cd "$CURDIR"
#echo Building helper tools...
#MAKELOG="$LOGDIR"/tools.log
#cd soltix/bin
#if ! make >"$MAKELOG" 2>&1; then
# echo Build error - see log "$MAKELOG"
# exit 1
#fi
#cd "$CURDIR"
BUILDDEPS="$PWD/builddeps"
INSTALLED_SOLC=`whereis solc | awk '{print $2}'`
# 1. Select compiler binary - using the current solc static binary as initial suggestion
# TODO use truffle external compiler function to reference the selected binary as well
SOLC_VERSION_5="0.5.9"
USER_INPUT=""
echo The test framework needs a solc compiler binary at least for code parsing.
echo To compile and run a program, the same solc binary or solc-js can be used.
echo
echo settings.cfg will be generated. It can be used to configure the choice between
echo a solc binary and solcjs, optimization settings, and other things.
echo
echo Generated code currently always complies with 0.5 language rules and does not use
echo 0.4 language-specific constructs anymore.
echo
while test "$USER_INPUT" != y && test "$USER_INPUT" != n; do
printf "Download static solc binary version ${SOLC_VERSION_5} now? [y]: "
if test "$USE_DEFAULTS" != yes; then
read USER_INPUT
fi
if test "$USER_INPUT" = ""; then
USER_INPUT=y
fi
done
if test "$USER_INPUT" = y; then
if test -f "$BUILDDEPS"/solc; then
echo Using solc from builddeps dir
INSTALLED_SOLC="$BUILDDEPS"/solc
else
echo Downloading default solc compiler binary $SOLC_VERSION_5 ...
if ! wget https://github.com/ethereum/solidity/releases/download/v${SOLC_VERSION_5}/solc-static-linux -O solc-${SOLC_VERSION_5} >/dev/null 2>&1; then
echo Error: could not download solc compiler binary
else
INSTALLED_SOLC=$PWD/solc-${SOLC_VERSION_5}
fi
fi
chmod +x "$INSTALLED_SOLC"
fi
if ! test -x "$INSTALLED_SOLC"; then
INSTALLED_SOLC=""
echo Could not locate any installed solc binary
else
echo Located installed solc binary at $INSTALLED_SOLC
fi
while test "$SELECTED_COMPILER" = ""; do
printf "Please select the solc compiler binary path to use [$INSTALLED_SOLC]: "
if test "$USE_DEFAULTS" != yes; then
read USER_INPUT
else
USER_INPUT=""
fi
if test "$USER_INPUT" = ""; then
if test "$INSTALLED_SOLC" = ""; then
echo Error: You selected the default compiler, but no installed compiler has been found
if test "$USE_DEFAULTS" = yes; then
echo Aborting installation
exit 1
fi
else
SELECTED_COMPILER="$INSTALLED_SOLC"
fi
else
if ! verify_solc_path; then
echo Error: "$SELECTED_COMPILER" does not appear to be an executable binary file
else
SELECTED_COMPILER=`realpath "$USER_INPUT"`
fi
fi
done
# 2. Select a node version. Try to find a default option first
SELECTED_NODE_DIR=/usr/local/bin
if ! verify_nodejs_path; then
SELECTED_NODE_DIR=/usr/bin
if verify_nodejs_path; then
DEFAULT_NODE_DIR="$SELECTED_NODE_DIR"
fi
else
DEFAULT_NODE_DIR="$SELECTED_NODE_DIR"
fi
SELECTED_NODE_DIR=""
while test "$SELECTED_NODE_DIR" = ""; do
printf "Please enter the directory path containing the node and npm binaries to use [$DEFAULT_NODE_DIR]: "
if test "$USE_DEFAULTS" != yes; then
read USER_INPUT
fi
if test "$USER_INPUT" = ""; then
# Default choice
SELECTED_NODE_DIR="$DEFAULT_NODE_DIR"
break
fi
SELECTED_NODE_DIR=`realpath "$USER_INPUT"`
if ! verify_nodejs_path; then
echo Error: "$USER_INPUT" does not contain executable node and npm binaries
fi
NODE_VERSION=`"$SELECTED_NODE_DIR"/node -v | awk -F. '{print $1}' | awk -Fv '{print $2}'`
if test "$NODE_VERSION" -lt 10; then
echo Error: node version too old, must be at least v10
SELECTED_NODE_DIR=""
fi
done
echo Installing node packages...
cd test-env-truffle
NPMLOG="$LOGDIR"/npm-install.log
if ! "$SELECTED_NODE_DIR"/npm install >"$NPMLOG" 2>&1; then
echo Warning: $SELECTED_NODE_DIR/npm install in ./test-env-truffle returned an error, see "$NPMLOG" for log output.
echo If the framework works regardless, this may be ignorable
fi
# Patch truffle for external compiler invocation
if ! ../tools/patch-truffle.sh ./node_modules/.bin/truffle; then
echo Error: Cannot patch truffle - aborting setup
exit 1
fi
# 3. Obtain geth blockchain client if desired
USER_INPUT=""
while test "$USER_INPUT" != y && test "$USER_INPUT" != n; do
printf "Download and compile geth blockchain backend now (takes a while and requires recent golang)? [y]: "
if test "$USE_DEFAULTS" != yes; then
read USER_INPUT
fi
if test "$USER_INPUT" = ""; then
USER_INPUT=y
fi
done
if test "$USER_INPUT" = y; then
cd "$CURDIR"
# First check local go version.
# TODO version check?
if test -f "$BUILDDEPS"/go.tgz; then
GOLANG_DIR="./go"
if ! test -d "$GOLANG_DIR"; then
mkdir "$GOLANG_DIR"
fi
tar -C "$GOLANG_DIR" -xzf "$BUILDDEPS"/go.tgz
export PATH="$PATH:`realpath $GOLANG_DIR/go/bin`"
elif ! which go; then
# Only advise on installation
echo 'Error: cannot find go binary. Binary installation in ./go on Linux'
echo '(see also https://golang.org/doc/install#install):'
echo 'Run ./tools/golang-setup.sh and then rerun this setup.'
if test `uname -s` = Linux && test `uname -m` = x86_64; then # TODO macOS?
USER_INPUT=""
GOLANG_DIR="./go"
while test "$USER_INPUT" != y && test "$USER_INPUT" != n; do
printf "Download and extract golang to '$GOLANG_DIR' directory now? [y]: "
if test "$USE_DEFAULTS" != yes; then
read USER_INPUT
fi
if test "$USER_INPUT" = ""; then
USER_INPUT=y
fi
done
if ./tools/golang-setup.sh "$GOLANG_DIR"; then
export PATH="$PATH:`realpath $GOLANG_DIR/go/bin`"
fi
fi
fi
if ! which go; then
echo 'Aborting geth setup due to lack of go installation'
elif ! test -d "$BUILDDEPS"/go-ethereum && git clone https://github.com/ethereum/go-ethereum.git; then
echo Error: Cannot git clone go-ethereum.git - aborting geth setup
else
if test -d "$BUILDDEPS"/go-ethereum; then
echo Using go-ethereum from builddeps dir
rm -rf go-ethereum
cp -R "$BUILDDEPS"/go-ethereum go-ethereum
fi
cd go-ethereum
if ! ../tools/patch-geth.sh; then
echo Error: Cannot patch geth code - aborting geth setup
else
if ! make all; then
echo Error: make all failed - aborting geth setup
else
cd ..
GETH_PATH=`realpath ./go-ethereum/build/bin/geth`
fi
fi
fi
fi
cd "$CURDIR"
echo "# use solcjs in truffle (otherwise: invoke external solc binary)?" >"$GENERATED_SETTINGS_FILE"
echo "export USE_SOLCJS=no" >>"$GENERATED_SETTINGS_FILE"
# solcjs version - auto-installed
echo "# if USE_SOLCJS=yes - solcjs version to use (auto-installed, see https://www.npmjs.com/package/solc)" >>"$GENERATED_SETTINGS_FILE"
echo "export SOLCJS_VERSION=\"0.5.7\"" >>"$GENERATED_SETTINGS_FILE"
# solc binary - needs manual download
echo "# if USE_SOLCJS=no - absolute path of solc binary to use (see https://github.com/ethereum/solidity/releases for static Linux release binaries)" >>"$GENERATED_SETTINGS_FILE"
echo "export SOLC_BINARY_PATH=\"$SELECTED_COMPILER\"" >>"$GENERATED_SETTINGS_FILE"
echo "# blockchain backend to use - ganache or geth?" >>"$GENERATED_SETTINGS_FILE"
echo "export BLOCKCHAIN_BACKEND=ganache" >>"$GENERATED_SETTINGS_FILE"
echo "# geth binary path to use if BLOCKCHAIN_BACKEND=geth" >>"$GENERATED_SETTINGS_FILE"
echo "export GETH_PATH=\"$GETH_PATH\"" >>"$GENERATED_SETTINGS_FILE"
echo "# enable optimization? will update truffle's 'optimizer { enabled:' setting " >>"$GENERATED_SETTINGS_FILE"
echo "export USE_SOLC_OPTIMIZATION=yes" >>"$GENERATED_SETTINGS_FILE"
echo "# if optimizing - how many runs? will update truffle's 'optimizer { runs:' setting " >>"$GENERATED_SETTINGS_FILE"
echo "export SOLC_OPTIMIZATION_RUNS=200" >>"$GENERATED_SETTINGS_FILE"
echo "# if optimizing - use experimental new yul optimizer?" >>"$GENERATED_SETTINGS_FILE"
echo "export SOLC_USE_YUL_OPTIMIZER=no" >>"$GENERATED_SETTINGS_FILE"
echo "# avoid generating exponentiation (**) code - workaround for ganache-cli crashes and old solc versions" >>"$GENERATED_SETTINGS_FILE"
echo "export CODEGEN_AVOID_EXP_OPERATOR=yes" >>"$GENERATED_SETTINGS_FILE"
echo "# avoid generating shift (<<, >>) code - workaround for ganache-cli crashes" >>"$GENERATED_SETTINGS_FILE"
echo "export CODEGEN_AVOID_SHIFT_OPERATORS=yes" >>"$GENERATED_SETTINGS_FILE"
echo "# use experimental version 2 ABI encoder? Needed for constructs like structure arguments, but 20x slower">>"$GENERATED_SETTINGS_FILE"
echo "export CODEGEN_USE_ABI_ENCODER_V2=no" >>"$GENERATED_SETTINGS_FILE"
echo "# generate function arguments of struct type? Requires CODEGEN_USE_ABI_ENCODER_V2=yes which may be undesirable due to performance" >>"$GENERATED_SETTINGS_FILE"
echo "export CODEGEN_ALLOW_STRUCTS_IN_FUNCTION_ABI=no" >>"$GENERATED_SETTINGS_FILE"
echo >>"$GENERATED_SETTINGS_FILE"
echo "export NODEDIR=\"${SELECTED_NODE_DIR}\"" >>"$GENERATED_SETTINGS_FILE"
echo "export PATH=\"${PWD}/soltix/bin:${PWD}/test-env-truffle/bin:${PWD}/test-env-truffle/tools:${PWD}/test-env-truffle/tools/external-solc:${PWD}/tools:${PWD}/tools/coordinator/bin:$PATH\"" >>"$GENERATED_SETTINGS_FILE"
. ./settings.cfg.sh # "$GENERATED_SETTINGS_FILE"
echo Testing whether the framework works...
# Run one test contract
TESTLOG="$LOGDIR"/test.log
if ! cd test-env-truffle || ! echo 'contract c { uint x = 123; function f() public { return ; } }' >x.sol || ! run-one-test.sh x.sol 1 >"$TESTLOG" 2>&1; then
echo - Error: Framework does not appear to work correctly, see log "$TESTLOG"
exit 1
else
echo - Test OK - see log "$TESTLOG"
fi
cd "$CURDIR"
echo "All done - settings (accessible in node via process.env.<name>):"
echo
cat "$GENERATED_SETTINGS_FILE"
echo
echo "You can change these in settings.cfg.sh"
exit 0