Skip to content

Commit

Permalink
test: corrected ramping condition
Browse files Browse the repository at this point in the history
Since contract were updated now test also respect the new ramping condition.

Also added a couple of function descriptions.
  • Loading branch information
AlbertoCentonze committed May 22, 2024
1 parent 866759c commit da26907
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 24 deletions.
16 changes: 11 additions & 5 deletions tests/unitary/pool/stateful/stateful_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,14 @@ def initialize_pool(self, pool, amount, user):

# --------------- utility methods ---------------

def is_ramping(self) -> bool:
"""Check if the pool is currently ramping."""

return self.pool.future_A_gamma_time() > boa.env.evm.patch.timestamp

def correct_decimals(self, amount: int, coin_idx: int) -> int:
"""Takes an amount that uses 18 decimals and reduces its precision"""

corrected_amount = int(
amount // (10 ** (18 - self.decimals[coin_idx]))
)
Expand All @@ -87,6 +94,9 @@ def correct_decimals(self, amount: int, coin_idx: int) -> int:
return corrected_amount

def correct_all_decimals(self, amounts: List[int]) -> Tuple[int, int]:
"""Takes a list of amounts that use 18 decimals and reduces their
precision to the number of decimals of the respective coins."""

return [self.correct_decimals(a, i) for i, a in enumerate(amounts)]

def get_balanced_deposit_amounts(self, amount: int):
Expand Down Expand Up @@ -351,10 +361,6 @@ def remove_liquidity_one_coin(
# store the balance of the user before the removal
user_balances_pre = self.coins[coin_idx].balanceOf(user)

pool_is_ramping = (
self.pool.future_A_gamma_time() > boa.env.evm.patch.timestamp
)

# lp tokens before the removal
lp_tokens_balance_pre = self.pool.balanceOf(user)

Expand Down Expand Up @@ -446,7 +452,7 @@ def remove_liquidity_one_coin(
# decimals: with such a low precision admin fees might be 0
or self.decimals[i] <= 4
), f"the admin fees collected should be positive for coin {i}"
assert not pool_is_ramping, "claim admin fees while ramping"
assert not self.is_ramping(), "claim admin fees while ramping"

# deduce the claimed amount from the pool balances
self.balances[i] -= claimed_amount
Expand Down
20 changes: 2 additions & 18 deletions tests/unitary/pool/stateful/test_stateful.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@
from hypothesis.strategies import data, floats, integers, sampled_from
from stateful_base import StatefulBase

from tests.utils.constants import (
MAX_A,
MAX_GAMMA,
MIN_A,
MIN_GAMMA,
MIN_RAMP_TIME,
UNIX_DAY,
)
from tests.utils.constants import MAX_A, MAX_GAMMA, MIN_A, MIN_GAMMA, UNIX_DAY
from tests.utils.strategies import address


Expand Down Expand Up @@ -279,16 +272,7 @@ class RampingStateful(ImbalancedLiquidityStateful):
# we fuzz the ramp duration up to a year
days = integers(min_value=1, max_value=365)

def can_ramp_again(self):
"""
Checks if the pool is not already ramping.
"""
return (
boa.env.evm.patch.timestamp
> self.pool.initial_A_gamma_time() + (MIN_RAMP_TIME - 1)
)

@precondition(can_ramp_again)
@precondition(lambda self: not self.is_ramping())
@rule(
A_change=change_step_strategy,
gamma_change=change_step_strategy,
Expand Down
1 change: 0 additions & 1 deletion tests/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
MIN_A = N_COINS**N_COINS * A_MULTIPLIER / 10
MAX_A = N_COINS**N_COINS * A_MULTIPLIER * 1000

MIN_RAMP_TIME = 86400
UNIX_DAY = 86400

MIN_FEE = 5 * 10**5
Expand Down

0 comments on commit da26907

Please sign in to comment.