-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_e2e_tests.sh
executable file
·178 lines (146 loc) · 5.13 KB
/
run_e2e_tests.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
#!/usr/bin/env bash
set -e # Exit on error
set -o pipefail # Exit if any command in a pipeline fails
set -u # Treat unset variables as errors
# Define paths
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
E2E_DIR="$ROOT_DIR/e2e_tests"
TESTS_DIR="$E2E_DIR/test/spec"
APPLICATIONS_DIR="$E2E_DIR/applications"
VERSION=$(grep '__version__' ./src/version.py | awk -F'=' '{print $2}' | tr -d ' "' | xargs)
APP1_NAME=$(grep '^APP1_NAME' accessible_constant.py | awk -F'=' '{print $2}' | tr -d ' "' | xargs)
APP2_NAME=$(grep '^APP2_NAME' accessible_constant.py | awk -F'=' '{print $2}' | tr -d ' "' | xargs)
# Paths for the built applications
FIRST_WALLET_NAME="iriswallet_${APP1_NAME}-${VERSION}-x86_64.AppImage"
SECOND_WALLET_NAME="iriswallet_${APP2_NAME}-${VERSION}-x86_64.AppImage"
APP1_PATH="$APPLICATIONS_DIR/$FIRST_WALLET_NAME"
APP2_PATH="$APPLICATIONS_DIR/$SECOND_WALLET_NAME"
# Paths for constants file
CONSTANT_FILE="./src/utils/constant.py"
BACKUP_FILE="./src/utils/constant_backup.py"
# Command-line arguments
TEST_FILE=""
RUN_ALL=false
FORCE_BUILD=false
WALLET_MODES=()
# Parse command-line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--force-build)
FORCE_BUILD=true
shift
;;
--all)
RUN_ALL=true
shift
;;
--wallet-mode)
if [[ -n "$2" ]]; then
WALLET_MODES+=("$2")
shift 2
else
echo "Error: --wallet-mode requires a value (embedded or remote)."
exit 1
fi
;;
*)
TEST_FILE=$1
shift
;;
esac
done
# Default to both wallet modes if none are specified
if [[ ${#WALLET_MODES[@]} -eq 0 ]]; then
WALLET_MODES=("embedded" "remote")
fi
# Ensure constants are restored if the script exits unexpectedly
trap restore_constants EXIT
# Function to temporarily modify constants before build
modify_constants() {
echo "Modifying constants for testing..."
[[ ! -f "$BACKUP_FILE" ]] && cp "$CONSTANT_FILE" "$BACKUP_FILE"
sed -i -E "
s|BITCOIND_RPC_HOST_REGTEST = 'regtest-bitcoind.rgbtools.org'|BITCOIND_RPC_HOST_REGTEST = 'localhost'|;
s|BITCOIND_RPC_PORT_REGTEST = 80|BITCOIND_RPC_PORT_REGTEST = 18443|;
s|INDEXER_URL_REGTEST = 'electrum.rgbtools.org:50041'|INDEXER_URL_REGTEST = '127.0.0.1:50001'|;
s|PROXY_ENDPOINT_REGTEST = 'rpcs://proxy.iriswallet.com/0.2/json-rpc'|PROXY_ENDPOINT_REGTEST = 'rpc://127.0.0.1:3000/json-rpc'|;
" "$CONSTANT_FILE"
echo "Constants modified."
}
# Function to restore original constants after build
restore_constants() {
if [[ -f "$BACKUP_FILE" ]]; then
echo "Restoring original constants..."
mv -f "$BACKUP_FILE" "$CONSTANT_FILE"
echo "Original constants restored."
fi
}
# Function to move an application after it is built
move_application() {
local app_name=$1
local app_path="$ROOT_DIR/$app_name"
echo "Moving $app_name to $APPLICATIONS_DIR..."
mkdir -p "$APPLICATIONS_DIR"
if [[ -f "$app_path" ]]; then
mv -f "$app_path" "$APPLICATIONS_DIR/"
echo "$app_name moved successfully."
else
echo "Error: $app_name not found at $app_path"
exit 1
fi
}
# Function to build applications if they are missing
build_applications() {
echo "Building applications..."
cd "$ROOT_DIR" || exit 1
# Modify constants before build
modify_constants
echo "Building first wallet..."
build-iris-wallet --network regtest --distribution appimage --app-name "${APP1_NAME}" &
wait $!
move_application "$FIRST_WALLET_NAME"
echo "Building second wallet..."
build-iris-wallet --network regtest --distribution appimage --app-name "${APP2_NAME}" &
wait $!
move_application "$SECOND_WALLET_NAME"
echo "Build process completed."
}
ensure_applications_exist() {
if [[ "$FORCE_BUILD" == true ]]; then
echo "--force-build flag detected. Rebuilding applications..."
build_applications
exit 0
fi
if [[ ! -f "$APP1_PATH" || ! -f "$APP2_PATH" ]]; then
echo "One or both applications are missing. Initiating build..."
build_applications
else
echo "Both applications are available. Proceeding with tests."
fi
}
run_e2e_tests() {
local wallet_mode=$1
local results_dir="allure-results-${wallet_mode}"
echo "Running E2E tests with wallet mode: $wallet_mode"
rm -rf "$results_dir"
mkdir -p "$results_dir"
if [[ "$RUN_ALL" == true ]]; then
echo "Running full test suite..."
pytest -s "$TESTS_DIR/" --alluredir="$results_dir" --wallet-mode "$wallet_mode"
elif [[ -n "$TEST_FILE" ]]; then
echo "Running single test file: $TEST_FILE"
pytest -s "$TESTS_DIR/$TEST_FILE" --alluredir="$results_dir" --wallet-mode "$wallet_mode"
else
echo "No test file provided. Use --all to run all tests."
exit 1
fi
if [[ $? -ne 0 ]]; then
echo "E2E tests failed!"
exit 1
fi
}
ensure_applications_exist
for mode in "${WALLET_MODES[@]}"; do
run_e2e_tests "$mode"
done
echo "Setup and tests completed successfully!"