Skip to content

Commit

Permalink
More test optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed Nov 25, 2024
1 parent 27ce5ff commit 31a0fcf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
26 changes: 10 additions & 16 deletions tests/test_clmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
from tradingstrategy.transport.cache import APIError


def test_load_clmm_two_pairs_mixed_exchange(persistent_test_client: Client):
def test_load_clmm_two_pairs_mixed_exchange(
persistent_test_client: Client,
default_pair_universe,
):
"""Load CLMM data for two pairs on Uniswap v3."""

client = persistent_test_client
Expand All @@ -23,13 +26,7 @@ def test_load_clmm_two_pairs_mixed_exchange(persistent_test_client: Client):
for p in Path(client.transport.cache_path).glob("clmm-*"):
p.unlink()

exchange_universe = client.fetch_exchange_universe()
pairs_df = client.fetch_pair_universe().to_pandas()

pair_universe = PandasPairUniverse(
pairs_df,
exchange_universe=exchange_universe,
)
pair_universe = default_pair_universe

pair = pair_universe.get_pair_by_human_description(
(ChainId.ethereum, "uniswap-v3", "WETH", "USDC", 0.0005)
Expand Down Expand Up @@ -71,18 +68,15 @@ def test_load_clmm_two_pairs_mixed_exchange(persistent_test_client: Client):
assert clmm_df.attrs["path"] is not None


def test_load_clmm_bad_pair(persistent_test_client: Client):
def test_load_clmm_bad_pair(
persistent_test_client: Client,
default_pair_universe,
):
"""Attempt load CLMM data for Uniswap v2 pair."""

client = persistent_test_client

exchange_universe = client.fetch_exchange_universe()
pairs_df = client.fetch_pair_universe().to_pandas()

pair_universe = PandasPairUniverse(
pairs_df,
exchange_universe=exchange_universe,
)
pair_universe = default_pair_universe

pair = pair_universe.get_pair_by_human_description(
(ChainId.ethereum, "uniswap-v2", "WETH", "USDC")
Expand Down
5 changes: 2 additions & 3 deletions tests/test_resampled_liquidity_universe.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
from tradingstrategy.timebucket import TimeBucket


def test_resampled_liquidity_universe(persistent_test_client: Client):
def test_resampled_liquidity_universe(persistent_test_client: Client, default_pair_universe):
"""Group downloaded liquidity sample data by a trading pair."""

client = persistent_test_client

exchange_universe = client.fetch_exchange_universe()
raw_pairs = client.fetch_pair_universe().to_pandas()
# Do some test calculations for a single pair
sushi_swap = exchange_universe.get_by_chain_and_name(ChainId.ethereum, "sushi")
pair_universe = PandasPairUniverse(raw_pairs, build_index=False)
pair_universe =default_pair_universe
sushi_usdt = pair_universe.get_one_pair_from_pandas_universe(sushi_swap.exchange_id, "SUSHI", "USDT")

raw_liquidity_samples = client.fetch_all_liquidity_samples(TimeBucket.d7).to_pandas()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_top_pairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_token_tax(persistent_test_client: Client):
assert 0 < (pair.get_sell_tax() or 0) < 5, f"Pair lacks tax data: {pair}"


def test_token_tax(persistent_test_client: Client):
def test_token_tax(persistent_test_client: Client, default_pairs_df):
"""Load token tax data in load_extra_metadata()."""

client = persistent_test_client
Expand All @@ -129,7 +129,7 @@ def test_token_tax(persistent_test_client: Client):
addresses = list(map(str.lower, addresses))

# Get all pairs data and filter to our subset
pairs_df = client.fetch_pair_universe().to_pandas()
pairs_df = default_pairs_df
pairs_df = add_base_quote_address_columns(pairs_df)
pairs_df = pairs_df.loc[
(pairs_df["base_token_address"].isin(addresses)) &
Expand Down

0 comments on commit 31a0fcf

Please sign in to comment.