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

Mainnet forking stopped working after 2.7.1 #2630

Closed
pdyraga opened this issue Apr 21, 2022 · 4 comments
Closed

Mainnet forking stopped working after 2.7.1 #2630

pdyraga opened this issue Apr 21, 2022 · 4 comments
Assignees

Comments

@pdyraga
Copy link

pdyraga commented Apr 21, 2022

tl;dr;

When trying to hardhat_reset on mainnet fork, I am getting TypeError: config.chains.has is not a function error. The code worked fine on hardhat version 2.7.1 and started failing once we updated to 2.8.4. Updating to the most recent version - 2.9.3 as of now - does not help.

How to reproduce

Option 1

  1. Check out https://github.com/threshold-network/solidity-contracts
  2. Try running FORKING_URL=https://eth-mainnet.alchemyapi.io/v2/<id> yarn test:system
  3. Observe TypeError: config.chains.has is not a function error

If you want to dive deeper: Go back in the history, to commit f129e209ff70e74d37e78d4db6d7987950844bb6, just before the version was updated you will see the tests passing. If you go to commit b8d198e9ec0e0adc91d35ad322d2815ad850a2b5 where the version was updated, you will see the tests failing.

Option 2

  1. Check out https://github.com/keep-network/coverage-pools
  2. Run FORKING_URL=https://eth-mainnet.alchemyapi.io/v2/<id> yarn test:system
  3. Observe tests passing
  4. Edit package.json and update Hardhat to the most recent version
  5. Run FORKING_URL=https://eth-mainnet.alchemyapi.io/v2/<id> yarn test:system
  6. Observe tests failing with TypeError: config.chains.has is not a function

Option 3

Try this piece of code with the most recent (2.9.3) hardhat version and config from either
https://github.com/threshold-network/solidity-contracts/blob/main/hardhat.config.ts
or
https://github.com/keep-network/coverage-pools/blob/main/hardhat.config.ts

You will see the test failing with TypeError: config.chains.has is not a function when trying to hardhat_reset.

const hre = require("hardhat")

describe.only("Forking test", () => {
  async function resetFork() {
    await hre.network.provider.request({
      method: "hardhat_reset",
      params: [
        {
          forking: {
            jsonRpcUrl: "https://eth-mainnet.alchemyapi.io/v2/<id>",
            blockNumber: 13619810,
          },
        },
      ],
    })
  }

  before(async () => {
    await resetFork()
  })

  it("should work", async () => {
    console.log("ok")
  })
})
  1) Forking test
       "before all" hook for "should work":
     TypeError: config.chains.has is not a function
      at Function.create (node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:199:25)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at async HardhatNetworkProvider._init (node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:250:28)
      at async HardhatNetworkProvider._send (node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:191:5)
      at async HardhatNetworkProvider.request (node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:117:18)
      at async resetFork (test/system/staking.test.js:5:5)
      at async Context.<anonymous> (test/system/staking.test.js:19:5)
@github-actions
Copy link
Contributor

This issue is also being tracked on Linear.

We use Linear to manage our development process, but we keep the conversations on Github.

LINEAR-ID: 146409a3-4675-476c-ba59-b12341a442d6

@fvictorio
Copy link
Member

Ugh, this one was hard. Thanks for reporting, @pdyraga.

I think the root of the issue is here:

https://github.com/keep-network/hardhat-local-networks-config/blob/964729beeb28115e143de61d6a99ece74eafb14b/src/index.ts#L21

The Hardhat Network config has a chains property, which is a Map. But if you use deepmerge with a map, it gets converted to an object (and you lose its contents):

> deepmerge({}, {a: new Map([[1, 1]])})
{ a: {} }

I don't know what's the right solution here. There is an open issue about this in the deepmerge repo and the author created an alternative that seems to support maps and sets, maybe that helps?

@fvictorio
Copy link
Member

I'm going to close this issue now because there's not much we can do here. Converting the chains Map to a plain object is a breaking change (and it would take a significant amount of work), so we won't be able to do it. But please let me know if I can help you in any way with this!

pdyraga added a commit to threshold-network/solidity-contracts that referenced this issue May 3, 2022
After an update in `deepmerge` library, `hardhat-local-networks-config`
stopped working and that lead to our system tests to fail with a
mysterious `TypeError: config.chains.has is not a function` error.

Until the problem is not fixed in `hardhat-local-networks-config`, the
plugin is removed. It was here for convenience and all tests are passing
without it.

See NomicFoundation/hardhat#2630
@pdyraga
Copy link
Author

pdyraga commented May 3, 2022

Thanks @fvictorio. I confirmed that after removing a reference to hardhat-local-networks-config-plugin from our config (threshold-network/solidity-contracts#102) tests on forked mainnet passed. I opened an issue in the plugin repo: facuspagnuolo/hardhat-local-networks-config-plugin#7

pdyraga added a commit to threshold-network/solidity-contracts that referenced this issue May 3, 2022
After an update in `deepmerge` library, `hardhat-local-networks-config`
stopped working and that lead to our system tests to fail with a
mysterious `TypeError: config.chains.has is not a function` error.

Until the problem is not fixed in `hardhat-local-networks-config`, the
plugin is removed. It was here for convenience and all tests are passing
without it.

See NomicFoundation/hardhat#2630
nkuba added a commit to threshold-network/solidity-contracts that referenced this issue May 6, 2022
Removed hardhat-local-networks-config plugin

After an update in `deepmerge` library, `hardhat-local-networks-config`
stopped working and that lead to our system tests failing with a
mysterious `TypeError: config.chains.has is not a function` error.

Until the problem is not fixed in `hardhat-local-networks-config`, the
plugin is removed. It was here for convenience and all tests are passing
without it.

See NomicFoundation/hardhat#2630


To test this change, try running system tests on `main`:
```
FORKING_URL=... yarn test:system --verbose
```

Then, try doing the same on this branch.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants