Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Important: If you're encountering any problem declaring contracts, please read the Blake Hash Support information.

get_current_vm_step

Gets the current step during test execution.

fn get_current_vm_step() -> u32;

Example

Test code:

use snforge_std::testing::get_current_vm_step;

#[feature("safe_dispatcher")]
fn setup() {
    let mut _counter = 0_u32;

    while _counter < 1_000 {
        _counter += 1;
    }
}

#[test]
fn test_setup_steps() {
    let steps_start = get_current_vm_step();
    setup();
    let steps_end = get_current_vm_step();

    // Assert that setup used no more than 20_000 steps
    assert!(steps_end - steps_start <= 20_000);
}

Let's run the test:

$ snforge test test_setup_steps
Output:
Collected 1 test(s) from testing_reference package
Running 1 test(s) from tests/
[PASS] testing_reference_integrationtest::tests::test_setup_steps ([..])
Running 0 test(s) from src/
Tests: 1 passed, 0 failed, 0 ignored, 0 filtered out