Skip to content

Commit

Permalink
chore: improve fuzz scrape bytecode test (#8953)
Browse files Browse the repository at this point in the history
* chore: improve fuzz scrape bytecode test

* Remove duped comments, Trigger CI
  • Loading branch information
grandizzy authored Sep 25, 2024
1 parent 8d5a66d commit ccabf8b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 52 deletions.
67 changes: 50 additions & 17 deletions crates/forge/tests/it/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,27 +155,60 @@ async fn test_persist_fuzz_failure() {
assert_ne!(initial_calldata, new_calldata);
}

#[tokio::test(flavor = "multi_thread")]
async fn test_scrape_bytecode() {
let filter = Filter::new(".*", ".*", ".*fuzz/FuzzScrapeBytecode.t.sol");
let mut runner = TEST_DATA_DEFAULT.runner();
runner.test_options.fuzz.runs = 2000;
runner.test_options.fuzz.seed = Some(U256::from(100u32));
let suite_result = runner.test_collect(&filter);
forgetest_init!(test_can_scrape_bytecode, |prj, cmd| {
prj.add_source(
"FuzzerDict.sol",
r#"
// https://github.com/foundry-rs/foundry/issues/1168
contract FuzzerDict {
// Immutables should get added to the dictionary.
address public immutable immutableOwner;
// Regular storage variables should also get added to the dictionary.
address public storageOwner;
constructor(address _immutableOwner, address _storageOwner) {
immutableOwner = _immutableOwner;
storageOwner = _storageOwner;
}
}
"#,
)
.unwrap();

assert!(!suite_result.is_empty());
prj.add_test(
"FuzzerDictTest.t.sol",
r#"
import {Test} from "forge-std/Test.sol";
import "src/FuzzerDict.sol";
for (_, SuiteResult { test_results, .. }) in suite_result {
for (test_name, result) in test_results {
match test_name.as_str() {
"testImmutableOwner(address)" | "testStorageOwner(address)" => {
assert_eq!(result.status, TestStatus::Failure)
}
_ => {}
}
}
contract FuzzerDictTest is Test {
FuzzerDict fuzzerDict;
function setUp() public {
fuzzerDict = new FuzzerDict(address(100), address(200));
}
/// forge-config: default.fuzz.runs = 2000
function testImmutableOwner(address who) public {
assertTrue(who != fuzzerDict.immutableOwner());
}
/// forge-config: default.fuzz.runs = 2000
function testStorageOwner(address who) public {
assertTrue(who != fuzzerDict.storageOwner());
}
}
"#,
)
.unwrap();

// Test that immutable address is used as fuzzed input, causing test to fail.
cmd.args(["test", "--fuzz-seed", "100", "--mt", "testImmutableOwner"]).assert_failure();
// Test that storage address is used as fuzzed input, causing test to fail.
cmd.forge_fuse()
.args(["test", "--fuzz-seed", "100", "--mt", "testStorageOwner"])
.assert_failure();
});

// tests that inline max-test-rejects config is properly applied
forgetest_init!(test_inline_max_test_rejects, |prj, cmd| {
Expand Down
35 changes: 0 additions & 35 deletions testdata/default/fuzz/FuzzScrapeBytecode.t.sol

This file was deleted.

0 comments on commit ccabf8b

Please sign in to comment.