Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipp Makarov authored and Filipp Makarov committed Oct 22, 2024
1 parent 85d1340 commit 362bf12
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
11 changes: 0 additions & 11 deletions contracts/sponsorship/BiconomySponsorshipPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol";
import { IBiconomySponsorshipPaymaster } from "../interfaces/IBiconomySponsorshipPaymaster.sol";

import "forge-std/console2.sol";

/**
* @title BiconomySponsorshipPaymaster
* @author livingrockrises<[email protected]>
Expand Down Expand Up @@ -332,8 +330,6 @@ contract BiconomySponsorshipPaymaster is
// Include unaccountedGas since EP doesn't include this in actualGasCost
// unaccountedGas = postOpGas + EP overhead gas + estimated penalty
actualGasCost = actualGasCost + (unaccountedGas * actualUserOpFeePerGas);
console2.log("gas at pm.postOp sent by EP + unaccountedGas ", actualGasCost);
console2.log("actual unaccountedGas (postOp overload) units at pm.postOp ", unaccountedGas);
// Apply the price markup
uint256 adjustedGasCost = (actualGasCost * priceMarkup) / _PRICE_DENOMINATOR;

Expand All @@ -344,11 +340,9 @@ contract BiconomySponsorshipPaymaster is

if (prechargedAmount > adjustedGasCost) {
// If overcharged refund the excess
console2.log("overcharged ", prechargedAmount - adjustedGasCost);
paymasterIdBalances[paymasterId] += (prechargedAmount - adjustedGasCost);
} else {
// deduct what needs to be deducted from paymasterId
console2.log("undercharged ", (adjustedGasCost - prechargedAmount));
paymasterIdBalances[paymasterId] -= (adjustedGasCost - prechargedAmount);
}
// here adjustedGasCost does not account for gasPenalty. prechargedAmount accounts for penalty with maxGasPenalty
Expand Down Expand Up @@ -425,11 +419,6 @@ contract BiconomySponsorshipPaymaster is
) * 10 * userOp.unpackMaxFeePerGas()
) / 100;

console2.log("call gas limit in pm ", uint128(uint256(userOp.accountGasLimits)));
console2.log("pm gas limit in pm", uint128(bytes16(userOp.paymasterAndData[_PAYMASTER_POSTOP_GAS_OFFSET:_PAYMASTER_DATA_OFFSET])));

console2.log("max penalty ", maxPenalty);

// Deduct the max gas cost.
uint256 effectiveCost =
(((requiredPreFund + unaccountedGas * userOp.unpackMaxFeePerGas()) * priceMarkup) / _PRICE_DENOMINATOR);
Expand Down
13 changes: 3 additions & 10 deletions test/unit/concrete/TestSponsorshipPaymaster.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ contract TestSponsorshipPaymasterWithPriceMarkup is TestBase {

uint256 public constant WITHDRAWAL_DELAY = 3600;
uint256 public constant MIN_DEPOSIT = 1e15;
uint256 public constant UNACCOUNTED_GAS = 15e3;

function setUp() public {
setupPaymasterTestEnvironment();
Expand All @@ -21,7 +22,7 @@ contract TestSponsorshipPaymasterWithPriceMarkup is TestBase {
entryPointArg: ENTRYPOINT,
verifyingSignerArg: PAYMASTER_SIGNER.addr,
feeCollectorArg: PAYMASTER_FEE_COLLECTOR.addr,
unaccountedGasArg: 15e3, //if set too low, PM will lose money
unaccountedGasArg: UNACCOUNTED_GAS, //if set too low, PM will lose money
paymasterIdWithdrawalDelayArg: WITHDRAWAL_DELAY,
minDepositArg: MIN_DEPOSIT
});
Expand Down Expand Up @@ -78,7 +79,7 @@ contract TestSponsorshipPaymasterWithPriceMarkup is TestBase {
assertEq(address(bicoPaymaster.entryPoint()), ENTRYPOINT_ADDRESS);
assertEq(bicoPaymaster.verifyingSigner(), PAYMASTER_SIGNER.addr);
assertEq(bicoPaymaster.feeCollector(), PAYMASTER_FEE_COLLECTOR.addr);
assertEq(bicoPaymaster.unaccountedGas(), 7e3);
assertEq(bicoPaymaster.unaccountedGas(), UNACCOUNTED_GAS);
}

function test_OwnershipTransfer() external prankModifier(PAYMASTER_OWNER.addr) {
Expand Down Expand Up @@ -241,9 +242,6 @@ contract TestSponsorshipPaymasterWithPriceMarkup is TestBase {
}

// try to use balance while request is cleared

// This doesn't pass as maxPenalty calculation is wrong

function test_executeWithdrawalRequest_Withdraws_WhateverIsLeft() external prankModifier(DAPP_ACCOUNT.addr) {
uint256 depositAmount = 1 ether;
bicoPaymaster.depositFor{ value: depositAmount }(DAPP_ACCOUNT.addr);
Expand All @@ -253,7 +251,6 @@ contract TestSponsorshipPaymasterWithPriceMarkup is TestBase {
PackedUserOperation[] memory ops = new PackedUserOperation[](1);
(PackedUserOperation memory userOp, bytes32 userOpHash) = createUserOp(ALICE, bicoPaymaster, 1e6, 55_000);
ops[0] = userOp;
console2.log("================");
startPrank(BUNDLER.addr);
ENTRYPOINT.handleOps(ops, payable(BUNDLER.addr));
stopPrank();
Expand All @@ -265,10 +262,6 @@ contract TestSponsorshipPaymasterWithPriceMarkup is TestBase {
IStakeManager.DepositInfo memory depositInfo = ENTRYPOINT.getDepositInfo(address(bicoPaymaster));
uint256 PAYMASTER_POSTOP_GAS_OFFSET = 36;
uint256 PAYMASTER_DATA_OFFSET = 52;
// console2.log("deposit in EP ", depositInfo.deposit);
// console2.log("payId Bal Aft ", dappPaymasterBalanceAfter);
console2.log("max gas fee ", uint128(uint256(userOp.gasFees)));
//console2.log("max gas ", this.getGasLimit(userOp));

vm.warp(block.timestamp + WITHDRAWAL_DELAY + 1);
bicoPaymaster.executeWithdrawalRequest(DAPP_ACCOUNT.addr);
Expand Down

0 comments on commit 362bf12

Please sign in to comment.