diff --git a/src/pages/position/manage.ts b/src/pages/position/manage.ts index 4824f606..9e9e9061 100644 --- a/src/pages/position/manage.ts +++ b/src/pages/position/manage.ts @@ -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(); + } } diff --git a/src/pages/position/overview.ts b/src/pages/position/overview.ts index 09f240d5..c8b5b326 100644 --- a/src/pages/position/overview.ts +++ b/src/pages/position/overview.ts @@ -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 diff --git a/src/pages/position/setup.ts b/src/pages/position/setup.ts index 406a923f..e37c7c76 100644 --- a/src/pages/position/setup.ts +++ b/src/pages/position/setup.ts @@ -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 diff --git a/tests/withWallet/aaveV2/aaveV2Multiply.spec.ts b/tests/withWallet/aaveV2/aaveV2Multiply.spec.ts index 249e43b4..61a36937 100644 --- a/tests/withWallet/aaveV2/aaveV2Multiply.spec.ts +++ b/tests/withWallet/aaveV2/aaveV2Multiply.spec.ts @@ -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); @@ -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'); diff --git a/tests/withWallet/aaveV3/base/aaveV3BorrowBase.spec.ts b/tests/withWallet/aaveV3/base/aaveV3BorrowBase.spec.ts index 95047e56..ba26b170 100644 --- a/tests/withWallet/aaveV3/base/aaveV3BorrowBase.spec.ts +++ b/tests/withWallet/aaveV3/base/aaveV3BorrowBase.spec.ts @@ -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 }); diff --git a/tests/withWallet/aaveV3/ethereum/aaveV3EarnEthereum.spec.ts b/tests/withWallet/aaveV3/ethereum/aaveV3EarnEthereum.spec.ts index 36103386..74e10f2b 100644 --- a/tests/withWallet/aaveV3/ethereum/aaveV3EarnEthereum.spec.ts +++ b/tests/withWallet/aaveV3/ethereum/aaveV3EarnEthereum.spec.ts @@ -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', @@ -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', @@ -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', @@ -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', diff --git a/tests/withWallet/spark/sparkBorrow.spec.ts b/tests/withWallet/spark/sparkBorrow.spec.ts index 119533af..fe329e29 100644 --- a/tests/withWallet/spark/sparkBorrow.spec.ts +++ b/tests/withWallet/spark/sparkBorrow.spec.ts @@ -229,6 +229,88 @@ test.describe('Spark Borrow - Wallet connected', async () => { await app.position.overview.shouldHaveExposure({ amount: '1.00000', token: 'WBTC' }); }); + test('It should withdraw some collateral from an existent Spark Borrow position @regression', async () => { + test.info().annotations.push({ + type: 'Test case', + description: '13113', + }); + + test.setTimeout(veryLongTestTimeout); + + await app.position.manage.shouldBeVisible('Manage collateral'); + await app.position.overview.shouldHaveExposure({ amount: '1.00000', token: 'WBTC' }); + + await app.position.manage.withdrawCollateral(); + await app.position.manage.enter({ token: 'WBTC', amount: '0.1' }); + 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.shouldHaveExposure({ amount: '0.90000', token: 'WBTC' }); + }); + + test('It should borrow more debt from an existing Spark Borrow position @regression', async () => { + test.info().annotations.push({ + type: 'Test case', + description: '13114', + }); + + test.setTimeout(veryLongTestTimeout); + + await app.position.manage.shouldBeVisible('Manage collateral'); + await app.position.overview.shouldHaveDebt({ amount: '0.0000', token: 'DAI' }); + + await app.position.manage.openManageOptions({ currentLabel: 'Manage WBTC' }); + await app.position.manage.select('Manage debt'); + await app.position.manage.enter({ token: 'DAI', amount: '5000' }); + 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,000.0000', token: 'DAI' }); + }); + + test('It should pay back some debt from an existing Spark Borrow position @regression', async () => { + test.info().annotations.push({ + type: 'Test case', + description: '13115', + }); + + test.setTimeout(veryLongTestTimeout); + + await app.position.manage.shouldBeVisible('Manage collateral'); + await app.position.overview.shouldHaveDebt({ amount: '0.0000', token: 'DAI' }); + + await app.position.manage.openManageOptions({ currentLabel: 'Manage WBTC' }); + await app.position.manage.select('Manage debt'); + await app.position.manage.payBackDebt(); + await app.position.manage.enter({ token: 'DAI', amount: '3000' }); + // Setting up allowance randomly fails - Retry until it's set. + await expect(async () => { + await app.position.setup.setupAllowance(); + await app.position.setup.approveAllowance(); + await test.step('Metamask: ConfirmAddToken', async () => { + await metamask.confirmAddToken(); + }); + await app.position.setup.continueShouldBeVisible(); + }).toPass(); + await app.position.setup.continue(); + 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: '2,000.[0-9]{4}', token: 'DAI' }); + }); + test('It should adjust risk of an existent Spark Borrow position - Up (WBTC/DAI) @regression', async () => { test.info().annotations.push({ type: 'Test case', @@ -342,7 +424,7 @@ test.describe('Spark Borrow - Wallet connected', async () => { } ); - test.setTimeout(extremelyLongTestTimeout); + test.setTimeout(veryLongTestTimeout); // await app.page.goto(`/owner/${walletAddress}`); @@ -363,7 +445,7 @@ test.describe('Spark Borrow - Wallet connected', async () => { } ); - test.setTimeout(extremelyLongTestTimeout); + test.setTimeout(veryLongTestTimeout); // await app.page.goto(`/owner/${walletAddress}`); // await app.portfolio.borrow.vaults.first.view();