forked from stellar/system-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start
executable file
·229 lines (199 loc) · 7.49 KB
/
start
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
#! /usr/bin/env bash
set -e
set -o pipefail
# the versions of software that tests will use
SOROBAN_EXAMPLES_GIT_HASH="main"
SOROBAN_EXAMPLES_REPO_URL="https://github.com/stellar/soroban-examples.git"
DEBUG_MODE=
# the target network under test
TARGET_NETWORK=
TARGET_NETWORK_PASSPHRASE="Standalone Network ; February 2017"
TARGET_NETWORK_SECRET_KEY="SC5O7VZUXDJ6JBDSZ74DSERXL7W3Y5LTOAMRF7RQRL3TAGAPS7LUVG3L"
TARGET_NETWORK_PUBLIC_KEY="GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI"
TARGET_NETWORK_RPC_URL=
QUICKSTART_LOG_FILE=/var/log/system-test-quickstart.log
LOCAL_CORE=false
ENABLE_SOROBAN_DIAGNOSTIC_EVENTS=--enable-soroban-diagnostic-events
# example filter for all combos of one scenario outline: ^TestDappDevelop$/^DApp developer compiles, deploys and invokes a contract.*$
# each row in example data for a scenario outline is postfixed with '#01', '#02', example:
# TestDappDevelop/DApp developer compiles, deploys and invokes a contract#01
TEST_FILTER=""
VERBOSE_OUTPUT=false
CANCELLED=false
# the relative path to runtime directory on image that feature files will be found at
# these files are aggregated into this directory by Dockerfile
FEATURE_PATH=.
function print_screen_output() {
echo "$1"
}
print_screen_output "Starting system test ..."
trap printout SIGINT
printout() {
echo "Cancelling and exit."
exit
}
trap finish EXIT
function finish {
if [ -z "$TARGET_NETWORK_RPC_URL" ] && [ $? -ne 0 ] && [ "$VERBOSE_OUTPUT" != "true" ]; then
# dump the local server logs if they were running in container.
echo "" >&2
echo "" >&2
echo "dumping system log output $QUICKSTART_LOG_FILE ..." >&2
echo "" >&2
echo "" >&2
cat $QUICKSTART_LOG_FILE >&2
fi
CANCELLED=true
if [ "$DEBUG_MODE" = "true" ]; then
print_screen_output "** DEBUG MODE Enabled **"
read -p 'Debug mode, you can shell into the container now, hit enter to let container stop: '
fi
}
function main() {
process_args "$@"
if [ ! -z "$TARGET_NETWORK_RPC_URL" ] && [ ! -z "$TARGET_NETWORK" ]; then
echo "Invalid TargetNetwork config, must set TargetNetwork or TargetNetworkRPCURL, aborting test ..." >&2
exit 1
fi
if [ -z "$TARGET_NETWORK_RPC_URL" ] && \
[ "$TARGET_NETWORK" != "standalone" ] && \
[ "$TARGET_NETWORK" != "local" ] && \
[ "$TARGET_NETWORK" != "futurenet" && ] && \
[ "$TARGET_NETWORK" != "testnet" && ]; then
echo "Invalid TargetNetwork, must be one of: standalone or local(both mean the same), futurenet, or testnet, aborting test ..." >&2
exit 1
fi
if [ -z "$TARGET_NETWORK_RPC_URL" ]; then
TARGET_NETWORK_RPC_URL=http://localhost:8000/soroban/rpc
LOCAL_CORE=true
print_screen_output "starting target stack on $TARGET_NETWORK with following server versions:"
print_screen_output " CORE VERSION=$(stellar-core version 2>/dev/null || echo "n/a")"
print_screen_output " HORIZON VERSION=$(stellar-horizon version 2>/dev/null || echo "n/a")"
print_screen_output " SOROBAN RPC VERSION=$(stellar-soroban-rpc version 2>/dev/null || echo "n/a")"
if [ "$TARGET_NETWORK" = "futurenet" ]; then
TARGET_NETWORK_PASSPHRASE="Test SDF Future Network ; October 2022"
fi
if [ "$VERBOSE_OUTPUT" = "true" ]; then
# redirects all quickstart output to console during test execution
/start --$TARGET_NETWORK --enable-soroban-rpc $ENABLE_SOROBAN_DIAGNOSTIC_EVENTS --logs 2>&1 &
else
# don't show any quickstart output on console during test execution
# all quickstart output is redirected(buffering disabled) to log file, which will be dumped to
# console if tests fail.
stdbuf -o0 -e0 /start --$TARGET_NETWORK --enable-soroban-rpc $ENABLE_SOROBAN_DIAGNOSTIC_EVENTS --logs >> $QUICKSTART_LOG_FILE 2>&1 &
fi
fi
soroban_rpc_status
# quickstart runs horizon, but sys tests don't need it.
if [ "$LOCAL_CORE" = "true" ]; then
supervisorctl stop horizon
fi
print_screen_output " RUST_TOOLCHAIN_VERSION=$(rustc --version 2>/dev/null || echo"n/a" )"
print_screen_output " SOROBAN_CLI_CRATE_VERSION=$(soroban version 2>/dev/null || echo "n/a" )"
print_screen_output " SOROBAN_EXAMPLES_GIT_HASH=$SOROBAN_EXAMPLES_GIT_HASH"
print_screen_output " SOROBAN_EXAMPLES_REPO_URL=$SOROBAN_EXAMPLES_REPO_URL"
print_screen_output " TARGET_NETWORK=$TARGET_NETWORK"
print_screen_output " TARGET_NETWORK_PASSPHRASE=$TARGET_NETWORK_PASSPHRASE"
print_screen_output " TARGET_NETWORK_SECRET_KEY=$TARGET_NETWORK_SECRET_KEY"
print_screen_output " TARGET_NETWORK_PUBLIC_KEY=$TARGET_NETWORK_PUBLIC_KEY"
print_screen_output " TARGET_NETWORK_RPC_URL=$TARGET_NETWORK_RPC_URL"
print_screen_output " TEST_FILTER=${TEST_FILTER}"
print_screen_output "Tests can now begin ..."
cd /home/tester/bin
export SorobanExamplesGitHash=${SOROBAN_EXAMPLES_GIT_HASH}
export SorobanExamplesRepoURL=${SOROBAN_EXAMPLES_REPO_URL}
export TargetNetworkPassPhrase="${TARGET_NETWORK_PASSPHRASE}"
export TargetNetworkSecretKey=${TARGET_NETWORK_SECRET_KEY}
export TargetNetworkPublicKey=${TARGET_NETWORK_PUBLIC_KEY}
export TargetNetworkRPCURL=${TARGET_NETWORK_RPC_URL}
export VerboseOutput=${VERBOSE_OUTPUT}
export LocalCore=${LOCAL_CORE}
export FeaturePath=${FEATURE_PATH}
for file in ./*;
do
if [ "$CANCELLED" = "true" ]; then
break
fi
if [[ "$file" =~ ^.*\.bin$ ]]; then
# these bin files were compiled from go feature tests in the Dockerfile during image build
print_screen_output "Running test binary ${file} ... "
${file} -test.v ${TEST_FILTER}
fi
done
}
function process_args() {
while [[ -n "$1" ]]; do
ARG="$1"
shift
case "${ARG}" in
--DebugMode)
DEBUG_MODE="$1"
shift
;;
--SorobanExamplesGitHash)
SOROBAN_EXAMPLES_GIT_HASH="$1"
shift
;;
--SorobanExamplesRepoURL)
SOROBAN_EXAMPLES_REPO_URL="$1"
shift
;;
--TestFilter)
TEST_FILTER="-test.run ""$1"""
shift
;;
--VerboseOutput)
VERBOSE_OUTPUT="$1"
shift
;;
--TargetNetwork)
TARGET_NETWORK="$1"
shift
;;
--TargetNetworkPassphrase)
TARGET_NETWORK_PASSPHRASE="$1"
shift
;;
--TargetNetworkTestAccountSecret)
TARGET_NETWORK_SECRET_KEY="$1"
shift
;;
--TargetNetworkTestAccountPublic)
TARGET_NETWORK_PUBLIC_KEY="$1"
shift
;;
--TargetNetworkRPCURL)
TARGET_NETWORK_RPC_URL="$1"
shift
;;
*)
esac
done
if [ -z "$TARGET_NETWORK_RPC_URL" ] && [ -z "$TARGET_NETWORK" ]; then
TARGET_NETWORK=local
fi
}
function soroban_rpc_status () {
print_screen_output "waiting for soroban rpc to report ready state..."
COUNTER=1
while ! $(curl --silent --location --request POST "$TARGET_NETWORK_RPC_URL" \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"id": 10235,
"method": "getHealth"
}' | jq --exit-status '.result.status == "healthy"' 2>/dev/null | grep -o true || echo false );
do
if [ $(expr $COUNTER % 12) -eq 0 ]; then
print_screen_output "waited $(expr $COUNTER / 12) minutes for soroban rpc to report ready state..."
fi
COUNTER=$[$COUNTER +1]
if [ $COUNTER -gt 900 ]; then
echo "Waited longer than 15 minutes for rpc, cancelling and exit."
exit
fi
sleep 5
done
print_screen_output "soroban rpc reported ready status, the service can be used by tools/cli now ..."
}
main "$@"