Compare commits

...
Author SHA1 Message Date
bwallacee c846ac0be0 chore(trading): teams test for local development 2024-01-19 12:59:52 +00:00
Ben 2a4a05630f chore(trading): fix skipped tests (#5638) 2024-01-19 08:20:52 +00:00
5 changed files with 211 additions and 274 deletions
+1 -1
View File
@@ -681,4 +681,4 @@ def test_fills_taker_fee_tooltip_discount_program(
row.locator(COL_FEE).hover()
expect(page.get_by_test_id(FEE_BREAKDOWN_TOOLTIP)).to_have_text(
f"If the market was activeFees to be paid by the taker; discounts are already applied.Infrastructure fee{infra_fee} tDAILiquidity fee0.00 tDAIMaker fee{maker_fee} tDAITotal fees{total_fee} tDAI"
)
)
@@ -16,34 +16,44 @@ def vega(request):
def continuous_market(vega):
return setup_continuous_market(vega)
@pytest.mark.usefixtures("auth", "risk_accepted")
def test_liquidity_provision_amendment(continuous_market, vega: VegaServiceNull, page: Page):
def test_liquidity_provision_amendment(
continuous_market, vega: VegaServiceNull, page: Page
):
# TODO Refactor asserting the grid
page.goto(f"/#/liquidity/{continuous_market}")
change_keys(page, vega, "market_maker")
row = page.get_by_test_id(
"tab-myLP").locator(".ag-center-cols-container .ag-row").first
expect(row).to_contain_text(
"Active"
row = (
page.get_by_test_id("tab-myLP")
.locator(".ag-center-cols-container .ag-row")
.first
)
expect(row).to_contain_text("Active")
# 5002-LIQP-006
expect(page.get_by_test_id("target-stake")
).to_have_text("Target stake5.82757 tDAI")
expect(page.get_by_test_id("target-stake")).to_have_text("Target stake5.82757 tDAI")
# 5002-LIQP-007
expect(page.get_by_test_id("supplied-stake")
).to_have_text("Supplied stake10,000.00 tDAI")
expect(page.get_by_test_id("supplied-stake")).to_have_text(
"Supplied stake10,000.00 tDAI"
)
# 5002-LIQP-008
expect(page.get_by_test_id("liquidity-supplied")
).to_have_text("Liquidity supplied 171,598.11%")
expect(page.get_by_test_id("liquidity-supplied")).to_have_text(
"Liquidity supplied 171,598.11%"
)
expect(page.get_by_test_id("fees-paid")).to_have_text("Fees paid-")
# 5002-LIQP-009
expect(page.get_by_test_id("liquidity-market-id")
).to_have_text("Market ID" + truncate_middle(continuous_market))
expect(page.get_by_test_id("liquidity-learn-more")
).to_have_text("Learn moreProviding liquidity")
expect(page.get_by_test_id("liquidity-market-id")).to_have_text(
"Market ID" + truncate_middle(continuous_market)
)
expect(page.get_by_test_id("liquidity-learn-more")).to_have_text(
"Learn moreProviding liquidity"
)
# 002-LIQP-010
expect(page.get_by_test_id("liquidity-learn-more").get_by_test_id("external-link")
).to_have_attribute("href", "https://docs.vega.xyz/testnet/concepts/liquidity/provision")
expect(
page.get_by_test_id("liquidity-learn-more").get_by_test_id("external-link")
).to_have_attribute(
"href", "https://docs.vega.xyz/testnet/concepts/liquidity/provision"
)
vega.submit_simple_liquidity(
key_name="market_maker",
@@ -56,41 +66,50 @@ def test_liquidity_provision_amendment(continuous_market, vega: VegaServiceNull,
vega.wait_fn(1)
vega.wait_for_total_catchup()
page.reload()
row = page.get_by_test_id(
"tab-myLP").locator(".ag-center-cols-container .ag-row").first
expect(row).to_contain_text(
"Updating next epoch"
row = (
page.get_by_test_id("tab-myLP")
.locator(".ag-center-cols-container .ag-row")
.first
)
expect(row).to_contain_text("Updating next epoch")
next_epoch(vega=vega)
page.reload()
expect(page.get_by_test_id("supplied-stake")).to_have_text(
"Supplied stake1.00001 tDAI"
)
expect(page.get_by_test_id("liquidity-supplied")).to_have_text(
"Liquidity supplied 17.16%"
)
row = (
page.get_by_test_id("tab-myLP")
.locator(".ag-center-cols-container .ag-row")
.first
)
expect(row).to_contain_text("Active")
@pytest.mark.usefixtures("auth", "risk_accepted")
def test_liquidity_provision_cancelled(
continuous_market, vega: VegaServiceNull, page: Page
):
page.goto(f"/#/liquidity/{continuous_market}")
change_keys(page, vega, "market_maker")
row = (
page.get_by_test_id("tab-myLP")
.locator(".ag-center-cols-container .ag-row")
.first
)
expect(row).to_contain_text("Active")
vega.cancel_liquidity(
key_name="market_maker",
market_id=continuous_market,
)
next_epoch(vega=vega)
page.reload()
expect(page.get_by_test_id("supplied-stake")
).to_have_text("Supplied stake1.00001 tDAI")
expect(page.get_by_test_id("liquidity-supplied")
).to_have_text("Liquidity supplied 17.16%")
row = page.get_by_test_id(
"tab-myLP").locator(".ag-center-cols-container .ag-row").first
expect(row).to_contain_text(
"Active"
expect(page.get_by_test_id("supplied-stake")).to_have_text(
"Supplied stake0.00 tDAI"
)
@pytest.mark.skip("Waiting for the ability to cancel LP")
@pytest.mark.usefixtures("auth", "risk_accepted")
def test_liquidity_provision_inactive(continuous_market, vega: VegaServiceNull, page: Page):
# TODO Refactor asserting the grid
page.goto(f"/#/liquidity/{continuous_market}")
change_keys(page, vega, "market_maker")
row = page.get_by_test_id(
"tab-myLP").locator(".ag-center-cols-container .ag-row").first
expect(row).to_contain_text(
"Active"
expect(page.get_by_test_id("liquidity-supplied")).to_have_text(
"Liquidity supplied 0.00%"
)
vega.submit_simple_liquidity(
key_name="market_maker",
market_id=continuous_market,
commitment_amount=0,
fee=0,
is_amendment=False,
)
vega.wait_fn(1)
vega.wait_for_total_catchup()
expect(page.locator(".ag-overlay-panel")).to_have_text("No data")
@@ -1,222 +0,0 @@
import pytest
from playwright.sync_api import Page, expect
from vega_sim.null_service import VegaServiceNull
from actions.vega import submit_order
from actions.utils import change_keys
from wallet_config import MM_WALLET, MM_WALLET2
import logging
logger = logging.getLogger()
table_row_selector = (
'[data-testid="tab-open-markets"] .ag-center-cols-container .ag-row'
)
trading_mode_col = '[col-id="tradingMode"]'
state_col = '[col-id="state"]'
item_value = "item-value"
price_monitoring_bounds_row = "key-value-table-row"
market_trading_mode = "market-trading-mode"
market_state = "market-state"
liquidity_supplied = "liquidity-supplied"
item_value = "item-value"
price_monitoring_bounds_row = "key-value-table-row"
market_trading_mode = "market-trading-mode"
market_state = "market-state"
liquidity_supplied = "liquidity-supplied"
initial_commitment: float = 100
initial_price: float = 1
initial_volume: float = 1
initial_spread: float = 0.1
market_name = "BTC:DAI_2023"
@pytest.mark.skip("tbd")
@pytest.mark.usefixtures("risk_accepted", "auth")
def test_price_monitoring(simple_market, vega: VegaServiceNull, page: Page):
page.goto(f"/#/markets/all")
expect(page.locator(table_row_selector).locator(trading_mode_col)).to_have_text(
"Opening auction"
)
expect(page.locator(table_row_selector).locator('[col-id="state"]')).to_have_text(
"Pending"
)
result = page.get_by_text(market_name)
result.first.click()
page.get_by_test_id(market_trading_mode).get_by_text("Opening auction").hover()
expect(page.get_by_test_id("opening-auction-sub-status").first).to_have_text(
"Opening auction: Not enough liquidity to open"
)
logger.info(page.get_by_test_id("opening-auction-sub-status").inner_text)
vega.submit_liquidity(
key_name=MM_WALLET.name,
market_id=simple_market,
commitment_amount=initial_commitment,
fee=0.002,
is_amendment=False,
)
vega.submit_order(
market_id=simple_market,
trading_key=MM_WALLET.name,
side="SIDE_BUY",
order_type="TYPE_LIMIT",
price=initial_price - 0.0005,
wait=False,
time_in_force="TIME_IN_FORCE_GTC",
volume=99,
)
vega.submit_order(
market_id=simple_market,
trading_key=MM_WALLET.name,
side="SIDE_SELL",
order_type="TYPE_LIMIT",
price=initial_price + 0.0005,
wait=False,
time_in_force="TIME_IN_FORCE_GTC",
volume=99,
)
# 6002-MDET-009
expect(
page.get_by_test_id(liquidity_supplied).get_by_test_id(item_value)
).to_have_text("0.00 (0.00%)")
# add orders to provide liquidity
submit_order(
vega, MM_WALLET.name, simple_market, "SIDE_BUY", initial_volume, initial_price
)
submit_order(
vega, MM_WALLET.name, simple_market, "SIDE_SELL", initial_volume, initial_price
)
submit_order(
vega,
MM_WALLET.name,
simple_market,
"SIDE_BUY",
initial_volume,
initial_price + initial_spread / 2,
)
submit_order(
vega,
MM_WALLET.name,
simple_market,
"SIDE_SELL",
initial_volume,
initial_price + initial_spread / 2,
)
submit_order(
vega, MM_WALLET2.name, simple_market, "SIDE_SELL", initial_volume, initial_price
)
expect(
page.get_by_test_id(liquidity_supplied).get_by_test_id(item_value)
).to_have_text("100.00 (>100%)")
vega.forward("10s")
vega.wait_fn(10)
vega.wait_for_total_catchup()
expect(
page.get_by_test_id(liquidity_supplied).get_by_test_id(item_value)
).to_have_text("50.00 (>100%)")
page.goto(f"/#/markets/all")
# temporary skip
# expect(page.locator(table_row_selector).locator(trading_mode_col)).to_have_text(
# "Continuous"
# )
# commented out because we have an issue #4233
# expect(page.locator(row_selector).locator(state_col)
# ).to_have_text("Pending")
page.goto(f"/#/markets/all")
result = page.get_by_text(market_name)
result.first.click()
page.get_by_test_id("Info").click()
page.get_by_test_id("accordion-title").get_by_text(
"Price monitoring bounds 1"
).click()
expect(
page.get_by_test_id(price_monitoring_bounds_row).first.get_by_text(
"1.32217 BTC"
)
).to_be_visible()
expect(
page.get_by_test_id(price_monitoring_bounds_row).last.get_by_text("0.79245 BTC")
).to_be_visible()
# add orders that change the price so that it goes beyond the limits of price monitoring
submit_order(vega, MM_WALLET.name, simple_market, "SIDE_SELL", 100, 110)
submit_order(vega, MM_WALLET2.name, simple_market, "SIDE_BUY", 100, 90)
submit_order(vega, MM_WALLET.name, simple_market, "SIDE_SELL", 100, 105)
submit_order(vega, MM_WALLET2.name, simple_market, "SIDE_BUY", 100, 95)
# add order at the current price so that it is possible to change the status to price monitoring
to_cancel = submit_order(vega, MM_WALLET2.name, simple_market, "SIDE_BUY", 1, 105)
vega.forward("10s")
vega.wait_fn(1)
vega.wait_for_total_catchup()
expect(
page.get_by_test_id(price_monitoring_bounds_row).first.get_by_text(
"135.44204 BTC"
)
).to_be_visible()
expect(
page.get_by_test_id(price_monitoring_bounds_row).last.get_by_text(
"81.17758 BTC"
)
).to_be_visible()
expect(
page.get_by_test_id(market_trading_mode).get_by_test_id(item_value)
).to_have_text("Monitoring auction - price")
expect(page.get_by_test_id(market_state).get_by_test_id(item_value)).to_have_text(
"Suspended"
)
expect(
page.get_by_test_id(liquidity_supplied).get_by_test_id(item_value)
).to_have_text("50.00 (8.78%)")
# cancel order to increase liquidity
vega.cancel_order(MM_WALLET2.name, simple_market, to_cancel)
vega.forward("10s")
vega.wait_fn(1)
vega.wait_for_total_catchup()
expect(page.get_by_text(market_name).first).to_be_attached()
expect(
page.get_by_test_id(market_trading_mode).get_by_test_id(item_value)
).to_have_text("Continuous")
expect(page.get_by_test_id(market_state).get_by_test_id(item_value)).to_have_text(
"Active"
)
# commented out because we have an issue #4233
# expect(page.get_by_text("Opening auction")).to_be_hidden()
# 6002-MDET-009
expect(
page.get_by_test_id(liquidity_supplied).get_by_test_id(item_value)
).to_have_text("50.00 (>100%)")
COL_ID_FEE = ".ag-center-cols-container [col-id='fee'] .ag-cell-value"
@pytest.mark.usefixtures("risk_accepted", "auth")
def test_auction_uncross_fees(continuous_market, vega: VegaServiceNull, page: Page):
page.goto(f"/#/markets/{continuous_market}")
page.get_by_test_id("Fills").click()
expect(page.locator(COL_ID_FEE)).to_have_text("0.00 tDAI")
# tbd - tooltip is not visible without this wait
page.wait_for_timeout(1000)
page.get_by_role("gridcell", name="0.00 tDAI").nth(0).hover()
expect(page.get_by_test_id("fee-breakdown-tooltip")).to_have_text(
"If the market was suspendedDuring auction, half the infrastructure and liquidity fees will be paid.Infrastructure fee0.00 tDAILiquidity fee0.00 tDAIMaker fee0.00 tDAITotal fees0.00 tDAI"
)
change_keys(page, vega, "market_maker")
expect(page.locator(COL_ID_FEE)).to_have_text("0.00 tDAI")
# tbd - tooltip is not visible without this wait
page.wait_for_timeout(1000)
page.get_by_role("gridcell", name="0.00 tDAI").nth(0).hover()
expect(page.get_by_test_id("fee-breakdown-tooltip")).to_have_text(
"If the market was suspendedDuring auction, half the infrastructure and liquidity fees will be paid.Infrastructure fee0.00 tDAILiquidity fee0.00 tDAIMaker fee0.00 tDAITotal fees0.00 tDAI"
)
@@ -4,9 +4,14 @@ from vega_sim.null_service import VegaServiceNull
from actions.vega import submit_order
from fixtures.market import setup_simple_market
from conftest import init_vega
from actions.utils import wait_for_toast_confirmation
from actions.utils import wait_for_toast_confirmation, change_keys
from wallet_config import MM_WALLET, MM_WALLET2
market_trading_mode = "market-trading-mode"
market_state = "market-state"
item_value = "item-value"
COL_ID_FEE = ".ag-center-cols-container [col-id='fee'] .ag-cell-value"
@pytest.fixture(scope="module")
def vega(request):
@@ -133,3 +138,29 @@ def test_market_monitoring_auction_price_volatility_market_order(
"This market is in auction due to high price volatility. Only limit orders are permitted when market is in auction."
)
expect(page.get_by_test_id("deal-ticket-error-message-type")).to_be_visible()
@pytest.mark.usefixtures("risk_accepted", "auth", "setup_market_monitoring_auction")
def test_market_price_volatility(
page: Page, simple_market, vega: VegaServiceNull
):
page.goto(f"/#/markets/{simple_market}")
expect(
page.get_by_test_id(market_trading_mode).get_by_test_id(item_value)
).to_have_text("Monitoring auction - price")
expect(page.get_by_test_id(market_state).get_by_test_id(item_value)).to_have_text(
"Suspended"
)
@pytest.mark.usefixtures("risk_accepted", "auth", "setup_market_monitoring_auction")
def test_auction_uncross_fees(simple_market, vega: VegaServiceNull, page: Page):
page.goto(f"/#/markets/{simple_market}")
change_keys(page, vega, "market_maker")
page.get_by_test_id("Fills").click()
row = page.locator('[row-index="3"]').nth(1)
expect(row.locator('[col-id="fee"]')).to_have_text("0.00 tDAI")
# tbd - tooltip is not visible without this wait
page.wait_for_timeout(1000)
row.locator('[col-id="fee"]').hover()
expect(page.get_by_test_id("fee-breakdown-tooltip")).to_have_text(
"If the market was suspendedDuring auction, half the infrastructure and liquidity fees will be paid.Infrastructure fee0.00 tDAILiquidity fee0.00 tDAIMaker fee0.00 tDAITotal fees0.00 tDAI"
)
+109
View File
@@ -0,0 +1,109 @@
import pytest
from playwright.sync_api import expect, Page
import vega_sim.proto.vega as vega_protos
from vega_sim.null_service import VegaServiceNull
from conftest import init_vega
from actions.utils import next_epoch
from fixtures.market import setup_continuous_market
from wallet_config import PARTY_A, PARTY_B, PARTY_C, PARTY_D, MM_WALLET
@pytest.fixture(scope="module")
def vega(request):
with init_vega(request) as vega:
yield vega
def setup_teams_and_games(vega: VegaServiceNull):
tDAI_market = setup_continuous_market(vega)
tDAI_asset_id = vega.find_asset_id(symbol="tDAI")
vega.mint(key_name=PARTY_B.name, asset=tDAI_asset_id, amount=100000)
vega.mint(key_name=PARTY_C.name, asset=tDAI_asset_id, amount=100000)
vega.mint(key_name=PARTY_A.name, asset=tDAI_asset_id, amount=100000)
vega.mint(key_name=PARTY_D.name, asset=tDAI_asset_id, amount=100000)
next_epoch(vega=vega)
tDAI_asset_id = vega.find_asset_id(symbol="tDAI")
vega.update_network_parameter(
MM_WALLET.name, parameter="reward.asset", new_value=tDAI_asset_id
)
next_epoch(vega=vega)
team_name = create_team(vega)
next_epoch(vega)
teams = vega.list_teams()
# list_teams actually returns a dictionary {"team_id": Team}
team_id = list(teams.keys())[0]
vega.apply_referral_code(PARTY_B.name, team_id)
# go to next epoch so we can check joinedAt and joinedAtEpoch appropriately
next_epoch(vega)
vega.apply_referral_code(PARTY_C.name, team_id)
next_epoch(vega)
vega.apply_referral_code(PARTY_D.name, team_id)
vega.wait_fn(1)
vega.wait_for_total_catchup()
vega.recurring_transfer(
from_key_name=PARTY_A.name,
from_account_type=vega_protos.vega.ACCOUNT_TYPE_GENERAL,
to_account_type=vega_protos.vega.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
asset=tDAI_asset_id,
reference="reward",
asset_for_metric=tDAI_asset_id,
metric=vega_protos.vega.DISPATCH_METRIC_MAKER_FEES_PAID,
entity_scope=vega_protos.vega.ENTITY_SCOPE_TEAMS,
n_top_performers=1,
amount=100,
factor=1.0,
)
vega.submit_order(
trading_key=PARTY_B.name,
market_id=tDAI_market,
order_type="TYPE_MARKET",
time_in_force="TIME_IN_FORCE_IOC",
side="SIDE_BUY",
volume=1,
)
vega.submit_order(
trading_key=PARTY_A.name,
market_id=tDAI_market,
order_type="TYPE_MARKET",
time_in_force="TIME_IN_FORCE_IOC",
side="SIDE_BUY",
volume=1,
)
next_epoch(vega=vega)
return tDAI_market, tDAI_asset_id, team_id, team_name
@pytest.mark.usefixtures("auth", "risk_accepted")
def test_teams(vega: VegaServiceNull, page: Page):
market_id, asset_id, team_id, team_name = setup_teams_and_games(vega)
page.goto(f"/#/competitions/team/{team_id}")
print(team_name)
print(team_id)
#page.pause()
expect(page.get_by_role("heading", level=1)).to_have_text(team_name)
expect(page.get_by_text("Members (3)")).to_be_visible()
def create_team(vega: VegaServiceNull):
team_name = "Foobar"
vega.create_referral_set(
key_name=PARTY_A.name,
name=team_name,
team_url="https://vega.xyz",
avatar_url="http://placekitten.com/200/200",
closed=False,
)
return team_name