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

Add test cases for EnumerableGuardianMap. #6

Merged
merged 7 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion test/integration/IntegrationBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ abstract contract IntegrationBase is RhinestoneModuleKit, Test {
AccountInstance instance;
address accountAddress;
address owner;
address anotherOwner;
address newOwner;

// recovery config
Expand Down Expand Up @@ -66,9 +67,11 @@ abstract contract IntegrationBase is RhinestoneModuleKit, Test {

// create owners
owner = vm.createWallet("owner").addr;
anotherOwner = vm.createWallet("anotherOwner").addr;
newOwner = vm.createWallet("newOwner").addr;
address[] memory owners = new address[](1);
address[] memory owners = new address[](2);
owners[0] = owner;
owners[1] = anotherOwner;

// Deploy and fund the account
instance = makeAccountInstance("account");
Expand Down
11 changes: 9 additions & 2 deletions test/unit/EmailRecoveryFactory/deployModuleAndManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ pragma solidity ^0.8.25;

import "forge-std/console2.sol";
import { UnitBase } from "../UnitBase.t.sol";
import { EmailRecoveryFactory } from "../../../src/EmailRecoveryFactory.sol";

contract EmailRecoveryManager_deployModuleAndManager_Test is UnitBase {
contract EmailRecoveryFactory_deployModuleAndManager_Test is UnitBase {
function setUp() public override {
super.setUp();
emailRecoveryFactory = new EmailRecoveryFactory();
}

function test_DeployModuleAndManager_Succeeds() public {
// TODO: test
emailRecoveryFactory.deployModuleAndManager(
address(verifier),
address(dkimRegistry),
address(emailAuthImpl),
address(emailRecoveryHandler)
);
}
}
23 changes: 18 additions & 5 deletions test/unit/EmailRecoveryManager/getGuardian.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,30 @@
pragma solidity ^0.8.25;

import "forge-std/console2.sol";
import { IEmailRecoveryManager } from "src/interfaces/IEmailRecoveryManager.sol";
import { EmailRecoveryModule } from "src/modules/EmailRecoveryModule.sol";
import { GuardianStorage, GuardianStatus } from "src/libraries/EnumerableGuardianMap.sol";
import { UnitBase } from "../UnitBase.t.sol";
import {IEmailRecoveryManager} from "src/interfaces/IEmailRecoveryManager.sol";
import {EmailRecoveryModule} from "src/modules/EmailRecoveryModule.sol";
import {GuardianStorage, GuardianStatus} from "src/libraries/EnumerableGuardianMap.sol";
import {UnitBase} from "../UnitBase.t.sol";

contract EmailRecoveryManager_getGuardian_Test is UnitBase {
address newGuardian = address(1);
uint256 newGuardianWeight = 1;

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

vm.startPrank(accountAddress);
emailRecoveryManager.addGuardian(newGuardian, newGuardianWeight);
vm.stopPrank();
}

function test_GetGuardian_Succeeds() public {
// TODO: test
GuardianStorage memory guardianStorage = emailRecoveryManager
.getGuardian(accountAddress, newGuardian);
assertEq(
uint256(guardianStorage.status),
uint256(GuardianStatus.REQUESTED)
);
assertEq(guardianStorage.weight, newGuardianWeight);
}
}
32 changes: 27 additions & 5 deletions test/unit/EmailRecoveryManager/getGuardianConfig.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,39 @@
pragma solidity ^0.8.25;

import "forge-std/console2.sol";
import { IEmailRecoveryManager } from "src/interfaces/IEmailRecoveryManager.sol";
import { EmailRecoveryModule } from "src/modules/EmailRecoveryModule.sol";
import { GuardianStorage, GuardianStatus } from "src/libraries/EnumerableGuardianMap.sol";
import { UnitBase } from "../UnitBase.t.sol";
import {IEmailRecoveryManager} from "src/interfaces/IEmailRecoveryManager.sol";
import {EmailRecoveryModule} from "src/modules/EmailRecoveryModule.sol";
import {GuardianStorage, GuardianStatus} from "src/libraries/EnumerableGuardianMap.sol";
import {UnitBase} from "../UnitBase.t.sol";

contract EmailRecoveryManager_getGuardianConfig_Test is UnitBase {
address newGuardian = address(1);
uint256 newGuardianWeight = 1;

uint256 expectedGuardianCount;
uint256 expectedTotalWeight;
uint256 expectedThreshold;

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

expectedGuardianCount = guardians.length + 1;
expectedTotalWeight = totalWeight + newGuardianWeight;
expectedThreshold = threshold;

vm.startPrank(accountAddress);
emailRecoveryManager.addGuardian(newGuardian, newGuardianWeight);
vm.stopPrank();
}

function test_GetGuardianConfig_Succeeds() public {
// TODO: test
IEmailRecoveryManager.GuardianConfig
memory guardianConfig = emailRecoveryManager.getGuardianConfig(
accountAddress
);
console2.log(expectedGuardianCount);
assertEq(guardianConfig.guardianCount, expectedGuardianCount);
assertEq(guardianConfig.totalWeight, expectedTotalWeight);
assertEq(guardianConfig.threshold, expectedThreshold);
}
}
31 changes: 26 additions & 5 deletions test/unit/EmailRecoveryManager/getRecoveryConfig.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,38 @@
pragma solidity ^0.8.25;

import "forge-std/console2.sol";
import { IEmailRecoveryManager } from "src/interfaces/IEmailRecoveryManager.sol";
import { EmailRecoveryModule } from "src/modules/EmailRecoveryModule.sol";
import { GuardianStorage, GuardianStatus } from "src/libraries/EnumerableGuardianMap.sol";
import { UnitBase } from "../UnitBase.t.sol";
import {IEmailRecoveryManager} from "src/interfaces/IEmailRecoveryManager.sol";
import {EmailRecoveryModule} from "src/modules/EmailRecoveryModule.sol";
import {GuardianStorage, GuardianStatus} from "src/libraries/EnumerableGuardianMap.sol";
import {UnitBase} from "../UnitBase.t.sol";

contract EmailRecoveryManager_getRecoveryConfig_Test is UnitBase {
uint256 newDelay = 1 days;
uint256 newExpiry = 4 weeks;

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

IEmailRecoveryManager.RecoveryConfig
memory recoveryConfig = IEmailRecoveryManager.RecoveryConfig(
newDelay,
newExpiry
);

vm.startPrank(accountAddress);
emailRecoveryManager.updateRecoveryConfig(recoveryConfig);

recoveryConfig = emailRecoveryManager.getRecoveryConfig(accountAddress);
assertEq(recoveryConfig.delay, newDelay);
assertEq(recoveryConfig.expiry, newExpiry);
}

function test_GetRecoveryConfig_Succeeds() public {
// TODO: test
IEmailRecoveryManager.RecoveryConfig
memory result = emailRecoveryManager.getRecoveryConfig(
accountAddress
);
assertEq(result.delay, newDelay);
assertEq(result.expiry, newExpiry);
}
}
22 changes: 17 additions & 5 deletions test/unit/EmailRecoveryManager/getRecoveryRequest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,29 @@
pragma solidity ^0.8.25;

