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

feat: integrate teams into market-sim #520

Merged
merged 9 commits into from
Oct 7, 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
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ flake8:

.PHONY: test
test:
@env PYTHONPATH=. pytest -m "not integration" tests/
@env PYTHONPATH=. pytest -m "not integration and not api" tests/

.PHONY: test_api
test_api:
@env PYTHONPATH=. pytest -m api tests/

.PHONY: test_integration
test_integration:
Expand Down
3 changes: 2 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[pytest]
markers =
integration: mark a test as requiring a full vega sim infrastructure with running backend
integration: mark a test as requiring a full vega sim infrastructure with running backend\
api: mark a test as checking vega-market-sim api coverage

log_file_format=%(asctime)s.%(msecs)03d %(threadName)s %(processName)s (%(filename)s:%(funcName)s:%(lineno)s):%(message)s
log_file_date_format=%Y-%m-%d %H:%M:%S
Expand Down
55 changes: 55 additions & 0 deletions tests/integration/test_trading.py
Original file line number Diff line number Diff line change
Expand Up @@ -1714,3 +1714,58 @@ def test_volume_discount_program(vega_service_with_market: VegaServiceNull):
assert discounted_trades[0].buyer_fee.maker_fee_volume_discount != 0
assert discounted_trades[0].buyer_fee.liquidity_fee_volume_discount != 0
assert discounted_trades[0].buyer_fee.infrastructure_fee_volume_discount != 0


@pytest.mark.integration
def test_teams(vega_service_with_market: VegaServiceNull):
vega = vega_service_with_market

# Initialise parties
create_and_faucet_wallet(vega=vega, wallet=PARTY_A)
vega.wait_for_total_catchup()
create_and_faucet_wallet(vega=vega, wallet=PARTY_B)
vega.wait_for_total_catchup()
create_and_faucet_wallet(vega=vega, wallet=PARTY_C)
vega.wait_for_total_catchup()

# Create referral sets, teams from sets, then get team ids
vega.create_referral_set(
key_name=PARTY_A.name,
name="name_a",
team_url="team_url_a",
avatar_url="avatar_url_a",
closed=False,
)
vega.create_referral_set(
key_name=PARTY_B.name,
name="name_b",
team_url="team_url_b",
avatar_url="avatar_url_b",
closed=False,
)
vega.wait_fn((1))
vega.wait_for_total_catchup()
team_a_id = list(vega.list_teams(key_name=PARTY_A.name).keys())[0]
team_b_id = list(vega.list_teams(key_name=PARTY_B.name).keys())[0]

# Apply code and check the party has joined team
vega.apply_referral_code(key_name=PARTY_C.name, id=team_a_id)
next_epoch(vega)
assert len(vega.list_team_referees(team_id=team_a_id)) > 0
assert len(vega.list_team_referees(team_id=team_b_id)) == 0

# Apply code and check the party has moved team
vega.apply_referral_code(key_name=PARTY_C.name, id=team_b_id)
next_epoch(vega)
assert len(vega.list_team_referees(team_id=team_a_id)) == 0
assert len(vega.list_team_referees(team_id=team_b_id)) > 0

# Check the history is consistent
team_referee_history = [
team_referee_history.team_id
for team_referee_history in vega.list_team_referee_history(
key_name=PARTY_C.name
)
]
assert team_a_id in team_referee_history
assert team_b_id in team_referee_history
76 changes: 76 additions & 0 deletions tests/vega_sim/api/test_api_coverage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"""Module contains tests for testing coverage of vega APIs.
"""

import pytest
import re

import vega_sim.proto.data_node.api.v2 as data_node_protos_v2
import vega_sim.proto.vega as vega_protos
import vega_sim.api.data as data
import vega_sim.api.data_raw as data_raw


def camel_to_snake(camel_case):
# Use regular expression to split words at capital letters
words = re.findall("[A-Z][a-z]*", camel_case)
# Join the words with underscores and convert to lowercase
snake_case = "_".join(word.lower() for word in words)
return snake_case


@pytest.mark.api
@pytest.mark.parametrize(
"item_name",
[
item_name
for item_name in dir(vega_protos.vega)
if hasattr(getattr(vega_protos.vega, item_name), "DESCRIPTOR")
and hasattr(getattr(vega_protos.vega, item_name), "SerializeToString")
],
)
def test_vega_protos(item_name):
assert hasattr(data, item_name)


@pytest.mark.api
@pytest.mark.parametrize(
"item_name",
[
item_name
for item_name in dir(vega_protos.events.v1.events)
if hasattr(getattr(vega_protos.events.v1.events, item_name), "DESCRIPTOR")
and hasattr(
getattr(vega_protos.events.v1.events, item_name), "SerializeToString"
)
],
)
def test_events_protos(item_name):
assert hasattr(data, item_name)


@pytest.mark.api
@pytest.mark.parametrize(
"item_name",
[
item_name
for item_name in dir(vega_protos.assets)
if hasattr(getattr(vega_protos.assets, item_name), "DESCRIPTOR")
and hasattr(getattr(vega_protos.assets, item_name), "SerializeToString")
],
)
def test_assets_protos(item_name):
assert hasattr(data, item_name)


@pytest.mark.api
@pytest.mark.parametrize(
"item_name",
[
method.name
for method in data_node_protos_v2.trading_data.DESCRIPTOR.services_by_name[
"TradingDataService"
].methods
],
)
def test_trading_data(item_name):
assert hasattr(data_raw, camel_to_snake(item_name))
Loading
Loading