Skip to content

Commit

Permalink
With wallet Ajna tests (simulation not working if wallet not connected)
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-langa committed Nov 10, 2023
1 parent fb27769 commit 0c9f98c
Show file tree
Hide file tree
Showing 14 changed files with 539 additions and 222 deletions.
7 changes: 5 additions & 2 deletions src/pages/position/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ export class Base {
}

@step
async getLoanToValue(): Promise<number> {
const value = await this.page.locator('span:has-text("Loan to Value") + span').innerText();
async getLoanToValue(protocol?: 'Ajna'): Promise<number> {
const ltvLocator = protocol
? 'span:has-text("Loan to Value") + span span'
: 'span:has-text("Loan to Value") + span';
const value = await this.page.locator(ltvLocator).innerText();
return parseFloat(value.slice(0, -1));
}

Expand Down
5 changes: 4 additions & 1 deletion src/pages/position/manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export class Manage {
}

@step
async getLoanToValue(): Promise<number> {
async getLoanToValue(protocol?: 'Ajna'): Promise<number> {
if (protocol) {
return await this.base.getLoanToValue('Ajna');
}
return await this.base.getLoanToValue();
}

Expand Down
119 changes: 112 additions & 7 deletions src/pages/position/orderInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ export class OrderInformation {
tokenAmount: string;
token: string;
dollarsAmount: string;
protocol?: 'Maker';
protocol?: 'Maker' | 'Ajna';
}) {
const regExp = new RegExp(
`${tokenAmount} ${token} ${protocol ? '\\(' : ''}\\$${dollarsAmount}${protocol ? '\\)' : ''}`
`${tokenAmount} ${token}${
protocol === 'Maker' ? ' \\(' : protocol === 'Ajna' ? '\\(' : ' '
}\\$${dollarsAmount}${protocol ? '\\)' : ''}`
);
await expect(
this.orderInformationLocator.locator('li:has-text("Buying") div:nth-child(2)')
Expand All @@ -51,8 +53,18 @@ export class OrderInformation {
}

@step
async shouldHavePriceImpact({ amount, percentage }: { amount: string; percentage: string }) {
const regExp = new RegExp(`${amount} \\(${percentage}%\\)`);
async shouldHavePriceImpact({
amount,
percentage,
protocol,
pair,
}: {
amount: string;
percentage: string;
protocol?: 'Ajna';
pair?: string;
}) {
const regExp = new RegExp(`${amount} ${protocol ? `${pair}` : ''}\\(${percentage}%\\)`);
await expect(
this.orderInformationLocator.locator('li:has-text("Price (impact)")')
).toContainText(regExp);
Expand Down Expand Up @@ -101,6 +113,21 @@ export class OrderInformation {
).toContainText(regExp);
}

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

await expect(this.orderInformationLocator.locator('li:has-text("Debt")')).toContainText(regExp);
}

@step
async shouldHaveTotalCollateral({
token,
Expand All @@ -119,10 +146,20 @@ export class OrderInformation {
}

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

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

@step
Expand Down Expand Up @@ -253,4 +290,72 @@ export class OrderInformation {
this.orderInformationLocator.locator('li:has-text("Fees + (max gas fee)")')
).toContainText(regExp);
}

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

await expect(
this.orderInformationLocator.locator('li:has-text("Collateral Locked")')
).toContainText(regExp);
}

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

await expect(
this.orderInformationLocator.locator('li:has-text("Liquidation Price")')
).toContainText(regExp);
}

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

await expect(
this.orderInformationLocator.locator('li:has-text("Available to Withdraw")')
).toContainText(regExp);
}

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

await expect(
this.orderInformationLocator.locator('li:has-text("Available to Borrow")')
).toContainText(regExp);
}
}
27 changes: 23 additions & 4 deletions src/pages/position/overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export class Overview {
).toHaveText(regExp, { timeout: positionTimeout });
}

