2

i'm getting this error while testing patrick collins smart-contract-lottery project, below is the part where the error coming from.

    describe("checkUpkeep", async function () {
          it("returns false if no one sends ETH", async function () {
              await network.provider.send("evm_increaseTime", [parseInt(interval) + 1]);
              await network.provider.send("evm_mine", []);
              const { upkeepNeeded } = await raffle.callStatic.checkUpkeep("0x");
              assert(!upkeepNeeded);
          });
      });

the relevant code of function from the contract is down below.

    function performUpkeep(bytes calldata /*performData*/) external override {
        (bool upkeepNeeded, ) = checkUpkeep("");
        if (!upkeepNeeded) {
            revert Raffle__upKeepNotNeeded(
                address(this).balance,
                s_players.length,
                uint256(s_raffleState)
            );
        }
        s_raffleState = RaffleState.CALCULATING;
        s_requestId = i_vrfcoordinator.requestRandomWords(
            i_gasLane,
            i_subscriptionId,
            REQUEST_CONFIRMATIONS,
            i_callbackGasLimit,
            NUM_WORDS
        );
        emit RequestedRaffleWinner(s_requestId);
    }

when i remove callStatic it works well, i think the problrm is from callStatic. can anyone help to solve this.

1 Answer 1

0

Ethers v6 comes with some major changes to their syntax, <contract>.staticCall.<function> is the way for v5, but the syntax for v6 looks like this:

enter image description here

For example:

it("Should transfer the funds to the owner", async function () {
        const { lock, unlockTime, lockedAmount, owner } = await loadFixture(
          deployOneYearLockFixture
        );
        await time.increaseTo(unlockTime);
        await lock.staticCall.withdraw();
      });

This test returns this error: TypeError: Cannot read properties of undefined (reading 'withdraw')

it("Should transfer the funds to the owner", async function () {
        const { lock, unlockTime, lockedAmount, owner } = await loadFixture(
          deployOneYearLockFixture
        );
        await time.increaseTo(unlockTime);
        await lock.withdraw.staticCall();
      });

And this test doesn't fail

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.