ChainLink Solidity课程:Staging测试监听器未解析超时错误
Raffle Staging Tests fulfillRandomWords Setting up test... Setting up Listener... Entering Raffle... Ok, time to wait... All Good here!!! 1) works with live Chainlink Keepers and Chainlink VRF, we get a random winner 0 passing (8m) 1 failing
问题描述
- 代码运行流程正常,但监听器执行
raffle.once("WinnerPicked", async () => { })时出现异常 - try/catch代码块无法被解析
- 已成功调用VRF,但未触发upkeep(已产生0.1 ETH的交易记录)
错误信息
Error: Timeout of 500000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
相关代码块
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("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.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 (error) { console.log(error) reject(e) } }) // 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() console.log("All Good here!!!") // and this code WONT complete until our listener has finished listening! }) }) })
已尝试的解决方案
- 参考相关社区讨论,移除以下代码会改变原有功能,且无法解决问题:
(bool upkeepNeeded, ) = checkUpkeep(""); if (!upkeepNeeded) { revert Raffle__UpkeepNotNeeded( address(this).balance, s_players.length, uint256(s_raffleState) ); }
- 参考其他相关社区讨论
- 谷歌搜索及技术论坛查询
已花费5天时间仍未解决问题...
复现步骤
- 可通过指定GitHub仓库复现该问题
相关代码来源
- 来自Chainlink Solidity课程仓库,对应文件路径:
../test/staging/Raffle.staging.test.js
恳请协助修复该问题代码,使其按预期运行。谢谢!
内容的提问来源于stack exchange,提问作者DorianDaSilva
相关产品推荐
相关产品推荐

