Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spark Multiply - History test #211

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/pages/position/history.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { expect, Page } from '@playwright/test';
import { step } from '#noWalletFixtures';

type LogPropertyName =
| 'Collateral Deposit'
| 'Total collateral'
| 'Position debt'
| 'Loan To Value'
| 'Liquidation price'
| 'Multiple'
| 'Net value'
| 'Swapped'
| 'Market price'
| 'Fees incl. gas';

type LogProperty = { property: LogPropertyName; value: string };

type LogData = LogProperty[];

export class History {
readonly page: Page;

constructor(page: Page) {
this.page = page;
}

@step
async openLog(logname: 'Open Position') {
await this.page.locator(`li:has-text("${logname}")`).click();
}

@step
async shouldHaveLogData(logData: LogData) {
for (const property in logData) {
await expect(
this.page.getByText(logData[property].property, { exact: true }).locator('..')
).toContainText(logData[property].value);
}
}
}
4 changes: 4 additions & 0 deletions src/pages/position/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect, Page } from '@playwright/test';
import { expectDefaultTimeout, positionTimeout } from 'utils/config';
import { step } from '#noWalletFixtures';
import { History } from './history';
import { Manage } from './manage';
import { Optimization } from './optimization';
import { OrderInformation } from './orderInformation';
Expand All @@ -11,6 +12,8 @@ import { Setup } from './setup';
export class Position {
readonly page: Page;

readonly history: History;

readonly manage: Manage;

readonly optimization: Optimization;
Expand All @@ -25,6 +28,7 @@ export class Position {

constructor(page: Page) {
this.page = page;
this.history = new History(page);
this.manage = new Manage(page);
this.optimization = new Optimization(page);
this.orderInformation = new OrderInformation(page);
Expand Down
4 changes: 2 additions & 2 deletions tests/withWallet/spark/multiply/sparkMultiply1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test.describe('Spark Multiply - Wallet connected', async () => {
await resetState();
});

test('It should siwtch a Spark Multiply Short position to Borrow interface', async () => {
test('It should switch a Spark Multiply Short position to Borrow interface', async () => {
test.info().annotations.push({
type: 'Test case',
description: 'xxx',
Expand Down Expand Up @@ -72,7 +72,7 @@ test.describe('Spark Multiply - Wallet connected', async () => {
});
});

test('It should siwtch a Spark Multiply Short position (from Borrow) back to Multiply interface', async () => {
test('It should switch a Spark Multiply Short position (from Borrow) back to Multiply interface', async () => {
test.info().annotations.push({
type: 'Test case',
description: 'xxx',
Expand Down
73 changes: 73 additions & 0 deletions tests/withWallet/spark/multiply/sparkMultiply5.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { BrowserContext, test } from '@playwright/test';
import { metamaskSetUp } from 'utils/setup';
import { resetState } from '@synthetixio/synpress/commands/synpress';
import * as tenderly from 'utils/tenderly';
import { setup } from 'utils/setup';
import { veryLongTestTimeout } from 'utils/config';
import { App } from 'src/app';

let context: BrowserContext;
let app: App;
let forkId: string;
let walletAddress: string;

test.describe.configure({ mode: 'serial' });

test.describe('Spark Multiply - Wallet connected', async () => {
test.afterAll(async () => {
await tenderly.deleteFork(forkId);

await app.page.close();

await context.close();

await resetState();
});

test('It should show History of a Spark Multiply Short position', async () => {
test.info().annotations.push({
type: 'Test case',
description: 'xxx',
});

test.setTimeout(veryLongTestTimeout);

await test.step('Test setup', async () => {
({ context } = await metamaskSetUp({ network: 'mainnet' }));
let page = await context.newPage();
app = new App(page);

({ forkId, walletAddress } = await setup({ app, network: 'mainnet' }));
await tenderly.setTokenBalance({
forkId,
walletAddress,
network: 'mainnet',
token: 'SDAI',
balance: '50000',
});
});

await tenderly.changeAccountOwner({
account: '0xb585a1bae38dc735988cc75278aecae786e6a5d6',
newOwner: walletAddress,
forkId,
});

await app.position.openPage('/ethereum/spark/multiply/sdai-eth/1448#overview');

await app.position.openTab('History');
await app.position.history.openLog('Open Position');
await app.position.history.shouldHaveLogData([
{ property: 'Collateral Deposit', value: '4.0000 SDAI' },
{ property: 'Total collateral', value: '0.00 SDAI 12.93 SDAI' },
{ property: 'Position debt', value: '0.00 ETH 0.0057 ETH' },
{ property: 'Loan To Value', value: '0.00% 144.02%' },
{ property: 'Liquidation price', value: '1,714.84 ETH/SDAI' },
{ property: 'Multiple', value: '0.00x 3.27x' },
{ property: 'Net value', value: '0.00 USD4.09 USD' },
{ property: 'Swapped', value: '0.0057 ETH8.9355 SDAI' },
{ property: 'Market price', value: '1,566.60 ETH/SDAI' },
{ property: 'Fees incl. gas', value: '28.93 USD' },
]);
});
});