-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Contract event listener is not firing when running hardhat tests #1692
Comments
This might be a duplicate of #588 |
Hey @adamdry, the reason this doesn't work is that ethers.js, by default, uses polling to get events, and the polling interval is 4 seconds. If you add this at the end of your test: await new Promise(res => setTimeout(() => res(null), 5000)); you'll see the log being printed. (The Also, I don't think the polling interval can be configured 🙁 But maybe you can check ethers.js discussions board to see if someone asked about that. Closing this for now, but please re-open if you think there's something we can do on our side. |
Actually the polling interval can be configured. See how I did it in this test: https://github.com/nomiclabs/hardhat/blob/master/packages/hardhat-ethers/test/index.ts#L642 Also, I commented in that test where I got this technique, but just convenience, here too is the source: ethers-io/ethers.js#615 (comment) |
@feuGeneA oh, nice. I tried modifying |
@fvictorio @feuGeneA Thank you for your input! These are both very helpful to know. This solved my problem. Cheers! |
Here is a very small repo to show the issue: https://github.com/adamdry/ethers-event-issue
But I'll explain it here too. This is my contract:
And this is my test code:
I was expecting the
###########
to get printed to the console however it doesn't so the listener function isn't being executed for some reason.If I dig into the ContractReceipt the correct event data is there:
The text was updated successfully, but these errors were encountered: