AssertionError: Expected transaction to be reverted #5238
Answered
by
alymurtazamemon
ImAnshuJoshi
asked this question in
Q&A
-
it("picks a winner, resets, and sends money", async () => {
const additionalEntrances = 3
const startingIndex = 2
for (let i = startingIndex; i < startingIndex + additionalEntrances; i++) {
raffle = raffle.connect(accounts[i])
await raffle.enterRaffle({ value: raffleEntranceFee })
}
const startingTimeStamp = await raffle.getLastTimeStamp()
await new Promise(async (resolve, reject) => {
raffle.once("WinnerPicked", async () => {
console.log("WinnerPicked event fired!")
try {
console.log("hi")
const recentWinner = await raffle.getRecentWinner()
const raffleState = await raffle.getRaffleState()
const winnerBalance = await accounts[2].getBalance()
const endingTimeStamp = await raffle.getLastTimeStamp()
console.log("hi2")
await expect(raffle.getPlayer(0)).to.be.reverted
console.log("hi3")
assert.equal(recentWinner.toString(), accounts[2].address)
assert.equal(raffleState, 0)
assert.equal(
winnerBalance.toString(),
startingBalance
.add(
raffleEntranceFee
.mul(additionalEntrances)
.add(raffleEntranceFee)
)
.toString()
)
assert(endingTimeStamp > startingTimeStamp)
resolve()
} catch (e) {
reject(e)
}
})
const tx = await raffle.performUpkeep("0x")
const txReceipt = await tx.wait(1)
const startingBalance = await accounts[1].getBalance()
await vrfCoordinatorV2Mock.fulfillRandomWords(
txReceipt.events[1].args.requestId,
raffle.address
)
})
}) On running the above test , i am getting the error . AssertionError: Expected transaction to be reverted
+ expected - actual
-Transaction NOT reverted.
+Transaction reverted. Can anyoone help me with this error . |
Beta Was this translation helpful? Give feedback.
Answered by
alymurtazamemon
Apr 6, 2023
Replies: 2 comments 2 replies
-
@ImAnshuJoshi Make sure you have reset the variables inside await expect(raffle.getPlayer(0)).to.be.reverted you are expecting a revert. But it looks like players' array still returns the address on index 0. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Yes , i have reset the variables and now getting this error .
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ImAnshuJoshi this is I think the assertion of balance, you are comparing the starting balance of account 1 with the winner balance of account 2.