From 10237c46e5e7f6afe0ade0029888f32480f111a1 Mon Sep 17 00:00:00 2001 From: John Guilding Date: Wed, 18 Sep 2024 21:06:05 +0100 Subject: [PATCH] extract more logic to base test & rename variables --- test/Base.t.sol | 300 +++++++++++++++++- .../EmailRecoveryManager.integration.t.sol | 78 ++--- test/integration/IntegrationBase.t.sol | 105 +----- .../EmailRecoveryModule.t.sol | 63 ++-- .../EmailRecoveryModuleBase.t.sol | 182 ++--------- .../UniversalEmailRecoveryModule.t.sol | 67 ++-- .../UniversalEmailRecoveryModuleBase.t.sol | 171 ++-------- .../SafeRecovery/SafeIntegrationBase.t.sol | 121 ++----- .../SafeNativeIntegrationBase.t.sol | 86 +++-- .../SafeRecovery/SafeRecovery.t.sol | 6 +- .../SafeRecoveryNativeModule.t.sol | 18 +- .../EmailRecoveryManager/acceptGuardian.t.sol | 36 ++- .../cancelExpiredRecovery.t.sol | 68 ++-- .../EmailRecoveryManager/cancelRecovery.t.sol | 30 +- .../completeRecovery.t.sol | 50 +-- .../configureRecovery.t.sol | 66 ++-- .../deInitRecoveryModule.t.sol | 28 +- .../deInitRecoveryModuleWithAddress.t.sol | 32 +- .../getRecoveryConfig.t.sol | 6 +- .../getRecoveryRequest.t.sol | 6 +- .../EmailRecoveryManager/isActivated.t.sol | 6 +- .../processRecovery.t.sol | 56 ++-- .../updateRecoveryConfig.t.sol | 22 +- test/unit/GuardianManager/addGuardian.t.sol | 40 +-- .../GuardianManager/changeThreshold.t.sol | 26 +- test/unit/GuardianManager/getGuardian.t.sol | 4 +- .../GuardianManager/getGuardianConfig.t.sol | 6 +- .../GuardianManager/removeAllGuardians.t.sol | 14 +- .../unit/GuardianManager/removeGuardian.t.sol | 46 +-- .../unit/GuardianManager/setupGuardians.t.sol | 50 +-- .../updateGuardianStatus.t.sol | 30 +- test/unit/SafeUnitBase.t.sol | 76 ++--- test/unit/UnitBase.t.sol | 215 +++---------- ...ecoveredAccountFromAcceptanceCommand.t.sol | 4 +- ...tRecoveredAccountFromRecoveryCommand.t.sol | 6 +- .../parseRecoveryCalldataHash.t.sol | 2 +- .../validateAcceptanceCommand.t.sol | 8 +- .../validateRecoveryCommand.t.sol | 6 +- ...tRecoveredAccountFromRecoveryCommand.t.sol | 2 +- .../libraries/EnumerableGuardianMap/get.t.sol | 8 +- .../EnumerableGuardianMap/keys.t.sol | 10 +- .../EnumerableGuardianMap/remove.t.sol | 60 ++-- .../EnumerableGuardianMap/removeAll.t.sol | 14 +- .../libraries/EnumerableGuardianMap/set.t.sol | 41 +-- .../EmailRecoveryModuleBase.t.sol | 211 +++--------- .../canStartRecoveryRequest.t.sol | 22 +- .../EmailRecoveryModule/onInstall.t.sol | 22 +- .../EmailRecoveryModule/onUninstall.t.sol | 8 +- .../modules/EmailRecoveryModule/recover.t.sol | 50 +-- .../allowValidatorRecovery.t.sol | 62 ++-- .../canStartRecoveryRequest.t.sol | 38 +-- .../disallowValidatorRecovery.t.sol | 56 ++-- .../getAllowedSelectors.t.sol | 10 +- .../getAllowedValidators.t.sol | 16 +- .../onInstall.t.sol | 20 +- .../onUninstall.t.sol | 28 +- .../recover.t.sol | 60 ++-- 57 files changed, 1235 insertions(+), 1639 deletions(-) diff --git a/test/Base.t.sol b/test/Base.t.sol index 25c72fba..d2d9a7f2 100644 --- a/test/Base.t.sol +++ b/test/Base.t.sol @@ -5,5 +5,303 @@ pragma solidity ^0.8.25; import { Test } from "forge-std/Test.sol"; import { console2 } from "forge-std/console2.sol"; +import { RhinestoneModuleKit, AccountInstance } from "modulekit/ModuleKit.sol"; +import { + EmailAuth, + EmailAuthMsg, + EmailProof +} from "@zk-email/ether-email-auth-contracts/src/EmailAuth.sol"; +import { CommandUtils } from "@zk-email/ether-email-auth-contracts/src/libraries/CommandUtils.sol"; +import { ECDSAOwnedDKIMRegistry } from + "@zk-email/ether-email-auth-contracts/src/utils/ECDSAOwnedDKIMRegistry.sol"; +import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; +import { ECDSA } from "solady/utils/ECDSA.sol"; -abstract contract BaseTest is Test { } +import { MockGroth16Verifier } from "src/test/MockGroth16Verifier.sol"; +import { OwnableValidator } from "src/test/OwnableValidator.sol"; + +interface IEmailRecoveryModule { + function computeAcceptanceTemplateId(uint256 templateIdx) external pure returns (uint256); + + function handleAcceptance(EmailAuthMsg memory emailAuthMsg, uint256 templateIdx) external; + + function handleRecovery(EmailAuthMsg memory emailAuthMsg, uint256 templateIdx) external; + + function completeRecovery(address account, bytes memory completeCalldata) external; +} + +abstract contract BaseTest is RhinestoneModuleKit, Test { + // ZK Email contracts and variables + address zkEmailDeployer; + ECDSAOwnedDKIMRegistry dkimRegistry; + MockGroth16Verifier verifier; + EmailAuth emailAuthImpl; + + OwnableValidator validator; + address validatorAddress; + + // account and owners + address owner1; + address owner2; + address owner3; + address newOwner1; + address newOwner2; + address newOwner3; + AccountInstance instance1; + AccountInstance instance2; + AccountInstance instance3; + address accountAddress1; + address accountAddress2; + address accountAddress3; + + // Account salts + bytes32 accountSalt1; + bytes32 accountSalt2; + bytes32 accountSalt3; + + // recovery config + address[] guardians1; + address[] guardians2; + address[] guardians3; + uint256[] guardianWeights; + uint256 totalWeight; + uint256 delay; + uint256 expiry; + uint256 threshold; + uint256 templateIdx; + + string selector = "12345"; + string domainName = "gmail.com"; + bytes32 publicKeyHash = 0x0ea9c777dc7110e5a9e89b13f0cfc540e3845ba120b2b6dc24024d61488d4788; + + uint256 nullifierCount; + + function setUp() public virtual { + init(); + + // create owners + owner1 = vm.createWallet("owner1").addr; + owner2 = vm.createWallet("owner2").addr; + owner3 = vm.createWallet("owner3").addr; + newOwner1 = vm.createWallet("newOwner1").addr; + newOwner2 = vm.createWallet("newOwner2").addr; + newOwner3 = vm.createWallet("newOwner3").addr; + + // Deploy and fund the accounts + instance1 = makeAccountInstance("account1"); + instance2 = makeAccountInstance("account2"); + instance3 = makeAccountInstance("account3"); + accountAddress1 = instance1.account; + accountAddress2 = instance2.account; + accountAddress3 = instance3.account; + vm.deal(address(instance1.account), 10 ether); + vm.deal(address(instance2.account), 10 ether); + vm.deal(address(instance3.account), 10 ether); + + accountSalt1 = keccak256(abi.encode("account salt 1")); + accountSalt2 = keccak256(abi.encode("account salt 2")); + accountSalt3 = keccak256(abi.encode("account salt 3")); + + zkEmailDeployer = vm.addr(1); + + vm.startPrank(zkEmailDeployer); + { + ECDSAOwnedDKIMRegistry dkimImpl = new ECDSAOwnedDKIMRegistry(); + ERC1967Proxy dkimProxy = new ERC1967Proxy( + address(dkimImpl), + abi.encodeCall(dkimImpl.initialize, (zkEmailDeployer, zkEmailDeployer)) + ); + dkimRegistry = ECDSAOwnedDKIMRegistry(address(dkimProxy)); + } + 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); + dkimRegistry.setDKIMPublicKeyHash(selector, domainName, publicKeyHash, signature); + + verifier = new MockGroth16Verifier(); + emailAuthImpl = new EmailAuth(); + vm.stopPrank(); + + // Deploy validator to be recovered + validator = new OwnableValidator(); + validatorAddress = address(validator); + + deployModule(); + + // Compute guardian addresses + guardians1 = new address[](3); + guardians1[0] = computeEmailAuthAddress(instance1.account, accountSalt1); + guardians1[1] = computeEmailAuthAddress(instance1.account, accountSalt2); + guardians1[2] = computeEmailAuthAddress(instance1.account, accountSalt3); + guardians2 = new address[](3); + guardians2[0] = computeEmailAuthAddress(instance2.account, accountSalt1); + guardians2[1] = computeEmailAuthAddress(instance2.account, accountSalt2); + guardians2[2] = computeEmailAuthAddress(instance2.account, accountSalt3); + guardians3 = new address[](3); + guardians3[0] = computeEmailAuthAddress(instance3.account, accountSalt1); + guardians3[1] = computeEmailAuthAddress(instance3.account, accountSalt2); + guardians3[2] = computeEmailAuthAddress(instance3.account, accountSalt3); + + // Set recovery config variables + guardianWeights = new uint256[](3); + guardianWeights[0] = 1; + guardianWeights[1] = 2; + guardianWeights[2] = 1; + totalWeight = 4; + delay = 1 seconds; + expiry = 2 weeks; + threshold = 3; + templateIdx = 0; + } + + function computeEmailAuthAddress( + address account, + bytes32 accountSalt + ) + public + view + virtual + returns (address); + + function deployModule() public virtual; + + function generateMockEmailProof( + string memory command, + bytes32 nullifier, + bytes32 accountSalt + ) + public + view + returns (EmailProof memory) + { + EmailProof memory emailProof; + emailProof.domainName = "gmail.com"; + emailProof.publicKeyHash = bytes32( + vm.parseUint( + "6632353713085157925504008443078919716322386156160602218536961028046468237192" + ) + ); + emailProof.timestamp = block.timestamp; + emailProof.maskedCommand = command; + emailProof.emailNullifier = nullifier; + emailProof.accountSalt = accountSalt; + emailProof.isCodeExist = true; + emailProof.proof = bytes("0"); + + return emailProof; + } + + function acceptGuardian( + address account, + address guardian, + address emailRecoveryModule + ) + public + { + EmailAuthMsg memory emailAuthMsg = + getAcceptanceEmailAuthMessage(account, guardian, emailRecoveryModule); + IEmailRecoveryModule(emailRecoveryModule).handleAcceptance(emailAuthMsg, templateIdx); + } + + // WithAccountSalt variation - used for creating incorrect recovery setups + function acceptGuardianWithAccountSalt( + address account, + address guardian, + address emailRecoveryModule, + bytes32 optionalAccountSalt + ) + public + { + EmailAuthMsg memory emailAuthMsg = getAcceptanceEmailAuthMessageWithAccountSalt( + account, guardian, emailRecoveryModule, optionalAccountSalt + ); + IEmailRecoveryModule(emailRecoveryModule).handleAcceptance(emailAuthMsg, templateIdx); + } + + function getAcceptanceEmailAuthMessage( + address account, + address guardian, + address emailRecoveryModule + ) + public + returns (EmailAuthMsg memory) + { + return getAcceptanceEmailAuthMessageWithAccountSalt( + account, guardian, emailRecoveryModule, bytes32(0) + ); + } + + // WithAccountSalt variation - used for creating incorrect recovery setups + function getAcceptanceEmailAuthMessageWithAccountSalt( + address account, + address guardian, + address emailRecoveryModule, + bytes32 optionalAccountSalt + ) + public + virtual + returns (EmailAuthMsg memory) + { + string memory accountString = CommandUtils.addressToChecksumHexString(account); + string memory command = string.concat("Accept guardian request for ", accountString); + bytes32 nullifier = generateNewNullifier(); + + bytes32 accountSalt; + if (optionalAccountSalt == bytes32(0)) { + accountSalt = getAccountSaltForGuardian(account, guardian); + } else { + accountSalt = optionalAccountSalt; + } + + EmailProof memory emailProof = generateMockEmailProof(command, nullifier, accountSalt); + + bytes[] memory commandParamsForAcceptance = new bytes[](1); + commandParamsForAcceptance[0] = abi.encode(account); + return EmailAuthMsg({ + templateId: IEmailRecoveryModule(emailRecoveryModule).computeAcceptanceTemplateId( + templateIdx + ), + commandParams: commandParamsForAcceptance, + skippedCommandPrefix: 0, + proof: emailProof + }); + } + + function getAccountSaltForGuardian( + address account, + address guardian + ) + public + view + returns (bytes32) + { + address[] memory guardians; + if (account == instance1.account) { + guardians = guardians1; + } else if (account == instance2.account) { + guardians = guardians2; + } else if (account == instance3.account) { + guardians = guardians3; + } else { + revert("getAccountSaltForGuardian - Invalid account address"); + } + if (guardian == guardians[0]) { + return accountSalt1; + } + if (guardian == guardians[1]) { + return accountSalt2; + } + if (guardian == guardians[2]) { + return accountSalt3; + } + + revert("getAccountSaltForGuardian - Invalid guardian address"); + } + + function generateNewNullifier() public returns (bytes32) { + return keccak256(abi.encode(nullifierCount++)); + } +} diff --git a/test/integration/EmailRecoveryManager/EmailRecoveryManager.integration.t.sol b/test/integration/EmailRecoveryManager/EmailRecoveryManager.integration.t.sol index 0abe8f19..6cb1e235 100644 --- a/test/integration/EmailRecoveryManager/EmailRecoveryManager.integration.t.sol +++ b/test/integration/EmailRecoveryManager/EmailRecoveryManager.integration.t.sol @@ -25,18 +25,19 @@ contract EmailRecoveryManager_Integration_Test is function test_RevertWhen_HandleAcceptanceCalled_BeforeConfigureRecovery() public { vm.prank(accountAddress1); - instance1.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); vm.stopPrank(); - EmailAuthMsg memory emailAuthMsg = - getAcceptanceEmailAuthMessage(accountAddress1, guardians1[0]); + EmailAuthMsg memory emailAuthMsg = getAcceptanceEmailAuthMessage( + accountAddress1, guardians1[0], emailRecoveryModuleAddress + ); vm.expectRevert(IEmailRecoveryManager.RecoveryIsNotActivated.selector); emailRecoveryModule.handleAcceptance(emailAuthMsg, templateIdx); } function test_RevertWhen_HandleRecoveryCalled_BeforeTimeStampChanged() public { - acceptGuardian(accountAddress1, guardians1[0]); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); EmailAuthMsg memory emailAuthMsg = getRecoveryEmailAuthMessage(accountAddress1, guardians1[0], recoveryDataHash1); @@ -46,13 +47,14 @@ contract EmailRecoveryManager_Integration_Test is } function test_RevertWhen_HandleAcceptanceCalled_DuringRecovery() public { - acceptGuardian(accountAddress1, guardians1[0]); - acceptGuardian(accountAddress1, guardians1[1]); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(accountAddress1, guardians1[0], recoveryDataHash1); - EmailAuthMsg memory emailAuthMsg = - getAcceptanceEmailAuthMessage(accountAddress1, guardians1[1]); + EmailAuthMsg memory emailAuthMsg = getAcceptanceEmailAuthMessage( + accountAddress1, guardians1[1], emailRecoveryModuleAddress + ); vm.expectRevert(IGuardianManager.RecoveryInProcess.selector); emailRecoveryModule.handleAcceptance(emailAuthMsg, templateIdx); @@ -62,29 +64,30 @@ contract EmailRecoveryManager_Integration_Test is ) public { - acceptGuardian(accountAddress1, guardians1[0]); - acceptGuardian(accountAddress1, guardians1[1]); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(accountAddress1, guardians1[0], recoveryDataHash1); handleRecovery(accountAddress1, guardians1[1], recoveryDataHash1); - EmailAuthMsg memory emailAuthMsg = - getAcceptanceEmailAuthMessage(accountAddress1, guardians1[2]); + EmailAuthMsg memory emailAuthMsg = getAcceptanceEmailAuthMessage( + accountAddress1, guardians1[2], emailRecoveryModuleAddress + ); vm.expectRevert(IGuardianManager.RecoveryInProcess.selector); emailRecoveryModule.handleAcceptance(emailAuthMsg, templateIdx); } function test_HandleNewAcceptanceSucceeds_AfterCompleteRecovery() public { - acceptGuardian(accountAddress1, guardians1[0]); - acceptGuardian(accountAddress1, guardians1[1]); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(accountAddress1, guardians1[0], recoveryDataHash1); handleRecovery(accountAddress1, guardians1[1], recoveryDataHash1); vm.warp(block.timestamp + delay); emailRecoveryModule.completeRecovery(accountAddress1, recoveryData1); - acceptGuardian(accountAddress1, guardians1[2]); + acceptGuardian(accountAddress1, guardians1[2], emailRecoveryModuleAddress); GuardianStorage memory guardianStorage = emailRecoveryModule.getGuardian(accountAddress1, guardians1[2]); @@ -94,7 +97,7 @@ contract EmailRecoveryManager_Integration_Test is function test_RevertWhen_HandleRecoveryCalled_BeforeConfigureRecovery() public { vm.prank(accountAddress1); - instance1.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); vm.stopPrank(); EmailAuthMsg memory emailAuthMsg = @@ -115,8 +118,8 @@ contract EmailRecoveryManager_Integration_Test is function test_RevertWhen_HandleRecoveryCalled_DuringRecoveryWithoutGuardianBeingDeployed() public { - acceptGuardian(accountAddress1, guardians1[0]); - acceptGuardian(accountAddress1, guardians1[1]); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(accountAddress1, guardians1[0], recoveryDataHash1); @@ -130,8 +133,8 @@ contract EmailRecoveryManager_Integration_Test is function test_RevertWhen_HandleRecoveryCalled_AfterRecoveryProcessedButBeforeCompleteRecovery() public { - acceptGuardian(accountAddress1, guardians1[0]); - acceptGuardian(accountAddress1, guardians1[1]); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(accountAddress1, guardians1[0], recoveryDataHash1); handleRecovery(accountAddress1, guardians1[1], recoveryDataHash1); @@ -144,9 +147,9 @@ contract EmailRecoveryManager_Integration_Test is } function test_HandleRecoveryCalled_AfterCompleteRecoveryStartsNewRecoveryRequest() public { - acceptGuardian(accountAddress1, guardians1[0]); - acceptGuardian(accountAddress1, guardians1[1]); - acceptGuardian(accountAddress1, guardians1[2]); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[2], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(accountAddress1, guardians1[0], recoveryDataHash1); handleRecovery(accountAddress1, guardians1[1], recoveryDataHash1); @@ -167,7 +170,7 @@ contract EmailRecoveryManager_Integration_Test is function test_RevertWhen_CompleteRecoveryCalled_BeforeConfigureRecovery() public { vm.prank(accountAddress1); - instance1.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); vm.stopPrank(); vm.expectRevert(IEmailRecoveryManager.NoRecoveryConfigured.selector); @@ -182,7 +185,7 @@ contract EmailRecoveryManager_Integration_Test is } function test_RevertWhen_CompleteRecoveryCalled_BeforeProcessRecovery() public { - acceptGuardian(accountAddress1, guardians1[0]); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); vm.expectRevert( abi.encodeWithSelector(IEmailRecoveryManager.NotEnoughApprovals.selector, 0, threshold) @@ -191,15 +194,18 @@ contract EmailRecoveryManager_Integration_Test is } function test_TryRecoverFunctionsWhenModuleNotInstalled() public { - EmailAuthMsg memory emailAuthMsg = - getAcceptanceEmailAuthMessage(accountAddress1, guardians1[0]); + EmailAuthMsg memory emailAuthMsg = getAcceptanceEmailAuthMessage( + accountAddress1, guardians1[0], emailRecoveryModuleAddress + ); emailRecoveryModule.handleAcceptance(emailAuthMsg, templateIdx); - emailAuthMsg = getAcceptanceEmailAuthMessage(accountAddress1, guardians1[1]); + emailAuthMsg = getAcceptanceEmailAuthMessage( + accountAddress1, guardians1[1], emailRecoveryModuleAddress + ); emailRecoveryModule.handleAcceptance(emailAuthMsg, templateIdx); vm.prank(accountAddress1); - instance1.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); vm.stopPrank(); vm.warp(12 seconds); @@ -217,7 +223,7 @@ contract EmailRecoveryManager_Integration_Test is function test_TryCompleteRecoveryWhenModuleNotInstalled() public { vm.prank(accountAddress1); - instance1.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); vm.stopPrank(); vm.expectRevert(IEmailRecoveryManager.NoRecoveryConfigured.selector); @@ -225,8 +231,8 @@ contract EmailRecoveryManager_Integration_Test is } function test_StaleRecoveryRequest() public { - acceptGuardian(accountAddress1, guardians1[0]); - acceptGuardian(accountAddress1, guardians1[1]); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(accountAddress1, guardians1[0], recoveryDataHash1); handleRecovery(accountAddress1, guardians1[1], recoveryDataHash1); @@ -255,8 +261,8 @@ contract EmailRecoveryManager_Integration_Test is } function test_CancelExpiredRecoveryRequest() public { - acceptGuardian(accountAddress1, guardians1[0]); - acceptGuardian(accountAddress1, guardians1[1]); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(accountAddress1, guardians1[0], recoveryDataHash1); handleRecovery(accountAddress1, guardians1[1], recoveryDataHash1); @@ -284,8 +290,8 @@ contract EmailRecoveryManager_Integration_Test is } function test_CannotComplete_CancelledExpiredRecoveryRequest() public { - acceptGuardian(accountAddress1, guardians1[0]); - acceptGuardian(accountAddress1, guardians1[1]); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(accountAddress1, guardians1[0], recoveryDataHash1); handleRecovery(accountAddress1, guardians1[1], recoveryDataHash1); diff --git a/test/integration/IntegrationBase.t.sol b/test/integration/IntegrationBase.t.sol index 93d6d4be..6f32e81e 100644 --- a/test/integration/IntegrationBase.t.sol +++ b/test/integration/IntegrationBase.t.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.25; -import { RhinestoneModuleKit, AccountInstance } from "modulekit/ModuleKit.sol"; +import { AccountInstance } from "modulekit/ModuleKit.sol"; import { ECDSAOwnedDKIMRegistry } from "@zk-email/ether-email-auth-contracts/src/utils/ECDSAOwnedDKIMRegistry.sol"; import { EmailAuth } from "@zk-email/ether-email-auth-contracts/src/EmailAuth.sol"; @@ -11,105 +11,8 @@ import { BaseTest } from "test/Base.t.sol"; import { MockGroth16Verifier } from "src/test/MockGroth16Verifier.sol"; import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; -abstract contract IntegrationBase is RhinestoneModuleKit, BaseTest { - // ZK Email contracts and variables - address zkEmailDeployer = vm.addr(1); - ECDSAOwnedDKIMRegistry dkimRegistry; - MockGroth16Verifier verifier; - EmailAuth emailAuthImpl; - - // account and owners - AccountInstance instance1; - AccountInstance instance2; - AccountInstance instance3; - address accountAddress1; - address accountAddress2; - address accountAddress3; - address owner1; - address owner2; - address owner3; - address newOwner1; - address newOwner2; - address newOwner3; - - // recovery config - address[] guardians1; - address[] guardians2; - address[] guardians3; - uint256[] guardianWeights; - uint256 totalWeight; - uint256 delay; - uint256 expiry; - uint256 threshold; - uint256 templateIdx; - - // Account salts - bytes32 accountSalt1; - bytes32 accountSalt2; - bytes32 accountSalt3; - - string selector = "12345"; - string domainName = "gmail.com"; - bytes32 publicKeyHash = 0x0ea9c777dc7110e5a9e89b13f0cfc540e3845ba120b2b6dc24024d61488d4788; - - function setUp() public virtual { - init(); - - // Create ZK Email contracts - vm.startPrank(zkEmailDeployer); - { - ECDSAOwnedDKIMRegistry dkimImpl = new ECDSAOwnedDKIMRegistry(); - ERC1967Proxy dkimProxy = new ERC1967Proxy( - address(dkimImpl), - abi.encodeCall(dkimImpl.initialize, (zkEmailDeployer, zkEmailDeployer)) - ); - dkimRegistry = ECDSAOwnedDKIMRegistry(address(dkimProxy)); - } - - 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); - dkimRegistry.setDKIMPublicKeyHash(selector, domainName, publicKeyHash, signature); - - verifier = new MockGroth16Verifier(); - emailAuthImpl = new EmailAuth(); - vm.stopPrank(); - - // create owners - owner1 = vm.createWallet("owner1").addr; - owner2 = vm.createWallet("owner2").addr; - owner3 = vm.createWallet("owner3").addr; - newOwner1 = vm.createWallet("newOwner1").addr; - newOwner2 = vm.createWallet("newOwner2").addr; - newOwner3 = vm.createWallet("newOwner3").addr; - - // Deploy and fund the accounts - instance1 = makeAccountInstance("account1"); - instance2 = makeAccountInstance("account2"); - instance3 = makeAccountInstance("account3"); - accountAddress1 = instance1.account; - accountAddress2 = instance2.account; - accountAddress3 = instance3.account; - vm.deal(address(instance1.account), 10 ether); - vm.deal(address(instance2.account), 10 ether); - vm.deal(address(instance3.account), 10 ether); - - accountSalt1 = keccak256(abi.encode("account salt 1")); - accountSalt2 = keccak256(abi.encode("account salt 2")); - accountSalt3 = keccak256(abi.encode("account salt 3")); - - // Set recovery config variables - guardianWeights = new uint256[](3); - guardianWeights[0] = 1; - guardianWeights[1] = 2; - guardianWeights[2] = 1; - totalWeight = 4; - delay = 1 seconds; - expiry = 2 weeks; - threshold = 3; - templateIdx = 0; +abstract contract IntegrationBase is BaseTest { + function setUp() public virtual override { + super.setUp(); } } diff --git a/test/integration/OwnableValidatorRecovery/EmailRecoveryModule/EmailRecoveryModule.t.sol b/test/integration/OwnableValidatorRecovery/EmailRecoveryModule/EmailRecoveryModule.t.sol index 9db31821..2842fe2e 100644 --- a/test/integration/OwnableValidatorRecovery/EmailRecoveryModule/EmailRecoveryModule.t.sol +++ b/test/integration/OwnableValidatorRecovery/EmailRecoveryModule/EmailRecoveryModule.t.sol @@ -29,8 +29,8 @@ contract OwnableValidatorRecovery_EmailRecoveryModule_Integration_Test is ) internal { - acceptGuardian(account, guardians[0]); - acceptGuardian(account, guardians[1]); + acceptGuardian(account, guardians[0], emailRecoveryModuleAddress); + acceptGuardian(account, guardians[1], emailRecoveryModuleAddress); vm.warp(block.timestamp + 12 seconds); handleRecovery(account, guardians[0], recoveryDataHash); handleRecovery(account, guardians[1], recoveryDataHash); @@ -44,14 +44,14 @@ contract OwnableValidatorRecovery_EmailRecoveryModule_Integration_Test is function test_Recover_RotatesOwnerSuccessfully() public { // Accept guardian 1 - acceptGuardian(accountAddress1, guardians1[0]); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); GuardianStorage memory guardianStorage1 = emailRecoveryModule.getGuardian(accountAddress1, guardians1[0]); assertEq(uint256(guardianStorage1.status), uint256(GuardianStatus.ACCEPTED)); assertEq(guardianStorage1.weight, uint256(1)); // Accept guardian 2 - acceptGuardian(accountAddress1, guardians1[1]); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); GuardianStorage memory guardianStorage2 = emailRecoveryModule.getGuardian(accountAddress1, guardians1[1]); assertEq(uint256(guardianStorage2.status), uint256(GuardianStatus.ACCEPTED)); @@ -95,8 +95,10 @@ contract OwnableValidatorRecovery_EmailRecoveryModule_Integration_Test is } function test_Recover_RevertWhen_MixAccountHandleAcceptance() public { - acceptGuardian(accountAddress1, guardians1[0]); - acceptGuardianWithAccountSalt(accountAddress2, guardians1[1], accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardianWithAccountSalt( + accountAddress2, guardians1[1], emailRecoveryModuleAddress, accountSalt2 + ); vm.warp(12 seconds); EmailAuthMsg memory emailAuthMsg = @@ -117,10 +119,12 @@ contract OwnableValidatorRecovery_EmailRecoveryModule_Integration_Test is } function test_Recover_RevertWhen_MixAccountHandleRecovery() public { - acceptGuardianWithAccountSalt(accountAddress2, guardians1[1], accountSalt2); + acceptGuardianWithAccountSalt( + accountAddress2, guardians1[1], emailRecoveryModuleAddress, accountSalt2 + ); - acceptGuardian(accountAddress1, guardians1[0]); - acceptGuardian(accountAddress1, guardians1[1]); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(block.timestamp + 12 seconds); handleRecovery(accountAddress1, guardians1[0], recoveryDataHash1); @@ -139,10 +143,11 @@ contract OwnableValidatorRecovery_EmailRecoveryModule_Integration_Test is } function test_Recover_RevertWhen_UninstallModuleBeforeAnyGuardiansAccepted() public { - instance1.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); - EmailAuthMsg memory emailAuthMsg = - getAcceptanceEmailAuthMessage(accountAddress1, guardians1[0]); + EmailAuthMsg memory emailAuthMsg = getAcceptanceEmailAuthMessage( + accountAddress1, guardians1[0], emailRecoveryModuleAddress + ); vm.expectRevert(IEmailRecoveryManager.RecoveryIsNotActivated.selector); emailRecoveryModule.handleAcceptance(emailAuthMsg, templateIdx); @@ -151,11 +156,12 @@ contract OwnableValidatorRecovery_EmailRecoveryModule_Integration_Test is function test_Recover_RevertWhen_UninstallModuleBeforeEnoughAcceptedAndTryHandleAcceptance() public { - acceptGuardian(accountAddress1, guardians1[0]); - instance1.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); - EmailAuthMsg memory emailAuthMsg = - getAcceptanceEmailAuthMessage(accountAddress1, guardians1[1]); + EmailAuthMsg memory emailAuthMsg = getAcceptanceEmailAuthMessage( + accountAddress1, guardians1[1], emailRecoveryModuleAddress + ); vm.expectRevert(IEmailRecoveryManager.RecoveryIsNotActivated.selector); emailRecoveryModule.handleAcceptance(emailAuthMsg, templateIdx); @@ -164,22 +170,22 @@ contract OwnableValidatorRecovery_EmailRecoveryModule_Integration_Test is function test_Recover_RevertWhen_UninstallModuleAfterEnoughAcceptedAndTryHandleRecovery() public { - acceptGuardian(accountAddress1, guardians1[0]); - acceptGuardian(accountAddress1, guardians1[1]); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); EmailAuthMsg memory emailAuthMsg = getRecoveryEmailAuthMessage(accountAddress1, guardians1[0], recoveryDataHash1); - instance1.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); vm.expectRevert(IEmailRecoveryManager.RecoveryIsNotActivated.selector); emailRecoveryModule.handleRecovery(emailAuthMsg, templateIdx); } function test_Recover_RevertWhen_UninstallModuleAfterOneApprovalAndTryHandleRecovery() public { - acceptGuardian(accountAddress1, guardians1[0]); - acceptGuardian(accountAddress1, guardians1[1]); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(accountAddress1, guardians1[0], recoveryDataHash1); @@ -191,8 +197,8 @@ contract OwnableValidatorRecovery_EmailRecoveryModule_Integration_Test is function test_Recover_RevertWhen_UninstallModuleProcessRecoveryAndTryCompleteRecovery() public { - acceptGuardian(accountAddress1, guardians1[0]); - acceptGuardian(accountAddress1, guardians1[1]); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(accountAddress1, guardians1[0], recoveryDataHash1); handleRecovery(accountAddress1, guardians1[1], recoveryDataHash1); @@ -208,10 +214,11 @@ contract OwnableValidatorRecovery_EmailRecoveryModule_Integration_Test is address updatedOwner1 = validator.owners(accountAddress1); assertEq(updatedOwner1, newOwner1); - instance1.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); - EmailAuthMsg memory emailAuthMsg = - getAcceptanceEmailAuthMessage(accountAddress1, guardians1[0]); + EmailAuthMsg memory emailAuthMsg = getAcceptanceEmailAuthMessage( + accountAddress1, guardians1[0], emailRecoveryModuleAddress + ); vm.expectRevert(IEmailRecoveryManager.RecoveryIsNotActivated.selector); emailRecoveryModule.handleAcceptance(emailAuthMsg, templateIdx); @@ -222,10 +229,10 @@ contract OwnableValidatorRecovery_EmailRecoveryModule_Integration_Test is address updatedOwner = validator.owners(accountAddress1); assertEq(updatedOwner, newOwner1); - instance1.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); instance1.installModule({ moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, + module: emailRecoveryModuleAddress, data: abi.encode(isInstalledContext, guardians1, guardianWeights, threshold, delay, expiry) }); diff --git a/test/integration/OwnableValidatorRecovery/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol b/test/integration/OwnableValidatorRecovery/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol index d61248f6..a17b003d 100644 --- a/test/integration/OwnableValidatorRecovery/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol +++ b/test/integration/OwnableValidatorRecovery/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol @@ -27,12 +27,10 @@ abstract contract OwnableValidatorRecovery_EmailRecoveryModule_Base is Integrati EmailRecoveryCommandHandler emailRecoveryHandler; EmailRecoveryModule emailRecoveryModule; - address recoveryModuleAddress; - address validatorAddress; + address emailRecoveryModuleAddress; - OwnableValidator validator; bytes isInstalledContext; - bytes4 functionSelector; + bytes4 constant functionSelector = bytes4(keccak256(bytes("changeOwner(address)"))); bytes recoveryData1; bytes recoveryData2; bytes recoveryData3; @@ -40,33 +38,10 @@ abstract contract OwnableValidatorRecovery_EmailRecoveryModule_Base is Integrati bytes32 recoveryDataHash2; bytes32 recoveryDataHash3; - uint256 nullifierCount; - function setUp() public virtual override { super.setUp(); - // Deploy validator to be recovered - validator = new OwnableValidator(); - validatorAddress = address(validator); isInstalledContext = bytes("0"); - functionSelector = bytes4(keccak256(bytes("changeOwner(address)"))); - - emailRecoveryFactory = new EmailRecoveryFactory(address(verifier), address(emailAuthImpl)); - emailRecoveryHandler = new EmailRecoveryCommandHandler(); - - // Deploy EmailRecoveryManager & EmailRecoveryModule - bytes32 commandHandlerSalt = bytes32(uint256(0)); - bytes32 recoveryModuleSalt = bytes32(uint256(0)); - bytes memory commandHandlerBytecode = type(EmailRecoveryCommandHandler).creationCode; - (recoveryModuleAddress,) = emailRecoveryFactory.deployEmailRecoveryModule( - commandHandlerSalt, - recoveryModuleSalt, - commandHandlerBytecode, - address(dkimRegistry), - validatorAddress, - functionSelector - ); - emailRecoveryModule = EmailRecoveryModule(recoveryModuleAddress); bytes memory changeOwnerCalldata1 = abi.encodeWithSelector(functionSelector, newOwner1); bytes memory changeOwnerCalldata2 = abi.encodeWithSelector(functionSelector, newOwner2); @@ -78,20 +53,6 @@ abstract contract OwnableValidatorRecovery_EmailRecoveryModule_Base is Integrati recoveryDataHash2 = keccak256(recoveryData2); recoveryDataHash3 = keccak256(recoveryData3); - // Compute guardian addresses - guardians1 = new address[](3); - guardians1[0] = emailRecoveryModule.computeEmailAuthAddress(instance1.account, accountSalt1); - guardians1[1] = emailRecoveryModule.computeEmailAuthAddress(instance1.account, accountSalt2); - guardians1[2] = emailRecoveryModule.computeEmailAuthAddress(instance1.account, accountSalt3); - guardians2 = new address[](3); - guardians2[0] = emailRecoveryModule.computeEmailAuthAddress(instance2.account, accountSalt1); - guardians2[1] = emailRecoveryModule.computeEmailAuthAddress(instance2.account, accountSalt2); - guardians2[2] = emailRecoveryModule.computeEmailAuthAddress(instance2.account, accountSalt3); - guardians3 = new address[](3); - guardians3[0] = emailRecoveryModule.computeEmailAuthAddress(instance3.account, accountSalt1); - guardians3[1] = emailRecoveryModule.computeEmailAuthAddress(instance3.account, accountSalt2); - guardians3[2] = emailRecoveryModule.computeEmailAuthAddress(instance3.account, accountSalt3); - bytes memory recoveryModuleInstallData1 = abi.encode(isInstalledContext, guardians1, guardianWeights, threshold, delay, expiry); bytes memory recoveryModuleInstallData2 = @@ -107,7 +68,7 @@ abstract contract OwnableValidatorRecovery_EmailRecoveryModule_Base is Integrati }); instance1.installModule({ moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, + module: emailRecoveryModuleAddress, data: recoveryModuleInstallData1 }); @@ -119,7 +80,7 @@ abstract contract OwnableValidatorRecovery_EmailRecoveryModule_Base is Integrati }); instance2.installModule({ moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, + module: emailRecoveryModuleAddress, data: recoveryModuleInstallData2 }); @@ -131,132 +92,43 @@ abstract contract OwnableValidatorRecovery_EmailRecoveryModule_Base is Integrati }); instance3.installModule({ moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, + module: emailRecoveryModuleAddress, data: recoveryModuleInstallData3 }); } // Helper functions - function generateMockEmailProof( - string memory command, - bytes32 nullifier, - bytes32 accountSalt - ) - public - view - returns (EmailProof memory) - { - EmailProof memory emailProof; - emailProof.domainName = "gmail.com"; - emailProof.publicKeyHash = bytes32( - vm.parseUint( - "6632353713085157925504008443078919716322386156160602218536961028046468237192" - ) - ); - emailProof.timestamp = block.timestamp; - emailProof.maskedCommand = command; - emailProof.emailNullifier = nullifier; - emailProof.accountSalt = accountSalt; - emailProof.isCodeExist = true; - emailProof.proof = bytes("0"); - - return emailProof; - } - - function getAccountSaltForGuardian( + function computeEmailAuthAddress( address account, - address guardian + bytes32 accountSalt ) public view - returns (bytes32) - { - address[] memory guardians; - if (account == instance1.account) { - guardians = guardians1; - } else if (account == instance2.account) { - guardians = guardians2; - } else if (account == instance3.account) { - guardians = guardians3; - } else { - revert("Invalid account address"); - } - if (guardian == guardians[0]) { - return accountSalt1; - } - if (guardian == guardians[1]) { - return accountSalt2; - } - if (guardian == guardians[2]) { - return accountSalt3; - } - - revert("Invalid guardian address"); - } - - function generateNewNullifier() public returns (bytes32) { - return keccak256(abi.encode(nullifierCount++)); - } - - function acceptGuardian(address account, address guardian) public { - EmailAuthMsg memory emailAuthMsg = getAcceptanceEmailAuthMessage(account, guardian); - emailRecoveryModule.handleAcceptance(emailAuthMsg, templateIdx); - } - - // WithAccountSalt variation - used for creating incorrect recovery setups - function acceptGuardianWithAccountSalt( - address account, - address guardian, - bytes32 optionalAccountSalt - ) - public - { - EmailAuthMsg memory emailAuthMsg = - getAcceptanceEmailAuthMessageWithAccountSalt(account, guardian, optionalAccountSalt); - emailRecoveryModule.handleAcceptance(emailAuthMsg, templateIdx); - } - - function getAcceptanceEmailAuthMessage( - address account, - address guardian - ) - public - returns (EmailAuthMsg memory) + override + returns (address) { - return getAcceptanceEmailAuthMessageWithAccountSalt(account, guardian, bytes32(0)); + return emailRecoveryModule.computeEmailAuthAddress(account, accountSalt); } - // WithAccountSalt variation - used for creating incorrect recovery setups - function getAcceptanceEmailAuthMessageWithAccountSalt( - address account, - address guardian, - bytes32 optionalAccountSalt - ) - public - returns (EmailAuthMsg memory) - { - string memory accountString = CommandUtils.addressToChecksumHexString(account); - string memory command = string.concat("Accept guardian request for ", accountString); - bytes32 nullifier = generateNewNullifier(); - - bytes32 accountSalt; - if (optionalAccountSalt == bytes32(0)) { - accountSalt = getAccountSaltForGuardian(account, guardian); - } else { - accountSalt = optionalAccountSalt; - } - - EmailProof memory emailProof = generateMockEmailProof(command, nullifier, accountSalt); + function deployModule() public override { + // Deploy handler, manager and module + emailRecoveryFactory = new EmailRecoveryFactory(address(verifier), address(emailAuthImpl)); + emailRecoveryHandler = new EmailRecoveryCommandHandler(); - bytes[] memory commandParamsForAcceptance = new bytes[](1); - commandParamsForAcceptance[0] = abi.encode(account); - return EmailAuthMsg({ - templateId: emailRecoveryModule.computeAcceptanceTemplateId(templateIdx), - commandParams: commandParamsForAcceptance, - skippedCommandPrefix: 0, - proof: emailProof - }); + // Deploy EmailRecoveryManager & EmailRecoveryModule + bytes32 commandHandlerSalt = bytes32(uint256(0)); + bytes32 recoveryModuleSalt = bytes32(uint256(0)); + bytes memory commandHandlerBytecode = type(EmailRecoveryCommandHandler).creationCode; + (emailRecoveryModuleAddress,) = emailRecoveryFactory.deployEmailRecoveryModule( + commandHandlerSalt, + recoveryModuleSalt, + commandHandlerBytecode, + address(dkimRegistry), + validatorAddress, + functionSelector + ); + emailRecoveryModule = EmailRecoveryModule(emailRecoveryModuleAddress); } function handleRecovery(address account, address guardian, bytes32 recoveryDataHash) public { diff --git a/test/integration/OwnableValidatorRecovery/UniversalEmailRecoveryModule/UniversalEmailRecoveryModule.t.sol b/test/integration/OwnableValidatorRecovery/UniversalEmailRecoveryModule/UniversalEmailRecoveryModule.t.sol index dad08f4c..dab760ba 100644 --- a/test/integration/OwnableValidatorRecovery/UniversalEmailRecoveryModule/UniversalEmailRecoveryModule.t.sol +++ b/test/integration/OwnableValidatorRecovery/UniversalEmailRecoveryModule/UniversalEmailRecoveryModule.t.sol @@ -28,8 +28,8 @@ contract OwnableValidatorRecovery_UniversalEmailRecoveryModule_Integration_Test ) internal { - acceptGuardian(account, guardians[0]); - acceptGuardian(account, guardians[1]); + acceptGuardian(account, guardians[0], emailRecoveryModuleAddress); + acceptGuardian(account, guardians[1], emailRecoveryModuleAddress); vm.warp(block.timestamp + 12 seconds); handleRecovery(account, guardians[0], recoveryDataHash); handleRecovery(account, guardians[1], recoveryDataHash); @@ -43,14 +43,14 @@ contract OwnableValidatorRecovery_UniversalEmailRecoveryModule_Integration_Test function test_Recover_RotatesOwnerSuccessfully() public { // Accept guardian 1 - acceptGuardian(accountAddress1, guardians1[0]); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); GuardianStorage memory guardianStorage1 = emailRecoveryModule.getGuardian(accountAddress1, guardians1[0]); assertEq(uint256(guardianStorage1.status), uint256(GuardianStatus.ACCEPTED)); assertEq(guardianStorage1.weight, uint256(1)); // Accept guardian 2 - acceptGuardian(accountAddress1, guardians1[1]); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); GuardianStorage memory guardianStorage2 = emailRecoveryModule.getGuardian(accountAddress1, guardians1[1]); assertEq(uint256(guardianStorage2.status), uint256(GuardianStatus.ACCEPTED)); @@ -94,8 +94,10 @@ contract OwnableValidatorRecovery_UniversalEmailRecoveryModule_Integration_Test } function test_Recover_RevertWhen_MixAccountHandleAcceptance() public { - acceptGuardian(accountAddress1, guardians1[0]); - acceptGuardianWithAccountSalt(accountAddress2, guardians1[1], accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardianWithAccountSalt( + accountAddress2, guardians1[1], emailRecoveryModuleAddress, accountSalt2 + ); vm.warp(12 seconds); EmailAuthMsg memory emailAuthMsg = @@ -116,10 +118,12 @@ contract OwnableValidatorRecovery_UniversalEmailRecoveryModule_Integration_Test } function test_Recover_RevertWhen_MixAccountHandleRecovery() public { - acceptGuardianWithAccountSalt(accountAddress2, guardians1[1], accountSalt2); + acceptGuardianWithAccountSalt( + accountAddress2, guardians1[1], emailRecoveryModuleAddress, accountSalt2 + ); - acceptGuardian(accountAddress1, guardians1[0]); - acceptGuardian(accountAddress1, guardians1[1]); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(accountAddress1, guardians1[0], recoveryDataHash1); @@ -138,10 +142,11 @@ contract OwnableValidatorRecovery_UniversalEmailRecoveryModule_Integration_Test } function test_Recover_RevertWhen_UninstallModuleBeforeAnyGuardiansAccepted() public { - instance1.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); - EmailAuthMsg memory emailAuthMsg = - getAcceptanceEmailAuthMessage(accountAddress1, guardians1[0]); + EmailAuthMsg memory emailAuthMsg = getAcceptanceEmailAuthMessage( + accountAddress1, guardians1[0], emailRecoveryModuleAddress + ); vm.expectRevert(IEmailRecoveryManager.RecoveryIsNotActivated.selector); emailRecoveryModule.handleAcceptance(emailAuthMsg, templateIdx); @@ -150,11 +155,12 @@ contract OwnableValidatorRecovery_UniversalEmailRecoveryModule_Integration_Test function test_Recover_RevertWhen_UninstallModuleBeforeEnoughAcceptedAndTryHandleAcceptance() public { - acceptGuardian(accountAddress1, guardians1[0]); - instance1.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); - EmailAuthMsg memory emailAuthMsg = - getAcceptanceEmailAuthMessage(accountAddress1, guardians1[1]); + EmailAuthMsg memory emailAuthMsg = getAcceptanceEmailAuthMessage( + accountAddress1, guardians1[1], emailRecoveryModuleAddress + ); vm.expectRevert(IEmailRecoveryManager.RecoveryIsNotActivated.selector); emailRecoveryModule.handleAcceptance(emailAuthMsg, templateIdx); @@ -163,22 +169,22 @@ contract OwnableValidatorRecovery_UniversalEmailRecoveryModule_Integration_Test function test_Recover_RevertWhen_UninstallModuleAfterEnoughAcceptedAndTryHandleRecovery() public { - acceptGuardian(accountAddress1, guardians1[0]); - acceptGuardian(accountAddress1, guardians1[1]); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); EmailAuthMsg memory emailAuthMsg = getRecoveryEmailAuthMessage(accountAddress1, guardians1[0], recoveryDataHash1); - instance1.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); vm.expectRevert(IEmailRecoveryManager.RecoveryIsNotActivated.selector); emailRecoveryModule.handleRecovery(emailAuthMsg, templateIdx); } function test_Recover_RevertWhen_UninstallModuleAfterOneApprovalAndTryHandleRecovery() public { - acceptGuardian(accountAddress1, guardians1[0]); - acceptGuardian(accountAddress1, guardians1[1]); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(accountAddress1, guardians1[0], recoveryDataHash1); @@ -190,8 +196,8 @@ contract OwnableValidatorRecovery_UniversalEmailRecoveryModule_Integration_Test function test_Recover_RevertWhen_UninstallModuleProcessRecoveryAndTryCompleteRecovery() public { - acceptGuardian(accountAddress1, guardians1[0]); - acceptGuardian(accountAddress1, guardians1[1]); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(accountAddress1, guardians1[0], recoveryDataHash1); handleRecovery(accountAddress1, guardians1[1], recoveryDataHash1); @@ -207,10 +213,11 @@ contract OwnableValidatorRecovery_UniversalEmailRecoveryModule_Integration_Test address updatedOwner1 = validator.owners(accountAddress1); assertEq(updatedOwner1, newOwner1); - instance1.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); - EmailAuthMsg memory emailAuthMsg = - getAcceptanceEmailAuthMessage(accountAddress1, guardians1[0]); + EmailAuthMsg memory emailAuthMsg = getAcceptanceEmailAuthMessage( + accountAddress1, guardians1[0], emailRecoveryModuleAddress + ); vm.expectRevert(IEmailRecoveryManager.RecoveryIsNotActivated.selector); emailRecoveryModule.handleAcceptance(emailAuthMsg, templateIdx); @@ -221,10 +228,10 @@ contract OwnableValidatorRecovery_UniversalEmailRecoveryModule_Integration_Test address updatedOwner = validator.owners(accountAddress1); assertEq(updatedOwner, newOwner1); - instance1.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); instance1.installModule({ moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, + module: emailRecoveryModuleAddress, data: abi.encode( validatorAddress, isInstalledContext, @@ -354,8 +361,8 @@ contract OwnableValidatorRecovery_UniversalEmailRecoveryModule_Integration_Test bytes32 validator2RecoveryDataHash = keccak256(validator2RecoveryData); // Accept guardians - acceptGuardian(accountAddress1, guardians1[0]); - acceptGuardian(accountAddress1, guardians1[1]); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(block.timestamp + 12 seconds); // process recovery for validator 1 diff --git a/test/integration/OwnableValidatorRecovery/UniversalEmailRecoveryModule/UniversalEmailRecoveryModuleBase.t.sol b/test/integration/OwnableValidatorRecovery/UniversalEmailRecoveryModule/UniversalEmailRecoveryModuleBase.t.sol index e822eeca..3b2ee7cf 100644 --- a/test/integration/OwnableValidatorRecovery/UniversalEmailRecoveryModule/UniversalEmailRecoveryModuleBase.t.sol +++ b/test/integration/OwnableValidatorRecovery/UniversalEmailRecoveryModule/UniversalEmailRecoveryModuleBase.t.sol @@ -29,10 +29,8 @@ abstract contract OwnableValidatorRecovery_UniversalEmailRecoveryModule_Base is EmailRecoveryCommandHandler emailRecoveryHandler; UniversalEmailRecoveryModuleHarness emailRecoveryModule; - address recoveryModuleAddress; - address validatorAddress; + address emailRecoveryModuleAddress; - OwnableValidator validator; bytes isInstalledContext; bytes4 functionSelector; bytes recoveryData1; @@ -42,27 +40,9 @@ abstract contract OwnableValidatorRecovery_UniversalEmailRecoveryModule_Base is bytes32 recoveryDataHash2; bytes32 recoveryDataHash3; - uint256 nullifierCount; - function setUp() public virtual override { super.setUp(); - emailRecoveryFactory = - new EmailRecoveryUniversalFactory(address(verifier), address(emailAuthImpl)); - emailRecoveryHandler = new EmailRecoveryCommandHandler(); - - // Deploy EmailRecoveryManager & UniversalEmailRecoveryModule - emailRecoveryModule = new UniversalEmailRecoveryModuleHarness( - address(verifier), - address(dkimRegistry), - address(emailAuthImpl), - address(emailRecoveryHandler) - ); - recoveryModuleAddress = address(emailRecoveryModule); - - // Deploy validator to be recovered - validator = new OwnableValidator(); - validatorAddress = address(validator); isInstalledContext = bytes("0"); functionSelector = bytes4(keccak256(bytes("changeOwner(address)"))); bytes memory changeOwnerCalldata1 = abi.encodeWithSelector(functionSelector, newOwner1); @@ -75,20 +55,6 @@ abstract contract OwnableValidatorRecovery_UniversalEmailRecoveryModule_Base is recoveryDataHash2 = keccak256(recoveryData2); recoveryDataHash3 = keccak256(recoveryData3); - // Compute guardian addresses - guardians1 = new address[](3); - guardians1[0] = emailRecoveryModule.computeEmailAuthAddress(instance1.account, accountSalt1); - guardians1[1] = emailRecoveryModule.computeEmailAuthAddress(instance1.account, accountSalt2); - guardians1[2] = emailRecoveryModule.computeEmailAuthAddress(instance1.account, accountSalt3); - guardians2 = new address[](3); - guardians2[0] = emailRecoveryModule.computeEmailAuthAddress(instance2.account, accountSalt1); - guardians2[1] = emailRecoveryModule.computeEmailAuthAddress(instance2.account, accountSalt2); - guardians2[2] = emailRecoveryModule.computeEmailAuthAddress(instance2.account, accountSalt3); - guardians3 = new address[](3); - guardians3[0] = emailRecoveryModule.computeEmailAuthAddress(instance3.account, accountSalt1); - guardians3[1] = emailRecoveryModule.computeEmailAuthAddress(instance3.account, accountSalt2); - guardians3[2] = emailRecoveryModule.computeEmailAuthAddress(instance3.account, accountSalt3); - bytes memory recoveryModuleInstallData1 = abi.encode( validatorAddress, isInstalledContext, @@ -128,7 +94,7 @@ abstract contract OwnableValidatorRecovery_UniversalEmailRecoveryModule_Base is }); instance1.installModule({ moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, + module: emailRecoveryModuleAddress, data: recoveryModuleInstallData1 }); @@ -140,7 +106,7 @@ abstract contract OwnableValidatorRecovery_UniversalEmailRecoveryModule_Base is }); instance2.installModule({ moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, + module: emailRecoveryModuleAddress, data: recoveryModuleInstallData2 }); @@ -152,132 +118,39 @@ abstract contract OwnableValidatorRecovery_UniversalEmailRecoveryModule_Base is }); instance3.installModule({ moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, + module: emailRecoveryModuleAddress, data: recoveryModuleInstallData3 }); } // Helper functions - function generateMockEmailProof( - string memory command, - bytes32 nullifier, - bytes32 accountSalt - ) - public - view - returns (EmailProof memory) - { - EmailProof memory emailProof; - emailProof.domainName = "gmail.com"; - emailProof.publicKeyHash = bytes32( - vm.parseUint( - "6632353713085157925504008443078919716322386156160602218536961028046468237192" - ) - ); - emailProof.timestamp = block.timestamp; - emailProof.maskedCommand = command; - emailProof.emailNullifier = nullifier; - emailProof.accountSalt = accountSalt; - emailProof.isCodeExist = true; - emailProof.proof = bytes("0"); - - return emailProof; - } - - function getAccountSaltForGuardian( + function computeEmailAuthAddress( address account, - address guardian + bytes32 accountSalt ) public view - returns (bytes32) - { - address[] memory guardians; - if (account == instance1.account) { - guardians = guardians1; - } else if (account == instance2.account) { - guardians = guardians2; - } else if (account == instance3.account) { - guardians = guardians3; - } else { - revert("Invalid account address"); - } - if (guardian == guardians[0]) { - return accountSalt1; - } - if (guardian == guardians[1]) { - return accountSalt2; - } - if (guardian == guardians[2]) { - return accountSalt3; - } - - revert("Invalid guardian address"); - } - - function generateNewNullifier() public returns (bytes32) { - return keccak256(abi.encode(nullifierCount++)); - } - - function acceptGuardian(address account, address guardian) public { - EmailAuthMsg memory emailAuthMsg = getAcceptanceEmailAuthMessage(account, guardian); - emailRecoveryModule.handleAcceptance(emailAuthMsg, templateIdx); - } - - // WithAccountSalt variation - used for creating incorrect recovery setups - function acceptGuardianWithAccountSalt( - address account, - address guardian, - bytes32 optionalAccountSalt - ) - public + override + returns (address) { - EmailAuthMsg memory emailAuthMsg = - getAcceptanceEmailAuthMessageWithAccountSalt(account, guardian, optionalAccountSalt); - emailRecoveryModule.handleAcceptance(emailAuthMsg, templateIdx); + return emailRecoveryModule.computeEmailAuthAddress(account, accountSalt); } - function getAcceptanceEmailAuthMessage( - address account, - address guardian - ) - public - returns (EmailAuthMsg memory) - { - return getAcceptanceEmailAuthMessageWithAccountSalt(account, guardian, bytes32(0)); - } - - // WithAccountSalt variation - used for creating incorrect recovery setups - function getAcceptanceEmailAuthMessageWithAccountSalt( - address account, - address guardian, - bytes32 optionalAccountSalt - ) - public - returns (EmailAuthMsg memory) - { - string memory accountString = CommandUtils.addressToChecksumHexString(account); - string memory command = string.concat("Accept guardian request for ", accountString); - bytes32 nullifier = generateNewNullifier(); - - bytes32 accountSalt; - if (optionalAccountSalt == bytes32(0)) { - accountSalt = getAccountSaltForGuardian(account, guardian); - } else { - accountSalt = optionalAccountSalt; - } - - EmailProof memory emailProof = generateMockEmailProof(command, nullifier, accountSalt); + function deployModule() public override { + // Deploy handler, manager and module + emailRecoveryFactory = + new EmailRecoveryUniversalFactory(address(verifier), address(emailAuthImpl)); + emailRecoveryHandler = new EmailRecoveryCommandHandler(); - bytes[] memory commandParamsForAcceptance = new bytes[](1); - commandParamsForAcceptance[0] = abi.encode(account); - return EmailAuthMsg({ - templateId: emailRecoveryModule.computeAcceptanceTemplateId(templateIdx), - commandParams: commandParamsForAcceptance, - skippedCommandPrefix: 0, - proof: emailProof - }); + // Deploy EmailRecoveryManager & UniversalEmailRecoveryModule + emailRecoveryModule = new UniversalEmailRecoveryModuleHarness( + address(verifier), + address(dkimRegistry), + address(emailAuthImpl), + address(emailRecoveryHandler) + ); + emailRecoveryModuleAddress = address(emailRecoveryModule); } function handleRecovery(address account, address guardian, bytes32 recoveryDataHash) public { diff --git a/test/integration/SafeRecovery/SafeIntegrationBase.t.sol b/test/integration/SafeRecovery/SafeIntegrationBase.t.sol index af9c1772..b91ab6b3 100644 --- a/test/integration/SafeRecovery/SafeIntegrationBase.t.sol +++ b/test/integration/SafeRecovery/SafeIntegrationBase.t.sol @@ -19,13 +19,11 @@ abstract contract SafeIntegrationBase is IntegrationBase { SafeRecoveryCommandHandler safeRecoveryCommandHandler; UniversalEmailRecoveryModule emailRecoveryModule; - address recoveryModuleAddress; + address emailRecoveryModuleAddress; bytes isInstalledContext; bytes4 functionSelector; - uint256 nullifierCount; - /** * Helper function to return if current account type is safe or not */ @@ -44,38 +42,13 @@ abstract contract SafeIntegrationBase is IntegrationBase { } super.setUp(); - // Deploy handler, manager and module - safeRecoveryCommandHandler = new SafeRecoveryCommandHandler(); - - emailRecoveryModule = new UniversalEmailRecoveryModule( - address(verifier), - address(dkimRegistry), - address(emailAuthImpl), - address(safeRecoveryCommandHandler) - ); - recoveryModuleAddress = address(emailRecoveryModule); - isInstalledContext = bytes("0"); functionSelector = bytes4(keccak256(bytes("swapOwner(address,address,address)"))); - // Compute guardian addresses - guardians1 = new address[](3); - guardians1[0] = emailRecoveryModule.computeEmailAuthAddress(accountAddress1, accountSalt1); - guardians1[1] = emailRecoveryModule.computeEmailAuthAddress(accountAddress1, accountSalt2); - guardians1[2] = emailRecoveryModule.computeEmailAuthAddress(accountAddress1, accountSalt3); - guardians2 = new address[](3); - guardians2[0] = emailRecoveryModule.computeEmailAuthAddress(instance2.account, accountSalt1); - guardians2[1] = emailRecoveryModule.computeEmailAuthAddress(instance2.account, accountSalt2); - guardians2[2] = emailRecoveryModule.computeEmailAuthAddress(instance2.account, accountSalt3); - guardians3 = new address[](3); - guardians3[0] = emailRecoveryModule.computeEmailAuthAddress(instance3.account, accountSalt1); - guardians3[1] = emailRecoveryModule.computeEmailAuthAddress(instance3.account, accountSalt2); - guardians3[2] = emailRecoveryModule.computeEmailAuthAddress(instance3.account, accountSalt3); - vm.prank(accountAddress1); instance1.installModule({ moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, + module: emailRecoveryModuleAddress, data: abi.encode( address(accountAddress1), isInstalledContext, @@ -90,96 +63,48 @@ abstract contract SafeIntegrationBase is IntegrationBase { vm.stopPrank(); } - function generateMockEmailProof( - string memory command, - bytes32 nullifier, + function computeEmailAuthAddress( + address account, bytes32 accountSalt ) public view - returns (EmailProof memory) + override + returns (address) { - EmailProof memory emailProof; - emailProof.domainName = "gmail.com"; - emailProof.publicKeyHash = bytes32( - vm.parseUint( - "6632353713085157925504008443078919716322386156160602218536961028046468237192" - ) - ); - emailProof.timestamp = block.timestamp; - emailProof.maskedCommand = command; - emailProof.emailNullifier = nullifier; - emailProof.accountSalt = accountSalt; - emailProof.isCodeExist = true; - emailProof.proof = bytes("0"); - - return emailProof; - } - - function getAccountSaltForGuardian(address guardian) public view returns (bytes32) { - if (guardian == guardians1[0]) { - return accountSalt1; - } - if (guardian == guardians1[1]) { - return accountSalt2; - } - if (guardian == guardians1[2]) { - return accountSalt3; - } - - revert("Invalid guardian address"); + return emailRecoveryModule.computeEmailAuthAddress(account, accountSalt); } - function generateNewNullifier() public returns (bytes32) { - return keccak256(abi.encode(nullifierCount++)); - } - - function acceptGuardian(address account, address guardian) public { - EmailAuthMsg memory emailAuthMsg = getAcceptanceEmailAuthMessage(account, guardian); - emailRecoveryModule.handleAcceptance(emailAuthMsg, templateIdx); - } - - function getAcceptanceEmailAuthMessage( - address account, - address guardian - ) - public - returns (EmailAuthMsg memory) - { - string memory accountString = CommandUtils.addressToChecksumHexString(account); - string memory command = string.concat("Accept guardian request for ", accountString); - bytes32 nullifier = generateNewNullifier(); - bytes32 accountSalt = getAccountSaltForGuardian(guardian); - - EmailProof memory emailProof = generateMockEmailProof(command, nullifier, accountSalt); + function deployModule() public override { + // Deploy handler, manager and module + safeRecoveryCommandHandler = new SafeRecoveryCommandHandler(); - bytes[] memory commandParamsForAcceptance = new bytes[](1); - commandParamsForAcceptance[0] = abi.encode(account); - return EmailAuthMsg({ - templateId: emailRecoveryModule.computeAcceptanceTemplateId(templateIdx), - commandParams: commandParamsForAcceptance, - skippedCommandPrefix: 0, - proof: emailProof - }); + emailRecoveryModule = new UniversalEmailRecoveryModule( + address(verifier), + address(dkimRegistry), + address(emailAuthImpl), + address(safeRecoveryCommandHandler) + ); + emailRecoveryModuleAddress = address(emailRecoveryModule); } function handleRecovery( address account, address oldOwner, - address newOwner, + address newOwner1, address guardian ) public { EmailAuthMsg memory emailAuthMsg = - getRecoveryEmailAuthMessage(account, oldOwner, newOwner, guardian); + getRecoveryEmailAuthMessage(account, oldOwner, newOwner1, guardian); emailRecoveryModule.handleRecovery(emailAuthMsg, templateIdx); } function getRecoveryEmailAuthMessage( address account, address oldOwner, - address newOwner, + address newOwner1, address guardian ) public @@ -187,7 +112,7 @@ abstract contract SafeIntegrationBase is IntegrationBase { { string memory accountString = CommandUtils.addressToChecksumHexString(account); string memory oldOwnerString = CommandUtils.addressToChecksumHexString(oldOwner); - string memory newOwnerString = CommandUtils.addressToChecksumHexString(newOwner); + string memory newOwnerString = CommandUtils.addressToChecksumHexString(newOwner1); string memory command = string.concat( "Recover account ", @@ -198,14 +123,14 @@ abstract contract SafeIntegrationBase is IntegrationBase { newOwnerString ); bytes32 nullifier = generateNewNullifier(); - bytes32 accountSalt = getAccountSaltForGuardian(guardian); + bytes32 accountSalt = getAccountSaltForGuardian(account, guardian); EmailProof memory emailProof = generateMockEmailProof(command, nullifier, accountSalt); bytes[] memory commandParamsForRecovery = new bytes[](3); commandParamsForRecovery[0] = abi.encode(account); commandParamsForRecovery[1] = abi.encode(oldOwner); - commandParamsForRecovery[2] = abi.encode(newOwner); + commandParamsForRecovery[2] = abi.encode(newOwner1); return EmailAuthMsg({ templateId: emailRecoveryModule.computeRecoveryTemplateId(templateIdx), diff --git a/test/integration/SafeRecovery/SafeNativeIntegrationBase.t.sol b/test/integration/SafeRecovery/SafeNativeIntegrationBase.t.sol index 1acb7a36..248074e7 100644 --- a/test/integration/SafeRecovery/SafeNativeIntegrationBase.t.sol +++ b/test/integration/SafeRecovery/SafeNativeIntegrationBase.t.sol @@ -13,6 +13,7 @@ import { SafeEmailRecoveryModule } from "src/modules/SafeEmailRecoveryModule.sol import { AccountHidingRecoveryCommandHandler } from "src/handlers/AccountHidingRecoveryCommandHandler.sol"; import { IntegrationBase } from "../IntegrationBase.t.sol"; +import { IEmailRecoveryModule } from "../../Base.t.sol"; abstract contract SafeNativeIntegrationBase is IntegrationBase { using ModuleKitHelpers for *; @@ -24,10 +25,8 @@ abstract contract SafeNativeIntegrationBase is IntegrationBase { Safe public safeSingleton; Safe public safe; address public safeAddress; - address public owner; bytes isInstalledContext; bytes4 functionSelector; - uint256 nullifierCount; address commandHandler; /** @@ -56,32 +55,21 @@ abstract contract SafeNativeIntegrationBase is IntegrationBase { } super.setUp(); - commandHandler = address(new AccountHidingRecoveryCommandHandler()); - emailRecoveryModule = new SafeEmailRecoveryModule( - address(verifier), - address(dkimRegistry), - address(emailAuthImpl), - address(commandHandler) - ); - emailRecoveryModuleAddress = address(emailRecoveryModule); - safeSingleton = new Safe(); SafeProxy safeProxy = new SafeProxy(address(safeSingleton)); safe = Safe(payable(address(safeProxy))); safeAddress = address(safe); - isInstalledContext = bytes("0"); - functionSelector = bytes4(keccak256(bytes("swapOwner(address,address,address)"))); - - // Compute guardian addresses - guardians1 = new address[](3); + // Overwrite the default values guardians1[0] = emailRecoveryModule.computeEmailAuthAddress(safeAddress, accountSalt1); guardians1[1] = emailRecoveryModule.computeEmailAuthAddress(safeAddress, accountSalt2); guardians1[2] = emailRecoveryModule.computeEmailAuthAddress(safeAddress, accountSalt3); + isInstalledContext = bytes("0"); + functionSelector = bytes4(keccak256(bytes("swapOwner(address,address,address)"))); + address[] memory owners = new address[](1); - owner = owner1; - owners[0] = owner; + owners[0] = owner1; safe.setup( owners, 1, address(0), bytes("0"), address(0), address(0), 0, payable(address(0)) @@ -92,30 +80,28 @@ abstract contract SafeNativeIntegrationBase is IntegrationBase { vm.stopPrank(); } - function generateMockEmailProof( - string memory command, - bytes32 nullifier, + function computeEmailAuthAddress( + address account, bytes32 accountSalt ) public view - returns (EmailProof memory) + override + returns (address) { - EmailProof memory emailProof; - emailProof.domainName = "gmail.com"; - emailProof.publicKeyHash = bytes32( - vm.parseUint( - "6632353713085157925504008443078919716322386156160602218536961028046468237192" - ) + return emailRecoveryModule.computeEmailAuthAddress(account, accountSalt); + } + + function deployModule() public override { + // Deploy handler, manager and module + commandHandler = address(new AccountHidingRecoveryCommandHandler()); + emailRecoveryModule = new SafeEmailRecoveryModule( + address(verifier), + address(dkimRegistry), + address(emailAuthImpl), + address(commandHandler) ); - emailProof.timestamp = block.timestamp; - emailProof.maskedCommand = command; - emailProof.emailNullifier = nullifier; - emailProof.accountSalt = accountSalt; - emailProof.isCodeExist = true; - emailProof.proof = bytes("0"); - - return emailProof; + emailRecoveryModuleAddress = address(emailRecoveryModule); } function getAccountSaltForGuardian(address guardian) public view returns (bytes32) { @@ -132,34 +118,36 @@ abstract contract SafeNativeIntegrationBase is IntegrationBase { revert("Invalid guardian address"); } - function generateNewNullifier() public returns (bytes32) { - return keccak256(abi.encode(nullifierCount++)); - } - - function acceptGuardian(address account, address guardian) public { - EmailAuthMsg memory emailAuthMsg = getAcceptanceEmailAuthMessage(account, guardian); - emailRecoveryModule.handleAcceptance(emailAuthMsg, templateIdx); - } - - function getAcceptanceEmailAuthMessage( + function getAcceptanceEmailAuthMessageWithAccountSalt( address account, - address guardian + address guardian, + address emailRecoveryModule, + bytes32 optionalAccountSalt ) public + override returns (EmailAuthMsg memory) { bytes32 accountHash = keccak256(abi.encodePacked(account)); string memory accountHashString = uint256(accountHash).toHexString(32); string memory command = string.concat("Accept guardian request for ", accountHashString); bytes32 nullifier = generateNewNullifier(); - bytes32 accountSalt = getAccountSaltForGuardian(guardian); + + bytes32 accountSalt; + if (optionalAccountSalt == bytes32(0)) { + accountSalt = getAccountSaltForGuardian(account, guardian); + } else { + accountSalt = optionalAccountSalt; + } EmailProof memory emailProof = generateMockEmailProof(command, nullifier, accountSalt); bytes[] memory commandParamsForAcceptance = new bytes[](1); commandParamsForAcceptance[0] = abi.encode(accountHashString); return EmailAuthMsg({ - templateId: emailRecoveryModule.computeAcceptanceTemplateId(templateIdx), + templateId: IEmailRecoveryModule(emailRecoveryModule).computeAcceptanceTemplateId( + templateIdx + ), commandParams: commandParamsForAcceptance, skippedCommandPrefix: 0, proof: emailProof diff --git a/test/integration/SafeRecovery/SafeRecovery.t.sol b/test/integration/SafeRecovery/SafeRecovery.t.sol index 1e518f96..dbe06b55 100644 --- a/test/integration/SafeRecovery/SafeRecovery.t.sol +++ b/test/integration/SafeRecovery/SafeRecovery.t.sol @@ -38,13 +38,13 @@ contract SafeRecovery_Integration_Test is SafeIntegrationBase { emailRecoveryModule.getGuardian(accountAddress1, guardians1[0]); // Accept guardian - acceptGuardian(accountAddress1, guardians1[0]); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); guardianStorage1 = emailRecoveryModule.getGuardian(accountAddress1, guardians1[0]); assertEq(uint256(guardianStorage1.status), uint256(GuardianStatus.ACCEPTED)); assertEq(guardianStorage1.weight, uint256(1)); // Accept guardian - acceptGuardian(accountAddress1, guardians1[1]); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); GuardianStorage memory guardianStorage2 = emailRecoveryModule.getGuardian(accountAddress1, guardians1[1]); assertEq(uint256(guardianStorage2.status), uint256(GuardianStatus.ACCEPTED)); @@ -96,7 +96,7 @@ contract SafeRecovery_Integration_Test is SafeIntegrationBase { // // Uninstall module // vm.prank(accountAddress1); - // account.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + // account.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); // vm.stopPrank(); // // bool isModuleInstalled = account.isModuleInstalled( diff --git a/test/integration/SafeRecovery/SafeRecoveryNativeModule.t.sol b/test/integration/SafeRecovery/SafeRecoveryNativeModule.t.sol index a67fe87e..0b2f435c 100644 --- a/test/integration/SafeRecovery/SafeRecoveryNativeModule.t.sol +++ b/test/integration/SafeRecovery/SafeRecoveryNativeModule.t.sol @@ -23,7 +23,7 @@ contract SafeRecoveryNativeModule_Integration_Test is SafeNativeIntegrationBase function testIntegration_AccountRecovery() public { skipIfNotSafeAccountType(); - address newOwner = owner2; + address newOwner1 = owner2; // Configure recovery vm.startPrank(safeAddress); emailRecoveryModule.configureSafeRecovery( @@ -32,7 +32,7 @@ contract SafeRecoveryNativeModule_Integration_Test is SafeNativeIntegrationBase vm.stopPrank(); bytes memory recoveryCalldata = abi.encodeWithSignature( - "swapOwner(address,address,address)", address(1), owner, newOwner + "swapOwner(address,address,address)", address(1), owner1, newOwner1 ); bytes memory recoveryData = abi.encode(safeAddress, recoveryCalldata); bytes32 recoveryDataHash = keccak256(recoveryData); @@ -40,7 +40,9 @@ contract SafeRecoveryNativeModule_Integration_Test is SafeNativeIntegrationBase AccountHidingRecoveryCommandHandler(commandHandler).storeAccountHash(safeAddress); // Accept guardian - EmailAuthMsg memory emailAuthMsg = getAcceptanceEmailAuthMessage(safeAddress, guardians1[0]); + EmailAuthMsg memory emailAuthMsg = getAcceptanceEmailAuthMessageWithAccountSalt( + safeAddress, guardians1[0], emailRecoveryModuleAddress, accountSalt1 + ); emailRecoveryModule.handleAcceptance(emailAuthMsg, templateIdx); GuardianStorage memory guardianStorage1 = emailRecoveryModule.getGuardian(safeAddress, guardians1[0]); @@ -48,7 +50,9 @@ contract SafeRecoveryNativeModule_Integration_Test is SafeNativeIntegrationBase assertEq(guardianStorage1.weight, uint256(1)); // Accept guardian - emailAuthMsg = getAcceptanceEmailAuthMessage(safeAddress, guardians1[1]); + emailAuthMsg = getAcceptanceEmailAuthMessageWithAccountSalt( + safeAddress, guardians1[1], emailRecoveryModuleAddress, accountSalt2 + ); emailRecoveryModule.handleAcceptance(emailAuthMsg, templateIdx); GuardianStorage memory guardianStorage2 = emailRecoveryModule.getGuardian(safeAddress, guardians1[1]); @@ -91,10 +95,10 @@ contract SafeRecoveryNativeModule_Integration_Test is SafeNativeIntegrationBase assertEq(recoveryRequest.recoveryDataHash, bytes32(0)); vm.prank(safeAddress); - bool isOwner = Safe(payable(safeAddress)).isOwner(newOwner); + bool isOwner = Safe(payable(safeAddress)).isOwner(newOwner1); assertTrue(isOwner); - bool oldOwnerIsOwner = Safe(payable(safeAddress)).isOwner(owner); + bool oldOwnerIsOwner = Safe(payable(safeAddress)).isOwner(owner1); assertFalse(oldOwnerIsOwner); } @@ -106,7 +110,7 @@ contract SafeRecoveryNativeModule_Integration_Test is SafeNativeIntegrationBase assertTrue(isModuleEnabled); // Uninstall module - // instance1.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + // instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); vm.prank(safeAddress); Safe(payable(safeAddress)).disableModule(address(1), emailRecoveryModuleAddress); vm.stopPrank(); diff --git a/test/unit/EmailRecoveryManager/acceptGuardian.t.sol b/test/unit/EmailRecoveryManager/acceptGuardian.t.sol index 4dc04d17..bb7a9b00 100644 --- a/test/unit/EmailRecoveryManager/acceptGuardian.t.sol +++ b/test/unit/EmailRecoveryManager/acceptGuardian.t.sol @@ -20,27 +20,31 @@ contract EmailRecoveryManager_acceptGuardian_Test is UnitBase { super.setUp(); commandParams = new bytes[](1); - commandParams[0] = abi.encode(accountAddress); + commandParams[0] = abi.encode(accountAddress1); nullifier = keccak256(abi.encode("nullifier 1")); } function test_AcceptGuardian_RevertWhen_AlreadyRecovering() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(recoveryDataHash, accountSalt1); vm.expectRevert(IGuardianManager.RecoveryInProcess.selector); - emailRecoveryModule.exposed_acceptGuardian(guardian1, templateIdx, commandParams, nullifier); + emailRecoveryModule.exposed_acceptGuardian( + guardians1[0], templateIdx, commandParams, nullifier + ); } function test_AcceptGuardian_RevertWhen_RecoveryModuleNotInstalled() public { - vm.prank(accountAddress); - instance.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + vm.prank(accountAddress1); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); vm.stopPrank(); vm.expectRevert(IEmailRecoveryManager.RecoveryIsNotActivated.selector); - emailRecoveryModule.exposed_acceptGuardian(guardian1, templateIdx, commandParams, nullifier); + emailRecoveryModule.exposed_acceptGuardian( + guardians1[0], templateIdx, commandParams, nullifier + ); } function test_AcceptGuardian_RevertWhen_GuardianStatusIsNONE() public { @@ -59,7 +63,9 @@ contract EmailRecoveryManager_acceptGuardian_Test is UnitBase { } function test_AcceptGuardian_RevertWhen_GuardianStatusIsACCEPTED() public { - emailRecoveryModule.exposed_acceptGuardian(guardian1, templateIdx, commandParams, nullifier); + emailRecoveryModule.exposed_acceptGuardian( + guardians1[0], templateIdx, commandParams, nullifier + ); vm.expectRevert( abi.encodeWithSelector( @@ -68,21 +74,25 @@ contract EmailRecoveryManager_acceptGuardian_Test is UnitBase { uint256(GuardianStatus.REQUESTED) ) ); - emailRecoveryModule.exposed_acceptGuardian(guardian1, templateIdx, commandParams, nullifier); + emailRecoveryModule.exposed_acceptGuardian( + guardians1[0], templateIdx, commandParams, nullifier + ); } function test_AcceptGuardian_Succeeds() public { vm.expectEmit(); - emit IEmailRecoveryManager.GuardianAccepted(accountAddress, guardian1); - emailRecoveryModule.exposed_acceptGuardian(guardian1, templateIdx, commandParams, nullifier); + emit IEmailRecoveryManager.GuardianAccepted(accountAddress1, guardians1[0]); + emailRecoveryModule.exposed_acceptGuardian( + guardians1[0], templateIdx, commandParams, nullifier + ); GuardianStorage memory guardianStorage = - emailRecoveryModule.getGuardian(accountAddress, guardian1); + emailRecoveryModule.getGuardian(accountAddress1, guardians1[0]); assertEq(uint256(guardianStorage.status), uint256(GuardianStatus.ACCEPTED)); assertEq(guardianStorage.weight, uint256(1)); IGuardianManager.GuardianConfig memory guardianConfig = - emailRecoveryModule.getGuardianConfig(accountAddress); + emailRecoveryModule.getGuardianConfig(accountAddress1); assertEq(guardianConfig.acceptedWeight, guardianStorage.weight); } } diff --git a/test/unit/EmailRecoveryManager/cancelExpiredRecovery.t.sol b/test/unit/EmailRecoveryManager/cancelExpiredRecovery.t.sol index 803ae5f2..1ecd73f2 100644 --- a/test/unit/EmailRecoveryManager/cancelExpiredRecovery.t.sol +++ b/test/unit/EmailRecoveryManager/cancelExpiredRecovery.t.sol @@ -13,20 +13,20 @@ contract EmailRecoveryManager_cancelExpiredRecovery_Test is UnitBase { } function test_CancelExpiredRecovery_RevertWhen_NoRecoveryInProcess() public { - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert(IEmailRecoveryManager.NoRecoveryInProcess.selector); - emailRecoveryModule.cancelExpiredRecovery(accountAddress); + emailRecoveryModule.cancelExpiredRecovery(accountAddress1); } function test_CancelExpiredRecovery_CannotCancelNotStartedRecoveryRequest() public { address otherAddress = address(99); - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); IEmailRecoveryManager.RecoveryRequest memory recoveryRequest = - emailRecoveryModule.getRecoveryRequest(accountAddress); + emailRecoveryModule.getRecoveryRequest(accountAddress1); assertEq(recoveryRequest.executeAfter, 0); assertEq(recoveryRequest.executeBefore, 0); assertEq(recoveryRequest.currentWeight, 0); @@ -34,17 +34,17 @@ contract EmailRecoveryManager_cancelExpiredRecovery_Test is UnitBase { vm.startPrank(otherAddress); vm.expectRevert(IEmailRecoveryManager.NoRecoveryInProcess.selector); - emailRecoveryModule.cancelExpiredRecovery(accountAddress); + emailRecoveryModule.cancelExpiredRecovery(accountAddress1); } function test_CancelExpiredRecovery_RevertWhen_PartialRequest_ExpiryNotPassed() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds + 1 seconds); handleRecovery(recoveryDataHash, accountSalt1); IEmailRecoveryManager.RecoveryRequest memory recoveryRequest = - emailRecoveryModule.getRecoveryRequest(accountAddress); + emailRecoveryModule.getRecoveryRequest(accountAddress1); assertEq(recoveryRequest.executeAfter, 0); assertEq(recoveryRequest.executeBefore, block.timestamp + expiry); assertEq(recoveryRequest.currentWeight, 1); @@ -55,25 +55,25 @@ contract EmailRecoveryManager_cancelExpiredRecovery_Test is UnitBase { vm.expectRevert( abi.encodeWithSelector( IEmailRecoveryManager.RecoveryHasNotExpired.selector, - accountAddress, + accountAddress1, block.timestamp, block.timestamp + expiry ) ); - emailRecoveryModule.cancelExpiredRecovery(accountAddress); + emailRecoveryModule.cancelExpiredRecovery(accountAddress1); } function test_CancelExpiredRecovery_RevertWhen_FullRequest_ExpiryNotPassed() public { address otherAddress = address(99); - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(recoveryDataHash, accountSalt1); handleRecovery(recoveryDataHash, accountSalt2); IEmailRecoveryManager.RecoveryRequest memory recoveryRequest = - emailRecoveryModule.getRecoveryRequest(accountAddress); + emailRecoveryModule.getRecoveryRequest(accountAddress1); assertEq(recoveryRequest.executeAfter, block.timestamp + delay); assertEq(recoveryRequest.executeBefore, block.timestamp + expiry); assertEq(recoveryRequest.currentWeight, 3); @@ -84,22 +84,22 @@ contract EmailRecoveryManager_cancelExpiredRecovery_Test is UnitBase { vm.expectRevert( abi.encodeWithSelector( IEmailRecoveryManager.RecoveryHasNotExpired.selector, - accountAddress, + accountAddress1, block.timestamp, block.timestamp + expiry ) ); - emailRecoveryModule.cancelExpiredRecovery(accountAddress); + emailRecoveryModule.cancelExpiredRecovery(accountAddress1); } function test_CancelExpiredRecovery_PartialRequest_Succeeds() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds + 1 seconds); handleRecovery(recoveryDataHash, accountSalt1); IEmailRecoveryManager.RecoveryRequest memory recoveryRequest = - emailRecoveryModule.getRecoveryRequest(accountAddress); + emailRecoveryModule.getRecoveryRequest(accountAddress1); assertEq(recoveryRequest.executeAfter, 0); assertEq(recoveryRequest.executeBefore, block.timestamp + expiry); assertEq(recoveryRequest.currentWeight, 1); @@ -109,10 +109,10 @@ contract EmailRecoveryManager_cancelExpiredRecovery_Test is UnitBase { address otherAddress = address(99); vm.startPrank(otherAddress); vm.expectEmit(); - emit IEmailRecoveryManager.RecoveryCancelled(accountAddress); - emailRecoveryModule.cancelExpiredRecovery(accountAddress); + emit IEmailRecoveryManager.RecoveryCancelled(accountAddress1); + emailRecoveryModule.cancelExpiredRecovery(accountAddress1); - recoveryRequest = emailRecoveryModule.getRecoveryRequest(accountAddress); + recoveryRequest = emailRecoveryModule.getRecoveryRequest(accountAddress1); assertEq(recoveryRequest.executeAfter, 0); assertEq(recoveryRequest.executeBefore, 0); assertEq(recoveryRequest.currentWeight, 0); @@ -122,14 +122,14 @@ contract EmailRecoveryManager_cancelExpiredRecovery_Test is UnitBase { function test_CancelExpiredRecovery_FullRequest_SucceedsWhenExecuteBeforeEqualsTimestamp() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds + 1 seconds); handleRecovery(recoveryDataHash, accountSalt1); handleRecovery(recoveryDataHash, accountSalt2); IEmailRecoveryManager.RecoveryRequest memory recoveryRequest = - emailRecoveryModule.getRecoveryRequest(accountAddress); + emailRecoveryModule.getRecoveryRequest(accountAddress1); assertEq(recoveryRequest.executeAfter, block.timestamp + delay); assertEq(recoveryRequest.executeBefore, block.timestamp + expiry); assertEq(recoveryRequest.currentWeight, 3); @@ -140,10 +140,10 @@ contract EmailRecoveryManager_cancelExpiredRecovery_Test is UnitBase { address otherAddress = address(99); vm.startPrank(otherAddress); vm.expectEmit(); - emit IEmailRecoveryManager.RecoveryCancelled(accountAddress); - emailRecoveryModule.cancelExpiredRecovery(accountAddress); + emit IEmailRecoveryManager.RecoveryCancelled(accountAddress1); + emailRecoveryModule.cancelExpiredRecovery(accountAddress1); - recoveryRequest = emailRecoveryModule.getRecoveryRequest(accountAddress); + recoveryRequest = emailRecoveryModule.getRecoveryRequest(accountAddress1); assertEq(recoveryRequest.executeAfter, 0); assertEq(recoveryRequest.executeBefore, 0); assertEq(recoveryRequest.currentWeight, 0); @@ -153,14 +153,14 @@ contract EmailRecoveryManager_cancelExpiredRecovery_Test is UnitBase { function test_CancelExpiredRecovery_FullRequest_SucceedsWhenExecuteBeforeIsLessThanTimestamp() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds + 1 seconds); handleRecovery(recoveryDataHash, accountSalt1); handleRecovery(recoveryDataHash, accountSalt2); IEmailRecoveryManager.RecoveryRequest memory recoveryRequest = - emailRecoveryModule.getRecoveryRequest(accountAddress); + emailRecoveryModule.getRecoveryRequest(accountAddress1); assertEq(recoveryRequest.executeAfter, block.timestamp + delay); assertEq(recoveryRequest.executeBefore, block.timestamp + expiry); assertEq(recoveryRequest.currentWeight, 3); @@ -171,10 +171,10 @@ contract EmailRecoveryManager_cancelExpiredRecovery_Test is UnitBase { address otherAddress = address(99); vm.startPrank(otherAddress); vm.expectEmit(); - emit IEmailRecoveryManager.RecoveryCancelled(accountAddress); - emailRecoveryModule.cancelExpiredRecovery(accountAddress); + emit IEmailRecoveryManager.RecoveryCancelled(accountAddress1); + emailRecoveryModule.cancelExpiredRecovery(accountAddress1); - recoveryRequest = emailRecoveryModule.getRecoveryRequest(accountAddress); + recoveryRequest = emailRecoveryModule.getRecoveryRequest(accountAddress1); assertEq(recoveryRequest.executeAfter, 0); assertEq(recoveryRequest.executeBefore, 0); assertEq(recoveryRequest.currentWeight, 0); diff --git a/test/unit/EmailRecoveryManager/cancelRecovery.t.sol b/test/unit/EmailRecoveryManager/cancelRecovery.t.sol index 304cd57f..c67333c0 100644 --- a/test/unit/EmailRecoveryManager/cancelRecovery.t.sol +++ b/test/unit/EmailRecoveryManager/cancelRecovery.t.sol @@ -13,7 +13,7 @@ contract EmailRecoveryManager_cancelRecovery_Test is UnitBase { } function test_CancelRecovery_RevertWhen_NoRecoveryInProcess() public { - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert(IEmailRecoveryManager.NoRecoveryInProcess.selector); emailRecoveryModule.cancelRecovery(); } @@ -21,13 +21,13 @@ contract EmailRecoveryManager_cancelRecovery_Test is UnitBase { function test_CancelRecovery_CannotCancelWrongRecoveryRequest() public { address otherAddress = address(99); - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(recoveryDataHash, accountSalt1); IEmailRecoveryManager.RecoveryRequest memory recoveryRequest = - emailRecoveryModule.getRecoveryRequest(accountAddress); + emailRecoveryModule.getRecoveryRequest(accountAddress1); assertEq(recoveryRequest.executeAfter, 0); assertEq(recoveryRequest.executeBefore, block.timestamp + expiry); assertEq(recoveryRequest.currentWeight, 1); @@ -39,22 +39,22 @@ contract EmailRecoveryManager_cancelRecovery_Test is UnitBase { } function test_CancelRecovery_PartialRequest_Succeeds() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(recoveryDataHash, accountSalt1); IEmailRecoveryManager.RecoveryRequest memory recoveryRequest = - emailRecoveryModule.getRecoveryRequest(accountAddress); + emailRecoveryModule.getRecoveryRequest(accountAddress1); assertEq(recoveryRequest.executeAfter, 0); assertEq(recoveryRequest.executeBefore, block.timestamp + expiry); assertEq(recoveryRequest.currentWeight, 1); assertEq(recoveryRequest.recoveryDataHash, recoveryDataHash); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.cancelRecovery(); - recoveryRequest = emailRecoveryModule.getRecoveryRequest(accountAddress); + recoveryRequest = emailRecoveryModule.getRecoveryRequest(accountAddress1); assertEq(recoveryRequest.executeAfter, 0); assertEq(recoveryRequest.executeBefore, 0); assertEq(recoveryRequest.currentWeight, 0); @@ -62,25 +62,25 @@ contract EmailRecoveryManager_cancelRecovery_Test is UnitBase { } function test_CancelRecovery_FullRequest_Succeeds() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(recoveryDataHash, accountSalt1); handleRecovery(recoveryDataHash, accountSalt2); IEmailRecoveryManager.RecoveryRequest memory recoveryRequest = - emailRecoveryModule.getRecoveryRequest(accountAddress); + emailRecoveryModule.getRecoveryRequest(accountAddress1); assertEq(recoveryRequest.executeAfter, block.timestamp + delay); assertEq(recoveryRequest.executeBefore, block.timestamp + expiry); assertEq(recoveryRequest.currentWeight, 3); assertEq(recoveryRequest.recoveryDataHash, recoveryDataHash); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectEmit(); - emit IEmailRecoveryManager.RecoveryCancelled(accountAddress); + emit IEmailRecoveryManager.RecoveryCancelled(accountAddress1); emailRecoveryModule.cancelRecovery(); - recoveryRequest = emailRecoveryModule.getRecoveryRequest(accountAddress); + recoveryRequest = emailRecoveryModule.getRecoveryRequest(accountAddress1); assertEq(recoveryRequest.executeAfter, 0); assertEq(recoveryRequest.executeBefore, 0); assertEq(recoveryRequest.currentWeight, 0); diff --git a/test/unit/EmailRecoveryManager/completeRecovery.t.sol b/test/unit/EmailRecoveryManager/completeRecovery.t.sol index 6c1f5e3a..113c19c1 100644 --- a/test/unit/EmailRecoveryManager/completeRecovery.t.sol +++ b/test/unit/EmailRecoveryManager/completeRecovery.t.sol @@ -17,8 +17,8 @@ contract EmailRecoveryManager_completeRecovery_Test is UnitBase { } function test_CompleteRecovery_RevertWhen_NotEnoughApprovals() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(recoveryDataHash, accountSalt1); // only one guardian added and one approval @@ -28,12 +28,12 @@ contract EmailRecoveryManager_completeRecovery_Test is UnitBase { IEmailRecoveryManager.NotEnoughApprovals.selector, guardianWeights[0], threshold ) ); - emailRecoveryModule.completeRecovery(accountAddress, recoveryData); + emailRecoveryModule.completeRecovery(accountAddress1, recoveryData); } function test_CompleteRecovery_RevertWhen_DelayNotPassed() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(recoveryDataHash, accountSalt1); handleRecovery(recoveryDataHash, accountSalt2); @@ -48,14 +48,14 @@ contract EmailRecoveryManager_completeRecovery_Test is UnitBase { block.timestamp + delay ) ); - emailRecoveryModule.completeRecovery(accountAddress, recoveryData); + emailRecoveryModule.completeRecovery(accountAddress1, recoveryData); } function test_CompleteRecovery_RevertWhen_RecoveryRequestExpiredAndTimestampEqualToExpiry() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(recoveryDataHash, accountSalt1); handleRecovery(recoveryDataHash, accountSalt2); @@ -69,14 +69,14 @@ contract EmailRecoveryManager_completeRecovery_Test is UnitBase { IEmailRecoveryManager.RecoveryRequestExpired.selector, block.timestamp, executeAfter ) ); - emailRecoveryModule.completeRecovery(accountAddress, recoveryData); + emailRecoveryModule.completeRecovery(accountAddress1, recoveryData); } function test_CompleteRecovery_RevertWhen_RecoveryRequestExpiredAndTimestampMoreThanExpiry() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(recoveryDataHash, accountSalt1); handleRecovery(recoveryDataHash, accountSalt2); @@ -90,14 +90,14 @@ contract EmailRecoveryManager_completeRecovery_Test is UnitBase { IEmailRecoveryManager.RecoveryRequestExpired.selector, block.timestamp, executeAfter ) ); - emailRecoveryModule.completeRecovery(accountAddress, recoveryData); + emailRecoveryModule.completeRecovery(accountAddress1, recoveryData); } function test_CompleteRecovery_RevertWhen_InvalidRecoveryDataHash() public { bytes memory invalidRecoveryData = bytes("Invalid calldata"); - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(recoveryDataHash, accountSalt1); handleRecovery(recoveryDataHash, accountSalt2); @@ -111,12 +111,12 @@ contract EmailRecoveryManager_completeRecovery_Test is UnitBase { recoveryDataHash ) ); - emailRecoveryModule.completeRecovery(accountAddress, invalidRecoveryData); + emailRecoveryModule.completeRecovery(accountAddress1, invalidRecoveryData); } function test_CompleteRecovery_Succeeds() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(recoveryDataHash, accountSalt1); handleRecovery(recoveryDataHash, accountSalt2); @@ -124,11 +124,11 @@ contract EmailRecoveryManager_completeRecovery_Test is UnitBase { vm.warp(block.timestamp + delay); vm.expectEmit(); - emit IEmailRecoveryManager.RecoveryCompleted(accountAddress); - emailRecoveryModule.completeRecovery(accountAddress, recoveryData); + emit IEmailRecoveryManager.RecoveryCompleted(accountAddress1); + emailRecoveryModule.completeRecovery(accountAddress1, recoveryData); IEmailRecoveryManager.RecoveryRequest memory recoveryRequest = - emailRecoveryModule.getRecoveryRequest(accountAddress); + emailRecoveryModule.getRecoveryRequest(accountAddress1); assertEq(recoveryRequest.executeAfter, 0); assertEq(recoveryRequest.executeBefore, 0); assertEq(recoveryRequest.currentWeight, 0); @@ -136,8 +136,8 @@ contract EmailRecoveryManager_completeRecovery_Test is UnitBase { } function test_CompleteRecovery_SucceedsAlmostExpiry() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(recoveryDataHash, accountSalt1); handleRecovery(recoveryDataHash, accountSalt2); @@ -145,11 +145,11 @@ contract EmailRecoveryManager_completeRecovery_Test is UnitBase { vm.warp(block.timestamp + expiry - 1 seconds); vm.expectEmit(); - emit IEmailRecoveryManager.RecoveryCompleted(accountAddress); - emailRecoveryModule.completeRecovery(accountAddress, recoveryData); + emit IEmailRecoveryManager.RecoveryCompleted(accountAddress1); + emailRecoveryModule.completeRecovery(accountAddress1, recoveryData); IEmailRecoveryManager.RecoveryRequest memory recoveryRequest = - emailRecoveryModule.getRecoveryRequest(accountAddress); + emailRecoveryModule.getRecoveryRequest(accountAddress1); assertEq(recoveryRequest.executeAfter, 0); assertEq(recoveryRequest.executeBefore, 0); assertEq(recoveryRequest.currentWeight, 0); diff --git a/test/unit/EmailRecoveryManager/configureRecovery.t.sol b/test/unit/EmailRecoveryManager/configureRecovery.t.sol index 24b18542..cb1b18af 100644 --- a/test/unit/EmailRecoveryManager/configureRecovery.t.sol +++ b/test/unit/EmailRecoveryManager/configureRecovery.t.sol @@ -16,67 +16,67 @@ contract EmailRecoveryManager_configureRecovery_Test is UnitBase { } function test_ConfigureRecovery_RevertWhen_AlreadyRecovering() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(recoveryDataHash, accountSalt1); vm.expectRevert(IEmailRecoveryManager.SetupAlreadyCalled.selector); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.exposed_configureRecovery( - guardians, guardianWeights, threshold, delay, expiry + guardians1, guardianWeights, threshold, delay, expiry ); } function test_ConfigureRecovery_RevertWhen_ConfigureRecoveryCalledTwice() public { - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert(IEmailRecoveryManager.SetupAlreadyCalled.selector); emailRecoveryModule.exposed_configureRecovery( - guardians, guardianWeights, threshold, delay, expiry + guardians1, guardianWeights, threshold, delay, expiry ); } function test_ConfigureRecovery_Succeeds() public { - instance.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); - vm.startPrank(accountAddress); - emailRecoveryModule.workaround_validatorsPush(accountAddress, validatorAddress); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); + vm.startPrank(accountAddress1); + emailRecoveryModule.workaround_validatorsPush(accountAddress1, validatorAddress); - bool isActivated = emailRecoveryModule.isActivated(accountAddress); + bool isActivated = emailRecoveryModule.isActivated(accountAddress1); assertFalse(isActivated); vm.expectEmit(); emit IEmailRecoveryManager.RecoveryConfigured( - instance.account, guardians.length, totalWeight, threshold + instance1.account, guardians1.length, totalWeight, threshold ); emailRecoveryModule.exposed_configureRecovery( - guardians, guardianWeights, threshold, delay, expiry + guardians1, guardianWeights, threshold, delay, expiry ); IEmailRecoveryManager.RecoveryConfig memory recoveryConfig = - emailRecoveryModule.getRecoveryConfig(accountAddress); + emailRecoveryModule.getRecoveryConfig(accountAddress1); assertEq(recoveryConfig.delay, delay); assertEq(recoveryConfig.expiry, expiry); IGuardianManager.GuardianConfig memory guardianConfig = - emailRecoveryModule.getGuardianConfig(accountAddress); - assertEq(guardianConfig.guardianCount, guardians.length); + emailRecoveryModule.getGuardianConfig(accountAddress1); + assertEq(guardianConfig.guardianCount, guardians1.length); assertEq(guardianConfig.totalWeight, totalWeight); - assertEq(guardianConfig.acceptedWeight, 0); // no guardians accepted yet + assertEq(guardianConfig.acceptedWeight, 0); // no guardians1 accepted yet assertEq(guardianConfig.threshold, threshold); GuardianStorage memory guardian = - emailRecoveryModule.getGuardian(accountAddress, guardians[0]); + emailRecoveryModule.getGuardian(accountAddress1, guardians1[0]); assertEq(uint256(guardian.status), uint256(GuardianStatus.REQUESTED)); assertEq(guardian.weight, guardianWeights[0]); - isActivated = emailRecoveryModule.isActivated(accountAddress); + isActivated = emailRecoveryModule.isActivated(accountAddress1); assertTrue(isActivated); } function test_ConfigureRecovery_RevertWhen_ZeroGuardians() public { - instance.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); - vm.startPrank(accountAddress); - emailRecoveryModule.workaround_validatorsPush(accountAddress, validatorAddress); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); + vm.startPrank(accountAddress1); + emailRecoveryModule.workaround_validatorsPush(accountAddress1, validatorAddress); address[] memory zeroGuardians; vm.expectRevert( @@ -92,39 +92,39 @@ contract EmailRecoveryManager_configureRecovery_Test is UnitBase { } function test_ConfigureRecovery_RevertWhen_ZeroGuardianWeights() public { - instance.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); - vm.startPrank(accountAddress); - emailRecoveryModule.workaround_validatorsPush(accountAddress, validatorAddress); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); + vm.startPrank(accountAddress1); + emailRecoveryModule.workaround_validatorsPush(accountAddress1, validatorAddress); uint256[] memory zeroGuardianWeights; vm.expectRevert( abi.encodeWithSelector( IGuardianManager.IncorrectNumberOfWeights.selector, - guardians.length, + guardians1.length, zeroGuardianWeights.length ) ); emailRecoveryModule.exposed_configureRecovery( - guardians, zeroGuardianWeights, threshold, delay, expiry + guardians1, zeroGuardianWeights, threshold, delay, expiry ); } function test_ConfigureRecovery_RevertWhen_ZeroThreshold() public { - instance.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); - vm.startPrank(accountAddress); - emailRecoveryModule.workaround_validatorsPush(accountAddress, validatorAddress); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); + vm.startPrank(accountAddress1); + emailRecoveryModule.workaround_validatorsPush(accountAddress1, validatorAddress); uint256 zeroThreshold = 0; vm.expectRevert(IGuardianManager.ThresholdCannotBeZero.selector); emailRecoveryModule.exposed_configureRecovery( - guardians, guardianWeights, zeroThreshold, delay, expiry + guardians1, guardianWeights, zeroThreshold, delay, expiry ); } function test_ConfigureRecovery_RevertWhen_NoGuardians() public { - instance.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); - vm.startPrank(accountAddress); - emailRecoveryModule.workaround_validatorsPush(accountAddress, validatorAddress); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); + vm.startPrank(accountAddress1); + emailRecoveryModule.workaround_validatorsPush(accountAddress1, validatorAddress); address[] memory zeroGuardians; uint256[] memory zeroGuardianWeights; diff --git a/test/unit/EmailRecoveryManager/deInitRecoveryModule.t.sol b/test/unit/EmailRecoveryManager/deInitRecoveryModule.t.sol index 2eeca303..d3714cdf 100644 --- a/test/unit/EmailRecoveryManager/deInitRecoveryModule.t.sol +++ b/test/unit/EmailRecoveryManager/deInitRecoveryModule.t.sol @@ -13,37 +13,37 @@ contract EmailRecoveryManager_deInitRecoveryModule_Test is UnitBase { } function test_DeInitRecoveryModule_RevertWhen_RecoveryInProcess() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(recoveryDataHash, accountSalt1); - vm.prank(accountAddress); + vm.prank(accountAddress1); vm.expectRevert(IGuardianManager.RecoveryInProcess.selector); emailRecoveryModule.exposed_deInitRecoveryModule(); } function test_DeInitRecoveryModule_Succeeds() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); - bool isActivated = emailRecoveryModule.isActivated(accountAddress); + bool isActivated = emailRecoveryModule.isActivated(accountAddress1); assertTrue(isActivated); - vm.prank(accountAddress); + vm.prank(accountAddress1); vm.expectEmit(); - emit IEmailRecoveryManager.RecoveryDeInitialized(accountAddress); + emit IEmailRecoveryManager.RecoveryDeInitialized(accountAddress1); emailRecoveryModule.exposed_deInitRecoveryModule(); // assert that recovery config has been cleared successfully IEmailRecoveryManager.RecoveryConfig memory recoveryConfig = - emailRecoveryModule.getRecoveryConfig(accountAddress); + emailRecoveryModule.getRecoveryConfig(accountAddress1); assertEq(recoveryConfig.delay, 0); assertEq(recoveryConfig.expiry, 0); // assert that the recovery request has been cleared successfully IEmailRecoveryManager.RecoveryRequest memory recoveryRequest = - emailRecoveryModule.getRecoveryRequest(accountAddress); + emailRecoveryModule.getRecoveryRequest(accountAddress1); assertEq(recoveryRequest.executeAfter, 0); assertEq(recoveryRequest.executeBefore, 0); assertEq(recoveryRequest.currentWeight, 0); @@ -51,25 +51,25 @@ contract EmailRecoveryManager_deInitRecoveryModule_Test is UnitBase { // assert that guardian storage has been cleared successfully for guardian 1 GuardianStorage memory guardianStorage1 = - emailRecoveryModule.getGuardian(accountAddress, guardian1); + emailRecoveryModule.getGuardian(accountAddress1, guardians1[0]); assertEq(uint256(guardianStorage1.status), uint256(GuardianStatus.NONE)); assertEq(guardianStorage1.weight, uint256(0)); // assert that guardian storage has been cleared successfully for guardian 2 GuardianStorage memory guardianStorage2 = - emailRecoveryModule.getGuardian(accountAddress, guardian2); + emailRecoveryModule.getGuardian(accountAddress1, guardians1[1]); assertEq(uint256(guardianStorage2.status), uint256(GuardianStatus.NONE)); assertEq(guardianStorage2.weight, uint256(0)); // assert that guardian config has been cleared successfully GuardianManager.GuardianConfig memory guardianConfig = - emailRecoveryModule.getGuardianConfig(accountAddress); + emailRecoveryModule.getGuardianConfig(accountAddress1); assertEq(guardianConfig.guardianCount, 0); assertEq(guardianConfig.totalWeight, 0); assertEq(guardianConfig.acceptedWeight, 0); assertEq(guardianConfig.threshold, 0); - isActivated = emailRecoveryModule.isActivated(accountAddress); + isActivated = emailRecoveryModule.isActivated(accountAddress1); assertFalse(isActivated); } } diff --git a/test/unit/EmailRecoveryManager/deInitRecoveryModuleWithAddress.t.sol b/test/unit/EmailRecoveryManager/deInitRecoveryModuleWithAddress.t.sol index 986865dc..77fedaaa 100644 --- a/test/unit/EmailRecoveryManager/deInitRecoveryModuleWithAddress.t.sol +++ b/test/unit/EmailRecoveryManager/deInitRecoveryModuleWithAddress.t.sol @@ -13,37 +13,37 @@ contract EmailRecoveryManager_deInitRecoveryModuleWithAddress_Test is UnitBase { } function test_DeInitRecoveryModuleWithAddress_RevertWhen_RecoveryInProcess() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(recoveryDataHash, accountSalt1); - vm.prank(accountAddress); + vm.prank(accountAddress1); vm.expectRevert(IGuardianManager.RecoveryInProcess.selector); - emailRecoveryModule.exposed_deInitRecoveryModule(accountAddress); + emailRecoveryModule.exposed_deInitRecoveryModule(accountAddress1); } function test_DeInitRecoveryModuleWithAddress_Succeeds() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); - bool isActivated = emailRecoveryModule.isActivated(accountAddress); + bool isActivated = emailRecoveryModule.isActivated(accountAddress1); assertTrue(isActivated); - vm.prank(accountAddress); + vm.prank(accountAddress1); vm.expectEmit(); - emit IEmailRecoveryManager.RecoveryDeInitialized(accountAddress); - emailRecoveryModule.exposed_deInitRecoveryModule(accountAddress); + emit IEmailRecoveryManager.RecoveryDeInitialized(accountAddress1); + emailRecoveryModule.exposed_deInitRecoveryModule(accountAddress1); // assert that recovery config has been cleared successfully IEmailRecoveryManager.RecoveryConfig memory recoveryConfig = - emailRecoveryModule.getRecoveryConfig(accountAddress); + emailRecoveryModule.getRecoveryConfig(accountAddress1); assertEq(recoveryConfig.delay, 0); assertEq(recoveryConfig.expiry, 0); // assert that the recovery request has been cleared successfully IEmailRecoveryManager.RecoveryRequest memory recoveryRequest = - emailRecoveryModule.getRecoveryRequest(accountAddress); + emailRecoveryModule.getRecoveryRequest(accountAddress1); assertEq(recoveryRequest.executeAfter, 0); assertEq(recoveryRequest.executeBefore, 0); assertEq(recoveryRequest.currentWeight, 0); @@ -51,25 +51,25 @@ contract EmailRecoveryManager_deInitRecoveryModuleWithAddress_Test is UnitBase { // assert that guardian storage has been cleared successfully for guardian 1 GuardianStorage memory guardianStorage1 = - emailRecoveryModule.getGuardian(accountAddress, guardian1); + emailRecoveryModule.getGuardian(accountAddress1, guardians1[0]); assertEq(uint256(guardianStorage1.status), uint256(GuardianStatus.NONE)); assertEq(guardianStorage1.weight, uint256(0)); // assert that guardian storage has been cleared successfully for guardian 2 GuardianStorage memory guardianStorage2 = - emailRecoveryModule.getGuardian(accountAddress, guardian2); + emailRecoveryModule.getGuardian(accountAddress1, guardians1[1]); assertEq(uint256(guardianStorage2.status), uint256(GuardianStatus.NONE)); assertEq(guardianStorage2.weight, uint256(0)); // assert that guardian config has been cleared successfully GuardianManager.GuardianConfig memory guardianConfig = - emailRecoveryModule.getGuardianConfig(accountAddress); + emailRecoveryModule.getGuardianConfig(accountAddress1); assertEq(guardianConfig.guardianCount, 0); assertEq(guardianConfig.totalWeight, 0); assertEq(guardianConfig.acceptedWeight, 0); assertEq(guardianConfig.threshold, 0); - isActivated = emailRecoveryModule.isActivated(accountAddress); + isActivated = emailRecoveryModule.isActivated(accountAddress1); assertFalse(isActivated); } } diff --git a/test/unit/EmailRecoveryManager/getRecoveryConfig.t.sol b/test/unit/EmailRecoveryManager/getRecoveryConfig.t.sol index 36e7a62b..551a6cb0 100644 --- a/test/unit/EmailRecoveryManager/getRecoveryConfig.t.sol +++ b/test/unit/EmailRecoveryManager/getRecoveryConfig.t.sol @@ -15,17 +15,17 @@ contract EmailRecoveryManager_getRecoveryConfig_Test is UnitBase { IEmailRecoveryManager.RecoveryConfig memory recoveryConfig = IEmailRecoveryManager.RecoveryConfig(newDelay, newExpiry); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.updateRecoveryConfig(recoveryConfig); - recoveryConfig = emailRecoveryModule.getRecoveryConfig(accountAddress); + recoveryConfig = emailRecoveryModule.getRecoveryConfig(accountAddress1); assertEq(recoveryConfig.delay, newDelay); assertEq(recoveryConfig.expiry, newExpiry); } function test_GetRecoveryConfig_Succeeds() public view { IEmailRecoveryManager.RecoveryConfig memory result = - emailRecoveryModule.getRecoveryConfig(accountAddress); + emailRecoveryModule.getRecoveryConfig(accountAddress1); assertEq(result.delay, newDelay); assertEq(result.expiry, newExpiry); } diff --git a/test/unit/EmailRecoveryManager/getRecoveryRequest.t.sol b/test/unit/EmailRecoveryManager/getRecoveryRequest.t.sol index a2627606..83813414 100644 --- a/test/unit/EmailRecoveryManager/getRecoveryRequest.t.sol +++ b/test/unit/EmailRecoveryManager/getRecoveryRequest.t.sol @@ -11,13 +11,13 @@ contract EmailRecoveryManager_getRecoveryRequest_Test is UnitBase { } function test_GetRecoveryRequest_Succeeds() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(recoveryDataHash, accountSalt1); IEmailRecoveryManager.RecoveryRequest memory recoveryRequest = - emailRecoveryModule.getRecoveryRequest(accountAddress); + emailRecoveryModule.getRecoveryRequest(accountAddress1); assertEq(recoveryRequest.executeAfter, 0); assertEq(recoveryRequest.executeBefore, block.timestamp + expiry); assertEq(recoveryRequest.currentWeight, 1); diff --git a/test/unit/EmailRecoveryManager/isActivated.t.sol b/test/unit/EmailRecoveryManager/isActivated.t.sol index 04aed35a..e80df67d 100644 --- a/test/unit/EmailRecoveryManager/isActivated.t.sol +++ b/test/unit/EmailRecoveryManager/isActivated.t.sol @@ -15,14 +15,14 @@ contract EmailRecoveryManager_isActivated_Test is UnitBase { } function test_isActivated_ReturnsTrueWhenModuleIsInstalled() public view { - bool isActivated = emailRecoveryModule.isActivated(accountAddress); + bool isActivated = emailRecoveryModule.isActivated(accountAddress1); assertTrue(isActivated); } function test_isActivated_ReturnsFalseWhenModuleIsInstalled() public { - instance.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); - bool isActivated = emailRecoveryModule.isActivated(accountAddress); + bool isActivated = emailRecoveryModule.isActivated(accountAddress1); assertFalse(isActivated); } } diff --git a/test/unit/EmailRecoveryManager/processRecovery.t.sol b/test/unit/EmailRecoveryManager/processRecovery.t.sol index a5c02976..0d15df99 100644 --- a/test/unit/EmailRecoveryManager/processRecovery.t.sol +++ b/test/unit/EmailRecoveryManager/processRecovery.t.sol @@ -22,7 +22,7 @@ contract EmailRecoveryManager_processRecovery_Test is UnitBase { recoveryDataHashString = uint256(recoveryDataHash).toHexString(32); commandParams = new bytes[](2); - commandParams[0] = abi.encode(accountAddress); + commandParams[0] = abi.encode(accountAddress1); commandParams[1] = abi.encode(recoveryDataHashString); nullifier = keccak256(abi.encode("nullifier 1")); } @@ -30,8 +30,8 @@ contract EmailRecoveryManager_processRecovery_Test is UnitBase { function test_ProcessRecovery_RevertWhen_GuardianStatusIsNONE() public { address invalidGuardian = address(1); - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); // invalidGuardian has not been configured nor accepted, so the guardian status is NONE vm.expectRevert( @@ -47,8 +47,8 @@ contract EmailRecoveryManager_processRecovery_Test is UnitBase { } function test_ProcessRecovery_RevertWhen_GuardianStatusIsREQUESTED() public { - acceptGuardian(accountSalt2); - acceptGuardian(accountSalt3); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[2], emailRecoveryModuleAddress); // Valid guardian but we haven't called acceptGuardian(), so the guardian // status is still REQUESTED @@ -60,18 +60,18 @@ contract EmailRecoveryManager_processRecovery_Test is UnitBase { ) ); emailRecoveryModule.exposed_processRecovery( - guardian1, templateIdx, commandParams, nullifier + guardians1[0], templateIdx, commandParams, nullifier ); } function test_ProcessRecovery_RevertWhen_RecoveryModuleNotInstalled() public { - vm.prank(accountAddress); - instance.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + vm.prank(accountAddress1); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); vm.stopPrank(); vm.expectRevert(IEmailRecoveryManager.RecoveryIsNotActivated.selector); emailRecoveryModule.exposed_processRecovery( - guardian1, templateIdx, commandParams, nullifier + guardians1[0], templateIdx, commandParams, nullifier ); } @@ -80,8 +80,8 @@ contract EmailRecoveryManager_processRecovery_Test is UnitBase { // threshold = 3 // useable weight from accepted guardians = 0 - acceptGuardian(accountSalt1); // weight = 1 - acceptGuardian(accountSalt2); // weight = 2 + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); // weight = 1 + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); // weight = 2 // total weight = 4 // threshold = 3 @@ -91,7 +91,7 @@ contract EmailRecoveryManager_processRecovery_Test is UnitBase { uint256 newWeight = 1; uint256 newThreshold = 5; - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.addGuardian(newGuardian, newWeight); emailRecoveryModule.changeThreshold(newThreshold); vm.stopPrank(); @@ -107,7 +107,7 @@ contract EmailRecoveryManager_processRecovery_Test is UnitBase { ) ); emailRecoveryModule.exposed_processRecovery( - guardian2, templateIdx, commandParams, nullifier + guardians1[1], templateIdx, commandParams, nullifier ); } @@ -116,11 +116,11 @@ contract EmailRecoveryManager_processRecovery_Test is UnitBase { string memory invalidRecoveryDataHashString = uint256(invalidRecoveryDataHash).toHexString(32); - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); emailRecoveryModule.exposed_processRecovery( - guardian1, templateIdx, commandParams, nullifier + guardians1[0], templateIdx, commandParams, nullifier ); commandParams[1] = abi.encode(invalidRecoveryDataHashString); @@ -133,22 +133,22 @@ contract EmailRecoveryManager_processRecovery_Test is UnitBase { ) ); emailRecoveryModule.exposed_processRecovery( - guardian1, templateIdx, commandParams, nullifier + guardians1[0], templateIdx, commandParams, nullifier ); } function test_ProcessRecovery_IncreasesTotalWeight() public { uint256 guardian1Weight = guardianWeights[0]; - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); emailRecoveryModule.exposed_processRecovery( - guardian1, templateIdx, commandParams, nullifier + guardians1[0], templateIdx, commandParams, nullifier ); IEmailRecoveryManager.RecoveryRequest memory recoveryRequest = - emailRecoveryModule.getRecoveryRequest(accountAddress); + emailRecoveryModule.getRecoveryRequest(accountAddress1); assertEq(recoveryRequest.executeAfter, 0); assertEq(recoveryRequest.executeBefore, block.timestamp + expiry); assertEq(recoveryRequest.currentWeight, guardian1Weight); @@ -159,27 +159,27 @@ contract EmailRecoveryManager_processRecovery_Test is UnitBase { uint256 guardian1Weight = guardianWeights[0]; uint256 guardian2Weight = guardianWeights[1]; - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); // Call processRecovery - increases currentWeight to 1 so not >= threshold yet handleRecovery(recoveryDataHash, accountSalt1); - // Call processRecovery with guardian2 which increases currentWeight to >= threshold + // Call processRecovery with guardians2 which increases currentWeight to >= threshold vm.expectEmit(); emit IEmailRecoveryManager.RecoveryProcessed( - accountAddress, - guardian2, + accountAddress1, + guardians1[1], block.timestamp + delay, block.timestamp + expiry, recoveryDataHash ); emailRecoveryModule.exposed_processRecovery( - guardian2, templateIdx, commandParams, nullifier + guardians1[1], templateIdx, commandParams, nullifier ); IEmailRecoveryManager.RecoveryRequest memory recoveryRequest = - emailRecoveryModule.getRecoveryRequest(accountAddress); + emailRecoveryModule.getRecoveryRequest(accountAddress1); assertEq(recoveryRequest.executeAfter, block.timestamp + delay); assertEq(recoveryRequest.executeBefore, block.timestamp + expiry); assertEq(recoveryRequest.currentWeight, guardian1Weight + guardian2Weight); diff --git a/test/unit/EmailRecoveryManager/updateRecoveryConfig.t.sol b/test/unit/EmailRecoveryManager/updateRecoveryConfig.t.sol index 2abd2a49..261e0f14 100644 --- a/test/unit/EmailRecoveryManager/updateRecoveryConfig.t.sol +++ b/test/unit/EmailRecoveryManager/updateRecoveryConfig.t.sol @@ -14,13 +14,13 @@ contract EmailRecoveryManager_updateRecoveryConfig_Test is UnitBase { IEmailRecoveryManager.RecoveryConfig memory recoveryConfig = IEmailRecoveryManager.RecoveryConfig(delay, expiry); - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(recoveryDataHash, accountSalt1); handleRecovery(recoveryDataHash, accountSalt2); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert(IGuardianManager.RecoveryInProcess.selector); emailRecoveryModule.updateRecoveryConfig(recoveryConfig); } @@ -41,7 +41,7 @@ contract EmailRecoveryManager_updateRecoveryConfig_Test is UnitBase { IEmailRecoveryManager.RecoveryConfig memory recoveryConfig = IEmailRecoveryManager.RecoveryConfig(invalidDelay, expiry); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert( abi.encodeWithSelector( IEmailRecoveryManager.DelayMoreThanExpiry.selector, invalidDelay, expiry @@ -57,7 +57,7 @@ contract EmailRecoveryManager_updateRecoveryConfig_Test is UnitBase { IEmailRecoveryManager.RecoveryConfig memory recoveryConfig = IEmailRecoveryManager.RecoveryConfig(newDelay, newExpiry); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert( abi.encodeWithSelector( IEmailRecoveryManager.RecoveryWindowTooShort.selector, newExpiry - newDelay @@ -73,7 +73,7 @@ contract EmailRecoveryManager_updateRecoveryConfig_Test is UnitBase { IEmailRecoveryManager.RecoveryConfig memory recoveryConfig = IEmailRecoveryManager.RecoveryConfig(newDelay, newExpiry); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert( abi.encodeWithSelector( IEmailRecoveryManager.RecoveryWindowTooShort.selector, newExpiry - newDelay @@ -91,10 +91,10 @@ contract EmailRecoveryManager_updateRecoveryConfig_Test is UnitBase { IEmailRecoveryManager.RecoveryConfig memory recoveryConfig = IEmailRecoveryManager.RecoveryConfig(newDelay, newExpiry); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.updateRecoveryConfig(recoveryConfig); - recoveryConfig = emailRecoveryModule.getRecoveryConfig(accountAddress); + recoveryConfig = emailRecoveryModule.getRecoveryConfig(accountAddress1); assertEq(recoveryConfig.delay, newDelay); assertEq(recoveryConfig.expiry, newExpiry); } @@ -106,14 +106,14 @@ contract EmailRecoveryManager_updateRecoveryConfig_Test is UnitBase { IEmailRecoveryManager.RecoveryConfig memory recoveryConfig = IEmailRecoveryManager.RecoveryConfig(newDelay, newExpiry); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectEmit(); emit IEmailRecoveryManager.RecoveryConfigUpdated( - accountAddress, recoveryConfig.delay, recoveryConfig.expiry + accountAddress1, recoveryConfig.delay, recoveryConfig.expiry ); emailRecoveryModule.updateRecoveryConfig(recoveryConfig); - recoveryConfig = emailRecoveryModule.getRecoveryConfig(accountAddress); + recoveryConfig = emailRecoveryModule.getRecoveryConfig(accountAddress1); assertEq(recoveryConfig.delay, newDelay); assertEq(recoveryConfig.expiry, newExpiry); } diff --git a/test/unit/GuardianManager/addGuardian.t.sol b/test/unit/GuardianManager/addGuardian.t.sol index 3c7efc79..3efca95e 100644 --- a/test/unit/GuardianManager/addGuardian.t.sol +++ b/test/unit/GuardianManager/addGuardian.t.sol @@ -15,30 +15,30 @@ contract GuardianManager_addGuardian_Test is UnitBase { } function test_AddGuardian_RevertWhen_AlreadyRecovering() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(recoveryDataHash, accountSalt1); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert(IGuardianManager.RecoveryInProcess.selector); - emailRecoveryModule.addGuardian(guardians[0], guardianWeights[0]); + emailRecoveryModule.addGuardian(guardians1[0], guardianWeights[0]); } function test_AddGuardian_RevertWhen_SetupNotCalled() public { - vm.prank(accountAddress); - instance.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + vm.prank(accountAddress1); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); vm.stopPrank(); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert(IGuardianManager.SetupNotCalled.selector); - emailRecoveryModule.addGuardian(guardians[0], guardianWeights[0]); + emailRecoveryModule.addGuardian(guardians1[0], guardianWeights[0]); } function test_AddGuardian_RevertWhen_InvalidGuardianAddress() public { address invalidGuardianAddress = address(0); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert( abi.encodeWithSelector( IGuardianManager.InvalidGuardianAddress.selector, invalidGuardianAddress @@ -48,9 +48,9 @@ contract GuardianManager_addGuardian_Test is UnitBase { } function test_AddGuardian_RevertWhen_GuardianAddressIsAccountAddress() public { - address invalidGuardianAddress = accountAddress; + address invalidGuardianAddress = accountAddress1; - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert( abi.encodeWithSelector( IGuardianManager.InvalidGuardianAddress.selector, invalidGuardianAddress @@ -60,16 +60,16 @@ contract GuardianManager_addGuardian_Test is UnitBase { } function test_AddGuardian_RevertWhen_AddressAlreadyGuardian() public { - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert(IGuardianManager.AddressAlreadyGuardian.selector); - emailRecoveryModule.addGuardian(guardians[0], guardianWeights[0]); + emailRecoveryModule.addGuardian(guardians1[0], guardianWeights[0]); } function test_AddGuardian_RevertWhen_InvalidGuardianWeight() public { address newGuardian = address(1); uint256 invalidGuardianWeight = 0; - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert(IGuardianManager.InvalidGuardianWeight.selector); emailRecoveryModule.addGuardian(newGuardian, invalidGuardianWeight); } @@ -78,23 +78,23 @@ contract GuardianManager_addGuardian_Test is UnitBase { address newGuardian = address(1); uint256 newGuardianWeight = 1; - uint256 expectedGuardianCount = guardians.length + 1; + uint256 expectedGuardianCount = guardians1.length + 1; uint256 expectedTotalWeight = totalWeight + newGuardianWeight; - uint256 expectedAcceptedWeight = 0; // no guardians accepted + uint256 expectedAcceptedWeight = 0; // no guardians1 accepted uint256 expectedThreshold = threshold; // same threshold - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectEmit(); - emit IGuardianManager.AddedGuardian(accountAddress, newGuardian, newGuardianWeight); + emit IGuardianManager.AddedGuardian(accountAddress1, newGuardian, newGuardianWeight); emailRecoveryModule.addGuardian(newGuardian, newGuardianWeight); GuardianStorage memory guardianStorage = - emailRecoveryModule.getGuardian(accountAddress, newGuardian); + emailRecoveryModule.getGuardian(accountAddress1, newGuardian); assertEq(uint256(guardianStorage.status), uint256(GuardianStatus.REQUESTED)); assertEq(guardianStorage.weight, newGuardianWeight); IGuardianManager.GuardianConfig memory guardianConfig = - emailRecoveryModule.getGuardianConfig(accountAddress); + emailRecoveryModule.getGuardianConfig(accountAddress1); assertEq(guardianConfig.guardianCount, expectedGuardianCount); assertEq(guardianConfig.totalWeight, expectedTotalWeight); assertEq(guardianConfig.acceptedWeight, expectedAcceptedWeight); diff --git a/test/unit/GuardianManager/changeThreshold.t.sol b/test/unit/GuardianManager/changeThreshold.t.sol index c41695d3..0be4690a 100644 --- a/test/unit/GuardianManager/changeThreshold.t.sol +++ b/test/unit/GuardianManager/changeThreshold.t.sol @@ -10,12 +10,12 @@ contract GuardianManager_changeThreshold_Test is UnitBase { } function test_RevertWhen_AlreadyRecovering() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(recoveryDataHash, accountSalt1); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert(IGuardianManager.RecoveryInProcess.selector); emailRecoveryModule.changeThreshold(threshold); } @@ -28,7 +28,7 @@ contract GuardianManager_changeThreshold_Test is UnitBase { function test_RevertWhen_ThresholdExceedsTotalWeight() public { uint256 highThreshold = totalWeight + 1; - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert( abi.encodeWithSelector( IGuardianManager.ThresholdExceedsTotalWeight.selector, highThreshold, totalWeight @@ -40,7 +40,7 @@ contract GuardianManager_changeThreshold_Test is UnitBase { function test_RevertWhen_ThresholdIsZero() public { uint256 zeroThreshold = 0; - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert(IGuardianManager.ThresholdCannotBeZero.selector); emailRecoveryModule.changeThreshold(zeroThreshold); } @@ -48,28 +48,28 @@ contract GuardianManager_changeThreshold_Test is UnitBase { function test_ChangeThreshold_IncreaseThreshold() public { uint256 newThreshold = threshold + 1; - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectEmit(); - emit IGuardianManager.ChangedThreshold(accountAddress, newThreshold); + emit IGuardianManager.ChangedThreshold(accountAddress1, newThreshold); emailRecoveryModule.changeThreshold(newThreshold); IGuardianManager.GuardianConfig memory guardianConfig = - emailRecoveryModule.getGuardianConfig(accountAddress); - assertEq(guardianConfig.guardianCount, guardians.length); + emailRecoveryModule.getGuardianConfig(accountAddress1); + assertEq(guardianConfig.guardianCount, guardians1.length); assertEq(guardianConfig.threshold, newThreshold); } function test_ChangeThreshold_DecreaseThreshold() public { uint256 newThreshold = threshold - 1; - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectEmit(); - emit IGuardianManager.ChangedThreshold(accountAddress, newThreshold); + emit IGuardianManager.ChangedThreshold(accountAddress1, newThreshold); emailRecoveryModule.changeThreshold(newThreshold); IGuardianManager.GuardianConfig memory guardianConfig = - emailRecoveryModule.getGuardianConfig(accountAddress); - assertEq(guardianConfig.guardianCount, guardians.length); + emailRecoveryModule.getGuardianConfig(accountAddress1); + assertEq(guardianConfig.guardianCount, guardians1.length); assertEq(guardianConfig.threshold, newThreshold); } } diff --git a/test/unit/GuardianManager/getGuardian.t.sol b/test/unit/GuardianManager/getGuardian.t.sol index c1779b9c..3268be96 100644 --- a/test/unit/GuardianManager/getGuardian.t.sol +++ b/test/unit/GuardianManager/getGuardian.t.sol @@ -11,14 +11,14 @@ contract GuardianManager_getGuardian_Test is UnitBase { function setUp() public override { super.setUp(); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.addGuardian(newGuardian, newGuardianWeight); vm.stopPrank(); } function test_GetGuardian_Succeeds() public view { GuardianStorage memory guardianStorage = - emailRecoveryModule.getGuardian(accountAddress, newGuardian); + emailRecoveryModule.getGuardian(accountAddress1, newGuardian); assertEq(uint256(guardianStorage.status), uint256(GuardianStatus.REQUESTED)); assertEq(guardianStorage.weight, newGuardianWeight); } diff --git a/test/unit/GuardianManager/getGuardianConfig.t.sol b/test/unit/GuardianManager/getGuardianConfig.t.sol index 978e5ab0..9d4d5b7d 100644 --- a/test/unit/GuardianManager/getGuardianConfig.t.sol +++ b/test/unit/GuardianManager/getGuardianConfig.t.sol @@ -17,19 +17,19 @@ contract EmailRecoveryManager_getGuardianConfig_Test is UnitBase { function setUp() public override { super.setUp(); - expectedGuardianCount = guardians.length + 1; + expectedGuardianCount = guardians1.length + 1; expectedTotalWeight = totalWeight + newGuardianWeight; expectedAcceptedWeight = 0; // no guardians accepted expectedThreshold = threshold; - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.addGuardian(newGuardian, newGuardianWeight); vm.stopPrank(); } function test_GetGuardianConfig_Succeeds() public view { IGuardianManager.GuardianConfig memory guardianConfig = - emailRecoveryModule.getGuardianConfig(accountAddress); + emailRecoveryModule.getGuardianConfig(accountAddress1); assertEq(guardianConfig.guardianCount, expectedGuardianCount); assertEq(guardianConfig.totalWeight, expectedTotalWeight); assertEq(guardianConfig.acceptedWeight, expectedAcceptedWeight); diff --git a/test/unit/GuardianManager/removeAllGuardians.t.sol b/test/unit/GuardianManager/removeAllGuardians.t.sol index b3091ba4..948559fd 100644 --- a/test/unit/GuardianManager/removeAllGuardians.t.sol +++ b/test/unit/GuardianManager/removeAllGuardians.t.sol @@ -14,24 +14,24 @@ contract GuardianManager_removeAllGuardians_Test is UnitBase { } function test_RemoveAllGuardians_Succeeds() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); - acceptGuardian(accountSalt3); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[2], emailRecoveryModuleAddress); - emailRecoveryModule.exposed_removeAllGuardians(accountAddress); + emailRecoveryModule.exposed_removeAllGuardians(accountAddress1); GuardianStorage memory guardianStorage1 = - emailRecoveryModule.getGuardian(accountAddress, guardian1); + emailRecoveryModule.getGuardian(accountAddress1, guardians1[0]); assertEq(uint256(guardianStorage1.status), uint256(GuardianStatus.NONE)); assertEq(guardianStorage1.weight, 0); GuardianStorage memory guardianStorage2 = - emailRecoveryModule.getGuardian(accountAddress, guardian2); + emailRecoveryModule.getGuardian(accountAddress1, guardians1[1]); assertEq(uint256(guardianStorage2.status), uint256(GuardianStatus.NONE)); assertEq(guardianStorage2.weight, 0); GuardianStorage memory guardianStorage3 = - emailRecoveryModule.getGuardian(accountAddress, guardian3); + emailRecoveryModule.getGuardian(accountAddress1, guardians1[2]); assertEq(uint256(guardianStorage3.status), uint256(GuardianStatus.NONE)); assertEq(guardianStorage3.weight, 0); } diff --git a/test/unit/GuardianManager/removeGuardian.t.sol b/test/unit/GuardianManager/removeGuardian.t.sol index 45bc3a7b..daa05c88 100644 --- a/test/unit/GuardianManager/removeGuardian.t.sol +++ b/test/unit/GuardianManager/removeGuardian.t.sol @@ -11,28 +11,28 @@ contract GuardianManager_removeGuardian_Test is UnitBase { } function test_RemoveGuardian_RevertWhen_AlreadyRecovering() public { - address guardian = guardian1; + address guardian = guardians1[0]; - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); vm.warp(12 seconds); handleRecovery(recoveryDataHash, accountSalt1); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert(IGuardianManager.RecoveryInProcess.selector); emailRecoveryModule.removeGuardian(guardian); } function test_RemoveGuardian_RevertWhen_AddressNotGuardianForAccount() public { - address unauthorizedAccount = guardian1; + address unauthorizedAccount = guardians1[0]; vm.startPrank(unauthorizedAccount); vm.expectRevert(IGuardianManager.AddressNotGuardianForAccount.selector); - emailRecoveryModule.removeGuardian(guardian1); + emailRecoveryModule.removeGuardian(guardians1[0]); } function test_RemoveGuardian_RevertWhen_ThresholdExceedsTotalWeight() public { - address guardian = guardian2; // guardian 2 weight is 2 + address guardian = guardians1[1]; // guardian 2 weight is 2 // threshold = 3 // totalWeight = 4 // weight = 2 @@ -41,9 +41,9 @@ contract GuardianManager_removeGuardian_Test is UnitBase { // (totalWeight - weight == 4 - 2) = 2 // (weight < threshold == 2 < 3) = fails - acceptGuardian(accountSalt1); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert( abi.encodeWithSelector( IGuardianManager.ThresholdExceedsTotalWeight.selector, @@ -55,7 +55,7 @@ contract GuardianManager_removeGuardian_Test is UnitBase { } function test_RemoveGuardian_Succeeds() public { - address guardian = guardian1; // guardian 1 weight is 1 + address guardian = guardians1[0]; // guardian 1 weight is 1 // threshold = 3 // totalWeight = 4 // weight = 1 @@ -64,19 +64,19 @@ contract GuardianManager_removeGuardian_Test is UnitBase { // (totalWeight - weight == 4 - 1) = 3 // (weight < threshold == 3 < 3) = succeeds - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectEmit(); - emit IGuardianManager.RemovedGuardian(accountAddress, guardian, guardianWeights[0]); + emit IGuardianManager.RemovedGuardian(accountAddress1, guardian, guardianWeights[0]); emailRecoveryModule.removeGuardian(guardian); GuardianStorage memory guardianStorage = - emailRecoveryModule.getGuardian(accountAddress, guardian); + emailRecoveryModule.getGuardian(accountAddress1, guardian); assertEq(uint256(guardianStorage.status), uint256(GuardianStatus.NONE)); assertEq(guardianStorage.weight, 0); IGuardianManager.GuardianConfig memory guardianConfig = - emailRecoveryModule.getGuardianConfig(accountAddress); - assertEq(guardianConfig.guardianCount, guardians.length - 1); + emailRecoveryModule.getGuardianConfig(accountAddress1); + assertEq(guardianConfig.guardianCount, guardians1.length - 1); assertEq(guardianConfig.totalWeight, totalWeight - guardianWeights[0]); assertEq(guardianConfig.acceptedWeight, 0); // 1 - 1 = 0 @@ -84,7 +84,7 @@ contract GuardianManager_removeGuardian_Test is UnitBase { } function test_RemoveGuardian_SucceedsWithAcceptedGuardian() public { - address guardian = guardian1; // guardian 1 weight is 1 + address guardian = guardians1[0]; // guardian 1 weight is 1 // threshold = 3 // totalWeight = 4 // weight = 1 @@ -93,22 +93,22 @@ contract GuardianManager_removeGuardian_Test is UnitBase { // (totalWeight - weight == 4 - 1) = 3 // (weight < threshold == 3 < 3) = succeeds - acceptGuardian(accountSalt1); // weight = 1 - acceptGuardian(accountSalt2); // weight = 2 + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); // weight = 1 + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); // weight = 2 - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectEmit(); - emit IGuardianManager.RemovedGuardian(accountAddress, guardian, guardianWeights[0]); + emit IGuardianManager.RemovedGuardian(accountAddress1, guardian, guardianWeights[0]); emailRecoveryModule.removeGuardian(guardian); GuardianStorage memory guardianStorage = - emailRecoveryModule.getGuardian(accountAddress, guardian); + emailRecoveryModule.getGuardian(accountAddress1, guardian); assertEq(uint256(guardianStorage.status), uint256(GuardianStatus.NONE)); assertEq(guardianStorage.weight, 0); IGuardianManager.GuardianConfig memory guardianConfig = - emailRecoveryModule.getGuardianConfig(accountAddress); - assertEq(guardianConfig.guardianCount, guardians.length - 1); + emailRecoveryModule.getGuardianConfig(accountAddress1); + assertEq(guardianConfig.guardianCount, guardians1.length - 1); assertEq(guardianConfig.totalWeight, totalWeight - guardianWeights[0]); // Accepted weight before guardian is removed = 3 diff --git a/test/unit/GuardianManager/setupGuardians.t.sol b/test/unit/GuardianManager/setupGuardians.t.sol index 4ae56d0a..81e81d4a 100644 --- a/test/unit/GuardianManager/setupGuardians.t.sol +++ b/test/unit/GuardianManager/setupGuardians.t.sol @@ -24,12 +24,12 @@ contract GuardianManager_setupGuardians_Test is UnitBase { vm.expectRevert( abi.encodeWithSelector( IGuardianManager.IncorrectNumberOfWeights.selector, - guardians.length, + guardians1.length, invalidGuardianWeights.length ) ); emailRecoveryModule.exposed_setupGuardians( - accountAddress, guardians, invalidGuardianWeights, threshold + accountAddress1, guardians1, invalidGuardianWeights, threshold ); } @@ -38,59 +38,59 @@ contract GuardianManager_setupGuardians_Test is UnitBase { vm.expectRevert(IGuardianManager.ThresholdCannotBeZero.selector); emailRecoveryModule.exposed_setupGuardians( - accountAddress, guardians, guardianWeights, zeroThreshold + accountAddress1, guardians1, guardianWeights, zeroThreshold ); } function test_SetupGuardians_RevertWhen_InvalidGuardianAddress() public { - guardians[0] = address(0); + guardians1[0] = address(0); vm.expectRevert( - abi.encodeWithSelector(IGuardianManager.InvalidGuardianAddress.selector, guardians[0]) + abi.encodeWithSelector(IGuardianManager.InvalidGuardianAddress.selector, guardians1[0]) ); emailRecoveryModule.exposed_setupGuardians( - accountAddress, guardians, guardianWeights, threshold + accountAddress1, guardians1, guardianWeights, threshold ); } function test_SetupGuardians_RevertWhen_GuardianAddressIsAccountAddress() public { - guardians[0] = accountAddress; + guardians1[0] = accountAddress1; vm.expectRevert( - abi.encodeWithSelector(IGuardianManager.InvalidGuardianAddress.selector, guardians[0]) + abi.encodeWithSelector(IGuardianManager.InvalidGuardianAddress.selector, guardians1[0]) ); emailRecoveryModule.exposed_setupGuardians( - accountAddress, guardians, guardianWeights, threshold + accountAddress1, guardians1, guardianWeights, threshold ); } function test_SetupGuardians_RevertWhen_InvalidGuardianWeight() public { - vm.prank(accountAddress); - instance.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + vm.prank(accountAddress1); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); vm.stopPrank(); guardianWeights[0] = 0; vm.expectRevert(IGuardianManager.InvalidGuardianWeight.selector); emailRecoveryModule.exposed_setupGuardians( - accountAddress, guardians, guardianWeights, threshold + accountAddress1, guardians1, guardianWeights, threshold ); } function test_SetupGuardians_RevertWhen_AddressAlreadyGuardian() public { - guardians[0] = guardians[1]; + guardians1[0] = guardians1[1]; vm.expectRevert(IGuardianManager.AddressAlreadyGuardian.selector); emailRecoveryModule.exposed_setupGuardians( - accountAddress, guardians, guardianWeights, threshold + accountAddress1, guardians1, guardianWeights, threshold ); } function test_SetupGuardians_RevertWhen_ThresholdExceedsTotalWeight() public { uint256 invalidThreshold = totalWeight + 1; - vm.prank(accountAddress); - instance.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + vm.prank(accountAddress1); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); vm.stopPrank(); vm.expectRevert( @@ -99,30 +99,30 @@ contract GuardianManager_setupGuardians_Test is UnitBase { ) ); emailRecoveryModule.exposed_setupGuardians( - accountAddress, guardians, guardianWeights, invalidThreshold + accountAddress1, guardians1, guardianWeights, invalidThreshold ); } function test_SetupGuardians_Succeeds() public { - uint256 expectedGuardianCount = guardians.length; + uint256 expectedGuardianCount = guardians1.length; uint256 expectedTotalWeight = totalWeight; uint256 expectedAcceptedWeight = 0; // no guardians accepted uint256 expectedThreshold = threshold; - vm.prank(accountAddress); - instance.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + vm.prank(accountAddress1); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); vm.stopPrank(); (uint256 guardianCount, uint256 totalWeight) = emailRecoveryModule.exposed_setupGuardians( - accountAddress, guardians, guardianWeights, threshold + accountAddress1, guardians1, guardianWeights, threshold ); GuardianStorage memory guardianStorage1 = - emailRecoveryModule.getGuardian(accountAddress, guardians[0]); + emailRecoveryModule.getGuardian(accountAddress1, guardians1[0]); GuardianStorage memory guardianStorage2 = - emailRecoveryModule.getGuardian(accountAddress, guardians[1]); + emailRecoveryModule.getGuardian(accountAddress1, guardians1[1]); GuardianStorage memory guardianStorage3 = - emailRecoveryModule.getGuardian(accountAddress, guardians[2]); + emailRecoveryModule.getGuardian(accountAddress1, guardians1[2]); assertEq(uint256(guardianStorage1.status), uint256(GuardianStatus.REQUESTED)); assertEq(guardianStorage1.weight, guardianWeights[0]); assertEq(uint256(guardianStorage2.status), uint256(GuardianStatus.REQUESTED)); @@ -134,7 +134,7 @@ contract GuardianManager_setupGuardians_Test is UnitBase { assertEq(totalWeight, expectedTotalWeight); IGuardianManager.GuardianConfig memory guardianConfig = - emailRecoveryModule.getGuardianConfig(accountAddress); + emailRecoveryModule.getGuardianConfig(accountAddress1); assertEq(guardianConfig.guardianCount, expectedGuardianCount); assertEq(guardianConfig.totalWeight, expectedTotalWeight); assertEq(guardianConfig.acceptedWeight, expectedAcceptedWeight); diff --git a/test/unit/GuardianManager/updateGuardianStatus.t.sol b/test/unit/GuardianManager/updateGuardianStatus.t.sol index b639967e..580d016e 100644 --- a/test/unit/GuardianManager/updateGuardianStatus.t.sol +++ b/test/unit/GuardianManager/updateGuardianStatus.t.sol @@ -13,8 +13,8 @@ contract GuardianManager_updateGuardianStatus_Test is UnitBase { function setUp() public override { super.setUp(); - vm.prank(accountAddress); - instance.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + vm.prank(accountAddress1); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); vm.stopPrank(); } @@ -26,46 +26,46 @@ contract GuardianManager_updateGuardianStatus_Test is UnitBase { IGuardianManager.StatusCannotBeTheSame.selector, uint256(newStatus) ) ); - emailRecoveryModule.exposed_updateGuardianStatus(accountAddress, guardian1, newStatus); + emailRecoveryModule.exposed_updateGuardianStatus(accountAddress1, guardians1[0], newStatus); } function test_UpdateGuardianStatus_RevertWhen_StatusIsAlreadyREQUESTED() public { GuardianStatus newStatus = GuardianStatus.REQUESTED; - emailRecoveryModule.exposed_updateGuardianStatus(accountAddress, guardian1, newStatus); + emailRecoveryModule.exposed_updateGuardianStatus(accountAddress1, guardians1[0], newStatus); vm.expectRevert( abi.encodeWithSelector( IGuardianManager.StatusCannotBeTheSame.selector, uint256(newStatus) ) ); - emailRecoveryModule.exposed_updateGuardianStatus(accountAddress, guardian1, newStatus); + emailRecoveryModule.exposed_updateGuardianStatus(accountAddress1, guardians1[0], newStatus); } function test_UpdateGuardianStatus_RevertWhen_StatusIsAlreadyACCEPTED() public { GuardianStatus newStatus = GuardianStatus.ACCEPTED; - emailRecoveryModule.exposed_updateGuardianStatus(accountAddress, guardian1, newStatus); + emailRecoveryModule.exposed_updateGuardianStatus(accountAddress1, guardians1[0], newStatus); vm.expectRevert( abi.encodeWithSelector( IGuardianManager.StatusCannotBeTheSame.selector, uint256(newStatus) ) ); - emailRecoveryModule.exposed_updateGuardianStatus(accountAddress, guardian1, newStatus); + emailRecoveryModule.exposed_updateGuardianStatus(accountAddress1, guardians1[0], newStatus); } function test_UpdateGuardianStatus_UpdatesStatusToNONE() public { GuardianStatus newStatus = GuardianStatus.NONE; emailRecoveryModule.exposed_updateGuardianStatus( - accountAddress, guardian1, GuardianStatus.REQUESTED + accountAddress1, guardians1[0], GuardianStatus.REQUESTED ); - emailRecoveryModule.exposed_updateGuardianStatus(accountAddress, guardian1, newStatus); + emailRecoveryModule.exposed_updateGuardianStatus(accountAddress1, guardians1[0], newStatus); GuardianStorage memory guardianStorage = - emailRecoveryModule.getGuardian(accountAddress, guardian1); + emailRecoveryModule.getGuardian(accountAddress1, guardians1[0]); assertEq(uint256(guardianStorage.status), uint256(newStatus)); assertEq(guardianStorage.weight, 0); } @@ -73,10 +73,10 @@ contract GuardianManager_updateGuardianStatus_Test is UnitBase { function test_UpdateGuardianStatus_UpdatesStatusToREQUESTED() public { GuardianStatus newStatus = GuardianStatus.REQUESTED; - emailRecoveryModule.exposed_updateGuardianStatus(accountAddress, guardian1, newStatus); + emailRecoveryModule.exposed_updateGuardianStatus(accountAddress1, guardians1[0], newStatus); GuardianStorage memory guardianStorage = - emailRecoveryModule.getGuardian(accountAddress, guardian1); + emailRecoveryModule.getGuardian(accountAddress1, guardians1[0]); assertEq(uint256(guardianStorage.status), uint256(newStatus)); assertEq(guardianStorage.weight, 0); } @@ -85,11 +85,11 @@ contract GuardianManager_updateGuardianStatus_Test is UnitBase { GuardianStatus newStatus = GuardianStatus.ACCEPTED; vm.expectEmit(); - emit IGuardianManager.GuardianStatusUpdated(accountAddress, guardian1, newStatus); - emailRecoveryModule.exposed_updateGuardianStatus(accountAddress, guardian1, newStatus); + emit IGuardianManager.GuardianStatusUpdated(accountAddress1, guardians1[0], newStatus); + emailRecoveryModule.exposed_updateGuardianStatus(accountAddress1, guardians1[0], newStatus); GuardianStorage memory guardianStorage = - emailRecoveryModule.getGuardian(accountAddress, guardian1); + emailRecoveryModule.getGuardian(accountAddress1, guardians1[0]); assertEq(uint256(guardianStorage.status), uint256(newStatus)); assertEq(guardianStorage.weight, 0); } diff --git a/test/unit/SafeUnitBase.t.sol b/test/unit/SafeUnitBase.t.sol index bd4ef1ed..be1e7155 100644 --- a/test/unit/SafeUnitBase.t.sol +++ b/test/unit/SafeUnitBase.t.sol @@ -20,7 +20,7 @@ abstract contract SafeUnitBase is IntegrationBase { EmailRecoveryFactory emailRecoveryFactory; SafeRecoveryCommandHandlerHarness safeRecoveryCommandHandler; UniversalEmailRecoveryModule emailRecoveryModule; - address recoveryModuleAddress; + address emailRecoveryModuleAddress; bytes4 functionSelector; bytes recoveryData; @@ -53,22 +53,8 @@ abstract contract SafeUnitBase is IntegrationBase { } super.setUp(); - // Deploy handler, manager and module - safeRecoveryCommandHandler = new SafeRecoveryCommandHandlerHarness(); - emailRecoveryFactory = new EmailRecoveryFactory(address(verifier), address(emailAuthImpl)); - - emailRecoveryModule = new UniversalEmailRecoveryModule( - address(verifier), - address(dkimRegistry), - address(emailAuthImpl), - address(safeRecoveryCommandHandler) - ); - recoveryModuleAddress = address(emailRecoveryModule); - functionSelector = bytes4(keccak256(bytes("swapOwner(address,address,address)"))); address previousOwnerInLinkedList = address(1); - // address previousOwnerInLinkedList = - // safeRecoveryCommandHandler.previousOwnerInLinkedList(accountAddress, owner); bytes memory swapOwnerCalldata = abi.encodeWithSignature( "swapOwner(address,address,address)", previousOwnerInLinkedList, owner1, newOwner1 ); @@ -76,15 +62,9 @@ abstract contract SafeUnitBase is IntegrationBase { recoveryDataHash = keccak256(recoveryData); isInstalledContext = bytes("0"); - // Compute guardian addresses - guardians1 = new address[](3); - guardians1[0] = emailRecoveryModule.computeEmailAuthAddress(instance1.account, accountSalt1); - guardians1[1] = emailRecoveryModule.computeEmailAuthAddress(instance1.account, accountSalt2); - guardians1[2] = emailRecoveryModule.computeEmailAuthAddress(instance1.account, accountSalt3); - instance1.installModule({ moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, + module: emailRecoveryModuleAddress, data: abi.encode( accountAddress1, isInstalledContext, @@ -98,50 +78,30 @@ abstract contract SafeUnitBase is IntegrationBase { }); } - function generateMockEmailProof( - string memory command, - bytes32 nullifier, + function computeEmailAuthAddress( + address account, bytes32 accountSalt ) public view - returns (EmailProof memory) + override + returns (address) { - EmailProof memory emailProof; - emailProof.domainName = "gmail.com"; - emailProof.publicKeyHash = bytes32( - vm.parseUint( - "6632353713085157925504008443078919716322386156160602218536961028046468237192" - ) - ); - emailProof.timestamp = block.timestamp; - emailProof.maskedCommand = command; - emailProof.emailNullifier = nullifier; - emailProof.accountSalt = accountSalt; - emailProof.isCodeExist = true; - emailProof.proof = bytes("0"); - - return emailProof; + return emailRecoveryModule.computeEmailAuthAddress(account, accountSalt); } - function acceptGuardian(address account, bytes32 accountSalt) public { - string memory accountString = CommandUtils.addressToChecksumHexString(account); - string memory command = string.concat("Accept guardian request for ", accountString); - - bytes32 nullifier = keccak256(abi.encode("nullifier 1")); - uint256 templateIdx = 0; - EmailProof memory emailProof = generateMockEmailProof(command, nullifier, accountSalt); - - bytes[] memory commandParamsForAcceptance = new bytes[](1); - commandParamsForAcceptance[0] = abi.encode(account); + function deployModule() public override { + // Deploy handler, manager and module + safeRecoveryCommandHandler = new SafeRecoveryCommandHandlerHarness(); + emailRecoveryFactory = new EmailRecoveryFactory(address(verifier), address(emailAuthImpl)); - EmailAuthMsg memory emailAuthMsg = EmailAuthMsg({ - templateId: emailRecoveryModule.computeAcceptanceTemplateId(templateIdx), - commandParams: commandParamsForAcceptance, - skippedCommandPrefix: 0, - proof: emailProof - }); - emailRecoveryModule.handleAcceptance(emailAuthMsg, templateIdx); + emailRecoveryModule = new UniversalEmailRecoveryModule( + address(verifier), + address(dkimRegistry), + address(emailAuthImpl), + address(safeRecoveryCommandHandler) + ); + emailRecoveryModuleAddress = address(emailRecoveryModule); } function handleRecovery(address account, bytes32 accountSalt) public { diff --git a/test/unit/UnitBase.t.sol b/test/unit/UnitBase.t.sol index 94352f2a..e48074d2 100644 --- a/test/unit/UnitBase.t.sol +++ b/test/unit/UnitBase.t.sol @@ -1,12 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.25; -import { - RhinestoneModuleKit, - AccountInstance, - ModuleKitHelpers, - ModuleKitUserOp -} from "modulekit/ModuleKit.sol"; +import { AccountInstance, ModuleKitHelpers, ModuleKitUserOp } from "modulekit/ModuleKit.sol"; import { MODULE_TYPE_EXECUTOR, MODULE_TYPE_VALIDATOR } from "modulekit/external/ERC7579.sol"; import { ECDSAOwnedDKIMRegistry } from "@zk-email/ether-email-auth-contracts/src/utils/ECDSAOwnedDKIMRegistry.sol"; @@ -29,156 +24,46 @@ import { OwnableValidator } from "src/test/OwnableValidator.sol"; import { MockGroth16Verifier } from "src/test/MockGroth16Verifier.sol"; import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; -abstract contract UnitBase is RhinestoneModuleKit, BaseTest { +abstract contract UnitBase is BaseTest { using ModuleKitHelpers for *; using ModuleKitUserOp for *; using Strings for uint256; - // ZK Email contracts and variables - address zkEmailDeployer = vm.addr(1); - ECDSAOwnedDKIMRegistry dkimRegistry; - MockGroth16Verifier verifier; - EmailAuth emailAuthImpl; - EmailRecoveryFactory emailRecoveryFactory; EmailRecoveryUniversalFactory emailRecoveryUniversalFactory; EmailRecoveryCommandHandler emailRecoveryHandler; UniversalEmailRecoveryModuleHarness emailRecoveryModule; - address recoveryModuleAddress; - address validatorAddress; + address emailRecoveryModuleAddress; - OwnableValidator validator; bytes isInstalledContext; bytes4 functionSelector; bytes recoveryData; bytes32 recoveryDataHash; - // account and owners - AccountInstance instance; - address accountAddress; - address owner; - address newOwner; - - // recovery config - address[] guardians; - address guardian1; - address guardian2; - address guardian3; - uint256[] guardianWeights; - uint256 totalWeight; - uint256 delay; - uint256 expiry; - uint256 threshold; - uint256 templateIdx; - - // Account salts - bytes32 accountSalt1; - bytes32 accountSalt2; - bytes32 accountSalt3; - - string selector = "12345"; - string domainName = "gmail.com"; - bytes32 publicKeyHash = 0x0ea9c777dc7110e5a9e89b13f0cfc540e3845ba120b2b6dc24024d61488d4788; - - function setUp() public virtual { - init(); - - // Create ZK Email contracts - vm.startPrank(zkEmailDeployer); - { - ECDSAOwnedDKIMRegistry dkimImpl = new ECDSAOwnedDKIMRegistry(); - ERC1967Proxy dkimProxy = new ERC1967Proxy( - address(dkimImpl), - abi.encodeCall(dkimImpl.initialize, (zkEmailDeployer, zkEmailDeployer)) - ); - dkimRegistry = ECDSAOwnedDKIMRegistry(address(dkimProxy)); - } - 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); - dkimRegistry.setDKIMPublicKeyHash(selector, domainName, publicKeyHash, signature); - - verifier = new MockGroth16Verifier(); - emailAuthImpl = new EmailAuth(); - vm.stopPrank(); + function setUp() public virtual override { + super.setUp(); - // create owners - owner = vm.createWallet("owner").addr; - newOwner = vm.createWallet("newOwner").addr; - address[] memory owners = new address[](1); - owners[0] = owner; - - // Deploy handler, manager and module - emailRecoveryHandler = new EmailRecoveryCommandHandler(); - emailRecoveryFactory = new EmailRecoveryFactory(address(verifier), address(emailAuthImpl)); - emailRecoveryUniversalFactory = - new EmailRecoveryUniversalFactory(address(verifier), address(emailAuthImpl)); - - emailRecoveryModule = new UniversalEmailRecoveryModuleHarness( - address(verifier), - address(dkimRegistry), - address(emailAuthImpl), - address(emailRecoveryHandler) - ); - recoveryModuleAddress = address(emailRecoveryModule); - - // Deploy and fund the account - instance = makeAccountInstance("account"); - accountAddress = instance.account; - vm.deal(address(instance.account), 10 ether); - - accountSalt1 = keccak256(abi.encode("account salt 1")); - accountSalt2 = keccak256(abi.encode("account salt 2")); - accountSalt3 = keccak256(abi.encode("account salt 3")); - - // Compute guardian addresses - guardian1 = emailRecoveryModule.computeEmailAuthAddress(instance.account, accountSalt1); - guardian2 = emailRecoveryModule.computeEmailAuthAddress(instance.account, accountSalt2); - guardian3 = emailRecoveryModule.computeEmailAuthAddress(instance.account, accountSalt3); - - guardians = new address[](3); - guardians[0] = guardian1; - guardians[1] = guardian2; - guardians[2] = guardian3; - - // Set recovery config variables - guardianWeights = new uint256[](3); - guardianWeights[0] = 1; - guardianWeights[1] = 2; - guardianWeights[2] = 1; - totalWeight = 4; - delay = 1 seconds; - expiry = 2 weeks; - threshold = 3; - templateIdx = 0; - - // Deploy validator to be recovered - validator = new OwnableValidator(); - validatorAddress = address(validator); isInstalledContext = bytes("0"); functionSelector = bytes4(keccak256(bytes("changeOwner(address)"))); - bytes memory changeOwnerCalldata = abi.encodeWithSelector(functionSelector, newOwner); + bytes memory changeOwnerCalldata = abi.encodeWithSelector(functionSelector, newOwner1); recoveryData = abi.encode(validatorAddress, changeOwnerCalldata); recoveryDataHash = keccak256(recoveryData); // Install modules - instance.installModule({ + instance1.installModule({ moduleTypeId: MODULE_TYPE_VALIDATOR, module: validatorAddress, - data: abi.encode(owner) + data: abi.encode(owner1) }); - instance.installModule({ + instance1.installModule({ moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, + module: emailRecoveryModuleAddress, data: abi.encode( validatorAddress, isInstalledContext, functionSelector, - guardians, + guardians1, guardianWeights, threshold, delay, @@ -189,6 +74,34 @@ abstract contract UnitBase is RhinestoneModuleKit, BaseTest { // Helper functions + function computeEmailAuthAddress( + address account, + bytes32 accountSalt + ) + public + view + override + returns (address) + { + return emailRecoveryModule.computeEmailAuthAddress(account, accountSalt); + } + + function deployModule() public override { + // Deploy handler, manager and module + emailRecoveryHandler = new EmailRecoveryCommandHandler(); + emailRecoveryFactory = new EmailRecoveryFactory(address(verifier), address(emailAuthImpl)); + emailRecoveryUniversalFactory = + new EmailRecoveryUniversalFactory(address(verifier), address(emailAuthImpl)); + + emailRecoveryModule = new UniversalEmailRecoveryModuleHarness( + address(verifier), + address(dkimRegistry), + address(emailAuthImpl), + address(emailRecoveryHandler) + ); + emailRecoveryModuleAddress = address(emailRecoveryModule); + } + function acceptanceCommandTemplates() public pure returns (string[][] memory) { string[][] memory templates = new string[][](1); templates[0] = new string[](5); @@ -213,54 +126,8 @@ abstract contract UnitBase is RhinestoneModuleKit, BaseTest { return templates; } - function generateMockEmailProof( - string memory command, - bytes32 nullifier, - bytes32 accountSalt - ) - public - view - returns (EmailProof memory) - { - EmailProof memory emailProof; - emailProof.domainName = "gmail.com"; - emailProof.publicKeyHash = bytes32( - vm.parseUint( - "6632353713085157925504008443078919716322386156160602218536961028046468237192" - ) - ); - emailProof.timestamp = block.timestamp; - emailProof.maskedCommand = command; - emailProof.emailNullifier = nullifier; - emailProof.accountSalt = accountSalt; - emailProof.isCodeExist = true; - emailProof.proof = bytes("0"); - - return emailProof; - } - - function acceptGuardian(bytes32 accountSalt) public { - string memory accountString = CommandUtils.addressToChecksumHexString(accountAddress); - string memory command = string.concat("Accept guardian request for ", accountString); - - bytes32 nullifier = keccak256(abi.encode("nullifier 1")); - - EmailProof memory emailProof = generateMockEmailProof(command, nullifier, accountSalt); - - bytes[] memory commandParamsForAcceptance = new bytes[](1); - commandParamsForAcceptance[0] = abi.encode(accountAddress); - EmailAuthMsg memory emailAuthMsg = EmailAuthMsg({ - templateId: emailRecoveryModule.computeAcceptanceTemplateId(templateIdx), - commandParams: commandParamsForAcceptance, - skippedCommandPrefix: 0, - proof: emailProof - }); - - emailRecoveryModule.handleAcceptance(emailAuthMsg, templateIdx); - } - function handleRecovery(bytes32 _recoveryDataHash, bytes32 accountSalt) public { - string memory accountString = CommandUtils.addressToChecksumHexString(accountAddress); + string memory accountString = CommandUtils.addressToChecksumHexString(accountAddress1); string memory recoveryDataHashString = uint256(_recoveryDataHash).toHexString(32); string memory commandPart1 = string.concat("Recover account ", accountString); @@ -271,7 +138,7 @@ abstract contract UnitBase is RhinestoneModuleKit, BaseTest { EmailProof memory emailProof = generateMockEmailProof(command, nullifier, accountSalt); bytes[] memory commandParamsForRecovery = new bytes[](2); - commandParamsForRecovery[0] = abi.encode(accountAddress); + commandParamsForRecovery[0] = abi.encode(accountAddress1); commandParamsForRecovery[1] = abi.encode(recoveryDataHashString); EmailAuthMsg memory emailAuthMsg = EmailAuthMsg({ diff --git a/test/unit/handlers/EmailRecoveryCommandHandler/extractRecoveredAccountFromAcceptanceCommand.t.sol b/test/unit/handlers/EmailRecoveryCommandHandler/extractRecoveredAccountFromAcceptanceCommand.t.sol index 549187d1..8875ceca 100644 --- a/test/unit/handlers/EmailRecoveryCommandHandler/extractRecoveredAccountFromAcceptanceCommand.t.sol +++ b/test/unit/handlers/EmailRecoveryCommandHandler/extractRecoveredAccountFromAcceptanceCommand.t.sol @@ -12,11 +12,11 @@ contract EmailRecoveryCommandHandler_extractRecoveredAccountFromAcceptanceComman function test_ExtractRecoveredAccountFromAcceptanceCommand_Succeeds() public view { bytes[] memory commandParams = new bytes[](1); - commandParams[0] = abi.encode(accountAddress); + commandParams[0] = abi.encode(accountAddress1); address extractedAccount = emailRecoveryHandler.extractRecoveredAccountFromAcceptanceCommand( commandParams, templateIdx ); - assertEq(extractedAccount, accountAddress); + assertEq(extractedAccount, accountAddress1); } } diff --git a/test/unit/handlers/EmailRecoveryCommandHandler/extractRecoveredAccountFromRecoveryCommand.t.sol b/test/unit/handlers/EmailRecoveryCommandHandler/extractRecoveredAccountFromRecoveryCommand.t.sol index f607e3cb..535a4348 100644 --- a/test/unit/handlers/EmailRecoveryCommandHandler/extractRecoveredAccountFromRecoveryCommand.t.sol +++ b/test/unit/handlers/EmailRecoveryCommandHandler/extractRecoveredAccountFromRecoveryCommand.t.sol @@ -15,13 +15,13 @@ contract EmailRecoveryCommandHandler_extractRecoveredAccountFromRecoveryCommand_ string memory recoveryDataHashString = uint256(recoveryDataHash).toHexString(32); bytes[] memory commandParams = new bytes[](3); - commandParams[0] = abi.encode(accountAddress); - commandParams[1] = abi.encode(recoveryModuleAddress); + commandParams[0] = abi.encode(accountAddress1); + commandParams[1] = abi.encode(emailRecoveryModuleAddress); commandParams[2] = abi.encode(recoveryDataHashString); address extractedAccount = emailRecoveryHandler.extractRecoveredAccountFromRecoveryCommand( commandParams, templateIdx ); - assertEq(extractedAccount, accountAddress); + assertEq(extractedAccount, accountAddress1); } } diff --git a/test/unit/handlers/EmailRecoveryCommandHandler/parseRecoveryCalldataHash.t.sol b/test/unit/handlers/EmailRecoveryCommandHandler/parseRecoveryCalldataHash.t.sol index f53b81f5..51d204d9 100644 --- a/test/unit/handlers/EmailRecoveryCommandHandler/parseRecoveryCalldataHash.t.sol +++ b/test/unit/handlers/EmailRecoveryCommandHandler/parseRecoveryCalldataHash.t.sol @@ -17,7 +17,7 @@ contract EmailRecoveryCommandHandler_parseRecoveryDataHash_Test is UnitBase { recoveryDataHashString = uint256(recoveryDataHash).toHexString(32); commandParams = new bytes[](2); - commandParams[0] = abi.encode(accountAddress); + commandParams[0] = abi.encode(accountAddress1); commandParams[1] = abi.encode(recoveryDataHashString); } diff --git a/test/unit/handlers/EmailRecoveryCommandHandler/validateAcceptanceCommand.t.sol b/test/unit/handlers/EmailRecoveryCommandHandler/validateAcceptanceCommand.t.sol index 9b242c45..6fe4f6a5 100644 --- a/test/unit/handlers/EmailRecoveryCommandHandler/validateAcceptanceCommand.t.sol +++ b/test/unit/handlers/EmailRecoveryCommandHandler/validateAcceptanceCommand.t.sol @@ -11,7 +11,7 @@ contract EmailRecoveryCommandHandler_validateAcceptanceCommand_Test is UnitBase function test_ValidateAcceptanceCommand_RevertWhen_InvalidTemplateIndex() public { bytes[] memory commandParams = new bytes[](1); - commandParams[0] = abi.encode(accountAddress); + commandParams[0] = abi.encode(accountAddress1); uint256 invalidTemplateIdx = 1; vm.expectRevert( @@ -37,7 +37,7 @@ contract EmailRecoveryCommandHandler_validateAcceptanceCommand_Test is UnitBase function test_ValidateAcceptanceCommand_RevertWhen_TooManyCommandParams() public { bytes[] memory commandParams = new bytes[](2); - commandParams[0] = abi.encode(accountAddress); + commandParams[0] = abi.encode(accountAddress1); commandParams[1] = abi.encode("extra param"); vm.expectRevert( @@ -50,9 +50,9 @@ contract EmailRecoveryCommandHandler_validateAcceptanceCommand_Test is UnitBase function test_ValidateAcceptanceCommand_Succeeds() public view { bytes[] memory commandParams = new bytes[](1); - commandParams[0] = abi.encode(accountAddress); + commandParams[0] = abi.encode(accountAddress1); address account = emailRecoveryHandler.validateAcceptanceCommand(templateIdx, commandParams); - assertEq(account, accountAddress); + assertEq(account, accountAddress1); } } diff --git a/test/unit/handlers/EmailRecoveryCommandHandler/validateRecoveryCommand.t.sol b/test/unit/handlers/EmailRecoveryCommandHandler/validateRecoveryCommand.t.sol index 29677c02..04bfee52 100644 --- a/test/unit/handlers/EmailRecoveryCommandHandler/validateRecoveryCommand.t.sol +++ b/test/unit/handlers/EmailRecoveryCommandHandler/validateRecoveryCommand.t.sol @@ -17,7 +17,7 @@ contract EmailRecoveryCommandHandler_validateRecoveryCommand_Test is UnitBase { recoveryDataHashString = uint256(recoveryDataHash).toHexString(32); commandParams = new bytes[](2); - commandParams[0] = abi.encode(accountAddress); + commandParams[0] = abi.encode(accountAddress1); commandParams[1] = abi.encode(recoveryDataHashString); } @@ -47,7 +47,7 @@ contract EmailRecoveryCommandHandler_validateRecoveryCommand_Test is UnitBase { function test_ValidateRecoveryCommand_RevertWhen_TooManyCommandParams() public { bytes[] memory longCommandParams = new bytes[](3); - longCommandParams[0] = abi.encode(accountAddress); + longCommandParams[0] = abi.encode(accountAddress1); longCommandParams[1] = abi.encode(recoveryDataHashString); longCommandParams[2] = abi.encode("extra param"); @@ -85,6 +85,6 @@ contract EmailRecoveryCommandHandler_validateRecoveryCommand_Test is UnitBase { function test_ValidateRecoveryCommand_Succeeds() public view { address accountFromEmail = emailRecoveryHandler.validateRecoveryCommand(templateIdx, commandParams); - assertEq(accountFromEmail, accountAddress); + assertEq(accountFromEmail, accountAddress1); } } diff --git a/test/unit/handlers/SafeRecoveryCommandHandler/extractRecoveredAccountFromRecoveryCommand.t.sol b/test/unit/handlers/SafeRecoveryCommandHandler/extractRecoveredAccountFromRecoveryCommand.t.sol index fed4015f..2a3066a4 100644 --- a/test/unit/handlers/SafeRecoveryCommandHandler/extractRecoveredAccountFromRecoveryCommand.t.sol +++ b/test/unit/handlers/SafeRecoveryCommandHandler/extractRecoveredAccountFromRecoveryCommand.t.sol @@ -15,7 +15,7 @@ contract SafeRecoveryCommandHandler_extractRecoveredAccountFromRecoveryCommand_T bytes[] memory commandParams = new bytes[](3); commandParams[0] = abi.encode(accountAddress1); commandParams[1] = abi.encode(newOwner1); - commandParams[2] = abi.encode(recoveryModuleAddress); + commandParams[2] = abi.encode(emailRecoveryModuleAddress); address extractedAccount = safeRecoveryCommandHandler .extractRecoveredAccountFromRecoveryCommand(commandParams, templateIdx); diff --git a/test/unit/libraries/EnumerableGuardianMap/get.t.sol b/test/unit/libraries/EnumerableGuardianMap/get.t.sol index 047db0ba..c92e0a9e 100644 --- a/test/unit/libraries/EnumerableGuardianMap/get.t.sol +++ b/test/unit/libraries/EnumerableGuardianMap/get.t.sol @@ -16,21 +16,21 @@ contract EnumerableGuardianMap_get_Test is UnitBase { function setUp() public override { super.setUp(); - guardiansStorage[accountAddress].set({ - key: guardian1, + guardiansStorage[accountAddress1].set({ + key: guardians1[0], value: GuardianStorage(GuardianStatus.REQUESTED, guardianWeights[0]) }); } function test_Get_GetsExistingValue() public view { - GuardianStorage memory result = guardiansStorage[accountAddress].get(guardian1); + GuardianStorage memory result = guardiansStorage[accountAddress1].get(guardians1[0]); require(result.status == GuardianStatus.REQUESTED, "Expected status to be REQUESTED"); require(result.weight == guardianWeights[0], "Expected weight to be 1"); } function test_Get_GetsNonExistentValue() public view { // It will returns the default value - GuardianStorage memory result = guardiansStorage[accountAddress].get(guardian2); + GuardianStorage memory result = guardiansStorage[accountAddress1].get(guardians1[1]); require(result.status == GuardianStatus.NONE, "Expected status to be NONE"); require(result.weight == 0, "Expected weight to be 0"); } diff --git a/test/unit/libraries/EnumerableGuardianMap/keys.t.sol b/test/unit/libraries/EnumerableGuardianMap/keys.t.sol index 813073bc..0185d975 100644 --- a/test/unit/libraries/EnumerableGuardianMap/keys.t.sol +++ b/test/unit/libraries/EnumerableGuardianMap/keys.t.sol @@ -19,7 +19,7 @@ contract EnumerableGuardianMap_keys_Test is UnitBase { } function test_Keys_StartsEmpty() public view { - address[] memory keys = guardiansStorage[accountAddress].keys(); + address[] memory keys = guardiansStorage[accountAddress1].keys(); assertEq(keys.length, 0); } @@ -27,13 +27,13 @@ contract EnumerableGuardianMap_keys_Test is UnitBase { bool result; for (uint256 i = 1; i <= 3; i++) { - result = guardiansStorage[accountAddress].set({ + result = guardiansStorage[accountAddress1].set({ key: vm.addr(i), value: GuardianStorage(GuardianStatus.REQUESTED, guardianWeights[1]) }); assertEq(result, true); } - address[] memory keys = guardiansStorage[accountAddress].keys(); + address[] memory keys = guardiansStorage[accountAddress1].keys(); assertEq(keys.length, 3); for (uint256 i = 0; i < 3; i++) { assertEq(keys[i], vm.addr(i + 1)); @@ -44,13 +44,13 @@ contract EnumerableGuardianMap_keys_Test is UnitBase { bool result; for (uint256 i = 1; i <= EnumerableGuardianMap.MAX_NUMBER_OF_GUARDIANS; i++) { - result = guardiansStorage[accountAddress].set({ + result = guardiansStorage[accountAddress1].set({ key: vm.addr(i), value: GuardianStorage(GuardianStatus.REQUESTED, guardianWeights[1]) }); assertEq(result, true); } - address[] memory keys = guardiansStorage[accountAddress].keys(); + address[] memory keys = guardiansStorage[accountAddress1].keys(); assertEq(keys.length, EnumerableGuardianMap.MAX_NUMBER_OF_GUARDIANS); for (uint256 i = 0; i < EnumerableGuardianMap.MAX_NUMBER_OF_GUARDIANS; i++) { assertEq(keys[i], vm.addr(i + 1)); diff --git a/test/unit/libraries/EnumerableGuardianMap/remove.t.sol b/test/unit/libraries/EnumerableGuardianMap/remove.t.sol index 362f6ad8..149b82a6 100644 --- a/test/unit/libraries/EnumerableGuardianMap/remove.t.sol +++ b/test/unit/libraries/EnumerableGuardianMap/remove.t.sol @@ -21,14 +21,14 @@ contract EnumerableGuardianMap_remove_Test is UnitBase { function test_Remove_RemovesAddedKeys() public { bool result; - guardiansStorage[accountAddress].set({ - key: guardian1, + guardiansStorage[accountAddress1].set({ + key: guardians1[0], value: GuardianStorage(GuardianStatus.REQUESTED, guardianWeights[0]) }); - result = guardiansStorage[accountAddress].remove(guardian1); + result = guardiansStorage[accountAddress1].remove(guardians1[0]); assertEq(result, true); require( - guardiansStorage[accountAddress]._values[guardian1].status == GuardianStatus.NONE, + guardiansStorage[accountAddress1]._values[guardians1[0]].status == GuardianStatus.NONE, "Expected status to be NONE" ); } @@ -36,7 +36,7 @@ contract EnumerableGuardianMap_remove_Test is UnitBase { function test_Remove_ReturnsFalseWhenRemovingKeysNotInTheSet() public { bool result; - result = guardiansStorage[accountAddress].remove(guardian1); + result = guardiansStorage[accountAddress1].remove(guardians1[0]); assertEq(result, false); } @@ -45,86 +45,88 @@ contract EnumerableGuardianMap_remove_Test is UnitBase { // [] - result = guardiansStorage[accountAddress].set({ - key: guardian1, + result = guardiansStorage[accountAddress1].set({ + key: guardians1[0], value: GuardianStorage(GuardianStatus.REQUESTED, guardianWeights[0]) }); assertEq(result, true); - result = guardiansStorage[accountAddress].set({ - key: guardian3, + result = guardiansStorage[accountAddress1].set({ + key: guardians1[2], value: GuardianStorage(GuardianStatus.REQUESTED, guardianWeights[0]) }); assertEq(result, true); // [1, 3] - result = guardiansStorage[accountAddress].remove(guardian1); + result = guardiansStorage[accountAddress1].remove(guardians1[0]); assertEq(result, true); - result = guardiansStorage[accountAddress].remove(guardian2); + result = guardiansStorage[accountAddress1].remove(guardians1[1]); assertEq(result, false); // [3] - result = guardiansStorage[accountAddress].set({ - key: guardian2, + result = guardiansStorage[accountAddress1].set({ + key: guardians1[1], value: GuardianStorage(GuardianStatus.REQUESTED, guardianWeights[0]) }); assertEq(result, true); // [3,2] - result = guardiansStorage[accountAddress].set({ - key: guardian1, + result = guardiansStorage[accountAddress1].set({ + key: guardians1[0], value: GuardianStorage(GuardianStatus.REQUESTED, guardianWeights[0]) }); assertEq(result, true); - result = guardiansStorage[accountAddress].remove(guardian3); + result = guardiansStorage[accountAddress1].remove(guardians1[2]); assertEq(result, true); // [1,2] - result = guardiansStorage[accountAddress].set({ - key: guardian1, + result = guardiansStorage[accountAddress1].set({ + key: guardians1[0], value: GuardianStorage(GuardianStatus.REQUESTED, guardianWeights[0]) }); assertEq(result, false); - result = guardiansStorage[accountAddress].set({ - key: guardian2, + result = guardiansStorage[accountAddress1].set({ + key: guardians1[1], value: GuardianStorage(GuardianStatus.REQUESTED, guardianWeights[0]) }); assertEq(result, false); // [1,2] - result = guardiansStorage[accountAddress].set({ - key: guardian3, + result = guardiansStorage[accountAddress1].set({ + key: guardians1[2], value: GuardianStorage(GuardianStatus.REQUESTED, guardianWeights[0]) }); assertEq(result, true); - result = guardiansStorage[accountAddress].remove(guardian1); + result = guardiansStorage[accountAddress1].remove(guardians1[0]); assertEq(result, true); // [2,3] - result = guardiansStorage[accountAddress].set({ - key: guardian1, + result = guardiansStorage[accountAddress1].set({ + key: guardians1[0], value: GuardianStorage(GuardianStatus.REQUESTED, guardianWeights[0]) }); assertEq(result, true); - result = guardiansStorage[accountAddress].remove(guardian2); + result = guardiansStorage[accountAddress1].remove(guardians1[1]); assertEq(result, true); // [1,3] require( - guardiansStorage[accountAddress]._values[guardian1].status == GuardianStatus.REQUESTED, + guardiansStorage[accountAddress1]._values[guardians1[0]].status + == GuardianStatus.REQUESTED, "Expected status to be REQUESTED" ); require( - guardiansStorage[accountAddress]._values[guardian2].status == GuardianStatus.NONE, + guardiansStorage[accountAddress1]._values[guardians1[1]].status == GuardianStatus.NONE, "Expected status to be NONE" ); require( - guardiansStorage[accountAddress]._values[guardian3].status == GuardianStatus.REQUESTED, + guardiansStorage[accountAddress1]._values[guardians1[2]].status + == GuardianStatus.REQUESTED, "Expected status to be REQUESTED" ); } diff --git a/test/unit/libraries/EnumerableGuardianMap/removeAll.t.sol b/test/unit/libraries/EnumerableGuardianMap/removeAll.t.sol index 5dacbb05..3fdf8464 100644 --- a/test/unit/libraries/EnumerableGuardianMap/removeAll.t.sol +++ b/test/unit/libraries/EnumerableGuardianMap/removeAll.t.sol @@ -22,7 +22,7 @@ contract EnumerableGuardianMap_removeAll_Test is UnitBase { bool result; for (uint256 i = 1; i <= 3; i++) { - result = guardiansStorage[accountAddress].set({ + result = guardiansStorage[accountAddress1].set({ key: vm.addr(i), value: GuardianStorage(GuardianStatus.REQUESTED, guardianWeights[1]) }); @@ -32,10 +32,10 @@ contract EnumerableGuardianMap_removeAll_Test is UnitBase { addresses[0] = vm.addr(1); addresses[1] = vm.addr(2); addresses[2] = vm.addr(3); - guardiansStorage[accountAddress].removeAll(addresses); + guardiansStorage[accountAddress1].removeAll(addresses); for (uint256 i = 1; i <= 3; i++) { require( - guardiansStorage[accountAddress]._values[vm.addr(i)].status == GuardianStatus.NONE, + guardiansStorage[accountAddress1]._values[vm.addr(i)].status == GuardianStatus.NONE, "Expected status to be NONE" ); } @@ -45,7 +45,7 @@ contract EnumerableGuardianMap_removeAll_Test is UnitBase { bool result; for (uint256 i = 1; i <= EnumerableGuardianMap.MAX_NUMBER_OF_GUARDIANS; i++) { - result = guardiansStorage[accountAddress].set({ + result = guardiansStorage[accountAddress1].set({ key: vm.addr(i), value: GuardianStorage(GuardianStatus.REQUESTED, guardianWeights[1]) }); @@ -56,10 +56,10 @@ contract EnumerableGuardianMap_removeAll_Test is UnitBase { for (uint256 i = 0; i < EnumerableGuardianMap.MAX_NUMBER_OF_GUARDIANS; i++) { addresses[i] = vm.addr(i + 1); } - guardiansStorage[accountAddress].removeAll(addresses); + guardiansStorage[accountAddress1].removeAll(addresses); for (uint256 i = 1; i <= EnumerableGuardianMap.MAX_NUMBER_OF_GUARDIANS; i++) { require( - guardiansStorage[accountAddress]._values[vm.addr(i)].status == GuardianStatus.NONE, + guardiansStorage[accountAddress1]._values[vm.addr(i)].status == GuardianStatus.NONE, "Expected status to be NONE" ); } @@ -73,6 +73,6 @@ contract EnumerableGuardianMap_removeAll_Test is UnitBase { addresses[i] = vm.addr(i + 1); } vm.expectRevert(EnumerableGuardianMap.TooManyValuesToRemove.selector); - guardiansStorage[accountAddress].removeAll(addresses); + guardiansStorage[accountAddress1].removeAll(addresses); } } diff --git a/test/unit/libraries/EnumerableGuardianMap/set.t.sol b/test/unit/libraries/EnumerableGuardianMap/set.t.sol index 0705e2c2..f8549c79 100644 --- a/test/unit/libraries/EnumerableGuardianMap/set.t.sol +++ b/test/unit/libraries/EnumerableGuardianMap/set.t.sol @@ -19,12 +19,13 @@ contract EnumerableGuardianMap_set_Test is UnitBase { } function test_Set_AddsAKey() public { - guardiansStorage[accountAddress].set({ - key: guardian1, + guardiansStorage[accountAddress1].set({ + key: guardians1[0], value: GuardianStorage(GuardianStatus.REQUESTED, guardianWeights[1]) }); require( - guardiansStorage[accountAddress]._values[guardian1].status == GuardianStatus.REQUESTED, + guardiansStorage[accountAddress1]._values[guardians1[0]].status + == GuardianStatus.REQUESTED, "Expected status to be REQUESTED" ); } @@ -33,25 +34,25 @@ contract EnumerableGuardianMap_set_Test is UnitBase { bool result; result = guardiansStorage[vm.addr(1)].set({ - key: guardian1, + key: guardians1[0], value: GuardianStorage(GuardianStatus.REQUESTED, guardianWeights[1]) }); assertEq(result, true); result = guardiansStorage[vm.addr(2)].set({ - key: guardian2, + key: guardians1[1], value: GuardianStorage(GuardianStatus.REQUESTED, guardianWeights[2]) }); assertEq(result, true); require( - guardiansStorage[vm.addr(1)]._values[guardian1].status == GuardianStatus.REQUESTED, + guardiansStorage[vm.addr(1)]._values[guardians1[0]].status == GuardianStatus.REQUESTED, "Expected status to be REQUESTED" ); require( - guardiansStorage[vm.addr(2)]._values[guardian2].status == GuardianStatus.REQUESTED, + guardiansStorage[vm.addr(2)]._values[guardians1[1]].status == GuardianStatus.REQUESTED, "Expected status to be REQUESTED" ); require( - guardiansStorage[vm.addr(3)]._values[guardian3].status == GuardianStatus.NONE, + guardiansStorage[vm.addr(3)]._values[guardians1[2]].status == GuardianStatus.NONE, "Expected status to be NONE" ); } @@ -60,12 +61,12 @@ contract EnumerableGuardianMap_set_Test is UnitBase { bool result; result = guardiansStorage[vm.addr(1)].set({ - key: guardian1, + key: guardians1[0], value: GuardianStorage(GuardianStatus.REQUESTED, guardianWeights[1]) }); assertEq(result, true); result = guardiansStorage[vm.addr(1)].set({ - key: guardian1, + key: guardians1[0], value: GuardianStorage(GuardianStatus.REQUESTED, guardianWeights[1]) }); assertEq(result, false); @@ -75,17 +76,17 @@ contract EnumerableGuardianMap_set_Test is UnitBase { bool result; result = guardiansStorage[vm.addr(1)].set({ - key: guardian1, + key: guardians1[0], value: GuardianStorage(GuardianStatus.REQUESTED, guardianWeights[1]) }); assertEq(result, true); result = guardiansStorage[vm.addr(1)].set({ - key: guardian1, + key: guardians1[0], value: GuardianStorage(GuardianStatus.ACCEPTED, guardianWeights[1]) }); assertEq(result, false); require( - guardiansStorage[vm.addr(1)]._values[guardian1].status == GuardianStatus.ACCEPTED, + guardiansStorage[vm.addr(1)]._values[guardians1[0]].status == GuardianStatus.ACCEPTED, "Expected status to be ACCEPTED" ); } @@ -93,15 +94,15 @@ contract EnumerableGuardianMap_set_Test is UnitBase { function test_Set_RevertWhen_MaxNumberOfGuardiansReached() public { bool result; for (uint256 i = 1; i <= 32; i++) { - result = guardiansStorage[accountAddress].set({ + result = guardiansStorage[accountAddress1].set({ key: vm.addr(i), value: GuardianStorage(GuardianStatus.REQUESTED, guardianWeights[1]) }); assertEq(result, true); } vm.expectRevert(EnumerableGuardianMap.MaxNumberOfGuardiansReached.selector); - guardiansStorage[accountAddress].set({ - key: guardian1, + guardiansStorage[accountAddress1].set({ + key: guardians1[0], value: GuardianStorage(GuardianStatus.REQUESTED, guardianWeights[1]) }); } @@ -109,24 +110,24 @@ contract EnumerableGuardianMap_set_Test is UnitBase { function test_Set_UpdatesValueWhenMaxNumberOfGuardiansReached() public { bool result; for (uint256 i = 1; i <= 32; i++) { - result = guardiansStorage[accountAddress].set({ + result = guardiansStorage[accountAddress1].set({ key: vm.addr(i), value: GuardianStorage(GuardianStatus.REQUESTED, guardianWeights[1]) }); assertEq(result, true); } - bool success = guardiansStorage[accountAddress].set({ + bool success = guardiansStorage[accountAddress1].set({ key: vm.addr(1), // update first guardian added in loop value: GuardianStorage(GuardianStatus.ACCEPTED, guardianWeights[0]) }); assertEq(success, false); require( - guardiansStorage[accountAddress]._values[vm.addr(1)].status == GuardianStatus.ACCEPTED, + guardiansStorage[accountAddress1]._values[vm.addr(1)].status == GuardianStatus.ACCEPTED, "Expected status to be ACCEPTED" ); require( - guardiansStorage[accountAddress]._values[vm.addr(1)].weight == guardianWeights[0], + guardiansStorage[accountAddress1]._values[vm.addr(1)].weight == guardianWeights[0], "Expected weight to be 1" ); } diff --git a/test/unit/modules/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol b/test/unit/modules/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol index d0bb7ca8..d1c87152 100644 --- a/test/unit/modules/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol +++ b/test/unit/modules/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol @@ -1,12 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.25; -import { - RhinestoneModuleKit, - AccountInstance, - ModuleKitHelpers, - ModuleKitUserOp -} from "modulekit/ModuleKit.sol"; +import { AccountInstance, ModuleKitHelpers, ModuleKitUserOp } from "modulekit/ModuleKit.sol"; import { MODULE_TYPE_EXECUTOR, MODULE_TYPE_VALIDATOR } from "modulekit/external/ERC7579.sol"; import { ECDSAOwnedDKIMRegistry } from "@zk-email/ether-email-auth-contracts/src/utils/ECDSAOwnedDKIMRegistry.sol"; @@ -19,7 +14,7 @@ import { import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; import { ECDSA } from "solady/utils/ECDSA.sol"; -import { BaseTest } from "test/Base.t.sol"; +import { BaseTest, console2 } from "test/Base.t.sol"; import { EmailRecoveryCommandHandler } from "src/handlers/EmailRecoveryCommandHandler.sol"; import { EmailRecoveryModuleHarness } from "../../EmailRecoveryModuleHarness.sol"; import { EmailRecoveryFactory } from "src/factories/EmailRecoveryFactory.sol"; @@ -27,98 +22,62 @@ import { OwnableValidator } from "src/test/OwnableValidator.sol"; import { MockGroth16Verifier } from "src/test/MockGroth16Verifier.sol"; import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; -abstract contract EmailRecoveryModuleBase is RhinestoneModuleKit, BaseTest { +abstract contract EmailRecoveryModuleBase is BaseTest { using ModuleKitHelpers for *; using ModuleKitUserOp for *; using Strings for uint256; - // ZK Email contracts and variables - address zkEmailDeployer = vm.addr(1); - ECDSAOwnedDKIMRegistry dkimRegistry; - MockGroth16Verifier verifier; - EmailAuth emailAuthImpl; - EmailRecoveryFactory emailRecoveryFactory; EmailRecoveryCommandHandler emailRecoveryHandler; EmailRecoveryModuleHarness emailRecoveryModule; - address recoveryModuleAddress; - address validatorAddress; + address emailRecoveryModuleAddress; - OwnableValidator validator; bytes isInstalledContext; - bytes4 functionSelector; + bytes4 constant functionSelector = bytes4(keccak256(bytes("changeOwner(address)"))); bytes recoveryData; bytes32 recoveryDataHash; - // account and owners - AccountInstance instance; - address accountAddress; - address owner; - address newOwner; - - // recovery config - address[] guardians; - address guardian1; - address guardian2; - address guardian3; - uint256[] guardianWeights; - uint256 totalWeight; - uint256 delay; - uint256 expiry; - uint256 threshold; - uint256 templateIdx; - - // Account salts - bytes32 accountSalt1; - bytes32 accountSalt2; - bytes32 accountSalt3; - - string selector = "12345"; - string domainName = "gmail.com"; - bytes32 publicKeyHash = 0x0ea9c777dc7110e5a9e89b13f0cfc540e3845ba120b2b6dc24024d61488d4788; - - function setUp() public virtual { - init(); - - // Create ZK Email contracts - vm.startPrank(zkEmailDeployer); - { - ECDSAOwnedDKIMRegistry dkimImpl = new ECDSAOwnedDKIMRegistry(); - ERC1967Proxy dkimProxy = new ERC1967Proxy( - address(dkimImpl), - abi.encodeCall(dkimImpl.initialize, (zkEmailDeployer, zkEmailDeployer)) - ); - dkimRegistry = ECDSAOwnedDKIMRegistry(address(dkimProxy)); - } - 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); - dkimRegistry.setDKIMPublicKeyHash(selector, domainName, publicKeyHash, signature); - - verifier = new MockGroth16Verifier(); - - emailAuthImpl = new EmailAuth(); - vm.stopPrank(); + function setUp() public virtual override { + super.setUp(); // create owners - owner = vm.createWallet("owner").addr; - newOwner = vm.createWallet("newOwner").addr; address[] memory owners = new address[](1); - owners[0] = owner; + owners[0] = owner1; - // Deploy validator to be recovered - validator = new OwnableValidator(); - validatorAddress = address(validator); isInstalledContext = bytes("0"); - functionSelector = bytes4(keccak256(bytes("changeOwner(address)"))); - bytes memory changeOwnerCalldata = abi.encodeWithSelector(functionSelector, newOwner); + bytes memory changeOwnerCalldata = abi.encodeWithSelector(functionSelector, newOwner1); recoveryData = abi.encode(validatorAddress, changeOwnerCalldata); recoveryDataHash = keccak256(recoveryData); + // Install modules + instance1.installModule({ + moduleTypeId: MODULE_TYPE_VALIDATOR, + module: validatorAddress, + data: abi.encode(owner1) + }); + instance1.installModule({ + moduleTypeId: MODULE_TYPE_EXECUTOR, + module: emailRecoveryModuleAddress, + data: abi.encode(isInstalledContext, guardians1, guardianWeights, threshold, delay, expiry) + }); + } + + // Helper functions + + function computeEmailAuthAddress( + address account, + bytes32 accountSalt + ) + public + view + override + returns (address) + { + return emailRecoveryModule.computeEmailAuthAddress(account, accountSalt); + } + + function deployModule() public override { // Deploy handler and module emailRecoveryHandler = new EmailRecoveryCommandHandler(); emailRecoveryFactory = new EmailRecoveryFactory(address(verifier), address(emailAuthImpl)); @@ -131,53 +90,9 @@ abstract contract EmailRecoveryModuleBase is RhinestoneModuleKit, BaseTest { validatorAddress, functionSelector ); - recoveryModuleAddress = address(emailRecoveryModule); - - // Deploy and fund the account - instance = makeAccountInstance("account"); - accountAddress = instance.account; - vm.deal(address(instance.account), 10 ether); - - accountSalt1 = keccak256(abi.encode("account salt 1")); - accountSalt2 = keccak256(abi.encode("account salt 2")); - accountSalt3 = keccak256(abi.encode("account salt 3")); - - // Compute guardian addresses - guardian1 = emailRecoveryModule.computeEmailAuthAddress(instance.account, accountSalt1); - guardian2 = emailRecoveryModule.computeEmailAuthAddress(instance.account, accountSalt2); - guardian3 = emailRecoveryModule.computeEmailAuthAddress(instance.account, accountSalt3); - - guardians = new address[](3); - guardians[0] = guardian1; - guardians[1] = guardian2; - guardians[2] = guardian3; - - // Set recovery config variables - guardianWeights = new uint256[](3); - guardianWeights[0] = 1; - guardianWeights[1] = 2; - guardianWeights[2] = 1; - totalWeight = 4; - delay = 1 seconds; - expiry = 2 weeks; - threshold = 3; - templateIdx = 0; - - // Install modules - instance.installModule({ - moduleTypeId: MODULE_TYPE_VALIDATOR, - module: validatorAddress, - data: abi.encode(owner) - }); - instance.installModule({ - moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, - data: abi.encode(isInstalledContext, guardians, guardianWeights, threshold, delay, expiry) - }); + emailRecoveryModuleAddress = address(emailRecoveryModule); } - // Helper functions - function acceptanceCommandTemplates() public pure returns (string[][] memory) { string[][] memory templates = new string[][](1); templates[0] = new string[](5); @@ -206,54 +121,8 @@ abstract contract EmailRecoveryModuleBase is RhinestoneModuleKit, BaseTest { return templates; } - function generateMockEmailProof( - string memory command, - bytes32 nullifier, - bytes32 accountSalt - ) - public - view - returns (EmailProof memory) - { - EmailProof memory emailProof; - emailProof.domainName = "gmail.com"; - emailProof.publicKeyHash = bytes32( - vm.parseUint( - "6632353713085157925504008443078919716322386156160602218536961028046468237192" - ) - ); - emailProof.timestamp = block.timestamp; - emailProof.maskedCommand = command; - emailProof.emailNullifier = nullifier; - emailProof.accountSalt = accountSalt; - emailProof.isCodeExist = true; - emailProof.proof = bytes("0"); - - return emailProof; - } - - function acceptGuardian(bytes32 accountSalt) public { - string memory accountString = CommandUtils.addressToChecksumHexString(accountAddress); - string memory command = string.concat("Accept guardian request for ", accountString); - - bytes32 nullifier = keccak256(abi.encode("nullifier 1")); - - EmailProof memory emailProof = generateMockEmailProof(command, nullifier, accountSalt); - - bytes[] memory commandParamsForAcceptance = new bytes[](1); - commandParamsForAcceptance[0] = abi.encode(accountAddress); - EmailAuthMsg memory emailAuthMsg = EmailAuthMsg({ - templateId: emailRecoveryModule.computeAcceptanceTemplateId(templateIdx), - commandParams: commandParamsForAcceptance, - skippedCommandPrefix: 0, - proof: emailProof - }); - - emailRecoveryModule.handleAcceptance(emailAuthMsg, templateIdx); - } - function handleRecovery(bytes32 _recoveryDataHash, bytes32 accountSalt) public { - string memory accountString = CommandUtils.addressToChecksumHexString(accountAddress); + string memory accountString = CommandUtils.addressToChecksumHexString(accountAddress1); string memory recoveryDataHashString = uint256(_recoveryDataHash).toHexString(32); string memory commandPart1 = string.concat("Recover account ", accountString); @@ -264,7 +133,7 @@ abstract contract EmailRecoveryModuleBase is RhinestoneModuleKit, BaseTest { EmailProof memory emailProof = generateMockEmailProof(command, nullifier, accountSalt); bytes[] memory commandParamsForRecovery = new bytes[](2); - commandParamsForRecovery[0] = abi.encode(accountAddress); + commandParamsForRecovery[0] = abi.encode(accountAddress1); commandParamsForRecovery[1] = abi.encode(recoveryDataHashString); EmailAuthMsg memory emailAuthMsg = EmailAuthMsg({ diff --git a/test/unit/modules/EmailRecoveryModule/canStartRecoveryRequest.t.sol b/test/unit/modules/EmailRecoveryModule/canStartRecoveryRequest.t.sol index a698121f..3ef03ca4 100644 --- a/test/unit/modules/EmailRecoveryModule/canStartRecoveryRequest.t.sol +++ b/test/unit/modules/EmailRecoveryModule/canStartRecoveryRequest.t.sol @@ -10,11 +10,11 @@ contract EmailRecoveryModule_canStartRecoveryRequest_Test is EmailRecoveryModule } function test_CanStartRecoveryRequest_ReturnsFalse_WhenThresholdCannotBeMet() public view { - bool canStartRecoveryRequest = emailRecoveryModule.canStartRecoveryRequest(accountAddress); + bool canStartRecoveryRequest = emailRecoveryModule.canStartRecoveryRequest(accountAddress1); // Checking accepted weight is what we expect for this test case IGuardianManager.GuardianConfig memory guardianConfig = - emailRecoveryModule.getGuardianConfig(accountAddress); + emailRecoveryModule.getGuardianConfig(accountAddress1); // No guardians have accepted assertFalse(canStartRecoveryRequest); @@ -22,15 +22,15 @@ contract EmailRecoveryModule_canStartRecoveryRequest_Test is EmailRecoveryModule } function test_CanStartRecoveryRequest_ReturnsTrue_WhenThresholdIsHigherThanWeight() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); - acceptGuardian(accountSalt3); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[2], emailRecoveryModuleAddress); - bool canStartRecoveryRequest = emailRecoveryModule.canStartRecoveryRequest(accountAddress); + bool canStartRecoveryRequest = emailRecoveryModule.canStartRecoveryRequest(accountAddress1); // Checking accepted weight is what we expect for this test case IGuardianManager.GuardianConfig memory guardianConfig = - emailRecoveryModule.getGuardianConfig(accountAddress); + emailRecoveryModule.getGuardianConfig(accountAddress1); // Enough guardians have accepted so that accepted weight is higher than the threshold assertTrue(canStartRecoveryRequest); @@ -38,14 +38,14 @@ contract EmailRecoveryModule_canStartRecoveryRequest_Test is EmailRecoveryModule } function test_CanStartRecoveryRequest_ReturnsTrue_WhenThresholdIsEqualToWeight() public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); - bool canStartRecoveryRequest = emailRecoveryModule.canStartRecoveryRequest(accountAddress); + bool canStartRecoveryRequest = emailRecoveryModule.canStartRecoveryRequest(accountAddress1); // Checking accepted weight is what we expect for this test case IGuardianManager.GuardianConfig memory guardianConfig = - emailRecoveryModule.getGuardianConfig(accountAddress); + emailRecoveryModule.getGuardianConfig(accountAddress1); // Enough guardians have accepted so that accepted weight is equal to the threshold assertTrue(canStartRecoveryRequest); diff --git a/test/unit/modules/EmailRecoveryModule/onInstall.t.sol b/test/unit/modules/EmailRecoveryModule/onInstall.t.sol index 7efb1db4..0be167fb 100644 --- a/test/unit/modules/EmailRecoveryModule/onInstall.t.sol +++ b/test/unit/modules/EmailRecoveryModule/onInstall.t.sol @@ -15,41 +15,41 @@ contract EmailRecoveryModule_onInstall_Test is EmailRecoveryModuleBase { } function test_OnInstall_RevertWhen_InvalidOnInstallData() public { - instance.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); bytes memory emptyData = new bytes(0); assertEq(emptyData.length, 0); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert(EmailRecoveryModule.InvalidOnInstallData.selector); emailRecoveryModule.onInstall(emptyData); } function test_OnInstall_RevertWhen_InvalidValidator() public { - instance.uninstallModule(MODULE_TYPE_VALIDATOR, validatorAddress, ""); + instance1.uninstallModule(MODULE_TYPE_VALIDATOR, validatorAddress, ""); vm.expectRevert( abi.encodeWithSelector(EmailRecoveryModule.InvalidValidator.selector, validatorAddress) ); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.onInstall( - abi.encode(isInstalledContext, guardians, guardianWeights, threshold, delay, expiry) + abi.encode(isInstalledContext, guardians1, guardianWeights, threshold, delay, expiry) ); } function test_OnInstall_Succeeds() public { - instance.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); - instance.installModule({ + instance1.installModule({ moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, - data: abi.encode(isInstalledContext, guardians, guardianWeights, threshold, delay, expiry) + module: emailRecoveryModuleAddress, + data: abi.encode(isInstalledContext, guardians1, guardianWeights, threshold, delay, expiry) }); - bool isInitialized = emailRecoveryModule.isInitialized(accountAddress); + bool isInitialized = emailRecoveryModule.isInitialized(accountAddress1); assertTrue(isInitialized); - bool isActivated = emailRecoveryModule.isActivated(accountAddress); + bool isActivated = emailRecoveryModule.isActivated(accountAddress1); assertTrue(isActivated); } } diff --git a/test/unit/modules/EmailRecoveryModule/onUninstall.t.sol b/test/unit/modules/EmailRecoveryModule/onUninstall.t.sol index 5445ab94..82583281 100644 --- a/test/unit/modules/EmailRecoveryModule/onUninstall.t.sol +++ b/test/unit/modules/EmailRecoveryModule/onUninstall.t.sol @@ -15,14 +15,14 @@ contract EmailRecoveryModule_onUninstall_Test is EmailRecoveryModuleBase { } function test_OnUninstall_Succeeds() public { - vm.prank(accountAddress); - instance.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + vm.prank(accountAddress1); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); vm.stopPrank(); - bool isInitialized = emailRecoveryModule.isInitialized(accountAddress); + bool isInitialized = emailRecoveryModule.isInitialized(accountAddress1); assertFalse(isInitialized); - bool isActivated = emailRecoveryModule.isActivated(accountAddress); + bool isActivated = emailRecoveryModule.isActivated(accountAddress1); assertFalse(isActivated); } } diff --git a/test/unit/modules/EmailRecoveryModule/recover.t.sol b/test/unit/modules/EmailRecoveryModule/recover.t.sol index fab65708..b9de5ff0 100644 --- a/test/unit/modules/EmailRecoveryModule/recover.t.sol +++ b/test/unit/modules/EmailRecoveryModule/recover.t.sol @@ -14,67 +14,69 @@ contract EmailRecoveryModule_recover_Test is EmailRecoveryModuleBase { function test_Recover_RevertWhen_InvalidCalldataSelector() public { bytes4 invalidSelector = bytes4(keccak256(bytes("wrongSelector(address,address,address)"))); - bytes memory invalidCalldata = - abi.encodeWithSelector(invalidSelector, accountAddress, recoveryModuleAddress, newOwner); - bytes memory invalidData = abi.encode(accountAddress, invalidCalldata); + bytes memory invalidCalldata = abi.encodeWithSelector( + invalidSelector, accountAddress1, emailRecoveryModuleAddress, newOwner1 + ); + bytes memory invalidData = abi.encode(accountAddress1, invalidCalldata); - vm.startPrank(recoveryModuleAddress); + vm.startPrank(emailRecoveryModuleAddress); vm.expectRevert( abi.encodeWithSelector(EmailRecoveryModule.InvalidSelector.selector, invalidSelector) ); - emailRecoveryModule.exposed_recover(accountAddress, invalidData); + emailRecoveryModule.exposed_recover(accountAddress1, invalidData); } function test_Recover_RevertWhen_InvalidZeroCalldataSelector() public { bytes memory invalidChangeOwnerCaldata = bytes("0x"); - bytes memory invalidCalldata = abi.encode(accountAddress, invalidChangeOwnerCaldata); + bytes memory invalidCalldata = abi.encode(accountAddress1, invalidChangeOwnerCaldata); bytes4 expectedSelector; assembly { expectedSelector := mload(add(invalidChangeOwnerCaldata, 32)) } - vm.startPrank(recoveryModuleAddress); + vm.startPrank(emailRecoveryModuleAddress); vm.expectRevert( abi.encodeWithSelector(EmailRecoveryModule.InvalidSelector.selector, expectedSelector) ); - emailRecoveryModule.exposed_recover(accountAddress, invalidCalldata); + emailRecoveryModule.exposed_recover(accountAddress1, invalidCalldata); } function test_Recover_RevertWhen_CalldataWithoutValidator() public { bytes4 invalidSelector = bytes4(keccak256(bytes("wrongSelector(address,address,address)"))); - bytes memory calldataWithoutValidator = - abi.encodeWithSelector(invalidSelector, accountAddress, recoveryModuleAddress, newOwner); + bytes memory calldataWithoutValidator = abi.encodeWithSelector( + invalidSelector, accountAddress1, emailRecoveryModuleAddress, newOwner1 + ); - vm.startPrank(recoveryModuleAddress); + vm.startPrank(emailRecoveryModuleAddress); vm.expectRevert(); - emailRecoveryModule.exposed_recover(accountAddress, calldataWithoutValidator); + emailRecoveryModule.exposed_recover(accountAddress1, calldataWithoutValidator); } function test_Recover_RevertWhen_RecoveryDataWithTruncatedValidatorAddress() public { - bytes memory validCalldata = abi.encodeWithSelector(functionSelector, newOwner); - bytes memory invalidData = abi.encode(bytes8(bytes20(accountAddress)), validCalldata); + bytes memory validCalldata = abi.encodeWithSelector(functionSelector, newOwner1); + bytes memory invalidData = abi.encode(bytes8(bytes20(accountAddress1)), validCalldata); - vm.startPrank(recoveryModuleAddress); + vm.startPrank(emailRecoveryModuleAddress); vm.expectRevert(); - emailRecoveryModule.exposed_recover(accountAddress, invalidData); + emailRecoveryModule.exposed_recover(accountAddress1, invalidData); } function test_Recover_DoesNotRevertWhen_ZeroAddress() public { - bytes memory validCalldata = abi.encodeWithSelector(functionSelector, newOwner); + bytes memory validCalldata = abi.encodeWithSelector(functionSelector, newOwner1); bytes memory dataWithZeroAddress = abi.encode(address(0), validCalldata); - vm.startPrank(recoveryModuleAddress); - emailRecoveryModule.exposed_recover(accountAddress, dataWithZeroAddress); + vm.startPrank(emailRecoveryModuleAddress); + emailRecoveryModule.exposed_recover(accountAddress1, dataWithZeroAddress); } function test_Recover_Succeeds() public { - vm.startPrank(recoveryModuleAddress); + vm.startPrank(emailRecoveryModuleAddress); vm.expectEmit(); - emit EmailRecoveryModule.RecoveryExecuted(accountAddress, validatorAddress); - emailRecoveryModule.exposed_recover(accountAddress, recoveryData); + emit EmailRecoveryModule.RecoveryExecuted(accountAddress1, validatorAddress); + emailRecoveryModule.exposed_recover(accountAddress1, recoveryData); - address updatedOwner = validator.owners(accountAddress); - assertEq(updatedOwner, newOwner); + address updatedOwner = validator.owners(accountAddress1); + assertEq(updatedOwner, newOwner1); } } diff --git a/test/unit/modules/UniversalEmailRecoveryModule/allowValidatorRecovery.t.sol b/test/unit/modules/UniversalEmailRecoveryModule/allowValidatorRecovery.t.sol index 334b9ee2..a348b1bb 100644 --- a/test/unit/modules/UniversalEmailRecoveryModule/allowValidatorRecovery.t.sol +++ b/test/unit/modules/UniversalEmailRecoveryModule/allowValidatorRecovery.t.sol @@ -22,25 +22,25 @@ contract UniversalEmailRecoveryModule_allowValidatorRecovery_Test is UnitBase { // Deploy & install new validator to avoid `LinkedList_EntryAlreadyInList` errors OwnableValidator newValidator = new OwnableValidator(); newValidatorAddress = address(newValidator); - instance.installModule({ + instance1.installModule({ moduleTypeId: MODULE_TYPE_VALIDATOR, module: newValidatorAddress, - data: abi.encode(owner) + data: abi.encode(owner1) }); } function test_AllowValidatorRecovery_RevertWhen_RecoveryModuleNotInitialized() public { // Uninstall module so module is not initialized - instance.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert(UniversalEmailRecoveryModule.RecoveryModuleNotInitialized.selector); emailRecoveryModule.allowValidatorRecovery(validatorAddress, bytes("0"), functionSelector); } function test_AllowValidatorRecovery_When_SafeAddOwnerSelector() public { _skipIfNotSafeAccountType(); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.allowValidatorRecovery( newValidatorAddress, bytes("0"), ISafe.addOwnerWithThreshold.selector ); @@ -48,7 +48,7 @@ contract UniversalEmailRecoveryModule_allowValidatorRecovery_Test is UnitBase { function test_AllowValidatorRecovery_When_SafeRemoveOwnerSelector() public { _skipIfNotSafeAccountType(); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.allowValidatorRecovery( newValidatorAddress, bytes("0"), ISafe.removeOwner.selector ); @@ -56,7 +56,7 @@ contract UniversalEmailRecoveryModule_allowValidatorRecovery_Test is UnitBase { function test_AllowValidatorRecovery_When_SafeSwapOwnerSelector() public { _skipIfNotSafeAccountType(); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.allowValidatorRecovery( newValidatorAddress, bytes("0"), ISafe.swapOwner.selector ); @@ -64,7 +64,7 @@ contract UniversalEmailRecoveryModule_allowValidatorRecovery_Test is UnitBase { function test_AllowValidatorRecovery_When_SafeChangeThresholdSelector() public { _skipIfNotSafeAccountType(); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.allowValidatorRecovery( newValidatorAddress, bytes("0"), ISafe.changeThreshold.selector ); @@ -76,7 +76,7 @@ contract UniversalEmailRecoveryModule_allowValidatorRecovery_Test is UnitBase { UniversalEmailRecoveryModule.InvalidSelector.selector, IModule.onInstall.selector ) ); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.allowValidatorRecovery( validatorAddress, bytes("0"), IModule.onInstall.selector ); @@ -88,7 +88,7 @@ contract UniversalEmailRecoveryModule_allowValidatorRecovery_Test is UnitBase { UniversalEmailRecoveryModule.InvalidSelector.selector, IModule.onUninstall.selector ) ); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.allowValidatorRecovery( validatorAddress, bytes("0"), IModule.onUninstall.selector ); @@ -98,25 +98,25 @@ contract UniversalEmailRecoveryModule_allowValidatorRecovery_Test is UnitBase { vm.expectRevert( abi.encodeWithSelector(UniversalEmailRecoveryModule.InvalidSelector.selector, bytes4(0)) ); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.allowValidatorRecovery(validatorAddress, bytes("0"), bytes4(0)); } function test_AllowValidatorRecovery_RevertWhen_InvalidValidator() public { - instance.uninstallModule(MODULE_TYPE_VALIDATOR, newValidatorAddress, ""); + instance1.uninstallModule(MODULE_TYPE_VALIDATOR, newValidatorAddress, ""); vm.expectRevert( abi.encodeWithSelector( UniversalEmailRecoveryModule.InvalidValidator.selector, newValidatorAddress ) ); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.allowValidatorRecovery( newValidatorAddress, bytes("0"), functionSelector ); } function test_AllowValidatorRecovery_RevertWhen_ValidatorAlreadyInList() public { - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert( abi.encodeWithSelector( SentinelListLib.LinkedList_EntryAlreadyInList.selector, validatorAddress @@ -129,43 +129,43 @@ contract UniversalEmailRecoveryModule_allowValidatorRecovery_Test is UnitBase { // One validator is already installed from setup for (uint256 i = 1; i <= 31; i++) { address _newValidatorAddress = address(new OwnableValidator()); - instance.installModule({ + instance1.installModule({ moduleTypeId: MODULE_TYPE_VALIDATOR, module: _newValidatorAddress, - data: abi.encode(owner) + data: abi.encode(owner1) }); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.allowValidatorRecovery(_newValidatorAddress, "", functionSelector); vm.stopPrank(); } address lastValidatorAddress = address(new OwnableValidator()); - instance.installModule({ + instance1.installModule({ moduleTypeId: MODULE_TYPE_VALIDATOR, module: lastValidatorAddress, - data: abi.encode(owner) + data: abi.encode(owner1) }); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert(UniversalEmailRecoveryModule.MaxValidatorsReached.selector); emailRecoveryModule.allowValidatorRecovery(lastValidatorAddress, "", functionSelector); - uint256 validatorCount = emailRecoveryModule.validatorCount(accountAddress); + uint256 validatorCount = emailRecoveryModule.validatorCount(accountAddress1); assertEq(validatorCount, 32); } function test_AllowValidatorRecovery_SucceedsWhenAlreadyInitialized() public { - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectEmit(); emit UniversalEmailRecoveryModule.NewValidatorRecovery({ - account: accountAddress, + account: accountAddress1, validator: newValidatorAddress, recoverySelector: functionSelector }); emailRecoveryModule.allowValidatorRecovery(newValidatorAddress, "", functionSelector); address[] memory allowedValidators = - emailRecoveryModule.getAllowedValidators(accountAddress); - bytes4[] memory allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress); + emailRecoveryModule.getAllowedValidators(accountAddress1); + bytes4[] memory allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress1); assertEq(allowedValidators.length, 2); assertEq(allowedValidators[0], newValidatorAddress); @@ -177,16 +177,16 @@ contract UniversalEmailRecoveryModule_allowValidatorRecovery_Test is UnitBase { function test_AllowValidatorRecovery_SucceedsWhenInitializing() public { // Uninstall module so state is reset - instance.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); - instance.installModule( + instance1.installModule( MODULE_TYPE_EXECUTOR, - recoveryModuleAddress, + emailRecoveryModuleAddress, abi.encode( validatorAddress, isInstalledContext, functionSelector, - guardians, + guardians1, guardianWeights, threshold, delay, @@ -195,8 +195,8 @@ contract UniversalEmailRecoveryModule_allowValidatorRecovery_Test is UnitBase { ); address[] memory allowedValidators = - emailRecoveryModule.getAllowedValidators(accountAddress); - bytes4[] memory allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress); + emailRecoveryModule.getAllowedValidators(accountAddress1); + bytes4[] memory allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress1); assertEq(allowedValidators.length, 1); assertEq(allowedValidators[0], validatorAddress); diff --git a/test/unit/modules/UniversalEmailRecoveryModule/canStartRecoveryRequest.t.sol b/test/unit/modules/UniversalEmailRecoveryModule/canStartRecoveryRequest.t.sol index f88667d3..144caa17 100644 --- a/test/unit/modules/UniversalEmailRecoveryModule/canStartRecoveryRequest.t.sol +++ b/test/unit/modules/UniversalEmailRecoveryModule/canStartRecoveryRequest.t.sol @@ -11,13 +11,13 @@ contract UniversalEmailRecoveryModule_canStartRecoveryRequest_Test is UnitBase { function test_CanStartRecoveryRequest_ReturnsFalse_WhenThresholdCannotBeMet() public view { bool canStartRecoveryRequest = - emailRecoveryModule.canStartRecoveryRequest(accountAddress, validatorAddress); + emailRecoveryModule.canStartRecoveryRequest(accountAddress1, validatorAddress); // Checking accepted weight and sentinel list storage are what we expect for this test case IGuardianManager.GuardianConfig memory guardianConfig = - emailRecoveryModule.getGuardianConfig(accountAddress); + emailRecoveryModule.getGuardianConfig(accountAddress1); bool contains = - emailRecoveryModule.workaround_validatorsContains(accountAddress, validatorAddress); + emailRecoveryModule.workaround_validatorsContains(accountAddress1, validatorAddress); // No guardians have accepted assertFalse(canStartRecoveryRequest); @@ -27,17 +27,17 @@ contract UniversalEmailRecoveryModule_canStartRecoveryRequest_Test is UnitBase { function test_CanStartRecoveryRequest_ReturnsFalse_WhenValidatorNotAdded() public { address invalidValidatorAddress = address(1); - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); bool canStartRecoveryRequest = - emailRecoveryModule.canStartRecoveryRequest(accountAddress, invalidValidatorAddress); + emailRecoveryModule.canStartRecoveryRequest(accountAddress1, invalidValidatorAddress); // Checking accepted weight and sentinel list storage are what we expect for this test case IGuardianManager.GuardianConfig memory guardianConfig = - emailRecoveryModule.getGuardianConfig(accountAddress); + emailRecoveryModule.getGuardianConfig(accountAddress1); bool contains = emailRecoveryModule.workaround_validatorsContains( - accountAddress, invalidValidatorAddress + accountAddress1, invalidValidatorAddress ); // Enough guardians have accepted but invalid guardian address @@ -50,18 +50,18 @@ contract UniversalEmailRecoveryModule_canStartRecoveryRequest_Test is UnitBase { ) public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); - acceptGuardian(accountSalt3); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[2], emailRecoveryModuleAddress); bool canStartRecoveryRequest = - emailRecoveryModule.canStartRecoveryRequest(accountAddress, validatorAddress); + emailRecoveryModule.canStartRecoveryRequest(accountAddress1, validatorAddress); // Checking accepted weight and sentinel list storage are what we expect for this test case IGuardianManager.GuardianConfig memory guardianConfig = - emailRecoveryModule.getGuardianConfig(accountAddress); + emailRecoveryModule.getGuardianConfig(accountAddress1); bool contains = - emailRecoveryModule.workaround_validatorsContains(accountAddress, validatorAddress); + emailRecoveryModule.workaround_validatorsContains(accountAddress1, validatorAddress); // Enough guardians have accepted so that accepted weight is higher than the threshold assertTrue(canStartRecoveryRequest); @@ -73,17 +73,17 @@ contract UniversalEmailRecoveryModule_canStartRecoveryRequest_Test is UnitBase { ) public { - acceptGuardian(accountSalt1); - acceptGuardian(accountSalt2); + acceptGuardian(accountAddress1, guardians1[0], emailRecoveryModuleAddress); + acceptGuardian(accountAddress1, guardians1[1], emailRecoveryModuleAddress); bool canStartRecoveryRequest = - emailRecoveryModule.canStartRecoveryRequest(accountAddress, validatorAddress); + emailRecoveryModule.canStartRecoveryRequest(accountAddress1, validatorAddress); // Checking accepted weight and sentinel list storage are what we expect for this test case IGuardianManager.GuardianConfig memory guardianConfig = - emailRecoveryModule.getGuardianConfig(accountAddress); + emailRecoveryModule.getGuardianConfig(accountAddress1); bool contains = - emailRecoveryModule.workaround_validatorsContains(accountAddress, validatorAddress); + emailRecoveryModule.workaround_validatorsContains(accountAddress1, validatorAddress); // Enough guardians have accepted so that accepted weight is equal to the threshold assertTrue(canStartRecoveryRequest); diff --git a/test/unit/modules/UniversalEmailRecoveryModule/disallowValidatorRecovery.t.sol b/test/unit/modules/UniversalEmailRecoveryModule/disallowValidatorRecovery.t.sol index 70f4147f..cad79dd6 100644 --- a/test/unit/modules/UniversalEmailRecoveryModule/disallowValidatorRecovery.t.sol +++ b/test/unit/modules/UniversalEmailRecoveryModule/disallowValidatorRecovery.t.sol @@ -20,9 +20,9 @@ contract UniversalEmailRecoveryModule_disallowValidatorRecovery_Test is UnitBase function test_DisallowValidatorRecovery_RevertWhen_RecoveryModuleNotInitialized() public { // Uninstall module so module is not initialized - instance.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert(UniversalEmailRecoveryModule.RecoveryModuleNotInitialized.selector); emailRecoveryModule.disallowValidatorRecovery( validatorAddress, address(1), functionSelector @@ -33,7 +33,7 @@ contract UniversalEmailRecoveryModule_disallowValidatorRecovery_Test is UnitBase OwnableValidator newValidator = new OwnableValidator(); address invalidPreviousValidator = address(newValidator); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert( abi.encodeWithSelector( SentinelListLib.LinkedList_InvalidEntry.selector, validatorAddress @@ -48,17 +48,17 @@ contract UniversalEmailRecoveryModule_disallowValidatorRecovery_Test is UnitBase // Deplopy and install new validator OwnableValidator newValidator = new OwnableValidator(); address newValidatorAddress = address(newValidator); - instance.installModule({ + instance1.installModule({ moduleTypeId: MODULE_TYPE_VALIDATOR, module: newValidatorAddress, - data: abi.encode(owner) + data: abi.encode(owner1) }); address[] memory allowedValidators = - emailRecoveryModule.getAllowedValidators(accountAddress); + emailRecoveryModule.getAllowedValidators(accountAddress1); address prevValidator = allowedValidators.findPrevious(validatorAddress); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert( abi.encodeWithSelector( SentinelListLib.LinkedList_InvalidEntry.selector, newValidatorAddress @@ -71,12 +71,12 @@ contract UniversalEmailRecoveryModule_disallowValidatorRecovery_Test is UnitBase function test_DisallowValidatorRecovery_RevertsWhen_InvalidSelector() public { address[] memory allowedValidators = - emailRecoveryModule.getAllowedValidators(accountAddress); + emailRecoveryModule.getAllowedValidators(accountAddress1); address prevValidator = allowedValidators.findPrevious(validatorAddress); bytes4 invalidSelector = bytes4(keccak256(bytes("wrongSelector(address,address,address)"))); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert( abi.encodeWithSelector( UniversalEmailRecoveryModule.InvalidSelector.selector, invalidSelector @@ -86,42 +86,42 @@ contract UniversalEmailRecoveryModule_disallowValidatorRecovery_Test is UnitBase validatorAddress, prevValidator, invalidSelector ); - allowedValidators = emailRecoveryModule.getAllowedValidators(accountAddress); - bytes4[] memory allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress); + allowedValidators = emailRecoveryModule.getAllowedValidators(accountAddress1); + bytes4[] memory allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress1); assertEq(allowedValidators.length, 1); assertEq(allowedSelectors.length, 1); } function test_DisallowValidatorRecovery_Succeeds() public { address[] memory allowedValidators = - emailRecoveryModule.getAllowedValidators(accountAddress); + emailRecoveryModule.getAllowedValidators(accountAddress1); address prevValidator = allowedValidators.findPrevious(validatorAddress); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.disallowValidatorRecovery( validatorAddress, prevValidator, functionSelector ); - allowedValidators = emailRecoveryModule.getAllowedValidators(accountAddress); - bytes4[] memory allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress); + allowedValidators = emailRecoveryModule.getAllowedValidators(accountAddress1); + bytes4[] memory allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress1); assertEq(allowedValidators.length, 0); assertEq(allowedSelectors.length, 0); } function test_DisallowValidatorRecovery_SucceedsWhenValidatorUninstalled() public { - instance.uninstallModule(MODULE_TYPE_VALIDATOR, validatorAddress, ""); + instance1.uninstallModule(MODULE_TYPE_VALIDATOR, validatorAddress, ""); address[] memory allowedValidators = - emailRecoveryModule.getAllowedValidators(accountAddress); + emailRecoveryModule.getAllowedValidators(accountAddress1); address prevValidator = allowedValidators.findPrevious(validatorAddress); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.disallowValidatorRecovery( validatorAddress, prevValidator, functionSelector ); - allowedValidators = emailRecoveryModule.getAllowedValidators(accountAddress); - bytes4[] memory allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress); + allowedValidators = emailRecoveryModule.getAllowedValidators(accountAddress1); + bytes4[] memory allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress1); assertEq(allowedValidators.length, 0); assertEq(allowedSelectors.length, 0); } @@ -130,23 +130,23 @@ contract UniversalEmailRecoveryModule_disallowValidatorRecovery_Test is UnitBase // Deplopy and install new validator OwnableValidator newValidator = new OwnableValidator(); address newValidatorAddress = address(newValidator); - instance.installModule({ + instance1.installModule({ moduleTypeId: MODULE_TYPE_VALIDATOR, module: newValidatorAddress, - data: abi.encode(owner) + data: abi.encode(owner1) }); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.allowValidatorRecovery(newValidatorAddress, "", functionSelector); address[] memory allowedValidators = - emailRecoveryModule.getAllowedValidators(accountAddress); + emailRecoveryModule.getAllowedValidators(accountAddress1); address prevValidator = allowedValidators.findPrevious(validatorAddress); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectEmit(); emit UniversalEmailRecoveryModule.RemovedValidatorRecovery({ - account: accountAddress, + account: accountAddress1, validator: validatorAddress, recoverySelector: functionSelector }); @@ -154,8 +154,8 @@ contract UniversalEmailRecoveryModule_disallowValidatorRecovery_Test is UnitBase validatorAddress, prevValidator, functionSelector ); - allowedValidators = emailRecoveryModule.getAllowedValidators(accountAddress); - bytes4[] memory allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress); + allowedValidators = emailRecoveryModule.getAllowedValidators(accountAddress1); + bytes4[] memory allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress1); assertEq(allowedValidators.length, 1); assertEq(allowedValidators[0], newValidatorAddress); assertEq(allowedSelectors.length, 1); diff --git a/test/unit/modules/UniversalEmailRecoveryModule/getAllowedSelectors.t.sol b/test/unit/modules/UniversalEmailRecoveryModule/getAllowedSelectors.t.sol index a1a54c5c..38403454 100644 --- a/test/unit/modules/UniversalEmailRecoveryModule/getAllowedSelectors.t.sol +++ b/test/unit/modules/UniversalEmailRecoveryModule/getAllowedSelectors.t.sol @@ -14,7 +14,7 @@ contract UniversalEmailRecoveryModule_getAllowedSelectors_Test is UnitBase { } function test_GetAllowedSelectors_Succeeds() public view { - bytes4[] memory allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress); + bytes4[] memory allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress1); assertEq(allowedSelectors.length, 1); assertEq(allowedSelectors[0], functionSelector); @@ -24,18 +24,18 @@ contract UniversalEmailRecoveryModule_getAllowedSelectors_Test is UnitBase { // Deplopy and install new validator OwnableValidator newValidator = new OwnableValidator(); address newValidatorAddress = address(newValidator); - instance.installModule({ + instance1.installModule({ moduleTypeId: MODULE_TYPE_VALIDATOR, module: newValidatorAddress, - data: abi.encode(owner) + data: abi.encode(owner1) }); bytes4 newFunctionSelector = bytes4(keccak256(bytes("rotateOwner(address,address)"))); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.allowValidatorRecovery(newValidatorAddress, "", newFunctionSelector); vm.stopPrank(); - bytes4[] memory allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress); + bytes4[] memory allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress1); assertEq(allowedSelectors.length, 2); assertEq(allowedSelectors[0], newFunctionSelector); assertEq(allowedSelectors[1], functionSelector); diff --git a/test/unit/modules/UniversalEmailRecoveryModule/getAllowedValidators.t.sol b/test/unit/modules/UniversalEmailRecoveryModule/getAllowedValidators.t.sol index f7bcfd0d..48b9538e 100644 --- a/test/unit/modules/UniversalEmailRecoveryModule/getAllowedValidators.t.sol +++ b/test/unit/modules/UniversalEmailRecoveryModule/getAllowedValidators.t.sol @@ -17,23 +17,23 @@ contract UniversalEmailRecoveryModule_getAllowedValidators_Test is UnitBase { function test_GetAllowedValidators_SucceedsWhenNoValidators() public { address[] memory allowedValidators = - emailRecoveryModule.getAllowedValidators(accountAddress); + emailRecoveryModule.getAllowedValidators(accountAddress1); address prevValidator = allowedValidators.findPrevious(validatorAddress); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.disallowValidatorRecovery( validatorAddress, prevValidator, functionSelector ); vm.stopPrank(); - allowedValidators = emailRecoveryModule.getAllowedValidators(accountAddress); + allowedValidators = emailRecoveryModule.getAllowedValidators(accountAddress1); assertEq(allowedValidators.length, 0); } function test_GetAllowedValidators_SucceedsWithOneValidator() public view { address[] memory allowedValidators = - emailRecoveryModule.getAllowedValidators(accountAddress); + emailRecoveryModule.getAllowedValidators(accountAddress1); assertEq(allowedValidators.length, 1); assertEq(allowedValidators[0], validatorAddress); @@ -43,19 +43,19 @@ contract UniversalEmailRecoveryModule_getAllowedValidators_Test is UnitBase { // Deplopy and install new validator OwnableValidator newValidator = new OwnableValidator(); address newValidatorAddress = address(newValidator); - instance.installModule({ + instance1.installModule({ moduleTypeId: MODULE_TYPE_VALIDATOR, module: newValidatorAddress, - data: abi.encode(owner) + data: abi.encode(owner1) }); bytes4 newFunctionSelector = bytes4(keccak256(bytes("rotateOwner(address,address)"))); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.allowValidatorRecovery(newValidatorAddress, "", newFunctionSelector); vm.stopPrank(); address[] memory allowedValidators = - emailRecoveryModule.getAllowedValidators(accountAddress); + emailRecoveryModule.getAllowedValidators(accountAddress1); assertEq(allowedValidators.length, 2); assertEq(allowedValidators[0], newValidatorAddress); assertEq(allowedValidators[1], validatorAddress); diff --git a/test/unit/modules/UniversalEmailRecoveryModule/onInstall.t.sol b/test/unit/modules/UniversalEmailRecoveryModule/onInstall.t.sol index 6d16e9f1..0cb49c39 100644 --- a/test/unit/modules/UniversalEmailRecoveryModule/onInstall.t.sol +++ b/test/unit/modules/UniversalEmailRecoveryModule/onInstall.t.sol @@ -15,27 +15,27 @@ contract UniversalEmailRecoveryModule_onInstall_Test is UnitBase { } function test_OnInstall_RevertWhen_InvalidOnInstallData() public { - instance.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); bytes memory emptyData = new bytes(0); assertEq(emptyData.length, 0); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); vm.expectRevert(UniversalEmailRecoveryModule.InvalidOnInstallData.selector); emailRecoveryModule.onInstall(emptyData); } function test_OnInstall_Succeeds() public { - instance.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); - instance.installModule({ + instance1.installModule({ moduleTypeId: MODULE_TYPE_EXECUTOR, - module: recoveryModuleAddress, + module: emailRecoveryModuleAddress, data: abi.encode( validatorAddress, isInstalledContext, functionSelector, - guardians, + guardians1, guardianWeights, threshold, delay, @@ -44,17 +44,17 @@ contract UniversalEmailRecoveryModule_onInstall_Test is UnitBase { }); bytes4 allowedSelector = - emailRecoveryModule.exposed_allowedSelectors(validatorAddress, accountAddress); + emailRecoveryModule.exposed_allowedSelectors(validatorAddress, accountAddress1); assertEq(allowedSelector, functionSelector); address[] memory allowedValidators = - emailRecoveryModule.getAllowedValidators(accountAddress); - bytes4[] memory allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress); + emailRecoveryModule.getAllowedValidators(accountAddress1); + bytes4[] memory allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress1); assertEq(allowedValidators.length, 1); assertEq(allowedSelectors.length, 1); - bool isActivated = emailRecoveryModule.isActivated(accountAddress); + bool isActivated = emailRecoveryModule.isActivated(accountAddress1); assertTrue(isActivated); } } diff --git a/test/unit/modules/UniversalEmailRecoveryModule/onUninstall.t.sol b/test/unit/modules/UniversalEmailRecoveryModule/onUninstall.t.sol index 8cab3ff6..b674a2ae 100644 --- a/test/unit/modules/UniversalEmailRecoveryModule/onUninstall.t.sol +++ b/test/unit/modules/UniversalEmailRecoveryModule/onUninstall.t.sol @@ -15,47 +15,47 @@ contract UniversalEmailRecoveryModule_onUninstall_Test is UnitBase { } function test_OnUninstall_Succeeds() public { - vm.prank(accountAddress); - instance.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + vm.prank(accountAddress1); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); vm.stopPrank(); bytes4 allowedSelector = - emailRecoveryModule.exposed_allowedSelectors(validatorAddress, accountAddress); + emailRecoveryModule.exposed_allowedSelectors(validatorAddress, accountAddress1); assertEq(allowedSelector, bytes4(0)); address[] memory allowedValidators = - emailRecoveryModule.getAllowedValidators(accountAddress); - bytes4[] memory allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress); + emailRecoveryModule.getAllowedValidators(accountAddress1); + bytes4[] memory allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress1); assertEq(allowedValidators.length, 0); assertEq(allowedSelectors.length, 0); } function test_OnUninstall_SucceedsWhenNoValidatorsConfigured() public { address[] memory allowedValidators = - emailRecoveryModule.getAllowedValidators(accountAddress); + emailRecoveryModule.getAllowedValidators(accountAddress1); address prevValidator = allowedValidators.findPrevious(validatorAddress); - vm.startPrank(accountAddress); + vm.startPrank(accountAddress1); emailRecoveryModule.disallowValidatorRecovery( validatorAddress, prevValidator, functionSelector ); vm.stopPrank(); - allowedValidators = emailRecoveryModule.getAllowedValidators(accountAddress); - bytes4[] memory allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress); + allowedValidators = emailRecoveryModule.getAllowedValidators(accountAddress1); + bytes4[] memory allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress1); assertEq(allowedValidators.length, 0); assertEq(allowedSelectors.length, 0); - vm.prank(accountAddress); - instance.uninstallModule(MODULE_TYPE_EXECUTOR, recoveryModuleAddress, ""); + vm.prank(accountAddress1); + instance1.uninstallModule(MODULE_TYPE_EXECUTOR, emailRecoveryModuleAddress, ""); vm.stopPrank(); - allowedValidators = emailRecoveryModule.getAllowedValidators(accountAddress); - allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress); + allowedValidators = emailRecoveryModule.getAllowedValidators(accountAddress1); + allowedSelectors = emailRecoveryModule.getAllowedSelectors(accountAddress1); assertEq(allowedValidators.length, 0); assertEq(allowedSelectors.length, 0); - bool isActivated = emailRecoveryModule.isActivated(accountAddress); + bool isActivated = emailRecoveryModule.isActivated(accountAddress1); assertFalse(isActivated); } } diff --git a/test/unit/modules/UniversalEmailRecoveryModule/recover.t.sol b/test/unit/modules/UniversalEmailRecoveryModule/recover.t.sol index db2b9213..7e3829c9 100644 --- a/test/unit/modules/UniversalEmailRecoveryModule/recover.t.sol +++ b/test/unit/modules/UniversalEmailRecoveryModule/recover.t.sol @@ -13,7 +13,7 @@ contract UniversalEmailRecoveryModule_recover_Test is UnitBase { function test_Recover_RevertWhen_InvalidAccount() public { address invalidAccount = address(1); - vm.startPrank(recoveryModuleAddress); + vm.startPrank(emailRecoveryModuleAddress); vm.expectRevert( abi.encodeWithSelector( UniversalEmailRecoveryModule.InvalidSelector.selector, functionSelector @@ -24,90 +24,92 @@ contract UniversalEmailRecoveryModule_recover_Test is UnitBase { function test_Recover_RevertWhen_InvalidCalldataSelector() public { bytes4 invalidSelector = bytes4(keccak256(bytes("wrongSelector(address,address,address)"))); - bytes memory changeOwnerCalldata = - abi.encodeWithSelector(invalidSelector, accountAddress, recoveryModuleAddress, newOwner); - bytes memory invalidCalldata = abi.encode(accountAddress, changeOwnerCalldata); + bytes memory changeOwnerCalldata = abi.encodeWithSelector( + invalidSelector, accountAddress1, emailRecoveryModuleAddress, newOwner1 + ); + bytes memory invalidCalldata = abi.encode(accountAddress1, changeOwnerCalldata); - vm.startPrank(recoveryModuleAddress); + vm.startPrank(emailRecoveryModuleAddress); vm.expectRevert( abi.encodeWithSelector( UniversalEmailRecoveryModule.InvalidSelector.selector, invalidSelector ) ); - emailRecoveryModule.exposed_recover(accountAddress, invalidCalldata); + emailRecoveryModule.exposed_recover(accountAddress1, invalidCalldata); } function test_Recover_RevertWhen_InvalidZeroCalldataSelector() public { bytes memory invalidChangeOwnerCaldata = bytes("0x"); - bytes memory invalidCalldata = abi.encode(accountAddress, invalidChangeOwnerCaldata); + bytes memory invalidCalldata = abi.encode(accountAddress1, invalidChangeOwnerCaldata); bytes4 expectedSelector; assembly { expectedSelector := mload(add(invalidChangeOwnerCaldata, 32)) } - vm.startPrank(recoveryModuleAddress); + vm.startPrank(emailRecoveryModuleAddress); vm.expectRevert( abi.encodeWithSelector( UniversalEmailRecoveryModule.InvalidSelector.selector, expectedSelector ) ); - emailRecoveryModule.exposed_recover(accountAddress, invalidCalldata); + emailRecoveryModule.exposed_recover(accountAddress1, invalidCalldata); } function test_Recover_RevertWhen_CalldataWithoutValidator() public { bytes4 invalidSelector = bytes4(keccak256(bytes("wrongSelector(address,address,address)"))); - bytes memory calldataWithoutValidator = - abi.encodeWithSelector(invalidSelector, accountAddress, recoveryModuleAddress, newOwner); + bytes memory calldataWithoutValidator = abi.encodeWithSelector( + invalidSelector, accountAddress1, emailRecoveryModuleAddress, newOwner1 + ); - vm.startPrank(recoveryModuleAddress); + vm.startPrank(emailRecoveryModuleAddress); vm.expectRevert(); - emailRecoveryModule.exposed_recover(accountAddress, calldataWithoutValidator); + emailRecoveryModule.exposed_recover(accountAddress1, calldataWithoutValidator); } function test_Recover_RevertWhen_RecoveryDataWithTruncatedValidatorAddress() public { - bytes memory validCalldata = abi.encodeWithSelector(functionSelector, newOwner); - bytes memory invalidData = abi.encode(bytes8(bytes20(accountAddress)), validCalldata); + bytes memory validCalldata = abi.encodeWithSelector(functionSelector, newOwner1); + bytes memory invalidData = abi.encode(bytes8(bytes20(accountAddress1)), validCalldata); - vm.startPrank(recoveryModuleAddress); + vm.startPrank(emailRecoveryModuleAddress); vm.expectRevert(); - emailRecoveryModule.exposed_recover(accountAddress, invalidData); + emailRecoveryModule.exposed_recover(accountAddress1, invalidData); } function test_Recover_RevertWhen_ZeroValidatorAddress() public { address zeroValidator = address(0); - bytes memory validCalldata = abi.encodeWithSelector(functionSelector, newOwner); + bytes memory validCalldata = abi.encodeWithSelector(functionSelector, newOwner1); bytes memory invalidData = abi.encode(zeroValidator, validCalldata); - vm.startPrank(recoveryModuleAddress); + vm.startPrank(emailRecoveryModuleAddress); vm.expectRevert( abi.encodeWithSelector( UniversalEmailRecoveryModule.InvalidValidator.selector, zeroValidator ) ); - emailRecoveryModule.exposed_recover(accountAddress, invalidData); + emailRecoveryModule.exposed_recover(accountAddress1, invalidData); } function test_Recover_RevertWhen_IncorrectValidatorAddress() public { - address wrongValidator = accountAddress; - bytes memory validCalldata = abi.encodeWithSelector(functionSelector, newOwner); + address wrongValidator = accountAddress1; + bytes memory validCalldata = abi.encodeWithSelector(functionSelector, newOwner1); bytes memory invalidData = abi.encode(wrongValidator, validCalldata); - vm.startPrank(recoveryModuleAddress); + vm.startPrank(emailRecoveryModuleAddress); vm.expectRevert( abi.encodeWithSelector( UniversalEmailRecoveryModule.InvalidSelector.selector, functionSelector ) ); - emailRecoveryModule.exposed_recover(accountAddress, invalidData); + emailRecoveryModule.exposed_recover(accountAddress1, invalidData); } function test_Recover_Succeeds() public { - vm.startPrank(recoveryModuleAddress); + vm.startPrank(emailRecoveryModuleAddress); vm.expectEmit(); - emit UniversalEmailRecoveryModule.RecoveryExecuted(accountAddress, validatorAddress); - emailRecoveryModule.exposed_recover(accountAddress, recoveryData); + emit UniversalEmailRecoveryModule.RecoveryExecuted(accountAddress1, validatorAddress); + emailRecoveryModule.exposed_recover(accountAddress1, recoveryData); - address updatedOwner = validator.owners(accountAddress); - assertEq(updatedOwner, newOwner); + address updatedOwner = validator.owners(accountAddress1); + assertEq(updatedOwner, newOwner1); } }