Skip to content

Commit

Permalink
Aave V2 - Simulate positions tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-langa committed Nov 2, 2023
1 parent 879bc0c commit d9bf4c1
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 105 deletions.
2 changes: 1 addition & 1 deletion src/modals/connectWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export class ConnectWallet {
await expect(
this.page.getByText('Available Wallets'),
'"Available Wallets" should be visible'
).toBeVisible({ timeout: 15_000 });
).toBeVisible({ timeout: 20_000 });
}
}
89 changes: 21 additions & 68 deletions src/pages/position/orderInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ export class OrderInformation {
);
await expect(
this.orderInformationLocator.locator('li:has-text("Buying") div:nth-child(2)')
).toContainText(regExp, {
timeout: positionTimeout,
});
).toContainText(regExp);
}

@step
Expand All @@ -40,9 +38,7 @@ export class OrderInformation {

await expect(
this.orderInformationLocator.locator('li:has-text("Flashloan Amount")')
).toContainText(regExp, {
timeout: positionTimeout,
});
).toContainText(regExp);
}

@step
Expand All @@ -51,40 +47,31 @@ export class OrderInformation {

await expect(
this.orderInformationLocator.locator('li:has-text("Flashloan Provider Liquidity")')
).toContainText(regExp, {
timeout: positionTimeout,
});
).toContainText(regExp);
}

@step
async shouldHavePriceImpact({ amount, percentage }: { amount: string; percentage: string }) {
const regExp = new RegExp(`${amount} \\(${percentage}%\\)`);
await expect(
this.orderInformationLocator.locator('li:has-text("Price (impact)")')
).toContainText('%)', {
timeout: positionTimeout,
});
).toContainText(regExp);
}

@step
async shouldHaveSlippageLimit(amount: string) {
const regExp = new RegExp(`${amount}%`);
await expect(
this.orderInformationLocator.locator('li:has-text("Slippage Limit")')
).toContainText(regExp, {
timeout: positionTimeout,
});
).toContainText(regExp);
}

@step
async shouldHaveMultiply({ current, future }: { current: string; future: string }) {
const regExp = new RegExp(`${current}x${future}x`);

await expect(this.orderInformationLocator.locator('li:has-text("Multiply")')).toContainText(
regExp,
{
timeout: positionTimeout,
}
regExp
);
}

Expand All @@ -93,10 +80,7 @@ export class OrderInformation {
const regExp = new RegExp(`${current}x${future}x`);

await expect(this.orderInformationLocator.locator('li:has-text("Multiple")')).toContainText(
regExp,
{
timeout: positionTimeout,
}
regExp
);
}

Expand All @@ -114,9 +98,7 @@ export class OrderInformation {

await expect(
this.orderInformationLocator.locator('li:has-text("Outstanding debt")')
).toContainText(regExp, {
timeout: positionTimeout,
});
).toContainText(regExp);
}

@step
Expand All @@ -133,18 +115,14 @@ export class OrderInformation {

await expect(
this.orderInformationLocator.locator('li:has-text("Total collateral")')
).toContainText(regExp, {
timeout: positionTimeout,
});
).toContainText(regExp);
}

@step
async shouldHaveLTV({ current, future }: { current: string; future: string }) {
const regExp = new RegExp(`${current}% ${future}%`);

await expect(this.orderInformationLocator.locator('li:has-text("LTV")')).toContainText(regExp, {
timeout: positionTimeout,
});
await expect(this.orderInformationLocator.locator('li:has-text("LTV")')).toContainText(regExp);
}

@step
Expand All @@ -153,9 +131,7 @@ export class OrderInformation {

await expect(
this.orderInformationLocator.locator('li:has-text("Transaction fee")')
).toContainText(regExp, {
timeout: positionTimeout,
});
).toContainText(regExp);
}

@step
Expand All @@ -172,20 +148,15 @@ export class OrderInformation {

await expect(
this.orderInformationLocator.locator('li:has-text("Amount to Lend")')
).toContainText(regExp, {
timeout: positionTimeout,
});
).toContainText(regExp);
}

@step
async shouldHaveNetAPY({ current, future }: { current: string; future: string }) {
const regExp = new RegExp(`${current}%${future}%`);

await expect(this.orderInformationLocator.locator('li:has-text("Net APY")')).toContainText(
regExp,
{
timeout: positionTimeout,
}
regExp
);
}

Expand All @@ -203,20 +174,15 @@ export class OrderInformation {

await expect(
this.orderInformationLocator.locator('li:has-text("Lending Price")')
).toContainText(regExp, {
timeout: positionTimeout,
});
).toContainText(regExp);
}

@step
async shouldHaveMaxLTV({ current, future }: { current: string; future: string }) {
const regExp = new RegExp(`${current}%${future}%`);

await expect(this.orderInformationLocator.locator('li:has-text("Max LTV")')).toContainText(
regExp,
{
timeout: positionTimeout,
}
regExp
);
}

Expand All @@ -225,20 +191,15 @@ export class OrderInformation {
const regExp = new RegExp(`${amount} ${token}`);

await expect(this.orderInformationLocator.locator('li:has-text("Deposit fee")')).toContainText(
regExp,
{
timeout: positionTimeout,
}
regExp
);
}

@step
async shouldHaveTotalDeposit({ amount, token }: { amount: string; token: string }) {
await expect(
this.orderInformationLocator.locator(`li:has-text("Total ${token} deposit")`)
).toContainText(amount, {
timeout: positionTimeout,
});
).toContainText(amount);
}

@step
Expand All @@ -247,19 +208,15 @@ export class OrderInformation {

await expect(
this.orderInformationLocator.locator('li:has-text("Estimated transaction cost")')
).toContainText(regExp, {
timeout: positionTimeout,
});
).toContainText(regExp);
}

