Skip to content

Commit

Permalink
Deployers in session scope + fixture fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed Jan 15, 2024
1 parent 35571d2 commit f2cbfc2
Show file tree
Hide file tree
Showing 15 changed files with 1,191 additions and 1,348 deletions.
24 changes: 13 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- repo: https://github.com/psf/black
rev: 22.3.0
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.12.0
hooks:
- id: black
args: [--line-length=120]
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
args:
- --skip-magic-trailing-comma
- --target-version=py310
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
args: [--max-line-length=120]
- repo: https://github.com/pycqa/isort
rev: 5.12.0
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--profile", "black", --line-length=120]
# profile and line-length to avoid clashes with black
args: ["--profile=black", "--line-length=88"]

default_language_version:
python: python3.10.4
python: python3.10
1,975 changes: 975 additions & 1,000 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ packages = []
[tool.poetry.dependencies]
python = "^3.10"
poetry = "1.5.1"
titanoboa = {git = "https://github.com/vyperlang/titanoboa.git", rev = "03949fe9e3b1c15b8d88dd169b4f5e44fb64fae0"}
titanoboa = {git = "https://github.com/vyperlang/titanoboa.git", rev = "47e95503b90338ad19114239b53326d3fc850eef"}
vyper = "0.3.10"
pycryptodome = "^3.18.0"
pre-commit = "^3.3.3"
Expand Down
24 changes: 7 additions & 17 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import boa
import pytest

from tests.constants import DECIMAL_PAIRS, POOL_TYPES, TOKEN_TYPES

pytest_plugins = [
"tests.fixtures.accounts",
"tests.fixtures.constants",
Expand All @@ -13,11 +15,6 @@
"tests.fixtures.tokens",
]

pool_types = {"basic": 0, "meta": 1}
token_types = {"plain": 0, "oracle": 1, "rebasing": 2}
return_types = {"revert": 0, "False": 1, "None": 2}
decimal_types = [(18, 18), (10, 12)]


@pytest.fixture(scope="session", autouse=True)
def fast_mode():
Expand All @@ -26,17 +23,14 @@ def fast_mode():

def pytest_generate_tests(metafunc):
if "pool_type" in metafunc.fixturenames:
pool_type_items = sorted(pool_types.items())
pool_type_items = sorted(POOL_TYPES.items())
metafunc.parametrize(
"pool_type",
[v for k, v in pool_type_items],
ids=[f"(PoolType={k})" for k, v in pool_type_items],
"pool_type", [v for k, v in pool_type_items], ids=[f"(PoolType={k})" for k, v in pool_type_items]
)

