Add one more test case for DioneOracle

This commit is contained in:
ChronosX88 2021-04-27 22:52:37 +03:00
parent e0051ce982
commit b11eef4df1
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A
2 changed files with 12 additions and 6 deletions

View File

@ -58,7 +58,6 @@ contract DioneOracle {
function requestOracles(uint8 _originChain, string memory _requestType, string memory _requestParams, address _callbackAddress, bytes4 _callbackMethodID) public returns (uint256) { function requestOracles(uint8 _originChain, string memory _requestType, string memory _requestParams, address _callbackAddress, bytes4 _callbackMethodID) public returns (uint256) {
requestCounter += 1; requestCounter += 1;
require(pendingRequests[requestCounter].reqID == 0, "This counter is not unique");
uint256 requestDeadline = block.timestamp.add(MAXIMUM_DELAY); uint256 requestDeadline = block.timestamp.add(MAXIMUM_DELAY);
pendingRequests[requestCounter] = OracleRequest({ pendingRequests[requestCounter] = OracleRequest({
requestSender: msg.sender, requestSender: msg.sender,
@ -87,8 +86,7 @@ contract DioneOracle {
require(pendingRequests[_reqID].deadline - int256(block.timestamp) >= 0, "submission has exceeded the deadline"); require(pendingRequests[_reqID].deadline - int256(block.timestamp) >= 0, "submission has exceeded the deadline");
delete pendingRequests[_reqID]; delete pendingRequests[_reqID];
dioneStaking.mine(msg.sender); dioneStaking.mine(msg.sender);
(bool success, ) = pendingRequests[_reqID].callbackAddress.call(abi.encodeWithSelector(pendingRequests[_reqID].callbackMethodID, _reqID, _data)); pendingRequests[_reqID].callbackAddress.call(abi.encodeWithSelector(pendingRequests[_reqID].callbackMethodID, _reqID, _data));
require(success == true, "cannot call callback method");
emit SubmittedOracleRequest(_reqID, _data); emit SubmittedOracleRequest(_reqID, _data);
return true; return true;
} }

View File

@ -27,7 +27,7 @@ describe("DioneOracle", function () {
const timestamp = 1625097600; const timestamp = 1625097600;
await ethers.provider.send("evm_setNextBlockTimestamp", [timestamp]); await ethers.provider.send("evm_setNextBlockTimestamp", [timestamp]);
const requestDeadline = timestamp + 300; 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') .to.emit(dioneOracle, 'NewOracleRequest')
.withArgs(1, "getTransaction", "bafy2bzaceaaab3kkoaocal2dzh3okzy4gscqpdt42hzrov3df6vjumalngc3g", 1, requestDeadline); .withArgs(1, "getTransaction", "bafy2bzaceaaab3kkoaocal2dzh3okzy4gscqpdt42hzrov3df6vjumalngc3g", 1, requestDeadline);
@ -43,7 +43,7 @@ describe("DioneOracle", function () {
it("should create request and submit it", async function() { it("should create request and submit it", async function() {
const [addr0] = await ethers.getSigners(); 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)); const res = dioneOracle.submitOracleRequest(1, BigNumber.from(0x8da5cb5b));
await expect(res) await expect(res)
.to.emit(dioneOracle, "SubmittedOracleRequest") .to.emit(dioneOracle, "SubmittedOracleRequest")
@ -55,7 +55,7 @@ describe("DioneOracle", function () {
}); });
it("should fail submission after request deadline", async 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 ethers.provider.send("evm_increaseTime", [301]);
await expect(dioneOracle.submitOracleRequest(1, BigNumber.from(0x8da5cb5b))) await expect(dioneOracle.submitOracleRequest(1, BigNumber.from(0x8da5cb5b)))
@ -71,4 +71,12 @@ describe("DioneOracle", function () {
await expect(dioneOracle.cancelOracleRequest(333)) await expect(dioneOracle.cancelOracleRequest(333))
.to.be.revertedWith("this request is not pending"); .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");
});
}); });