From d526ff95df5d7817f5730db93a3898fa78a0ad58 Mon Sep 17 00:00:00 2001 From: zorzal Date: Sat, 2 Nov 2024 08:49:06 -0400 Subject: [PATCH] feat: update circuit resolve module --- .../modules/dispute/CircuitResolverModule.sol | 15 +++-- .../dispute/CircuitResolverModule.t.sol | 58 ++++++------------- 2 files changed, 26 insertions(+), 47 deletions(-) diff --git a/solidity/contracts/modules/dispute/CircuitResolverModule.sol b/solidity/contracts/modules/dispute/CircuitResolverModule.sol index e4c955d9..80b6894a 100644 --- a/solidity/contracts/modules/dispute/CircuitResolverModule.sol +++ b/solidity/contracts/modules/dispute/CircuitResolverModule.sol @@ -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) { @@ -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({ @@ -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]; @@ -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 diff --git a/solidity/test/unit/modules/dispute/CircuitResolverModule.t.sol b/solidity/test/unit/modules/dispute/CircuitResolverModule.t.sol index 691b87d7..144a5e2d 100644 --- a/solidity/test/unit/modules/dispute/CircuitResolverModule.t.sol +++ b/solidity/test/unit/modules/dispute/CircuitResolverModule.t.sol @@ -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) ); @@ -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) ); @@ -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) ); @@ -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)); @@ -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);