Skip to content

Commit

Permalink
test: update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xorsal committed Oct 23, 2024
1 parent ed39f02 commit 88eaddf
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 98 deletions.
5 changes: 4 additions & 1 deletion solidity/test/mocks/MockArbitrator.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {IAccessController} from '@defi-wonderland/prophet-core/solidity/interfaces/IAccessController.sol';

import {IArbitrator, IOracle} from '../../interfaces/IArbitrator.sol';

contract MockArbitrator is IArbitrator {
Expand All @@ -13,7 +15,8 @@ contract MockArbitrator is IArbitrator {
function resolve(
IOracle.Request memory,
IOracle.Response memory,
IOracle.Dispute memory
IOracle.Dispute memory,
IAccessController.AccessControl memory AccessControl
) external pure returns (bytes memory _result) {
_result = new bytes(0);
}
Expand Down
6 changes: 4 additions & 2 deletions solidity/test/mocks/MockAtomicArbitrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.19;

import {IArbitrator} from '../../interfaces/IArbitrator.sol';
import {IAccessController} from '@defi-wonderland/prophet-core/solidity/interfaces/IAccessController.sol';
import {IOracle} from '@defi-wonderland/prophet-core/solidity/interfaces/IOracle.sol';

contract MockAtomicArbitrator is IArbitrator {
Expand All @@ -15,11 +16,12 @@ contract MockAtomicArbitrator is IArbitrator {
function resolve(
IOracle.Request memory _request,
IOracle.Response memory _response,
IOracle.Dispute memory _dispute
IOracle.Dispute memory _dispute,
IAccessController.AccessControl memory _accessControl
) external returns (bytes memory _result) {
_result = new bytes(0);
answer = IOracle.DisputeStatus.Won;
oracle.resolveDispute(_request, _response, _dispute);
oracle.resolveDispute(_request, _response, _dispute, _accessControl);
}

function getAnswer(bytes32 /* _dispute */ ) external view returns (IOracle.DisputeStatus _answer) {
Expand Down
50 changes: 34 additions & 16 deletions solidity/test/unit/modules/dispute/BondEscalationModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ contract BondEscalationModule_Unit_PledgeForDispute is BaseTest {
function test_revertIfInvalidDisputeBody() public {
// Check: does it revert if the dispute body is invalid?
vm.expectRevert(ValidatorLib.ValidatorLib_InvalidDisputeBody.selector);
bondEscalationModule.pledgeForDispute(mockRequest, mockDispute);
bondEscalationModule.pledgeForDispute(mockRequest, mockDispute, _createAccessControl(address(this)));
}

/**
Expand All @@ -991,7 +991,7 @@ contract BondEscalationModule_Unit_PledgeForDispute is BaseTest {

// Check: does it revert if the dispute is not escalated yet?
vm.expectRevert(IBondEscalationModule.BondEscalationModule_InvalidDispute.selector);
bondEscalationModule.pledgeForDispute(mockRequest, _dispute);
bondEscalationModule.pledgeForDispute(mockRequest, _dispute, _createAccessControl(address(this)));
}

/**
Expand All @@ -1017,7 +1017,7 @@ contract BondEscalationModule_Unit_PledgeForDispute is BaseTest {

// Check: does it revert if the bond escalation is over?
vm.expectRevert(IBondEscalationModule.BondEscalationModule_BondEscalationOver.selector);
bondEscalationModule.pledgeForDispute(mockRequest, _dispute);
bondEscalationModule.pledgeForDispute(mockRequest, _dispute, _createAccessControl(address(this)));
}

/**
Expand Down Expand Up @@ -1046,7 +1046,7 @@ contract BondEscalationModule_Unit_PledgeForDispute is BaseTest {

// Check: does it revert if the maximum number of escalations is reached?
vm.expectRevert(IBondEscalationModule.BondEscalationModule_MaxNumberOfEscalationsReached.selector);
bondEscalationModule.pledgeForDispute(mockRequest, _dispute);
bondEscalationModule.pledgeForDispute(mockRequest, _dispute, _createAccessControl(address(this)));
}

/**
Expand Down Expand Up @@ -1074,7 +1074,7 @@ contract BondEscalationModule_Unit_PledgeForDispute is BaseTest {

// Check: does it revert if trying to pledge in a dispute that is already surpassed?
vm.expectRevert(IBondEscalationModule.BondEscalationModule_CanOnlySurpassByOnePledge.selector);
bondEscalationModule.pledgeForDispute(mockRequest, _dispute);
bondEscalationModule.pledgeForDispute(mockRequest, _dispute, _createAccessControl(address(this)));
}

/**
Expand Down Expand Up @@ -1107,7 +1107,7 @@ contract BondEscalationModule_Unit_PledgeForDispute is BaseTest {

// Check: does it revert if trying to tie outside of the tying buffer?
vm.expectRevert(IBondEscalationModule.BondEscalationModule_CannotBreakTieDuringTyingBuffer.selector);
bondEscalationModule.pledgeForDispute(mockRequest, _dispute);
bondEscalationModule.pledgeForDispute(mockRequest, _dispute, _createAccessControl(address(this)));
}

/**
Expand Down Expand Up @@ -1148,7 +1148,7 @@ contract BondEscalationModule_Unit_PledgeForDispute is BaseTest {
vm.expectEmit(true, true, true, true, address(bondEscalationModule));
emit PledgedForDispute(_disputeId, address(this), _params.bondSize);

bondEscalationModule.pledgeForDispute(mockRequest, _dispute);
bondEscalationModule.pledgeForDispute(mockRequest, _dispute, _createAccessControl(address(this)));

uint256 _pledgesForDispute = bondEscalationModule.getEscalation(_requestId).amountOfPledgesForDispute;
// Check: is the number of pledges for the dispute properly updated?
Expand All @@ -1167,7 +1167,7 @@ contract BondEscalationModule_Unit_PledgeAgainstDispute is BaseTest {
function test_revertIfInvalidDisputeBody() public {
// Check: does it revert if the dispute body is invalid?
vm.expectRevert(ValidatorLib.ValidatorLib_InvalidDisputeBody.selector);
bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute);
bondEscalationModule.pledgeAgainstDispute(mockRequest, mockDispute, _createAccessControl(address(this)));
}

/**
Expand All @@ -1178,7 +1178,7 @@ contract BondEscalationModule_Unit_PledgeAgainstDispute is BaseTest {

// Check: does it revert if the dispute is not escalated yet?
vm.expectRevert(IBondEscalationModule.BondEscalationModule_InvalidDispute.selector);
bondEscalationModule.pledgeAgainstDispute(mockRequest, _dispute);
bondEscalationModule.pledgeAgainstDispute(mockRequest, _dispute, _createAccessControl(address(this)));
}

/**
Expand All @@ -1204,7 +1204,7 @@ contract BondEscalationModule_Unit_PledgeAgainstDispute is BaseTest {

// Check: does it revert if the bond escalation is over?
vm.expectRevert(IBondEscalationModule.BondEscalationModule_BondEscalationOver.selector);
bondEscalationModule.pledgeAgainstDispute(mockRequest, _dispute);
bondEscalationModule.pledgeAgainstDispute(mockRequest, _dispute, _createAccessControl(address(this)));
}

/**
Expand Down Expand Up @@ -1234,7 +1234,7 @@ contract BondEscalationModule_Unit_PledgeAgainstDispute is BaseTest {
// Check: does it revert if the maximum number of escalations is reached?
vm.expectRevert(IBondEscalationModule.BondEscalationModule_MaxNumberOfEscalationsReached.selector);

bondEscalationModule.pledgeAgainstDispute(mockRequest, _dispute);
bondEscalationModule.pledgeAgainstDispute(mockRequest, _dispute, _createAccessControl(address(this)));
}

/**
Expand Down Expand Up @@ -1265,7 +1265,7 @@ contract BondEscalationModule_Unit_PledgeAgainstDispute is BaseTest {
// Check: does it revert if trying to pledge in a dispute that is already surpassed?
vm.expectRevert(IBondEscalationModule.BondEscalationModule_CanOnlySurpassByOnePledge.selector);

bondEscalationModule.pledgeAgainstDispute(mockRequest, _dispute);
bondEscalationModule.pledgeAgainstDispute(mockRequest, _dispute, _createAccessControl(address(this)));
}

/**
Expand Down Expand Up @@ -1298,7 +1298,7 @@ contract BondEscalationModule_Unit_PledgeAgainstDispute is BaseTest {

// Check: does it revert if trying to tie outside of the tying buffer?
vm.expectRevert(IBondEscalationModule.BondEscalationModule_CannotBreakTieDuringTyingBuffer.selector);
bondEscalationModule.pledgeAgainstDispute(mockRequest, _dispute);
bondEscalationModule.pledgeAgainstDispute(mockRequest, _dispute, _createAccessControl(address(this)));
}

/**
Expand Down Expand Up @@ -1337,7 +1337,7 @@ contract BondEscalationModule_Unit_PledgeAgainstDispute is BaseTest {
vm.expectEmit(true, true, true, true, address(bondEscalationModule));
emit PledgedAgainstDispute(_disputeId, address(this), _params.bondSize);

bondEscalationModule.pledgeAgainstDispute(mockRequest, _dispute);
bondEscalationModule.pledgeAgainstDispute(mockRequest, _dispute, _createAccessControl(address(this)));

uint256 _pledgesForDispute = bondEscalationModule.getEscalation(_requestId).amountOfPledgesAgainstDispute;
// Check: is the number of pledges for the dispute properly updated?
Expand Down Expand Up @@ -1489,7 +1489,16 @@ contract BondEscalationModule_Unit_SettleBondEscalation is BaseTest {

_mockAndExpect(
address(oracle),
abi.encodeCall(IOracle.updateDisputeStatus, (mockRequest, _response, _dispute, IOracle.DisputeStatus.Won)),
abi.encodeCall(
IOracle.updateDisputeStatus,
(
mockRequest,
_response,
_dispute,
IOracle.DisputeStatus.Won,
_createAccessControl(address(bondEscalationModule))
)
),
abi.encode(true)
);

Expand Down Expand Up @@ -1534,7 +1543,16 @@ contract BondEscalationModule_Unit_SettleBondEscalation is BaseTest {

_mockAndExpect(
address(oracle),
abi.encodeCall(IOracle.updateDisputeStatus, (mockRequest, _response, _dispute, IOracle.DisputeStatus.Lost)),
abi.encodeCall(
IOracle.updateDisputeStatus,
(
mockRequest,
_response,
_dispute,
IOracle.DisputeStatus.Lost,
_createAccessControl(address(bondEscalationModule))
)
),
abi.encode(true)
);

Expand Down
46 changes: 39 additions & 7 deletions solidity/test/unit/modules/dispute/CircuitResolverModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,19 @@ contract CircuitResolverModule_Unit_DisputeResponse is BaseTest {
// Mock and expect the call the oracle, updating the dispute's status
_mockAndExpect(
address(oracle),
abi.encodeWithSelector(
oracle.updateDisputeStatus.selector, mockRequest, mockResponse, mockDispute, IOracle.DisputeStatus.Won
abi.encodeCall(
IOracle.updateDisputeStatus,
(
mockRequest,
mockResponse,
mockDispute,
IOracle.DisputeStatus.Won,
_createAccessControl(address(circuitResolverModule))
)
),
// abi.encodeWithSelector(
// oracle.updateDisputeStatus.selector,
// ),
abi.encode(true)
);

Expand Down Expand Up @@ -201,8 +211,18 @@ contract CircuitResolverModule_Unit_DisputeResponse is BaseTest {
// Mock and expect the call the oracle, updating the dispute's status
_mockAndExpect(
address(oracle),
abi.encodeWithSelector(
oracle.updateDisputeStatus.selector, mockRequest, mockResponse, mockDispute, IOracle.DisputeStatus.Won
// abi.encodeWithSelector(
// oracle.updateDisputeStatus.selector, mockRequest, mockResponse, mockDispute, IOracle.DisputeStatus.Won
// ),
abi.encodeCall(
IOracle.updateDisputeStatus,
(
mockRequest,
mockResponse,
mockDispute,
IOracle.DisputeStatus.Won,
_createAccessControl(address(circuitResolverModule))
)
),
abi.encode(true)
);
Expand Down Expand Up @@ -254,9 +274,19 @@ contract CircuitResolverModule_Unit_DisputeResponse is BaseTest {
// Mock and expect the call the oracle, updating the dispute's status
_mockAndExpect(
address(oracle),
abi.encodeWithSelector(
oracle.updateDisputeStatus.selector, mockRequest, mockResponse, mockDispute, IOracle.DisputeStatus.Lost
abi.encodeCall(
IOracle.updateDisputeStatus,
(
mockRequest,
mockResponse,
mockDispute,
IOracle.DisputeStatus.Lost,
_createAccessControl(address(circuitResolverModule))
)
),
// abi.encodeWithSelector(
// oracle.updateDisputeStatus.selector, mockRequest, mockResponse, mockDispute, IOracle.DisputeStatus.Lost
// ),
abi.encode(true)
);

Expand Down Expand Up @@ -377,7 +407,9 @@ contract CircuitResolverModule_Unit_OnDisputeStatusChange is BaseTest {
// Mock and expect the call to the oracle, proposing the correct response
_mockAndExpect(
address(oracle),
abi.encodeCall(IOracle.proposeResponse, (mockRequest, _newResponse)),
abi.encodeCall(
IOracle.proposeResponse, (mockRequest, _newResponse, _createAccessControl(address(circuitResolverModule)))
),
abi.encode(_getId(_newResponse))
);

Expand Down
42 changes: 36 additions & 6 deletions solidity/test/unit/modules/dispute/RootVerificationModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,18 @@ contract RootVerificationModule_Unit_DisputeResponse is BaseTest {
// Mock and expect the call the oracle, updating the dispute's status
_mockAndExpect(
address(oracle),
abi.encodeWithSelector(
oracle.updateDisputeStatus.selector, mockRequest, mockResponse, mockDispute, IOracle.DisputeStatus.Won
// abi.encodeWithSelector(
// oracle.updateDisputeStatus.selector, mockRequest, mockResponse, mockDispute, IOracle.DisputeStatus.Won
// ),
abi.encodeCall(
IOracle.updateDisputeStatus,
(
mockRequest,
mockResponse,
mockDispute,
IOracle.DisputeStatus.Won,
_createAccessControl(address(rootVerificationModule))
)
),
abi.encode(true)
);
Expand Down Expand Up @@ -250,9 +260,19 @@ contract RootVerificationModule_Unit_DisputeResponse is BaseTest {
// Mock and expect the call the oracle, updating the dispute's status
_mockAndExpect(
address(oracle),
abi.encodeWithSelector(
oracle.updateDisputeStatus.selector, mockRequest, mockResponse, mockDispute, IOracle.DisputeStatus.Won
abi.encodeCall(
IOracle.updateDisputeStatus,
(
mockRequest,
mockResponse,
mockDispute,
IOracle.DisputeStatus.Won,
_createAccessControl(address(rootVerificationModule))
)
),
// abi.encodeWithSelector(
// oracle.updateDisputeStatus.selector, mockRequest, mockResponse, mockDispute, IOracle.DisputeStatus.Won
// ),
abi.encode(true)
);

Expand Down Expand Up @@ -305,9 +325,19 @@ contract RootVerificationModule_Unit_DisputeResponse is BaseTest {
// Mock and expect the call the oracle, updating the dispute's status
_mockAndExpect(
address(oracle),
abi.encodeWithSelector(
oracle.updateDisputeStatus.selector, mockRequest, mockResponse, mockDispute, IOracle.DisputeStatus.Lost
abi.encodeCall(
IOracle.updateDisputeStatus,
(
mockRequest,
mockResponse,
mockDispute,
IOracle.DisputeStatus.Lost,
_createAccessControl(address(rootVerificationModule))
)
),
// abi.encodeWithSelector(
// oracle.updateDisputeStatus.selector, mockRequest, mockResponse, mockDispute, IOracle.DisputeStatus.Lost
// ),
abi.encode(true)
);

Expand Down
26 changes: 22 additions & 4 deletions solidity/test/unit/modules/resolution/ArbitratorModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ contract ArbitratorModule_Unit_StartResolution is BaseTest {

// Mock and expect the callback to the arbitrator
_mockAndExpect(
_arbitrator, abi.encodeCall(arbitrator.resolve, (mockRequest, mockResponse, mockDispute)), abi.encode(bytes(''))
_arbitrator,
abi.encodeCall(
arbitrator.resolve,
// review
(mockRequest, mockResponse, mockDispute, _createAccessControl(address(arbitratorModule)))
),
abi.encode(bytes(''))
);

vm.prank(address(oracle));
Expand All @@ -135,7 +141,13 @@ contract ArbitratorModule_Unit_StartResolution is BaseTest {

// Mock and expect the callback to the arbitrator
_mockAndExpect(
_arbitrator, abi.encodeCall(arbitrator.resolve, (mockRequest, mockResponse, mockDispute)), abi.encode(bytes(''))
_arbitrator,
abi.encodeCall(
arbitrator.resolve,
// review
(mockRequest, mockResponse, mockDispute, _createAccessControl(address(arbitratorModule)))
),
abi.encode(bytes(''))
);

// Check: is the event emitted?
Expand Down Expand Up @@ -196,7 +208,10 @@ contract ArbitratorModule_Unit_ResolveDispute is BaseTest {
// Mock and expect IOracle.updateDisputeStatus to be called
_mockAndExpect(
address(oracle),
abi.encodeCall(oracle.updateDisputeStatus, (mockRequest, mockResponse, mockDispute, _arbitratorStatus)),
abi.encodeCall(
oracle.updateDisputeStatus,
(mockRequest, mockResponse, mockDispute, _arbitratorStatus, _createAccessControl(address(arbitratorModule)))
),
abi.encode()
);

Expand Down Expand Up @@ -251,7 +266,10 @@ contract ArbitratorModule_Unit_ResolveDispute is BaseTest {
// Mock and expect IOracle.updateDisputeStatus to be called
_mockAndExpect(
address(oracle),
abi.encodeCall(oracle.updateDisputeStatus, (mockRequest, mockResponse, mockDispute, _arbitratorStatus)),
abi.encodeCall(
oracle.updateDisputeStatus,
(mockRequest, mockResponse, mockDispute, _arbitratorStatus, _createAccessControl(address(arbitratorModule)))
),
abi.encode()
);

Expand Down
Loading

0 comments on commit 88eaddf

Please sign in to comment.