Skip to content

Commit

Permalink
test: fixed broken tests due to boa version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertoCentonze committed Jan 28, 2025
1 parent cea728a commit 01e48b0
Show file tree
Hide file tree
Showing 17 changed files with 165 additions and 213 deletions.
8 changes: 4 additions & 4 deletions tests/fixtures/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@pytest.fixture(scope="module")
def math_contract(deployer):
with boa.env.prank(deployer):
return boa.load("contracts/main/CurveCryptoMathOptimized2.vy")
return boa.load("contracts/main/TwocryptoMath.vy")


@pytest.fixture(scope="module")
Expand All @@ -21,7 +21,7 @@ def gauge_implementation(deployer, gauge_interface):

@pytest.fixture(scope="module")
def amm_interface():
return boa.load_partial("contracts/main/CurveTwocryptoOptimized.vy")
return boa.load_partial("contracts/main/Twocrypto.vy")


@pytest.fixture(scope="module")
Expand All @@ -33,7 +33,7 @@ def amm_implementation(deployer, amm_interface):
@pytest.fixture(scope="module")
def views_contract(deployer):
with boa.env.prank(deployer):
return boa.load("contracts/main/CurveCryptoViews2Optimized.vy")
return boa.load("contracts/main/TwocryptoView.vy")


@pytest.fixture(scope="module")
Expand All @@ -47,7 +47,7 @@ def factory(
views_contract,
):
with boa.env.prank(deployer):
factory = boa.load("contracts/main/CurveTwocryptoFactory.vy")
factory = boa.load("contracts/main/TwocryptoFactory.vy")
factory.initialise_ownership(fee_receiver, owner)

with boa.env.prank(owner):
Expand Down
4 changes: 2 additions & 2 deletions tests/unitary/factory/test_deploy_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def empty_factory(deployer, fee_receiver, owner):
with boa.env.prank(deployer):
factory = boa.load(
"contracts/main/CurveTwocryptoFactory.vy",
"contracts/main/TwocryptoFactory.vy",
)

assert factory.admin() == ZERO_ADDRESS
Expand All @@ -31,7 +31,7 @@ def test_deployer_cannot_set_ownership_twice(empty_factory, deployer):
def test_nondeployer_cannot_set_ownership(deployer):
with boa.env.prank(deployer):
factory = boa.load(
"contracts/main/CurveTwocryptoFactory.vy",
"contracts/main/TwocryptoFactory.vy",
)

with boa.env.prank(boa.env.generate_address()), boa.reverts():
Expand Down
2 changes: 1 addition & 1 deletion tests/unitary/math/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@pytest.fixture(scope="module")
def math_optimized(deployer):
with boa.env.prank(deployer):
return boa.load("contracts/main/CurveCryptoMathOptimized2.vy")
return boa.load("contracts/main/TwocryptoMath.vy")


@pytest.fixture(scope="module")
Expand Down
33 changes: 17 additions & 16 deletions tests/unitary/math/contracts/newton_y_exposed.vy
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pragma version ~=0.4.0
# Minimized version of the math contracts that expose some inner details of newton_y for testing purposes:
# - Additionally to the final value it also returns the number of iterations it took to find the value.
# From commit: 6dec22f6956cc04fb865d93c1e521f146e066cab
Expand All @@ -8,7 +9,7 @@ A_MULTIPLIER: constant(uint256) = 10000
MIN_GAMMA: constant(uint256) = 10**10
MAX_GAMMA: constant(uint256) = 3 * 10**17

MIN_A: constant(uint256) = N_COINS**N_COINS * A_MULTIPLIER / 10
MIN_A: constant(uint256) = N_COINS**N_COINS * A_MULTIPLIER // 10
MAX_A: constant(uint256) = N_COINS**N_COINS * A_MULTIPLIER * 1000

