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: use bound instead of vm.assume #53

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Changes from 2 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
140 changes: 118 additions & 22 deletions test/unit/HorizonAccountingExtension.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -564,20 +564,23 @@ contract HorizonAccountingExtension_Unit_OnSettleBondEscalation is HorizonAccoun

contract HorizonAccountingExtension_Unit_ClaimEscalationReward is HorizonAccountingExtension_Unit_BaseTest {
modifier happyPath(uint256 _pledgesForDispute, uint256 _pledgesAgainstDispute, uint256 _bondSize, uint256 _amount) {
vm.assume(_pledgesForDispute > 0 && _pledgesForDispute < type(uint64).max);
vm.assume(_pledgesAgainstDispute > 0 && _pledgesAgainstDispute < type(uint64).max);
vm.assume(_amount > type(uint16).max && _amount < type(uint64).max);
vm.assume(_bondSize > 0 && _bondSize < type(uint16).max);
_setUpHappyPath(_pledgesForDispute, _pledgesAgainstDispute, _bondSize, _amount);
_;
}

function _setUpHappyPath(
uint256 _pledgesForDispute,
uint256 _pledgesAgainstDispute,
uint256 _bondSize,
uint256 _amount
) internal {
horizonAccountingExtension.setDisputeBalanceForTest(
_mockDisputeId, _amount * (_pledgesForDispute + _pledgesAgainstDispute)
);

horizonAccountingExtension.setEscalationResultForTest(
_mockDisputeId, _mockRequestId, _amount, _bondSize, bondEscalationModule
);

_;
}

function test_revertIfNoEscalationResult(address _pledger) public {
Expand All @@ -591,7 +594,15 @@ contract HorizonAccountingExtension_Unit_ClaimEscalationReward is HorizonAccount
uint256 _pledgesAgainstDispute,
uint256 _bondSize,
uint256 _amount
) public happyPath(_pledgesForDispute, _pledgesAgainstDispute, _bondSize, _amount) {
) public {
// bound input parameters
_pledgesForDispute = bound(_pledgesForDispute, 1, type(uint64).max);
_pledgesAgainstDispute = bound(_pledgesAgainstDispute, 1, type(uint64).max);
_amount = bound(_amount, type(uint16).max, type(uint64).max);
_bondSize = bound(_bondSize, 1, type(uint16).max);

_setUpHappyPath(_pledgesForDispute, _pledgesAgainstDispute, _bondSize, _amount);

horizonAccountingExtension.setPledgerClaimedForTest(_mockRequestId, _pledger, true);

vm.expectRevert(IHorizonAccountingExtension.HorizonAccountingExtension_AlreadyClaimed.selector);
Expand All @@ -604,7 +615,15 @@ contract HorizonAccountingExtension_Unit_ClaimEscalationReward is HorizonAccount
uint256 _pledgesAgainstDispute,
uint256 _bondSize,
uint256 _amount
) public happyPath(_pledgesForDispute, _pledgesAgainstDispute, _bondSize, _amount) {
) public {
// bound input parameters
_pledgesForDispute = bound(_pledgesForDispute, 1, type(uint64).max);
_pledgesAgainstDispute = bound(_pledgesAgainstDispute, 1, type(uint64).max);
_amount = bound(_amount, type(uint16).max, type(uint64).max);
_bondSize = bound(_bondSize, 1, type(uint16).max);

_setUpHappyPath(_pledgesForDispute, _pledgesAgainstDispute, _bondSize, _amount);

// Mock and expect the call to oracle checking the dispute status
_mockAndExpect(
address(oracle),
Expand Down Expand Up @@ -634,7 +653,15 @@ contract HorizonAccountingExtension_Unit_ClaimEscalationReward is HorizonAccount
uint256 _pledgesAgainstDispute,
uint256 _bondSize,
uint256 _amount
) public happyPath(_pledgesForDispute, _pledgesAgainstDispute, _bondSize, _amount) {
) public {
// bound input parameters
_pledgesForDispute = bound(_pledgesForDispute, 1, type(uint64).max);
_pledgesAgainstDispute = bound(_pledgesAgainstDispute, 1, type(uint64).max);
_amount = bound(_amount, type(uint16).max, type(uint64).max);
_bondSize = bound(_bondSize, 1, type(uint16).max);

_setUpHappyPath(_pledgesForDispute, _pledgesAgainstDispute, _bondSize, _amount);

// Mock and expect the call to oracle checking the dispute status
_mockAndExpect(
address(oracle),
Expand Down Expand Up @@ -687,7 +714,15 @@ contract HorizonAccountingExtension_Unit_ClaimEscalationReward is HorizonAccount
uint256 _pledgesAgainstDispute,
uint256 _bondSize,
uint256 _amount
) public happyPath(_pledgesForDispute, _pledgesAgainstDispute, _bondSize, _amount) {
) public {
// bound input parameters
_pledgesForDispute = bound(_pledgesForDispute, 1, type(uint64).max);
_pledgesAgainstDispute = bound(_pledgesAgainstDispute, 1, type(uint64).max);
_amount = bound(_amount, type(uint16).max, type(uint64).max);
_bondSize = bound(_bondSize, 1, type(uint16).max);

_setUpHappyPath(_pledgesForDispute, _pledgesAgainstDispute, _bondSize, _amount);

// Mock and expect the call to oracle checking the dispute status
_mockAndExpect(
address(oracle),
Expand Down Expand Up @@ -734,7 +769,15 @@ contract HorizonAccountingExtension_Unit_ClaimEscalationReward is HorizonAccount
uint256 _pledgesAgainstDispute,
uint256 _bondSize,
uint256 _amount
) public happyPath(_pledgesForDispute, _pledgesAgainstDispute, _bondSize, _amount) {
) public {
// bound input parameters
_pledgesForDispute = bound(_pledgesForDispute, 1, type(uint64).max);
_pledgesAgainstDispute = bound(_pledgesAgainstDispute, 1, type(uint64).max);
_amount = bound(_amount, type(uint16).max, type(uint64).max);
_bondSize = bound(_bondSize, 1, type(uint16).max);

_setUpHappyPath(_pledgesForDispute, _pledgesAgainstDispute, _bondSize, _amount);

// Mock and expect the call to oracle checking the dispute status
_mockAndExpect(
address(oracle),
Expand Down Expand Up @@ -782,10 +825,18 @@ contract HorizonAccountingExtension_Unit_ClaimEscalationReward is HorizonAccount
uint256 _pledgesAgainstDispute,
uint256 _bondSize,
uint256 _amount
) public happyPath(_pledgesForDispute, _pledgesAgainstDispute, _bondSize, _amount) {
) public {
vm.assume(_pledger != _slashedUser);
vm.assume(_slashedUser != _notSlashedUser);

// bound input parameters
_pledgesForDispute = bound(_pledgesForDispute, 1, type(uint64).max);
_pledgesAgainstDispute = bound(_pledgesAgainstDispute, 1, type(uint64).max);
_amount = bound(_amount, type(uint16).max, type(uint64).max);
_bondSize = bound(_bondSize, 1, type(uint16).max);

_setUpHappyPath(_pledgesForDispute, _pledgesAgainstDispute, _bondSize, _amount);

_pledgesAgainstDispute = _pledgesForDispute * _amount / _bondSize + 1;

// Mock and expect the call to oracle checking the dispute status
Expand Down Expand Up @@ -853,9 +904,16 @@ contract HorizonAccountingExtension_Unit_ClaimEscalationReward is HorizonAccount
uint256 _pledgesAgainstDispute,
uint256 _bondSize,
uint256 _amount
) public happyPath(_pledgesForDispute, _pledgesAgainstDispute, _bondSize, _amount) {
) public {
vm.assume(_pledger != _slashedUser);
vm.assume(_slashedUser != _notSlashedUser);
// bound input parameters
_pledgesForDispute = bound(_pledgesForDispute, 1, type(uint64).max);
_pledgesAgainstDispute = bound(_pledgesAgainstDispute, 1, type(uint64).max);
_amount = bound(_amount, type(uint16).max, type(uint64).max);
_bondSize = bound(_bondSize, 1, type(uint16).max);

_setUpHappyPath(_pledgesForDispute, _pledgesAgainstDispute, _bondSize, _amount);

_pledgesForDispute = _pledgesAgainstDispute * _amount / _bondSize + 1;

Expand Down Expand Up @@ -1478,11 +1536,18 @@ contract HorizonAccountingExtension_Unit_Slash is HorizonAccountingExtension_Uni
uint256 _pledgesForDispute,
uint256 _bondSize
) {
vm.assume(_usersToSlash > 0 && _usersToSlash < type(uint16).max);
vm.assume(_maxUsersToCheck > 0 && _maxUsersToCheck < type(uint16).max);
_setUpHappyPath(_usersToSlash, _maxUsersToCheck, _users, _pledgesForDispute, _bondSize);
_;
}

function _setUpHappyPath(
uint256 _usersToSlash,
uint256 _maxUsersToCheck,
address[] memory _users,
uint256 _pledgesForDispute,
uint256 _bondSize
) internal {
vm.assume(_users.length > 0 && _users.length < type(uint16).max);
vm.assume(_pledgesForDispute > 0 && _pledgesForDispute < type(uint16).max);
vm.assume(_bondSize > 0 && _bondSize < type(uint16).max);

uint256 _slashAmount = _pledgesForDispute * _bondSize;

Expand All @@ -1499,7 +1564,6 @@ contract HorizonAccountingExtension_Unit_Slash is HorizonAccountingExtension_Uni
horizonAccountingExtension.setEscalationResultForTest(
_mockDisputeId, _mockRequestId, 1, _bondSize, bondEscalationModule
);
_;
}

function test_revertIfNoEscalationResult(uint256 _usersToSlash, uint256 _maxUsersToCheck, address _pledger) public {
Expand All @@ -1518,7 +1582,15 @@ contract HorizonAccountingExtension_Unit_Slash is HorizonAccountingExtension_Uni
address[] memory _users,
uint256 _pledgesAgainstDispute,
uint256 _bondSize
) public happyPath(_usersToSlash, _maxUsersToCheck, _users, _pledgesAgainstDispute, _bondSize) {
) public {
// bound input parameters
_usersToSlash = bound(_usersToSlash, 1, type(uint16).max);
_maxUsersToCheck = bound(_maxUsersToCheck, 1, type(uint16).max);
_pledgesAgainstDispute = bound(_pledgesAgainstDispute, 1, type(uint64).max);
_bondSize = bound(_bondSize, 1, type(uint16).max);

_setUpHappyPath(_usersToSlash, _maxUsersToCheck, _users, _pledgesAgainstDispute, _bondSize);

horizonAccountingExtension.setBondedTokensForTest(_cleanPledgers.at(0), 0);

// Mock and expect the call to oracle checking the dispute status
Expand Down Expand Up @@ -1554,7 +1626,15 @@ contract HorizonAccountingExtension_Unit_Slash is HorizonAccountingExtension_Uni
address[] memory _users,
uint256 _pledgesAgainstDispute,
uint256 _bondSize
) public happyPath(_usersToSlash, _maxUsersToCheck, _users, _pledgesAgainstDispute, _bondSize) {
) public {
// bound input parameters
_usersToSlash = bound(_usersToSlash, 1, type(uint16).max);
_maxUsersToCheck = bound(_maxUsersToCheck, 1, type(uint16).max);
_pledgesAgainstDispute = bound(_pledgesAgainstDispute, 1, type(uint64).max);
_bondSize = bound(_bondSize, 1, type(uint16).max);

_setUpHappyPath(_usersToSlash, _maxUsersToCheck, _users, _pledgesAgainstDispute, _bondSize);

// Mock and expect the call to oracle checking the dispute status
_mockAndExpect(
address(oracle),
Expand Down Expand Up @@ -1599,7 +1679,15 @@ contract HorizonAccountingExtension_Unit_Slash is HorizonAccountingExtension_Uni
address[] memory _users,
uint256 _pledgesForDispute,
uint256 _bondSize
) public happyPath(_usersToSlash, _maxUsersToCheck, _users, _pledgesForDispute, _bondSize) {
) public {
// bound input parameters
_usersToSlash = bound(_usersToSlash, 1, type(uint16).max);
_maxUsersToCheck = bound(_maxUsersToCheck, 1, type(uint16).max);
_pledgesForDispute = bound(_pledgesForDispute, 1, type(uint64).max);
_bondSize = bound(_bondSize, 1, type(uint16).max);

_setUpHappyPath(_usersToSlash, _maxUsersToCheck, _users, _pledgesForDispute, _bondSize);

// Mock and expect the call to oracle checking the dispute status
_mockAndExpect(
address(oracle),
Expand Down Expand Up @@ -1644,7 +1732,15 @@ contract HorizonAccountingExtension_Unit_Slash is HorizonAccountingExtension_Uni
address[] memory _users,
uint256 _pledgesForDispute,
uint256 _bondSize
) public happyPath(_usersToSlash, _maxUsersToCheck, _users, _pledgesForDispute, _bondSize) {
) public {
// bound input parameters
_usersToSlash = bound(_usersToSlash, 1, type(uint16).max);
_maxUsersToCheck = bound(_maxUsersToCheck, 1, type(uint16).max);
_pledgesForDispute = bound(_pledgesForDispute, 1, type(uint64).max);
_bondSize = bound(_bondSize, 1, type(uint16).max);

_setUpHappyPath(_usersToSlash, _maxUsersToCheck, _users, _pledgesForDispute, _bondSize);

// Mock and expect the call to oracle checking the dispute status
_mockAndExpect(
address(oracle),
Expand Down
Loading