Skip to content

Commit

Permalink
test: test coverage for bonded response module
Browse files Browse the repository at this point in the history
  • Loading branch information
moebius committed Dec 12, 2023
1 parent 5e09c11 commit eab5725
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
7 changes: 3 additions & 4 deletions solidity/test/integration/Finalization.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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);
}
/**
Expand Down
46 changes: 38 additions & 8 deletions solidity/test/unit/modules/response/BondedResponseModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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));
}
Expand Down

0 comments on commit eab5725

Please sign in to comment.