Repository navigation
Expand file tree
/
Copy pathpost_install_check
More file actions
executable file
·239 lines (179 loc) · 6.72 KB
/
Copy pathpost_install_check
File metadata and controls
executable file
·239 lines (179 loc) · 6.72 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
#!/usr/bin/env bash
set -euo pipefail
BASE_DIR=${XDG_CONFIG_HOME:-$HOME}
DOJO_DIR=${DOJO_DIR-"$BASE_DIR/.dojo"}
log() {
echo "$1"
}
success() {
echo "[✓] $1"
}
error() {
echo "[✗] $1"
exit 1
}
# Cleanups background processes.
cleanup() {
local pids=("$@")
log "Cleaning up background processes..."
for pid in "${pids[@]}"; do
if kill -0 "$pid" 2>/dev/null; then
kill "$pid" 2>/dev/null || true
fi
done
wait "${pids[@]}" 2>/dev/null || true
}
# Tests the dojoup install command.
test_install() {
log "Testing dojoup install..."
# Check if .env file exists
if [ ! -f "${DOJO_DIR}/env" ]; then
error "Installation failed: .env file not found in ${DOJO_DIR}"
fi
# Source the .env file of dojo
. "${DOJO_DIR}"/env
# Technically, it's already installed since 1.5.0 is currently the last release.
# However, to ensure the install can be checked with fixed versions, we re-install 1.5.0 explicitly.
dojoup install 1.5.0
if [ ! -d "$DOJO_DIR" ]; then
error "Installation failed: .dojo directory not created"
fi
if [ ! -d "$DOJO_DIR/bin" ]; then
error "Installation failed: bin directory not created"
fi
for binary in sozo torii katana dojo-language-server; do
if [ ! -f "$DOJO_DIR/bin/$binary" ]; then
error "Installation failed: $binary not found"
fi
done
success "Installation test passed"
}
# Tests the dojoup default version switching command.
test_default_version() {
log "Testing dojoup default version switching..."
current_version=$(dojoup show | grep "version:" | cut -d' ' -f2)
dojoup install "1.4.0"
dojoup default "1.4.0"
new_version=$(dojoup show | grep "version:" | cut -d' ' -f2)
if [ "$new_version" != "1.4.0" ]; then
error "Default version switch failed: expected 1.4.0, got $new_version"
fi
dojoup default "$current_version"
success "Default version switching test passed"
}
# Tests the dojoup component management command.
test_component_management() {
log "Testing dojoup component management..."
current_version=$(dojoup show | grep "version:" | cut -d' ' -f2)
dojoup component add katana 1.5.1
# Only test the bin symlink, since we may have internal folder structure changes
# in the future for dojoup.
# Also, the current version of component overrides the Katana install into the
# default toolchain version folder.
if [ ! -f "$DOJO_DIR/bin/katana" ]; then
error "Component installation failed: katana not found"
fi
component_version=$("$DOJO_DIR/bin/katana" --version | head -1 | cut -d' ' -f2)
if [ "$component_version" != "1.5.1" ]; then
error "Component version mismatch: expected 1.5.1, got $component_version"
fi
success "Component management test passed"
}
# Tests the dojoup list versions command.
test_list_versions() {
log "Testing dojoup list versions..."
versions=$(dojoup list)
# Verify both versions are present that we installed during this post-install check.
if ! echo "$versions" | grep -q "1.4.0"; then
error "List versions failed: version 1.4.0 not found"
fi
if ! echo "$versions" | grep -q "1.5.0"; then
error "List versions failed: version 1.5.0 not found"
fi
if ! echo "$versions" | grep -q "1.5.0 (default)"; then
error "List versions failed: default version marker not found"
fi
success "List versions test passed"
}
# Tests the dojoup show version command.
test_show_version() {
log "Testing dojoup show version..."
# Get current version info
version_info=$(dojoup show)
# Verify version format and exact version
if ! echo "$version_info" | grep -q "version: 1.5.0"; then
error "Show version failed: expected version 1.5.0 not found"
fi
# Verify components section exists
if ! echo "$version_info" | grep -q "components:"; then
error "Show version failed: components section not found"
fi
# Check each component version
if ! echo "$version_info" | grep -q "sozo: 1.5"; then
error "Show version failed: sozo version not found or less than 1.5"
fi
if ! echo "$version_info" | grep -q "torii: 1.5"; then
error "Show version failed: torii version not found or less than 1.5"
fi
if ! echo "$version_info" | grep -q "katana: 1.5"; then
error "Show version failed: katana version not found or less than 1.5"
fi
if ! echo "$version_info" | grep -q "dojo-language-server: 1.5"; then
error "Show version failed: dojo-language-server version not found or less than 1.5"
fi
success "Show version test passed"
}
# A end to end test that starts Katana and Torii and migrates a world using Sozo.
test_katana_torii() {
log "Testing Katana and Torii functionality..."
KATANA_LOG="/tmp/katana.log"
TORII_LOG="/tmp/torii.log"
TEST_DIR="/tmp/dojo-test"
# 1. Start katana in the background
katana --dev > "${KATANA_LOG}" 2>&1 &
KATANA_PID=$!
# Wait a bit for katana to be up
sleep 2
# Check if katana is running and has no errors
if ! pgrep -f katana > /dev/null || grep -i "error" "${KATANA_LOG}"; then
error "Katana failed to start or encountered errors"
fi
log "Katana started with PID $KATANA_PID"
# 2. Initialize, build and migrate with sozo
rm -rf "${TEST_DIR}"
sozo init "${TEST_DIR}"
cd "${TEST_DIR}"
sozo build
sozo migrate
# 3. Start torii with a dummy world address in background.
WORLD_ADDRESS=$(jq -r '.world.address' "${TEST_DIR}/manifest_dev.json")
torii --world "${WORLD_ADDRESS}" > "${TORII_LOG}" 2>&1 &
TORII_PID=$!
# Wait for torii to be up and indexing data.
sleep 2
# Check if torii is running and has no errors
if ! pgrep -f torii > /dev/null || grep -i "error" "${TORII_LOG}"; then
error "Torii failed to start or encountered errors"
cleanup "$KATANA_PID"
fi
log "Torii started with PID $TORII_PID"
WORLD_CHECK=$(curl -s -X POST http://localhost:8080/sql -d "SELECT contract_address FROM contracts WHERE contract_address = '${WORLD_ADDRESS}';")
WORLD_CHECK=$(echo "${WORLD_CHECK}" | jq -r '.[0].contract_address')
if [ -z "${WORLD_CHECK}" ] || [ "${WORLD_CHECK}" != "${WORLD_ADDRESS}" ]; then
error "World address mismatch. Expected: ${WORLD_ADDRESS}, Got: ${WORLD_CHECK}"
cleanup "$KATANA_PID" "$TORII_PID"
fi
cleanup "$KATANA_PID" "$TORII_PID"
success "Katana and Torii test passed"
}
main() {
log "Starting dojoup test suite..."
test_install
test_default_version
test_component_management
test_list_versions
test_show_version
test_katana_torii
success "All tests passed!"
}
main