Skip to content

Commit

Permalink
add ways to catch AA33 with revert reason
Browse files Browse the repository at this point in the history
  • Loading branch information
livingrockrises committed Dec 14, 2023
1 parent ff71663 commit 08ad285
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions contracts/sponsorship/SponsorshipPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ contract SponsorshipPaymaster is
) public override nonReentrant {
if (withdrawAddress == address(0)) revert CanNotWithdrawToZeroAddress();
uint256 currentBalance = paymasterIdBalances[msg.sender];
if (amount > currentBalance)
revert InsufficientBalance(amount, currentBalance);
require(amount <= currentBalance, "Sponsorship Paymaster: Insufficient withdrawable funds");
paymasterIdBalances[msg.sender] = currentBalance - amount;
entryPoint.withdrawTo(withdrawAddress, amount);
emit GasWithdrawn(msg.sender, withdrawAddress, amount);
Expand Down Expand Up @@ -336,6 +335,7 @@ contract SponsorshipPaymaster is
effectiveCost,
paymasterIdBalances[paymasterId]
);
// require(effectiveCost <= paymasterIdBalances[paymasterId], "BTPM: account does not have enough token balance");

context = abi.encode(
paymasterId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,12 @@ describe("EntryPoint with VerifyingPaymaster Singleton", function () {
console.log("paymaster Id ", paymasterId);
const userOp = await getUserOpWithPaymasterInfo(paymasterId);

await expect(
entryPoint.callStatic.simulateValidation(userOp)
).to.be.revertedWithCustomError(entryPoint, "FailedOp");
// Review
// We would like it to be reverted with proper revert reason
// TODO: look into it why it goes into OOG in EP
await expect(entryPoint.callStatic.simulateValidation(userOp))
.to.be.revertedWithCustomError(entryPoint, "FailedOp")
.withArgs(0, "AA23 reverted (or OOG)");
});

it("succeed with valid signature", async () => {
Expand Down Expand Up @@ -387,9 +390,8 @@ describe("EntryPoint with VerifyingPaymaster Singleton", function () {
sponsorshipPaymaster
.connect(depositorSigner)
.withdrawTo(paymasterId, parseEther("1.1"))
).to.be.revertedWithCustomError(
sponsorshipPaymaster,
"InsufficientBalance"
).to.be.revertedWith(
"Sponsorship Paymaster: Insufficient withdrawable funds"
);
});
});
Expand Down

0 comments on commit 08ad285

Please sign in to comment.