@step
async shouldHaveTotalSdaiToConvert(amount: string) {
const regExp = new RegExp(amount);
await expect(
this.orderInformationLocator.locator('li:has-text("Total SDAI convert")')
).toContainText(regExp, {
timeout: positionTimeout,
});
).toContainText(regExp);
}

@step
Expand All @@ -276,9 +233,7 @@ export class OrderInformation {

await expect(
this.orderInformationLocator.locator(`li:has-text("Total ${token} exposure")`)
).toContainText(regExp, {
timeout: positionTimeout,
});
).toContainText(regExp);
}

@step
Expand All @@ -287,9 +242,7 @@ export class OrderInformation {

await expect(
this.orderInformationLocator.locator('li:has-text("Collateral Ratio")')
).toContainText(regExp, {
timeout: positionTimeout,
});
).toContainText(regExp);
}

@step
Expand Down
31 changes: 10 additions & 21 deletions src/pages/position/overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,11 @@ export class Overview {
).toHaveText(regExp, { timeout: positionTimeout });
}

/**
@param price - It must be regExp representing the the whole amount
*/
@step
async shouldHaveLoanToValueAfterPill(percentage: RegExp) {
async shouldHaveLoanToValueAfterPill(percentage: string) {
const regExp = new RegExp(percentage);
await expect(
this.page.getByText('Loan to Value').locator('..').getByText('After')
).toContainText(percentage, { timeout: positionTimeout });
).toContainText(regExp);
}

@step
Expand All @@ -123,9 +120,6 @@ export class Overview {
).not.toHaveText('0.00%');
}

/**
@param cost - It must be regExp representing the the whole amount
*/
@step
async shouldHaveBorrowCost(cost: string) {
const regExp = new RegExp(`${cost}%`);
Expand All @@ -134,14 +128,12 @@ export class Overview {
).toHaveText(regExp, { timeout: positionTimeout });
}

/**
@param cost - It must be regExp representing the the whole amount
*/
@step
async shouldHaveBorrowCostAfterPill(cost: RegExp) {
async shouldHaveBorrowCostAfterPill(cost: string) {
const regExp = new RegExp(cost);
await expect(
this.page.getByText('Cost to Borrow').locator('..').getByText('After')
).toContainText(cost, { timeout: positionTimeout });
).toContainText(regExp);
}

/**
Expand Down Expand Up @@ -190,8 +182,7 @@ export class Overview {
let regExp = new RegExp(`${amount} ${token}`);

await expect(this.page.locator('li:has-text("exposure")').getByText('After')).toContainText(
regExp,
{ timeout: positionTimeout }
regExp
);
}

Expand Down Expand Up @@ -220,8 +211,7 @@ export class Overview {
let regexObj = new RegExp(`${amount} ${token}`);

await expect(this.page.locator('li:has-text(" Debt")').getByText('After')).toContainText(
regexObj,
{ timeout: positionTimeout }
regexObj
);
}

Expand All @@ -239,8 +229,7 @@ export class Overview {
let regexObj = new RegExp(`${amount}x`);

await expect(this.page.locator('li:has-text("Multiple")').getByText('After')).toContainText(
regexObj,
{ timeout: positionTimeout }
regexObj
);
}

Expand Down Expand Up @@ -280,7 +269,7 @@ export class Overview {
? this.page.getByText('Buying Power').locator('..')
: this.page.locator('li:has-text("Buying Power")');

await expect(locator.getByText('After')).toContainText(regexObj, { timeout: positionTimeout });
await expect(locator.getByText('After')).toContainText(regexObj);
}

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

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

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: '33.12345' });

await app.position.overview.shouldHaveTokenAmount({ amount: '33.12', token: 'ETH' });
await app.position.overview.shouldHavePrev30daysNetValue({
token: 'ETH',
amount: '33.[0-9]{2}',
});
await app.position.setup.shouldHaveCurrentPrice({
amount: '[0-9](.[0-9]{2,4})?',
pair: 'STETH/ETH',
});
await app.position.setup.shouldHaveLiquidationPrice({
amount: '[0-3].[0-9]{3,4}',
pair: 'STETH/ETH',
});
await app.position.setup.orderInformation.shouldHaveBuyingAmount({
tokenAmount: '[0-9]{2,3}.[0-9]{5}',
token: 'STETH',
dollarsAmount: '[0-9]{2,3},[0-9]{3}.[0-9]{2}',
});
await app.position.setup.orderInformation.shouldHaveFlashloanAmount({
token: 'DAI',
amount: '[0-9]{2,3},[0-9]{3}.[0-9]{4}',
});
await app.position.setup.orderInformation.shouldHavePriceImpact({
amount: '[0-9].[0-9]{4}',
percentage: '0.[0-9]{2}',
});
await app.position.setup.orderInformation.shouldHaveSlippageLimit('0.[0-9]{2}');
await app.position.setup.orderInformation.shouldHaveMultiply({
current: '1',
future: '[1-9](.[0-9]{1,2})?',
});
await app.position.setup.orderInformation.shouldHaveOutstandingDebt({
token: 'ETH',
current: '0.00000',
future: '[0-9]{2,3}.[0-9]{5}',
});
await app.position.setup.orderInformation.shouldHaveTotalCollateral({
token: 'STETH',
current: '0.00000',
future: '[0-9]{2,3}.[0-9]{5}',
});
await app.position.setup.orderInformation.shouldHaveLTV({
current: '0.00',
future: '[0-9]{2,3}.[0-9]{2}',
});
await app.position.setup.orderInformation.shouldHaveTransactionFee({ fee: '0' });
});
});
Loading

0 comments on commit d9bf4c1

Please sign in to comment.