smartcontractkit / full-blockchain-solidity-course-js

Learn Blockchain, Solidity, and Full Stack Web3 Development with Javascript
12.01k stars 2.91k forks source link

LESSON 9: error while passing empty bytes array to performUpkeep method in #5879

Closed J-dev740 closed 1 year ago

J-dev740 commented 1 year ago

error while passing empty bytes array to performUpkeep method ErrorCode:

TypeError: invalid BytesLike value (argument="value", value="[]", code=INVALID_ARGUMENT, version=6.6.4)

bugged part of code:

            try {
                await raffle.performUpkeep([])
            } catch (error) {
                console.log(error)
                process.exit(1)
            }

complete Raffle.test.js code:

const {assert,expect}=require("chai")
const {getNamedAccounts,deployments,ethers,network}=require("hardhat")
const {networkConfig,developmentChains}=require("../../helper-hardhat-config")
const {time,helpers}=require("@nomicfoundation/hardhat-network-helpers")
!developmentChains.includes(network.name)
?describe.skip
:
describe("Raffle",()=>{
    //contract var def should be given here else scope error is most likely going to occur such as
    //ReferenceError: raffle is not defined etcc....
    let raffle,vrfCoordinatorV2,ethEntranceFee,deployer,interval
    let interval1=31

    const chainId=network.config.chainId;
    beforeEach(async ()=>{
        // const {deployer}= await getNamedAccounts()
        const accounts = await ethers.getSigners();
        deployer=accounts[0];

        await deployments.fixture("all");
        const raffle_address= (await deployments.get("Raffle")).address;
        raffle=await ethers.getContractAt("Raffle",raffle_address);
        raffle=raffle.connect(deployer);
        const vrfCoordinatorV2_address= (await deployments.get("VRFCoordinatorV2Mock")).address;
        vrfCoordinatorV2= await ethers.getContractAt("VRFCoordinatorV2Mock",vrfCoordinatorV2_address);
        vrfCoordinatorV2=vrfCoordinatorV2.connect(deployer);
        ethEntranceFee=await raffle.getEntranceFee();
        interval= await raffle.getInterval();
        // interval=interval.toNumber()
        interval=ethers.toNumber(interval)
        console.log(interval)

    });
    describe("constructor",()=>{
        it("should set initial raffle state to open",async ()=>{
            const raffle_state=  await  raffle.getRaffleState()
            console.log(raffle_state)
            assert(raffle_state.toString(),"0")
        });

        it("should set the min interval to 30 seconds ",async () =>{

            // const interval=  await raffle.getInterval()
            console.log(interval)
            assert(interval.toString(),networkConfig[chainId]["interval"])

        });

    });
    describe("enterRaffle",()=>{
        it("should revert if no min eth is provided to enter raffle",async ()=>{
           await expect (raffle.enterRaffle()).to.be.revertedWithCustomError(raffle,"Raffle_sendMoreToEnterRaffle")

        })
        it("should add players to array entering raffle",async()=>{
            await raffle.enterRaffle({value:ethEntranceFee})
            const player= raffle.getPlayer(0)
            assert(player.toString(),deployer.toString())
        })
        it("should not allow to enter if state is calculating",async()=>{
            //increase interval just enough to make raffle state calculating
            console.log("hello")
            console.log(`${typeof(interval)}`)
            await raffle.enterRaffle({value:ethEntranceFee})
            console.log("breaking here")
            // await network.provider.request({ method: "evm_increaseTime", params: [300] })
            // await network.provider.send(`evm_increaseTime`,[40])
            // await helpers.time.increase(interval+1)
            await time.increase(interval+1)

            // await network.provider.send()
            //mines a single block to simulate next state of blockchain
            // await network.provider.send("evm_mine",[])
            //now we are acting as the chainlink keepers and calling performKeep to 
            //simulate the raffle state to be CALCULATING
            try {
                await raffle.performUpkeep([])
            } catch (error) {
                console.log(error)
                process.exit(1)
            }

            console.log("End")
            await expect(raffle.enterRaffle({value:ethEntranceFee})).to.be.revertedWithCustomError(raffle,"Raffle_RaffleNotOpen")
        })
      })
});

Originally posted by @J-dev740 in https://github.com/smartcontractkit/full-blockchain-solidity-course-js/discussions/5878

J-dev740 commented 1 year ago

resolved by :

performUpkeep([])->performUpkeep("0x")
WeDev00 commented 5 months ago

I had the same problem and worked with me too, but why?