-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement a realitio mock controlled by a trusted user group
- Loading branch information
Showing
5 changed files
with
102 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
pragma solidity ^0.8.0; | ||
|
||
interface IRealitio { | ||
function getContentHash(bytes32 questionId) external view returns (bytes32); | ||
function getOpeningTS(bytes32 questionId) external view returns (uint32); | ||
function resultFor(bytes32 questionId) external view returns (bytes32); | ||
} | ||
|
||
contract MockRealitio is IRealitio { | ||
mapping(address => bool) public owners; | ||
mapping(bytes32 => bytes32) private contentHashes; | ||
mapping(bytes32 => uint32) private openingTimestamps; | ||
mapping(bytes32 => bytes32) private results; | ||
|
||
constructor() { | ||
owners[msg.sender] = true; | ||
} | ||
|
||
modifier onlyOwners() { | ||
require(owners[msg.sender], "Only owner can call this function"); | ||
_; | ||
} | ||
|
||
function addOwner(address newOwner) external onlyOwners { | ||
owners[newOwner] = true; | ||
} | ||
|
||
function removeOwner(address ownerToRemove) external onlyOwners { | ||
require(msg.sender != ownerToRemove, "Owner cannot remove themselves"); | ||
owners[ownerToRemove] = false; | ||
} | ||
|
||
function getContentHash(bytes32 questionId) external view returns (bytes32) { | ||
return contentHashes[questionId]; | ||
} | ||
|
||
function getOpeningTS(bytes32 questionId) external view returns (uint32) { | ||
return openingTimestamps[questionId]; | ||
} | ||
|
||
function resultFor(bytes32 questionId) external view returns (bytes32) { | ||
return results[questionId]; | ||
} | ||
|
||
function setContentHash(bytes32 questionId, bytes32 contentHash) external onlyOwners { | ||
contentHashes[questionId] = contentHash; | ||
} | ||
|
||
function setOpeningTS(bytes32 questionId, uint32 openingTS) external onlyOwners { | ||
openingTimestamps[questionId] = openingTS; | ||
} | ||
|
||
function setResult(bytes32 questionId, bytes32 result) external onlyOwners { | ||
results[questionId] = result; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
import "forge-std/console2.sol"; | ||
import {MockRealitio} from "../src/MockRealitio.sol"; | ||
|
||
contract MockRealitioTest is Test { | ||
MockRealitio public mockRealitio; | ||
|
||
function setUp() public { | ||
mockRealitio = new MockRealitio(); | ||
} | ||
|
||
function test_AddOwner() public { | ||
address newOwner = address(0x123); | ||
mockRealitio.addOwner(newOwner); | ||
assertTrue(mockRealitio.owners(newOwner)); | ||
} | ||
|
||
function test_RemoveOwner() public { | ||
address ownerToRemove = address(0x456); | ||
mockRealitio.addOwner(ownerToRemove); | ||
mockRealitio.removeOwner(ownerToRemove); | ||
assertFalse(mockRealitio.owners(ownerToRemove)); | ||
} | ||
|
||
function testFuzz_SetContentHash(bytes32 questionId, bytes32 contentHash) public { | ||
mockRealitio.setContentHash(questionId, contentHash); | ||
assertEq(mockRealitio.getContentHash(questionId), contentHash); | ||
} | ||
|
||
function testFuzz_SetOpeningTS(bytes32 questionId, uint32 openingTS) public { | ||
mockRealitio.setOpeningTS(questionId, openingTS); | ||
assertEq(mockRealitio.getOpeningTS(questionId), openingTS); | ||
} | ||
|
||
function testFuzz_SetResult(bytes32 questionId, bytes32 result) public { | ||
mockRealitio.setResult(questionId, result); | ||
assertEq(mockRealitio.resultFor(questionId), result); | ||
} | ||
} |