Skip to content

Commit

Permalink
Increase MINIMUM_RECOVERY_WINDOW
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnGuilding committed May 31, 2024
1 parent 59ee198 commit 373fef1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ZkEmailRecovery.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ contract ZkEmailRecovery is EmailAccountRecovery, IZkEmailRecovery {
* Minimum required time window between when a recovery attempt becomes valid and when it
* becomes invalid
*/
uint256 public constant MINIMUM_RECOVERY_WINDOW = 1 days;
uint256 public constant MINIMUM_RECOVERY_WINDOW = 2 days;

/**
* Account address to recovery config
Expand Down
49 changes: 46 additions & 3 deletions test/unit/ZkEmailRecovery/updateRecoveryConfig.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,26 @@ contract ZkEmailRecovery_updateRecoveryConfig_Test is UnitBase {
}

function test_UpdateRecoveryConfig_RevertWhen_RecoveryWindowTooShort() public {
uint256 newDelay = 1 hours;
uint256 newExpiry = 24 hours;
uint256 newDelay = 1 days;
uint256 newExpiry = 2 days;

IZkEmailRecovery.RecoveryConfig memory recoveryConfig =
IZkEmailRecovery.RecoveryConfig(recoveryModuleAddress, newDelay, newExpiry);

vm.startPrank(accountAddress);
zkEmailRecovery.configureRecovery(
recoveryModuleAddress, guardians, guardianWeights, threshold, delay, expiry
);
vm.stopPrank();

vm.startPrank(accountAddress);
vm.expectRevert(IZkEmailRecovery.RecoveryWindowTooShort.selector);
zkEmailRecovery.updateRecoveryConfig(recoveryConfig);
}

function test_UpdateRecoveryConfig_RevertWhen_RecoveryWindowTooShortByOneSecond() public {
uint256 newDelay = 1 seconds;
uint256 newExpiry = 2 days;

IZkEmailRecovery.RecoveryConfig memory recoveryConfig =
IZkEmailRecovery.RecoveryConfig(recoveryModuleAddress, newDelay, newExpiry);
Expand All @@ -98,7 +116,32 @@ contract ZkEmailRecovery_updateRecoveryConfig_Test is UnitBase {
zkEmailRecovery.updateRecoveryConfig(recoveryConfig);
}

function test_UpdateRecoveryConfig_UpdateRecoveryConfig_Succeeds() public {
function test_UpdateRecoveryConfig_SucceedsWhenRecoveryWindowEqualsMinimumRecoveryWindow()
public
{
address newRecoveryModule = address(1);
uint256 newDelay = 0 seconds;
uint256 newExpiry = 2 days;

IZkEmailRecovery.RecoveryConfig memory recoveryConfig =
IZkEmailRecovery.RecoveryConfig(newRecoveryModule, newDelay, newExpiry);

vm.startPrank(accountAddress);
zkEmailRecovery.configureRecovery(
recoveryModuleAddress, guardians, guardianWeights, threshold, delay, expiry
);
vm.stopPrank();

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

recoveryConfig = zkEmailRecovery.getRecoveryConfig(accountAddress);
assertEq(recoveryConfig.recoveryModule, newRecoveryModule);
assertEq(recoveryConfig.delay, newDelay);
assertEq(recoveryConfig.expiry, newExpiry);
}

function test_UpdateRecoveryConfig_Succeeds() public {
address newRecoveryModule = address(1);
uint256 newDelay = 1 days;
uint256 newExpiry = 4 weeks;
Expand Down

0 comments on commit 373fef1

Please sign in to comment.