Skip to content

Commit

Permalink
No-wallet - Simultae risk adjustment - Aave
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-langa committed Nov 3, 2023
1 parent 65cc7d6 commit 7025731
Show file tree
Hide file tree
Showing 10 changed files with 446 additions and 399 deletions.
2 changes: 1 addition & 1 deletion src/pages/position/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class Base {
@step
async getLiquidationPrice(): Promise<number> {
const value = await this.page.locator('span:has-text("Liquidation Price") + span').innerText();
return parseFloat(value.slice(0, value.indexOf(' ')));
return parseFloat(value.slice(0, value.indexOf(' ')).replace(',', ''));
}

@step
Expand Down
10 changes: 2 additions & 8 deletions src/pages/position/manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,8 @@ export class Manage {
* @param value should be between '0' and '1' both included | 0: far left | 1: far right
*/
@step
async moveSlider({
protocol,
value,
}: {
protocol: 'Aave V2' | 'Aave V3' | 'Ajna' | 'Maker' | 'Spark';
value: number;
}) {
if (protocol === 'Ajna') {
async moveSlider({ protocol, value }: { protocol?: 'Ajna'; value: number }) {
if (protocol) {
await this.base.moveSlider({ value });
} else {
await this.base.moveSlider({ process: 'manage', value });
Expand Down
36 changes: 22 additions & 14 deletions src/pages/position/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,8 @@ 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: 'Aave V2' | 'Aave V3' | 'Ajna' | 'Maker' | 'Spark';
value: number;
}) {
if (protocol === 'Ajna') {
async moveSlider({ protocol, value }: { protocol?: 'Ajna'; value: number }) {
if (protocol) {
await this.base.moveSlider({ value });
} else {
await this.base.moveSlider({ process: 'setup', value });
Expand Down Expand Up @@ -266,13 +260,27 @@ export class Setup {
}

@step
async shouldHaveLiquidationPrice({ amount, pair }: { amount: string; pair?: string }) {
const regExp = new RegExp(`${amount}${pair ? ` ${pair}` : ''}`);
async shouldHaveLiquidationPrice({
amount,
pair,
exactAmount,
}: {
amount: string;
pair?: string;
exactAmount?: boolean;
}) {
if (exactAmount) {
await expect(this.page.locator('span:has-text("Liquidation Price") + span')).toHaveText(
amount
);
} else {
const regExp = new RegExp(`${amount}${pair ? ` ${pair}` : ''}`);

await expect(this.page.locator('span:has-text("Liquidation Price") + span')).toContainText(
regExp,
{ timeout: positionTimeout } // Liquidation price takes longer to be updated
);
await expect(this.page.locator('span:has-text("Liquidation Price") + span')).toContainText(
regExp,
{ timeout: positionTimeout } // Liquidation price takes longer to be updated
);
}
}

@step
Expand Down
54 changes: 53 additions & 1 deletion tests/noWallet/aaveV2/aaveV2Earn.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test } from '#noWalletFixtures';
import { expect, test } from '#noWalletFixtures';
import { longTestTimeout } from 'utils/config';

test.describe('Aave v2 Earn', async () => {
Expand Down Expand Up @@ -65,4 +65,56 @@ test.describe('Aave v2 Earn', async () => {
});
await app.position.setup.orderInformation.shouldHaveTransactionFee({ fee: '0' });
});

test('It should allow to simulate an Aave V2 Earn position before opening it - Adjust risk - Down and Up - No wallet connected @regression', async ({
app,
}) => {
test.info().annotations.push({
type: 'Test case',
description: '12601',
});

test.setTimeout(longTestTimeout);

await app.page.goto('/ethereum/aave/v2/earn/stETHeth#simulate');

// Depositing collateral too quickly after loading page returns wrong simulation results
await app.position.setup.waitForComponentToBeStable();
await app.position.setup.deposit({ token: 'ETH', amount: '19' });

await app.position.setup.shouldHaveLiquidationPrice({
amount: '0.[0-9]([0-9]{2,3})? STETH/ETH',
});
const initialLiqPrice = await app.position.manage.getLiquidationPrice();

// RISK DOWN
await app.position.setup.moveSlider({ value: 0.5 });

// Wait for simulation to update with new risk
await app.position.setup.shouldHaveLiquidationPrice({
amount: '...',
exactAmount: true,
});
await app.position.setup.shouldHaveLiquidationPrice({
amount: '0.[0-9]([0-9]{2,3})? STETH/ETH',
});

const updatedLiqPrice = await app.position.manage.getLiquidationPrice();
expect(updatedLiqPrice).toBeLessThan(initialLiqPrice);

// RISK UP
await app.position.setup.moveSlider({ value: 0.8 });

// Wait for simulation to update with new risk
await app.position.setup.shouldHaveLiquidationPrice({
amount: '...',
exactAmount: true,
});
await app.position.setup.shouldHaveLiquidationPrice({
amount: '0.[0-9]([0-9]{2,3})? STETH/ETH',
});

const updatedLiqPrice2 = await app.position.manage.getLiquidationPrice();
expect(updatedLiqPrice2).toBeGreaterThan(updatedLiqPrice);
});
});
62 changes: 61 additions & 1 deletion tests/noWallet/aaveV2/aaveV2Multiply.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test } from '#noWalletFixtures';
import { expect, test } from '#noWalletFixtures';
import { longTestTimeout } from 'utils/config';

test.describe('Aave v2 Multiply', async () => {
Expand Down Expand Up @@ -72,4 +72,64 @@ test.describe('Aave v2 Multiply', async () => {
token: 'USDC',
});
});

test('It should allow to simulate an Aave V2 Multiply position before opening it - Adjust risk - Up and Down - No wallet connected @regression', async ({
app,
}) => {
test.info().annotations.push({
type: 'Test case',
description: '12599',
});

test.setTimeout(longTestTimeout);

await app.page.goto('/ethereum/aave/v2/multiply/wBTCusdc#simulate');

// Depositing collateral too quickly after loading page returns wrong simulation results
await app.position.overview.waitForComponentToBeStable();
await app.position.setup.deposit({ token: 'WBTC', amount: '1.12345' });

await app.position.overview.shouldHaveLiquidationPriceAfterPill('[0-9],[0-9]{3}.[0-9]{2}');
await app.position.setup.shouldHaveLiquidationPrice({
amount: '[0-9],[0-9]{3}(.[0-9]{1,2})? USDC',
});
const initialLiqPrice = await app.position.manage.getLiquidationPrice();
const initialLoanToValue = await app.position.manage.getLoanToValue();

// RISK UP
await app.position.setup.moveSlider({ value: 0.5 });

// Wait for simulation to update with new risk
await app.position.setup.shouldHaveLiquidationPrice({
amount: '...',
exactAmount: true,
});
await app.position.setup.shouldHaveLiquidationPrice({
amount: '[0-9]{2},[0-9]{3}(.[0-9]{1,2})? USDC',
});

await app.position.overview.shouldHaveLiquidationPriceAfterPill('[0-9]{2},[0-9]{3}.[0-9]{2}');
const updatedLiqPrice = await app.position.manage.getLiquidationPrice();
const updatedLoanToValue = await app.position.manage.getLoanToValue();
expect(updatedLiqPrice).toBeGreaterThan(initialLiqPrice);
expect(updatedLoanToValue).toBeGreaterThan(initialLoanToValue);

// RISK DOWN
await app.position.setup.moveSlider({ value: 0.1 });

// Wait for simulation to update with new risk
await app.position.setup.shouldHaveLiquidationPrice({
amount: '...',
exactAmount: true,
});
await app.position.setup.shouldHaveLiquidationPrice({
amount: '[0-9]{1,2},[0-9]{3}(.[0-9]{1,2})? USDC',
});

await app.position.overview.shouldHaveLiquidationPriceAfterPill('[0-9]{1,2},[0-9]{3}.[0-9]{2}');
const updatedLiqPrice2 = await app.position.manage.getLiquidationPrice();
const updatedLoanToValue2 = await app.position.manage.getLoanToValue();
expect(updatedLiqPrice2).toBeLessThan(updatedLiqPrice);
expect(updatedLoanToValue2).toBeLessThan(updatedLoanToValue);
});
});
Loading

0 comments on commit 7025731

Please sign in to comment.