Skip to content

Commit

Permalink
feat: add console2.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
mds1 committed Apr 20, 2022
1 parent 9401f07 commit ced2ef1
Show file tree
Hide file tree
Showing 3 changed files with 1,554 additions and 1 deletion.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,21 @@ contract Bar {

### `console.log`

Usage follows the same format as [Hardhat](https://hardhat.org/hardhat-network/reference/#console-log):
Usage follows the same format as [Hardhat](https://hardhat.org/hardhat-network/reference/#console-log).
It's recommended to use `console2.sol` as shown below, as this will show the decoded logs in Forge traces.

```solidity
// import it indirectly via Test.sol
import "forge-std/Test.sol";
// or directly import it
import "forge-std/console2.sol";
...
console2.log(someValue);
```

If you need compatibility with Hardhat, you must use the standard `console.sol` instead.
Due to a bug in `console.sol`, logs that use `uint256` or `int256` types will not be properly decoded in Forge traces.

```solidity
// import it indirectly via Test.sol
import "forge-std/Test.sol";
Expand Down
1 change: 1 addition & 0 deletions src/Test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity >=0.6.0 <0.9.0;
import "./Vm.sol";
import "ds-test/test.sol";
import "./console.sol";
import "./console2.sol";

// Wrappers around Cheatcodes to avoid footguns
abstract contract Test is DSTest {
Expand Down
Loading

0 comments on commit ced2ef1

Please sign in to comment.