Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
PaulRBerg opened this issue Sep 15, 2021 · 6 comments

Comments

@PaulRBerg
Copy link
Contributor

PaulRBerg commented Sep 15, 2021

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

  • hardhat@2.6.2
@PaulRBerg
Copy link
Contributor Author

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

@alcuadrado
Copy link
Member

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

@github-actions
Copy link
Contributor

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 github-actions bot added the Stale label Jul 23, 2022
@github-actions
Copy link
Contributor

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

@PaulRBerg
Copy link
Contributor Author

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

@fvictorio
Copy link
Member

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 #2718.

@fvictorio fvictorio closed this as not planned Won't fix, can't repro, duplicate, stale Dec 29, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

3 participants