chore(trading): remove container cleanup

This commit is contained in:
bwallacee 2024-03-07 14:18:55 +00:00
parent 20b25bbb6a
commit 1e0fdb11ee
No known key found for this signature in database
GPG Key ID: E1234921C80BFE6D
28 changed files with 349 additions and 299 deletions

View File

@ -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))
request.addfinalizer(lambda: cleanup_container(vega_instance))
yield vega_instance
```

View File

@ -67,10 +67,23 @@ class CustomHttpRequestHandler(http.server.SimpleHTTPRequestHandler):
@contextmanager
def init_vega(request=None):
local_server = os.getenv("LOCAL_SERVER", "false").lower() == "true"
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
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}")
logger.info("Starting VegaServiceNull", extra={"worker_id": os.getenv("PYTEST_XDIST_WORKER", "default")})
vega_service_args = {
"run_with_console": False,
"launch_graphql": False,
@ -80,28 +93,38 @@ 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})
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")})
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")},
)
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:
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}")
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}")
@contextmanager
@ -159,36 +182,35 @@ 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))
request.addfinalizer(lambda: cleanup_container(vega_instance))
yield vega_instance
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}")
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)}")
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
@ -304,21 +326,16 @@ 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()
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)
@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

View File

@ -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, request))
request.addfinalizer(lambda: cleanup_container(vega_instance))
yield vega_instance

View File

@ -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, request))
request.addfinalizer(lambda: cleanup_container(vega_instance))
yield vega_instance
@pytest.fixture(scope="class")

View File

@ -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))
request.addfinalizer(lambda: cleanup_container(vega_instance))
yield vega_instance

View File

@ -1,7 +1,7 @@
import pytest
import threading
from typing import Tuple, Generator
from fees_test_ids import *
from playwright.sync_api import Page, expect
from playwright.sync_api import expect, Page
from vega_sim.null_service import VegaServiceNull
from actions.vega import submit_order
from wallet_config import MM_WALLET
@ -15,19 +15,25 @@ 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 setup_environment(request, browser):
# Initialize Vega with cleanup
with init_vega(request) as vega_instance:
request.addfinalizer(lambda: cleanup_container(vega_instance, request))
# Setup the market with volume and referral discount programs
@pytest.fixture(scope="module")
def setup_environment(
request, browser
) -> Generator[Tuple[VegaServiceNull, str, Page], None, None]:
with init_vega(request) as vega_instance:
request.addfinalizer(lambda: cleanup_container(vega_instance))
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},
{
"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,
)
@ -65,30 +71,15 @@ def setup_environment(request, browser):
submit_order(vega_instance, "Key 1", market, "SIDE_BUY", 2, 110)
forward_time(vega_instance, True if _ < 2 - 1 else False)
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]
print("Non-Daemonic Threads:")
for thread in non_daemonic_threads:
print(f"{thread.name} (ID: {thread.ident})")
# Example usage
list_non_daemonic_threads()
# 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(setup_environment):
def test_fees_page_discount_program_my_trading_fees(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto("/#/fees")
expect(page.get_by_test_id(ADJUSTED_FEES)).to_have_text("6.432%-6.432%")
@ -100,10 +91,9 @@ def test_fees_page_discount_program_my_trading_fees(setup_environment):
expect(page.get_by_test_id(LIQUIDITY_FEES)).to_have_text("Liquidity0%-0%")
@pytest.mark.xdist_group(name="test_fees_combo_tier_2")
def test_fees_page_discount_program_total_discount(
setup_environment,
):
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto("/#/fees")
expect(page.get_by_test_id(TOTAL_DISCOUNT)).to_have_text("36%")
@ -117,8 +107,9 @@ 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(setup_environment):
def test_fees_page_discount_program_fees_by_market(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto("/#/fees")
pinned = page.locator(PINNED_ROW_LOCATOR)
@ -131,10 +122,9 @@ def test_fees_page_discount_program_fees_by_market(setup_environment):
expect(row.locator(COL_TOTAL_FEE)).to_have_text("10.05%")
@pytest.mark.xdist_group(name="test_fees_combo_tier_2")
def test_deal_ticket_discount_program(
setup_environment
):
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto(f"/#/markets/{market}")
page.get_by_test_id(ORDER_SIZE).fill("1")
@ -155,10 +145,7 @@ def test_deal_ticket_discount_program(
expect(tooltip.get_by_test_id(TOTAL_FEE_VALUE)).to_have_text("0.06432 tDAI")
@pytest.mark.xdist_group(name="test_fees_combo_tier_2")
def test_fills_taker_discount_program(
setup_environment
):
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()
@ -171,10 +158,9 @@ def test_fills_taker_discount_program(
expect(row.locator(COL_FEE_DISCOUNT)).to_have_text("7.48926 tDAI")
@pytest.mark.xdist_group(name="test_fees_combo_tier_2")
def test_fills_maker_discount_program(
setup_environment
):
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto(f"/#/markets/{market}")
change_keys(page, vega, MM_WALLET.name)
@ -188,9 +174,9 @@ def test_fills_maker_discount_program(
expect(row.locator(COL_FEE_DISCOUNT)).to_have_text("7.452 tDAI")
@pytest.mark.xdist_group(name="test_fees_combo_tier_2")
def test_fills_maker_fee_tooltip_discount_program(setup_environment
):
def test_fills_maker_fee_tooltip_discount_program(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto(f"/#/markets/{market}")
change_keys(page, vega, MM_WALLET.name)
@ -204,10 +190,9 @@ def test_fills_maker_fee_tooltip_discount_program(setup_environment
)
@pytest.mark.xdist_group(name="test_fees_combo_tier_2")
def test_fills_taker_fee_tooltip_discount_program(
setup_environment,
):
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto(f"/#/markets/{market}")
page.get_by_test_id(FILLS).click()

View File

@ -1,4 +1,5 @@
import pytest
from typing import Tuple, Generator
from fees_test_ids import *
from playwright.sync_api import Page, expect
from vega_sim.null_service import VegaServiceNull
@ -16,10 +17,11 @@ from fixtures.market import setup_continuous_market
@pytest.fixture(scope="module")
def setup_environment(request, browser):
# Initialize Vega and setup for cleanup
def setup_environment(
request, browser
) -> Generator[Tuple[VegaServiceNull, str, Page], None, None]:
with init_vega(request) as vega_instance:
request.addfinalizer(lambda: cleanup_container(vega_instance, request))
request.addfinalizer(lambda: cleanup_container(vega_instance))
# Setup the market with the referral discount program
market = setup_continuous_market(vega_instance, custom_quantum=100000)
@ -55,15 +57,15 @@ def setup_environment(request, browser):
submit_order(vega_instance, "Key 1", market, "SIDE_BUY", 1, 110)
forward_time(vega_instance, True if _ < 2 - 1 else False)
# 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(setup_environment):
def test_fees_page_discount_program_my_trading_fees(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto("/#/fees")
expect(page.get_by_test_id(ADJUSTED_FEES)).to_have_text("9.045%-9.045%")
@ -75,8 +77,9 @@ def test_fees_page_discount_program_my_trading_fees(setup_environment):
expect(page.get_by_test_id(LIQUIDITY_FEES)).to_have_text("Liquidity0%-0%")
@pytest.mark.xdist_group(name="test_fees_referral_tier_1")
def test_fees_page_discount_program_total_discount(setup_environment):
def test_fees_page_discount_program_total_discount(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto("/#/fees")
expect(page.get_by_test_id(TOTAL_DISCOUNT)).to_have_text("10%")
@ -90,16 +93,18 @@ def test_fees_page_discount_program_total_discount(setup_environment):
)
@pytest.mark.xdist_group(name="test_fees_referral_tier_1")
def test_fees_page_referral_discount_program_referral_benefits(setup_environment):
def test_fees_page_referral_discount_program_referral_benefits(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
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(setup_environment):
def test_fees_page_discount_program_discount(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto("/#/fees")
expect(page.get_by_test_id(TIER_VALUE_0)).to_have_text("1")
@ -116,8 +121,9 @@ def test_fees_page_discount_program_discount(setup_environment):
expect(page.get_by_test_id("your-referral-tier-0").nth(1)).to_have_text("Your tier")
@pytest.mark.xdist_group(name="test_fees_referral_tier_1")
def test_fees_page_discount_program_fees_by_market(setup_environment):
def test_fees_page_discount_program_fees_by_market(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto("/#/fees")
pinned = page.locator(PINNED_ROW_LOCATOR)
@ -130,8 +136,9 @@ def test_fees_page_discount_program_fees_by_market(setup_environment):
expect(row.locator(COL_TOTAL_FEE)).to_have_text("10.05%")
@pytest.mark.xdist_group(name="test_fees_referral_tier_1")
def test_deal_ticket_discount_program(setup_environment):
def test_deal_ticket_discount_program(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto(f"/#/markets/{market}")
page.get_by_test_id(ORDER_SIZE).fill("1")
@ -152,8 +159,9 @@ def test_deal_ticket_discount_program(setup_environment):
expect(tooltip.get_by_test_id(TOTAL_FEE_VALUE)).to_have_text("0.09045 tDAI")
@pytest.mark.xdist_group(name="test_fees_referral_tier_1")
def test_fills_taker_discount_program(setup_environment):
def test_fills_taker_discount_program(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto(f"/#/markets/{market}")
page.get_by_test_id(FILLS).click()
@ -166,8 +174,9 @@ def test_fills_taker_discount_program(setup_environment):
expect(row.locator(COL_FEE_DISCOUNT)).to_have_text("1.04017 tDAI")
@pytest.mark.xdist_group(name="test_fees_referral_tier_1")
def test_fills_maker_discount_program(setup_environment):
def test_fills_maker_discount_program(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto(f"/#/markets/{market}")
change_keys(page, vega, MM_WALLET.name)
@ -181,8 +190,9 @@ def test_fills_maker_discount_program(setup_environment):
expect(row.locator(COL_FEE_DISCOUNT)).to_have_text("1.035 tDAI")
@pytest.mark.xdist_group(name="test_fees_referral_tier_1")
def test_fills_maker_fee_tooltip_discount_program(setup_environment):
def test_fills_maker_fee_tooltip_discount_program(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto(f"/#/markets/{market}")
change_keys(page, vega, MM_WALLET.name)
@ -196,8 +206,9 @@ def test_fills_maker_fee_tooltip_discount_program(setup_environment):
)
@pytest.mark.xdist_group(name="test_fees_referral_tier_1")
def test_fills_taker_fee_tooltip_discount_program(setup_environment):
def test_fills_taker_fee_tooltip_discount_program(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto(f"/#/markets/{market}")
page.get_by_test_id(FILLS).click()

View File

@ -1,5 +1,6 @@
import pytest
from fees_test_ids import *
from typing import Tuple, Generator
from playwright.sync_api import Page, expect
from vega_sim.null_service import VegaServiceNull
from actions.vega import submit_order
@ -16,10 +17,11 @@ from fixtures.market import setup_continuous_market
@pytest.fixture(scope="module")
def setup_environment(request, browser):
# Initialize Vega with cleanup
def setup_environment(
request, browser
) -> Generator[Tuple[VegaServiceNull, str, Page], None, None]:
with init_vega(request) as vega_instance:
request.addfinalizer(lambda: cleanup_container(vega_instance, request))
request.addfinalizer(lambda: cleanup_container(vega_instance))
# Setup market with referral discount program
market = setup_continuous_market(vega_instance, custom_quantum=100000)
@ -55,15 +57,15 @@ def setup_environment(request, browser):
submit_order(vega_instance, "Key 1", market, "SIDE_BUY", 2, 110)
forward_time(vega_instance, True if _ < 2 - 1 else False)
# 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(setup_environment):
def test_fees_page_discount_program_my_trading_fees(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto("/#/fees")
expect(page.get_by_test_id(ADJUSTED_FEES)).to_have_text("8.04%-8.04%")
@ -75,8 +77,9 @@ def test_fees_page_discount_program_my_trading_fees(setup_environment):
expect(page.get_by_test_id(LIQUIDITY_FEES)).to_have_text("Liquidity0%-0%")
@pytest.mark.xdist_group(name="test_fees_referral_tier_2")
def test_fees_page_discount_program_total_discount(setup_environment):
def test_fees_page_discount_program_total_discount(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto("/#/fees")
expect(page.get_by_test_id(TOTAL_DISCOUNT)).to_have_text("20%")
@ -90,16 +93,18 @@ def test_fees_page_discount_program_total_discount(setup_environment):
)
@pytest.mark.xdist_group(name="test_fees_referral_tier_2")
def test_fees_page_referral_discount_program_referral_benefits(setup_environment):
def test_fees_page_referral_discount_program_referral_benefits(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
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(setup_environment):
def test_fees_page_discount_program_discount(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto("/#/fees")
expect(page.get_by_test_id(TIER_VALUE_0)).to_have_text("1")
@ -116,8 +121,9 @@ def test_fees_page_discount_program_discount(setup_environment):
expect(page.get_by_test_id("your-referral-tier-1").nth(1)).to_have_text("Your tier")
@pytest.mark.xdist_group(name="test_fees_referral_tier_2")
def test_fees_page_discount_program_fees_by_market(setup_environment):
def test_fees_page_discount_program_fees_by_market(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto("/#/fees")
pinned = page.locator(PINNED_ROW_LOCATOR)
@ -130,8 +136,9 @@ def test_fees_page_discount_program_fees_by_market(setup_environment):
expect(row.locator(COL_TOTAL_FEE)).to_have_text("10.05%")
@pytest.mark.xdist_group(name="test_fees_referral_tier_2")
def test_deal_ticket_discount_program(setup_environment):
def test_deal_ticket_discount_program(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto(f"/#/markets/{market}")
page.get_by_test_id(ORDER_SIZE).fill("1")
@ -152,8 +159,9 @@ def test_deal_ticket_discount_program(setup_environment):
expect(tooltip.get_by_test_id(TOTAL_FEE_VALUE)).to_have_text("0.0804 tDAI")
@pytest.mark.xdist_group(name="test_fees_referral_tier_2")
def test_fills_taker_discount_program(setup_environment):
def test_fills_taker_discount_program(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto(f"/#/markets/{market}")
page.get_by_test_id(FILLS).click()
@ -166,8 +174,9 @@ def test_fills_taker_discount_program(setup_environment):
expect(row.locator(COL_FEE_DISCOUNT)).to_have_text("4.1607 tDAI")
@pytest.mark.xdist_group(name="test_fees_referral_tier_2")
def test_fills_maker_discount_program(setup_environment):
def test_fills_maker_discount_program(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto(f"/#/markets/{market}")
change_keys(page, vega, MM_WALLET.name)
@ -181,8 +190,9 @@ def test_fills_maker_discount_program(setup_environment):
expect(row.locator(COL_FEE_DISCOUNT)).to_have_text("4.14 tDAI")
@pytest.mark.xdist_group(name="test_fees_referral_tier_2")
def test_fills_maker_fee_tooltip_discount_program(setup_environment):
def test_fills_maker_fee_tooltip_discount_program(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto(f"/#/markets/{market}")
change_keys(page, vega, MM_WALLET.name)
@ -196,8 +206,9 @@ def test_fills_maker_fee_tooltip_discount_program(setup_environment):
)
@pytest.mark.xdist_group(name="test_fees_referral_tier_2")
def test_fills_taker_fee_tooltip_discount_program(setup_environment):
def test_fills_taker_fee_tooltip_discount_program(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto(f"/#/markets/{market}")
page.get_by_test_id(FILLS).click()

View File

@ -1,5 +1,6 @@
import pytest
from fees_test_ids import *
from typing import Tuple, Generator
from playwright.sync_api import Page, expect
from vega_sim.null_service import VegaServiceNull
from actions.vega import submit_order
@ -16,18 +17,25 @@ from fixtures.market import setup_continuous_market
@pytest.fixture(scope="module")
def setup_vega_and_market(request, browser):
# Initialize Vega with cleanup
def setup_environment(
request, browser
) -> Generator[Tuple[VegaServiceNull, str, Page], None, None]:
with init_vega(request) as vega_instance:
request.addfinalizer(lambda: cleanup_container(vega_instance, request))
request.addfinalizer(lambda: cleanup_container(vega_instance))
# 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},
{
"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,
)
@ -44,8 +52,10 @@ def setup_vega_and_market(request, browser):
yield vega_instance, market, page
def test_fees_page_discount_program_my_trading_fees(setup_vega_and_market):
vega, market, page = setup_vega_and_market
def test_fees_page_discount_program_my_trading_fees(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
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(
@ -56,11 +66,10 @@ def test_fees_page_discount_program_my_trading_fees(setup_vega_and_market):
expect(page.get_by_test_id(LIQUIDITY_FEES)).to_have_text("Liquidity0%-0%")
def test_fees_page_discount_program_total_discount(
setup_vega_and_market
):
vega, market, page = setup_vega_and_market
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
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 discount10%")
@ -73,22 +82,20 @@ def test_fees_page_discount_program_total_discount(
)
def test_fees_page_volume_discount_program_my_current_volume(
setup_vega_and_market
):
vega, market, page = setup_vega_and_market
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
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")
def test_fees_page_discount_program_discount(
setup_vega_and_market
):
vega, market, page = setup_vega_and_market
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
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")
@ -101,9 +108,10 @@ def test_fees_page_discount_program_discount(
expect(page.get_by_test_id("your-volume-tier-0").nth(1)).to_have_text("Your tier")
def test_fees_page_discount_program_fees_by_market(setup_vega_and_market):
vega, market, page = setup_vega_and_market
def test_fees_page_discount_program_fees_by_market(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto("/#/fees")
pinned = page.locator(PINNED_ROW_LOCATOR)
row = page.locator(ROW_LOCATOR)
@ -115,11 +123,10 @@ def test_fees_page_discount_program_fees_by_market(setup_vega_and_market):
expect(row.locator(COL_TOTAL_FEE)).to_have_text("10.05%")
def test_deal_ticket_discount_program_testing(
setup_vega_and_market
):
vega, market, page = setup_vega_and_market
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
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")
@ -139,10 +146,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(
setup_vega_and_market
):
vega, market, page = setup_vega_and_market
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
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
@ -154,10 +162,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(
setup_vega_and_market
):
vega, market, page = setup_vega_and_market
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto(f"/#/markets/{market}")
change_keys(page, vega, MM_WALLET.name)
page.get_by_test_id(FILLS).click()
@ -170,11 +179,10 @@ def test_fills_maker_discount_program(
expect(row.locator(COL_FEE_DISCOUNT)).to_have_text("1.035 tDAI")
def test_fills_maker_fee_tooltip_discount_program(
setup_vega_and_market
):
vega, market, page = setup_vega_and_market
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto(f"/#/markets/{market}")
change_keys(page, vega, MM_WALLET.name)
page.get_by_test_id(FILLS).click()
@ -187,11 +195,10 @@ def test_fills_maker_fee_tooltip_discount_program(
)
def test_fills_taker_fee_tooltip_discount_program(
setup_vega_and_market
):
vega, market, page = setup_vega_and_market
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
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

View File

@ -1,5 +1,6 @@
import pytest
from fees_test_ids import *
from typing import Tuple, Generator
from playwright.sync_api import Page, expect
from vega_sim.null_service import VegaServiceNull
from actions.vega import submit_order
@ -16,10 +17,11 @@ from fixtures.market import setup_continuous_market
@pytest.fixture(scope="module")
def setup_environment(request, browser):
# Initialize Vega and setup cleanup
def setup_environment(
request, browser
) -> Generator[Tuple[VegaServiceNull, str, Page], None, None]:
with init_vega(request) as vega_instance:
request.addfinalizer(lambda: cleanup_container(vega_instance, request))
request.addfinalizer(lambda: cleanup_container(vega_instance))
# Setup the market with volume discount program
market = setup_continuous_market(vega_instance, custom_quantum=100000)
@ -50,8 +52,9 @@ def setup_environment(request, browser):
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(setup_environment):
def test_fees_page_discount_program_my_trading_fees(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto("/#/fees")
expect(page.get_by_test_id(ADJUSTED_FEES)).to_have_text("8.04%-8.04%")
@ -63,8 +66,9 @@ def test_fees_page_discount_program_my_trading_fees(setup_environment):
expect(page.get_by_test_id(LIQUIDITY_FEES)).to_have_text("Liquidity0%-0%")
@pytest.mark.xdist_group(name="test_fees_volume_tier_2")
def test_fees_page_discount_program_total_discount(setup_environment):
def test_fees_page_discount_program_total_discount(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto("/#/fees")
expect(page.get_by_test_id(TOTAL_DISCOUNT)).to_have_text("20%")
@ -78,16 +82,18 @@ def test_fees_page_discount_program_total_discount(setup_environment):
)
@pytest.mark.xdist_group(name="test_fees_volume_tier_2")
def test_fees_page_volume_discount_program_my_current_volume(setup_environment):
def test_fees_page_volume_discount_program_my_current_volume(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
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(setup_environment):
def test_fees_page_discount_program_discount(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto("/#/fees")
expect(page.get_by_test_id(TIER_VALUE_0)).to_have_text("1")
@ -101,7 +107,6 @@ def test_fees_page_discount_program_discount(setup_environment):
expect(page.get_by_test_id("your-volume-tier-1").nth(1)).to_have_text("Your tier")
@pytest.mark.xdist_group(name="test_fees_volume_tier_2")
def test_fees_page_discount_program_fees_by_market(setup_environment):
vega, market, page = setup_environment
page.goto("/#/fees")
@ -115,8 +120,9 @@ def test_fees_page_discount_program_fees_by_market(setup_environment):
expect(row.locator(COL_TOTAL_FEE)).to_have_text("10.05%")
@pytest.mark.xdist_group(name="test_fees_volume_tier_2")
def test_deal_ticket_discount_program(setup_environment):
def test_deal_ticket_discount_program(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto(f"/#/markets/{market}")
page.get_by_test_id(ORDER_SIZE).fill("1")
@ -137,8 +143,9 @@ def test_deal_ticket_discount_program(setup_environment):
expect(tooltip.get_by_test_id(TOTAL_FEE_VALUE)).to_have_text("0.0804 tDAI")
@pytest.mark.xdist_group(name="test_fees_volume_tier_2")
def test_fills_taker_discount_program(setup_environment):
def test_fills_taker_discount_program(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto(f"/#/markets/{market}")
page.get_by_test_id(FILLS).click()
@ -153,10 +160,9 @@ def test_fills_taker_discount_program(setup_environment):
expect(row.locator(COL_FEE_DISCOUNT)).to_have_text("2.08035 tDAI")
@pytest.mark.xdist_group(name="test_fees_volume_tier_2")
def test_fills_maker_discount_program(
setup_environment,
):
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto(f"/#/markets/{market}")
change_keys(page, vega, MM_WALLET.name)
@ -170,8 +176,9 @@ def test_fills_maker_discount_program(
expect(row.locator(COL_FEE_DISCOUNT)).to_have_text("2.07 tDAI")
@pytest.mark.xdist_group(name="test_fees_volume_tier_2")
def test_fills_maker_fee_tooltip_discount_program(setup_environment):
def test_fills_maker_fee_tooltip_discount_program(
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto(f"/#/markets/{market}")
change_keys(page, vega, MM_WALLET.name)
@ -185,10 +192,9 @@ def test_fills_maker_fee_tooltip_discount_program(setup_environment):
)
@pytest.mark.xdist_group(name="test_fees_volume_tier_2")
def test_fills_taker_fee_tooltip_discount_program(
setup_environment,
):
setup_environment: Tuple[VegaServiceNull, str, Page],
) -> None:
vega, market, page = setup_environment
page.goto(f"/#/markets/{market}")
page.get_by_test_id(FILLS).click()

View File

@ -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))
request.addfinalizer(lambda: cleanup_container(vega_instance))
yield vega_instance

View File

@ -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))
request.addfinalizer(lambda: cleanup_container(vega_instance))
yield vega_instance

View File

@ -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))
request.addfinalizer(lambda: cleanup_container(vega_instance))
yield vega_instance

View File

@ -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))
request.addfinalizer(lambda: cleanup_container(vega_instance))
yield vega_instance

View File

@ -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))
request.addfinalizer(lambda: cleanup_container(vega_instance))
yield vega_instance

View File

@ -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))
request.addfinalizer(lambda: cleanup_container(vega_instance))
yield vega_instance

View File

@ -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))
request.addfinalizer(lambda: cleanup_container(vega_instance))
yield vega_instance

View File

@ -13,7 +13,7 @@ order_tab = "tab-orders"
def setup_environment(request, browser):
# Initialize Vega with cleanup
with init_vega(request) as vega_instance:
request.addfinalizer(lambda: cleanup_container(vega_instance, request))
request.addfinalizer(lambda: cleanup_container(vega_instance))
# Setup multiple markets
markets = {

View File

@ -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))
request.addfinalizer(lambda: cleanup_container(vega_instance))
yield vega_instance

View File

@ -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))
request.addfinalizer(lambda: cleanup_container(vega_instance))
yield vega_instance
@pytest.fixture(scope="class")

View File

@ -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))
request.addfinalizer(lambda: cleanup_container(vega_instance))
yield vega_instance

View File

@ -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))
request.addfinalizer(lambda: cleanup_container(vega_instance))
yield vega_instance

View File

@ -1,8 +1,15 @@
import pytest
import vega_sim.proto.vega as vega_protos
from typing import Tuple, Generator
from rewards_test_ids import *
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,15 +17,12 @@ from vega_sim.null_service import VegaServiceNull
@pytest.fixture(scope="module")
def setup_environment(request, browser):
# Initialize Vega with cleanup
def setup_environment(request, browser) -> Generator[Tuple[Page, str, str], None, None]:
with init_vega(request) as vega_instance:
request.addfinalizer(lambda: cleanup_container(vega_instance, request))
request.addfinalizer(lambda: cleanup_container(vega_instance))
# 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)
@ -27,7 +31,6 @@ def setup_environment(request, browser):
yield page, tDAI_market, tDAI_asset_id
def setup_market_with_reward_program(vega: VegaServiceNull):
tDAI_market = setup_continuous_market(vega)
PARTY_A, PARTY_B, PARTY_C, PARTY_D = keys(vega)
@ -85,27 +88,25 @@ def setup_market_with_reward_program(vega: VegaServiceNull):
return tDAI_market, tDAI_asset_id
def test_network_reward_pot(
setup_environment,
):
setup_environment: Tuple[Page, str, str],
) -> None:
page, tDAI_market, tDAI_asset_id = setup_environment
expect(page.get_by_test_id(TOTAL_REWARDS)).to_have_text("50.00 tDAI")
def test_reward_multiplier(
setup_environment
):
setup_environment: Tuple[Page, str, str],
) -> None:
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")
def test_hoarder_bonus(
setup_environment
):
setup_environment: Tuple[Page, str, str],
) -> None:
page, tDAI_market, tDAI_asset_id = setup_environment
expect(page.get_by_test_id(HOARDER_BONUS_TOTAL_HOARDED)).to_contain_text(
"5,000,000"
@ -113,8 +114,8 @@ def test_hoarder_bonus(
def test_reward_history(
setup_environment
):
setup_environment: Tuple[Page, str, str],
) -> None:
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(
@ -122,4 +123,4 @@ def test_reward_history(
)
expect((page.get_by_role(ROW).locator(TOTAL_COL_ID)).nth(1)).to_have_text("100.00")
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("50.00")
expect((page.get_by_role(ROW).locator(TOTAL_COL_ID)).nth(1)).to_have_text("50.00")

View File

@ -1,5 +1,6 @@
import pytest
from rewards_test_ids import *
from typing import Tuple, Generator
import vega_sim.proto.vega as vega_protos
from playwright.sync_api import Page, expect
from conftest import (
@ -16,10 +17,10 @@ from vega_sim.null_service import VegaServiceNull
@pytest.fixture(scope="module")
def setup_environment(request, browser):
def setup_environment(request, browser) -> Generator[Tuple[Page, str, str], None, None]:
with init_vega(request) as vega_instance:
request.addfinalizer(lambda: cleanup_container(vega_instance, request))
request.addfinalizer(lambda: cleanup_container(vega_instance))
tDAI_market, tDAI_asset_id = setup_market_with_reward_program(vega_instance)
@ -139,28 +140,34 @@ def setup_market_with_reward_program(vega: VegaServiceNull):
return tDAI_market, tDAI_asset_id
def test_network_reward_pot(setup_environment):
def test_network_reward_pot(
setup_environment: Tuple[Page, str, str],
) -> None:
page, tDAI_market, tDAI_asset_id = setup_environment
expect(page.get_by_test_id(TOTAL_REWARDS)).to_have_text("166.66666 tDAI")
def test_reward_multiplier(
setup_environment,
):
setup_environment: Tuple[Page, str, str],
) -> None:
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")
def test_hoarder_bonus(setup_environment):
def test_hoarder_bonus(
setup_environment: Tuple[Page, str, str],
) -> None:
page, tDAI_market, tDAI_asset_id = setup_environment
expect(page.get_by_test_id(HOARDER_BONUS_TOTAL_HOARDED)).to_contain_text(
"16,666,666"
)
def test_reward_history(setup_environment):
def test_reward_history(
setup_environment: Tuple[Page, str, str],
) -> None:
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(

View File

@ -1,5 +1,6 @@
import pytest
from rewards_test_ids import *
from typing import Tuple, Generator
import vega_sim.proto.vega as vega_protos
from playwright.sync_api import Page, expect
from conftest import (
@ -16,10 +17,10 @@ from vega_sim.null_service import VegaServiceNull
@pytest.fixture(scope="module")
def setup_environment(request, browser):
def setup_environment(request, browser) -> Generator[Tuple[Page, str, str], None, None]:
with init_vega(request) as vega_instance:
request.addfinalizer(lambda: cleanup_container(vega_instance, request))
request.addfinalizer(lambda: cleanup_container(vega_instance))
tDAI_market, tDAI_asset_id = setup_market_with_reward_program(vega_instance)
@ -91,22 +92,22 @@ def setup_market_with_reward_program(vega: VegaServiceNull):
def test_network_reward_pot(
setup_environment
):
setup_environment: Tuple[Page, str, str],
) -> None:
page, tDAI_market, tDAI_asset_id = setup_environment
expect(page.get_by_test_id(TOTAL_REWARDS)).to_have_text("50.00 tDAI")
def test_reward_multiplier(
setup_environment
):
setup_environment: Tuple[Page, str, str],
) -> None:
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_activity_tier_0")
"""
def test_activity_streak(
page: Page,
):
@ -115,7 +116,6 @@ def test_activity_streak(
)
@pytest.mark.xdist_group(name="test_rewards_activity_tier_0")
def test_reward_history(
page: Page,
):

View File

@ -1,8 +1,15 @@
import pytest
from rewards_test_ids import *
from typing import Tuple, Generator
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,10 +17,10 @@ from vega_sim.null_service import VegaServiceNull
@pytest.fixture(scope="module")
def setup_environment(request, browser):
def setup_environment(request, browser) -> Generator[Tuple[Page, str, str], None, None]:
with init_vega(request) as vega_instance:
request.addfinalizer(lambda: cleanup_container(vega_instance, request))
request.addfinalizer(lambda: cleanup_container(vega_instance))
tDAI_market, tDAI_asset_id = setup_market_with_reward_program(vega_instance)
@ -127,16 +134,16 @@ def setup_market_with_reward_program(vega: VegaServiceNull):
return tDAI_market, tDAI_asset_id
def test_network_reward_pot(setup_environment):
def test_network_reward_pot(
setup_environment: Tuple[Page, str, str],
) -> None:
page, tDAI_market, tDAI_asset_id = setup_environment
expect(page.get_by_test_id(TOTAL_REWARDS)).to_have_text("116.66666 tDAI")
def test_reward_multiplier(
setup_environment
):
setup_environment: Tuple[Page, str, str],
) -> None:
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")
@ -144,18 +151,17 @@ def test_reward_multiplier(
def test_activity_streak(
setup_environment
):
setup_environment: Tuple[Page, str, str],
) -> None:
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)"
)
def test_reward_history(
setup_environment
):
setup_environment: Tuple[Page, str, str],
) -> None:
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(
@ -168,10 +174,9 @@ def test_reward_history(
)
def test_redeem(
setup_environment
):
setup_environment: Tuple[Page, str, str],
) -> None:
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(
@ -186,4 +191,4 @@ def test_redeem(
)
page.get_by_test_id("use-max-button").first.click()
expect(page.get_by_test_id(TRANSFER_AMOUNT)).to_have_text(available_to_withdraw)
expect(page.get_by_test_id(TRANSFER_AMOUNT)).to_have_text(available_to_withdraw)

View File

@ -1,5 +1,6 @@
import pytest
from rewards_test_ids import *
from typing import Tuple, Generator
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
@ -9,10 +10,9 @@ from wallet_config import MM_WALLET
from vega_sim.null_service import VegaServiceNull
@pytest.fixture(scope="module")
def setup_environment(request, browser):
def setup_environment(request, browser) -> Generator[Tuple[Page, str, str], None, None]:
with init_vega(request) as vega_instance:
request.addfinalizer(lambda: cleanup_container(vega_instance, request))
request.addfinalizer(lambda: cleanup_container(vega_instance))
tDAI_market, tDAI_asset_id = setup_market_with_reward_program(vega_instance)
@ -138,16 +138,16 @@ def setup_market_with_reward_program(vega: VegaServiceNull):
def test_network_reward_pot( setup_environment
):
def test_network_reward_pot( setup_environment: Tuple[Page, str, str],
) -> None:
page, tDAI_market, tDAI_asset_id = setup_environment
expect(page.get_by_test_id(TOTAL_REWARDS)).to_have_text("183.33333 tDAI")
def test_reward_multiplier(
setup_environment
):
setup_environment: Tuple[Page, str, str],
) -> None:
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(
@ -160,8 +160,8 @@ def test_reward_multiplier(
def test_reward_history(
setup_environment
):
setup_environment: Tuple[Page, str, str],
) -> None:
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(

View File

@ -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))
request.addfinalizer(lambda: cleanup_container(vega_instance))
yield vega_instance