Skip to content

Commit 00ec82c

Browse files
Fix tests
1 parent 106787c commit 00ec82c

File tree

2 files changed

+225
-49
lines changed

2 files changed

+225
-49
lines changed

vm/src/hint_processor/builtin_hint_processor/math_utils.rs

Lines changed: 219 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,20 +2066,43 @@ mod tests {
20662066
HintReference::new(-3, 1, true, true, true),
20672067
),
20682068
]);
2069+
let identifiers = HashMap::from([
2070+
(
2071+
"MAX_LOW".to_string(),
2072+
Identifier {
2073+
pc: None,
2074+
type_: Some("const".to_string()),
2075+
value: Some(Felt252::ZERO),
2076+
full_name: None,
2077+
members: None,
2078+
cairo_type: None,
2079+
size: None,
2080+
destination: None,
2081+
},
2082+
),
2083+
(
2084+
"MAX_HIGH".to_string(),
2085+
Identifier {
2086+
pc: None,
2087+
type_: Some("const".to_string()),
2088+
value: Some(felt_str!("10633823966279327296825105735305134080")),
2089+
full_name: None,
2090+
members: None,
2091+
cairo_type: None,
2092+
size: None,
2093+
destination: None,
2094+
},
2095+
),
2096+
]);
20692097
//Execute the hint
20702098
assert_matches!(
20712099
run_hint!(
20722100
vm,
20732101
ids_data,
20742102
hint_code,
20752103
exec_scopes_ref!(),
2076-
&HashMap::from([
2077-
("MAX_LOW".to_string(), Felt252::ZERO),
2078-
(
2079-
"MAX_HIGH".to_string(),
2080-
felt_str!("10633823966279327296825105735305134080")
2081-
)
2082-
])
2104+
&HashMap::default(),
2105+
identifiers
20832106
),
20842107
Ok(())
20852108
);
@@ -2106,20 +2129,45 @@ mod tests {
21062129
//Create incomplete ids
21072130
//Create ids_data & hint_data
21082131
let ids_data = ids_data!["low"];
2132+
2133+
let identifiers = HashMap::from([
2134+
(
2135+
"MAX_LOW".to_string(),
2136+
Identifier {
2137+
pc: None,
2138+
type_: Some("const".to_string()),
2139+
value: Some(Felt252::ZERO),
2140+
full_name: None,
2141+
members: None,
2142+
cairo_type: None,
2143+
size: None,
2144+
destination: None,
2145+
},
2146+
),
2147+
(
2148+
"MAX_HIGH".to_string(),
2149+
Identifier {
2150+
pc: None,
2151+
type_: Some("const".to_string()),
2152+
value: Some(felt_str!("10633823966279327296825105735305134080")),
2153+
full_name: None,
2154+
members: None,
2155+
cairo_type: None,
2156+
size: None,
2157+
destination: None,
2158+
},
2159+
),
2160+
]);
2161+
21092162
//Execute the hint
21102163
assert_matches!(
21112164
run_hint!(
21122165
vm,
21132166
ids_data,
21142167
hint_code,
21152168
exec_scopes_ref!(),
2116-
&HashMap::from([
2117-
("MAX_LOW".to_string(), Felt252::ZERO),
2118-
(
2119-
"MAX_HIGH".to_string(),
2120-
felt_str!("10633823966279327296825105735305134080")
2121-
)
2122-
])
2169+
&HashMap::default(),
2170+
identifiers
21232171
),
21242172
Err(HintError::UnknownIdentifier(bx)) if bx.as_ref() == "value"
21252173
);
@@ -2151,20 +2199,44 @@ mod tests {
21512199
),
21522200
]);
21532201

