Lesson 9: Staging test failed - Timeout of 500000ms #960
-
All my unit tests passed successfully and the deployment works fine.. Unfortunately, the staging test is not working as expected.
This is const { assert, expect } = require("chai");
const { network, getNamedAccounts, ethers } = require("hardhat");
const { developmentChains, networkConfig } = 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("fulfillRandomWords", function () {
it("works with live Chainlink Keepers and Chainlink VRF, we get a random winner", async function () {
console.log("Setting up test...");
const startingTimeStamp = await raffle.getLastTimeStamp();
const accounts = await ethers.getSigners();
console.log("Setting up Listener...");
await new Promise(async (resolve, reject) => {
raffle.once("WinnerPicked", async () => {
console.log("WinnerPicked event fired!");
try {
const recentWinner = await raffle.getRecentWinner();
const raffleState = await raffle.getRaffleState();
const winnerEndingBalance = await accounts[0].getBalance();
const endingTimeStamp = await raffle.getLastTimeStamp();
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 (e) {
console.log(e);
reject(e);
}
});
});
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();
});
});
}); When the code reaches This is the link to the contract @PatrickAlphaC and @ali-thegilfoyle What is the way out. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
@samlak You need to put the enterRaffle whole code inside promise and out of event lisenter. |
Beta Was this translation helpful? Give feedback.
@samlak You need to put the enterRaffle whole code inside promise and out of event lisenter.