Skip to content

Commit 78eae20

Browse files
feat: add test_helpers module (error_utils, test_utils) behind test_utlis flag (#2381)
Co-authored-by: Omri Eshhar <omri@starkware.co>
1 parent dc8971a commit 78eae20

12 files changed

Lines changed: 576 additions & 21 deletions

File tree

.github/workflows/rust.yml

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ env:
1818
cairo_programs/**/*.json
1919
!cairo_programs/manually_compiled/*
2020
cairo_programs/cairo-1-programs/bitwise.sierra
21+
vm/src/tests/cairo_test_suite/**/*.json
2122
TEST_COLLECT_COVERAGE: 1
2223
PROPTEST_CASES: 100
2324

@@ -46,6 +47,7 @@ jobs:
4647
- cairo_bench_programs
4748
- cairo_proof_programs
4849
- cairo_test_programs
50+
- cairo_test_suite_programs
4951
- cairo_1_test_contracts
5052
- cairo_2_test_contracts
5153
name: Build Cairo programs
@@ -66,7 +68,7 @@ jobs:
6668
id: cache-programs
6769
with:
6870
path: ${{ env.CAIRO_PROGRAMS_PATH }}
69-
key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'Makefile', 'requirements.txt') }}
71+
key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'vm/src/tests/cairo_test_suite/**/*.cairo', 'Makefile', 'requirements.txt') }}
7072

7173
# This is not pretty, but we need `make` to see the compiled programs are
7274
# actually newer than the sources, otherwise it will try to rebuild them
@@ -120,37 +122,43 @@ jobs:
120122
uses: actions/cache/restore@v3
121123
with:
122124
path: ${{ env.CAIRO_PROGRAMS_PATH }}
123-
key: cairo_test_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'Makefile', 'requirements.txt') }}
125+
key: cairo_test_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'vm/src/tests/cairo_test_suite/**/*.cairo', 'Makefile', 'requirements.txt') }}
124126
fail-on-cache-miss: true
125127
- name: Fetch proof programs
126128
uses: actions/cache/restore@v3
127129
with:
128130
path: ${{ env.CAIRO_PROGRAMS_PATH }}
129-
key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'Makefile', 'requirements.txt') }}
131+
key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'vm/src/tests/cairo_test_suite/**/*.cairo', 'Makefile', 'requirements.txt') }}
130132
fail-on-cache-miss: true
131133
- name: Fetch bench programs
132134
uses: actions/cache/restore@v3
133135
with:
134136
path: ${{ env.CAIRO_PROGRAMS_PATH }}
135-
key: cairo_bench_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'Makefile', 'requirements.txt') }}
137+
key: cairo_bench_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'vm/src/tests/cairo_test_suite/**/*.cairo', 'Makefile', 'requirements.txt') }}
138+
fail-on-cache-miss: true
139+
- name: Fetch cairo test suite programs
140+
uses: actions/cache/restore@v3
141+
with:
142+
path: ${{ env.CAIRO_PROGRAMS_PATH }}
143+
key: cairo_test_suite_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'vm/src/tests/cairo_test_suite/**/*.cairo', 'Makefile', 'requirements.txt') }}
136144
fail-on-cache-miss: true
137145
- name: Fetch test contracts (Cairo 1)
138146
uses: actions/cache/restore@v3
139147
with:
140148
path: ${{ env.CAIRO_PROGRAMS_PATH }}
141-
key: cairo_1_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'Makefile', 'requirements.txt') }}
149+
key: cairo_1_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'vm/src/tests/cairo_test_suite/**/*.cairo', 'Makefile', 'requirements.txt') }}
142150
fail-on-cache-miss: true
143151
- name: Fetch test contracts (Cairo 2)
144152
uses: actions/cache/restore@v3
145153
with:
146154
path: ${{ env.CAIRO_PROGRAMS_PATH }}
147-
key: cairo_2_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'Makefile', 'requirements.txt') }}
155+
key: cairo_2_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'vm/src/tests/cairo_test_suite/**/*.cairo', 'Makefile', 'requirements.txt') }}
148156
fail-on-cache-miss: true
149157
- name: Merge caches
150158
uses: actions/cache/save@v3
151159
with:
152160
path: ${{ env.CAIRO_PROGRAMS_PATH }}
153-
key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'Makefile', 'requirements.txt') }}
161+
key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'vm/src/tests/cairo_test_suite/**/*.cairo', 'Makefile', 'requirements.txt') }}
154162

