Skip to content

Commit 60cda6e

Browse files
committed
blockifier: share the test util assert_eq_test_result
1 parent 27a652b commit 60cda6e

File tree

4 files changed

+20
-28
lines changed

4 files changed

+20
-28
lines changed

crates/apollo_gateway/src/state_reader_test.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use blockifier::execution::contract_class::RunnableCompiledClass;
1818
use blockifier::state::contract_class_manager::ContractClassManager;
1919
use blockifier::state::errors::StateError;
2020
use blockifier::state::state_api::{StateReader, StateResult};
21+
use blockifier::state::state_api_test_utils::assert_eq_state_result;
2122
use blockifier::state::state_reader_and_contract_manager::StateReaderAndContractManager;
2223
use blockifier::test_utils::initial_test_state::state_reader_and_contract_manager_for_testing;
2324
use lazy_static::lazy_static;
@@ -430,21 +431,6 @@ lazy_static! {
430431
DUMMY_CONTRACT_CLASS_V0.clone().try_into().unwrap();
431432
}
432433

433-
fn assert_eq_state_result(
434-
a: &StateResult<RunnableCompiledClass>,
435-
b: &StateResult<RunnableCompiledClass>,
436-
) {
437-
match (a, b) {
438-
(Ok(a), Ok(b)) => assert_eq!(a, b),
439-
(Err(StateError::UndeclaredClassHash(a)), Err(StateError::UndeclaredClassHash(b))) => {
440-
assert_eq!(a, b)
441-
}
442-
_ => panic!("StateResult mismatch (or unsupported comparison): {a:?} vs {b:?}"),
443-
}
444-
}
445-
446-
// TODO(Arni): Check if any test cases here should move to the tests of
447-
// `StateReaderAndContractManager`.
448434
#[rstest]
449435
#[case::cairo_0_declared_and_cached(
450436
cairo_0_declared_scenario(),

crates/apollo_gateway/src/sync_state_reader_test.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use apollo_test_utils::{get_rng, GetTestInstance};
1111
use blockifier::execution::contract_class::RunnableCompiledClass;
1212
use blockifier::state::errors::StateError;
1313
use blockifier::state::state_api::{StateReader, StateResult};
14+
use blockifier::state::state_api_test_utils::assert_eq_state_result;
1415
use lazy_static::lazy_static;
1516
use mockall::predicate;
1617
use rstest::rstest;
@@ -200,19 +201,6 @@ lazy_static! {
200201
static ref DUMMY_CONTRACT_CLASS: ContractClass = ContractClass::test_casm_contract_class();
201202
}
202203

203-
fn assert_eq_state_result(
204-
a: &StateResult<RunnableCompiledClass>,
205-
b: &StateResult<RunnableCompiledClass>,
206-
) {
207-
match (a, b) {
208-
(Ok(a), Ok(b)) => assert_eq!(a, b),
209-
(Err(StateError::UndeclaredClassHash(a)), Err(StateError::UndeclaredClassHash(b))) => {
210-
assert_eq!(a, b)
211-
}
212-
_ => panic!("StateResult mismatch (or unsupported comparison): {a:?} vs {b:?}"),
213-
}
214-
}
215-
216204
#[rstest]
217205
#[case::class_declared(
218206
Ok(Some(DUMMY_CONTRACT_CLASS.clone())),

crates/blockifier/src/state.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ pub mod global_cache;
88
#[cfg(feature = "cairo_native")]
99
pub mod native_class_manager;
1010
pub mod state_api;
11+
#[cfg(any(feature = "testing", test))]
12+
pub mod state_api_test_utils;
1113
pub mod state_reader_and_contract_manager;
1214
pub mod stateful_compression;
1315
#[cfg(any(feature = "testing", test))]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use crate::execution::contract_class::RunnableCompiledClass;
2+
use crate::state::errors::StateError;
3+
use crate::state::state_api::StateResult;
4+
5+
pub fn assert_eq_state_result(
6+
a: &StateResult<RunnableCompiledClass>,
7+
b: &StateResult<RunnableCompiledClass>,
8+
) {
9+
match (a, b) {
10+
(Ok(a), Ok(b)) => assert_eq!(a, b),
11+
(Err(StateError::UndeclaredClassHash(a)), Err(StateError::UndeclaredClassHash(b))) => {
12+
assert_eq!(a, b)
13+
}
14+
_ => panic!("StateResult mismatch (or unsupported comparison): {a:?} vs {b:?}"),
15+
}
16+
}

0 commit comments

Comments
 (0)