-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Labels
_priority:P0Critical priorityCritical priority
Description
A user lost time on their mocha test suite using chai matchers, as they where missing an await on an expect. The error shown was:
HardhatError: HHE100: An internal invariant was violatedWe should try and detect for this case and show a clear error message suggesting that the likely cause is a lack of an await.
Example
it('Should transfer money to another wallet with extra value', async function () {
const { accounts: { alice }, contracts: { drop }, others: { hashedElements, leaves, proofs, signature } } = await loadFixture(deployContractsFixture);
const txn = await drop.claim(alice, 1, proofs[leaves.indexOf(hashedElements[0])], signature, { value: 10 });
expect(txn).to.changeEtherBalance(ethers, alice, 10); // <-- missing await expect(txn)
});Investigation
An initial look suggests something like the following is happening
- By missing out the
awaitonexpect(txn).to.changeEtherBalance(ethers, alice, 10);, the test completes and passes - The test assertion is then run (in this case
changeEtherBalance) because it was not awaited - The assertion uses
ethersunderlying provider to make agetBlockrequest. The provider can't connect andethersreturns null - The null block number trips the internal variant exception.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
_priority:P0Critical priorityCritical priority
Type
Projects
Status
In Review