Skip to content

Commit cbdd37e

Browse files
committed
Apply code review suggestions
1 parent 113bc5f commit cbdd37e

File tree

9 files changed

+29
-27
lines changed

9 files changed

+29
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
#### Added
1313

14-
- `get_current_step` function to get the current step from Cairo VM during test execution. For more see [docs](https://foundry-rs.github.io/starknet-foundry/snforge-library/testing/get_current_step.html)
14+
- `get_current_vm_step` function to get the current step from Cairo VM during test execution. For more see [docs](https://foundry-rs.github.io/starknet-foundry/snforge-library/testing/get_current_vm_step.html)
1515

1616
#### Changed
1717

crates/cheatnet/src/runtime_extensions/forge_runtime_extension/mod.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -554,26 +554,28 @@ impl<'a> ExtensionLogic for ForgeExtension<'a> {
554554
.cheat_block_hash(block_number, operation);
555555
Ok(CheatcodeHandlingResult::from_serializable(()))
556556
}
557-
"get_current_step" => {
557+
"get_current_vm_step" => {
558558
let top_call = extended_runtime
559559
.extended_runtime
560560
.extension
561561
.cheatnet_state
562562
.trace_data
563563
.current_call_stack
564564
.top();
565-
565+
let vm_steps_from_calls = calculate_vm_steps_from_calls(&top_call);
566566
let top_call_syscalls = &extended_runtime
567567
.extended_runtime
568568
.extended_runtime
569569
.hint_handler
570570
.base
571571
.syscalls_usage;
572+
let vm_steps_from_syscalls = &VersionedConstants::latest_constants()
573+
.get_additional_os_syscall_resources(top_call_syscalls)
574+
.n_steps;
575+
let total_vm_steps =
576+
vm_steps_from_calls + vm_steps_from_syscalls + vm.get_current_step();
572577

573-
let steps_from_calls = calculate_steps_from_calls(&top_call, top_call_syscalls);
574-
let total_steps = steps_from_calls + vm.get_current_step();
575-
576-
Ok(CheatcodeHandlingResult::from_serializable(total_steps))
578+
Ok(CheatcodeHandlingResult::from_serializable(total_vm_steps))
577579
}
578580
_ => Ok(CheatcodeHandlingResult::Forwarded),
579581
}
@@ -882,9 +884,9 @@ pub fn get_all_used_resources(
882884
}
883885
}
884886

885-
fn calculate_steps_from_calls(
887+
fn calculate_vm_steps_from_calls(
886888
top_call: &Rc<RefCell<CallTrace>>,
887-
top_call_syscalls: &SyscallUsageMap,
889+
// top_call_syscalls: &SyscallUsageMap,
888890
) -> usize {
889891
// Resources from inner calls already include syscall resources used in them
890892
let used_resources =
@@ -898,9 +900,9 @@ fn calculate_steps_from_calls(
898900
}
899901
CallTraceNode::DeployWithoutConstructor => acc,
900902
});
901-
let total_syscalls_exeucution_resources = &VersionedConstants::latest_constants()
902-
.get_additional_os_syscall_resources(&top_call_syscalls);
903-
let resources_from_calls = used_resources + total_syscalls_exeucution_resources;
903+
// let total_syscalls_exeucution_resources = &VersionedConstants::latest_constants()
904+
// .get_additional_os_syscall_resources(&top_call_syscalls);
905+
// let resources_from_calls = used_resources + total_syscalls_exeucution_resources;
904906

905-
resources_from_calls.n_steps
907+
used_resources.n_steps
906908
}

crates/forge/tests/integration/get_current_step.rs renamed to crates/forge/tests/integration/get_current_vm_step.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ use test_utils::running_tests::run_test_case;
66
use test_utils::test_case;
77

88
#[test]
9-
fn test_get_current_step() {
9+
fn test_get_current_vm_step() {
1010
let test = test_case!(
1111
indoc!(
1212
r#"
13-
use snforge_std::testing::get_current_step;
13+
use snforge_std::testing::get_current_vm_step;
1414
use snforge_std::{ContractClassTrait, DeclareResultTrait, declare};
1515
1616
#[test]
1717
fn check_current_step() {
18-
let step_start = get_current_step();
18+
let step_start = get_current_vm_step();
1919
2020
let contract = declare("HelloStarknet").unwrap().contract_class().clone();
2121
let _ = contract.deploy(@ArrayTrait::new()).unwrap();
2222
23-
let step_end = get_current_step();
23+
let step_end = get_current_vm_step();
2424
2525
assert!(step_end > step_start);
2626
}

crates/forge/tests/integration/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ mod gas;
1818
mod generate_random_felt;
1919
mod get_available_gas;
2020
mod get_class_hash;
21-
mod get_current_step;
21+
mod get_current_vm_step;
2222
mod interact_with_state;
2323
mod l1_handler_executor;
2424
mod message_to_l1;

docs/listings/testing_reference/tests/tests.cairo

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use snforge_std::testing::get_current_step;
1+
use snforge_std::testing::get_current_vm_step;
22
use snforge_std::{ContractClassTrait, DeclareResultTrait, declare};
33
use testing_reference::{ICounterSafeDispatcher, ICounterSafeDispatcherTrait};
44

@@ -21,9 +21,9 @@ fn setup() {
2121

2222
#[test]
2323
fn test_setup_steps() {
24-
let steps_start = get_current_step();
24+
let steps_start = get_current_vm_step();
2525
setup();
26-
let steps_end = get_current_step();
26+
let steps_end = get_current_vm_step();
2727

2828
// Assert that setup used no more than 100 steps
2929
assert!(steps_end - steps_start <= 100);

docs/src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
* [signature](appendix/snforge-library/signature.md)
131131
* [fuzzable](appendix/snforge-library/fuzzable.md)
132132
* [testing](appendix/snforge-library/testing.md)
133-
* [get_current_step](appendix/snforge-library/testing/get_current_step.md)
133+
* [get_current_vm_step](appendix/snforge-library/testing/get_current_vm_step.md)
134134
* [`sncast` Commands](appendix/sncast.md)
135135
* [common flags](appendix/sncast/common.md)
136136
* [account](appendix/sncast/account/account.md)

docs/src/appendix/snforge-library/testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Module containing functions useful for testing.
44

55
## Functions
66

7-
* [`get_current_step`](./testing/get_current_step.md)
7+
* [`get_current_vm_step`](./testing/get_current_vm_step.md)

docs/src/appendix/snforge-library/testing/get_current_step.md renamed to docs/src/appendix/snforge-library/testing/get_current_vm_step.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# `get_current_step`
1+
# `get_current_vm_step`
22

33
Gets the current step from Cairo VM during test execution.
44

55
```rust
6-
fn get_current_step() -> u32;
6+
fn get_current_vm_step() -> u32;
77
```
88

99
## Example

snforge_std/src/testing.cairo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::cheatcode::execute_cheatcode_and_deserialize;
22

33
/// Gets the current step from Cairo VM during test execution
4-
pub fn get_current_step() -> u32 {
5-
execute_cheatcode_and_deserialize::<'get_current_step', u32>(array![].span())
4+
pub fn get_current_vm_step() -> u32 {
5+
execute_cheatcode_and_deserialize::<'get_current_vm_step', u32>(array![].span())
66
}

0 commit comments

Comments
 (0)