Add integration test
This commit is contained in:
@@ -9,6 +9,7 @@ import {NATIVE_TOKEN_ADDRESS} from "@ekubo/math/constants.sol";
|
||||
import {ICore} from "@ekubo/interfaces/ICore.sol";
|
||||
|
||||
contract EkuboExecutorTest is Test, Constants {
|
||||
address constant EXECUTOR_ADDRESS = 0xcA4F73Fe97D0B987a0D12B39BBD562c779BAb6f6; // Same address as in swap_encoder.rs tests
|
||||
EkuboExecutor executor;
|
||||
|
||||
IERC20 USDC = IERC20(USDC_ADDR);
|
||||
@@ -19,9 +20,14 @@ contract EkuboExecutorTest is Test, Constants {
|
||||
bytes32 constant ORACLE_CONFIG = 0x51d02a5948496a67827242eabc5725531342527c000000000000000000000000;
|
||||
|
||||
function setUp() public {
|
||||
uint256 forkBlock = 22082754;
|
||||
vm.createSelectFork(vm.rpcUrl("mainnet"), forkBlock);
|
||||
executor = new EkuboExecutor(ICore(payable(CORE_ADDRESS)));
|
||||
vm.createSelectFork(vm.rpcUrl("mainnet"), 22082754);
|
||||
|
||||
deployCodeTo(
|
||||
"executors/EkuboExecutor.sol",
|
||||
abi.encode(CORE_ADDRESS),
|
||||
EXECUTOR_ADDRESS
|
||||
);
|
||||
executor = EkuboExecutor(payable(EXECUTOR_ADDRESS));
|
||||
}
|
||||
|
||||
function testSingleSwapEth() public {
|
||||
@@ -86,7 +92,8 @@ contract EkuboExecutorTest is Test, Constants {
|
||||
assertEq(address(executor).balance, ethBalanceBeforeExecutor + amountOut);
|
||||
}
|
||||
|
||||
function testMultiHopSwap() public {
|
||||
// Expects input that encodes the same test case as swap_encoder::tests::ekubo::test_encode_swap_multi
|
||||
function multiHopSwap(bytes memory data) internal {
|
||||
uint256 amountIn = 1 ether;
|
||||
|
||||
deal(address(executor), amountIn);
|
||||
@@ -97,15 +104,6 @@ contract EkuboExecutorTest is Test, Constants {
|
||||
uint256 usdtBalanceBeforeCore = USDT.balanceOf(CORE_ADDRESS);
|
||||
uint256 usdtBalanceBeforeExecutor = USDT.balanceOf(address(executor));
|
||||
|
||||
bytes memory data = abi.encodePacked(
|
||||
address(executor), // receiver
|
||||
NATIVE_TOKEN_ADDRESS, // tokenIn
|
||||
USDC_ADDR, // tokenOut of 1st swap
|
||||
ORACLE_CONFIG, // config of 1st swap
|
||||
USDT_ADDR, // tokenOut of 2nd swap
|
||||
bytes32(0x00000000000000000000000000000000000000000001a36e2eb1c43200000032) // config of 2nd swap (0.0025% fee & 0.005% base pool)
|
||||
);
|
||||
|
||||
uint256 gasBefore = gasleft();
|
||||
uint256 amountOut = executor.swap(amountIn, data);
|
||||
console.log(gasBefore - gasleft());
|
||||
@@ -118,4 +116,24 @@ contract EkuboExecutorTest is Test, Constants {
|
||||
assertEq(USDT.balanceOf(CORE_ADDRESS), usdtBalanceBeforeCore - amountOut);
|
||||
assertEq(USDT.balanceOf(address(executor)), usdtBalanceBeforeExecutor + amountOut);
|
||||
}
|
||||
|
||||
// Same test case as in swap_encoder::tests::ekubo::test_encode_swap_multi
|
||||
function testMultiHopSwap() public {
|
||||
bytes memory data = abi.encodePacked(
|
||||
address(executor), // receiver
|
||||
NATIVE_TOKEN_ADDRESS, // tokenIn
|
||||
USDC_ADDR, // tokenOut of 1st swap
|
||||
ORACLE_CONFIG, // config of 1st swap
|
||||
USDT_ADDR, // tokenOut of 2nd swap
|
||||
bytes32(0x00000000000000000000000000000000000000000001a36e2eb1c43200000032) // config of 2nd swap (0.0025% fee & 0.005% base pool)
|
||||
);
|
||||
multiHopSwap(data);
|
||||
}
|
||||
|
||||
// Data is generated by test case in swap_encoder::tests::ekubo::test_encode_swap_multi
|
||||
function testMultiHopSwapIntegration() public {
|
||||
multiHopSwap(
|
||||
hex"ca4f73fe97d0b987a0d12b39bbd562c779bab6f60000000000000000000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4851d02a5948496a67827242eabc5725531342527c000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000001a36e2eb1c43200000032"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user