Skip to content

Commit

Permalink
test: update expected errors in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xorsal committed Sep 20, 2024
1 parent 0afb9f1 commit 84a05a8
Showing 1 changed file with 58 additions and 22 deletions.
80 changes: 58 additions & 22 deletions solidity/test/unit/Oracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ contract MockOracle is Oracle {
disputeCreatedAt[_disputeId] = _disputeCreatedAt;
}

function mock_setTotalRequestCount(uint256 _totalRequestCount) external {
function mock_setTotalRequestCount(
uint256 _totalRequestCount
) external {
totalRequestCount = _totalRequestCount;
}

Expand Down Expand Up @@ -126,7 +128,9 @@ contract BaseTest is Test, Helpers {
/**
* @notice If no dispute and finality module used, set them to address(0)
*/
modifier setResolutionAndFinality(bool _useResolutionAndFinality) {
modifier setResolutionAndFinality(
bool _useResolutionAndFinality
) {
if (!_useResolutionAndFinality) {
resolutionModule = IResolutionModule(address(0));
finalityModule = IFinalityModule(address(0));
Expand Down Expand Up @@ -199,7 +203,9 @@ contract Oracle_Unit_CreateRequest is BaseTest {
/**
* @notice Check that creating a request with a nonce that already exists reverts
*/
function test_createRequest_revertsIfInvalidNonce(uint256 _nonce) public {
function test_createRequest_revertsIfInvalidNonce(
uint256 _nonce
) public {
vm.assume(_nonce != oracle.totalRequestCount());

// Set the nonce
Expand All @@ -216,7 +222,9 @@ contract Oracle_Unit_CreateRequest is BaseTest {
/**
* @notice Check that creating a request with a misconfigured requester reverts
*/
function test_createRequest_revertsIfInvalidRequester(address _requester) public {
function test_createRequest_revertsIfInvalidRequester(
address _requester
) public {
vm.assume(_requester != requester);

// Set the nonce
Expand Down Expand Up @@ -337,7 +345,9 @@ contract Oracle_Unit_ListRequestIds is BaseTest {
/**
* @notice Test list requests ids, fuzz the batch size
*/
function test_listRequestIds(uint256 _numberOfRequests) public {
function test_listRequestIds(
uint256 _numberOfRequests
) public {
// 0 to 10 request to list, fuzzed
_numberOfRequests = bound(_numberOfRequests, 0, 10);

Expand Down Expand Up @@ -367,7 +377,9 @@ contract Oracle_Unit_ListRequestIds is BaseTest {
/**
* @notice Test the request listing if asking for more request than it exists
*/
function test_listRequestIds_tooManyRequested(uint256 _numberOfRequests) public {
function test_listRequestIds_tooManyRequested(
uint256 _numberOfRequests
) public {
// 1 to 10 request to list, fuzzed
_numberOfRequests = bound(_numberOfRequests, 1, 10);

Expand Down Expand Up @@ -401,7 +413,9 @@ contract Oracle_Unit_ListRequestIds is BaseTest {
/**
* @notice Test the request listing if there are no requests encoded
*/
function test_listRequestIds_zeroToReturn(uint256 _numberOfRequests) public {
function test_listRequestIds_zeroToReturn(
uint256 _numberOfRequests
) public {
// Test: fetch any number of requests
bytes32[] memory _requestsIds = oracle.listRequestIds(0, _numberOfRequests);

Expand All @@ -414,7 +428,9 @@ contract Oracle_Unit_ProposeResponse is BaseTest {
/**
* @notice Proposing a response should call the response module, emit an event and return the response id
*/
function test_proposeResponse(bytes calldata _responseData) public {
function test_proposeResponse(
bytes calldata _responseData
) public {
bytes32 _requestId = _getId(mockRequest);

// Update mock response
Expand Down Expand Up @@ -475,13 +491,15 @@ contract Oracle_Unit_ProposeResponse is BaseTest {
/**
* @notice Revert if the caller is not the proposer nor the dispute module
*/
function test_proposeResponse_revertsIfInvalidCaller(address _caller) public {
function test_proposeResponse_revertsIfInvalidCaller(
address _caller
) public {
vm.assume(_caller != proposer && _caller != address(disputeModule));

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 +518,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 All @@ -510,7 +528,9 @@ contract Oracle_Unit_ProposeResponse is BaseTest {
/**
* @notice Proposing a response to a finalized request should fail
*/
function test_proposeResponse_revertsIfAlreadyFinalized(uint128 _finalizedAt) public {
function test_proposeResponse_revertsIfAlreadyFinalized(
uint128 _finalizedAt
) public {
vm.assume(_finalizedAt > 0);

// Set the finalization time
Expand Down Expand Up @@ -571,12 +591,14 @@ contract Oracle_Unit_DisputeResponse is BaseTest {
/**
* @notice Reverts if the dispute proposer and response proposer are not same
*/
function test_disputeResponse_revertIfProposerIsNotValid(address _otherProposer) public {
function test_disputeResponse_revertIfProposerIsNotValid(
address _otherProposer
) public {
vm.assume(_otherProposer != proposer);
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 All @@ -602,11 +624,13 @@ contract Oracle_Unit_DisputeResponse is BaseTest {
/**
* @notice Reverts if the caller and the disputer are not the same
*/
function test_disputeResponse_revertIfWrongDisputer(address _caller) public {
function test_disputeResponse_revertIfWrongDisputer(
address _caller
) public {
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 Expand Up @@ -692,7 +716,9 @@ contract Oracle_Unit_UpdateDisputeStatus is BaseTest {
/**
* @notice If the sender is not the dispute/resolution module, the call should revert
*/
function test_updateDisputeStatus_revertsIfWrongCaller(uint256 _newStatus) public {
function test_updateDisputeStatus_revertsIfWrongCaller(
uint256 _newStatus
) public {
// 0 to 3 status, fuzzed
_newStatus = bound(_newStatus, 0, 3);

Expand Down Expand Up @@ -845,7 +871,9 @@ contract Oracle_Unit_AllowedModule is BaseTest {
/**
* @notice Test if the modules are recognized as allowed and random addresses aren't
*/
function test_allowedModule(address _notAModule) public {
function test_allowedModule(
address _notAModule
) public {
// Fuzz any address not in the modules of the request
vm.assume(
_notAModule != address(requestModule) && _notAModule != address(responseModule)
Expand Down Expand Up @@ -987,7 +1015,9 @@ contract Oracle_Unit_Finalize is BaseTest {
/**
* @notice Test the response validation, its requestId should match the id of the provided request
*/
function test_finalize_withResponse_revertsInvalidRequestId(bytes32 _requestId) public {
function test_finalize_withResponse_revertsInvalidRequestId(
bytes32 _requestId
) public {
vm.assume(_requestId != bytes32(0) && _requestId != _getId(mockRequest));

mockResponse.requestId = _requestId;
Expand All @@ -1007,7 +1037,9 @@ contract Oracle_Unit_Finalize is BaseTest {
/**
* @notice Finalizing a request with a successfully disputed response should revert
*/
function test_finalize_withResponse_revertsIfDisputedResponse(uint256 _status) public {
function test_finalize_withResponse_revertsIfDisputedResponse(
uint256 _status
) public {
vm.assume(_status != uint256(IOracle.DisputeStatus.Lost));
vm.assume(_status != uint256(IOracle.DisputeStatus.None));
vm.assume(_status <= uint256(type(IOracle.DisputeStatus).max));
Expand Down Expand Up @@ -1117,7 +1149,9 @@ contract Oracle_Unit_Finalize is BaseTest {
/**
* @notice Finalizing an already finalized response shouldn't be possible
*/
function test_finalize_withoutResponse_revertsWhenAlreadyFinalized(address _caller) public withoutResponse {
function test_finalize_withoutResponse_revertsWhenAlreadyFinalized(
address _caller
) public withoutResponse {
bytes32 _requestId = _getId(mockRequest);

// Override the finalizedAt to make it be finalized
Expand All @@ -1133,7 +1167,9 @@ contract Oracle_Unit_Finalize is BaseTest {
/**
* @notice Finalizing a request with a non-disputed response should revert
*/
function test_finalize_withoutResponse_revertsWithNonDisputedResponse(bytes32 _responseId) public withoutResponse {
function test_finalize_withoutResponse_revertsWithNonDisputedResponse(
bytes32 _responseId
) public withoutResponse {
vm.assume(_responseId != bytes32(0));

bytes32 _requestId = _getId(mockRequest);
Expand Down

0 comments on commit 84a05a8

Please sign in to comment.