Lesson 9. Unit testing: Error: Timeout of 200000ms exceeded. It("picks a winner, reset the lottery, and send money") #5406
Replies: 5 comments 1 reply
-
Hey, did you happen to find any answer to the error? |
Beta Was this translation helpful? Give feedback.
-
Error: Timeout of 400000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
Hope this will help. |
Beta Was this translation helpful? Give feedback.
-
If you want I have the solution for ethers v6 but I suppose it's similar for ethers v5 |
Beta Was this translation helpful? Give feedback.
-
hi, it's 2025 and I am stuck too. package.json file: {
"name": "hardhat-fund-me",
"version": "1.0.0",
"description": "",
"license": "MIT",
"author": "",
"type": "commonjs",
"devDependencies": {
"@chainlink/contracts": "^1.4.0",
"@nomicfoundation/hardhat-chai-matchers": "^2.1.0",
"@nomicfoundation/hardhat-ethers": "^3.1.0",
"@nomicfoundation/hardhat-toolbox": "^6.1.0",
"@nomicfoundations/hardhat-ethers": "npm:hardhat-deploy-ethers@^0.4.2",
"dotenv": "^17.2.2",
"ethers": "^6.15.0",
"hardhat": "^2.26.3",
"hardhat-contract-sizer": "^2.10.1",
"hardhat-deploy": "^0.12.4",
"hardhat-deploy-ethers": "^0.4.2",
"hardhat-gas-reporter": "^2.3.0",
"prettier": "^3.6.2",
"prettier-plugin-solidity": "^2.1.0",
"solidity-coverage": "^0.8.16"
},
"scripts": {
"test": "hardhat test",
"test-staging": "hardhat test --network sepolia",
"coverage": "hardhat coverage",
"typechain": "yarn hardhat typechain"
}
} raffle.stating.test.ts file: import { assert, expect } from "chai";
import { network, ethers } from "hardhat";
import { developmentChains } from "../../helper-hardhat.config";
import fs from "fs";
import path from "path";
import { Raffle } from "../../typechain-types";
import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";
developmentChains.includes(network.name)
? describe.skip
: describe("Raffle Staging Tests", function () {
let raffle: Raffle;
let raffleEntranceFee: bigint;
let deployer: SignerWithAddress;
beforeEach(async function () {
const accounts = await ethers.getSigners();
deployer = accounts[0];
const deploymentPath = path.join(
__dirname,
`../../ignition/deployments/chain-${network.config.chainId}/deployed_addresses.json`,
);
const deploymentJson = JSON.parse(
fs.readFileSync(deploymentPath, "utf8"),
);
const raffleAddress = deploymentJson["RaffleModule#Raffle"];
if (!raffleAddress) {
throw new Error("Address not found");
}
raffle = (await ethers.getContractAt(
"Raffle",
raffleAddress,
)) as unknown as Raffle;
raffleEntranceFee = await raffle.getEntranceFee();
console.log(
`Raffle address is ${raffleAddress} and entrance fee is ${raffleEntranceFee}`,
);
});
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.getLastTimeStamp();
const accounts = await ethers.getSigners();
console.log("Setting up Listener...");
await new Promise<void>(async (resolve, reject) => {
setTimeout(resolve, 5000);
// setup listener before we enter the raffle
// Just in case the blockchain moves REALLY fast
raffle.once(raffle.filters.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 ethers.provider.getBalance(
accounts[0].address,
);
const endingTimeStamp =
await raffle.getLastTimeStamp();
await expect(raffle.getPlayer(0)).to.be.reverted;
assert.equal(
recentWinner.toString(),
accounts[0].address,
);
assert.equal(raffleState.toString(), "0");
assert.equal(
Number(winnerEndingBalance),
Number(winnerStartingBalance) +
Number(
ethers.formatEther(raffleEntranceFee),
),
);
assert(endingTimeStamp > startingTimeStamp);
resolve();
} catch (error) {
console.log(error);
reject(error);
}
});
// Then entering the raffle
console.log("Entering Raffle...");
const tx = await raffle.enterRaffle({
value: raffleEntranceFee,
});
await tx.wait(1);
console.log("Entered Raffle!");
console.log(
"Raffle state:",
(await raffle.getRaffleState()).toString(),
);
console.log("Players:", await raffle.getPlayer(0));
console.log(
"Interval:",
(await raffle.getInterval()).toString(),
);
console.log(
"Last timestamp:",
(await raffle.getLastTimeStamp()).toString(),
);
const winnerStartingBalance =
await ethers.provider.getBalance(accounts[0].address);
console.log("Ok, time to wait...");
// and this code WONT complete until our listener has finished listening!
});
});
});
}); I even set mocha time out to 20 mins, it's still the same. @TucanCrypto @Gandouye, I'd appreciate if you can help @muhammet72 were you able to figre it out? |
Beta Was this translation helpful? Give feedback.
-
I figured mine out. it was my helper config: export const networkConfig: networkConfigInfo = {
31337: {
name: "localhost",
subscriptionId: "588",
gasLane:
"0x474e34a077df58807dbe9c96d3c009b23b3c6d0cce433e59bbf5b34f823bc56c", // 30 gwei
keepersUpdateInterval: "30",
raffleEntranceFee: ethers.parseEther("0.01").toString(), // 0.01 ETH
callbackGasLimit: "500000", // 500,000 gas
},
11155111: {
name: "sepolia",
subscriptionId: "4529",
gasLane:
"0x787d74caea10b2b357790d5b5247c2f63d1d91572a9846f780606e4d953677ae", // 30 gwei <--- It was this
keepersUpdateInterval: "30",
raffleEntranceFee: ethers.parseEther("0.01").toString(), // 0.01 ETH
callbackGasLimit: "2500000",
vrfCoordinatorV2: "0x9DdfaCa8183c41ad55329BdeeD9F6A8d53168B1B", <--- and this
},
1: {
name: "mainnet",
keepersUpdateInterval: "30",
},
}; |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
.
Error
code
`
it("picks a winner, reset the lottery, and send money", async () => {
const additionalEntrants = 3
const startingAccountIndex = 1 // deployer = 0
const accounts = await ethers.getSigners()
for (let i = startingAccountIndex; i < startingAccountIndex + additionalEntrants; i++) {
const accountConnectedLottery = lottery.connect(accounts[i])
await accountConnectedLottery.enterLottery({ value: lotteryEntranceFee })
}
const startingTimeStamp = await lottery.getLatestTimeStamp()
// performUpkeep (mock being chainlink keeper)
// fulfilledRandomWords (mock being chainlink VRF)
// we will have to wait for fulfilledRandomWords to be called
await new Promise(async (resolve, reject) => {
lottery.once("winnerPicked", async () => {
console.log("Found the event!")
try {
const recentWinner = await lottery.getRecentWinner()
const lotteryState = await lottery.getLotteryState()
const endingTimeStamp = await lottery.getLatestTimeStamp()
const numPlayers = await lottery.getNumPlayers()
const winnerEndingBalance = await accounts[1].getBalance()
`
Beta Was this translation helpful? Give feedback.
All reactions