feat: add univ2 executor test with hex
This commit is contained in:
@@ -43,7 +43,7 @@ contract UniswapV2Executor is IExecutor {
|
|||||||
bool zeroForOne
|
bool zeroForOne
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (data.length != 61) {
|
if (data.length < 61) {
|
||||||
revert UniswapV2Executor__InvalidDataLength();
|
revert UniswapV2Executor__InvalidDataLength();
|
||||||
}
|
}
|
||||||
inToken = IERC20(address(bytes20(data[0:20])));
|
inToken = IERC20(address(bytes20(data[0:20])));
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ pragma solidity ^0.8.28;
|
|||||||
import "@src/executors/UniswapV2Executor.sol";
|
import "@src/executors/UniswapV2Executor.sol";
|
||||||
import {Test} from "../../lib/forge-std/src/Test.sol";
|
import {Test} from "../../lib/forge-std/src/Test.sol";
|
||||||
import {Constants} from "../Constants.sol";
|
import {Constants} from "../Constants.sol";
|
||||||
|
import {console} from "forge-std/console.sol";
|
||||||
contract UniswapV2ExecutorExposed is UniswapV2Executor {
|
contract UniswapV2ExecutorExposed is UniswapV2Executor {
|
||||||
function decodeParams(bytes calldata data)
|
function decodeParams(bytes calldata data)
|
||||||
external
|
external
|
||||||
@@ -93,4 +93,18 @@ contract UniswapV2ExecutorTest is UniswapV2ExecutorExposed, Test, Constants {
|
|||||||
uint256 finalBalance = DAI.balanceOf(BOB);
|
uint256 finalBalance = DAI.balanceOf(BOB);
|
||||||
assertGe(finalBalance, amountOut);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ mod tests {
|
|||||||
.encode_strategy(solution)
|
.encode_strategy(solution)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let hex_protocol_data = encode(&protocol_data);
|
let hex_protocol_data = encode(&protocol_data);
|
||||||
|
println!("{}", hex_protocol_data);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
executor_address,
|
executor_address,
|
||||||
Address::from_str("0x5c2f5a71f67c01775180adc06909288b4c329308").unwrap()
|
Address::from_str("0x5c2f5a71f67c01775180adc06909288b4c329308").unwrap()
|
||||||
|
|||||||
Reference in New Issue
Block a user