Skip to content

Commit

Permalink
Merge pull request #90 from OasisDEX/withdraw-debt
Browse files Browse the repository at this point in the history
Withdraw debt
  • Loading branch information
juan-langa authored Nov 28, 2023
2 parents db00136 + 9e5fb5c commit e3bfaf8
Show file tree
Hide file tree
Showing 7 changed files with 330 additions and 26 deletions.
10 changes: 10 additions & 0 deletions src/pages/position/manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,14 @@ export class Manage {
.getByPlaceholder(`0 ${token}`)
.fill(amount);
}

@step
async withdrawCollateral() {
await this.page.getByRole('button', { name: 'Withdraw collateral' }).click();
}

@step
async payBackDebt() {
await this.page.getByRole('button', { name: 'Pay back debt' }).click();
}
}
4 changes: 3 additions & 1 deletion src/pages/position/overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ export class Overview {
async shouldHaveExposure({ amount, token }: { amount: string; token: string }) {
let regExp = new RegExp(`${amount} ${token}`);

await expect(this.page.locator('li:has-text("exposure") > p')).toHaveText(regExp);
await expect(this.page.locator('li:has-text("exposure") > p')).toHaveText(regExp, {
timeout: positionTimeout,
});
}

@step
Expand Down
12 changes: 8 additions & 4 deletions src/pages/position/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,14 @@ export class Setup {

@step
async confirmOrRetry() {
await this.page
.getByRole('button', { name: 'Back to editing' })
.locator('xpath=//preceding::button[1]')
.click();
const confirm = this.page.getByRole('button', { name: 'Confirm' });
const retry = this.page.getByRole('button', { name: 'Retry' });

if (await confirm.isVisible()) {
await confirm.click();
} else if (await retry.isVisible()) {
await retry.click();
}
}

@step
Expand Down
160 changes: 147 additions & 13 deletions tests/withWallet/aaveV2/aaveV2Multiply.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,17 @@ 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 { hooksTimeout, extremelyLongTestTimeout, baseUrl } from 'utils/config';
import { extremelyLongTestTimeout, baseUrl, veryLongTestTimeout } from 'utils/config';
import { App } from 'src/app';

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

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

test.describe('Aave v2 Multiply - Wallet connected', async () => {
test.skip(baseUrl.includes('staging') || baseUrl.includes('//summer.fi'));

test.beforeEach(async () => {
test.setTimeout(hooksTimeout);

({ context } = await metamaskSetUp({ network: 'mainnet' }));
let page = await context.newPage();
app = new App(page);

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

test.afterAll(async () => {
await tenderly.deleteFork(forkId);

Expand All @@ -36,12 +25,157 @@ test.describe('Aave v2 Multiply - Wallet connected', async () => {
await resetState();
});

test('It should deposit extra collateral on an existing Aave V2 Multiply position @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: '13091',
});

test.setTimeout(extremelyLongTestTimeout);

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

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

await tenderly.changeAccountOwner({
account: '0x8451c582ab882fb534175b5465e91dfbde97917e',
newOwner: walletAddress,
forkId,
});

await app.page.goto('/ethereum/aave/v2/178#overview');

await app.position.manage.shouldBeVisible('Manage Multiply position');
await app.position.manage.openManageOptions({ currentLabel: 'Adjust' });
await app.position.manage.select('Manage collateral');
await app.position.manage.enter({ token: 'ETH', amount: '15' });
await app.position.manage.confirm();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
});
await app.position.manage.shouldShowSuccessScreen();
await app.position.manage.ok();

await app.position.overview.shouldHaveNetValue({
value: '[0-9]{2},[0-9]{3}.[0-9]{2}',
token: 'USDC',
});
await app.position.overview.shouldHaveExposure({ amount: '15.00000', token: 'ETH' });
await app.position.overview.shouldHaveBuyingPower('[0-9]{2},[0-9]{3}.[0-9]{2}');
});

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

test.setTimeout(veryLongTestTimeout);

await app.position.manage.shouldBeVisible('Manage Multiply position');

const initialLiqPrice = await app.position.manage.getLiquidationPrice();
const initialLoanToValue = await app.position.manage.getLoanToValue();

await app.position.manage.waitForSliderToBeEditable();
await app.position.manage.moveSlider({ value: 0.9 });

await app.position.manage.adjustRisk();
await app.position.manage.confirm();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
});
await app.position.manage.shouldShowSuccessScreen();
await app.position.manage.ok();

await app.position.manage.shouldBeVisible('Manage 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 Aave V2 Multiply position - Down @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: '13093',
});

test.setTimeout(veryLongTestTimeout);

await app.position.manage.shouldBeVisible('Manage Multiply position');
const initialLiqPrice = await app.position.manage.getLiquidationPrice();
const initialLoanToValue = await app.position.manage.getLoanToValue();

await app.position.manage.waitForSliderToBeEditable();
await app.position.manage.moveSlider({ value: 0.3 });

await app.position.manage.adjustRisk();
await app.position.manage.confirm();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
});
await app.position.manage.shouldShowSuccessScreen();
await app.position.manage.ok();

await app.position.manage.shouldBeVisible('Manage 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 an existing Aave V2 Multiply position - Close to debt token (ETH) @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: '13094',
});

test.setTimeout(veryLongTestTimeout);

await app.position.manage.openManageOptions({ currentLabel: 'Adjust' });
await app.position.manage.select('Close position');

await app.position.manage.closeTo('ETH');
await app.position.manage.shouldHaveTokenAmountAfterClosing({
token: 'ETH',
amount: '[0-9]{1,2}.[0-9]{1,2}',
});

