-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathtrans_sync_across_mixed_cluster_test.sh
executable file
·213 lines (184 loc) · 5.61 KB
/
trans_sync_across_mixed_cluster_test.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
#!/bin/bash
###############################################################
# Test for validating transaction synchronization across cluster nodes.
# Nodes can be producing or non-producing.
# -p <producing nodes count>
# -n <total nodes>
# -s <topology>
# -d <delay between nodes startup>
###############################################################
pnodes=1
topo=mesh
delay=1
args=`getopt p:n:s:d: $*`
if [ $? == 0 ]; then
set -- $args
for i; do
case "$i"
in
-p) pnodes=$2;
shift; shift;;
-n) total_nodes=$2;
shift; shift;;
-d) delay=$2;
shift; shift;;
-s) topo="$2";
shift; shift;;
--) shift;
break;;
esac
done
else
echo "huh we got err $?"
if [ -n "$1" ]; then
pnodes=$1
if [ -n "$2" ]; then
topo=$2
if [ -n "$3" ]; then
total_nodes=$3
fi
fi
fi
fi
total_nodes="${total_nodes:-`echo $pnodes`}"
# $1 - error message
error()
{
(>&2 echo $1)
killAll
echo =================================================================
exit 1
}
verifyErrorCode()
{
rc=$?
if [[ $rc != 0 ]]; then
error "FAILURE - $1 returned error code $rc"
fi
}
killAll()
{
programs/eosio-launcher/eosio-launcher -k 15
}
cleanup()
{
rm -rf etc/eosio/node_*
rm -rf var/lib/node_*
}
# result stored in HEAD_BLOCK_NUM
getHeadBlockNum()
{
INFO="$(programs/cleos/cleos get info)"
verifyErrorCode "cleos get info"
HEAD_BLOCK_NUM="$(echo "$INFO" | awk '/head_block_num/ {print $2}')"
# remove trailing coma
HEAD_BLOCK_NUM=${HEAD_BLOCK_NUM%,}
}
waitForNextBlock()
{
getHeadBlockNum
NEXT_BLOCK_NUM=$((HEAD_BLOCK_NUM+1))
while [ "$HEAD_BLOCK_NUM" -lt "$NEXT_BLOCK_NUM" ]; do
sleep 0.25
getHeadBlockNum
done
}
# $1 - string that contains "transaction_id": "<trans id>", in it
# result <trans id> stored in TRANS_ID
getTransactionId()
{
TRANS_ID="$(echo "$1" | awk '/transaction_id/ {print $2}')"
# remove leading/trailing quotes
TRANS_ID=${TRANS_ID#\"}
TRANS_ID=${TRANS_ID%\",}
}
INITA_PRV_KEY="5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
# cleanup from last run
cleanup
# stand up nodeos cluster
launcherOpts="-p $pnodes -n $total_nodes -s $topo -d $delay"
echo Launcher options: --nodeos \"--plugin eosio::wallet_api_plugin\" $launcherOpts
programs/eosio-launcher/eosio-launcher --nodeos "--plugin eosio::wallet_api_plugin" $launcherOpts
sleep 7
startPort=8888
endport=`expr $startPort + $total_nodes`
echo startPort: $startPort
echo endPort: $endPort
# basic cluster validation
port2=$startPort
while [ $port2 -ne $endport ]; do
echo Request block 1 from node on port $port2
TRANS_INFO="$(programs/cleos/cleos --port $port2 get block 1)"
verifyErrorCode "cleos get block"
port2=`expr $port2 + 1`
done
# create 3 keys
KEYS="$(programs/cleos/cleos create key)"
verifyErrorCode "cleos create key"
PRV_KEY1="$(echo "$KEYS" | awk '/Private/ {print $3}')"
PUB_KEY1="$(echo "$KEYS" | awk '/Public/ {print $3}')"
KEYS="$(programs/cleos/cleos create key)"
verifyErrorCode "cleos create key"
PRV_KEY2="$(echo "$KEYS" | awk '/Private/ {print $3}')"
PUB_KEY2="$(echo "$KEYS" | awk '/Public/ {print $3}')"
KEYS="$(programs/cleos/cleos create key)"
verifyErrorCode "cleos create key"
PRV_KEY3="$(echo "$KEYS" | awk '/Private/ {print $3}')"
PUB_KEY3="$(echo "$KEYS" | awk '/Public/ {print $3}')"
if [ -z "$PRV_KEY1" ] || [ -z "$PRV_KEY2" ] || [ -z "$PRV_KEY3" ] || [ -z "$PUB_KEY1" ] || [ -z "$PUB_KEY2" ] || [ -z "$PUB_KEY3" ]; then
error "FAILURE - create keys"
fi
# create wallet for inita
PASSWORD_INITA="$(programs/cleos/cleos wallet create --name inita)"
verifyErrorCode "cleos wallet create"
# strip out password from output
PASSWORD_INITA="$(echo "$PASSWORD_INITA" | awk '/PW/ {print $1}')"
# remove leading/trailing quotes
PASSWORD_INITA=${PASSWORD_INITA#\"}
PASSWORD_INITA=${PASSWORD_INITA%\"}
programs/cleos/cleos wallet import --name inita --private-key $INITA_PRV_KEY
verifyErrorCode "cleos wallet import"
programs/cleos/cleos wallet import --name inita --private-key $PRV_KEY1
verifyErrorCode "cleos wallet import"
programs/cleos/cleos wallet import --name inita --private-key $PRV_KEY2
verifyErrorCode "cleos wallet import"
programs/cleos/cleos wallet import --name inita --private-key $PRV_KEY3
verifyErrorCode "cleos wallet import"
#
# Account and Transfer Tests
#
# create new account
echo Creating account testera
ACCOUNT_INFO="$(programs/cleos/cleos create account inita testera $PUB_KEY1 $PUB_KEY3)"
verifyErrorCode "cleos create account"
waitForNextBlock
# verify account created
ACCOUNT_INFO="$(programs/cleos/cleos get account testera)"
verifyErrorCode "cleos get account"
count=`echo $ACCOUNT_INFO | grep -c "staked_balance"`
if [ $count == 0 ]; then
error "FAILURE - account creation failed: $ACCOUNT_INFO"
fi
pPort=$startPort
port=$startPort
echo Producing node port: $pPort
while [ $port -ne $endport ]; do
echo Sending transfer request to node on port $port.
TRANSFER_INFO="$(programs/cleos/cleos transfer inita testera 975321 "test transfer")"
verifyErrorCode "cleos transfer"
getTransactionId "$TRANSFER_INFO"
echo Transaction id: $TRANS_ID
echo Wait for next block
waitForNextBlock
port2=$startPort
while [ $port2 -ne $endport ]; do
echo Verifying transaction exists on node on port $port2
TRANS_INFO="$(programs/cleos/cleos --port $port2 get transaction $TRANS_ID)"
verifyErrorCode "cleos get transaction trans_id of <$TRANS_INFO> from node on port $port2"
port2=`expr $port2 + 1`
done
port=`expr $port + 1`
done
killAll
cleanup
echo SUCCESS!