Skip to content

Commit 1c8d49d

Browse files
starknet_os_flow_tests: implement FuzzCallInfo::new_call
1 parent 33156c6 commit 1c8d49d

1 file changed

Lines changed: 23 additions & 16 deletions

File tree

crates/starknet_os_flow_tests/src/fuzz_tests.rs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ struct FuzzCallInfo {
199199
pub inner_calls: Vec<FuzzCallInfo>,
200200
}
201201

202+
impl FuzzCallInfo {
203+
pub fn new_call(
204+
address: ContractAddress,
205+
class_hash: ClassHash,
206+
parent_failure_behavior: ParentFailureBehavior,
207+
) -> Self {
208+
Self { address, class_hash, parent_failure_behavior, inner_calls: vec![] }
209+
}
210+
}
211+
202212
/// Represents the call tree of a fuzz test.
203213
#[allow(dead_code)]
204214
struct FuzzTestManager {
@@ -267,13 +277,12 @@ impl FuzzTestManager {
267277
}
268278

269279
// First call is the orchestrator calling the first fuzz test contract.
270-
let first_call = FuzzCallInfo {
271-
address: cairo1_contract_address_a,
272-
class_hash: *CAIRO1_CONTRACT_CLASS_HASH,
280+
let first_call = FuzzCallInfo::new_call(
281+
cairo1_contract_address_a,
282+
*CAIRO1_CONTRACT_CLASS_HASH,
273283
// The orchestrator always starts the test in a catching context.
274-
parent_failure_behavior: ParentFailureBehavior::Cairo1Catching,
275-
inner_calls: vec![],
276-
};
284+
ParentFailureBehavior::Cairo1Catching,
285+
);
277286
Self {
278287
calls: vec![first_call],
279288
current_call: vec![0],
@@ -402,22 +411,20 @@ impl FuzzTestManager {
402411
FuzzOperationData::Call(call_operation_data) => {
403412
let address = *call_operation_data.address();
404413
let class_hash = *self.deployed_fuzz_contracts.get(&address).unwrap();
405-
self.current_fuzz_call_info_mut().inner_calls.push(FuzzCallInfo {
414+
self.current_fuzz_call_info_mut().inner_calls.push(FuzzCallInfo::new_call(
406415
address,
407416
class_hash,
408-
parent_failure_behavior: call_operation_data.parent_failure_behavior(),
409-
inner_calls: vec![],
410-
});
417+
call_operation_data.parent_failure_behavior(),
418+
));
411419
self.current_call.push(self.current_fuzz_call_info().inner_calls.len() - 1);
412420
}
413421
FuzzOperationData::LibraryCall(library_call_operation_data) => {
414422
let current_address = self.current_fuzz_call_info().address;
415-
self.current_fuzz_call_info_mut().inner_calls.push(FuzzCallInfo {
416-
address: current_address,
417-
class_hash: *library_call_operation_data.class_hash(),
418-
parent_failure_behavior: library_call_operation_data.parent_failure_behavior(),
419-
inner_calls: vec![],
420-
});
423+
self.current_fuzz_call_info_mut().inner_calls.push(FuzzCallInfo::new_call(
424+
current_address,
425+
*library_call_operation_data.class_hash(),
426+
library_call_operation_data.parent_failure_behavior(),
427+
));
421428
self.current_call.push(self.current_fuzz_call_info().inner_calls.len() - 1);
422429
}
423430
}

0 commit comments

Comments
 (0)