Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsoncusack committed Mar 11, 2024
1 parent cee2631 commit 2f28bb2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 55 deletions.
47 changes: 22 additions & 25 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
PostOpTest:test_DoesNotTransferIfPostOpFailed(uint256,uint256,uint256) (runs: 256, μ: 94728, ~: 94980)
PostOpTest:test_PersistsExcessIfPostOpFailed(uint256,uint256,uint256) (runs: 256, μ: 110321, ~: 110735)
PostOpTest:test_RevertsIfPostOpFailed(uint256,uint256,uint256) (runs: 256, μ: 94983, ~: 97095)
PostOpTest:test_entryPointAddStake(uint112,uint32) (runs: 256, μ: 56233, ~: 56233)
PostOpTest:test_entryPointDeposit(uint112) (runs: 256, μ: 32479, ~: 32962)
PostOpTest:test_entryPointDeposit(uint112) (runs: 256, μ: 32442, ~: 32962)
PostOpTest:test_entryPointUnlockStake() (gas: 54910)
PostOpTest:test_entryPointWithdraw(uint112) (runs: 256, μ: 63350, ~: 65300)
PostOpTest:test_entryPointWithdraw(uint112) (runs: 256, μ: 63500, ~: 65300)
PostOpTest:test_entryPointWithdrawStake() (gas: 71825)
PostOpTest:test_paymasterPaysForOp() (gas: 208461)
PostOpTest:test_transfersExcess(uint256,uint256,uint256,uint256) (runs: 256, μ: 112688, ~: 113692)
PostOpTest:test_paymasterPaysForOp() (gas: 208401)
PostOpTest:test_transfersExcess(uint256,uint256,uint256,uint256) (runs: 256, μ: 110233, ~: 111237)
Simulate:test() (gas: 12114)
ValidatePaymasterUserOpTest:test_doesNotOverwriteExcess(uint256,uint256,uint256) (runs: 256, μ: 155887, ~: 158210)
ValidatePaymasterUserOpTest:test_emitsCorrectly(address,uint256,uint256) (runs: 256, μ: 102634, ~: 103867)
ValidatePaymasterUserOpTest:test_recordsNonceUsed(uint256) (runs: 256, μ: 109968, ~: 111057)
ValidatePaymasterUserOpTest:test_returns1sIfWrongSignature() (gas: 94108)
ValidatePaymasterUserOpTest:test_returnsCorrectly() (gas: 88974)
ValidatePaymasterUserOpTest:test_revertsIfMaxCostMoreThanRequested() (gas: 39164)
ValidatePaymasterUserOpTest:test_revertsIfNonceUsed() (gas: 101328)
ValidatePaymasterUserOpTest:test_revertsIfWithdrawAssetNotZero() (gas: 55990)
ValidatePaymasterUserOpTest:test_setsExcess(uint256,uint256,uint256) (runs: 256, μ: 89980, ~: 91165)
ValidatePaymasterUserOpTest:test_emitsCorrectly(address,uint256,uint256) (runs: 256, μ: 102602, ~: 103835)
ValidatePaymasterUserOpTest:test_recordsNonceUsed(uint256) (runs: 256, μ: 109936, ~: 111025)
ValidatePaymasterUserOpTest:test_returns1sIfWrongSignature() (gas: 94076)
ValidatePaymasterUserOpTest:test_returnsCorrectly() (gas: 88920)
ValidatePaymasterUserOpTest:test_revertsIfMaxCostMoreThanRequested() (gas: 39141)
ValidatePaymasterUserOpTest:test_revertsIfNonceUsed() (gas: 101280)
ValidatePaymasterUserOpTest:test_revertsIfWithdrawAssetNotZero() (gas: 55974)
ValidateTest:test_receive() (gas: 14687)
WithdrawGasExcess:test_RevertsIfNoExcess(uint256) (runs: 256, μ: 68946, ~: 69209)
WithdrawGasExcess:test_transferExcess(uint256,uint256,uint256) (runs: 256, μ: 102106, ~: 102106)
WithdrawTest:test_emitsCorrectly(address,uint256,uint256) (runs: 256, μ: 116015, ~: 119113)
WithdrawTest:test_emitsCorrectlyERC20Withdraw(address,uint256,uint256) (runs: 256, μ: 158226, ~: 160553)
WithdrawTest:test_recordsNonceUsed(uint256) (runs: 256, μ: 109118, ~: 110207)
WithdrawTest:test_revertsIfExpired(uint48,uint256) (runs: 256, μ: 59454, ~: 59575)
WithdrawTest:test_revertsIfNonceUsed() (gas: 93546)
WithdrawTest:test_revertsIfWrongSignature() (gas: 61576)
WithdrawTest:test_transfersERC20Successfully(uint256) (runs: 256, μ: 136425, ~: 138865)
WithdrawTest:test_transfersETHSuccessfully(uint256) (runs: 256, μ: 89438, ~: 91435)
WithdrawGasExcess:test_RevertsIfNoExcess(uint256) (runs: 256, μ: 68914, ~: 69177)
WithdrawGasExcess:test_transferExcess(uint256,uint256,uint256) (runs: 256, μ: 102074, ~: 102074)
WithdrawTest:test_emitsCorrectly(address,uint256,uint256) (runs: 256, μ: 116020, ~: 119073)
WithdrawTest:test_emitsCorrectlyERC20Withdraw(address,uint256,uint256) (runs: 256, μ: 158167, ~: 160513)
WithdrawTest:test_recordsNonceUsed(uint256) (runs: 256, μ: 109078, ~: 110167)
WithdrawTest:test_revertsIfExpired(uint48,uint256) (runs: 256, μ: 59414, ~: 59535)
WithdrawTest:test_revertsIfNonceUsed() (gas: 93506)
WithdrawTest:test_revertsIfWrongSignature() (gas: 61536)
WithdrawTest:test_transfersERC20Successfully(uint256) (runs: 256, μ: 136385, ~: 138825)
WithdrawTest:test_transfersETHSuccessfully(uint256) (runs: 256, μ: 89398, ~: 91395)
44 changes: 14 additions & 30 deletions test/PostOp.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,29 @@ contract PostOpTest is PaymasterMagicSpendBaseTest {

function test_transfersExcess(uint256 mode, uint256 amount_, uint256 maxCost_, uint256 actualCost) public {
mode = bound(mode, 0, 1);
amount_ = bound(amount_, 0, address(magic).balance);
maxCost_ = bound(maxCost_, 0, amount_);
actualCost = bound(actualCost, 0, maxCost_);
amount = amount_;

assertEq(withdrawer.balance, 0);
vm.deal(address(magic), amount);
(bytes memory context,) = magic.validatePaymasterUserOp(_getUserOp(), userOpHash, maxCost_);
uint256 expectedBalance = amount - actualCost;
vm.deal(address(magic), expectedBalance);
magic.postOp(IPaymaster.PostOpMode(mode), context, actualCost);
assertEq(withdrawer.balance, expectedBalance);
}

// function test_DoesNotTransferIfPostOpFailed(uint256 amount_, uint256 maxCost_, uint256 actualCost) public {
// amount_ = bound(amount_, 0, address(magic).balance);
// maxCost_ = bound(maxCost_, 0, amount_);
// actualCost = bound(actualCost, 0, maxCost_);

// assertEq(withdrawer.balance, 0);
// (bytes memory context,) = magic.validatePaymasterUserOp(_getUserOp(), userOpHash, maxCost_);
// uint256 expectedBalance = 0;
// magic.postOp(IPaymaster.PostOpMode.postOpReverted, context, actualCost);
// assertEq(withdrawer.balance, expectedBalance);
// }
function test_RevertsIfPostOpFailed(uint256 amount_, uint256 maxCost_, uint256 actualCost) public {
maxCost_ = bound(maxCost_, 0, amount_);
actualCost = bound(actualCost, 0, maxCost_);
amount = amount_;

// function test_PersistsExcessIfPostOpFailed(uint256 amount_, uint256 maxCost_, uint256 actualCost) public {
// vm.assume(maxCost_ <= amount_);
// vm.assume(actualCost <= maxCost_);
// amount = amount_;
// (bytes memory context,) = magic.validatePaymasterUserOp(_getUserOp(), userOpHash, maxCost_);
// magic.postOp(IPaymaster.PostOpMode.postOpReverted, context, actualCost);
// uint256 expectedBalance = amount - actualCost;
// assertEq(withdrawer.balance, 0);
// assertEq(magic.fundsExcessBalance(withdrawer), expectedBalance);
// vm.stopPrank();
// vm.deal(address(magic), expectedBalance);
// if (expectedBalance > 0) {
// vm.prank(withdrawer);
// magic.withdrawGasExcess();
// assertEq(withdrawer.balance, expectedBalance);
// }
// }
assertEq(withdrawer.balance, 0);
vm.deal(address(magic), amount);
(bytes memory context,) = magic.validatePaymasterUserOp(_getUserOp(), userOpHash, maxCost_);
uint256 expectedBalance = 0;
vm.expectRevert();
magic.postOp(IPaymaster.PostOpMode.postOpReverted, context, actualCost);
assertEq(withdrawer.balance, expectedBalance);
}
}

0 comments on commit 2f28bb2

Please sign in to comment.