// Position closure randomly fails - Retry until it's closed.
await expect(async () => {
await app.position.setup.confirmOrRetry();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
});
await app.position.manage.shouldShowSuccessScreen();
}).toPass();

await app.position.manage.ok();

await app.page.goto('/ethereum/aave/v2/178#overview');
await app.position.overview.shouldHaveLiquidationPrice({ price: '0.00', token: 'USDC' });
await app.position.overview.shouldHaveLoanToValue('0.00');
await app.position.overview.shouldHaveBorrowCost('0.00');
await app.position.overview.shouldHaveNetValue({ value: '0.00', token: 'USDC' });
await app.position.overview.shouldHaveExposure({ amount: '0.00000', token: 'ETH' });
await app.position.overview.shouldHaveDebt({ amount: '0.0000', token: 'USDC' });
await app.position.overview.shouldHaveMultiple('1');
await app.position.overview.shouldHaveBuyingPower('0.00');
});

test('It should open an Aave v2 Multiply position @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: '11773',
});

test.skip(baseUrl.includes('staging') || baseUrl.includes('//summer.fi'));

test.setTimeout(extremelyLongTestTimeout);

await app.page.goto('/ethereum/aave/v2/multiply/ethusdc#simulate');
Expand Down
2 changes: 0 additions & 2 deletions tests/withWallet/aaveV3/base/aaveV3BorrowBase.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,4 @@ test.describe('Aave V3 Borrow - Base - Wallet connected', async () => {
await app.position.setup.goToPosition();
await app.position.manage.shouldBeVisible('Manage ');
});

// Risk UP -> 13035
});
82 changes: 78 additions & 4 deletions tests/withWallet/aaveV3/ethereum/aaveV3EarnEthereum.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test.describe('Aave V3 Earn - Ethereum - Wallet connected', async () => {
await resetState();
});

test('It should deposit extra collateral on an existent Aave V3 Ethereum Earn position @regression', async () => {
test('It should deposit extra collateral on an existing Aave V3 Ethereum Earn position @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: '13078',
Expand Down Expand Up @@ -78,7 +78,81 @@ test.describe('Aave V3 Earn - Ethereum - Wallet connected', async () => {
await app.position.overview.shouldHaveTotalCollateral({ amount: '20.00000', token: 'WSTETH' });
});

test('It should adjust risk of an existent Aave V3 Earn Ethereum position - Up @regression', async () => {
test('It should withdraw some collateral from an existing Aave V3 Ethereum Earn position @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: '13109',
});

test.setTimeout(extremelyLongTestTimeout);

await app.position.manage.shouldBeVisible('Manage Earn position');
await app.position.overview.shouldHaveTotalCollateral({ amount: '20.00000', token: 'WSTETH' });

await app.position.manage.openManageOptions({ currentLabel: 'Adjust' });
await app.position.manage.select('Manage collateral');
await app.position.manage.withdrawCollateral();
await app.position.manage.enter({ token: 'WSTETH', amount: '5' });
await app.position.manage.confirm();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
});
await app.position.manage.shouldShowSuccessScreen();
await app.position.manage.ok();

await app.position.overview.shouldHaveTotalCollateral({ amount: '15.00000', token: 'WSTETH' });
});

test('It should borrow more debt from an existing Aave V3 Ethereum Earn position @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: '13108',
});

test.setTimeout(extremelyLongTestTimeout);

await app.position.manage.shouldBeVisible('Manage Earn position');
await app.position.overview.shouldHaveDebt({ amount: '0.00000', token: 'ETH' });

await app.position.manage.openManageOptions({ currentLabel: 'Adjust' });
await app.position.manage.select('Manage debt');
await app.position.manage.enter({ token: 'ETH', amount: '5' });
await app.position.manage.confirm();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
});
await app.position.manage.shouldShowSuccessScreen();
await app.position.manage.ok();

await app.position.overview.shouldHaveDebt({ amount: '5.00000', token: 'ETH' });
});

test('It should pay back some debt from an existing Aave V3 Ethereum Earn position @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: '13110',
});

test.setTimeout(extremelyLongTestTimeout);

await app.position.manage.shouldBeVisible('Manage Earn position');
await app.position.overview.shouldHaveDebt({ amount: '5.00000', token: 'ETH' });

await app.position.manage.openManageOptions({ currentLabel: 'Adjust' });
await app.position.manage.select('Manage debt');
await app.position.manage.payBackDebt();
await app.position.manage.enter({ token: 'ETH', amount: '2' });
await app.position.manage.confirm();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
});
await app.position.manage.shouldShowSuccessScreen();
await app.position.manage.ok();

await app.position.overview.shouldHaveDebt({ amount: '3.00000', token: 'ETH' });
});

test('It should adjust risk of an existing Aave V3 Earn Ethereum position - Up @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: '13060',
Expand Down Expand Up @@ -106,7 +180,7 @@ test.describe('Aave V3 Earn - Ethereum - Wallet connected', async () => {
expect(updatedLiqPrice).toBeGreaterThan(initialLiqPrice);
});

test('It should adjust risk of an existent Aave V3 Earn Ethereum position - Down @regression', async () => {
test('It should adjust risk of an existing Aave V3 Earn Ethereum position - Down @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: '13061',
Expand All @@ -133,7 +207,7 @@ test.describe('Aave V3 Earn - Ethereum - Wallet connected', async () => {
expect(updatedLiqPrice).toBeLessThan(initialLiqPrice);
});

test('It should close an existent Aave V3 Earn Ethereum position - Close to debt token (ETH) @regression', async () => {
test('It should close an existing Aave V3 Earn Ethereum position - Close to debt token (ETH) @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: '13062',
Expand Down
Loading

0 comments on commit e3bfaf8

Please sign in to comment.