Skip to content

Commit

Permalink
add test for 6492-compliant signature from already deployed account
Browse files Browse the repository at this point in the history
  • Loading branch information
amiecorso committed Oct 16, 2024
1 parent 9a53327 commit 4a15e07
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion test/src/SpendPermissions/permit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ contract PermitTest is SpendPermissionManagerBase {
mockSpendPermissionManager.permit(spendPermission, signature);
}

function test_permit_6492_signature_success(
function test_permit_6492_signature_success_preDeploy(
uint128 ownerPk,
address spender,
address token,
Expand Down Expand Up @@ -198,5 +198,46 @@ contract PermitTest is SpendPermissionManagerBase {
mockSpendPermissionManager.permit(spendPermission, signature);

// verify that the account is now deployed (has code) and that a call to isValidSignature returns true
vm.assertGt(counterfactualAccount.code.length, 0);
}

function test_permit_6492_signature_success_alreadyDeployed(
uint128 ownerPk,
address spender,
address token,
uint48 start,
uint48 end,
uint48 period,
uint160 allowance
) public {
vm.assume(start > 0);
vm.assume(start < end);
vm.assume(period > 0);
vm.assume(allowance > 0);
vm.assume(ownerPk != 0);
// generate the counterfactual address for the account
address ownerAddress = vm.addr(ownerPk);
bytes[] memory owners = new bytes[](1);
owners[0] = abi.encode(ownerAddress);
address counterfactualAccount = mockCoinbaseSmartWalletFactory.getAddress(owners, 0);
// deploy the account already
mockCoinbaseSmartWalletFactory.createAccount(owners, 0);
// create a 6492-compliant signature for the spend permission
SpendPermissionManager.SpendPermission memory spendPermission = SpendPermissionManager.SpendPermission({
account: counterfactualAccount,
spender: spender,
token: token,
start: start,
end: end,
period: period,
allowance: allowance
});
bytes memory signature = _signSpendPermission6492(spendPermission, ownerPk, 0);
// verify that the account is already deployed
vm.assertGt(counterfactualAccount.code.length, 0);

// submit the spend permission with the signature, see permit succeed
vm.startPrank(spender);
mockSpendPermissionManager.permit(spendPermission, signature);
}
}

0 comments on commit 4a15e07

Please sign in to comment.