Closed uditrajawat closed 1 year ago
const { inputToConfig } = require("@ethereum-waffle/compiler"); const { assert, expect } = require("chai"); const { network, getNamedAccounts, deployments, ethers } = require("hardhat"); const { resolveConfigFile } = require("prettier"); const { developmentChains, networkConfig, } = require("../../helper-hardhat-config"); developmentChains.includes(network.name) ? describe.skip : describe("Raffle Unit Tests", function () { let raffle, raffleEntranceFee, deployer; beforeEach(async function () { deployer = (await getNamedAccounts()).deployer; raffle = await ethers.getContract("Raffle", deployer); raffleEntranceFee = await raffle.getentraceFee(); }); describe("fulfillRandomWords", function () { it("works only with live chainLink Keepers and chinlink vrf,we get a random winner", async function () { const startingTimeStamp = await raffle.getLatestTimeStamp(); const accounts = await ethers.getSigners(); await new Promise(async (resolve, reject) => { raffle.once("Winner Picked", async function () { console.log("winner picked,event fired"); try { const recentWinner = await raffle.getRecentWinner(); const raffleState = await raffle.getgetRaffleState(); 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 await raffle.raffleEntranceFee({ value: raffleEntranceFee, }); const winnerStartingBalance = await accounts[0].getBalance(); }); }); }); });
Can you: