Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,4 @@ tracing = "0.1.41"
tracing-chrome = "0.7.2"
tracing-log = "0.2.0"
comfy-table = "7"
insta = { version = "1.43.1", features = ["filters"] }
1 change: 1 addition & 0 deletions crates/forge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ cairo-lang-starknet-classes.workspace = true
walkdir.workspace = true
test-case.workspace = true
itertools.workspace = true
insta.workspace = true
docs = { workspace = true, features = ["testing"] }
packages_validation = { path = "../testing/packages_validation" }
project-root.workspace = true
1 change: 1 addition & 0 deletions crates/forge/tests/e2e/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use cairo_annotations::trace_data::{
CallTraceNode as ProfilerCallTraceNode, CallTraceV1 as ProfilerCallTrace,
};

mod output;
pub mod runner;

#[cfg(not(feature = "cairo-native"))]
Expand Down
24 changes: 24 additions & 0 deletions crates/forge/tests/e2e/common/output.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// Asserts a cleaned `stdout` snapshot using `insta`, filtered for non-deterministic lines.
/// Uses the current Scarb version as a snapshot suffix.
#[macro_export]
macro_rules! assert_cleaned_output {
($output:expr) => {{
let stdout = String::from_utf8_lossy(&$output.get_output().stdout);

let scarb_version = scarb_api::version::scarb_version()
.expect("Failed to get scarb version")
.scarb;

insta::with_settings!({
snapshot_suffix => scarb_version.to_string(),
filters => vec![
(r"\x1B\[[0-?]*[ -/]*[@-~]", ""), // ANSI escape regex - needed for CI
(r"(?m)^\s*(Compiling|Finished|Blocking).*", ""), // scarb output
(r"(?m)^\s*(Collected|Running|Tests:|Latest block number).*", ""), // snforge output
]},
{
insta::assert_snapshot!(stdout);
}
);
}};
}
123 changes: 7 additions & 116 deletions crates/forge/tests/e2e/gas_report.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::assert_cleaned_output;
use crate::e2e::common::runner::{
BASE_FILE_PATTERNS, Package, setup_package, setup_package_with_file_patterns, test_runner,
};
Expand All @@ -13,66 +14,19 @@ fn basic() {
.assert()
.code(0);

assert_stdout_contains(
output,
indoc! {r"
[..]Compiling[..]
[..]Finished[..]


Collected 1 test(s) from simple_package package
Running 0 test(s) from src/
Running 1 test(s) from tests/
[PASS] simple_package_integrationtest::contract::call_and_invoke (l1_gas: ~0, l1_data_gas: ~[..], l2_gas: ~[..])
╭------------------------+-------+-------+-------+---------+---------╮
| HelloStarknet Contract | | | | | |
+====================================================================+
| Function Name | Min | Max | Avg | Std Dev | # Calls |
|------------------------+-------+-------+-------+---------+---------|
| get_balance | 13340 | 13340 | 13340 | 0 | 2 |
|------------------------+-------+-------+-------+---------+---------|
| increase_balance | 24940 | 24940 | 24940 | 0 | 1 |
╰------------------------+-------+-------+-------+---------+---------╯

Tests: 1 passed, 0 failed, 0 ignored, [..] filtered out
"},
);
assert_cleaned_output!(output);
}

#[test]
fn recursive_calls() {
let temp = setup_package("debugging");

let output = test_runner(&temp)
.arg("test_debugging_trace_success")
.arg("--gas-report")
.arg("test_debugging_trace_success")
.assert()
.code(0);

assert_stdout_contains(
output,
indoc! {r"
[..]Compiling[..]
[..]Finished[..]


Collected 1 test(s) from debugging package
Running 0 test(s) from src/
Running 1 test(s) from tests/
[PASS] debugging_integrationtest::test_trace::test_debugging_trace_success (l1_gas: ~0, l1_data_gas: ~[..], l2_gas: ~[..])
╭-------------------------+-------+--------+--------+---------+---------╮
| SimpleContract Contract | | | | | |
+=======================================================================+
| Function Name | Min | Max | Avg | Std Dev | # Calls |
|-------------------------+-------+--------+--------+---------+---------|
| execute_calls | 11680 | 609080 | 183924 | 235859 | 5 |
|-------------------------+-------+--------+--------+---------+---------|
| fail | 17950 | 17950 | 17950 | 0 | 1 |
╰-------------------------+-------+--------+--------+---------+---------╯

Tests: 1 passed, 0 failed, 0 ignored, [..] filtered out
"},
);
assert_cleaned_output!(output);
}

#[test]
Expand All @@ -84,38 +38,7 @@ fn multiple_contracts_and_constructor() {
.assert()
.code(0);

assert_stdout_contains(
output,
indoc! {r"
[..]Compiling[..]
[..]Finished[..]


Collected 1 test(s) from simple_package_with_cheats package
Running 0 test(s) from src/
Running 1 test(s) from tests/
[PASS] simple_package_with_cheats_integrationtest::contract::call_and_invoke_proxy (l1_gas: ~0, l1_data_gas: ~[..], l2_gas: ~[..])
╭------------------------+-------+-------+-------+---------+---------╮
| HelloStarknet Contract | | | | | |
+====================================================================+
| Function Name | Min | Max | Avg | Std Dev | # Calls |
|------------------------+-------+-------+-------+---------+---------|
| get_block_number | 15780 | 15780 | 15780 | 0 | 2 |
╰------------------------+-------+-------+-------+---------+---------╯

╭-----------------------------+--------+--------+--------+---------+---------╮
| HelloStarknetProxy Contract | | | | | |
+============================================================================+
| Function Name | Min | Max | Avg | Std Dev | # Calls |
|-----------------------------+--------+--------+--------+---------+---------|
| constructor | 14650 | 14650 | 14650 | 0 | 1 |
|-----------------------------+--------+--------+--------+---------+---------|
| get_block_number | 125280 | 125280 | 125280 | 0 | 2 |
╰-----------------------------+--------+--------+--------+---------+---------╯

Tests: 1 passed, 0 failed, 0 ignored, [..] filtered out
"},
);
assert_cleaned_output!(output);
}

#[test]
Expand All @@ -124,44 +47,12 @@ fn fork() {
setup_package_with_file_patterns(Package::Name("forking".to_string()), BASE_FILE_PATTERNS);

let output = test_runner(&temp)
.arg("test_track_resources")
.arg("--gas-report")
.arg("test_track_resources")
.assert()
.code(0);

assert_stdout_contains(
output,
indoc! {r"
[..]Compiling[..]
[..]Finished[..]

Collected 1 test(s) from forking package
Running 1 test(s) from src/
[PASS] forking::tests::test_track_resources (l1_gas: ~0, l1_data_gas: ~[..], l2_gas: ~[..])
╭---------------------------+-------+-------+-------+---------+---------╮
| forked contract | | | | | |
| (class hash: 0x06a7…1550) | | | | | |
+=======================================================================+
| Function Name | Min | Max | Avg | Std Dev | # Calls |
|---------------------------+-------+-------+-------+---------+---------|
| get_balance | 40000 | 40000 | 40000 | 0 | 1 |
|---------------------------+-------+-------+-------+---------+---------|
| increase_balance | 40000 | 40000 | 40000 | 0 | 1 |
╰---------------------------+-------+-------+-------+---------+---------╯
╭---------------------------+-------+-------+-------+---------+---------╮
| forked contract | | | | | |
| (class hash: 0x07aa…af4b) | | | | | |
+=======================================================================+
| Function Name | Min | Max | Avg | Std Dev | # Calls |
|---------------------------+-------+-------+-------+---------+---------|
| get_balance | 13840 | 13840 | 13840 | 0 | 1 |
|---------------------------+-------+-------+-------+---------+---------|
| increase_balance | 25840 | 25840 | 25840 | 0 | 1 |
╰---------------------------+-------+-------+-------+---------+---------╯

Tests: 1 passed, 0 failed, 0 ignored, [..] filtered out
"},
);
assert_cleaned_output!(output);
}

#[test]
Expand Down
14 changes: 14 additions & 0 deletions crates/forge/tests/e2e/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: crates/forge/tests/e2e/gas_report.rs
expression: stdout
---
[PASS] simple_package_integrationtest::contract::call_and_invoke (l1_gas: ~0, l1_data_gas: ~192, l2_gas: ~524000)
╭------------------------+-------+-------+-------+---------+---------╮
| HelloStarknet Contract | | | | | |
+====================================================================+
| Function Name | Min | Max | Avg | Std Dev | # Calls |
|------------------------+-------+-------+-------+---------+---------|
| get_balance | 13840 | 13840 | 13840 | 0 | 2 |
|------------------------+-------+-------+-------+---------+---------|
| increase_balance | 25640 | 25640 | 25640 | 0 | 1 |
╰------------------------+-------+-------+-------+---------+---------╯
14 changes: 14 additions & 0 deletions crates/forge/tests/e2e/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: crates/forge/tests/e2e/gas_report.rs
expression: stdout
---
[PASS] simple_package_integrationtest::contract::call_and_invoke (l1_gas: ~0, l1_data_gas: ~192, l2_gas: ~510880)
╭------------------------+-------+-------+-------+---------+---------╮
| HelloStarknet Contract | | | | | |
+====================================================================+
| Function Name | Min | Max | Avg | Std Dev | # Calls |
|------------------------+-------+-------+-------+---------+---------|
| get_balance | 13340 | 13340 | 13340 | 0 | 2 |
|------------------------+-------+-------+-------+---------+---------|
| increase_balance | 24940 | 24940 | 24940 | 0 | 1 |
╰------------------------+-------+-------+-------+---------+---------╯
14 changes: 14 additions & 0 deletions crates/forge/tests/e2e/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: crates/forge/tests/e2e/gas_report.rs
expression: stdout
---
[PASS] simple_package_integrationtest::contract::call_and_invoke (l1_gas: ~0, l1_data_gas: ~192, l2_gas: ~510880)
╭------------------------+-------+-------+-------+---------+---------╮
| HelloStarknet Contract | | | | | |
+====================================================================+
| Function Name | Min | Max | Avg | Std Dev | # Calls |
|------------------------+-------+-------+-------+---------+---------|
| get_balance | 13340 | 13340 | 13340 | 0 | 2 |
|------------------------+-------+-------+-------+---------+---------|
| increase_balance | 24940 | 24940 | 24940 | 0 | 1 |
╰------------------------+-------+-------+-------+---------+---------╯
14 changes: 14 additions & 0 deletions crates/forge/tests/e2e/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: crates/forge/tests/e2e/gas_report.rs
expression: stdout
---
[PASS] simple_package_integrationtest::contract::call_and_invoke (l1_gas: ~0, l1_data_gas: ~192, l2_gas: ~510880)
╭------------------------+-------+-------+-------+---------+---------╮
| HelloStarknet Contract | | | | | |
+====================================================================+
| Function Name | Min | Max | Avg | Std Dev | # Calls |
|------------------------+-------+-------+-------+---------+---------|
| get_balance | 13340 | 13340 | 13340 | 0 | 2 |
|------------------------+-------+-------+-------+---------+---------|
| increase_balance | 24940 | 24940 | 24940 | 0 | 1 |
╰------------------------+-------+-------+-------+---------+---------╯
26 changes: 26 additions & 0 deletions crates/forge/tests/e2e/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
source: crates/forge/tests/e2e/gas_report.rs
expression: stdout
---
[PASS] forking::tests::test_track_resources (l1_gas: ~0, l1_data_gas: ~320, l2_gas: ~513850)
╭-------------------------+-------+-------+-------+---------+---------╮
| forked contract | | | | | |
| (class hash: 0x06…1550) | | | | | |
+=====================================================================+
| Function Name | Min | Max | Avg | Std Dev | # Calls |
|-------------------------+-------+-------+-------+---------+---------|
| get_balance | 40000 | 40000 | 40000 | 0 | 1 |
|-------------------------+-------+-------+-------+---------+---------|
| increase_balance | 40000 | 40000 | 40000 | 0 | 1 |
╰-------------------------+-------+-------+-------+---------+---------╯

╭-------------------------+-------+-------+-------+---------+---------╮
| forked contract | | | | | |
| (class hash: 0x07…af4b) | | | | | |
+=====================================================================+
| Function Name | Min | Max | Avg | Std Dev | # Calls |
|-------------------------+-------+-------+-------+---------+---------|
| get_balance | 13840 | 13840 | 13840 | 0 | 1 |
|-------------------------+-------+-------+-------+---------+---------|
| increase_balance | 25840 | 25840 | 25840 | 0 | 1 |
╰-------------------------+-------+-------+-------+---------+---------╯
26 changes: 26 additions & 0 deletions crates/forge/tests/e2e/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
source: crates/forge/tests/e2e/gas_report.rs
expression: stdout
---
[PASS] forking::tests::test_track_resources (l1_gas: ~0, l1_data_gas: ~320, l2_gas: ~509780)
╭---------------------------+-------+-------+-------+---------+---------╮
| forked contract | | | | | |
| (class hash: 0x06a7…1550) | | | | | |
+=======================================================================+
| Function Name | Min | Max | Avg | Std Dev | # Calls |
|---------------------------+-------+-------+-------+---------+---------|
| get_balance | 40000 | 40000 | 40000 | 0 | 1 |
|---------------------------+-------+-------+-------+---------+---------|
| increase_balance | 40000 | 40000 | 40000 | 0 | 1 |
╰---------------------------+-------+-------+-------+---------+---------╯

╭---------------------------+-------+-------+-------+---------+---------╮
| forked contract | | | | | |
| (class hash: 0x07aa…af4b) | | | | | |
+=======================================================================+
| Function Name | Min | Max | Avg | Std Dev | # Calls |
|---------------------------+-------+-------+-------+---------+---------|
| get_balance | 13840 | 13840 | 13840 | 0 | 1 |
|---------------------------+-------+-------+-------+---------+---------|
| increase_balance | 25840 | 25840 | 25840 | 0 | 1 |
╰---------------------------+-------+-------+-------+---------+---------╯
26 changes: 26 additions & 0 deletions crates/forge/tests/e2e/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
source: crates/forge/tests/e2e/gas_report.rs
expression: stdout
---
[PASS] forking::tests::test_track_resources (l1_gas: ~0, l1_data_gas: ~320, l2_gas: ~509780)
╭-------------------------+-------+-------+-------+---------+---------╮
| forked contract | | | | | |
| (class hash: 0x06…1550) | | | | | |
+=====================================================================+
| Function Name | Min | Max | Avg | Std Dev | # Calls |
|-------------------------+-------+-------+-------+---------+---------|
| get_balance | 40000 | 40000 | 40000 | 0 | 1 |
|-------------------------+-------+-------+-------+---------+---------|
| increase_balance | 40000 | 40000 | 40000 | 0 | 1 |
╰-------------------------+-------+-------+-------+---------+---------╯

╭-------------------------+-------+-------+-------+---------+---------╮
| forked contract | | | | | |
| (class hash: 0x07…af4b) | | | | | |
+=====================================================================+
| Function Name | Min | Max | Avg | Std Dev | # Calls |
|-------------------------+-------+-------+-------+---------+---------|
| get_balance | 13840 | 13840 | 13840 | 0 | 1 |
|-------------------------+-------+-------+-------+---------+---------|
| increase_balance | 25840 | 25840 | 25840 | 0 | 1 |
╰-------------------------+-------+-------+-------+---------+---------╯
Loading
Loading