Skip to content

Commit

Permalink
Merge pull request #173 from OasisDEX/omni-new-multiply
Browse files Browse the repository at this point in the history
Reusing and cleaning - Omnikit
  • Loading branch information
juan-langa authored Feb 14, 2024
2 parents 278e22e + 0c2c43b commit 06deb98
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 202 deletions.
123 changes: 121 additions & 2 deletions src/pages/position/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, Page } from '@playwright/test';
import { positionTimeout } from 'utils/config';
import { expect, Page, test } from '@playwright/test';
import { longTestTimeout, positionTimeout } from 'utils/config';
import * as tx from 'utils/tx';
import { step } from '#noWalletFixtures';
import { Manage } from './manage';
import { Optimization } from './optimization';
Expand Down Expand Up @@ -51,4 +52,122 @@ export class Position {
async openTab(tab: string) {
await this.page.getByRole('button', { name: tab }).click();
}

@step
async openNewMultiplyPosition({
forkId,
deposit,
}: {
forkId: string;
deposit: { token: string; amount: string };
}) {
const { token, amount } = deposit;
// await this.setup.deposit({ token: 'WSTETH', amount: '70' });
await this.setup.deposit({ token, amount });
await this.setup.createSmartDeFiAccount();

// Smart DeFi Acount creation randomly fails - Retry until it's created.
await test.step('Confirm Smart DeFi account and verify tx success', async () => {
await expect(async () => {
await this.setup.createSmartDeFiAccount();
await tx.confirmAndVerifySuccess({ metamaskAction: 'confirmAddToken', forkId });
await this.setup.continueShouldBeVisible();
}).toPass({ timeout: longTestTimeout });
});

await this.setup.continue();

// Setting up allowance randomly fails - Retry until it's set.
await test.step('Approve allowance and verify tx success', async () => {
await expect(async () => {
await this.setup.approveAllowance();
await tx.confirmAndVerifySuccess({ metamaskAction: 'confirmAddToken', forkId });
await this.setup.continueShouldBeVisible();
}).toPass({ timeout: longTestTimeout });
});

await this.setup.continue();

// Position creation randomly fails - Retry until it's created.
await expect(async () => {
await this.setup.confirmOrRetry();
await tx.confirmAndVerifySuccess({ metamaskAction: 'confirmPermissionToSpend', forkId });
await this.setup.shouldShowCreatingPosition();
}).toPass({ timeout: longTestTimeout });

// UI sometimes gets stuck after confirming position creation
// - 'Reload' added to avoid flakines
await this.page.reload();
}

@step
async adjustRiskOnExistingMultiplyPosition({
protocol,
forkId,
newSliderPosition,
}: {
protocol: 'Ajna' | 'Morpho';
forkId: string;
newSliderPosition: number;
}) {
await this.setup.moveSlider({ protocol, value: newSliderPosition });

await this.manage.confirm();

// UI sometimes gets stuck after confirming position creation
// - 'Reload' added to avoid flakines
await this.setup.confirm();
await tx.confirmAndVerifySuccess({ forkId, metamaskAction: 'confirmPermissionToSpend' });
await this.setup.shouldShowUpdatingPosition();

await this.page.reload();
}

@step
async adjustRiskOnExistingMultiplyPosition_UP({
protocol,
forkId,
newSliderPosition,
}: {
protocol: 'Ajna' | 'Morpho';
forkId: string;
newSliderPosition: number;
}) {
const initialLiqPrice = await this.manage.getLiquidationPrice();
const initialLoanToValue = await this.manage.getLoanToValue();

await this.adjustRiskOnExistingMultiplyPosition({ protocol, forkId, newSliderPosition });

// Wait for Liq price to update
await expect(async () => {
const updatedLiqPrice = await this.manage.getLiquidationPrice();
const updatedLoanToValue = await this.manage.getLoanToValue();
expect(updatedLiqPrice).toBeGreaterThan(initialLiqPrice);
expect(updatedLoanToValue).toBeGreaterThan(initialLoanToValue);
}, 'New Liq. Price and LTV should be higher than original ones').toPass();
}

@step
async adjustRiskOnExistingMultiplyPosition_DOWN({
protocol,
forkId,
newSliderPosition,
}: {
protocol: 'Ajna' | 'Morpho';
forkId: string;
newSliderPosition: number;
}) {
const initialLiqPrice = await this.manage.getLiquidationPrice();
const initialLoanToValue = await this.manage.getLoanToValue();

await this.adjustRiskOnExistingMultiplyPosition({ protocol, forkId, newSliderPosition });

// Wait for Liq price to update
await expect(async () => {
const updatedLiqPrice = await this.manage.getLiquidationPrice();
const updatedLoanToValue = await this.manage.getLoanToValue();
expect(updatedLiqPrice).toBeLessThan(initialLiqPrice);
expect(updatedLoanToValue).toBeLessThan(initialLoanToValue);
}, 'New Liq. Price and LTV should be lower than original ones').toPass();
}
}
2 changes: 1 addition & 1 deletion src/pages/position/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class Setup {
* @param value should be between '0' and '1' both included | 0: far left | 1: far right
*/
@step
async moveSlider({ protocol, value }: { protocol?: 'Ajna' | 'Morpho Blue'; value: number }) {
async moveSlider({ protocol, value }: { protocol?: 'Ajna' | 'Morpho'; value: number }) {
if (protocol) {
await this.base.moveSlider({ value });
} else {
Expand Down
109 changes: 11 additions & 98 deletions tests/withWallet/ajna/ethereum/ajnaMultiplyEthereum.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,47 +164,12 @@ test.describe('Ajna Ethereum Multiply - Wallet connected', async () => {
await app.page.goto('/ethereum/ajna/multiply/WSTETH-ETH#setup');
await app.position.setup.acknowlegeAjnaInfo();

await app.position.setup.deposit({ token: 'WSTETH', amount: '70' });
await app.position.setup.createSmartDeFiAccount();

// Smart DeFi Acount creation randomly fails - Retry until it's created.
await expect(async () => {
await app.position.setup.createSmartDeFiAccount();
await test.step('Metamask: ConfirmAddToken', async () => {
await metamask.confirmAddToken();
});
await app.position.setup.continueShouldBeVisible();
}).toPass({ timeout: longTestTimeout });

await app.position.setup.continue();

// Setting up allowance randomly fails - Retry until it's set.
await expect(async () => {
await app.position.setup.approveAllowance();
await test.step('Metamask: ConfirmAddToken', async () => {
await metamask.confirmAddToken();
});
await app.position.setup.continueShouldBeVisible();
}).toPass({ timeout: longTestTimeout });

await app.position.setup.continue();

// ======================================================================

// UI sometimes gets stuck after confirming position creation
// - 'Reload' added to avoid flakines

await app.position.setup.confirm();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
await app.position.openNewMultiplyPosition({
forkId,
deposit: { token: 'WSTETH', amount: '70' },
});
await app.position.setup.shouldShowCreatingPosition();

await app.page.reload();
await app.position.setup.goToPosition();

// ======================================================================

await app.position.manage.shouldBeVisible('Manage your Ajna Multiply Position');
});

Expand All @@ -216,37 +181,11 @@ test.describe('Ajna Ethereum Multiply - Wallet connected', async () => {

test.setTimeout(longTestTimeout);

const initialLiqPrice = await app.position.manage.getLiquidationPrice();
const initialLoanToValue = await app.position.manage.getLoanToValue();

await app.position.setup.moveSlider({ protocol: 'Ajna', value: 0.6 });

await app.position.manage.confirm();

// ======================================================================

// UI sometimes gets stuck after confirming position creation
// - 'Reload' added to avoid flakines

await app.position.setup.confirm();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
await app.position.adjustRiskOnExistingMultiplyPosition_UP({
protocol: 'Ajna',
forkId,
newSliderPosition: 0.6,
});
await app.position.setup.shouldShowUpdatingPosition();

await app.page.reload();

// ======================================================================

await app.position.manage.shouldBeVisible('Manage your Ajna Multiply Position');

// Wait for Liq price to update
await expect(async () => {
const updatedLiqPrice = await app.position.manage.getLiquidationPrice();
const updatedLoanToValue = await app.position.manage.getLoanToValue();
expect(updatedLiqPrice).toBeGreaterThan(initialLiqPrice);
expect(updatedLoanToValue).toBeGreaterThan(initialLoanToValue);
}).toPass();
});

test('It should adjust risk of an existing Ajna Ethereum Multiply position - Down @regression', async () => {
Expand All @@ -257,37 +196,11 @@ test.describe('Ajna Ethereum Multiply - Wallet connected', async () => {

test.setTimeout(longTestTimeout);

const initialLiqPrice = await app.position.manage.getLiquidationPrice();
const initialLoanToValue = await app.position.manage.getLoanToValue();

await app.position.setup.moveSlider({ protocol: 'Ajna', value: 0.5 });

await app.position.manage.confirm();

// ======================================================================

// UI sometimes gets stuck after confirming position creation
// - 'Reload' added to avoid flakines

await app.position.setup.confirm();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
await app.position.adjustRiskOnExistingMultiplyPosition_DOWN({
protocol: 'Ajna',
forkId,
newSliderPosition: 0.5,
});
await app.position.setup.shouldShowUpdatingPosition();

await app.page.reload();

// ======================================================================

await app.position.manage.shouldBeVisible('Manage your Ajna Multiply Position');

// Wait for Liq price to update
await expect(async () => {
const updatedLiqPrice = await app.position.manage.getLiquidationPrice();
const updatedLoanToValue = await app.position.manage.getLoanToValue();
expect(updatedLiqPrice).toBeLessThan(initialLiqPrice);
expect(updatedLoanToValue).toBeLessThan(initialLoanToValue);
}).toPass();
});

test('It should Close to collateral an existing Ajna Ethereum Multiply position @regression', async () => {
Expand Down
Loading

0 comments on commit 06deb98

Please sign in to comment.