Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 2015cad

Browse files
fmolettafannyguthmann
authored andcommitted
Fix ExecutionResources::increment_syscall_counter (#971)
* Fix increment_syscall_counter * Add test + fix test * Fix test * Fix tests * fmt
1 parent 04b2e35 commit 2015cad

File tree

5 files changed

+27
-16
lines changed

5 files changed

+27
-16
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ mod test {
392392
block_context.starknet_os_config.gas_price = 1;
393393

394394
let estimated_fee = estimate_message_fee(&l1_handler, state, &block_context).unwrap();
395-
assert_eq!(estimated_fee, (19708, 19695));
395+
assert_eq!(estimated_fee, (19709, 19695));
396396
}
397397

398398
#[test]

src/state/mod.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,11 @@ impl ExecutionResourcesManager {
8989
}
9090
}
9191

92-
pub fn increment_syscall_counter(&mut self, syscall_name: &str, amount: u64) -> Option<()> {
93-
self.syscall_counter
94-
.get_mut(syscall_name)
95-
.map(|val| *val += amount)
92+
pub fn increment_syscall_counter(&mut self, syscall_name: &str, amount: u64) {
93+
*self
94+
.syscall_counter
95+
.entry(syscall_name.to_string())
96+
.or_default() += amount
9697
}
9798

9899
pub fn get_syscall_counter(&self, syscall_name: &str) -> Option<u64> {
@@ -294,9 +295,7 @@ mod test {
294295
Default::default(),
295296
);
296297

297-
execution_resources_manager
298-
.increment_syscall_counter("syscall1", 1)
299-
.unwrap();
298+
execution_resources_manager.increment_syscall_counter("syscall1", 1);
300299

301300
assert_eq!(
302301
execution_resources_manager.get_syscall_counter("syscall1"),
@@ -308,6 +307,18 @@ mod test {
308307
);
309308
}
310309

310+
#[test]
311+
fn execution_resources_manager_should_add_syscall_if_not_present() {
312+
let mut execution_resources_manager = super::ExecutionResourcesManager::default();
313+
314+
execution_resources_manager.increment_syscall_counter("syscall1", 1);
315+
316+
assert_eq!(
317+
execution_resources_manager.get_syscall_counter("syscall1"),
318+
Some(1)
319+
);
320+
}
321+
311322
#[test]
312323
fn state_diff_to_cached_state_should_return_correct_cached_state() {
313324
let mut state_reader = InMemoryStateReader::default();

src/transaction/l1_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ mod test {
336336
fee_transfer_info: None,
337337
actual_fee: 0,
338338
actual_resources: HashMap::from([
339-
("n_steps".to_string(), 1229),
339+
("n_steps".to_string(), 1319),
340340
("pedersen_builtin".to_string(), 13),
341341
("range_check_builtin".to_string(), 23),
342342
("l1_gas_usage".to_string(), 19695),

tests/deploy_account.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ fn internal_deploy_account_cairo1() {
171171
let n_steps;
172172
#[cfg(not(feature = "cairo_1_tests"))]
173173
{
174-
n_steps = 3873;
174+
n_steps = 3948;
175175
}
176176
#[cfg(feature = "cairo_1_tests")]
177177
{
178-
n_steps = 3877;
178+
n_steps = 3952;
179179
}
180180

181181
assert_eq!(

tests/internals.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,10 +1224,10 @@ fn expected_fib_validate_call_info_2() -> CallInfo {
12241224

12251225
fn expected_transaction_execution_info(block_context: &BlockContext) -> TransactionExecutionInfo {
12261226
let resources = HashMap::from([
1227-
("n_steps".to_string(), 3445),
1227+
("n_steps".to_string(), 4135),
12281228
("pedersen_builtin".to_string(), 16),
12291229
("l1_gas_usage".to_string(), 2448),
1230-
("range_check_builtin".to_string(), 82),
1230+
("range_check_builtin".to_string(), 101),
12311231
]);
12321232
let fee = calculate_tx_fee(&resources, *GAS_PRICE, block_context).unwrap();
12331233
TransactionExecutionInfo::new(
@@ -1247,17 +1247,17 @@ fn expected_fib_transaction_execution_info(
12471247
let n_steps;
12481248
#[cfg(not(feature = "cairo_1_tests"))]
12491249
{
1250-
n_steps = 3541;
1250+
n_steps = 4231;
12511251
}
12521252
#[cfg(feature = "cairo_1_tests")]
12531253
{
1254-
n_steps = 3544;
1254+
n_steps = 4234;
12551255
}
12561256
let resources = HashMap::from([
12571257
("n_steps".to_string(), n_steps),
12581258
("l1_gas_usage".to_string(), 7344),
12591259
("pedersen_builtin".to_string(), 16),
1260-
("range_check_builtin".to_string(), 85),
1260+
("range_check_builtin".to_string(), 104),
12611261
]);
12621262
let fee = calculate_tx_fee(&resources, *GAS_PRICE, block_context).unwrap();
12631263
TransactionExecutionInfo::new(

0 commit comments

Comments
 (0)