Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add more preview swap coverage (SC-503) #24

Merged
merged 37 commits into from
Jul 17, 2024
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
8e20594
feat: update swap to swapExactAmountIn
lucas-manuel Jul 2, 2024
b3a2d67
feat: add preview test coverage
lucas-manuel Jul 2, 2024
1c42d99
feat: add new function
lucas-manuel Jul 3, 2024
278d99e
feat: create new file, failure tests passing
lucas-manuel Jul 4, 2024
54ca402
ci: add coverage backgp
lucas-manuel Jul 4, 2024
95c9654
Merge branch 'master' into sc-490-add-exact-amount-out-swap
lucas-manuel Jul 4, 2024
1a426da
Merge branch 'add-coverage-back' into sc-490-add-exact-amount-out-swap
lucas-manuel Jul 4, 2024
02074d0
feat: get new swap tests passing
lucas-manuel Jul 4, 2024
93220d5
feat: set up initial test
lucas-manuel Jul 4, 2024
7a9c76e
feat: refactor code to add returns
lucas-manuel Jul 4, 2024
8279856
feat: add return value assertions
lucas-manuel Jul 4, 2024
389c859
Merge branch 'sc-490-add-exact-amount-out-swap' into sc-482-swap-fuzz…
lucas-manuel Jul 4, 2024
2aabbf8
feat: working fuzz test
lucas-manuel Jul 4, 2024
e810447
feat: add swap exact out, show that rounding is against user
lucas-manuel Jul 4, 2024
3484433
fix: update natspec
lucas-manuel Jul 4, 2024
86cf19d
Merge branch 'sc-490-add-exact-amount-out-swap' into sc-482-swap-fuzz…
lucas-manuel Jul 4, 2024
d736ad1
feat: refactor to round up on swap exact out
lucas-manuel Jul 4, 2024
4bffb0e
feat: all tests passing
lucas-manuel Jul 4, 2024
2ec107e
fix: merge conflicts
lucas-manuel Jul 4, 2024
747eb61
Merge branch 'master' into add-coverage-back
lucas-manuel Jul 4, 2024
869ccdc
Merge branch 'add-coverage-back' into sc-490-add-exact-amount-out-swap
lucas-manuel Jul 4, 2024
113cd97
Merge branch 'sc-490-add-exact-amount-out-swap' into sc-482-swap-fuzz…
lucas-manuel Jul 4, 2024
132d11b
fix: merge conflicts
lucas-manuel Jul 4, 2024
c76f76c
Merge branch 'sc-490-add-exact-amount-out-swap' into sc-482-swap-fuzz…
lucas-manuel Jul 4, 2024
6b5b94b
fix: cleanup
lucas-manuel Jul 4, 2024
b3db93e
Merge branch 'sc-490-add-exact-amount-out-swap' into sc-482-swap-fuzz…
lucas-manuel Jul 4, 2024
226c8db
feat: update tolerances
lucas-manuel Jul 4, 2024
c30dc9e
Merge branch 'sc-490-add-exact-amount-out-swap' into sc-482-swap-fuzz…
lucas-manuel Jul 4, 2024
da5ce84
fix: update tolerance
lucas-manuel Jul 4, 2024
777b8e0
Merge branch 'sc-490-add-exact-amount-out-swap' into sc-482-swap-fuzz…
lucas-manuel Jul 4, 2024
057b057
fix: increase fuzz tolerance
lucas-manuel Jul 4, 2024
82aa91b
Merge branch 'sc-490-add-exact-amount-out-swap' into sc-482-swap-fuzz…
lucas-manuel Jul 4, 2024
5f7742a
fix: conflicts
lucas-manuel Jul 5, 2024
30edbaf
Merge branch 'master' into sc-482-swap-fuzz-testing
lucas-manuel Jul 5, 2024
00aea79
fix: updat to totalAssets
lucas-manuel Jul 5, 2024
ee7975f
feat: add more coverage for rounding
lucas-manuel Jul 5, 2024
fa87f10
fix: merge conflicts
lucas-manuel Jul 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions test/unit/Previews.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ contract PSMPreviewSwapExactOut_FailureTests is PSMTestBase {
contract PSMPreviewSwapExactIn_DaiAssetInTests is PSMTestBase {

function test_previewSwapExactIn_daiToUsdc() public view {
// Demo rounding down
assertEq(psm.previewSwapExactIn(address(dai), address(usdc), 1e18 - 1), 1e6 - 1);
assertEq(psm.previewSwapExactIn(address(dai), address(usdc), 1e18), 1e6);
assertEq(psm.previewSwapExactIn(address(dai), address(usdc), 1e18 + 1), 1e6);

assertEq(psm.previewSwapExactIn(address(dai), address(usdc), 1e12 - 1), 0);
assertEq(psm.previewSwapExactIn(address(dai), address(usdc), 1e12), 1);

Expand All @@ -81,6 +86,11 @@ contract PSMPreviewSwapExactIn_DaiAssetInTests is PSMTestBase {
}

function test_previewSwapExactIn_daiToSDai() public view {
// Demo rounding down
assertEq(psm.previewSwapExactIn(address(dai), address(sDai), 1e18 - 1), 0.8e18 - 1);
assertEq(psm.previewSwapExactIn(address(dai), address(sDai), 1e18), 0.8e18);
assertEq(psm.previewSwapExactIn(address(dai), address(sDai), 1e18 + 1), 0.8e18);

assertEq(psm.previewSwapExactIn(address(dai), address(sDai), 1e18), 0.8e18);
assertEq(psm.previewSwapExactIn(address(dai), address(sDai), 2e18), 1.6e18);
assertEq(psm.previewSwapExactIn(address(dai), address(sDai), 3e18), 2.4e18);
Expand All @@ -102,6 +112,11 @@ contract PSMPreviewSwapExactIn_DaiAssetInTests is PSMTestBase {
contract PSMPreviewSwapExactOut_DaiAssetInTests is PSMTestBase {

function test_previewSwapExactOut_daiToUsdc() public view {
// Demo rounding up
assertEq(psm.previewSwapExactOut(address(dai), address(usdc), 1e6 - 1), 0.999999e18);
assertEq(psm.previewSwapExactOut(address(dai), address(usdc), 1e6), 1e18);
assertEq(psm.previewSwapExactOut(address(dai), address(usdc), 1e6 + 1), 1.000001e18);

assertEq(psm.previewSwapExactOut(address(dai), address(usdc), 1e6), 1e18);
assertEq(psm.previewSwapExactOut(address(dai), address(usdc), 2e6), 2e18);
assertEq(psm.previewSwapExactOut(address(dai), address(usdc), 3e6), 3e18);
Expand All @@ -114,6 +129,11 @@ contract PSMPreviewSwapExactOut_DaiAssetInTests is PSMTestBase {
}

function test_previewSwapExactOut_daiToSDai() public view {
// Demo rounding up
assertEq(psm.previewSwapExactOut(address(dai), address(sDai), 1e18 - 1), 1.25e18 - 1);
assertEq(psm.previewSwapExactOut(address(dai), address(sDai), 1e18), 1.25e18);
assertEq(psm.previewSwapExactOut(address(dai), address(sDai), 1e18 + 1), 1.25e18 + 2);

assertEq(psm.previewSwapExactOut(address(dai), address(sDai), 0.8e18), 1e18);
assertEq(psm.previewSwapExactOut(address(dai), address(sDai), 1.6e18), 2e18);
assertEq(psm.previewSwapExactOut(address(dai), address(sDai), 2.4e18), 3e18);
Expand All @@ -138,6 +158,11 @@ contract PSMPreviewSwapExactOut_DaiAssetInTests is PSMTestBase {
contract PSMPreviewSwapExactIn_USDCAssetInTests is PSMTestBase {

function test_previewSwapExactIn_usdcToDai() public view {
// Demo rounding down
assertEq(psm.previewSwapExactIn(address(usdc), address(dai), 1e6 - 1), 0.999999e18);
assertEq(psm.previewSwapExactIn(address(usdc), address(dai), 1e6), 1e18);
assertEq(psm.previewSwapExactIn(address(usdc), address(dai), 1e6 + 1), 1.000001e18);

assertEq(psm.previewSwapExactIn(address(usdc), address(dai), 1e6), 1e18);
assertEq(psm.previewSwapExactIn(address(usdc), address(dai), 2e6), 2e18);
assertEq(psm.previewSwapExactIn(address(usdc), address(dai), 3e6), 3e18);
Expand All @@ -150,6 +175,11 @@ contract PSMPreviewSwapExactIn_USDCAssetInTests is PSMTestBase {
}

function test_previewSwapExactIn_usdcToSDai() public view {
// Demo rounding down
assertEq(psm.previewSwapExactIn(address(usdc), address(sDai), 1e6 - 1), 0.799999e18);
assertEq(psm.previewSwapExactIn(address(usdc), address(sDai), 1e6), 0.8e18);
assertEq(psm.previewSwapExactIn(address(usdc), address(sDai), 1e6 + 1), 0.8e18);

assertEq(psm.previewSwapExactIn(address(usdc), address(sDai), 1e6), 0.8e18);
assertEq(psm.previewSwapExactIn(address(usdc), address(sDai), 2e6), 1.6e18);
assertEq(psm.previewSwapExactIn(address(usdc), address(sDai), 3e6), 2.4e18);
Expand All @@ -171,6 +201,11 @@ contract PSMPreviewSwapExactIn_USDCAssetInTests is PSMTestBase {
contract PSMPreviewSwapExactOut_USDCAssetInTests is PSMTestBase {

function test_previewSwapExactOut_usdcToDai() public view {
// Demo rounding up
assertEq(psm.previewSwapExactOut(address(usdc), address(dai), 1e18 - 1), 1e6);
assertEq(psm.previewSwapExactOut(address(usdc), address(dai), 1e18), 1e6);
assertEq(psm.previewSwapExactOut(address(usdc), address(dai), 1e18 + 1), 1e6 + 1);

assertEq(psm.previewSwapExactOut(address(usdc), address(dai), 1e18), 1e6);
assertEq(psm.previewSwapExactOut(address(usdc), address(dai), 2e18), 2e6);
assertEq(psm.previewSwapExactOut(address(usdc), address(dai), 3e18), 3e6);
Expand All @@ -186,6 +221,11 @@ contract PSMPreviewSwapExactOut_USDCAssetInTests is PSMTestBase {
}

function test_previewSwapExactOut_usdcToSDai() public view {
// Demo rounding up
assertEq(psm.previewSwapExactOut(address(usdc), address(sDai), 1e18 - 1), 1.25e6);
assertEq(psm.previewSwapExactOut(address(usdc), address(sDai), 1e18), 1.25e6);
assertEq(psm.previewSwapExactOut(address(usdc), address(sDai), 1e18 + 1), 1.25e6 + 1);

assertEq(psm.previewSwapExactOut(address(usdc), address(sDai), 0.8e18), 1e6);
assertEq(psm.previewSwapExactOut(address(usdc), address(sDai), 1.6e18), 2e6);
assertEq(psm.previewSwapExactOut(address(usdc), address(sDai), 2.4e18), 3e6);
Expand All @@ -206,11 +246,40 @@ contract PSMPreviewSwapExactOut_USDCAssetInTests is PSMTestBase {
assertLe(amountIn - expectedAmountIn, 1);
}

function test_demoRoundingUp_usdcToSDai() public view {
uint256 expectedAmountIn1 = psm.previewSwapExactOut(address(usdc), address(sDai), 0.8e18);
uint256 expectedAmountIn2 = psm.previewSwapExactOut(address(usdc), address(sDai), 0.8e18 + 1);
uint256 expectedAmountIn3 = psm.previewSwapExactOut(address(usdc), address(sDai), 0.8e18 + 0.8e12);
uint256 expectedAmountIn4 = psm.previewSwapExactOut(address(usdc), address(sDai), 0.8e18 + 0.8e12 + 1);

assertEq(expectedAmountIn1, 1e6);
assertEq(expectedAmountIn2, 1e6 + 1);
assertEq(expectedAmountIn3, 1e6 + 1);
assertEq(expectedAmountIn4, 1e6 + 2);
}

function test_demoRoundingUp_usdcToDai() public view {
uint256 expectedAmountIn1 = psm.previewSwapExactOut(address(usdc), address(dai), 1e18);
uint256 expectedAmountIn2 = psm.previewSwapExactOut(address(usdc), address(dai), 1e18 + 1);
uint256 expectedAmountIn3 = psm.previewSwapExactOut(address(usdc), address(dai), 1e18 + 1e12);
uint256 expectedAmountIn4 = psm.previewSwapExactOut(address(usdc), address(dai), 1e18 + 1e12 + 1);

assertEq(expectedAmountIn1, 1e6);
assertEq(expectedAmountIn2, 1e6 + 1);
assertEq(expectedAmountIn3, 1e6 + 1);
assertEq(expectedAmountIn4, 1e6 + 2);
}

}

contract PSMPreviewSwapExactIn_SDaiAssetInTests is PSMTestBase {

function test_previewSwapExactIn_sDaiToDai() public view {
// Demo rounding down
assertEq(psm.previewSwapExactIn(address(sDai), address(dai), 1e18 - 1), 1.25e18 - 2);
assertEq(psm.previewSwapExactIn(address(sDai), address(dai), 1e18), 1.25e18);
assertEq(psm.previewSwapExactIn(address(sDai), address(dai), 1e18 + 1), 1.25e18 + 1);

assertEq(psm.previewSwapExactIn(address(sDai), address(dai), 1e18), 1.25e18);
assertEq(psm.previewSwapExactIn(address(sDai), address(dai), 2e18), 2.5e18);
assertEq(psm.previewSwapExactIn(address(sDai), address(dai), 3e18), 3.75e18);
Expand All @@ -228,6 +297,11 @@ contract PSMPreviewSwapExactIn_SDaiAssetInTests is PSMTestBase {
}

function test_previewSwapExactIn_sDaiToUsdc() public view {
// Demo rounding down
assertEq(psm.previewSwapExactIn(address(sDai), address(usdc), 1e18 - 1), 1.25e6 - 1);
assertEq(psm.previewSwapExactIn(address(sDai), address(usdc), 1e18), 1.25e6);
assertEq(psm.previewSwapExactIn(address(sDai), address(usdc), 1e18 + 1), 1.25e6);

assertEq(psm.previewSwapExactIn(address(sDai), address(usdc), 1e18), 1.25e6);
assertEq(psm.previewSwapExactIn(address(sDai), address(usdc), 2e18), 2.5e6);
assertEq(psm.previewSwapExactIn(address(sDai), address(usdc), 3e18), 3.75e6);
Expand All @@ -249,6 +323,11 @@ contract PSMPreviewSwapExactIn_SDaiAssetInTests is PSMTestBase {
contract PSMPreviewSwapExactOut_SDaiAssetInTests is PSMTestBase {

function test_previewSwapExactOut_sDaiToDai() public view {
// Demo rounding up
assertEq(psm.previewSwapExactOut(address(sDai), address(dai), 1e18 - 1), 0.8e18);
assertEq(psm.previewSwapExactOut(address(sDai), address(dai), 1e18), 0.8e18);
assertEq(psm.previewSwapExactOut(address(sDai), address(dai), 1e18 + 1), 0.8e18 + 1);

assertEq(psm.previewSwapExactOut(address(sDai), address(dai), 1.25e18), 1e18);
assertEq(psm.previewSwapExactOut(address(sDai), address(dai), 2.5e18), 2e18);
assertEq(psm.previewSwapExactOut(address(sDai), address(dai), 3.75e18), 3e18);
Expand All @@ -269,6 +348,11 @@ contract PSMPreviewSwapExactOut_SDaiAssetInTests is PSMTestBase {
}

function test_previewSwapExactOut_sDaiToUsdc() public view {
// Demo rounding up
assertEq(psm.previewSwapExactOut(address(sDai), address(usdc), 1e6 - 1), 0.8e18);
assertEq(psm.previewSwapExactOut(address(sDai), address(usdc), 1e6), 0.8e18);
assertEq(psm.previewSwapExactOut(address(sDai), address(usdc), 1e6 + 1), 0.800001e18);

assertEq(psm.previewSwapExactOut(address(sDai), address(usdc), 1.25e6), 1e18);
assertEq(psm.previewSwapExactOut(address(sDai), address(usdc), 2.5e6), 2e18);
assertEq(psm.previewSwapExactOut(address(sDai), address(usdc), 3.75e6), 3e18);
Expand Down
Loading