chore: cleanup tech debt from Bebop tests and the execution harness

This commit is contained in:
pedrobergamini
2025-08-08 12:28:24 -03:00
parent 7f8e1e6e3b
commit 712d863368
3 changed files with 17 additions and 116 deletions

View File

@@ -249,101 +249,4 @@ contract BebopExecutorHarness is BebopExecutor, Test {
// no-op; keep function end balanced
}
// Special method for direct test calls that need harness behavior
function swapForTest(uint256 givenAmount, bytes calldata data)
external
payable
returns (uint256 calculatedAmount)
{
return _handleDirectTestSwap(givenAmount, data);
}
function _handleDirectTestSwap(uint256 givenAmount, bytes calldata data)
internal
returns (uint256 calculatedAmount)
{
// Decode the packed data
(
address tokenIn,
,
TransferType transferType,
bytes memory bebopCalldata,
, // partialFillOffset not needed in test harness
uint256 originalFilledTakerAmount,
, // approvalNeeded not needed in test harness
// receiver not needed since we extract it from bebop calldata
) = _decodeData(data);
// Extract taker address, receiver, and expiry from bebop calldata
bytes4 sel = _getSelector(bebopCalldata);
address takerAddress;
address receiverAddress;
uint256 expiry;
bytes memory bebopCalldataWithoutSelector =
_stripSelector(bebopCalldata);
if (sel == SWAP_SINGLE_SELECTOR) {
(IBebopSettlement.Single memory order,,) = abi.decode(
bebopCalldataWithoutSelector,
(
IBebopSettlement.Single,
IBebopSettlement.MakerSignature,
uint256
)
);
takerAddress = order.taker_address;
receiverAddress = order.receiver;
expiry = order.expiry;
} else {
(IBebopSettlement.Aggregate memory order,,) = abi.decode(
bebopCalldataWithoutSelector,
(
IBebopSettlement.Aggregate,
IBebopSettlement.MakerSignature[],
uint256
)
);
takerAddress = order.taker_address;
receiverAddress = order.receiver;
expiry = order.expiry;
}
uint256 actualFilledTakerAmount = originalFilledTakerAmount
> givenAmount ? givenAmount : originalFilledTakerAmount;
// For testing: transfer tokens from executor to taker address
// This simulates the taker having the tokens with approval
if (tokenIn != address(0)) {
// The executor already has the tokens from the test, just transfer to taker
IERC20(tokenIn).safeTransfer(takerAddress, actualFilledTakerAmount);
// Approve settlement from taker's perspective
// Stop any existing prank first
vm.stopPrank();
vm.startPrank(takerAddress);
IERC20(tokenIn).forceApprove(bebopSettlement, type(uint256).max);
vm.stopPrank();
} else {
vm.stopPrank();
// For native ETH, deal it to the taker address
payable(takerAddress).transfer(actualFilledTakerAmount);
}
// IMPORTANT: Prank as the taker address to pass the settlement validation
vm.stopPrank();
vm.startPrank(takerAddress);
// Set block timestamp to ensure order is valid regardless of fork block
uint256 currentTimestamp = block.timestamp;
vm.warp(expiry - 1); // Set timestamp to just before expiry
// Call the parent's internal _swap function
calculatedAmount = _swap(givenAmount, data);
// Restore original timestamp
vm.warp(currentTimestamp);
vm.stopPrank();
}
}