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

test(concurrency): test scenarios of validate_reads with unvalid reads #1955

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 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,80 @@ 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()
}
)]
fn test_false_validate_reads(
#[case] tx_1_reads: StateMaps,
#[case] tx_0_writes: StateMaps,
safe_versioned_state: ThreadSafeVersionedState<CachedState<DictStateReader>>,
) {
let version_state_proxy = safe_versioned_state.pin_version(0);
version_state_proxy.state().apply_writes(0, &tx_0_writes, &HashMap::default());
assert!(!safe_versioned_state.pin_version(1).validate_reads(&tx_1_reads));
}

#[rstest]
fn test_false_validate_reads_declared_contracts(
safe_versioned_state: ThreadSafeVersionedState<CachedState<DictStateReader>>,
) {
let tx_1_reads = StateMaps {
declared_contracts: HashMap::from([(class_hash!(1_u8), false)]),
..Default::default()
};
let tx_0_writes = StateMaps {
declared_contracts: HashMap::from([(class_hash!(1_u8), true)]),
..Default::default()
};
let version_state_proxy = safe_versioned_state.pin_version(0);
let compiled_contract_calss = FeatureContract::TestContract(CairoVersion::Cairo1).get_class();
let class_hash_to_class = HashMap::from([(class_hash!(1_u8), compiled_contract_calss)]);
version_state_proxy.state().apply_writes(0, &tx_0_writes, &class_hash_to_class);
assert!(!safe_versioned_state.pin_version(1).validate_reads(&tx_1_reads));
}

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