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: not pledged #47

Merged
merged 9 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
5 changes: 3 additions & 2 deletions solidity/contracts/extensions/BondEscalationAccounting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract BondEscalationAccounting is AccountingExtension, IBondEscalationAccount
mapping(bytes32 _disputeId => EscalationResult _result) public escalationResults;

/// @inheritdoc IBondEscalationAccounting
mapping(bytes32 _requestId => mapping(address _pledger => bool)) public pledgerClaimed;
mapping(bytes32 _requestId => mapping(address _pledger => bool _claimed)) public pledgerClaimed;

constructor(IOracle _oracle) AccountingExtension(_oracle) {}

Expand Down Expand Up @@ -84,7 +84,8 @@ contract BondEscalationAccounting is AccountingExtension, IBondEscalationAccount
uint256 _numberOfPledges;

if (_status == IOracle.DisputeStatus.NoResolution) {
_numberOfPledges = 1;
_numberOfPledges = _result.bondEscalationModule.pledgesForDispute(_requestId, _pledger)
+ _result.bondEscalationModule.pledgesAgainstDispute(_requestId, _pledger);
} else {
_numberOfPledges = _status == IOracle.DisputeStatus.Won
? _result.bondEscalationModule.pledgesForDispute(_requestId, _pledger)
Expand Down
4 changes: 2 additions & 2 deletions solidity/test/integration/BondEscalation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ contract Integration_BondEscalation is IntegrationBase {

// Step 10: Participants claim their rewards
// Test: The requester has paid out the reward and is left with no balance
_bondEscalationAccounting.claimEscalationReward(_disputeId, requester);
assertEq(_bondEscalationAccounting.balanceOf(requester, usdc), 0, 'Mismatch: Requester balance');
// _bondEscalationAccounting.claimEscalationReward(_disputeId, requester);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mistake

// assertEq(_bondEscalationAccounting.balanceOf(requester, usdc), 0, 'Mismatch: Requester balance');

// Test: The proposer has lost his pledge and bond
_bondEscalationAccounting.claimEscalationReward(_disputeId, proposer);
Expand Down
2 changes: 1 addition & 1 deletion solidity/test/integration/IntegrationBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {TestConstants} from '../utils/TestConstants.sol';
// solhint-enable no-unused-import

contract IntegrationBase is DSTestPlus, TestConstants, Helpers {
uint256 public constant FORK_BLOCK = 100_000_000;
uint256 public constant FORK_BLOCK = 122_612_760;

uint256 internal _initialBalance = 100_000 ether;

Expand Down
55 changes: 55 additions & 0 deletions solidity/test/unit/modules/dispute/BondEscalationAccounting.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -533,4 +533,59 @@ contract BondEscalationAccounting_Unit_ClaimEscalationReward is BaseTest {
// Check: are the pledges updated?
assertEq(bondEscalationAccounting.pledges(_disputeId, token), 0);
}

function test_noResolution(
bytes32 _disputeId,
bytes32 _requestId,
uint256 _amount,
uint256 _pledges,
address _bondEscalationModule
) public assumeFuzzable(_bondEscalationModule) {
vm.assume(_amount > 0);
vm.assume(_pledges > 0 && _pledges < 30);

_amount = bound(_amount, 0, type(uint128).max / _pledges);

bondEscalationAccounting.forTest_setEscalationResult(
_disputeId, _requestId, token, _amount, IBondEscalationModule(_bondEscalationModule)
);

bondEscalationAccounting.forTest_setPledge(_disputeId, token, _amount * _pledges * 2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a different number of pledges for and against so we are sure we are adding both numbers correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


// Mock and expect to call the oracle getting the dispute status
_mockAndExpect(
address(oracle),
abi.encodeCall(IOracle.disputeStatus, (_disputeId)),
abi.encode(IOracle.DisputeStatus.NoResolution)
);

// Mock and expect to call the escalation module asking for pledges
_mockAndExpect(
_bondEscalationModule,
abi.encodeCall(IBondEscalationModule.pledgesAgainstDispute, (_requestId, pledger)),
abi.encode(_pledges)
);

// Mock and expect the call to the escalation module asking for pledges
_mockAndExpect(
_bondEscalationModule,
abi.encodeCall(IBondEscalationModule.pledgesForDispute, (_requestId, pledger)),
abi.encode(_pledges)
);

// Check: is the event emitted?
vm.expectEmit(true, true, true, true, address(bondEscalationAccounting));
emit EscalationRewardClaimed(_requestId, _disputeId, pledger, token, _amount * _pledges * 2);

vm.prank(_bondEscalationModule);
bondEscalationAccounting.claimEscalationReward(_disputeId, pledger);

// Check: is the balance of the pledger properly updated?
assertEq(bondEscalationAccounting.balanceOf(pledger, token), _amount * _pledges * 2);
// Check: is the reward marked as claimed for the pledger?
assertTrue(bondEscalationAccounting.pledgerClaimed(_requestId, pledger));

// Check: are the pledges updated?
assertEq(bondEscalationAccounting.pledges(_disputeId, token), 0);
}
}
Loading