foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Custom errors are not decoded (hex shown)

Open dxganta opened this issue 9 months ago • 2 comments

Component

Forge

Have you ensured that all of these are up to date?

  • [X] Foundry
  • [X] Foundryup

What version of Foundry are you on?

forge 0.2.0 (d431f74 2024-04-27T00:16:52.929844000Z)

What command(s) is the bug in?

forge test

Operating System

macOS (Apple Silicon)

Describe the bug

I would like to reopen the issue from here https://github.com/foundry-rs/foundry/issues/6579

I am not sure if the issue has been fixed because I am also getting hexadecimal custom errors.

Screenshot 2024-04-27 at 12 21 36 PM

To recreate the bug, please go to this repo here and use the command -> forge test --match-path test/scWETHv2.base.t.sol --match-test test_invest_basic -vv

dxganta avatar Apr 27 '24 06:04 dxganta

#6579 was done for custom errors within setup, will check the scenario you hit

grandizzy avatar Apr 27 '24 07:04 grandizzy

yep, I managed to recreate with the project above, the error is ErrorNotEnoughBalance thrown by the ERC20Bridged contract https://basescan.org/address/0x69ce2505CE515C0203160450157366F927243309 which is not an artifact created during test so the abi to properly decode error is not available - you can check this by for example adding error ErrorNotEnoughBalance(); in contract PriceConverter which is created during test run, it will output

Failing tests:
Encountered 1 failing test in test/scWETHv2.base.t.sol:scWETHv2Base
[FAIL. Reason: ErrorNotEnoughBalance()] test_invest_basic() (gas: 852945)

grandizzy avatar Apr 27 '24 13:04 grandizzy

yep, I managed to recreate with the project above, the error is ErrorNotEnoughBalance thrown by the ERC20Bridged contract https://basescan.org/address/0x69ce2505CE515C0203160450157366F927243309 which is not an artifact created during test so the abi to properly decode error is not available - you can check this by for example adding error ErrorNotEnoughBalance(); in contract PriceConverter which is created during test run, it will output

Failing tests:
Encountered 1 failing test in test/scWETHv2.base.t.sol:scWETHv2Base
[FAIL. Reason: ErrorNotEnoughBalance()] test_invest_basic() (gas: 852945)

I see. Thank you so much. Can you please tell me how did you decode the error is ErrorNotEnoughBalance() from the hex code please? That was really amazing.

dxganta avatar Apr 28 '24 06:04 dxganta

I took the code for failing contract and run forge inspect errors on it, see https://book.getfoundry.sh/reference/cli/forge/inspect?#forge-inspect You can also use forge selectors list https://book.getfoundry.sh/reference/cli/forge/selectors/list

(to get the code you can use forge clone or cast etherscan to download from verified contracts but you could only get the errors from failing contract, put in a local contract and run the command against)

grandizzy avatar Apr 28 '24 06:04 grandizzy

I took the code for failing contract and run forge inspect errors on it, see https://book.getfoundry.sh/reference/cli/forge/inspect?#forge-inspect You can also use forge selectors list https://book.getfoundry.sh/reference/cli/forge/selectors/list

(to get the code you can use forge clone or cast etherscan to download from verified contracts but you could only get the errors from failing contract, put in a local contract and run the command against)

So cooooooooollll. Thank you so much man. That was very helpful.

dxganta avatar Apr 28 '24 06:04 dxganta