Add one more test case for DioneOracle
This commit is contained in:
parent
e0051ce982
commit
b11eef4df1
@ -58,7 +58,6 @@ contract DioneOracle {
|
||||
|
||||
function requestOracles(uint8 _originChain, string memory _requestType, string memory _requestParams, address _callbackAddress, bytes4 _callbackMethodID) public returns (uint256) {
|
||||
requestCounter += 1;
|
||||
require(pendingRequests[requestCounter].reqID == 0, "This counter is not unique");
|
||||
uint256 requestDeadline = block.timestamp.add(MAXIMUM_DELAY);
|
||||
pendingRequests[requestCounter] = OracleRequest({
|
||||
requestSender: msg.sender,
|
||||
@ -87,8 +86,7 @@ contract DioneOracle {
|
||||
require(pendingRequests[_reqID].deadline - int256(block.timestamp) >= 0, "submission has exceeded the deadline");
|
||||
delete pendingRequests[_reqID];
|
||||
dioneStaking.mine(msg.sender);
|
||||
(bool success, ) = pendingRequests[_reqID].callbackAddress.call(abi.encodeWithSelector(pendingRequests[_reqID].callbackMethodID, _reqID, _data));
|
||||
require(success == true, "cannot call callback method");
|
||||
pendingRequests[_reqID].callbackAddress.call(abi.encodeWithSelector(pendingRequests[_reqID].callbackMethodID, _reqID, _data));
|
||||
emit SubmittedOracleRequest(_reqID, _data);
|
||||
return true;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ describe("DioneOracle", function () {
|
||||
const timestamp = 1625097600;
|
||||
await ethers.provider.send("evm_setNextBlockTimestamp", [timestamp]);
|
||||
const requestDeadline = timestamp + 300;
|
||||
await expect(dioneOracle.requestOracles(1, "getTransaction", "bafy2bzaceaaab3kkoaocal2dzh3okzy4gscqpdt42hzrov3df6vjumalngc3g", dioneOracle.address, BigNumber.from(0x8da5cb5b)))
|
||||
await expect(dioneOracle.requestOracles(1, "getTransaction", "bafy2bzaceaaab3kkoaocal2dzh3okzy4gscqpdt42hzrov3df6vjumalngc3g", "0x0000000000000000000000000000000000000000", "0x00000000"))
|
||||
.to.emit(dioneOracle, 'NewOracleRequest')
|
||||
.withArgs(1, "getTransaction", "bafy2bzaceaaab3kkoaocal2dzh3okzy4gscqpdt42hzrov3df6vjumalngc3g", 1, requestDeadline);
|
||||
|
||||
@ -43,7 +43,7 @@ describe("DioneOracle", function () {
|
||||
it("should create request and submit it", async function() {
|
||||
const [addr0] = await ethers.getSigners();
|
||||
|
||||
await dioneOracle.requestOracles(1, "getTransaction", "bafy2bzaceaaab3kkoaocal2dzh3okzy4gscqpdt42hzrov3df6vjumalngc3g", dioneOracle.address, BigNumber.from(0x8da5cb5b));
|
||||
await dioneOracle.requestOracles(1, "getTransaction", "bafy2bzaceaaab3kkoaocal2dzh3okzy4gscqpdt42hzrov3df6vjumalngc3g", "0x0000000000000000000000000000000000000000", "0x00000000");
|
||||
const res = dioneOracle.submitOracleRequest(1, BigNumber.from(0x8da5cb5b));
|
||||
await expect(res)
|
||||
.to.emit(dioneOracle, "SubmittedOracleRequest")
|
||||
@ -55,7 +55,7 @@ describe("DioneOracle", function () {
|
||||
});
|
||||
|
||||
it("should fail submission after request deadline", async function () {
|
||||
await dioneOracle.requestOracles(1, "getTransaction", "bafy2bzaceaaab3kkoaocal2dzh3okzy4gscqpdt42hzrov3df6vjumalngc3g", dioneOracle.address, BigNumber.from(0x8da5cb5b));
|
||||
await dioneOracle.requestOracles(1, "getTransaction", "bafy2bzaceaaab3kkoaocal2dzh3okzy4gscqpdt42hzrov3df6vjumalngc3g", "0x0000000000000000000000000000000000000000", "0x00000000");
|
||||
|
||||
await ethers.provider.send("evm_increaseTime", [301]);
|
||||
await expect(dioneOracle.submitOracleRequest(1, BigNumber.from(0x8da5cb5b)))
|
||||
@ -71,4 +71,12 @@ describe("DioneOracle", function () {
|
||||
await expect(dioneOracle.cancelOracleRequest(333))
|
||||
.to.be.revertedWith("this request is not pending");
|
||||
});
|
||||
|
||||
it("should fail when canceling request as not request sender", async () => {
|
||||
const [,addr1] = await ethers.getSigners();
|
||||
|
||||
await dioneOracle.requestOracles(1, "getTransaction", "bafy2bzaceaaab3kkoaocal2dzh3okzy4gscqpdt42hzrov3df6vjumalngc3g", "0x0000000000000000000000000000000000000000", "0x00000000");
|
||||
await expect(dioneOracle.connect(addr1).cancelOracleRequest(1))
|
||||
.to.be.revertedWith("you aren't request sender");
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user