hardhat icon indicating copy to clipboard operation
hardhat copied to clipboard

Calling any view method on a contract deployed with "hardhat_setCode" return an empty string

Open PaulRBerg opened this issue 4 years ago • 5 comments

Description

I am doing the following things to deploy a contract with the hardhat_setCode JSON-RPC method:

  1. Deploy a contract the usual way (via the CREATE opcode) with waffle.deployContract
  2. Load the runtime bytecode of that contract into a variable via getCode
  3. Set the runtime bytecode at a custom address
  4. Re-create the ethers.js contract at the custom address used in step 3

When I attempt to call a view method on this contract, I am getting only empty strings back. That makes my tests fail:

AssertionError: expected '' to equal 'Hello, world!'

Steps to Reproduce

  1. Clone https://github.com/paulrberg/hardhat-set-code-bug
  2. Install dependencies with yarn install
  3. Create a .env file by following the .env.example
  4. Generate TypeChain bindings via yarn typechain
  5. Run yarn test

To make the tests pass, you can uncomment line 35.

Environment

PaulRBerg avatar Sep 15 '21 14:09 PaulRBerg

Just tried with Hardhat v2.6.4 and I got the same result.

PaulRBerg avatar Sep 15 '21 17:09 PaulRBerg

This is pretty odd, as we have a test that (tries to) verify this. We'll dig deeper into this. Thanks, @paulrberg

alcuadrado avatar Sep 17 '21 12:09 alcuadrado

This issue was marked as stale because it didn't have any activity in the last 30 days. If you think it's still relevant, please leave a comment indicating so. Otherwise, it will be closed in 7 days.

github-actions[bot] avatar Jul 23 '22 08:07 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Jul 30 '22 09:07 github-actions[bot]

This might still be relevant @alcuadrado @fvictorio. Might be worth it to re-open the issue if the behavior hasn't been patched.

PaulRBerg avatar Jul 31 '22 09:07 PaulRBerg

The problem here is that the expected response is part of the state of the contract, set during deployment, and not part of the code. So the bytecode is copied, but the state of the greet state variable is empty.

We should have an easy way to do this, like the hardhat_copyAccount method suggested in https://github.com/NomicFoundation/hardhat/issues/2718.

fvictorio avatar Dec 29 '22 07:12 fvictorio