From bd3573abbc3e9294bb8ef74ff42da9857b8fc3a0 Mon Sep 17 00:00:00 2001 From: JohnGuilding Date: Mon, 17 Jun 2024 11:24:03 +0100 Subject: [PATCH] Cleaner unit test setup & additional rename --- .../EmailRecoveryManager/acceptGuardian.t.sol | 30 -------- .../EmailRecoveryManager/addGuardian.t.sol | 29 ------- .../EmailRecoveryManager/cancelRecovery.t.sol | 29 ------- .../changeThreshold.t.sol | 29 ------- .../completeRecovery.t.sol | 77 ++----------------- .../configureRecovery.t.sol | 29 ------- .../deInitRecoveryFromModule.t.sol | 29 ------- .../processRecovery.t.sol | 29 ------- .../EmailRecoveryManager/removeGuardian.t.sol | 29 ------- .../updateRecoveryConfig.t.sol | 29 ------- .../validateAcceptanceSubjectTemplates.t.sol | 17 +--- .../validateRecoverySubjectTemplates.t.sol | 32 +------- test/unit/UnitBase.t.sol | 56 +++++++++----- .../EnumerableGuardianMap/get.t.sol | 0 .../EnumerableGuardianMap/keys.t.sol | 0 .../EnumerableGuardianMap/remove.t.sol | 0 .../EnumerableGuardianMap/removeAll.t.sol | 0 .../EnumerableGuardianMap/set.t.sol | 0 .../getPreviousOwnerInLinkedList.t.sol | 2 +- .../EmailRecoveryModule/isInitialized.t.sol | 2 +- .../EmailRecoveryModule/isModuleType.t.sol | 2 +- .../EmailRecoveryModule/name.t.sol | 2 +- .../EmailRecoveryModule/onInstall.t.sol | 2 +- .../EmailRecoveryModule/onUninstall.t.sol | 2 +- .../EmailRecoveryModule/recover.t.sol | 2 +- .../EmailRecoveryModule/version.t.sol | 2 +- 26 files changed, 57 insertions(+), 403 deletions(-) rename test/unit/{ => libraries}/EnumerableGuardianMap/get.t.sol (100%) rename test/unit/{ => libraries}/EnumerableGuardianMap/keys.t.sol (100%) rename test/unit/{ => libraries}/EnumerableGuardianMap/remove.t.sol (100%) rename test/unit/{ => libraries}/EnumerableGuardianMap/removeAll.t.sol (100%) rename test/unit/{ => libraries}/EnumerableGuardianMap/set.t.sol (100%) rename test/unit/{ => modules}/EmailRecoveryModule/getPreviousOwnerInLinkedList.t.sol (88%) rename test/unit/{ => modules}/EmailRecoveryModule/isInitialized.t.sol (85%) rename test/unit/{ => modules}/EmailRecoveryModule/isModuleType.t.sol (81%) rename test/unit/{ => modules}/EmailRecoveryModule/name.t.sol (83%) rename test/unit/{ => modules}/EmailRecoveryModule/onInstall.t.sol (81%) rename test/unit/{ => modules}/EmailRecoveryModule/onUninstall.t.sol (81%) rename test/unit/{ => modules}/EmailRecoveryModule/recover.t.sol (90%) rename test/unit/{ => modules}/EmailRecoveryModule/version.t.sol (82%) diff --git a/test/unit/EmailRecoveryManager/acceptGuardian.t.sol b/test/unit/EmailRecoveryManager/acceptGuardian.t.sol index 8f7dc51f..224d8576 100644 --- a/test/unit/EmailRecoveryManager/acceptGuardian.t.sol +++ b/test/unit/EmailRecoveryManager/acceptGuardian.t.sol @@ -11,38 +11,8 @@ import { UnitBase } from "../UnitBase.t.sol"; import { OwnableValidator } from "src/test/OwnableValidator.sol"; contract ZkEmailRecovery_acceptGuardian_Test is UnitBase { - using ModuleKitHelpers for *; - using ModuleKitUserOp for *; - - OwnableValidator validator; - bytes4 functionSelector; - function setUp() public override { super.setUp(); - - validator = new OwnableValidator(); - functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)"))); - - instance.installModule({ - moduleTypeId: MODULE_TYPE_VALIDATOR, - module: address(validator), - data: abi.encode(owner, recoveryModuleAddress) - }); - - // Install recovery module - configureRecovery is called on `onInstall` - instance.installModule({ - moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, - data: abi.encode( - address(validator), - functionSelector, - guardians, - guardianWeights, - threshold, - delay, - expiry - ) - }); } // function test_AcceptGuardian_RevertWhen_AlreadyRecovering() public { diff --git a/test/unit/EmailRecoveryManager/addGuardian.t.sol b/test/unit/EmailRecoveryManager/addGuardian.t.sol index fc270565..03d711a1 100644 --- a/test/unit/EmailRecoveryManager/addGuardian.t.sol +++ b/test/unit/EmailRecoveryManager/addGuardian.t.sol @@ -18,37 +18,8 @@ error InvalidGuardianWeight(); event AddedGuardian(address indexed account, address indexed guardian); contract ZkEmailRecovery_addGuardian_Test is UnitBase { - using ModuleKitHelpers for *; - using ModuleKitUserOp for *; - - OwnableValidator validator; - bytes4 functionSelector; - function setUp() public override { super.setUp(); - - validator = new OwnableValidator(); - functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)"))); - - instance.installModule({ - moduleTypeId: MODULE_TYPE_VALIDATOR, - module: address(validator), - data: abi.encode(owner, recoveryModuleAddress) - }); - // Install recovery module - configureRecovery is called on `onInstall` - instance.installModule({ - moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, - data: abi.encode( - address(validator), - functionSelector, - guardians, - guardianWeights, - threshold, - delay, - expiry - ) - }); } // function test_AddGuardian_RevertWhen_AlreadyRecovering() public { diff --git a/test/unit/EmailRecoveryManager/cancelRecovery.t.sol b/test/unit/EmailRecoveryManager/cancelRecovery.t.sol index bce9b8f7..ce67557e 100644 --- a/test/unit/EmailRecoveryManager/cancelRecovery.t.sol +++ b/test/unit/EmailRecoveryManager/cancelRecovery.t.sol @@ -10,37 +10,8 @@ import { EmailRecoveryModule } from "src/modules/EmailRecoveryModule.sol"; import { OwnableValidator } from "src/test/OwnableValidator.sol"; contract ZkEmailRecovery_cancelRecovery_Test is UnitBase { - using ModuleKitHelpers for *; - using ModuleKitUserOp for *; - - OwnableValidator validator; - bytes4 functionSelector; - function setUp() public override { super.setUp(); - - validator = new OwnableValidator(); - functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)"))); - - instance.installModule({ - moduleTypeId: MODULE_TYPE_VALIDATOR, - module: address(validator), - data: abi.encode(owner, recoveryModuleAddress) - }); - // Install recovery module - configureRecovery is called on `onInstall` - instance.installModule({ - moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, - data: abi.encode( - address(validator), - functionSelector, - guardians, - guardianWeights, - threshold, - delay, - expiry - ) - }); } // function test_CancelRecovery_CannotCancelWrongRecoveryRequest() public { diff --git a/test/unit/EmailRecoveryManager/changeThreshold.t.sol b/test/unit/EmailRecoveryManager/changeThreshold.t.sol index 9cca9269..070f860a 100644 --- a/test/unit/EmailRecoveryManager/changeThreshold.t.sol +++ b/test/unit/EmailRecoveryManager/changeThreshold.t.sol @@ -16,37 +16,8 @@ error ThresholdCannotBeZero(); event ChangedThreshold(address indexed account, uint256 threshold); contract ZkEmailRecovery_changeThreshold_Test is UnitBase { - using ModuleKitHelpers for *; - using ModuleKitUserOp for *; - - OwnableValidator validator; - bytes4 functionSelector; - function setUp() public override { super.setUp(); - - validator = new OwnableValidator(); - functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)"))); - - instance.installModule({ - moduleTypeId: MODULE_TYPE_VALIDATOR, - module: address(validator), - data: abi.encode(owner, recoveryModuleAddress) - }); - // Install recovery module - configureRecovery is called on `onInstall` - instance.installModule({ - moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, - data: abi.encode( - address(validator), - functionSelector, - guardians, - guardianWeights, - threshold, - delay, - expiry - ) - }); } // function test_RevertWhen_AlreadyRecovering() public { diff --git a/test/unit/EmailRecoveryManager/completeRecovery.t.sol b/test/unit/EmailRecoveryManager/completeRecovery.t.sol index 2a55c61b..8585d589 100644 --- a/test/unit/EmailRecoveryManager/completeRecovery.t.sol +++ b/test/unit/EmailRecoveryManager/completeRecovery.t.sol @@ -12,46 +12,15 @@ import { OwnableValidator } from "src/test/OwnableValidator.sol"; // completeRecovery(accountAddress, recoveryCalldata) contract ZkEmailRecovery_completeRecovery_Test is UnitBase { - using ModuleKitHelpers for *; - using ModuleKitUserOp for *; - - OwnableValidator validator; - - bytes recoveryCalldata; - bytes4 functionSelector; - function setUp() public override { super.setUp(); - - validator = new OwnableValidator(); - functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)"))); - - instance.installModule({ - moduleTypeId: MODULE_TYPE_VALIDATOR, - module: address(validator), - data: abi.encode(owner, recoveryModuleAddress) - }); - // Install recovery module - configureRecovery is called on `onInstall` - instance.installModule({ - moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, - data: abi.encode( - address(validator), - functionSelector, - guardians, - guardianWeights, - threshold, - delay, - expiry - ) - }); - - recoveryCalldata = abi.encodeWithSignature( - "changeOwner(address,address,address)", accountAddress, recoveryModuleAddress, newOwner - ); } // function test_CompleteRecovery_RevertWhen_NotCalledFromCorrectRouter() public { + // bytes memory recoveryCalldata = abi.encodeWithSignature( + // "changeOwner(address,address,address)", accountAddress, recoveryModuleAddress, + // newOwner + // ); // acceptGuardian(accountSalt1); // acceptGuardian(accountSalt2); // vm.warp(12 seconds); @@ -85,46 +54,14 @@ contract ZkEmailRecovery_completeRecovery_Test is UnitBase { // completeRecovery(address account) contract ZkEmailRecovery_completeRecoveryWithAddress_Test is UnitBase { - using ModuleKitHelpers for *; - using ModuleKitUserOp for *; - - OwnableValidator validator; - - bytes recoveryCalldata; - bytes4 functionSelector; - function setUp() public override { super.setUp(); - - validator = new OwnableValidator(); - functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)"))); - - instance.installModule({ - moduleTypeId: MODULE_TYPE_VALIDATOR, - module: address(validator), - data: abi.encode(owner, recoveryModuleAddress) - }); - // Install recovery module - configureRecovery is called on `onInstall` - instance.installModule({ - moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, - data: abi.encode( - address(validator), - functionSelector, - guardians, - guardianWeights, - threshold, - delay, - expiry - ) - }); - - recoveryCalldata = abi.encodeWithSignature( - "changeOwner(address,address,address)", accountAddress, recoveryModuleAddress, newOwner - ); } // function test_CompleteRecovery_RevertWhen_InvalidAccountAddress() public { + // bytes memory recoveryCalldata = abi.encodeWithSignature( + // "changeOwner(address,address,address)", accountAddress, recoveryModuleAddress, + // newOwner // address invalidAccount = address(0); // vm.expectRevert(IEmailRecoveryManager.InvalidAccountAddress.selector); diff --git a/test/unit/EmailRecoveryManager/configureRecovery.t.sol b/test/unit/EmailRecoveryManager/configureRecovery.t.sol index 8e425370..281c8a92 100644 --- a/test/unit/EmailRecoveryManager/configureRecovery.t.sol +++ b/test/unit/EmailRecoveryManager/configureRecovery.t.sol @@ -15,37 +15,8 @@ import { OwnableValidator } from "src/test/OwnableValidator.sol"; error SetupAlreadyCalled(); contract ZkEmailRecovery_configureRecovery_Test is UnitBase { - using ModuleKitHelpers for *; - using ModuleKitUserOp for *; - - OwnableValidator validator; - bytes4 functionSelector; - function setUp() public override { super.setUp(); - - validator = new OwnableValidator(); - functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)"))); - - instance.installModule({ - moduleTypeId: MODULE_TYPE_VALIDATOR, - module: address(validator), - data: abi.encode(owner, recoveryModuleAddress) - }); - // Install recovery module - configureRecovery is called on `onInstall` - instance.installModule({ - moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, - data: abi.encode( - address(validator), - functionSelector, - guardians, - guardianWeights, - threshold, - delay, - expiry - ) - }); } // function test_ConfigureRecovery_RevertWhen_AlreadyRecovering() public { diff --git a/test/unit/EmailRecoveryManager/deInitRecoveryFromModule.t.sol b/test/unit/EmailRecoveryManager/deInitRecoveryFromModule.t.sol index a50a2a14..520e8995 100644 --- a/test/unit/EmailRecoveryManager/deInitRecoveryFromModule.t.sol +++ b/test/unit/EmailRecoveryManager/deInitRecoveryFromModule.t.sol @@ -12,37 +12,8 @@ import { EmailRecoveryModule } from "src/modules/EmailRecoveryModule.sol"; import { OwnableValidator } from "src/test/OwnableValidator.sol"; contract ZkEmailRecovery_deInitRecoveryFromModule_Test is UnitBase { - using ModuleKitHelpers for *; - using ModuleKitUserOp for *; - - OwnableValidator validator; - bytes4 functionSelector; - function setUp() public override { super.setUp(); - - validator = new OwnableValidator(); - functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)"))); - - instance.installModule({ - moduleTypeId: MODULE_TYPE_VALIDATOR, - module: address(validator), - data: abi.encode(owner, recoveryModuleAddress) - }); - // Install recovery module - configureRecovery is called on `onInstall` - instance.installModule({ - moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, - data: abi.encode( - address(validator), - functionSelector, - guardians, - guardianWeights, - threshold, - delay, - expiry - ) - }); } // function test_DeInitRecoveryFromModule_RevertWhen_NotCalledFromRecoveryModule() public { diff --git a/test/unit/EmailRecoveryManager/processRecovery.t.sol b/test/unit/EmailRecoveryManager/processRecovery.t.sol index 140a13d3..0481790d 100644 --- a/test/unit/EmailRecoveryManager/processRecovery.t.sol +++ b/test/unit/EmailRecoveryManager/processRecovery.t.sol @@ -12,37 +12,8 @@ import { OwnableValidator } from "src/test/OwnableValidator.sol"; import { GuardianStorage, GuardianStatus } from "src/libraries/EnumerableGuardianMap.sol"; contract ZkEmailRecovery_processRecovery_Test is UnitBase { - using ModuleKitHelpers for *; - using ModuleKitUserOp for *; - - OwnableValidator validator; - bytes4 functionSelector; - function setUp() public override { super.setUp(); - - validator = new OwnableValidator(); - functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)"))); - - instance.installModule({ - moduleTypeId: MODULE_TYPE_VALIDATOR, - module: address(validator), - data: abi.encode(owner, recoveryModuleAddress) - }); - // Install recovery module - configureRecovery is called on `onInstall` - instance.installModule({ - moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, - data: abi.encode( - address(validator), - functionSelector, - guardians, - guardianWeights, - threshold, - delay, - expiry - ) - }); } // function test_ProcessRecovery_RevertWhen_GuardianStatusIsNONE() public { diff --git a/test/unit/EmailRecoveryManager/removeGuardian.t.sol b/test/unit/EmailRecoveryManager/removeGuardian.t.sol index df028946..8ade0985 100644 --- a/test/unit/EmailRecoveryManager/removeGuardian.t.sol +++ b/test/unit/EmailRecoveryManager/removeGuardian.t.sol @@ -15,37 +15,8 @@ error ThresholdCannotExceedTotalWeight(); error UnauthorizedAccountForGuardian(); contract ZkEmailRecovery_removeGuardian_Test is UnitBase { - using ModuleKitHelpers for *; - using ModuleKitUserOp for *; - - OwnableValidator validator; - bytes4 functionSelector; - function setUp() public override { super.setUp(); - - validator = new OwnableValidator(); - functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)"))); - - instance.installModule({ - moduleTypeId: MODULE_TYPE_VALIDATOR, - module: address(validator), - data: abi.encode(owner, recoveryModuleAddress) - }); - // Install recovery module - configureRecov ery is called on `onInstall` - instance.installModule({ - moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, - data: abi.encode( - address(validator), - functionSelector, - guardians, - guardianWeights, - threshold, - delay, - expiry - ) - }); } // function test_RemoveGuardian_RevertWhen_UnauthorizedAccountForGuardian() public { diff --git a/test/unit/EmailRecoveryManager/updateRecoveryConfig.t.sol b/test/unit/EmailRecoveryManager/updateRecoveryConfig.t.sol index 192cfc24..50967014 100644 --- a/test/unit/EmailRecoveryManager/updateRecoveryConfig.t.sol +++ b/test/unit/EmailRecoveryManager/updateRecoveryConfig.t.sol @@ -11,37 +11,8 @@ import { EmailRecoveryModule } from "src/modules/EmailRecoveryModule.sol"; import { OwnableValidator } from "src/test/OwnableValidator.sol"; contract ZkEmailRecovery_updateRecoveryConfig_Test is UnitBase { - using ModuleKitHelpers for *; - using ModuleKitUserOp for *; - - OwnableValidator validator; - bytes4 functionSelector; - function setUp() public override { super.setUp(); - - validator = new OwnableValidator(); - functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)"))); - - instance.installModule({ - moduleTypeId: MODULE_TYPE_VALIDATOR, - module: address(validator), - data: abi.encode(owner, recoveryModuleAddress) - }); - // Install recovery module - configureRecovery is called on `onInstall` - instance.installModule({ - moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, - data: abi.encode( - address(validator), - functionSelector, - guardians, - guardianWeights, - threshold, - delay, - expiry - ) - }); } // function test_UpdateRecoveryConfig_RevertWhen_AlreadyRecovering() public { diff --git a/test/unit/EmailRecoveryManager/validateAcceptanceSubjectTemplates.t.sol b/test/unit/EmailRecoveryManager/validateAcceptanceSubjectTemplates.t.sol index e6590df9..ddc1d52b 100644 --- a/test/unit/EmailRecoveryManager/validateAcceptanceSubjectTemplates.t.sol +++ b/test/unit/EmailRecoveryManager/validateAcceptanceSubjectTemplates.t.sol @@ -12,20 +12,9 @@ pragma solidity ^0.8.25; // import { UnitBase } from "../UnitBase.t.sol"; // contract ZkEmailRecovery_validateAcceptanceSubjectTemplates_Test is UnitBase { -// using ModuleKitHelpers for *; -// using ModuleKitUserOp for *; - -// EmailRecoveryModule recoveryModule; -// address recoveryModuleAddress; - -// function setUp() public override { -// super.setUp(); - -// recoveryModule = -// new EmailRecoveryModule{ salt: "test salt" -// }(address(emailRecoveryManager)); -// recoveryModuleAddress = address(recoveryModule); -// } +// function setUp() public override { +// super.setUp(); +// } // function test_ValidateAcceptanceSubjectTemplates_RevertWhen_InvalidTemplateIndex() public { // uint256 invalidTemplateIdx = 1; diff --git a/test/unit/EmailRecoveryManager/validateRecoverySubjectTemplates.t.sol b/test/unit/EmailRecoveryManager/validateRecoverySubjectTemplates.t.sol index ef02bc18..94b4bf00 100644 --- a/test/unit/EmailRecoveryManager/validateRecoverySubjectTemplates.t.sol +++ b/test/unit/EmailRecoveryManager/validateRecoverySubjectTemplates.t.sol @@ -12,35 +12,9 @@ pragma solidity ^0.8.25; // import { UnitBase } from "../UnitBase.t.sol"; // contract ZkEmailRecovery_validateRecoverySubjectTemplates_Test is UnitBase { -// using ModuleKitHelpers for *; -// using ModuleKitUserOp for *; - -// OwnableValidator validator; -// EmailRecoveryModule recoveryModule; -// address recoveryModuleAddress; - -// function setUp() public override { -// super.setUp(); - -// validator = new OwnableValidator(); -// recoveryModule = -// new EmailRecoveryModule{ salt: "test salt" -// }(address(emailRecoveryManager)); -// recoveryModuleAddress = address(recoveryModule); - -// instance.installModule({ -// moduleTypeId: MODULE_TYPE_VALIDATOR, -// module: address(validator), -// data: abi.encode(owner, recoveryModuleAddress) -// }); -// // Install recovery module - configureRecovery is called on `onInstall` -// instance.installModule({ -// moduleTypeId: MODULE_TYPE_EXECUTOR, -// module: recoveryModuleAddress, -// data: abi.encode(address(validator), guardians, guardianWeights, threshold, delay, -// expiry) -// }); -// } +// function setUp() public override { +// super.setUp(); +// } // function test_ValidateRecoverySubjectTemplates_RevertWhen_InvalidTemplateIndex() public { // uint256 invalidTemplateIdx = 1; diff --git a/test/unit/UnitBase.t.sol b/test/unit/UnitBase.t.sol index 3f011ef8..eb266fb7 100644 --- a/test/unit/UnitBase.t.sol +++ b/test/unit/UnitBase.t.sol @@ -22,16 +22,18 @@ import { MockGroth16Verifier } from "src/test/MockGroth16Verifier.sol"; abstract contract UnitBase is RhinestoneModuleKit, Test { // ZK Email contracts and variables address zkEmailDeployer = vm.addr(1); - ECDSAOwnedDKIMRegistry ecdsaOwnedDkimRegistry; + ECDSAOwnedDKIMRegistry dkimRegistry; MockGroth16Verifier verifier; EmailAuth emailAuthImpl; EmailRecoverySubjectHandler emailRecoveryHandler; EmailRecoveryManagerHarness emailRecoveryManager; - address emailRecoveryManagerAddress; address recoveryModuleAddress; + OwnableValidator validator; + bytes4 functionSelector; + // account and owners AccountInstance instance; address accountAddress; @@ -64,14 +66,14 @@ abstract contract UnitBase is RhinestoneModuleKit, Test { // Create ZK Email contracts vm.startPrank(zkEmailDeployer); - ecdsaOwnedDkimRegistry = new ECDSAOwnedDKIMRegistry(zkEmailDeployer); - string memory signedMsg = ecdsaOwnedDkimRegistry.computeSignedMsg( - ecdsaOwnedDkimRegistry.SET_PREFIX(), selector, domainName, publicKeyHash + dkimRegistry = new ECDSAOwnedDKIMRegistry(zkEmailDeployer); + string memory signedMsg = dkimRegistry.computeSignedMsg( + dkimRegistry.SET_PREFIX(), selector, domainName, publicKeyHash ); bytes32 digest = ECDSA.toEthSignedMessageHash(bytes(signedMsg)); (uint8 v, bytes32 r, bytes32 s) = vm.sign(1, digest); bytes memory signature = abi.encodePacked(r, s, v); - ecdsaOwnedDkimRegistry.setDKIMPublicKeyHash(selector, domainName, publicKeyHash, signature); + dkimRegistry.setDKIMPublicKeyHash(selector, domainName, publicKeyHash, signature); verifier = new MockGroth16Verifier(); emailAuthImpl = new EmailAuth(); @@ -83,30 +85,24 @@ abstract contract UnitBase is RhinestoneModuleKit, Test { address[] memory owners = new address[](1); owners[0] = owner; + // Deploy handler, manager and module emailRecoveryHandler = new EmailRecoverySubjectHandler(); - EmailRecoveryManagerHarness emailRecoveryManager = new EmailRecoveryManagerHarness( address(verifier), - address(ecdsaOwnedDkimRegistry), + address(dkimRegistry), address(emailAuthImpl), address(emailRecoveryHandler) ); - address manager = address(emailRecoveryManager); + emailRecoveryManagerAddress = address(emailRecoveryManager); - EmailRecoveryModule emailRecoveryModule = new EmailRecoveryModule(manager); + EmailRecoveryModule emailRecoveryModule = + new EmailRecoveryModule(emailRecoveryManagerAddress); recoveryModuleAddress = address(emailRecoveryModule); - emailRecoveryManager.initialize(recoveryModuleAddress); - // Deploy EmailRecoveryManager & EmailRecoveryModule - // (emailRecoveryManagerAddress, recoveryModuleAddress) = emailRecoveryFactory - // .deployModuleAndManager( - // address(verifier), - // address(ecdsaOwnedDkimRegistry), - // address(emailAuthImpl), - // address(emailRecoveryHandler) - // ); - // emailRecoveryManager = EmailRecoveryManager(emailRecoveryManagerAddress); + // Deploy validator to be recovered + validator = new OwnableValidator(); + functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)"))); // Deploy and fund the account instance = makeAccountInstance("account"); @@ -137,6 +133,26 @@ abstract contract UnitBase is RhinestoneModuleKit, Test { expiry = 2 weeks; threshold = 3; templateIdx = 0; + + // Install modules + instance.installModule({ + moduleTypeId: MODULE_TYPE_VALIDATOR, + module: address(validator), + data: abi.encode(owner, recoveryModuleAddress) + }); + instance.installModule({ + moduleTypeId: MODULE_TYPE_EXECUTOR, + module: recoveryModuleAddress, + data: abi.encode( + address(validator), + functionSelector, + guardians, + guardianWeights, + threshold, + delay, + expiry + ) + }); } // Helper functions diff --git a/test/unit/EnumerableGuardianMap/get.t.sol b/test/unit/libraries/EnumerableGuardianMap/get.t.sol similarity index 100% rename from test/unit/EnumerableGuardianMap/get.t.sol rename to test/unit/libraries/EnumerableGuardianMap/get.t.sol diff --git a/test/unit/EnumerableGuardianMap/keys.t.sol b/test/unit/libraries/EnumerableGuardianMap/keys.t.sol similarity index 100% rename from test/unit/EnumerableGuardianMap/keys.t.sol rename to test/unit/libraries/EnumerableGuardianMap/keys.t.sol diff --git a/test/unit/EnumerableGuardianMap/remove.t.sol b/test/unit/libraries/EnumerableGuardianMap/remove.t.sol similarity index 100% rename from test/unit/EnumerableGuardianMap/remove.t.sol rename to test/unit/libraries/EnumerableGuardianMap/remove.t.sol diff --git a/test/unit/EnumerableGuardianMap/removeAll.t.sol b/test/unit/libraries/EnumerableGuardianMap/removeAll.t.sol similarity index 100% rename from test/unit/EnumerableGuardianMap/removeAll.t.sol rename to test/unit/libraries/EnumerableGuardianMap/removeAll.t.sol diff --git a/test/unit/EnumerableGuardianMap/set.t.sol b/test/unit/libraries/EnumerableGuardianMap/set.t.sol similarity index 100% rename from test/unit/EnumerableGuardianMap/set.t.sol rename to test/unit/libraries/EnumerableGuardianMap/set.t.sol diff --git a/test/unit/EmailRecoveryModule/getPreviousOwnerInLinkedList.t.sol b/test/unit/modules/EmailRecoveryModule/getPreviousOwnerInLinkedList.t.sol similarity index 88% rename from test/unit/EmailRecoveryModule/getPreviousOwnerInLinkedList.t.sol rename to test/unit/modules/EmailRecoveryModule/getPreviousOwnerInLinkedList.t.sol index fb37dd07..4a6558ee 100644 --- a/test/unit/EmailRecoveryModule/getPreviousOwnerInLinkedList.t.sol +++ b/test/unit/modules/EmailRecoveryModule/getPreviousOwnerInLinkedList.t.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.25; import "forge-std/console2.sol"; import { UnitBase } from "../UnitBase.t.sol"; -contract SafeRecoveryModule_getPreviousOwnerInLinkedList_Test is UnitBase { +contract EmailRecoveryModule_getPreviousOwnerInLinkedList_Test is UnitBase { function setUp() public override { super.setUp(); } diff --git a/test/unit/EmailRecoveryModule/isInitialized.t.sol b/test/unit/modules/EmailRecoveryModule/isInitialized.t.sol similarity index 85% rename from test/unit/EmailRecoveryModule/isInitialized.t.sol rename to test/unit/modules/EmailRecoveryModule/isInitialized.t.sol index ebd48b4c..2787dd1d 100644 --- a/test/unit/EmailRecoveryModule/isInitialized.t.sol +++ b/test/unit/modules/EmailRecoveryModule/isInitialized.t.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.25; import "forge-std/console2.sol"; import { UnitBase } from "../UnitBase.t.sol"; -contract SafeRecoveryModule_isInitialized_Test is UnitBase { +contract EmailRecoveryModule_isInitialized_Test is UnitBase { function setUp() public override { super.setUp(); } diff --git a/test/unit/EmailRecoveryModule/isModuleType.t.sol b/test/unit/modules/EmailRecoveryModule/isModuleType.t.sol similarity index 81% rename from test/unit/EmailRecoveryModule/isModuleType.t.sol rename to test/unit/modules/EmailRecoveryModule/isModuleType.t.sol index e626cd27..916f6990 100644 --- a/test/unit/EmailRecoveryModule/isModuleType.t.sol +++ b/test/unit/modules/EmailRecoveryModule/isModuleType.t.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.25; import "forge-std/console2.sol"; import { UnitBase } from "../UnitBase.t.sol"; -contract SafeRecoveryModule_isModuleType_Test is UnitBase { +contract EmailRecoveryModule_isModuleType_Test is UnitBase { function setUp() public override { super.setUp(); } diff --git a/test/unit/EmailRecoveryModule/name.t.sol b/test/unit/modules/EmailRecoveryModule/name.t.sol similarity index 83% rename from test/unit/EmailRecoveryModule/name.t.sol rename to test/unit/modules/EmailRecoveryModule/name.t.sol index b2c07b98..b1d1d25a 100644 --- a/test/unit/EmailRecoveryModule/name.t.sol +++ b/test/unit/modules/EmailRecoveryModule/name.t.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.25; import "forge-std/console2.sol"; import { UnitBase } from "../UnitBase.t.sol"; -contract SafeRecoveryModule_name_Test is UnitBase { +contract EmailRecoveryModule_name_Test is UnitBase { function setUp() public override { super.setUp(); } diff --git a/test/unit/EmailRecoveryModule/onInstall.t.sol b/test/unit/modules/EmailRecoveryModule/onInstall.t.sol similarity index 81% rename from test/unit/EmailRecoveryModule/onInstall.t.sol rename to test/unit/modules/EmailRecoveryModule/onInstall.t.sol index 5ce93a3c..f5ddb4ab 100644 --- a/test/unit/EmailRecoveryModule/onInstall.t.sol +++ b/test/unit/modules/EmailRecoveryModule/onInstall.t.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.25; import "forge-std/console2.sol"; import { UnitBase } from "../UnitBase.t.sol"; -contract SafeRecoveryModule_onInstall_Test is UnitBase { +contract EmailRecoveryModule_onInstall_Test is UnitBase { function setUp() public override { super.setUp(); } diff --git a/test/unit/EmailRecoveryModule/onUninstall.t.sol b/test/unit/modules/EmailRecoveryModule/onUninstall.t.sol similarity index 81% rename from test/unit/EmailRecoveryModule/onUninstall.t.sol rename to test/unit/modules/EmailRecoveryModule/onUninstall.t.sol index 0a106407..559857d7 100644 --- a/test/unit/EmailRecoveryModule/onUninstall.t.sol +++ b/test/unit/modules/EmailRecoveryModule/onUninstall.t.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.25; import "forge-std/console2.sol"; import { UnitBase } from "../UnitBase.t.sol"; -contract SafeRecoveryModule_onUninstall_Test is UnitBase { +contract EmailRecoveryModule_onUninstall_Test is UnitBase { function setUp() public override { super.setUp(); } diff --git a/test/unit/EmailRecoveryModule/recover.t.sol b/test/unit/modules/EmailRecoveryModule/recover.t.sol similarity index 90% rename from test/unit/EmailRecoveryModule/recover.t.sol rename to test/unit/modules/EmailRecoveryModule/recover.t.sol index 7b04c4f1..5f7ed034 100644 --- a/test/unit/EmailRecoveryModule/recover.t.sol +++ b/test/unit/modules/EmailRecoveryModule/recover.t.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.25; import "forge-std/console2.sol"; import { UnitBase } from "../UnitBase.t.sol"; -contract SafeRecoveryModule_recover_Test is UnitBase { +contract EmailRecoveryModule_recover_Test is UnitBase { function setUp() public override { super.setUp(); } diff --git a/test/unit/EmailRecoveryModule/version.t.sol b/test/unit/modules/EmailRecoveryModule/version.t.sol similarity index 82% rename from test/unit/EmailRecoveryModule/version.t.sol rename to test/unit/modules/EmailRecoveryModule/version.t.sol index d2675f2d..1b31ba04 100644 --- a/test/unit/EmailRecoveryModule/version.t.sol +++ b/test/unit/modules/EmailRecoveryModule/version.t.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.25; import "forge-std/console2.sol"; import { UnitBase } from "../UnitBase.t.sol"; -contract SafeRecoveryModule_version_Test is UnitBase { +contract EmailRecoveryModule_version_Test is UnitBase { function setUp() public override { super.setUp(); }