Skip to content

Commit

Permalink
Merge pull request #199 from OasisDEX/ajna-arbitrum
Browse files Browse the repository at this point in the history
Ajna arbitrum
  • Loading branch information
juan-langa authored Mar 1, 2024
2 parents 2573a1f + 650bd51 commit db61ecf
Show file tree
Hide file tree
Showing 14 changed files with 557 additions and 74 deletions.
25 changes: 25 additions & 0 deletions src/pages/position/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,31 @@ export class Base {
}).toPass();
}

/**
* @param value should be between '0' and '1' both included | 0: far left | 1: far right
*/
@step
async moveSliderOmni({ value }: { value: number }) {
await expect(async () => {
const sliderRail = this.page.locator('.rc-slider-rail');
const sliderPill = this.page.locator('[role="slider"]');

const initialPillValue = await sliderPill.getAttribute('aria-valuenow');

const sliderOffsetWidth = await sliderRail.evaluate((el) => {
return el.getBoundingClientRect().width;
});

await sliderRail.click({
force: true,
position: { x: sliderOffsetWidth * value, y: 0 },
});

const newPillValue = await sliderPill.getAttribute('aria-valuenow');
expect(newPillValue !== initialPillValue).toBe(true);
}).toPass();
}

@step
async setNoThreshold() {
await this.page.locator('span > span:has-text("Set No Threshold")').click();
Expand Down
4 changes: 3 additions & 1 deletion src/pages/position/manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ export class Manage {

@step
async adjustRisk() {
await this.page.getByRole('button', { name: 'Adjust Risk' }).click();
await this.page
.getByRole('button', { name: 'Adjust Risk' })
.click({ timeout: expectDefaultTimeout * 3 });
}

@step
Expand Down
2 changes: 1 addition & 1 deletion src/pages/position/overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export class Overview {
timeout?: number;
} = { amount: '', token: '', timeout: expectDefaultTimeout }
) {
const regExp = new RegExp(`${amount}${token}`);
const regExp = new RegExp(`${amount}.*${token}`);

await expect(this.page.locator('li:has-text("Collateral Deposited")')).toContainText(regExp, {
timeout,
Expand Down
11 changes: 10 additions & 1 deletion src/pages/position/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ export class Setup {
}
}

/**
*
* @param adjustRisk should be between '0' and '1' both included | 0: far left in slider | 1: far right
*/
@step
async moveSliderOmni({ value }: { value: number }) {
await this.base.moveSliderOmni({ value });
}

@step
async showLendingPriceEditor({ pair }: { pair: string }) {
await this.page.getByText(`Or enter specific ${pair} Lending Price`).click();
Expand All @@ -143,7 +152,7 @@ export class Setup {
await this.page
.locator(`:has-text("Input ${collateralToken} Lending Price") + div > button`)
.nth(adjust === 'down' ? 0 : 1)
.click();
.click({ clickCount: 5 });
}

@step
Expand Down
32 changes: 23 additions & 9 deletions tests/sharedTestSteps/positionManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,46 @@ import * as tx from 'utils/tx';
import { App } from 'src/app';
import { longTestTimeout, positionTimeout } from 'utils/config';

/**
*
* @param adjustRisk should be between '0' and '1' both included | 0: far left in slider | 1: far right
*/
export const openPosition = async ({
app,
forkId,
deposit,
borrow,
existingDPM,
adjustRisk,
}: {
app: App;
forkId: string;
deposit: { token: string; amount: string };
borrow?: { token: string; amount: string };
existingDPM?: boolean;
adjustRisk?: { value: number };
}) => {
await app.position.setup.deposit(deposit);
if (borrow) {
await app.position.setup.borrow(borrow);
}

await app.position.setup.createSmartDeFiAccount();

// Smart DeFi Acount creation randomly fails - Retry until it's created.
await expect(async () => {
if (adjustRisk) {
await app.position.setup.moveSliderOmni({ value: adjustRisk.value });
}
if (!existingDPM) {
await app.position.setup.createSmartDeFiAccount();
await tx.confirmAndVerifySuccess({ forkId, metamaskAction: 'confirmAddToken' });
await app.position.setup.continueShouldBeVisible();
}).toPass({ timeout: longTestTimeout });

await app.position.setup.continue();
// Smart DeFi Acount creation randomly fails - Retry until it's created.
await expect(async () => {
await app.position.setup.createSmartDeFiAccount();
await tx.confirmAndVerifySuccess({ forkId, metamaskAction: 'confirmAddToken' });
await app.position.setup.continueShouldBeVisible();
}).toPass({ timeout: longTestTimeout });

await app.position.setup.continue();
} else if (deposit.token !== 'ETH') {
await app.position.setup.setTokenAllowance(deposit.token);
}

if (deposit.token !== 'ETH') {
// Setting up allowance randomly fails - Retry until it's set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,14 @@ test.describe('Aave v3 Multiply - Ethereum - Wallet connected', async () => {
console.log('+++ Position ID: ', positionId);

await app.position.setup.goToPosition();
await app.position.manage.shouldBeVisible('Manage Multiply position');
await app.position.manage.shouldHaveButton({ label: 'Adjust' });

// !! Skipping position type verification since 'DB collision' issue is back
// await app.position.manage.shouldBeVisible('Manage Multiply position');
// await app.position.manage.shouldHaveButton({ label: 'Adjust' });
await app.position.manage.shouldBeVisible('Manage ');
});

test('It should close an existent Aave V3 Multiply Ethereum position - Close to debt token (WBTC) @regression', async () => {
test('It should close an existent Aave V3 Multiply Ethereum position - Close to debt token (WBTC)', async () => {
test.info().annotations.push({
type: 'Test case',
description: '12057',
Expand Down Expand Up @@ -150,7 +153,7 @@ test.describe('Aave v3 Multiply - Ethereum - Wallet connected', async () => {
await app.position.overview.shouldHaveMultiple('1.00');
});

test('It should adjust risk of an existent Aave V3 Multiply Ethereum position - Up @regression', async () => {
test('It should adjust risk of an existent Aave V3 Multiply Ethereum position - Up', async () => {
test.info().annotations.push({
type: 'Test case',
description: '12055',
Expand Down Expand Up @@ -197,7 +200,7 @@ test.describe('Aave v3 Multiply - Ethereum - Wallet connected', async () => {
}).toPass();
});

test('It should adjust risk of an existent Aave V3 Multiply Ethereum position - Down @regression', async () => {
test('It should adjust risk of an existent Aave V3 Multiply Ethereum position - Down', async () => {
test.info().annotations.push({
type: 'Test case',
description: '12056',
Expand Down
186 changes: 186 additions & 0 deletions tests/withWallet/ajna/arbitrum/ajnaArbitrumBorrow.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
import { BrowserContext, test } from '@playwright/test';
import { metamaskSetUp } from 'utils/setup';
import { resetState } from '@synthetixio/synpress/commands/synpress';
import * as tenderly from 'utils/tenderly';
import { setup } from 'utils/setup';
import { extremelyLongTestTimeout, longTestTimeout } from 'utils/config';
import { App } from 'src/app';
import {
close,
depositAndBorrow,
openPosition,
withdrawAndPayBack,
} from 'tests/sharedTestSteps/positionManagement';

let context: BrowserContext;
let app: App;
let forkId: string;
let walletAddress: string;

test.describe.configure({ mode: 'serial' });

test.describe('Ajna Arbitrum Borrow - Wallet connected', async () => {
test.afterAll(async () => {
await tenderly.deleteFork(forkId);

await app.page.close();

await context.close();

await resetState();
});

test('It should open an Ajna Arbitrum Borrow position @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: 'xxx',
});

test.setTimeout(extremelyLongTestTimeout);

await test.step('Test setup', async () => {
({ context } = await metamaskSetUp({ network: 'arbitrum' }));
let page = await context.newPage();
app = new App(page);

({ forkId, walletAddress } = await setup({
app,
network: 'arbitrum',
}));

await tenderly.setTokenBalance({
forkId,
walletAddress,
network: 'arbitrum',
token: 'RETH',
balance: '100',
});
});
await app.page.goto('/arbitrum/ajna/borrow/RETH-ETH#setup');

await app.position.setup.acknowlegeAjnaInfo();

await openPosition({
app,
forkId,
deposit: { token: 'RETH', amount: '0.1' },
borrow: { token: 'ETH', amount: '0.01' },
});
});

test('It should Deposit and Borrow in a single tx form an existing Ajna Base Borrow position @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: 'xxxxx',
});

test.setTimeout(longTestTimeout);

await depositAndBorrow({
app,
forkId,
deposit: { token: 'RETH', amount: '0.1' },
borrow: { token: 'ETH', amount: '0.05' },
expectedCollateralDeposited: {
amount: '0.20',
token: 'RETH',
},
expectedDebt: { amount: '0.06([0-9]{1,2})?', token: 'ETH' },
});
});

test('It should Withdraw and Pay back in a single tx form an existing Ajna Base Borrow position @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: 'xxxxx',
});

test.setTimeout(longTestTimeout);

await app.position.manage.withdrawCollateral();

await withdrawAndPayBack({
app,
forkId,
withdraw: { token: 'RETH', amount: '0.1' },
payback: { token: 'ETH', amount: '0.01' },
expectedCollateralDeposited: {
amount: '0.10',
token: 'RETH',
},
expectedDebt: { amount: '0.05([0-9]{1,2})?', token: 'ETH' },
});
});

test('It should Borrow and Deposit in a single tx on an existing Ajna Base Borrow position @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: 'xxxx',
});

test.setTimeout(longTestTimeout);

await app.position.manage.openManageOptions({ currentLabel: 'RETH' });
await app.position.manage.select('Manage debt');

await depositAndBorrow({
app,
forkId,
borrow: { token: 'ETH', amount: '0.02' },
deposit: { token: 'RETH', amount: '0.2' },
expectedCollateralDeposited: {
amount: '0.30',
token: 'RETH',
},
expectedDebt: { amount: '0.07([0-9]{1,2})?', token: 'ETH' },
});
});

test('It should Pay back and Withdraw in a single tx on an existing Ajna Base Borrow position @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: 'xxxx',
});

test.setTimeout(longTestTimeout);

await app.position.manage.openManageOptions({ currentLabel: 'RETH' });
await app.position.manage.select('Manage debt');

await app.position.manage.payBackDebt();

await withdrawAndPayBack({
app,
forkId,
payback: { token: 'ETH', amount: '0.01' },
withdraw: { token: 'RETH', amount: '0.1' },
expectedCollateralDeposited: {
amount: '0.20',
token: 'RETH',
},
expectedDebt: { amount: '0.06([0-9]{1,2})?', token: 'ETH' },
});
});

// !! tx failing with very low liquidity - To re-test when liquidity rises
test.skip('It should Close to collateral an existing Ajna Base Borrow position @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: 'xxxx',
});

test.setTimeout(longTestTimeout);

await close({
app,
forkId,
positionType: 'Borrow',
closeTo: 'collateral',
collateralToken: 'RETH',
debtToken: 'ETH',
tokenAmountAfterClosing: '0.[0-9]{3,4}',
});
});

//TEST
});
Loading

0 comments on commit db61ecf

Please sign in to comment.