forked from ussyalfaks/Grainlify-Stellar-Contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_deploy_failures.sh
More file actions
executable file
·91 lines (70 loc) · 2.5 KB
/
Copy pathtest_deploy_failures.sh
File metadata and controls
executable file
·91 lines (70 loc) · 2.5 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
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
DEPLOY_SCRIPT="$SCRIPT_DIR/deploy.sh"
# --- Create a valid dummy WASM file so validation passes ---
FAKE_WASM=/tmp/fake_valid.wasm
echo -n -e "\x00\x61\x73\x6D\x01" > "$FAKE_WASM" # Minimal WASM magic header
fail() { echo "✘ FAIL: $1"; exit 1; }
pass() { echo "✔ PASS: $1"; }
# --------------------- MOCKING HELPERS ----------------------
MOCK_BIN="$(pwd)/mock_bin"
mkdir -p "$MOCK_BIN"
enable_identity_mock() {
echo '#!/usr/bin/env bash
if [[ "$1" = "keys" && "$2" = "address" ]]; then
echo FAKE_ADDRESS
exit 0
fi
echo "Mock stellar call"
exit 0' > "$MOCK_BIN/stellar"
chmod +x "$MOCK_BIN/stellar"
export PATH="$MOCK_BIN:$ORIGINAL_PATH"
}
disable_identity_mock() {
export PATH="$ORIGINAL_PATH"
}
ORIGINAL_PATH="$PATH"
# --------------------- TEST RUNNER --------------------------
run_expect_fail() {
desc="$1"
expected="$2"
shift 2
set +e
output=$("$DEPLOY_SCRIPT" "$@" 2>&1)
exit_code=$?
set -e
if [[ $exit_code -eq 0 ]]; then
echo "$output"
fail "$desc (expected failure, got exit 0)"
fi
if ! echo "$output" | grep -q "$expected"; then
echo "$output"
fail "$desc (expected message '$expected')"
fi
pass "$desc"
}
echo "=== Deployment Script Failure Tests ==="
# ------------------------------------------------------------
# 1. Missing WASM file (NO mocking)
# ------------------------------------------------------------
disable_identity_mock
run_expect_fail "Missing WASM file" "No WASM file specified"
# ------------------------------------------------------------
# 2. Invalid WASM path (NO mocking)
# ------------------------------------------------------------
run_expect_fail "Invalid WASM file path" "WASM file not found" "/tmp/this_file_does_not_exist.wasm"
# ------------------------------------------------------------
# 3. Invalid identity should FAIL identity check (NO mocking)
# ------------------------------------------------------------
disable_identity_mock
run_expect_fail "Invalid identity" "Identity not found" "$FAKE_WASM" --identity "ghost_id"
# ------------------------------------------------------------
# 4. Missing CLI dependency (requires identity mock)
# ------------------------------------------------------------
enable_identity_mock
PATH="/usr/bin:/bin" run_expect_fail \
"Missing soroban CLI" \
"Neither 'stellar' nor 'soroban' CLI found" \
"$FAKE_WASM"
echo "All deployment failure tests passed!"