-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[Chai-matchers] Add polling mechanism when automine is not available #7997
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
Changes from all commits
6dfa35c
f144be3
157d989
005bf7d
08a5c71
670fd5b
30b0331
e62710d
df7f24a
df3c60f
6a5fe85
39b05e5
eb16806
4ddbc68
9cda25f
f2234be
d3eef66
fb64d99
cfea545
b8ed143
7b0535e
e52c968
3361fb0
9acae43
cc0c382
5fcc07a
a8baa1a
838b6a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@nomicfoundation/hardhat-ethers": patch | ||
| --- | ||
|
|
||
| Added `HardhatEthersProvider.waitForTransaction` to provide polling support for `non-automining` networks ([#7952](https://github.com/NomicFoundation/hardhat/issues/7952)). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@nomicfoundation/hardhat-ethers-chai-matchers": patch | ||
| --- | ||
|
|
||
| Added support to `hardhat-ethers-chai-matchers` for networks that do not support `automine` ([7952](https://github.com/NomicFoundation/hardhat/issues/7952)). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,3 +40,51 @@ describe("Rocket test", () => { | |
| expect(await rocket.status()).to.equal("lift-off"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Matchers without automining", () => { | ||
| it("emit should wait for the tx to be mined", async () => { | ||
| const { ethers, provider } = await hre.network.connect(); | ||
|
Comment on lines
+44
to
+46
|
||
|
|
||
| const Rocket = await ethers.getContractFactory("Rocket"); | ||
| const rocket = await Rocket.deploy("Apollo 11"); | ||
|
|
||
| await provider.request({ method: "evm_setAutomine", params: [false] }); | ||
|
|
||
| try { | ||
| const tx = await rocket.launch(); | ||
| const emitPromise = expect(tx).to.emit(rocket, "LaunchWithoutArgs"); | ||
|
|
||
| await provider.request({ method: "hardhat_mine", params: [] }); | ||
| await emitPromise; | ||
| } finally { | ||
| await provider.request({ method: "evm_setAutomine", params: [true] }); | ||
| } | ||
| }); | ||
|
|
||
| it("revert should wait for the tx to be mined", async () => { | ||
| const { ethers, provider } = await hre.network.connect(); | ||
|
|
||
| const FailingContract = await ethers.getContractFactory("FailingContract"); | ||
| const failing = await FailingContract.deploy(); | ||
|
|
||
| await provider.request({ method: "evm_setAutomine", params: [false] }); | ||
|
|
||
| try { | ||
| // Send the tx manually because fail() is pure, which makes ethers | ||
| // use staticCall instead of sending a real transaction. | ||
| const [signer] = await ethers.getSigners(); | ||
| const tx = await signer.sendTransaction({ | ||
| to: await failing.getAddress(), | ||
| data: failing.interface.encodeFunctionData("fail"), | ||
| gasLimit: 1_000_000, | ||
| }); | ||
|
|
||
| const revertPromise = expect(tx).to.be.revert(ethers); | ||
|
|
||
| await provider.request({ method: "hardhat_mine", params: [] }); | ||
| await revertPromise; | ||
| } finally { | ||
| await provider.request({ method: "evm_setAutomine", params: [true] }); | ||
| } | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ import type { | |||||||||||
| OverrideEventContract, | ||||||||||||
| } from "../helpers/contracts.js"; | ||||||||||||
| import type { HardhatEthers } from "@nomicfoundation/hardhat-ethers/types"; | ||||||||||||
| import type { EthereumProvider } from "hardhat/types/providers"; | ||||||||||||
|
|
||||||||||||
| import { before, beforeEach, describe, it } from "node:test"; | ||||||||||||
|
|
||||||||||||
|
|
@@ -896,6 +897,28 @@ describe(".to.emit (contract events)", { timeout: 60000 }, () => { | |||||||||||
| await expect(tx.hash).to.emit(contract, "WithoutArgs"); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| it("With an invalid transaction hash string", async () => { | ||||||||||||
| await assertRejects( | ||||||||||||
| () => expect("0x123").to.emit(contract, "WithoutArgs"), | ||||||||||||
| (e) => | ||||||||||||
| e.message.includes( | ||||||||||||
| 'Expected a valid transaction hash, but got "0x123"', | ||||||||||||
| ), | ||||||||||||
| "Expected invalid transaction hash error message", | ||||||||||||
| ); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| it("With a bytes32-encoded string that is not a real tx hash", async () => { | ||||||||||||
| await expect( | ||||||||||||
| expect( | ||||||||||||
| "0x3230323400000000000000000000000000000000000000000000000000000000", | ||||||||||||
| ).to.emit(contract, "WithoutArgs"), | ||||||||||||
| ).to.be.eventually.rejectedWith( | ||||||||||||
| AssertionError, | ||||||||||||
| "Transaction's receipt cannot be fetched from the network", | ||||||||||||
| ); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| describe("When event is overloaded", () => { | ||||||||||||
| it("should fail when the event name is ambiguous", async () => { | ||||||||||||
| await expect( | ||||||||||||
|
|
@@ -919,5 +942,59 @@ describe(".to.emit (contract events)", { timeout: 60000 }, () => { | |||||||||||
| ); | ||||||||||||
| }); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| describe("When automining is disabled", () => { | ||||||||||||
| let provider: EthereumProvider; | ||||||||||||
|
|
||||||||||||
| before(async () => { | ||||||||||||
| ({ provider } = await initEnvironment("events")); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
|
Comment on lines
+947
to
+952
|
||||||||||||
| let provider: EthereumProvider; | |
| before(async () => { | |
| ({ provider } = await initEnvironment("events")); | |
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TMP file to test in example project that the bug is fixed, it will be removed before merging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind leaving it to be honest.