foundry icon indicating copy to clipboard operation
foundry copied to clipboard

bug(`forge`): `--debug` filter does not accept functions with arguments

Open 0xbok opened this issue 3 years ago • 6 comments

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

0xbok avatar Oct 03 '22 12:10 0xbok

@mattsse Any insight on this? Just ran into this as well. Thank you.

KholdStare avatar Mar 02 '23 20:03 KholdStare

I am as well

addiaddiaddi avatar Mar 23 '23 22:03 addiaddiaddi

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.

smitrajput avatar Apr 25 '23 07:04 smitrajput

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.

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.

thedavidmeister avatar Jul 02 '23 17:07 thedavidmeister

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
;

llllvvuu avatar Sep 07 '23 23:09 llllvvuu

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 avatar Aug 06 '24 09:08 zerosnacks

@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.

qiweiii avatar Sep 21 '24 10:09 qiweiii

Thanks for looking into this and the PR @qiweiii!

zerosnacks avatar Sep 21 '24 17:09 zerosnacks