PatrickAlphaC / hardhat-smartcontract-lottery-fcc

MIT License
117 stars 182 forks source link

{upkeepNeeded} = undefined after preforming checkUpKeep static call #158

Closed Ahmedborwin closed 1 year ago

Ahmedborwin commented 1 year ago

Hope you are well

The const { upkeepNeeded } = await raffleContract.callStatic.checkUpkeep("0x") s resulting in an undefined upkeepNeeded const no matter what I do. 

At this point, I have copy/pasted both the checkUpkeep and the test function but my const returned or upkeepNeeded is still undefined...

Bearing in mind other tests that interact with the contract as working fine, it's only when I try to call the checkupKeep function (for now)

Any suggestions on what I am doing? Thank you in advance

// UpKeep function on my 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 = (timePassed && isOpen && hasBalance && hasPlayers);
        return (upkeepNeeded, "0x0"); // can we comment this out?

// Test for upkeep function
          describe("checkupkeep tests", async () => {
              it("returns false if enough time hasn't passed", async () => {
                  await raffleContract.enterRaffle({ value: raffleEntranceFee })
                  await network.provider.send("evm_increaseTime", [interval.toNumber() - 5]) // use a higher number here if this test fails
                  await network.provider.request({ method: "evm_mine", params: [] })
                  const { upkeepNeeded } = await raffleContract.callStatic.checkUpkeep("0x") // upkeepNeeded = (timePassed && isOpen && hasBalance && hasPlayers)
                  assert.equal(upkeepNeeded == false)
              })
          })
    }
PatrickAlphaC commented 1 year ago

Hmmm perhaps your contract isn't being deployed correctly. Could you clone this repo and see if you're still getting the error?

Ahmedborwin commented 1 year ago

Hi Patrick,

It's strange because the {upkeepNeeded} is set to true when the checkUpkeep tests all pass. If they fail though rather than setting upkeepNeeded = false, it's undefined. When i realised i could pass the tests by using !upkeepNeeded I ended up moving on with the course. Thank you for responding Patrick