diff --git a/apps/trading/e2e/tests/deal_ticket/test_isolated_cross_margin.py b/apps/trading/e2e/tests/deal_ticket/test_isolated_cross_margin.py index 88db44a67..996619970 100644 --- a/apps/trading/e2e/tests/deal_ticket/test_isolated_cross_margin.py +++ b/apps/trading/e2e/tests/deal_ticket/test_isolated_cross_margin.py @@ -9,6 +9,16 @@ leverage_input = "#leverage-input" tab_positions = "tab-positions" margin_row = '[col-id="margin"]' +current_margin = "deal-ticket-fee-current-margin" +available_collateral = "deal-ticket-fee-available-collateral" +additional_margin_required = "deal-ticket-fee-additional-margin-required" +liquidation_estimate = "deal-ticket-fee-liquidation-estimate" +dialog_content = "dialog-content" +cross_margin = "cross-margin" +isolated_margin = "isolated-margin" +confirm_cross_margin_mode = "confirm-cross-margin-mode" +confirm_isolated_margin_mode = "confirm-isolated-margin-mode" + def create_position(vega: VegaServiceNull, market_id): submit_order(vega, "Key 1", market_id, "SIDE_SELL", 100, 110) @@ -29,10 +39,9 @@ def test_switch_cross_isolated_margin( expect(page.get_by_test_id(tooltip_content).nth(0)).to_have_text( "Liquidation: 582.81328Margin: 874.21992General account: 998,084.95183" ) - page.get_by_role("button", name="Isolated 10x").click() - page.locator(leverage_input).clear() - page.locator(leverage_input).type("1") - page.get_by_role("button", name="Confirm").click() + page.get_by_test_id(isolated_margin).click() + page.locator(leverage_input).fill("1") + page.get_by_test_id(confirm_isolated_margin_mode).click() wait_for_toast_confirmation(page) next_epoch(vega=vega) expect(page.get_by_test_id("toast-content")).to_have_text( @@ -45,9 +54,52 @@ def test_switch_cross_isolated_margin( expect(page.get_by_test_id(tooltip_content).nth(0)).to_have_text( "Liquidation: 583.62409Margin: 11,109.99996Order: 11,000.00" ) - page.get_by_role("button", name="Cross").click() - page.get_by_role("button", name="Confirm").click() + page.get_by_test_id(cross_margin).click() + page.get_by_test_id(confirm_cross_margin_mode).click() wait_for_toast_confirmation(page) next_epoch(vega=vega) expect(page.locator(margin_row).nth(1)).to_have_text( "22,109.99996Cross1.0x") + + +@pytest.mark.usefixtures("auth", "risk_accepted") +def test_check_cross_isolated_margin_info( + continuous_market, vega: VegaServiceNull, page: Page): + create_position(vega, continuous_market) + page.goto(f"/#/markets/{continuous_market}") + expect(page.get_by_test_id(current_margin)).to_have_text( + "Current margin874.21992 tDAI") + expect(page.get_by_test_id(available_collateral) + ).to_have_text("Available collateral998,084.95183 tDAI") + expect(page.get_by_test_id(additional_margin_required) + ).to_have_text("Additional margin required0.00 tDAI") + expect(page.get_by_test_id(liquidation_estimate) + ).to_have_text("Liquidation estimate- BTC") + page.get_by_test_id(isolated_margin).click() + page.locator(leverage_input).fill("6") + expect(page.get_by_test_id(dialog_content).get_by_test_id("notification")).to_have_text( + "You have an existing position and and open order on this market.Changing the margin mode and leverage will move 2,703.11341 tDAI from your general account to fund the position.") + expect(page.get_by_test_id(dialog_content).get_by_test_id(current_margin)).to_have_text( + "Current margin874.21992 tDAI") + expect(page.get_by_test_id(dialog_content).get_by_test_id(available_collateral) + ).to_have_text("Available collateral998,084.95183 tDAI") + expect(page.get_by_test_id(dialog_content).get_by_test_id(additional_margin_required) + ).to_have_text("Additional margin required2,703.11341 tDAI") + expect(page.get_by_test_id(dialog_content).get_by_test_id(liquidation_estimate) + ).to_have_text("Liquidation estimate95.23553 BTC") + page.get_by_test_id(confirm_isolated_margin_mode).click() + wait_for_toast_confirmation(page) + next_epoch(vega=vega) + expect(page.get_by_test_id("toast-content")).to_have_text( + "ConfirmedYour transaction has been confirmedView in block explorerUpdate margin modeBTC:DAI_2023Isolated margin mode, leverage: 6.0x") + page.get_by_test_id(cross_margin).click() + expect(page.get_by_test_id(dialog_content).get_by_test_id( + "notification")).not_to_be_visible() + expect(page.get_by_test_id(dialog_content).get_by_test_id(current_margin)).to_have_text( + "Current margin4,223.33332 tDAI") + expect(page.get_by_test_id(dialog_content).get_by_test_id(available_collateral) + ).to_have_text("Available collateral995,381.83843 tDAI") + expect(page.get_by_test_id(dialog_content).get_by_test_id(additional_margin_required) + ).to_have_text("Additional margin required0.00 tDAI") + expect(page.get_by_test_id(dialog_content).get_by_test_id(liquidation_estimate) + ).to_have_text("Liquidation estimate0.00 BTC") diff --git a/libs/deal-ticket/src/components/deal-ticket/margin-mode-selector.tsx b/libs/deal-ticket/src/components/deal-ticket/margin-mode-selector.tsx index a0113d637..0db80f69f 100644 --- a/libs/deal-ticket/src/components/deal-ticket/margin-mode-selector.tsx +++ b/libs/deal-ticket/src/components/deal-ticket/margin-mode-selector.tsx @@ -222,6 +222,7 @@ const CrossMarginModeDialog = ({ @@ -363,6 +368,7 @@ export const MarginModeSelector = ({ marketId }: { marketId: string }) => {