@step
async shouldHaveLoanToValueAfterPill(percentage: string) {
const regExp = new RegExp(percentage);
await expect(
Expand Down Expand Up @@ -207,12 +208,22 @@ export class Overview {
}

@step
async shouldHaveDebtAfterPill({ amount, token }: { amount: string; token: string }) {
async shouldHaveDebtAfterPill({
amount,
token,
protocol,
}: {
amount: string;
token: string;
protocol?: 'Ajna';
}) {
const debtElement = protocol
? this.page.getByText('Position debt').locator('..')
: this.page.locator('li:has-text(" Debt")');

let regexObj = new RegExp(`${amount} ${token}`);

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

@step
Expand Down Expand Up @@ -305,6 +316,14 @@ export class Overview {
).toContainText(regExp);
}

@step
async shouldHaveAvailableToBorrow({ amount, token }: { amount: string; token: string }) {
const regExp = new RegExp(`${amount} ${token}`);
await expect(
this.page.locator('li:has-text("Available to borrow")').getByText('After')
).toContainText(regExp);
}

/**
@param price - It must be regExp representing the the whole amount
*/
Expand Down
17 changes: 17 additions & 0 deletions src/pages/position/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,21 @@ export class Setup {
regExp
);
}

@step
async shouldHaveOriginationFee({
token,
tokenAmount,
dollarsAmount,
}: {
token: string;
tokenAmount: string;
dollarsAmount: string;
}) {
const regExp = new RegExp(`${tokenAmount} ${token} \\(\\$${dollarsAmount}\\)`);

await expect(this.page.locator('p > span:has-text("Origination Fee") + span')).toContainText(
regExp
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test.describe('Aave v3 Multiply Ethereum', async () => {
await app.position.overview.shouldHaveBorrowCostAfterPill('[0-9].[0-9]{2}');
await app.position.overview.shouldHaveNetValueAfterPill('[4-8][0-9],[0-9]{3}.[0-9]{2}');
await app.position.overview.shouldHaveExposureAfterPill({
amount: '[1-4].[0-9]{5}',
amount: '[2-4].[0-9]{5}',
token: 'WBTC',
});
await app.position.overview.shouldHaveDebtAfterPill({
Expand Down
4 changes: 2 additions & 2 deletions tests/withWallet/aaveV3/base/aaveV3MultiplyBase.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ test.describe('Aave v3 Multiply - Base - Wallet connected', async () => {
const initialLoanToValue = await app.position.manage.getLoanToValue();

await app.position.manage.waitForSliderToBeEditable();
await app.position.manage.moveSlider({ protocol: 'Aave V3', value: 0.5 });
await app.position.manage.moveSlider({ value: 0.5 });

await app.position.manage.adjustRisk();
await app.position.manage.confirm();
Expand Down Expand Up @@ -143,7 +143,7 @@ test.describe('Aave v3 Multiply - Base - Wallet connected', async () => {
const initialLoanToValue = await app.position.manage.getLoanToValue();

await app.position.manage.waitForSliderToBeEditable();
await app.position.manage.moveSlider({ protocol: 'Aave V3', value: 0.3 });
await app.position.manage.moveSlider({ value: 0.3 });

await app.position.manage.adjustRisk();
await app.position.manage.confirm();
Expand Down
4 changes: 2 additions & 2 deletions tests/withWallet/aaveV3/ethereum/aaveV3BorrowEthereum.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ test.describe('Aave V3 Borrow - Ethereum - Wallet connected', async () => {
const initialLoanToValue = await app.position.manage.getLoanToValue();

await app.position.manage.waitForSliderToBeEditable();
await app.position.manage.moveSlider({ protocol: 'Aave V3', value: 0.5 });
await app.position.manage.moveSlider({ value: 0.5 });

await app.position.manage.adjustRisk();
await app.position.manage.confirm();
Expand Down Expand Up @@ -121,7 +121,7 @@ test.describe('Aave V3 Borrow - Ethereum - Wallet connected', async () => {
const initialLoanToValue = await app.position.manage.getLoanToValue();

await app.position.manage.waitForSliderToBeEditable();
await app.position.manage.moveSlider({ protocol: 'Aave V3', value: 0.3 });
await app.position.manage.moveSlider({ value: 0.3 });

await app.position.manage.adjustRisk();
await app.position.manage.confirm();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ test.describe('Aave v3 Multiply - Ethereum - Wallet connected', async () => {
const initialLoanToValue = await app.position.manage.getLoanToValue();

await app.position.manage.waitForSliderToBeEditable();
await app.position.manage.moveSlider({ protocol: 'Aave V3', value: 0.5 });
await app.position.manage.moveSlider({ value: 0.5 });

await app.position.manage.adjustRisk();
await app.position.manage.confirm();
Expand Down Expand Up @@ -144,7 +144,7 @@ test.describe('Aave v3 Multiply - Ethereum - Wallet connected', async () => {
const initialLoanToValue = await app.position.manage.getLoanToValue();

await app.position.manage.waitForSliderToBeEditable();
await app.position.manage.moveSlider({ protocol: 'Aave V3', value: 0.3 });
await app.position.manage.moveSlider({ value: 0.3 });

await app.position.manage.adjustRisk();
await app.position.manage.confirm();
Expand Down
74 changes: 0 additions & 74 deletions tests/withWallet/ajna/ajnaBorrow.spec.ts

This file was deleted.

Loading

0 comments on commit 0c9f98c

Please sign in to comment.