From 0196767eff1d18481e3154defd92514bd45d74b9 Mon Sep 17 00:00:00 2001 From: royvardhan Date: Wed, 29 Jan 2025 23:20:55 +0530 Subject: [PATCH] feat: add swap test with hex for univ2 executor --- foundry/test/executors/UniswapV2Executor.t.sol | 12 ++++++++++++ src/encoding/evm/strategy_encoder/encoder.rs | 8 ++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/foundry/test/executors/UniswapV2Executor.t.sol b/foundry/test/executors/UniswapV2Executor.t.sol index 300293c..070bc21 100644 --- a/foundry/test/executors/UniswapV2Executor.t.sol +++ b/foundry/test/executors/UniswapV2Executor.t.sol @@ -107,4 +107,16 @@ contract UniswapV2ExecutorTest is UniswapV2ExecutorExposed, Test, Constants { assertEq(receiver, 0x0000000000000000000000000000000000000001); assertEq(zeroForOne, false); } + + function testSwapExecutorSwap() public { + bytes memory protocolData = + hex"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2a478c2975ab1ea89e8196811f51a7b7ade33eb111d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e0000"; + uint256 amountIn = 10 ** 18; + uint256 amountOut = 1847751195973566072891; + deal(WETH_ADDR, address(uniswapV2Exposed), amountIn); + uniswapV2Exposed.swap(amountIn, protocolData); + + uint256 finalBalance = DAI.balanceOf(BOB); + assertGe(finalBalance, amountOut); + } } diff --git a/src/encoding/evm/strategy_encoder/encoder.rs b/src/encoding/evm/strategy_encoder/encoder.rs index 87b8122..b12a50e 100644 --- a/src/encoding/evm/strategy_encoder/encoder.rs +++ b/src/encoding/evm/strategy_encoder/encoder.rs @@ -97,7 +97,7 @@ mod tests { let swap = Swap { component: ProtocolComponent { - id: "0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640".to_string(), + id: "0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11".to_string(), protocol_system: "uniswap_v2".to_string(), ..Default::default() }, @@ -114,7 +114,7 @@ mod tests { checked_token: token_out, check_amount: None, sender: Bytes::from_str("0x0000000000000000000000000000000000000000").unwrap(), - receiver: Bytes::from_str("0x0000000000000000000000000000000000000001").unwrap(), + receiver: Bytes::from_str("0x1d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e").unwrap(), swaps: vec![swap], straight_to_pool: true, router_address: Some(Bytes::zero(20)), @@ -137,9 +137,9 @@ mod tests { // in token "c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // component id - "88e6a0c2ddd26feeb64f039a2c41296fcb3f5640", + "a478c2975ab1ea89e8196811f51a7b7ade33eb11", // receiver - "0000000000000000000000000000000000000001", + "1d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e", // zero for one "00", // exact out