Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: additional validations #18

Merged
merged 10 commits into from
Dec 12, 2023
9 changes: 9 additions & 0 deletions solidity/contracts/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ contract Oracle is IOracle {
revert Oracle_InvalidResponseBody();
}

// Can't propose the same response twice
if (createdAt[_responseId] != 0) {
revert Oracle_InvalidResponseBody();
}

if (finalizedAt[_response.requestId] != 0) {
revert Oracle_AlreadyFinalized(_response.requestId);
}
Expand All @@ -124,6 +129,10 @@ contract Oracle is IOracle {
) external returns (bytes32 _disputeId) {
_disputeId = _validateDispute(_request, _response, _dispute);

if (_dispute.disputer != msg.sender) {
revert Oracle_InvalidDisputeBody();
}

if (createdAt[_dispute.requestId] == 0) {
revert Oracle_InvalidDisputeBody();
}
Expand Down
1 change: 0 additions & 1 deletion solidity/test/integration/Finalization.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ contract Integration_Finalization is IntegrationBase {

function setUp() public override {
super.setUp();
_expectedDeadline = block.timestamp + BLOCK_TIME * 600;
vm.etch(_callbackTarget, hex'069420');
}

Expand Down
2 changes: 2 additions & 0 deletions solidity/test/integration/IntegrationBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ contract IntegrationBase is TestConstants, Helpers {

vm.stopPrank();

_expectedDeadline = block.timestamp + BLOCK_TIME * 600;

// Configure the mock request
mockRequest.requestModuleData = abi.encode(
IMockRequestModule.RequestParameters({
Expand Down
10 changes: 4 additions & 6 deletions solidity/test/integration/ResponseDispute.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ contract Integration_ResponseDispute is IntegrationBase {
bytes internal _responseData;
bytes32 internal _requestId;
bytes32 internal _responseId;
bytes internal _requestModuleData;
bytes internal _responseModuleData;
bytes internal _disputeModuleData;
bytes internal _resolutionModuleData;
bytes internal _finalityModuleData;

function setUp() public override {
super.setUp();
Expand Down Expand Up @@ -43,7 +38,10 @@ contract Integration_ResponseDispute is IntegrationBase {
vm.prank(disputer);
oracle.disputeResponse(mockRequest, mockResponse, mockDispute);

vm.prank(disputer);
address _anotherDisputer = makeAddr('anotherDisputer');
mockDispute.disputer = _anotherDisputer;

vm.prank(_anotherDisputer);
vm.expectRevert(abi.encodeWithSelector(IOracle.Oracle_ResponseAlreadyDisputed.selector, _responseId));
oracle.disputeResponse(mockRequest, mockResponse, mockDispute);
}
Expand Down
46 changes: 1 addition & 45 deletions solidity/test/integration/ResponseProposal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,7 @@ contract Integration_ResponseProposal is IntegrationBase {
function setUp() public override {
super.setUp();

_expectedDeadline = block.timestamp + BLOCK_TIME * 600;

mockRequest.requestModuleData = abi.encode(
IMockRequestModule.RequestParameters({
url: _expectedUrl,
body: _expectedBody,
accountingExtension: _accountingExtension,
paymentToken: usdc,
paymentAmount: _expectedReward
})
);

mockRequest.responseModuleData = abi.encode(
IMockResponseModule.RequestParameters({
accountingExtension: _accountingExtension,
bondToken: usdc,
bondAmount: _expectedBondAmount,
deadline: _expectedDeadline,
disputeWindow: _baseDisputeWindow
})
);

mockRequest.disputeModuleData = abi.encode(
IMockDisputeModule.RequestParameters({
accountingExtension: _accountingExtension,
bondToken: usdc,
bondAmount: _expectedBondAmount
})
);

mockRequest.resolutionModuleData = abi.encode();

mockRequest.finalityModuleData = abi.encode(
IMockFinalityModule.RequestParameters({target: address(_mockCallback), data: abi.encode(_expectedCallbackValue)})
);

mockRequest.requestModule = address(_requestModule);
mockRequest.responseModule = address(_responseModule);
mockRequest.disputeModule = address(_disputeModule);
mockRequest.resolutionModule = address(_resolutionModule);
mockRequest.finalityModule = address(_finalityModule);

mockRequest.nonce = uint96(oracle.totalRequestCount());
mockRequest.requester = requester;

mockResponse.requestId = _getId(mockRequest);

vm.prank(requester);
_requestId = oracle.createRequest(mockRequest, _ipfsHash);
Expand Down Expand Up @@ -82,6 +37,7 @@ contract Integration_ResponseProposal is IntegrationBase {
vm.warp(_timestamp);
oracle.finalize(mockRequest, mockResponse);

mockResponse.response = abi.encode(_timestamp);
vm.expectRevert(abi.encodeWithSelector(IOracle.Oracle_AlreadyFinalized.selector, _requestId));
vm.prank(proposer);
oracle.proposeResponse(mockRequest, mockResponse);
Expand Down
34 changes: 32 additions & 2 deletions solidity/test/unit/Oracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,22 @@ contract Oracle_Unit_ProposeResponse is BaseTest {
oracle.proposeResponse(mockRequest, mockResponse);
}

/**
* @notice Revert if the response has been already proposed
*/
function test_proposeResponse_revertsIfDuplicateResponse() public {
// Test: propose a response
vm.prank(proposer);
oracle.proposeResponse(mockRequest, mockResponse);

// Check: revert?
vm.expectRevert(IOracle.Oracle_InvalidResponseBody.selector);

// Test: try to propose the same response again
vm.prank(proposer);
oracle.proposeResponse(mockRequest, mockResponse);
}

/**
* @notice Proposing a response to a finalized request should fail
*/
Expand All @@ -440,8 +456,8 @@ contract Oracle_Unit_ProposeResponse is BaseTest {
}

contract Oracle_Unit_DisputeResponse is BaseTest {
bytes32 _responseId;
bytes32 _disputeId;
bytes32 internal _responseId;
bytes32 internal _disputeId;

function setUp() public override {
super.setUp();
Expand Down Expand Up @@ -496,6 +512,20 @@ contract Oracle_Unit_DisputeResponse is BaseTest {
oracle.disputeResponse(mockRequest, mockResponse, mockDispute);
}

/**
* @notice Reverts if the caller and the disputer are not the same
*/
function test_disputeResponse_revertIfWrongDisputer(address _caller) public {
vm.assume(_caller != disputer);

// Check: revert?
vm.expectRevert(IOracle.Oracle_InvalidDisputeBody.selector);

// Test: try to dispute the response again
vm.prank(_caller);
oracle.disputeResponse(mockRequest, mockResponse, mockDispute);
}

/**
* @notice Reverts if the request has already been disputed
*/
Expand Down
Loading