Skip to content

Commit 82f7b39

Browse files
DaniPopesmattsse
andauthored
test: memory_limit (#12299)
* test: memory_limit * update --------- Co-authored-by: Matthias Seitz <[email protected]>
1 parent 7163da0 commit 82f7b39

File tree

1 file changed

+50
-0
lines changed
  • crates/forge/tests/cli/test_cmd

1 file changed

+50
-0
lines changed

crates/forge/tests/cli/test_cmd/mod.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4236,3 +4236,53 @@ contract InvariantOutputTest is Test {
42364236
.assert_failure()
42374237
.stdout_eq(file!["../../fixtures/invariant_traces.svg": TermSvg]);
42384238
});
4239+
4240+
forgetest_init!(memory_limit, |prj, cmd| {
4241+
prj.wipe_contracts();
4242+
prj.update_config(|config| {
4243+
config.memory_limit = 500 * 32;
4244+
});
4245+
prj.add_test(
4246+
"MemoryLimit.t.sol",
4247+
r#"
4248+
import {Test} from "forge-std/Test.sol";
4249+
4250+
contract Memory {
4251+
function allocate(uint256 n) external pure returns (uint256[] memory) {
4252+
return new uint256[](n);
4253+
}
4254+
}
4255+
4256+
contract MemoryLimitTest is Test {
4257+
Memory public m = new Memory();
4258+
4259+
function test_inBounds() public {
4260+
m.allocate(100);
4261+
}
4262+
4263+
function test_oom() public {
4264+
m.allocate(1000);
4265+
}
4266+
}
4267+
"#,
4268+
);
4269+
4270+
cmd.arg("test").assert_failure().stdout_eq(str![[r#"
4271+
...
4272+
Ran 2 tests for test/MemoryLimit.t.sol:MemoryLimitTest
4273+
[PASS] test_inBounds() ([GAS])
4274+
[FAIL: EvmError: Revert] test_oom() ([GAS])
4275+
Suite result: FAILED. 1 passed; 1 failed; 0 skipped; [ELAPSED]
4276+
4277+
Ran 1 test suite [ELAPSED]: 1 tests passed, 1 failed, 0 skipped (2 total tests)
4278+
4279+
Failing tests:
4280+
Encountered 1 failing test in test/MemoryLimit.t.sol:MemoryLimitTest
4281+
[FAIL: EvmError: Revert] test_oom() ([GAS])
4282+
4283+
Encountered a total of 1 failing tests, 1 tests succeeded
4284+
4285+
Tip: Run `forge test --rerun` to retry only the 1 failed test
4286+
4287+
"#]]);
4288+
});

0 commit comments

Comments
 (0)