Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adding escalated status check #46

Merged
merged 8 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ contract PrivateERC20ResolutionModule is Module, IPrivateERC20ResolutionModule {
function commitVote(IOracle.Request calldata _request, IOracle.Dispute calldata _dispute, bytes32 _commitment) public {
bytes32 _disputeId = _getId(_dispute);
if (ORACLE.createdAt(_disputeId) == 0) revert PrivateERC20ResolutionModule_NonExistentDispute();
if (ORACLE.disputeStatus(_disputeId) != IOracle.DisputeStatus.None) {
if (ORACLE.disputeStatus(_disputeId) != IOracle.DisputeStatus.Escalated) {
revert PrivateERC20ResolutionModule_AlreadyResolved();
}

Expand Down Expand Up @@ -114,7 +114,7 @@ contract PrivateERC20ResolutionModule is Module, IPrivateERC20ResolutionModule {
IOracle.Dispute calldata _dispute
) external onlyOracle {
if (ORACLE.createdAt(_disputeId) == 0) revert PrivateERC20ResolutionModule_NonExistentDispute();
if (ORACLE.disputeStatus(_disputeId) != IOracle.DisputeStatus.None) {
if (ORACLE.disputeStatus(_disputeId) != IOracle.DisputeStatus.Escalated) {
revert PrivateERC20ResolutionModule_AlreadyResolved();
0xJabberwock marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ contract BaseTest is Test, Helpers {

_mockAndExpect(address(oracle), abi.encodeCall(IOracle.createdAt, (_disputeId)), abi.encode(1));
_mockAndExpect(
address(oracle), abi.encodeCall(IOracle.disputeStatus, (_disputeId)), abi.encode(IOracle.DisputeStatus.None)
address(oracle),
abi.encodeCall(IOracle.disputeStatus, (_disputeId)),
abi.encode(IOracle.DisputeStatus.Escalated)
);
module.commitVote(_request, _dispute, _commitment);

Expand Down Expand Up @@ -196,7 +198,7 @@ contract PrivateERC20ResolutionModule_Unit_CommitVote is BaseTest {
_mockAndExpect(address(oracle), abi.encodeCall(IOracle.createdAt, (_disputeId)), abi.encode(1));
// Mock and expect IOracle.disputeStatus to be called
_mockAndExpect(
address(oracle), abi.encodeCall(IOracle.disputeStatus, (_disputeId)), abi.encode(IOracle.DisputeStatus.None)
address(oracle), abi.encodeCall(IOracle.disputeStatus, (_disputeId)), abi.encode(IOracle.DisputeStatus.Escalated)
);

// Check: does it revert if no commitment is given?
Expand Down Expand Up @@ -239,6 +241,68 @@ contract PrivateERC20ResolutionModule_Unit_CommitVote is BaseTest {
module.commitVote(mockRequest, mockDispute, _commitment);
}

/**
* @notice Test that `commitVote` reverts if called with `_disputeId` of an already active dispute.
*/
function test_revertIfActive(bytes32 _requestId, bytes32 _commitment) public {
// Computer proper IDs
mockDispute.requestId = _requestId;
bytes32 _disputeId = _getId(mockDispute);

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

// Check: does it revert if the dispute is already resolved?
vm.expectRevert(IPrivateERC20ResolutionModule.PrivateERC20ResolutionModule_AlreadyResolved.selector);
module.commitVote(mockRequest, mockDispute, _commitment);
}

/**
* @notice Test that `commitVote` reverts if called with `_disputeId` of a dispute with no resolution.
*/
function test_revertIfNoResolution(bytes32 _requestId, bytes32 _commitment) public {
// Computer proper IDs
mockDispute.requestId = _requestId;
bytes32 _disputeId = _getId(mockDispute);

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

// Check: does it revert if the dispute is already resolved?
vm.expectRevert(IPrivateERC20ResolutionModule.PrivateERC20ResolutionModule_AlreadyResolved.selector);
module.commitVote(mockRequest, mockDispute, _commitment);
}

/**
* @notice Test that `commitVote` reverts if called with `_disputeId` of a dispute that has already been won.
*/
function test_revertIfWon(bytes32 _requestId, bytes32 _commitment) public {
// Computer proper IDs
mockDispute.requestId = _requestId;
bytes32 _disputeId = _getId(mockDispute);

// Mock and expect IOracle.createdAt to be called
_mockAndExpect(address(oracle), abi.encodeCall(IOracle.createdAt, (_disputeId)), abi.encode(1));
// 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 is already resolved?
vm.expectRevert(IPrivateERC20ResolutionModule.PrivateERC20ResolutionModule_AlreadyResolved.selector);
module.commitVote(mockRequest, mockDispute, _commitment);
}

/**
* @notice Test that `commitVote` reverts if called with `_disputeId` of an already resolved dispute.
*/
Expand Down Expand Up @@ -271,7 +335,7 @@ contract PrivateERC20ResolutionModule_Unit_CommitVote is BaseTest {
_mockAndExpect(address(oracle), abi.encodeCall(IOracle.createdAt, (_disputeId)), abi.encode(1));
// Mock and expect IOracle.disputeStatus to be called
_mockAndExpect(
address(oracle), abi.encodeCall(IOracle.disputeStatus, (_disputeId)), abi.encode(IOracle.DisputeStatus.None)
address(oracle), abi.encodeCall(IOracle.disputeStatus, (_disputeId)), abi.encode(IOracle.DisputeStatus.Escalated)
);

// Check: reverts if dispute is not escalated? == no escalation data
Expand Down Expand Up @@ -311,7 +375,7 @@ contract PrivateERC20ResolutionModule_Unit_CommitVote is BaseTest {
_mockAndExpect(address(oracle), abi.encodeCall(IOracle.createdAt, (_disputeId)), abi.encode(1));
// Mock and expect IOracle.disputeStatus to be called
_mockAndExpect(
address(oracle), abi.encodeCall(IOracle.disputeStatus, (_disputeId)), abi.encode(IOracle.DisputeStatus.None)
address(oracle), abi.encodeCall(IOracle.disputeStatus, (_disputeId)), abi.encode(IOracle.DisputeStatus.Escalated)
);

// Check: does it revert if the committing phase is over?
Expand Down Expand Up @@ -545,7 +609,7 @@ contract PrivateERC20ResolutionModule_Unit_ResolveDispute is BaseTest {

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

// Check: is the event emitted?
Expand Down Expand Up @@ -588,7 +652,7 @@ contract PrivateERC20ResolutionModule_Unit_ResolveDispute is BaseTest {
_mockAndExpect(address(oracle), abi.encodeCall(IOracle.createdAt, (_disputeId)), abi.encode(1));
// Mock and expect IOracle.disputeStatus to be called
_mockAndExpect(
address(oracle), abi.encodeCall(IOracle.disputeStatus, (_disputeId)), abi.encode(IOracle.DisputeStatus.None)
address(oracle), abi.encodeCall(IOracle.disputeStatus, (_disputeId)), abi.encode(IOracle.DisputeStatus.Escalated)
);

// Jump to timestamp
Expand All @@ -606,4 +670,134 @@ contract PrivateERC20ResolutionModule_Unit_ResolveDispute is BaseTest {
module.resolveDispute(_disputeId, mockRequest, mockResponse, mockDispute);
}
}

function test_revertIfActive() public {
// Set request data
mockRequest.resolutionModuleData = abi.encode(
IPrivateERC20ResolutionModule.RequestParameters({
accountingExtension: IAccountingExtension(makeAddr('AccountingExtension')),
votingToken: token,
minVotesForQuorum: 1,
committingTimeWindow: 500_000,
revealingTimeWindow: 1_000_000
})
);

// Compute proper ids
bytes32 _requestId = _getId(mockRequest);
mockDispute.requestId = _requestId;
bytes32 _disputeId = _getId(mockDispute);

module.forTest_setStartTime(_disputeId, 1);

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

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

function test_revertIfWon() public {
// Set request data
mockRequest.resolutionModuleData = abi.encode(
IPrivateERC20ResolutionModule.RequestParameters({
accountingExtension: IAccountingExtension(makeAddr('AccountingExtension')),
votingToken: token,
minVotesForQuorum: 1,
committingTimeWindow: 500_000,
revealingTimeWindow: 1_000_000
})
);

// Compute proper ids
bytes32 _requestId = _getId(mockRequest);
mockDispute.requestId = _requestId;
bytes32 _disputeId = _getId(mockDispute);

module.forTest_setStartTime(_disputeId, 1);

// Mock and expect IOracle.createdAt to be called
_mockAndExpect(address(oracle), abi.encodeCall(IOracle.createdAt, (_disputeId)), abi.encode(1));
// 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 is already resolved?
vm.expectRevert(IPrivateERC20ResolutionModule.PrivateERC20ResolutionModule_AlreadyResolved.selector);
vm.prank(address(oracle));
module.resolveDispute(_disputeId, mockRequest, mockResponse, mockDispute);
}

function test_revertIfLost() public {
// Set request data
mockRequest.resolutionModuleData = abi.encode(
IPrivateERC20ResolutionModule.RequestParameters({
accountingExtension: IAccountingExtension(makeAddr('AccountingExtension')),
votingToken: token,
minVotesForQuorum: 1,
committingTimeWindow: 500_000,
revealingTimeWindow: 1_000_000
})
);

// Compute proper ids
bytes32 _requestId = _getId(mockRequest);
mockDispute.requestId = _requestId;
bytes32 _disputeId = _getId(mockDispute);

module.forTest_setStartTime(_disputeId, 1);

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

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

function test_revertIfNonResolve() public {
// Set request data
mockRequest.resolutionModuleData = abi.encode(
IPrivateERC20ResolutionModule.RequestParameters({
accountingExtension: IAccountingExtension(makeAddr('AccountingExtension')),
votingToken: token,
minVotesForQuorum: 1,
committingTimeWindow: 500_000,
revealingTimeWindow: 1_000_000
})
);

// Compute proper ids
bytes32 _requestId = _getId(mockRequest);
mockDispute.requestId = _requestId;
bytes32 _disputeId = _getId(mockDispute);

module.forTest_setStartTime(_disputeId, 1);

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

// Check: does it revert if the dispute is already resolved?
vm.expectRevert(IPrivateERC20ResolutionModule.PrivateERC20ResolutionModule_AlreadyResolved.selector);
vm.prank(address(oracle));
module.resolveDispute(_disputeId, mockRequest, mockResponse, mockDispute);
}
}
Loading