Code runs properly until listener tries to listen to raffle.once("WinnerPicked", async () => { }

  • It fails to resolve the try/catch block
  • It fails to call upkeep but calls vrf succesfully (transactions for 0.1 ETH registered)


Error: Timeout of 500000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.


Code Block:

          describe("fulfillRandomWords", function () {
              it("works with live Chainlink Keepers and Chainlink VRF, we get a random winner", async function () {
                  // enter the raffle
                  console.log("Setting up test...")
                  const startingTimeStamp = await raffle.getLatestTimeStamp()
                  const accounts = await ethers.getSigners()

                  console.log("Setting up Listener...")
                  await new Promise(async (resolve, reject) => {
                      // setup listener before we enter the raffle
                      // Just in case the blockchain moves REALLY fast
                      raffle.once("WinnerPicked", async () => {
                          console.log("WinnerPicked event fired!")
                          try {
                              // add our asserts here
                              const recentWinner = await raffle.getRecentWinner()
                              const raffleState = await raffle.getRaffleState()
                              const winnerEndingBalance = await accounts[0].getBalance()
                              const endingTimeStamp = await raffle.getLatestTimeStamp()

                              await expect(raffle.getPlayer(0)).to.be.reverted
                              assert.equal(recentWinner.toString(), accounts[0].address)
                              assert.equal(raffleState, 0)
                              assert(endingTimeStamp > startingTimeStamp)
                          } catch (error) {

                      // Then entering the raffle
                      console.log("Entering Raffle...")
                      const tx = await raffle.enterRaffle({ value: raffleEntranceFee })
                      await tx.wait(1)
                      console.log("Ok, time to wait...")
                      const winnerStartingBalance = await accounts[0].getBalance()
                      console.log("All Good here!!!")
                      // and this code WONT complete until our listener has finished listening!


Solutions Attempted:

| When removed alters the code and functionality & does not fix the problem in my case

(bool upkeepNeeded, ) = checkUpkeep("");
      if (!upkeepNeeded) {
          revert Raffle__UpkeepNotNeeded(

| 5 days spent researching a solution but still no success...

================================================================ Steps to reproduce:


Chainlink Solidity Course Repo: https://github.com/PatrickAlphaC/hardhat-smartcontract-lottery-fcc

  • ../test/staging/Raffle.staging.test.js


I would appreciate if someone could help me figure out how to fix the problem block or code so it runs as originally intended.

Thank you!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.