PatrickAlphaC / hardhat-smartcontract-lottery-fcc

MIT License
117 stars 183 forks source link

Staging test issue #163

Closed GIRISHNP closed 1 year ago

GIRISHNP commented 1 year ago

When I run staging test , I got this issue '1) Raffle Unit Tests "before each" hook for "works with live Chainlink Keepers and Chainlink VRF, we get a random winner": ProviderError: Unsupported method: evm_snapshot. See available methods at https://docs.alchemy.com/alchemy/documentation/apis'

Here is my code // Inorder to test this in test network we need this things //1. Get our SubId for Chainlink VRF //2. Deploy our contract using the SubId //3.Register the contract with chainlink VRF and its subId //4. Register the contract with chainlink keepers //5. Run staging tests

const { assert, expect } = require("chai") const { network, deployments, ethers, getNamedAccounts } = require("hardhat") const { developmentChains, networkConfig } = require("../../helper-hardhat-config")

developmentChains.includes(network.name) ? describe.skip : describe("Raffle Unit Tests", function () { let raffle, raffleEntranceFee, deployer // , deployer const chainId = network.config.chainId

    beforeEach(async () => {
        deployer = (await getNamedAccounts()).deployer
        await deployments.fixture(["all"])
        raffle = await ethers.getContract("Raffle", deployer)
        vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock", deployer)
        interval = await raffle.getInterval()
        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.getLastTimeStamp()
            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.getLastTimeStamp()

                        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(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!
            })
        })
    })
})
PatrickAlphaC commented 1 year ago

Can you:

  1. Make this a discusson on the full repo? https://github.com/smartcontractkit/full-blockchain-solidity-course-js/
  2. Follow this section for formatting questions? https://www.youtube.com/watch?t=19846&v=gyMwXuJrbJQ&feature=youtu.be