Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
test(concurrency): test scenarios of validate_reads with unvalid reads
Browse files Browse the repository at this point in the history
  • Loading branch information
OriStarkware committed Jun 13, 2024
1 parent 1bb3d97 commit 9916468
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions crates/blockifier/src/concurrency/versioned_state_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,71 @@ fn test_validate_reads(
);
}

#[rstest]
#[case::storage(
StateMaps {
storage: HashMap::from(
[((contract_address!("0x1"), storage_key!("0x1")), stark_felt!(1_u8))]
),
..Default::default()
},
StateMaps {
storage: HashMap::from(
[((contract_address!("0x1"), storage_key!("0x1")), stark_felt!(2_u8))]
),
..Default::default()
}
)]
#[case::nonces(
StateMaps {
nonces: HashMap::from([(contract_address!("0x1"), nonce!(1_u8))]),
..Default::default()
},
StateMaps {
nonces: HashMap::from([(contract_address!("0x1"), nonce!(2_u8))]),
..Default::default()
}
)]
#[case::class_hashes(
StateMaps {
class_hashes: HashMap::from([(contract_address!("0x1"), class_hash!(1_u8))]),
..Default::default()
},
StateMaps {
class_hashes: HashMap::from([(contract_address!("0x1"), class_hash!(2_u8))]),
..Default::default()
}
)]
#[case::compiled_class_hashes(
StateMaps {
compiled_class_hashes: HashMap::from([(class_hash!(1_u8), compiled_class_hash!(1_u8))]),
..Default::default()
},
StateMaps {
compiled_class_hashes: HashMap::from([(class_hash!(1_u8), compiled_class_hash!(2_u8))]),
..Default::default()
}
)]
#[case::declared_contracts(
StateMaps {
declared_contracts: HashMap::from([(class_hash!(1_u8), false)]),
..Default::default()
},
StateMaps {
declared_contracts: HashMap::from([(class_hash!(1_u8), true)]),
..Default::default()
}
)]
fn test_false_validate_reads(
#[case] state_maps_to_apply: StateMaps,
#[case] state_maps_to_validate: StateMaps,
safe_versioned_state: ThreadSafeVersionedState<CachedState<DictStateReader>>,
) {
let version_state_proxy = safe_versioned_state.pin_version(0);
version_state_proxy.state().apply_writes(0, &state_maps_to_apply, &HashMap::default());
assert!(!safe_versioned_state.pin_version(1).validate_reads(&state_maps_to_validate));
}

#[rstest]
fn test_apply_writes(
contract_address: ContractAddress,
Expand Down

0 comments on commit 9916468

Please sign in to comment.