diff --git a/solidity/test/integration/Finalization.t.sol b/solidity/test/integration/Finalization.t.sol index a70c594a..d30124b9 100644 --- a/solidity/test/integration/Finalization.t.sol +++ b/solidity/test/integration/Finalization.t.sol @@ -152,8 +152,9 @@ contract Integration_Finalization is IntegrationBase { /** * @notice Test to check that finalizing a request with a ongoing dispute with revert. */ + //asdf function test_revertFinalizeInDisputeWindow(uint256 _block) public { - vm.assume(_block < _expectedDeadline + _baseDisputeWindow); + _block = bound(_block, block.number, _expectedDeadline - _baseDisputeWindow - 1); address _callbackTarget = makeAddr('target'); vm.etch(_callbackTarget, hex'069420'); @@ -179,9 +180,7 @@ contract Integration_Finalization is IntegrationBase { vm.roll(_block); vm.prank(_finalizer); - if (_block < _expectedDeadline + _baseDisputeWindow) { - vm.expectRevert(IBondedResponseModule.BondedResponseModule_TooEarlyToFinalize.selector); - } + vm.expectRevert(IBondedResponseModule.BondedResponseModule_TooEarlyToFinalize.selector); oracle.finalize(_request, _response); } /** diff --git a/solidity/test/unit/modules/response/BondedResponseModule.t.sol b/solidity/test/unit/modules/response/BondedResponseModule.t.sol index f402a180..a9465e90 100644 --- a/solidity/test/unit/modules/response/BondedResponseModule.t.sol +++ b/solidity/test/unit/modules/response/BondedResponseModule.t.sol @@ -178,19 +178,31 @@ contract BondedResponseModule_Unit_FinalizeRequest is BaseTest { } function test_revertsBeforeDeadline( - IERC20 _token, - uint256 _bondSize, + uint256 _responseCreationBlock, + uint256 _finalizationBlock, uint256 _deadline, - uint256 _disputeWindow, - address _proposer + uint256 _disputeWindow ) public { - _deadline = bound(_deadline, block.timestamp + 1, type(uint248).max); - _disputeWindow = bound(_disputeWindow, 61, 365 days); + // Amount of blocks to wait before finalizing a response + _disputeWindow = bound(_disputeWindow, 10, 90_000); + // Last block in which a response can be proposed + _deadline = bound(_deadline, 100_000, type(uint128).max); + // Block in which the response was proposed + _responseCreationBlock = bound(_responseCreationBlock, _deadline - _disputeWindow + 1, _deadline - 1); + // Block in which the request will be tried to be finalized + _finalizationBlock = bound(_finalizationBlock, _deadline, _responseCreationBlock + _disputeWindow - 1); // Check revert if deadline has not passed - mockRequest.responseModuleData = abi.encode(accounting, _token, _bondSize, _deadline, _disputeWindow); + mockRequest.responseModuleData = abi.encode( + IBondedResponseModule.RequestParameters({ + accountingExtension: accounting, + bondToken: IERC20(makeAddr('token')), + bondSize: 999_999, + deadline: _deadline, + disputeWindow: _disputeWindow + }) + ); mockResponse.requestId = _getId(mockRequest); - mockResponse.proposer = _proposer; // Mock and expect IOracle.allowedModule to be called _mockAndExpect( @@ -200,6 +212,24 @@ contract BondedResponseModule_Unit_FinalizeRequest is BaseTest { // Check: does it revert if it's too early to finalize? vm.expectRevert(IBondedResponseModule.BondedResponseModule_TooEarlyToFinalize.selector); + vm.roll(_deadline - 1); + vm.prank(address(oracle)); + bondedResponseModule.finalizeRequest(mockRequest, mockResponse, address(this)); + + // Mock and expect IOracle.allowedModule to be called + _mockAndExpect( + address(oracle), abi.encodeCall(IOracle.allowedModule, (_getId(mockRequest), address(this))), abi.encode(false) + ); + + // Mock and expect IOracle.allowedModule to be called + _mockAndExpect( + address(oracle), abi.encodeCall(IOracle.createdAt, (_getId(mockResponse))), abi.encode(_responseCreationBlock) + ); + + // Check: does it revert if it's too early to finalize? + vm.expectRevert(IBondedResponseModule.BondedResponseModule_TooEarlyToFinalize.selector); + + vm.roll(_finalizationBlock); vm.prank(address(oracle)); bondedResponseModule.finalizeRequest(mockRequest, mockResponse, address(this)); }