ameymeow
ameymeow

Reputation: 11

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

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");
    }

Upvotes: 1

Views: 538

Answers (4)

jackyW
jackyW

Reputation: 1

proved answer, that works for the ethers v6.

Upvotes: 0

Raffaele Spinoni
Raffaele Spinoni

Reputation: 127

If anyone has this problem and is using ethers v6, this is the way to achieve the same in the version 6:

const { upkeepNeeded } = await raffle.checkUpkeep.staticCall("0x");

Upvotes: 2

Diyaa Daoud
Diyaa Daoud

Reputation: 86

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

Upvotes: 2

ZeusLawyer
ZeusLawyer

Reputation: 294

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.

Upvotes: 2

Related Questions