Support for hardhat/foundry console output#1050
Conversation
msooseth
left a comment
There was a problem hiding this comment.
LGTM, but can you maybe give more explanation at the top of the PR what this is about? I am not very familiar with hardhat. Then I'll approve and we can merge!
|
Added some description to this PR. |
blishko
left a comment
There was a problem hiding this comment.
Looks reasonable to me.
The tests need additional work.
EXTCODESIZE now returns 1 for the console address (matching cheatCode behavior), so contracts that check code size before calling won't skip the console.log call. Added 8 new tests covering EXTCODESIZE, format decoding (bool, address, no-args, unknown selector, short input), return value correctness, and multiple console.log calls. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
I did a thing -- adding more tests, changelog, and also one more place where a hardcoded address should be checked maybe? |
The test contract files were not tracked in git, causing CI failures since the Nix build only includes git-tracked files. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@blishko can you maybe re-review and then we can merge? Thanks! |
blishko
left a comment
There was a problem hiding this comment.
The unit tests should be moved, otherwise should be good to go!
| [ testCase "format-string" $ do | ||
| let encoded = ConcreteBuf $ abiMethod "log(string)" (AbiTuple $ V.fromList [AbiString "hello world"]) | ||
| assertEqual "console.log(string) format" "console::log(\"hello world\")" (formatConsoleLog encoded) | ||
| , testCase "format-uint" $ do | ||
| let encoded = ConcreteBuf $ abiMethod "log(uint256)" (AbiTuple $ V.fromList [AbiUInt 256 42]) | ||
| assertEqual "console.log(uint256) format" "console::log(42)" (formatConsoleLog encoded) | ||
| , testCase "format-string-uint" $ do | ||
| let encoded = ConcreteBuf $ abiMethod "log(string,uint256)" (AbiTuple $ V.fromList [AbiString "count", AbiUInt 256 7]) | ||
| assertEqual "console.log(string,uint256) format" "console::log(\"count\", 7)" (formatConsoleLog encoded) | ||
| , testCase "format-bool" $ do | ||
| let encoded = ConcreteBuf $ abiMethod "log(bool)" (AbiTuple $ V.fromList [AbiBool True]) | ||
| assertEqual "console.log(bool) format" "console::log(true)" (formatConsoleLog encoded) | ||
| , testCase "format-address" $ do | ||
| let encoded = ConcreteBuf $ abiMethod "log(address)" (AbiTuple $ V.fromList [AbiAddress 0xdeadbeef]) | ||
| assertEqual "console.log(address) format" "console::log(0x00000000000000000000000000000000DeaDBeef)" (formatConsoleLog encoded) | ||
| , testCase "format-no-args" $ do | ||
| let encoded = ConcreteBuf $ abiMethod "log()" (AbiTuple $ V.fromList []) | ||
| assertEqual "console.log() format" "console::log()" (formatConsoleLog encoded) | ||
| , testCase "format-unknown-selector" $ do | ||
| let encoded = ConcreteBuf $ BS.pack [0xde, 0xad, 0xbe, 0xef, 0x01, 0x02] | ||
| let result = formatConsoleLog encoded | ||
| assertBool "unknown selector should produce hex fallback" (T.isPrefixOf "console::log(0x" result) | ||
| , testCase "format-short-input" $ do | ||
| let encoded = ConcreteBuf $ BS.pack [0x01, 0x02] | ||
| assertEqual "short input format" "console::log()" (formatConsoleLog encoded) | ||
| ] |
There was a problem hiding this comment.
These tests should be moved elsewhere.
They do not test concrete VM executions (which is the purpose of this file), they are just unit tests for formatConsoleLog.
Not sure what is the best place for them, we can move them to the main test.hs for now.
Description
This PR implement console logging in the same way Foundry did (and Hardhat initially). The feature is explained here. This will help to fix crytic/echidna#1233.
Checklist