-
Notifications
You must be signed in to change notification settings - Fork 36
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
Provider events are not being forwarded by wrapper #73
Comments
I'm using |
So, as far as I understand, Since this bug happens with a very specific combination of ethers v5, hardhat-tracer, and fixtures/reset, IMO a less risky workaround at the hardhat-tracer would be ideal. I can help with figuring out how to do it. Off the top of my head, you would need to do something like: // get existing listeners and remove them from the provider
let eventListeners = {}
for (const eventName of provider.eventNames()) {
eventListeners[eventName] = []
for (const listener of provider.listeners(eventName)) {
eventListeners[eventName].push(listener)
}
provider.removeAllListeners(eventName)
}
// wrap the provider as you are doing today
hre.network.provider = wrapProvider(...)
// re-register the listeners
for (const [eventName, listeners] of Object.entries(eventListeners)) {
for (const listener of listeners) {
hre.network.provider.on(eventName, listener)
}
} (I haven't tested this though) |
I have included this in [email protected] |
Tested my reproduction steps with v3.1.0 but the behavior is the same 😕 |
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 whenhardhat-tracer
is used, any listener already set is "removed". This is easier to understand with an example.Take this
hardhat.config.js
:Here the
extendEnvironment
before loadinghardhat-tracer
is used to represent a plugin that registers a listener on the provider. I'm placing it before loadinghardhat-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 runawait hre.network.provider.send("hardhat_reset")
, you should seereset
being logged, but it's not. If you comment out thehardhat-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.The text was updated successfully, but these errors were encountered: