forked from solutions-plug/predictIQ
-
Notifications
You must be signed in to change notification settings - Fork 0
337 lines (282 loc) · 8.97 KB
/
test.yml
File metadata and controls
337 lines (282 loc) · 8.97 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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
name: Comprehensive Test Suite
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Cache cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
- name: Install Soroban CLI
run: |
cargo install --locked soroban-cli --features opt
- name: Run unit tests
run: cargo test --lib --workspace
working-directory: contracts/predict-iq
- name: Run module tests
run: cargo test --lib --features testutils
working-directory: contracts/predict-iq
integration-tests:
name: Integration Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install Soroban CLI
run: cargo install --locked soroban-cli --features opt
- name: Run integration tests
run: cargo test --test '*' --workspace
working-directory: contracts/predict-iq
gas-benchmarks:
name: Gas Benchmarks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install Soroban CLI
run: cargo install --locked soroban-cli --features opt
- name: Run gas benchmarks
run: cargo test --benches --features testutils
working-directory: contracts/predict-iq
- name: Check benchmark results
run: |
echo "Benchmark results:"
cat target/criterion/*/report/index.html || echo "No criterion reports found"
coverage:
name: Code Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: llvm-tools-preview
- name: Install cargo-llvm-cov
run: cargo install cargo-llvm-cov
- name: Install Soroban CLI
run: cargo install --locked soroban-cli --features opt
- name: Generate coverage
run: cargo llvm-cov --workspace --lcov --output-path lcov.info
working-directory: contracts/predict-iq
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: ./contracts/predict-iq/lcov.info
fail_ci_if_error: true
verbose: true
- name: Check coverage threshold
run: |
coverage=$(cargo llvm-cov --workspace --summary-only | grep -oP 'TOTAL.*\K[0-9.]+(?=%)')
echo "Coverage: $coverage%"
if (( $(echo "$coverage < 80" | bc -l) )); then
echo "Coverage $coverage% is below 80% threshold"
exit 1
fi
working-directory: contracts/predict-iq
security-audit:
name: Security Audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install cargo-audit
run: cargo install cargo-audit
- name: Run security audit
run: cargo audit
working-directory: contracts/predict-iq
clippy:
name: Clippy Lints
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: clippy
- name: Run Clippy
run: cargo clippy --all-targets --all-features -- -D warnings
working-directory: contracts/predict-iq
oracle-quality-gate:
name: Oracle Module — Clippy + Warnings-as-Errors
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: clippy
- name: Clippy (deny warnings) — oracle module
env:
RUSTFLAGS: -D warnings
run: >
cargo clippy
--package predict-iq
--all-features
-- -D warnings
working-directory: contracts/predict-iq
- name: Build (deny warnings) — contract crate
env:
RUSTFLAGS: -D warnings
run: cargo build --package predict-iq --all-features
working-directory: contracts/predict-iq
- name: Run oracle tests
run: cargo test --package predict-iq --lib oracles
working-directory: contracts/predict-iq
format:
name: Code Formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt
- name: Check formatting
run: cargo fmt --all -- --check
working-directory: contracts/predict-iq
snapshot-tests:
name: Snapshot Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install Soroban CLI
run: cargo install --locked soroban-cli --features opt
- name: Run snapshot tests
run: cargo test --features testutils
working-directory: contracts/predict-iq
- name: Check for snapshot changes
run: |
if git diff --exit-code test_snapshots/; then
echo "Snapshots are up to date"
else
echo "Snapshot changes detected - review carefully"
git diff test_snapshots/
exit 1
fi
working-directory: contracts/predict-iq
build-optimized:
name: Build Optimized Contract
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
target: wasm32-unknown-unknown
- name: Install Soroban CLI
run: cargo install --locked soroban-cli --features opt
- name: Build optimized WASM
run: cargo build --target wasm32-unknown-unknown --release
working-directory: contracts/predict-iq
- name: Optimize WASM
run: |
soroban contract optimize \
--wasm target/wasm32-unknown-unknown/release/predict_iq.wasm \
--wasm-out target/wasm32-unknown-unknown/release/predict_iq_optimized.wasm
working-directory: contracts/predict-iq
- name: Check WASM size
run: |
size=$(stat -f%z target/wasm32-unknown-unknown/release/predict_iq_optimized.wasm 2>/dev/null || stat -c%s target/wasm32-unknown-unknown/release/predict_iq_optimized.wasm)
echo "Optimized WASM size: $size bytes"
max_size=65536 # 64KB limit
if [ $size -gt $max_size ]; then
echo "WASM size $size exceeds limit of $max_size bytes"
exit 1
fi
working-directory: contracts/predict-iq
all-tests-passed:
name: All Tests Passed
needs:
- unit-tests
- integration-tests
- gas-benchmarks
- coverage
- security-audit
- clippy
- oracle-quality-gate
- format
- snapshot-tests
- build-optimized
runs-on: ubuntu-latest
steps:
- name: Success
run: echo "All tests passed successfully!"