Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mark tests #1115

Merged
merged 3 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def chain(self) -> LocalChain:

return chain

@pytest.mark.anvil
def _ensure_db_wallet_matches_agent_wallet(
self,
interactive_hyperdrive: InteractiveHyperdrive,
Expand Down Expand Up @@ -86,9 +87,9 @@ def _ensure_db_wallet_matches_agent_wallet(
# Lots of things to test
# pylint: disable=too-many-locals
# pylint: disable=too-many-statements
@pytest.mark.anvil
def test_funding_and_trades(self, chain):
"""Tests interactive hyperdrive end to end"""

# Parameters for pool initialization. If empty, defaults to default values, allows for custom values if needed
initial_pool_config = InteractiveHyperdrive.Config()
# Launches 2 pools on the same local chain
Expand Down Expand Up @@ -189,6 +190,7 @@ def test_funding_and_trades(self, chain):
assert hyperdrive_agent0.wallet.withdraw_shares == FixedPoint(0)
self._ensure_db_wallet_matches_agent_wallet(interactive_hyperdrive, hyperdrive_agent0.wallet)

@pytest.mark.anvil
def test_advance_time(self, chain):
"""Tests interactive hyperdrive end to end"""
# We need the underlying hyperdrive interface here to test time
Expand Down
3 changes: 3 additions & 0 deletions lib/agent0/agent0/hyperdrive/policies/random_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
from typing import TYPE_CHECKING, cast

import pytest
from eth_typing import URI
from ethpy import EthConfig
from fixedpointmath import FixedPoint
Expand All @@ -31,6 +32,7 @@
class TestRandomPolicy:
"""Tests pipeline from bots making trades to viewing the trades in the db"""

@pytest.mark.anvil
def test_random_policy(
self,
local_hyperdrive_pool: DeployedHyperdrivePool,
Expand Down Expand Up @@ -96,6 +98,7 @@ def test_random_policy(
for _ in range(10):
_ = asyncio.run(async_execute_agent_trades(hyperdrive, agent_accounts, liquidate))

@pytest.mark.anvil
def test_random_policy_trades(
self,
local_hyperdrive_pool: DeployedHyperdrivePool,
Expand Down
1 change: 1 addition & 0 deletions lib/agent0/tests/target_rate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from web3 import HTTPProvider


@pytest.mark.anvil
@pytest.mark.parametrize("delta", [-1e5, 1e5])
def test_hit_target_rate(local_hyperdrive_pool: DeployedHyperdrivePool, delta: float):
"""Ensure bot can hit target rate."""
Expand Down
8 changes: 8 additions & 0 deletions lib/chainsync/chainsync/db/base/interface_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def test_drop_table(dummy_session):
class TestAddrToUsernameInterface:
"""Testing postgres interface for usermap table"""

@pytest.mark.docker
def test_get_addr_to_username(self, db_session):
"""Testing retrieval of usernames via interface"""
username_1 = "a"
Expand All @@ -52,6 +53,7 @@ def test_get_addr_to_username(self, db_session):
np.testing.assert_array_equal(user_map_df["username"], ["a", "a", "a", "b", "b", "c"])
np.testing.assert_array_equal(user_map_df["address"], ["1", "2", "3", "4", "5", "6"])

@pytest.mark.docker
def test_get_query_address(self, db_session):
"""Testing querying by address of addr_to_username via interface"""
username_1 = "a"
Expand All @@ -72,6 +74,7 @@ def test_get_query_address(self, db_session):
user_map_df = get_addr_to_username(db_session, address="5")
np.testing.assert_array_equal(user_map_df["username"], ["b"])

@pytest.mark.docker
def test_addr_to_username_insertion_error(self, db_session):
"""Testing insertion conflicts of addr_to_username via interface"""
username_1 = "a"
Expand Down Expand Up @@ -105,6 +108,7 @@ def test_addr_to_username_insertion_error(self, db_session):
np.testing.assert_array_equal(user_map_df["username"], ["a", "a", "a", "a"])
np.testing.assert_array_equal(user_map_df["address"], ["1", "2", "3", "5"])

@pytest.mark.docker
def test_addr_to_username_force_insertion(self, db_session):
"""Testing force insertion of addr_to_username via interface"""
username_1 = "a"
Expand All @@ -128,6 +132,7 @@ def test_addr_to_username_force_insertion(self, db_session):
class TestUserToUsernameInterface:
"""Testing postgres interface for usermap table"""

@pytest.mark.docker
def test_get_user_to_username(self, db_session):
"""Testing retrieval of usernames via interface"""
user_1 = "1"
Expand All @@ -148,6 +153,7 @@ def test_get_user_to_username(self, db_session):
np.testing.assert_array_equal(user_map_df["username"], ["a", "b", "c"])
np.testing.assert_array_equal(user_map_df["user"], ["1", "2", "2"])

@pytest.mark.docker
def test_get_query_username(self, db_session):
"""Testing querying by username of username_to_user via interface"""
user_1 = "1"
Expand All @@ -168,6 +174,7 @@ def test_get_query_username(self, db_session):
user_map_df = get_username_to_user(db_session, username="c")
np.testing.assert_array_equal(user_map_df["user"], ["2"])

@pytest.mark.docker
def test_username_to_user_insertion_error(self, db_session):
"""Testing insertion conflicts of username_to_user via interface"""
user_1 = "1"
Expand Down Expand Up @@ -207,6 +214,7 @@ def test_username_to_user_insertion_error(self, db_session):
np.testing.assert_array_equal(user_map_df["username"], ["a", "b", "c"])
np.testing.assert_array_equal(user_map_df["user"], ["1", "2", "2"])

@pytest.mark.docker
def test_addr_to_username_force_insertion(self, db_session):
"""Testing force insertion of addr_to_username via interface"""
user_1 = "1"
Expand Down
8 changes: 8 additions & 0 deletions lib/chainsync/chainsync/db/base/schema_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
"""CRUD tests for UserMap"""
import pytest

from .schema import AddrToUsername, UsernameToUser


class TestAddrToUsernameTable:
"""CRUD tests for AddrToUsername table"""

@pytest.mark.docker
def test_create_addr_to_username(self, db_session):
"""Create and entry"""
user_map = AddrToUsername(address="1", username="a")
Expand All @@ -15,6 +18,7 @@ def test_create_addr_to_username(self, db_session):
assert retrieved_map is not None
assert retrieved_map.username == "a"

@pytest.mark.docker
def test_update_addr_to_username(self, db_session):
"""Update an entry"""
user_map = AddrToUsername(address="1", username="a")
Expand All @@ -27,6 +31,7 @@ def test_update_addr_to_username(self, db_session):
updated_map = db_session.query(AddrToUsername).filter_by(address="1").first()
assert updated_map.username == "b"

@pytest.mark.docker
def test_delete_addr_to_username(self, db_session):
"""Delete an entry"""
user_map = AddrToUsername(address="1", username="a")
Expand All @@ -43,6 +48,7 @@ def test_delete_addr_to_username(self, db_session):
class TestUsernameToUserTable:
"""CRUD tests for UsernameToUser table"""

@pytest.mark.docker
def test_create_username_to_user(self, db_session):
"""Create and entry"""
user_map = UsernameToUser(username="a", user="1")
Expand All @@ -53,6 +59,7 @@ def test_create_username_to_user(self, db_session):
assert retrieved_map is not None
assert retrieved_map.user == "1"

@pytest.mark.docker
def test_update_username_to_user(self, db_session):
"""Update an entry"""
user_map = UsernameToUser(username="a", user="1")
Expand All @@ -65,6 +72,7 @@ def test_update_username_to_user(self, db_session):
updated_map = db_session.query(UsernameToUser).filter_by(username="a").first()
assert updated_map.user == "2"

@pytest.mark.docker
def test_delete_username_to_user(self, db_session):
"""Delete an entry"""
user_map = UsernameToUser(username="a", user="1")
Expand Down
3 changes: 3 additions & 0 deletions lib/chainsync/chainsync/db/hyperdrive/export_data_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from decimal import Decimal
from tempfile import TemporaryDirectory

import pytest

from .export_data import export_db_to_file, import_to_pandas
from .interface import add_pool_config, get_pool_config
from .schema import PoolConfig
Expand All @@ -11,6 +13,7 @@
class TestExportImportData:
"""Testing export and import data for precision"""

@pytest.mark.docker
def test_export_import(self, db_session):
"""Testing retrieval of transaction via interface"""
# Write data to database
Expand Down
23 changes: 22 additions & 1 deletion lib/chainsync/chainsync/db/hyperdrive/interface_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

import numpy as np
import pytest
from chainsync.db.base import get_latest_block_number_from_table
from ethpy.hyperdrive import BASE_TOKEN_SYMBOL

from chainsync.db.base import get_latest_block_number_from_table

from .interface import (
add_checkpoint_infos,
add_current_wallet,
Expand All @@ -31,6 +32,7 @@
class TestTransactionInterface:
"""Testing postgres interface for transaction table"""

@pytest.mark.docker
def test_latest_block_number(self, db_session):
"""Testing retrieval of transaction via interface"""
transaction_1 = HyperdriveTransaction(block_number=1, transaction_hash="a", event_value=Decimal("3.0"))
Expand All @@ -46,6 +48,7 @@ def test_latest_block_number(self, db_session):
latest_block_number = get_latest_block_number_from_table(HyperdriveTransaction, db_session)
assert latest_block_number == 3

@pytest.mark.docker
def test_get_transactions(self, db_session):
"""Testing retrieval of transactions via interface"""
transaction_1 = HyperdriveTransaction(block_number=0, transaction_hash="a", event_value=Decimal("3.1"))
Expand All @@ -56,6 +59,7 @@ def test_get_transactions(self, db_session):
transactions_df = get_transactions(db_session)
np.testing.assert_array_equal(transactions_df["event_value"], [3.1, 3.2, 3.3])

@pytest.mark.docker
def test_block_query_transactions(self, db_session):
"""Testing querying by block number of transactions via interface"""
transaction_1 = HyperdriveTransaction(block_number=0, transaction_hash="a", event_value=Decimal("3.1"))
Expand All @@ -82,6 +86,7 @@ def test_block_query_transactions(self, db_session):
class TestCheckpointInterface:
"""Testing postgres interface for checkpoint table"""

@pytest.mark.docker
def test_latest_block_number(self, db_session):
"""Testing retrieval of checkpoint via interface"""
checkpoint_1 = CheckpointInfo(block_number=1, timestamp=datetime.now())
Expand All @@ -98,6 +103,7 @@ def test_latest_block_number(self, db_session):
latest_block_number = get_latest_block_number_from_table(CheckpointInfo, db_session)
assert latest_block_number == 3

@pytest.mark.docker
def test_get_checkpoints(self, db_session):
"""Testing retrieval of checkpoints via interface"""
date_1 = datetime(1945, 8, 6)
Expand All @@ -113,6 +119,7 @@ def test_get_checkpoints(self, db_session):
checkpoints_df["timestamp"].dt.to_pydatetime(), np.array([date_1, date_2, date_3])
)

@pytest.mark.docker
def test_block_query_checkpoints(self, db_session):
"""Testing querying by block number of checkpoints via interface"""
checkpoint_1 = CheckpointInfo(block_number=0, timestamp=datetime.now(), share_price=Decimal("3.1"))
Expand All @@ -139,6 +146,7 @@ def test_block_query_checkpoints(self, db_session):
class TestPoolConfigInterface:
"""Testing postgres interface for poolconfig table"""

@pytest.mark.docker
def test_get_pool_config(self, db_session):
"""Testing retrieval of pool config via interface"""
pool_config_1 = PoolConfig(contract_address="0", initial_share_price=Decimal("3.2"))
Expand All @@ -155,6 +163,7 @@ def test_get_pool_config(self, db_session):
assert len(pool_config_df_2) == 2
np.testing.assert_array_equal(pool_config_df_2["initial_share_price"], np.array([3.2, 3.4]))

@pytest.mark.docker
def test_primary_id_query_pool_config(self, db_session):
"""Testing retrieval of pool config via interface"""
pool_config = PoolConfig(contract_address="0", initial_share_price=Decimal("3.2"))
Expand All @@ -167,6 +176,7 @@ def test_primary_id_query_pool_config(self, db_session):
pool_config_df_2 = get_pool_config(db_session, contract_address="1")
assert len(pool_config_df_2) == 0

@pytest.mark.docker
def test_pool_config_verify(self, db_session):
"""Testing retrieval of pool config via interface"""
pool_config_1 = PoolConfig(contract_address="0", initial_share_price=Decimal("3.2"))
Expand All @@ -191,6 +201,7 @@ def test_pool_config_verify(self, db_session):
class TestPoolInfoInterface:
"""Testing postgres interface for poolinfo table"""

@pytest.mark.docker
def test_latest_block_number(self, db_session):
"""Testing latest block number call"""
timestamp_1 = datetime.fromtimestamp(1628472000)
Expand All @@ -209,6 +220,7 @@ def test_latest_block_number(self, db_session):
latest_block_number = get_latest_block_number_from_pool_info_table(db_session)
assert latest_block_number == 3

@pytest.mark.docker
def test_get_pool_info(self, db_session):
"""Testing retrieval of pool info via interface"""
timestamp_1 = datetime.fromtimestamp(1628472000)
Expand All @@ -224,6 +236,7 @@ def test_get_pool_info(self, db_session):
pool_info_df["timestamp"].dt.to_pydatetime(), np.array([timestamp_1, timestamp_2, timestamp_3])
)

@pytest.mark.docker
def test_block_query_pool_info(self, db_session):
"""Testing retrieval of pool info via interface"""
timestamp_1 = datetime.fromtimestamp(1628472000)
Expand Down Expand Up @@ -252,6 +265,7 @@ def test_block_query_pool_info(self, db_session):
class TestWalletDeltaInterface:
"""Testing postgres interface for walletinfo table"""

@pytest.mark.docker
def test_latest_block_number(self, db_session):
"""Testing retrieval of wallet info via interface"""
wallet_delta_1 = WalletDelta(block_number=1, transaction_hash="a", delta=Decimal("3.0"))
Expand All @@ -264,6 +278,7 @@ def test_latest_block_number(self, db_session):
latest_block_number = get_latest_block_number_from_table(WalletDelta, db_session)
assert latest_block_number == 3

@pytest.mark.docker
def test_get_wallet_delta(self, db_session):
"""Testing retrievals of walletinfo via interface"""
wallet_delta_1 = WalletDelta(block_number=0, transaction_hash="a", delta=Decimal("3.1"))
Expand All @@ -275,6 +290,7 @@ def test_get_wallet_delta(self, db_session):
wallet_delta_df = get_wallet_deltas(db_session, return_timestamp=False)
np.testing.assert_array_equal(wallet_delta_df["delta"], np.array([3.1, 3.2, 3.3]))

@pytest.mark.docker
def test_block_query_wallet_delta(self, db_session):
"""Testing querying by block number of wallet info via interface"""
wallet_delta_1 = WalletDelta(block_number=0, transaction_hash="a", delta=Decimal("3.1"))
Expand All @@ -292,6 +308,7 @@ def test_block_query_wallet_delta(self, db_session):
wallet_delta_df = get_wallet_deltas(db_session, start_block=1, end_block=-1, return_timestamp=False)
np.testing.assert_array_equal(wallet_delta_df["delta"], np.array([3.2]))

@pytest.mark.docker
def test_get_agents(self, db_session):
"""Testing helper function to get current wallet values"""
wallet_delta_1 = WalletDelta(block_number=0, transaction_hash="a", wallet_address="addr_1")
Expand All @@ -307,6 +324,7 @@ def test_get_agents(self, db_session):
class TestCurrentWalletInterface:
"""Testing postgres interface for CurrentWallet table"""

@pytest.mark.docker
def test_latest_block_number(self, db_session):
"""Testing retrieval of wallet info via interface"""
wallet_info_1 = CurrentWallet(block_number=1, value=Decimal("3.0"))
Expand All @@ -319,6 +337,7 @@ def test_latest_block_number(self, db_session):
latest_block_number = get_latest_block_number_from_table(CurrentWallet, db_session)
assert latest_block_number == 3

@pytest.mark.docker
def test_get_current_wallet(self, db_session):
"""Testing retrieval of walletinfo via interface"""
wallet_info_1 = CurrentWallet(block_number=0, wallet_address="a", value=Decimal("3.1"))
Expand All @@ -330,6 +349,7 @@ def test_get_current_wallet(self, db_session):
wallet_info_df = wallet_info_df.sort_values(by=["value"])
np.testing.assert_array_equal(wallet_info_df["value"], np.array([3.1, 3.2, 3.3]))

@pytest.mark.docker
def test_block_query_wallet_info(self, db_session):
"""Testing querying by block number of wallet info via interface"""
wallet_info_1 = CurrentWallet(block_number=0, wallet_address="a", value=Decimal("3.1"))
Expand All @@ -343,6 +363,7 @@ def test_block_query_wallet_info(self, db_session):
wallet_info_df = wallet_info_df.sort_values(by=["value"])
np.testing.assert_array_equal(wallet_info_df["value"], np.array([3.1, 3.2]))

@pytest.mark.docker
def test_current_wallet_info(self, db_session):
"""Testing helper function to get current wallet values"""
wallet_info_1 = CurrentWallet(
Expand Down
Loading
Loading