Skip to content

Commit

Permalink
fix: BICONOMYSPONSOR-007 minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
livingrockrises committed Oct 8, 2024
1 parent 1d9364e commit cfb0ad8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
7 changes: 6 additions & 1 deletion contracts/common/BiconomySponsorshipPaymasterErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ contract BiconomySponsorshipPaymasterErrors {
/**
* @notice Throws when insufficient funds to withdraw
*/
error InsufficientFundsInGasTank();
error InsufficientFunds();

/**
* @notice Throws when invalid signature length in paymasterAndData
Expand All @@ -67,6 +67,11 @@ contract BiconomySponsorshipPaymasterErrors {
*/
error CanNotWithdrawToZeroAddress();

/**
* @notice Throws when trying to withdraw zero amount
*/
error CanNotWithdrawZeroAmount();

/**
* @notice Throws when trying unaccountedGas is too high
*/
Expand Down
7 changes: 4 additions & 3 deletions contracts/sponsorship/BiconomySponsorshipPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ contract BiconomySponsorshipPaymaster is
}

/**
* @dev Set a new unaccountedEPGasOverhead value.
* @param value The new value to be set as the unaccountedEPGasOverhead.
* @dev Set a new unaccountedGas value.
* @param value The new value to be set as the unaccountedGas.
* @notice only to be called by the owner of the contract.
*/
function setUnaccountedGas(uint256 value) external payable onlyOwner {
Expand Down Expand Up @@ -158,9 +158,10 @@ contract BiconomySponsorshipPaymaster is
*/
function withdrawTo(address payable withdrawAddress, uint256 amount) external override nonReentrant {
if (withdrawAddress == address(0)) revert CanNotWithdrawToZeroAddress();
if (amount == 0) revert CanNotWithdrawZeroAmount();
uint256 currentBalance = paymasterIdBalances[msg.sender];
if (amount > currentBalance) {
revert InsufficientFundsInGasTank();
revert InsufficientFunds();
}
paymasterIdBalances[msg.sender] = currentBalance - amount;
entryPoint.withdrawTo(withdrawAddress, amount);
Expand Down
7 changes: 6 additions & 1 deletion test/unit/concrete/TestSponsorshipPaymaster.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,13 @@ contract TestSponsorshipPaymasterWithPriceMarkup is TestBase {
bicoPaymaster.withdrawTo(payable(address(0)), 0 ether);
}

function test_RevertIf_WithdrawZeroAmount() external prankModifier(DAPP_ACCOUNT.addr) {
vm.expectRevert(abi.encodeWithSelector(CanNotWithdrawZeroAmount.selector));
bicoPaymaster.withdrawTo(payable(BOB_ADDRESS), 0 ether);
}

function test_RevertIf_WithdrawToExceedsBalance() external prankModifier(DAPP_ACCOUNT.addr) {
vm.expectRevert(abi.encodeWithSelector(InsufficientFundsInGasTank.selector));
vm.expectRevert(abi.encodeWithSelector(InsufficientFunds.selector));
bicoPaymaster.withdrawTo(payable(BOB_ADDRESS), 1 ether);
}

Expand Down

0 comments on commit cfb0ad8

Please sign in to comment.