Skip to content

Commit

Permalink
Only run fixtures when used
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed Jan 19, 2024
1 parent 07e2bff commit 607b5a2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
3 changes: 2 additions & 1 deletion tests/fixtures/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def pool_tokens(pool_token_types, request):

# <--------------------- Metapool configuration --------------------->
@pytest.fixture()
def metapool_token(metapool_token_type, request):
def metapool_token(metapool_token_type, request, initial_decimals):
assert initial_decimals, "Fixture required for requesting `decimals` downstream"
fixture = {
TOKEN_TYPES["plain"]: "plain_tokens",
TOKEN_TYPES["oracle"]: "oracle_tokens",
Expand Down
40 changes: 25 additions & 15 deletions tests/pools/oracle/test_oracle.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import boa
import pytest

from tests.constants import POOL_TYPES
from tests.constants import POOL_TYPES, TOKEN_TYPES
from tests.fixtures.accounts import add_base_pool_liquidity, mint_account
from tests.fixtures.constants import INITIAL_AMOUNT
from tests.utils.tokens import mint_for_testing
Expand All @@ -15,12 +15,22 @@ def initial_setup_alice(pool_type, request):
Set up the initial state for Alice.
Run either the basic or meta fixture depending on the pool type.
"""
fixture_name = {POOL_TYPES["basic"]: "basic_setup_alice", POOL_TYPES["meta"]: "meta_setup_alice"}[pool_type]
return request.getfixturevalue(fixture_name)
fixtures = {POOL_TYPES["basic"]: "basic_setup_alice", POOL_TYPES["meta"]: "meta_setup_alice"}
return request.getfixturevalue(fixtures[pool_type])


@pytest.fixture()
def basic_setup_alice(alice, initial_amounts, initial_balance, oracle_tokens, basic_swap):
def basic_setup_alice(
alice,
initial_amounts,
initial_balance,
oracle_tokens,
basic_swap,
base_pool_tokens,
base_pool,
base_pool_decimals,
underlying_tokens,
):
mint_for_testing(alice, 1 * 10**18, None, True)
mint_account(alice, oracle_tokens, initial_balance, initial_amounts)
with boa.env.prank(alice):
Expand Down Expand Up @@ -52,22 +62,22 @@ def test_initial_liquidity(
oracle_tokens,
metapool_token,
):
amounts = []

if pool_type == 0:
for i, t in enumerate(pool_token_types):
if t != 1:
amounts.append(DEPOSIT_AMOUNT * 10 ** decimals[i])
else:
amounts.append(DEPOSIT_AMOUNT * 10 ** decimals[i] * 10**18 // oracle_tokens[i].exchangeRate())
amounts = [
DEPOSIT_AMOUNT * 10 ** decimals[i] * 10**18 // oracle_tokens[i].exchangeRate()
if t == TOKEN_TYPES["oracle"]
else DEPOSIT_AMOUNT * 10 ** decimals[i]
for i, t in enumerate(pool_token_types)
]
else:
if metapool_token_type == 1:
amounts = [
amounts = (
[
DEPOSIT_AMOUNT * 10**meta_decimals * 10**18 // metapool_token.exchangeRate(),
DEPOSIT_AMOUNT * 10**18,
]
else:
amounts = [DEPOSIT_AMOUNT * 10**meta_decimals, DEPOSIT_AMOUNT * 10**18]
if metapool_token_type == 1
else [DEPOSIT_AMOUNT * 10**meta_decimals, DEPOSIT_AMOUNT * 10**18]
)

swap.add_liquidity(amounts, 0, sender=alice)
swap.add_liquidity(amounts, 0, sender=alice)
Expand Down

0 comments on commit 607b5a2

Please sign in to comment.