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 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
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
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
57 changes: 57 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,61 @@ 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 _pledgesAgainst,
uint256 _pledgesFor,
address _bondEscalationModule
) public assumeFuzzable(_bondEscalationModule) {
vm.assume(_amount > 0);
vm.assume(_pledgesAgainst > 0 && _pledgesAgainst < 10_000);
vm.assume(_pledgesFor > 0 && _pledgesFor < 10_000);

_amount = bound(_amount, 0, type(uint128).max / (_pledgesAgainst + _pledgesFor));

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

bondEscalationAccounting.forTest_setPledge(_disputeId, token, _amount * (_pledgesAgainst + _pledgesFor));

// 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(_pledgesAgainst)
);

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

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

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

// Check: is the balance of the pledger properly updated?
assertEq(bondEscalationAccounting.balanceOf(pledger, token), _amount * (_pledgesAgainst + _pledgesFor));
// 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