if "pool_token_types" in metafunc.fixturenames:
items = [
(k, v) for k, v in token_types.items()
if not metafunc.definition.get_closest_marker(f"skip_{k}_tokens")
(k, v) for k, v in TOKEN_TYPES.items() if not metafunc.definition.get_closest_marker(f"skip_{k}_tokens")
]
combinations = sorted(itertools.combinations_with_replacement(items, 2))
metafunc.parametrize(
Expand All @@ -47,7 +41,7 @@ def pytest_generate_tests(metafunc):

if "metapool_token_type" in metafunc.fixturenames:
# for meta pool only 1st coin is selected
token_type_items = sorted(token_types.items())
token_type_items = sorted(TOKEN_TYPES.items())
metafunc.parametrize(
"metapool_token_type",
[v for k, v in token_type_items],
Expand All @@ -56,11 +50,7 @@ def pytest_generate_tests(metafunc):

if "initial_decimals" in metafunc.fixturenames:
# this is only used in the decimals fixture
metafunc.parametrize(
"initial_decimals",
decimal_types,
ids=[f"(Decimals={i},{j})" for i, j in decimal_types],
)
metafunc.parametrize("initial_decimals", DECIMAL_PAIRS, ids=[f"(Decimals={i},{j})" for i, j in DECIMAL_PAIRS])


@pytest.fixture(scope="session")
Expand Down
3 changes: 3 additions & 0 deletions tests/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POOL_TYPES = {"basic": 0, "meta": 1}
TOKEN_TYPES = {"plain": 0, "oracle": 1, "rebasing": 2}
DECIMAL_PAIRS = [(18, 18), (10, 12)]
79 changes: 30 additions & 49 deletions tests/factory/test_factory_add_pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,19 @@
@pytest.fixture
def empty_factory(deployer, fee_receiver, owner):
with boa.env.prank(deployer):
_factory = boa.load(
"contracts/main/CurveStableSwapFactoryNG.vy",
fee_receiver,
owner,
)
_factory = boa.load("contracts/main/CurveStableSwapFactoryNG.vy", fee_receiver, owner)
return _factory


@pytest.fixture
def empty_factory_with_implementations(
empty_factory,
owner,
gauge_implementation,
views_implementation,
math_implementation,
amm_implementation,
amm_implementation_meta,
empty_factory,
owner,
gauge_implementation,
views_implementation,
math_implementation,
amm_implementation,
amm_implementation_meta,
):
with boa.env.prank(owner):
empty_factory.set_gauge_implementation(gauge_implementation.address)
Expand All @@ -34,14 +30,7 @@ def empty_factory_with_implementations(
return empty_factory


def test_add_base_pool_already_exists(
owner,
factory,
add_base_pool,
base_pool,
base_pool_lp_token,
base_pool_tokens,
):
def test_add_base_pool_already_exists(owner, factory, add_base_pool, base_pool, base_pool_lp_token, base_pool_tokens):
with boa.reverts():
factory.add_base_pool(
base_pool.address,
Expand All @@ -52,13 +41,7 @@ def test_add_base_pool_already_exists(
)


def test_add_base_pool_only_admin(
factory,
bob,
base_pool,
base_pool_lp_token,
base_pool_tokens,
):
def test_add_base_pool_only_admin(factory, bob, base_pool, base_pool_lp_token, base_pool_tokens):
with boa.reverts():
factory.add_base_pool(
base_pool.address,
Expand All @@ -69,9 +52,7 @@ def test_add_base_pool_only_admin(
)


def test_deploy_plain_pool(
empty_factory_with_implementations, amm_interface, plain_tokens, pool_size, zero_address
):
def test_deploy_plain_pool(empty_factory_with_implementations, amm_deployer, plain_tokens, pool_size, zero_address):
swap_address = empty_factory_with_implementations.deploy_plain_pool(
"test",
"test",
Expand All @@ -87,7 +68,7 @@ def test_deploy_plain_pool(
)
assert swap_address != zero_address

swap = amm_interface.at(swap_address)
swap = amm_deployer.at(swap_address)
assert swap.coins(0) == plain_tokens[0].address
assert swap.coins(1) == plain_tokens[1].address

Expand All @@ -100,27 +81,27 @@ def test_deploy_plain_pool(


def test_pool_count(
empty_factory_with_implementations,
add_base_pool,
amm_interface,
set_pool_implementations,
pool_tokens,
pool_size,
zero_address,
empty_factory_with_implementations,
add_base_pool,
amm_deployer,
set_pool_implementations,
pool_tokens,
pool_size,
zero_address,
):
assert empty_factory_with_implementations.pool_count() == 0

empty_factory_with_implementations.deploy_plain_pool(
"test",
"test",
[t.address for t in pool_tokens],
2000,
1000000,
20000000000,
866,
0,
[0] * pool_size,
[bytes(b"")] * pool_size,
[zero_address] * pool_size,
"test", # name: String[32]
"test", # symbol: String[10]
[t.address for t in pool_tokens], # coins: address[]
2000, # A: uint256
1000000, # fee: uint256
20000000000, # offpeg_fee_multiplier: uint256
866, # ma_exp_time: uint256
0, # implementation_idx: uint256
[0] * pool_size, # asset_types: uint8[]
[bytes(b"")] * pool_size, # method_ids: bytes4[]
[zero_address] * pool_size, # oracles: address[]
)
assert empty_factory_with_implementations.pool_count() == 1
2 changes: 1 addition & 1 deletion tests/factory/test_factory_general.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def test_get_A(factory, swap):
def test_get_A(factory, swap, set_metapool_implementations):
assert factory.get_A(swap.address) == swap.A()


Expand Down
Loading

0 comments on commit f2cbfc2

Please sign in to comment.