-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fuzz test getPreviousOwnerInLinkedList
- Loading branch information
1 parent
a8f6de4
commit 0602c37
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
test/unit/handlers/SafeRecoveryCommandHandler/fuzz/getPreviousOwnerInLinkedList.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.25; | ||
|
||
import { SafeNativeIntegrationBase } from | ||
"../../../../integration/SafeRecovery/SafeNativeIntegrationBase.t.sol"; | ||
import { SafeRecoveryCommandHandlerHarness } from "../../../SafeRecoveryCommandHandlerHarness.sol"; | ||
|
||
interface ISafe { | ||
function addOwnerWithThreshold(address owner, uint256 _threshold) external; | ||
function getOwners() external view returns (address[] memory); | ||
function isOwner(address owner) external view returns (bool); | ||
} | ||
|
||
contract SafeRecoveryCommandHandler_getPreviousOwnerInLinkedList_Fuzz_Test is | ||
SafeNativeIntegrationBase | ||
{ | ||
address internal constant SENTINEL_OWNERS = address(0x1); | ||
|
||
SafeRecoveryCommandHandlerHarness public safeRecoveryCommandHandler; | ||
|
||
function setUp() public override { | ||
super.setUp(); | ||
safeRecoveryCommandHandler = new SafeRecoveryCommandHandlerHarness(); | ||
} | ||
|
||
function testFuzz_GetPreviousOwnerInLinkedList_Succeeds(address[] memory owners) public { | ||
skipIfNotSafeAccountType(); | ||
|
||
vm.startPrank(accountAddress1); | ||
for (uint256 i = 0; i < owners.length; i++) { | ||
if (ISafe(accountAddress1).isOwner(owners[i])) { | ||
break; | ||
} | ||
vm.assume(owners[i] != address(0)); | ||
vm.assume(owners[i] != address(1)); | ||
vm.assume(owners[i] != accountAddress1); | ||
ISafe(accountAddress1).addOwnerWithThreshold(owners[i], 1); | ||
} | ||
vm.stopPrank(); | ||
|
||
address[] memory ownersArr = ISafe(accountAddress1).getOwners(); | ||
|
||
address expectedPreviousOwner; | ||
for (uint256 i = 1; i < ownersArr.length; i++) { | ||
address previousOwner = safeRecoveryCommandHandler.exposed_getPreviousOwnerInLinkedList( | ||
accountAddress1, ownersArr[i] | ||
); | ||
if (i == 0) { | ||
assertEq(previousOwner, SENTINEL_OWNERS); | ||
} | ||
|
||
uint256 prevOwnerIndex = i - 1; | ||
expectedPreviousOwner = ownersArr[prevOwnerIndex]; | ||
|
||
assertEq(expectedPreviousOwner, previousOwner); | ||
} | ||
} | ||
} |