From 978590e7033113163eb19a91954ef66aab316b3e Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 9 May 2024 12:35:55 +0200 Subject: [PATCH] chore: using `UNIX_DAY` constant --- tests/unitary/pool/admin/test_ramp_A_gamma.py | 6 ++++-- tests/unitary/pool/admin/test_revert_ramp.py | 8 +++++--- tests/unitary/pool/stateful/stateful_base.py | 3 ++- tests/unitary/pool/stateful/stateful_base2.py | 3 ++- tests/unitary/pool/test_a_gamma.py | 8 +++++--- tests/unitary/pool/test_oracles.py | 9 +++++---- 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/tests/unitary/pool/admin/test_ramp_A_gamma.py b/tests/unitary/pool/admin/test_ramp_A_gamma.py index f06126ca..3a0089a4 100644 --- a/tests/unitary/pool/admin/test_ramp_A_gamma.py +++ b/tests/unitary/pool/admin/test_ramp_A_gamma.py @@ -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( @@ -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( diff --git a/tests/unitary/pool/admin/test_revert_ramp.py b/tests/unitary/pool/admin/test_revert_ramp.py index 005a31e5..0fdf9ca4 100644 --- a/tests/unitary/pool/admin/test_revert_ramp.py +++ b/tests/unitary/pool/admin/test_revert_ramp.py @@ -1,5 +1,7 @@ import boa +from tests.utils.constants import UNIX_DAY + def test_revert_unauthorised_ramp(swap, user): @@ -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) @@ -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) @@ -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 diff --git a/tests/unitary/pool/stateful/stateful_base.py b/tests/unitary/pool/stateful/stateful_base.py index 6491d894..7acac4e4 100644 --- a/tests/unitary/pool/stateful/stateful_base.py +++ b/tests/unitary/pool/stateful/stateful_base.py @@ -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 @@ -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): diff --git a/tests/unitary/pool/stateful/stateful_base2.py b/tests/unitary/pool/stateful/stateful_base2.py index 3e5400cb..fcccd438 100644 --- a/tests/unitary/pool/stateful/stateful_base2.py +++ b/tests/unitary/pool/stateful/stateful_base2.py @@ -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 @@ -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. diff --git a/tests/unitary/pool/test_a_gamma.py b/tests/unitary/pool/test_a_gamma.py index 33167a5a..f4643dc4 100644 --- a/tests/unitary/pool/test_a_gamma.py +++ b/tests/unitary/pool/test_a_gamma.py @@ -1,5 +1,7 @@ import boa +from tests.utils.constants import UNIX_DAY + def test_A_gamma(swap, params): A = swap.A() @@ -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) @@ -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( diff --git a/tests/unitary/pool/test_oracles.py b/tests/unitary/pool/test_oracles.py index 80666a0c..672694af 100644 --- a/tests/unitary/pool/test_oracles.py +++ b/tests/unitary/pool/test_oracles.py @@ -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} @@ -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): @@ -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): @@ -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): @@ -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]