OpenZeppelin / openzeppelin-upgrades

Plugins for Hardhat and Foundry to deploy and manage upgradeable contracts on Ethereum.
MIT License
629 stars 270 forks source link

Register proxies in hardhat node for logging purposes #137

Open spalladino opened 4 years ago

spalladino commented 4 years ago

Buidler's wrapper around ethereumjs-vm, buidler node, provides meaningful logs regarding contract deployment, since it recognizes each contract from its bytecode:

eth_sendTransaction
  Contract deployment: Pool
  Contract address:    0x7c2c195cd6d34b8f845992d380aadb2730bb9c6f
  Transaction:         0xd33fa355826d6e90b300718e1ab43e933f8dfe3a38e95dba307b82829047b897
  From:                0xc783df8a850f42e7f7e57013759c285caa701eb6
  Value:               0 ETH
  Gas used:            382547 of 1912735
  Block #1:            0xa7fd692368f8066a5d5171f6823366848ae81aea226ab59deb56449285bc5e28

However, when deploying a proxy, the operation is shown on an UnrecognizedContract:

eth_sendTransaction
  Contract deployment: <UnrecognizedContract>

See if it's possible to use buidler_addCompilationResult or a similar method to register the proxies bytecode and name, so they show as Proxy in the logs.

frangio commented 4 years ago

This is not possible in Buidler yet but it's a feature they're building. I think the issue is https://github.com/nomiclabs/buidler/issues/553.

frangio commented 4 years ago

I was mistaken, it's already possible using the RPC method you mentioned.

Here's an example how to use it:

https://github.com/nomiclabs/buidler/blob/ec399160290a63f9fb247841b84af1ee2975bb6f/packages/buidler-core/src/builtin-tasks/utils/watch.ts#L49-L53

(Note that compilerVersion is the version of solc without a leading v, e.g. "0.6.0".)

thegostep commented 4 years ago

Ideally, the solution here would also provide stack traces to where the error occurs in the smart contract

frangio commented 4 years ago

@thegostep I'm pretty confident that stack traces through proxies do work. Here's an example I just ran:

$ hh run scripts/sample-script.js
Nothing to compile
Error: VM Exception while processing transaction: revert here
    at Box.fail2 (contracts/Box.sol:30)
    at Box.fail (contracts/Box.sol:26)
    at <UnrecognizedContract>.<unknown> (0x9fe46736679d2d9a65f0992f2272de9f3c7fa6e0)
    at process._tickCallback (internal/process/next_tick.js:68:7)

The only thing that is not working is the third line that shows UnrecognizedContract, which is what this issue is about, but is a minor issue.

If you're not seeing stack traces beyond the proxy there must be something else going on in your setup. Are you using hardhat test?

thegostep commented 4 years ago

The only thing that is not working is the third line that shows UnrecognizedContract, which is what this issue is about, but is a minor issue.

yes this is what I am referring to, apologies for the lack of clarity in my request.