TypeError:无法读取未定义的属性(checkUpkeep、chainlink keeper)

问题描述 投票:0回答:3

我在使用安全帽测试我的智能合约时遇到此错误

类型错误:无法读取未定义的属性(读取“checkUpkeep”)

测试代码

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

智能合约相关代码

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");
    }
javascript ethereum solidity chainlink chainlink-keepers
3个回答
2
投票

我知道已经太晚了,但是当你尝试调用 checkUpkeep 函数时,它应该是“callStatic”而不是“callstatic”


2
投票

由于它的 JS 很难知道哪个函数调用正在尝试访问具有未定义值的变量。根据您提供的代码,甚至可能对

raffle
的引用未定义。

但我假设这段代码与这里的代码相同。

您的安全帽配置或测试导入中可能缺少导入。仔细检查那些。看起来您的执行上下文需要一些东西,但在测试运行时没有注入。


0
投票
如果有人遇到这个问题并且正在使用 ethers v6,这是在版本 6 中实现相同问题的方法:

const { upkeepNeeded } = await raffle.checkUpkeep.staticCall("0x");
    
© www.soinside.com 2019 - 2024. All rights reserved.