diff --git a/apps/trading/e2e/README.md b/apps/trading/e2e/README.md index 765e232a6..f91d384da 100644 --- a/apps/trading/e2e/README.md +++ b/apps/trading/e2e/README.md @@ -81,7 +81,7 @@ To ensure proper cleanup of containers after each test, use the following fixtur @pytest.fixture def vega(request): with init_vega(request) as vega_instance: - request.addfinalizer(lambda: cleanup_container(vega_instance)) + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) yield vega_instance ``` diff --git a/apps/trading/e2e/conftest.py b/apps/trading/e2e/conftest.py index 520d5d484..e5a97bcf9 100644 --- a/apps/trading/e2e/conftest.py +++ b/apps/trading/e2e/conftest.py @@ -67,23 +67,10 @@ class CustomHttpRequestHandler(http.server.SimpleHTTPRequestHandler): @contextmanager def init_vega(request=None): local_server = os.getenv("LOCAL_SERVER", "false").lower() == "true" - port_config = None - if local_server: - port_config = { - Ports.DATA_NODE_REST: 8001, - } - default_seconds = 1 - seconds_per_block = default_seconds - if request and hasattr(request, "param"): - seconds_per_block = request.param - - logger.info( - "Starting VegaServiceNull", - extra={"worker_id": os.environ.get("PYTEST_XDIST_WORKER")}, - ) - logger.info(f"Using console image: {console_image_name}") - logger.info(f"Using vega version: {vega_version}") + port_config = {"Ports.DATA_NODE_REST": 8001} if local_server else None + seconds_per_block = request.param if request and hasattr(request, "param") else 1 + logger.info("Starting VegaServiceNull", extra={"worker_id": os.getenv("PYTEST_XDIST_WORKER", "default")}) vega_service_args = { "run_with_console": False, "launch_graphql": False, @@ -93,38 +80,28 @@ def init_vega(request=None): "transactions_per_block": 1000, "seconds_per_block": seconds_per_block, "genesis_time": datetime.now() - timedelta(days=1), + "port_config": port_config, } - if port_config is not None: - vega_service_args["port_config"] = port_config - with VegaServiceNull(**vega_service_args) as vega: + container = None try: - container = docker_client.containers.run( - console_image_name, detach=True, ports={"80/tcp": vega.console_port} - ) - - if not isinstance(container, Container): - raise Exception("container instance invalid") - - logger.info( - f"Container {container.id} started", - extra={"worker_id": os.environ.get("PYTEST_XDIST_WORKER")}, - ) + container = docker_client.containers.run(console_image_name, detach=True, ports={"80/tcp": vega.console_port}) + module_file_name = request.module.__file__ if request and hasattr(request, 'module') else "Unknown Module" + test_name = request.node.name if request and hasattr(request, 'node') else "Unknown Test" + logger.info(f"Container {container.id}, {container.name} started for VegaService. Module File Name: {module_file_name}, Test Name: {test_name}", extra={"worker_id": os.getenv("PYTEST_XDIST_WORKER", "default")}) vega.container = container - logger.info(f"Container ID: {container.id}, Name: {container.name}, Status: {container.status}") yield vega - except APIError as e: - logger.info(f"Container creation failed.") - logger.info(e) - raise e finally: - logger.info(f"Stopping container {container.id}") - container.stop() - logger.info(f"Container ID: {container.id}, Name: {container.name}, Status: {container.status}") - logger.info(f"Removing container {container.id}") - container.remove() - logger.info(f"Container ID: {container.id}, Name: {container.name}, Status: {container.status}") + if container: + try: + logger.info(f"Stopping and removing container {container.id}") + container.stop() + container.wait() + container.remove() + logger.info(f"Container {container.id} has been removed") + except Exception as e: + logger.error(f"Error during container cleanup: {e}") @contextmanager @@ -182,35 +159,36 @@ def init_page(vega: VegaServiceNull, browser: Browser, request: pytest.FixtureRe @pytest.fixture def vega(request): with init_vega(request) as vega_instance: - request.addfinalizer(lambda: cleanup_container(vega_instance)) + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) yield vega_instance -def cleanup_container(vega_instance): - # Ensure there is a list of containers to work with - if hasattr(vega_instance, 'containers') and vega_instance.containers: - for container in vega_instance.containers: - try: - # Check if each container is still running and then stop it - if container.status == 'running': - print(f"Stopping container {container.id}") - container.stop() - else: - print(f"Container {container.id} is not running.") - except docker.errors.NotFound: - print(f"Container {container.id} not found, may have been stopped and removed.") - except Exception as e: - print(f"Error during cleanup for container {container.id}: {str(e)}") +def cleanup_container(vega_instance:VegaServiceNull, request=None): + try: + vega_instance.stop() + except Exception as e: + logger.info(f"Unable to stop vega_instance in cleanup_container.{e}") + if not hasattr(vega_instance, 'containers') or not vega_instance.containers: + print(f"No containers to cleanup.") + return + + module_file_name = request.module.__file__ if request and hasattr(request, 'module') else "Unknown Module" + test_name = request.node.name if request and hasattr(request, 'node') else "Unknown Test" + container_count = len(vega_instance.containers) + logger.info(f"Starting cleanup for {container_count} containers for test {test_name} in {module_file_name}") + + for container in vega_instance.containers: + try: + if container.status == 'running': + logger.info(f"Stopping container {container.id} ({container.name})") + container.stop() + container.wait() + container.remove() + logger.info(f"Container {container.id} ({container.name}) removed.") + except docker.errors.NotFound: + logger.info(f"Container {container.id} not found, may have been stopped and removed.") + except Exception as e: + logger.error(f"Error during cleanup for container {container.id} ({container.name}): {e}") - try: - # Attempt to remove the container after stopping it - container.remove() - print(f"Container {container.id} removed.") - except docker.errors.NotFound: - print(f"Container {container.id} not found, may have been removed.") - except Exception as e: - print(f"Error during container removal for container {container.id}: {str(e)}") - else: - print("No containers to cleanup.") @pytest.fixture @@ -326,17 +304,21 @@ def perps_market(vega, request): kwargs.update(request.param) return setup_perps_market(vega, **kwargs) +@pytest.fixture(scope="session", autouse=True) +def cleanup_all_containers(request): + yield + logger.info("test run complete") + # The code after 'yield' runs after all tests are done. + client = docker.from_env() -@pytest.fixture(autouse=True) -def retry_on_http_error(request): - retry_count = 3 - for i in range(retry_count): - try: - yield - return - except requests.exceptions.HTTPError: - if i < retry_count - 1: - print(f"Retrying due to HTTPError (attempt {i+1}/{retry_count})") - else: - raise + def remove_all_containers(): + for container in client.containers.list(all=True): + logger.info(f"Stopping and removing container {container.id}, {container.name}...") + try: + container.stop() + container.remove() + logger.info(f"Container {container.id}, {container.name} successfully removed.") + except Exception as e: + logger.info(f"Error removing container {container.id}: {e}") + request.addfinalizer(remove_all_containers) \ No newline at end of file diff --git a/apps/trading/e2e/tests/deal_ticket/test_basic.py b/apps/trading/e2e/tests/deal_ticket/test_basic.py index 0a97dff71..dbaf71868 100644 --- a/apps/trading/e2e/tests/deal_ticket/test_basic.py +++ b/apps/trading/e2e/tests/deal_ticket/test_basic.py @@ -18,7 +18,7 @@ expire = "expire" @pytest.fixture(scope="module") def vega(request): with init_vega(request) as vega_instance: - request.addfinalizer(lambda: cleanup_container(vega_instance)) # Register the cleanup function + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) yield vega_instance diff --git a/apps/trading/e2e/tests/deal_ticket/test_stop_order.py b/apps/trading/e2e/tests/deal_ticket/test_stop_order.py index 6ae055806..4c81fbeea 100644 --- a/apps/trading/e2e/tests/deal_ticket/test_stop_order.py +++ b/apps/trading/e2e/tests/deal_ticket/test_stop_order.py @@ -261,7 +261,7 @@ class TestStopOcoValidation: @pytest.fixture(scope="class") def vega(request): with init_vega(request) as vega_instance: - request.addfinalizer(lambda: cleanup_container(vega_instance)) # Register the cleanup function + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) yield vega_instance @pytest.fixture(scope="class") diff --git a/apps/trading/e2e/tests/deal_ticket/test_trading_deal_ticket_submit_account.py b/apps/trading/e2e/tests/deal_ticket/test_trading_deal_ticket_submit_account.py index ba296b671..85f4b8bcc 100644 --- a/apps/trading/e2e/tests/deal_ticket/test_trading_deal_ticket_submit_account.py +++ b/apps/trading/e2e/tests/deal_ticket/test_trading_deal_ticket_submit_account.py @@ -15,7 +15,7 @@ deal_ticket_deposit_dialog_button = "deal-ticket-deposit-dialog-button" @pytest.fixture(scope="module") def vega(request): with init_vega(request) as vega_instance: - request.addfinalizer(lambda: cleanup_container(vega_instance)) + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) yield vega_instance diff --git a/apps/trading/e2e/tests/fees/test_fees_combo_tier_2.py b/apps/trading/e2e/tests/fees/test_fees_combo_tier_2.py index dd7f3e1a2..54c4ece87 100644 --- a/apps/trading/e2e/tests/fees/test_fees_combo_tier_2.py +++ b/apps/trading/e2e/tests/fees/test_fees_combo_tier_2.py @@ -1,4 +1,5 @@ import pytest +import threading from fees_test_ids import * from playwright.sync_api import Page, expect from vega_sim.null_service import VegaServiceNull @@ -14,79 +15,81 @@ from conftest import ( from actions.utils import next_epoch, change_keys, forward_time from fixtures.market import setup_continuous_market - @pytest.fixture(scope="module") -def vega(request): +def setup_environment(request, browser): + # Initialize Vega with cleanup with init_vega(request) as vega_instance: - request.addfinalizer( - lambda: cleanup_container(vega_instance) + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) + + # Setup the market with volume and referral discount programs + market = setup_continuous_market(vega_instance, custom_quantum=100000) + vega_instance.update_volume_discount_program( + proposal_key=MM_WALLET.name, + benefit_tiers=[ + {"minimum_running_notional_taker_volume": 100, "volume_discount_factor": 0.1}, + {"minimum_running_notional_taker_volume": 200, "volume_discount_factor": 0.2}, + ], + window_length=7, ) - yield vega_instance + next_epoch(vega_instance) + + vega_instance.update_referral_program( + proposal_key=MM_WALLET.name, + benefit_tiers=[ + { + "minimum_running_notional_taker_volume": 100, + "minimum_epochs": 1, + "referral_reward_factor": 0.1, + "referral_discount_factor": 0.1, + }, + { + "minimum_running_notional_taker_volume": 200, + "minimum_epochs": 2, + "referral_reward_factor": 0.2, + "referral_discount_factor": 0.2, + }, + ], + staking_tiers=[ + {"minimum_staked_tokens": 100, "referral_reward_multiplier": 1.1}, + {"minimum_staked_tokens": 200, "referral_reward_multiplier": 1.2}, + ], + window_length=1, + ) + vega_instance.create_referral_set(key_name=MM_WALLET.name) + next_epoch(vega_instance) + referral_set_id = list(vega_instance.list_referral_sets().keys())[0] + vega_instance.apply_referral_code(key_name="Key 1", id=referral_set_id) + next_epoch(vega_instance) + + for _ in range(2): + submit_order(vega_instance, "Key 1", market, "SIDE_BUY", 2, 110) + forward_time(vega_instance, True if _ < 2 - 1 else False) -@pytest.fixture(scope="module") -def page(vega, browser, request): - with init_page(vega, browser, request) as page: - risk_accepted_setup(page) - auth_setup(vega, page) - yield page + def list_non_daemonic_threads(): + # Get the current list of all active threads + current_threads = threading.enumerate() + # Filter and list non-daemonic threads + non_daemonic_threads = [t for t in current_threads if not t.daemon] -@pytest.fixture(scope="module", autouse=True) -def setup_combined_market(vega: VegaServiceNull): - market = setup_continuous_market(vega, custom_quantum=100000) - vega.update_volume_discount_program( - proposal_key=MM_WALLET.name, - benefit_tiers=[ - { - "minimum_running_notional_taker_volume": 100, - "volume_discount_factor": 0.1, - }, - { - "minimum_running_notional_taker_volume": 200, - "volume_discount_factor": 0.2, - }, - ], - window_length=7, - ) - next_epoch(vega=vega) + print("Non-Daemonic Threads:") + for thread in non_daemonic_threads: + print(f"{thread.name} (ID: {thread.ident})") - vega.update_referral_program( - proposal_key=MM_WALLET.name, - benefit_tiers=[ - { - "minimum_running_notional_taker_volume": 100, - "minimum_epochs": 1, - "referral_reward_factor": 0.1, - "referral_discount_factor": 0.1, - }, - { - "minimum_running_notional_taker_volume": 200, - "minimum_epochs": 2, - "referral_reward_factor": 0.2, - "referral_discount_factor": 0.2, - }, - ], - staking_tiers=[ - {"minimum_staked_tokens": 100, "referral_reward_multiplier": 1.1}, - {"minimum_staked_tokens": 200, "referral_reward_multiplier": 1.2}, - ], - window_length=1, - ) - vega.create_referral_set(key_name=MM_WALLET.name) - next_epoch(vega=vega) - referral_set_id = list(vega.list_referral_sets().keys())[0] - vega.apply_referral_code(key_name="Key 1", id=referral_set_id) - next_epoch(vega=vega) + # Example usage + list_non_daemonic_threads() - for _ in range(2): - submit_order(vega, "Key 1", market, "SIDE_BUY", 2, 110) - forward_time(vega, True if _ < 2 - 1 else False) - return market + # Initialize page and setup + with init_page(vega_instance, browser, request) as page_instance: + risk_accepted_setup(page_instance) + auth_setup(vega_instance, page_instance) + yield vega_instance, market, page_instance @pytest.mark.xdist_group(name="test_fees_combo_tier_2") -def test_fees_page_discount_program_my_trading_fees(page: Page): +def test_fees_page_discount_program_my_trading_fees(setup_environment): + vega, market, page = setup_environment page.goto("/#/fees") expect(page.get_by_test_id(ADJUSTED_FEES)).to_have_text("6.432%-6.432%") expect(page.get_by_test_id(TOTAL_FEE_BEFORE_DISCOUNT)).to_have_text( @@ -99,8 +102,9 @@ def test_fees_page_discount_program_my_trading_fees(page: Page): @pytest.mark.xdist_group(name="test_fees_combo_tier_2") def test_fees_page_discount_program_total_discount( - page: Page, + setup_environment, ): + vega, market, page = setup_environment page.goto("/#/fees") expect(page.get_by_test_id(TOTAL_DISCOUNT)).to_have_text("36%") expect(page.get_by_test_id(VOLUME_DISCOUNT_ROW)).to_have_text("Volume discount20%") @@ -114,7 +118,8 @@ def test_fees_page_discount_program_total_discount( @pytest.mark.xdist_group(name="test_fees_combo_tier_2") -def test_fees_page_discount_program_fees_by_market(page: Page): +def test_fees_page_discount_program_fees_by_market(setup_environment): + vega, market, page = setup_environment page.goto("/#/fees") pinned = page.locator(PINNED_ROW_LOCATOR) row = page.locator(ROW_LOCATOR) @@ -128,10 +133,10 @@ def test_fees_page_discount_program_fees_by_market(page: Page): @pytest.mark.xdist_group(name="test_fees_combo_tier_2") def test_deal_ticket_discount_program( - page: Page, - setup_combined_market, + setup_environment ): - page.goto(f"/#/markets/{setup_combined_market}") + vega, market, page = setup_environment + page.goto(f"/#/markets/{market}") page.get_by_test_id(ORDER_SIZE).fill("1") page.get_by_test_id(ORDER_PRICE).fill("1") expect(page.get_by_test_id(DISCOUNT_PILL)).to_have_text("-36%") @@ -152,10 +157,10 @@ def test_deal_ticket_discount_program( @pytest.mark.xdist_group(name="test_fees_combo_tier_2") def test_fills_taker_discount_program( - page: Page, - setup_combined_market, + setup_environment ): - page.goto(f"/#/markets/{setup_combined_market}") + vega, market, page = setup_environment + page.goto(f"/#/markets/{market}") page.get_by_test_id(FILLS).click() row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first expect(row.locator(COL_SIZE)).to_have_text("+2") @@ -168,11 +173,10 @@ def test_fills_taker_discount_program( @pytest.mark.xdist_group(name="test_fees_combo_tier_2") def test_fills_maker_discount_program( - vega: VegaServiceNull, - page: Page, - setup_combined_market, + setup_environment ): - page.goto(f"/#/markets/{setup_combined_market}") + vega, market, page = setup_environment + page.goto(f"/#/markets/{market}") change_keys(page, vega, MM_WALLET.name) page.get_by_test_id(FILLS).click() row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first @@ -185,10 +189,10 @@ def test_fills_maker_discount_program( @pytest.mark.xdist_group(name="test_fees_combo_tier_2") -def test_fills_maker_fee_tooltip_discount_program( - vega: VegaServiceNull, page: Page, setup_combined_market +def test_fills_maker_fee_tooltip_discount_program(setup_environment ): - page.goto(f"/#/markets/{setup_combined_market}") + vega, market, page = setup_environment + page.goto(f"/#/markets/{market}") change_keys(page, vega, MM_WALLET.name) page.get_by_test_id(FILLS).click() row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first @@ -202,10 +206,10 @@ def test_fills_maker_fee_tooltip_discount_program( @pytest.mark.xdist_group(name="test_fees_combo_tier_2") def test_fills_taker_fee_tooltip_discount_program( - page: Page, - setup_combined_market, + setup_environment, ): - page.goto(f"/#/markets/{setup_combined_market}") + vega, market, page = setup_environment + page.goto(f"/#/markets/{market}") page.get_by_test_id(FILLS).click() row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first # tbd - tooltip is not visible without this wait diff --git a/apps/trading/e2e/tests/fees/test_fees_referral_discount_tier_1.py b/apps/trading/e2e/tests/fees/test_fees_referral_discount_tier_1.py index 877672ba6..dbf3fd38a 100644 --- a/apps/trading/e2e/tests/fees/test_fees_referral_discount_tier_1.py +++ b/apps/trading/e2e/tests/fees/test_fees_referral_discount_tier_1.py @@ -14,63 +14,57 @@ from conftest import ( from actions.utils import next_epoch, change_keys, forward_time from fixtures.market import setup_continuous_market + @pytest.fixture(scope="module") -def vega(request): +def setup_environment(request, browser): + # Initialize Vega and setup for cleanup with init_vega(request) as vega_instance: - request.addfinalizer( - lambda: cleanup_container(vega_instance) + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) + + # Setup the market with the referral discount program + market = setup_continuous_market(vega_instance, custom_quantum=100000) + vega_instance.update_referral_program( + proposal_key=MM_WALLET.name, + benefit_tiers=[ + { + "minimum_running_notional_taker_volume": 100, + "minimum_epochs": 1, + "referral_reward_factor": 0.1, + "referral_discount_factor": 0.1, + }, + { + "minimum_running_notional_taker_volume": 200, + "minimum_epochs": 2, + "referral_reward_factor": 0.2, + "referral_discount_factor": 0.2, + }, + ], + staking_tiers=[ + {"minimum_staked_tokens": 100, "referral_reward_multiplier": 1.1}, + {"minimum_staked_tokens": 200, "referral_reward_multiplier": 1.2}, + ], + window_length=1, ) - yield vega_instance + vega_instance.create_referral_set(key_name=MM_WALLET.name) + next_epoch(vega_instance) + referral_set_id = list(vega_instance.list_referral_sets().keys())[0] + vega_instance.apply_referral_code(key_name="Key 1", id=referral_set_id) + next_epoch(vega_instance) + for _ in range(2): + submit_order(vega_instance, "Key 1", market, "SIDE_BUY", 1, 110) + forward_time(vega_instance, True if _ < 2 - 1 else False) -@pytest.fixture(scope="module") -def page(vega, browser, request): - with init_page(vega, browser, request) as page: - risk_accepted_setup(page) - auth_setup(vega, page) - yield page - - -@pytest.fixture(scope="module", autouse=True) -def setup_market_with_referral_discount_program(vega: VegaServiceNull): - market = setup_continuous_market(vega, custom_quantum=100000) - vega.update_referral_program( - proposal_key=MM_WALLET.name, - benefit_tiers=[ - { - "minimum_running_notional_taker_volume": 100, - "minimum_epochs": 1, - "referral_reward_factor": 0.1, - "referral_discount_factor": 0.1, - }, - { - "minimum_running_notional_taker_volume": 200, - "minimum_epochs": 2, - "referral_reward_factor": 0.2, - "referral_discount_factor": 0.2, - }, - ], - staking_tiers=[ - {"minimum_staked_tokens": 100, "referral_reward_multiplier": 1.1}, - {"minimum_staked_tokens": 200, "referral_reward_multiplier": 1.2}, - ], - window_length=1, - ) - vega.create_referral_set(key_name=MM_WALLET.name) - next_epoch(vega=vega) - referral_set_id = list(vega.list_referral_sets().keys())[0] - vega.apply_referral_code(key_name="Key 1", id=referral_set_id) - next_epoch(vega=vega) - - for _ in range(2): - submit_order(vega, "Key 1", market, "SIDE_BUY", 1, 110) - forward_time(vega, True if _ < 2 - 1 else False) - - return market + # Initialize page and setup + with init_page(vega_instance, browser, request) as page_instance: + risk_accepted_setup(page_instance) + auth_setup(vega_instance, page_instance) + yield vega_instance, market, page_instance @pytest.mark.xdist_group(name="test_fees_referral_tier_1") -def test_fees_page_discount_program_my_trading_fees(page: Page): +def test_fees_page_discount_program_my_trading_fees(setup_environment): + vega, market, page = setup_environment page.goto("/#/fees") expect(page.get_by_test_id(ADJUSTED_FEES)).to_have_text("9.045%-9.045%") expect(page.get_by_test_id(TOTAL_FEE_BEFORE_DISCOUNT)).to_have_text( @@ -82,7 +76,8 @@ def test_fees_page_discount_program_my_trading_fees(page: Page): @pytest.mark.xdist_group(name="test_fees_referral_tier_1") -def test_fees_page_discount_program_total_discount(page: Page): +def test_fees_page_discount_program_total_discount(setup_environment): + vega, market, page = setup_environment page.goto("/#/fees") expect(page.get_by_test_id(TOTAL_DISCOUNT)).to_have_text("10%") expect(page.get_by_test_id(VOLUME_DISCOUNT_ROW)).to_have_text("Volume discount0%") @@ -96,14 +91,16 @@ def test_fees_page_discount_program_total_discount(page: Page): @pytest.mark.xdist_group(name="test_fees_referral_tier_1") -def test_fees_page_referral_discount_program_referral_benefits(page: Page): +def test_fees_page_referral_discount_program_referral_benefits(setup_environment): + vega, market, page = setup_environment page.goto("/#/fees") expect(page.get_by_test_id(RUNNING_NOTIONAL_TAKER_VOLUME)).to_have_text("103") expect(page.get_by_test_id(EPOCHS_IN_REFERRAL_SET)).to_have_text("1") @pytest.mark.xdist_group(name="test_fees_referral_tier_1") -def test_fees_page_discount_program_discount(page: Page): +def test_fees_page_discount_program_discount(setup_environment): + vega, market, page = setup_environment page.goto("/#/fees") expect(page.get_by_test_id(TIER_VALUE_0)).to_have_text("1") expect(page.get_by_test_id(TIER_VALUE_1)).to_have_text("2") @@ -120,7 +117,8 @@ def test_fees_page_discount_program_discount(page: Page): @pytest.mark.xdist_group(name="test_fees_referral_tier_1") -def test_fees_page_discount_program_fees_by_market(page: Page): +def test_fees_page_discount_program_fees_by_market(setup_environment): + vega, market, page = setup_environment page.goto("/#/fees") pinned = page.locator(PINNED_ROW_LOCATOR) row = page.locator(ROW_LOCATOR) @@ -133,10 +131,9 @@ def test_fees_page_discount_program_fees_by_market(page: Page): @pytest.mark.xdist_group(name="test_fees_referral_tier_1") -def test_deal_ticket_discount_program( - page: Page, setup_market_with_referral_discount_program -): - page.goto(f"/#/markets/{setup_market_with_referral_discount_program}") +def test_deal_ticket_discount_program(setup_environment): + vega, market, page = setup_environment + page.goto(f"/#/markets/{market}") page.get_by_test_id(ORDER_SIZE).fill("1") page.get_by_test_id(ORDER_PRICE).fill("1") expect(page.get_by_test_id(DISCOUNT_PILL)).to_have_text("-10%") @@ -156,11 +153,9 @@ def test_deal_ticket_discount_program( @pytest.mark.xdist_group(name="test_fees_referral_tier_1") -def test_fills_taker_discount_program( - page: Page, - setup_market_with_referral_discount_program, -): - page.goto(f"/#/markets/{setup_market_with_referral_discount_program}") +def test_fills_taker_discount_program(setup_environment): + vega, market, page = setup_environment + page.goto(f"/#/markets/{market}") page.get_by_test_id(FILLS).click() row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first expect(row.locator(COL_SIZE)).to_have_text("+1") @@ -172,12 +167,9 @@ def test_fills_taker_discount_program( @pytest.mark.xdist_group(name="test_fees_referral_tier_1") -def test_fills_maker_discount_program( - vega: VegaServiceNull, - page: Page, - setup_market_with_referral_discount_program, -): - page.goto(f"/#/markets/{setup_market_with_referral_discount_program}") +def test_fills_maker_discount_program(setup_environment): + vega, market, page = setup_environment + page.goto(f"/#/markets/{market}") change_keys(page, vega, MM_WALLET.name) page.get_by_test_id(FILLS).click() row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first @@ -190,10 +182,9 @@ def test_fills_maker_discount_program( @pytest.mark.xdist_group(name="test_fees_referral_tier_1") -def test_fills_maker_fee_tooltip_discount_program( - vega: VegaServiceNull, page: Page, setup_market_with_referral_discount_program -): - page.goto(f"/#/markets/{setup_market_with_referral_discount_program}") +def test_fills_maker_fee_tooltip_discount_program(setup_environment): + vega, market, page = setup_environment + page.goto(f"/#/markets/{market}") change_keys(page, vega, MM_WALLET.name) page.get_by_test_id(FILLS).click() row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first @@ -206,11 +197,9 @@ def test_fills_maker_fee_tooltip_discount_program( @pytest.mark.xdist_group(name="test_fees_referral_tier_1") -def test_fills_taker_fee_tooltip_discount_program( - page: Page, - setup_market_with_referral_discount_program, -): - page.goto(f"/#/markets/{setup_market_with_referral_discount_program}") +def test_fills_taker_fee_tooltip_discount_program(setup_environment): + vega, market, page = setup_environment + page.goto(f"/#/markets/{market}") page.get_by_test_id(FILLS).click() row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first # tbd - tooltip is not visible without this wait diff --git a/apps/trading/e2e/tests/fees/test_fees_referral_discount_tier_2.py b/apps/trading/e2e/tests/fees/test_fees_referral_discount_tier_2.py index b6c860549..798603f5c 100644 --- a/apps/trading/e2e/tests/fees/test_fees_referral_discount_tier_2.py +++ b/apps/trading/e2e/tests/fees/test_fees_referral_discount_tier_2.py @@ -16,62 +16,55 @@ from fixtures.market import setup_continuous_market @pytest.fixture(scope="module") -def vega(request): +def setup_environment(request, browser): + # Initialize Vega with cleanup with init_vega(request) as vega_instance: - request.addfinalizer( - lambda: cleanup_container(vega_instance) + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) + + # Setup market with referral discount program + market = setup_continuous_market(vega_instance, custom_quantum=100000) + vega_instance.update_referral_program( + proposal_key=MM_WALLET.name, + benefit_tiers=[ + { + "minimum_running_notional_taker_volume": 100, + "minimum_epochs": 1, + "referral_reward_factor": 0.1, + "referral_discount_factor": 0.1, + }, + { + "minimum_running_notional_taker_volume": 200, + "minimum_epochs": 2, + "referral_reward_factor": 0.2, + "referral_discount_factor": 0.2, + }, + ], + staking_tiers=[ + {"minimum_staked_tokens": 100, "referral_reward_multiplier": 1.1}, + {"minimum_staked_tokens": 200, "referral_reward_multiplier": 1.2}, + ], + window_length=1, ) - yield vega_instance + vega_instance.create_referral_set(key_name=MM_WALLET.name) + next_epoch(vega_instance) + referral_set_id = list(vega_instance.list_referral_sets().keys())[0] + vega_instance.apply_referral_code(key_name="Key 1", id=referral_set_id) + next_epoch(vega_instance) + for _ in range(2): + submit_order(vega_instance, "Key 1", market, "SIDE_BUY", 2, 110) + forward_time(vega_instance, True if _ < 2 - 1 else False) -@pytest.fixture(scope="module") -def page(vega, browser, request): - with init_page(vega, browser, request) as page: - risk_accepted_setup(page) - auth_setup(vega, page) - yield page - - -@pytest.fixture(scope="module", autouse=True) -def setup_market_with_referral_discount_program(vega: VegaServiceNull): - market = setup_continuous_market(vega, custom_quantum=100000) - vega.update_referral_program( - proposal_key=MM_WALLET.name, - benefit_tiers=[ - { - "minimum_running_notional_taker_volume": 100, - "minimum_epochs": 1, - "referral_reward_factor": 0.1, - "referral_discount_factor": 0.1, - }, - { - "minimum_running_notional_taker_volume": 200, - "minimum_epochs": 2, - "referral_reward_factor": 0.2, - "referral_discount_factor": 0.2, - }, - ], - staking_tiers=[ - {"minimum_staked_tokens": 100, "referral_reward_multiplier": 1.1}, - {"minimum_staked_tokens": 200, "referral_reward_multiplier": 1.2}, - ], - window_length=1, - ) - vega.create_referral_set(key_name=MM_WALLET.name) - next_epoch(vega=vega) - referral_set_id = list(vega.list_referral_sets().keys())[0] - vega.apply_referral_code(key_name="Key 1", id=referral_set_id) - next_epoch(vega=vega) - - for _ in range(2): - submit_order(vega, "Key 1", market, "SIDE_BUY", 2, 110) - forward_time(vega, True if _ < 2 - 1 else False) - - return market + # Initialize page and setup + with init_page(vega_instance, browser, request) as page_instance: + risk_accepted_setup(page_instance) + auth_setup(vega_instance, page_instance) + yield vega_instance, market, page_instance @pytest.mark.xdist_group(name="test_fees_referral_tier_2") -def test_fees_page_discount_program_my_trading_fees(page: Page): +def test_fees_page_discount_program_my_trading_fees(setup_environment): + vega, market, page = setup_environment page.goto("/#/fees") expect(page.get_by_test_id(ADJUSTED_FEES)).to_have_text("8.04%-8.04%") expect(page.get_by_test_id(TOTAL_FEE_BEFORE_DISCOUNT)).to_have_text( @@ -83,7 +76,8 @@ def test_fees_page_discount_program_my_trading_fees(page: Page): @pytest.mark.xdist_group(name="test_fees_referral_tier_2") -def test_fees_page_discount_program_total_discount(page: Page): +def test_fees_page_discount_program_total_discount(setup_environment): + vega, market, page = setup_environment page.goto("/#/fees") expect(page.get_by_test_id(TOTAL_DISCOUNT)).to_have_text("20%") expect(page.get_by_test_id(VOLUME_DISCOUNT_ROW)).to_have_text("Volume discount0%") @@ -97,14 +91,16 @@ def test_fees_page_discount_program_total_discount(page: Page): @pytest.mark.xdist_group(name="test_fees_referral_tier_2") -def test_fees_page_referral_discount_program_referral_benefits(page: Page): +def test_fees_page_referral_discount_program_referral_benefits(setup_environment): + vega, market, page = setup_environment page.goto("/#/fees") expect(page.get_by_test_id(RUNNING_NOTIONAL_TAKER_VOLUME)).to_have_text("207") expect(page.get_by_test_id(REQUIRED_FOR_NEXT_TIER)).not_to_be_visible() @pytest.mark.xdist_group(name="test_fees_referral_tier_2") -def test_fees_page_discount_program_discount(page: Page): +def test_fees_page_discount_program_discount(setup_environment): + vega, market, page = setup_environment page.goto("/#/fees") expect(page.get_by_test_id(TIER_VALUE_0)).to_have_text("1") expect(page.get_by_test_id(TIER_VALUE_1)).to_have_text("2") @@ -121,7 +117,8 @@ def test_fees_page_discount_program_discount(page: Page): @pytest.mark.xdist_group(name="test_fees_referral_tier_2") -def test_fees_page_discount_program_fees_by_market(page: Page): +def test_fees_page_discount_program_fees_by_market(setup_environment): + vega, market, page = setup_environment page.goto("/#/fees") pinned = page.locator(PINNED_ROW_LOCATOR) row = page.locator(ROW_LOCATOR) @@ -134,10 +131,9 @@ def test_fees_page_discount_program_fees_by_market(page: Page): @pytest.mark.xdist_group(name="test_fees_referral_tier_2") -def test_deal_ticket_discount_program( - page: Page, setup_market_with_referral_discount_program -): - page.goto(f"/#/markets/{setup_market_with_referral_discount_program}") +def test_deal_ticket_discount_program(setup_environment): + vega, market, page = setup_environment + page.goto(f"/#/markets/{market}") page.get_by_test_id(ORDER_SIZE).fill("1") page.get_by_test_id(ORDER_PRICE).fill("1") expect(page.get_by_test_id(DISCOUNT_PILL)).to_have_text("-20%") @@ -157,11 +153,9 @@ def test_deal_ticket_discount_program( @pytest.mark.xdist_group(name="test_fees_referral_tier_2") -def test_fills_taker_discount_program( - page: Page, - setup_market_with_referral_discount_program, -): - page.goto(f"/#/markets/{setup_market_with_referral_discount_program}") +def test_fills_taker_discount_program(setup_environment): + vega, market, page = setup_environment + page.goto(f"/#/markets/{market}") page.get_by_test_id(FILLS).click() row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first expect(row.locator(COL_SIZE)).to_have_text("+2") @@ -173,12 +167,9 @@ def test_fills_taker_discount_program( @pytest.mark.xdist_group(name="test_fees_referral_tier_2") -def test_fills_maker_discount_program( - vega: VegaServiceNull, - page: Page, - setup_market_with_referral_discount_program, -): - page.goto(f"/#/markets/{setup_market_with_referral_discount_program}") +def test_fills_maker_discount_program(setup_environment): + vega, market, page = setup_environment + page.goto(f"/#/markets/{market}") change_keys(page, vega, MM_WALLET.name) page.get_by_test_id(FILLS).click() row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first @@ -191,10 +182,9 @@ def test_fills_maker_discount_program( @pytest.mark.xdist_group(name="test_fees_referral_tier_2") -def test_fills_maker_fee_tooltip_discount_program( - vega: VegaServiceNull, page: Page, setup_market_with_referral_discount_program -): - page.goto(f"/#/markets/{setup_market_with_referral_discount_program}") +def test_fills_maker_fee_tooltip_discount_program(setup_environment): + vega, market, page = setup_environment + page.goto(f"/#/markets/{market}") change_keys(page, vega, MM_WALLET.name) page.get_by_test_id(FILLS).click() row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first @@ -207,11 +197,9 @@ def test_fills_maker_fee_tooltip_discount_program( @pytest.mark.xdist_group(name="test_fees_referral_tier_2") -def test_fills_taker_fee_tooltip_discount_program( - page: Page, - setup_market_with_referral_discount_program, -): - page.goto(f"/#/markets/{setup_market_with_referral_discount_program}") +def test_fills_taker_fee_tooltip_discount_program(setup_environment): + vega, market, page = setup_environment + page.goto(f"/#/markets/{market}") page.get_by_test_id(FILLS).click() row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first # tbd - tooltip is not visible without this wait diff --git a/apps/trading/e2e/tests/fees/test_fees_volume_discount_tier_1.py b/apps/trading/e2e/tests/fees/test_fees_volume_discount_tier_1.py index 3f037ecba..eb7aae522 100644 --- a/apps/trading/e2e/tests/fees/test_fees_volume_discount_tier_1.py +++ b/apps/trading/e2e/tests/fees/test_fees_volume_discount_tier_1.py @@ -16,49 +16,36 @@ from fixtures.market import setup_continuous_market @pytest.fixture(scope="module") -def vega(request): +def setup_vega_and_market(request, browser): + # Initialize Vega with cleanup with init_vega(request) as vega_instance: - request.addfinalizer( - lambda: cleanup_container(vega_instance) + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) + + # Setup the market with volume discount program + market = setup_continuous_market(vega_instance, custom_quantum=100000) + vega_instance.update_volume_discount_program( + proposal_key=MM_WALLET.name, + benefit_tiers=[ + {"minimum_running_notional_taker_volume": 100, "volume_discount_factor": 0.1}, + {"minimum_running_notional_taker_volume": 200, "volume_discount_factor": 0.2}, + ], + window_length=7, ) - yield vega_instance + next_epoch(vega=vega_instance) + + for _ in range(2): + submit_order(vega_instance, "Key 1", market, "SIDE_BUY", 1, 110) + forward_time(vega_instance, True if _ < 2 - 1 else False) + + # Initialize and setup page + with init_page(vega_instance, browser, request) as page: + risk_accepted_setup(page) + auth_setup(vega_instance, page) + yield vega_instance, market, page -@pytest.fixture(scope="module") -def page(vega, browser, request): - with init_page(vega, browser, request) as page: - risk_accepted_setup(page) - auth_setup(vega, page) - yield page - - -@pytest.fixture(scope="module", autouse=True) -def setup_market_with_volume_discount_program(vega: VegaServiceNull): - market = setup_continuous_market(vega, custom_quantum=100000) - vega.update_volume_discount_program( - proposal_key=MM_WALLET.name, - benefit_tiers=[ - { - "minimum_running_notional_taker_volume": 100, - "volume_discount_factor": 0.1, - }, - { - "minimum_running_notional_taker_volume": 200, - "volume_discount_factor": 0.2, - }, - ], - window_length=7, - ) - next_epoch(vega=vega) - - for _ in range(2): - submit_order(vega, "Key 1", market, "SIDE_BUY", 1, 110) - forward_time(vega, True if _ < 2 - 1 else False) - return market - - -@pytest.mark.xdist_group(name="test_fees_volume_tier_1") -def test_fees_page_discount_program_my_trading_fees(page: Page): +def test_fees_page_discount_program_my_trading_fees(setup_vega_and_market): + vega, market, page = setup_vega_and_market page.goto("/#/fees") expect(page.get_by_test_id(ADJUSTED_FEES)).to_have_text("9.045%-9.045%") expect(page.get_by_test_id(TOTAL_FEE_BEFORE_DISCOUNT)).to_have_text( @@ -69,10 +56,11 @@ def test_fees_page_discount_program_my_trading_fees(page: Page): expect(page.get_by_test_id(LIQUIDITY_FEES)).to_have_text("Liquidity0%-0%") -@pytest.mark.xdist_group(name="test_fees_volume_tier_1") + def test_fees_page_discount_program_total_discount( - page: Page, + setup_vega_and_market ): + vega, market, page = setup_vega_and_market page.goto("/#/fees") expect(page.get_by_test_id(TOTAL_DISCOUNT)).to_have_text("10%") expect(page.get_by_test_id(VOLUME_DISCOUNT_ROW)).to_have_text("Volume discount10%") @@ -85,20 +73,22 @@ def test_fees_page_discount_program_total_discount( ) -@pytest.mark.xdist_group(name="test_fees_volume_tier_1") + def test_fees_page_volume_discount_program_my_current_volume( - page: Page, + setup_vega_and_market ): + vega, market, page = setup_vega_and_market page.goto("/#/fees") expect(page.get_by_test_id(PAST_EPOCHS_VOLUME)).to_have_text("103") expect(page.get_by_test_id(REQUIRED_FOR_NEXT_TIER)).to_have_text("97") -@pytest.mark.xdist_group(name="test_fees_volume_tier_1") + def test_fees_page_discount_program_discount( - page: Page, + setup_vega_and_market ): + vega, market, page = setup_vega_and_market page.goto("/#/fees") expect(page.get_by_test_id(TIER_VALUE_0)).to_have_text("1") expect(page.get_by_test_id(TIER_VALUE_1)).to_have_text("2") @@ -111,8 +101,9 @@ def test_fees_page_discount_program_discount( expect(page.get_by_test_id("your-volume-tier-0").nth(1)).to_have_text("Your tier") -@pytest.mark.xdist_group(name="test_fees_volume_tier_1") -def test_fees_page_discount_program_fees_by_market(page: Page): + +def test_fees_page_discount_program_fees_by_market(setup_vega_and_market): + vega, market, page = setup_vega_and_market page.goto("/#/fees") pinned = page.locator(PINNED_ROW_LOCATOR) row = page.locator(ROW_LOCATOR) @@ -124,11 +115,12 @@ def test_fees_page_discount_program_fees_by_market(page: Page): expect(row.locator(COL_TOTAL_FEE)).to_have_text("10.05%") -@pytest.mark.xdist_group(name="test_fees_volume_tier_1") + def test_deal_ticket_discount_program_testing( - page: Page, setup_market_with_volume_discount_program + setup_vega_and_market ): - page.goto(f"/#/markets/{setup_market_with_volume_discount_program}") + vega, market, page = setup_vega_and_market + page.goto(f"/#/markets/{market}") page.get_by_test_id(ORDER_SIZE).fill("1") page.get_by_test_id(ORDER_PRICE).fill("1") expect(page.get_by_test_id(DISCOUNT_PILL)).to_have_text("-10%") @@ -147,11 +139,11 @@ def test_deal_ticket_discount_program_testing( expect(tooltip.get_by_test_id(TOTAL_FEE_VALUE)).to_have_text("0.09045 tDAI") -@pytest.mark.xdist_group(name="test_fees_volume_tier_1") def test_fills_taker_discount_program( - page: Page, setup_market_with_volume_discount_program + setup_vega_and_market ): - page.goto(f"/#/markets/{setup_market_with_volume_discount_program}") + vega, market, page = setup_vega_and_market + page.goto(f"/#/markets/{market}") page.get_by_test_id(FILLS).click() row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first expect(row.locator(COL_SIZE)).to_have_text("+1") @@ -162,11 +154,11 @@ def test_fills_taker_discount_program( expect(row.locator(COL_FEE_DISCOUNT)).to_have_text("1.04017 tDAI") -@pytest.mark.xdist_group(name="test_fees_volume_tier_1") def test_fills_maker_discount_program( - page: Page, setup_market_with_volume_discount_program, vega: VegaServiceNull + setup_vega_and_market ): - page.goto(f"/#/markets/{setup_market_with_volume_discount_program}") + vega, market, page = setup_vega_and_market + page.goto(f"/#/markets/{market}") change_keys(page, vega, MM_WALLET.name) page.get_by_test_id(FILLS).click() row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first @@ -178,11 +170,12 @@ def test_fills_maker_discount_program( expect(row.locator(COL_FEE_DISCOUNT)).to_have_text("1.035 tDAI") -@pytest.mark.xdist_group(name="test_fees_volume_tier_1") + def test_fills_maker_fee_tooltip_discount_program( - vega: VegaServiceNull, page: Page, setup_market_with_volume_discount_program + setup_vega_and_market ): - page.goto(f"/#/markets/{setup_market_with_volume_discount_program}") + vega, market, page = setup_vega_and_market + page.goto(f"/#/markets/{market}") change_keys(page, vega, MM_WALLET.name) page.get_by_test_id(FILLS).click() row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first @@ -194,12 +187,12 @@ def test_fills_maker_fee_tooltip_discount_program( ) -@pytest.mark.xdist_group(name="test_fees_volume_tier_1") + def test_fills_taker_fee_tooltip_discount_program( - page: Page, - setup_market_with_volume_discount_program, + setup_vega_and_market ): - page.goto(f"/#/markets/{setup_market_with_volume_discount_program}") + vega, market, page = setup_vega_and_market + page.goto(f"/#/markets/{market}") page.get_by_test_id(FILLS).click() row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first # tbd - tooltip is not visible without this wait diff --git a/apps/trading/e2e/tests/fees/test_fees_volume_discount_tier_2.py b/apps/trading/e2e/tests/fees/test_fees_volume_discount_tier_2.py index 71590c20d..9373f9175 100644 --- a/apps/trading/e2e/tests/fees/test_fees_volume_discount_tier_2.py +++ b/apps/trading/e2e/tests/fees/test_fees_volume_discount_tier_2.py @@ -14,51 +14,45 @@ from conftest import ( from actions.utils import next_epoch, change_keys, forward_time from fixtures.market import setup_continuous_market + @pytest.fixture(scope="module") -def vega(request): +def setup_environment(request, browser): + # Initialize Vega and setup cleanup with init_vega(request) as vega_instance: - request.addfinalizer( - lambda: cleanup_container(vega_instance) + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) + + # Setup the market with volume discount program + market = setup_continuous_market(vega_instance, custom_quantum=100000) + vega_instance.update_volume_discount_program( + proposal_key=MM_WALLET.name, + benefit_tiers=[ + { + "minimum_running_notional_taker_volume": 100, + "volume_discount_factor": 0.1, + }, + { + "minimum_running_notional_taker_volume": 200, + "volume_discount_factor": 0.2, + }, + ], + window_length=7, ) - yield vega_instance + next_epoch(vega=vega_instance) + for _ in range(3): + submit_order(vega_instance, "Key 1", market, "SIDE_BUY", 1, 110) + forward_time(vega_instance, True if _ < 3 - 1 else False) -@pytest.fixture(scope="module") -def page(vega, browser, request): - with init_page(vega, browser, request) as page: - risk_accepted_setup(page) - auth_setup(vega, page) - yield page - - -@pytest.fixture(scope="module", autouse=True) -def setup_market_with_volume_discount_program(vega: VegaServiceNull): - market = setup_continuous_market(vega, custom_quantum=100000) - vega.update_volume_discount_program( - proposal_key=MM_WALLET.name, - benefit_tiers=[ - { - "minimum_running_notional_taker_volume": 100, - "volume_discount_factor": 0.1, - }, - { - "minimum_running_notional_taker_volume": 200, - "volume_discount_factor": 0.2, - }, - ], - window_length=7, - ) - next_epoch(vega=vega) - - for _ in range(3): - submit_order(vega, "Key 1", market, "SIDE_BUY", 1, 110) - forward_time(vega, True if _ < 3 - 1 else False) - - return market + # Initialize page and apply setups + with init_page(vega_instance, browser, request) as page_instance: + risk_accepted_setup(page_instance) + auth_setup(vega_instance, page_instance) + yield vega_instance, market, page_instance @pytest.mark.xdist_group(name="test_fees_volume_tier_2") -def test_fees_page_discount_program_my_trading_fees(page: Page): +def test_fees_page_discount_program_my_trading_fees(setup_environment): + vega, market, page = setup_environment page.goto("/#/fees") expect(page.get_by_test_id(ADJUSTED_FEES)).to_have_text("8.04%-8.04%") expect(page.get_by_test_id(TOTAL_FEE_BEFORE_DISCOUNT)).to_have_text( @@ -70,7 +64,8 @@ def test_fees_page_discount_program_my_trading_fees(page: Page): @pytest.mark.xdist_group(name="test_fees_volume_tier_2") -def test_fees_page_discount_program_total_discount(page: Page): +def test_fees_page_discount_program_total_discount(setup_environment): + vega, market, page = setup_environment page.goto("/#/fees") expect(page.get_by_test_id(TOTAL_DISCOUNT)).to_have_text("20%") expect(page.get_by_test_id(VOLUME_DISCOUNT_ROW)).to_have_text("Volume discount20%") @@ -84,14 +79,16 @@ def test_fees_page_discount_program_total_discount(page: Page): @pytest.mark.xdist_group(name="test_fees_volume_tier_2") -def test_fees_page_volume_discount_program_my_current_volume(page: Page): +def test_fees_page_volume_discount_program_my_current_volume(setup_environment): + vega, market, page = setup_environment page.goto("/#/fees") expect(page.get_by_test_id(PAST_EPOCHS_VOLUME)).to_have_text("206") expect(page.get_by_test_id(REQUIRED_FOR_NEXT_TIER)).not_to_be_visible() @pytest.mark.xdist_group(name="test_fees_volume_tier_2") -def test_fees_page_discount_program_discount(page: Page): +def test_fees_page_discount_program_discount(setup_environment): + vega, market, page = setup_environment page.goto("/#/fees") expect(page.get_by_test_id(TIER_VALUE_0)).to_have_text("1") expect(page.get_by_test_id(TIER_VALUE_1)).to_have_text("2") @@ -105,7 +102,8 @@ def test_fees_page_discount_program_discount(page: Page): @pytest.mark.xdist_group(name="test_fees_volume_tier_2") -def test_fees_page_discount_program_fees_by_market(page: Page): +def test_fees_page_discount_program_fees_by_market(setup_environment): + vega, market, page = setup_environment page.goto("/#/fees") pinned = page.locator(PINNED_ROW_LOCATOR) row = page.locator(ROW_LOCATOR) @@ -118,11 +116,9 @@ def test_fees_page_discount_program_fees_by_market(page: Page): @pytest.mark.xdist_group(name="test_fees_volume_tier_2") -def test_deal_ticket_discount_program( - page: Page, - setup_market_with_volume_discount_program, -): - page.goto(f"/#/markets/{setup_market_with_volume_discount_program}") +def test_deal_ticket_discount_program(setup_environment): + vega, market, page = setup_environment + page.goto(f"/#/markets/{market}") page.get_by_test_id(ORDER_SIZE).fill("1") page.get_by_test_id(ORDER_PRICE).fill("1") expect(page.get_by_test_id(DISCOUNT_PILL)).to_have_text("-20%") @@ -142,11 +138,9 @@ def test_deal_ticket_discount_program( @pytest.mark.xdist_group(name="test_fees_volume_tier_2") -def test_fills_taker_discount_program( - page: Page, - setup_market_with_volume_discount_program, -): - page.goto(f"/#/markets/{setup_market_with_volume_discount_program}") +def test_fills_taker_discount_program(setup_environment): + vega, market, page = setup_environment + page.goto(f"/#/markets/{market}") page.get_by_test_id(FILLS).click() row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first expect(row.locator(COL_SIZE)).to_have_text("+1") @@ -161,11 +155,10 @@ def test_fills_taker_discount_program( @pytest.mark.xdist_group(name="test_fees_volume_tier_2") def test_fills_maker_discount_program( - vega: VegaServiceNull, - page: Page, - setup_market_with_volume_discount_program, + setup_environment, ): - page.goto(f"/#/markets/{setup_market_with_volume_discount_program}") + vega, market, page = setup_environment + page.goto(f"/#/markets/{market}") change_keys(page, vega, MM_WALLET.name) page.get_by_test_id(FILLS).click() row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first @@ -178,10 +171,9 @@ def test_fills_maker_discount_program( @pytest.mark.xdist_group(name="test_fees_volume_tier_2") -def test_fills_maker_fee_tooltip_discount_program( - vega, page: Page, setup_market_with_volume_discount_program -): - page.goto(f"/#/markets/{setup_market_with_volume_discount_program}") +def test_fills_maker_fee_tooltip_discount_program(setup_environment): + vega, market, page = setup_environment + page.goto(f"/#/markets/{market}") change_keys(page, vega, MM_WALLET.name) page.get_by_test_id(FILLS).click() row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first @@ -195,10 +187,10 @@ def test_fills_maker_fee_tooltip_discount_program( @pytest.mark.xdist_group(name="test_fees_volume_tier_2") def test_fills_taker_fee_tooltip_discount_program( - page: Page, - setup_market_with_volume_discount_program, + setup_environment, ): - page.goto(f"/#/markets/{setup_market_with_volume_discount_program}") + vega, market, page = setup_environment + page.goto(f"/#/markets/{market}") page.get_by_test_id(FILLS).click() row = page.get_by_test_id(TAB_FILLS).locator(ROW_LOCATOR).first # tbd - tooltip is not visible without this wait diff --git a/apps/trading/e2e/tests/get_started/test_get_started.py b/apps/trading/e2e/tests/get_started/test_get_started.py index 2231694df..7132ed4c2 100644 --- a/apps/trading/e2e/tests/get_started/test_get_started.py +++ b/apps/trading/e2e/tests/get_started/test_get_started.py @@ -14,7 +14,7 @@ logger = logging.getLogger() @pytest.fixture(scope="class") def vega(request): with init_vega(request) as vega_instance: - request.addfinalizer(lambda: cleanup_container(vega_instance)) + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) yield vega_instance diff --git a/apps/trading/e2e/tests/liquidity_provision/test_liquidity_provision.py b/apps/trading/e2e/tests/liquidity_provision/test_liquidity_provision.py index 9688155e3..a21990b78 100644 --- a/apps/trading/e2e/tests/liquidity_provision/test_liquidity_provision.py +++ b/apps/trading/e2e/tests/liquidity_provision/test_liquidity_provision.py @@ -8,7 +8,7 @@ from actions.utils import next_epoch, truncate_middle, change_keys @pytest.fixture(scope="module") def vega(request): with init_vega(request) as vega_instance: - request.addfinalizer(lambda: cleanup_container(vega_instance)) + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) yield vega_instance diff --git a/apps/trading/e2e/tests/market/test_closed_markets.py b/apps/trading/e2e/tests/market/test_closed_markets.py index f6b4e0a56..9aeafae36 100644 --- a/apps/trading/e2e/tests/market/test_closed_markets.py +++ b/apps/trading/e2e/tests/market/test_closed_markets.py @@ -11,7 +11,7 @@ from actions.utils import next_epoch @pytest.fixture(scope="class") def vega(request): with init_vega(request) as vega_instance: - request.addfinalizer(lambda: cleanup_container(vega_instance)) + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) yield vega_instance diff --git a/apps/trading/e2e/tests/market/test_market_info.py b/apps/trading/e2e/tests/market/test_market_info.py index db5705d5a..68c7b7e3b 100644 --- a/apps/trading/e2e/tests/market/test_market_info.py +++ b/apps/trading/e2e/tests/market/test_market_info.py @@ -11,7 +11,7 @@ market_title_test_id = "accordion-title" @pytest.fixture(scope="module") def vega(request): with init_vega(request) as vega_instance: - request.addfinalizer(lambda: cleanup_container(vega_instance)) + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) yield vega_instance diff --git a/apps/trading/e2e/tests/market/test_markets_proposed.py b/apps/trading/e2e/tests/market/test_markets_proposed.py index 81531ddb8..930b3e39a 100644 --- a/apps/trading/e2e/tests/market/test_markets_proposed.py +++ b/apps/trading/e2e/tests/market/test_markets_proposed.py @@ -14,7 +14,7 @@ col_market_id = '[col-id="market"] [data-testid="stack-cell-primary"]' @pytest.fixture(scope="module") def vega(request): with init_vega(request) as vega_instance: - request.addfinalizer(lambda: cleanup_container(vega_instance)) + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) yield vega_instance diff --git a/apps/trading/e2e/tests/market/test_monitoring_auction_price_volatility_market.py b/apps/trading/e2e/tests/market/test_monitoring_auction_price_volatility_market.py index 9468371df..31d9a7cf7 100644 --- a/apps/trading/e2e/tests/market/test_monitoring_auction_price_volatility_market.py +++ b/apps/trading/e2e/tests/market/test_monitoring_auction_price_volatility_market.py @@ -16,7 +16,7 @@ COL_ID_FEE = ".ag-center-cols-container [col-id='fee'] .ag-cell-value" @pytest.fixture(scope="module") def vega(request): with init_vega(request) as vega_instance: - request.addfinalizer(lambda: cleanup_container(vega_instance)) + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) yield vega_instance diff --git a/apps/trading/e2e/tests/navigation/test_navigation.py b/apps/trading/e2e/tests/navigation/test_navigation.py index 6d2d595ac..bcfcc6bdc 100644 --- a/apps/trading/e2e/tests/navigation/test_navigation.py +++ b/apps/trading/e2e/tests/navigation/test_navigation.py @@ -7,7 +7,7 @@ from conftest import init_page, init_vega, cleanup_container @pytest.fixture(scope="module") def vega(request): with init_vega(request) as vega_instance: - request.addfinalizer(lambda: cleanup_container(vega_instance)) + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) yield vega_instance diff --git a/apps/trading/e2e/tests/order/test_order_status.py b/apps/trading/e2e/tests/order/test_order_status.py index 69be71638..a4ec5d466 100644 --- a/apps/trading/e2e/tests/order/test_order_status.py +++ b/apps/trading/e2e/tests/order/test_order_status.py @@ -10,228 +10,218 @@ order_tab = "tab-orders" @pytest.fixture(scope="module") -def vega(request): +def setup_environment(request, browser): + # Initialize Vega with cleanup with init_vega(request) as vega_instance: - request.addfinalizer(lambda: cleanup_container(vega_instance)) # Register the cleanup function - yield vega_instance + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) + # Setup multiple markets + markets = { + "market_1": setup_continuous_market(vega_instance, custom_market_name="market-1"), + "market_2": setup_continuous_market(vega_instance, custom_market_name="market-2"), + "market_3": setup_continuous_market(vega_instance, custom_market_name="market-3"), + "market_4": setup_continuous_market(vega_instance, custom_market_name="market-4"), + "market_5": setup_simple_market(vega_instance, custom_market_name="market-5"), + } -@pytest.fixture(scope="module", autouse=True) -def markets(vega: VegaServiceNull): - market_1 = setup_continuous_market( - vega, - custom_market_name="market-1", - ) - market_2 = setup_continuous_market( - vega, - custom_market_name="market-2", - ) - market_3 = setup_continuous_market( - vega, - custom_market_name="market-3", - ) - market_4 = setup_continuous_market( - vega, - custom_market_name="market-4", - ) - market_5 = setup_simple_market( - vega, - custom_market_name="market-5", - ) + # Execute a series of orders across different markets + # Example for market_1 orders, adjust as necessary for your test scenario + vega_instance.submit_order( + trading_key="Key 1", + market_id=markets["market_1"], + time_in_force="TIME_IN_FORCE_IOC", + order_type="TYPE_LIMIT", + side="SIDE_SELL", + volume=100, + price=130, + ) + + vega_instance.forward("2s") + vega_instance.wait_fn(1) + vega_instance.wait_for_total_catchup() - vega.submit_order( - trading_key="Key 1", - market_id=market_1, - time_in_force="TIME_IN_FORCE_IOC", - order_type="TYPE_LIMIT", - side="SIDE_SELL", - volume=100, - price=130, - ) + vega_instance.submit_order( + trading_key="Key 1", + market_id=markets["market_1"], + time_in_force="TIME_IN_FORCE_GTC", + order_type="TYPE_LIMIT", + side="SIDE_SELL", + volume=100, + price=88, + ) - vega.forward("2s") - vega.wait_fn(1) - vega.wait_for_total_catchup() + vega_instance.forward("2s") + vega_instance.wait_fn(1) + vega_instance.wait_for_total_catchup() - vega.submit_order( - trading_key="Key 1", - market_id=market_1, - time_in_force="TIME_IN_FORCE_GTC", - order_type="TYPE_LIMIT", - side="SIDE_SELL", - volume=100, - price=88, - ) + vega_instance.submit_order( + trading_key="Key 1", + market_id=markets["market_1"], + time_in_force="TIME_IN_FORCE_IOC", + order_type="TYPE_LIMIT", + side="SIDE_SELL", + volume=100, + price=88, + ) - vega.forward("2s") - vega.wait_fn(1) - vega.wait_for_total_catchup() + vega_instance.forward("2s") + vega_instance.wait_fn(1) + vega_instance.wait_for_total_catchup() - vega.submit_order( - trading_key="Key 1", - market_id=market_1, - time_in_force="TIME_IN_FORCE_IOC", - order_type="TYPE_LIMIT", - side="SIDE_SELL", - volume=100, - price=88, - ) + vega_instance.submit_order( + trading_key="Key 1", + market_id=markets["market_1"], + time_in_force="TIME_IN_FORCE_GTC", + order_type="TYPE_LIMIT", + side="SIDE_SELL", + volume=1e10, + price=130, + wait=False, + ) - vega.forward("2s") - vega.wait_fn(1) - vega.wait_for_total_catchup() + vega_instance.forward("2s") + vega_instance.wait_fn(1) + vega_instance.wait_for_total_catchup() - vega.submit_order( - trading_key="Key 1", - market_id=market_1, - time_in_force="TIME_IN_FORCE_GTC", - order_type="TYPE_LIMIT", - side="SIDE_SELL", - volume=1e10, - price=130, - wait=False, - ) + vega_instance.submit_order( + trading_key="Key 1", + market_id=markets["market_2"], + time_in_force="TIME_IN_FORCE_IOC", + order_type="TYPE_LIMIT", + side="SIDE_BUY", + volume=100, + price=104, + ) + vega_instance.forward("2s") + vega_instance.wait_fn(1) + vega_instance.wait_for_total_catchup() - vega.forward("2s") - vega.wait_fn(1) - vega.wait_for_total_catchup() + vega_instance.submit_order( + trading_key="Key 1", + market_id=markets["market_3"], + time_in_force="TIME_IN_FORCE_GTT", + order_type="TYPE_LIMIT", + side="SIDE_SELL", + volume=10, + price=120, + expires_at=vega_instance.get_blockchain_time() + 5 * 1e9, + ) - vega.submit_order( - trading_key="Key 1", - market_id=market_2, - time_in_force="TIME_IN_FORCE_IOC", - order_type="TYPE_LIMIT", - side="SIDE_BUY", - volume=100, - price=104, - ) - vega.forward("2s") - vega.wait_fn(1) - vega.wait_for_total_catchup() + vega_instance.forward("2s") + vega_instance.wait_fn(1) + vega_instance.wait_for_total_catchup() - vega.submit_order( - trading_key="Key 1", - market_id=market_3, - time_in_force="TIME_IN_FORCE_GTT", - order_type="TYPE_LIMIT", - side="SIDE_SELL", - volume=10, - price=120, - expires_at=vega.get_blockchain_time() + 5 * 1e9, - ) + vega_instance.submit_order( + market_id=markets["market_4"], + trading_key="Key 1", + side="SIDE_BUY", + order_type="TYPE_LIMIT", + pegged_order=PeggedOrder(reference="PEGGED_REFERENCE_MID", offset=5), + time_in_force="TIME_IN_FORCE_GTC", + volume=20, + ) - vega.forward("2s") - vega.wait_fn(1) - vega.wait_for_total_catchup() + vega_instance.forward("2s") + vega_instance.wait_fn(1) + vega_instance.wait_for_total_catchup() - vega.submit_order( - market_id=market_4, - trading_key="Key 1", - side="SIDE_BUY", - order_type="TYPE_LIMIT", - pegged_order=PeggedOrder(reference="PEGGED_REFERENCE_MID", offset=5), - time_in_force="TIME_IN_FORCE_GTC", - volume=20, - ) + vega_instance.submit_order( + market_id=markets["market_4"], + trading_key="Key 1", + side="SIDE_BUY", + order_type="TYPE_LIMIT", + pegged_order=PeggedOrder(reference="PEGGED_REFERENCE_BEST_BID", offset=10), + time_in_force="TIME_IN_FORCE_GTC", + volume=40, + ) - vega.forward("2s") - vega.wait_fn(1) - vega.wait_for_total_catchup() + vega_instance.forward("2s") + vega_instance.wait_fn(1) + vega_instance.wait_for_total_catchup() - vega.submit_order( - market_id=market_4, - trading_key="Key 1", - side="SIDE_BUY", - order_type="TYPE_LIMIT", - pegged_order=PeggedOrder(reference="PEGGED_REFERENCE_BEST_BID", offset=10), - time_in_force="TIME_IN_FORCE_GTC", - volume=40, - ) + vega_instance.submit_order( + market_id=markets["market_4"], + trading_key="Key 1", + side="SIDE_SELL", + order_type="TYPE_LIMIT", + pegged_order=PeggedOrder(reference="PEGGED_REFERENCE_BEST_ASK", offset=15), + time_in_force="TIME_IN_FORCE_GTC", + volume=60, + ) - vega.forward("2s") - vega.wait_fn(1) - vega.wait_for_total_catchup() + vega_instance.forward("2s") + vega_instance.wait_fn(1) + vega_instance.wait_for_total_catchup() - vega.submit_order( - market_id=market_4, - trading_key="Key 1", - side="SIDE_SELL", - order_type="TYPE_LIMIT", - pegged_order=PeggedOrder(reference="PEGGED_REFERENCE_BEST_ASK", offset=15), - time_in_force="TIME_IN_FORCE_GTC", - volume=60, - ) + vega_instance.submit_order( + market_id=markets["market_5"], + trading_key="Key 1", + side="SIDE_SELL", + order_type="TYPE_LIMIT", + pegged_order=PeggedOrder(reference="PEGGED_REFERENCE_BEST_ASK", offset=15), + wait=False, + time_in_force="TIME_IN_FORCE_GTC", + volume=60, + ) - vega.forward("2s") - vega.wait_fn(1) - vega.wait_for_total_catchup() + vega_instance.forward("2s") + vega_instance.wait_fn(1) + vega_instance.wait_for_total_catchup() - vega.submit_order( - market_id=market_5, - trading_key="Key 1", - side="SIDE_SELL", - order_type="TYPE_LIMIT", - pegged_order=PeggedOrder(reference="PEGGED_REFERENCE_BEST_ASK", offset=15), - wait=False, - time_in_force="TIME_IN_FORCE_GTC", - volume=60, - ) + vega_instance.submit_order( + trading_key="Key 1", + market_id=markets["market_2"], + time_in_force="TIME_IN_FORCE_GTC", + order_type="TYPE_LIMIT", + side="SIDE_SELL", + volume=10, + price=150, + ) + + vega_instance.wait_fn(1) + vega_instance.wait_for_total_catchup() - vega.forward("2s") - vega.wait_fn(1) - vega.wait_for_total_catchup() + vega_instance.submit_order( + trading_key="Key 1", + market_id=markets["market_2"], + time_in_force="TIME_IN_FORCE_GTC", + order_type="TYPE_LIMIT", + side="SIDE_SELL", + volume=10, + price=160, + ) - vega.submit_order( - trading_key="Key 1", - market_id=market_2, - time_in_force="TIME_IN_FORCE_GTC", - order_type="TYPE_LIMIT", - side="SIDE_SELL", - volume=10, - price=150, - ) - - vega.wait_fn(1) - vega.wait_for_total_catchup() + vega_instance.wait_fn(1) + vega_instance.wait_for_total_catchup() - vega.submit_order( - trading_key="Key 1", - market_id=market_2, - time_in_force="TIME_IN_FORCE_GTC", - order_type="TYPE_LIMIT", - side="SIDE_SELL", - volume=10, - price=160, - ) + vega_instance.submit_order( + trading_key="Key 1", + market_id=markets["market_3"], + time_in_force="TIME_IN_FORCE_GTC", + order_type="TYPE_LIMIT", + side="SIDE_BUY", + volume=10, + price=60, + ) - vega.wait_fn(1) - vega.wait_for_total_catchup() - - vega.submit_order( - trading_key="Key 1", - market_id=market_3, - time_in_force="TIME_IN_FORCE_GTC", - order_type="TYPE_LIMIT", - side="SIDE_BUY", - volume=10, - price=60, - ) - - vega.wait_fn(1) - vega.wait_for_total_catchup() + vega_instance.wait_fn(1) + vega_instance.wait_for_total_catchup() + # Initialize page and setup + + yield vega_instance, markets @pytest.fixture(scope="module") -def page(vega, browser, request): - with init_page(vega, browser, request) as page: +def page(setup_environment, browser, request): + vega_instance, markets = setup_environment + with init_page(vega_instance, browser, request) as page: risk_accepted_setup(page) - auth_setup(vega, page) + auth_setup(vega_instance, page) page.goto("/") page.get_by_test_id("All").click() yield page -# close toast that is still opened after test @pytest.fixture(autouse=True) def after_each(page: Page): yield @@ -381,7 +371,8 @@ def test_order_status_pegged_mid(page: Page): ) -def test_order_amend_order(vega: VegaServiceNull, page: Page): +def test_order_amend_order(setup_environment, page:Page): + vega, markets = setup_environment # 7002-SORD-053 # 7003-MORD-012 # 7003-MORD-014 @@ -402,13 +393,13 @@ def test_order_amend_order(vega: VegaServiceNull, page: Page): ) -def test_order_cancel_single_order(vega: VegaServiceNull, page: Page): +def test_order_cancel_single_order(setup_environment, page:Page): + vega, markets = setup_environment # 7003-MORD-009 # 7003-MORD-010 # 7003-MORD-011 # 7002-SORD-043 page.get_by_test_id("cancel").first.click() - wait_for_toast_confirmation(page, timeout=5000) vega.wait_fn(1) vega.wait_for_total_catchup() @@ -420,7 +411,8 @@ def test_order_cancel_single_order(vega: VegaServiceNull, page: Page): ) -def test_order_cancel_all_orders(vega: VegaServiceNull, page: Page): +def test_order_cancel_all_orders(setup_environment, page:Page): + vega, markets = setup_environment # 7003-MORD-009 # 7003-MORD-010 # 7003-MORD-011 diff --git a/apps/trading/e2e/tests/orderbook/test_orderbook.py b/apps/trading/e2e/tests/orderbook/test_orderbook.py index 83654f490..6e3079057 100644 --- a/apps/trading/e2e/tests/orderbook/test_orderbook.py +++ b/apps/trading/e2e/tests/orderbook/test_orderbook.py @@ -12,7 +12,7 @@ from actions.utils import next_epoch @pytest.fixture(scope="module") def vega(request): with init_vega(request) as vega_instance: - request.addfinalizer(lambda: cleanup_container(vega_instance)) + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) yield vega_instance diff --git a/apps/trading/e2e/tests/perpetual_market/test_perpetuals.py b/apps/trading/e2e/tests/perpetual_market/test_perpetuals.py index 7b12a0b1f..dee986029 100644 --- a/apps/trading/e2e/tests/perpetual_market/test_perpetuals.py +++ b/apps/trading/e2e/tests/perpetual_market/test_perpetuals.py @@ -18,7 +18,7 @@ class TestPerpetuals: @pytest.fixture(scope="class") def vega(self, request): with init_vega(request) as vega_instance: - request.addfinalizer(lambda: cleanup_container(vega_instance)) + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) yield vega_instance @pytest.fixture(scope="class") diff --git a/apps/trading/e2e/tests/positions/test_collateral.py b/apps/trading/e2e/tests/positions/test_collateral.py index 34d2ddc66..94811caba 100644 --- a/apps/trading/e2e/tests/positions/test_collateral.py +++ b/apps/trading/e2e/tests/positions/test_collateral.py @@ -12,7 +12,7 @@ COL_ID_USED = ".ag-center-cols-container [col-id='used'] .ag-cell-value" @pytest.fixture(scope="module") def vega(request): with init_vega(request) as vega_instance: - request.addfinalizer(lambda: cleanup_container(vega_instance)) + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) yield vega_instance diff --git a/apps/trading/e2e/tests/referrals/test_referrals.py b/apps/trading/e2e/tests/referrals/test_referrals.py index 40601f439..dd4c153b5 100644 --- a/apps/trading/e2e/tests/referrals/test_referrals.py +++ b/apps/trading/e2e/tests/referrals/test_referrals.py @@ -15,7 +15,7 @@ BUY_ORDERS = [[1, 106], [1, 107], [1, 108]] @pytest.fixture(scope="module") def vega(request): with init_vega(request) as vega_instance: - request.addfinalizer(lambda: cleanup_container(vega_instance)) + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) yield vega_instance diff --git a/apps/trading/e2e/tests/rewards/test_hoarder_tier_0.py b/apps/trading/e2e/tests/rewards/test_hoarder_tier_0.py index d608069f0..283e3e409 100644 --- a/apps/trading/e2e/tests/rewards/test_hoarder_tier_0.py +++ b/apps/trading/e2e/tests/rewards/test_hoarder_tier_0.py @@ -10,22 +10,24 @@ from vega_sim.null_service import VegaServiceNull @pytest.fixture(scope="module") -def vega(request): +def setup_environment(request, browser): + # Initialize Vega with cleanup with init_vega(request) as vega_instance: - request.addfinalizer(lambda: cleanup_container(vega_instance)) - yield vega_instance + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) + + # Setup the market with the reward program + tDAI_market, tDAI_asset_id = setup_market_with_reward_program(vega_instance) + + # Setup the page + with init_page(vega_instance, browser, request) as page: + risk_accepted_setup(page) + auth_setup(vega_instance, page) + page.goto(REWARDS_URL) + change_keys(page, vega_instance, PARTY_B) + yield page, tDAI_market, tDAI_asset_id -@pytest.fixture(scope="module") -def page(vega, browser, request): - with init_page(vega, browser, request) as page: - risk_accepted_setup(page) - auth_setup(vega, page) - page.goto(REWARDS_URL) - change_keys(page, vega, PARTY_B) - yield page -@pytest.fixture(scope="module", autouse=True) def setup_market_with_reward_program(vega: VegaServiceNull): tDAI_market = setup_continuous_market(vega) PARTY_A, PARTY_B, PARTY_C, PARTY_D = keys(vega) @@ -83,35 +85,37 @@ def setup_market_with_reward_program(vega: VegaServiceNull): return tDAI_market, tDAI_asset_id -@pytest.mark.xdist_group(name="test_rewards_hoarder_tier_0") + def test_network_reward_pot( - page: Page, + setup_environment, ): + page, tDAI_market, tDAI_asset_id = setup_environment expect(page.get_by_test_id(TOTAL_REWARDS)).to_have_text("50.00 tDAI") -@pytest.mark.xdist_group(name="test_rewards_hoarder_tier_0") def test_reward_multiplier( - page: Page, + setup_environment ): + page, tDAI_market, tDAI_asset_id = setup_environment expect(page.get_by_test_id(COMBINED_MULTIPLIERS)).to_have_text("1x") expect(page.get_by_test_id(STREAK_REWARD_MULTIPLIER_VALUE)).to_have_text("1x") expect(page.get_by_test_id(HOARDER_REWARD_MULTIPLIER_VALUE)).to_have_text("1x") -@pytest.mark.xdist_group(name="test_rewards_hoarder_tier_0") + def test_hoarder_bonus( - page: Page, + setup_environment ): + page, tDAI_market, tDAI_asset_id = setup_environment expect(page.get_by_test_id(HOARDER_BONUS_TOTAL_HOARDED)).to_contain_text( "5,000,000" ) -@pytest.mark.xdist_group(name="test_rewards_hoarder_tier_0") def test_reward_history( - page: Page, + setup_environment ): + page, tDAI_market, tDAI_asset_id = setup_environment page.locator('[name="fromEpoch"]').fill("1") expect((page.get_by_role(ROW).locator(PRICE_TAKING_COL_ID)).nth(1)).to_have_text( "100.00100.00%" diff --git a/apps/trading/e2e/tests/rewards/test_hoarder_tier_1.py b/apps/trading/e2e/tests/rewards/test_hoarder_tier_1.py index ecb1c2765..e99776d11 100644 --- a/apps/trading/e2e/tests/rewards/test_hoarder_tier_1.py +++ b/apps/trading/e2e/tests/rewards/test_hoarder_tier_1.py @@ -2,7 +2,13 @@ import pytest from rewards_test_ids import * import vega_sim.proto.vega as vega_protos from playwright.sync_api import Page, expect -from conftest import init_vega, init_page, auth_setup, risk_accepted_setup, cleanup_container +from conftest import ( + init_vega, + init_page, + auth_setup, + risk_accepted_setup, + cleanup_container, +) from fixtures.market import setup_continuous_market from actions.utils import next_epoch, change_keys from wallet_config import MM_WALLET @@ -10,23 +16,21 @@ from vega_sim.null_service import VegaServiceNull @pytest.fixture(scope="module") -def vega(request): +def setup_environment(request, browser): + with init_vega(request) as vega_instance: - request.addfinalizer(lambda: cleanup_container(vega_instance)) - yield vega_instance + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) + + tDAI_market, tDAI_asset_id = setup_market_with_reward_program(vega_instance) + + with init_page(vega_instance, browser, request) as page: + risk_accepted_setup(page) + auth_setup(vega_instance, page) + page.goto(REWARDS_URL) + change_keys(page, vega_instance, PARTY_B) + yield page, tDAI_market, tDAI_asset_id -@pytest.fixture(scope="module") -def page(vega, browser, request): - with init_page(vega, browser, request) as page: - risk_accepted_setup(page) - auth_setup(vega, page) - page.goto(REWARDS_URL) - change_keys(page, vega, PARTY_B) - yield page - - -@pytest.fixture(scope="module", autouse=True) def setup_market_with_reward_program(vega: VegaServiceNull): tDAI_market = setup_continuous_market(vega) PARTY_A, PARTY_B, PARTY_C, PARTY_D = keys(vega) @@ -135,31 +139,29 @@ def setup_market_with_reward_program(vega: VegaServiceNull): return tDAI_market, tDAI_asset_id -@pytest.mark.xdist_group(name="test_rewards_hoarder_tier_1") -def test_network_reward_pot( - page: Page, -): +def test_network_reward_pot(setup_environment): + page, tDAI_market, tDAI_asset_id = setup_environment expect(page.get_by_test_id(TOTAL_REWARDS)).to_have_text("166.66666 tDAI") -@pytest.mark.xdist_group(name="test_rewards_hoarder_tier_1") def test_reward_multiplier( - page: Page, + setup_environment, ): + page, tDAI_market, tDAI_asset_id = setup_environment expect(page.get_by_test_id(COMBINED_MULTIPLIERS)).to_have_text("2x") expect(page.get_by_test_id(STREAK_REWARD_MULTIPLIER_VALUE)).to_have_text("1x") expect(page.get_by_test_id(HOARDER_REWARD_MULTIPLIER_VALUE)).to_have_text("2x") -@pytest.mark.xdist_group(name="test_rewards_hoarder_tier_1") -def test_hoarder_bonus(page: Page): +def test_hoarder_bonus(setup_environment): + page, tDAI_market, tDAI_asset_id = setup_environment expect(page.get_by_test_id(HOARDER_BONUS_TOTAL_HOARDED)).to_contain_text( "16,666,666" ) -@pytest.mark.xdist_group(name="test_rewards_hoarder_tier_1") -def test_reward_history(page: Page): +def test_reward_history(setup_environment): + page, tDAI_market, tDAI_asset_id = setup_environment page.locator('[name="fromEpoch"]').fill("1") expect((page.get_by_role(ROW).locator(PRICE_TAKING_COL_ID)).nth(1)).to_have_text( "299.99999100.00%" @@ -170,4 +172,4 @@ def test_reward_history(page: Page): page.get_by_test_id(EARNED_BY_ME_BUTTON).click() expect((page.get_by_role(ROW).locator(TOTAL_COL_ID)).nth(1)).to_have_text( "166.66666" - ) \ No newline at end of file + ) diff --git a/apps/trading/e2e/tests/rewards/test_rewards_activity_tier_0.py b/apps/trading/e2e/tests/rewards/test_rewards_activity_tier_0.py index 667244e25..3893480e9 100644 --- a/apps/trading/e2e/tests/rewards/test_rewards_activity_tier_0.py +++ b/apps/trading/e2e/tests/rewards/test_rewards_activity_tier_0.py @@ -16,23 +16,23 @@ from vega_sim.null_service import VegaServiceNull @pytest.fixture(scope="module") -def vega(request): +def setup_environment(request, browser): + with init_vega(request) as vega_instance: - request.addfinalizer(lambda: cleanup_container(vega_instance)) - yield vega_instance + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) + + tDAI_market, tDAI_asset_id = setup_market_with_reward_program(vega_instance) + + with init_page(vega_instance, browser, request) as page: + risk_accepted_setup(page) + auth_setup(vega_instance, page) + page.goto(REWARDS_URL) + change_keys(page, vega_instance, PARTY_B) + yield page, tDAI_market, tDAI_asset_id -@pytest.fixture(scope="module") -def page(vega, browser, request): - with init_page(vega, browser, request) as page: - risk_accepted_setup(page) - auth_setup(vega, page) - page.goto(REWARDS_URL) - change_keys(page, vega, PARTY_B) - yield page -@pytest.fixture(scope="module", autouse=True) def setup_market_with_reward_program(vega: VegaServiceNull): tDAI_market = setup_continuous_market(vega) PARTY_A, PARTY_B, PARTY_C, PARTY_D = keys(vega) @@ -90,19 +90,17 @@ def setup_market_with_reward_program(vega: VegaServiceNull): return tDAI_market, tDAI_asset_id -@pytest.mark.xdist_group(name="test_rewards_activity_tier_0") def test_network_reward_pot( - page: Page, + setup_environment ): + page, tDAI_market, tDAI_asset_id = setup_environment expect(page.get_by_test_id(TOTAL_REWARDS)).to_have_text("50.00 tDAI") - page.pause() -@pytest.mark.xdist_group(name="test_rewards_activity_tier_0") def test_reward_multiplier( - page: Page, + setup_environment ): - page.pause() + page, tDAI_market, tDAI_asset_id = setup_environment expect(page.get_by_test_id(COMBINED_MULTIPLIERS)).to_have_text("1x") expect(page.get_by_test_id(STREAK_REWARD_MULTIPLIER_VALUE)).to_have_text("1x") expect(page.get_by_test_id(HOARDER_REWARD_MULTIPLIER_VALUE)).to_have_text("1x") diff --git a/apps/trading/e2e/tests/rewards/test_rewards_activity_tier_1.py b/apps/trading/e2e/tests/rewards/test_rewards_activity_tier_1.py index 80467326e..21a4a2bda 100644 --- a/apps/trading/e2e/tests/rewards/test_rewards_activity_tier_1.py +++ b/apps/trading/e2e/tests/rewards/test_rewards_activity_tier_1.py @@ -10,22 +10,21 @@ from vega_sim.null_service import VegaServiceNull @pytest.fixture(scope="module") -def vega(request): +def setup_environment(request, browser): + with init_vega(request) as vega_instance: - request.addfinalizer(lambda: cleanup_container(vega_instance)) - yield vega_instance + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) + + tDAI_market, tDAI_asset_id = setup_market_with_reward_program(vega_instance) + + with init_page(vega_instance, browser, request) as page: + risk_accepted_setup(page) + auth_setup(vega_instance, page) + page.goto(REWARDS_URL) + change_keys(page, vega_instance, PARTY_B) + yield page, tDAI_market, tDAI_asset_id -@pytest.fixture(scope="module") -def page(vega, browser, request): - with init_page(vega, browser, request) as page: - risk_accepted_setup(page) - auth_setup(vega, page) - page.goto(REWARDS_URL) - change_keys(page, vega, PARTY_B) - yield page - -@pytest.fixture(scope="module", autouse=True) def setup_market_with_reward_program(vega: VegaServiceNull): tDAI_market = setup_continuous_market(vega) PARTY_A, PARTY_B, PARTY_C, PARTY_D = keys(vega) @@ -128,34 +127,36 @@ def setup_market_with_reward_program(vega: VegaServiceNull): return tDAI_market, tDAI_asset_id -@pytest.mark.xdist_group(name="test_rewards_activity_tier_1") -def test_network_reward_pot(page: Page): - + +def test_network_reward_pot(setup_environment): + page, tDAI_market, tDAI_asset_id = setup_environment expect(page.get_by_test_id(TOTAL_REWARDS)).to_have_text("116.66666 tDAI") -@pytest.mark.xdist_group(name="test_rewards_activity_tier_1") + def test_reward_multiplier( - page: Page, + setup_environment ): + page, tDAI_market, tDAI_asset_id = setup_environment expect(page.get_by_test_id(COMBINED_MULTIPLIERS)).to_have_text("2x") expect(page.get_by_test_id(STREAK_REWARD_MULTIPLIER_VALUE)).to_have_text("2x") expect(page.get_by_test_id(HOARDER_REWARD_MULTIPLIER_VALUE)).to_have_text("1x") -@pytest.mark.xdist_group(name="test_rewards_activity_tier_1") def test_activity_streak( - page: Page, + setup_environment ): + page, tDAI_market, tDAI_asset_id = setup_environment expect(page.get_by_test_id(EPOCH_STREAK)).to_have_text( "Active trader: 7 epochs so far (Tier 1 as of last epoch)" ) -@pytest.mark.xdist_group(name="test_rewards_activity_tier_1") + def test_reward_history( - page: Page, + setup_environment ): + page, tDAI_market, tDAI_asset_id = setup_environment page.locator('[name="fromEpoch"]').fill("1") expect((page.get_by_role(ROW).locator(PRICE_TAKING_COL_ID)).nth(1)).to_have_text( "300.00100.00%" @@ -167,10 +168,11 @@ def test_reward_history( ) -@pytest.mark.xdist_group(name="test_rewards_activity_tier_1") + def test_redeem( - page: Page, + setup_environment ): + page, tDAI_market, tDAI_asset_id = setup_environment page.get_by_test_id("redeem-rewards-button").click() available_to_withdraw = page.get_by_test_id( "available-to-withdraw-value" diff --git a/apps/trading/e2e/tests/rewards/test_rewards_combo_tier_1.py b/apps/trading/e2e/tests/rewards/test_rewards_combo_tier_1.py index a2263dcc9..bb4307ee9 100644 --- a/apps/trading/e2e/tests/rewards/test_rewards_combo_tier_1.py +++ b/apps/trading/e2e/tests/rewards/test_rewards_combo_tier_1.py @@ -9,24 +9,21 @@ from wallet_config import MM_WALLET from vega_sim.null_service import VegaServiceNull @pytest.fixture(scope="module") -def vega(request): +def setup_environment(request, browser): + with init_vega(request) as vega_instance: - request.addfinalizer(lambda: cleanup_container(vega_instance)) - yield vega_instance + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) + + tDAI_market, tDAI_asset_id = setup_market_with_reward_program(vega_instance) + + with init_page(vega_instance, browser, request) as page: + risk_accepted_setup(page) + auth_setup(vega_instance, page) + page.goto(REWARDS_URL) + change_keys(page, vega_instance, PARTY_B) + yield page, tDAI_market, tDAI_asset_id - -@pytest.fixture(scope="module") -def page(vega, browser, request): - with init_page(vega, browser, request) as page: - risk_accepted_setup(page) - auth_setup(vega, page) - page.goto(REWARDS_URL) - change_keys(page, vega, PARTY_B) - yield page - - -@pytest.fixture(scope="module", autouse=True) def setup_market_with_reward_program(vega: VegaServiceNull): tDAI_market = setup_continuous_market(vega) PARTY_A, PARTY_B, PARTY_C, PARTY_D = keys(vega) @@ -140,16 +137,18 @@ def setup_market_with_reward_program(vega: VegaServiceNull): return tDAI_market, tDAI_asset_id -@pytest.mark.xdist_group(name="test_rewards_combo_tier_1") -def test_network_reward_pot( page: Page + +def test_network_reward_pot( setup_environment ): + page, tDAI_market, tDAI_asset_id = setup_environment expect(page.get_by_test_id(TOTAL_REWARDS)).to_have_text("183.33333 tDAI") -@pytest.mark.xdist_group(name="test_rewards_combo_tier_1") + def test_reward_multiplier( - page: Page, + setup_environment ): + page, tDAI_market, tDAI_asset_id = setup_environment expect(page.get_by_test_id(COMBINED_MULTIPLIERS)).to_have_text("4x") expect(page.get_by_test_id(STREAK_REWARD_MULTIPLIER_VALUE)).to_have_text( "2x" @@ -159,10 +158,11 @@ def test_reward_multiplier( ) -@pytest.mark.xdist_group(name="test_rewards_combo_tier_1") + def test_reward_history( - page: Page, + setup_environment ): + page, tDAI_market, tDAI_asset_id = setup_environment page.locator('[name="fromEpoch"]').fill("1") expect((page.get_by_role(ROW).locator(PRICE_TAKING_COL_ID)).nth(1)).to_have_text( "299.99999100.00%" diff --git a/apps/trading/e2e/tests/settings/test_settings.py b/apps/trading/e2e/tests/settings/test_settings.py index aa0d3f609..47e16ae24 100644 --- a/apps/trading/e2e/tests/settings/test_settings.py +++ b/apps/trading/e2e/tests/settings/test_settings.py @@ -6,7 +6,7 @@ from conftest import init_vega, cleanup_container @pytest.fixture(scope="module") def vega(request): with init_vega(request) as vega_instance: - request.addfinalizer(lambda: cleanup_container(vega_instance)) + request.addfinalizer(lambda: cleanup_container(vega_instance, request)) yield vega_instance