Skip to content

Commit

Permalink
feat: granular reverts (#45)
Browse files Browse the repository at this point in the history
* refactor: set params_first_multi for multiline_func_header in forge fmt

* feat: avoid using duplicate errors

* test: update expected errors in unit tests

* style: remove dot from @notice tags
  • Loading branch information
xorsal authored Sep 24, 2024
1 parent 0954a47 commit c90a3e8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ bracket_spacing = false
int_types = 'long'
quote_style = 'single'
number_underscore = 'thousands'
multiline_func_header = 'params_first'
multiline_func_header = 'params_first_multi'
sort_imports = true

[profile.default]
Expand Down
8 changes: 4 additions & 4 deletions solidity/contracts/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ contract Oracle is IOracle {

// The caller must be the proposer, unless the response is coming from a dispute module
if (msg.sender != _response.proposer && msg.sender != address(_request.disputeModule)) {
revert Oracle_InvalidResponseBody();
revert Oracle_InvalidProposer();
}

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

if (finalizedAt[_requestId] != 0) {
Expand Down Expand Up @@ -153,11 +153,11 @@ contract Oracle is IOracle {
}

if (_dispute.proposer != _response.proposer) {
revert Oracle_InvalidDisputeBody();
revert Oracle_InvalidProposer();
}

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

if (finalizedAt[_requestId] != 0) {
Expand Down
15 changes: 15 additions & 0 deletions solidity/interfaces/IOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,21 @@ interface IOracle {
*/
error Oracle_InvalidDispute();

/**
* @notice Thrown when response has been already proposed
*/
error Oracle_ResponseAlreadyProposed();

/**
* @notice Thrown when the proposer is invalid
*/
error Oracle_InvalidProposer();

/**
* @notice Thrown when the disputer is invalid
*/
error Oracle_InvalidDisputer();

/*///////////////////////////////////////////////////////////////
ENUMS
//////////////////////////////////////////////////////////////*/
Expand Down
8 changes: 4 additions & 4 deletions solidity/test/unit/Oracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ contract Oracle_Unit_ProposeResponse is BaseTest {
oracle.mock_setRequestCreatedAt(_getId(mockRequest), uint128(block.number));

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

// Test: try to propose a response from a random address
vm.prank(_caller);
Expand All @@ -500,7 +500,7 @@ contract Oracle_Unit_ProposeResponse is BaseTest {
oracle.proposeResponse(mockRequest, mockResponse);

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

// Test: try to propose the same response again
vm.prank(proposer);
Expand Down Expand Up @@ -576,7 +576,7 @@ contract Oracle_Unit_DisputeResponse is BaseTest {
oracle.mock_setRequestCreatedAt(_getId(mockRequest), uint128(block.number));

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

mockDispute.proposer = _otherProposer;

Expand Down Expand Up @@ -606,7 +606,7 @@ contract Oracle_Unit_DisputeResponse is BaseTest {
vm.assume(_caller != disputer);

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

// Test: try to dispute the response again
vm.prank(_caller);
Expand Down

0 comments on commit c90a3e8

Please sign in to comment.