oracle - Chainlink Fullfill_alarm()在使用mocha测试成功请求发送到oracle后没有回调
问题描述
我正在尝试在 kovan fork 网络上使用安全帽按照文档步骤测试 Chainlink 警报预言机。
https://docs.chain.link/docs/chainlink-alarm-clock/#:~:text=ala
当我用它测试合同时,npx hardhat test
它看起来像向 oracle 发送请求函数,但从未回调过fulfill_alarm()。
我想知道这是否可能是 fork 网络或我的测试代码的问题。
我正在使用 Alchemy api 作为 kovan 上 fork 网络的 url。
另外,我正在使用 mocha 超时,因此它可以等待回调执行,但永远不会命中。
第一个 it 语句正确执行,但是在第二个它应该在彩票完成后增加 lotteryId + 1 (调用 fulfill_alarm() )没有通过。看起来该函数永远不会被chainlink oracle执行。
甲骨文:0xAA1DC356dc4B18f30C347798FD5379F3D77ABC5b
工作编号:'982105d690504c5d9ce374d040c08654'
坚固性代码:
//Starting Oracle Alarm
function start_new_lottery(uint256 duration) public {
require(lottery_state == LOTTERY_STATE.CLOSED, "can't start a n
lottery_state = LOTTERY_STATE.OPEN;
Chainlink.Request memory req = buildChainlinkRequest(jobId, add
req.addUint("until", block.timestamp + duration);
sendChainlinkRequestTo(oracle, req, oraclePayment);
console.log('LINK REQ SEND');
}
//Callback Function after Oracle Alarm is Fulfilled
function fulfill_alarm(bytes32 _requestId) public recordChainlinkFu
require(lottery_state == LOTTERY_STATE.OPEN, "The lottery hasn'
lotteryId = lotteryId + 1;
console.log('ALARM_FULFILLED');
pickWinner();
}
测试代码:
const {expect} = require("chai");
const { time } = require("@openzeppelin/test-helpers");
describe("彩票合约", function() {
//Defining global variables for testing.
const price_lottery = ethers.BigNumber.from(1);
let owner;
let Lottery;
let lottery;
before(async function () {
Lottery = await ethers.getContractFactory("Lottery");
[owner] = await ethers.getSigners();
lottery = await Lottery.deploy(
price_lottery,
);
//Starting new Lottery
await lottery.start_new_lottery(60);
});
it("should start a chainlink alarm to init new lottery", async func
let lottery_state = await lottery.lottery_state();
expect(lottery_state).to.equal(0);
//Initial value
let lotteryId = await lottery.lotteryId();
expect(lotteryId).to.equal(1);
})
it("increments lotteryID + 1, when chainlink alarm is fulfilled aft
//Wait until alarm is fulfilled
function timeout(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
await timeout(120000);
//Expected value
let lotteryId = await lottery.lotteryId();
expect(lotteryId).to.equal(2);
})
})
解决方案
推荐阅读
- jquery - 为什么 jQuery 不能在 WordPress 页面上运行?
- google-sheets - SUMPRODUCT 与 Google 表格上的 AND 标准
- python - pyautogui 故障保护的目的是什么?
- android - 未能为 AOSIP 构建一些目标
- expo - 在一个 gnu-screen 终端中所做的更改是否会以正在进行的过程填充到另一个终端中
- javascript - 输入 Object.prototype.function() 的原型,其中所有的 EventListener 都是安全的(Javascript)
- java - Selenium/Java - 是否可以验证 driver.switchTo().frame(element) 是否成功?
- python - \models\official\vision\image_classification\efficientnet\efficientnet_model.py 语法无效
- architecture - 微服务:没有计数器的并行计算
- javascript - 在 textarea 中添加新行在我的 CI 项目中不起作用