From 2e75458fdb0d7d57a60f6f99f599a1363cf2dcee Mon Sep 17 00:00:00 2001 From: Tiago Silva Date: Wed, 17 Jan 2024 17:59:17 +0000 Subject: [PATCH] Add undercut limit e2e test --- e2e/tests/strategy/recurring/index.ts | 1 + e2e/tests/strategy/recurring/undercut.ts | 79 +++++++++++++++++++ e2e/utils/strategy/MyStrategyDriver.ts | 1 + .../overview/strategyBlock/StrategyGraph.tsx | 2 +- 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 e2e/tests/strategy/recurring/undercut.ts diff --git a/e2e/tests/strategy/recurring/index.ts b/e2e/tests/strategy/recurring/index.ts index 85fe3e490..e7d690aa2 100644 --- a/e2e/tests/strategy/recurring/index.ts +++ b/e2e/tests/strategy/recurring/index.ts @@ -2,6 +2,7 @@ export { createRecurringStrategy } from './create'; export { deleteStrategyTest } from './delete'; export { depositStrategyTest } from './deposit'; export { duplicateStrategyTest } from './duplicate'; +export { undercutStrategyTest } from './undercut'; export { editPriceStrategyTest } from './edit'; export { pauseStrategyTest } from './pause'; export { renewStrategyTest } from './renew'; diff --git a/e2e/tests/strategy/recurring/undercut.ts b/e2e/tests/strategy/recurring/undercut.ts new file mode 100644 index 000000000..64db80bf0 --- /dev/null +++ b/e2e/tests/strategy/recurring/undercut.ts @@ -0,0 +1,79 @@ +import { expect, test } from '@playwright/test'; +import { MyStrategyDriver } from './../../../utils/strategy'; +import { fiatPrice, tokenPrice } from './../../../utils/operators'; +import { CreateStrategyTemplate } from './../../../utils/strategy/template'; +import { NotificationDriver } from './../../../utils/NotificationDriver'; +import { ManageStrategyDriver } from './../../../utils/strategy/ManageStrategyDriver'; +import { waitModalOpen } from '../../../utils/modal'; +import { SafeDecimal } from '../../../../src/libs/safedecimal'; + +export const undercutStrategyTest = (testCase: CreateStrategyTemplate) => { + return test('Undercut', async ({ page }) => { + const { base, quote, buy, sell } = testCase; + const buyBudgetFiat = parseFloat(buy.budgetFiat ?? '0'); + const sellBudgetFiat = parseFloat(sell.budgetFiat ?? '0'); + const undercutRate = 0.001; + + const manage = new ManageStrategyDriver(page); + const strategy = await manage.createStrategy(testCase); + await strategy.clickManageEntry('manage-strategy-duplicateStrategy'); + + const modal = await waitModalOpen(page); + await modal.getByTestId('undercut-strategy-btn').click(); + + await page.waitForURL('/strategies/create?strategy=*', { + timeout: 10_000, + }); + + await page.getByText('Create Strategy').click(); + await page.waitForURL('/', { timeout: 10_000 }); + + const notif = new NotificationDriver(page, 'create-strategy'); + await expect(notif.getTitle()).toHaveText('Success'); + await expect(notif.getDescription()).toHaveText( + 'New strategy was successfully created.' + ); + + const myStrategies = new MyStrategyDriver(page); + const strategies = await myStrategies.getAllStrategies(); + await expect(strategies).toHaveCount(2); + + const strategyUndercut = await myStrategies.getStrategy(2); + + await expect(strategyUndercut.pair()).toHaveText(`${base}/${quote}`); + await expect(strategyUndercut.status()).toHaveText('Active'); + await expect(strategyUndercut.totalBudget()).toHaveText( + fiatPrice(buyBudgetFiat + sellBudgetFiat) + ); + await expect(strategyUndercut.buyBudget()).toHaveText( + tokenPrice(buy.budget, quote) + ); + await expect(strategyUndercut.buyBudgetFiat()).toHaveText( + fiatPrice(buyBudgetFiat) + ); + await expect(strategyUndercut.sellBudget()).toHaveText( + tokenPrice(sell.budget, base) + ); + await expect(strategyUndercut.sellBudgetFiat()).toHaveText( + fiatPrice(sellBudgetFiat) + ); + + const buyTooltip = await strategyUndercut.priceTooltip('buy'); + await expect(buyTooltip.startPrice()).toHaveText( + tokenPrice( + new SafeDecimal(buy.min).times(1 + undercutRate).toString(), + quote + ) + ); + await buyTooltip.waitForDetached(); + + const sellTooltip = await strategyUndercut.priceTooltip('sell'); + await expect(sellTooltip.startPrice()).toHaveText( + tokenPrice( + new SafeDecimal(sell.min).times(1 - undercutRate).toString(), + quote + ) + ); + await sellTooltip.waitForDetached(); + }); +}; diff --git a/e2e/utils/strategy/MyStrategyDriver.ts b/e2e/utils/strategy/MyStrategyDriver.ts index 5ca5046a5..733f02b2e 100644 --- a/e2e/utils/strategy/MyStrategyDriver.ts +++ b/e2e/utils/strategy/MyStrategyDriver.ts @@ -51,6 +51,7 @@ export class MyStrategyDriver { minPrice: () => tooltip.getByTestId('min-price'), maxPrice: () => tooltip.getByTestId('max-price'), marginalPrice: () => tooltip.getByTestId('marginal-price'), + startPrice: () => tooltip.getByTestId('start-price'), waitForDetached: async () => { await this.page.mouse.move(0, 0); await tooltip.waitFor({ state: 'detached' }); diff --git a/src/components/strategies/overview/strategyBlock/StrategyGraph.tsx b/src/components/strategies/overview/strategyBlock/StrategyGraph.tsx index d41280bd0..6a94ef2af 100644 --- a/src/components/strategies/overview/strategyBlock/StrategyGraph.tsx +++ b/src/components/strategies/overview/strategyBlock/StrategyGraph.tsx @@ -578,7 +578,7 @@ const OrderTooltip: FC = ({ strategy, buy }) => { Price - + {startPrice} {quote.symbol}