Skip to content

Commit

Permalink
Fix typo in SponsorPaymaster.sol comment and add unit test for valida…
Browse files Browse the repository at this point in the history
…ting paymaster user operation when wallet is an app in SponsorPaymaster.t.sol.
  • Loading branch information
ylv-io committed Dec 5, 2024
1 parent 8860441 commit c220c7b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/paymasters/SponsorPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions test/unit/SponsorPaymaster.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit c220c7b

Please sign in to comment.