Lesson 9: Error: Timeout of 500000ms exceeded. URGENCY!!! #5485
-
I've been getting this error
And I have tried implementing what others did to have their solutions, I even copied the code from the GitHub repo and pasted it and I got the same error. Please can someone help me. This is the staging code: Raffle.staging.test.js const { assert, expect } = require("chai")
const { getNamedAccounts, ethers, network } = require("hardhat")
const { developmentChains } = require("../../helper-hardhat-config")
developmentChains.includes(network.name)
? describe.skip
: describe("Raffle Staging Tests", function () {
let raffle, raffleEntranceFee, deployer
beforeEach(async function () {
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 () {
// 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("Raffle__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.getPlayers(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(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()
// and this code WONT complete until our listener has finished listening!
})
})
})
}) hardhat.config.js require("@nomiclabs/hardhat-waffle")
require("@nomiclabs/hardhat-etherscan")
require("hardhat-deploy")
require("solidity-coverage")
require("hardhat-gas-reporter")
require("hardhat-contract-sizer")
require("dotenv").config()
/** @type import('hardhat/config').HardhatUserConfig */
const SEPOLIA_RPC_URL = process.env.SEPOLIA_RPC_URL
const PRIVATE_KEY = process.env.PRIVATE_KEY
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY || ""
const COINMARKETCAP_API_KEY = process.env.COINMARKETCAP_API_KEY
module.exports = {
defaultNetwork: "hardhat",
networks: {
hardhat: {
chainId: 31337,
blockConfirmations: 1,
},
sepolia: {
url: SEPOLIA_RPC_URL,
chainId: 11155111,
accounts: [PRIVATE_KEY],
saveDeployments: true,
blockConfirmations: 6,
},
},
solidity: "0.8.18",
namedAccounts: {
deployer: {
default: 0,
},
player: {
default: 1,
},
},
etherscan: {
apiKey: {
sepolia: ETHERSCAN_API_KEY,
},
},
gasReporter: {
enabled: false,
currency: "USD",
outputFile: "gas-report.txt",
noColors: true,
},
mocha: {
timeout: 500000, //500 seconds max
},
} This is the Raffle.sol //SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
// Raffle contract (What I need):
// Enter the lottery
// Pick a random winner (verifiably random)
// Winner should be selected every X minutes -> completely automated
// We need a chainlink oracle (we need the randomness from outside the blockchain)
// We need automated execution to trigger selecting a winner (chainlink keepers)
/**@title A sample Raffle Contract
* @author Akin-Thomas Bishop
* @notice This contract is for creating a sample raffle contract
* @dev This implements the Chainlink VRF Version 2
*/
// We need a chainlink oracle (we need the randomness from outside the blockchain)
import "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol";
import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol";
// We need automated execution to trigger selecting a winner (chainlink keepers)
import "@chainlink/contracts/src/v0.8/interfaces/KeeperCompatibleInterface.sol";
//error
error Raffle__notEnoughETHEntered();
error Raffle__TransferFailed();
error Raffle__NotOpen();
error Raffle__UpkeepNotNeeded(uint256 currectBalance, uint256 numPlayers, uint256 raffleState);
contract Raffle is VRFConsumerBaseV2, KeeperCompatibleInterface {
/*Type Declartions */
enum RaffleState {
OPEN,
CALCULATING
}
/*State Variables */
uint256 private immutable i_entranceFee;
address payable[] private s_players;
VRFCoordinatorV2Interface private immutable i_vrfCoordinator;
bytes32 private immutable i_gasLane;
uint64 private immutable i_subscriptionId;
uint32 private immutable i_callbackGasLimit;
uint16 private constant REQUEST_CONFIRMATION = 3;
uint32 private constant NUM_WORDS = 1;
/*Lottery variables */
address private s_recentWinner;
RaffleState private s_raffleState;
uint256 private s_lastTimestamp;
uint256 private immutable i_interval;
/*Events */
event RaffleEnter(address indexed player);
event RequestedRaffleWinner(uint256 indexed requestId);
event Raffle__WinnerPicked(address indexed winner);
constructor(
address vrfCoordinatorV2,
uint256 entranceFee,
bytes32 gasLane,
uint64 subscriptionId,
uint32 callbackGasLimit,
uint256 interval
) VRFConsumerBaseV2(vrfCoordinatorV2) {
i_entranceFee = entranceFee;
i_vrfCoordinator = VRFCoordinatorV2Interface(vrfCoordinatorV2);
i_gasLane = gasLane;
i_subscriptionId = subscriptionId;
i_callbackGasLimit = callbackGasLimit;
s_raffleState = RaffleState.OPEN;
s_lastTimestamp = block.timestamp;
i_interval = interval;
}
modifier entranceFeePayment() {
if (msg.value < i_entranceFee) {
revert Raffle__notEnoughETHEntered();
}
_;
}
//Enter the lottery
function enterRaffle() public payable entranceFeePayment {
if (s_raffleState != RaffleState.OPEN) {
revert Raffle__NotOpen();
}
s_players.push(payable(msg.sender));
// Emit an even when we update a dynamic array or mapping
emit RaffleEnter(msg.sender);
}
/**@dev (checkUpkeep) => This is the fuction that the ChainLink Keepers nodes call
* they look for the `upkeepNeeded` to return true
* The following should be true for this to return true:
* 1. The time interval has passed between raffle runs.
* 2. The lottery is open Have atleast one player.
* 3. The contract has some ETH.
* 4. Implicity, your subscription is funded with LINK.
* 5. The lottery should be in an "open" state.
*/
// Winner should be selected every X minutes -> completely automated
function checkUpkeep(
bytes memory /* performData */
) public view override returns (bool upkeepNeeded, bytes memory /*performData*/) {
bool isOpen = (RaffleState.OPEN == s_raffleState);
// (the current block.timestamp - the last block.timestamp) > an interval
bool timePassed = ((block.timestamp - s_lastTimestamp) > i_interval);
bool hasPlayers = s_players.length > 0;
bool hasBalance = address(this).balance > 0;
upkeepNeeded = (isOpen && timePassed && hasPlayers && hasBalance);
return (upkeepNeeded, "0x0");
}
function performUpkeep(bytes memory /*performData*/) external override {
// (bool upkeepNeeded, ) = checkUpkeep("");
// if (!upkeepNeeded) {
// revert Raffle__UpkeepNotNeeded(
// address(this).balance,
// s_players.length,
// uint256(s_raffleState)
// );
// }
s_raffleState = RaffleState.CALCULATING;
uint256 requestId = i_vrfCoordinator.requestRandomWords(
i_gasLane,
i_subscriptionId,
REQUEST_CONFIRMATION,
i_callbackGasLimit,
NUM_WORDS
);
emit RequestedRaffleWinner(requestId);
}
// Pick a random winner (verifiably random)
function fulfillRandomWords(
uint256 /*requestId*/,
uint256[] memory randomWords
) internal override {
uint256 indexOfWinner = randomWords[0] % s_players.length;
address payable recentWinner = s_players[indexOfWinner];
s_recentWinner = recentWinner;
s_raffleState = RaffleState.OPEN;
s_players = new address payable[](0);
s_lastTimestamp = block.timestamp;
//open the raffle state and send the money to the random winner
(bool success, ) = recentWinner.call{value: address(this).balance}("");
if (!success) {
revert Raffle__TransferFailed();
}
emit Raffle__WinnerPicked(recentWinner);
}
/*Pure | View Functions */
function getEntranceFee() public view returns (uint256) {
return i_entranceFee;
}
function getPlayers(uint index) public view returns (address) {
return s_players[index];
}
function getRecentWinner() public view returns (address) {
return s_recentWinner;
}
function getRaffleState() public view returns (RaffleState) {
return s_raffleState;
}
function getNumWords() public pure returns (uint256) {
return NUM_WORDS;
}
function getNumOfPlayers() public view returns (uint256) {
return s_players.length;
}
function getLatestTimeStamp() public view returns (uint256) {
return s_lastTimestamp;
}
function getRequestConfirmations() public pure returns (uint256) {
return REQUEST_CONFIRMATION;
}
function getInterval() public view returns(uint256){
return i_interval;
}
}
Thank you in advance for helping me find a solution |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
@AKIN-THOMAS For the staging test issue, only you can help your self because it needs to interact with the vrf dashboard which only the owner can do. But few tips here;
|
Beta Was this translation helpful? Give feedback.
-
I had this error - the cause was the funding on my VRF Subscription. I'd run the test a couple of times with errors in my Raffle.staging.test.js file, and this had been using LINK I'd funded the subscription with. You'll know if it's the same for you if you have a "Pending" section on your VRF Subscription page, between "Consumers" and "History". If this is why you're getting the error, your test script should be timing out on the comment "Entering Raffle..." This is because you're calling .enterRaffle on your contract, checkUpkeep is then returning true, and performUpkeep is calling i_vrfCoordinator.requestRandomWords However, because you don't have LINK, fulfillRandomWords is not being called, and so the event "WinnerPicked" is never being emitted, which means your promise never fulfills. Hope this helped someone! |
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.
@AKIN-THOMAS For the staging test issue, only you can help your self because it needs to interact with the vrf dashboard which only the owner can do.
But few tips here;