test: Router integration test with many TODOs

This commit is contained in:
TAMARA LIPOWSKI
2025-01-30 23:36:10 -05:00
committed by Diana Carvalho
parent b01fa4cf04
commit 4d697bfebf
4 changed files with 37 additions and 9 deletions

View File

@@ -14,6 +14,7 @@ import "@uniswap/v3-updated/CallbackValidationV2.sol";
import "./ExecutionDispatcher.sol"; import "./ExecutionDispatcher.sol";
import "./CallbackVerificationDispatcher.sol"; import "./CallbackVerificationDispatcher.sol";
import {LibSwap} from "../lib/LibSwap.sol"; import {LibSwap} from "../lib/LibSwap.sol";
import "forge-std/console.sol";
error TychoRouter__WithdrawalFailed(); error TychoRouter__WithdrawalFailed();
error TychoRouter__AddressZero(); error TychoRouter__AddressZero();
@@ -197,6 +198,7 @@ contract TychoRouter is
uint256[] memory remainingAmounts = new uint256[](nTokens); uint256[] memory remainingAmounts = new uint256[](nTokens);
uint256[] memory amounts = new uint256[](nTokens); uint256[] memory amounts = new uint256[](nTokens);
console.logUint(amountIn);
amounts[0] = amountIn; amounts[0] = amountIn;
remainingAmounts[0] = amountIn; remainingAmounts[0] = amountIn;
@@ -208,9 +210,13 @@ contract TychoRouter is
currentAmountIn = split > 0 currentAmountIn = split > 0
? (amounts[tokenInIndex] * split) / 0xffffff ? (amounts[tokenInIndex] * split) / 0xffffff
: remainingAmounts[tokenInIndex]; : remainingAmounts[tokenInIndex];
console.logUint(split);
console.logUint(tokenInIndex); // This gives 1, I guess it should be 0
console.logUint(currentAmountIn);
currentAmountOut = _callExecutor( currentAmountOut = _callExecutor(
swapData.executor(), swapData.executor(),
swapData.executorSelector(), swapData.executorSelector(),
// TODO 0 is being passed here which makes it fail
currentAmountIn, currentAmountIn,
swapData.protocolData() swapData.protocolData()
); );

View File

