Skip to content

Commit

Permalink
Comment out tests to come back to in a later PR
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnGuilding committed Jun 14, 2024
1 parent f0df1d8 commit c035b84
Show file tree
Hide file tree
Showing 18 changed files with 1,130 additions and 1,076 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ contract OwnableValidatorRecovery_Integration_Test is OwnableValidatorRecoveryBa
using ModuleKitUserOp for *;

OwnableValidator validator;

bytes4 functionSelector;

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

validator = new OwnableValidator();

functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)")));

instance.installModule({
Expand Down
187 changes: 94 additions & 93 deletions test/integration/SafeRecovery/SafeRecovery.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,99 +21,100 @@ contract SafeRecovery_Integration_Test is SafeIntegrationBase {

bytes4 functionSelector;

function setUp() public override {
super.setUp();
recoveryModule = new EmailRecoveryModule(address(emailRecoveryManager));
recoveryModuleAddress = address(recoveryModule);

functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)")));

instance.installModule({
moduleTypeId: MODULE_TYPE_EXECUTOR,
module: recoveryModuleAddress,
data: abi.encode(
address(safe), // FIXME: requires rhinestone change
functionSelector,
guardians,
guardianWeights,
threshold,
delay,
expiry
)
});
}

function test_Recover_RotatesOwnerSuccessfully() public {
IERC7579Account account = IERC7579Account(accountAddress);
bytes memory recoveryCalldata = abi.encodeWithSignature(
"changeOwner(address,address,address)", accountAddress, recoveryModuleAddress, newOwner
);
bytes32 calldataHash = keccak256(recoveryCalldata);

bytes[] memory subjectParamsForRecovery = new bytes[](4);
subjectParamsForRecovery[0] = abi.encode(accountAddress);
subjectParamsForRecovery[1] = abi.encode(owner);
subjectParamsForRecovery[2] = abi.encode(newOwner);
subjectParamsForRecovery[3] = abi.encode(recoveryModuleAddress);

// // Install recovery module - configureRecovery is called on `onInstall`
// vm.prank(accountAddress);
// account.installModule(
// MODULE_TYPE_EXECUTOR,
// recoveryModuleAddress,
// abi.encode(guardians, guardianWeights, threshold, delay, expiry)
// );
// vm.stopPrank();

// Accept guardian
acceptGuardian(accountSalt1);
GuardianStorage memory guardianStorage1 =
emailRecoveryManager.getGuardian(accountAddress, guardian1);
assertEq(uint256(guardianStorage1.status), uint256(GuardianStatus.ACCEPTED));
assertEq(guardianStorage1.weight, uint256(1));

// Accept guardian
acceptGuardian(accountSalt2);
GuardianStorage memory guardianStorage2 =
emailRecoveryManager.getGuardian(accountAddress, guardian2);
assertEq(uint256(guardianStorage2.status), uint256(GuardianStatus.ACCEPTED));
assertEq(guardianStorage2.weight, uint256(2));

// Time travel so that EmailAuth timestamp is valid
vm.warp(12 seconds);

// handle recovery request for guardian 1
handleRecovery(recoveryModuleAddress, calldataHash, accountSalt1);
IEmailRecoveryManager.RecoveryRequest memory recoveryRequest =
emailRecoveryManager.getRecoveryRequest(accountAddress);
assertEq(recoveryRequest.currentWeight, 1);

// handle recovery request for guardian 2
uint256 executeAfter = block.timestamp + delay;
uint256 executeBefore = block.timestamp + expiry;
handleRecovery(recoveryModuleAddress, calldataHash, accountSalt2);
recoveryRequest = emailRecoveryManager.getRecoveryRequest(accountAddress);
assertEq(recoveryRequest.executeAfter, executeAfter);
assertEq(recoveryRequest.executeBefore, executeBefore);
assertEq(recoveryRequest.currentWeight, 3);

vm.warp(block.timestamp + delay);

// Complete recovery
emailRecoveryManager.completeRecovery(accountAddress, recoveryCalldata);

recoveryRequest = emailRecoveryManager.getRecoveryRequest(accountAddress);
assertEq(recoveryRequest.executeAfter, 0);
assertEq(recoveryRequest.executeBefore, 0);
assertEq(recoveryRequest.currentWeight, 0);

vm.prank(accountAddress);
bool isOwner = Safe(payable(accountAddress)).isOwner(newOwner);
assertTrue(isOwner);

bool oldOwnerIsOwner = Safe(payable(accountAddress)).isOwner(owner);
assertFalse(oldOwnerIsOwner);
}
// function setUp() public override {
// super.setUp();
// recoveryModule = new EmailRecoveryModule(address(emailRecoveryManager));
// recoveryModuleAddress = address(recoveryModule);

// functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)")));

// instance.installModule({
// moduleTypeId: MODULE_TYPE_EXECUTOR,
// module: recoveryModuleAddress,
// data: abi.encode(
// address(safe), // FIXME: requires rhinestone change
// functionSelector,
// guardians,
// guardianWeights,
// threshold,
// delay,
// expiry
// )
// });
// }

// function test_Recover_RotatesOwnerSuccessfully() public {
// IERC7579Account account = IERC7579Account(accountAddress);
// bytes memory recoveryCalldata = abi.encodeWithSignature(
// "changeOwner(address,address,address)", accountAddress, recoveryModuleAddress,
// newOwner
// );
// bytes32 calldataHash = keccak256(recoveryCalldata);

// bytes[] memory subjectParamsForRecovery = new bytes[](4);
// subjectParamsForRecovery[0] = abi.encode(accountAddress);
// subjectParamsForRecovery[1] = abi.encode(owner);
// subjectParamsForRecovery[2] = abi.encode(newOwner);
// subjectParamsForRecovery[3] = abi.encode(recoveryModuleAddress);

// // // Install recovery module - configureRecovery is called on `onInstall`
// // vm.prank(accountAddress);
// // account.installModule(
// // MODULE_TYPE_EXECUTOR,
// // recoveryModuleAddress,
// // abi.encode(guardians, guardianWeights, threshold, delay, expiry)
// // );
// // vm.stopPrank();

// // Accept guardian
// acceptGuardian(accountSalt1);
// GuardianStorage memory guardianStorage1 =
// emailRecoveryManager.getGuardian(accountAddress, guardian1);
// assertEq(uint256(guardianStorage1.status), uint256(GuardianStatus.ACCEPTED));
// assertEq(guardianStorage1.weight, uint256(1));

// // Accept guardian
// acceptGuardian(accountSalt2);
// GuardianStorage memory guardianStorage2 =
// emailRecoveryManager.getGuardian(accountAddress, guardian2);
// assertEq(uint256(guardianStorage2.status), uint256(GuardianStatus.ACCEPTED));
// assertEq(guardianStorage2.weight, uint256(2));

// // Time travel so that EmailAuth timestamp is valid
// vm.warp(12 seconds);

// // handle recovery request for guardian 1
// handleRecovery(recoveryModuleAddress, calldataHash, accountSalt1);
// IEmailRecoveryManager.RecoveryRequest memory recoveryRequest =
// emailRecoveryManager.getRecoveryRequest(accountAddress);
// assertEq(recoveryRequest.currentWeight, 1);

// // handle recovery request for guardian 2
// uint256 executeAfter = block.timestamp + delay;
// uint256 executeBefore = block.timestamp + expiry;
// handleRecovery(recoveryModuleAddress, calldataHash, accountSalt2);
// recoveryRequest = emailRecoveryManager.getRecoveryRequest(accountAddress);
// assertEq(recoveryRequest.executeAfter, executeAfter);
// assertEq(recoveryRequest.executeBefore, executeBefore);
// assertEq(recoveryRequest.currentWeight, 3);

// vm.warp(block.timestamp + delay);

// // Complete recovery
// emailRecoveryManager.completeRecovery(accountAddress, recoveryCalldata);

// recoveryRequest = emailRecoveryManager.getRecoveryRequest(accountAddress);
// assertEq(recoveryRequest.executeAfter, 0);
// assertEq(recoveryRequest.executeBefore, 0);
// assertEq(recoveryRequest.currentWeight, 0);

// vm.prank(accountAddress);
// bool isOwner = Safe(payable(accountAddress)).isOwner(newOwner);
// assertTrue(isOwner);

// bool oldOwnerIsOwner = Safe(payable(accountAddress)).isOwner(owner);
// assertFalse(oldOwnerIsOwner);
// }

// FIXME: This test cannot uninstall the module - reverts with no error message
// function test_OnUninstall_DeInitsStateSuccessfully() public {
Expand Down
23 changes: 21 additions & 2 deletions test/unit/UnitBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ECDSA } from "solady/utils/ECDSA.sol";

import { EmailRecoveryManagerHarness } from "./EmailRecoveryManagerHarness.sol";
import { EmailRecoverySubjectHandler } from "src/handlers/EmailRecoverySubjectHandler.sol";
import { EmailRecoveryModule } from "src/modules/EmailRecoveryModule.sol";
import { MockGroth16Verifier } from "src/test/MockGroth16Verifier.sol";

abstract contract UnitBase is RhinestoneModuleKit, Test {
Expand All @@ -28,6 +29,9 @@ abstract contract UnitBase is RhinestoneModuleKit, Test {
EmailRecoverySubjectHandler emailRecoveryHandler;
EmailRecoveryManagerHarness emailRecoveryManager;

address emailRecoveryManagerAddress;
address recoveryModuleAddress;

// account and owners
AccountInstance instance;
address accountAddress;
Expand Down Expand Up @@ -81,13 +85,28 @@ abstract contract UnitBase is RhinestoneModuleKit, Test {

emailRecoveryHandler = new EmailRecoverySubjectHandler();

// Deploy EmailRecoveryManager
emailRecoveryManager = new EmailRecoveryManagerHarness(
EmailRecoveryManagerHarness emailRecoveryManager = new EmailRecoveryManagerHarness(
address(verifier),
address(ecdsaOwnedDkimRegistry),
address(emailAuthImpl),
address(emailRecoveryHandler)
);
address manager = address(emailRecoveryManager);

EmailRecoveryModule emailRecoveryModule = new EmailRecoveryModule(manager);
recoveryModuleAddress = address(emailRecoveryModule);

emailRecoveryManager.initialize(recoveryModuleAddress);

// Deploy EmailRecoveryManager & EmailRecoveryModule
// (emailRecoveryManagerAddress, recoveryModuleAddress) = emailRecoveryFactory
// .deployModuleAndManager(
// address(verifier),
// address(ecdsaOwnedDkimRegistry),
// address(emailAuthImpl),
// address(emailRecoveryHandler)
// );
// emailRecoveryManager = EmailRecoveryManager(emailRecoveryManagerAddress);

// Deploy and fund the account
instance = makeAccountInstance("account");
Expand Down
Loading

0 comments on commit c035b84

Please sign in to comment.