Skip to content

Commit eccd6b0

Browse files
committed
chore: add invariant output test
1 parent c7d9703 commit eccd6b0

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed

crates/forge/tests/cli/test_cmd.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4104,3 +4104,41 @@ Encountered a total of 2 failing tests, 0 tests succeeded
41044104
41054105
"#]]);
41064106
});
4107+
4108+
// <https://github.com/foundry-rs/foundry/issues/11632>
4109+
#[cfg(not(feature = "isolate-by-default"))]
4110+
forgetest_init!(invariant_consistent_output, |prj, cmd| {
4111+
prj.update_config(|config| {
4112+
config.fuzz.seed = Some(U256::from(100u32));
4113+
config.invariant.runs = 10;
4114+
config.invariant.depth = 100;
4115+
});
4116+
prj.add_test(
4117+
"InvariantOutputTest.t.sol",
4118+
r#"
4119+
import {Test} from "forge-std/Test.sol";
4120+
4121+
contract InvariantOutputTest is Test {
4122+
uint256 count;
4123+
4124+
function setCond(uint256 cond) public {
4125+
if (cond > type(uint256).max / 2) {
4126+
count++;
4127+
}
4128+
}
4129+
4130+
function setUp() public {
4131+
targetContract(address(this));
4132+
}
4133+
4134+
function invariant_check_count() public {
4135+
require(count < 2, "failed invariant");
4136+
}
4137+
}
4138+
"#,
4139+
);
4140+
4141+
cmd.args(["test", "--mt", "invariant_check_count", "--color", "always"])
4142+
.assert_failure()
4143+
.stdout_eq(file!["../fixtures/invariant_traces.svg": TermSvg]);
4144+
});
Lines changed: 95 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)