Skip to content

Commit

Permalink
Added test for excess balance shipping
Browse files Browse the repository at this point in the history
  • Loading branch information
ephess committed Feb 26, 2024
1 parent 007a56c commit 7809000
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion test/PFL_AuctionHandler.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,12 @@ contract PFLAuctionHandlerTest is PFLHelper, FastLaneAuctionHandlerEvents, Test

function testCollectFees() public {
vm.deal(SEARCHER_ADDRESS1, 100 ether);
address EXCESS_RECIPIENT = address(0);

uint256 bidAmount = 2 ether;
uint256 expectedValidatorPayout = bidAmount - 1;
uint256 validatorCut = (bidAmount * (1_000_000 - 50_000)) / 1_000_000;
uint256 excessBalance = bidAmount - validatorCut;
uint256 expectedValidatorPayout = validatorCut - 1;
bytes32 oppTx = bytes32("tx1");
bytes memory searcherUnusedData = abi.encodeWithSignature("unused()");

Expand All @@ -368,13 +371,20 @@ contract PFLAuctionHandlerTest is PFLHelper, FastLaneAuctionHandlerEvents, Test
uint256 snap = vm.snapshot();

// As V1 pay itself
uint256 excessRecipientBalanceBefore = EXCESS_RECIPIENT.balance;
uint256 balanceBefore = VALIDATOR1.balance;
vm.expectEmit(true, true, true, true);
emit RelayProcessingPaidValidator(VALIDATOR1, expectedValidatorPayout, VALIDATOR1);
emit RelayWithdrawExcessBalance(address(0), excessBalance);

vm.prank(VALIDATOR1);

uint256 returnedAmountPaid = PFR.collectFees();
uint256 actualAmountPaid = VALIDATOR1.balance - balanceBefore;
uint256 excessRecipientBalanceAfter = EXCESS_RECIPIENT.balance;

// Excess balance was sent to the excess recipient
assertEq(excessRecipientBalanceAfter - excessRecipientBalanceBefore, excessBalance);

// Validator actually got paid as expected
assertEq(returnedAmountPaid, expectedValidatorPayout);
Expand Down

0 comments on commit 7809000

Please sign in to comment.