feat: add univ2 executor test with hex

This commit is contained in:
royvardhan
2025-01-29 23:10:23 +05:30
parent 0007c4924c
commit c482e21a5f
3 changed files with 17 additions and 2 deletions

View File

@@ -43,7 +43,7 @@ contract UniswapV2Executor is IExecutor {
bool zeroForOne
)
{
if (data.length != 61) {
if (data.length < 61) {
revert UniswapV2Executor__InvalidDataLength();
}
inToken = IERC20(address(bytes20(data[0:20])));

View File

@@ -4,7 +4,7 @@ pragma solidity ^0.8.28;
import "@src/executors/UniswapV2Executor.sol";
import {Test} from "../../lib/forge-std/src/Test.sol";
import {Constants} from "../Constants.sol";
import {console} from "forge-std/console.sol";
contract UniswapV2ExecutorExposed is UniswapV2Executor {
function decodeParams(bytes calldata data)
external
@@ -93,4 +93,18 @@ contract UniswapV2ExecutorTest is UniswapV2ExecutorExposed, Test, Constants {
uint256 finalBalance = DAI.balanceOf(BOB);
assertGe(finalBalance, amountOut);
}
function testSwapExecutorEncoderData() public {
bytes memory protocolData =
hex"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc288e6a0c2ddd26feeb64f039a2c41296fcb3f564000000000000000000000000000000000000000010000";
console.log(protocolData.length);
(IERC20 tokenIn, address target, address receiver, bool zeroForOne) =
uniswapV2Exposed.decodeParams(protocolData);
assertEq(address(tokenIn), WETH_ADDR);
assertEq(target, 0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640);
assertEq(receiver, 0x0000000000000000000000000000000000000001);
assertEq(zeroForOne, false);
}
}

View File

@@ -126,6 +126,7 @@ mod tests {
.encode_strategy(solution)
.unwrap();
let hex_protocol_data = encode(&protocol_data);
println!("{}", hex_protocol_data);
assert_eq!(
executor_address,
Address::from_str("0x5c2f5a71f67c01775180adc06909288b4c329308").unwrap()