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

Invariant tests for UbiquityPoolFacet #953

Open
wants to merge 17 commits into
base: development
Choose a base branch
from

Conversation

alexandr-masl
Copy link

@alexandr-masl alexandr-masl commented Aug 21, 2024

Resolves #563

@0x4007
Copy link
Member

0x4007 commented Aug 22, 2024

I understand that this is a draft pull request, so you should mark it as a draft pull request instead of emphasizing in your pull request body.

@0x4007 0x4007 marked this pull request as draft August 22, 2024 08:52
@ubiquity-os-deployer
Copy link

ubiquity-os-deployer bot commented Aug 25, 2024

@alexandr-masl alexandr-masl changed the title [DRAFT] test(UbiquityPoolFacet): initial invariant tests for collateral token addition and price feed setup [DRAFT] test(UbiquityPoolFacet): initial invariant tests for UbiquityPoolFacet Aug 25, 2024
@alexandr-masl alexandr-masl marked this pull request as ready for review September 3, 2024 18:13
@alexandr-masl alexandr-masl changed the title [DRAFT] test(UbiquityPoolFacet): initial invariant tests for UbiquityPoolFacet test(UbiquityPoolFacet): initial invariant tests for UbiquityPoolFacet Sep 3, 2024
@alexandr-masl
Copy link
Author

Hey everyone,

I believe we're could start with this invariant test. The primary goal was to implement a condition that consistently ensures the dollar amount remains fully collateralized. This condition addresses two key scenarios:

  1. Users cannot mint more Dollars (in USD value) than the provided collateral
  2. Users cannot redeem more collateral (in USD value) than the corresponding Dollar tokens

If either of these scenarios were to succeed, it would break the collateralization of the Dollar, thereby violating the invariant

During the test, it performs various manipulations with the values of collateral, USD, ETH/USDT, and Dollar prices, as well as minting and redemption fees, among other parameters

As the next step, additional invariants might be about the governance token and its associated logic

Looking forward to your feedback

@alexandr-masl alexandr-masl changed the title test(UbiquityPoolFacet): initial invariant tests for UbiquityPoolFacet UbiquityPoolFacet: initial invariant tests for UbiquityPoolFacet Sep 6, 2024
@rndquu rndquu self-requested a review September 9, 2024 08:21
Copy link
Member

@rndquu rndquu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexandr-masl Overall this is a great job.

  1. Pls fix minor issues in the comments
  2. Here you mention the Users cannot redeem more collateral (in USD value) than the corresponding Dollar tokens invariant test. Is it going to be implemented?
  3. This issue also implies setting up CI. You may take fuzzing CI as an example.

@alexandr-masl
Copy link
Author

@alexandr-masl Overall this is a great job.

Thanks for the feedback and kind words, will come up with an update soon

@alexandr-masl alexandr-masl marked this pull request as draft September 10, 2024 21:33
@gitcoindev
Copy link
Contributor

I did a review of the invariant tests skeleton, looks like a good start. Looking forward to see it in the ready for review stage.

@alexandr-masl
Copy link
Author

I did a review of the invariant tests skeleton, looks like a good start. Looking forward to see it in the ready for review stage.

Thanks for the feedback. I'm actively working on it

@alexandr-masl alexandr-masl changed the title UbiquityPoolFacet: initial invariant tests for UbiquityPoolFacet Invariant tests for UbiquityPoolFacet Sep 12, 2024
@alexandr-masl alexandr-masl marked this pull request as ready for review September 14, 2024 12:30
@alexandr-masl
Copy link
Author

Please review my basic invariant tests. I have minimized the use of prank(admin) and focused more on simulating user activity. The tests cover regular scenarios where there is no need to burn uDollars to rebalance collateral coverage. Additionally, I have included tests for the following conditions:

  • Users cannot mint more uDollars (in USD) than the provided collateral
  • Users cannot redeem more collateral (in USD) than the Dollar tokens they hold

Copy link
Member

@rndquu rndquu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls add this config to foundry.toml:

[profile.intense.invariant]
runs = 50000 # ~1 hour

@alexandr-masl
Copy link
Author

alexandr-masl commented Sep 18, 2024

Pls add this config to foundry.toml:

[profile.intense.invariant]
runs = 50000 # ~1 hour

I'm not highly experienced with the foundry.toml profile settings, but when I try to run the tests locally under the intense profile using the command FOUNDRY_PROFILE=intense forge test --match-path "test/invariant/**/*", the number of runs increases from the regular 256 to 4743 and 3280. However, it is still significantly lower than the 50,000 runs defined in the foundry.toml

Ran 2 tests for test/invariant/diamond/facets/UbiquityPoolFacet.invariant.t.sol:UbiquityPoolFacetInvariantTest
[PASS] invariant_CannotMintMoreDollarsThanCollateral() (runs: 3280, calls: 1640000, reverts: 133999)
[PASS] invariant_CannotRedeemMoreCollateralThanDollarValue() (runs: 4743, calls: 2371500, reverts: 193564)
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 809.21s (1384.47s CPU time)

@rndquu
Copy link
Member

rndquu commented Sep 19, 2024

Pls add this config to foundry.toml:

[profile.intense.invariant]
runs = 50000 # ~1 hour

I'm not highly experienced with the foundry.toml profile settings, but when I try to run the tests locally under the intense profile using the command FOUNDRY_PROFILE=intense forge test --match-path "test/invariant/**/*", the number of runs increases from the regular 256 to 4743 and 3280. However, it is still significantly lower than the 50,000 runs defined in the foundry.toml

Ran 2 tests for test/invariant/diamond/facets/UbiquityPoolFacet.invariant.t.sol:UbiquityPoolFacetInvariantTest
[PASS] invariant_CannotMintMoreDollarsThanCollateral() (runs: 3280, calls: 1640000, reverts: 133999)
[PASS] invariant_CannotRedeemMoreCollateralThanDollarValue() (runs: 4743, calls: 2371500, reverts: 193564)
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 809.21s (1384.47s CPU time)

That's strange, we'll see how it goes in the CI environment.

Copy link
Member

@rndquu rndquu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this is a good start. There're still too many reverts but it's something that we should work out in the next invariant tests iteration.

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.

Invariant Testing
4 participants