155163
lint:
156164
needs: merge-caches
@@ -179,7 +187,7 @@ jobs:
179187
uses: actions/cache/restore@v3
180188
with:
181189
path: ${{ env.CAIRO_PROGRAMS_PATH }}
182-
key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'Makefile', 'requirements.txt') }}
190+
key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'vm/src/tests/cairo_test_suite/**/*.cairo', 'Makefile', 'requirements.txt') }}
183191
fail-on-cache-miss: true
184192

185193
- name: Run clippy
@@ -229,7 +237,7 @@ jobs:
229237
uses: actions/cache/restore@v3
230238
with:
231239
path: ${{ env.CAIRO_PROGRAMS_PATH }}
232-
key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'Makefile', 'requirements.txt') }}
240+
key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'vm/src/tests/cairo_test_suite/**/*.cairo', 'Makefile', 'requirements.txt') }}
233241
fail-on-cache-miss: true
234242

235243
# NOTE: we do this separately because --workspace operates in weird ways
@@ -274,7 +282,7 @@ jobs:
274282
uses: actions/cache/restore@v3
275283
with:
276284
path: ${{ env.CAIRO_PROGRAMS_PATH }}
277-
key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'Makefile', 'requirements.txt') }}
285+
key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'vm/src/tests/cairo_test_suite/**/*.cairo', 'Makefile', 'requirements.txt') }}
278286
fail-on-cache-miss: true
279287

280288
- name: Check all features (workspace)
@@ -309,7 +317,7 @@ jobs:
309317
uses: actions/cache/restore@v3
310318
with:
311319
path: ${{ env.CAIRO_PROGRAMS_PATH }}
312-
key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'Makefile', 'requirements.txt') }}
320+
key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'vm/src/tests/cairo_test_suite/**/*.cairo', 'Makefile', 'requirements.txt') }}
313321
fail-on-cache-miss: true
314322

315323
- name: Install testing tools
@@ -409,7 +417,7 @@ jobs:
409417
uses: actions/cache/restore@v3
410418
with:
411419
path: ${{ env.CAIRO_PROGRAMS_PATH }}
412-
key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'Makefile', 'requirements.txt') }}
420+
key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'vm/src/tests/cairo_test_suite/**/*.cairo', 'Makefile', 'requirements.txt') }}
413421
fail-on-cache-miss: true
414422

415423
# This is not pretty, but we need `make` to see the compiled programs are
@@ -456,7 +464,7 @@ jobs:
456464
uses: actions/cache/restore@v3
457465
with:
458466
path: ${{ env.CAIRO_PROGRAMS_PATH }}
459-
key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'Makefile', 'requirements.txt') }}
467+
key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'vm/src/tests/cairo_test_suite/**/*.cairo', 'Makefile', 'requirements.txt') }}
460468
fail-on-cache-miss: true
461469

462470
- name: Generate traces
@@ -675,7 +683,7 @@ jobs:
675683
uses: actions/cache/restore@v3
676684
with:
677685
path: ${{ env.CAIRO_PROGRAMS_PATH }}
678-
key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'Makefile', 'requirements.txt') }}
686+
key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'vm/src/tests/cairo_test_suite/**/*.cairo', 'Makefile', 'requirements.txt') }}
679687
fail-on-cache-miss: true
680688

681689
- name: Run script
@@ -715,7 +723,7 @@ jobs:
715723
uses: actions/cache/restore@v3
716724
with:
717725
path: ${{ env.CAIRO_PROGRAMS_PATH }}
718-
key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'Makefile', 'requirements.txt') }}
726+
key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'vm/src/tests/cairo_test_suite/**/*.cairo', 'Makefile', 'requirements.txt') }}
719727
fail-on-cache-miss: true
720728

