chore(trading): remove wait for graphql (#5265)

This commit is contained in:
Ben 2023-11-16 08:11:48 +00:00 committed by GitHub
parent f377e07996
commit 8e898cfd78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 222 deletions

View File

@ -1,5 +1,4 @@
from collections import namedtuple
from playwright.sync_api import Page
from vega_sim.null_service import VegaServiceNull
from typing import Optional

View File

@ -1,7 +1,6 @@
import pytest
from playwright.sync_api import expect, Page
@pytest.mark.usefixtures("page", "continuous_market", "risk_accepted")
def test_see_market_depth_chart(continuous_market, page: Page):
page.goto(f"/#/markets/{continuous_market}")

View File

@ -48,32 +48,6 @@ updatedAt_col = '[col-id="updatedAt"]'
close_toast = "toast-close"
def wait_for_graphql_response(page, query_name, timeout=5000):
response_data = {}
def handle_response(route, request):
if "graphql" in request.url:
response = request.response()
if response is not None:
json_response = response.json()
if json_response and "data" in json_response:
data = json_response["data"]
if query_name in data:
response_data["data"] = data
route.continue_()
return
route.continue_()
# Register the route handler
page.route("**", handle_response)
# Wait for the response data to be populated
page.wait_for_timeout(timeout)
# Unregister the route handler
page.unroute("**", handle_response)
def create_position(vega: VegaService, market_id):
submit_order(vega, "Key 1", market_id, "SIDE_SELL", 100, 110)
submit_order(vega, "Key 1", market_id, "SIDE_BUY", 100, 110)
@ -118,7 +92,6 @@ def test_submit_stop_order_rejected(continuous_market, vega: VegaService, page:
vega.wait_fn(1)
vega.wait_for_total_catchup()
page.get_by_test_id(close_toast).click()
wait_for_graphql_response(page, "stopOrders")
page.get_by_role(row_table).locator(market_name_col).nth(1).is_visible()
expect((page.get_by_role(row_table).locator(market_name_col)).nth(1)).to_have_text(
"BTC:DAI_2023Futr"
@ -174,7 +147,6 @@ def test_submit_stop_market_order_triggered(
vega.wait_for_total_catchup()
page.wait_for_selector('[data-testid="toast-close"]', state="visible")
page.get_by_test_id(close_toast).click()
wait_for_graphql_response(page, "stopOrders")
page.get_by_role(row_table).locator(market_name_col).nth(1).is_visible()
expect((page.get_by_role(row_table).locator(market_name_col)).nth(1)).to_have_text(
@ -235,7 +207,6 @@ def test_submit_stop_limit_order_pending(
page.wait_for_selector('[data-testid="toast-close"]', state="visible")
page.get_by_test_id(close_toast).click()
wait_for_graphql_response(page, "stopOrders")
page.get_by_role(row_table).locator(market_name_col).nth(1).is_visible()
expect((page.get_by_role(row_table).locator(market_name_col)).nth(1)).to_have_text(
"BTC:DAI_2023Futr"
@ -287,7 +258,6 @@ def test_submit_stop_limit_order_cancel(
vega.wait_for_total_catchup()
page.get_by_test_id(close_toast).first.click()
wait_for_graphql_response(page, "stopOrders")
page.get_by_test_id(cancel).click()
vega.forward("10s")
vega.wait_fn(1)
@ -409,7 +379,6 @@ class TestStopOcoValidation:
vega.wait_for_total_catchup()
if page.get_by_test_id(close_toast).is_visible():
page.get_by_test_id(close_toast).click()
wait_for_graphql_response(page, "stopOrders")
# 7002-SORD-011
expect(page.get_by_test_id("stop-order-warning-limit")).to_have_text(
"There is a limit of 4 active stop orders per market. Orders submitted above the limit will be immediately rejected."

View File

@ -1,10 +1,9 @@
from math import exp
import pytest
from collections import namedtuple
from playwright.sync_api import Page, expect
from vega_sim.service import VegaService
from actions.vega import submit_order
from conftest import init_vega, page
from conftest import init_vega
from fixtures.market import setup_continuous_market
from actions.utils import wait_for_toast_confirmation
@ -54,37 +53,9 @@ trigger_price_oco = "triggerPrice-oco"
order_size_oco = "order-size-oco"
order_limit_price_oco = "order-price-oco"
def wait_for_graphql_response(page, query_name, timeout=5000):
response_data = {}
def handle_response(route, request):
if "graphql" in request.url:
response = request.response()
if response is not None:
json_response = response.json()
if json_response and "data" in json_response:
data = json_response["data"]
if query_name in data:
response_data["data"] = data
route.continue_()
return
route.continue_()
# Register the route handler
page.route("**", handle_response)
# Wait for the response data to be populated
page.wait_for_timeout(timeout)
# Unregister the route handler
page.unroute("**", handle_response)
def create_position(vega: VegaService, market_id):
submit_order(vega, "Key 1", market_id, "SIDE_SELL", 100, 110)
submit_order(vega, "Key 1", market_id, "SIDE_BUY", 100, 110)
vega.forward("10s")
vega.wait_fn(1)
vega.wait_for_total_catchup
@ -93,10 +64,8 @@ def create_position(vega: VegaService, market_id):
def test_submit_stop_order_market_oco_rejected(
continuous_market, vega: VegaService, page: Page
):
market_id = continuous_market
page.goto(f"/#/markets/{market_id}")
page.goto(f"/#/markets/{continuous_market}")
page.get_by_test_id(stop_orders_tab).click()
wait_for_graphql_response(page, "stopOrders")
page.get_by_test_id(stop_order_btn).click()
page.get_by_test_id(stop_market_order_btn).is_visible()
page.get_by_test_id(stop_market_order_btn).click()
@ -116,12 +85,8 @@ def test_submit_stop_order_market_oco_rejected(
page.get_by_test_id(order_size_oco).fill("3")
page.get_by_test_id(submit_stop_order).click()
wait_for_toast_confirmation(page)
vega.forward("10s")
vega.wait_fn(1)
vega.wait_for_total_catchup()
page.get_by_test_id(close_toast).click()
wait_for_graphql_response(page, "stopOrders")
page.get_by_role(row_table).locator(market_name_col).nth(1).is_visible()
expect((page.get_by_role(row_table).locator(market_name_col)).nth(1)).to_have_text(
@ -176,11 +141,10 @@ def test_submit_stop_order_market_oco_rejected(
def test_submit_stop_oco_market_order_triggered(
continuous_market, vega: VegaService, page: Page
):
market_id = continuous_market
page.goto(f"/#/markets/{market_id}")
create_position(vega, continuous_market)
page.goto(f"/#/markets/{continuous_market}")
page.get_by_test_id(stop_orders_tab).click()
create_position(vega, market_id)
wait_for_graphql_response(page, "stopOrders")
page.get_by_test_id(stop_order_btn).click()
page.get_by_test_id(stop_market_order_btn).is_visible()
page.get_by_test_id(stop_market_order_btn).click()
@ -198,12 +162,8 @@ def test_submit_stop_oco_market_order_triggered(
page.get_by_test_id(order_size_oco).fill("3")
page.get_by_test_id(submit_stop_order).click()
wait_for_toast_confirmation(page)
vega.forward("10s")
vega.wait_fn(1)
vega.wait_for_total_catchup()
page.get_by_test_id(close_toast).click()
wait_for_graphql_response(page, "stopOrders")
page.get_by_role(row_table).locator(market_name_col).nth(1).is_visible()
expect((page.get_by_role(row_table).locator(market_name_col)).nth(1)).to_have_text(
@ -257,12 +217,10 @@ def test_submit_stop_oco_market_order_triggered(
@pytest.mark.usefixtures("page", "vega", "continuous_market", "auth", "risk_accepted")
def test_submit_stop_oco_market_order_pending(
continuous_market, vega: VegaService, page: Page
):
market_id = continuous_market
page.goto(f"/#/markets/{market_id}")
):
create_position(vega, continuous_market)
page.goto(f"/#/markets/{continuous_market}")
page.get_by_test_id(stop_orders_tab).click()
create_position(vega, market_id)
wait_for_graphql_response(page, "stopOrders")
page.get_by_test_id(stop_order_btn).click()
page.get_by_test_id(stop_market_order_btn).is_visible()
page.get_by_test_id(stop_market_order_btn).click()
@ -276,11 +234,9 @@ def test_submit_stop_oco_market_order_pending(
page.get_by_test_id(order_size_oco).fill("2")
page.get_by_test_id(submit_stop_order).click()
wait_for_toast_confirmation(page)
vega.forward("10s")
vega.wait_fn(1)
vega.wait_for_total_catchup()
page.get_by_test_id(close_toast).click()
wait_for_graphql_response(page, "stopOrders")
page.get_by_role(row_table).locator(market_name_col).nth(1).is_visible()
expect((page.get_by_role(row_table).locator(status_col)).nth(1)).to_have_text(
@ -290,16 +246,13 @@ def test_submit_stop_oco_market_order_pending(
"PendingOCO"
)
@pytest.mark.usefixtures("page", "vega", "continuous_market", "auth", "risk_accepted")
def test_submit_stop_oco_limit_order_pending(
continuous_market, vega: VegaService, page: Page
):
market_id = continuous_market
page.goto(f"/#/markets/{market_id}")
create_position(vega, continuous_market)
page.goto(f"/#/markets/{continuous_market}")
page.get_by_test_id(stop_orders_tab).click()
create_position(vega, market_id)
wait_for_graphql_response(page, "stopOrders")
page.get_by_test_id(stop_order_btn).click()
page.get_by_test_id(stop_limit_order_btn).is_visible()
page.get_by_test_id(stop_limit_order_btn).click()
@ -317,12 +270,10 @@ def test_submit_stop_oco_limit_order_pending(
page.get_by_test_id(order_limit_price_oco).fill("99")
page.get_by_test_id(submit_stop_order).click()
wait_for_toast_confirmation(page)
vega.forward("10s")
vega.wait_fn(1)
vega.wait_for_total_catchup()
page.get_by_test_id(close_toast).click()
wait_for_graphql_response(page, "stopOrders")
page.get_by_role(row_table).locator(market_name_col).nth(1).is_visible()
expect((page.get_by_role(row_table).locator(submission_type)).nth(1)).to_have_text(
@ -350,11 +301,8 @@ def test_submit_stop_oco_limit_order_pending(
def test_submit_stop_oco_limit_order_cancel(
continuous_market, vega: VegaService, page: Page
):
market_id = continuous_market
page.goto(f"/#/markets/{market_id}")
page.get_by_test_id(stop_orders_tab).click()
create_position(vega, market_id)
wait_for_graphql_response(page, "stopOrders")
create_position(vega, continuous_market)
page.goto(f"/#/markets/{continuous_market}")
page.get_by_test_id(stop_order_btn).click()
page.get_by_test_id(stop_limit_order_btn).is_visible()
page.get_by_test_id(stop_limit_order_btn).click()
@ -373,19 +321,14 @@ def test_submit_stop_oco_limit_order_cancel(
page.get_by_test_id(order_limit_price_oco).fill("99")
page.get_by_test_id(submit_stop_order).click()
wait_for_toast_confirmation(page)
vega.forward("10s")
vega.wait_fn(1)
vega.wait_for_total_catchup()
page.get_by_test_id(close_toast).click()
wait_for_graphql_response(page, "stopOrders")
page.get_by_test_id(stop_orders_tab).click()
page.get_by_test_id(cancel).first.click()
wait_for_toast_confirmation(page)
vega.forward("10s")
vega.wait_fn(1)
vega.wait_for_total_catchup()
page.get_by_test_id(close_toast).first.click()
expect(
page.locator(".ag-center-cols-container").locator('[col-id="status"]').first
).to_have_text("CancelledOCO")
@ -393,7 +336,6 @@ def test_submit_stop_oco_limit_order_cancel(
page.locator(".ag-center-cols-container").locator('[col-id="status"]').last
).to_have_text("CancelledOCO")
class TestStopOcoValidation:
@pytest.fixture(scope="class")
def vega(self, request):
@ -406,8 +348,7 @@ class TestStopOcoValidation:
@pytest.mark.usefixtures("page", "auth", "risk_accepted")
def test_stop_market_order_oco_form_validation(self, continuous_market, page: Page):
market_id = continuous_market
page.goto(f"/#/markets/{market_id}")
page.goto(f"/#/markets/{continuous_market}")
page.get_by_test_id(stop_order_btn).click()
page.get_by_test_id(stop_market_order_btn).is_visible()
page.get_by_test_id(stop_market_order_btn).click()
@ -434,8 +375,7 @@ class TestStopOcoValidation:
@pytest.mark.usefixtures("page", "auth", "risk_accepted")
def test_stop_limit_order_oco_form_validation(self, continuous_market, page: Page):
market_id = continuous_market
page.goto(f"/#/markets/{market_id}")
page.goto(f"/#/markets/{continuous_market}")
page.get_by_test_id(stop_order_btn).click()
page.get_by_test_id(stop_market_order_btn).is_visible()
page.get_by_test_id(stop_limit_order_btn).click()
@ -465,12 +405,8 @@ class TestStopOcoValidation:
@pytest.mark.usefixtures("page", "auth", "risk_accepted")
def test_maximum_number_of_active_stop_orders_oco(
self, continuous_market, vega: VegaService, page: Page
):
market_id = continuous_market
page.goto(f"/#/markets/{market_id}")
page.get_by_test_id(stop_orders_tab).click()
create_position(vega, market_id)
wait_for_graphql_response(page, "stopOrders")
):
page.goto(f"/#/markets/{continuous_market}")
page.get_by_test_id(stop_order_btn).click()
page.get_by_test_id(stop_limit_order_btn).is_visible()
page.get_by_test_id(stop_limit_order_btn).click()
@ -486,12 +422,11 @@ class TestStopOcoValidation:
for i in range(2):
page.get_by_test_id(submit_stop_order).click()
wait_for_toast_confirmation(page)
vega.forward("10s")
vega.wait_fn(1)
vega.forward("20s")
vega.wait_for_total_catchup()
if page.get_by_test_id(close_toast).is_visible():
page.get_by_test_id(close_toast).click()
wait_for_graphql_response(page, "stopOrders")
page.get_by_test_id(close_toast).click()
# 7002-SORD-011
expect(page.get_by_test_id("stop-order-warning-limit")).to_have_text(
"There is a limit of 4 active stop orders per market. Orders submitted above the limit will be immediately rejected."

View File

@ -1,22 +1,17 @@
import pytest
import re
import logging
from playwright.sync_api import expect, Page
from vega_sim.service import VegaService
from playwright.sync_api import expect
from actions.vega import submit_order
import logging
logger = logging.getLogger()
# Could be turned into a helper function in the future.
def verify_data_grid(page, data_test_id, expected_pattern):
def verify_data_grid(page: Page, data_test_id, expected_pattern):
page.get_by_test_id(data_test_id).click()
# Required so that we can get liquidation price
if data_test_id == "Positions":
wait_for_graphql_response(page, "EstimatePosition")
expect(
page.locator(
f'[data-testid^="tab-{data_test_id.lower()}"] >> .ag-center-cols-container .ag-row-first'
@ -42,34 +37,7 @@ def verify_data_grid(page, data_test_id, expected_pattern):
raise AssertionError(f"Pattern does not match: {expected} != {actual}")
# Required so that we can get liquidation price - Could also become a helper
def wait_for_graphql_response(page, query_name, timeout=5000):
response_data = {}
def handle_response(route, request):
if "graphql" in request.url:
response = request.response()
if response is not None:
json_response = response.json()
if json_response and "data" in json_response:
data = json_response["data"]
if query_name in data:
response_data["data"] = data
route.continue_()
return
route.continue_()
# Register the route handler
page.route("**", handle_response)
# Wait for the response data to be populated
page.wait_for_timeout(timeout)
# Unregister the route handler
page.unroute("**", handle_response)
def submit_order(vega, wallet_name, market_id, side, volume, price):
def submit_order(vega: VegaService, wallet_name, market_id, side, volume, price):
vega.submit_order(
trading_key=wallet_name,
market_id=market_id,
@ -91,7 +59,6 @@ def test_limit_order_trade_open_order(
submit_order(vega, "Key 1", market_id, "SIDE_BUY", 1, 110)
page.goto(f"/#/markets/{market_id}")
# Assert that the user order is displayed on the orderbook
orderbook_trade = page.get_by_test_id("price-11000000").nth(1)
# 6003-ORDB-001
@ -188,4 +155,5 @@ def test_limit_order_trade_order_trade_away(continuous_market, page: Page):
page.get_by_test_id("Orderbook").click()
price_element = page.get_by_test_id("price-11000000").nth(1)
# 6003-ORDB-010
print(price_element)
expect(price_element).to_be_hidden()

View File

@ -3,33 +3,6 @@ from playwright.sync_api import Page
from vega_sim.service import VegaService
from actions.vega import submit_order
def wait_for_graphql_response(page, query_name, timeout=5000):
response_data = {}
def handle_response(route, request):
if "graphql" in request.url:
response = request.response()
if response is not None:
json_response = response.json()
if json_response and "data" in json_response:
data = json_response["data"]
if query_name in data:
response_data["data"] = data
route.continue_()
return
route.continue_()
# Register the route handler
page.route("**", handle_response)
# Wait for the response data to be populated
page.wait_for_timeout(timeout)
# Unregister the route handler
page.unroute("**", handle_response)
def check_pnl_color_value(element, expected_color, expected_value):
color = element.evaluate("element => getComputedStyle(element).color")
value = element.inner_text()
@ -40,7 +13,6 @@ def check_pnl_color_value(element, expected_color, expected_value):
def test_pnl(continuous_market, vega: VegaService, page: Page):
page.set_viewport_size({"width": 1748, "height": 977})
submit_order(vega, "Key 1", continuous_market, "SIDE_BUY", 1, 104.50000)
vega.forward("10s")
vega.wait_fn(1)
vega.wait_for_total_catchup()
page.goto(f"/#/markets/{continuous_market}")
@ -71,7 +43,6 @@ def test_pnl(continuous_market, vega: VegaService, page: Page):
page.get_by_test_id("manage-vega-wallet").click(force=True)
page.get_by_role("link", name="Portfolio").click()
page.get_by_test_id("Positions").click()
wait_for_graphql_response(page, "EstimatePosition")
page.wait_for_selector(
'[data-testid="tab-positions"] .ag-center-cols-container .ag-row',
state="visible",
@ -103,10 +74,8 @@ def test_pnl(continuous_market, vega: VegaService, page: Page):
check_pnl_color_value(key_mm2_unrealised_pnl, "rgb(0, 0, 0)", "0.00")
submit_order(vega, "Key 1", continuous_market, "SIDE_SELL", 2, 101.50000)
vega.forward("10s")
vega.wait_fn(1)
vega.wait_for_total_catchup()
wait_for_graphql_response(page, "EstimatePosition")
check_pnl_color_value(key_1_realised_pnl, "rgb(236, 0, 60)", "-8.00")
check_pnl_color_value(key_1_unrealised_pnl, "rgb(0, 0, 0)", "0.00")

View File

@ -1,9 +1,11 @@
import pytest
import re
import logging
from playwright.sync_api import expect
from actions.vega import submit_order
from conftest import init_vega
import logging
from playwright.sync_api import Page
from vega_sim.null_service import VegaService
logger = logging.getLogger()
@ -15,11 +17,9 @@ def vega():
# Could be turned into a helper function in the future.
def verify_data_grid(page, data_test_id, expected_pattern):
def verify_data_grid(page: Page, data_test_id, expected_pattern):
page.get_by_test_id(data_test_id).click()
# Required so that we can get liquidation price
if data_test_id == "Positions":
wait_for_graphql_response(page, "EstimatePosition")
expect(
page.locator(
f'[data-testid^="tab-{data_test_id.lower()}"] >> .ag-center-cols-container .ag-row-first'
@ -45,41 +45,12 @@ def verify_data_grid(page, data_test_id, expected_pattern):
raise AssertionError(f"Pattern does not match: {expected} != {actual}")
# Required so that we can get liquidation price - Could also become a helper
def wait_for_graphql_response(page, query_name, timeout=5000):
response_data = {}
def handle_response(route, request):
if "graphql" in request.url:
response = request.response()
if response is not None:
json_response = response.json()
if json_response and "data" in json_response:
data = json_response["data"]
if query_name in data:
response_data["data"] = data
route.continue_()
return
route.continue_()
# Register the route handler
page.route("**", handle_response)
# Wait for the response data to be populated
page.wait_for_timeout(timeout)
# Unregister the route handler
page.unroute("**", handle_response)
@pytest.mark.usefixtures("page", "continuous_market", "auth", "risk_accepted")
def test_limit_order_new_trade_top_of_list(continuous_market, vega, page):
def test_limit_order_new_trade_top_of_list(continuous_market, vega: VegaService, page: Page):
submit_order(vega, "Key 1", continuous_market, "SIDE_BUY", 1, 110)
page.goto(f"/#/markets/{continuous_market}")
vega.forward("10s")
vega.wait_fn(10)
vega.wait_fn(1)
vega.wait_for_total_catchup()
page.goto(f"/#/markets/{continuous_market}")
expected_trade = [
"103.50",
"1",
@ -97,10 +68,9 @@ def test_limit_order_new_trade_top_of_list(continuous_market, vega, page):
@pytest.mark.usefixtures("page", "continuous_market", "auth", "risk_accepted")
def test_price_copied_to_deal_ticket(continuous_market, page):
def test_price_copied_to_deal_ticket(continuous_market, page: Page):
page.goto(f"/#/markets/{continuous_market}")
page.get_by_test_id("Trades").click()
wait_for_graphql_response(page, "Trades")
page.locator("[col-id=price]").last.click()
# 6005-THIS-007
expect(page.get_by_test_id("order-price")).to_have_value("107.50000")