2202+
let identifiers = HashMap::from([
2203+
(
2204+
"MAX_LOW".to_string(),
2205+
Identifier {
2206+
pc: None,
2207+
type_: Some("const".to_string()),
2208+
value: Some(Felt252::ZERO),
2209+
full_name: None,
2210+
members: None,
2211+
cairo_type: None,
2212+
size: None,
2213+
destination: None,
2214+
},
2215+
),
2216+
(
2217+
"MAX_HIGH".to_string(),
2218+
Identifier {
2219+
pc: None,
2220+
type_: Some("const".to_string()),
2221+
value: Some(felt_str!("10633823966279327296825105735305134080")),
2222+
full_name: None,
2223+
members: None,
2224+
cairo_type: None,
2225+
size: None,
2226+
destination: None,
2227+
},
2228+
),
2229+
]);
2230+
21542231
//Execute the hint
21552232
assert_matches!(
21562233
run_hint!(
21572234
vm,
21582235
ids_data,
21592236
hint_code,
21602237
exec_scopes_ref!(),
2161-
&HashMap::from([
2162-
("MAX_LOW".to_string(), Felt252::ZERO),
2163-
(
2164-
"MAX_HIGH".to_string(),
2165-
felt_str!("10633823966279327296825105735305134080")
2166-
)
2167-
])
2238+
&HashMap::default(),
2239+
identifiers
21682240
),
21692241
Err(HintError::Memory(
21702242
MemoryError::InconsistentMemory(bx)
@@ -2200,20 +2272,45 @@ mod tests {
22002272
HintReference::new(-3, 1, true, true, true),
22012273
),
22022274
]);
2275+
2276+
let identifiers = HashMap::from([
2277+
(
2278+
"MAX_LOW".to_string(),
2279+
Identifier {
2280+
pc: None,
2281+
type_: Some("const".to_string()),
2282+
value: Some(Felt252::ZERO),
2283+
full_name: None,
2284+
members: None,
2285+
cairo_type: None,
2286+
size: None,
2287+
destination: None,
2288+
},
2289+
),
2290+
(
2291+
"MAX_HIGH".to_string(),
2292+
Identifier {
2293+
pc: None,
2294+
type_: Some("const".to_string()),
2295+
value: Some(felt_str!("10633823966279327296825105735305134080")),
2296+
full_name: None,
2297+
members: None,
2298+
cairo_type: None,
2299+
size: None,
2300+
destination: None,
2301+
},
2302+
),
2303+
]);
2304+
22032305
//Execute the hint
22042306
assert_matches!(
22052307
run_hint!(
22062308
vm,
22072309
ids_data,
22082310
hint_code,
22092311
exec_scopes_ref!(),
2210-
&HashMap::from([
2211-
("MAX_LOW".to_string(), Felt252::ZERO),
2212-
(
2213-
"MAX_HIGH".to_string(),
2214-
felt_str!("10633823966279327296825105735305134080")
2215-
)
2216-
])
2312+
&HashMap::default(),
2313+
identifiers
22172314
),
22182315
Err(HintError::Memory(
22192316
MemoryError::InconsistentMemory(bx)
@@ -2244,20 +2341,43 @@ mod tests {
22442341
HintReference::new(-3, 1, true, true, true),
22452342
),
22462343
]);
2344+
let identifiers = HashMap::from([
2345+
(
2346+
"MAX_LOW".to_string(),
2347+
Identifier {
2348+
pc: None,
2349+
type_: Some("const".to_string()),
2350+
value: Some(Felt252::ZERO),
2351+
full_name: None,
2352+
members: None,
2353+
cairo_type: None,
2354+
size: None,
2355+
destination: None,
2356+
},
2357+
),
2358+
(
2359+
"MAX_HIGH".to_string(),
2360+
Identifier {
2361+
pc: None,
2362+
type_: Some("const".to_string()),
2363+
value: Some(felt_str!("10633823966279327296825105735305134080")),
2364+
full_name: None,
2365+
members: None,
2366+
cairo_type: None,
2367+
size: None,
2368+
destination: None,
2369+
},
2370+
),
2371+
]);
22472372
//Execute the hint
22482373
assert_matches!(
22492374
run_hint!(
22502375
vm,
22512376
ids_data,
22522377
hint_code,
22532378
exec_scopes_ref!(),
2254-
&HashMap::from([
2255-
("MAX_LOW".to_string(), Felt252::ZERO),
2256-
(
2257-
"MAX_HIGH".to_string(),
2258-
felt_str!("10633823966279327296825105735305134080")
2259-
)
2260-
])
2379+
&HashMap::default(),
2380+
identifiers
22612381
),
22622382
Err(HintError::IdentifierNotInteger(bx)) if bx.as_ref() == "value"
22632383
);
@@ -2320,20 +2440,45 @@ mod tests {
23202440
HintReference::new(-3, 1, true, true, true),
23212441
),
23222442
]);
2443+
2444+
let identifiers = HashMap::from([
2445+
(
2446+
"a.MAX_LOW".to_string(),
2447+
Identifier {
2448+
pc: None,
2449+
type_: Some("const".to_string()),
2450+
value: Some(Felt252::from(-1)),
2451+
full_name: None,
2452+
members: None,
2453+
cairo_type: None,
2454+
size: None,
2455+
destination: None,
2456+
},
2457+
),
2458+
(
2459+
"a.MAX_HIGH".to_string(),
2460+
Identifier {
2461+
pc: None,
2462+
type_: Some("const".to_string()),
2463+
value: Some(Felt252::from(-1)),
2464+
full_name: None,
2465+
members: None,
2466+
cairo_type: None,
2467+
size: None,
2468+
destination: None,
2469+
},
2470+
),
2471+
]);
2472+
23232473
//Execute the hint
23242474
assert_matches!(
23252475
run_hint!(
23262476
vm,
23272477
ids_data,
23282478
hint_code,
23292479
exec_scopes_ref!(),
2330-
&HashMap::from([
2331-
("MAX_LOW".to_string(), Felt252::from(-1)),
2332-
(
2333-
"MAX_HIGH".to_string(),
2334-
Felt252::from(-1),
2335-
)
2336-
])
2480+
&HashMap::default(),
2481+
identifiers
23372482
),
23382483
Err(HintError::AssertionFailed(x)) if &(*x) == "assert ids.MAX_HIGH < 2**128 and ids.MAX_LOW < 2**128"
23392484
);
@@ -2364,20 +2509,45 @@ mod tests {
23642509
HintReference::new(-3, 1, true, true, true),
23652510
),
23662511
]);
2512+
2513+
let identifiers = HashMap::from([
2514+
(
2515+
"MAX_LOW".to_string(),
2516+
Identifier {
2517+
pc: None,
2518+
type_: Some("const".to_string()),
2519+
value: Some(Felt252::ZERO),
2520+
full_name: None,
2521+
members: None,
2522+
cairo_type: None,
2523+
size: None,
2524+
destination: None,
2525+
},
2526+
),
2527+
(
2528+
"MAX_HIGH".to_string(),
2529+
Identifier {
2530+
pc: None,
2531+
type_: Some("const".to_string()),
2532+
value: Some(Felt252::ZERO),
2533+
full_name: None,
2534+
members: None,
2535+
cairo_type: None,
2536+
size: None,
2537+
destination: None,
2538+
},
2539+
),
2540+
]);
2541+
23672542
//Execute the hint
23682543
assert_matches!(
23692544
run_hint!(
23702545
vm,
23712546
ids_data,
23722547
hint_code,
23732548
exec_scopes_ref!(),
2374-
&HashMap::from([
2375-
("MAX_LOW".to_string(), Felt252::ZERO),
2376-
(
2377-
"MAX_HIGH".to_string(),
2378-
Felt252::ZERO,
2379-
)
2380-
])
2549+
&HashMap::default(),
2550+
identifiers
23812551
),
23822552
Err(HintError::AssertionFailed(x)) if &(*x) == "assert PRIME - 1 == ids.MAX_HIGH * 2**128 + ids.MAX_LOW"
23832553
);

vm/src/utils.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,12 @@ pub mod test_utils {
473473
pub(crate) use exec_scopes_ref;
474474

475475
macro_rules! run_hint {
476+
($vm:expr, $ids_data:expr, $hint_code:expr, $exec_scopes:expr, $constants:expr, $identifiers:expr) => {{
477+
let mut hint_data = HintProcessorData::new_default($hint_code.to_string(), $ids_data);
478+
hint_data.identifiers = $identifiers;
479+
let mut hint_processor = BuiltinHintProcessor::new_empty();
480+
hint_processor.execute_hint(&mut $vm, $exec_scopes, &any_box!(hint_data), $constants)
481+
}};
476482
($vm:expr, $ids_data:expr, $hint_code:expr, $exec_scopes:expr, $constants:expr) => {{
477483
let hint_data = HintProcessorData::new_default($hint_code.to_string(), $ids_data);
478484
let mut hint_processor = BuiltinHintProcessor::new_empty();

0 commit comments

Comments
 (0)