Skip to content

Commit

Permalink
Fix difference basic vs plain
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed Jan 17, 2024
1 parent eb344cd commit c5712e0
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 69 deletions.
32 changes: 22 additions & 10 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from itertools import combinations_with_replacement
from random import sample, seed
from random import Random

import boa
import pytest
Expand Down Expand Up @@ -31,17 +31,11 @@ def pytest_generate_tests(metafunc):
)

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")
]

all_combinations = list(combinations_with_replacement(items, 2)) # make all combinations possible
seed(len(metafunc.fixturenames)) # make sure we get the same result in each worker
samples = sorted(sample(all_combinations, k=2)) # take 2 combinations for smaller test set
pool_token_pairs = get_pool_token_pairs(metafunc)
metafunc.parametrize(
"pool_token_types",
[(v1, v2) for (k1, v1), (k2, v2) in samples],
ids=[f"(PoolTokenTypes={k1}+{k2})" for (k1, v1), (k2, v2) in samples],
[(v1, v2) for (k1, v1), (k2, v2) in pool_token_pairs],
ids=[f"(PoolTokenTypes={k1}+{k2})" for (k1, v1), (k2, v2) in pool_token_pairs],
)

if "metapool_token_type" in metafunc.fixturenames:
Expand All @@ -58,6 +52,24 @@ def pytest_generate_tests(metafunc):
metafunc.parametrize("initial_decimals", DECIMAL_PAIRS, ids=[f"(Decimals={i},{j})" for i, j in DECIMAL_PAIRS])


def get_pool_token_pairs(metafunc):
for name, number in TOKEN_TYPES.items():
if metafunc.definition.get_closest_marker(f"only_{name}_tokens"):
return [((name, number), (name, number))]

items = [
(name, number)
for name, number in TOKEN_TYPES.items()
if not metafunc.definition.get_closest_marker(f"skip_{name}_tokens")
]
# make all combinations possible
all_combinations = list(combinations_with_replacement(items, 2))
# make sure we get the same result in each worker
random = Random(len(metafunc.fixturenames))
# take 2 combinations for smaller test set
return sorted(random.sample(all_combinations, k=2))


@pytest.fixture(scope="session")
def pool_size():
return 2
Expand Down
60 changes: 60 additions & 0 deletions tests/factory/test_factory_basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import boa
import pytest


@pytest.mark.parametrize("sending,receiving", [(0, 1), (1, 0)])
def test_find_pool_for_coins(factory, basic_swap, pool_tokens, sending, receiving):
assert (
factory.find_pool_for_coins(pool_tokens[sending].address, pool_tokens[receiving].address) == basic_swap.address
)


def test_get_n_coins(factory, basic_swap, pool_tokens, pool_size):
assert factory.get_n_coins(basic_swap.address) == 2


def test_get_coins(factory, basic_swap, pool_tokens, pool_size):
assert factory.get_coins(basic_swap.address) == [pt.address for pt in pool_tokens]


def test_get_decimals(factory, basic_swap, decimals):
assert factory.get_decimals(basic_swap.address) == decimals


def test_get_balances(factory, basic_swap, pool_size):
assert factory.get_balances(basic_swap.address) == [basic_swap.balances(i) for i in range(pool_size)]


def test_get_underlying_balances(factory, basic_swap):
with boa.reverts() as e:
factory.get_underlying_balances(basic_swap.address)
assert str(e) == "dev: pool is not a metapool"


def test_get_A(factory, basic_swap):
assert factory.get_A(basic_swap.address) == basic_swap.A()


def test_get_fees(factory, basic_swap):
assert factory.get_fees(basic_swap.address) == (basic_swap.fee(), basic_swap.admin_fee())


@pytest.mark.parametrize("sending,receiving", [(0, 1), (1, 0)])
def test_get_coin_indices(factory, basic_swap, sending, receiving, pool_tokens):
i, j, is_underlying = factory.get_coin_indices(
basic_swap.address, pool_tokens[sending].address, pool_tokens[receiving].address
)
assert i == sending
assert j == receiving


def test_get_implementation_address(factory, basic_swap, amm_implementation):
assert factory.get_implementation_address(basic_swap.address) == amm_implementation.address


def test_is_meta(factory, basic_swap):
assert factory.is_meta(basic_swap.address) is False


def test_get_pool_types(factory, basic_swap, pool_token_types):
assert factory.get_pool_asset_types(basic_swap.address) == list(pool_token_types)
58 changes: 0 additions & 58 deletions tests/factory/test_factory_plain.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/pools/meta/test_exchange_underlying.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from tests.utils import approx

pytest.mark.usefixtures("initial_setup")
pytestmark = pytest.mark.usefixtures("initial_setup")


@pytest.mark.skip_oracle_tokens
Expand Down

0 comments on commit c5712e0

Please sign in to comment.