DorianDaSilva
DorianDaSilva

Reputation: 1

Staging test: Listener not resolving - TimeOut Error ( ChainLink Solidity Course)

  Raffle Staging Tests
    fulfillRandomWords
Setting up test...
Setting up Listener...
Entering Raffle...
Ok, time to wait...
All Good here!!!
      1) works with live Chainlink Keepers and Chainlink VRF, we get a random winner


  0 passing (8m)
  1 failing

Problem:

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

Error:

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.equal(
                                  winnerEndingBalance.toString(),
                                  winnerStartingBalance.add(raffleEntranceFee).toString()
                              )
                              assert(endingTimeStamp > startingTimeStamp)
                              resolve()
                          } catch (error) {
                              console.log(error)
                              reject(e)
                          }
                      })

                      // 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(
              address(this).balance,
              s_players.length,
              uint256(s_raffleState)
          );
      }

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

================================================================

Steps to reproduce:

================================================================

Repo:

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

================================================================

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!

Upvotes: 0

Views: 206

Answers (0)

Related Questions