nodeset-org / constellation

GNU General Public License v3.0
5 stars 0 forks source link

[Test] Add Comprehensive Tests for Yield Accrual Functionality #263

Closed teddy-nodeset closed 2 months ago

teddy-nodeset commented 2 months ago

This PR introduces a comprehensive suite of tests for the onEthRewardsReceived function in the Yield Accrual contract. These tests cover various scenarios to ensure the correct behavior and proper error handling of the function. The test cases include:

Test Cases for Yield Accrual

When sender is not protocol:

  1. Should revert with "Can only be called by Protocol!"

When sender is protocol:

When rewards are positive:

When insufficient balance:

  1. Should revert when there is not enough ETH in Asset Router for avgTreasuryFee with "Transfer to treasury failed".
  2. Should revert when there is not enough ETH in Asset Router for avgOperatorsFee with "Transfer to yield distributor failed".

When sufficient balance:

When community rewards are positive:
  1. Should increase balanceEthAndWeth & call onIncreaseOracleError with avgTreasuryFee=0.6, avgOperatorsFee=0.4.
  2. Should increase balanceEthAndWeth & call onIncreaseOracleError with avgTreasuryFee=0.1, avgOperatorsFee=0.1.
  3. Should increase balanceEthAndWeth & call onIncreaseOracleError with avgTreasuryFee=0.5, avgOperatorsFee=0.4.
  4. Should increase balanceEthAndWeth & call onIncreaseOracleError with avgTreasuryFee=0.99, avgOperatorsFee=0.01.
  5. Should increase balanceEthAndWeth & call onIncreaseOracleError with avgTreasuryFee=0.99999, avgOperatorsFee=0.00001.
  6. Should increase balanceEthAndWeth & call onIncreaseOracleError with avgTreasuryFee=1, avgOperatorsFee=0.
  7. Should increase balanceEthAndWeth & call onIncreaseOracleError with avgTreasuryFee=0, avgOperatorsFee=1.
When community rewards are negative:
  1. Should revert with panic code 0x11.

When rewards are zero:

  1. Should do nothing.

When rewards are negative:

  1. Should revert.