chore: fix test filledTakerAmount extraction and decoding logic

This commit is contained in:
pedrobergamini
2025-08-04 18:52:53 -03:00
parent d4df49a796
commit 4cb570edb1
4 changed files with 557 additions and 407 deletions

View File

@@ -195,22 +195,17 @@ contract TychoRouterTestSetup is Constants, Permit2TestHelper, TestUtils {
address tokenIn, address tokenIn,
address tokenOut, address tokenOut,
RestrictTransferFrom.TransferType transferType, RestrictTransferFrom.TransferType transferType,
BebopExecutorHarness.OrderType orderType, bytes memory bebopCalldata,
bytes memory quoteData, uint256 originalAmountIn,
uint8 signatureType,
bytes memory signature,
bool approvalNeeded bool approvalNeeded
) internal pure returns (bytes memory) { ) internal pure returns (bytes memory) {
return abi.encodePacked( return abi.encodePacked(
tokenIn, tokenIn,
tokenOut, tokenOut,
transferType, uint8(transferType),
orderType, uint32(bebopCalldata.length),
uint32(quoteData.length), bebopCalldata,
quoteData, originalAmountIn,
signatureType,
uint32(signature.length),
signature,
approvalNeeded ? uint8(1) : uint8(0) approvalNeeded ? uint8(1) : uint8(0)
); );
} }

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -82,7 +82,7 @@ contract BebopExecutorHarness is BebopExecutor, Test {
); );
} }
// Override to prank the taker address before calling the real settlement // Override swap to handle test setup
function swap(uint256 givenAmount, bytes calldata data) function swap(uint256 givenAmount, bytes calldata data)
external external
payable payable
@@ -98,19 +98,17 @@ contract BebopExecutorHarness is BebopExecutor, Test {
uint256 originalFilledTakerAmount, uint256 originalFilledTakerAmount,
) = _decodeData(data); ) = _decodeData(data);
uint256 actualFilledTakerAmount = // Extract taker address, receiver, and expiry from bebop calldata
_getActualFilledTakerAmount(givenAmount, originalFilledTakerAmount);
// Extract taker address and expiry from bebop calldata
bytes4 sel = _getSelector(bebopCalldata); bytes4 sel = _getSelector(bebopCalldata);
address takerAddress; address takerAddress;
address receiverAddress;
uint256 expiry; uint256 expiry;
bytes memory bebopCalldataWithoutSelector; bytes memory bebopCalldataWithoutSelector =
_stripSelector(bebopCalldata);
if (sel == SWAP_SINGLE_SELECTOR) { if (sel == SWAP_SINGLE_SELECTOR) {
bebopCalldataWithoutSelector = _stripSelector(bebopCalldata); (IBebopSettlement.Single memory order,,) = abi.decode(
(IBebopSettlement.Single memory ord,,) = abi.decode(
bebopCalldataWithoutSelector, bebopCalldataWithoutSelector,
( (
IBebopSettlement.Single, IBebopSettlement.Single,
@@ -118,11 +116,11 @@ contract BebopExecutorHarness is BebopExecutor, Test {
uint256 uint256
) )
); );
takerAddress = ord.taker_address; takerAddress = order.taker_address;
expiry = ord.expiry; receiverAddress = order.receiver;
expiry = order.expiry;
} else { } else {
bebopCalldataWithoutSelector = _stripSelector(bebopCalldata); (IBebopSettlement.Aggregate memory order,,) = abi.decode(
(IBebopSettlement.Aggregate memory ord,,) = abi.decode(
bebopCalldataWithoutSelector, bebopCalldataWithoutSelector,
( (
IBebopSettlement.Aggregate, IBebopSettlement.Aggregate,
@@ -130,10 +128,14 @@ contract BebopExecutorHarness is BebopExecutor, Test {
uint256 uint256
) )
); );
takerAddress = ord.taker_address; takerAddress = order.taker_address;
expiry = ord.expiry; receiverAddress = order.receiver;
expiry = order.expiry;
} }
uint256 actualFilledTakerAmount =
_getActualFilledTakerAmount(givenAmount, originalFilledTakerAmount);
// For testing: transfer tokens from executor to taker address // For testing: transfer tokens from executor to taker address
// This simulates the taker having the tokens with approval // This simulates the taker having the tokens with approval
if (tokenIn != address(0)) { if (tokenIn != address(0)) {
@@ -150,7 +152,7 @@ contract BebopExecutorHarness is BebopExecutor, Test {
vm.stopPrank(); vm.stopPrank();
} else { } else {
vm.stopPrank(); vm.stopPrank();
// For native ETH, send it to the taker address // For native ETH, deal it to the taker address
payable(takerAddress).transfer(actualFilledTakerAmount); payable(takerAddress).transfer(actualFilledTakerAmount);
} }
@@ -162,8 +164,6 @@ contract BebopExecutorHarness is BebopExecutor, Test {
uint256 currentTimestamp = block.timestamp; uint256 currentTimestamp = block.timestamp;
vm.warp(expiry - 1); // Set timestamp to just before expiry vm.warp(expiry - 1); // Set timestamp to just before expiry
// Execute the single swap with the original data
// The parent's _swap will handle the modification of filledTakerAmount
calculatedAmount = _swap(givenAmount, data); calculatedAmount = _swap(givenAmount, data);
// Restore original timestamp // Restore original timestamp