Skip to content

Commit

Permalink
move gas_report_fuzz_invariant to integration
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Feb 2, 2025
1 parent bbf9882 commit 622b35f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 65 deletions.
66 changes: 1 addition & 65 deletions crates/forge/bin/cmd/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,8 +952,7 @@ fn junit_xml_report(results: &BTreeMap<String, SuiteResult>, verbosity: u8) -> R
#[cfg(test)]
mod tests {
use super::*;
use foundry_config::{Chain, InvariantConfig};
use foundry_test_utils::forgetest_async;
use foundry_config::Chain;

#[test]
fn watch_parse() {
Expand Down Expand Up @@ -987,67 +986,4 @@ mod tests {
test("--chain-id=1", Chain::mainnet());
test("--chain-id=42", Chain::from_id(42));
}

forgetest_async!(gas_report_fuzz_invariant, |prj, _cmd| {
// speed up test by running with depth of 15
let config = Config {
invariant: { InvariantConfig { depth: 15, ..Default::default() } },
..Default::default()
};
prj.write_config(config);

prj.insert_ds_test();
prj.add_source(
"Contracts.sol",
r#"
//SPDX-license-identifier: MIT
import "./test.sol";
contract Foo {
function foo() public {}
}
contract Bar {
function bar() public {}
}
contract FooBarTest is DSTest {
Foo public targetContract;
function setUp() public {
targetContract = new Foo();
}
function invariant_dummy() public {
assertTrue(true);
}
function testFuzz_bar(uint256 _val) public {
(new Bar()).bar();
}
}
"#,
)
.unwrap();

let args = TestArgs::parse_from([
"foundry-cli",
"--gas-report",
"--root",
&prj.root().to_string_lossy(),
]);
let outcome = args.run().await.unwrap();
let gas_report = outcome.gas_report.as_ref().unwrap();

assert_eq!(gas_report.contracts.len(), 3, "{}", outcome.summary(Default::default()));
let call_cnts = gas_report
.contracts
.values()
.flat_map(|c| c.functions.values().flat_map(|f| f.values().map(|v| v.frames.len())))
.collect::<Vec<_>>();
// assert that all functions were called at least 100 times
assert!(call_cnts.iter().all(|c| *c > 100));
});
}
44 changes: 44 additions & 0 deletions crates/forge/tests/cli/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3520,6 +3520,50 @@ Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)
);
});

forgetest_async!(gas_report_fuzz_invariant, |prj, cmd| {
// speed up test by running with depth of 15
let config = Config {
invariant: { InvariantConfig { depth: 15, ..Default::default() } },
..Default::default()
};
prj.write_config(config);

prj.insert_ds_test();
prj.add_source(
"Contracts.sol",
r#"
import "./test.sol";
contract Foo {
function foo() public {}
}
contract Bar {
function bar() public {}
}
contract FooBarTest is DSTest {
Foo public targetContract;
function setUp() public {
targetContract = new Foo();
}
function invariant_dummy() public {
assertTrue(true);
}
function testFuzz_bar(uint256 _val) public {
(new Bar()).bar();
}
}
"#,
)
.unwrap();

cmd.args(["test", "--gas-report"]).assert_success();
});

// <https://github.com/foundry-rs/foundry/issues/5847>
forgetest_init!(can_bind_enum_modules, |prj, cmd| {
prj.clear();
Expand Down

0 comments on commit 622b35f

Please sign in to comment.