Skip to content

Commit

Permalink
fix: access control in unit and integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gas1cent committed Nov 6, 2024
1 parent 330e236 commit e7ea21f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/contracts/CouncilArbitrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ contract CouncilArbitrator is ICouncilArbitrator {
getAnswer[_disputeId] = _award;
// TODO: Make sure the access control is correct
IAccessController.AccessControl memory _accessControl =
IAccessController.AccessControl({user: msg.sender, data: bytes('')});
IAccessController.AccessControl({user: address(this), data: bytes('')});

ORACLE.resolveDispute(
_resolutionParams.request, _resolutionParams.response, _resolutionParams.dispute, _accessControl
Expand Down
23 changes: 19 additions & 4 deletions test/integration/arbitrum/IntegrationBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ contract IntegrationBase is Deploy, Test {
uint256 internal _currentEpoch;
uint256 internal _blockNumber;

IAccessController.AccessControl internal _accessControl =
IAccessController.AccessControl({user: address(0), data: bytes('')});
IAccessController.AccessControl internal _accessControl;

function setUp() public virtual override {
vm.createSelectFork(vm.rpcUrl('arbitrum'), _ARBITRUM_SEPOLIA_FORK_BLOCK);
Expand Down Expand Up @@ -65,6 +64,9 @@ contract IntegrationBase is Deploy, Test {

// Set block number
_blockNumber = block.number;

// Configure the access control
_accessControl = IAccessController.AccessControl({user: address(0), data: bytes('')});
}

function _createRequest() internal returns (bytes32 _requestId) {
Expand All @@ -89,9 +91,11 @@ contract IntegrationBase is Deploy, Test {

function _proposeResponse(bytes32 _requestId) internal returns (bytes32 _responseId) {
IOracle.Request memory _requestData = _requests[_requestId];

IOracle.Response memory _responseData = _instantiateResponseData(_requestId);

// Set the caller
_accessControl.user = _proposer;

vm.prank(_proposer);
oracle.proposeResponse(_requestData, _responseData, _accessControl);

Expand All @@ -102,9 +106,11 @@ contract IntegrationBase is Deploy, Test {
function _disputeResponse(bytes32 _requestId, bytes32 _responseId) internal returns (bytes32 _disputeId) {
IOracle.Request memory _requestData = _requests[_requestId];
IOracle.Response memory _responseData = _responses[_responseId];

IOracle.Dispute memory _disputeData = _instantiateDisputeData(_requestId, _responseId);

// Set the caller
_accessControl.user = _disputer;

vm.prank(_disputer);
oracle.disputeResponse(_requestData, _responseData, _disputeData, _accessControl);

Expand Down Expand Up @@ -143,6 +149,9 @@ contract IntegrationBase is Deploy, Test {
IOracle.Response memory _responseData = _responses[_responseId];
IOracle.Dispute memory _disputeData = _disputes[_disputeId];

// Set the caller
_accessControl.user = address(this);

oracle.escalateDispute(_requestData, _responseData, _disputeData, _accessControl);
}

Expand All @@ -151,6 +160,9 @@ contract IntegrationBase is Deploy, Test {
IOracle.Response memory _responseData = _responses[_responseId];
IOracle.Dispute memory _disputeData = _disputes[_disputeId];

// Set the caller
_accessControl.user = address(this);

oracle.resolveDispute(_requestData, _responseData, _disputeData, _accessControl);
}

Expand All @@ -163,6 +175,9 @@ contract IntegrationBase is Deploy, Test {
IOracle.Request memory _requestData = _requests[_requestId];
IOracle.Response memory _responseData = _responses[_responseId];

// Set the caller
_accessControl.user = address(this);

oracle.finalize(_requestData, _responseData, _accessControl);
}

Expand Down
4 changes: 2 additions & 2 deletions test/unit/CouncilArbitrator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ contract CouncilArbitrator_Unit_BaseTest is Test, Helpers {
IOracle public oracle;
IArbitratorModule public arbitratorModule;
IArbitrable public arbitrable;
IAccessController.AccessControl internal _accessControl =
IAccessController.AccessControl({user: address(0), data: bytes('')});
IAccessController.AccessControl internal _accessControl;

event ResolutionStarted(
bytes32 indexed _disputeId, IOracle.Request _request, IOracle.Response _response, IOracle.Dispute _dispute
Expand All @@ -61,6 +60,7 @@ contract CouncilArbitrator_Unit_BaseTest is Test, Helpers {
vm.mockCall(address(arbitratorModule), abi.encodeCall(IValidator.ORACLE, ()), abi.encode(oracle));

councilArbitrator = new MockCouncilArbitrator(arbitratorModule, arbitrable);
_accessControl = IAccessController.AccessControl({user: address(councilArbitrator), data: bytes('')});
}

function _mockGetAnswer(bytes32 _disputeId, IOracle.DisputeStatus _status) internal {
Expand Down

0 comments on commit e7ea21f

Please sign in to comment.