Skip to content

Commit

Permalink
chore: using UNIX_DAY constant
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertoCentonze committed May 9, 2024
1 parent 8bf8ee1 commit 978590e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
6 changes: 4 additions & 2 deletions tests/unitary/pool/admin/test_ramp_A_gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import boa

from tests.utils.constants import UNIX_DAY


def test_ramp_A_gamma_up(swap, factory_admin, params):

p = copy.deepcopy(params)
future_A = p["A"] + 10000
future_gamma = p["gamma"] + 10000
future_time = boa.env.vm.state.timestamp + 86400
future_time = boa.env.vm.state.timestamp + UNIX_DAY

initial_A_gamma = [swap.A(), swap.gamma()]
swap.ramp_A_gamma(
Expand All @@ -31,7 +33,7 @@ def test_ramp_A_gamma_down(swap, factory_admin, params):
p = copy.deepcopy(params)
future_A = p["A"] - 10000
future_gamma = p["gamma"] - 10000
future_time = boa.env.vm.state.timestamp + 86400
future_time = boa.env.vm.state.timestamp + UNIX_DAY

initial_A_gamma = [swap.A(), swap.gamma()]
swap.ramp_A_gamma(
Expand Down
8 changes: 5 additions & 3 deletions tests/unitary/pool/admin/test_revert_ramp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import boa

from tests.utils.constants import UNIX_DAY


def test_revert_unauthorised_ramp(swap, user):

Expand All @@ -13,7 +15,7 @@ def test_revert_ramp_while_ramping(swap, factory_admin):
assert swap.initial_A_gamma_time() == 0

A_gamma = [swap.A(), swap.gamma()]
future_time = boa.env.vm.state.timestamp + 86400 + 1
future_time = boa.env.vm.state.timestamp + UNIX_DAY + 1
with boa.env.prank(factory_admin):
swap.ramp_A_gamma(A_gamma[0] + 1, A_gamma[1] + 1, future_time)

Expand All @@ -35,7 +37,7 @@ def test_revert_unauthorised_stop_ramp(swap, factory_admin, user):
assert swap.initial_A_gamma_time() == 0

A_gamma = [swap.A(), swap.gamma()]
future_time = boa.env.vm.state.timestamp + 86400 + 1
future_time = boa.env.vm.state.timestamp + UNIX_DAY + 1
with boa.env.prank(factory_admin):
swap.ramp_A_gamma(A_gamma[0] + 1, A_gamma[1] + 1, future_time)

Expand All @@ -50,7 +52,7 @@ def test_revert_ramp_too_far(swap, factory_admin):

A = swap.A()
gamma = swap.gamma()
future_time = boa.env.vm.state.timestamp + 86400 + 1
future_time = boa.env.vm.state.timestamp + UNIX_DAY + 1

with boa.env.prank(factory_admin), boa.reverts("A change too high"):
future_A = A * 11 # can at most increase by 10x
Expand Down
3 changes: 2 additions & 1 deletion tests/unitary/pool/stateful/stateful_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from hypothesis.stateful import RuleBasedStateMachine, invariant, rule

from tests.fixtures.pool import INITIAL_PRICES
from tests.utils.constants import UNIX_DAY
from tests.utils.tokens import mint_for_testing

MAX_SAMPLES = 20
Expand All @@ -15,7 +16,7 @@
class StatefulBase(RuleBasedStateMachine):
exchange_amount_in = strategy("uint256", max_value=10**9 * 10**18)
exchange_i = strategy("uint8", max_value=1)
sleep_time = strategy("uint256", max_value=86400 * 7)
sleep_time = strategy("uint256", max_value=UNIX_DAY * 7)
user = strategy("address")

def __init__(self):
Expand Down
3 changes: 2 additions & 1 deletion tests/unitary/pool/stateful/stateful_base2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from strategies import pool as pool_strategy

from contracts.mocks import ERC20Mock as ERC20
from tests.utils.constants import UNIX_DAY
from tests.utils.tokens import mint_for_testing


Expand Down Expand Up @@ -160,7 +161,7 @@ def remove_liquidity(self, amount, user):
def remove_liquidity_one_coin(self, percentage):
pass

@rule(time_increase=integers(min_value=1, max_value=86400 * 7))
@rule(time_increase=integers(min_value=1, max_value=UNIX_DAY * 7))
def time_forward(self, time_increase):
"""Make the time moves forward by `sleep_time` seconds.
Useful for ramping, oracle updates, etc.
Expand Down
8 changes: 5 additions & 3 deletions tests/unitary/pool/test_a_gamma.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import boa

from tests.utils.constants import UNIX_DAY


def test_A_gamma(swap, params):
A = swap.A()
Expand All @@ -16,7 +18,7 @@ def test_revert_ramp_A_gamma(swap, factory_admin):
future_A = A * 10 # 10 is too large of a jump
future_gamma = gamma // 100
t0 = boa.env.vm.state.timestamp
t1 = t0 + 7 * 86400
t1 = t0 + 7 * UNIX_DAY

with boa.env.prank(factory_admin), boa.reverts():
swap.ramp_A_gamma(future_A, future_gamma, t1)
Expand All @@ -32,13 +34,13 @@ def test_ramp_A_gamma(swap, factory_admin):
future_A = A * 9
future_gamma = gamma // 10
t0 = boa.env.vm.state.timestamp
t1 = t0 + 7 * 86400
t1 = t0 + 7 * UNIX_DAY

with boa.env.prank(factory_admin):
swap.ramp_A_gamma(future_A, future_gamma, t1)

for i in range(1, 8):
boa.env.time_travel(86400)
boa.env.time_travel(UNIX_DAY)
A_gamma = [swap.A(), swap.gamma()]
assert (
abs(
Expand Down
9 changes: 5 additions & 4 deletions tests/unitary/pool/test_oracles.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from tests.fixtures.pool import INITIAL_PRICES
from tests.utils import approx
from tests.utils.constants import UNIX_DAY
from tests.utils.tokens import mint_for_testing

SETTINGS = {"max_examples": 1000, "deadline": None}
Expand Down Expand Up @@ -50,7 +51,7 @@ def test_last_price_remove_liq(swap_with_deposit, user, token_frac, i):
"uint256", min_value=10**10, max_value=2 * 10**6 * 10**18
), # Can be more than we have
i=strategy("uint8", min_value=0, max_value=1),
t=strategy("uint256", min_value=10, max_value=10 * 86400),
t=strategy("uint256", min_value=10, max_value=10 * UNIX_DAY),
)
@settings(**SETTINGS)
def test_ma(swap_with_deposit, coins, user, amount, i, t):
Expand Down Expand Up @@ -89,7 +90,7 @@ def test_ma(swap_with_deposit, coins, user, amount, i, t):
"uint256", min_value=10**10, max_value=2 * 10**6 * 10**18
), # Can be more than we have
i=strategy("uint8", min_value=0, max_value=1),
t=strategy("uint256", min_value=10, max_value=10 * 86400),
t=strategy("uint256", min_value=10, max_value=10 * UNIX_DAY),
)
@settings(**SETTINGS)
def test_xcp_ma(swap_with_deposit, coins, user, amount, i, t):
Expand Down Expand Up @@ -142,7 +143,7 @@ def test_xcp_ma(swap_with_deposit, coins, user, amount, i, t):
"uint256", min_value=10**10, max_value=2 * 10**6 * 10**18
), # Can be more than we have
i=strategy("uint8", min_value=0, max_value=1),
t=strategy("uint256", max_value=10 * 86400),
t=strategy("uint256", max_value=10 * UNIX_DAY),
)
@settings(**SETTINGS)
def test_price_scale_range(swap_with_deposit, coins, user, amount, i, t):
Expand Down Expand Up @@ -172,7 +173,7 @@ def test_price_scale_range(swap_with_deposit, coins, user, amount, i, t):
def test_price_scale_change(swap_with_deposit, i, coins, users):
j = 1 - i
amount = 10**6 * 10**18
t = 86400
t = UNIX_DAY
user = users[1]
prices1 = INITIAL_PRICES
amount = amount * 10**18 // prices1[i]
Expand Down

0 comments on commit 978590e

Please sign in to comment.