yearn / yearn-vaults-v3

GNU Affero General Public License v3.0
104 stars 37 forks source link

E2E Tests (Generic issue) #63

Closed jmonteer closed 2 years ago

jmonteer commented 2 years ago

Description: Before deploying any code and entering into "test in prod phase", we need to build an extensive suite of E2E tests.

E2E tests need to cover from basic behavior to complex one

To achieve good test coverage at the lowest cost possible we will split test writting in two weeks.

1 week of tests (from today 21st of July to next Thursday 28th of July)

1 week of more complex tests (from 28th July to 4th August):

The objective is that contributors are incentivised to create tests ASAP in the first week to receive payment, tackling first the most simple ones but also doing complex ones at the less expensive rate.

Tests must be proposed in a comment in this issue: 1 test - 1 comment The format will be *test__doing_whatever_by_role_X__reverts*: description of the test

Approved tests will have a reaction of 👍 by a yearn contributor Rejected tests will have nothing and might be commented for them to be amended or improved

IMPORTANT: tests should have a bare minimum quality and complexity. Those that are not complex enough but need to be implemented will be put together in a separate issue and be implemented in a batch as a dev-lvl-0 bounty. Feel free to suggest whatever test though

Dependencies: NA

Acceptance criteria:

Payment Trigger: PR is merged

Category: DEV

Level: NA

bufander commented 2 years ago

test__lossy_strategy_flow: test will implement a full scenario in which there is a lossy strategy and users that take losses.

  1. we add a lossy strategy to a vault
  2. user_1 deposits into vault
  3. we call update_debt
  4. we generate loss in the strategy
  5. we call process_report: there should be a loss and current_debt on strategy should reflect it
  6. user_2 deposits in vault: price_per_share should be below 1:1
  7. we update_debt on strategy
  8. we generate more losses on strategy
  9. we call process_report: there should be a loss and strategy.current_debt on strategy should reflect it
  10. we update vault min_total_idle (on a lossy strategy situation we want to ensure that the vault has assets for users to withdraw)
  11. we update_debt to reflect changes on the strategy
  12. user1 withdraws total_idle
  13. we update_debt to ensure min_total_idle on vault: we can ensure that min_total_idle forces the strategy to return all its debt
  14. all users withdraw everything: balance of users should be lower than initially
  15. we revoke strategy
bufander commented 2 years ago

now that _profitdistribution issue is done, we can add a similar scenario with a profitable strategy:

test__profitable_strategy_flow: test will implement a full scenario in which there is a profitable strategy and users that take profits. We can use the lossy strategy contract, so we can also create losses.

  1. we add a profitable strategy to a vault
  2. user_1 deposits into vault
  3. add fees to vault
  4. we call update_debt
  5. we generate profit in the strategy
  6. we call process_report: there should be a profit and distribution rate should reflect it
  7. we let time pass to see how profits get unlocked
  8. user_2 deposits in vault: price_per_share should be above 1:1
  9. we update_debt on strategy
  10. we generate more profits on strategy
  11. we call process_report: there should be a profit and distribution rate should reflect it
  12. we create a small loss. it should not affect total_assets as there is enough profit buffer to handle it. Distribution rate should be lower now.
  13. we update vault min_total_idle
  14. we update_debt to reflect changes on the strategy
  15. user1 withdraws total_idle
  16. we update_debt to ensure min_total_idle on vault: we can ensure that min_total_idle forces the strategy to return all its debt
  17. we let the profit buffer unlock everything
  18. all users withdraw everything: balance of users should be higher than initially
  19. we revoke strategy