ChaosLabsInc / chainlink-hardhat-plugin

A hardhat plugin for configuring price feed return values based on mined blocks.
MIT License
15 stars 1 forks source link

Hardhat chainlink network error #1

Open kjr217 opened 2 years ago

kjr217 commented 2 years ago

Im trying to use the plugin on a hardhat mainnet fork. I'm using a slightly unconventional way of setting the network so I can choose whether to use mainnet fork on a suite by suite basis. This is a code snippet that is in the before() of the test suite. Shown below:

   await hre.network.provider.request({
            method: "hardhat_reset",
            params: [
                {
                    forking: {
                        chainId: 1,
                        jsonRpcUrl: `https://eth-mainnet.alchemyapi.io/v2/${process.env.ALCHEMY}`,
                        blockNumber: 14290000
                    }
                }
            ]
        })

But when trying to call initChainlinkPriceFeedConfig I get the error shown in the second snippet below:

const chainlinkConfig = new hre.ChainlinkPriceFeedConfig(url);
// Here we set the plugin to work with ETH/USD pair on Mainnet:
await chainlinkConfig.initChainlinkPriceFeedConfig("ETH/USD", "Mainnet");
Error: could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.6.0)
      at Logger.makeError (node_modules/@ethersproject/logger/src.ts/index.ts:261:28)
      at Logger.throwError (node_modules/@ethersproject/logger/src.ts/index.ts:273:20)
      at JsonRpcProvider.<anonymous> (node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:403:23)
      at step (node_modules/@ethersproject/providers/lib/json-rpc-provider.js:48:23)
      at Object.throw (node_modules/@ethersproject/providers/lib/json-rpc-provider.js:29:53)
      at rejected (node_modules/@ethersproject/providers/lib/json-rpc-provider.js:21:65)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:95:5)

When running the tests I am not specifying a network as I want some of my test suites to run on different networks, so ideally I would like it to work with how im setting the network.

I'm wondering if theres an issue with how im establishing the config or if its something else. If its an issue with establishing the config how would you recommend amending it that doesn't involve setting the network when running the test suite, alternatively is it possible to amend how the init function gets the network state.

Thanks :)

aapsi commented 1 month ago

@kjr217 Were you able to solve this?