diff --git a/solidity/contracts/extensions/BondEscalationAccounting.sol b/solidity/contracts/extensions/BondEscalationAccounting.sol index 294d57c9..851ce760 100644 --- a/solidity/contracts/extensions/BondEscalationAccounting.sol +++ b/solidity/contracts/extensions/BondEscalationAccounting.sol @@ -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) {} @@ -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) diff --git a/solidity/test/integration/IntegrationBase.sol b/solidity/test/integration/IntegrationBase.sol index 728cbde3..f5ce3e33 100644 --- a/solidity/test/integration/IntegrationBase.sol +++ b/solidity/test/integration/IntegrationBase.sol @@ -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; diff --git a/solidity/test/unit/modules/dispute/BondEscalationAccounting.t.sol b/solidity/test/unit/modules/dispute/BondEscalationAccounting.t.sol index 7030d4ab..3c71e321 100644 --- a/solidity/test/unit/modules/dispute/BondEscalationAccounting.t.sol +++ b/solidity/test/unit/modules/dispute/BondEscalationAccounting.t.sol @@ -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); + } }