@@ -673,21 +673,37 @@ contract TychoRouterTest is TychoRouterTestSetup {
} }
function testSingleSwapIntegration() public { function testSingleSwapIntegration() public {
// Test created with calldata from our router encoder // Test created with calldata from our router encoder, replacing the executor
// address with the USV2 executor address.
// Tests swapping WETH -> DAI on a USV2 pool // Tests swapping WETH -> DAI on a USV2 pool
vm.rollFork(21740300); deal(WETH_ADDR, ALICE, 1 ether);
deal(WETH_ADDR, tychoRouterAddr, 1 ether);
uint256 balancerBefore = IERC20(DAI_ADDR).balanceOf(ALICE); uint256 balancerBefore = IERC20(DAI_ADDR).balanceOf(ALICE);
// Encoded solution generated using `test_split_swap_strategy_encoder` with // Approve permit2
// Alice's private key vm.startPrank(ALICE);
(bool success,) = tychoRouterAddr.call( IERC20(WETH_ADDR).approve(
hex"e73e3baa0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002c6a3cd97c6283b95ac8c5a4459ebb0d5fd404f4000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000067c38a9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c6a3cd97c6283b95ac8c5a4459ebb0d5fd404f400000000000000000000000000000000000000000000000000000000679c0498000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000041eea332470b38c64899045460469146ef146969d3ed5f64fc58f25f58bc709dfb172ef15397b7591fcfd6642cd5a50509702c39a39d87ab79575d5c5388203e3b1b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005c005a01000000005c2f5a71f67c01775180adc06909288b4c329308bd0625abc02aaa39b223fe8d0a0e5c4f27ead9083c756cc288e6a0c2ddd26feeb64f039a2c41296fcb3f56402c6a3cd97c6283b95ac8c5a4459ebb0d5fd404f40000000000" address(0x000000000022D473030F116dDEE9F6B43aC78BA3),
type(uint256).max
); );
// Encoded solution generated using `test_split_swap_strategy_encoder` but
// manually replacing the executor address `5c2f5a71f67c01775180adc06909288b4c329308`
// with the one in this test `5615deb798bb3e4dfa0139dfa1b3d433cc23b72f`
(bool success,) = tychoRouterAddr.call(
hex"4860f9ed0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000cd09f75e2bf2a4d11f3ab23f1389fcc1621c0cc2000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000067c3df5a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000003ede3eca2a72b3aecc820e955b36f38437d0139500000000000000000000000000000000000000000000000000000000679c5962000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000041d3d0a64c002bdbedfa0dd859cba103fed3337b0bac6ec26ed22f83475426b83a58fd79adfeefea58c5f2e52e915e20a57220c8f32578d942ab5dc15fca3f47241c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005c005a01000000005615deb798bb3e4dfa0139dfa1b3d433cc23b72fbd0625abc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2a478c2975ab1ea89e8196811f51a7b7ade33eb113ede3eca2a72b3aecc820e955b36f38437d013950000000000"
);
// TODO why does this only work when Alice is the caller? I tried to say the
// sender is address(this) but that doesn't work...
vm.stopPrank();
console.logAddress((address(usv2Executor)));
console.logAddress(address(this));
console.logUint(block.timestamp);
uint256 balancerAfter = IERC20(DAI_ADDR).balanceOf(ALICE); uint256 balancerAfter = IERC20(DAI_ADDR).balanceOf(ALICE);
assertTrue(success, "Call Failed"); assertTrue(success, "Call Failed");
assertGt(balancerAfter, balancerBefore); assertGt(balancerAfter, balancerBefore);
} }
} }

View File

@@ -39,7 +39,10 @@ contract TychoRouterTestSetup is Test, Constants {
MockERC20[] tokens; MockERC20[] tokens;
function setUp() public { function setUp() public {
uint256 forkBlock = 21000000; // TODO I changed the forked block to match the signature
// of the integration test and now all the other tests fail
// fix this when the integration test passes.
uint256 forkBlock = 21742149;
vm.createSelectFork(vm.rpcUrl("mainnet"), forkBlock); vm.createSelectFork(vm.rpcUrl("mainnet"), forkBlock);
vm.startPrank(ADMIN); vm.startPrank(ADMIN);

View File

@@ -124,6 +124,7 @@ impl StrategyEncoder for SplitSwapStrategyEncoder {
U8::from( U8::from(
tokens tokens
.iter() .iter()
// TODO Something is wrong with our token in and out indices
.position(|t| *t == swap.token_in) .position(|t| *t == swap.token_in)
.ok_or_else(|| { .ok_or_else(|| {
EncodingError::InvalidInput( EncodingError::InvalidInput(
@@ -134,6 +135,7 @@ impl StrategyEncoder for SplitSwapStrategyEncoder {
U8::from( U8::from(
tokens tokens
.iter() .iter()
// TODO Something is wrong with our token in and out indices
.position(|t| *t == swap.token_out) .position(|t| *t == swap.token_out)
.ok_or_else(|| { .ok_or_else(|| {
EncodingError::InvalidInput( EncodingError::InvalidInput(
@@ -385,6 +387,7 @@ mod tests {
)); ));
let hex_calldata = encode(&calldata); let hex_calldata = encode(&calldata);
println!("{}", hex_calldata);
assert_eq!(hex_calldata[..520], expected_input); assert_eq!(hex_calldata[..520], expected_input);
assert_eq!(hex_calldata[1288..], expected_swaps); assert_eq!(hex_calldata[1288..], expected_swaps);
} }