import "forge-std/console2.sol";
import { IEmailRecoveryManager } from "src/interfaces/IEmailRecoveryManager.sol";
import { EmailRecoveryModule } from "src/modules/EmailRecoveryModule.sol";
import { GuardianStorage, GuardianStatus } from "src/libraries/EnumerableGuardianMap.sol";
import { UnitBase } from "../UnitBase.t.sol";
import {IEmailRecoveryManager} from "src/interfaces/IEmailRecoveryManager.sol";
import {EmailRecoveryModule} from "src/modules/EmailRecoveryModule.sol";
import {GuardianStorage, GuardianStatus} from "src/libraries/EnumerableGuardianMap.sol";
import {UnitBase} from "../UnitBase.t.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";

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

function test_GetRecoveryRequest_Succeeds() public {
// TODO: test
acceptGuardian(accountSalt1);
vm.warp(12 seconds);
handleRecovery(recoveryModuleAddress, calldataHash, accountSalt1);

IEmailRecoveryManager.RecoveryRequest
memory recoveryRequest = emailRecoveryManager.getRecoveryRequest(
accountAddress
);
assertEq(recoveryRequest.executeAfter, 0);
assertEq(recoveryRequest.executeBefore, 0);
assertEq(recoveryRequest.currentWeight, 1);
assertEq(recoveryRequest.calldataHashString, "");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you merge the latest changes in, this has been changed to bytes32 from a string

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ contract SafeRecoverySubjectHandler_getPreviousOwnerInLinkedList_Test is SafeUni
}

function test_GetPreviousOwnerInLinkedList_SucceedsWithMultipleAccounts() public {
// TODO: test
address expectedPreviousOwner = address(1);
address previousOwner =
safeRecoverySubjectHandler.exposed_getPreviousOwnerInLinkedList(accountAddress, owner);

assertEq(expectedPreviousOwner, previousOwner);
previousOwner =
safeRecoverySubjectHandler.exposed_getPreviousOwnerInLinkedList(accountAddress, anotherOwner);
assertEq(expectedPreviousOwner, previousOwner);
}
}
2 changes: 1 addition & 1 deletion test/unit/libraries/EnumerableGuardianMap/keys.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract EnumerableGuardianMap_keys_Test is UnitBase {
}

function test_Keys_ReturnsEmptyArrayOfKeys() public view {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, can you remove this test case then?

// TODO: It's same as test_Keys_StartsEmpty()
// It's same as test_Keys_StartsEmpty()
}

function test_Keys_ReturnsArrayOfKeys() public {
Expand Down