Skip to content

Commit

Permalink
Add initial getPreviousOwnerInLinkedList tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnGuilding committed Jun 20, 2024
1 parent 11b8e9a commit 8648e51
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 7 deletions.
19 changes: 19 additions & 0 deletions test/unit/SafeRecoverySubjectHandlerHarness.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

import "forge-std/console2.sol";
import { SafeRecoverySubjectHandler } from "src/handlers/SafeRecoverySubjectHandler.sol";

contract SafeRecoverySubjectHandlerHarness is SafeRecoverySubjectHandler {
constructor() SafeRecoverySubjectHandler() { }

function exposed_getPreviousOwnerInLinkedList(
address safe,
address oldOwner
)
external
returns (address)
{
return getPreviousOwnerInLinkedList(safe, oldOwner);
}
}
6 changes: 3 additions & 3 deletions test/unit/SafeUnitBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ import { Solarray } from "solarray/Solarray.sol";
import { EmailRecoveryManagerHarness } from "./EmailRecoveryManagerHarness.sol";
import { EmailRecoveryManager } from "src/EmailRecoveryManager.sol";
import { EmailRecoveryModule } from "src/modules/EmailRecoveryModule.sol";
import { SafeRecoverySubjectHandler } from "src/handlers/SafeRecoverySubjectHandler.sol";
import { SafeRecoverySubjectHandlerHarness } from "./SafeRecoverySubjectHandlerHarness.sol";
import { EmailRecoveryFactory } from "src/EmailRecoveryFactory.sol";
import { MockRegistry } from "../integration/external/MockRegistry.sol";
import { IntegrationBase } from "../integration/IntegrationBase.t.sol";

abstract contract SafeUnitBase is IntegrationBase {
EmailRecoveryFactory emailRecoveryFactory;
SafeRecoverySubjectHandler safeRecoverySubjectHandler;
SafeRecoverySubjectHandlerHarness safeRecoverySubjectHandler;
EmailRecoveryManager emailRecoveryManager;
address emailRecoveryManagerAddress;
address recoveryModuleAddress;
Expand All @@ -60,7 +60,7 @@ abstract contract SafeUnitBase is IntegrationBase {
super.setUp();

// Deploy handler, manager and module
safeRecoverySubjectHandler = new SafeRecoverySubjectHandler();
safeRecoverySubjectHandler = new SafeRecoverySubjectHandlerHarness();
emailRecoveryFactory = new EmailRecoveryFactory();

emailRecoveryManager = new EmailRecoveryManagerHarness(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,46 @@ import "forge-std/console2.sol";
import { SafeUnitBase } from "../../SafeUnitBase.t.sol";

contract SafeRecoverySubjectHandler_getPreviousOwnerInLinkedList_Test is SafeUnitBase {
address internal constant SENTINEL_OWNERS = address(0x1);

function setUp() public override {
super.setUp();
}

function test_GetPreviousOwnerInLinkedList_RevertWhen_InvalidOldOwner() public view { }
function test_GetPreviousOwnerInLinkedList_RevertWhen_OldOwnerIsSentinel() public view { }
function test_GetPreviousOwnerInLinkedList_RevertWhen_OldOwnerIsZeroAddress() public view { }
function test_GetPreviousOwnerInLinkedList_Succeeds() public view { }
function test_GetPreviousOwnerInLinkedList_InvalidOwner_ReturnsSentinel() public {
address invalidOwner = address(0);

address previousOwner = safeRecoverySubjectHandler.exposed_getPreviousOwnerInLinkedList(
accountAddress, invalidOwner
);

assertEq(previousOwner, SENTINEL_OWNERS);
}

function test_GetPreviousOwnerInLinkedList_OwnerIsSentinel_ReturnsSentinel() public {
address invalidOwner = SENTINEL_OWNERS;

address previousOwner = safeRecoverySubjectHandler.exposed_getPreviousOwnerInLinkedList(
accountAddress, invalidOwner
);

assertEq(previousOwner, SENTINEL_OWNERS);
}

function test_GetPreviousOwnerInLinkedList_RevertWhen_InvalidAccount() public {
address invalidAccount = address(0);

vm.expectRevert();
safeRecoverySubjectHandler.exposed_getPreviousOwnerInLinkedList(invalidAccount, owner);
}

function test_GetPreviousOwnerInLinkedList_Succeeds() public {
address expectedPreviousOwner = address(1);
address previousOwner =
safeRecoverySubjectHandler.exposed_getPreviousOwnerInLinkedList(accountAddress, owner);

assertEq(expectedPreviousOwner, previousOwner);
}

function test_GetPreviousOwnerInLinkedList_SucceedsWithMultipleAccounts() public { }
}

0 comments on commit 8648e51

Please sign in to comment.