Skip to content

Commit

Permalink
test: fixing stateful test edge cases
Browse files Browse the repository at this point in the history
* removed sanity checks from ramping tests since continuous running could lead to xcp being less than 1.

* virtual price invariant is now checked only after at least a swap has been done. In some cases you can have a balanced deposit followed by an unbalanced withdrawal which would break this invariant (tentative fix).

* removed assertion about equilibrium since it wasn't sensitive enough for small amounts.
  • Loading branch information
AlbertoCentonze committed May 22, 2024
1 parent ebf1049 commit b580be8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 5 additions & 4 deletions tests/unitary/pool/stateful/stateful_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
RuleBasedStateMachine,
initialize,
invariant,
precondition,
rule,
)
from hypothesis.strategies import integers
Expand Down Expand Up @@ -57,6 +58,8 @@ def initialize_pool(self, pool, amount, user):

self.equilibrium = 5e17

self.swapped_once = False

self.fee_receiver = factory.at(pool.factory()).fee_receiver()
self.admin = factory.at(pool.factory()).admin()

Expand Down Expand Up @@ -130,10 +133,6 @@ def report_equilibrium(self):

self.equilibrium = (xp + yp) / self.pool.D()

assert (
self.equilibrium != old_equilibrium
), "equlibrium didn't change after an imbalanced operation"

# we compute the percentage change from the old equilibrium
# to have a sense of how much an operation changed the pool
percentage_change = (
Expand Down Expand Up @@ -288,6 +287,7 @@ def exchange(self, dx: int, i: int, user: str) -> bool:
)
)

self.swapped_once = True
return True

def remove_liquidity(self, amount: int, user: str):
Expand Down Expand Up @@ -558,6 +558,7 @@ def sanity_check(self):
self.pool.balanceOf(d) > 0
), "tracked depositors should not have 0 lp tokens"

@precondition(lambda self: self.swapped_once)
@invariant()
def virtual_price(self):
assert (self.pool.virtual_price() - 1e18) * 2 >= (
Expand Down
4 changes: 4 additions & 0 deletions tests/unitary/pool/stateful/test_stateful.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ def up_only_profit(self):
# we disable this invariant because ramping can lead to losses
pass

def sanity_check(self):
# we disable this invariant because ramping can lead to losses
pass


TestOnlySwap = OnlySwapStateful.TestCase
TestUpOnlyLiquidity = UpOnlyLiquidityStateful.TestCase
Expand Down

0 comments on commit b580be8

Please sign in to comment.