Skip to content

Commit

Permalink
Cleaner unit test setup & additional rename
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnGuilding committed Jun 17, 2024
1 parent 6d62218 commit bd3573a
Show file tree
Hide file tree
Showing 26 changed files with 57 additions and 403 deletions.
30 changes: 0 additions & 30 deletions test/unit/EmailRecoveryManager/acceptGuardian.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,8 @@ import { UnitBase } from "../UnitBase.t.sol";
import { OwnableValidator } from "src/test/OwnableValidator.sol";

contract ZkEmailRecovery_acceptGuardian_Test is UnitBase {
using ModuleKitHelpers for *;
using ModuleKitUserOp for *;

OwnableValidator validator;
bytes4 functionSelector;

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

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

instance.installModule({
moduleTypeId: MODULE_TYPE_VALIDATOR,
module: address(validator),
data: abi.encode(owner, recoveryModuleAddress)
});

// Install recovery module - configureRecovery is called on `onInstall`
instance.installModule({
moduleTypeId: MODULE_TYPE_EXECUTOR,
module: recoveryModuleAddress,
data: abi.encode(
address(validator),
functionSelector,
guardians,
guardianWeights,
threshold,
delay,
expiry
)
});
}

// function test_AcceptGuardian_RevertWhen_AlreadyRecovering() public {
Expand Down
29 changes: 0 additions & 29 deletions test/unit/EmailRecoveryManager/addGuardian.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,8 @@ error InvalidGuardianWeight();
event AddedGuardian(address indexed account, address indexed guardian);

contract ZkEmailRecovery_addGuardian_Test is UnitBase {
using ModuleKitHelpers for *;
using ModuleKitUserOp for *;

OwnableValidator validator;
bytes4 functionSelector;

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

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

instance.installModule({
moduleTypeId: MODULE_TYPE_VALIDATOR,
module: address(validator),
data: abi.encode(owner, recoveryModuleAddress)
});
// Install recovery module - configureRecovery is called on `onInstall`
instance.installModule({
moduleTypeId: MODULE_TYPE_EXECUTOR,
module: recoveryModuleAddress,
data: abi.encode(
address(validator),
functionSelector,
guardians,
guardianWeights,
threshold,
delay,
expiry
)
});
}

// function test_AddGuardian_RevertWhen_AlreadyRecovering() public {
Expand Down
29 changes: 0 additions & 29 deletions test/unit/EmailRecoveryManager/cancelRecovery.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,8 @@ import { EmailRecoveryModule } from "src/modules/EmailRecoveryModule.sol";
import { OwnableValidator } from "src/test/OwnableValidator.sol";

contract ZkEmailRecovery_cancelRecovery_Test is UnitBase {
using ModuleKitHelpers for *;
using ModuleKitUserOp for *;

OwnableValidator validator;
bytes4 functionSelector;

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

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

instance.installModule({
moduleTypeId: MODULE_TYPE_VALIDATOR,
module: address(validator),
data: abi.encode(owner, recoveryModuleAddress)
});
// Install recovery module - configureRecovery is called on `onInstall`
instance.installModule({
moduleTypeId: MODULE_TYPE_EXECUTOR,
module: recoveryModuleAddress,
data: abi.encode(
address(validator),
functionSelector,
guardians,
guardianWeights,
threshold,
delay,
expiry
)
});
}

// function test_CancelRecovery_CannotCancelWrongRecoveryRequest() public {
Expand Down
29 changes: 0 additions & 29 deletions test/unit/EmailRecoveryManager/changeThreshold.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,8 @@ error ThresholdCannotBeZero();
event ChangedThreshold(address indexed account, uint256 threshold);

contract ZkEmailRecovery_changeThreshold_Test is UnitBase {
using ModuleKitHelpers for *;
using ModuleKitUserOp for *;

OwnableValidator validator;
bytes4 functionSelector;

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

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

instance.installModule({
moduleTypeId: MODULE_TYPE_VALIDATOR,
module: address(validator),
data: abi.encode(owner, recoveryModuleAddress)
});
// Install recovery module - configureRecovery is called on `onInstall`
instance.installModule({
moduleTypeId: MODULE_TYPE_EXECUTOR,
module: recoveryModuleAddress,
data: abi.encode(
address(validator),
functionSelector,
guardians,
guardianWeights,
threshold,
delay,
expiry
)
});
}

// function test_RevertWhen_AlreadyRecovering() public {
Expand Down
77 changes: 7 additions & 70 deletions test/unit/EmailRecoveryManager/completeRecovery.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,15 @@ import { OwnableValidator } from "src/test/OwnableValidator.sol";

// completeRecovery(accountAddress, recoveryCalldata)
contract ZkEmailRecovery_completeRecovery_Test is UnitBase {
using ModuleKitHelpers for *;
using ModuleKitUserOp for *;

OwnableValidator validator;

bytes recoveryCalldata;
bytes4 functionSelector;

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

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

instance.installModule({
moduleTypeId: MODULE_TYPE_VALIDATOR,
module: address(validator),
data: abi.encode(owner, recoveryModuleAddress)
});
// Install recovery module - configureRecovery is called on `onInstall`
instance.installModule({
moduleTypeId: MODULE_TYPE_EXECUTOR,
module: recoveryModuleAddress,
data: abi.encode(
address(validator),
functionSelector,
guardians,
guardianWeights,
threshold,
delay,
expiry
)
});

recoveryCalldata = abi.encodeWithSignature(
"changeOwner(address,address,address)", accountAddress, recoveryModuleAddress, newOwner
);
}

