Skip to content

Commit

Permalink
test: increase some modules test coverage to 100
Browse files Browse the repository at this point in the history
  • Loading branch information
moebius committed Dec 8, 2023
1 parent e8aec63 commit b58d723
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 2 deletions.
65 changes: 63 additions & 2 deletions solidity/test/unit/modules/dispute/CircuitResolverModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ contract CircuitResolverModule_Unit_DisputeResponse is BaseTest {
}

contract CircuitResolverModule_Unit_OnDisputeStatusChange is BaseTest {
function test_emitsEvent(
function test_emitsEvent_lostDispute(
IAccountingExtension _accountingExtension,
IERC20 _randomToken,
uint256 _bondSize,
Expand All @@ -277,7 +277,7 @@ contract CircuitResolverModule_Unit_OnDisputeStatusChange is BaseTest {

mockResponse.requestId = _requestId;
mockResponse.response = _encodedCorrectResponse;
mockResponse.proposer = mockDispute.disputer;
mockResponse.proposer = makeAddr('proposer');

// Mock and expect the call to the oracle, finalizing the request
_mockAndExpect(address(oracle), abi.encodeCall(IOracle.finalize, (mockRequest, mockResponse)), abi.encode());
Expand All @@ -295,4 +295,65 @@ contract CircuitResolverModule_Unit_OnDisputeStatusChange is BaseTest {
vm.prank(address(oracle));
circuitResolverModule.onDisputeStatusChange(_disputeId, mockRequest, mockResponse, mockDispute);
}

function test_emitsEvent_wonDispute(
IAccountingExtension _accountingExtension,
IERC20 _randomToken,
uint256 _bondSize,
bytes memory _callData
) public {
mockRequest.disputeModuleData = abi.encode(
ICircuitResolverModule.RequestParameters({
callData: _callData,
verifier: address(mockVerifier),
accountingExtension: _accountingExtension,
bondToken: _randomToken,
bondSize: _bondSize
})
);

bytes32 _requestId = _getId(mockRequest);
bytes memory _encodedCorrectResponse = abi.encode(true);

circuitResolverModule.forTest_setCorrectResponse(_requestId, _encodedCorrectResponse);

mockResponse.requestId = _requestId;
mockResponse.response = abi.encode(false);
mockResponse.proposer = makeAddr('proposer');

// Populate the mock dispute with the correct values
mockDispute.responseId = _getId(mockResponse);
mockDispute.requestId = _requestId;
bytes32 _disputeId = _getId(mockDispute);
IOracle.DisputeStatus _status = IOracle.DisputeStatus.Won;

// Mock and expect the call to the accounting extension, paying the disputer
_mockAndExpect(
address(_accountingExtension),
abi.encodeCall(
IAccountingExtension.pay, (_requestId, makeAddr('proposer'), mockDispute.disputer, _randomToken, _bondSize)
),
abi.encode()
);

IOracle.Response memory _newResponse =
IOracle.Response({requestId: _requestId, response: _encodedCorrectResponse, proposer: mockDispute.disputer});

// Check: is the event emitted?
vm.expectEmit(true, true, true, true, address(circuitResolverModule));
emit DisputeStatusChanged(_disputeId, mockDispute, _status);

// Mock and expect the call to the oracle, proposing the correct response
_mockAndExpect(
address(oracle),
abi.encodeCall(IOracle.proposeResponse, (mockRequest, _newResponse)),
abi.encode(_getId(_newResponse))
);

// Mock and expect the call to the accounting extension, paying the disputer
_mockAndExpect(address(oracle), abi.encodeCall(IOracle.finalize, (mockRequest, _newResponse)), abi.encode());

vm.prank(address(oracle));
circuitResolverModule.onDisputeStatusChange(_disputeId, mockRequest, mockResponse, mockDispute);
}
}
26 changes: 26 additions & 0 deletions solidity/test/unit/modules/request/ContractCallRequestModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,32 @@ contract ContractCallRequestModule_Unit_ModuleData is BaseTest {
}
}

contract ContractCallRequestModule_Unit_CreateRequest is BaseTest {
function test_createRequest(
address _requester,
IContractCallRequestModule.RequestParameters memory _params
) public assumeFuzzable(_requester) {
mockRequest.requestModuleData = abi.encode(_params);
mockRequest.requester = _requester;

// Mock and expect the bond to be placed
_mockAndExpect(
address(_params.accountingExtension),
abi.encodeWithSignature(
'bond(address,bytes32,address,uint256)',
_requester,
_getId(mockRequest),
_params.paymentToken,
_params.paymentAmount
),
abi.encode()
);

vm.prank(address(oracle));
contractCallRequestModule.createRequest(_getId(mockRequest), mockRequest.requestModuleData, _requester);
}
}

contract ContractCallRequestModule_Unit_FinalizeRequest is BaseTest {
/**
* @notice Test that finalizeRequest calls:
Expand Down
11 changes: 11 additions & 0 deletions solidity/test/unit/modules/resolution/ERC20ResolutionModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,17 @@ contract ERC20ResolutionModule_Unit_ResolveDispute is BaseTest {
// Warp to resolving phase
vm.warp(150_000);

// Mock and expect IOracle.disputeStatus to be called
_mockAndExpect(
address(oracle), abi.encodeCall(IOracle.disputeStatus, (_disputeId)), abi.encode(IOracle.DisputeStatus.Won)
);

// Check: does it revert if the dispute status is != Escalated?
vm.expectRevert(IERC20ResolutionModule.ERC20ResolutionModule_AlreadyResolved.selector);
vm.prank(address(oracle));
module.resolveDispute(_disputeId, mockRequest, mockResponse, mockDispute);

// Mock and expect IOracle.disputeStatus to be called
_mockAndExpect(
address(oracle), abi.encodeCall(IOracle.disputeStatus, (_disputeId)), abi.encode(IOracle.DisputeStatus.Escalated)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,16 @@ contract PrivateERC20ResolutionModule_Unit_ResolveDispute is BaseTest {
// Warp to resolving phase
vm.warp(190_000);

// Mock and expect IOracle.disputeStatus to be called
_mockAndExpect(
address(oracle), abi.encodeCall(IOracle.disputeStatus, (_disputeId)), abi.encode(IOracle.DisputeStatus.Won)
);

// Check: does it revert if the dispute status is != None?
vm.expectRevert(IPrivateERC20ResolutionModule.PrivateERC20ResolutionModule_AlreadyResolved.selector);
vm.prank(address(oracle));
module.resolveDispute(_disputeId, mockRequest, mockResponse, mockDispute);

// Mock and expect token transfers (should happen always)
for (uint256 _i = 1; _i <= _votersAmount;) {
_mockAndExpect(address(token), abi.encodeCall(IERC20.transfer, (vm.addr(_i), 100)), abi.encode());
Expand All @@ -519,6 +529,11 @@ contract PrivateERC20ResolutionModule_Unit_ResolveDispute is BaseTest {
abi.encode()
);

// Mock and expect IOracle.disputeStatus to be called
_mockAndExpect(
address(oracle), abi.encodeCall(IOracle.disputeStatus, (_disputeId)), abi.encode(IOracle.DisputeStatus.None)
);

// Check: is the event emitted?
vm.expectEmit(true, true, true, true);
emit DisputeResolved(_requestId, _disputeId, _newStatus);
Expand Down

0 comments on commit b58d723

Please sign in to comment.