From c5712e097cf6dc241e27aacddc47cc56aa79376a Mon Sep 17 00:00:00 2001 From: Daniel Schiavini Date: Wed, 17 Jan 2024 12:42:59 +0100 Subject: [PATCH] Fix difference basic vs plain --- tests/conftest.py | 32 +++++++---- tests/factory/test_factory_basic.py | 60 ++++++++++++++++++++ tests/factory/test_factory_plain.py | 58 ------------------- tests/pools/meta/test_exchange_underlying.py | 2 +- 4 files changed, 83 insertions(+), 69 deletions(-) create mode 100644 tests/factory/test_factory_basic.py delete mode 100644 tests/factory/test_factory_plain.py diff --git a/tests/conftest.py b/tests/conftest.py index 450c6e9a..26d71998 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 @@ -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: @@ -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 diff --git a/tests/factory/test_factory_basic.py b/tests/factory/test_factory_basic.py new file mode 100644 index 00000000..c5a24049 --- /dev/null +++ b/tests/factory/test_factory_basic.py @@ -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) diff --git a/tests/factory/test_factory_plain.py b/tests/factory/test_factory_plain.py deleted file mode 100644 index be4bb690..00000000 --- a/tests/factory/test_factory_plain.py +++ /dev/null @@ -1,58 +0,0 @@ -import boa -import pytest - - -@pytest.mark.parametrize("sending,receiving", [(0, 1), (1, 0)]) -def test_find_pool_for_coins(factory, swap, plain_tokens, sending, receiving): - assert factory.find_pool_for_coins(plain_tokens[sending].address, plain_tokens[receiving].address) == swap.address - - -def test_get_n_coins(factory, swap, plain_tokens, pool_size): - assert factory.get_n_coins(swap.address) == 2 - - -def test_get_coins(factory, swap, plain_tokens, pool_size): - assert factory.get_coins(swap.address) == [pt.address for pt in plain_tokens] - - -def test_get_decimals(factory, swap, decimals): - assert factory.get_decimals(swap.address) == decimals - - -def test_get_balances(factory, swap, pool_size): - assert factory.get_balances(swap.address) == [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, swap): - assert factory.get_A(swap.address) == swap.A() - - -def test_get_fees(factory, swap): - assert factory.get_fees(swap.address) == (swap.fee(), swap.admin_fee()) - - -@pytest.mark.parametrize("sending,receiving", [(0, 1), (1, 0)]) -def test_get_coin_indices(factory, swap, sending, receiving, plain_tokens): - i, j, is_underlying = factory.get_coin_indices( - swap.address, plain_tokens[sending].address, plain_tokens[receiving].address - ) - assert i == sending - assert j == receiving - - -def test_get_implementation_address(factory, swap, amm_implementation): - assert factory.get_implementation_address(swap.address) == amm_implementation.address - - -def test_is_meta(factory, swap): - assert factory.is_meta(swap.address) is False - - -def test_get_pool_types(factory, swap, pool_token_types): - assert factory.get_pool_asset_types(swap.address) == list(pool_token_types) diff --git a/tests/pools/meta/test_exchange_underlying.py b/tests/pools/meta/test_exchange_underlying.py index 2ed2c246..55943bf0 100644 --- a/tests/pools/meta/test_exchange_underlying.py +++ b/tests/pools/meta/test_exchange_underlying.py @@ -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