Error: Timeout of 500000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. #5050
-
Can anyone help me with this error im stuck here from a long time im not able to find error . error: attaching github repo link : - https://github.com/deepak2301/hardhat-raffle staging-test.js const { assert, expect } = require("chai")
const { network, getNamedAccounts, deployments, ethers } = require("hardhat")
const {
developmentChains,
networkConfig,
} = require("../../helper-hardhat-config")
//* describe can't work with promises so we dont need to make the async function
developmentChains.includes(network.name)
? describe.skip
: describe("Raffle Unit Tests", function () {
let raffle, raffleEntryFee, deployer
beforeEach(async () => {
deployer = (await getNamedAccounts()).deployers
raffle = await ethers.getContract("Raffle", deployer)
raffleEntryFee = await raffle.getEntryFee()
})
describe("fulfillRandomWords", function () {
it("Works with live ChainlinkKeeprs and ChainLink VRF,we get a random winnner", async () => {
console.log("Setting up test...")
//* Enter the raffle
const startingTimeStamp = await raffle.getLatestTimeStamp()
const accounts = await ethers.getSigners()
console.log("listening...")
await new Promise(async (resolve, reject) => {
//*setup listener before we enter the raffle
//* just in case the blockchain moves really fast
raffle.once("Winner Picked", async () => {
console.log("Winner Picked event fired!")
try {
//* add asserts
const recentWinner = await raffle.getRecentWinner()
const raffleState = await raffle.getRaffleState()
const winnerEndingBalance =
await accounts[0].getBalance()
const endingTimeStamp = await raffle.getLatestTimeStamp()
assert.expect(raffle.getPlayer(0)).to.be.reverted
assert.equal(
recentWinner.toString(),
accounts[0].address
)
assert.equal(raffleState, 0)
assert.equal(
winnerEndingBalance.toString(),
winnerStartingBalance.add(raffleEntryFee).toString()
)
assert.equal(endingTimeStamp > startingTimeStamp)
resolve()
} catch (error) {
console.log(error)
reject(error)
}
})
//* Then entering the raffle
console.log("Entering Raffle")
await raffle.enterraffle({ value: raffleEntryFee })
const winnerStartingBalance = await accounts[0].getBalance()
//* This block of code WONT complete until listener has finished listening
})
})
})
}) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
After // entering the raffle at bottom: (and enterRaffle is misspelled ) ADD: |
Beta Was this translation helpful? Give feedback.
-
If using ethers v6,some changes are needed. const winnerStartingBalance = await accounts[0].getBalance() To: const winnerStartingBalance = await ethers.provider.getBalance(accounts[1].address) furthermore, in v6, the BigNumber class has been replaced with the built-in ES2020, winnerStartingBalance.add(raffleEntryFee) To:
|
Beta Was this translation helpful? Give feedback.
After // entering the raffle at bottom: (and enterRaffle is misspelled )
Change:
await raffle.enterraffle({ value: raffleEntryFee })
TO:
const tx = await raffle.enterRaffle({value: raffleEntranceFee})
ADD:
await tx.wait(1)