// function test_CompleteRecovery_RevertWhen_NotCalledFromCorrectRouter() public {
// bytes memory recoveryCalldata = abi.encodeWithSignature(
// "changeOwner(address,address,address)", accountAddress, recoveryModuleAddress,
// newOwner
// );
// acceptGuardian(accountSalt1);
// acceptGuardian(accountSalt2);
// vm.warp(12 seconds);
Expand Down Expand Up @@ -85,46 +54,14 @@ contract ZkEmailRecovery_completeRecovery_Test is UnitBase {

// completeRecovery(address account)
contract ZkEmailRecovery_completeRecoveryWithAddress_Test is UnitBase {
using ModuleKitHelpers for *;
using ModuleKitUserOp for *;

OwnableValidator validator;

bytes recoveryCalldata;
bytes4 functionSelector;

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

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

instance.installModule({
moduleTypeId: MODULE_TYPE_VALIDATOR,
module: address(validator),
data: abi.encode(owner, recoveryModuleAddress)
});
// Install recovery module - configureRecovery is called on `onInstall`
instance.installModule({
moduleTypeId: MODULE_TYPE_EXECUTOR,
module: recoveryModuleAddress,
data: abi.encode(
address(validator),
functionSelector,
guardians,
guardianWeights,
threshold,
delay,
expiry
)
});

recoveryCalldata = abi.encodeWithSignature(
"changeOwner(address,address,address)", accountAddress, recoveryModuleAddress, newOwner
);
}

// function test_CompleteRecovery_RevertWhen_InvalidAccountAddress() public {
// bytes memory recoveryCalldata = abi.encodeWithSignature(
// "changeOwner(address,address,address)", accountAddress, recoveryModuleAddress,
// newOwner
// address invalidAccount = address(0);

// vm.expectRevert(IEmailRecoveryManager.InvalidAccountAddress.selector);
Expand Down
29 changes: 0 additions & 29 deletions test/unit/EmailRecoveryManager/configureRecovery.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,8 @@ import { OwnableValidator } from "src/test/OwnableValidator.sol";
error SetupAlreadyCalled();

contract ZkEmailRecovery_configureRecovery_Test is UnitBase {
using ModuleKitHelpers for *;
using ModuleKitUserOp for *;

OwnableValidator validator;
bytes4 functionSelector;

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

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

instance.installModule({
moduleTypeId: MODULE_TYPE_VALIDATOR,
module: address(validator),
data: abi.encode(owner, recoveryModuleAddress)
});
// Install recovery module - configureRecovery is called on `onInstall`
instance.installModule({
moduleTypeId: MODULE_TYPE_EXECUTOR,
module: recoveryModuleAddress,
data: abi.encode(
address(validator),
functionSelector,
guardians,
guardianWeights,
threshold,
delay,
expiry
)
});
}

// function test_ConfigureRecovery_RevertWhen_AlreadyRecovering() public {
Expand Down
29 changes: 0 additions & 29 deletions test/unit/EmailRecoveryManager/deInitRecoveryFromModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,8 @@ import { EmailRecoveryModule } from "src/modules/EmailRecoveryModule.sol";
import { OwnableValidator } from "src/test/OwnableValidator.sol";

contract ZkEmailRecovery_deInitRecoveryFromModule_Test is UnitBase {
using ModuleKitHelpers for *;
using ModuleKitUserOp for *;

OwnableValidator validator;
bytes4 functionSelector;

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

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

instance.installModule({
moduleTypeId: MODULE_TYPE_VALIDATOR,
module: address(validator),
data: abi.encode(owner, recoveryModuleAddress)
});
// Install recovery module - configureRecovery is called on `onInstall`
instance.installModule({
moduleTypeId: MODULE_TYPE_EXECUTOR,
module: recoveryModuleAddress,
data: abi.encode(
address(validator),
functionSelector,
guardians,
guardianWeights,
threshold,
delay,
expiry
)
});
}

// function test_DeInitRecoveryFromModule_RevertWhen_NotCalledFromRecoveryModule() public {
Expand Down
29 changes: 0 additions & 29 deletions test/unit/EmailRecoveryManager/processRecovery.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,8 @@ import { OwnableValidator } from "src/test/OwnableValidator.sol";
import { GuardianStorage, GuardianStatus } from "src/libraries/EnumerableGuardianMap.sol";

contract ZkEmailRecovery_processRecovery_Test is UnitBase {
using ModuleKitHelpers for *;
using ModuleKitUserOp for *;

OwnableValidator validator;
bytes4 functionSelector;

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

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

instance.installModule({
moduleTypeId: MODULE_TYPE_VALIDATOR,
module: address(validator),
data: abi.encode(owner, recoveryModuleAddress)
});
// Install recovery module - configureRecovery is called on `onInstall`
instance.installModule({
moduleTypeId: MODULE_TYPE_EXECUTOR,
module: recoveryModuleAddress,
data: abi.encode(
address(validator),
functionSelector,
guardians,
guardianWeights,
threshold,
delay,
expiry
)
});
}

// function test_ProcessRecovery_RevertWhen_GuardianStatusIsNONE() public {
Expand Down
Loading

0 comments on commit bd3573a

Please sign in to comment.