forked from AnchorKit-1/AnchorKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathci_preflight_check.sh
More file actions
executable file
·288 lines (243 loc) · 12 KB
/
Copy pathci_preflight_check.sh
File metadata and controls
executable file
·288 lines (243 loc) · 12 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/bin/bash
# CI/CD Pre-flight Check for Anchor Info Discovery
# Simulates GitHub Actions checks locally
set -e
echo "╔══════════════════════════════════════════════════════════════════════════════╗"
echo "║ CI/CD PRE-FLIGHT CHECK ║"
echo "║ Anchor Info Discovery Service ║"
echo "╚══════════════════════════════════════════════════════════════════════════════╝"
echo ""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Track failures
FAILURES=0
check_pass() {
echo -e "${GREEN}✓${NC} $1"
}
check_fail() {
echo -e "${RED}✗${NC} $1"
FAILURES=$((FAILURES + 1))
}
check_warn() {
echo -e "${YELLOW}⚠${NC} $1"
}
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "1. FILE STRUCTURE CHECKS"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Check required files exist
if [ -f "src/anchor_info_discovery.rs" ]; then
check_pass "src/anchor_info_discovery.rs exists"
else
check_fail "src/anchor_info_discovery.rs missing"
fi
if [ -f "src/anchor_info_discovery_tests.rs" ]; then
check_pass "src/anchor_info_discovery_tests.rs exists"
else
check_fail "src/anchor_info_discovery_tests.rs missing"
fi
if [ -f "ANCHOR_INFO_DISCOVERY.md" ]; then
check_pass "ANCHOR_INFO_DISCOVERY.md exists"
else
check_fail "ANCHOR_INFO_DISCOVERY.md missing"
fi
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "2. MODULE DECLARATION CHECKS"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Check module is declared in lib.rs
if grep -q "^mod anchor_info_discovery;" src/lib.rs; then
check_pass "Module declared in lib.rs"
else
check_fail "Module NOT declared in lib.rs"
fi
# Check test module is declared
if grep -q "^#\[cfg(test)\]" src/lib.rs && grep -A1 "^#\[cfg(test)\]" src/lib.rs | grep -q "^mod anchor_info_discovery_tests;"; then
check_pass "Test module declared with #[cfg(test)]"
else
check_fail "Test module NOT properly declared"
fi
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "3. IMPORT CHECKS"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Check imports in anchor_info_discovery.rs
if grep -q "use soroban_sdk::" src/anchor_info_discovery.rs; then
check_pass "Soroban SDK imported in anchor_info_discovery.rs"
else
check_fail "Soroban SDK NOT imported"
fi
if grep -q "use crate::errors::Error;" src/anchor_info_discovery.rs; then
check_pass "Error type imported in anchor_info_discovery.rs"
else
check_fail "Error type NOT imported"
fi
# Check imports in test file
if grep -q "use crate::anchor_info_discovery::" src/anchor_info_discovery_tests.rs; then
check_pass "Module imported in test file"
else
check_fail "Module NOT imported in test file"
fi
if grep -q "use soroban_sdk::.*Address" src/anchor_info_discovery_tests.rs; then
check_pass "Address type imported in test file"
else
check_fail "Address type NOT imported in test file"
fi
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "4. DATA STRUCTURE CHECKS"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Check for required data structures
if grep -q "pub struct StellarToml" src/anchor_info_discovery.rs; then
check_pass "StellarToml struct defined"
else
check_fail "StellarToml struct NOT defined"
fi
if grep -q "pub struct AssetInfo" src/anchor_info_discovery.rs; then
check_pass "AssetInfo struct defined"
else
check_fail "AssetInfo struct NOT defined"
fi
if grep -q "pub struct CachedToml" src/anchor_info_discovery.rs; then
check_pass "CachedToml struct defined"
else
check_fail "CachedToml struct NOT defined"
fi
# Check for #[contracttype] attribute
if grep -q "#\[contracttype\]" src/anchor_info_discovery.rs; then
check_pass "#[contracttype] attribute present"
else
check_fail "#[contracttype] attribute missing"
fi
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "5. PUBLIC API CHECKS"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Count public methods in lib.rs
PUBLIC_METHODS=(
"fetch_anchor_info"
"get_anchor_toml"
"refresh_anchor_info"
"get_anchor_assets"
"get_anchor_asset_info"
"get_anchor_deposit_limits"
"get_anchor_withdrawal_limits"
"get_anchor_deposit_fees"
"get_anchor_withdrawal_fees"
"anchor_supports_deposits"
"anchor_supports_withdrawals"
)
for method in "${PUBLIC_METHODS[@]}"; do
if grep -q "pub fn $method" src/lib.rs; then
check_pass "Method $method exposed in contract"
else
check_fail "Method $method NOT exposed"
fi
done
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "6. TEST CHECKS"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Count test functions
UNIT_TESTS=$(grep -c "fn test_" src/anchor_info_discovery.rs || echo "0")
INTEGRATION_TESTS=$(grep -c "fn test_" src/anchor_info_discovery_tests.rs || echo "0")
TOTAL_TESTS=$((UNIT_TESTS + INTEGRATION_TESTS))
if [ "$UNIT_TESTS" -ge 15 ]; then
check_pass "Unit tests: $UNIT_TESTS (expected: 18)"
else
check_fail "Unit tests: $UNIT_TESTS (expected: 18)"
fi
if [ "$INTEGRATION_TESTS" -ge 15 ]; then
check_pass "Integration tests: $INTEGRATION_TESTS (expected: 20)"
else
check_fail "Integration tests: $INTEGRATION_TESTS (expected: 20)"
fi
if [ "$TOTAL_TESTS" -ge 30 ]; then
check_pass "Total tests: $TOTAL_TESTS (expected: 38)"
else
check_warn "Total tests: $TOTAL_TESTS (expected: 38)"
fi
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "7. CODE QUALITY CHECKS"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Check for proper error handling (no unwrap in non-test code)
NON_TEST_UNWRAPS=$(grep -n "\.unwrap()" src/anchor_info_discovery.rs | grep -v "fn test_" | grep -v "mod tests" | wc -l || echo "0")
if [ "$NON_TEST_UNWRAPS" -eq 0 ]; then
check_pass "No unwrap() in production code"
else
check_warn "Found $NON_TEST_UNWRAPS unwrap() calls in production code"
fi
# Check for TODO/FIXME comments
TODOS=$(grep -c "TODO\|FIXME" src/anchor_info_discovery.rs || echo "0")
if [ "$TODOS" -eq 0 ]; then
check_pass "No TODO/FIXME comments"
else
check_warn "Found $TODOS TODO/FIXME comments"
fi
# Check for proper documentation
if grep -q "/// " src/anchor_info_discovery.rs; then
check_pass "Documentation comments present"
else
check_warn "No documentation comments found"
fi
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "8. CARGO.TOML CHECKS"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
if [ -f "Cargo.toml" ]; then
check_pass "Cargo.toml exists"
if grep -q "soroban-sdk" Cargo.toml; then
check_pass "soroban-sdk dependency present"
else
check_fail "soroban-sdk dependency missing"
fi
if grep -q "\[features\]" Cargo.toml; then
check_pass "Feature flags defined"
else
check_warn "No feature flags defined"
fi
else
check_fail "Cargo.toml missing"
fi
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "9. DOCUMENTATION CHECKS"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Check README updated
if grep -q "Anchor Info Discovery" README.md; then
check_pass "README.md mentions Anchor Info Discovery"
else
check_fail "README.md NOT updated"
fi
if grep -q "ANCHOR_INFO_DISCOVERY.md" README.md; then
check_pass "README.md links to documentation"
else
check_fail "README.md missing documentation link"
fi
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "10. SUMMARY"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
if [ $FAILURES -eq 0 ]; then
echo -e "${GREEN}✓ ALL CHECKS PASSED${NC}"
echo ""
echo "The implementation is ready for CI/CD pipeline."
echo ""
echo "Next steps:"
echo " 1. Run: cargo check"
echo " 2. Run: cargo build"
echo " 3. Run: cargo test anchor_info_discovery"
echo " 4. Run: cargo clippy -- -D warnings"
echo ""
exit 0
else
echo -e "${RED}✗ $FAILURES CHECK(S) FAILED${NC}"
echo ""
echo "Please fix the issues above before proceeding."
echo ""
exit 1
fi