Skip to content

Provider events are not being forwarded by wrapper #73

@fvictorio

Description

@fvictorio

hre.network.provider is an EventEmitter. One way Hardhat uses this is to emit events when the network is reset or a snapshot is reverted. But when hardhat-tracer is used, any listener already set is "removed". This is easier to understand with an example.

Take this hardhat.config.js:

extendEnvironment(hre => {
  hre.network.provider.on("hardhatNetworkReset", () => console.log("reset"))
})

require("hardhat-tracer")

module.exports = {
  solidity: "0.8.24",
};

Here the extendEnvironment before loading hardhat-tracer is used to represent a plugin that registers a listener on the provider. I'm placing it before loading hardhat-tracer, but it actually doesn't matter if it's after it (because of the way Hardhat executes its initailization).

If you open a console with npx hardhat console and run await hre.network.provider.send("hardhat_reset"), you should see reset being logged, but it's not. If you comment out the hardhat-tracer require, then it will work as expected.

I'm not sure what's the right fix here, but I suspect wrapProvider should somehow re-register any listeners already set in the existing provider.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions