feat: Finalized tests
This commit is contained in:
@@ -8,10 +8,14 @@ import "src/libraries/FractionMath.sol";
|
|||||||
import "src/etherfi/EtherfiAdapter.sol";
|
import "src/etherfi/EtherfiAdapter.sol";
|
||||||
|
|
||||||
contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
|
contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
|
||||||
|
using FractionMath for Fraction;
|
||||||
|
|
||||||
EtherfiAdapter adapter;
|
EtherfiAdapter adapter;
|
||||||
IWeEth weEth = IWeEth(0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee);
|
IWeEth weEth = IWeEth(0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee);
|
||||||
IeEth eEth;
|
IeEth eEth;
|
||||||
|
|
||||||
|
uint256 constant TEST_ITERATIONS = 100;
|
||||||
|
|
||||||
function setUp() public {
|
function setUp() public {
|
||||||
uint256 forkBlock = 19218495;
|
uint256 forkBlock = 19218495;
|
||||||
vm.createSelectFork(vm.rpcUrl("mainnet"), forkBlock);
|
vm.createSelectFork(vm.rpcUrl("mainnet"), forkBlock);
|
||||||
@@ -288,15 +292,15 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
executeIncreasingSwapsEtherfi(OrderSide.Buy);
|
executeIncreasingSwapsEtherfi(OrderSide.Buy);
|
||||||
}
|
}
|
||||||
|
|
||||||
function executeIncreasingSwapsIntegral(OrderSide side) internal {
|
function executeIncreasingSwapsEtherfi(OrderSide side) internal {
|
||||||
bytes32 pair = bytes32(0);
|
bytes32 pair = bytes32(0);
|
||||||
|
|
||||||
uint256 amountConstant_ = side == 10**18;
|
uint256 amountConstant_ = 10**18;
|
||||||
|
|
||||||
uint256[] memory amounts = new uint256[](TEST_ITERATIONS);
|
uint256[] memory amounts = new uint256[](TEST_ITERATIONS);
|
||||||
amounts[0] = amountConstant_;
|
amounts[0] = amountConstant_;
|
||||||
for (uint256 i = 1; i < TEST_ITERATIONS; i++) {
|
for (uint256 i = 1; i < TEST_ITERATIONS; i++) {
|
||||||
amounts[i] = amountConstant_ * i;
|
amounts[i] = amountConstant_ + i;
|
||||||
}
|
}
|
||||||
|
|
||||||
Trade[] memory trades = new Trade[](TEST_ITERATIONS);
|
Trade[] memory trades = new Trade[](TEST_ITERATIONS);
|
||||||
@@ -304,10 +308,10 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
for (uint256 i = 1; i < TEST_ITERATIONS; i++) {
|
for (uint256 i = 1; i < TEST_ITERATIONS; i++) {
|
||||||
beforeSwap = vm.snapshot();
|
beforeSwap = vm.snapshot();
|
||||||
|
|
||||||
deal(address(USDC), address(this), amounts[i]);
|
deal(address(weEth), address(this), amounts[i]);
|
||||||
USDC.approve(address(adapter), amounts[i]);
|
IERC20(address(weEth)).approve(address(adapter), amounts[i]);
|
||||||
|
|
||||||
trades[i] = adapter.swap(pair, USDC, WETH, side, amounts[i]);
|
trades[i] = adapter.swap(pair, IERC20(address(weEth)), IERC20(address(eEth)), side, amounts[i]);
|
||||||
vm.revertTo(beforeSwap);
|
vm.revertTo(beforeSwap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,7 +321,6 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
|
|||||||
trades[i + 1].calculatedAmount
|
trades[i + 1].calculatedAmount
|
||||||
);
|
);
|
||||||
assertLe(trades[i].gasUsed, trades[i + 1].gasUsed);
|
assertLe(trades[i].gasUsed, trades[i + 1].gasUsed);
|
||||||
assertEq(trades[i].price.compareFractions(trades[i + 1].price), 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user