Skip to content

Commit

Permalink
feat: make finalized response ids public
Browse files Browse the repository at this point in the history
  • Loading branch information
gas1cent committed Dec 12, 2023
1 parent 75af5a4 commit d747ca7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 33 deletions.
15 changes: 4 additions & 11 deletions solidity/contracts/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ contract Oracle is IOracle {
/// @inheritdoc IOracle
mapping(uint256 _requestNumber => bytes32 _id) public nonceToRequestId;

/// @inheritdoc IOracle
mapping(bytes32 _requestId => bytes32 _finalizedResponseId) public finalizedResponseId;

/**
* @notice The list of the response ids for each request
*/
Expand All @@ -40,11 +43,6 @@ contract Oracle is IOracle {
*/
mapping(bytes32 _requestId => bytes _allowedModules) internal _allowedModules;

/**
* @notice The finalized response for each request
*/
mapping(bytes32 _requestId => bytes32 _finalizedResponseId) internal _finalizedResponses;

/// @inheritdoc IOracle
uint256 public totalRequestCount;

Expand Down Expand Up @@ -260,11 +258,6 @@ contract Oracle is IOracle {
_isParticipant = _matchBytes(bytes32(uint256(uint160(_user))), _participants[_requestId], 20);
}

/// @inheritdoc IOracle
function getFinalizedResponseId(bytes32 _requestId) external view returns (bytes32 _finalizedResponseId) {
_finalizedResponseId = _finalizedResponses[_requestId];
}

/// @inheritdoc IOracle
function getResponseIds(bytes32 _requestId) public view returns (bytes32[] memory _ids) {
bytes memory _responses = _responseIds[_requestId];
Expand Down Expand Up @@ -367,7 +360,7 @@ contract Oracle is IOracle {
revert Oracle_InvalidFinalizedResponse();
}

_finalizedResponses[_requestId] = _responseId;
finalizedResponseId[_requestId] = _responseId;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion solidity/interfaces/IModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interface IModule {

/*///////////////////////////////////////////////////////////////
VARIABLES
//////////////////////////////////////////////////////////////*/
//////////////////////////////////////////////////////////////*/

/**
* @notice Returns the address of the oracle
Expand Down
16 changes: 8 additions & 8 deletions solidity/interfaces/IOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ interface IOracle {
*/
function nonceToRequestId(uint256 _nonce) external view returns (bytes32 _requestId);

/**
* @notice Returns the finalized response ID for a given request
*
* @param _requestId The id of the request
* @return _finalizedResponseId The id of the finalized response
*/
function finalizedResponseId(bytes32 _requestId) external view returns (bytes32 _finalizedResponseId);

/**
* @notice The number of the block at which a request, response, or a dispute was created
*
Expand Down Expand Up @@ -384,14 +392,6 @@ interface IOracle {
*/
function isParticipant(bytes32 _requestId, address _user) external view returns (bool _isParticipant);

/**
* @notice Returns the finalized response ID for a given request
*
* @param _requestId The id of the request
* @return _finalizedResponseId The id of the finalized response
*/
function getFinalizedResponseId(bytes32 _requestId) external view returns (bytes32 _finalizedResponseId);

/**
* @notice Returns the ids of the responses for a given request
*
Expand Down
2 changes: 1 addition & 1 deletion solidity/test/integration/Finalization.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ contract Integration_Finalization is IntegrationBase {
vm.prank(_finalizer);
oracle.finalize(mockRequest, mockResponse);

bytes32 _responseId = oracle.getFinalizedResponseId(_requestId);
bytes32 _responseId = oracle.finalizedResponseId(_requestId);
// Check: is request finalized?
assertEq(_responseId, _getId(mockResponse));
}
Expand Down
13 changes: 1 addition & 12 deletions solidity/test/unit/Oracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract MockOracle is Oracle {
}

function mock_setFinalizedResponseId(bytes32 _requestId, bytes32 _finalizedResponseId) external {
_finalizedResponses[_requestId] = _finalizedResponseId;
finalizedResponseId[_requestId] = _finalizedResponseId;
}

function mock_setFinalizedAt(bytes32 _requestId, uint128 _finalizedAt) external {
Expand Down Expand Up @@ -730,17 +730,6 @@ contract Oracle_Unit_IsParticipant is BaseTest {
}
}

contract Oracle_Unit_GetFinalizedResponseId is BaseTest {
/**
* @notice Test if the finalized response id is returned correctly
*/
function test_getFinalizedResponseId(bytes32 _requestId, bytes32 _finalizedResponseId) public {
assertEq(oracle.getFinalizedResponseId(_requestId), bytes32(0));
oracle.mock_setFinalizedResponseId(_requestId, _finalizedResponseId);
assertEq(oracle.getFinalizedResponseId(_requestId), _finalizedResponseId);
}
}

contract Oracle_Unit_Finalize is BaseTest {
modifier withoutResponse() {
mockResponse.requestId = bytes32(0);
Expand Down

0 comments on commit d747ca7

Please sign in to comment.