Skip to content

Commit bd9d36d

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

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed

crates/forge/tests/cli/test_cmd.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4104,3 +4104,42 @@ 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+
config.invariant.show_metrics = false;
4116+
});
4117+
prj.add_test(
4118+
"InvariantOutputTest.t.sol",
4119+
r#"
4120+
import {Test} from "forge-std/Test.sol";
4121+
4122+
contract InvariantOutputTest is Test {
4123+
uint256 count;
4124+
4125+
function setCond(uint256 cond) public {
4126+
if (cond > type(uint256).max / 2) {
4127+
count++;
4128+
}
4129+
}
4130+
4131+
function setUp() public {
4132+
targetContract(address(this));
4133+
}
4134+
4135+
function invariant_check_count() public view {
4136+
require(count < 2, "failed invariant");
4137+
}
4138+
}
4139+
"#,
4140+
);
4141+
4142+
cmd.args(["test", "--mt", "invariant_check_count", "--color", "always"])
4143+
.assert_failure()
4144+
.stdout_eq(file!["../fixtures/invariant_traces.svg": TermSvg]);
4145+
});
Lines changed: 97 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)