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

Tests: fix CI with precise computations #695

Merged
merged 3 commits into from
Sep 30, 2024
Merged

Conversation

QGarchery
Copy link
Contributor

@QGarchery QGarchery commented Sep 29, 2024

This PR:

  • fixes, in f178c58, the computation of repaidAssets in _liquidateSeizedAssets, where interest not being accrued can underestimate it. Note that then it would potentially revert with "insufficient balance" in the following liquidate.
See failing test to add to MorphoInvariantTest.sol
    function testPreciseRepaidAssets() public {
        bool success;
        vm.prank(USER);
        (success,) = address(this).call(
            abi.encodeCall(
                this.supplySharesOnBehalfNoRevert,
                (
                    12120140710833733770211937208572361813353,
                    115792089237316195423570985008687907853269984665640564039457584007913129639932,
                    47864507797463465527
                )
            )
        );
        require(success);
        vm.prank(USER);
        (success,) = address(this).call(
            abi.encodeCall(
                this.supplyCollateralOnBehalfNoRevert,
                (
                    6435052175716277,
                    2228508671749618012310924141807912904392434873641473790,
                    9172044389146582702825330639391132781
                )
            )
        );
        require(success);
        vm.prank(USER);
        (success,) = address(this).call(
            abi.encodeCall(
                this.borrowAssetsOnBehalfNoRevert,
                (
                    1037090935628654632096113780633684768273947888827139171,
                    115792089237316195423570985008687907853269984665640564039457584007913129639932,
                    92919271977526577528324241,
                    0xb9524FC61bB10455497B76eCb47f7E15f5745c7b
                )
            )
        );
        require(success);
        vm.prank(USER);
        (success,) =
            address(this).call(abi.encodeCall(this.mine, (1917255564262442434629483470867958936496970738886927248333)));
        require(success);
        vm.prank(USER);
        (success,) = address(this).call(
            abi.encodeCall(
                this.liquidateSeizedAssetsNoRevert,
                (
                    423100602366647113405520187643810494979637824649807,
                    387663186081816078315953644541605829239672,
                    2906615577213273566318347175683901325413471477552651909
                )
            )
        );
        require(success);
    }
  • fixes, in fc6793a, the _boundUnhealthyPosition function to exclude some edge case positions that were actually healthy. For a failing test, run testBorrowUnhealthyPosition(1000, 800, 800, 1e36);
  • fixes, in 208c886, the _boundLiquidateSeizedAssets function that was rounding up the maxRepaidAssets
See failing test to add to MorphoInvariantTest.sol
    function testUnderflowShares() public {
        bool success;
        vm.prank(USER);
        (success,) = address(this).call(
            abi.encodeCall(
                this.supplyAssetsOnBehalfNoRevert,
                (5359, 2834887728753290660080060877037723411257078492004434445635685037311818465281, 5492)
            )
        );
        require(success);
        vm.prank(USER);
        (success,) = address(this).call(
            abi.encodeCall(
                this.supplyCollateralOnBehalfNoRevert,
                (
                    13564749995715475,
                    289569068587302794245905088352847419974621660102028416637799895,
                    93568447518652389288497189907082257029069294440600267233672740108057536
                )
            )
        );
        require(success);
        vm.prank(USER);
        (success,) = address(this).call(
            abi.encodeCall(
                this.borrowAssetsOnBehalfNoRevert,
                (21253, 37687424321302508251177020996897486395182, 783, 0x00000000000000000000000000000000000003f4)
            )
        );
        require(success);
        vm.prank(USER);
        (success,) =
            address(this).call(abi.encodeCall(this.setPrice, (6663006047491614880599209616220218899614508160112)));
        require(success);
        vm.prank(USER);
        (success,) = address(this).call(abi.encodeCall(this.mine, (347004)));
        require(success);
        vm.prank(USER);
        (success,) = address(this).call(
            abi.encodeCall(
                this.liquidateSeizedAssetsNoRevert,
                (
                    1,
                    115792089237316195423570985008687907853269984665640564039457584007913129639934,
                    1405888047604400359344857338824181942093566199035292748
                )
            )
        );
        require(success);
    }

@QGarchery QGarchery self-assigned this Sep 29, 2024
@QGarchery QGarchery changed the title Tests: fix CI with precise computation Tests: fix CI with precise computations Sep 29, 2024
@QGarchery QGarchery marked this pull request as ready for review September 30, 2024 09:25
@QGarchery QGarchery requested a review from MathisGD September 30, 2024 09:25
test/forge/BaseTest.sol Show resolved Hide resolved
test/forge/BaseTest.sol Show resolved Hide resolved
@MathisGD MathisGD merged commit dee5cfc into main Sep 30, 2024
16 checks passed
@MathisGD MathisGD deleted the test/fix-precision-ci branch September 30, 2024 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants