TypeError: Cannot read properties of undefined (checkUpkeep, chainlink keepers)

391 Views Asked by At

I'm getting this error while testing my smart contract using hardhat

TypeError: Cannot read properties of undefined (reading 'checkUpkeep')

code for the test

 describe("checkUpkeep", () => {
              it("returns false if people haven't sent any eth", async () => {
                  await network.provider.send("evm_increaseTime", [interval.toNumber() + 1])
                  await network.provider.send("evm_mine", [])
                  const { upkeepNeeded } = await raffle.callstatic.checkUpkeep("0x")
                  assert(!upkeepNeeded)
              })
          })

relevant code of the smart contract

function checkUpkeep(
        bytes memory /* checkData*/
    )
        public
        view
        override
        returns (
            bool upkeepNeeded,
            bytes memory /* performData */
        )
    {
        bool isOpen = RaffleState.OPEN == s_raffleState;
        bool timePassed = (((block.timestamp) - s_lastTimeStamp) > i_interval);
        bool hasPlayers = s_players.length > 0;
        bool hasBalance = address(this).balance > 0;
        upkeepNeeded = (isOpen && timePassed && hasPlayers && hasBalance);
        return (upkeepNeeded, "0x0");
    }
2

There are 2 best solutions below

0
On BEST ANSWER

I know it's too late, but when you try to call the checkUpkeep function, it should be "callStatic" not "callstatic"

0
On

Since its JS its hard to know which of the function calls is trying to access a variable with an undefined value. Based on the code you supplied it could even be that the reference to raffle is undefined.

But I'm assuming this code is the same as what's here.

There may be a missing import in your hardhat config or in your test imports. Double check those. It looks like there is something that your execution context requires that is not injected when your tests are running.