Skip to content

Commit

Permalink
Merge pull request #138 from OasisDEX/ajna-multiply
Browse files Browse the repository at this point in the history
Ajna Ethereum Multiply tests
  • Loading branch information
juan-langa authored Jan 24, 2024
2 parents 2d5ccd5 + 232209f commit 5775438
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 12 deletions.
8 changes: 5 additions & 3 deletions src/pages/position/overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,17 @@ export class Overview {
token,
timeout,
protocol,
}: { amount: string; token: string; timeout?: number; protocol?: 'Ajna' | 'Morpho Blue' } = {
}: { amount: string; token: string; timeout?: number; protocol?: 'Ajna' } = {
amount: '',
token: '',
timeout: expectDefaultTimeout,
}
) {
let regexObj = new RegExp(`${amount}${protocol ? `${token}` : ` ${token}`}`);
let regexObj = new RegExp(`${amount}.*${token}`);

await expect(this.page.locator('li:has-text(" Debt") > p').nth(0)).toHaveText(regexObj, {
await expect(
this.page.locator(`li:has-text("${protocol ? 'Position Debt' : ' Debt'}") > p`).nth(0)
).toHaveText(regexObj, {
timeout,
});
}
Expand Down
149 changes: 140 additions & 9 deletions tests/withWallet/ajna/ethereum/ajnaMultiplyEthereum.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { resetState } from '@synthetixio/synpress/commands/synpress';
import * as metamask from '@synthetixio/synpress/commands/metamask';
import * as tenderly from 'utils/tenderly';
import { setup } from 'utils/setup';
import { extremelyLongTestTimeout, veryLongTestTimeout, longTestTimeout } from 'utils/config';
import {
extremelyLongTestTimeout,
veryLongTestTimeout,
longTestTimeout,
positionTimeout,
} from 'utils/config';
import { App } from 'src/app';

let context: BrowserContext;
Expand Down Expand Up @@ -184,16 +189,142 @@ test.describe('Ajna Ethereum Multiply - Wallet connected', async () => {

await app.position.setup.continue();

// Position creation randomly fails - Retry until it's created.
await expect(async () => {
await app.position.setup.confirmOrRetry();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
});
await app.position.setup.shouldConfirmPositionCreation();
}).toPass({ timeout: longTestTimeout });
// ======================================================================

// 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.setup.shouldShowCreatingPosition();

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

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

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

test('It should adjust risk of an existing Ajna Ethereum Multiply position - Up @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: 'xxx',
});

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.8 });

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.setup.shouldShowUpdatingPosition();

await app.page.reload();

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

await app.position.manage.shouldBeVisible('Manage your Ajna Multiply Position');
const updatedLiqPrice = await app.position.manage.getLiquidationPrice();
const updatedLoanToValue = await app.position.manage.getLoanToValue();
expect(updatedLiqPrice).toBeGreaterThan(initialLiqPrice);
expect(updatedLoanToValue).toBeGreaterThan(initialLoanToValue);
});

test('It should adjust risk of an existing Ajna Ethereum Multiply position - Down @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: 'xxxx',
});

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.setup.shouldShowUpdatingPosition();

await app.page.reload();

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

await app.position.manage.shouldBeVisible('Manage your Ajna Multiply Position');
const updatedLiqPrice = await app.position.manage.getLiquidationPrice();
const updatedLoanToValue = await app.position.manage.getLoanToValue();
expect(updatedLiqPrice).toBeLessThan(initialLiqPrice);
expect(updatedLoanToValue).toBeLessThan(initialLoanToValue);
});

test('It should Close to collateral an existing Ajna Ethereum Multiply position @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: 'xxxx',
});

test.setTimeout(longTestTimeout);

await app.position.manage.openManageOptions({ currentLabel: 'Adjust' });
await app.position.manage.select('Close position');
await app.position.manage.shouldHaveTokenAmountAfterClosing({
token: 'WSTETH',
amount: '[0-9]{1,2}.[0-9]{1,2}',
});

await app.position.setup.confirm();

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

// UI sometimes gets stuck after confirming position update
// - 'Reload' added to avoid flakines
await app.position.setup.confirm();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
});
await app.position.setup.shouldShowUpdatingPosition();
await app.page.reload();

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

await app.position.overview.shouldHaveLiquidationPrice({
price: '0.00',
timeout: positionTimeout,
});
await app.position.overview.shouldHaveLoanToValue('0.00');
await app.position.overview.shouldHaveNetValue({ value: '0.00' });
await app.position.overview.shouldHaveBuyingPower('0.00');
await app.position.overview.shouldHaveExposure({ token: 'WSTETH', amount: '0.00' });
await app.position.overview.shouldHaveDebt({
amount: '0.00',
token: 'ETH',
protocol: 'Ajna',
});
await app.position.overview.shouldHaveMultiple('1.00');
});
});

0 comments on commit 5775438

Please sign in to comment.