Skip to content

Commit

Permalink
feat: Add test for account recovery through self-execution
Browse files Browse the repository at this point in the history
  • Loading branch information
jpgonzalezra committed May 20, 2024
1 parent 6b5d593 commit 6281531
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/SimplePlusAccount.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,29 @@ contract SimplePlusAccountTest is AccountTest {
assertEq(account.owner(), newOwner);
}

function testSelfExecuteCanRecoverAccount() public {
uint256 nonce = account.getNonce(eoaAddress);
address newOwner = address(0x100);

bytes32 structHash = keccak256(abi.encode(account._RECOVER_TYPEHASH(), eoaAddress, newOwner, nonce));
bytes32 digest = MessageHashUtils.toTypedDataHash(domainSeparator(address(account)), structHash);
bytes memory signature = sign(GUARDIAN_PRIVATE_KEY, digest);

PackedUserOperation memory op = getSignedOp(
entryPoint,
uint8(SimplePlusAccount.SignatureType.EOA),
abi.encodeCall(
SimpleAccount.execute,
(address(account), 0, abi.encodeCall(SimpleGuardianModule.recoverAccount, (newOwner, nonce, signature)))
),
EOA_PRIVATE_KEY,
address(account)
);

_executeOperation(op);
assertEq(account.owner(), newOwner);
}

function _transferOwnership(address currentOwner, address newOwner) internal {
vm.prank(currentOwner);
vm.expectEmit(true, true, false, false);
Expand Down

0 comments on commit 6281531

Please sign in to comment.