Skip to content

Commit

Permalink
Add getAllGuardians getter function
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnGuilding committed Oct 8, 2024
1 parent 9bf6559 commit 3845eb5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/GuardianManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,16 @@ abstract contract GuardianManager is IGuardianManager {
function removeAllGuardians(address account) internal {
guardiansStorage[account].removeAll(guardiansStorage[account].keys());
}

/**
* @notice Gets all guardians associated with an account
* @dev Return an array containing all the keys. O(n) where n <= 32
*
* WARNING: This operation will copy the entire storage to memory, which could
* be quite expensive.
* @param account The address of the account associated with the guardians
*/
function getAllGuardians(address account) external returns (address[] memory) {
return guardiansStorage[account].keys();
}
}
2 changes: 2 additions & 0 deletions src/interfaces/IGuardianManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ interface IGuardianManager {
function removeGuardian(address guardian) external;

function changeThreshold(uint256 threshold) external;

function getAllGuardians(address account) external returns (address[] memory);
}
18 changes: 18 additions & 0 deletions test/unit/GuardianManager/getAllGuardians.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

import { UnitBase } from "../UnitBase.t.sol";

contract GuardianManager_getAllGuardians_Test is UnitBase {
function setUp() public override {
super.setUp();
}

function test_getAllGuardians_Succeeds() public {
address[] memory guardians = emailRecoveryModule.getAllGuardians(accountAddress1);
assertEq(guardians.length, guardians1.length);
assertEq(guardians[0], guardians1[0]);
assertEq(guardians[1], guardians1[1]);
assertEq(guardians[2], guardians1[2]);
}
}

0 comments on commit 3845eb5

Please sign in to comment.