PatrickAlphaC / hardhat-smartcontract-lottery-fcc

MIT License
117 stars 182 forks source link

Lesson 9: Staging test timing out at the 500 second mark #123

Closed Ugwumsi closed 1 year ago

Ugwumsi commented 1 year ago

Hello, I have been stuck on this for days now; I am trying to run the staging test but it always times out. Please refer to the code below. I tried using 'console.log()' to try and locate the part of the code that was taking too long and it seems to be the enter raffle part after the listener has been set up

 console.log("The first Phase")
                    //console.log(deployer)
                    await raffle.enterRaffle({value: raffleEntranceFee})
const { assert, expect } = require("chai")
const { network, getNamedAccounts, deployments, ethers } = require("hardhat")
const { resolveConfigFile } = require("prettier")
const { developmentChains } = require("../../helper-hardhat-config")

developmentChains.includes(network.name)
    ? describe.skip
    : describe("Raffle Unit Tests", function () {
          let raffle, raffleEntranceFee, deployer 

          beforeEach(async () => {
            deployer = (await getNamedAccounts()).deployer
            raffle = await ethers.getContract("Raffle", deployer)  
            raffleEntranceFee = await raffle.getEntranceFee()

          })
          describe("Fulfill Random Words", function () {
            //console.log("About to begin")
            it("Works with Live Chainlink Keepers and chainlink VRF, we get a random Winner", async function () {
                console.log("started...")
                const startingTimeStamp = await raffle.getLatestTimeStamp()
                const accounts = await ethers.getSigners()

                await new Promise(async (resolve, reject) => {
                    raffle.once("winnerPicked", async () => {
                        console.log("Winner Picked Event fired")
                        try{
                            const recentWinner = await raffle.getRecentWinner()
                            const raffleState = await raffle.getRaffleState()
                            const winnerBalance = 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(winnerBalance.toString(), winnerStartingBalance.add(raffleEntranceFee).toString())
                            assert(endingTimeStamp > startingTimeStamp)
                            done()
                            resolve()
                        } catch(error){
                            console.log(error)
                            reject(error)
                        }
                    })
                    console.log("The first Phase")
                    //console.log(deployer)
                    await raffle.enterRaffle({value: raffleEntranceFee})
                    console.log(accounts[0])
                    const winnerStartingBalance = await accounts[0].getBalance()

                    console.log("Finished first Phase")
                })   
            })
          })
    })
Ugwumsi commented 1 year ago

This is my terminal output when I try to run the staging test on the goerli network

macbookpro2018@macbooks-MacBook-Pro-2 hardhat-lottery % yarn hardhat test --network goerli
yarn run v1.22.19
$ /Users/macbookpro2018/Documents/blockchain/hh-fcc/hardhat-lottery/node_modules/.bin/hardhat test --network goerli

  Raffle Unit Tests
    Fulfill Random Words
started...
The first Phase
      1) Works with Live Chainlink Keepers and chainlink VRF, we get a random Winner

  0 passing (10m)
  1 failing

  1) Raffle Unit Tests
       Fulfill Random Words
         Works with Live Chainlink Keepers and chainlink VRF, we get a random Winner:
     Error: Timeout of 500000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/macbookpro2018/Documents/blockchain/hh-fcc/hardhat-lottery/test/staging/Raffle.staging.test.js)
      at listOnTimeout (node:internal/timers:564:17)
      at processTimers (node:internal/timers:507:7)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I have no idea what is going on. I will appreciate any assistance. Thank you!!

PatrickAlphaC commented 1 year ago

Can you:

  1. Make this a discusson on the full repo? https://github.com/smartcontractkit/full-blockchain-solidity-course-js/

Thanks!