Testing
How to test, if my oracle can communicate with plugin and start sharing the data
// SPDX-License-Identifier: MIT
pragma solidity ^0.4.24;
import "https://github.com/GoPlugin/contracts/blob/main/src/v0.4/PluginClient.sol";
import "https://github.com/GoPlugin/contracts/blob/main/src/v0.4/vendor/Ownable.sol";
contract AlarmClockSample is PluginClient, Ownable {
using Plugin for Plugin.Request;
bool public alarmDone;
address private oracle;
bytes32 private jobId;
uint256 private fee;
/**
* Network: Mainnet
* Oracle: Plugin - 0xf180e56bb575806aefaf2a7616622a9fc180b51c
* Job ID: Plugin - bcbac9232272445294102fdd1ee97c98
* Fee: 0.1 PLI
*/
constructor(address _pli) public Ownable() {
setPluginToken(_pli);
oracle = 0xf180e56bb575806aefaf2a7616622a9fc180b51c;
jobId = "982105d690504c5e9ce374d040c08654";
fee = 0.1 * 10 ** 18; // 0.1 PLI
alarmDone = false;
}
/* Create a Plugin request to start an alarm and after the time in seconds is up, return throught the fulfillAlarm function */
function requestAlarmClock(uint256 durationInSeconds) public returns (bytes32 requestId)
{
Plugin.Request memory request = buildPluginRequest(jobId, address(this), this.fulfillAlarm.selector);
// This will return in 90 seconds
request.addUint("until", block.timestamp + durationInSeconds);
return sendPluginRequestTo(oracle, request, fee);
}
/**
* Receive the response in the form of uint256
*/
function fulfillAlarm(bytes32 _requestId, uint256 _volume) public recordPluginFulfillment(_requestId)
{
alarmDone = true;
}
function withdrawPli() public onlyOwner() {
PliTokenInterface pliToken = PliTokenInterface(pluginTokenAddress());
require(pliToken.transfer(msg.sender, pliToken.balanceOf(address(this))), "Unable to transfer");
}
}



Last updated