Calling any view method on a contract deployed with "hardhat_setCode" return an empty string
Description
I am doing the following things to deploy a contract with the hardhat_setCode JSON-RPC method:
- Deploy a contract the usual way (via the
CREATEopcode) with waffle.deployContract - Load the runtime bytecode of that contract into a variable via
getCode - Set the runtime bytecode at a custom address
- 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
- Clone https://github.com/paulrberg/hardhat-set-code-bug
- Install dependencies with
yarn install - Create a
.envfile by following the.env.example - Generate TypeChain bindings via
yarn typechain - Run
yarn test
To make the tests pass, you can uncomment line 35.
Environment
Just tried with Hardhat v2.6.4 and I got the same result.
This is pretty odd, as we have a test that (tries to) verify this. We'll dig deeper into this. Thanks, @paulrberg
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.
This issue was closed because it has been stalled for 7 days with no activity.
This might still be relevant @alcuadrado @fvictorio. Might be worth it to re-open the issue if the behavior hasn't been patched.
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.