@internal
Expand All @@ -21,17 +22,17 @@ def _newton_y(ANN: uint256, gamma: uint256, x: uint256[N_COINS], D: uint256, i:
"""

x_j: uint256 = x[1 - i]
y: uint256 = D**2 / (x_j * N_COINS**2)
K0_i: uint256 = (10**18 * N_COINS) * x_j / D
y: uint256 = D**2 // (x_j * N_COINS**2)
K0_i: uint256 = (10**18 * N_COINS) * x_j // D

assert (K0_i >= unsafe_div(10**36, lim_mul)) and (K0_i <= lim_mul) # dev: unsafe values x[i]

convergence_limit: uint256 = max(max(x_j / 10**14, D / 10**14), 100)
convergence_limit: uint256 = max(max(x_j // 10**14, D // 10**14), 100)

for j in range(255):
for j: uint256 in range(255):
y_prev: uint256 = y

K0: uint256 = K0_i * y * N_COINS / D
K0: uint256 = K0_i * y * N_COINS // D
S: uint256 = x_j + y

_g1k0: uint256 = gamma + 10**18
Expand All @@ -41,28 +42,28 @@ def _newton_y(ANN: uint256, gamma: uint256, x: uint256[N_COINS], D: uint256, i:
_g1k0 = K0 - _g1k0 + 1

# D / (A * N**N) * _g1k0**2 / gamma**2
mul1: uint256 = 10**18 * D / gamma * _g1k0 / gamma * _g1k0 * A_MULTIPLIER / ANN
mul1: uint256 = 10**18 * D // gamma * _g1k0 // gamma * _g1k0 * A_MULTIPLIER // ANN

# 2*K0 / _g1k0
mul2: uint256 = 10**18 + (2 * 10**18) * K0 / _g1k0
mul2: uint256 = 10**18 + (2 * 10**18) * K0 // _g1k0

yfprime: uint256 = 10**18 * y + S * mul2 + mul1
_dyfprime: uint256 = D * mul2
if yfprime < _dyfprime:
y = y_prev / 2
y = y_prev // 2
continue
else:
yfprime -= _dyfprime
fprime: uint256 = yfprime / y
fprime: uint256 = yfprime // y

# y -= f / f_prime; y = (y * fprime - f) / fprime
# y -= f // f_prime; y = (y * fprime - f) // fprime
# y = (yfprime + 10**18 * D - 10**18 * S) // fprime + mul1 // fprime * (10**18 - K0) // K0
y_minus: uint256 = mul1 / fprime
y_plus: uint256 = (yfprime + 10**18 * D) / fprime + y_minus * 10**18 / K0
y_minus += 10**18 * S / fprime
y_minus: uint256 = mul1 // fprime
y_plus: uint256 = (yfprime + 10**18 * D) // fprime + y_minus * 10**18 // K0
y_minus += 10**18 * S // fprime

if y_plus < y_minus:
y = y_prev / 2
y = y_prev // 2
else:
y = y_plus - y_minus

Expand All @@ -72,7 +73,7 @@ def _newton_y(ANN: uint256, gamma: uint256, x: uint256[N_COINS], D: uint256, i:
else:
diff = y_prev - y

if diff < max(convergence_limit, y / 10**14):
if diff < max(convergence_limit, y // 10**14):
return y, j

raise "Did not converge"
14 changes: 7 additions & 7 deletions tests/unitary/math/test_get_p.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ def get_p(
assert _D > 10**17 - 1 and _D < 10**15 * 10**18 + 1 # dev: unsafe D values
K0: uint256 = 4 * _xp[0] * _xp[1] / _D * 10**36 / _D
K0: uint256 = 4 * _xp[0] * _xp[1] // _D * 10**36 // _D
GK0: uint256 = (
2 * K0 * K0 / 10**36 * K0 / 10**36
2 * K0 * K0 // 10**36 * K0 // 10**36
+ (_A_gamma[1] + 10**18)**2
- K0**2 / 10**36 * (2 * _A_gamma[1] + 3 * 10**18) / 10**18
- K0**2 // 10**36 * (2 * _A_gamma[1] + 3 * 10**18) // 10**18
)
NNAG2: uint256 = _A_gamma[0] * _A_gamma[1]**2 / A_MULTIPLIER
denominator: uint256 = GK0 + NNAG2 * _xp[0] / _D * K0 / 10**36
numerator: uint256 = _xp[0] * ( GK0 + NNAG2 * _xp[1] / _D * K0 / 10**36 ) / _xp[1]
return numerator * 10**18 / denominator
NNAG2: uint256 = _A_gamma[0] * _A_gamma[1]**2 // A_MULTIPLIER
denominator: uint256 = GK0 + NNAG2 * _xp[0] // _D * K0 // 10**36
numerator: uint256 = _xp[0] * ( GK0 + NNAG2 * _xp[1] // _D * K0 // 10**36 ) // _xp[1]
return numerator * 10**18 // denominator
"""
return boa.loads(get_price_impl)

Expand Down
2 changes: 1 addition & 1 deletion tests/unitary/math/test_get_y.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def calculate_F_by_y0(y0):
except Exception as e:
event("hit unsafe for unoptimizied")
if "unsafe value" in str(e):
assert "gamma" not in str(e)
assert "unsafe value for gamma" not in str(e)
assert gamma > 2 * 10**16
return
else: # Did not converge?
Expand Down
12 changes: 6 additions & 6 deletions tests/unitary/pool/admin/test_revert_commit_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def test_commit_incorrect_fee_params(swap, factory_admin, params):
p["mid_fee"] = params["mid_fee"]
p["out_fee"] = 10**10 + 1 # <-- MAX_FEE
_apply_new_params(swap, p)
logs = swap.get_logs()[0]
assert logs.args[1] == params["out_fee"]
log = swap.get_logs()[0]
assert log.out_fee == params["out_fee"]


def test_commit_incorrect_fee_gamma(swap, factory_admin, params):
Expand All @@ -45,7 +45,7 @@ def test_commit_incorrect_fee_gamma(swap, factory_admin, params):
_apply_new_params(swap, p)

# it will not change fee_gamma as it is above 10**18
assert swap.get_logs()[0].args[2] == params["fee_gamma"]
assert swap.get_logs()[0].fee_gamma == params["fee_gamma"]


def test_commit_rebalancing_params(swap, factory_admin, params):
Expand All @@ -60,9 +60,9 @@ def test_commit_rebalancing_params(swap, factory_admin, params):
logs = swap.get_logs()[0]

# values revert to contract's storage values:
assert logs.args[3] == params["allowed_extra_profit"]
assert logs.args[4] == params["adjustment_step"]
assert logs.args[5] == params["ma_time"]
assert logs.allowed_extra_profit == params["allowed_extra_profit"]
assert logs.adjustment_step == params["adjustment_step"]
assert logs.ma_time == params["ma_time"]

with boa.reverts("MA time should be longer than 60/ln(2)"):
p["ma_time"] = 86
Expand Down
2 changes: 1 addition & 1 deletion tests/unitary/pool/stateful/stateful_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
from hypothesis.strategies import integers

from contracts.main import CurveTwocryptoFactory as factory
from contracts.main import TwocryptoFactory as factory
from contracts.mocks import ERC20Mock as ERC20
from tests.utils.constants import UNIX_DAY
from tests.utils.strategies import address, pool_from_preset
Expand Down
2 changes: 1 addition & 1 deletion tests/unitary/pool/test_deposit_withdraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def test_immediate_withdraw_one(

logs = swap_with_deposit.get_logs()
for log in logs:
if log.event_type.name == "ClaimAdminFee":
if type(log).__name__ == "ClaimAdminFee":
claimed_fees = log.args[0]

except Exception:
Expand Down
55 changes: 0 additions & 55 deletions tests/unitary/pool/token/conftest.py

This file was deleted.

8 changes: 4 additions & 4 deletions tests/unitary/pool/token/test_approve.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def test_approval_event_fires(swap, alice, bob):
logs = swap.get_logs()

assert len(logs) == 1
assert logs[0].event_type.name == "Approval"
assert logs[0].topics[0].lower() == alice.lower()
assert logs[0].topics[1].lower() == bob.lower()
assert logs[0].args[0] == 10**19
assert type(logs[0]).__name__ == "Approval"
assert logs[0].owner.lower() == alice.lower()
assert logs[0].spender.lower() == bob.lower()
assert logs[0].value == 10**19


def test_infinite_approval(swap, alice, bob):
Expand Down
90 changes: 0 additions & 90 deletions tests/unitary/pool/token/test_permit.py

This file was deleted.

Loading

0 comments on commit 01e48b0

Please sign in to comment.