From 84a05a87deb4589dddbf3bc81dc1178641e0560b Mon Sep 17 00:00:00 2001 From: zorzal Date: Fri, 20 Sep 2024 10:55:17 -0400 Subject: [PATCH] test: update expected errors in unit tests --- solidity/test/unit/Oracle.t.sol | 80 ++++++++++++++++++++++++--------- 1 file changed, 58 insertions(+), 22 deletions(-) diff --git a/solidity/test/unit/Oracle.t.sol b/solidity/test/unit/Oracle.t.sol index 07f6b23..0e561a9 100644 --- a/solidity/test/unit/Oracle.t.sol +++ b/solidity/test/unit/Oracle.t.sol @@ -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; } @@ -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)); @@ -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 @@ -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 @@ -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); @@ -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); @@ -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); @@ -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 @@ -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); @@ -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); @@ -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 @@ -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; @@ -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); @@ -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); @@ -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) @@ -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; @@ -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)); @@ -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 @@ -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);