Skip to content

Commit

Permalink
feat: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ashitakah committed Jul 24, 2024
1 parent b4f76dc commit 5161792
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
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);
assertEq(_bondEscalationAccounting.balanceOf(requester, usdc), 0, 'Mismatch: Requester balance');

// Test: The proposer has lost his pledge and bond
_bondEscalationAccounting.claimEscalationReward(_disputeId, proposer);
Expand Down
18 changes: 10 additions & 8 deletions solidity/test/unit/modules/dispute/BondEscalationAccounting.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -538,19 +538,21 @@ contract BondEscalationAccounting_Unit_ClaimEscalationReward is BaseTest {
bytes32 _disputeId,
bytes32 _requestId,
uint256 _amount,
uint256 _pledges,
uint256 _pledgesAgainst,
uint256 _pledgesFor,
address _bondEscalationModule
) public assumeFuzzable(_bondEscalationModule) {
vm.assume(_amount > 0);
vm.assume(_pledges > 0 && _pledges < 30);
vm.assume(_pledgesAgainst > 0 && _pledgesAgainst < 10_000);
vm.assume(_pledgesFor > 0 && _pledgesFor < 10_000);

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

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

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

// Mock and expect to call the oracle getting the dispute status
_mockAndExpect(
Expand All @@ -563,25 +565,25 @@ contract BondEscalationAccounting_Unit_ClaimEscalationReward is BaseTest {
_mockAndExpect(
_bondEscalationModule,
abi.encodeCall(IBondEscalationModule.pledgesAgainstDispute, (_requestId, pledger)),
abi.encode(_pledges)
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(_pledges)
abi.encode(_pledgesFor)
);

// Check: is the event emitted?
vm.expectEmit(true, true, true, true, address(bondEscalationAccounting));
emit EscalationRewardClaimed(_requestId, _disputeId, pledger, token, _amount * _pledges * 2);
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 * _pledges * 2);
assertEq(bondEscalationAccounting.balanceOf(pledger, token), _amount * (_pledgesAgainst + _pledgesFor));
// Check: is the reward marked as claimed for the pledger?
assertTrue(bondEscalationAccounting.pledgerClaimed(_requestId, pledger));

Expand Down

0 comments on commit 5161792

Please sign in to comment.