From 8648e51627537f8edef6d2f31b6625ab606c93f8 Mon Sep 17 00:00:00 2001 From: JohnGuilding Date: Thu, 20 Jun 2024 17:45:34 +0100 Subject: [PATCH] Add initial getPreviousOwnerInLinkedList tests --- .../SafeRecoverySubjectHandlerHarness.sol | 19 +++++++++ test/unit/SafeUnitBase.t.sol | 6 +-- .../getPreviousOwnerInLinkedList.t.sol | 42 +++++++++++++++++-- 3 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 test/unit/SafeRecoverySubjectHandlerHarness.sol diff --git a/test/unit/SafeRecoverySubjectHandlerHarness.sol b/test/unit/SafeRecoverySubjectHandlerHarness.sol new file mode 100644 index 00000000..a7177eca --- /dev/null +++ b/test/unit/SafeRecoverySubjectHandlerHarness.sol @@ -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); + } +} diff --git a/test/unit/SafeUnitBase.t.sol b/test/unit/SafeUnitBase.t.sol index 68aec676..a8ff776b 100644 --- a/test/unit/SafeUnitBase.t.sol +++ b/test/unit/SafeUnitBase.t.sol @@ -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; @@ -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( diff --git a/test/unit/handlers/SafeRecoverySubjectHandler/getPreviousOwnerInLinkedList.t.sol b/test/unit/handlers/SafeRecoverySubjectHandler/getPreviousOwnerInLinkedList.t.sol index 458b2d0c..44f41dfd 100644 --- a/test/unit/handlers/SafeRecoverySubjectHandler/getPreviousOwnerInLinkedList.t.sol +++ b/test/unit/handlers/SafeRecoverySubjectHandler/getPreviousOwnerInLinkedList.t.sol @@ -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 { } }