foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Add table layout for `forge inspect <contract> abi`

Open zaevlad opened this issue 2 years ago • 2 comments

I guess it will be very useful to add a forge command to see all available functions in the contract as well as inherited in it. For example, with a "forge functions -contract MyContract" user will get a table in the respond like:

Fisrt column - function name; Second column - internal, external, payable, public; Third - contract name (inherited one); Probably, forth - inside functios;

So it will be much easier to see a contract stucture.

zaevlad avatar Feb 04 '23 14:02 zaevlad

forge inspect <contract> abi will give you all this information, we just need to add support to convert it into a table format by appending the --pretty flag. Similar to forge inspect <contract> storage-layout --pretty

mds1 avatar Feb 06 '23 16:02 mds1

forge inspect <contract> abi will give you all this information, we just need to add support to convert it into a table format by appending the --pretty flag. Similar to forge inspect <contract> storage-layout --pretty

yea, that --pretty with storage looks cool! If you could do the same with ABI, it would be aawesome! Thanks!

zaevlad avatar Feb 06 '23 17:02 zaevlad

we have the --pretty implemented, which would print something as below (not table)

forge inspect Counter abi --pretty
interface Counter {
    function getCounter() external view returns (uint256);
    function setCounter(uint256 count) external;
}

It's a little bit inconsistent and also json is default instead using the --json flag, @zerosnacks could you please chime in, is this something we'd want to make it consistent for all inspect commands by using --json flag and default to what's now behind --pretty flag?

grandizzy avatar Nov 25 '24 08:11 grandizzy

I tend to agree

JSON is the default here because you are effectively just extracting fields from a JSON artifact

I think we should change it so that --json yields effectively what is shown now as default and change the default to a Markdown table report structure, not an interface.

This is in line with cast storage e.g.

$ cast storage 0x5FbDB2315678afecb367f032d93F642f64180aa3

| Name   | Type    | Slot | Offset | Bytes | Value | Hex Value                                                          | Contract                |
|--------|---------|------|--------|-------|-------|--------------------------------------------------------------------|-------------------------|
| number | uint256 | 0    | 0      | 32    | 0     | 0x0000000000000000000000000000000000000000000000000000000000000000 | src/Counter.sol:Counter |
$ cast storage 0x5FbDB2315678afecb367f032d93F642f64180aa3 --json

{
  "storage": [
    {
      "astId": 40179,
      "contract": "src/Counter.sol:Counter",
      "label": "number",
      "offset": 0,
      "slot": "0",
      "type": "t_uint256"
    }
  ],
  "types": {
    "t_uint256": {
      "encoding": "inplace",
      "label": "uint256",
      "numberOfBytes": "32"
    }
  },
  "values": [
    "0x0000000000000000000000000000000000000000000000000000000000000000"
  ]
}

zerosnacks avatar Nov 25 '24 09:11 zerosnacks