From c220c7b702933bf7f12d17047430038766ce5631 Mon Sep 17 00:00:00 2001 From: Igor Yalovoy Date: Wed, 4 Dec 2024 18:20:22 -0600 Subject: [PATCH] Fix typo in SponsorPaymaster.sol comment and add unit test for validating paymaster user operation when wallet is an app in SponsorPaymaster.t.sol. --- src/paymasters/SponsorPaymaster.sol | 2 +- test/unit/SponsorPaymaster.t.sol | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/paymasters/SponsorPaymaster.sol b/src/paymasters/SponsorPaymaster.sol index 9fe316f9..4c9fee5b 100644 --- a/src/paymasters/SponsorPaymaster.sol +++ b/src/paymasters/SponsorPaymaster.sol @@ -351,7 +351,7 @@ contract SponsorPaymaster is Initializable, BasePaymaster, UUPSUpgradeable, Reen if (sponsor != userOp.sender) { revert DepositTooLow(); } - // Wallets get automfunded by kinto core app + // Wallets get auto funded by kinto core app sponsor = appRegistry.getApp(address(walletFactory)); } return (abi.encode(sponsor, userOp.sender, userOp.maxFeePerGas, userOp.maxPriorityFeePerGas), 0); diff --git a/test/unit/SponsorPaymaster.t.sol b/test/unit/SponsorPaymaster.t.sol index f60e3379..1c2ac157 100644 --- a/test/unit/SponsorPaymaster.t.sol +++ b/test/unit/SponsorPaymaster.t.sol @@ -15,6 +15,8 @@ import {IKintoWalletFactory} from "@kinto-core/interfaces/IKintoWalletFactory.so import "@kinto-core-test/SharedSetup.t.sol"; +import "forge-std/console2.sol"; + contract SponsorPaymasterUpgrade is SponsorPaymaster { constructor(IEntryPoint __entryPoint, IKintoWalletFactory factory, address _owner) SponsorPaymaster(__entryPoint, factory) @@ -253,6 +255,23 @@ contract SponsorPaymasterTest is SharedSetup { _paymaster.validatePaymasterUserOp(userOp, "", 0); } + function testValidatePaymasterUserOp_WhenWalletIsApp() public { + address wallet = address(alice); + UserOperation memory userOp = _createUserOperation( + wallet, wallet, 0, privateKeys, abi.encodeWithSignature("increment()"), address(_paymaster) + ); + + address kintoCoreApp = _paymaster.appRegistry().getApp(address(_walletFactory)); + + vm.prank(address(_entryPoint)); + (bytes memory context, uint256 validationData) = _paymaster.validatePaymasterUserOp(userOp, "", 0.01 ether); + + assertEq(validationData, 0); + (address sponsor, address sender,,) = abi.decode(context, (address, address, uint256, uint256)); + assertEq(sponsor, kintoCoreApp, "Sponsor for the wallet has to be a Kinto App"); + assertEq(sender, wallet, "Sender has to be a wallet"); + } + function testValidatePaymasterUserOp_RevertWhen_GasLimitIsLessThanCostOfPost() public { UserOperation memory userOp = _createUserOperation( address(_kintoWallet),