bug(`forge`): `--debug` filter does not accept functions with arguments
Component
Forge
Describe the feature you would like
Test functions can have arguments to enable fuzzing. However, currently they can't be debugged using the --debug flag. It fails with:
Error:
Invalid hex calldata
Context:
- Invalid character 'x' at position 1
Additional context
No response
@mattsse Any insight on this? Just ran into this as well. Thank you.
I am as well
Got this when the function signature of test_myFunc() in
forge test --debug "test_myFunc(uint256,string)"
didn't match with the one in my code.
Ensure that the function signature in the command matches with the one in your code and retry.
Got this when the function signature of
test_myFunc()inforge test --debug "test_myFunc(uint256,string)"didn't match with the one in my code.Ensure that the function signature in the command matches with the one in your code and retry.
when i try this i get
[⠢] Compiling...
No files changed, compilation skipped
Error:
0 tests matched your criteria, but exactly 1 test must match in order to run the debugger.
Use --match-contract and --match-path to further limit the search.
I see the error reported by the OP, to me it sounds like a mismatch between a 0x prefixed hex string and something that just expects hex bytes.
It seems like in some places Foundry thinks the name is testIncrement and in others it thinks its testIncrement()? You also see this if you try to do an exact --match-test pattern for example, --match-test "^testIncrement$" doesn't work nor does --match-test "^testIncrement\(\)$
; forge test --match-test "^testIncrement"
[⠢] Compiling...
No files changed, compilation skipped
Running 1 test for test/Counter.t.sol:CounterTest
[PASS] testIncrement() (gas: 28334)
Test result: ok. 1 passed; 0 failed; 0 skipped; finished in 683.50µs
Ran 1 test suites: 1 tests passed, 0 failed, 0 skipped (1 total tests)
; forge test --match-test "^testIncrement\("
[⠢] Compiling...
No files changed, compilation skipped
;
Confirming that this is still unexpected
forge test --debug "testFuzz_SetNumber"
function testFuzz_SetNumber(bytes32 x) public {
counter.setNumber(uint256(x));
assertEq(counter.number(), uint256(x));
}
function testFuzz_SetNumber(uint256 x) public {
counter.setNumber(x);
assertEq(counter.number(), x);
}
Yields
2 tests matched your criteria, but exactly 1 test must match in order to run the debugger.
Use --match-contract and --match-path to further limit the search.
Using forge test --debug "testFuzz_SetNumber(bytes32)" or forge test --debug "testFuzz_SetNumber(uint256)" in an attempt to narrow it down yields:
Error:
0 tests matched your criteria, but exactly 1 test must match in order to run the debugger.
Use --match-contract and --match-path to further limit the search.
Filter used:
match-test: `testFuzz_SetNumber(uint256)
It is expected that you are able to filter by defining the function signature
@zerosnacks I looked into this, it's because --debug expect a regex, and "testFuzz_SetNumber(bytes32)" include ( and ) which means group in regex, so if I run forge test --debug testFuzz_SetNumber\(bytes32\)" it will work.
To resolve this issue, maybe make docs clearer.
Thanks for looking into this and the PR @qiweiii!