Skip to content

Commit

Permalink
feat: update circuit resolve module
Browse files Browse the repository at this point in the history
  • Loading branch information
xorsal committed Nov 2, 2024
1 parent ea1d17f commit d526ff9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 47 deletions.
15 changes: 9 additions & 6 deletions solidity/contracts/modules/dispute/CircuitResolverModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import {IOracle} from '@defi-wonderland/prophet-core/solidity/interfaces/IOracle
import {IProphetVerifier} from '../../../interfaces/IProphetVerifier.sol';
import {ICircuitResolverModule} from '../../../interfaces/modules/dispute/ICircuitResolverModule.sol';

contract CircuitResolverModule is Module, ICircuitResolverModule {
import {AccessControllerModule} from '../accessControl/AccessControllerModule.sol';

contract CircuitResolverModule is AccessControllerModule, ICircuitResolverModule {
/// @notice Keeps track of the correct responses to requests
mapping(bytes32 _requestId => bytes _correctResponse) internal _correctResponses;

constructor(IOracle _oracle) Module(_oracle) {}
constructor(IOracle _oracle) AccessControllerModule(_oracle) {}

/// @inheritdoc IModule
function moduleName() external pure returns (string memory _moduleName) {
Expand All @@ -32,6 +34,7 @@ contract CircuitResolverModule is Module, ICircuitResolverModule {
) external onlyOracle {
RequestParameters memory _params = decodeRequestData(_request.disputeModuleData);
IOracle.DisputeStatus _status = ORACLE.disputeStatus(_disputeId);
AccessControl memory _accessControl = _defaultAccessControl();

if (_status == IOracle.DisputeStatus.Won) {
_params.accountingExtension.pay({
Expand All @@ -50,12 +53,12 @@ contract CircuitResolverModule is Module, ICircuitResolverModule {

emit DisputeStatusChanged({_disputeId: _disputeId, _dispute: _dispute, _status: IOracle.DisputeStatus.Won});

ORACLE.proposeResponse(_request, _newResponse);
ORACLE.finalize(_request, _newResponse);
ORACLE.proposeResponse(_request, _newResponse, _accessControl);
ORACLE.finalize(_request, _newResponse, _accessControl);
} else {
emit DisputeStatusChanged({_disputeId: _disputeId, _dispute: _dispute, _status: IOracle.DisputeStatus.Lost});

ORACLE.finalize(_request, _response);
ORACLE.finalize(_request, _response, _accessControl);
}

delete _correctResponses[_dispute.requestId];
Expand Down Expand Up @@ -88,7 +91,7 @@ contract CircuitResolverModule is Module, ICircuitResolverModule {
_dispute: _dispute
});

ORACLE.updateDisputeStatus(_request, _response, _dispute, _status);
ORACLE.updateDisputeStatus({_request: _request, _response: _response, _dispute: _dispute, _status: _status});
}

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

Expand Down Expand Up @@ -211,19 +199,7 @@ 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.encodeCall(IOracle.updateDisputeStatus, (mockRequest, mockResponse, mockDispute, IOracle.DisputeStatus.Won)),
abi.encode(true)
);

Expand Down Expand Up @@ -274,19 +250,7 @@ contract CircuitResolverModule_Unit_DisputeResponse is BaseTest {
// Mock and expect the call the oracle, updating the dispute's status
_mockAndExpect(
address(oracle),
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.encodeCall(IOracle.updateDisputeStatus, (mockRequest, mockResponse, mockDispute, IOracle.DisputeStatus.Lost)),
abi.encode(true)
);

Expand Down Expand Up @@ -344,7 +308,13 @@ contract CircuitResolverModule_Unit_OnDisputeStatusChange is BaseTest {
_mockAndExpect(address(oracle), abi.encodeCall(IOracle.disputeStatus, (_disputeId)), abi.encode(_status));

// Mock and expect the call to the oracle, finalizing the request
_mockAndExpect(address(oracle), abi.encodeCall(IOracle.finalize, (mockRequest, mockResponse)), abi.encode());
_mockAndExpect(
address(oracle),
abi.encodeCall(
IOracle.finalize, (mockRequest, mockResponse, _createAccessControl(address(circuitResolverModule)))
),
abi.encode()
);

// Check: is the event emitted?
vm.expectEmit(true, true, true, true, address(circuitResolverModule));
Expand Down Expand Up @@ -414,7 +384,13 @@ contract CircuitResolverModule_Unit_OnDisputeStatusChange is BaseTest {
);

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

vm.prank(address(oracle));
circuitResolverModule.onDisputeStatusChange(_disputeId, mockRequest, mockResponse, mockDispute);
Expand Down

0 comments on commit d526ff9

Please sign in to comment.