Waffle
Waffle copied to clipboard
"Error: [object Promise] is not a valid transaction" when calling `expect().to.emit()`
Hi there!
I'm facing this error when trying to call the event catcher:
await expect(
tokenFarm.depositTokens(tokens("100"), 0, {
from: investor,
})
)
.to.emit(tokenFarm, "Deposit")
.withArgs([investor, 0, tokens("97")]);
It seems to be caused by the following code:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.waitForPendingTransaction = void 0;
async function waitForPendingTransaction(tx, provider) {
let hash;
if (tx instanceof Promise) {
({ hash } = await tx); // Here the destructuring should be "tx" insdead of "hash"
}
else if (typeof tx === 'string') {
hash = tx;
}
else {
({ hash } = tx);
}
if (!hash) {
throw new Error(`${tx} is not a valid transaction`);
}
return provider.waitForTransaction(hash);
}
exports.waitForPendingTransaction = waitForPendingTransaction;
When destructuring hash
as follows:
({tx:hash} = await tx)
The error is now TypeError: Cannot read property 'waitForTransaction' of undefined
I appreciate any help!
I am seeing this same issue. I am just trying to figure out how to use await expect(...).to.emit()...
but can't seem to get it to work. Have you made any progress debugging this in the last couple of months?
I get the same error (from your title):
Error: [object Promise] is not a valid transaction
From my code:
await expect(token0.transfer(bobby, 1000, { from: alice }))
.to.emit(token0, 'Transfer')
.withArgs(alice, bobby, 1000)
I am fairly new to Eth/Solidity development, so I am a bit lost here. Hope someone can help!
Thanks!
Have you guys had any luck finding a fix for this ?
Any luck guys facing same issue.?
Got the same error, using hardhat. Oddly, it only breaks on one of my 27 tests. It's the only test that calls a method from a foreign contract. I'll try to figure it out
Okay, this is why I was having it:
You're supposed to be passing a contract as first param like this
TypeScript saves my day. Not sure if that was your problem, though. Had to refactor everything to use TS but it was worth it
EDIT: I see that wasn't your issue. I remember another change I made, maybe this was the one that fixed it (I don't think so, though). Here, at the top, I had something like this.
If you leave it like this, without semicolons, the line below the getSigners is passed as parameter. You need to use a semicolon to enforce it as a separate statement.
I doubt any of this was the fix, but it's what I got. This is all magic to me
I'm having the same problem... I've tried various combinations of awaiting, passing expect
a function rather than a promise, etc.
In the end, I have the same error (Error: [object Promise] is not a valid transaction
).
Here is an excerpt of code triggering this error.
it('Blah', async () => {
const subject = access.paginateGovernors(0, 3);
await expect(subject).to.emit(paginationLib, 'A');
})
Is anyone having this problem with Waffle 4? This part was worked on so the issue could already be fixed in Waffle 4.