721729
- name: Fetch pie

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
**/*.json
55
!hint_accountant/whitelists/*.json
66
!cairo_programs/manually_compiled/*.json
7+
!vm/src/test_helpers/dummy.json
78
**/*.casm
89
**/*.sierra
910
**/*.trace

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Both branches support Stwo prover opcodes (Blake2s, QM31) since v2.0.0.
1111
---
1212

1313
#### Upcoming Changes
14+
* feat: add `test_helpers` module (`error_utils`, `test_utils`) with `assert_mr_eq`, `load_cairo_program!` macro and `expect_*` error checkers, behind `test_utils` feature flag [#2381](https://github.com/starkware-libs/cairo-vm/pull/2381)
15+
16+
* feat(makefile,ci): add `cairo_test_suite_programs` Makefile target and CI integration to compile Cairo test suite programs before running tests [#2380](https://github.com/starkware-libs/cairo-vm/pull/2380)
1417

1518
* Add Stwo cairo runner API [#2351](https://github.com/starkware-libs/cairo-vm/pull/2351)
1619
* feat: make max traceback entries configurable [#2370](https://github.com/starkware-libs/cairo-vm/pull/2370)

Makefile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ UNAME := $(shell uname)
2121
compare_trace_memory compare_trace compare_memory compare_pie compare_all_no_proof \
2222
compare_trace_memory_proof compare_all_proof compare_trace_proof compare_memory_proof compare_air_public_input compare_air_private_input\
2323
hyper-threading-benchmarks \
24-
cairo_bench_programs cairo_proof_programs cairo_test_programs cairo_1_test_contracts cairo_2_test_contracts \
24+
cairo_bench_programs cairo_proof_programs cairo_test_programs cairo_test_suite_programs cairo_1_test_contracts cairo_2_test_contracts \
2525
cairo_trace cairo-vm_trace cairo_proof_trace cairo-vm_proof_trace python-deps python-deps-macos \
2626
build-cairo-lang hint-accountant \ create-proof-programs-symlinks \
2727
$(RELBIN) $(DBGBIN)
@@ -124,6 +124,10 @@ NORETROCOMPAT_DIR:=cairo_programs/noretrocompat
124124
NORETROCOMPAT_FILES:=$(wildcard $(NORETROCOMPAT_DIR)/*.cairo)
125125
COMPILED_NORETROCOMPAT_TESTS:=$(patsubst $(NORETROCOMPAT_DIR)/%.cairo, $(NORETROCOMPAT_DIR)/%.json, $(NORETROCOMPAT_FILES))
126126

127+
CAIRO_TEST_SUITE_ROOT:=vm/src/tests/cairo_test_suite
128+
CAIRO_TEST_SUITE_FILES:=$(shell find $(CAIRO_TEST_SUITE_ROOT) -name "*.cairo")
129+
COMPILED_CAIRO_TEST_SUITE:=$(patsubst %.cairo,%.json,$(CAIRO_TEST_SUITE_FILES))
130+
127131
$(BENCH_DIR)/%.json: $(BENCH_DIR)/%.cairo
128132
cairo-compile --cairo_path="$(TEST_DIR):$(BENCH_DIR)" $< --output $@ --proof_mode
129133

@@ -145,6 +149,9 @@ $(BAD_TEST_DIR)/%.json: $(BAD_TEST_DIR)/%.cairo
145149
$(PRINT_TEST_DIR)/%.json: $(PRINT_TEST_DIR)/%.cairo
146150
cairo-compile $< --output $@
147151

152+
$(CAIRO_TEST_SUITE_ROOT)/%.json: $(CAIRO_TEST_SUITE_ROOT)/%.cairo
153+
cairo-compile $< --output $@
154+
148155
# ======================
149156
# Test Cairo 1 Contracts
150157
# ======================
@@ -268,6 +275,8 @@ run:
268275
check:
269276
cargo check
270277

278+
cairo_test_suite_programs: $(COMPILED_CAIRO_TEST_SUITE)
279+
271280
cairo_test_programs: $(COMPILED_TESTS) $(COMPILED_BAD_TESTS) $(COMPILED_NORETROCOMPAT_TESTS) $(COMPILED_PRINT_TESTS) $(COMPILED_MOD_BUILTIN_TESTS) $(COMPILED_SECP_CAIRO0_HINTS) $(COMPILED_KZG_DA_CAIRO0_HINTS) $(COMPILED_SEGMENT_ARENA_CAIRO0_HINTS)
272281
cairo_proof_programs: $(COMPILED_PROOF_TESTS) $(COMPILED_MOD_BUILTIN_PROOF_TESTS) $(COMPILED_STWO_EXCLUSIVE_TESTS)
273282
cairo_bench_programs: $(COMPILED_BENCHES)
@@ -286,7 +295,7 @@ ifdef TEST_COLLECT_COVERAGE
286295
TEST_COMMAND:=cargo llvm-cov nextest --no-report
287296
endif
288297

289-
test: cairo_proof_programs cairo_test_programs cairo_1_test_contracts cairo_2_test_contracts cairo_1_program
298+
test: cairo_proof_programs cairo_test_programs cairo_test_suite_programs cairo_1_test_contracts cairo_2_test_contracts cairo_1_program
290299
$(TEST_COMMAND) --workspace --features "test_utils, cairo-1-hints"
291300
test-extensive_hints: cairo_proof_programs cairo_test_programs cairo_1_test_contracts cairo_1_program cairo_2_test_contracts
292301
$(TEST_COMMAND) --workspace --features "test_utils, cairo-1-hints, cairo-0-secp-hints, cairo-0-data-availability-hints, extensive_hints"

vm/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ pub mod types;
2626
pub mod utils;
2727
pub mod vm;
2828

29+
#[cfg(feature = "test_utils")]
30+
pub mod test_helpers;
31+
2932
// TODO: use `Felt` directly
3033
pub use starknet_types_core::felt::Felt as Felt252;
3134

vm/src/test_helpers/dummy.json

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"attributes": [],
3+
"builtins": [],
4+
"compiler_version": "0.13.5",
5+
"data": [
6+
"0x208b7fff7fff7ffe"
7+
],
8+
"debug_info": {
9+
"file_contents": {},
10+
"instruction_locations": {
11+
"0": {
12+
"accessible_scopes": [
13+
"__main__",
14+
"__main__.main"
15+
],
16+
"flow_tracking_data": {
17+
"ap_tracking": {
18+
"group": 0,
19+
"offset": 0
20+
},
21+
"reference_ids": {}
22+
},
23+
"hints": [],
24+
"inst": {
25+
"end_col": 15,
26+
"end_line": 2,
27+
"input_file": {
28+
"filename": "vm/src/test_helpers/dummy.cairo"
29+
},
30+
"start_col": 5,
31+
"start_line": 2
32+
}
33+
}
34+
}
35+
},
36+
"hints": {},
37+
"identifiers": {
38+
"__main__.main": {
39+
"decorators": [],
40+
"pc": 0,
41+
"type": "function"
42+
},
43+
"__main__.main.Args": {
44+
"full_name": "__main__.main.Args",
45+
"members": {},
46+
"size": 0,
47+
"type": "struct"
48+
},
49+
"__main__.main.ImplicitArgs": {
50+
"full_name": "__main__.main.ImplicitArgs",
51+
"members": {},
52+
"size": 0,
53+
"type": "struct"
54+
},
55+
"__main__.main.Return": {
56+
"cairo_type": "()",
57+
"type": "type_definition"
58+
},
59+
"__main__.main.SIZEOF_LOCALS": {
60+
"type": "const",
61+
"value": 0
62+
}
63+
},
64+
"main_scope": "__main__",
65+
"prime": "0x800000000000011000000000000000000000000000000000000000000000001",
66+
"reference_manager": {
67+
"references": []
68+
}
69+
}

0 commit comments

Comments
 (0)