forked from tophat1720/eris-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_chains_make.sh
More file actions
executable file
·313 lines (284 loc) · 6.77 KB
/
test_chains_make.sh
File metadata and controls
executable file
·313 lines (284 loc) · 6.77 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
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
#!/usr/bin/env bash
# ----------------------------------------------------------
# Other variables
repo=`pwd`
was_running=0
test_exit=0
chains_dir=$HOME/.monax/chains
# Use the current built target, if it exists
# Otherwise default to system wide executable
COMMIT_SHA=$(git rev-parse --short --verify HEAD)
cli_exec="$GOPATH/src/github.com/monax/cli/target/cli-${COMMIT_SHA}"
if ! [ -e $cli_exec ]
then
cli_exec="monax"
fi
export MONAX_PULL_APPROVE="true"
export MONAX_MIGRATE_APPROVE="true"
# ---------------------------------------------------------------------------
# Needed functionality
ensure_running(){
if [[ "$($cli_exec ls -format {{.ShortName}} | grep $1)" == "$1" ]]
then
echo "$1 already started. Not starting."
was_running=1
else
echo "Starting service: $1"
$cli_exec services start $1 1>/dev/null
early_exit
sleep 3 # boot time
fi
}
early_exit(){
if [ $? -eq 0 ]
then
return 0
fi
echo "There was an error duing setup; keys were not properly imported. Exiting."
if [ "$was_running" -eq 0 ]
then
if [ "$ci" = true ]
then
$cli_exec services stop keys
else
$cli_exec services stop -r keys
fi
fi
exit 1
}
get_uuid() {
if [[ "$(uname -s)" == "Linux" ]]
then
uuid=$(cat /proc/sys/kernel/random/uuid | tr -dc 'a-zA-Z0-9' | fold -w 12 | head -n 1)
elif [[ "$(uname -s)" == "Darwin" ]]
then
uuid=$(uuidgen | tr -dc 'a-zA-Z0-9' | fold -w 12 | head -n 1)
else
uuid="62d1486f0fe5"
fi
echo $uuid
}
test_setup(){
ensure_running keys
}
check_test(){
# check chain is running
chain=( $($cli_exec ls --running --format {{.ShortName}} | grep $uuid) )
if [ "$chain" != "$uuid" ]
then
echo "chain does not appear to be running"
echo
ls -la $dir_to_use
test_exit=1
return 1
fi
# check results file exists
if [ ! -e "$chains_dir/$uuid/accounts.csv" ]
then
echo "accounts.csv not present"
ls -la $chains_dir/$uuid
pwd
ls -la $chains_dir
test_exit=1
return 1
fi
# check genesis.json
genOut=$(cat $dir_to_use/genesis.json | sed 's/[[:space:]]//g')
genIn=$($cli_exec chains exec $uuid "cat /home/monax/.monax/chains/$uuid/genesis.json" | sed 's/[[:space:]]//g')
if [[ "$genOut" != "$genIn" ]]
then
test_exit=1
echo "genesis.json's do not match"
echo
echo "expected"
echo
echo -e "$genOut"
echo
echo "received"
echo
echo -e "$genIn"
echo
echo "difference"
echo
diff <(echo "$genOut" ) <(echo "$genIn") | colordiff
return 1
fi
# check priv_validator
privOut=$(cat $dir_to_use/priv_validator.json | tr '\n' ' ' | sed 's/[[:space:]]//g' | set 's/(,\"last_height\":[^0-9]+,\"last_round\":[^0-9]+,\"last_step\":[^0-9]+//g' )
privIn=$($cli_exec chains exec $uuid "cat /home/monax/.monax/chains/$uuid/priv_validator.json" | tr '\n' ' ' | sed 's/[[:space:]]//g' | set 's/(,\"last_height\":[^0-9]+,\"last_round\":[^0-9]+,\"last_step\":[^0-9]+//g' )
if [[ "$privOut" != "$privIn" ]]
then
test_exit=1
echo "priv_validator.json's do not match"
echo
echo "expected"
echo
echo -e "$privOut"
echo
echo "received"
echo
echo -e "$privIn"
echo
echo "difference"
echo
diff <(echo "$privOut" ) <(echo "$privIn") | colordiff
return 1
fi
}
run_test(){
if [ $? -ne 0 ]
then
test_exit=1
return 1
fi
dir_to_use=$chains_dir/$uuid/$direct
$cli_exec chains start $uuid --init-dir $uuid/$direct
if [ $? -ne 0 ]
then
test_exit=1
return 1
fi
sleep 3 # let 'er boot
check_test
if [ $? -ne 0 ]
then
test_exit=1
fi
$cli_exec chains stop --force $uuid
if [ ! "$ci" = true ]
then
$cli_exec chains rm --data $uuid
fi
rm -rf $HOME/.monax/scratch/data/$uuid
rm -rf $chains_dir/$uuid
}
perform_tests(){
echo
echo "single account-type test"
uuid=$(get_uuid)
direct="$uuid"_full_000
$cli_exec chains make $uuid --account-types=Full:1 --unsafe
run_test
if [ $test_exit -eq 1 ]
then
return 1
fi
echo
echo "more complex flags test"
uuid=$(get_uuid)
direct="$uuid"_validator_000
$cli_exec chains make $uuid --account-types=Root:2,Developer:2,Participant:2,Validator:1 --unsafe
run_test
if [ $test_exit -eq 1 ]
then
return 1
fi
echo
echo "assume simplechain test"
uuid=$(get_uuid)
direct="$uuid"_full_000
$cli_exec chains make $uuid --unsafe
run_test
if [ $test_exit -eq 1 ]
then
return 1
fi
echo
echo "add a new account type test"
uuid=$(get_uuid)
direct="$uuid"_test_000
cp $repo/tests/cm_test_fixtures/tester.toml $chains_dir/account-types/.
$cli_exec chains make $uuid --account-types=Test:1 --unsafe
run_test
if [ $test_exit -eq 1 ]
then
return 1
fi
rm $chains_dir/account-types/tester.toml
echo
echo "add a new chain type test"
uuid=$(get_uuid)
direct="$uuid"_full_000
cp $repo/tests/cm_test_fixtures/testchain.toml $chains_dir/chain-types/.
$cli_exec chains make $uuid --chain-type=testchain --unsafe
run_test
if [ $test_exit -eq 1 ]
then
return 1
fi
rm $chains_dir/chain-types/testchain.toml
echo
echo "export/inspect tars"
uuid=$(get_uuid)
direct=""
$cli_exec chains make $uuid --account-types=Full:2 --output tar --unsafe
if [ $? -ne 0 ]
then
test_exit=1
return 1
fi
tar -xzf $chains_dir/$uuid/"$uuid"_full_000.tar.gz -C $chains_dir/$uuid/.
run_test
if [ $test_exit -eq 1 ]
then
return 1
fi
echo
# # export/inspect zips
# # todo
echo "make a known chain using csv test"
uuid=$(get_uuid)
direct="$uuid"_full_000
$cli_exec chains make $uuid --account-types=Full:1 --unsafe
if [ $? -ne 0 ]
then
test_exit=1
return 1
fi
rm $chains_dir/$uuid/$direct/genesis.json
prev_dir=`pwd`
gen=$($cli_exec chains make $uuid --known --accounts $chains_dir/$uuid/accounts.csv --validators $chains_dir/$uuid/validators.csv --unsafe)
echo "$gen" > $chains_dir/$uuid/$direct/genesis.json
run_test
cd $prev_dir
if [ $test_exit -eq 1 ]
then
return 1
fi
echo
}
test_teardown(){
if [ -z "$ci" ]
then
echo
if [ "$was_running" -eq 0 ]
then
$cli_exec services stop -rx keys
fi
echo
fi
if [ "$test_exit" -eq 0 ]
then
echo "Tests complete! Tests are Green. :)"
else
echo "Tests complete. Tests are Red. :("
fi
cd $start
exit $test_exit
}
# ---------------------------------------------------------------------------
# Get the things build and dependencies turned on
echo "Hello! I'm the marmot that tests the [monax chains make] command"
echo
echo "testing with target $cli_exec"
echo
start=`pwd`
cd $repo
test_setup
# ---------------------------------------------------------------------------
# Go!
echo "Running Tests..."
perform_tests
# ---------------------------------------------------------------------------
# Cleaning up
test_teardown