Lesson 9: Listener not resolving - TimeOut Error #1088
Unanswered
DorianDaSilva
asked this question in
Q&A
Replies: 2 comments 27 replies
-
@DorianDaSilva Are you funding a subscription in the deploy raffle? |
Beta Was this translation helpful? Give feedback.
22 replies
-
I resolved this problem by adding view while defining the checkUpkeep function. I hope it helps you too. Here's how my checkUpkeep function looks: function checkUpkeep(
bytes memory /* checkData */
)
public
view // <----------- I added this
override
returns (
bool upkeepNeeded,
bytes memory /* performData */
)
{
bool timePassed = ((block.timestamp - s_lastTimeStamp) > i_interval);
bool isOpen = s_raffleState == RaffleState.OPEN;
bool hasPlayers = s_players.length > 0;
bool hasBalance = address(this).balance > 0;
upkeepNeeded = (timePassed && isOpen && hasPlayers && hasBalance);
} my staging test looks like this: const { assert, expect } = require("chai")
const { network, getNamedAccounts, ethers } = require("hardhat")
const { developmentChains } = require("../../helper-hardhat-config")
developmentChains.includes(network.name)
? describe.skip
: describe("Raffle Staging Tests", function () {
let raffle, deployer, raffleEntranceFee
beforeEach(async function () {
deployer = (await getNamedAccounts()).deployer
raffle = await ethers.getContract("Raffle", deployer)
raffleEntranceFee = await raffle.getEntraceFee()
})
describe("fulfillRandomWords", function () {
it("works with live Chainlink Keepers and Chainlink VRF, we get a random winnder", async function () {
// enter raffle/lottery
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) => {
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.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 (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()
})
})
})
}) and helper file like this: const { ethers } = require("hardhat")
const networkConfig = {
// we use helper-hardhat-config for our mocks
4: {
name: "rinkeby",
vrfCoordinatorV2: "0x6168499c0cFfCaCD319c818142124B7A15E857ab",
entranceFee: ethers.utils.parseEther("0.01"),
gasLane: "0xd89b2bf150e3b9e13446986e571fb9cab24b13cea0a43ea20a6049a85cc807cc", // 30 gwei
subscriptionId: "9400", // required!
// required to setup Chainlink Keepers
callbackGasLimit: "500000", // 500k
interval: "30",
},
31337: {
name: "hardhat",
entranceFee: ethers.utils.parseEther("0.01"),
gasLane: "0xd89b2bf150e3b9e13446986e571fb9cab24b13cea0a43ea20a6049a85cc807cc", // we don't need to specify it, our mock will automatically do it for us. We can put any value here
callbackGasLimit: "500000",
interval: "30",
},
}
const developmentChains = ["hardhat", "localhost"]
module.exports = {
networkConfig,
developmentChains,
} |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
==============================================================================
Problem:
Code runs properly until listener tries to listen to
raffle.once("WinnerPicked", async () => { }
Error:
=============================================================================
Code Block:
===========================================================================
Solutions Attempted:
| When removed alters the code and functionality & does not fix the problem in my case
| 5 days spent researching a solution but still no success...
===========================================================================
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!
Beta Was this translation helpful? Give feedback.
All reactions