From f366183fcb4fb4a0a654eb1126a716dd10e54b3b Mon Sep 17 00:00:00 2001 From: yivlad Date: Fri, 13 Dec 2024 11:59:24 +0100 Subject: [PATCH 01/29] Comment all e2e tests Co-authored-by: Oskar --- .../dialogs/borrow/BorrowDialog.test-e2e.ts | 984 ++++++------ .../ClaimRewardsDialog.test-e2e.ts | 126 +- .../collateral/CollateralDialog.test-e2e.ts | 838 +++++----- .../ConvertStablesDialog.test-e2e.ts | 124 +- .../e2e/base/UsdcToUsds.test-e2e.ts | 118 +- .../e2e/base/UsdsToUsdc.test-e2e.ts | 118 +- .../e2e/mainnet/DaiToUsdc.test-e2e.ts | 120 +- .../e2e/mainnet/DaiToUsds.test-e2e.ts | 120 +- .../e2e/mainnet/UsdcToDai.test-e2e.ts | 120 +- .../e2e/mainnet/UsdcToUsds.test-e2e.ts | 120 +- .../e2e/mainnet/UsdsToDai.test-e2e.ts | 120 +- .../e2e/mainnet/UsdsToUsdc.test-e2e.ts | 120 +- .../dialogs/deposit/DepositDialog.test-e2e.ts | 936 +++++------ .../dialogs/e-mode/EModeDialog.test-e2e.ts | 1064 ++++++------- .../dialogs/repay/RepayDialog.test-e2e.ts | 1390 ++++++++--------- .../deposit/SavingsDepositDialog.test-e2e.ts | 314 ++-- .../deposit/e2e/base/DepositUSDC.test-e2e.ts | 132 +- .../deposit/e2e/base/DepositUSDS.test-e2e.ts | 126 +- .../e2e/gnosis/DepositXDAI.test-e2e.ts | 130 +- .../e2e/mainnet/DepositDAI.test-e2e.ts | 314 ++-- .../e2e/mainnet/DepositUSDC.test-e2e.ts | 224 +-- .../e2e/mainnet/DepositUSDS.test-e2e.ts | 128 +- .../deposit/e2e/mainnet/General.test-e2e.ts | 120 +- .../e2e/mainnet/Validation.test-e2e.ts | 156 +- .../downgrade/e2e/UsdsToDai.test-e2e.ts | 208 +-- .../migrate/upgrade/e2e/DaiToUsds.test-e2e.ts | 220 +-- .../upgrade/e2e/sDaiToSUsds.test-e2e.ts | 210 +-- .../SavingsWithdrawDialog.test-e2e.ts | 390 ++--- .../withdraw/e2e/base/SendUSDC.test-e2e.ts | 158 +- .../withdraw/e2e/base/SendUSDS.test-e2e.ts | 148 +- .../e2e/base/WithdrawMaxUSDC.test-e2e.ts | 120 +- .../e2e/base/WithdrawMaxUSDS.test-e2e.ts | 118 +- .../e2e/base/WithdrawUSDC.test-e2e.ts | 128 +- .../e2e/base/WithdrawUSDS.test-e2e.ts | 118 +- .../withdraw/e2e/gnosis/SendXDAI.test-e2e.ts | 142 +- .../e2e/gnosis/WithdrawMaxXDAI.test-e2e.ts | 126 +- .../e2e/gnosis/WithdrawXDAI.test-e2e.ts | 126 +- .../withdraw/e2e/mainnet/SendDAI.test-e2e.ts | 146 +- .../e2e/mainnet/SendDAIValidation.test-e2e.ts | 492 +++--- .../withdraw/e2e/mainnet/SendUSDC.test-e2e.ts | 352 ++--- .../withdraw/e2e/mainnet/SendUSDS.test-e2e.ts | 340 ++-- .../e2e/mainnet/WithdrawDAI.test-e2e.ts | 288 ++-- .../e2e/mainnet/WithdrawMaxDAI.test-e2e.ts | 116 +- .../e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts | 296 ++-- .../e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts | 284 ++-- .../e2e/mainnet/WithdrawUSDC.test-e2e.ts | 296 ++-- .../e2e/mainnet/WithdrawUSDS.test-e2e.ts | 284 ++-- .../withdraw/WithdrawDialog.test-e2e.ts | 1288 +++++++-------- .../stake/e2e/mainnet/StakeDAI.test-e2e.ts | 158 +- .../stake/e2e/mainnet/StakeSDAI.test-e2e.ts | 162 +- .../stake/e2e/mainnet/StakeSUSDS.test-e2e.ts | 180 +-- .../stake/e2e/mainnet/StakeUSDC.test-e2e.ts | 158 +- .../stake/e2e/mainnet/StakeUSDS.test-e2e.ts | 324 ++-- .../e2e/mainnet/UnstakeDAI.test-e2e.ts | 172 +- .../e2e/mainnet/UnstakeUSDC.test-e2e.ts | 172 +- .../e2e/mainnet/UnstakeUSDS.test-e2e.ts | 376 ++--- .../e2e/mainnet/WithdrawMaxDai.test-e2e.ts | 324 ++-- .../e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts | 324 ++-- .../e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts | 434 ++--- .../src/features/topbar/Topbar.test-e2e.ts | 328 ++-- packages/app/src/pages/Borrow.test-e2e.ts | 1140 +++++++------- packages/app/src/pages/Farms.test-e2e.ts | 56 +- .../app/src/pages/MarketDetails.test-e2e.ts | 1178 +++++++------- packages/app/src/pages/Markets.test-e2e.ts | 548 +++---- .../app/src/pages/MyPortfolio.test-e2e.ts | 202 +-- packages/app/src/pages/Savings.test-e2e.ts | 440 +++--- .../PageNotSupportedWarning.PageObject.ts | 36 +- .../PageNotSupportedWarning.test-e2e.ts | 62 +- 68 files changed, 10615 insertions(+), 10615 deletions(-) diff --git a/packages/app/src/features/dialogs/borrow/BorrowDialog.test-e2e.ts b/packages/app/src/features/dialogs/borrow/BorrowDialog.test-e2e.ts index a82643237..cee34ce0d 100644 --- a/packages/app/src/features/dialogs/borrow/BorrowDialog.test-e2e.ts +++ b/packages/app/src/features/dialogs/borrow/BorrowDialog.test-e2e.ts @@ -1,500 +1,500 @@ -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' - -import { borrowValidationIssueToMessage } from '@/domain/market-validators/validateBorrow' -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { BorrowPageObject } from '@/pages/Borrow.PageObject' -import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' -import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { screenshot } from '@/test/e2e/utils' - -import { CollateralDialogPageObject } from '../collateral/CollateralDialog.PageObject' -import { DialogPageObject } from '../common/Dialog.PageObject' - -const headerRegExp = /Borrow */ - -test.describe('Borrow dialog', () => { - const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) - const initialBalances = { - rETH: 100, - wstETH: 100, - } - - test.describe('Position with deposit and borrow', () => { - const initialDeposits = { - rETH: 2, - wstETH: 2, - } - const daiToBorrow = 1500 - const expectedInitialHealthFactor = '5.42' - const expectedHealthFactor = '2.04' - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ...initialBalances }, - }, - }) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) - await borrowPage.viewInMyPortfolioAction() - - const myPortfolioPage = new MyPortfolioPageObject(page) - - // wait for all transactions to be executed - await myPortfolioPage.expectHealthFactor(expectedInitialHealthFactor) - }) - - test('opens dialog with selected asset', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickBorrowButtonAction('rETH') - - const borrowDialog = new DialogPageObject(page, headerRegExp) - await borrowDialog.expectSelectedAsset('rETH') - await borrowDialog.expectDialogHeader('Borrow rETH') - await borrowDialog.expectHealthFactorBeforeVisible() - - await screenshot(borrowDialog.getDialog(), 'borrow-dialog-default-view') - }) - - test('calculates health factor changes correctly', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickBorrowButtonAction('rETH') - - const borrowDialog = new DialogPageObject(page, headerRegExp) - await borrowDialog.fillAmountAction(1) - - await borrowDialog.expectRiskLevelBefore('Healthy') - await borrowDialog.expectHealthFactorBefore(expectedInitialHealthFactor) - await borrowDialog.expectRiskLevelAfter('Moderate') - await borrowDialog.expectHealthFactorAfter(expectedHealthFactor) - - // @note this is needed for deterministic screenshots - const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) - await actionsContainer.expectEnabledActionAtIndex(0) - - await screenshot(borrowDialog.getDialog(), 'borrow-dialog-health-factor') - }) - - test('after borrow, health factor matches myPortfolio', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickBorrowButtonAction('rETH') +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' + +// import { borrowValidationIssueToMessage } from '@/domain/market-validators/validateBorrow' +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { BorrowPageObject } from '@/pages/Borrow.PageObject' +// import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { screenshot } from '@/test/e2e/utils' + +// import { CollateralDialogPageObject } from '../collateral/CollateralDialog.PageObject' +// import { DialogPageObject } from '../common/Dialog.PageObject' + +// const headerRegExp = /Borrow */ + +// test.describe('Borrow dialog', () => { +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) +// const initialBalances = { +// rETH: 100, +// wstETH: 100, +// } + +// test.describe('Position with deposit and borrow', () => { +// const initialDeposits = { +// rETH: 2, +// wstETH: 2, +// } +// const daiToBorrow = 1500 +// const expectedInitialHealthFactor = '5.42' +// const expectedHealthFactor = '2.04' + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ...initialBalances }, +// }, +// }) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) +// await borrowPage.viewInMyPortfolioAction() + +// const myPortfolioPage = new MyPortfolioPageObject(page) + +// // wait for all transactions to be executed +// await myPortfolioPage.expectHealthFactor(expectedInitialHealthFactor) +// }) + +// test('opens dialog with selected asset', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickBorrowButtonAction('rETH') + +// const borrowDialog = new DialogPageObject(page, headerRegExp) +// await borrowDialog.expectSelectedAsset('rETH') +// await borrowDialog.expectDialogHeader('Borrow rETH') +// await borrowDialog.expectHealthFactorBeforeVisible() + +// await screenshot(borrowDialog.getDialog(), 'borrow-dialog-default-view') +// }) + +// test('calculates health factor changes correctly', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickBorrowButtonAction('rETH') + +// const borrowDialog = new DialogPageObject(page, headerRegExp) +// await borrowDialog.fillAmountAction(1) + +// await borrowDialog.expectRiskLevelBefore('Healthy') +// await borrowDialog.expectHealthFactorBefore(expectedInitialHealthFactor) +// await borrowDialog.expectRiskLevelAfter('Moderate') +// await borrowDialog.expectHealthFactorAfter(expectedHealthFactor) + +// // @note this is needed for deterministic screenshots +// const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) +// await actionsContainer.expectEnabledActionAtIndex(0) + +// await screenshot(borrowDialog.getDialog(), 'borrow-dialog-health-factor') +// }) + +// test('after borrow, health factor matches myPortfolio', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickBorrowButtonAction('rETH') - const borrowDialog = new DialogPageObject(page, headerRegExp) - await borrowDialog.fillAmountAction(1) - const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(1) - - await borrowDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectHealthFactor(expectedHealthFactor) - }) - - test('has correct action plan for erc-20', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) +// const borrowDialog = new DialogPageObject(page, headerRegExp) +// await borrowDialog.fillAmountAction(1) +// const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(1) + +// await borrowDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectHealthFactor(expectedHealthFactor) +// }) + +// test('has correct action plan for erc-20', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickBorrowButtonAction('rETH') - - const borrowDialog = new DialogPageObject(page, headerRegExp) - await borrowDialog.fillAmountAction(1) - const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) - await actionsContainer.expectActions([{ type: 'borrow', asset: 'rETH' }]) - }) +// await myPortfolioPage.clickBorrowButtonAction('rETH') + +// const borrowDialog = new DialogPageObject(page, headerRegExp) +// await borrowDialog.fillAmountAction(1) +// const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) +// await actionsContainer.expectActions([{ type: 'borrow', asset: 'rETH' }]) +// }) - test('can borrow erc-20', async ({ page }) => { - const borrow = { - asset: 'rETH', - amount: 1, - } +// test('can borrow erc-20', async ({ page }) => { +// const borrow = { +// asset: 'rETH', +// amount: 1, +// } - const myPortfolioPage = new MyPortfolioPageObject(page) +// const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickBorrowButtonAction(borrow.asset) +// await myPortfolioPage.clickBorrowButtonAction(borrow.asset) - const borrowDialog = new DialogPageObject(page, headerRegExp) - await borrowDialog.fillAmountAction(borrow.amount) - const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(1) - await borrowDialog.expectSuccessPage([borrow], fork) +// const borrowDialog = new DialogPageObject(page, headerRegExp) +// await borrowDialog.fillAmountAction(borrow.amount) +// const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(1) +// await borrowDialog.expectSuccessPage([borrow], fork) - await screenshot(borrowDialog.getDialog(), 'borrow-dialog-erc-20-success') - - await borrowDialog.viewInMyPortfolioAction() - - await myPortfolioPage.expectBorrowTable({ - [borrow.asset]: borrow.amount, - }) - }) +// await screenshot(borrowDialog.getDialog(), 'borrow-dialog-erc-20-success') + +// await borrowDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.expectBorrowTable({ +// [borrow.asset]: borrow.amount, +// }) +// }) - test('has correct action plan for native asset', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - - await myPortfolioPage.clickBorrowButtonAction('WETH') - - const borrowDialog = new DialogPageObject(page, headerRegExp) - await borrowDialog.selectAssetAction('ETH') - await borrowDialog.fillAmountAction(1) - - await borrowDialog.expectHealthFactorVisible() - - const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) - await actionsContainer.expectActions([ - { type: 'approveDelegation', asset: 'ETH' }, - { type: 'borrow', asset: 'ETH' }, - ]) - - await screenshot(borrowDialog.getDialog(), 'borrow-dialog-eth-action-plan') - }) - - test('can borrow native asset', async ({ page }) => { - const borrow = { - asset: 'ETH', - amount: 1, - } - - const myPortfolioPage = new MyPortfolioPageObject(page) - - await myPortfolioPage.clickBorrowButtonAction('WETH') - - const borrowDialog = new DialogPageObject(page, headerRegExp) - await borrowDialog.selectAssetAction(borrow.asset) - await borrowDialog.fillAmountAction(1) - const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) - await borrowDialog.expectSuccessPage([borrow], fork) - await screenshot(borrowDialog.getDialog(), 'borrow-dialog-eth-success') - - await borrowDialog.viewInMyPortfolioAction() - - await myPortfolioPage.expectBorrowTable({ - WETH: borrow.amount, - }) - }) - - test('can borrow same asset again', async ({ page }) => { - const borrow = { - asset: 'DAI', - amount: 1500, - } - - const myPortfolioPage = new MyPortfolioPageObject(page) - - await myPortfolioPage.clickBorrowButtonAction(borrow.asset) - - const borrowDialog = new DialogPageObject(page, headerRegExp) - await borrowDialog.fillAmountAction(borrow.amount) - const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(1) - await borrowDialog.expectSuccessPage([borrow], fork) - - await screenshot(borrowDialog.getDialog(), 'borrow-dialog-borrow-twice-success') - - await borrowDialog.viewInMyPortfolioAction() - - await myPortfolioPage.expectBorrowTable({ - [borrow.asset]: borrow.amount + daiToBorrow, - }) - }) - - test("can't borrow more than allowed", async ({ page }) => { - const borrowAsset = 'wstETH' - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickBorrowButtonAction(borrowAsset) - - const borrowDialog = new DialogPageObject(page, headerRegExp) - await borrowDialog.fillAmountAction(initialDeposits[borrowAsset] * 10) - - await borrowDialog.expectAssetInputError(borrowValidationIssueToMessage['insufficient-collateral']) - await borrowDialog.expectHealthFactorBeforeVisible() - await screenshot(borrowDialog.getDialog(), 'borrow-dialog-exceeds-max-amount') - }) - }) - - test.describe('Position with only deposit', () => { - const initialDeposits = { - wstETH: 2, - rETH: 2, - } - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ...initialBalances }, - }, - }) - - const borrowPage = new BorrowPageObject(page) - // to simulate a position with only deposits, we go through the easy borrow flow - // but interrupt it before the borrow action, going directly to the myPortfolio - // this way we have deposit transactions executed, but no borrow transaction - // resulting in a position with only deposits - await borrowPage.fillDepositAssetAction(0, 'wstETH', initialDeposits.wstETH) - await borrowPage.addNewDepositAssetAction() - await borrowPage.fillBorrowAssetAction(1) // doesn't matter, we're not borrowing anything - await borrowPage.fillDepositAssetAction(1, 'rETH', initialDeposits.rETH) - await borrowPage.submitAction() - - const actionsContainer = new ActionsPageObject(page) - for (let i = 0; i < 4; i++) { - await actionsContainer.acceptActionAtIndex(i) - } - await actionsContainer.expectEnabledActionAtIndex(4) - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.goToMyPortfolioAction() - await myPortfolioPage.expectDepositedAssets(10_220) - }) - - test('can borrow erc-20', async ({ page }) => { - const borrow = { - asset: 'wstETH', - amount: 1, - } - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickBorrowButtonAction(borrow.asset) - - const borrowDialog = new DialogPageObject(page, headerRegExp) - await borrowDialog.fillAmountAction(borrow.amount) - const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(1) - await borrowDialog.expectSuccessPage([borrow], fork) - - await screenshot(borrowDialog.getDialog(), 'borrow-dialog-only-deposit-erc-20-success') - - await borrowDialog.viewInMyPortfolioAction() - - await myPortfolioPage.expectBorrowTable({ - [borrow.asset]: borrow.amount, - }) - }) - - test('can borrow USDC', async ({ page }) => { - const borrow = { - asset: 'USDC', - amount: 100, - } - - const myPortfolioPage = new MyPortfolioPageObject(page) - - await myPortfolioPage.clickBorrowButtonAction(borrow.asset) - - const borrowDialog = new DialogPageObject(page, headerRegExp) - await borrowDialog.fillAmountAction(borrow.amount) - const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(1) - await borrowDialog.expectSuccessPage([borrow], fork) - - await screenshot(borrowDialog.getDialog(), 'borrow-dialog-USDC-success') - - await borrowDialog.viewInMyPortfolioAction() - - await myPortfolioPage.expectBorrowTable({ - [borrow.asset]: borrow.amount, - }) - }) - - test('displays health factor', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickBorrowButtonAction('rETH') - - const borrowDialog = new DialogPageObject(page, headerRegExp) - await borrowDialog.fillAmountAction(1) - await borrowDialog.expectHealthFactorAfterVisible() - - // @note this is needed for deterministic screenshots - const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) - await actionsContainer.expectEnabledActionAtIndex(0) - - await screenshot(borrowDialog.getDialog(), 'borrow-dialog-only-deposit-health-factor') - }) - - test('clicking MAX sets input to 99% of possible borrow', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickBorrowButtonAction('DAI') - - const borrowDialog = new DialogPageObject(page, headerRegExp) - await borrowDialog.clickMaxAmountAction() - - await borrowDialog.expectInputValue('6929.369808') - await borrowDialog.expectMaxButtonDisabled() - await borrowDialog.expectLiquidationRiskWarning( - 'Borrowing this amount puts you at risk of quick liquidation. You may lose part of your collateral.', - ) - - await borrowDialog.clickAcknowledgeRisk() - - await borrowDialog.actionsContainer.expectActions([{ type: 'borrow', asset: 'DAI' }]) - await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) - }) - }) - - test.describe('Position in isolation mode', () => { - const fork = setupFork({ - blockNumber: 20230000n, - chainId: mainnet.id, - simulationDateOverride: new Date('2024-07-04T15:32:19Z'), - }) - const initialDeposits = { - weETH: 200, - } - - let myPortfolioPage: MyPortfolioPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'myPortfolio', - account: { - type: 'connected-random', - assetBalances: { ...initialDeposits }, - }, - }) - - myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickDepositButtonAction('weETH') - const depositDialog = new DialogPageObject(page, /Deposit weETH/) - await depositDialog.fillAmountAction(initialDeposits.weETH) - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) - await depositDialog.viewInMyPortfolioAction() - - await myPortfolioPage.clickCollateralSwitchAction('weETH') - - const collateralDialog = new CollateralDialogPageObject(page) - await collateralDialog.setUseAsCollateralAction('weETH', 'enabled') - await collateralDialog.viewInMyPortfolioAction() - - await myPortfolioPage.expectDepositedAssets(671_900) - }) - - test('MAX borrow accounts for isolation debt ceiling', async ({ page }) => { - await myPortfolioPage.clickBorrowButtonAction('DAI') - - const borrowDialog = new DialogPageObject(page, headerRegExp) - await borrowDialog.clickMaxAmountAction() - - await borrowDialog.expectInputValue('110616.31') - await borrowDialog.expectMaxButtonDisabled() - await borrowDialog.actionsContainer.expectActions([{ type: 'borrow', asset: 'DAI' }]) - await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) - }) - }) - - test.describe('Position with large deposit', () => { - const fork = setupFork({ - blockNumber: 20235425n, - chainId: mainnet.id, - simulationDateOverride: new Date('2024-07-04T21:26:19Z'), - }) - const initialDeposits = { - WETH: 100_000, - } - - let myPortfolioPage: MyPortfolioPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'myPortfolio', - account: { - type: 'connected-random', - assetBalances: { ...initialDeposits }, - }, - }) - - myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickDepositButtonAction('WETH') - const depositDialog = new DialogPageObject(page, /Deposit WETH/) - await depositDialog.fillAmountAction(initialDeposits.WETH) - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) - await depositDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectDepositedAssets(313_328_590) - }) - - test('MAX borrow accounts for borrow cap', async ({ page }) => { - await myPortfolioPage.clickBorrowButtonAction('wstETH') - - const borrowDialog = new DialogPageObject(page, headerRegExp) - await borrowDialog.clickMaxAmountAction() - - await borrowDialog.expectInputValue('99.323398') - await borrowDialog.expectMaxButtonDisabled() - await borrowDialog.actionsContainer.expectActions([{ type: 'borrow', asset: 'wstETH' }]) - await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) - }) - - test('MAX borrow accounts for available liquidity', async ({ page }) => { - await myPortfolioPage.clickBorrowButtonAction('USDC') - - const borrowDialog = new DialogPageObject(page, headerRegExp) - await borrowDialog.clickMaxAmountAction() - - await borrowDialog.expectInputValue('409207.097251') - await borrowDialog.expectMaxButtonDisabled() - await borrowDialog.actionsContainer.expectActions([{ type: 'borrow', asset: 'USDC' }]) - await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) - }) - }) - - test.describe('Liquidation risk warning', () => { - let borrowDialog: DialogPageObject - let myPortfolioPage: MyPortfolioPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, - }, - }) - - borrowDialog = new DialogPageObject(page, headerRegExp) - myPortfolioPage = new MyPortfolioPageObject(page) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositWithoutBorrowActions({ rETH: 2, wstETH: 10 }) - await myPortfolioPage.goToMyPortfolioAction() - }) - - test('shows risk warning', async () => { - await myPortfolioPage.clickBorrowButtonAction('WETH') - - await borrowDialog.fillAmountAction(8) - await borrowDialog.expectLiquidationRiskWarning( - 'Borrowing this amount puts you at risk of quick liquidation. You may lose part of your collateral.', - ) - }) - - test('actions stay disabled until risk warning is acknowledged', async () => { - await myPortfolioPage.clickBorrowButtonAction('WETH') - - await borrowDialog.fillAmountAction(8) - await borrowDialog.actionsContainer.expectDisabledActionAtIndex(0) - await borrowDialog.clickAcknowledgeRisk() - await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) - }) - - test('hf above danger zone threshold; risk warning is not shown', async () => { - await myPortfolioPage.clickBorrowButtonAction('WETH') - - await borrowDialog.fillAmountAction(0.1) - await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) - await borrowDialog.expectLiquidationRiskWarningNotVisible() - }) - - test('input validation error; risk warning is not shown', async () => { - await myPortfolioPage.clickBorrowButtonAction('WETH') - - await borrowDialog.fillAmountAction(0) - await borrowDialog.expectAssetInputError(borrowValidationIssueToMessage['value-not-positive']) - await borrowDialog.expectLiquidationRiskWarningNotVisible() - }) - }) -}) +// test('has correct action plan for native asset', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) + +// await myPortfolioPage.clickBorrowButtonAction('WETH') + +// const borrowDialog = new DialogPageObject(page, headerRegExp) +// await borrowDialog.selectAssetAction('ETH') +// await borrowDialog.fillAmountAction(1) + +// await borrowDialog.expectHealthFactorVisible() + +// const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) +// await actionsContainer.expectActions([ +// { type: 'approveDelegation', asset: 'ETH' }, +// { type: 'borrow', asset: 'ETH' }, +// ]) + +// await screenshot(borrowDialog.getDialog(), 'borrow-dialog-eth-action-plan') +// }) + +// test('can borrow native asset', async ({ page }) => { +// const borrow = { +// asset: 'ETH', +// amount: 1, +// } + +// const myPortfolioPage = new MyPortfolioPageObject(page) + +// await myPortfolioPage.clickBorrowButtonAction('WETH') + +// const borrowDialog = new DialogPageObject(page, headerRegExp) +// await borrowDialog.selectAssetAction(borrow.asset) +// await borrowDialog.fillAmountAction(1) +// const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) +// await borrowDialog.expectSuccessPage([borrow], fork) +// await screenshot(borrowDialog.getDialog(), 'borrow-dialog-eth-success') + +// await borrowDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.expectBorrowTable({ +// WETH: borrow.amount, +// }) +// }) + +// test('can borrow same asset again', async ({ page }) => { +// const borrow = { +// asset: 'DAI', +// amount: 1500, +// } + +// const myPortfolioPage = new MyPortfolioPageObject(page) + +// await myPortfolioPage.clickBorrowButtonAction(borrow.asset) + +// const borrowDialog = new DialogPageObject(page, headerRegExp) +// await borrowDialog.fillAmountAction(borrow.amount) +// const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(1) +// await borrowDialog.expectSuccessPage([borrow], fork) + +// await screenshot(borrowDialog.getDialog(), 'borrow-dialog-borrow-twice-success') + +// await borrowDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.expectBorrowTable({ +// [borrow.asset]: borrow.amount + daiToBorrow, +// }) +// }) + +// test("can't borrow more than allowed", async ({ page }) => { +// const borrowAsset = 'wstETH' +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickBorrowButtonAction(borrowAsset) + +// const borrowDialog = new DialogPageObject(page, headerRegExp) +// await borrowDialog.fillAmountAction(initialDeposits[borrowAsset] * 10) + +// await borrowDialog.expectAssetInputError(borrowValidationIssueToMessage['insufficient-collateral']) +// await borrowDialog.expectHealthFactorBeforeVisible() +// await screenshot(borrowDialog.getDialog(), 'borrow-dialog-exceeds-max-amount') +// }) +// }) + +// test.describe('Position with only deposit', () => { +// const initialDeposits = { +// wstETH: 2, +// rETH: 2, +// } + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ...initialBalances }, +// }, +// }) + +// const borrowPage = new BorrowPageObject(page) +// // to simulate a position with only deposits, we go through the easy borrow flow +// // but interrupt it before the borrow action, going directly to the myPortfolio +// // this way we have deposit transactions executed, but no borrow transaction +// // resulting in a position with only deposits +// await borrowPage.fillDepositAssetAction(0, 'wstETH', initialDeposits.wstETH) +// await borrowPage.addNewDepositAssetAction() +// await borrowPage.fillBorrowAssetAction(1) // doesn't matter, we're not borrowing anything +// await borrowPage.fillDepositAssetAction(1, 'rETH', initialDeposits.rETH) +// await borrowPage.submitAction() + +// const actionsContainer = new ActionsPageObject(page) +// for (let i = 0; i < 4; i++) { +// await actionsContainer.acceptActionAtIndex(i) +// } +// await actionsContainer.expectEnabledActionAtIndex(4) + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.goToMyPortfolioAction() +// await myPortfolioPage.expectDepositedAssets(10_220) +// }) + +// test('can borrow erc-20', async ({ page }) => { +// const borrow = { +// asset: 'wstETH', +// amount: 1, +// } + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickBorrowButtonAction(borrow.asset) + +// const borrowDialog = new DialogPageObject(page, headerRegExp) +// await borrowDialog.fillAmountAction(borrow.amount) +// const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(1) +// await borrowDialog.expectSuccessPage([borrow], fork) + +// await screenshot(borrowDialog.getDialog(), 'borrow-dialog-only-deposit-erc-20-success') + +// await borrowDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.expectBorrowTable({ +// [borrow.asset]: borrow.amount, +// }) +// }) + +// test('can borrow USDC', async ({ page }) => { +// const borrow = { +// asset: 'USDC', +// amount: 100, +// } + +// const myPortfolioPage = new MyPortfolioPageObject(page) + +// await myPortfolioPage.clickBorrowButtonAction(borrow.asset) + +// const borrowDialog = new DialogPageObject(page, headerRegExp) +// await borrowDialog.fillAmountAction(borrow.amount) +// const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(1) +// await borrowDialog.expectSuccessPage([borrow], fork) + +// await screenshot(borrowDialog.getDialog(), 'borrow-dialog-USDC-success') + +// await borrowDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.expectBorrowTable({ +// [borrow.asset]: borrow.amount, +// }) +// }) + +// test('displays health factor', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickBorrowButtonAction('rETH') + +// const borrowDialog = new DialogPageObject(page, headerRegExp) +// await borrowDialog.fillAmountAction(1) +// await borrowDialog.expectHealthFactorAfterVisible() + +// // @note this is needed for deterministic screenshots +// const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) +// await actionsContainer.expectEnabledActionAtIndex(0) + +// await screenshot(borrowDialog.getDialog(), 'borrow-dialog-only-deposit-health-factor') +// }) + +// test('clicking MAX sets input to 99% of possible borrow', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickBorrowButtonAction('DAI') + +// const borrowDialog = new DialogPageObject(page, headerRegExp) +// await borrowDialog.clickMaxAmountAction() + +// await borrowDialog.expectInputValue('6929.369808') +// await borrowDialog.expectMaxButtonDisabled() +// await borrowDialog.expectLiquidationRiskWarning( +// 'Borrowing this amount puts you at risk of quick liquidation. You may lose part of your collateral.', +// ) + +// await borrowDialog.clickAcknowledgeRisk() + +// await borrowDialog.actionsContainer.expectActions([{ type: 'borrow', asset: 'DAI' }]) +// await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) +// }) +// }) + +// test.describe('Position in isolation mode', () => { +// const fork = setupFork({ +// blockNumber: 20230000n, +// chainId: mainnet.id, +// simulationDateOverride: new Date('2024-07-04T15:32:19Z'), +// }) +// const initialDeposits = { +// weETH: 200, +// } + +// let myPortfolioPage: MyPortfolioPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'myPortfolio', +// account: { +// type: 'connected-random', +// assetBalances: { ...initialDeposits }, +// }, +// }) + +// myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickDepositButtonAction('weETH') +// const depositDialog = new DialogPageObject(page, /Deposit weETH/) +// await depositDialog.fillAmountAction(initialDeposits.weETH) +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) +// await depositDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.clickCollateralSwitchAction('weETH') + +// const collateralDialog = new CollateralDialogPageObject(page) +// await collateralDialog.setUseAsCollateralAction('weETH', 'enabled') +// await collateralDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.expectDepositedAssets(671_900) +// }) + +// test('MAX borrow accounts for isolation debt ceiling', async ({ page }) => { +// await myPortfolioPage.clickBorrowButtonAction('DAI') + +// const borrowDialog = new DialogPageObject(page, headerRegExp) +// await borrowDialog.clickMaxAmountAction() + +// await borrowDialog.expectInputValue('110616.31') +// await borrowDialog.expectMaxButtonDisabled() +// await borrowDialog.actionsContainer.expectActions([{ type: 'borrow', asset: 'DAI' }]) +// await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) +// }) +// }) + +// test.describe('Position with large deposit', () => { +// const fork = setupFork({ +// blockNumber: 20235425n, +// chainId: mainnet.id, +// simulationDateOverride: new Date('2024-07-04T21:26:19Z'), +// }) +// const initialDeposits = { +// WETH: 100_000, +// } + +// let myPortfolioPage: MyPortfolioPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'myPortfolio', +// account: { +// type: 'connected-random', +// assetBalances: { ...initialDeposits }, +// }, +// }) + +// myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickDepositButtonAction('WETH') +// const depositDialog = new DialogPageObject(page, /Deposit WETH/) +// await depositDialog.fillAmountAction(initialDeposits.WETH) +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) +// await depositDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectDepositedAssets(313_328_590) +// }) + +// test('MAX borrow accounts for borrow cap', async ({ page }) => { +// await myPortfolioPage.clickBorrowButtonAction('wstETH') + +// const borrowDialog = new DialogPageObject(page, headerRegExp) +// await borrowDialog.clickMaxAmountAction() + +// await borrowDialog.expectInputValue('99.323398') +// await borrowDialog.expectMaxButtonDisabled() +// await borrowDialog.actionsContainer.expectActions([{ type: 'borrow', asset: 'wstETH' }]) +// await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) +// }) + +// test('MAX borrow accounts for available liquidity', async ({ page }) => { +// await myPortfolioPage.clickBorrowButtonAction('USDC') + +// const borrowDialog = new DialogPageObject(page, headerRegExp) +// await borrowDialog.clickMaxAmountAction() + +// await borrowDialog.expectInputValue('409207.097251') +// await borrowDialog.expectMaxButtonDisabled() +// await borrowDialog.actionsContainer.expectActions([{ type: 'borrow', asset: 'USDC' }]) +// await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) +// }) +// }) + +// test.describe('Liquidation risk warning', () => { +// let borrowDialog: DialogPageObject +// let myPortfolioPage: MyPortfolioPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, +// }, +// }) + +// borrowDialog = new DialogPageObject(page, headerRegExp) +// myPortfolioPage = new MyPortfolioPageObject(page) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositWithoutBorrowActions({ rETH: 2, wstETH: 10 }) +// await myPortfolioPage.goToMyPortfolioAction() +// }) + +// test('shows risk warning', async () => { +// await myPortfolioPage.clickBorrowButtonAction('WETH') + +// await borrowDialog.fillAmountAction(8) +// await borrowDialog.expectLiquidationRiskWarning( +// 'Borrowing this amount puts you at risk of quick liquidation. You may lose part of your collateral.', +// ) +// }) + +// test('actions stay disabled until risk warning is acknowledged', async () => { +// await myPortfolioPage.clickBorrowButtonAction('WETH') + +// await borrowDialog.fillAmountAction(8) +// await borrowDialog.actionsContainer.expectDisabledActionAtIndex(0) +// await borrowDialog.clickAcknowledgeRisk() +// await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) +// }) + +// test('hf above danger zone threshold; risk warning is not shown', async () => { +// await myPortfolioPage.clickBorrowButtonAction('WETH') + +// await borrowDialog.fillAmountAction(0.1) +// await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) +// await borrowDialog.expectLiquidationRiskWarningNotVisible() +// }) + +// test('input validation error; risk warning is not shown', async () => { +// await myPortfolioPage.clickBorrowButtonAction('WETH') + +// await borrowDialog.fillAmountAction(0) +// await borrowDialog.expectAssetInputError(borrowValidationIssueToMessage['value-not-positive']) +// await borrowDialog.expectLiquidationRiskWarningNotVisible() +// }) +// }) +// }) diff --git a/packages/app/src/features/dialogs/claim-rewards/ClaimRewardsDialog.test-e2e.ts b/packages/app/src/features/dialogs/claim-rewards/ClaimRewardsDialog.test-e2e.ts index cf0ceccea..7d1de43c6 100644 --- a/packages/app/src/features/dialogs/claim-rewards/ClaimRewardsDialog.test-e2e.ts +++ b/packages/app/src/features/dialogs/claim-rewards/ClaimRewardsDialog.test-e2e.ts @@ -1,75 +1,75 @@ -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { TopbarPageObject } from '@/features/topbar/Topbar.PageObject' -import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { ClaimRewardsDialogPageObject } from './ClaimRewardsDialog.PageObject' +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { TopbarPageObject } from '@/features/topbar/Topbar.PageObject' +// import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { ClaimRewardsDialogPageObject } from './ClaimRewardsDialog.PageObject' -test.describe('Claim rewards dialog', () => { - const fork = setupFork({ - blockNumber: 20189272n, // block number where the reward program is finished - chainId: mainnet.id, - }) - let navbar: TopbarPageObject - let claimRewardsDialog: ClaimRewardsDialogPageObject - let actionsContainer: ActionsPageObject +// test.describe('Claim rewards dialog', () => { +// const fork = setupFork({ +// blockNumber: 20189272n, // block number where the reward program is finished +// chainId: mainnet.id, +// }) +// let navbar: TopbarPageObject +// let claimRewardsDialog: ClaimRewardsDialogPageObject +// let actionsContainer: ActionsPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-address', - address: '0xf8de75c7b95edb6f1e639751318f117663021cf0', - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-address', +// address: '0xf8de75c7b95edb6f1e639751318f117663021cf0', +// }, +// }) - navbar = new TopbarPageObject(page) - await navbar.openClaimRewardsDialog() +// navbar = new TopbarPageObject(page) +// await navbar.openClaimRewardsDialog() - claimRewardsDialog = new ClaimRewardsDialogPageObject(page) - actionsContainer = new ActionsPageObject(claimRewardsDialog.locatePanelByHeader('Actions')) - }) +// claimRewardsDialog = new ClaimRewardsDialogPageObject(page) +// actionsContainer = new ActionsPageObject(claimRewardsDialog.locatePanelByHeader('Actions')) +// }) - test('displays correct transaction overview', async () => { - await claimRewardsDialog.expectRewards([ - { - tokenSymbol: 'wstETH', - amount: '6.3697', - amountUSD: '$25,583.20', - }, - ]) - }) +// test('displays correct transaction overview', async () => { +// await claimRewardsDialog.expectRewards([ +// { +// tokenSymbol: 'wstETH', +// amount: '6.3697', +// amountUSD: '$25,583.20', +// }, +// ]) +// }) - test('has correct action plan', async () => { - await actionsContainer.expectActions([ - { - type: 'claimMarketRewards', - asset: 'wstETH', - }, - ]) - }) +// test('has correct action plan', async () => { +// await actionsContainer.expectActions([ +// { +// type: 'claimMarketRewards', +// asset: 'wstETH', +// }, +// ]) +// }) - test('executes transaction', async ({ page }) => { - await actionsContainer.acceptAllActionsAction(1) +// test('executes transaction', async ({ page }) => { +// await actionsContainer.acceptAllActionsAction(1) - await claimRewardsDialog.expectClaimRewardsSuccessPage([ - { - tokenSymbol: 'wstETH', - amount: '6.3697', - amountUSD: '$25,583.20', - }, - ]) +// await claimRewardsDialog.expectClaimRewardsSuccessPage([ +// { +// tokenSymbol: 'wstETH', +// amount: '6.3697', +// amountUSD: '$25,583.20', +// }, +// ]) - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.goToMyPortfolioAction() +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.goToMyPortfolioAction() - await myPortfolioPage.expectBalancesInDepositTable({ - wstETH: 6.3697, - }) +// await myPortfolioPage.expectBalancesInDepositTable({ +// wstETH: 6.3697, +// }) - await navbar.expectRewardsBadgeNotVisible() - }) -}) +// await navbar.expectRewardsBadgeNotVisible() +// }) +// }) diff --git a/packages/app/src/features/dialogs/collateral/CollateralDialog.test-e2e.ts b/packages/app/src/features/dialogs/collateral/CollateralDialog.test-e2e.ts index 4e5fbe172..2b3be99b4 100644 --- a/packages/app/src/features/dialogs/collateral/CollateralDialog.test-e2e.ts +++ b/packages/app/src/features/dialogs/collateral/CollateralDialog.test-e2e.ts @@ -1,419 +1,419 @@ -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' - -import { setUseAsCollateralValidationIssueToMessage } from '@/domain/market-validators/validateSetUseAsCollateral' -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { BorrowPageObject } from '@/pages/Borrow.PageObject' -import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' -import { DEFAULT_BLOCK_NUMBER, GNO_ACTIVE_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' - -import { DialogPageObject } from '../common/Dialog.PageObject' -import { CollateralDialogPageObject } from './CollateralDialog.PageObject' - -test.describe('Collateral dialog', () => { - const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) - const initialBalances = { - wstETH: 100, - rETH: 100, - DAI: 10000, - GNO: 100, - } - - test.describe('Deposited multiple assets, no borrow', () => { - const initialDeposits = { - wstETH: 1, - } - const myPortfolioDesposits = { - DAI: 1000, // cannot be used as collateral - } - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ...initialBalances }, - }, - }) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositWithoutBorrowActions(initialDeposits) - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.goToMyPortfolioAction() - - // Depositing DAI in myPortfolio - await myPortfolioPage.clickDepositButtonAction('DAI') - const depositDialog = new DialogPageObject(page, /Deposit/) - await depositDialog.fillAmountAction(myPortfolioDesposits.DAI) - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) - await depositDialog.viewInMyPortfolioAction() - - await myPortfolioPage.expectDepositTable({ - wstETH: initialDeposits.wstETH, - DAI: myPortfolioDesposits.DAI, - }) - }) - - test('disables collateral', async ({ page }) => { - const collateral = 'wstETH' - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.expectCollateralSwitch(collateral, true) - await myPortfolioPage.clickCollateralSwitchAction(collateral) - - const collateralDialog = new CollateralDialogPageObject(page) - await collateralDialog.expectDialogHeader('Collateral') - await collateralDialog.expectHealthFactorNotVisible() - const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(1) - await collateralDialog.expectSetUseAsCollateralSuccessPage(collateral, 'disabled') - - await myPortfolioPage.goToMyPortfolioAction() - await myPortfolioPage.expectCollateralSwitch('wstETH', false) - }) - - test('enables collateral', async ({ page }) => { - const collateral = 'wstETH' - - // disabling collateral - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickCollateralSwitchAction(collateral) - const collateralDialog = new CollateralDialogPageObject(page) - await collateralDialog.setUseAsCollateralAction(collateral, 'disabled') - await myPortfolioPage.goToMyPortfolioAction() - - // enabling collateral - await myPortfolioPage.expectCollateralSwitch(collateral, false) - await myPortfolioPage.clickCollateralSwitchAction(collateral) - await collateralDialog.expectDialogHeader('Collateral') - await collateralDialog.expectHealthFactorNotVisible() - const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(1) - await collateralDialog.expectSetUseAsCollateralSuccessPage(collateral, 'enabled') - - await myPortfolioPage.goToMyPortfolioAction() - await myPortfolioPage.expectCollateralSwitch(collateral, true) - }) - - test('cannot enable collateral for asset that cannot be used as collateral', async ({ page }) => { - const asset = 'DAI' - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.expectCollateralSwitch(asset, false) - await myPortfolioPage.clickCollateralSwitchAction(asset) - - const collateralDialog = new CollateralDialogPageObject(page) - await collateralDialog.expectDialogHeader('Collateral') - await collateralDialog.expectHealthFactorNotVisible() - await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['zero-ltv-asset']) - const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) - await actionsContainer.expectDisabledActionAtIndex(0) - - await myPortfolioPage.goToMyPortfolioAction() - await myPortfolioPage.expectCollateralSwitch(asset, false) - }) - - test('cannot enable collateral for not deposited asset', async ({ page }) => { - const asset = 'WBTC' - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.expectCollateralSwitch(asset, false) - await myPortfolioPage.clickCollateralSwitchAction(asset) - - const collateralDialog = new CollateralDialogPageObject(page) - await collateralDialog.expectDialogHeader('Collateral') - await collateralDialog.expectHealthFactorNotVisible() - await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['zero-deposit-asset']) - const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) - await actionsContainer.expectDisabledActionAtIndex(0) - - await myPortfolioPage.goToMyPortfolioAction() - await myPortfolioPage.expectCollateralSwitch(asset, false) - }) - }) - - test.describe('Single collateral, DAI borrow', () => { - const initialDeposits = { - wstETH: 1, - } - const daiToBorrow = 1000 - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ...initialBalances }, - }, - }) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) - await borrowPage.viewInMyPortfolioAction() - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.goToMyPortfolioAction() - - await myPortfolioPage.expectDepositTable({ - wstETH: initialDeposits.wstETH, - }) - }) - - test('cannot disable sole collateral', async ({ page }) => { - const collateral = 'wstETH' - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.expectCollateralSwitch(collateral, true) - await myPortfolioPage.clickCollateralSwitchAction(collateral) - - const collateralDialog = new CollateralDialogPageObject(page) - await collateralDialog.expectDialogHeader('Collateral') - await collateralDialog.expectHealthFactorBefore('2.08') - await collateralDialog.expectHealthFactorAfter('0') - await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['exceeds-ltv']) - const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) - await actionsContainer.expectDisabledActionAtIndex(0) - - await myPortfolioPage.goToMyPortfolioAction() - await myPortfolioPage.expectCollateralSwitch(collateral, true) - }) - }) - - test.describe('Multiple collaterals, DAI borrow', () => { - const initialDeposits = { - wstETH: 1, - rETH: 0.01, - } - const daiToBorrow = 1000 - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ...initialBalances }, - }, - }) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) - await borrowPage.viewInMyPortfolioAction() - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.goToMyPortfolioAction() - - await myPortfolioPage.expectDepositTable({ - wstETH: initialDeposits.wstETH, - rETH: initialDeposits.rETH, - }) - }) - - test('disables collateral', async ({ page }) => { - const collateral = 'rETH' - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.expectCollateralSwitch(collateral, true) - await myPortfolioPage.clickCollateralSwitchAction(collateral) - - const collateralDialog = new CollateralDialogPageObject(page) - await collateralDialog.expectDialogHeader('Collateral') - await collateralDialog.expectHealthFactorBefore('2.1') - await collateralDialog.expectHealthFactorAfter('2.08') - const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(1) - - await collateralDialog.expectSetUseAsCollateralSuccessPage(collateral, 'disabled') - await myPortfolioPage.goToMyPortfolioAction() - await myPortfolioPage.expectCollateralSwitch('rETH', false) - }) - - test('cannot disable collateral when second one would not cover loan', async ({ page }) => { - const collateral = 'wstETH' - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.expectCollateralSwitch(collateral, true) - await myPortfolioPage.clickCollateralSwitchAction(collateral) - - const collateralDialog = new CollateralDialogPageObject(page) - await collateralDialog.expectDialogHeader('Collateral') - await collateralDialog.expectHealthFactorBefore('2.1') - await collateralDialog.expectHealthFactorAfter('0.02') - await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['exceeds-ltv']) - const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) - await actionsContainer.expectDisabledActionAtIndex(0) - - await myPortfolioPage.goToMyPortfolioAction() - await myPortfolioPage.expectCollateralSwitch(collateral, true) - }) - }) - - test.describe('Isolation mode', () => { - const fork = setupFork({ blockNumber: GNO_ACTIVE_BLOCK_NUMBER, chainId: mainnet.id }) - const isolatedAsset = 'GNO' - const regularAsset = 'rETH' - const initialDeposits = { - [regularAsset]: 1, - } - const myPortfolioDesposits = { - [isolatedAsset]: 100, - } - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ...initialBalances }, - }, - }) - - // Depositing regular asset at borrow page to show myPortfolio positions - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositWithoutBorrowActions(initialDeposits) - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.goToMyPortfolioAction() - - await myPortfolioPage.expectDepositTable({ - [regularAsset]: initialDeposits[regularAsset], - }) - - // Depositing isolated asset at myPortfolio - await myPortfolioPage.clickDepositButtonAction(isolatedAsset) - const depositDialog = new DialogPageObject(page, /Deposit/) - await depositDialog.fillAmountAction(myPortfolioDesposits[isolatedAsset]) - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) - await depositDialog.viewInMyPortfolioAction() - - const collateralDialog = new CollateralDialogPageObject(page) - // Disabling regular asset as collateral - await myPortfolioPage.clickCollateralSwitchAction(regularAsset) - await collateralDialog.setUseAsCollateralAction(regularAsset, 'disabled') - await myPortfolioPage.goToMyPortfolioAction() - await myPortfolioPage.expectCollateralSwitch(isolatedAsset, false) - - // Entering isolation mode - await myPortfolioPage.clickCollateralSwitchAction(isolatedAsset) - await collateralDialog.setUseAsCollateralAction(isolatedAsset, 'enabled') - await myPortfolioPage.goToMyPortfolioAction() - - await myPortfolioPage.expectCollateralSwitch(isolatedAsset, true) - }) - - test('cannot enable asset as collateral in isolation mode', async ({ page }) => { - const collateral = 'rETH' - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.expectCollateralSwitch(collateral, false) - await myPortfolioPage.clickCollateralSwitchAction(collateral) - - const collateralDialog = new CollateralDialogPageObject(page) - await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['isolation-mode-active']) - const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) - await actionsContainer.expectDisabledActionAtIndex(0) - - await myPortfolioPage.goToMyPortfolioAction() - await myPortfolioPage.expectCollateralSwitch(collateral, false) - }) - }) - - test.describe('Liquidation risk warning', () => { - test.describe('In danger zone', () => { - let collateralDialog: CollateralDialogPageObject - let myPortfolioPage: MyPortfolioPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, - }, - }) - - collateralDialog = new CollateralDialogPageObject(page) - myPortfolioPage = new MyPortfolioPageObject(page) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositWithoutBorrowActions({ rETH: 2, wstETH: 10 }) - await myPortfolioPage.goToMyPortfolioAction() - - await myPortfolioPage.clickBorrowButtonAction('WETH') - const borrowDialog = new DialogPageObject(page, /Borrow/) - await borrowDialog.fillAmountAction(7) - await borrowDialog.actionsContainer.acceptAllActionsAction(1) - await borrowDialog.expectSuccessPage([{ asset: 'WETH', amount: 7 }], fork) - await borrowDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectAssetToBeInBorrowTable('WETH') - }) - - test('shows risk warning', async () => { - await myPortfolioPage.clickCollateralSwitchAction('rETH') - await collateralDialog.expectLiquidationRiskWarning( - 'Disabling this asset as collateral puts you at risk of quick liquidation. You may lose part of your remaining collateral.', - ) - }) - - test('actions stay disabled until risk warning is acknowledged', async () => { - await myPortfolioPage.clickCollateralSwitchAction('rETH') - - await collateralDialog.actionsContainer.expectDisabledActionAtIndex(0) - await collateralDialog.clickAcknowledgeRisk() - await collateralDialog.actionsContainer.expectEnabledActionAtIndex(0) - }) - }) - - test.describe('Not in danger zone', () => { - let collateralDialog: CollateralDialogPageObject - let myPortfolioPage: MyPortfolioPageObject - - const rETHDeposit = { asset: 'rETH', amount: 1 } - const wstETHDeposit = { asset: 'wstETH', amount: 1 } - const daiBorrow = { asset: 'DAI', amount: 500 } - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, - }, - }) - - collateralDialog = new CollateralDialogPageObject(page) - myPortfolioPage = new MyPortfolioPageObject(page) - }) - - test('validation issue; risk warning is not shown', async ({ page }) => { - // depositing single asset as collateral, so turing off will trigger validation - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositAssetsActions({ rETH: rETHDeposit.amount }, daiBorrow.amount) - await borrowPage.expectSuccessPage([rETHDeposit], daiBorrow, fork) - await myPortfolioPage.goToMyPortfolioAction() - await myPortfolioPage.expectAssetToBeInBorrowTable('DAI') - - await myPortfolioPage.clickCollateralSwitchAction('rETH') - await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['exceeds-ltv']) - await collateralDialog.expectLiquidationRiskWarningNotVisible() - }) - - test('no validation issue; risk warning is not shown', async ({ page }) => { - // depositing multiple assets as collateral, so turning off single asset will not trigger validation - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositAssetsActions( - { wstETH: wstETHDeposit.amount, rETH: rETHDeposit.amount }, - daiBorrow.amount, - ) - await borrowPage.expectSuccessPage([wstETHDeposit, rETHDeposit], daiBorrow, fork) - await myPortfolioPage.goToMyPortfolioAction() - await myPortfolioPage.expectAssetToBeInBorrowTable('DAI') - - await myPortfolioPage.clickCollateralSwitchAction('rETH') - await collateralDialog.expectLiquidationRiskWarningNotVisible() - }) - }) - }) -}) +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' + +// import { setUseAsCollateralValidationIssueToMessage } from '@/domain/market-validators/validateSetUseAsCollateral' +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { BorrowPageObject } from '@/pages/Borrow.PageObject' +// import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' +// import { DEFAULT_BLOCK_NUMBER, GNO_ACTIVE_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' + +// import { DialogPageObject } from '../common/Dialog.PageObject' +// import { CollateralDialogPageObject } from './CollateralDialog.PageObject' + +// test.describe('Collateral dialog', () => { +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) +// const initialBalances = { +// wstETH: 100, +// rETH: 100, +// DAI: 10000, +// GNO: 100, +// } + +// test.describe('Deposited multiple assets, no borrow', () => { +// const initialDeposits = { +// wstETH: 1, +// } +// const myPortfolioDesposits = { +// DAI: 1000, // cannot be used as collateral +// } + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ...initialBalances }, +// }, +// }) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositWithoutBorrowActions(initialDeposits) +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.goToMyPortfolioAction() + +// // Depositing DAI in myPortfolio +// await myPortfolioPage.clickDepositButtonAction('DAI') +// const depositDialog = new DialogPageObject(page, /Deposit/) +// await depositDialog.fillAmountAction(myPortfolioDesposits.DAI) +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) +// await depositDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.expectDepositTable({ +// wstETH: initialDeposits.wstETH, +// DAI: myPortfolioDesposits.DAI, +// }) +// }) + +// test('disables collateral', async ({ page }) => { +// const collateral = 'wstETH' + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.expectCollateralSwitch(collateral, true) +// await myPortfolioPage.clickCollateralSwitchAction(collateral) + +// const collateralDialog = new CollateralDialogPageObject(page) +// await collateralDialog.expectDialogHeader('Collateral') +// await collateralDialog.expectHealthFactorNotVisible() +// const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(1) +// await collateralDialog.expectSetUseAsCollateralSuccessPage(collateral, 'disabled') + +// await myPortfolioPage.goToMyPortfolioAction() +// await myPortfolioPage.expectCollateralSwitch('wstETH', false) +// }) + +// test('enables collateral', async ({ page }) => { +// const collateral = 'wstETH' + +// // disabling collateral +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickCollateralSwitchAction(collateral) +// const collateralDialog = new CollateralDialogPageObject(page) +// await collateralDialog.setUseAsCollateralAction(collateral, 'disabled') +// await myPortfolioPage.goToMyPortfolioAction() + +// // enabling collateral +// await myPortfolioPage.expectCollateralSwitch(collateral, false) +// await myPortfolioPage.clickCollateralSwitchAction(collateral) +// await collateralDialog.expectDialogHeader('Collateral') +// await collateralDialog.expectHealthFactorNotVisible() +// const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(1) +// await collateralDialog.expectSetUseAsCollateralSuccessPage(collateral, 'enabled') + +// await myPortfolioPage.goToMyPortfolioAction() +// await myPortfolioPage.expectCollateralSwitch(collateral, true) +// }) + +// test('cannot enable collateral for asset that cannot be used as collateral', async ({ page }) => { +// const asset = 'DAI' + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.expectCollateralSwitch(asset, false) +// await myPortfolioPage.clickCollateralSwitchAction(asset) + +// const collateralDialog = new CollateralDialogPageObject(page) +// await collateralDialog.expectDialogHeader('Collateral') +// await collateralDialog.expectHealthFactorNotVisible() +// await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['zero-ltv-asset']) +// const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) +// await actionsContainer.expectDisabledActionAtIndex(0) + +// await myPortfolioPage.goToMyPortfolioAction() +// await myPortfolioPage.expectCollateralSwitch(asset, false) +// }) + +// test('cannot enable collateral for not deposited asset', async ({ page }) => { +// const asset = 'WBTC' + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.expectCollateralSwitch(asset, false) +// await myPortfolioPage.clickCollateralSwitchAction(asset) + +// const collateralDialog = new CollateralDialogPageObject(page) +// await collateralDialog.expectDialogHeader('Collateral') +// await collateralDialog.expectHealthFactorNotVisible() +// await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['zero-deposit-asset']) +// const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) +// await actionsContainer.expectDisabledActionAtIndex(0) + +// await myPortfolioPage.goToMyPortfolioAction() +// await myPortfolioPage.expectCollateralSwitch(asset, false) +// }) +// }) + +// test.describe('Single collateral, DAI borrow', () => { +// const initialDeposits = { +// wstETH: 1, +// } +// const daiToBorrow = 1000 + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ...initialBalances }, +// }, +// }) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) +// await borrowPage.viewInMyPortfolioAction() + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.goToMyPortfolioAction() + +// await myPortfolioPage.expectDepositTable({ +// wstETH: initialDeposits.wstETH, +// }) +// }) + +// test('cannot disable sole collateral', async ({ page }) => { +// const collateral = 'wstETH' + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.expectCollateralSwitch(collateral, true) +// await myPortfolioPage.clickCollateralSwitchAction(collateral) + +// const collateralDialog = new CollateralDialogPageObject(page) +// await collateralDialog.expectDialogHeader('Collateral') +// await collateralDialog.expectHealthFactorBefore('2.08') +// await collateralDialog.expectHealthFactorAfter('0') +// await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['exceeds-ltv']) +// const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) +// await actionsContainer.expectDisabledActionAtIndex(0) + +// await myPortfolioPage.goToMyPortfolioAction() +// await myPortfolioPage.expectCollateralSwitch(collateral, true) +// }) +// }) + +// test.describe('Multiple collaterals, DAI borrow', () => { +// const initialDeposits = { +// wstETH: 1, +// rETH: 0.01, +// } +// const daiToBorrow = 1000 + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ...initialBalances }, +// }, +// }) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) +// await borrowPage.viewInMyPortfolioAction() + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.goToMyPortfolioAction() + +// await myPortfolioPage.expectDepositTable({ +// wstETH: initialDeposits.wstETH, +// rETH: initialDeposits.rETH, +// }) +// }) + +// test('disables collateral', async ({ page }) => { +// const collateral = 'rETH' + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.expectCollateralSwitch(collateral, true) +// await myPortfolioPage.clickCollateralSwitchAction(collateral) + +// const collateralDialog = new CollateralDialogPageObject(page) +// await collateralDialog.expectDialogHeader('Collateral') +// await collateralDialog.expectHealthFactorBefore('2.1') +// await collateralDialog.expectHealthFactorAfter('2.08') +// const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(1) + +// await collateralDialog.expectSetUseAsCollateralSuccessPage(collateral, 'disabled') +// await myPortfolioPage.goToMyPortfolioAction() +// await myPortfolioPage.expectCollateralSwitch('rETH', false) +// }) + +// test('cannot disable collateral when second one would not cover loan', async ({ page }) => { +// const collateral = 'wstETH' + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.expectCollateralSwitch(collateral, true) +// await myPortfolioPage.clickCollateralSwitchAction(collateral) + +// const collateralDialog = new CollateralDialogPageObject(page) +// await collateralDialog.expectDialogHeader('Collateral') +// await collateralDialog.expectHealthFactorBefore('2.1') +// await collateralDialog.expectHealthFactorAfter('0.02') +// await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['exceeds-ltv']) +// const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) +// await actionsContainer.expectDisabledActionAtIndex(0) + +// await myPortfolioPage.goToMyPortfolioAction() +// await myPortfolioPage.expectCollateralSwitch(collateral, true) +// }) +// }) + +// test.describe('Isolation mode', () => { +// const fork = setupFork({ blockNumber: GNO_ACTIVE_BLOCK_NUMBER, chainId: mainnet.id }) +// const isolatedAsset = 'GNO' +// const regularAsset = 'rETH' +// const initialDeposits = { +// [regularAsset]: 1, +// } +// const myPortfolioDesposits = { +// [isolatedAsset]: 100, +// } + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ...initialBalances }, +// }, +// }) + +// // Depositing regular asset at borrow page to show myPortfolio positions +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositWithoutBorrowActions(initialDeposits) +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.goToMyPortfolioAction() + +// await myPortfolioPage.expectDepositTable({ +// [regularAsset]: initialDeposits[regularAsset], +// }) + +// // Depositing isolated asset at myPortfolio +// await myPortfolioPage.clickDepositButtonAction(isolatedAsset) +// const depositDialog = new DialogPageObject(page, /Deposit/) +// await depositDialog.fillAmountAction(myPortfolioDesposits[isolatedAsset]) +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) +// await depositDialog.viewInMyPortfolioAction() + +// const collateralDialog = new CollateralDialogPageObject(page) +// // Disabling regular asset as collateral +// await myPortfolioPage.clickCollateralSwitchAction(regularAsset) +// await collateralDialog.setUseAsCollateralAction(regularAsset, 'disabled') +// await myPortfolioPage.goToMyPortfolioAction() +// await myPortfolioPage.expectCollateralSwitch(isolatedAsset, false) + +// // Entering isolation mode +// await myPortfolioPage.clickCollateralSwitchAction(isolatedAsset) +// await collateralDialog.setUseAsCollateralAction(isolatedAsset, 'enabled') +// await myPortfolioPage.goToMyPortfolioAction() + +// await myPortfolioPage.expectCollateralSwitch(isolatedAsset, true) +// }) + +// test('cannot enable asset as collateral in isolation mode', async ({ page }) => { +// const collateral = 'rETH' + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.expectCollateralSwitch(collateral, false) +// await myPortfolioPage.clickCollateralSwitchAction(collateral) + +// const collateralDialog = new CollateralDialogPageObject(page) +// await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['isolation-mode-active']) +// const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) +// await actionsContainer.expectDisabledActionAtIndex(0) + +// await myPortfolioPage.goToMyPortfolioAction() +// await myPortfolioPage.expectCollateralSwitch(collateral, false) +// }) +// }) + +// test.describe('Liquidation risk warning', () => { +// test.describe('In danger zone', () => { +// let collateralDialog: CollateralDialogPageObject +// let myPortfolioPage: MyPortfolioPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, +// }, +// }) + +// collateralDialog = new CollateralDialogPageObject(page) +// myPortfolioPage = new MyPortfolioPageObject(page) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositWithoutBorrowActions({ rETH: 2, wstETH: 10 }) +// await myPortfolioPage.goToMyPortfolioAction() + +// await myPortfolioPage.clickBorrowButtonAction('WETH') +// const borrowDialog = new DialogPageObject(page, /Borrow/) +// await borrowDialog.fillAmountAction(7) +// await borrowDialog.actionsContainer.acceptAllActionsAction(1) +// await borrowDialog.expectSuccessPage([{ asset: 'WETH', amount: 7 }], fork) +// await borrowDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectAssetToBeInBorrowTable('WETH') +// }) + +// test('shows risk warning', async () => { +// await myPortfolioPage.clickCollateralSwitchAction('rETH') +// await collateralDialog.expectLiquidationRiskWarning( +// 'Disabling this asset as collateral puts you at risk of quick liquidation. You may lose part of your remaining collateral.', +// ) +// }) + +// test('actions stay disabled until risk warning is acknowledged', async () => { +// await myPortfolioPage.clickCollateralSwitchAction('rETH') + +// await collateralDialog.actionsContainer.expectDisabledActionAtIndex(0) +// await collateralDialog.clickAcknowledgeRisk() +// await collateralDialog.actionsContainer.expectEnabledActionAtIndex(0) +// }) +// }) + +// test.describe('Not in danger zone', () => { +// let collateralDialog: CollateralDialogPageObject +// let myPortfolioPage: MyPortfolioPageObject + +// const rETHDeposit = { asset: 'rETH', amount: 1 } +// const wstETHDeposit = { asset: 'wstETH', amount: 1 } +// const daiBorrow = { asset: 'DAI', amount: 500 } + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, +// }, +// }) + +// collateralDialog = new CollateralDialogPageObject(page) +// myPortfolioPage = new MyPortfolioPageObject(page) +// }) + +// test('validation issue; risk warning is not shown', async ({ page }) => { +// // depositing single asset as collateral, so turing off will trigger validation +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositAssetsActions({ rETH: rETHDeposit.amount }, daiBorrow.amount) +// await borrowPage.expectSuccessPage([rETHDeposit], daiBorrow, fork) +// await myPortfolioPage.goToMyPortfolioAction() +// await myPortfolioPage.expectAssetToBeInBorrowTable('DAI') + +// await myPortfolioPage.clickCollateralSwitchAction('rETH') +// await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['exceeds-ltv']) +// await collateralDialog.expectLiquidationRiskWarningNotVisible() +// }) + +// test('no validation issue; risk warning is not shown', async ({ page }) => { +// // depositing multiple assets as collateral, so turning off single asset will not trigger validation +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositAssetsActions( +// { wstETH: wstETHDeposit.amount, rETH: rETHDeposit.amount }, +// daiBorrow.amount, +// ) +// await borrowPage.expectSuccessPage([wstETHDeposit, rETHDeposit], daiBorrow, fork) +// await myPortfolioPage.goToMyPortfolioAction() +// await myPortfolioPage.expectAssetToBeInBorrowTable('DAI') + +// await myPortfolioPage.clickCollateralSwitchAction('rETH') +// await collateralDialog.expectLiquidationRiskWarningNotVisible() +// }) +// }) +// }) +// }) diff --git a/packages/app/src/features/dialogs/convert-stables/ConvertStablesDialog.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/ConvertStablesDialog.test-e2e.ts index 811e68121..19eb2bed9 100644 --- a/packages/app/src/features/dialogs/convert-stables/ConvertStablesDialog.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/ConvertStablesDialog.test-e2e.ts @@ -1,75 +1,75 @@ -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { ConvertStablesDialogPageObject } from './ConvertStablesDialog.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { ConvertStablesDialogPageObject } from './ConvertStablesDialog.PageObject' -test.describe('Convert Stables Dialog', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let convertStablesDialog: ConvertStablesDialogPageObject +// test.describe('Convert Stables Dialog', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let convertStablesDialog: ConvertStablesDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - DAI: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// DAI: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) - await savingsPage.clickConvertStablesButtonAction() - convertStablesDialog = new ConvertStablesDialogPageObject(page) - }) +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickConvertStablesButtonAction() +// convertStablesDialog = new ConvertStablesDialogPageObject(page) +// }) - test('has correct selectors configuration', async ({ page }) => { - await convertStablesDialog.expectAssetInSelectorSelectedOption('DAI') - await convertStablesDialog.openAssetInSelectorAction() - await convertStablesDialog.expectSelectorOptions(['USDC', 'USDS']) - await page.keyboard.press('Escape') // closing selector +// test('has correct selectors configuration', async ({ page }) => { +// await convertStablesDialog.expectAssetInSelectorSelectedOption('DAI') +// await convertStablesDialog.openAssetInSelectorAction() +// await convertStablesDialog.expectSelectorOptions(['USDC', 'USDS']) +// await page.keyboard.press('Escape') // closing selector - await convertStablesDialog.expectAssetOutSelectorSelectedOption('USDC') - await convertStablesDialog.openAssetOutSelectorAction() - await convertStablesDialog.expectSelectorOptions(['USDS']) // no DAI option cause already selected in first selector - }) +// await convertStablesDialog.expectAssetOutSelectorSelectedOption('USDC') +// await convertStablesDialog.openAssetOutSelectorAction() +// await convertStablesDialog.expectSelectorOptions(['USDS']) // no DAI option cause already selected in first selector +// }) - test('first selector can override second selector', async () => { - await convertStablesDialog.expectAssetInSelectorSelectedOption('DAI') - await convertStablesDialog.expectAssetOutSelectorSelectedOption('USDC') +// test('first selector can override second selector', async () => { +// await convertStablesDialog.expectAssetInSelectorSelectedOption('DAI') +// await convertStablesDialog.expectAssetOutSelectorSelectedOption('USDC') - await convertStablesDialog.selectAssetInAction('USDC') // choosing already selected in second selector option +// await convertStablesDialog.selectAssetInAction('USDC') // choosing already selected in second selector option - await convertStablesDialog.expectAssetOutSelectorSelectedOption('DAI') // fist selector can override second - await convertStablesDialog.openAssetOutSelectorAction() - await convertStablesDialog.expectSelectorOptions(['USDS']) - }) +// await convertStablesDialog.expectAssetOutSelectorSelectedOption('DAI') // fist selector can override second +// await convertStablesDialog.openAssetOutSelectorAction() +// await convertStablesDialog.expectSelectorOptions(['USDS']) +// }) - test('changing value of any input updates both inputs', async () => { - await convertStablesDialog.fillAmountInAction(5000) - await convertStablesDialog.expectAssetInInputValue('5000') - await convertStablesDialog.expectAssetOutInputValue('5000') +// test('changing value of any input updates both inputs', async () => { +// await convertStablesDialog.fillAmountInAction(5000) +// await convertStablesDialog.expectAssetInInputValue('5000') +// await convertStablesDialog.expectAssetOutInputValue('5000') - await convertStablesDialog.clickMaxAmountInAction() - await convertStablesDialog.expectAssetInInputValue('10000') - await convertStablesDialog.expectAssetOutInputValue('10000') +// await convertStablesDialog.clickMaxAmountInAction() +// await convertStablesDialog.expectAssetInInputValue('10000') +// await convertStablesDialog.expectAssetOutInputValue('10000') - await convertStablesDialog.fillAmountOutAction(8_000) - await convertStablesDialog.expectAssetInInputValue('8000') - await convertStablesDialog.expectAssetOutInputValue('8000') +// await convertStablesDialog.fillAmountOutAction(8_000) +// await convertStablesDialog.expectAssetInInputValue('8000') +// await convertStablesDialog.expectAssetOutInputValue('8000') - await convertStablesDialog.clickMaxAmountOutAction() - await convertStablesDialog.expectAssetInInputValue('10000') - await convertStablesDialog.expectAssetOutInputValue('10000') - }) +// await convertStablesDialog.clickMaxAmountOutAction() +// await convertStablesDialog.expectAssetInInputValue('10000') +// await convertStablesDialog.expectAssetOutInputValue('10000') +// }) - test('displays validation error only for first input', async () => { - await convertStablesDialog.fillAmountInAction(20_000) - await convertStablesDialog.expectSingleInputError('Exceeds your balance') - }) -}) +// test('displays validation error only for first input', async () => { +// await convertStablesDialog.fillAmountInAction(20_000) +// await convertStablesDialog.expectSingleInputError('Exceeds your balance') +// }) +// }) diff --git a/packages/app/src/features/dialogs/convert-stables/e2e/base/UsdcToUsds.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/e2e/base/UsdcToUsds.test-e2e.ts index 9539dde75..e3b5f98e7 100644 --- a/packages/app/src/features/dialogs/convert-stables/e2e/base/UsdcToUsds.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/e2e/base/UsdcToUsds.test-e2e.ts @@ -1,66 +1,66 @@ -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { base } from 'viem/chains' -import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { base } from 'viem/chains' +// import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' -test.describe('Convert USDC to USDS', () => { - const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let convertStablesDialog: ConvertStablesDialogPageObject +// test.describe('Convert USDC to USDS', () => { +// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let convertStablesDialog: ConvertStablesDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDC: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// USDC: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) - await savingsPage.clickConvertStablesButtonAction() +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickConvertStablesButtonAction() - convertStablesDialog = new ConvertStablesDialogPageObject(page) - await convertStablesDialog.selectAssetInAction('USDC') - await convertStablesDialog.selectAssetOutAction('USDS') - await convertStablesDialog.fillAmountInAction(10_000) - }) +// convertStablesDialog = new ConvertStablesDialogPageObject(page) +// await convertStablesDialog.selectAssetInAction('USDC') +// await convertStablesDialog.selectAssetOutAction('USDS') +// await convertStablesDialog.fillAmountInAction(10_000) +// }) - test('uses psm convert action', async () => { - await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) - await convertStablesDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'USDC' }, - { type: 'psmConvert', inToken: 'USDC', outToken: 'USDS' }, - ]) - }) +// test('uses psm convert action', async () => { +// await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) +// await convertStablesDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'USDC' }, +// { type: 'psmConvert', inToken: 'USDC', outToken: 'USDS' }, +// ]) +// }) - test('displays transaction overview', async () => { - await convertStablesDialog.expectTransactionOverview({ - routeItems: [ - { - tokenAmount: '10,000.00 USDC', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - ], - outcome: '10,000.00 USDS', - outcomeUsd: '$10,000.00', - }) - }) +// test('displays transaction overview', async () => { +// await convertStablesDialog.expectTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '10,000.00 USDC', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// outcome: '10,000.00 USDS', +// outcomeUsd: '$10,000.00', +// }) +// }) - test('executes conversion', async () => { - await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) - await convertStablesDialog.expectSuccessPage() - await convertStablesDialog.clickBackToSavingsButton() - await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') - await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000.00') - }) -}) +// test('executes conversion', async () => { +// await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) +// await convertStablesDialog.expectSuccessPage() +// await convertStablesDialog.clickBackToSavingsButton() +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000.00') +// }) +// }) diff --git a/packages/app/src/features/dialogs/convert-stables/e2e/base/UsdsToUsdc.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/e2e/base/UsdsToUsdc.test-e2e.ts index 495fd9ba0..0591f3253 100644 --- a/packages/app/src/features/dialogs/convert-stables/e2e/base/UsdsToUsdc.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/e2e/base/UsdsToUsdc.test-e2e.ts @@ -1,66 +1,66 @@ -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { base } from 'viem/chains' -import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { base } from 'viem/chains' +// import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' -test.describe('Convert USDS to USDC', () => { - const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let convertStablesDialog: ConvertStablesDialogPageObject +// test.describe('Convert USDS to USDC', () => { +// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let convertStablesDialog: ConvertStablesDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDS: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// USDS: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) - await savingsPage.clickConvertStablesButtonAction() +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickConvertStablesButtonAction() - convertStablesDialog = new ConvertStablesDialogPageObject(page) - await convertStablesDialog.selectAssetInAction('USDS') - await convertStablesDialog.selectAssetOutAction('USDC') - await convertStablesDialog.fillAmountInAction(10_000) - }) +// convertStablesDialog = new ConvertStablesDialogPageObject(page) +// await convertStablesDialog.selectAssetInAction('USDS') +// await convertStablesDialog.selectAssetOutAction('USDC') +// await convertStablesDialog.fillAmountInAction(10_000) +// }) - test('uses psm convert action', async () => { - await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) - await convertStablesDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'USDS' }, - { type: 'psmConvert', inToken: 'USDS', outToken: 'USDC' }, - ]) - }) +// test('uses psm convert action', async () => { +// await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) +// await convertStablesDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'USDS' }, +// { type: 'psmConvert', inToken: 'USDS', outToken: 'USDC' }, +// ]) +// }) - test('displays transaction overview', async () => { - await convertStablesDialog.expectTransactionOverview({ - routeItems: [ - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '10,000.00 USDC', - tokenUsdValue: '$10,000.00', - }, - ], - outcome: '10,000.00 USDC', - outcomeUsd: '$10,000.00', - }) - }) +// test('displays transaction overview', async () => { +// await convertStablesDialog.expectTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '10,000.00 USDC', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// outcome: '10,000.00 USDC', +// outcomeUsd: '$10,000.00', +// }) +// }) - test('executes conversion', async () => { - await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) - await convertStablesDialog.expectSuccessPage() - await convertStablesDialog.clickBackToSavingsButton() - await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') - await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '10,000.00') - }) -}) +// test('executes conversion', async () => { +// await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) +// await convertStablesDialog.expectSuccessPage() +// await convertStablesDialog.clickBackToSavingsButton() +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '10,000.00') +// }) +// }) diff --git a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsdc.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsdc.test-e2e.ts index de83923ee..ec1a69f57 100644 --- a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsdc.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsdc.test-e2e.ts @@ -1,67 +1,67 @@ -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' -test.describe('Convert DAI to USDC', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let convertStablesDialog: ConvertStablesDialogPageObject +// test.describe('Convert DAI to USDC', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let convertStablesDialog: ConvertStablesDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - DAI: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// DAI: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) - await savingsPage.clickConvertStablesButtonAction() +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickConvertStablesButtonAction() - convertStablesDialog = new ConvertStablesDialogPageObject(page) - await convertStablesDialog.selectAssetInAction('DAI') - await convertStablesDialog.selectAssetOutAction('USDC') - await convertStablesDialog.fillAmountInAction(10_000) - }) +// convertStablesDialog = new ConvertStablesDialogPageObject(page) +// await convertStablesDialog.selectAssetInAction('DAI') +// await convertStablesDialog.selectAssetOutAction('USDC') +// await convertStablesDialog.fillAmountInAction(10_000) +// }) - test('uses psm convert action', async () => { - await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) - await convertStablesDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'DAI' }, - { type: 'psmConvert', inToken: 'DAI', outToken: 'USDC' }, - ]) - }) +// test('uses psm convert action', async () => { +// await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) +// await convertStablesDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'DAI' }, +// { type: 'psmConvert', inToken: 'DAI', outToken: 'USDC' }, +// ]) +// }) - test('displays transaction overview', async () => { - await convertStablesDialog.expectTransactionOverview({ - routeItems: [ - { - tokenAmount: '10,000.00 DAI', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '10,000.00 USDC', - tokenUsdValue: '$10,000.00', - }, - ], - outcome: '10,000.00 USDC', - outcomeUsd: '$10,000.00', - }) - }) +// test('displays transaction overview', async () => { +// await convertStablesDialog.expectTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '10,000.00 DAI', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '10,000.00 USDC', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// outcome: '10,000.00 USDC', +// outcomeUsd: '$10,000.00', +// }) +// }) - test('executes conversion', async () => { - await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) - await convertStablesDialog.expectSuccessPage() - await convertStablesDialog.clickBackToSavingsButton() - await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') - await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '10,000.00') - }) -}) +// test('executes conversion', async () => { +// await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) +// await convertStablesDialog.expectSuccessPage() +// await convertStablesDialog.clickBackToSavingsButton() +// await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '10,000.00') +// }) +// }) diff --git a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsds.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsds.test-e2e.ts index b64437b61..20477c59e 100644 --- a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsds.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsds.test-e2e.ts @@ -1,67 +1,67 @@ -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' -test.describe('Convert DAI to USDS', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let convertStablesDialog: ConvertStablesDialogPageObject +// test.describe('Convert DAI to USDS', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let convertStablesDialog: ConvertStablesDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - DAI: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// DAI: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) - await savingsPage.clickConvertStablesButtonAction() +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickConvertStablesButtonAction() - convertStablesDialog = new ConvertStablesDialogPageObject(page) - await convertStablesDialog.selectAssetInAction('DAI') - await convertStablesDialog.selectAssetOutAction('USDS') - await convertStablesDialog.fillAmountInAction(10_000) - }) +// convertStablesDialog = new ConvertStablesDialogPageObject(page) +// await convertStablesDialog.selectAssetInAction('DAI') +// await convertStablesDialog.selectAssetOutAction('USDS') +// await convertStablesDialog.fillAmountInAction(10_000) +// }) - test('uses upgrade action', async () => { - await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) - await convertStablesDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'DAI' }, - { type: 'upgrade', fromToken: 'DAI', toToken: 'USDS' }, - ]) - }) +// test('uses upgrade action', async () => { +// await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) +// await convertStablesDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'DAI' }, +// { type: 'upgrade', fromToken: 'DAI', toToken: 'USDS' }, +// ]) +// }) - test('displays transaction overview', async () => { - await convertStablesDialog.expectTransactionOverview({ - routeItems: [ - { - tokenAmount: '10,000.00 DAI', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - ], - outcome: '10,000.00 USDS', - outcomeUsd: '$10,000.00', - }) - }) +// test('displays transaction overview', async () => { +// await convertStablesDialog.expectTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '10,000.00 DAI', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// outcome: '10,000.00 USDS', +// outcomeUsd: '$10,000.00', +// }) +// }) - test('executes conversion', async () => { - await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) - await convertStablesDialog.expectSuccessPage() - await convertStablesDialog.clickBackToSavingsButton() - await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') - await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000.00') - }) -}) +// test('executes conversion', async () => { +// await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) +// await convertStablesDialog.expectSuccessPage() +// await convertStablesDialog.clickBackToSavingsButton() +// await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000.00') +// }) +// }) diff --git a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToDai.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToDai.test-e2e.ts index 66fcf6653..5359f831c 100644 --- a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToDai.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToDai.test-e2e.ts @@ -1,67 +1,67 @@ -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' -test.describe('Convert USDC to DAI', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let convertStablesDialog: ConvertStablesDialogPageObject +// test.describe('Convert USDC to DAI', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let convertStablesDialog: ConvertStablesDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDC: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// USDC: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) - await savingsPage.clickConvertStablesButtonAction() +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickConvertStablesButtonAction() - convertStablesDialog = new ConvertStablesDialogPageObject(page) - await convertStablesDialog.selectAssetInAction('USDC') - await convertStablesDialog.selectAssetOutAction('DAI') - await convertStablesDialog.fillAmountInAction(10_000) - }) +// convertStablesDialog = new ConvertStablesDialogPageObject(page) +// await convertStablesDialog.selectAssetInAction('USDC') +// await convertStablesDialog.selectAssetOutAction('DAI') +// await convertStablesDialog.fillAmountInAction(10_000) +// }) - test('uses psm convert action', async () => { - await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) - await convertStablesDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'USDC' }, - { type: 'psmConvert', inToken: 'USDC', outToken: 'DAI' }, - ]) - }) +// test('uses psm convert action', async () => { +// await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) +// await convertStablesDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'USDC' }, +// { type: 'psmConvert', inToken: 'USDC', outToken: 'DAI' }, +// ]) +// }) - test('displays transaction overview', async () => { - await convertStablesDialog.expectTransactionOverview({ - routeItems: [ - { - tokenAmount: '10,000.00 USDC', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '10,000.00 DAI', - tokenUsdValue: '$10,000.00', - }, - ], - outcome: '10,000.00 DAI', - outcomeUsd: '$10,000.00', - }) - }) +// test('displays transaction overview', async () => { +// await convertStablesDialog.expectTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '10,000.00 USDC', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '10,000.00 DAI', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// outcome: '10,000.00 DAI', +// outcomeUsd: '$10,000.00', +// }) +// }) - test('executes conversion', async () => { - await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) - await convertStablesDialog.expectSuccessPage() - await convertStablesDialog.clickBackToSavingsButton() - await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') - await savingsPage.expectUpgradableDaiBalance('10,000.00') - }) -}) +// test('executes conversion', async () => { +// await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) +// await convertStablesDialog.expectSuccessPage() +// await convertStablesDialog.clickBackToSavingsButton() +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') +// await savingsPage.expectUpgradableDaiBalance('10,000.00') +// }) +// }) diff --git a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToUsds.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToUsds.test-e2e.ts index 3d43aeeb5..b9906ae96 100644 --- a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToUsds.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToUsds.test-e2e.ts @@ -1,67 +1,67 @@ -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' -test.describe('Convert USDC to USDS', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let convertStablesDialog: ConvertStablesDialogPageObject +// test.describe('Convert USDC to USDS', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let convertStablesDialog: ConvertStablesDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDC: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// USDC: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) - await savingsPage.clickConvertStablesButtonAction() +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickConvertStablesButtonAction() - convertStablesDialog = new ConvertStablesDialogPageObject(page) - await convertStablesDialog.selectAssetInAction('USDC') - await convertStablesDialog.selectAssetOutAction('USDS') - await convertStablesDialog.fillAmountInAction(10_000) - }) +// convertStablesDialog = new ConvertStablesDialogPageObject(page) +// await convertStablesDialog.selectAssetInAction('USDC') +// await convertStablesDialog.selectAssetOutAction('USDS') +// await convertStablesDialog.fillAmountInAction(10_000) +// }) - test('uses psm convert action', async () => { - await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) - await convertStablesDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'USDC' }, - { type: 'psmConvert', inToken: 'USDC', outToken: 'USDS' }, - ]) - }) +// test('uses psm convert action', async () => { +// await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) +// await convertStablesDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'USDC' }, +// { type: 'psmConvert', inToken: 'USDC', outToken: 'USDS' }, +// ]) +// }) - test('displays transaction overview', async () => { - await convertStablesDialog.expectTransactionOverview({ - routeItems: [ - { - tokenAmount: '10,000.00 USDC', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - ], - outcome: '10,000.00 USDS', - outcomeUsd: '$10,000.00', - }) - }) +// test('displays transaction overview', async () => { +// await convertStablesDialog.expectTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '10,000.00 USDC', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// outcome: '10,000.00 USDS', +// outcomeUsd: '$10,000.00', +// }) +// }) - test('executes conversion', async () => { - await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) - await convertStablesDialog.expectSuccessPage() - await convertStablesDialog.clickBackToSavingsButton() - await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') - await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000.00') - }) -}) +// test('executes conversion', async () => { +// await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) +// await convertStablesDialog.expectSuccessPage() +// await convertStablesDialog.clickBackToSavingsButton() +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000.00') +// }) +// }) diff --git a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToDai.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToDai.test-e2e.ts index 1a269054c..c5c321126 100644 --- a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToDai.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToDai.test-e2e.ts @@ -1,67 +1,67 @@ -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' -test.describe('Convert USDS to DAI', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let convertStablesDialog: ConvertStablesDialogPageObject +// test.describe('Convert USDS to DAI', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let convertStablesDialog: ConvertStablesDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDS: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// USDS: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) - await savingsPage.clickConvertStablesButtonAction() +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickConvertStablesButtonAction() - convertStablesDialog = new ConvertStablesDialogPageObject(page) - await convertStablesDialog.selectAssetInAction('USDS') - await convertStablesDialog.selectAssetOutAction('DAI') - await convertStablesDialog.fillAmountInAction(10_000) - }) +// convertStablesDialog = new ConvertStablesDialogPageObject(page) +// await convertStablesDialog.selectAssetInAction('USDS') +// await convertStablesDialog.selectAssetOutAction('DAI') +// await convertStablesDialog.fillAmountInAction(10_000) +// }) - test('uses downgrade action', async () => { - await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) - await convertStablesDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'USDS' }, - { type: 'downgrade', fromToken: 'USDS', toToken: 'DAI' }, - ]) - }) +// test('uses downgrade action', async () => { +// await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) +// await convertStablesDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'USDS' }, +// { type: 'downgrade', fromToken: 'USDS', toToken: 'DAI' }, +// ]) +// }) - test('displays transaction overview', async () => { - await convertStablesDialog.expectTransactionOverview({ - routeItems: [ - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '10,000.00 DAI', - tokenUsdValue: '$10,000.00', - }, - ], - outcome: '10,000.00 DAI', - outcomeUsd: '$10,000.00', - }) - }) +// test('displays transaction overview', async () => { +// await convertStablesDialog.expectTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '10,000.00 DAI', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// outcome: '10,000.00 DAI', +// outcomeUsd: '$10,000.00', +// }) +// }) - test('executes conversion', async () => { - await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) - await convertStablesDialog.expectSuccessPage() - await convertStablesDialog.clickBackToSavingsButton() - await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') - await savingsPage.expectUpgradableDaiBalance('10,000.00') - }) -}) +// test('executes conversion', async () => { +// await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) +// await convertStablesDialog.expectSuccessPage() +// await convertStablesDialog.clickBackToSavingsButton() +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') +// await savingsPage.expectUpgradableDaiBalance('10,000.00') +// }) +// }) diff --git a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToUsdc.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToUsdc.test-e2e.ts index 7fce3b536..08a9405c6 100644 --- a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToUsdc.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToUsdc.test-e2e.ts @@ -1,67 +1,67 @@ -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' -test.describe('Convert USDS to USDC', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let convertStablesDialog: ConvertStablesDialogPageObject +// test.describe('Convert USDS to USDC', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let convertStablesDialog: ConvertStablesDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDS: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// USDS: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) - await savingsPage.clickConvertStablesButtonAction() +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickConvertStablesButtonAction() - convertStablesDialog = new ConvertStablesDialogPageObject(page) - await convertStablesDialog.selectAssetInAction('USDS') - await convertStablesDialog.selectAssetOutAction('USDC') - await convertStablesDialog.fillAmountInAction(10_000) - }) +// convertStablesDialog = new ConvertStablesDialogPageObject(page) +// await convertStablesDialog.selectAssetInAction('USDS') +// await convertStablesDialog.selectAssetOutAction('USDC') +// await convertStablesDialog.fillAmountInAction(10_000) +// }) - test('uses psm convert action', async () => { - await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) - await convertStablesDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'USDS' }, - { type: 'psmConvert', inToken: 'USDS', outToken: 'USDC' }, - ]) - }) +// test('uses psm convert action', async () => { +// await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) +// await convertStablesDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'USDS' }, +// { type: 'psmConvert', inToken: 'USDS', outToken: 'USDC' }, +// ]) +// }) - test('displays transaction overview', async () => { - await convertStablesDialog.expectTransactionOverview({ - routeItems: [ - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '10,000.00 USDC', - tokenUsdValue: '$10,000.00', - }, - ], - outcome: '10,000.00 USDC', - outcomeUsd: '$10,000.00', - }) - }) +// test('displays transaction overview', async () => { +// await convertStablesDialog.expectTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '10,000.00 USDC', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// outcome: '10,000.00 USDC', +// outcomeUsd: '$10,000.00', +// }) +// }) - test('executes conversion', async () => { - await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) - await convertStablesDialog.expectSuccessPage() - await convertStablesDialog.clickBackToSavingsButton() - await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') - await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '10,000.00') - }) -}) +// test('executes conversion', async () => { +// await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) +// await convertStablesDialog.expectSuccessPage() +// await convertStablesDialog.clickBackToSavingsButton() +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '10,000.00') +// }) +// }) diff --git a/packages/app/src/features/dialogs/deposit/DepositDialog.test-e2e.ts b/packages/app/src/features/dialogs/deposit/DepositDialog.test-e2e.ts index 15f466339..a89b2c3ab 100644 --- a/packages/app/src/features/dialogs/deposit/DepositDialog.test-e2e.ts +++ b/packages/app/src/features/dialogs/deposit/DepositDialog.test-e2e.ts @@ -1,468 +1,468 @@ -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' - -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { BorrowPageObject } from '@/pages/Borrow.PageObject' -import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' -import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { screenshot } from '@/test/e2e/utils' - -import { tenderlyRpcActions } from '@/domain/tenderly/TenderlyRpcActions' -import { DialogPageObject } from '../common/Dialog.PageObject' - -const headerRegExp = /Deposit */ - -test.describe('Deposit dialog', () => { - const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) - const initialBalances = { - wstETH: 100, - rETH: 100, - ETH: 100, - } - - test.describe('Position with deposit and borrow', () => { - const initialDeposits = { - wstETH: 1, - rETH: 2, - } - const daiToBorrow = 1500 - const expectedInitialHealthFactor = '4.03' - const expectedHealthFactor = '5.35' - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ...initialBalances }, - }, - }) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) - await borrowPage.viewInMyPortfolioAction() - - const myPortfolioPage = new MyPortfolioPageObject(page) - // @todo This waits for the refetch of the data after successful borrow transaction to happen. - // This is no ideal, probably we need to refactor expectDepositTable so it takes advantage from - // playwright's timeouts instead of parsing it's current state. Then we would be able to - // easily wait for the table to be updated. - await myPortfolioPage.expectAssetToBeInDepositTable('DAI') - }) - - test('opens dialog with selected asset', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickDepositButtonAction('rETH') - - const depositDialog = new DialogPageObject(page, headerRegExp) - await depositDialog.expectSelectedAsset('rETH') - await depositDialog.expectDialogHeader('Deposit rETH') - await depositDialog.expectHealthFactorBeforeVisible() - - await screenshot(depositDialog.getDialog(), 'deposit-dialog-default-view') - }) - - test('calculates health factor changes correctly', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickDepositButtonAction('rETH') - - const depositDialog = new DialogPageObject(page, headerRegExp) - await depositDialog.fillAmountAction(1) - - await depositDialog.expectRiskLevelBefore('Healthy') - await depositDialog.expectHealthFactorBefore(expectedInitialHealthFactor) - await depositDialog.expectRiskLevelAfter('Healthy') - await depositDialog.expectHealthFactorAfter(expectedHealthFactor) - - // @note this is needed for deterministic screenshots - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await actionsContainer.expectEnabledActionAtIndex(0) - - await screenshot(depositDialog.getDialog(), 'deposit-dialog-health-factor') - }) - - test('after deposit, health factor matches myPortfolio', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickDepositButtonAction('rETH') - - const depositDialog = new DialogPageObject(page, headerRegExp) - await depositDialog.fillAmountAction(1) - - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) - - await depositDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectHealthFactor(expectedHealthFactor) - }) - - test('has correct action plan for erc-20 with permit support', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.expectDepositTable(initialDeposits) - - await myPortfolioPage.clickDepositButtonAction('wstETH') - - const depositDialog = new DialogPageObject(page, headerRegExp) - await depositDialog.fillAmountAction(1) - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await actionsContainer.expectActions([ - { type: 'permit', asset: 'wstETH' }, - { type: 'deposit', asset: 'wstETH' }, - ]) - }) - - test('can switch to approves in action plan', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.expectDepositTable(initialDeposits) - - await myPortfolioPage.clickDepositButtonAction('wstETH') - - const depositDialog = new DialogPageObject(page, headerRegExp) - await depositDialog.fillAmountAction(1) - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - - await actionsContainer.expectEnabledActionAtIndex(0) - await actionsContainer.expectActions([ - { type: 'permit', asset: 'wstETH' }, - { type: 'deposit', asset: 'wstETH' }, - ]) - - await actionsContainer.switchPreferPermitsAction() - - await actionsContainer.expectEnabledActionAtIndex(0) - await actionsContainer.expectActions([ - { type: 'approve', asset: 'wstETH' }, - { type: 'deposit', asset: 'wstETH' }, - ]) - }) - - test('has correct action plan for erc-20 with no permit support', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.expectDepositTable(initialDeposits) - - await myPortfolioPage.clickDepositButtonAction('rETH') - - const depositDialog = new DialogPageObject(page, headerRegExp) - await depositDialog.fillAmountAction(1) - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await actionsContainer.expectActions([ - { type: 'approve', asset: 'rETH' }, - { type: 'deposit', asset: 'rETH' }, - ]) - }) - - test('can deposit erc-20 using permits', async ({ page }) => { - const deposit = { - asset: 'wstETH', - amount: 1, - } - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.expectDepositTable(initialDeposits) - - await myPortfolioPage.clickDepositButtonAction(deposit.asset) - - const depositDialog = new DialogPageObject(page, headerRegExp) - await depositDialog.fillAmountAction(deposit.amount) - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) - await depositDialog.expectSuccessPage([deposit], fork) - - await screenshot(depositDialog.getDialog(), 'deposit-dialog-wsteth-success') - - await depositDialog.viewInMyPortfolioAction() - - await myPortfolioPage.expectDepositTable({ - ...initialDeposits, - wstETH: initialDeposits.wstETH + 1, - }) - }) - - test('can deposit erc-20 using approves', async ({ page }) => { - const deposit = { - asset: 'rETH', - amount: 1, - } - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.expectDepositTable(initialDeposits) - - await myPortfolioPage.clickDepositButtonAction(deposit.asset) - - const depositDialog = new DialogPageObject(page, headerRegExp) - await depositDialog.fillAmountAction(deposit.amount) - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) - await depositDialog.expectSuccessPage([deposit], fork) - - await screenshot(depositDialog.getDialog(), 'deposit-dialog-reth-success') - - await depositDialog.viewInMyPortfolioAction() - - await myPortfolioPage.expectDepositTable({ - ...initialDeposits, - rETH: initialDeposits.rETH + 1, - }) - }) - - test('has correct action plan for native asset', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.expectDepositTable(initialDeposits) - - await myPortfolioPage.clickDepositButtonAction('WETH') - - const depositDialog = new DialogPageObject(page, headerRegExp) - await depositDialog.selectAssetAction('ETH') - await depositDialog.fillAmountAction(1) - await depositDialog.expectHealthFactorVisible() - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await actionsContainer.expectActions([{ type: 'deposit', asset: 'ETH' }]) - - await screenshot(depositDialog.getDialog(), 'deposit-dialog-eth-action-plan') - }) - - test('can deposit native asset', async ({ page }) => { - const deposit = { - asset: 'WETH', - amount: 1, - } - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.expectDepositTable(initialDeposits) - - await myPortfolioPage.clickDepositButtonAction(deposit.asset) - - const depositDialog = new DialogPageObject(page, headerRegExp) - await depositDialog.selectAssetAction('ETH') - await depositDialog.fillAmountAction(deposit.amount) - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(1) - await depositDialog.expectSuccessPage( - [ - { - asset: 'ETH', - amount: deposit.amount, - }, - ], - fork, - ) - await screenshot(depositDialog.getDialog(), 'deposit-dialog-eth-success') - - await depositDialog.viewInMyPortfolioAction() - - await myPortfolioPage.expectDepositTable({ - ...initialDeposits, - // @todo Figure out how WETH and ETH conversion should work - WETH: 1, - }) - }) - - test("can't deposit more than wallet balance", async ({ page }) => { - const depositAsset = 'rETH' - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickDepositButtonAction(depositAsset) - - const depositDialog = new DialogPageObject(page, headerRegExp) - await depositDialog.fillAmountAction(initialBalances[depositAsset] - initialDeposits[depositAsset] + 1) - - await depositDialog.expectAssetInputError('Exceeds your balance') - await depositDialog.expectHealthFactorBeforeVisible() - await screenshot(depositDialog.getDialog(), 'deposit-dialog-exceeds-balance') - }) - - test('requires new approve when the input value is increased', async ({ page }) => { - const depositAsset = 'rETH' - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickDepositButtonAction(depositAsset) - - const depositDialog = new DialogPageObject(page, headerRegExp) - await depositDialog.fillAmountAction(1) - - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - - await actionsContainer.acceptActionAtIndex(0) - await actionsContainer.expectEnabledActionAtIndex(1, { type: 'deposit', asset: depositAsset }) - - await depositDialog.fillAmountAction(2) - - await actionsContainer.expectEnabledActionAtIndex(0, { type: 'approve', asset: depositAsset }) - }) - - test('requires new permit when the input value is changed', async ({ page }) => { - const depositAsset = 'wstETH' - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickDepositButtonAction(depositAsset) - - const depositDialog = new DialogPageObject(page, headerRegExp) - await depositDialog.fillAmountAction(2) - - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - - await actionsContainer.acceptActionAtIndex(0) - await actionsContainer.expectEnabledActionAtIndex(1, { type: 'deposit', asset: depositAsset }) - - await depositDialog.fillAmountAction(1) - - await actionsContainer.expectEnabledActionAtIndex(0, { type: 'permit', asset: depositAsset }) - }) - }) - - test.describe('Position with only deposit', () => { - const initialDeposits = { - wstETH: 10, - rETH: 2, - } - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ...initialBalances }, - }, - }) - - const borrowPage = new BorrowPageObject(page) - // to simulate a position with only deposits, we go through the easy borrow flow - // but interrupt it before the borrow action, going directly to the myPortfolio - // this way we have deposit transactions executed, but no borrow transaction - // resulting in a position with only deposits - await borrowPage.fillDepositAssetAction(0, 'wstETH', initialDeposits.wstETH) - await borrowPage.addNewDepositAssetAction() - await borrowPage.fillBorrowAssetAction(1) // doesn't matter, we're not borrowing anything - await borrowPage.fillDepositAssetAction(1, 'rETH', initialDeposits.rETH) - await borrowPage.submitAction() - - const actionsContainer = new ActionsPageObject(page) - for (let i = 0; i < 4; i++) { - await actionsContainer.acceptActionAtIndex(i) - } - await actionsContainer.expectEnabledActionAtIndex(4) - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.goToMyPortfolioAction() - }) - - test('does not display health factor', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickDepositButtonAction('rETH') - - const depositDialog = new DialogPageObject(page, headerRegExp) - await depositDialog.fillAmountAction(1) - - await depositDialog.expectHealthFactorNotVisible() - - // @note this is needed for deterministic screenshots - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await actionsContainer.expectEnabledActionAtIndex(0) - - await screenshot(depositDialog.getDialog(), 'deposit-dialog-only-deposit-health-factor') - }) - }) - - test.describe('No position', () => { - const fork = setupFork({ blockNumber: 19588510n, chainId: mainnet.id }) // block number with WBTC supply close to cap - - test('can deposit up to max cap', async ({ page }) => { - const initialBalances = { - ETH: 1, - WBTC: 1000, - } - - await setup(page, fork, { - initialPage: 'myPortfolio', - account: { - type: 'connected-random', - assetBalances: { ...initialBalances }, - }, - }) - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickDepositButtonAction('WBTC') - - const depositDialog = new DialogPageObject(page, headerRegExp) - await depositDialog.clickMaxAmountAction() - await tenderlyRpcActions.evmIncreaseTime(fork.forkUrl, 5 * 60) - - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) - await depositDialog.expectSuccessPage( - [ - { - asset: 'WBTC', - amount: 507.527307, - }, - ], - fork, - { - WBTC: 34_087_363.63, - }, - ) - - await depositDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectDepositTable({ - WBTC: 507.527307, - }) - }) - - test('can deposit asset that cannot be used as collateral', async ({ page }) => { - const initialBalances = { - ETH: 1, - USDT: 10000, - } - - await setup(page, fork, { - initialPage: 'myPortfolio', - account: { - type: 'connected-random', - assetBalances: { ...initialBalances }, - }, - }) - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickDepositButtonAction('USDT') - - const depositDialog = new DialogPageObject(page, headerRegExp) - await depositDialog.fillAmountAction(initialBalances.USDT) - - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) - await depositDialog.expectSuccessPage( - [ - { - asset: 'USDT', - amount: initialBalances.USDT, - }, - ], - fork, - ) - - await depositDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectDepositTable({ - USDT: initialBalances.USDT, - }) - }) - - test('retains some native asset when depositing max', async ({ page }) => { - await setup(page, fork, { - initialPage: 'myPortfolio', - account: { - type: 'connected-random', - assetBalances: { ETH: 1 }, - }, - }) - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickDepositButtonAction('WETH') - const depositDialog = new DialogPageObject(page, headerRegExp) - await depositDialog.selectAssetAction('ETH') - await depositDialog.clickMaxAmountAction() - - await depositDialog.expectInputValue('0.999') - await depositDialog.expectMaxButtonDisabled() - await depositDialog.actionsContainer.expectEnabledActionAtIndex(0) - await depositDialog.actionsContainer.expectActions([{ type: 'deposit', asset: 'ETH' }]) - }) - }) -}) +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' + +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { BorrowPageObject } from '@/pages/Borrow.PageObject' +// import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { screenshot } from '@/test/e2e/utils' + +// import { tenderlyRpcActions } from '@/domain/tenderly/TenderlyRpcActions' +// import { DialogPageObject } from '../common/Dialog.PageObject' + +// const headerRegExp = /Deposit */ + +// test.describe('Deposit dialog', () => { +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) +// const initialBalances = { +// wstETH: 100, +// rETH: 100, +// ETH: 100, +// } + +// test.describe('Position with deposit and borrow', () => { +// const initialDeposits = { +// wstETH: 1, +// rETH: 2, +// } +// const daiToBorrow = 1500 +// const expectedInitialHealthFactor = '4.03' +// const expectedHealthFactor = '5.35' + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ...initialBalances }, +// }, +// }) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) +// await borrowPage.viewInMyPortfolioAction() + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// // @todo This waits for the refetch of the data after successful borrow transaction to happen. +// // This is no ideal, probably we need to refactor expectDepositTable so it takes advantage from +// // playwright's timeouts instead of parsing it's current state. Then we would be able to +// // easily wait for the table to be updated. +// await myPortfolioPage.expectAssetToBeInDepositTable('DAI') +// }) + +// test('opens dialog with selected asset', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickDepositButtonAction('rETH') + +// const depositDialog = new DialogPageObject(page, headerRegExp) +// await depositDialog.expectSelectedAsset('rETH') +// await depositDialog.expectDialogHeader('Deposit rETH') +// await depositDialog.expectHealthFactorBeforeVisible() + +// await screenshot(depositDialog.getDialog(), 'deposit-dialog-default-view') +// }) + +// test('calculates health factor changes correctly', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickDepositButtonAction('rETH') + +// const depositDialog = new DialogPageObject(page, headerRegExp) +// await depositDialog.fillAmountAction(1) + +// await depositDialog.expectRiskLevelBefore('Healthy') +// await depositDialog.expectHealthFactorBefore(expectedInitialHealthFactor) +// await depositDialog.expectRiskLevelAfter('Healthy') +// await depositDialog.expectHealthFactorAfter(expectedHealthFactor) + +// // @note this is needed for deterministic screenshots +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await actionsContainer.expectEnabledActionAtIndex(0) + +// await screenshot(depositDialog.getDialog(), 'deposit-dialog-health-factor') +// }) + +// test('after deposit, health factor matches myPortfolio', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickDepositButtonAction('rETH') + +// const depositDialog = new DialogPageObject(page, headerRegExp) +// await depositDialog.fillAmountAction(1) + +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) + +// await depositDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectHealthFactor(expectedHealthFactor) +// }) + +// test('has correct action plan for erc-20 with permit support', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.expectDepositTable(initialDeposits) + +// await myPortfolioPage.clickDepositButtonAction('wstETH') + +// const depositDialog = new DialogPageObject(page, headerRegExp) +// await depositDialog.fillAmountAction(1) +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await actionsContainer.expectActions([ +// { type: 'permit', asset: 'wstETH' }, +// { type: 'deposit', asset: 'wstETH' }, +// ]) +// }) + +// test('can switch to approves in action plan', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.expectDepositTable(initialDeposits) + +// await myPortfolioPage.clickDepositButtonAction('wstETH') + +// const depositDialog = new DialogPageObject(page, headerRegExp) +// await depositDialog.fillAmountAction(1) +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) + +// await actionsContainer.expectEnabledActionAtIndex(0) +// await actionsContainer.expectActions([ +// { type: 'permit', asset: 'wstETH' }, +// { type: 'deposit', asset: 'wstETH' }, +// ]) + +// await actionsContainer.switchPreferPermitsAction() + +// await actionsContainer.expectEnabledActionAtIndex(0) +// await actionsContainer.expectActions([ +// { type: 'approve', asset: 'wstETH' }, +// { type: 'deposit', asset: 'wstETH' }, +// ]) +// }) + +// test('has correct action plan for erc-20 with no permit support', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.expectDepositTable(initialDeposits) + +// await myPortfolioPage.clickDepositButtonAction('rETH') + +// const depositDialog = new DialogPageObject(page, headerRegExp) +// await depositDialog.fillAmountAction(1) +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await actionsContainer.expectActions([ +// { type: 'approve', asset: 'rETH' }, +// { type: 'deposit', asset: 'rETH' }, +// ]) +// }) + +// test('can deposit erc-20 using permits', async ({ page }) => { +// const deposit = { +// asset: 'wstETH', +// amount: 1, +// } + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.expectDepositTable(initialDeposits) + +// await myPortfolioPage.clickDepositButtonAction(deposit.asset) + +// const depositDialog = new DialogPageObject(page, headerRegExp) +// await depositDialog.fillAmountAction(deposit.amount) +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) +// await depositDialog.expectSuccessPage([deposit], fork) + +// await screenshot(depositDialog.getDialog(), 'deposit-dialog-wsteth-success') + +// await depositDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.expectDepositTable({ +// ...initialDeposits, +// wstETH: initialDeposits.wstETH + 1, +// }) +// }) + +// test('can deposit erc-20 using approves', async ({ page }) => { +// const deposit = { +// asset: 'rETH', +// amount: 1, +// } + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.expectDepositTable(initialDeposits) + +// await myPortfolioPage.clickDepositButtonAction(deposit.asset) + +// const depositDialog = new DialogPageObject(page, headerRegExp) +// await depositDialog.fillAmountAction(deposit.amount) +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) +// await depositDialog.expectSuccessPage([deposit], fork) + +// await screenshot(depositDialog.getDialog(), 'deposit-dialog-reth-success') + +// await depositDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.expectDepositTable({ +// ...initialDeposits, +// rETH: initialDeposits.rETH + 1, +// }) +// }) + +// test('has correct action plan for native asset', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.expectDepositTable(initialDeposits) + +// await myPortfolioPage.clickDepositButtonAction('WETH') + +// const depositDialog = new DialogPageObject(page, headerRegExp) +// await depositDialog.selectAssetAction('ETH') +// await depositDialog.fillAmountAction(1) +// await depositDialog.expectHealthFactorVisible() +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await actionsContainer.expectActions([{ type: 'deposit', asset: 'ETH' }]) + +// await screenshot(depositDialog.getDialog(), 'deposit-dialog-eth-action-plan') +// }) + +// test('can deposit native asset', async ({ page }) => { +// const deposit = { +// asset: 'WETH', +// amount: 1, +// } + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.expectDepositTable(initialDeposits) + +// await myPortfolioPage.clickDepositButtonAction(deposit.asset) + +// const depositDialog = new DialogPageObject(page, headerRegExp) +// await depositDialog.selectAssetAction('ETH') +// await depositDialog.fillAmountAction(deposit.amount) +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(1) +// await depositDialog.expectSuccessPage( +// [ +// { +// asset: 'ETH', +// amount: deposit.amount, +// }, +// ], +// fork, +// ) +// await screenshot(depositDialog.getDialog(), 'deposit-dialog-eth-success') + +// await depositDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.expectDepositTable({ +// ...initialDeposits, +// // @todo Figure out how WETH and ETH conversion should work +// WETH: 1, +// }) +// }) + +// test("can't deposit more than wallet balance", async ({ page }) => { +// const depositAsset = 'rETH' +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickDepositButtonAction(depositAsset) + +// const depositDialog = new DialogPageObject(page, headerRegExp) +// await depositDialog.fillAmountAction(initialBalances[depositAsset] - initialDeposits[depositAsset] + 1) + +// await depositDialog.expectAssetInputError('Exceeds your balance') +// await depositDialog.expectHealthFactorBeforeVisible() +// await screenshot(depositDialog.getDialog(), 'deposit-dialog-exceeds-balance') +// }) + +// test('requires new approve when the input value is increased', async ({ page }) => { +// const depositAsset = 'rETH' +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickDepositButtonAction(depositAsset) + +// const depositDialog = new DialogPageObject(page, headerRegExp) +// await depositDialog.fillAmountAction(1) + +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) + +// await actionsContainer.acceptActionAtIndex(0) +// await actionsContainer.expectEnabledActionAtIndex(1, { type: 'deposit', asset: depositAsset }) + +// await depositDialog.fillAmountAction(2) + +// await actionsContainer.expectEnabledActionAtIndex(0, { type: 'approve', asset: depositAsset }) +// }) + +// test('requires new permit when the input value is changed', async ({ page }) => { +// const depositAsset = 'wstETH' +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickDepositButtonAction(depositAsset) + +// const depositDialog = new DialogPageObject(page, headerRegExp) +// await depositDialog.fillAmountAction(2) + +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) + +// await actionsContainer.acceptActionAtIndex(0) +// await actionsContainer.expectEnabledActionAtIndex(1, { type: 'deposit', asset: depositAsset }) + +// await depositDialog.fillAmountAction(1) + +// await actionsContainer.expectEnabledActionAtIndex(0, { type: 'permit', asset: depositAsset }) +// }) +// }) + +// test.describe('Position with only deposit', () => { +// const initialDeposits = { +// wstETH: 10, +// rETH: 2, +// } + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ...initialBalances }, +// }, +// }) + +// const borrowPage = new BorrowPageObject(page) +// // to simulate a position with only deposits, we go through the easy borrow flow +// // but interrupt it before the borrow action, going directly to the myPortfolio +// // this way we have deposit transactions executed, but no borrow transaction +// // resulting in a position with only deposits +// await borrowPage.fillDepositAssetAction(0, 'wstETH', initialDeposits.wstETH) +// await borrowPage.addNewDepositAssetAction() +// await borrowPage.fillBorrowAssetAction(1) // doesn't matter, we're not borrowing anything +// await borrowPage.fillDepositAssetAction(1, 'rETH', initialDeposits.rETH) +// await borrowPage.submitAction() + +// const actionsContainer = new ActionsPageObject(page) +// for (let i = 0; i < 4; i++) { +// await actionsContainer.acceptActionAtIndex(i) +// } +// await actionsContainer.expectEnabledActionAtIndex(4) + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.goToMyPortfolioAction() +// }) + +// test('does not display health factor', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickDepositButtonAction('rETH') + +// const depositDialog = new DialogPageObject(page, headerRegExp) +// await depositDialog.fillAmountAction(1) + +// await depositDialog.expectHealthFactorNotVisible() + +// // @note this is needed for deterministic screenshots +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await actionsContainer.expectEnabledActionAtIndex(0) + +// await screenshot(depositDialog.getDialog(), 'deposit-dialog-only-deposit-health-factor') +// }) +// }) + +// test.describe('No position', () => { +// const fork = setupFork({ blockNumber: 19588510n, chainId: mainnet.id }) // block number with WBTC supply close to cap + +// test('can deposit up to max cap', async ({ page }) => { +// const initialBalances = { +// ETH: 1, +// WBTC: 1000, +// } + +// await setup(page, fork, { +// initialPage: 'myPortfolio', +// account: { +// type: 'connected-random', +// assetBalances: { ...initialBalances }, +// }, +// }) + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickDepositButtonAction('WBTC') + +// const depositDialog = new DialogPageObject(page, headerRegExp) +// await depositDialog.clickMaxAmountAction() +// await tenderlyRpcActions.evmIncreaseTime(fork.forkUrl, 5 * 60) + +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) +// await depositDialog.expectSuccessPage( +// [ +// { +// asset: 'WBTC', +// amount: 507.527307, +// }, +// ], +// fork, +// { +// WBTC: 34_087_363.63, +// }, +// ) + +// await depositDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectDepositTable({ +// WBTC: 507.527307, +// }) +// }) + +// test('can deposit asset that cannot be used as collateral', async ({ page }) => { +// const initialBalances = { +// ETH: 1, +// USDT: 10000, +// } + +// await setup(page, fork, { +// initialPage: 'myPortfolio', +// account: { +// type: 'connected-random', +// assetBalances: { ...initialBalances }, +// }, +// }) + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickDepositButtonAction('USDT') + +// const depositDialog = new DialogPageObject(page, headerRegExp) +// await depositDialog.fillAmountAction(initialBalances.USDT) + +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) +// await depositDialog.expectSuccessPage( +// [ +// { +// asset: 'USDT', +// amount: initialBalances.USDT, +// }, +// ], +// fork, +// ) + +// await depositDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectDepositTable({ +// USDT: initialBalances.USDT, +// }) +// }) + +// test('retains some native asset when depositing max', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'myPortfolio', +// account: { +// type: 'connected-random', +// assetBalances: { ETH: 1 }, +// }, +// }) + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickDepositButtonAction('WETH') +// const depositDialog = new DialogPageObject(page, headerRegExp) +// await depositDialog.selectAssetAction('ETH') +// await depositDialog.clickMaxAmountAction() + +// await depositDialog.expectInputValue('0.999') +// await depositDialog.expectMaxButtonDisabled() +// await depositDialog.actionsContainer.expectEnabledActionAtIndex(0) +// await depositDialog.actionsContainer.expectActions([{ type: 'deposit', asset: 'ETH' }]) +// }) +// }) +// }) diff --git a/packages/app/src/features/dialogs/e-mode/EModeDialog.test-e2e.ts b/packages/app/src/features/dialogs/e-mode/EModeDialog.test-e2e.ts index 224edd3ff..b9520ddfc 100644 --- a/packages/app/src/features/dialogs/e-mode/EModeDialog.test-e2e.ts +++ b/packages/app/src/features/dialogs/e-mode/EModeDialog.test-e2e.ts @@ -1,532 +1,532 @@ -import { setUserEModeValidationIssueToMessage } from '@/domain/market-validators/validateSetUserEMode' -import { BorrowPageObject } from '@/pages/Borrow.PageObject' -import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' -import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { DialogPageObject } from '../common/Dialog.PageObject' -import { EModeDialogPageObject } from './EModeDialog.PageObject' - -test.describe('E-Mode dialog', () => { - const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - - test.describe('ETH correlated assets borrowed', () => { - let eModeDialog: EModeDialogPageObject - let borrowDialog: DialogPageObject - let myPortfolioPage: MyPortfolioPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ETH: 1, wstETH: 100 }, - }, - }) - - eModeDialog = new EModeDialogPageObject(page) - borrowDialog = new DialogPageObject(page, /Borrow/) - myPortfolioPage = new MyPortfolioPageObject(page) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositWithoutBorrowActions({ wstETH: 20 }) - await myPortfolioPage.goToMyPortfolioAction() - - await myPortfolioPage.clickBorrowButtonAction('rETH') - await borrowDialog.fillAmountAction(5) - await borrowDialog.actionsContainer.acceptAllActionsAction(1) - await borrowDialog.viewInMyPortfolioAction() - await myPortfolioPage.clickBorrowButtonAction('WETH') - await borrowDialog.fillAmountAction(5) - await borrowDialog.actionsContainer.acceptAllActionsAction(1) - await borrowDialog.viewInMyPortfolioAction() - }) - - test('can switch from no e-mode to eth correlated', async () => { - await myPortfolioPage.clickEModeButtonAction() - await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') - await eModeDialog.expectEModeCategoryTileStatus('ETH Correlated', 'Inactive') - await eModeDialog.expectEModeTransactionOverview({ - variant: 'e-mode-no-change', - availableAssets: { - assets: 'All assets', - }, - hf: '1.75', - maxLtv: '68.50%', - }) - - await eModeDialog.clickEModeCategoryTileAction('ETH Correlated') - await eModeDialog.actionsContainer.expectActions([{ type: 'setUserEMode', eModeCategoryId: 1 }]) - await eModeDialog.expectEModeTransactionOverview({ - variant: 'e-mode-change', - availableAssets: { - category: 'ETH Correlated', - assets: 'WETH, wstETH, rETH', - }, - hf: { - before: '1.75', - after: '2.05', - }, - maxLtv: { - before: '68.50%', - after: '90.00%', - }, - }) - - await eModeDialog.actionsContainer.acceptAllActionsAction(1) - await eModeDialog.expectEModeSuccessPage('ETH Correlated') - await eModeDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectEModeBadgeText('ETH Correlated') - }) - - test('cannot switch from no e-mode to stablecoins', async () => { - await myPortfolioPage.clickEModeButtonAction() - await eModeDialog.clickEModeCategoryTileAction('Stablecoins') - await eModeDialog.expectAlertMessage( - setUserEModeValidationIssueToMessage['borrowed-assets-emode-category-mismatch'], - ) - await eModeDialog.actionsContainer.expectDisabledActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) - }) - - test('can enter eth correlated e-mode and switch back to no e-mode', async () => { - await myPortfolioPage.clickEModeButtonAction() - await eModeDialog.setEModeAction('ETH Correlated') - await myPortfolioPage.expectEModeBadgeText('ETH Correlated') - await myPortfolioPage.clickEModeButtonAction() - - await eModeDialog.expectEModeCategoryTileStatus('ETH Correlated', 'Active') - await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Inactive') - await eModeDialog.clickEModeCategoryTileAction('No E-Mode') - - await eModeDialog.expectEModeTransactionOverview({ - variant: 'e-mode-change', - availableAssets: { - assets: 'All assets', - }, - hf: { - before: '2.05', - after: '1.75', - }, - maxLtv: { - before: '90.00%', - after: '68.50%', - }, - }) - await eModeDialog.actionsContainer.acceptAllActionsAction(1) - await eModeDialog.expectEModeSuccessPage('No E-Mode') - await eModeDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectEModeBadgeText('E-Mode Off') - }) - - test('cannot switch back to no e-mode if hf below 1', async () => { - await myPortfolioPage.clickEModeButtonAction() - await eModeDialog.setEModeAction('ETH Correlated') - await myPortfolioPage.expectEModeBadgeText('ETH Correlated') - - await myPortfolioPage.clickBorrowButtonAction('WETH') - await borrowDialog.fillAmountAction(10) - await eModeDialog.clickAcknowledgeRisk() - await borrowDialog.actionsContainer.acceptAllActionsAction(1) - await borrowDialog.viewInMyPortfolioAction() - - await myPortfolioPage.clickEModeButtonAction() - await eModeDialog.clickEModeCategoryTileAction('No E-Mode') - await eModeDialog.expectAlertMessage(setUserEModeValidationIssueToMessage['exceeds-ltv']) - await eModeDialog.actionsContainer.expectDisabledActions([{ type: 'setUserEMode', eModeCategoryId: 0 }]) - }) - }) - - test.describe('Stablecoins borrowed', () => { - let eModeDialog: EModeDialogPageObject - let borrowDialog: DialogPageObject - let myPortfolioPage: MyPortfolioPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ETH: 1, wstETH: 100 }, - }, - }) - - eModeDialog = new EModeDialogPageObject(page) - borrowDialog = new DialogPageObject(page, /Borrow/) - myPortfolioPage = new MyPortfolioPageObject(page) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositWithoutBorrowActions({ wstETH: 1 }) - await myPortfolioPage.goToMyPortfolioAction() - - await myPortfolioPage.clickBorrowButtonAction('USDC') - await borrowDialog.fillAmountAction(1000) - await borrowDialog.actionsContainer.acceptAllActionsAction(1) - await borrowDialog.viewInMyPortfolioAction() - }) - - test('can switch from no e-mode to stablecoins', async () => { - await myPortfolioPage.clickEModeButtonAction() - await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') - await eModeDialog.expectEModeCategoryTileStatus('Stablecoins', 'Inactive') - await eModeDialog.expectEModeTransactionOverview({ - variant: 'e-mode-no-change', - availableAssets: { - assets: 'All assets', - }, - hf: '2.08', - maxLtv: '68.50%', - }) - - await eModeDialog.clickEModeCategoryTileAction('Stablecoins') - await eModeDialog.actionsContainer.expectActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) - await eModeDialog.expectEModeTransactionOverview({ - variant: 'e-mode-change', - availableAssets: { - category: 'Stablecoins', - assets: 'sDAI, USDC, USDT', - }, - hf: { - before: '2.08', - after: '2.08', - }, - maxLtv: { - before: '68.50%', - after: '68.50%', - }, - }) - - await eModeDialog.actionsContainer.acceptAllActionsAction(1) - await eModeDialog.expectEModeSuccessPage('Stablecoins') - await eModeDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectEModeBadgeText('Stablecoins') - }) - - test('cannot switch from no e-mode to eth correlated', async () => { - await myPortfolioPage.clickEModeButtonAction() - await eModeDialog.clickEModeCategoryTileAction('ETH Correlated') - await eModeDialog.expectAlertMessage( - setUserEModeValidationIssueToMessage['borrowed-assets-emode-category-mismatch'], - ) - await eModeDialog.actionsContainer.expectDisabledActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) - }) - - test('can enter stablecoins e-mode and switch back to no e-mode', async () => { - await myPortfolioPage.clickEModeButtonAction() - await eModeDialog.setEModeAction('Stablecoins') - await myPortfolioPage.expectEModeBadgeText('Stablecoins') - await myPortfolioPage.clickEModeButtonAction() - - await eModeDialog.expectEModeCategoryTileStatus('Stablecoins', 'Active') - await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Inactive') - await eModeDialog.clickEModeCategoryTileAction('No E-Mode') - - await eModeDialog.expectEModeTransactionOverview({ - variant: 'e-mode-change', - availableAssets: { - assets: 'All assets', - }, - hf: { - before: '2.08', - after: '2.08', - }, - maxLtv: { - before: '68.50%', - after: '68.50%', - }, - }) - await eModeDialog.actionsContainer.acceptAllActionsAction(1) - await eModeDialog.expectEModeSuccessPage('No E-Mode') - await eModeDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectEModeBadgeText('E-Mode Off') - }) - }) - - test.describe('Assets from multiple categories borrowed', () => { - let eModeDialog: EModeDialogPageObject - let borrowDialog: DialogPageObject - let myPortfolioPage: MyPortfolioPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ETH: 1, wstETH: 100 }, - }, - }) - - eModeDialog = new EModeDialogPageObject(page) - borrowDialog = new DialogPageObject(page, /Borrow/) - myPortfolioPage = new MyPortfolioPageObject(page) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositWithoutBorrowActions({ wstETH: 10 }) - await myPortfolioPage.goToMyPortfolioAction() - - await myPortfolioPage.clickBorrowButtonAction('rETH') - await borrowDialog.fillAmountAction(1) - await borrowDialog.actionsContainer.acceptAllActionsAction(1) - await borrowDialog.viewInMyPortfolioAction() - - await myPortfolioPage.clickBorrowButtonAction('WBTC') - await borrowDialog.fillAmountAction(0.1) - await borrowDialog.actionsContainer.acceptAllActionsAction(1) - await borrowDialog.viewInMyPortfolioAction() - }) - - test('cannot switch from no e-mode to stablecoins', async () => { - await myPortfolioPage.clickEModeButtonAction() - await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') - await eModeDialog.expectEModeCategoryTileStatus('Stablecoins', 'Inactive') - - await eModeDialog.clickEModeCategoryTileAction('Stablecoins') - - await eModeDialog.expectAlertMessage( - setUserEModeValidationIssueToMessage['borrowed-assets-emode-category-mismatch'], - ) - await eModeDialog.expectEModeTransactionOverview({ - variant: 'e-mode-change', - availableAssets: { - category: 'Stablecoins', - assets: 'sDAI, USDC, USDT', - }, - hf: { - before: '3.12', - after: '3.12', - }, - maxLtv: { - before: '68.50%', - after: '68.50%', - }, - }) - await eModeDialog.actionsContainer.expectDisabledActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) - }) - - test('cannot switch from no e-mode to eth correlated', async () => { - await myPortfolioPage.clickEModeButtonAction() - await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') - await eModeDialog.expectEModeCategoryTileStatus('ETH Correlated', 'Inactive') - - await eModeDialog.clickEModeCategoryTileAction('ETH Correlated') - await eModeDialog.expectEModeTransactionOverview({ - variant: 'e-mode-change', - availableAssets: { - category: 'ETH Correlated', - assets: 'WETH, wstETH, rETH', - }, - hf: { - before: '3.12', - after: '3.65', - }, - maxLtv: { - before: '68.50%', - after: '90.00%', - }, - }) - await eModeDialog.expectAlertMessage( - setUserEModeValidationIssueToMessage['borrowed-assets-emode-category-mismatch'], - ) - await eModeDialog.actionsContainer.expectDisabledActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) - }) - }) - - test.describe('Nothing borrowed', () => { - let eModeDialog: EModeDialogPageObject - let myPortfolioPage: MyPortfolioPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ETH: 1, wstETH: 100 }, - }, - }) - - eModeDialog = new EModeDialogPageObject(page) - myPortfolioPage = new MyPortfolioPageObject(page) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositWithoutBorrowActions({ wstETH: 20 }) - await myPortfolioPage.goToMyPortfolioAction() - }) - - test('can switch from no e-mode to eth correleated', async () => { - await myPortfolioPage.clickEModeButtonAction() - await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') - await eModeDialog.expectEModeCategoryTileStatus('ETH Correlated', 'Inactive') - - await eModeDialog.clickEModeCategoryTileAction('ETH Correlated') - await eModeDialog.actionsContainer.expectActions([{ type: 'setUserEMode', eModeCategoryId: 1 }]) - await eModeDialog.expectEModeTransactionOverview({ - variant: 'no-borrow', - availableAssets: { - category: 'ETH Correlated', - assets: 'WETH, wstETH, rETH', - }, - maxLtv: { - before: '68.50%', - after: '90.00%', - }, - }) - - await eModeDialog.actionsContainer.acceptAllActionsAction(1) - await eModeDialog.expectEModeSuccessPage('ETH Correlated') - await eModeDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectEModeBadgeText('ETH Correlated') - }) - - test('can switch from no e-mode to stablecoins', async () => { - await myPortfolioPage.clickEModeButtonAction() - await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') - - await eModeDialog.expectEModeCategoryTileStatus('Stablecoins', 'Inactive') - await eModeDialog.clickEModeCategoryTileAction('Stablecoins') - await eModeDialog.actionsContainer.expectActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) - await eModeDialog.expectEModeTransactionOverview({ - variant: 'no-borrow', - availableAssets: { - category: 'Stablecoins', - assets: 'sDAI, USDC, USDT', - }, - maxLtv: { - before: '68.50%', - after: '68.50%', - }, - }) - - await eModeDialog.actionsContainer.acceptAllActionsAction(1) - await eModeDialog.expectEModeSuccessPage('Stablecoins') - await eModeDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectEModeBadgeText('Stablecoins') - }) - - test('can enter e-mode and switch back to no e-mode', async () => { - await myPortfolioPage.clickEModeButtonAction() - await eModeDialog.setEModeAction('Stablecoins') - await myPortfolioPage.expectEModeBadgeText('Stablecoins') - await myPortfolioPage.clickEModeButtonAction() - - await eModeDialog.expectEModeCategoryTileStatus('Stablecoins', 'Active') - await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Inactive') - await eModeDialog.clickEModeCategoryTileAction('No E-Mode') - - await eModeDialog.expectEModeTransactionOverview({ - variant: 'no-borrow', - availableAssets: { - assets: 'All assets', - }, - maxLtv: { - before: '68.50%', - after: '68.50%', - }, - }) - await eModeDialog.actionsContainer.acceptAllActionsAction(1) - await eModeDialog.expectEModeSuccessPage('No E-Mode') - await eModeDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectEModeBadgeText('E-Mode Off') - }) - }) - - test.describe('Liquidation risk warning', () => { - test.describe('In danger zone', () => { - let eModeDialog: EModeDialogPageObject - let myPortfolioPage: MyPortfolioPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, - }, - }) - - eModeDialog = new EModeDialogPageObject(page) - myPortfolioPage = new MyPortfolioPageObject(page) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositWithoutBorrowActions({ rETH: 2, wstETH: 10 }) - await myPortfolioPage.goToMyPortfolioAction() - - await myPortfolioPage.clickBorrowButtonAction('WETH') - const borrowDialog = new DialogPageObject(page, /Borrow/) - await borrowDialog.fillAmountAction(8) - await borrowDialog.clickAcknowledgeRisk() - await borrowDialog.actionsContainer.acceptAllActionsAction(1) - await borrowDialog.expectSuccessPage([{ asset: 'WETH', amount: 8 }], fork) - await borrowDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectAssetToBeInBorrowTable('WETH') - - await myPortfolioPage.clickEModeButtonAction() - await eModeDialog.setEModeAction('ETH Correlated') - await myPortfolioPage.expectEModeBadgeText('ETH Correlated') - }) - - test('shows risk warning', async () => { - await myPortfolioPage.clickEModeButtonAction() - await eModeDialog.clickEModeCategoryTileAction('No E-Mode') - await eModeDialog.expectLiquidationRiskWarning( - 'Disabling E-Mode decreases health factor of your position and puts you at risk of quick liquidation. You may lose part of your collateral.', - ) - }) - - test('actions stay disabled until risk warning is acknowledged', async () => { - await myPortfolioPage.clickEModeButtonAction() - - await eModeDialog.clickEModeCategoryTileAction('No E-Mode') - await eModeDialog.actionsContainer.expectDisabledActionAtIndex(0) - await eModeDialog.clickAcknowledgeRisk() - await eModeDialog.actionsContainer.expectEnabledActionAtIndex(0) - }) - - test('validation error; risk warning is not shown', async () => { - await myPortfolioPage.clickEModeButtonAction() - - await eModeDialog.clickEModeCategoryTileAction('Stablecoins') - await eModeDialog.expectAlertMessage( - setUserEModeValidationIssueToMessage['borrowed-assets-emode-category-mismatch'], - ) - await eModeDialog.expectLiquidationRiskWarningNotVisible() - }) - }) - - test.describe('Not in danger zone', () => { - let eModeDialog: EModeDialogPageObject - let myPortfolioPage: MyPortfolioPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, - }, - }) - - eModeDialog = new EModeDialogPageObject(page) - myPortfolioPage = new MyPortfolioPageObject(page) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositWithoutBorrowActions({ rETH: 2, wstETH: 10 }) - await myPortfolioPage.goToMyPortfolioAction() - - await myPortfolioPage.clickBorrowButtonAction('WETH') - const borrowDialog = new DialogPageObject(page, /Borrow/) - await borrowDialog.fillAmountAction(2) - await borrowDialog.actionsContainer.acceptAllActionsAction(1) - await borrowDialog.expectSuccessPage([{ asset: 'WETH', amount: 2 }], fork) - await borrowDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectAssetToBeInBorrowTable('WETH') - }) - - test('hf above danger zone threshold; risk warning is not shown', async () => { - await myPortfolioPage.clickEModeButtonAction() - await eModeDialog.clickEModeCategoryTileAction('No E-Mode') - await eModeDialog.expectLiquidationRiskWarningNotVisible() - }) - }) - }) -}) +// import { setUserEModeValidationIssueToMessage } from '@/domain/market-validators/validateSetUserEMode' +// import { BorrowPageObject } from '@/pages/Borrow.PageObject' +// import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { DialogPageObject } from '../common/Dialog.PageObject' +// import { EModeDialogPageObject } from './EModeDialog.PageObject' + +// test.describe('E-Mode dialog', () => { +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) + +// test.describe('ETH correlated assets borrowed', () => { +// let eModeDialog: EModeDialogPageObject +// let borrowDialog: DialogPageObject +// let myPortfolioPage: MyPortfolioPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ETH: 1, wstETH: 100 }, +// }, +// }) + +// eModeDialog = new EModeDialogPageObject(page) +// borrowDialog = new DialogPageObject(page, /Borrow/) +// myPortfolioPage = new MyPortfolioPageObject(page) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositWithoutBorrowActions({ wstETH: 20 }) +// await myPortfolioPage.goToMyPortfolioAction() + +// await myPortfolioPage.clickBorrowButtonAction('rETH') +// await borrowDialog.fillAmountAction(5) +// await borrowDialog.actionsContainer.acceptAllActionsAction(1) +// await borrowDialog.viewInMyPortfolioAction() +// await myPortfolioPage.clickBorrowButtonAction('WETH') +// await borrowDialog.fillAmountAction(5) +// await borrowDialog.actionsContainer.acceptAllActionsAction(1) +// await borrowDialog.viewInMyPortfolioAction() +// }) + +// test('can switch from no e-mode to eth correlated', async () => { +// await myPortfolioPage.clickEModeButtonAction() +// await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') +// await eModeDialog.expectEModeCategoryTileStatus('ETH Correlated', 'Inactive') +// await eModeDialog.expectEModeTransactionOverview({ +// variant: 'e-mode-no-change', +// availableAssets: { +// assets: 'All assets', +// }, +// hf: '1.75', +// maxLtv: '68.50%', +// }) + +// await eModeDialog.clickEModeCategoryTileAction('ETH Correlated') +// await eModeDialog.actionsContainer.expectActions([{ type: 'setUserEMode', eModeCategoryId: 1 }]) +// await eModeDialog.expectEModeTransactionOverview({ +// variant: 'e-mode-change', +// availableAssets: { +// category: 'ETH Correlated', +// assets: 'WETH, wstETH, rETH', +// }, +// hf: { +// before: '1.75', +// after: '2.05', +// }, +// maxLtv: { +// before: '68.50%', +// after: '90.00%', +// }, +// }) + +// await eModeDialog.actionsContainer.acceptAllActionsAction(1) +// await eModeDialog.expectEModeSuccessPage('ETH Correlated') +// await eModeDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectEModeBadgeText('ETH Correlated') +// }) + +// test('cannot switch from no e-mode to stablecoins', async () => { +// await myPortfolioPage.clickEModeButtonAction() +// await eModeDialog.clickEModeCategoryTileAction('Stablecoins') +// await eModeDialog.expectAlertMessage( +// setUserEModeValidationIssueToMessage['borrowed-assets-emode-category-mismatch'], +// ) +// await eModeDialog.actionsContainer.expectDisabledActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) +// }) + +// test('can enter eth correlated e-mode and switch back to no e-mode', async () => { +// await myPortfolioPage.clickEModeButtonAction() +// await eModeDialog.setEModeAction('ETH Correlated') +// await myPortfolioPage.expectEModeBadgeText('ETH Correlated') +// await myPortfolioPage.clickEModeButtonAction() + +// await eModeDialog.expectEModeCategoryTileStatus('ETH Correlated', 'Active') +// await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Inactive') +// await eModeDialog.clickEModeCategoryTileAction('No E-Mode') + +// await eModeDialog.expectEModeTransactionOverview({ +// variant: 'e-mode-change', +// availableAssets: { +// assets: 'All assets', +// }, +// hf: { +// before: '2.05', +// after: '1.75', +// }, +// maxLtv: { +// before: '90.00%', +// after: '68.50%', +// }, +// }) +// await eModeDialog.actionsContainer.acceptAllActionsAction(1) +// await eModeDialog.expectEModeSuccessPage('No E-Mode') +// await eModeDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectEModeBadgeText('E-Mode Off') +// }) + +// test('cannot switch back to no e-mode if hf below 1', async () => { +// await myPortfolioPage.clickEModeButtonAction() +// await eModeDialog.setEModeAction('ETH Correlated') +// await myPortfolioPage.expectEModeBadgeText('ETH Correlated') + +// await myPortfolioPage.clickBorrowButtonAction('WETH') +// await borrowDialog.fillAmountAction(10) +// await eModeDialog.clickAcknowledgeRisk() +// await borrowDialog.actionsContainer.acceptAllActionsAction(1) +// await borrowDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.clickEModeButtonAction() +// await eModeDialog.clickEModeCategoryTileAction('No E-Mode') +// await eModeDialog.expectAlertMessage(setUserEModeValidationIssueToMessage['exceeds-ltv']) +// await eModeDialog.actionsContainer.expectDisabledActions([{ type: 'setUserEMode', eModeCategoryId: 0 }]) +// }) +// }) + +// test.describe('Stablecoins borrowed', () => { +// let eModeDialog: EModeDialogPageObject +// let borrowDialog: DialogPageObject +// let myPortfolioPage: MyPortfolioPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ETH: 1, wstETH: 100 }, +// }, +// }) + +// eModeDialog = new EModeDialogPageObject(page) +// borrowDialog = new DialogPageObject(page, /Borrow/) +// myPortfolioPage = new MyPortfolioPageObject(page) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositWithoutBorrowActions({ wstETH: 1 }) +// await myPortfolioPage.goToMyPortfolioAction() + +// await myPortfolioPage.clickBorrowButtonAction('USDC') +// await borrowDialog.fillAmountAction(1000) +// await borrowDialog.actionsContainer.acceptAllActionsAction(1) +// await borrowDialog.viewInMyPortfolioAction() +// }) + +// test('can switch from no e-mode to stablecoins', async () => { +// await myPortfolioPage.clickEModeButtonAction() +// await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') +// await eModeDialog.expectEModeCategoryTileStatus('Stablecoins', 'Inactive') +// await eModeDialog.expectEModeTransactionOverview({ +// variant: 'e-mode-no-change', +// availableAssets: { +// assets: 'All assets', +// }, +// hf: '2.08', +// maxLtv: '68.50%', +// }) + +// await eModeDialog.clickEModeCategoryTileAction('Stablecoins') +// await eModeDialog.actionsContainer.expectActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) +// await eModeDialog.expectEModeTransactionOverview({ +// variant: 'e-mode-change', +// availableAssets: { +// category: 'Stablecoins', +// assets: 'sDAI, USDC, USDT', +// }, +// hf: { +// before: '2.08', +// after: '2.08', +// }, +// maxLtv: { +// before: '68.50%', +// after: '68.50%', +// }, +// }) + +// await eModeDialog.actionsContainer.acceptAllActionsAction(1) +// await eModeDialog.expectEModeSuccessPage('Stablecoins') +// await eModeDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectEModeBadgeText('Stablecoins') +// }) + +// test('cannot switch from no e-mode to eth correlated', async () => { +// await myPortfolioPage.clickEModeButtonAction() +// await eModeDialog.clickEModeCategoryTileAction('ETH Correlated') +// await eModeDialog.expectAlertMessage( +// setUserEModeValidationIssueToMessage['borrowed-assets-emode-category-mismatch'], +// ) +// await eModeDialog.actionsContainer.expectDisabledActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) +// }) + +// test('can enter stablecoins e-mode and switch back to no e-mode', async () => { +// await myPortfolioPage.clickEModeButtonAction() +// await eModeDialog.setEModeAction('Stablecoins') +// await myPortfolioPage.expectEModeBadgeText('Stablecoins') +// await myPortfolioPage.clickEModeButtonAction() + +// await eModeDialog.expectEModeCategoryTileStatus('Stablecoins', 'Active') +// await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Inactive') +// await eModeDialog.clickEModeCategoryTileAction('No E-Mode') + +// await eModeDialog.expectEModeTransactionOverview({ +// variant: 'e-mode-change', +// availableAssets: { +// assets: 'All assets', +// }, +// hf: { +// before: '2.08', +// after: '2.08', +// }, +// maxLtv: { +// before: '68.50%', +// after: '68.50%', +// }, +// }) +// await eModeDialog.actionsContainer.acceptAllActionsAction(1) +// await eModeDialog.expectEModeSuccessPage('No E-Mode') +// await eModeDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectEModeBadgeText('E-Mode Off') +// }) +// }) + +// test.describe('Assets from multiple categories borrowed', () => { +// let eModeDialog: EModeDialogPageObject +// let borrowDialog: DialogPageObject +// let myPortfolioPage: MyPortfolioPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ETH: 1, wstETH: 100 }, +// }, +// }) + +// eModeDialog = new EModeDialogPageObject(page) +// borrowDialog = new DialogPageObject(page, /Borrow/) +// myPortfolioPage = new MyPortfolioPageObject(page) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositWithoutBorrowActions({ wstETH: 10 }) +// await myPortfolioPage.goToMyPortfolioAction() + +// await myPortfolioPage.clickBorrowButtonAction('rETH') +// await borrowDialog.fillAmountAction(1) +// await borrowDialog.actionsContainer.acceptAllActionsAction(1) +// await borrowDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.clickBorrowButtonAction('WBTC') +// await borrowDialog.fillAmountAction(0.1) +// await borrowDialog.actionsContainer.acceptAllActionsAction(1) +// await borrowDialog.viewInMyPortfolioAction() +// }) + +// test('cannot switch from no e-mode to stablecoins', async () => { +// await myPortfolioPage.clickEModeButtonAction() +// await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') +// await eModeDialog.expectEModeCategoryTileStatus('Stablecoins', 'Inactive') + +// await eModeDialog.clickEModeCategoryTileAction('Stablecoins') + +// await eModeDialog.expectAlertMessage( +// setUserEModeValidationIssueToMessage['borrowed-assets-emode-category-mismatch'], +// ) +// await eModeDialog.expectEModeTransactionOverview({ +// variant: 'e-mode-change', +// availableAssets: { +// category: 'Stablecoins', +// assets: 'sDAI, USDC, USDT', +// }, +// hf: { +// before: '3.12', +// after: '3.12', +// }, +// maxLtv: { +// before: '68.50%', +// after: '68.50%', +// }, +// }) +// await eModeDialog.actionsContainer.expectDisabledActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) +// }) + +// test('cannot switch from no e-mode to eth correlated', async () => { +// await myPortfolioPage.clickEModeButtonAction() +// await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') +// await eModeDialog.expectEModeCategoryTileStatus('ETH Correlated', 'Inactive') + +// await eModeDialog.clickEModeCategoryTileAction('ETH Correlated') +// await eModeDialog.expectEModeTransactionOverview({ +// variant: 'e-mode-change', +// availableAssets: { +// category: 'ETH Correlated', +// assets: 'WETH, wstETH, rETH', +// }, +// hf: { +// before: '3.12', +// after: '3.65', +// }, +// maxLtv: { +// before: '68.50%', +// after: '90.00%', +// }, +// }) +// await eModeDialog.expectAlertMessage( +// setUserEModeValidationIssueToMessage['borrowed-assets-emode-category-mismatch'], +// ) +// await eModeDialog.actionsContainer.expectDisabledActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) +// }) +// }) + +// test.describe('Nothing borrowed', () => { +// let eModeDialog: EModeDialogPageObject +// let myPortfolioPage: MyPortfolioPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ETH: 1, wstETH: 100 }, +// }, +// }) + +// eModeDialog = new EModeDialogPageObject(page) +// myPortfolioPage = new MyPortfolioPageObject(page) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositWithoutBorrowActions({ wstETH: 20 }) +// await myPortfolioPage.goToMyPortfolioAction() +// }) + +// test('can switch from no e-mode to eth correleated', async () => { +// await myPortfolioPage.clickEModeButtonAction() +// await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') +// await eModeDialog.expectEModeCategoryTileStatus('ETH Correlated', 'Inactive') + +// await eModeDialog.clickEModeCategoryTileAction('ETH Correlated') +// await eModeDialog.actionsContainer.expectActions([{ type: 'setUserEMode', eModeCategoryId: 1 }]) +// await eModeDialog.expectEModeTransactionOverview({ +// variant: 'no-borrow', +// availableAssets: { +// category: 'ETH Correlated', +// assets: 'WETH, wstETH, rETH', +// }, +// maxLtv: { +// before: '68.50%', +// after: '90.00%', +// }, +// }) + +// await eModeDialog.actionsContainer.acceptAllActionsAction(1) +// await eModeDialog.expectEModeSuccessPage('ETH Correlated') +// await eModeDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectEModeBadgeText('ETH Correlated') +// }) + +// test('can switch from no e-mode to stablecoins', async () => { +// await myPortfolioPage.clickEModeButtonAction() +// await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') + +// await eModeDialog.expectEModeCategoryTileStatus('Stablecoins', 'Inactive') +// await eModeDialog.clickEModeCategoryTileAction('Stablecoins') +// await eModeDialog.actionsContainer.expectActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) +// await eModeDialog.expectEModeTransactionOverview({ +// variant: 'no-borrow', +// availableAssets: { +// category: 'Stablecoins', +// assets: 'sDAI, USDC, USDT', +// }, +// maxLtv: { +// before: '68.50%', +// after: '68.50%', +// }, +// }) + +// await eModeDialog.actionsContainer.acceptAllActionsAction(1) +// await eModeDialog.expectEModeSuccessPage('Stablecoins') +// await eModeDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectEModeBadgeText('Stablecoins') +// }) + +// test('can enter e-mode and switch back to no e-mode', async () => { +// await myPortfolioPage.clickEModeButtonAction() +// await eModeDialog.setEModeAction('Stablecoins') +// await myPortfolioPage.expectEModeBadgeText('Stablecoins') +// await myPortfolioPage.clickEModeButtonAction() + +// await eModeDialog.expectEModeCategoryTileStatus('Stablecoins', 'Active') +// await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Inactive') +// await eModeDialog.clickEModeCategoryTileAction('No E-Mode') + +// await eModeDialog.expectEModeTransactionOverview({ +// variant: 'no-borrow', +// availableAssets: { +// assets: 'All assets', +// }, +// maxLtv: { +// before: '68.50%', +// after: '68.50%', +// }, +// }) +// await eModeDialog.actionsContainer.acceptAllActionsAction(1) +// await eModeDialog.expectEModeSuccessPage('No E-Mode') +// await eModeDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectEModeBadgeText('E-Mode Off') +// }) +// }) + +// test.describe('Liquidation risk warning', () => { +// test.describe('In danger zone', () => { +// let eModeDialog: EModeDialogPageObject +// let myPortfolioPage: MyPortfolioPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, +// }, +// }) + +// eModeDialog = new EModeDialogPageObject(page) +// myPortfolioPage = new MyPortfolioPageObject(page) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositWithoutBorrowActions({ rETH: 2, wstETH: 10 }) +// await myPortfolioPage.goToMyPortfolioAction() + +// await myPortfolioPage.clickBorrowButtonAction('WETH') +// const borrowDialog = new DialogPageObject(page, /Borrow/) +// await borrowDialog.fillAmountAction(8) +// await borrowDialog.clickAcknowledgeRisk() +// await borrowDialog.actionsContainer.acceptAllActionsAction(1) +// await borrowDialog.expectSuccessPage([{ asset: 'WETH', amount: 8 }], fork) +// await borrowDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectAssetToBeInBorrowTable('WETH') + +// await myPortfolioPage.clickEModeButtonAction() +// await eModeDialog.setEModeAction('ETH Correlated') +// await myPortfolioPage.expectEModeBadgeText('ETH Correlated') +// }) + +// test('shows risk warning', async () => { +// await myPortfolioPage.clickEModeButtonAction() +// await eModeDialog.clickEModeCategoryTileAction('No E-Mode') +// await eModeDialog.expectLiquidationRiskWarning( +// 'Disabling E-Mode decreases health factor of your position and puts you at risk of quick liquidation. You may lose part of your collateral.', +// ) +// }) + +// test('actions stay disabled until risk warning is acknowledged', async () => { +// await myPortfolioPage.clickEModeButtonAction() + +// await eModeDialog.clickEModeCategoryTileAction('No E-Mode') +// await eModeDialog.actionsContainer.expectDisabledActionAtIndex(0) +// await eModeDialog.clickAcknowledgeRisk() +// await eModeDialog.actionsContainer.expectEnabledActionAtIndex(0) +// }) + +// test('validation error; risk warning is not shown', async () => { +// await myPortfolioPage.clickEModeButtonAction() + +// await eModeDialog.clickEModeCategoryTileAction('Stablecoins') +// await eModeDialog.expectAlertMessage( +// setUserEModeValidationIssueToMessage['borrowed-assets-emode-category-mismatch'], +// ) +// await eModeDialog.expectLiquidationRiskWarningNotVisible() +// }) +// }) + +// test.describe('Not in danger zone', () => { +// let eModeDialog: EModeDialogPageObject +// let myPortfolioPage: MyPortfolioPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, +// }, +// }) + +// eModeDialog = new EModeDialogPageObject(page) +// myPortfolioPage = new MyPortfolioPageObject(page) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositWithoutBorrowActions({ rETH: 2, wstETH: 10 }) +// await myPortfolioPage.goToMyPortfolioAction() + +// await myPortfolioPage.clickBorrowButtonAction('WETH') +// const borrowDialog = new DialogPageObject(page, /Borrow/) +// await borrowDialog.fillAmountAction(2) +// await borrowDialog.actionsContainer.acceptAllActionsAction(1) +// await borrowDialog.expectSuccessPage([{ asset: 'WETH', amount: 2 }], fork) +// await borrowDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectAssetToBeInBorrowTable('WETH') +// }) + +// test('hf above danger zone threshold; risk warning is not shown', async () => { +// await myPortfolioPage.clickEModeButtonAction() +// await eModeDialog.clickEModeCategoryTileAction('No E-Mode') +// await eModeDialog.expectLiquidationRiskWarningNotVisible() +// }) +// }) +// }) +// }) diff --git a/packages/app/src/features/dialogs/repay/RepayDialog.test-e2e.ts b/packages/app/src/features/dialogs/repay/RepayDialog.test-e2e.ts index 9593c7ec7..696114a55 100644 --- a/packages/app/src/features/dialogs/repay/RepayDialog.test-e2e.ts +++ b/packages/app/src/features/dialogs/repay/RepayDialog.test-e2e.ts @@ -1,700 +1,700 @@ -import { Page, test } from '@playwright/test' -import { mainnet } from 'viem/chains' - -import { repayValidationIssueToMessage } from '@/domain/market-validators/validateRepay' -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { BorrowPageObject } from '@/pages/Borrow.PageObject' -import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' -import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { screenshot } from '@/test/e2e/utils' - -import { tenderlyRpcActions } from '@/domain/tenderly/TenderlyRpcActions' -import { injectFixedDate } from '@/test/e2e/injectSetup' -import { BaseUnitNumber, NormalizedUnitNumber } from '@marsfoundation/common-universal' -import { http, Address, createPublicClient } from 'viem' -import { DialogPageObject } from '../common/Dialog.PageObject' - -const headerRegExp = /Repa*/ - -test.describe('Repay dialog', () => { - const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) - const initialBalances = { - wstETH: 100, - rETH: 100, - WETH: 100, - DAI: 10000, - } - const expectedInitialHealthFactor = '5.65' - const expectedHealthFactor = '5.82' - - test.describe('Position with borrowed DAI', () => { - const initialDeposits = { - rETH: 10, - } as const - const daiToBorrow = 3500 - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ...initialBalances }, - }, - }) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) - await borrowPage.viewInMyPortfolioAction() - - const myPortfolioPage = new MyPortfolioPageObject(page) - // @todo This waits for the refetch of the data after successful borrow transaction to happen. - // This is no ideal, probably we need to refactor expectDepositTable so it takes advantage from - // playwright's timeouts instead of parsing it's current state. Then we would be able to - // easily wait for the table to be updated. - await myPortfolioPage.expectAssetToBeInDepositTable('DAI') - }) - - test('opens dialog with selected asset', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickRepayButtonAction('DAI') - - const repayDialog = new DialogPageObject(page, headerRegExp) - await repayDialog.expectSelectedAsset('DAI') - await repayDialog.expectDialogHeader('Repay DAI') - await repayDialog.expectHealthFactorBeforeVisible() - - await screenshot(repayDialog.getDialog(), 'repay-dialog-default-view') - }) - - test('calculates health factor changes correctly when repaying part', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickRepayButtonAction('DAI') - - const repayDialog = new DialogPageObject(page, headerRegExp) - await repayDialog.fillAmountAction(100) - - await repayDialog.expectRiskLevelBefore('Healthy') - await repayDialog.expectHealthFactorBefore(expectedInitialHealthFactor) - await repayDialog.expectRiskLevelAfter('Healthy') - await repayDialog.expectHealthFactorAfter(expectedHealthFactor) - - // @note this is needed for deterministic screenshots - const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) - await actionsContainer.expectEnabledActionAtIndex(0) - - await screenshot(repayDialog.getDialog(), 'repay-dialog-health-factor-partial-repay') - }) - - test('calculates health factor changes correctly when repaying all', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickRepayButtonAction('DAI') - - const repayDialog = new DialogPageObject(page, headerRegExp) - await repayDialog.clickMaxAmountAction() - - await repayDialog.expectRiskLevelBefore('Healthy') - await repayDialog.expectHealthFactorBefore(expectedInitialHealthFactor) - await repayDialog.expectRiskLevelAfter('No debt') - await repayDialog.expectHealthFactorAfter(String.fromCharCode(0x221e)) - - // @note this is needed for deterministic screenshots - const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) - await actionsContainer.expectEnabledActionAtIndex(0) - - await screenshot(repayDialog.getDialog(), 'repay-dialog-health-factor-full-repay') - }) - - test('after repay, health factor matches myPortfolio', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickRepayButtonAction('DAI') - - const repayDialog = new DialogPageObject(page, headerRegExp) - await repayDialog.fillAmountAction(100) - - const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) - - await repayDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectHealthFactor(expectedHealthFactor) - }) - - test('has correct action plan for DAI', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - - await myPortfolioPage.clickRepayButtonAction('DAI') - - const repayDialog = new DialogPageObject(page, headerRegExp) - await repayDialog.fillAmountAction(100) - const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) - await actionsContainer.expectActions([ - { type: 'approve', asset: 'DAI' }, - { type: 'repay', asset: 'DAI' }, - ]) - }) - - test('can repay DAI', async ({ page }) => { - const repay = { - asset: 'DAI', - amount: 100, - } as const - - const myPortfolioPage = new MyPortfolioPageObject(page) - - await myPortfolioPage.clickRepayButtonAction(repay.asset) - - const repayDialog = new DialogPageObject(page, headerRegExp) - await repayDialog.fillAmountAction(repay.amount) - const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) - await repayDialog.expectSuccessPage([repay], fork) - - await screenshot(repayDialog.getDialog(), 'repay-dialog-dai-success') +// import { Page, test } from '@playwright/test' +// import { mainnet } from 'viem/chains' + +// import { repayValidationIssueToMessage } from '@/domain/market-validators/validateRepay' +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { BorrowPageObject } from '@/pages/Borrow.PageObject' +// import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { screenshot } from '@/test/e2e/utils' + +// import { tenderlyRpcActions } from '@/domain/tenderly/TenderlyRpcActions' +// import { injectFixedDate } from '@/test/e2e/injectSetup' +// import { BaseUnitNumber, NormalizedUnitNumber } from '@marsfoundation/common-universal' +// import { http, Address, createPublicClient } from 'viem' +// import { DialogPageObject } from '../common/Dialog.PageObject' + +// const headerRegExp = /Repa*/ + +// test.describe('Repay dialog', () => { +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) +// const initialBalances = { +// wstETH: 100, +// rETH: 100, +// WETH: 100, +// DAI: 10000, +// } +// const expectedInitialHealthFactor = '5.65' +// const expectedHealthFactor = '5.82' + +// test.describe('Position with borrowed DAI', () => { +// const initialDeposits = { +// rETH: 10, +// } as const +// const daiToBorrow = 3500 + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ...initialBalances }, +// }, +// }) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) +// await borrowPage.viewInMyPortfolioAction() + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// // @todo This waits for the refetch of the data after successful borrow transaction to happen. +// // This is no ideal, probably we need to refactor expectDepositTable so it takes advantage from +// // playwright's timeouts instead of parsing it's current state. Then we would be able to +// // easily wait for the table to be updated. +// await myPortfolioPage.expectAssetToBeInDepositTable('DAI') +// }) + +// test('opens dialog with selected asset', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickRepayButtonAction('DAI') + +// const repayDialog = new DialogPageObject(page, headerRegExp) +// await repayDialog.expectSelectedAsset('DAI') +// await repayDialog.expectDialogHeader('Repay DAI') +// await repayDialog.expectHealthFactorBeforeVisible() + +// await screenshot(repayDialog.getDialog(), 'repay-dialog-default-view') +// }) + +// test('calculates health factor changes correctly when repaying part', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickRepayButtonAction('DAI') + +// const repayDialog = new DialogPageObject(page, headerRegExp) +// await repayDialog.fillAmountAction(100) + +// await repayDialog.expectRiskLevelBefore('Healthy') +// await repayDialog.expectHealthFactorBefore(expectedInitialHealthFactor) +// await repayDialog.expectRiskLevelAfter('Healthy') +// await repayDialog.expectHealthFactorAfter(expectedHealthFactor) + +// // @note this is needed for deterministic screenshots +// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) +// await actionsContainer.expectEnabledActionAtIndex(0) + +// await screenshot(repayDialog.getDialog(), 'repay-dialog-health-factor-partial-repay') +// }) + +// test('calculates health factor changes correctly when repaying all', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickRepayButtonAction('DAI') + +// const repayDialog = new DialogPageObject(page, headerRegExp) +// await repayDialog.clickMaxAmountAction() + +// await repayDialog.expectRiskLevelBefore('Healthy') +// await repayDialog.expectHealthFactorBefore(expectedInitialHealthFactor) +// await repayDialog.expectRiskLevelAfter('No debt') +// await repayDialog.expectHealthFactorAfter(String.fromCharCode(0x221e)) + +// // @note this is needed for deterministic screenshots +// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) +// await actionsContainer.expectEnabledActionAtIndex(0) + +// await screenshot(repayDialog.getDialog(), 'repay-dialog-health-factor-full-repay') +// }) + +// test('after repay, health factor matches myPortfolio', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickRepayButtonAction('DAI') + +// const repayDialog = new DialogPageObject(page, headerRegExp) +// await repayDialog.fillAmountAction(100) + +// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) + +// await repayDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectHealthFactor(expectedHealthFactor) +// }) + +// test('has correct action plan for DAI', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) + +// await myPortfolioPage.clickRepayButtonAction('DAI') + +// const repayDialog = new DialogPageObject(page, headerRegExp) +// await repayDialog.fillAmountAction(100) +// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) +// await actionsContainer.expectActions([ +// { type: 'approve', asset: 'DAI' }, +// { type: 'repay', asset: 'DAI' }, +// ]) +// }) + +// test('can repay DAI', async ({ page }) => { +// const repay = { +// asset: 'DAI', +// amount: 100, +// } as const + +// const myPortfolioPage = new MyPortfolioPageObject(page) + +// await myPortfolioPage.clickRepayButtonAction(repay.asset) + +// const repayDialog = new DialogPageObject(page, headerRegExp) +// await repayDialog.fillAmountAction(repay.amount) +// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) +// await repayDialog.expectSuccessPage([repay], fork) + +// await screenshot(repayDialog.getDialog(), 'repay-dialog-dai-success') - await repayDialog.viewInMyPortfolioAction() +// await repayDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectBorrowTable({ - [repay.asset]: daiToBorrow - repay.amount, - }) - }) +// await myPortfolioPage.expectBorrowTable({ +// [repay.asset]: daiToBorrow - repay.amount, +// }) +// }) - test('can fully repay DAI', async ({ page }) => { - const repay = { - asset: 'DAI', - amount: 3500, - } as const +// test('can fully repay DAI', async ({ page }) => { +// const repay = { +// asset: 'DAI', +// amount: 3500, +// } as const - const myPortfolioPage = new MyPortfolioPageObject(page) - - await myPortfolioPage.clickRepayButtonAction(repay.asset) - - const repayDialog = new DialogPageObject(page, headerRegExp) - await repayDialog.clickMaxAmountAction() - const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) - await repayDialog.expectSuccessPage([repay], fork) - - await screenshot(repayDialog.getDialog(), 'repay-dialog-dai-success') - - await repayDialog.viewInMyPortfolioAction() - - await myPortfolioPage.expectBorrowTable({ - [repay.asset]: 0, - }) - }) +// const myPortfolioPage = new MyPortfolioPageObject(page) + +// await myPortfolioPage.clickRepayButtonAction(repay.asset) + +// const repayDialog = new DialogPageObject(page, headerRegExp) +// await repayDialog.clickMaxAmountAction() +// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) +// await repayDialog.expectSuccessPage([repay], fork) + +// await screenshot(repayDialog.getDialog(), 'repay-dialog-dai-success') + +// await repayDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.expectBorrowTable({ +// [repay.asset]: 0, +// }) +// }) - // @todo: doesn't work properly because of fixed date or something - test.skip('exact approvals are not required when repaying all', async ({ page }) => { - const repay = { - asset: 'DAI', - amount: 3500, - } as const - - const myPortfolioPage = new MyPortfolioPageObject(page) - - await myPortfolioPage.clickRepayButtonAction(repay.asset) - - const repayDialog = new DialogPageObject(page, headerRegExp) - await repayDialog.clickMaxAmountAction() - const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) - // (1) first approval with extra buffer - await actionsContainer.acceptActionAtIndex(0) - await actionsContainer.expectEnabledActionAtIndex(1) - - await page.reload() - await myPortfolioPage.clickRepayButtonAction(repay.asset) - await repayDialog.clickMaxAmountAction() - - // exact amount of debt slightly increased but approval (1) has a buffer so it should be enough - // this should be rewrite to assert whole action plan and then accept - // await actionsContainer.acceptActionAtIndex(1, { type: 'repay', asset: repay.asset }) - // await actionsContainer.acceptNextActionAction() - - await repayDialog.expectSuccessPage([repay], fork) - }) - }) - - test.describe('Position when borrowed asset was not in user wallet before', () => { - const DAI_ADDRESS = '0x6B175474E89094C44Da98b954EedeAC495271d0F' - const DAI_DECIMALS = 18 - - const initialDeposits = { - wstETH: 10, - } as const - - const daiToBorrow = 10_000 - const daiDebtIncreaseIn1Epoch = 1.0000029476774694 // hardcoded for DAI borrow rate 5.53% - const daiDebtIncreaseIn2Epochs = 1.0000058953636277 // hardcoded for DAI borrow rate 5.53% - - let account: Address - let myPortfolioPage: MyPortfolioPageObject - let repayDialog: DialogPageObject - - async function overrideDaiBalance({ balance, page }: { balance: BaseUnitNumber; page: Page }): Promise { - await tenderlyRpcActions.setTokenBalance(fork.forkUrl, DAI_ADDRESS, account, balance) - await page.reload() - } - - test.beforeEach(async ({ page }) => { - ;({ account } = await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { wstETH: 10 }, - }, - })) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) - await borrowPage.viewInMyPortfolioAction() - - myPortfolioPage = new MyPortfolioPageObject(page) - repayDialog = new DialogPageObject(page, headerRegExp) - - await myPortfolioPage.expectHealthFactor('2.08') - - // forcefully set browser time to the timestamp of borrow transaction - const publicClient = createPublicClient({ - transport: http(fork.forkUrl), - }) - const block = await publicClient.getBlock() - await injectFixedDate(page, new Date(Number(block.timestamp) * 1000)) - await page.reload() - }) - - test('can repay if balance is less than debt', async ({ page }) => { - const newBalance = 0.9 * daiToBorrow - const repay = { - asset: 'DAI', - amount: newBalance, - } as const - - await overrideDaiBalance({ - balance: BaseUnitNumber(NormalizedUnitNumber(newBalance).shiftedBy(DAI_DECIMALS)), - page, - }) - - await myPortfolioPage.clickRepayButtonAction(repay.asset) - - await repayDialog.clickMaxAmountAction() - const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) - await repayDialog.expectSuccessPage([repay], fork) - - await repayDialog.viewInMyPortfolioAction() - - await myPortfolioPage.expectNonZeroAmountInBorrowTable(repay.asset) - }) - - test('can repay if balance gt debt but lt debt after 1 epoch', async ({ page }) => { - // The test asserts and edge case where user's balance is greater than debt, but less than debt after 1 epoch (30 minutes). - // In this case the current implementation does not try to repay the debt including the interest accrued in the following time period - // before the repay transaction is mined. Only the current debt is repaid. Therefore after the repay transaction some dust - // (accrued interest) is left in the user's borrow table. - const repay = { - asset: 'DAI', - amount: daiToBorrow, - } as const - - const daiDebtIn1Epoch = NormalizedUnitNumber(daiToBorrow).times(daiDebtIncreaseIn1Epoch) - // newBalance = (daiToBorrow, daiDebtIn1Epoch) / 2 - a number somewhere between daiToBorrow and daiDebtIn1Epoch - const newBalance = BaseUnitNumber(daiDebtIn1Epoch.plus(daiToBorrow).div(2).shiftedBy(DAI_DECIMALS)) - await overrideDaiBalance({ - balance: newBalance, - page, - }) - - await myPortfolioPage.clickRepayButtonAction(repay.asset) - - await repayDialog.clickMaxAmountAction() - const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) - await repayDialog.expectSuccessPage( - [ - { - asset: repay.asset, - amount: daiToBorrow, - }, - ], - fork, - ) - - await repayDialog.viewInMyPortfolioAction() - - await myPortfolioPage.expectNonZeroAmountInBorrowTable(repay.asset) - }) - - test('can repay if balance gt debt after 1 epoch but lt debt after 2 epochs', async ({ page }) => { - const repay = { - asset: 'DAI', - amount: daiToBorrow, - } as const - - const daiDebtIn1Epoch = NormalizedUnitNumber(daiToBorrow).times(daiDebtIncreaseIn1Epoch) - const daiDebtIn2Epochs = NormalizedUnitNumber(daiToBorrow).times(daiDebtIncreaseIn2Epochs) - // newBalance = (daiDebtIn1Epoch + daiDebtIn2Epochs) / 2 - a number somewhere between daiDebtIn1Epoch and daiDebtIn2Epochs - const newBalance = BaseUnitNumber(daiDebtIn2Epochs.plus(daiDebtIn1Epoch).div(2).shiftedBy(DAI_DECIMALS)) - await overrideDaiBalance({ - balance: newBalance, - page, - }) - - await myPortfolioPage.clickRepayButtonAction(repay.asset) - - const repayDialog = new DialogPageObject(page, headerRegExp) - await repayDialog.clickMaxAmountAction() - const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) - await repayDialog.expectSuccessPage( - [ - { - asset: repay.asset, - amount: daiToBorrow, - }, - ], - fork, - ) - - await repayDialog.viewInMyPortfolioAction() - - await myPortfolioPage.expectBorrowTable({ - [repay.asset]: 0, - }) - }) - }) - - test.describe('Position with multiple borrowed assets', () => { - const initialDeposits = { - wstETH: initialBalances.wstETH, // deposit whole balance - } as const - - const wstETHBorrow = { - asset: 'wstETH', - amount: 10, - } - - const WETHBorrow = { - asset: 'WETH', - amount: 10, - } - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ...initialBalances }, - }, - }) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositWithoutBorrowActions(initialDeposits) // deposit whole wallet balance - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.goToMyPortfolioAction() - - // borrow wstETH and WETH - const borrowDialog = new DialogPageObject(page, /Borrow */) - const borrowActionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) - // borrow wstETH - await myPortfolioPage.clickBorrowButtonAction(wstETHBorrow.asset) - await borrowDialog.fillAmountAction(wstETHBorrow.amount) - await borrowActionsContainer.acceptAllActionsAction(1) - await borrowDialog.viewInMyPortfolioAction() - // borrow WETH - await myPortfolioPage.clickBorrowButtonAction(WETHBorrow.asset) - await borrowDialog.fillAmountAction(WETHBorrow.amount) - await borrowActionsContainer.acceptAllActionsAction(1) - await borrowDialog.viewInMyPortfolioAction() - }) - - test('can change asset to aToken', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickRepayButtonAction('wstETH') - - const repayDialog = new DialogPageObject(page, headerRegExp) - await repayDialog.selectAssetAction('awstETH') - await repayDialog.expectSelectedAsset('awstETH') - await repayDialog.expectDialogHeader('Repay wstETH') - await repayDialog.expectHealthFactorBeforeVisible() - }) - - test('has correct action plan for repaying erc-20 using aToken', async ({ page }) => { - const repay = { - asset: 'awstETH', - amount: 5, - } as const - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickRepayButtonAction('wstETH') - - const repayDialog = new DialogPageObject(page, headerRegExp) - await repayDialog.selectAssetAction(repay.asset) - await repayDialog.fillAmountAction(repay.amount) - - const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) - await actionsContainer.expectActions([{ type: 'repay', asset: repay.asset }]) - - await screenshot(repayDialog.getDialog(), 'repay-dialog-erc20-atoken-action-plan') - }) - - test('can repay erc-20 using aToken', async ({ page }) => { - const repay = { - asset: 'awstETH', - amount: 5, - } as const - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickRepayButtonAction('wstETH') - - const repayDialog = new DialogPageObject(page, headerRegExp) - await repayDialog.selectAssetAction(repay.asset) - await repayDialog.fillAmountAction(repay.amount) - - const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(1) - - await screenshot(repayDialog.getDialog(), 'repay-dialog-erc20-atoken-success') - - await repayDialog.viewInMyPortfolioAction() - - await myPortfolioPage.expectBorrowTable({ - wstETH: wstETHBorrow.amount - repay.amount, - }) - }) - - test('has correct action plan for erc-20 repay with permits', async ({ page }) => { - const repay = { - asset: 'wstETH', - amount: 5, - } as const - - const myPortfolioPage = new MyPortfolioPageObject(page) - - await myPortfolioPage.clickRepayButtonAction(repay.asset) - - const repayDialog = new DialogPageObject(page, headerRegExp) - await repayDialog.fillAmountAction(repay.amount) - const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) - await actionsContainer.expectActions([ - { type: 'permit', asset: repay.asset }, - { type: 'repay', asset: repay.asset }, - ]) - - await screenshot(repayDialog.getDialog(), 'repay-dialog-erc20-permit-action-plan') - }) - - test('has correct action plan for erc-20 repay with approves', async ({ page }) => { - const repay = { - asset: 'wstETH', - amount: 5, - } as const - - const myPortfolioPage = new MyPortfolioPageObject(page) - - await myPortfolioPage.clickRepayButtonAction(repay.asset) - - const repayDialog = new DialogPageObject(page, headerRegExp) - const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) - await actionsContainer.switchPreferPermitsAction() - - await repayDialog.fillAmountAction(repay.amount) - await actionsContainer.expectActions([ - { type: 'approve', asset: repay.asset }, - { type: 'repay', asset: repay.asset }, - ]) - - await screenshot(repayDialog.getDialog(), 'repay-dialog-erc20-approve-action-plan') - }) - - test('can repay erc-20 using permits', async ({ page }) => { - const repay = { - asset: 'wstETH', - amount: 5, - } as const - - const myPortfolioPage = new MyPortfolioPageObject(page) - - await myPortfolioPage.clickRepayButtonAction(repay.asset) - - const repayDialog = new DialogPageObject(page, headerRegExp) - await repayDialog.fillAmountAction(repay.amount) - const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) - await repayDialog.expectSuccessPage([repay], fork) - - await screenshot(repayDialog.getDialog(), 'repay-dialog-erc20-success') - - await repayDialog.viewInMyPortfolioAction() - - await myPortfolioPage.expectBorrowTable({ - [repay.asset]: wstETHBorrow.amount - repay.amount, - }) - }) - - test('can repay erc-20 using approves', async ({ page }) => { - const repay = { - asset: 'wstETH', - amount: 5, - } as const - - const myPortfolioPage = new MyPortfolioPageObject(page) - - await myPortfolioPage.clickRepayButtonAction(repay.asset) - - const repayDialog = new DialogPageObject(page, headerRegExp) - const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) - await actionsContainer.switchPreferPermitsAction() - await repayDialog.fillAmountAction(repay.amount) - await actionsContainer.acceptAllActionsAction(2) - await repayDialog.expectSuccessPage([repay], fork) - - await repayDialog.viewInMyPortfolioAction() - - await myPortfolioPage.expectBorrowTable({ - [repay.asset]: wstETHBorrow.amount - repay.amount, - }) - }) - }) - - test.describe('Form validation', () => { - const initialDeposits = { - wstETH: initialBalances.wstETH, // deposit whole balance - } as const - - const wstETHBorrow = { - asset: 'wstETH', - amount: 50, - } - - const wstETHDeposit = { - asset: 'wstETH', - amount: 50, - } - - const WETHBorrow = { - asset: 'WETH', - amount: 10, - } - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ...initialBalances }, - }, - }) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositWithoutBorrowActions(initialDeposits) // deposit whole wallet balance - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.goToMyPortfolioAction() - - // borrow wstETH and WETH - const borrowDialog = new DialogPageObject(page, /Borrow */) - const borrowActionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) - // borrow wstETH - await myPortfolioPage.clickBorrowButtonAction(wstETHBorrow.asset) - await borrowDialog.fillAmountAction(wstETHBorrow.amount) - await borrowActionsContainer.acceptAllActionsAction(1) - await borrowDialog.viewInMyPortfolioAction() - // borrow WETH - await myPortfolioPage.clickBorrowButtonAction(WETHBorrow.asset) - await borrowDialog.fillAmountAction(WETHBorrow.amount) - await borrowDialog.clickAcknowledgeRisk() - await borrowActionsContainer.acceptAllActionsAction(1) - await borrowDialog.viewInMyPortfolioAction() - - // deposit wstETH to have balance not enough to later repay debt using wstETH - const depositDialog = new DialogPageObject(page, /Deposit */) - const depositActionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await myPortfolioPage.clickDepositButtonAction(wstETHDeposit.asset) - await depositDialog.fillAmountAction(wstETHDeposit.amount) - await depositActionsContainer.acceptAllActionsAction(2) - await depositDialog.viewInMyPortfolioAction() - }) - - test('cannot repay repay more than owe', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickRepayButtonAction(WETHBorrow.asset) - - const repayDialog = new DialogPageObject(page, headerRegExp) - await repayDialog.expectHealthFactorBefore('2.03') - await repayDialog.fillAmountAction(WETHBorrow.amount + 1) - await repayDialog.expectAssetInputError(repayValidationIssueToMessage['exceeds-debt']) - - await screenshot(repayDialog.getDialog(), 'repay-dialog-more-than-owe') - }) - - test('cannot repay more than wallet balance', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickRepayButtonAction(wstETHBorrow.asset) - - const repayDialog = new DialogPageObject(page, headerRegExp) - await repayDialog.expectHealthFactorBefore('2.03') - await repayDialog.fillAmountAction(1) - await repayDialog.expectAssetInputError(repayValidationIssueToMessage['exceeds-balance']) - - await screenshot(repayDialog.getDialog(), 'repay-dialog-more-than-balance') - }) - }) - - // @note Add tests when problem with native asset deposit is solved - test.describe('Position with native token debt', () => {}) - - test.describe('Position with only deposit', () => { - const initialDeposits = { - wstETH: 10, - } as const - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ...initialBalances }, - }, - }) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositWithoutBorrowActions(initialDeposits) - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.goToMyPortfolioAction() - }) - - test('nothing to repay', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.expectBorrowedAssetsToBeEmpty() - await screenshot(page, 'repay-dialog-nothing-to-repay') - }) - - test('when repaying native asset retain some in wallet', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickBorrowButtonAction('WETH') - - const borrowDialog = new DialogPageObject(page, /Borrow */) - await borrowDialog.selectAssetAction('ETH') - await borrowDialog.fillAmountAction(5) - const borrowActionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) - await borrowActionsContainer.acceptAllActionsAction(2) - await borrowDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectBorrowTable({ WETH: 5 }) - - await myPortfolioPage.clickRepayButtonAction('WETH') - const repayDialog = new DialogPageObject(page, headerRegExp) - await repayDialog.selectAssetAction('ETH') - const repayActionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) - // wait for select to switch to ETH - await repayActionsContainer.expectActions([ - { - type: 'repay', - asset: 'ETH', - }, - ]) - await repayDialog.clickMaxAmountAction() - - await repayDialog.expectInputValue('4.999') - }) - }) -}) +// // @todo: doesn't work properly because of fixed date or something +// test.skip('exact approvals are not required when repaying all', async ({ page }) => { +// const repay = { +// asset: 'DAI', +// amount: 3500, +// } as const + +// const myPortfolioPage = new MyPortfolioPageObject(page) + +// await myPortfolioPage.clickRepayButtonAction(repay.asset) + +// const repayDialog = new DialogPageObject(page, headerRegExp) +// await repayDialog.clickMaxAmountAction() +// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) +// // (1) first approval with extra buffer +// await actionsContainer.acceptActionAtIndex(0) +// await actionsContainer.expectEnabledActionAtIndex(1) + +// await page.reload() +// await myPortfolioPage.clickRepayButtonAction(repay.asset) +// await repayDialog.clickMaxAmountAction() + +// // exact amount of debt slightly increased but approval (1) has a buffer so it should be enough +// // this should be rewrite to assert whole action plan and then accept +// // await actionsContainer.acceptActionAtIndex(1, { type: 'repay', asset: repay.asset }) +// // await actionsContainer.acceptNextActionAction() + +// await repayDialog.expectSuccessPage([repay], fork) +// }) +// }) + +// test.describe('Position when borrowed asset was not in user wallet before', () => { +// const DAI_ADDRESS = '0x6B175474E89094C44Da98b954EedeAC495271d0F' +// const DAI_DECIMALS = 18 + +// const initialDeposits = { +// wstETH: 10, +// } as const + +// const daiToBorrow = 10_000 +// const daiDebtIncreaseIn1Epoch = 1.0000029476774694 // hardcoded for DAI borrow rate 5.53% +// const daiDebtIncreaseIn2Epochs = 1.0000058953636277 // hardcoded for DAI borrow rate 5.53% + +// let account: Address +// let myPortfolioPage: MyPortfolioPageObject +// let repayDialog: DialogPageObject + +// async function overrideDaiBalance({ balance, page }: { balance: BaseUnitNumber; page: Page }): Promise { +// await tenderlyRpcActions.setTokenBalance(fork.forkUrl, DAI_ADDRESS, account, balance) +// await page.reload() +// } + +// test.beforeEach(async ({ page }) => { +// ;({ account } = await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { wstETH: 10 }, +// }, +// })) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) +// await borrowPage.viewInMyPortfolioAction() + +// myPortfolioPage = new MyPortfolioPageObject(page) +// repayDialog = new DialogPageObject(page, headerRegExp) + +// await myPortfolioPage.expectHealthFactor('2.08') + +// // forcefully set browser time to the timestamp of borrow transaction +// const publicClient = createPublicClient({ +// transport: http(fork.forkUrl), +// }) +// const block = await publicClient.getBlock() +// await injectFixedDate(page, new Date(Number(block.timestamp) * 1000)) +// await page.reload() +// }) + +// test('can repay if balance is less than debt', async ({ page }) => { +// const newBalance = 0.9 * daiToBorrow +// const repay = { +// asset: 'DAI', +// amount: newBalance, +// } as const + +// await overrideDaiBalance({ +// balance: BaseUnitNumber(NormalizedUnitNumber(newBalance).shiftedBy(DAI_DECIMALS)), +// page, +// }) + +// await myPortfolioPage.clickRepayButtonAction(repay.asset) + +// await repayDialog.clickMaxAmountAction() +// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) +// await repayDialog.expectSuccessPage([repay], fork) + +// await repayDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.expectNonZeroAmountInBorrowTable(repay.asset) +// }) + +// test('can repay if balance gt debt but lt debt after 1 epoch', async ({ page }) => { +// // The test asserts and edge case where user's balance is greater than debt, but less than debt after 1 epoch (30 minutes). +// // In this case the current implementation does not try to repay the debt including the interest accrued in the following time period +// // before the repay transaction is mined. Only the current debt is repaid. Therefore after the repay transaction some dust +// // (accrued interest) is left in the user's borrow table. +// const repay = { +// asset: 'DAI', +// amount: daiToBorrow, +// } as const + +// const daiDebtIn1Epoch = NormalizedUnitNumber(daiToBorrow).times(daiDebtIncreaseIn1Epoch) +// // newBalance = (daiToBorrow, daiDebtIn1Epoch) / 2 - a number somewhere between daiToBorrow and daiDebtIn1Epoch +// const newBalance = BaseUnitNumber(daiDebtIn1Epoch.plus(daiToBorrow).div(2).shiftedBy(DAI_DECIMALS)) +// await overrideDaiBalance({ +// balance: newBalance, +// page, +// }) + +// await myPortfolioPage.clickRepayButtonAction(repay.asset) + +// await repayDialog.clickMaxAmountAction() +// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) +// await repayDialog.expectSuccessPage( +// [ +// { +// asset: repay.asset, +// amount: daiToBorrow, +// }, +// ], +// fork, +// ) + +// await repayDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.expectNonZeroAmountInBorrowTable(repay.asset) +// }) + +// test('can repay if balance gt debt after 1 epoch but lt debt after 2 epochs', async ({ page }) => { +// const repay = { +// asset: 'DAI', +// amount: daiToBorrow, +// } as const + +// const daiDebtIn1Epoch = NormalizedUnitNumber(daiToBorrow).times(daiDebtIncreaseIn1Epoch) +// const daiDebtIn2Epochs = NormalizedUnitNumber(daiToBorrow).times(daiDebtIncreaseIn2Epochs) +// // newBalance = (daiDebtIn1Epoch + daiDebtIn2Epochs) / 2 - a number somewhere between daiDebtIn1Epoch and daiDebtIn2Epochs +// const newBalance = BaseUnitNumber(daiDebtIn2Epochs.plus(daiDebtIn1Epoch).div(2).shiftedBy(DAI_DECIMALS)) +// await overrideDaiBalance({ +// balance: newBalance, +// page, +// }) + +// await myPortfolioPage.clickRepayButtonAction(repay.asset) + +// const repayDialog = new DialogPageObject(page, headerRegExp) +// await repayDialog.clickMaxAmountAction() +// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) +// await repayDialog.expectSuccessPage( +// [ +// { +// asset: repay.asset, +// amount: daiToBorrow, +// }, +// ], +// fork, +// ) + +// await repayDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.expectBorrowTable({ +// [repay.asset]: 0, +// }) +// }) +// }) + +// test.describe('Position with multiple borrowed assets', () => { +// const initialDeposits = { +// wstETH: initialBalances.wstETH, // deposit whole balance +// } as const + +// const wstETHBorrow = { +// asset: 'wstETH', +// amount: 10, +// } + +// const WETHBorrow = { +// asset: 'WETH', +// amount: 10, +// } + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ...initialBalances }, +// }, +// }) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositWithoutBorrowActions(initialDeposits) // deposit whole wallet balance +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.goToMyPortfolioAction() + +// // borrow wstETH and WETH +// const borrowDialog = new DialogPageObject(page, /Borrow */) +// const borrowActionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) +// // borrow wstETH +// await myPortfolioPage.clickBorrowButtonAction(wstETHBorrow.asset) +// await borrowDialog.fillAmountAction(wstETHBorrow.amount) +// await borrowActionsContainer.acceptAllActionsAction(1) +// await borrowDialog.viewInMyPortfolioAction() +// // borrow WETH +// await myPortfolioPage.clickBorrowButtonAction(WETHBorrow.asset) +// await borrowDialog.fillAmountAction(WETHBorrow.amount) +// await borrowActionsContainer.acceptAllActionsAction(1) +// await borrowDialog.viewInMyPortfolioAction() +// }) + +// test('can change asset to aToken', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickRepayButtonAction('wstETH') + +// const repayDialog = new DialogPageObject(page, headerRegExp) +// await repayDialog.selectAssetAction('awstETH') +// await repayDialog.expectSelectedAsset('awstETH') +// await repayDialog.expectDialogHeader('Repay wstETH') +// await repayDialog.expectHealthFactorBeforeVisible() +// }) + +// test('has correct action plan for repaying erc-20 using aToken', async ({ page }) => { +// const repay = { +// asset: 'awstETH', +// amount: 5, +// } as const + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickRepayButtonAction('wstETH') + +// const repayDialog = new DialogPageObject(page, headerRegExp) +// await repayDialog.selectAssetAction(repay.asset) +// await repayDialog.fillAmountAction(repay.amount) + +// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) +// await actionsContainer.expectActions([{ type: 'repay', asset: repay.asset }]) + +// await screenshot(repayDialog.getDialog(), 'repay-dialog-erc20-atoken-action-plan') +// }) + +// test('can repay erc-20 using aToken', async ({ page }) => { +// const repay = { +// asset: 'awstETH', +// amount: 5, +// } as const + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickRepayButtonAction('wstETH') + +// const repayDialog = new DialogPageObject(page, headerRegExp) +// await repayDialog.selectAssetAction(repay.asset) +// await repayDialog.fillAmountAction(repay.amount) + +// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(1) + +// await screenshot(repayDialog.getDialog(), 'repay-dialog-erc20-atoken-success') + +// await repayDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.expectBorrowTable({ +// wstETH: wstETHBorrow.amount - repay.amount, +// }) +// }) + +// test('has correct action plan for erc-20 repay with permits', async ({ page }) => { +// const repay = { +// asset: 'wstETH', +// amount: 5, +// } as const + +// const myPortfolioPage = new MyPortfolioPageObject(page) + +// await myPortfolioPage.clickRepayButtonAction(repay.asset) + +// const repayDialog = new DialogPageObject(page, headerRegExp) +// await repayDialog.fillAmountAction(repay.amount) +// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) +// await actionsContainer.expectActions([ +// { type: 'permit', asset: repay.asset }, +// { type: 'repay', asset: repay.asset }, +// ]) + +// await screenshot(repayDialog.getDialog(), 'repay-dialog-erc20-permit-action-plan') +// }) + +// test('has correct action plan for erc-20 repay with approves', async ({ page }) => { +// const repay = { +// asset: 'wstETH', +// amount: 5, +// } as const + +// const myPortfolioPage = new MyPortfolioPageObject(page) + +// await myPortfolioPage.clickRepayButtonAction(repay.asset) + +// const repayDialog = new DialogPageObject(page, headerRegExp) +// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) +// await actionsContainer.switchPreferPermitsAction() + +// await repayDialog.fillAmountAction(repay.amount) +// await actionsContainer.expectActions([ +// { type: 'approve', asset: repay.asset }, +// { type: 'repay', asset: repay.asset }, +// ]) + +// await screenshot(repayDialog.getDialog(), 'repay-dialog-erc20-approve-action-plan') +// }) + +// test('can repay erc-20 using permits', async ({ page }) => { +// const repay = { +// asset: 'wstETH', +// amount: 5, +// } as const + +// const myPortfolioPage = new MyPortfolioPageObject(page) + +// await myPortfolioPage.clickRepayButtonAction(repay.asset) + +// const repayDialog = new DialogPageObject(page, headerRegExp) +// await repayDialog.fillAmountAction(repay.amount) +// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) +// await repayDialog.expectSuccessPage([repay], fork) + +// await screenshot(repayDialog.getDialog(), 'repay-dialog-erc20-success') + +// await repayDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.expectBorrowTable({ +// [repay.asset]: wstETHBorrow.amount - repay.amount, +// }) +// }) + +// test('can repay erc-20 using approves', async ({ page }) => { +// const repay = { +// asset: 'wstETH', +// amount: 5, +// } as const + +// const myPortfolioPage = new MyPortfolioPageObject(page) + +// await myPortfolioPage.clickRepayButtonAction(repay.asset) + +// const repayDialog = new DialogPageObject(page, headerRegExp) +// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) +// await actionsContainer.switchPreferPermitsAction() +// await repayDialog.fillAmountAction(repay.amount) +// await actionsContainer.acceptAllActionsAction(2) +// await repayDialog.expectSuccessPage([repay], fork) + +// await repayDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.expectBorrowTable({ +// [repay.asset]: wstETHBorrow.amount - repay.amount, +// }) +// }) +// }) + +// test.describe('Form validation', () => { +// const initialDeposits = { +// wstETH: initialBalances.wstETH, // deposit whole balance +// } as const + +// const wstETHBorrow = { +// asset: 'wstETH', +// amount: 50, +// } + +// const wstETHDeposit = { +// asset: 'wstETH', +// amount: 50, +// } + +// const WETHBorrow = { +// asset: 'WETH', +// amount: 10, +// } + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ...initialBalances }, +// }, +// }) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositWithoutBorrowActions(initialDeposits) // deposit whole wallet balance +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.goToMyPortfolioAction() + +// // borrow wstETH and WETH +// const borrowDialog = new DialogPageObject(page, /Borrow */) +// const borrowActionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) +// // borrow wstETH +// await myPortfolioPage.clickBorrowButtonAction(wstETHBorrow.asset) +// await borrowDialog.fillAmountAction(wstETHBorrow.amount) +// await borrowActionsContainer.acceptAllActionsAction(1) +// await borrowDialog.viewInMyPortfolioAction() +// // borrow WETH +// await myPortfolioPage.clickBorrowButtonAction(WETHBorrow.asset) +// await borrowDialog.fillAmountAction(WETHBorrow.amount) +// await borrowDialog.clickAcknowledgeRisk() +// await borrowActionsContainer.acceptAllActionsAction(1) +// await borrowDialog.viewInMyPortfolioAction() + +// // deposit wstETH to have balance not enough to later repay debt using wstETH +// const depositDialog = new DialogPageObject(page, /Deposit */) +// const depositActionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await myPortfolioPage.clickDepositButtonAction(wstETHDeposit.asset) +// await depositDialog.fillAmountAction(wstETHDeposit.amount) +// await depositActionsContainer.acceptAllActionsAction(2) +// await depositDialog.viewInMyPortfolioAction() +// }) + +// test('cannot repay repay more than owe', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickRepayButtonAction(WETHBorrow.asset) + +// const repayDialog = new DialogPageObject(page, headerRegExp) +// await repayDialog.expectHealthFactorBefore('2.03') +// await repayDialog.fillAmountAction(WETHBorrow.amount + 1) +// await repayDialog.expectAssetInputError(repayValidationIssueToMessage['exceeds-debt']) + +// await screenshot(repayDialog.getDialog(), 'repay-dialog-more-than-owe') +// }) + +// test('cannot repay more than wallet balance', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickRepayButtonAction(wstETHBorrow.asset) + +// const repayDialog = new DialogPageObject(page, headerRegExp) +// await repayDialog.expectHealthFactorBefore('2.03') +// await repayDialog.fillAmountAction(1) +// await repayDialog.expectAssetInputError(repayValidationIssueToMessage['exceeds-balance']) + +// await screenshot(repayDialog.getDialog(), 'repay-dialog-more-than-balance') +// }) +// }) + +// // @note Add tests when problem with native asset deposit is solved +// test.describe('Position with native token debt', () => {}) + +// test.describe('Position with only deposit', () => { +// const initialDeposits = { +// wstETH: 10, +// } as const + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ...initialBalances }, +// }, +// }) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositWithoutBorrowActions(initialDeposits) +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.goToMyPortfolioAction() +// }) + +// test('nothing to repay', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.expectBorrowedAssetsToBeEmpty() +// await screenshot(page, 'repay-dialog-nothing-to-repay') +// }) + +// test('when repaying native asset retain some in wallet', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickBorrowButtonAction('WETH') + +// const borrowDialog = new DialogPageObject(page, /Borrow */) +// await borrowDialog.selectAssetAction('ETH') +// await borrowDialog.fillAmountAction(5) +// const borrowActionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) +// await borrowActionsContainer.acceptAllActionsAction(2) +// await borrowDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectBorrowTable({ WETH: 5 }) + +// await myPortfolioPage.clickRepayButtonAction('WETH') +// const repayDialog = new DialogPageObject(page, headerRegExp) +// await repayDialog.selectAssetAction('ETH') +// const repayActionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) +// // wait for select to switch to ETH +// await repayActionsContainer.expectActions([ +// { +// type: 'repay', +// asset: 'ETH', +// }, +// ]) +// await repayDialog.clickMaxAmountAction() + +// await repayDialog.expectInputValue('4.999') +// }) +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/deposit/SavingsDepositDialog.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/SavingsDepositDialog.test-e2e.ts index 2b57db00a..303428dc4 100644 --- a/packages/app/src/features/dialogs/savings/deposit/SavingsDepositDialog.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/deposit/SavingsDepositDialog.test-e2e.ts @@ -1,157 +1,157 @@ -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { GNOSIS_DEFAULT_BLOCK_NUMBER, LITE_PSM_ACTIONS_OPERABLE } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { base, gnosis, mainnet } from 'viem/chains' -import { SavingsDialogPageObject } from '../common/e2e/SavingsDialog.PageObject' - -test.describe('Savings deposit dialog', () => { - test.describe('Mainnet', () => { - const fork = setupFork({ - blockNumber: LITE_PSM_ACTIONS_OPERABLE, - chainId: mainnet.id, - useTenderlyVnet: true, - }) - - let depositDialog: SavingsDialogPageObject - let savingsPage: SavingsPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - DAI: 10_000, - USDC: 10_000, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - await savingsPage.clickStartSavingButtonAction() - - depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) - }) - - test('can switch between tokens', async () => { - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - - await depositDialog.fillAmountAction(1000) - await actionsContainer.expectEnabledActionAtIndex(0) - await actionsContainer.expectActions([ - { type: 'approve', asset: 'DAI' }, - { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sDAI' }, - ]) - - await depositDialog.selectAssetAction('USDC') - await depositDialog.fillAmountAction(1000) - await actionsContainer.expectEnabledActionAtIndex(0) - await actionsContainer.expectActions([ - { type: 'approve', asset: 'USDC' }, - { type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sDAI' }, - ]) - - await depositDialog.selectAssetAction('DAI') - await depositDialog.fillAmountAction(1000) - await actionsContainer.expectEnabledActionAtIndex(0) - await actionsContainer.expectActions([ - { type: 'approve', asset: 'DAI' }, - { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sDAI' }, - ]) - }) - - test('can select only supported assets', async () => { - await depositDialog.openAssetSelectorAction() - await depositDialog.expectAssetSelectorOptions(['DAI', 'USDC']) - }) - }) - - test.describe('Gnosis', () => { - const fork = setupFork({ blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let depositDialog: SavingsDialogPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - XDAI: 100, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - await savingsPage.clickStartSavingButtonAction() - - depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) - }) - - test('can select only supported assets', async () => { - await depositDialog.openAssetSelectorAction() - await depositDialog.expectAssetSelectorOptions(['XDAI']) - }) - }) - - test.describe('Base', () => { - const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) - - let depositDialog: SavingsDialogPageObject - let savingsPage: SavingsPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - USDC: 1000, - USDS: 10_000, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - await savingsPage.clickStartSavingButtonAction() - - depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) - }) - - test('can switch between tokens', async () => { - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - - await depositDialog.fillAmountAction(1000) - await actionsContainer.expectEnabledActionAtIndex(0) - await actionsContainer.expectActions([ - { type: 'approve', asset: 'USDS' }, - { type: 'depositToSavings', asset: 'USDS', savingsAsset: 'sUSDS' }, - ]) - - await depositDialog.selectAssetAction('USDC') - await depositDialog.fillAmountAction(1000) - await actionsContainer.expectEnabledActionAtIndex(0) - await actionsContainer.expectActions([ - { type: 'approve', asset: 'USDC' }, - { type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sUSDS' }, - ]) - - await depositDialog.selectAssetAction('USDS') - await depositDialog.fillAmountAction(1000) - await actionsContainer.expectEnabledActionAtIndex(0) - await actionsContainer.expectActions([ - { type: 'approve', asset: 'USDS' }, - { type: 'depositToSavings', asset: 'USDS', savingsAsset: 'sUSDS' }, - ]) - }) - - test('can select only supported assets', async () => { - await depositDialog.openAssetSelectorAction() - await depositDialog.expectAssetSelectorOptions(['USDC', 'USDS']) - }) - }) -}) +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { GNOSIS_DEFAULT_BLOCK_NUMBER, LITE_PSM_ACTIONS_OPERABLE } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { base, gnosis, mainnet } from 'viem/chains' +// import { SavingsDialogPageObject } from '../common/e2e/SavingsDialog.PageObject' + +// test.describe('Savings deposit dialog', () => { +// test.describe('Mainnet', () => { +// const fork = setupFork({ +// blockNumber: LITE_PSM_ACTIONS_OPERABLE, +// chainId: mainnet.id, +// useTenderlyVnet: true, +// }) + +// let depositDialog: SavingsDialogPageObject +// let savingsPage: SavingsPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// DAI: 10_000, +// USDC: 10_000, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickStartSavingButtonAction() + +// depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) +// }) + +// test('can switch between tokens', async () => { +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) + +// await depositDialog.fillAmountAction(1000) +// await actionsContainer.expectEnabledActionAtIndex(0) +// await actionsContainer.expectActions([ +// { type: 'approve', asset: 'DAI' }, +// { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sDAI' }, +// ]) + +// await depositDialog.selectAssetAction('USDC') +// await depositDialog.fillAmountAction(1000) +// await actionsContainer.expectEnabledActionAtIndex(0) +// await actionsContainer.expectActions([ +// { type: 'approve', asset: 'USDC' }, +// { type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sDAI' }, +// ]) + +// await depositDialog.selectAssetAction('DAI') +// await depositDialog.fillAmountAction(1000) +// await actionsContainer.expectEnabledActionAtIndex(0) +// await actionsContainer.expectActions([ +// { type: 'approve', asset: 'DAI' }, +// { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sDAI' }, +// ]) +// }) + +// test('can select only supported assets', async () => { +// await depositDialog.openAssetSelectorAction() +// await depositDialog.expectAssetSelectorOptions(['DAI', 'USDC']) +// }) +// }) + +// test.describe('Gnosis', () => { +// const fork = setupFork({ blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let depositDialog: SavingsDialogPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// XDAI: 100, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickStartSavingButtonAction() + +// depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) +// }) + +// test('can select only supported assets', async () => { +// await depositDialog.openAssetSelectorAction() +// await depositDialog.expectAssetSelectorOptions(['XDAI']) +// }) +// }) + +// test.describe('Base', () => { +// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) + +// let depositDialog: SavingsDialogPageObject +// let savingsPage: SavingsPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// USDC: 1000, +// USDS: 10_000, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickStartSavingButtonAction() + +// depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) +// }) + +// test('can switch between tokens', async () => { +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) + +// await depositDialog.fillAmountAction(1000) +// await actionsContainer.expectEnabledActionAtIndex(0) +// await actionsContainer.expectActions([ +// { type: 'approve', asset: 'USDS' }, +// { type: 'depositToSavings', asset: 'USDS', savingsAsset: 'sUSDS' }, +// ]) + +// await depositDialog.selectAssetAction('USDC') +// await depositDialog.fillAmountAction(1000) +// await actionsContainer.expectEnabledActionAtIndex(0) +// await actionsContainer.expectActions([ +// { type: 'approve', asset: 'USDC' }, +// { type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sUSDS' }, +// ]) + +// await depositDialog.selectAssetAction('USDS') +// await depositDialog.fillAmountAction(1000) +// await actionsContainer.expectEnabledActionAtIndex(0) +// await actionsContainer.expectActions([ +// { type: 'approve', asset: 'USDS' }, +// { type: 'depositToSavings', asset: 'USDS', savingsAsset: 'sUSDS' }, +// ]) +// }) + +// test('can select only supported assets', async () => { +// await depositDialog.openAssetSelectorAction() +// await depositDialog.expectAssetSelectorOptions(['USDC', 'USDS']) +// }) +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/base/DepositUSDC.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/base/DepositUSDC.test-e2e.ts index a9e4461eb..25de60173 100644 --- a/packages/app/src/features/dialogs/savings/deposit/e2e/base/DepositUSDC.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/deposit/e2e/base/DepositUSDC.test-e2e.ts @@ -1,76 +1,76 @@ -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { base } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { base } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -test.describe('Deposit USDC', () => { - const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) +// test.describe('Deposit USDC', () => { +// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let depositDialog: SavingsDialogPageObject +// let savingsPage: SavingsPageObject +// let depositDialog: SavingsDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDC: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// USDC: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) - await savingsPage.clickDepositButtonAction('USDC') +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickDepositButtonAction('USDC') - depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) - await depositDialog.fillAmountAction(10_000) - }) +// depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) +// await depositDialog.fillAmountAction(10_000) +// }) - test('has correct action plan', async () => { - await depositDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'USDC' }, - { type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sUSDS' }, - ]) - }) +// test('has correct action plan', async () => { +// await depositDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'USDC' }, +// { type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sUSDS' }, +// ]) +// }) - test('displays transaction overview', async () => { - await depositDialog.expectNativeRouteTransactionOverview({ - apy: { - value: '6.50%', - description: 'Earn ~650.00 USDS/year', - }, - routeItems: [ - { - tokenAmount: '10,000.00 USDC', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '9,911.77 sUSDS', - tokenUsdValue: '$10,000.00', - }, - ], - outcome: '9,911.77 sUSDS', - outcomeUsd: '$10,000.00', - }) - }) +// test('displays transaction overview', async () => { +// await depositDialog.expectNativeRouteTransactionOverview({ +// apy: { +// value: '6.50%', +// description: 'Earn ~650.00 USDS/year', +// }, +// routeItems: [ +// { +// tokenAmount: '10,000.00 USDC', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '9,911.77 sUSDS', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// outcome: '9,911.77 sUSDS', +// outcomeUsd: '$10,000.00', +// }) +// }) - test('executes deposit', async () => { - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) +// test('executes deposit', async () => { +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) - await depositDialog.expectSuccessPage() - await depositDialog.clickBackToSavingsButton() +// await depositDialog.expectSuccessPage() +// await depositDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,911.77 sUSDS', estimatedUsdsValue: '10,000' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') - }) -}) +// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,911.77 sUSDS', estimatedUsdsValue: '10,000' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/base/DepositUSDS.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/base/DepositUSDS.test-e2e.ts index 2e4952d86..6fcb732b1 100644 --- a/packages/app/src/features/dialogs/savings/deposit/e2e/base/DepositUSDS.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/deposit/e2e/base/DepositUSDS.test-e2e.ts @@ -1,73 +1,73 @@ -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { base } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { base } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -test.describe('Deposit USDS', () => { - const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let depositDialog: SavingsDialogPageObject +// test.describe('Deposit USDS', () => { +// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let depositDialog: SavingsDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDS: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// USDS: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) - await savingsPage.clickDepositButtonAction('USDS') +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickDepositButtonAction('USDS') - depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) - await depositDialog.fillAmountAction(10_000) - }) +// depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) +// await depositDialog.fillAmountAction(10_000) +// }) - test('has correct action plan', async () => { - await depositDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'USDS' }, - { type: 'depositToSavings', asset: 'USDS', savingsAsset: 'sUSDS' }, - ]) - }) +// test('has correct action plan', async () => { +// await depositDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'USDS' }, +// { type: 'depositToSavings', asset: 'USDS', savingsAsset: 'sUSDS' }, +// ]) +// }) - test('displays transaction overview', async () => { - await depositDialog.expectNativeRouteTransactionOverview({ - apy: { - value: '6.50%', - description: 'Earn ~650.00 USDS/year', - }, - routeItems: [ - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '9,911.77 sUSDS', - tokenUsdValue: '$10,000.00', - }, - ], - outcome: '9,911.77 sUSDS', - outcomeUsd: '$10,000.00', - }) +// test('displays transaction overview', async () => { +// await depositDialog.expectNativeRouteTransactionOverview({ +// apy: { +// value: '6.50%', +// description: 'Earn ~650.00 USDS/year', +// }, +// routeItems: [ +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '9,911.77 sUSDS', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// outcome: '9,911.77 sUSDS', +// outcomeUsd: '$10,000.00', +// }) - await depositDialog.expectUpgradeSwitchToBeHidden() - }) +// await depositDialog.expectUpgradeSwitchToBeHidden() +// }) - test('executes deposit', async () => { - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2, fork) +// test('executes deposit', async () => { +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2, fork) - await depositDialog.expectSuccessPage() - await depositDialog.clickBackToSavingsButton() +// await depositDialog.expectSuccessPage() +// await depositDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,911.77 sUSDS', estimatedUsdsValue: '10,000' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') - }) -}) +// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,911.77 sUSDS', estimatedUsdsValue: '10,000' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/gnosis/DepositXDAI.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/gnosis/DepositXDAI.test-e2e.ts index 375097842..e08da542e 100644 --- a/packages/app/src/features/dialogs/savings/deposit/e2e/gnosis/DepositXDAI.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/deposit/e2e/gnosis/DepositXDAI.test-e2e.ts @@ -1,74 +1,74 @@ -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { gnosis } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { gnosis } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -test.describe('Deposit XDAI on Gnosis', () => { - const fork = setupFork({ - blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, - chainId: gnosis.id, - useTenderlyVnet: true, - }) - let savingsPage: SavingsPageObject - let depositDialog: SavingsDialogPageObject +// test.describe('Deposit XDAI on Gnosis', () => { +// const fork = setupFork({ +// blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, +// chainId: gnosis.id, +// useTenderlyVnet: true, +// }) +// let savingsPage: SavingsPageObject +// let depositDialog: SavingsDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - XDAI: 10_100, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// XDAI: 10_100, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) - await savingsPage.clickDepositButtonAction('XDAI') +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickDepositButtonAction('XDAI') - depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) - await depositDialog.fillAmountAction(10_000) - }) +// depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) +// await depositDialog.fillAmountAction(10_000) +// }) - test('uses native sDai deposit', async () => { - await depositDialog.actionsContainer.expectActions([ - { type: 'depositToSavings', asset: 'XDAI', savingsAsset: 'sDAI' }, - ]) - }) +// test('uses native sDai deposit', async () => { +// await depositDialog.actionsContainer.expectActions([ +// { type: 'depositToSavings', asset: 'XDAI', savingsAsset: 'sDAI' }, +// ]) +// }) - test('displays transaction overview', async () => { - await depositDialog.expectNativeRouteTransactionOverview({ - apy: { - value: '10.60%', - description: 'Earn ~1,059.80 XDAI/year', - }, - routeItems: [ - { - tokenAmount: '10,000.00 XDAI', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '9,192.79 sDAI', - tokenUsdValue: '$10,000.00', - }, - ], - outcome: '9,192.79 sDAI', - outcomeUsd: '$10,000.00', - }) - }) +// test('displays transaction overview', async () => { +// await depositDialog.expectNativeRouteTransactionOverview({ +// apy: { +// value: '10.60%', +// description: 'Earn ~1,059.80 XDAI/year', +// }, +// routeItems: [ +// { +// tokenAmount: '10,000.00 XDAI', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '9,192.79 sDAI', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// outcome: '9,192.79 sDAI', +// outcomeUsd: '$10,000.00', +// }) +// }) - test('executes deposit', async () => { - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(1, fork) +// test('executes deposit', async () => { +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(1, fork) - await depositDialog.expectSuccessPage() - await depositDialog.clickBackToSavingsButton() +// await depositDialog.expectSuccessPage() +// await depositDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '9,192.32 sDAI', estimatedDaiValue: '9,999.48' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('XDAI', '100') - }) -}) +// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '9,192.32 sDAI', estimatedDaiValue: '9,999.48' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('XDAI', '100') +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositDAI.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositDAI.test-e2e.ts index ddc8a5aef..f9d0e7f27 100644 --- a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositDAI.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositDAI.test-e2e.ts @@ -1,157 +1,157 @@ -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' - -test.describe('Deposit DAI', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let depositDialog: SavingsDialogPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - DAI: 10_000, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - await savingsPage.clickDepositButtonAction('DAI') - - depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) - await depositDialog.fillAmountAction(10_000) - }) - - test.describe('To sUSDS', () => { - test('uses PSM actions native deposit', async () => { - await depositDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'DAI' }, - { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sUSDS' }, - ]) - }) - - test('displays transaction overview', async () => { - await depositDialog.expectNativeRouteTransactionOverview({ - apy: { - value: '6.25%', - description: 'Earn ~625.00 USDS/year', - }, - routeItems: [ - { - tokenAmount: '10,000.00 DAI', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '9,999.77 sUSDS', - tokenUsdValue: '$10,000.00', - }, - ], - outcome: '9,999.77 sUSDS', - outcomeUsd: '$10,000.00', - }) - }) - - test('executes deposit', async () => { - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) - - await depositDialog.expectSuccessPage() - await depositDialog.clickBackToSavingsButton() - - await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,999.77 sUSDS', estimatedUsdsValue: '10,000' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') - }) - }) - - test.describe('To sDAI', () => { - test.beforeEach(async () => { - await depositDialog.clickUpgradeSwitch() - }) - - test('uses PSM actions native deposit', async () => { - await depositDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'DAI' }, - { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sDAI' }, - ]) - }) - - test('displays transaction overview', async () => { - await depositDialog.expectNativeRouteTransactionOverview({ - apy: { - value: '6.00%', - description: 'Earn ~600.00 DAI/year', - }, - routeItems: [ - { - tokenAmount: '10,000.00 DAI', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '9,020.46 sDAI', - tokenUsdValue: '$10,000.00', - }, - ], - outcome: '9,020.46 sDAI', - outcomeUsd: '$10,000.00', - }) - }) - - test('executes deposit', async () => { - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) - - await depositDialog.expectSuccessPage() - await depositDialog.clickBackToSavingsButton() - - await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '9,020.46 sDAI', estimatedDaiValue: '10,000' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') - }) - }) - - test('executes sDai deposit after switching from already approved sUsds', async () => { - // accepting only approve - await depositDialog.actionsContainer.acceptAllActionsAction(1) - await depositDialog.actionsContainer.expectEnabledActionAtIndex(1) - // switching to sDai deposit when already approved sUsds - await depositDialog.clickUpgradeSwitch() - // actions should reset and new approval is required - await depositDialog.actionsContainer.acceptAllActionsAction(2) - - await depositDialog.expectSuccessPage() - await depositDialog.clickBackToSavingsButton() - - await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '9,020.46 sDAI', estimatedDaiValue: '10,000' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') - }) - - test('executes sUsds deposit after switching from already approved sUsds and back', async () => { - // accepting only approve - await depositDialog.actionsContainer.acceptAllActionsAction(1) - await depositDialog.actionsContainer.expectEnabledActionAtIndex(1) - // switching to sDai deposit and back to sUsds - await depositDialog.clickUpgradeSwitch() - await depositDialog.actionsContainer.expectEnabledActionAtIndex(0) - await depositDialog.clickUpgradeSwitch() - // approval should be already successful, only deposit needed - await depositDialog.actionsContainer.acceptActionAtIndex(1) - - await depositDialog.expectSuccessPage() - await depositDialog.clickBackToSavingsButton() - - await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,999.77 sUSDS', estimatedUsdsValue: '10,000' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') - }) -}) +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' + +// test.describe('Deposit DAI', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let depositDialog: SavingsDialogPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// DAI: 10_000, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickDepositButtonAction('DAI') + +// depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) +// await depositDialog.fillAmountAction(10_000) +// }) + +// test.describe('To sUSDS', () => { +// test('uses PSM actions native deposit', async () => { +// await depositDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'DAI' }, +// { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sUSDS' }, +// ]) +// }) + +// test('displays transaction overview', async () => { +// await depositDialog.expectNativeRouteTransactionOverview({ +// apy: { +// value: '6.25%', +// description: 'Earn ~625.00 USDS/year', +// }, +// routeItems: [ +// { +// tokenAmount: '10,000.00 DAI', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '9,999.77 sUSDS', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// outcome: '9,999.77 sUSDS', +// outcomeUsd: '$10,000.00', +// }) +// }) + +// test('executes deposit', async () => { +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) + +// await depositDialog.expectSuccessPage() +// await depositDialog.clickBackToSavingsButton() + +// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,999.77 sUSDS', estimatedUsdsValue: '10,000' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') +// }) +// }) + +// test.describe('To sDAI', () => { +// test.beforeEach(async () => { +// await depositDialog.clickUpgradeSwitch() +// }) + +// test('uses PSM actions native deposit', async () => { +// await depositDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'DAI' }, +// { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sDAI' }, +// ]) +// }) + +// test('displays transaction overview', async () => { +// await depositDialog.expectNativeRouteTransactionOverview({ +// apy: { +// value: '6.00%', +// description: 'Earn ~600.00 DAI/year', +// }, +// routeItems: [ +// { +// tokenAmount: '10,000.00 DAI', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '9,020.46 sDAI', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// outcome: '9,020.46 sDAI', +// outcomeUsd: '$10,000.00', +// }) +// }) + +// test('executes deposit', async () => { +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) + +// await depositDialog.expectSuccessPage() +// await depositDialog.clickBackToSavingsButton() + +// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '9,020.46 sDAI', estimatedDaiValue: '10,000' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') +// }) +// }) + +// test('executes sDai deposit after switching from already approved sUsds', async () => { +// // accepting only approve +// await depositDialog.actionsContainer.acceptAllActionsAction(1) +// await depositDialog.actionsContainer.expectEnabledActionAtIndex(1) +// // switching to sDai deposit when already approved sUsds +// await depositDialog.clickUpgradeSwitch() +// // actions should reset and new approval is required +// await depositDialog.actionsContainer.acceptAllActionsAction(2) + +// await depositDialog.expectSuccessPage() +// await depositDialog.clickBackToSavingsButton() + +// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '9,020.46 sDAI', estimatedDaiValue: '10,000' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') +// }) + +// test('executes sUsds deposit after switching from already approved sUsds and back', async () => { +// // accepting only approve +// await depositDialog.actionsContainer.acceptAllActionsAction(1) +// await depositDialog.actionsContainer.expectEnabledActionAtIndex(1) +// // switching to sDai deposit and back to sUsds +// await depositDialog.clickUpgradeSwitch() +// await depositDialog.actionsContainer.expectEnabledActionAtIndex(0) +// await depositDialog.clickUpgradeSwitch() +// // approval should be already successful, only deposit needed +// await depositDialog.actionsContainer.acceptActionAtIndex(1) + +// await depositDialog.expectSuccessPage() +// await depositDialog.clickBackToSavingsButton() + +// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,999.77 sUSDS', estimatedUsdsValue: '10,000' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDC.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDC.test-e2e.ts index 9ac008573..b6d3a53dd 100644 --- a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDC.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDC.test-e2e.ts @@ -1,127 +1,127 @@ -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -test.describe('Deposit USDC', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let depositDialog: SavingsDialogPageObject +// test.describe('Deposit USDC', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let depositDialog: SavingsDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDC: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// USDC: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) - await savingsPage.clickDepositButtonAction('USDC') +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickDepositButtonAction('USDC') - depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) - await depositDialog.fillAmountAction(10_000) - }) +// depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) +// await depositDialog.fillAmountAction(10_000) +// }) - test.describe('To sUSDS', () => { - test('uses PSM actions native deposit', async () => { - await depositDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'USDC' }, - { type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sUSDS' }, - ]) - }) +// test.describe('To sUSDS', () => { +// test('uses PSM actions native deposit', async () => { +// await depositDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'USDC' }, +// { type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sUSDS' }, +// ]) +// }) - test('displays transaction overview', async () => { - await depositDialog.expectNativeRouteTransactionOverview({ - apy: { - value: '6.25%', - description: 'Earn ~625.00 USDS/year', - }, - routeItems: [ - { - tokenAmount: '10,000.00 USDC', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '9,999.77 sUSDS', - tokenUsdValue: '$10,000.00', - }, - ], - outcome: '9,999.77 sUSDS', - outcomeUsd: '$10,000.00', - }) - }) +// test('displays transaction overview', async () => { +// await depositDialog.expectNativeRouteTransactionOverview({ +// apy: { +// value: '6.25%', +// description: 'Earn ~625.00 USDS/year', +// }, +// routeItems: [ +// { +// tokenAmount: '10,000.00 USDC', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '9,999.77 sUSDS', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// outcome: '9,999.77 sUSDS', +// outcomeUsd: '$10,000.00', +// }) +// }) - test('executes deposit', async () => { - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) +// test('executes deposit', async () => { +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) - await depositDialog.expectSuccessPage() - await depositDialog.clickBackToSavingsButton() +// await depositDialog.expectSuccessPage() +// await depositDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,999.77 sUSDS', estimatedUsdsValue: '10,000' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') - }) - }) +// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,999.77 sUSDS', estimatedUsdsValue: '10,000' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') +// }) +// }) - test.describe('To sDAI', () => { - test.beforeEach(async () => { - await depositDialog.clickUpgradeSwitch() - }) +// test.describe('To sDAI', () => { +// test.beforeEach(async () => { +// await depositDialog.clickUpgradeSwitch() +// }) - test('uses PSM actions native deposit', async () => { - await depositDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'USDC' }, - { type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sDAI' }, - ]) - }) +// test('uses PSM actions native deposit', async () => { +// await depositDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'USDC' }, +// { type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sDAI' }, +// ]) +// }) - test('displays transaction overview', async () => { - await depositDialog.expectNativeRouteTransactionOverview({ - apy: { - value: '6.00%', - description: 'Earn ~600.00 DAI/year', - }, - routeItems: [ - { - tokenAmount: '10,000.00 USDC', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '10,000.00 DAI', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '9,020.46 sDAI', - tokenUsdValue: '$10,000.00', - }, - ], - outcome: '9,020.46 sDAI', - outcomeUsd: '$10,000.00', - }) - }) +// test('displays transaction overview', async () => { +// await depositDialog.expectNativeRouteTransactionOverview({ +// apy: { +// value: '6.00%', +// description: 'Earn ~600.00 DAI/year', +// }, +// routeItems: [ +// { +// tokenAmount: '10,000.00 USDC', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '10,000.00 DAI', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '9,020.46 sDAI', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// outcome: '9,020.46 sDAI', +// outcomeUsd: '$10,000.00', +// }) +// }) - test('executes deposit', async () => { - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) +// test('executes deposit', async () => { +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) - await depositDialog.expectSuccessPage() - await depositDialog.clickBackToSavingsButton() +// await depositDialog.expectSuccessPage() +// await depositDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '9,020.46 sDAI', estimatedDaiValue: '10,000' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') - }) - }) -}) +// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '9,020.46 sDAI', estimatedDaiValue: '10,000' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') +// }) +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDS.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDS.test-e2e.ts index 5b78e2812..31e924a25 100644 --- a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDS.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDS.test-e2e.ts @@ -1,74 +1,74 @@ -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -test.describe('Deposit USDS', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let depositDialog: SavingsDialogPageObject +// test.describe('Deposit USDS', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let depositDialog: SavingsDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDS: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// USDS: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) - await savingsPage.clickDepositButtonAction('USDS') +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickDepositButtonAction('USDS') - depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) - await depositDialog.fillAmountAction(10_000) - }) +// depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) +// await depositDialog.fillAmountAction(10_000) +// }) - test('uses native sUSDS deposit', async () => { - await depositDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'USDS' }, - { type: 'depositToSavings', asset: 'USDS', savingsAsset: 'sUSDS' }, - ]) - }) +// test('uses native sUSDS deposit', async () => { +// await depositDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'USDS' }, +// { type: 'depositToSavings', asset: 'USDS', savingsAsset: 'sUSDS' }, +// ]) +// }) - test('displays transaction overview', async () => { - await depositDialog.expectNativeRouteTransactionOverview({ - apy: { - value: '6.25%', - description: 'Earn ~625.00 USDS/year', - }, - routeItems: [ - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '9,999.77 sUSDS', - tokenUsdValue: '$10,000.00', - }, - ], - outcome: '9,999.77 sUSDS', - outcomeUsd: '$10,000.00', - }) +// test('displays transaction overview', async () => { +// await depositDialog.expectNativeRouteTransactionOverview({ +// apy: { +// value: '6.25%', +// description: 'Earn ~625.00 USDS/year', +// }, +// routeItems: [ +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '9,999.77 sUSDS', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// outcome: '9,999.77 sUSDS', +// outcomeUsd: '$10,000.00', +// }) - await depositDialog.expectUpgradeSwitchToBeHidden() - }) +// await depositDialog.expectUpgradeSwitchToBeHidden() +// }) - test('executes deposit', async () => { - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2, fork) +// test('executes deposit', async () => { +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2, fork) - await depositDialog.expectSuccessPage() - await depositDialog.clickBackToSavingsButton() +// await depositDialog.expectSuccessPage() +// await depositDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,999.77 sUSDS', estimatedUsdsValue: '10,000' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') - }) -}) +// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,999.77 sUSDS', estimatedUsdsValue: '10,000' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/General.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/General.test-e2e.ts index 2e2211bfd..7fc03389e 100644 --- a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/General.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/General.test-e2e.ts @@ -1,60 +1,60 @@ -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { LITE_PSM_ACTIONS_OPERABLE } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' - -test.describe('General dialog behavior', () => { - const fork = setupFork({ - blockNumber: LITE_PSM_ACTIONS_OPERABLE, - chainId: mainnet.id, - useTenderlyVnet: true, - }) - - test('can switch between tokens', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - DAI: 100, - USDC: 100, - }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - - await savingsPage.clickDepositButtonAction('DAI') - - const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) - const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - - await depositDialog.fillAmountAction(100) - await actionsContainer.expectEnabledActionAtIndex(0) - await actionsContainer.expectActions([ - { type: 'approve', asset: 'DAI' }, - { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sDAI' }, - ]) - - await depositDialog.selectAssetAction('USDC') - await depositDialog.fillAmountAction(100) - await actionsContainer.expectEnabledActionAtIndex(0) - await actionsContainer.expectActions([ - { type: 'approve', asset: 'USDC' }, - { type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sDAI' }, - ]) - - await depositDialog.selectAssetAction('DAI') - await depositDialog.fillAmountAction(100) - await actionsContainer.expectEnabledActionAtIndex(0) - await actionsContainer.expectActions([ - { type: 'approve', asset: 'DAI' }, - { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sDAI' }, - ]) - }) -}) +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { LITE_PSM_ACTIONS_OPERABLE } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' + +// test.describe('General dialog behavior', () => { +// const fork = setupFork({ +// blockNumber: LITE_PSM_ACTIONS_OPERABLE, +// chainId: mainnet.id, +// useTenderlyVnet: true, +// }) + +// test('can switch between tokens', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// DAI: 100, +// USDC: 100, +// }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// await savingsPage.clickDepositButtonAction('DAI') + +// const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) +// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) + +// await depositDialog.fillAmountAction(100) +// await actionsContainer.expectEnabledActionAtIndex(0) +// await actionsContainer.expectActions([ +// { type: 'approve', asset: 'DAI' }, +// { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sDAI' }, +// ]) + +// await depositDialog.selectAssetAction('USDC') +// await depositDialog.fillAmountAction(100) +// await actionsContainer.expectEnabledActionAtIndex(0) +// await actionsContainer.expectActions([ +// { type: 'approve', asset: 'USDC' }, +// { type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sDAI' }, +// ]) + +// await depositDialog.selectAssetAction('DAI') +// await depositDialog.fillAmountAction(100) +// await actionsContainer.expectEnabledActionAtIndex(0) +// await actionsContainer.expectActions([ +// { type: 'approve', asset: 'DAI' }, +// { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sDAI' }, +// ]) +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/Validation.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/Validation.test-e2e.ts index 9b68080f1..bb6a23a62 100644 --- a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/Validation.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/Validation.test-e2e.ts @@ -1,89 +1,89 @@ -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -import { depositValidationIssueToMessage } from '../../logic/validation' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +// import { depositValidationIssueToMessage } from '../../logic/validation' -test.describe('Validation', () => { - const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) - let savingsPage: SavingsPageObject - let depositDialog: SavingsDialogPageObject +// test.describe('Validation', () => { +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) +// let savingsPage: SavingsPageObject +// let depositDialog: SavingsDialogPageObject - test.describe('Input value exceeds balance', () => { - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - DAI: 100, - }, - }, - }) +// test.describe('Input value exceeds balance', () => { +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// DAI: 100, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) - await savingsPage.clickDepositButtonAction('DAI') +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickDepositButtonAction('DAI') - depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) - await depositDialog.fillAmountAction(10_000) - }) +// depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) +// await depositDialog.fillAmountAction(10_000) +// }) - test('displays validation error', async () => { - await depositDialog.expectAssetInputError(depositValidationIssueToMessage['exceeds-balance']) - }) +// test('displays validation error', async () => { +// await depositDialog.expectAssetInputError(depositValidationIssueToMessage['exceeds-balance']) +// }) - test('actions are disabled', async () => { - await depositDialog.actionsContainer.expectDisabledActions([ - { type: 'approve', asset: 'DAI' }, - { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sDAI' }, - ]) - }) +// test('actions are disabled', async () => { +// await depositDialog.actionsContainer.expectDisabledActions([ +// { type: 'approve', asset: 'DAI' }, +// { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sDAI' }, +// ]) +// }) - test('displays sensible tx overview', async () => { - await depositDialog.expectNativeRouteTransactionOverview({ - apy: { - value: '5.00%', - description: 'Earn ~500.00 DAI/year', - }, - routeItems: [ - { - tokenAmount: '10,000.00 DAI', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '9,332.66 sDAI', - tokenUsdValue: '$10,000.00', - }, - ], - outcome: '9,332.66 sDAI', - outcomeUsd: '$10,000.00', - }) - }) - }) +// test('displays sensible tx overview', async () => { +// await depositDialog.expectNativeRouteTransactionOverview({ +// apy: { +// value: '5.00%', +// description: 'Earn ~500.00 DAI/year', +// }, +// routeItems: [ +// { +// tokenAmount: '10,000.00 DAI', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '9,332.66 sDAI', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// outcome: '9,332.66 sDAI', +// outcomeUsd: '$10,000.00', +// }) +// }) +// }) - test('displays validation error for dirty input with 0 value', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - DAI: 100, - }, - }, - }) +// test('displays validation error for dirty input with 0 value', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// DAI: 100, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) - await savingsPage.clickDepositButtonAction('DAI') - depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickDepositButtonAction('DAI') +// depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) - await depositDialog.fillAmountAction(10) - await depositDialog.fillAmountAction(0) +// await depositDialog.fillAmountAction(10) +// await depositDialog.fillAmountAction(0) - await depositDialog.expectAssetInputError(depositValidationIssueToMessage['value-not-positive']) - }) -}) +// await depositDialog.expectAssetInputError(depositValidationIssueToMessage['value-not-positive']) +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/migrate/downgrade/e2e/UsdsToDai.test-e2e.ts b/packages/app/src/features/dialogs/savings/migrate/downgrade/e2e/UsdsToDai.test-e2e.ts index 7184de669..a536683ef 100644 --- a/packages/app/src/features/dialogs/savings/migrate/downgrade/e2e/UsdsToDai.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/migrate/downgrade/e2e/UsdsToDai.test-e2e.ts @@ -1,104 +1,104 @@ -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { DowngradeDialogPageObject } from '../DowngradeDialog.PageObject' - -test.describe('Downgrade USDS to DAI', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - - test('downgrade to DAI is disabled when USDS balance is 0', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { USDS: 0 }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - - await savingsPage.expectDowngradeToDaiToBeDisabled() - }) - - test('uses downgrade action', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { USDS: 10_000 }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - - await savingsPage.clickDowngradeUsdsToDaiOption() - - const downgradeDialog = new DowngradeDialogPageObject(page) - await downgradeDialog.fillAmountAction(100) - - await downgradeDialog.actionsContainer.expectEnabledActionAtIndex(0) - await downgradeDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'USDS' }, - { type: 'downgrade', fromToken: 'USDS', toToken: 'DAI' }, - ]) - }) - - test('displays transaction overview', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { USDS: 10_000 }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - - await savingsPage.clickDowngradeUsdsToDaiOption() - - const downgradeDialog = new DowngradeDialogPageObject(page) - await downgradeDialog.fillAmountAction(100) - - await downgradeDialog.expectTransactionOverview({ - routeItems: [ - { - tokenAmount: '100.00 USDS', - tokenUsdValue: '$100.00', - }, - { - tokenAmount: '100.00 DAI', - tokenUsdValue: '$100.00', - }, - ], - outcome: '100.00 DAI', - outcomeUsd: '$100.00', - }) - }) - - test('executes transaction', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { USDS: 10_000 }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - - await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') - await savingsPage.clickDowngradeUsdsToDaiOption() - - const downgradeDialog = new DowngradeDialogPageObject(page) - await downgradeDialog.fillAmountAction(10_000) - - await downgradeDialog.actionsContainer.acceptAllActionsAction(2, fork) - await downgradeDialog.expectDowngradeSuccessPage({ token: 'USDS', amount: '10,000.00', usdValue: '$10,000.00' }) - await downgradeDialog.clickBackToSavingsButton() - - await savingsPage.expectUpgradableDaiBalance('10,000.00') - }) -}) +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { DowngradeDialogPageObject } from '../DowngradeDialog.PageObject' + +// test.describe('Downgrade USDS to DAI', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) + +// test('downgrade to DAI is disabled when USDS balance is 0', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { USDS: 0 }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// await savingsPage.expectDowngradeToDaiToBeDisabled() +// }) + +// test('uses downgrade action', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { USDS: 10_000 }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// await savingsPage.clickDowngradeUsdsToDaiOption() + +// const downgradeDialog = new DowngradeDialogPageObject(page) +// await downgradeDialog.fillAmountAction(100) + +// await downgradeDialog.actionsContainer.expectEnabledActionAtIndex(0) +// await downgradeDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'USDS' }, +// { type: 'downgrade', fromToken: 'USDS', toToken: 'DAI' }, +// ]) +// }) + +// test('displays transaction overview', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { USDS: 10_000 }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// await savingsPage.clickDowngradeUsdsToDaiOption() + +// const downgradeDialog = new DowngradeDialogPageObject(page) +// await downgradeDialog.fillAmountAction(100) + +// await downgradeDialog.expectTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '100.00 USDS', +// tokenUsdValue: '$100.00', +// }, +// { +// tokenAmount: '100.00 DAI', +// tokenUsdValue: '$100.00', +// }, +// ], +// outcome: '100.00 DAI', +// outcomeUsd: '$100.00', +// }) +// }) + +// test('executes transaction', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { USDS: 10_000 }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') +// await savingsPage.clickDowngradeUsdsToDaiOption() + +// const downgradeDialog = new DowngradeDialogPageObject(page) +// await downgradeDialog.fillAmountAction(10_000) + +// await downgradeDialog.actionsContainer.acceptAllActionsAction(2, fork) +// await downgradeDialog.expectDowngradeSuccessPage({ token: 'USDS', amount: '10,000.00', usdValue: '$10,000.00' }) +// await downgradeDialog.clickBackToSavingsButton() + +// await savingsPage.expectUpgradableDaiBalance('10,000.00') +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/DaiToUsds.test-e2e.ts b/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/DaiToUsds.test-e2e.ts index ef8085cac..e3c85e862 100644 --- a/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/DaiToUsds.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/DaiToUsds.test-e2e.ts @@ -1,110 +1,110 @@ -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { UpgradeDialogPageObject } from '../UpgradeDialog.PageObject' - -test.describe('Upgrade DAI to USDS', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - - test('does not show upgrade button when DAI balance is 0', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { USDS: 10_000 }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - - // wait to load - await savingsPage.expectOpportunityStablecoinsAmount('~$10,000.00') - - await savingsPage.expectUpgradeDaiToUsdsButtonToBeHidden() - }) - - test('uses upgrade action', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { DAI: 10_000 }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - - await savingsPage.clickUpgradeDaiToUsdsButtonAction() - - const upgradeDialog = new UpgradeDialogPageObject(page) - - await upgradeDialog.actionsContainer.expectEnabledActionAtIndex(0) - await upgradeDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'DAI' }, - { type: 'upgrade', fromToken: 'DAI', toToken: 'USDS' }, - ]) - }) - - test('displays transaction overview', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { DAI: 10_000 }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - await savingsPage.clickUpgradeDaiToUsdsButtonAction() - const upgradeDialog = new UpgradeDialogPageObject(page) - - await upgradeDialog.expectTransactionOverview({ - routeItems: [ - { - tokenAmount: '10,000.00 DAI', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - ], - outcome: '10,000.00 USDS', - outcomeUsd: '$10,000.00', - }) - }) - - test('executes transaction', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { DAI: 10_000 }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - - await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') - await savingsPage.clickUpgradeDaiToUsdsButtonAction() - - const upgradeDialog = new UpgradeDialogPageObject(page) - - await upgradeDialog.actionsContainer.acceptAllActionsAction(2, fork) - await upgradeDialog.expectSuccessPage( - [ - { - asset: 'DAI', - amount: 10_000, - }, - ], - fork, - ) - await upgradeDialog.clickBackToSavingsButton() - - await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000') - }) -}) +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { UpgradeDialogPageObject } from '../UpgradeDialog.PageObject' + +// test.describe('Upgrade DAI to USDS', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) + +// test('does not show upgrade button when DAI balance is 0', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { USDS: 10_000 }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// // wait to load +// await savingsPage.expectOpportunityStablecoinsAmount('~$10,000.00') + +// await savingsPage.expectUpgradeDaiToUsdsButtonToBeHidden() +// }) + +// test('uses upgrade action', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { DAI: 10_000 }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// await savingsPage.clickUpgradeDaiToUsdsButtonAction() + +// const upgradeDialog = new UpgradeDialogPageObject(page) + +// await upgradeDialog.actionsContainer.expectEnabledActionAtIndex(0) +// await upgradeDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'DAI' }, +// { type: 'upgrade', fromToken: 'DAI', toToken: 'USDS' }, +// ]) +// }) + +// test('displays transaction overview', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { DAI: 10_000 }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) +// await savingsPage.clickUpgradeDaiToUsdsButtonAction() +// const upgradeDialog = new UpgradeDialogPageObject(page) + +// await upgradeDialog.expectTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '10,000.00 DAI', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// outcome: '10,000.00 USDS', +// outcomeUsd: '$10,000.00', +// }) +// }) + +// test('executes transaction', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { DAI: 10_000 }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') +// await savingsPage.clickUpgradeDaiToUsdsButtonAction() + +// const upgradeDialog = new UpgradeDialogPageObject(page) + +// await upgradeDialog.actionsContainer.acceptAllActionsAction(2, fork) +// await upgradeDialog.expectSuccessPage( +// [ +// { +// asset: 'DAI', +// amount: 10_000, +// }, +// ], +// fork, +// ) +// await upgradeDialog.clickBackToSavingsButton() + +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000') +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/sDaiToSUsds.test-e2e.ts b/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/sDaiToSUsds.test-e2e.ts index 34bffeb4b..2d8ce9a16 100644 --- a/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/sDaiToSUsds.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/sDaiToSUsds.test-e2e.ts @@ -1,105 +1,105 @@ -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { UpgradeDialogPageObject } from '../UpgradeDialog.PageObject' - -test.describe('Upgrade sDAI to sUSDS', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - - test('does not show upgrade banner when sDai balance is 0', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { sDAI: 0, sUSDS: 10_000 }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - - // wait to load - await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '10,000.00 sUSDS', estimatedUsdsValue: '10,000.23' }) - - await savingsPage.expectUpgradeDaiToUsdsButtonToBeHidden() - }) - - test('uses upgrade action', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { sDAI: 10_000 }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - - await savingsPage.clickUpgradeSDaiButtonAction() - - const upgradeDialog = new UpgradeDialogPageObject(page) - - await upgradeDialog.actionsContainer.expectEnabledActionAtIndex(0) - await upgradeDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'sDAI' }, - { type: 'upgrade', fromToken: 'sDAI', toToken: 'sUSDS' }, - ]) - }) - - test('displays transaction overview', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { sDAI: 10_000 }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - - await savingsPage.clickUpgradeSDaiButtonAction() - - const upgradeDialog = new UpgradeDialogPageObject(page) - - await upgradeDialog.expectTransactionOverview({ - apyChange: { - current: '6.00%', - updated: '6.25%', - }, - routeItems: [ - { - tokenAmount: '10,000.00 sDAI', - tokenUsdValue: '$11,085.91', - }, - { - tokenAmount: '11,085.65 sUSDS', - tokenUsdValue: '$11,085.91', - }, - ], - outcome: '11,085.65 sUSDS', - outcomeUsd: '$11,085.91', - }) - }) - - test('executes transaction', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { sDAI: 10_000, sUSDS: 10_000 }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - await savingsPage.clickUpgradeSDaiButtonAction() - - const upgradeDialog = new UpgradeDialogPageObject(page) - await upgradeDialog.actionsContainer.acceptAllActionsAction(2, fork) - await upgradeDialog.expectUpgradeSuccessPage({ token: 'sDAI', amount: '10,000.00', usdValue: '$11,085.91' }) - await upgradeDialog.clickBackToSavingsButton() - - await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '21,085.65 sUSDS', estimatedUsdsValue: '21,086.13' }) - }) -}) +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { UpgradeDialogPageObject } from '../UpgradeDialog.PageObject' + +// test.describe('Upgrade sDAI to sUSDS', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) + +// test('does not show upgrade banner when sDai balance is 0', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { sDAI: 0, sUSDS: 10_000 }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// // wait to load +// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '10,000.00 sUSDS', estimatedUsdsValue: '10,000.23' }) + +// await savingsPage.expectUpgradeDaiToUsdsButtonToBeHidden() +// }) + +// test('uses upgrade action', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { sDAI: 10_000 }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// await savingsPage.clickUpgradeSDaiButtonAction() + +// const upgradeDialog = new UpgradeDialogPageObject(page) + +// await upgradeDialog.actionsContainer.expectEnabledActionAtIndex(0) +// await upgradeDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'sDAI' }, +// { type: 'upgrade', fromToken: 'sDAI', toToken: 'sUSDS' }, +// ]) +// }) + +// test('displays transaction overview', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { sDAI: 10_000 }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// await savingsPage.clickUpgradeSDaiButtonAction() + +// const upgradeDialog = new UpgradeDialogPageObject(page) + +// await upgradeDialog.expectTransactionOverview({ +// apyChange: { +// current: '6.00%', +// updated: '6.25%', +// }, +// routeItems: [ +// { +// tokenAmount: '10,000.00 sDAI', +// tokenUsdValue: '$11,085.91', +// }, +// { +// tokenAmount: '11,085.65 sUSDS', +// tokenUsdValue: '$11,085.91', +// }, +// ], +// outcome: '11,085.65 sUSDS', +// outcomeUsd: '$11,085.91', +// }) +// }) + +// test('executes transaction', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { sDAI: 10_000, sUSDS: 10_000 }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) +// await savingsPage.clickUpgradeSDaiButtonAction() + +// const upgradeDialog = new UpgradeDialogPageObject(page) +// await upgradeDialog.actionsContainer.acceptAllActionsAction(2, fork) +// await upgradeDialog.expectUpgradeSuccessPage({ token: 'sDAI', amount: '10,000.00', usdValue: '$11,085.91' }) +// await upgradeDialog.clickBackToSavingsButton() + +// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '21,085.65 sUSDS', estimatedUsdsValue: '21,086.13' }) +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/withdraw/SavingsWithdrawDialog.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/SavingsWithdrawDialog.test-e2e.ts index e36053f0b..8ec2ba3ee 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/SavingsWithdrawDialog.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/SavingsWithdrawDialog.test-e2e.ts @@ -1,195 +1,195 @@ -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { DEFAULT_BLOCK_NUMBER, GNOSIS_DEFAULT_BLOCK_NUMBER, LITE_PSM_ACTIONS_OPERABLE } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { base, gnosis, mainnet } from 'viem/chains' -import { SavingsDialogPageObject } from '../common/e2e/SavingsDialog.PageObject' - -test.describe('Savings withdraw dialog', () => { - test.describe('Mainnet', () => { - const fork = setupFork({ - blockNumber: LITE_PSM_ACTIONS_OPERABLE, - chainId: mainnet.id, - useTenderlyVnet: true, - }) - - test('can switch between tokens', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sDAI: 1000, - }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - - await savingsPage.clickWithdrawSDaiButtonAction() - - const withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) - const actionsContainer = new ActionsPageObject(withdrawalDialog.locatePanelByHeader('Actions')) - - await withdrawalDialog.fillAmountAction(1000) - await actionsContainer.expectEnabledActionAtIndex(0) - await actionsContainer.expectActions([ - { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'withdraw' }, - ]) - - await withdrawalDialog.selectAssetAction('USDC') - await withdrawalDialog.fillAmountAction(1000) - await actionsContainer.expectEnabledActionAtIndex(0) - await actionsContainer.expectActions([ - { type: 'approve', asset: 'sDAI' }, - { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sDAI', mode: 'withdraw' }, - ]) - - await withdrawalDialog.selectAssetAction('DAI') - await withdrawalDialog.fillAmountAction(1000) - await actionsContainer.expectEnabledActionAtIndex(0) - await actionsContainer.expectActions([ - { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'withdraw' }, - ]) - }) - }) - - test.describe('Base', () => { - const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) - - test('can switch between tokens', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sUSDS: 1000, - }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - - await savingsPage.clickWithdrawSUsdsButtonAction() - - const withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) - const actionsContainer = new ActionsPageObject(withdrawalDialog.locatePanelByHeader('Actions')) - - await withdrawalDialog.fillAmountAction(1000) - await actionsContainer.expectEnabledActionAtIndex(0) - await actionsContainer.expectActions([ - { type: 'approve', asset: 'sUSDS' }, - { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, - ]) - - await withdrawalDialog.selectAssetAction('USDC') - await withdrawalDialog.fillAmountAction(1000) - await actionsContainer.expectEnabledActionAtIndex(0) - await actionsContainer.expectActions([ - { type: 'approve', asset: 'sUSDS' }, - { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'withdraw' }, - ]) - - await withdrawalDialog.selectAssetAction('USDS') - await withdrawalDialog.fillAmountAction(1000) - await actionsContainer.expectEnabledActionAtIndex(0) - await actionsContainer.expectActions([ - { type: 'approve', asset: 'sUSDS' }, - { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, - ]) - }) - }) -}) - -test.describe('Savings withdraw dialog send mode', () => { - test.describe('Mainnet', () => { - const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let sendDialog: SavingsDialogPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sDAI: 10_000, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - await savingsPage.clickSendSDaiButtonAction() - - sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) - }) - - test('can select only supported assets', async () => { - await sendDialog.openAssetSelectorAction() - await sendDialog.expectAssetSelectorOptions(['DAI', 'USDC']) - }) - }) - - test.describe('Gnosis', () => { - const fork = setupFork({ blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let sendDialog: SavingsDialogPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - XDAI: 100, - sDAI: 10_000, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - await savingsPage.clickSendSDaiButtonAction() - - sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) - }) - - test('can select only supported assets', async () => { - await sendDialog.openAssetSelectorAction() - await sendDialog.expectAssetSelectorOptions(['XDAI']) - }) - }) - - test.describe('Base', () => { - const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let sendDialog: SavingsDialogPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - USDS: 100, - sUSDS: 10_000, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - await savingsPage.clickSendSUsdsButtonAction() - - sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) - }) - - test('can select only supported assets', async () => { - await sendDialog.openAssetSelectorAction() - await sendDialog.expectAssetSelectorOptions(['USDC', 'USDS']) - }) - }) -}) +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { DEFAULT_BLOCK_NUMBER, GNOSIS_DEFAULT_BLOCK_NUMBER, LITE_PSM_ACTIONS_OPERABLE } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { base, gnosis, mainnet } from 'viem/chains' +// import { SavingsDialogPageObject } from '../common/e2e/SavingsDialog.PageObject' + +// test.describe('Savings withdraw dialog', () => { +// test.describe('Mainnet', () => { +// const fork = setupFork({ +// blockNumber: LITE_PSM_ACTIONS_OPERABLE, +// chainId: mainnet.id, +// useTenderlyVnet: true, +// }) + +// test('can switch between tokens', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sDAI: 1000, +// }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// await savingsPage.clickWithdrawSDaiButtonAction() + +// const withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) +// const actionsContainer = new ActionsPageObject(withdrawalDialog.locatePanelByHeader('Actions')) + +// await withdrawalDialog.fillAmountAction(1000) +// await actionsContainer.expectEnabledActionAtIndex(0) +// await actionsContainer.expectActions([ +// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'withdraw' }, +// ]) + +// await withdrawalDialog.selectAssetAction('USDC') +// await withdrawalDialog.fillAmountAction(1000) +// await actionsContainer.expectEnabledActionAtIndex(0) +// await actionsContainer.expectActions([ +// { type: 'approve', asset: 'sDAI' }, +// { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sDAI', mode: 'withdraw' }, +// ]) + +// await withdrawalDialog.selectAssetAction('DAI') +// await withdrawalDialog.fillAmountAction(1000) +// await actionsContainer.expectEnabledActionAtIndex(0) +// await actionsContainer.expectActions([ +// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'withdraw' }, +// ]) +// }) +// }) + +// test.describe('Base', () => { +// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) + +// test('can switch between tokens', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sUSDS: 1000, +// }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// await savingsPage.clickWithdrawSUsdsButtonAction() + +// const withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) +// const actionsContainer = new ActionsPageObject(withdrawalDialog.locatePanelByHeader('Actions')) + +// await withdrawalDialog.fillAmountAction(1000) +// await actionsContainer.expectEnabledActionAtIndex(0) +// await actionsContainer.expectActions([ +// { type: 'approve', asset: 'sUSDS' }, +// { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, +// ]) + +// await withdrawalDialog.selectAssetAction('USDC') +// await withdrawalDialog.fillAmountAction(1000) +// await actionsContainer.expectEnabledActionAtIndex(0) +// await actionsContainer.expectActions([ +// { type: 'approve', asset: 'sUSDS' }, +// { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'withdraw' }, +// ]) + +// await withdrawalDialog.selectAssetAction('USDS') +// await withdrawalDialog.fillAmountAction(1000) +// await actionsContainer.expectEnabledActionAtIndex(0) +// await actionsContainer.expectActions([ +// { type: 'approve', asset: 'sUSDS' }, +// { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, +// ]) +// }) +// }) +// }) + +// test.describe('Savings withdraw dialog send mode', () => { +// test.describe('Mainnet', () => { +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let sendDialog: SavingsDialogPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sDAI: 10_000, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickSendSDaiButtonAction() + +// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) +// }) + +// test('can select only supported assets', async () => { +// await sendDialog.openAssetSelectorAction() +// await sendDialog.expectAssetSelectorOptions(['DAI', 'USDC']) +// }) +// }) + +// test.describe('Gnosis', () => { +// const fork = setupFork({ blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let sendDialog: SavingsDialogPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// XDAI: 100, +// sDAI: 10_000, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickSendSDaiButtonAction() + +// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) +// }) + +// test('can select only supported assets', async () => { +// await sendDialog.openAssetSelectorAction() +// await sendDialog.expectAssetSelectorOptions(['XDAI']) +// }) +// }) + +// test.describe('Base', () => { +// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let sendDialog: SavingsDialogPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// USDS: 100, +// sUSDS: 10_000, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickSendSUsdsButtonAction() + +// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) +// }) + +// test('can select only supported assets', async () => { +// await sendDialog.openAssetSelectorAction() +// await sendDialog.expectAssetSelectorOptions(['USDC', 'USDS']) +// }) +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/SendUSDC.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/SendUSDC.test-e2e.ts index d7ba5e841..d4f72a627 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/SendUSDC.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/SendUSDC.test-e2e.ts @@ -1,92 +1,92 @@ -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { TOKENS_ON_FORK } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { randomAddress } from '@/test/utils/addressUtils' -import { test } from '@playwright/test' -import { base } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { TOKENS_ON_FORK } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { randomAddress } from '@/test/utils/addressUtils' +// import { test } from '@playwright/test' +// import { base } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -test.describe('Send USDC', () => { - const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) +// test.describe('Send USDC', () => { +// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let sendDialog: SavingsDialogPageObject +// let savingsPage: SavingsPageObject +// let sendDialog: SavingsDialogPageObject - const receiver = randomAddress('bob') - const amount = 7000 - const usdc = TOKENS_ON_FORK[base.id].USDC +// const receiver = randomAddress('bob') +// const amount = 7000 +// const usdc = TOKENS_ON_FORK[base.id].USDC - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sUSDS: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sUSDS: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) +// savingsPage = new SavingsPageObject(page) - await savingsPage.clickSendSUsdsButtonAction() - sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) +// await savingsPage.clickSendSUsdsButtonAction() +// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) - await sendDialog.selectAssetAction('USDC') - await sendDialog.fillAmountAction(amount) - await sendDialog.fillReceiverAction(receiver) - }) +// await sendDialog.selectAssetAction('USDC') +// await sendDialog.fillAmountAction(amount) +// await sendDialog.fillReceiverAction(receiver) +// }) - test('has correct action plan', async () => { - await sendDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'sUSDS' }, - { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'send' }, - ]) - }) +// test('has correct action plan', async () => { +// await sendDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'sUSDS' }, +// { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'send' }, +// ]) +// }) - test('displays transaction overview', async () => { - await sendDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '6,938.24 sUSDS', - tokenUsdValue: '$7,000.00', - }, - { - tokenAmount: '7,000.00 USDS', - tokenUsdValue: '$7,000.00', - }, - { - tokenAmount: '7,000.00 USDC', - tokenUsdValue: '$7,000.00', - }, - ], - outcome: '7,000.00 USDC', - outcomeUsd: '$7,000.00', - }) - }) +// test('displays transaction overview', async () => { +// await sendDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '6,938.24 sUSDS', +// tokenUsdValue: '$7,000.00', +// }, +// { +// tokenAmount: '7,000.00 USDS', +// tokenUsdValue: '$7,000.00', +// }, +// { +// tokenAmount: '7,000.00 USDC', +// tokenUsdValue: '$7,000.00', +// }, +// ], +// outcome: '7,000.00 USDC', +// outcomeUsd: '$7,000.00', +// }) +// }) - test('executes send', async () => { - await sendDialog.expectReceiverTokenBalance({ - forkUrl: fork.forkUrl, - receiver, - token: usdc, - expectedBalance: 0, - }) +// test('executes send', async () => { +// await sendDialog.expectReceiverTokenBalance({ +// forkUrl: fork.forkUrl, +// receiver, +// token: usdc, +// expectedBalance: 0, +// }) - await sendDialog.actionsContainer.acceptAllActionsAction(2, fork) - await sendDialog.expectSuccessPage() +// await sendDialog.actionsContainer.acceptAllActionsAction(2, fork) +// await sendDialog.expectSuccessPage() - await sendDialog.expectReceiverTokenBalance({ - forkUrl: fork.forkUrl, - receiver, - token: usdc, - expectedBalance: amount, - }) +// await sendDialog.expectReceiverTokenBalance({ +// forkUrl: fork.forkUrl, +// receiver, +// token: usdc, +// expectedBalance: amount, +// }) - await sendDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '3,061.76 sUSDS', estimatedUsdsValue: '3,089' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') - }) -}) +// await sendDialog.clickBackToSavingsButton() +// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '3,061.76 sUSDS', estimatedUsdsValue: '3,089' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/SendUSDS.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/SendUSDS.test-e2e.ts index 6377de25c..f19ec24bf 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/SendUSDS.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/SendUSDS.test-e2e.ts @@ -1,84 +1,84 @@ -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { TOKENS_ON_FORK } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { randomAddress } from '@/test/utils/addressUtils' -import { test } from '@playwright/test' -import { base } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { TOKENS_ON_FORK } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { randomAddress } from '@/test/utils/addressUtils' +// import { test } from '@playwright/test' +// import { base } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -test.describe('Send USDS', () => { - const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let sendDialog: SavingsDialogPageObject - const receiver = randomAddress('bob') - const amount = 7000 - const usds = TOKENS_ON_FORK[base.id].USDS +// test.describe('Send USDS', () => { +// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let sendDialog: SavingsDialogPageObject +// const receiver = randomAddress('bob') +// const amount = 7000 +// const usds = TOKENS_ON_FORK[base.id].USDS - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sUSDS: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sUSDS: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) +// savingsPage = new SavingsPageObject(page) - await savingsPage.clickSendSUsdsButtonAction() - sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) - await sendDialog.fillAmountAction(amount) - await sendDialog.fillReceiverAction(receiver) - }) +// await savingsPage.clickSendSUsdsButtonAction() +// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) +// await sendDialog.fillAmountAction(amount) +// await sendDialog.fillReceiverAction(receiver) +// }) - test('has correct action plan', async () => { - await sendDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'sUSDS' }, - { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'send' }, - ]) - }) +// test('has correct action plan', async () => { +// await sendDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'sUSDS' }, +// { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'send' }, +// ]) +// }) - test('displays transaction overview', async () => { - await sendDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '6,938.24 sUSDS', - tokenUsdValue: '$7,000.00', - }, - { - tokenAmount: '7,000.00 USDS', - tokenUsdValue: '$7,000.00', - }, - ], - outcome: '7,000.00 USDS', - outcomeUsd: '$7,000.00', - }) - }) +// test('displays transaction overview', async () => { +// await sendDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '6,938.24 sUSDS', +// tokenUsdValue: '$7,000.00', +// }, +// { +// tokenAmount: '7,000.00 USDS', +// tokenUsdValue: '$7,000.00', +// }, +// ], +// outcome: '7,000.00 USDS', +// outcomeUsd: '$7,000.00', +// }) +// }) - test('executes send', async () => { - await sendDialog.expectReceiverTokenBalance({ - forkUrl: fork.forkUrl, - receiver, - token: usds, - expectedBalance: 0, - }) +// test('executes send', async () => { +// await sendDialog.expectReceiverTokenBalance({ +// forkUrl: fork.forkUrl, +// receiver, +// token: usds, +// expectedBalance: 0, +// }) - await sendDialog.actionsContainer.acceptAllActionsAction(2, fork) - await sendDialog.expectSuccessPage() +// await sendDialog.actionsContainer.acceptAllActionsAction(2, fork) +// await sendDialog.expectSuccessPage() - await sendDialog.expectReceiverTokenBalance({ - forkUrl: fork.forkUrl, - receiver, - token: usds, - expectedBalance: amount, - }) +// await sendDialog.expectReceiverTokenBalance({ +// forkUrl: fork.forkUrl, +// receiver, +// token: usds, +// expectedBalance: amount, +// }) - await sendDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '3,061.76 sUSDS', estimatedUsdsValue: '3,089' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') - }) -}) +// await sendDialog.clickBackToSavingsButton() +// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '3,061.76 sUSDS', estimatedUsdsValue: '3,089' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawMaxUSDC.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawMaxUSDC.test-e2e.ts index d3ac6fc02..2f3a16501 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawMaxUSDC.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawMaxUSDC.test-e2e.ts @@ -1,70 +1,70 @@ -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { base } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { base } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -test.describe('Withdraw Max USDC', () => { - const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let withdrawDialog: SavingsDialogPageObject +// test.describe('Withdraw Max USDC', () => { +// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let withdrawDialog: SavingsDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sUSDS: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sUSDS: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) +// savingsPage = new SavingsPageObject(page) - await savingsPage.clickWithdrawSUsdsButtonAction() - withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) - await withdrawDialog.selectAssetAction('USDC') - await withdrawDialog.clickMaxAmountAction() - }) +// await savingsPage.clickWithdrawSUsdsButtonAction() +// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) +// await withdrawDialog.selectAssetAction('USDC') +// await withdrawDialog.clickMaxAmountAction() +// }) - test('has correct action plan', async () => { - await withdrawDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'sUSDS' }, - { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'withdraw' }, - ]) - }) +// test('has correct action plan', async () => { +// await withdrawDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'sUSDS' }, +// { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'withdraw' }, +// ]) +// }) - test('displays transaction overview', async () => { - await withdrawDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '10,000.00 sUSDS', - tokenUsdValue: '$10,089.01', - }, - { - tokenAmount: '10,089.01 USDS', - tokenUsdValue: '$10,089.01', - }, - ], - outcome: '10,089.01 USDC', - outcomeUsd: '$10,089.01', - }) +// test('displays transaction overview', async () => { +// await withdrawDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '10,000.00 sUSDS', +// tokenUsdValue: '$10,089.01', +// }, +// { +// tokenAmount: '10,089.01 USDS', +// tokenUsdValue: '$10,089.01', +// }, +// ], +// outcome: '10,089.01 USDC', +// outcomeUsd: '$10,089.01', +// }) - await withdrawDialog.expectUpgradeSwitchToBeHidden() - }) +// await withdrawDialog.expectUpgradeSwitchToBeHidden() +// }) - test('executes withdraw', async () => { - const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2, fork) +// test('executes withdraw', async () => { +// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2, fork) - await withdrawDialog.expectSuccessPage() - await withdrawDialog.clickBackToSavingsButton() +// await withdrawDialog.expectSuccessPage() +// await withdrawDialog.clickBackToSavingsButton() - await savingsPage.expectOpportunityStablecoinsAmount('~$10,089.01') - await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '10,089.01') - }) -}) +// await savingsPage.expectOpportunityStablecoinsAmount('~$10,089.01') +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '10,089.01') +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawMaxUSDS.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawMaxUSDS.test-e2e.ts index 44d196dfb..9128574f7 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawMaxUSDS.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawMaxUSDS.test-e2e.ts @@ -1,69 +1,69 @@ -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { base } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { base } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -test.describe('Withdraw Max USDS', () => { - const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let withdrawDialog: SavingsDialogPageObject +// test.describe('Withdraw Max USDS', () => { +// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let withdrawDialog: SavingsDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sUSDS: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sUSDS: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) +// savingsPage = new SavingsPageObject(page) - await savingsPage.clickWithdrawSUsdsButtonAction() - withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) - await withdrawDialog.clickMaxAmountAction() - }) +// await savingsPage.clickWithdrawSUsdsButtonAction() +// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) +// await withdrawDialog.clickMaxAmountAction() +// }) - test('has correct action plan', async () => { - await withdrawDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'sUSDS' }, - { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, - ]) - }) +// test('has correct action plan', async () => { +// await withdrawDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'sUSDS' }, +// { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, +// ]) +// }) - test('displays transaction overview', async () => { - await withdrawDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '10,000.00 sUSDS', - tokenUsdValue: '$10,089.01', - }, - { - tokenAmount: '10,089.01 USDS', - tokenUsdValue: '$10,089.01', - }, - ], - outcome: '10,089.01 USDS', - outcomeUsd: '$10,089.01', - }) +// test('displays transaction overview', async () => { +// await withdrawDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '10,000.00 sUSDS', +// tokenUsdValue: '$10,089.01', +// }, +// { +// tokenAmount: '10,089.01 USDS', +// tokenUsdValue: '$10,089.01', +// }, +// ], +// outcome: '10,089.01 USDS', +// outcomeUsd: '$10,089.01', +// }) - await withdrawDialog.expectUpgradeSwitchToBeHidden() - }) +// await withdrawDialog.expectUpgradeSwitchToBeHidden() +// }) - test('executes withdraw', async () => { - const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2, fork) +// test('executes withdraw', async () => { +// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2, fork) - await withdrawDialog.expectSuccessPage() - await withdrawDialog.clickBackToSavingsButton() +// await withdrawDialog.expectSuccessPage() +// await withdrawDialog.clickBackToSavingsButton() - await savingsPage.expectOpportunityStablecoinsAmount('~$10,089.01') - await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,089.01') - }) -}) +// await savingsPage.expectOpportunityStablecoinsAmount('~$10,089.01') +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,089.01') +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawUSDC.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawUSDC.test-e2e.ts index 78e012810..702a0eb28 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawUSDC.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawUSDC.test-e2e.ts @@ -1,74 +1,74 @@ -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { base } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { base } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -test.describe('Withdraw USDC', () => { - const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let withdrawDialog: SavingsDialogPageObject +// test.describe('Withdraw USDC', () => { +// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let withdrawDialog: SavingsDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sUSDS: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sUSDS: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) +// savingsPage = new SavingsPageObject(page) - await savingsPage.clickWithdrawSUsdsButtonAction() - withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) - await withdrawDialog.selectAssetAction('USDC') - await withdrawDialog.fillAmountAction(1000) - }) +// await savingsPage.clickWithdrawSUsdsButtonAction() +// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) +// await withdrawDialog.selectAssetAction('USDC') +// await withdrawDialog.fillAmountAction(1000) +// }) - test('has correct action plan', async () => { - await withdrawDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'sUSDS' }, - { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'withdraw' }, - ]) - }) +// test('has correct action plan', async () => { +// await withdrawDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'sUSDS' }, +// { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'withdraw' }, +// ]) +// }) - test('displays transaction overview', async () => { - await withdrawDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '991.18 sUSDS', - tokenUsdValue: '$1,000.00', - }, - { - tokenAmount: '1,000.00 USDS', - tokenUsdValue: '$1,000.00', - }, - { - tokenAmount: '1,000.00 USDC', - tokenUsdValue: '$1,000.00', - }, - ], - outcome: '1,000.00 USDC', - outcomeUsd: '$1,000.00', - }) +// test('displays transaction overview', async () => { +// await withdrawDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '991.18 sUSDS', +// tokenUsdValue: '$1,000.00', +// }, +// { +// tokenAmount: '1,000.00 USDS', +// tokenUsdValue: '$1,000.00', +// }, +// { +// tokenAmount: '1,000.00 USDC', +// tokenUsdValue: '$1,000.00', +// }, +// ], +// outcome: '1,000.00 USDC', +// outcomeUsd: '$1,000.00', +// }) - await withdrawDialog.expectUpgradeSwitchToBeHidden() - }) +// await withdrawDialog.expectUpgradeSwitchToBeHidden() +// }) - test('executes withdraw', async () => { - const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2, fork) +// test('executes withdraw', async () => { +// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2, fork) - await withdrawDialog.expectSuccessPage() - await withdrawDialog.clickBackToSavingsButton() +// await withdrawDialog.expectSuccessPage() +// await withdrawDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,008.82 sUSDS', estimatedUsdsValue: '9,089' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '1,000') - }) -}) +// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,008.82 sUSDS', estimatedUsdsValue: '9,089' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '1,000') +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawUSDS.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawUSDS.test-e2e.ts index ce54ce555..06c3348a3 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawUSDS.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawUSDS.test-e2e.ts @@ -1,69 +1,69 @@ -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { base } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { base } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -test.describe('Withdraw USDS', () => { - const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let withdrawDialog: SavingsDialogPageObject +// test.describe('Withdraw USDS', () => { +// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let withdrawDialog: SavingsDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sUSDS: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sUSDS: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) +// savingsPage = new SavingsPageObject(page) - await savingsPage.clickWithdrawSUsdsButtonAction() - withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) - await withdrawDialog.fillAmountAction(1000) - }) +// await savingsPage.clickWithdrawSUsdsButtonAction() +// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) +// await withdrawDialog.fillAmountAction(1000) +// }) - test('has correct action plan', async () => { - await withdrawDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'sUSDS' }, - { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, - ]) - }) +// test('has correct action plan', async () => { +// await withdrawDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'sUSDS' }, +// { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, +// ]) +// }) - test('displays transaction overview', async () => { - await withdrawDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '991.18 sUSDS', - tokenUsdValue: '$1,000.00', - }, - { - tokenAmount: '1,000.00 USDS', - tokenUsdValue: '$1,000.00', - }, - ], - outcome: '1,000.00 USDS', - outcomeUsd: '$1,000.00', - }) +// test('displays transaction overview', async () => { +// await withdrawDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '991.18 sUSDS', +// tokenUsdValue: '$1,000.00', +// }, +// { +// tokenAmount: '1,000.00 USDS', +// tokenUsdValue: '$1,000.00', +// }, +// ], +// outcome: '1,000.00 USDS', +// outcomeUsd: '$1,000.00', +// }) - await withdrawDialog.expectUpgradeSwitchToBeHidden() - }) +// await withdrawDialog.expectUpgradeSwitchToBeHidden() +// }) - test('executes withdraw', async () => { - const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2, fork) +// test('executes withdraw', async () => { +// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2, fork) - await withdrawDialog.expectSuccessPage() - await withdrawDialog.clickBackToSavingsButton() +// await withdrawDialog.expectSuccessPage() +// await withdrawDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,008.82 sUSDS', estimatedUsdsValue: '9,089' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '1,000') - }) -}) +// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,008.82 sUSDS', estimatedUsdsValue: '9,089' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '1,000') +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/SendXDAI.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/SendXDAI.test-e2e.ts index 21aad26e3..a9bbb8987 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/SendXDAI.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/SendXDAI.test-e2e.ts @@ -1,81 +1,81 @@ -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { randomAddress } from '@/test/utils/addressUtils' -import { test } from '@playwright/test' -import { gnosis } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { randomAddress } from '@/test/utils/addressUtils' +// import { test } from '@playwright/test' +// import { gnosis } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -test.describe('Send XDAI on Gnosis', () => { - const fork = setupFork({ blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let sendDialog: SavingsDialogPageObject - const receiver = randomAddress('bob') - const amount = 7000 +// test.describe('Send XDAI on Gnosis', () => { +// const fork = setupFork({ blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let sendDialog: SavingsDialogPageObject +// const receiver = randomAddress('bob') +// const amount = 7000 - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - XDAI: 100, - sDAI: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// XDAI: 100, +// sDAI: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) - await savingsPage.clickSendSDaiButtonAction() +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickSendSDaiButtonAction() - sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) - await sendDialog.fillAmountAction(amount) - await sendDialog.fillReceiverAction(receiver) - }) +// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) +// await sendDialog.fillAmountAction(amount) +// await sendDialog.fillReceiverAction(receiver) +// }) - test('uses native sDai withdraw and send', async () => { - await sendDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'sDAI' }, - { type: 'withdrawFromSavings', asset: 'XDAI', savingsAsset: 'sDAI', mode: 'send' }, - ]) - }) +// test('uses native sDai withdraw and send', async () => { +// await sendDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'sDAI' }, +// { type: 'withdrawFromSavings', asset: 'XDAI', savingsAsset: 'sDAI', mode: 'send' }, +// ]) +// }) - test('displays transaction overview', async () => { - await sendDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '6,434.95 sDAI', - tokenUsdValue: '$7,000.00', - }, - { - tokenAmount: '7,000.00 XDAI', - tokenUsdValue: '$7,000.00', - }, - ], - outcome: '7,000.00 XDAI', - outcomeUsd: '$7,000.00', - }) - }) +// test('displays transaction overview', async () => { +// await sendDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '6,434.95 sDAI', +// tokenUsdValue: '$7,000.00', +// }, +// { +// tokenAmount: '7,000.00 XDAI', +// tokenUsdValue: '$7,000.00', +// }, +// ], +// outcome: '7,000.00 XDAI', +// outcomeUsd: '$7,000.00', +// }) +// }) - test('executes send', async () => { - await sendDialog.expectReceiverBalance({ - forkUrl: fork.forkUrl, - receiver, - expectedBalance: 0, - }) +// test('executes send', async () => { +// await sendDialog.expectReceiverBalance({ +// forkUrl: fork.forkUrl, +// receiver, +// expectedBalance: 0, +// }) - await sendDialog.actionsContainer.acceptAllActionsAction(2, fork) - await sendDialog.expectSuccessPage() +// await sendDialog.actionsContainer.acceptAllActionsAction(2, fork) +// await sendDialog.expectSuccessPage() - await sendDialog.expectReceiverBalance({ - forkUrl: fork.forkUrl, - receiver, - expectedBalance: amount, - }) +// await sendDialog.expectReceiverBalance({ +// forkUrl: fork.forkUrl, +// receiver, +// expectedBalance: amount, +// }) - await sendDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,565.05 sDAI', estimatedDaiValue: '3,878.094168' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('XDAI', '100') - }) -}) +// await sendDialog.clickBackToSavingsButton() +// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,565.05 sDAI', estimatedDaiValue: '3,878.094168' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('XDAI', '100') +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/WithdrawMaxXDAI.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/WithdrawMaxXDAI.test-e2e.ts index f7fee1acc..77f590f44 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/WithdrawMaxXDAI.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/WithdrawMaxXDAI.test-e2e.ts @@ -1,72 +1,72 @@ -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { gnosis } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { gnosis } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -test.describe('Withdraw max XDAI on Gnosis', () => { - const fork = setupFork({ - blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, - chainId: gnosis.id, - useTenderlyVnet: true, - }) - let savingsPage: SavingsPageObject - let withdrawalDialog: SavingsDialogPageObject +// test.describe('Withdraw max XDAI on Gnosis', () => { +// const fork = setupFork({ +// blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, +// chainId: gnosis.id, +// useTenderlyVnet: true, +// }) +// let savingsPage: SavingsPageObject +// let withdrawalDialog: SavingsDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - XDAI: 100, - sDAI: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// XDAI: 100, +// sDAI: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) - await savingsPage.clickWithdrawSDaiButtonAction() +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickWithdrawSDaiButtonAction() - withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) - await withdrawalDialog.clickMaxAmountAction() - }) +// withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) +// await withdrawalDialog.clickMaxAmountAction() +// }) - test('uses native sDai withdrawal', async () => { - await withdrawalDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'sDAI' }, - { type: 'withdrawFromSavings', asset: 'XDAI', savingsAsset: 'sDAI', mode: 'withdraw' }, - ]) - }) +// test('uses native sDai withdrawal', async () => { +// await withdrawalDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'sDAI' }, +// { type: 'withdrawFromSavings', asset: 'XDAI', savingsAsset: 'sDAI', mode: 'withdraw' }, +// ]) +// }) - test('displays transaction overview', async () => { - await withdrawalDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '10,000.00 sDAI', - tokenUsdValue: '$10,878.09', - }, - { - tokenAmount: '10,878.09 XDAI', - tokenUsdValue: '$10,878.09', - }, - ], - outcome: '10,878.09 XDAI', - outcomeUsd: '$10,878.09', - }) - }) +// test('displays transaction overview', async () => { +// await withdrawalDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '10,000.00 sDAI', +// tokenUsdValue: '$10,878.09', +// }, +// { +// tokenAmount: '10,878.09 XDAI', +// tokenUsdValue: '$10,878.09', +// }, +// ], +// outcome: '10,878.09 XDAI', +// outcomeUsd: '$10,878.09', +// }) +// }) - test('executes max withdrawal', async () => { - const actionsContainer = new ActionsPageObject(withdrawalDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2, fork) +// test('executes max withdrawal', async () => { +// const actionsContainer = new ActionsPageObject(withdrawalDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2, fork) - await withdrawalDialog.expectSuccessPage() - await withdrawalDialog.clickBackToSavingsButton() +// await withdrawalDialog.expectSuccessPage() +// await withdrawalDialog.clickBackToSavingsButton() - await savingsPage.expectOpportunityStablecoinsAmount('~$10,978.09') - await savingsPage.expectStablecoinsInWalletAssetBalance('XDAI', '10,978.09') - }) -}) +// await savingsPage.expectOpportunityStablecoinsAmount('~$10,978.09') +// await savingsPage.expectStablecoinsInWalletAssetBalance('XDAI', '10,978.09') +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/WithdrawXDAI.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/WithdrawXDAI.test-e2e.ts index 8a678c26f..45583c809 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/WithdrawXDAI.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/WithdrawXDAI.test-e2e.ts @@ -1,72 +1,72 @@ -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { gnosis } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { gnosis } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -test.describe('Withdraw XDAI on Gnosis', () => { - const fork = setupFork({ - blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, - chainId: gnosis.id, - useTenderlyVnet: true, - }) - let savingsPage: SavingsPageObject - let withdrawalDialog: SavingsDialogPageObject +// test.describe('Withdraw XDAI on Gnosis', () => { +// const fork = setupFork({ +// blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, +// chainId: gnosis.id, +// useTenderlyVnet: true, +// }) +// let savingsPage: SavingsPageObject +// let withdrawalDialog: SavingsDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - XDAI: 100, - sDAI: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// XDAI: 100, +// sDAI: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) - await savingsPage.clickWithdrawSDaiButtonAction() +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickWithdrawSDaiButtonAction() - withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) - await withdrawalDialog.fillAmountAction(7000) - }) +// withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) +// await withdrawalDialog.fillAmountAction(7000) +// }) - test('uses native sDai withdrawal', async () => { - await withdrawalDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'sDAI' }, - { type: 'withdrawFromSavings', asset: 'XDAI', savingsAsset: 'sDAI', mode: 'withdraw' }, - ]) - }) +// test('uses native sDai withdrawal', async () => { +// await withdrawalDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'sDAI' }, +// { type: 'withdrawFromSavings', asset: 'XDAI', savingsAsset: 'sDAI', mode: 'withdraw' }, +// ]) +// }) - test('displays transaction overview', async () => { - await withdrawalDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '6,434.95 sDAI', - tokenUsdValue: '$7,000.00', - }, - { - tokenAmount: '7,000.00 XDAI', - tokenUsdValue: '$7,000.00', - }, - ], - outcome: '7,000.00 XDAI', - outcomeUsd: '$7,000.00', - }) - }) +// test('displays transaction overview', async () => { +// await withdrawalDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '6,434.95 sDAI', +// tokenUsdValue: '$7,000.00', +// }, +// { +// tokenAmount: '7,000.00 XDAI', +// tokenUsdValue: '$7,000.00', +// }, +// ], +// outcome: '7,000.00 XDAI', +// outcomeUsd: '$7,000.00', +// }) +// }) - test('executes withdrawal', async () => { - const actionsContainer = new ActionsPageObject(withdrawalDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2, fork) +// test('executes withdrawal', async () => { +// const actionsContainer = new ActionsPageObject(withdrawalDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2, fork) - await withdrawalDialog.expectSuccessPage() - await withdrawalDialog.clickBackToSavingsButton() +// await withdrawalDialog.expectSuccessPage() +// await withdrawalDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,565.05 sDAI', estimatedDaiValue: '3,878.09' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('XDAI', '7,100.00') - }) -}) +// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,565.05 sDAI', estimatedDaiValue: '3,878.09' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('XDAI', '7,100.00') +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendDAI.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendDAI.test-e2e.ts index 620a2781c..4ab4fcf46 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendDAI.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendDAI.test-e2e.ts @@ -1,83 +1,83 @@ -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { DEFAULT_BLOCK_NUMBER, TOKENS_ON_FORK } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { randomAddress } from '@/test/utils/addressUtils' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { DEFAULT_BLOCK_NUMBER, TOKENS_ON_FORK } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { randomAddress } from '@/test/utils/addressUtils' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -test.describe('Send DAI on Mainnet', () => { - const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let sendDialog: SavingsDialogPageObject - const receiver = randomAddress('bob') - const amount = 7000 - const dai = TOKENS_ON_FORK[mainnet.id].DAI +// test.describe('Send DAI on Mainnet', () => { +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let sendDialog: SavingsDialogPageObject +// const receiver = randomAddress('bob') +// const amount = 7000 +// const dai = TOKENS_ON_FORK[mainnet.id].DAI - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sDAI: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sDAI: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) - await savingsPage.clickSendSDaiButtonAction() +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickSendSDaiButtonAction() - sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) - await sendDialog.fillAmountAction(amount) - await sendDialog.fillReceiverAction(receiver) - }) +// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) +// await sendDialog.fillAmountAction(amount) +// await sendDialog.fillReceiverAction(receiver) +// }) - test('uses native sDai withdraw and send', async () => { - await sendDialog.actionsContainer.expectActions([ - { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, - ]) - }) +// test('uses native sDai withdraw and send', async () => { +// await sendDialog.actionsContainer.expectActions([ +// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, +// ]) +// }) - test('displays transaction overview', async () => { - await sendDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '6,647.10 sDAI', - tokenUsdValue: '$7,000.00', - }, - { - tokenAmount: '7,000.00 DAI', - tokenUsdValue: '$7,000.00', - }, - ], - outcome: '7,000.00 DAI', - outcomeUsd: '$7,000.00', - }) - }) +// test('displays transaction overview', async () => { +// await sendDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '6,647.10 sDAI', +// tokenUsdValue: '$7,000.00', +// }, +// { +// tokenAmount: '7,000.00 DAI', +// tokenUsdValue: '$7,000.00', +// }, +// ], +// outcome: '7,000.00 DAI', +// outcomeUsd: '$7,000.00', +// }) +// }) - test('executes send', async () => { - await sendDialog.expectReceiverTokenBalance({ - forkUrl: fork.forkUrl, - receiver, - token: dai, - expectedBalance: 0, - }) +// test('executes send', async () => { +// await sendDialog.expectReceiverTokenBalance({ +// forkUrl: fork.forkUrl, +// receiver, +// token: dai, +// expectedBalance: 0, +// }) - await sendDialog.actionsContainer.acceptAllActionsAction(1, fork) - await sendDialog.expectSuccessPage() +// await sendDialog.actionsContainer.acceptAllActionsAction(1, fork) +// await sendDialog.expectSuccessPage() - await sendDialog.expectReceiverTokenBalance({ - forkUrl: fork.forkUrl, - receiver, - token: dai, - expectedBalance: amount, - }) +// await sendDialog.expectReceiverTokenBalance({ +// forkUrl: fork.forkUrl, +// receiver, +// token: dai, +// expectedBalance: amount, +// }) - await sendDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,352.90 sDAI', estimatedDaiValue: '3,530.91' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') - }) -}) +// await sendDialog.clickBackToSavingsButton() +// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,352.90 sDAI', estimatedDaiValue: '3,530.91' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendDAIValidation.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendDAIValidation.test-e2e.ts index 05f580dec..f6f2be2bf 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendDAIValidation.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendDAIValidation.test-e2e.ts @@ -1,246 +1,246 @@ -import { receiverValidationIssueToMessage } from '@/domain/savings/validateReceiver' -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { Address, zeroAddress } from 'viem' -import { mainnet } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -import { withdrawValidationIssueToMessage } from '../../logic/validation' - -test.describe('Asset input validation', () => { - const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let sendDialog: SavingsDialogPageObject - const receiver = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' - - test.describe('Input value exceeds sDAI value', () => { - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sDAI: 100, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - await savingsPage.clickSendSDaiButtonAction() - - sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) - await sendDialog.fillAmountAction(200) - await sendDialog.fillReceiverAction(receiver) - }) - - test('displays validation error', async () => { - await sendDialog.expectAssetInputError(withdrawValidationIssueToMessage['exceeds-balance']) - }) - - test('actions are disabled', async () => { - await sendDialog.actionsContainer.expectDisabledActions([ - { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, - ]) - }) - - test('displays sensible tx overview', async () => { - await sendDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '189.92 sDAI', - tokenUsdValue: '$200.00', - }, - { - tokenAmount: '200.00 DAI', - tokenUsdValue: '$200.00', - }, - ], - outcome: '200.00 DAI', - outcomeUsd: '$200.00', - }) - }) - }) - - test('displays validation error for dirty input with 0 value', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sDAI: 100, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - await savingsPage.clickSendSDaiButtonAction() - sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) - - await sendDialog.fillAmountAction(10) - await sendDialog.fillAmountAction(0) - - await sendDialog.expectAssetInputError(withdrawValidationIssueToMessage['value-not-positive']) - }) -}) - -test.describe('Receiver input validation', () => { - const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let sendDialog: SavingsDialogPageObject - let selfAddress: Address - - test.describe('Incorrect receiver address', () => { - test.beforeEach(async ({ page }) => { - const { account } = await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sDAI: 100, - }, - }, - }) - - selfAddress = account - - savingsPage = new SavingsPageObject(page) - await savingsPage.clickSendSDaiButtonAction() - - sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) - await sendDialog.fillAmountAction(50) // valid input amount - }) - - test('displays validation error', async () => { - // invalid address is not valid - await sendDialog.fillReceiverAction('0x0') - await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['invalid-address']) - await sendDialog.fillReceiverAction('not-an-address') - await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['invalid-address']) - await sendDialog.fillReceiverAction('0XD8DA6BF26964AF9D7EED9E03E53415D37AA96045') // uppercase - await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['invalid-address']) - - // zero address is not valid - await sendDialog.fillReceiverAction(zeroAddress) - await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['zero-address']) - - // reserve address is not valid - await sendDialog.fillReceiverAction('0x6B175474E89094C44Da98b954EedeAC495271d0F') // dai - await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['token-address']) - - // self address is not valid - await sendDialog.fillReceiverAction(selfAddress) - await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['self-address']) - - // empty address is not valid - await sendDialog.fillReceiverAction('') - await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['undefined-receiver']) - }) - - test('actions are disabled when receiver input is invalid', async () => { - await sendDialog.fillReceiverAction('not-an-address') - await sendDialog.actionsContainer.expectDisabledActions([ - { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, - ]) - }) - - test('displays sensible tx overview when amount is provided and receiver is invalid', async () => { - await sendDialog.fillReceiverAction('not-an-address') - await sendDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '47.48 sDAI', - tokenUsdValue: '$50.00', - }, - { - tokenAmount: '50.00 DAI', - tokenUsdValue: '$50.00', - }, - ], - outcome: '50.00 DAI', - outcomeUsd: '$50.00', - }) - }) - }) - - test('displays warning when receiver is smart contract address', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sDAI: 100, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - await savingsPage.clickSendSDaiButtonAction() - sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) - await sendDialog.fillAmountAction(50) // valid input amount - - await sendDialog.fillReceiverAction('0x197E90f9FAD81970bA7976f33CbD77088E5D7cf7') // pot address - await sendDialog.expectReceiverIsSmartContractWarning() - }) -}) - -test.describe('Form validation', () => { - const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let sendDialog: SavingsDialogPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sDAI: 100, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - await savingsPage.clickSendSDaiButtonAction() - - sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) - }) - - test('actions are disabled when amount is invalid, but receiver is valid', async () => { - await sendDialog.fillAmountAction(200) - await sendDialog.fillReceiverAction('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045') - await sendDialog.actionsContainer.expectDisabledActions([ - { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, - ]) - }) - - test('actions are disabled when amount is valid, but receiver is invalid', async () => { - await sendDialog.fillAmountAction(50) - await sendDialog.fillReceiverAction('not-an-address') - await sendDialog.actionsContainer.expectDisabledActions([ - { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, - ]) - }) - - test('actions are disabled when both amount and receiver are invalid', async () => { - await sendDialog.fillAmountAction(200) - await sendDialog.fillReceiverAction('not-an-address') - await sendDialog.actionsContainer.expectDisabledActions([ - { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, - ]) - }) - - test('actions are enabled when amount and receiver are valid', async () => { - await sendDialog.fillAmountAction(50) - await sendDialog.fillReceiverAction('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045') - await sendDialog.actionsContainer.expectActions([ - { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, - ]) - }) -}) +// import { receiverValidationIssueToMessage } from '@/domain/savings/validateReceiver' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { Address, zeroAddress } from 'viem' +// import { mainnet } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +// import { withdrawValidationIssueToMessage } from '../../logic/validation' + +// test.describe('Asset input validation', () => { +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let sendDialog: SavingsDialogPageObject +// const receiver = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' + +// test.describe('Input value exceeds sDAI value', () => { +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sDAI: 100, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickSendSDaiButtonAction() + +// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) +// await sendDialog.fillAmountAction(200) +// await sendDialog.fillReceiverAction(receiver) +// }) + +// test('displays validation error', async () => { +// await sendDialog.expectAssetInputError(withdrawValidationIssueToMessage['exceeds-balance']) +// }) + +// test('actions are disabled', async () => { +// await sendDialog.actionsContainer.expectDisabledActions([ +// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, +// ]) +// }) + +// test('displays sensible tx overview', async () => { +// await sendDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '189.92 sDAI', +// tokenUsdValue: '$200.00', +// }, +// { +// tokenAmount: '200.00 DAI', +// tokenUsdValue: '$200.00', +// }, +// ], +// outcome: '200.00 DAI', +// outcomeUsd: '$200.00', +// }) +// }) +// }) + +// test('displays validation error for dirty input with 0 value', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sDAI: 100, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickSendSDaiButtonAction() +// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) + +// await sendDialog.fillAmountAction(10) +// await sendDialog.fillAmountAction(0) + +// await sendDialog.expectAssetInputError(withdrawValidationIssueToMessage['value-not-positive']) +// }) +// }) + +// test.describe('Receiver input validation', () => { +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let sendDialog: SavingsDialogPageObject +// let selfAddress: Address + +// test.describe('Incorrect receiver address', () => { +// test.beforeEach(async ({ page }) => { +// const { account } = await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sDAI: 100, +// }, +// }, +// }) + +// selfAddress = account + +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickSendSDaiButtonAction() + +// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) +// await sendDialog.fillAmountAction(50) // valid input amount +// }) + +// test('displays validation error', async () => { +// // invalid address is not valid +// await sendDialog.fillReceiverAction('0x0') +// await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['invalid-address']) +// await sendDialog.fillReceiverAction('not-an-address') +// await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['invalid-address']) +// await sendDialog.fillReceiverAction('0XD8DA6BF26964AF9D7EED9E03E53415D37AA96045') // uppercase +// await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['invalid-address']) + +// // zero address is not valid +// await sendDialog.fillReceiverAction(zeroAddress) +// await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['zero-address']) + +// // reserve address is not valid +// await sendDialog.fillReceiverAction('0x6B175474E89094C44Da98b954EedeAC495271d0F') // dai +// await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['token-address']) + +// // self address is not valid +// await sendDialog.fillReceiverAction(selfAddress) +// await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['self-address']) + +// // empty address is not valid +// await sendDialog.fillReceiverAction('') +// await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['undefined-receiver']) +// }) + +// test('actions are disabled when receiver input is invalid', async () => { +// await sendDialog.fillReceiverAction('not-an-address') +// await sendDialog.actionsContainer.expectDisabledActions([ +// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, +// ]) +// }) + +// test('displays sensible tx overview when amount is provided and receiver is invalid', async () => { +// await sendDialog.fillReceiverAction('not-an-address') +// await sendDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '47.48 sDAI', +// tokenUsdValue: '$50.00', +// }, +// { +// tokenAmount: '50.00 DAI', +// tokenUsdValue: '$50.00', +// }, +// ], +// outcome: '50.00 DAI', +// outcomeUsd: '$50.00', +// }) +// }) +// }) + +// test('displays warning when receiver is smart contract address', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sDAI: 100, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickSendSDaiButtonAction() +// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) +// await sendDialog.fillAmountAction(50) // valid input amount + +// await sendDialog.fillReceiverAction('0x197E90f9FAD81970bA7976f33CbD77088E5D7cf7') // pot address +// await sendDialog.expectReceiverIsSmartContractWarning() +// }) +// }) + +// test.describe('Form validation', () => { +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let sendDialog: SavingsDialogPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sDAI: 100, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickSendSDaiButtonAction() + +// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) +// }) + +// test('actions are disabled when amount is invalid, but receiver is valid', async () => { +// await sendDialog.fillAmountAction(200) +// await sendDialog.fillReceiverAction('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045') +// await sendDialog.actionsContainer.expectDisabledActions([ +// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, +// ]) +// }) + +// test('actions are disabled when amount is valid, but receiver is invalid', async () => { +// await sendDialog.fillAmountAction(50) +// await sendDialog.fillReceiverAction('not-an-address') +// await sendDialog.actionsContainer.expectDisabledActions([ +// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, +// ]) +// }) + +// test('actions are disabled when both amount and receiver are invalid', async () => { +// await sendDialog.fillAmountAction(200) +// await sendDialog.fillReceiverAction('not-an-address') +// await sendDialog.actionsContainer.expectDisabledActions([ +// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, +// ]) +// }) + +// test('actions are enabled when amount and receiver are valid', async () => { +// await sendDialog.fillAmountAction(50) +// await sendDialog.fillReceiverAction('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045') +// await sendDialog.actionsContainer.expectActions([ +// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, +// ]) +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDC.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDC.test-e2e.ts index 4f4df0f0c..dc5aae60b 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDC.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDC.test-e2e.ts @@ -1,176 +1,176 @@ -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { TOKENS_ON_FORK, USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { randomAddress } from '@/test/utils/addressUtils' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' - -test.describe('Send USDC (withdrawing from sUSDS)', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let sendDialog: SavingsDialogPageObject - const receiver = randomAddress('bob') - const amount = 7000 - const usdc = TOKENS_ON_FORK[mainnet.id].USDC - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDS: 10_000, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - - await savingsPage.clickDepositButtonAction('USDS') - const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) - await depositDialog.fillAmountAction(10_000) - await depositDialog.actionsContainer.acceptAllActionsAction(2, fork) - await depositDialog.clickBackToSavingsButton() - - await savingsPage.clickSendSUsdsButtonAction() - sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) - await sendDialog.selectAssetAction('USDC') - await sendDialog.fillAmountAction(amount) - await sendDialog.fillReceiverAction(receiver) - }) - - test('has correct action plan', async () => { - await sendDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'sUSDS' }, - { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'send' }, - ]) - }) - - test('displays transaction overview', async () => { - await sendDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '6,999.84 sUSDS', - tokenUsdValue: '$7,000.00', - }, - { - tokenAmount: '7,000.00 USDS', - tokenUsdValue: '$7,000.00', - }, - { - tokenAmount: '7,000.00 USDC', - tokenUsdValue: '$7,000.00', - }, - ], - outcome: '7,000.00 USDC', - outcomeUsd: '$7,000.00', - }) - }) - - test('executes send', async () => { - await sendDialog.expectReceiverTokenBalance({ - forkUrl: fork.forkUrl, - receiver, - token: usdc, - expectedBalance: 0, - }) - - await sendDialog.actionsContainer.acceptAllActionsAction(2, fork) - await sendDialog.expectSuccessPage() - - await sendDialog.expectReceiverTokenBalance({ - forkUrl: fork.forkUrl, - receiver, - token: usdc, - expectedBalance: amount, - }) - - await sendDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '2,999.93 sUSDS', estimatedUsdsValue: '3,000' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') - }) -}) - -test.describe('Send USDC (withdrawing from sDAI)', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let sendDialog: SavingsDialogPageObject - const receiver = randomAddress('bob') - const amount = 7000 - const usdc = TOKENS_ON_FORK[mainnet.id].USDC - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sDAI: 10_000, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - - await savingsPage.clickSendSDaiButtonAction() - sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) - await sendDialog.selectAssetAction('USDC') - await sendDialog.fillAmountAction(amount) - await sendDialog.fillReceiverAction(receiver) - }) - - test('uses convert sDAI to USDS action', async () => { - await sendDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'sDAI' }, - { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sDAI', mode: 'send' }, - ]) - }) - - test('displays transaction overview', async () => { - await sendDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '6,314.32 sDAI', - tokenUsdValue: '$7,000.00', - }, - { - tokenAmount: '7,000.00 DAI', - tokenUsdValue: '$7,000.00', - }, - { - tokenAmount: '7,000.00 USDC', - tokenUsdValue: '$7,000.00', - }, - ], - outcome: '7,000.00 USDC', - outcomeUsd: '$7,000.00', - }) - }) - - test('executes send', async () => { - await sendDialog.expectReceiverTokenBalance({ - forkUrl: fork.forkUrl, - receiver, - token: usdc, - expectedBalance: 0, - }) - - await sendDialog.actionsContainer.acceptAllActionsAction(2, fork) - await sendDialog.expectSuccessPage() - - await sendDialog.expectReceiverTokenBalance({ - forkUrl: fork.forkUrl, - receiver, - token: usdc, - expectedBalance: amount, - }) - - await sendDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,685.68 sDAI', estimatedDaiValue: '4,085.90' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') - }) -}) +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { TOKENS_ON_FORK, USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { randomAddress } from '@/test/utils/addressUtils' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' + +// test.describe('Send USDC (withdrawing from sUSDS)', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let sendDialog: SavingsDialogPageObject +// const receiver = randomAddress('bob') +// const amount = 7000 +// const usdc = TOKENS_ON_FORK[mainnet.id].USDC + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// USDS: 10_000, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) + +// await savingsPage.clickDepositButtonAction('USDS') +// const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) +// await depositDialog.fillAmountAction(10_000) +// await depositDialog.actionsContainer.acceptAllActionsAction(2, fork) +// await depositDialog.clickBackToSavingsButton() + +// await savingsPage.clickSendSUsdsButtonAction() +// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) +// await sendDialog.selectAssetAction('USDC') +// await sendDialog.fillAmountAction(amount) +// await sendDialog.fillReceiverAction(receiver) +// }) + +// test('has correct action plan', async () => { +// await sendDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'sUSDS' }, +// { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'send' }, +// ]) +// }) + +// test('displays transaction overview', async () => { +// await sendDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '6,999.84 sUSDS', +// tokenUsdValue: '$7,000.00', +// }, +// { +// tokenAmount: '7,000.00 USDS', +// tokenUsdValue: '$7,000.00', +// }, +// { +// tokenAmount: '7,000.00 USDC', +// tokenUsdValue: '$7,000.00', +// }, +// ], +// outcome: '7,000.00 USDC', +// outcomeUsd: '$7,000.00', +// }) +// }) + +// test('executes send', async () => { +// await sendDialog.expectReceiverTokenBalance({ +// forkUrl: fork.forkUrl, +// receiver, +// token: usdc, +// expectedBalance: 0, +// }) + +// await sendDialog.actionsContainer.acceptAllActionsAction(2, fork) +// await sendDialog.expectSuccessPage() + +// await sendDialog.expectReceiverTokenBalance({ +// forkUrl: fork.forkUrl, +// receiver, +// token: usdc, +// expectedBalance: amount, +// }) + +// await sendDialog.clickBackToSavingsButton() +// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '2,999.93 sUSDS', estimatedUsdsValue: '3,000' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') +// }) +// }) + +// test.describe('Send USDC (withdrawing from sDAI)', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let sendDialog: SavingsDialogPageObject +// const receiver = randomAddress('bob') +// const amount = 7000 +// const usdc = TOKENS_ON_FORK[mainnet.id].USDC + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sDAI: 10_000, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) + +// await savingsPage.clickSendSDaiButtonAction() +// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) +// await sendDialog.selectAssetAction('USDC') +// await sendDialog.fillAmountAction(amount) +// await sendDialog.fillReceiverAction(receiver) +// }) + +// test('uses convert sDAI to USDS action', async () => { +// await sendDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'sDAI' }, +// { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sDAI', mode: 'send' }, +// ]) +// }) + +// test('displays transaction overview', async () => { +// await sendDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '6,314.32 sDAI', +// tokenUsdValue: '$7,000.00', +// }, +// { +// tokenAmount: '7,000.00 DAI', +// tokenUsdValue: '$7,000.00', +// }, +// { +// tokenAmount: '7,000.00 USDC', +// tokenUsdValue: '$7,000.00', +// }, +// ], +// outcome: '7,000.00 USDC', +// outcomeUsd: '$7,000.00', +// }) +// }) + +// test('executes send', async () => { +// await sendDialog.expectReceiverTokenBalance({ +// forkUrl: fork.forkUrl, +// receiver, +// token: usdc, +// expectedBalance: 0, +// }) + +// await sendDialog.actionsContainer.acceptAllActionsAction(2, fork) +// await sendDialog.expectSuccessPage() + +// await sendDialog.expectReceiverTokenBalance({ +// forkUrl: fork.forkUrl, +// receiver, +// token: usdc, +// expectedBalance: amount, +// }) + +// await sendDialog.clickBackToSavingsButton() +// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,685.68 sDAI', estimatedDaiValue: '4,085.90' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDS.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDS.test-e2e.ts index 9f9223c2e..dc6b64c90 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDS.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDS.test-e2e.ts @@ -1,170 +1,170 @@ -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { TOKENS_ON_FORK, USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { randomAddress } from '@/test/utils/addressUtils' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' - -test.describe('Send USDS (withdrawing from sUSDS)', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let sendDialog: SavingsDialogPageObject - const receiver = randomAddress('bob') - const amount = 7000 - const usds = TOKENS_ON_FORK[mainnet.id].USDS - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDS: 10_000, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - - await savingsPage.clickDepositButtonAction('USDS') - const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) - await depositDialog.fillAmountAction(10_000) - await depositDialog.actionsContainer.acceptAllActionsAction(2, fork) - await depositDialog.clickBackToSavingsButton() - - await savingsPage.clickSendSUsdsButtonAction() - sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) - await sendDialog.fillAmountAction(amount) - await sendDialog.fillReceiverAction(receiver) - }) - - test('uses native sUSDS withdraw and send', async () => { - await sendDialog.actionsContainer.expectActions([ - { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'send' }, - ]) - }) - - test('displays transaction overview', async () => { - await sendDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '6,999.84 sUSDS', - tokenUsdValue: '$7,000.00', - }, - { - tokenAmount: '7,000.00 USDS', - tokenUsdValue: '$7,000.00', - }, - ], - outcome: '7,000.00 USDS', - outcomeUsd: '$7,000.00', - }) - }) - - test('executes send', async () => { - await sendDialog.expectReceiverTokenBalance({ - forkUrl: fork.forkUrl, - receiver, - token: usds, - expectedBalance: 0, - }) - - await sendDialog.actionsContainer.acceptAllActionsAction(1, fork) - await sendDialog.expectSuccessPage() - - await sendDialog.expectReceiverTokenBalance({ - forkUrl: fork.forkUrl, - receiver, - token: usds, - expectedBalance: amount, - }) - - await sendDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '2,999.93 sUSDS', estimatedUsdsValue: '3,000' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') - }) -}) - -test.describe('Send USDS (withdrawing from sDAI)', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let sendDialog: SavingsDialogPageObject - const receiver = randomAddress('bob') - const amount = 7000 - const usds = TOKENS_ON_FORK[mainnet.id].USDS - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sDAI: 10_000, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - - await savingsPage.clickSendSDaiButtonAction() - sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) - await sendDialog.selectAssetAction('USDS') - await sendDialog.fillAmountAction(amount) - await sendDialog.fillReceiverAction(receiver) - }) - - test('uses migrate sDAI to USDS action', async () => { - await sendDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'sDAI' }, - { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sDAI', mode: 'send' }, - ]) - }) - - test('displays transaction overview', async () => { - await sendDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '6,314.32 sDAI', - tokenUsdValue: '$7,000.00', - }, - { - tokenAmount: '7,000.00 DAI', - tokenUsdValue: '$7,000.00', - }, - { - tokenAmount: '7,000.00 USDS', - tokenUsdValue: '$7,000.00', - }, - ], - outcome: '7,000.00 USDS', - outcomeUsd: '$7,000.00', - }) - }) - - test('executes send', async () => { - await sendDialog.expectReceiverTokenBalance({ - forkUrl: fork.forkUrl, - receiver, - token: usds, - expectedBalance: 0, - }) - - await sendDialog.actionsContainer.acceptAllActionsAction(2, fork) - await sendDialog.expectSuccessPage() - - await sendDialog.expectReceiverTokenBalance({ - forkUrl: fork.forkUrl, - receiver, - token: usds, - expectedBalance: amount, - }) - - await sendDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,685.68 sDAI', estimatedDaiValue: '4,085.90' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') - }) -}) +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { TOKENS_ON_FORK, USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { randomAddress } from '@/test/utils/addressUtils' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' + +// test.describe('Send USDS (withdrawing from sUSDS)', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let sendDialog: SavingsDialogPageObject +// const receiver = randomAddress('bob') +// const amount = 7000 +// const usds = TOKENS_ON_FORK[mainnet.id].USDS + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// USDS: 10_000, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) + +// await savingsPage.clickDepositButtonAction('USDS') +// const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) +// await depositDialog.fillAmountAction(10_000) +// await depositDialog.actionsContainer.acceptAllActionsAction(2, fork) +// await depositDialog.clickBackToSavingsButton() + +// await savingsPage.clickSendSUsdsButtonAction() +// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) +// await sendDialog.fillAmountAction(amount) +// await sendDialog.fillReceiverAction(receiver) +// }) + +// test('uses native sUSDS withdraw and send', async () => { +// await sendDialog.actionsContainer.expectActions([ +// { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'send' }, +// ]) +// }) + +// test('displays transaction overview', async () => { +// await sendDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '6,999.84 sUSDS', +// tokenUsdValue: '$7,000.00', +// }, +// { +// tokenAmount: '7,000.00 USDS', +// tokenUsdValue: '$7,000.00', +// }, +// ], +// outcome: '7,000.00 USDS', +// outcomeUsd: '$7,000.00', +// }) +// }) + +// test('executes send', async () => { +// await sendDialog.expectReceiverTokenBalance({ +// forkUrl: fork.forkUrl, +// receiver, +// token: usds, +// expectedBalance: 0, +// }) + +// await sendDialog.actionsContainer.acceptAllActionsAction(1, fork) +// await sendDialog.expectSuccessPage() + +// await sendDialog.expectReceiverTokenBalance({ +// forkUrl: fork.forkUrl, +// receiver, +// token: usds, +// expectedBalance: amount, +// }) + +// await sendDialog.clickBackToSavingsButton() +// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '2,999.93 sUSDS', estimatedUsdsValue: '3,000' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') +// }) +// }) + +// test.describe('Send USDS (withdrawing from sDAI)', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let sendDialog: SavingsDialogPageObject +// const receiver = randomAddress('bob') +// const amount = 7000 +// const usds = TOKENS_ON_FORK[mainnet.id].USDS + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sDAI: 10_000, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) + +// await savingsPage.clickSendSDaiButtonAction() +// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) +// await sendDialog.selectAssetAction('USDS') +// await sendDialog.fillAmountAction(amount) +// await sendDialog.fillReceiverAction(receiver) +// }) + +// test('uses migrate sDAI to USDS action', async () => { +// await sendDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'sDAI' }, +// { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sDAI', mode: 'send' }, +// ]) +// }) + +// test('displays transaction overview', async () => { +// await sendDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '6,314.32 sDAI', +// tokenUsdValue: '$7,000.00', +// }, +// { +// tokenAmount: '7,000.00 DAI', +// tokenUsdValue: '$7,000.00', +// }, +// { +// tokenAmount: '7,000.00 USDS', +// tokenUsdValue: '$7,000.00', +// }, +// ], +// outcome: '7,000.00 USDS', +// outcomeUsd: '$7,000.00', +// }) +// }) + +// test('executes send', async () => { +// await sendDialog.expectReceiverTokenBalance({ +// forkUrl: fork.forkUrl, +// receiver, +// token: usds, +// expectedBalance: 0, +// }) + +// await sendDialog.actionsContainer.acceptAllActionsAction(2, fork) +// await sendDialog.expectSuccessPage() + +// await sendDialog.expectReceiverTokenBalance({ +// forkUrl: fork.forkUrl, +// receiver, +// token: usds, +// expectedBalance: amount, +// }) + +// await sendDialog.clickBackToSavingsButton() +// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,685.68 sDAI', estimatedDaiValue: '4,085.90' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawDAI.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawDAI.test-e2e.ts index 0f682b6a6..4a3fb69cd 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawDAI.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawDAI.test-e2e.ts @@ -1,144 +1,144 @@ -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -import { withdrawValidationIssueToMessage } from '../../logic/validation' - -test.describe('Withdraw DAI on Mainnet', () => { - const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) - let savingsPage: SavingsPageObject - let withdrawalDialog: SavingsDialogPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sDAI: 10_000, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - await savingsPage.clickWithdrawSDaiButtonAction() - - withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) - await withdrawalDialog.fillAmountAction(7000) - }) - - test('uses native sDai withdrawal', async () => { - await withdrawalDialog.actionsContainer.expectActions([ - { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'withdraw' }, - ]) - }) - - test('displays transaction overview', async () => { - await withdrawalDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '6,532.86 sDAI', - tokenUsdValue: '$7,000.00', - }, - { - tokenAmount: '7,000.00 DAI', - tokenUsdValue: '$7,000.00', - }, - ], - outcome: '7,000.00 DAI', - outcomeUsd: '$7,000.00', - }) - }) - - test('executes withdrawal', async () => { - const actionsContainer = new ActionsPageObject(withdrawalDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(1) - - await withdrawalDialog.expectSuccessPage() - await withdrawalDialog.clickBackToSavingsButton() - - await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,467.14 sDAI', estimatedDaiValue: '3,715.05' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '7,000.00') - }) -}) - -test.describe('Validation', () => { - const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) - let savingsPage: SavingsPageObject - let withdrawalDialog: SavingsDialogPageObject - - test.describe('Input value exceeds sDAI value', () => { - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sDAI: 100, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - await savingsPage.clickWithdrawSDaiButtonAction() - - withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) - await withdrawalDialog.fillAmountAction(200) - }) - - test('displays validation error', async () => { - await withdrawalDialog.expectAssetInputError(withdrawValidationIssueToMessage['exceeds-balance']) - }) - - test('actions are disabled', async () => { - await withdrawalDialog.actionsContainer.expectDisabledActions([ - { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'withdraw' }, - ]) - }) - - test('displays sensible tx overview', async () => { - await withdrawalDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '186.65 sDAI', - tokenUsdValue: '$200.00', - }, - { - tokenAmount: '200.00 DAI', - tokenUsdValue: '$200.00', - }, - ], - outcome: '200.00 DAI', - outcomeUsd: '$200.00', - }) - }) - }) - - test('displays validation error for dirty input with 0 value', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sDAI: 100, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - await savingsPage.clickWithdrawSDaiButtonAction() - withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) - - await withdrawalDialog.fillAmountAction(10) - await withdrawalDialog.fillAmountAction(0) - - await withdrawalDialog.expectAssetInputError(withdrawValidationIssueToMessage['value-not-positive']) - }) -}) +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +// import { withdrawValidationIssueToMessage } from '../../logic/validation' + +// test.describe('Withdraw DAI on Mainnet', () => { +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) +// let savingsPage: SavingsPageObject +// let withdrawalDialog: SavingsDialogPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sDAI: 10_000, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickWithdrawSDaiButtonAction() + +// withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) +// await withdrawalDialog.fillAmountAction(7000) +// }) + +// test('uses native sDai withdrawal', async () => { +// await withdrawalDialog.actionsContainer.expectActions([ +// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'withdraw' }, +// ]) +// }) + +// test('displays transaction overview', async () => { +// await withdrawalDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '6,532.86 sDAI', +// tokenUsdValue: '$7,000.00', +// }, +// { +// tokenAmount: '7,000.00 DAI', +// tokenUsdValue: '$7,000.00', +// }, +// ], +// outcome: '7,000.00 DAI', +// outcomeUsd: '$7,000.00', +// }) +// }) + +// test('executes withdrawal', async () => { +// const actionsContainer = new ActionsPageObject(withdrawalDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(1) + +// await withdrawalDialog.expectSuccessPage() +// await withdrawalDialog.clickBackToSavingsButton() + +// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,467.14 sDAI', estimatedDaiValue: '3,715.05' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '7,000.00') +// }) +// }) + +// test.describe('Validation', () => { +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) +// let savingsPage: SavingsPageObject +// let withdrawalDialog: SavingsDialogPageObject + +// test.describe('Input value exceeds sDAI value', () => { +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sDAI: 100, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickWithdrawSDaiButtonAction() + +// withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) +// await withdrawalDialog.fillAmountAction(200) +// }) + +// test('displays validation error', async () => { +// await withdrawalDialog.expectAssetInputError(withdrawValidationIssueToMessage['exceeds-balance']) +// }) + +// test('actions are disabled', async () => { +// await withdrawalDialog.actionsContainer.expectDisabledActions([ +// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'withdraw' }, +// ]) +// }) + +// test('displays sensible tx overview', async () => { +// await withdrawalDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '186.65 sDAI', +// tokenUsdValue: '$200.00', +// }, +// { +// tokenAmount: '200.00 DAI', +// tokenUsdValue: '$200.00', +// }, +// ], +// outcome: '200.00 DAI', +// outcomeUsd: '$200.00', +// }) +// }) +// }) + +// test('displays validation error for dirty input with 0 value', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sDAI: 100, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickWithdrawSDaiButtonAction() +// withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) + +// await withdrawalDialog.fillAmountAction(10) +// await withdrawalDialog.fillAmountAction(0) + +// await withdrawalDialog.expectAssetInputError(withdrawValidationIssueToMessage['value-not-positive']) +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxDAI.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxDAI.test-e2e.ts index 478c3be80..754cc9b65 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxDAI.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxDAI.test-e2e.ts @@ -1,67 +1,67 @@ -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -test.describe('Withdraw max DAI on Mainnet', () => { - const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) - let savingsPage: SavingsPageObject - let withdrawalDialog: SavingsDialogPageObject +// test.describe('Withdraw max DAI on Mainnet', () => { +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) +// let savingsPage: SavingsPageObject +// let withdrawalDialog: SavingsDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sDAI: 10_000, - }, - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sDAI: 10_000, +// }, +// }, +// }) - savingsPage = new SavingsPageObject(page) - await savingsPage.clickWithdrawSDaiButtonAction() +// savingsPage = new SavingsPageObject(page) +// await savingsPage.clickWithdrawSDaiButtonAction() - withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) - await withdrawalDialog.clickMaxAmountAction() - }) +// withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) +// await withdrawalDialog.clickMaxAmountAction() +// }) - test('uses native sDai withdrawal', async () => { - await withdrawalDialog.actionsContainer.expectActions([ - { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'withdraw' }, - ]) - }) +// test('uses native sDai withdrawal', async () => { +// await withdrawalDialog.actionsContainer.expectActions([ +// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'withdraw' }, +// ]) +// }) - test('displays transaction overview', async () => { - await withdrawalDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '10,000.00 sDAI', - tokenUsdValue: '$10,715.05', - }, - { - tokenAmount: '10,715.05 DAI', - tokenUsdValue: '$10,715.05', - }, - ], - outcome: '10,715.05 DAI', - outcomeUsd: '$10,715.05', - }) - }) +// test('displays transaction overview', async () => { +// await withdrawalDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '10,000.00 sDAI', +// tokenUsdValue: '$10,715.05', +// }, +// { +// tokenAmount: '10,715.05 DAI', +// tokenUsdValue: '$10,715.05', +// }, +// ], +// outcome: '10,715.05 DAI', +// outcomeUsd: '$10,715.05', +// }) +// }) - test('executes max withdrawal', async () => { - const actionsContainer = new ActionsPageObject(withdrawalDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(1) +// test('executes max withdrawal', async () => { +// const actionsContainer = new ActionsPageObject(withdrawalDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(1) - await withdrawalDialog.expectSuccessPage() - await withdrawalDialog.clickBackToSavingsButton() +// await withdrawalDialog.expectSuccessPage() +// await withdrawalDialog.clickBackToSavingsButton() - await savingsPage.expectOpportunityStablecoinsAmount('~$10,715.05') - await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '10,715.05') - }) -}) +// await savingsPage.expectOpportunityStablecoinsAmount('~$10,715.05') +// await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '10,715.05') +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts index c6fcd4f84..fd9b7fe46 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts @@ -1,148 +1,148 @@ -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' - -test.describe('Withdraw USDC from sUSDS', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let withdrawDialog: SavingsDialogPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDS: 10_000, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - - await savingsPage.clickDepositButtonAction('USDS') - const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) - await depositDialog.fillAmountAction(10_000) - await depositDialog.actionsContainer.acceptAllActionsAction(2, fork) - await depositDialog.clickBackToSavingsButton() - - await savingsPage.clickWithdrawSUsdsButtonAction() - withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) - await withdrawDialog.selectAssetAction('USDC') - await withdrawDialog.clickMaxAmountAction() - }) - - test('has correct action plan', async () => { - await withdrawDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'sUSDS' }, - { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'withdraw' }, - ]) - }) - - test('displays transaction overview', async () => { - await withdrawDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '9,999.77 sUSDS', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '10,000.00 USDC', - tokenUsdValue: '$10,000.00', - }, - ], - outcome: '10,000.00 USDC', - outcomeUsd: '$10,000.00', - }) - - await withdrawDialog.expectUpgradeSwitchToBeHidden() - }) - - test('executes withdraw', async () => { - const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2, fork) - - await withdrawDialog.expectSuccessPage() - await withdrawDialog.clickBackToSavingsButton() - - await savingsPage.expectOpportunityStablecoinsAmount('~$10,000.00') - await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '10,000') - }) -}) - -test.describe('Withdraw USDC from sDAI', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let withdrawDialog: SavingsDialogPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sDAI: 10_000, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - - await savingsPage.clickWithdrawSDaiButtonAction() - withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) - await withdrawDialog.selectAssetAction('USDC') - await withdrawDialog.clickMaxAmountAction() - }) - - test('has correct action plan', async () => { - await withdrawDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'sDAI' }, - { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sDAI', mode: 'withdraw' }, - ]) - }) - - test('displays transaction overview', async () => { - await withdrawDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '10,000.00 sDAI', - tokenUsdValue: '$11,085.91', - }, - { - tokenAmount: '11,085.91 DAI', - tokenUsdValue: '$11,085.91', - }, - { - tokenAmount: '11,085.91 USDC', - tokenUsdValue: '$11,085.91', - }, - ], - outcome: '11,085.91 USDC', - outcomeUsd: '$11,085.91', - }) - - await withdrawDialog.expectUpgradeSwitchToBeHidden() - }) - - test('executes withdraw', async () => { - const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2, fork) - - await withdrawDialog.expectSuccessPage() - await withdrawDialog.clickBackToSavingsButton() - - await savingsPage.expectOpportunityStablecoinsAmount('~$11,085.91') - await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '11,085.91') - }) -}) +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' + +// test.describe('Withdraw USDC from sUSDS', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let withdrawDialog: SavingsDialogPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// USDS: 10_000, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) + +// await savingsPage.clickDepositButtonAction('USDS') +// const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) +// await depositDialog.fillAmountAction(10_000) +// await depositDialog.actionsContainer.acceptAllActionsAction(2, fork) +// await depositDialog.clickBackToSavingsButton() + +// await savingsPage.clickWithdrawSUsdsButtonAction() +// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) +// await withdrawDialog.selectAssetAction('USDC') +// await withdrawDialog.clickMaxAmountAction() +// }) + +// test('has correct action plan', async () => { +// await withdrawDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'sUSDS' }, +// { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'withdraw' }, +// ]) +// }) + +// test('displays transaction overview', async () => { +// await withdrawDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '9,999.77 sUSDS', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '10,000.00 USDC', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// outcome: '10,000.00 USDC', +// outcomeUsd: '$10,000.00', +// }) + +// await withdrawDialog.expectUpgradeSwitchToBeHidden() +// }) + +// test('executes withdraw', async () => { +// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2, fork) + +// await withdrawDialog.expectSuccessPage() +// await withdrawDialog.clickBackToSavingsButton() + +// await savingsPage.expectOpportunityStablecoinsAmount('~$10,000.00') +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '10,000') +// }) +// }) + +// test.describe('Withdraw USDC from sDAI', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let withdrawDialog: SavingsDialogPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sDAI: 10_000, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) + +// await savingsPage.clickWithdrawSDaiButtonAction() +// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) +// await withdrawDialog.selectAssetAction('USDC') +// await withdrawDialog.clickMaxAmountAction() +// }) + +// test('has correct action plan', async () => { +// await withdrawDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'sDAI' }, +// { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sDAI', mode: 'withdraw' }, +// ]) +// }) + +// test('displays transaction overview', async () => { +// await withdrawDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '10,000.00 sDAI', +// tokenUsdValue: '$11,085.91', +// }, +// { +// tokenAmount: '11,085.91 DAI', +// tokenUsdValue: '$11,085.91', +// }, +// { +// tokenAmount: '11,085.91 USDC', +// tokenUsdValue: '$11,085.91', +// }, +// ], +// outcome: '11,085.91 USDC', +// outcomeUsd: '$11,085.91', +// }) + +// await withdrawDialog.expectUpgradeSwitchToBeHidden() +// }) + +// test('executes withdraw', async () => { +// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2, fork) + +// await withdrawDialog.expectSuccessPage() +// await withdrawDialog.clickBackToSavingsButton() + +// await savingsPage.expectOpportunityStablecoinsAmount('~$11,085.91') +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '11,085.91') +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts index 129100da9..762a7d556 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts @@ -1,142 +1,142 @@ -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' - -test.describe('Withdraw USDS from sUSDS', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let withdrawDialog: SavingsDialogPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDS: 10_000, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - - await savingsPage.clickDepositButtonAction('USDS') - const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) - await depositDialog.fillAmountAction(10_000) - await depositDialog.actionsContainer.acceptAllActionsAction(2, fork) - await depositDialog.clickBackToSavingsButton() - - await savingsPage.clickWithdrawSUsdsButtonAction() - withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) - await withdrawDialog.clickMaxAmountAction() - }) - - test('uses native sUSDS withdraw', async () => { - await withdrawDialog.actionsContainer.expectActions([ - { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, - ]) - }) - - test('displays transaction overview', async () => { - await withdrawDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '9,999.77 sUSDS', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - ], - outcome: '10,000.00 USDS', - outcomeUsd: '$10,000.00', - }) - - await withdrawDialog.expectUpgradeSwitchToBeHidden() - }) - - test('executes withdraw', async () => { - const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(1, fork) - - await withdrawDialog.expectSuccessPage() - await withdrawDialog.clickBackToSavingsButton() - - await savingsPage.expectOpportunityStablecoinsAmount('~$10,000.00') - await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000') - }) -}) - -test.describe('Withdraw USDS from sDAI', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let withdrawDialog: SavingsDialogPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sDAI: 10_000, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - - await savingsPage.clickWithdrawSDaiButtonAction() - withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) - await withdrawDialog.selectAssetAction('USDS') - await withdrawDialog.clickMaxAmountAction() - }) - - test('uses migrate sDAI to USDS action', async () => { - await withdrawDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'sDAI' }, - { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sDAI', mode: 'withdraw' }, - ]) - }) - - test('displays transaction overview', async () => { - await withdrawDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '10,000.00 sDAI', - tokenUsdValue: '$11,085.91', - }, - { - tokenAmount: '11,085.91 DAI', - tokenUsdValue: '$11,085.91', - }, - { - tokenAmount: '11,085.91 USDS', - tokenUsdValue: '$11,085.91', - }, - ], - outcome: '11,085.91 USDS', - outcomeUsd: '$11,085.91', - }) - - await withdrawDialog.expectUpgradeSwitchToBeHidden() - }) - - test('executes withdraw', async () => { - const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2, fork) - - await withdrawDialog.expectSuccessPage() - await withdrawDialog.clickBackToSavingsButton() - - await savingsPage.expectOpportunityStablecoinsAmount('~$11,085.91') - await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '11,085.91') - }) -}) +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' + +// test.describe('Withdraw USDS from sUSDS', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let withdrawDialog: SavingsDialogPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// USDS: 10_000, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) + +// await savingsPage.clickDepositButtonAction('USDS') +// const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) +// await depositDialog.fillAmountAction(10_000) +// await depositDialog.actionsContainer.acceptAllActionsAction(2, fork) +// await depositDialog.clickBackToSavingsButton() + +// await savingsPage.clickWithdrawSUsdsButtonAction() +// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) +// await withdrawDialog.clickMaxAmountAction() +// }) + +// test('uses native sUSDS withdraw', async () => { +// await withdrawDialog.actionsContainer.expectActions([ +// { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, +// ]) +// }) + +// test('displays transaction overview', async () => { +// await withdrawDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '9,999.77 sUSDS', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// outcome: '10,000.00 USDS', +// outcomeUsd: '$10,000.00', +// }) + +// await withdrawDialog.expectUpgradeSwitchToBeHidden() +// }) + +// test('executes withdraw', async () => { +// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(1, fork) + +// await withdrawDialog.expectSuccessPage() +// await withdrawDialog.clickBackToSavingsButton() + +// await savingsPage.expectOpportunityStablecoinsAmount('~$10,000.00') +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000') +// }) +// }) + +// test.describe('Withdraw USDS from sDAI', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let withdrawDialog: SavingsDialogPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sDAI: 10_000, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) + +// await savingsPage.clickWithdrawSDaiButtonAction() +// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) +// await withdrawDialog.selectAssetAction('USDS') +// await withdrawDialog.clickMaxAmountAction() +// }) + +// test('uses migrate sDAI to USDS action', async () => { +// await withdrawDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'sDAI' }, +// { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sDAI', mode: 'withdraw' }, +// ]) +// }) + +// test('displays transaction overview', async () => { +// await withdrawDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '10,000.00 sDAI', +// tokenUsdValue: '$11,085.91', +// }, +// { +// tokenAmount: '11,085.91 DAI', +// tokenUsdValue: '$11,085.91', +// }, +// { +// tokenAmount: '11,085.91 USDS', +// tokenUsdValue: '$11,085.91', +// }, +// ], +// outcome: '11,085.91 USDS', +// outcomeUsd: '$11,085.91', +// }) + +// await withdrawDialog.expectUpgradeSwitchToBeHidden() +// }) + +// test('executes withdraw', async () => { +// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2, fork) + +// await withdrawDialog.expectSuccessPage() +// await withdrawDialog.clickBackToSavingsButton() + +// await savingsPage.expectOpportunityStablecoinsAmount('~$11,085.91') +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '11,085.91') +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDC.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDC.test-e2e.ts index 6874b89b8..cd6c88b23 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDC.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDC.test-e2e.ts @@ -1,148 +1,148 @@ -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' - -test.describe('Withdraw USDC from sUSDS', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let withdrawDialog: SavingsDialogPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDC: 10_000, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - - await savingsPage.clickDepositButtonAction('USDC') - const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) - await depositDialog.fillAmountAction(10_000) - await depositDialog.actionsContainer.acceptAllActionsAction(2, fork) - await depositDialog.clickBackToSavingsButton() - - await savingsPage.clickWithdrawSUsdsButtonAction() - withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) - await withdrawDialog.selectAssetAction('USDC') - await withdrawDialog.fillAmountAction(1000) - }) - - test('has correct action plan', async () => { - await withdrawDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'sUSDS' }, - { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'withdraw' }, - ]) - }) - - test('displays transaction overview', async () => { - await withdrawDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '999.98 sUSDS', - tokenUsdValue: '$1,000.00', - }, - { - tokenAmount: '1,000.00 USDS', - tokenUsdValue: '$1,000.00', - }, - { - tokenAmount: '1,000.00 USDC', - tokenUsdValue: '$1,000.00', - }, - ], - outcome: '1,000.00 USDC', - outcomeUsd: '$1,000.00', - }) - - await withdrawDialog.expectUpgradeSwitchToBeHidden() - }) - - test('executes withdraw', async () => { - const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2, fork) - - await withdrawDialog.expectSuccessPage() - await withdrawDialog.clickBackToSavingsButton() - - await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '8,999.79 sUSDS', estimatedUsdsValue: '9,000' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '1,000') - }) -}) - -test.describe('Withdraw USDC from sDAI', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let withdrawDialog: SavingsDialogPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sDAI: 10_000, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - - await savingsPage.clickWithdrawSDaiButtonAction() - withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) - await withdrawDialog.selectAssetAction('USDC') - await withdrawDialog.fillAmountAction(1000) - }) - - test('has correct action plan', async () => { - await withdrawDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'sDAI' }, - { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sDAI', mode: 'withdraw' }, - ]) - }) - - test('displays transaction overview', async () => { - await withdrawDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '902.05 sDAI', - tokenUsdValue: '$1,000.00', - }, - { - tokenAmount: '1,000.00 DAI', - tokenUsdValue: '$1,000.00', - }, - { - tokenAmount: '1,000.00 USDC', - tokenUsdValue: '$1,000.00', - }, - ], - outcome: '1,000.00 USDC', - outcomeUsd: '$1,000.00', - }) - - await withdrawDialog.expectUpgradeSwitchToBeHidden() - }) - - test('executes withdraw', async () => { - const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2, fork) - - await withdrawDialog.expectSuccessPage() - await withdrawDialog.clickBackToSavingsButton() - - await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '9,097.95 sDAI', estimatedDaiValue: '10,085.90' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '1,000') - }) -}) +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' + +// test.describe('Withdraw USDC from sUSDS', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let withdrawDialog: SavingsDialogPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// USDC: 10_000, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) + +// await savingsPage.clickDepositButtonAction('USDC') +// const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) +// await depositDialog.fillAmountAction(10_000) +// await depositDialog.actionsContainer.acceptAllActionsAction(2, fork) +// await depositDialog.clickBackToSavingsButton() + +// await savingsPage.clickWithdrawSUsdsButtonAction() +// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) +// await withdrawDialog.selectAssetAction('USDC') +// await withdrawDialog.fillAmountAction(1000) +// }) + +// test('has correct action plan', async () => { +// await withdrawDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'sUSDS' }, +// { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'withdraw' }, +// ]) +// }) + +// test('displays transaction overview', async () => { +// await withdrawDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '999.98 sUSDS', +// tokenUsdValue: '$1,000.00', +// }, +// { +// tokenAmount: '1,000.00 USDS', +// tokenUsdValue: '$1,000.00', +// }, +// { +// tokenAmount: '1,000.00 USDC', +// tokenUsdValue: '$1,000.00', +// }, +// ], +// outcome: '1,000.00 USDC', +// outcomeUsd: '$1,000.00', +// }) + +// await withdrawDialog.expectUpgradeSwitchToBeHidden() +// }) + +// test('executes withdraw', async () => { +// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2, fork) + +// await withdrawDialog.expectSuccessPage() +// await withdrawDialog.clickBackToSavingsButton() + +// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '8,999.79 sUSDS', estimatedUsdsValue: '9,000' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '1,000') +// }) +// }) + +// test.describe('Withdraw USDC from sDAI', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let withdrawDialog: SavingsDialogPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sDAI: 10_000, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) + +// await savingsPage.clickWithdrawSDaiButtonAction() +// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) +// await withdrawDialog.selectAssetAction('USDC') +// await withdrawDialog.fillAmountAction(1000) +// }) + +// test('has correct action plan', async () => { +// await withdrawDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'sDAI' }, +// { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sDAI', mode: 'withdraw' }, +// ]) +// }) + +// test('displays transaction overview', async () => { +// await withdrawDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '902.05 sDAI', +// tokenUsdValue: '$1,000.00', +// }, +// { +// tokenAmount: '1,000.00 DAI', +// tokenUsdValue: '$1,000.00', +// }, +// { +// tokenAmount: '1,000.00 USDC', +// tokenUsdValue: '$1,000.00', +// }, +// ], +// outcome: '1,000.00 USDC', +// outcomeUsd: '$1,000.00', +// }) + +// await withdrawDialog.expectUpgradeSwitchToBeHidden() +// }) + +// test('executes withdraw', async () => { +// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2, fork) + +// await withdrawDialog.expectSuccessPage() +// await withdrawDialog.clickBackToSavingsButton() + +// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '9,097.95 sDAI', estimatedDaiValue: '10,085.90' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '1,000') +// }) +// }) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDS.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDS.test-e2e.ts index 2d2143a3e..c533d88a0 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDS.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDS.test-e2e.ts @@ -1,142 +1,142 @@ -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' - -test.describe('Withdraw USDS from sUSDS', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let withdrawDialog: SavingsDialogPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDS: 10_000, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - - await savingsPage.clickDepositButtonAction('USDS') - const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) - await depositDialog.fillAmountAction(10_000) - await depositDialog.actionsContainer.acceptAllActionsAction(2, fork) - await depositDialog.clickBackToSavingsButton() - - await savingsPage.clickWithdrawSUsdsButtonAction() - withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) - await withdrawDialog.fillAmountAction(1000) - }) - - test('uses native sUSDS withdraw', async () => { - await withdrawDialog.actionsContainer.expectActions([ - { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, - ]) - }) - - test('displays transaction overview', async () => { - await withdrawDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '999.98 sUSDS', - tokenUsdValue: '$1,000.00', - }, - { - tokenAmount: '1,000.00 USDS', - tokenUsdValue: '$1,000.00', - }, - ], - outcome: '1,000.00 USDS', - outcomeUsd: '$1,000.00', - }) - - await withdrawDialog.expectUpgradeSwitchToBeHidden() - }) - - test('executes withdraw', async () => { - const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(1, fork) - - await withdrawDialog.expectSuccessPage() - await withdrawDialog.clickBackToSavingsButton() - - await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '8,999.79 sUSDS', estimatedUsdsValue: '9,000' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '1,000') - }) -}) - -test.describe('Withdraw USDS from sDAI', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let savingsPage: SavingsPageObject - let withdrawDialog: SavingsDialogPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sDAI: 10_000, - }, - }, - }) - - savingsPage = new SavingsPageObject(page) - - await savingsPage.clickWithdrawSDaiButtonAction() - withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) - await withdrawDialog.selectAssetAction('USDS') - await withdrawDialog.fillAmountAction(1000) - }) - - test('uses migrate sDAI to USDS action', async () => { - await withdrawDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'sDAI' }, - { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sDAI', mode: 'withdraw' }, - ]) - }) - - test('displays transaction overview', async () => { - await withdrawDialog.expectNativeRouteTransactionOverview({ - routeItems: [ - { - tokenAmount: '902.05 sDAI', - tokenUsdValue: '$1,000.00', - }, - { - tokenAmount: '1,000.00 DAI', - tokenUsdValue: '$1,000.00', - }, - { - tokenAmount: '1,000.00 USDS', - tokenUsdValue: '$1,000.00', - }, - ], - outcome: '1,000.00 USDS', - outcomeUsd: '$1,000.00', - }) - - await withdrawDialog.expectUpgradeSwitchToBeHidden() - }) - - test('executes withdraw', async () => { - const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2, fork) - - await withdrawDialog.expectSuccessPage() - await withdrawDialog.clickBackToSavingsButton() - - await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '9,097.95 sDAI', estimatedDaiValue: '10,085.90' }) - await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '1,000') - }) -}) +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' + +// test.describe('Withdraw USDS from sUSDS', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let withdrawDialog: SavingsDialogPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// USDS: 10_000, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) + +// await savingsPage.clickDepositButtonAction('USDS') +// const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) +// await depositDialog.fillAmountAction(10_000) +// await depositDialog.actionsContainer.acceptAllActionsAction(2, fork) +// await depositDialog.clickBackToSavingsButton() + +// await savingsPage.clickWithdrawSUsdsButtonAction() +// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) +// await withdrawDialog.fillAmountAction(1000) +// }) + +// test('uses native sUSDS withdraw', async () => { +// await withdrawDialog.actionsContainer.expectActions([ +// { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, +// ]) +// }) + +// test('displays transaction overview', async () => { +// await withdrawDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '999.98 sUSDS', +// tokenUsdValue: '$1,000.00', +// }, +// { +// tokenAmount: '1,000.00 USDS', +// tokenUsdValue: '$1,000.00', +// }, +// ], +// outcome: '1,000.00 USDS', +// outcomeUsd: '$1,000.00', +// }) + +// await withdrawDialog.expectUpgradeSwitchToBeHidden() +// }) + +// test('executes withdraw', async () => { +// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(1, fork) + +// await withdrawDialog.expectSuccessPage() +// await withdrawDialog.clickBackToSavingsButton() + +// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '8,999.79 sUSDS', estimatedUsdsValue: '9,000' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '1,000') +// }) +// }) + +// test.describe('Withdraw USDS from sDAI', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let savingsPage: SavingsPageObject +// let withdrawDialog: SavingsDialogPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sDAI: 10_000, +// }, +// }, +// }) + +// savingsPage = new SavingsPageObject(page) + +// await savingsPage.clickWithdrawSDaiButtonAction() +// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) +// await withdrawDialog.selectAssetAction('USDS') +// await withdrawDialog.fillAmountAction(1000) +// }) + +// test('uses migrate sDAI to USDS action', async () => { +// await withdrawDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'sDAI' }, +// { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sDAI', mode: 'withdraw' }, +// ]) +// }) + +// test('displays transaction overview', async () => { +// await withdrawDialog.expectNativeRouteTransactionOverview({ +// routeItems: [ +// { +// tokenAmount: '902.05 sDAI', +// tokenUsdValue: '$1,000.00', +// }, +// { +// tokenAmount: '1,000.00 DAI', +// tokenUsdValue: '$1,000.00', +// }, +// { +// tokenAmount: '1,000.00 USDS', +// tokenUsdValue: '$1,000.00', +// }, +// ], +// outcome: '1,000.00 USDS', +// outcomeUsd: '$1,000.00', +// }) + +// await withdrawDialog.expectUpgradeSwitchToBeHidden() +// }) + +// test('executes withdraw', async () => { +// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2, fork) + +// await withdrawDialog.expectSuccessPage() +// await withdrawDialog.clickBackToSavingsButton() + +// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '9,097.95 sDAI', estimatedDaiValue: '10,085.90' }) +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '1,000') +// }) +// }) diff --git a/packages/app/src/features/dialogs/withdraw/WithdrawDialog.test-e2e.ts b/packages/app/src/features/dialogs/withdraw/WithdrawDialog.test-e2e.ts index 4b167bfc2..f82c9914e 100644 --- a/packages/app/src/features/dialogs/withdraw/WithdrawDialog.test-e2e.ts +++ b/packages/app/src/features/dialogs/withdraw/WithdrawDialog.test-e2e.ts @@ -1,644 +1,644 @@ -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' - -import { withdrawalValidationIssueToMessage } from '@/domain/market-validators/validateWithdraw' -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { BorrowPageObject } from '@/pages/Borrow.PageObject' -import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' -import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { screenshot } from '@/test/e2e/utils' - -import { CollateralDialogPageObject } from '../collateral/CollateralDialog.PageObject' -import { DialogPageObject } from '../common/Dialog.PageObject' -import { EModeDialogPageObject } from '../e-mode/EModeDialog.PageObject' -import { withdrawValidationIssueToMessage } from '../savings/withdraw/logic/validation' - -const headerRegExp = /Withdr*/ - -test.describe('Withdraw dialog', () => { - const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) - const initialBalances = { - wstETH: 100, - rETH: 100, - ETH: 100, - } - - test.describe('Position with deposit and borrow', () => { - const initialDeposits = { - wstETH: 2, - rETH: 2, - } as const - const daiToBorrow = 3500 - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ...initialBalances }, - }, - }) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) - await borrowPage.viewInMyPortfolioAction() - - const myPortfolioPage = new MyPortfolioPageObject(page) - // @todo This waits for the refetch of the data after successful borrow transaction to happen. - // This is no ideal, probably we need to refactor expectDepositTable so it takes advantage from - // playwright's timeouts instead of parsing it's current state. Then we would be able to - // easily wait for the table to be updated. - await myPortfolioPage.expectAssetToBeInDepositTable('DAI') - }) - - test('opens dialog with selected asset', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickWithdrawButtonAction('rETH') - - const withdrawDialog = new DialogPageObject(page, headerRegExp) - await withdrawDialog.expectSelectedAsset('rETH') - await withdrawDialog.expectDialogHeader('Withdraw rETH') - await withdrawDialog.expectHealthFactorBeforeVisible() - - await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-default-view') - }) - - test('calculates health factor changes correctly', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickWithdrawButtonAction('rETH') - - const withdrawDialog = new DialogPageObject(page, headerRegExp) - await withdrawDialog.fillAmountAction(1) - - await withdrawDialog.expectRiskLevelBefore('Moderate') - await withdrawDialog.expectHealthFactorBefore('2.32') - await withdrawDialog.expectRiskLevelAfter('Risky') - await withdrawDialog.expectHealthFactorAfter('1.76') - - // @note this is needed for deterministic screenshots - const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) - await actionsContainer.expectEnabledActionAtIndex(0) - - await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-health-factor') - }) - - test('has correct action plan for erc-20', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - - await myPortfolioPage.clickWithdrawButtonAction('rETH') - - const withdrawDialog = new DialogPageObject(page, headerRegExp) - await withdrawDialog.fillAmountAction(1) - const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) - await actionsContainer.expectActions([{ type: 'withdraw', asset: 'rETH' }]) - }) - - test('can withdraw erc-20', async ({ page }) => { - const withdraw = { - asset: 'rETH', - amount: 1, - } as const - - const myPortfolioPage = new MyPortfolioPageObject(page) - - await myPortfolioPage.clickWithdrawButtonAction(withdraw.asset) - - const withdrawDialog = new DialogPageObject(page, headerRegExp) - await withdrawDialog.fillAmountAction(withdraw.amount) - const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(1) - await withdrawDialog.expectSuccessPage([withdraw], fork) - - await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-erc-20-success') - - await withdrawDialog.viewInMyPortfolioAction() - - await myPortfolioPage.expectDepositTable({ - ...initialDeposits, - [withdraw.asset]: initialDeposits[withdraw.asset] - withdraw.amount, - }) - }) - }) - - test.describe('Form validation', () => { - const initialDeposits = { - wstETH: 5, - rETH: 1, - } as const - const daiToBorrow = 4500 - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ...initialBalances }, - }, - }) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) - await borrowPage.viewInMyPortfolioAction() - - const myPortfolioPage = new MyPortfolioPageObject(page) - // @todo This waits for the refetch of the data after successful borrow transaction to happen. - // This is no ideal, probably we need to refactor expectDepositTable so it takes advantage from - // playwright's timeouts instead of parsing it's current state. Then we would be able to - // easily wait for the table to be updated. - await myPortfolioPage.expectAssetToBeInDepositTable('DAI') - }) - - test('cannot withdraw amount that will result in health factor under 1', async ({ page }) => { - const withdrawAsset = 'wstETH' - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.expectDepositTable(initialDeposits) - await myPortfolioPage.clickWithdrawButtonAction(withdrawAsset) - - const withdrawDialog = new DialogPageObject(page, headerRegExp) - await withdrawDialog.expectHealthFactorBefore('2.75') - await withdrawDialog.fillAmountAction(initialDeposits[withdrawAsset] - 0.1) // we subtract small amount to ensure that we have enough balance in test, which may not be the case due to timestamp issues - await withdrawDialog.expectAssetInputError('Remaining collateral cannot support the loan') - - await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-cannot-support-loan') - }) - - test('cannot withdraw more than deposited', async ({ page }) => { - const withdrawAsset = 'rETH' - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.expectDepositTable(initialDeposits) - await myPortfolioPage.clickWithdrawButtonAction(withdrawAsset) - - const withdrawDialog = new DialogPageObject(page, headerRegExp) - await withdrawDialog.expectHealthFactorBefore('2.75') - await withdrawDialog.fillAmountAction(initialDeposits[withdrawAsset] + 1) - await withdrawDialog.expectAssetInputError(withdrawalValidationIssueToMessage['exceeds-balance']) - - await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-more-than-deposited') - }) - }) - - test.describe('Position with native deposit and borrow', () => { - const ETHdeposit = { - asset: 'ETH', - amount: 10, - } - const borrow = { - asset: 'DAI', - amount: 1000, - } - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ...initialBalances }, - }, - }) - - const borrowPage = new BorrowPageObject(page) - const actionsContainer = new ActionsPageObject(page) - await borrowPage.fillDepositAssetAction(0, ETHdeposit.asset, ETHdeposit.amount) - await borrowPage.fillBorrowAssetAction(borrow.amount) - - await borrowPage.submitAction() - - await actionsContainer.acceptAllActionsAction(2) - - await borrowPage.expectSuccessPage([ETHdeposit], borrow, fork) - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.goToMyPortfolioAction() - }) - - // @note When ETH is deposited, deposit table shows WETH instead of ETH - test('has correct action plan for native asset', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - - await myPortfolioPage.clickWithdrawButtonAction('WETH') - - const withdrawDialog = new DialogPageObject(page, headerRegExp) - await withdrawDialog.selectAssetAction('ETH') - await withdrawDialog.fillAmountAction(1) - await withdrawDialog.expectHealthFactorVisible() - const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) - await actionsContainer.expectActions([ - { type: 'approve', asset: 'aWETH' }, - { type: 'withdraw', asset: 'ETH' }, - ]) - - await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-eth-action-plan') - }) - - // @note When ETH is deposited, deposit table shows WETH instead of ETH - test('can withdraw native asset', async ({ page }) => { - const withdrawAmount = 1 - - const myPortfolioPage = new MyPortfolioPageObject(page) - - await myPortfolioPage.clickWithdrawButtonAction('WETH') - - const withdrawDialog = new DialogPageObject(page, headerRegExp) - await withdrawDialog.selectAssetAction('ETH') - await withdrawDialog.fillAmountAction(withdrawAmount) - const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) - await withdrawDialog.expectSuccessPage( - [ - { - asset: 'ETH', - amount: withdrawAmount, - }, - ], - fork, - ) - await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-eth-success') - - await withdrawDialog.viewInMyPortfolioAction() - - await myPortfolioPage.expectDepositTable({ - // @todo Figure out how WETH and ETH conversion should work - WETH: ETHdeposit.amount - withdrawAmount, - }) - }) - }) - - test.describe('Position with only deposit', () => { - const initialDeposits = { - wstETH: 10, - ETH: 2, - } as const - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ...initialBalances }, - }, - }) - - const borrowPage = new BorrowPageObject(page) - // to simulate a position with only deposits, we go through the easy borrow flow - // but interrupt it before the borrow action, going directly to the myPortfolio - // this way we have deposit transactions executed, but no borrow transaction - // resulting in a position with only deposits - await borrowPage.fillDepositAssetAction(0, 'wstETH', initialDeposits.wstETH) - await borrowPage.addNewDepositAssetAction() - await borrowPage.fillBorrowAssetAction(1) // doesn't matter, we're not borrowing anything - await borrowPage.fillDepositAssetAction(1, 'ETH', initialDeposits.ETH) - await borrowPage.submitAction() - - const actionsContainer = new ActionsPageObject(page) - await actionsContainer.acceptAllActionsAction(3) - await actionsContainer.expectEnabledActionAtIndex(3) - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.goToMyPortfolioAction() - }) - - test('can withdraw erc-20', async ({ page }) => { - const withdraw = { - asset: 'wstETH', - amount: 1, - } as const - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickWithdrawButtonAction(withdraw.asset) - - const withdrawDialog = new DialogPageObject(page, headerRegExp) - await withdrawDialog.fillAmountAction(withdraw.amount) - const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(1) - await withdrawDialog.expectSuccessPage([withdraw], fork) - - await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-only-deposit-erc-20-success') - - await withdrawDialog.viewInMyPortfolioAction() - - await myPortfolioPage.expectDepositTable({ - WETH: initialDeposits.ETH, - [withdraw.asset]: initialDeposits[withdraw.asset] - withdraw.amount, - }) - }) - - test('can fully withdraw erc-20', async ({ page }) => { - const withdraw = { - asset: 'wstETH', - amount: 10, - } as const - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickWithdrawButtonAction(withdraw.asset) - - const withdrawDialog = new DialogPageObject(page, headerRegExp) - await withdrawDialog.clickMaxAmountAction() - const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(1) - await withdrawDialog.expectSuccessPage([withdraw], fork) - - await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-only-deposit-erc-20-success') - - await withdrawDialog.viewInMyPortfolioAction() - - await myPortfolioPage.expectDepositTable({ - WETH: initialDeposits.ETH, - [withdraw.asset]: 0, - }) - }) - - test('does not display health factor', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickWithdrawButtonAction('wstETH') - - const withdrawDialog = new DialogPageObject(page, headerRegExp) - await withdrawDialog.fillAmountAction(1) - - await withdrawDialog.expectHealthFactorNotVisible() - - // @note this is needed for deterministic screenshots - const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) - await actionsContainer.expectEnabledActionAtIndex(0) - - await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-only-deposit-health-factor') - }) - - test('can fully withdraw native asset', async ({ page }) => { - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.clickWithdrawButtonAction('WETH') - - const withdrawDialog = new DialogPageObject(page, headerRegExp) - await withdrawDialog.selectAssetAction('ETH') - await withdrawDialog.clickMaxAmountAction() - const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(2) - await withdrawDialog.expectSuccessPage( - [ - { - asset: 'ETH', - amount: initialDeposits.ETH, - }, - ], - fork, - ) - - await withdrawDialog.viewInMyPortfolioAction() - - await myPortfolioPage.expectDepositTable({ - WETH: 0, - wstETH: initialDeposits.wstETH, - }) - }) - }) - - test.describe('Liquidation risk warning', () => { - let withdrawDialog: DialogPageObject - let myPortfolioPage: MyPortfolioPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, - }, - }) - - withdrawDialog = new DialogPageObject(page, headerRegExp) - myPortfolioPage = new MyPortfolioPageObject(page) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositWithoutBorrowActions({ rETH: 2, wstETH: 10 }) - await myPortfolioPage.goToMyPortfolioAction() - - await myPortfolioPage.clickBorrowButtonAction('WETH') - const borrowDialog = new DialogPageObject(page, /Borrow/) - await borrowDialog.fillAmountAction(7) - await borrowDialog.actionsContainer.acceptAllActionsAction(1) - await borrowDialog.expectSuccessPage([{ asset: 'WETH', amount: 7 }], fork) - await borrowDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectAssetToBeInBorrowTable('WETH') - }) - - test('shows risk warning', async () => { - await myPortfolioPage.clickWithdrawButtonAction('rETH') - - await withdrawDialog.clickMaxAmountAction() - await withdrawDialog.expectLiquidationRiskWarning( - 'Withdrawing this amount puts you at risk of quick liquidation. You may lose part of your collateral.', - ) - }) - - test('actions stay disabled until risk warning is acknowledged', async () => { - await myPortfolioPage.clickWithdrawButtonAction('rETH') - - await withdrawDialog.clickMaxAmountAction() - await withdrawDialog.actionsContainer.expectDisabledActionAtIndex(0) - await withdrawDialog.clickAcknowledgeRisk() - await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) - }) - - test('hf above danger zone threshold; risk warning is not shown', async () => { - await myPortfolioPage.clickWithdrawButtonAction('rETH') - - await withdrawDialog.fillAmountAction(0.1) - await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) - await withdrawDialog.expectLiquidationRiskWarningNotVisible() - }) - - test('input validation error; risk warning is not shown', async () => { - await myPortfolioPage.clickWithdrawButtonAction('rETH') - - await withdrawDialog.fillAmountAction(0) - await withdrawDialog.expectAssetInputError(withdrawValidationIssueToMessage['value-not-positive']) - await withdrawDialog.expectLiquidationRiskWarningNotVisible() - }) - - test('hf in danger zone; asset not collateral; risk warning is not shown', async ({ page }) => { - // disabling collateral and entering danger zone - await myPortfolioPage.clickCollateralSwitchAction('rETH') - const collateralDialog = new CollateralDialogPageObject(page) - await collateralDialog.clickAcknowledgeRisk() - await collateralDialog.actionsContainer.acceptAllActionsAction(1) - await collateralDialog.expectSetUseAsCollateralSuccessPage('rETH', 'disabled') - await myPortfolioPage.goToMyPortfolioAction() - await myPortfolioPage.expectCollateralSwitch('rETH', false) - - await myPortfolioPage.clickWithdrawButtonAction('rETH') - await withdrawDialog.clickMaxAmountAction() - await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) - await withdrawDialog.expectLiquidationRiskWarningNotVisible() - }) - }) - - test.describe('MAX button', () => { - let withdrawDialog: DialogPageObject - let borrowDialog: DialogPageObject - let depositDialog: DialogPageObject - let myPortfolioPage: MyPortfolioPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'myPortfolio', - account: { - type: 'connected-random', - assetBalances: { ETH: 10, wstETH: 5, rETH: 1, WBTC: 1 }, - }, - }) - - withdrawDialog = new DialogPageObject(page, headerRegExp) - myPortfolioPage = new MyPortfolioPageObject(page) - borrowDialog = new DialogPageObject(page, /Borrow/) - - await myPortfolioPage.clickDepositButtonAction('wstETH') - depositDialog = new DialogPageObject(page, /Deposit/) - await depositDialog.fillAmountAction(5) - await depositDialog.actionsContainer.acceptAllActionsAction(2, fork) - await depositDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectDepositedAssets(13_104.84) - }) - - test('withdraws amount up to HF 1.01', async () => { - await myPortfolioPage.clickBorrowButtonAction('DAI') - await borrowDialog.fillAmountAction(5000) - await borrowDialog.actionsContainer.acceptAllActionsAction(1) - await borrowDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectHealthFactor('2.08') - - await myPortfolioPage.clickWithdrawButtonAction('wstETH') - - await withdrawDialog.clickMaxAmountAction() - await withdrawDialog.clickAcknowledgeRisk() - - await withdrawDialog.expectInputValue('2.576392') - await withdrawDialog.expectHealthFactorBefore('2.08') - await withdrawDialog.expectHealthFactorAfter('1.01') - await withdrawDialog.actionsContainer.expectActions([{ type: 'withdraw', asset: 'wstETH' }]) - await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) - }) - - test('works for collaterals with different liquidation thresholds', async () => { - await myPortfolioPage.clickDepositButtonAction('WBTC') - await depositDialog.fillAmountAction(1) - await depositDialog.actionsContainer.acceptAllActionsAction(2) - await depositDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectDepositedAssets(54_910) - - await myPortfolioPage.clickBorrowButtonAction('DAI') - await borrowDialog.fillAmountAction(35000) - await borrowDialog.clickAcknowledgeRisk() - await borrowDialog.actionsContainer.acceptAllActionsAction(1) - await borrowDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectHealthFactor('1.19') - - await myPortfolioPage.clickWithdrawButtonAction('WBTC') - - await withdrawDialog.clickMaxAmountAction() - await withdrawDialog.clickAcknowledgeRisk() - - await withdrawDialog.expectInputValue('0.204922') - await withdrawDialog.expectHealthFactorBefore('1.19') - await withdrawDialog.expectHealthFactorAfter('1.01') - await withdrawDialog.actionsContainer.expectActions([{ type: 'withdraw', asset: 'WBTC' }]) - await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) - }) - - test('works in e-mode', async ({ page }) => { - await myPortfolioPage.clickBorrowButtonAction('WETH') - await borrowDialog.fillAmountAction(2) - await borrowDialog.actionsContainer.acceptAllActionsAction(1) - await borrowDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectHealthFactor('2.3') - await myPortfolioPage.clickEModeButtonAction() - const eModeDialog = new EModeDialogPageObject(page) - await eModeDialog.clickEModeCategoryTileAction('ETH Correlated') - await eModeDialog.actionsContainer.acceptAllActionsAction(1) - await eModeDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectHealthFactor('2.69') - - await myPortfolioPage.clickWithdrawButtonAction('wstETH') - await withdrawDialog.clickMaxAmountAction() - await withdrawDialog.clickAcknowledgeRisk() - - await withdrawDialog.expectInputValue('3.119467') - await withdrawDialog.expectHealthFactorBefore('2.69') - await withdrawDialog.expectHealthFactorAfter('1.01') - await withdrawDialog.actionsContainer.expectActions([{ type: 'withdraw', asset: 'wstETH' }]) - await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) - }) - - test('works for asset with usage as collateral disabled', async ({ page }) => { - await myPortfolioPage.clickBorrowButtonAction('DAI') - await borrowDialog.clickMaxAmountAction() - await borrowDialog.clickAcknowledgeRisk() - await borrowDialog.actionsContainer.acceptAllActionsAction(1) - await borrowDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectHealthFactor('1.17') - - await myPortfolioPage.clickDepositButtonAction('rETH') - const depositDialog = new DialogPageObject(page, /Deposit/) - await depositDialog.fillAmountAction(1) - await depositDialog.actionsContainer.acceptAllActionsAction(2) - await depositDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectHealthFactor('1.39') - - await myPortfolioPage.clickCollateralSwitchAction('rETH') - const collateralDialog = new CollateralDialogPageObject(page) - await collateralDialog.clickAcknowledgeRisk() - await collateralDialog.setUseAsCollateralAction('rETH', 'disabled') - await myPortfolioPage.goToMyPortfolioAction() - await myPortfolioPage.expectHealthFactor('1.17') - - await myPortfolioPage.clickWithdrawButtonAction('rETH') - await withdrawDialog.clickMaxAmountAction() - - await withdrawDialog.expectInputValue('1') - await withdrawDialog.expectMaxButtonDisabled() - await withdrawDialog.expectHealthFactorBefore('1.17') - await withdrawDialog.expectHealthFactorAfter('1.17') - await withdrawDialog.actionsContainer.expectActions([{ type: 'withdraw', asset: 'rETH' }]) - await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) - }) - - test('native asset withdrawal requires enough approval', async () => { - await myPortfolioPage.clickDepositButtonAction('WETH') - await depositDialog.selectAssetAction('ETH') - await depositDialog.fillAmountAction(5) - await depositDialog.actionsContainer.acceptAllActionsAction(1, fork) - await depositDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectDepositedAssets(24_450) - - await myPortfolioPage.clickWithdrawButtonAction('WETH') - await withdrawDialog.selectAssetAction('ETH') - await withdrawDialog.clickMaxAmountAction() - - await withdrawDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'aWETH' }, - { type: 'withdraw', asset: 'ETH' }, - ]) - - await withdrawDialog.actionsContainer.acceptActionAtIndex(0, fork) - await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(1) - await withdrawDialog.closeDialog() - - await myPortfolioPage.clickDepositButtonAction('WETH') - await depositDialog.selectAssetAction('ETH') - await depositDialog.fillAmountAction(4) - await depositDialog.actionsContainer.acceptAllActionsAction(1) - await depositDialog.viewInMyPortfolioAction() - await myPortfolioPage.expectDepositedAssets(33_530) - - // following checks leverage the fact that approval is cached, therefore we input different values to estimate the approval value - await myPortfolioPage.clickWithdrawButtonAction('WETH') - await withdrawDialog.selectAssetAction('ETH') - await withdrawDialog.fillAmountAction(5.000001) - await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(1) - await withdrawDialog.fillAmountAction(5.000003) - await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(1) - await withdrawDialog.fillAmountAction(5.000004) - await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) - }) - }) -}) +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' + +// import { withdrawalValidationIssueToMessage } from '@/domain/market-validators/validateWithdraw' +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { BorrowPageObject } from '@/pages/Borrow.PageObject' +// import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { screenshot } from '@/test/e2e/utils' + +// import { CollateralDialogPageObject } from '../collateral/CollateralDialog.PageObject' +// import { DialogPageObject } from '../common/Dialog.PageObject' +// import { EModeDialogPageObject } from '../e-mode/EModeDialog.PageObject' +// import { withdrawValidationIssueToMessage } from '../savings/withdraw/logic/validation' + +// const headerRegExp = /Withdr*/ + +// test.describe('Withdraw dialog', () => { +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) +// const initialBalances = { +// wstETH: 100, +// rETH: 100, +// ETH: 100, +// } + +// test.describe('Position with deposit and borrow', () => { +// const initialDeposits = { +// wstETH: 2, +// rETH: 2, +// } as const +// const daiToBorrow = 3500 + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ...initialBalances }, +// }, +// }) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) +// await borrowPage.viewInMyPortfolioAction() + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// // @todo This waits for the refetch of the data after successful borrow transaction to happen. +// // This is no ideal, probably we need to refactor expectDepositTable so it takes advantage from +// // playwright's timeouts instead of parsing it's current state. Then we would be able to +// // easily wait for the table to be updated. +// await myPortfolioPage.expectAssetToBeInDepositTable('DAI') +// }) + +// test('opens dialog with selected asset', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickWithdrawButtonAction('rETH') + +// const withdrawDialog = new DialogPageObject(page, headerRegExp) +// await withdrawDialog.expectSelectedAsset('rETH') +// await withdrawDialog.expectDialogHeader('Withdraw rETH') +// await withdrawDialog.expectHealthFactorBeforeVisible() + +// await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-default-view') +// }) + +// test('calculates health factor changes correctly', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickWithdrawButtonAction('rETH') + +// const withdrawDialog = new DialogPageObject(page, headerRegExp) +// await withdrawDialog.fillAmountAction(1) + +// await withdrawDialog.expectRiskLevelBefore('Moderate') +// await withdrawDialog.expectHealthFactorBefore('2.32') +// await withdrawDialog.expectRiskLevelAfter('Risky') +// await withdrawDialog.expectHealthFactorAfter('1.76') + +// // @note this is needed for deterministic screenshots +// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) +// await actionsContainer.expectEnabledActionAtIndex(0) + +// await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-health-factor') +// }) + +// test('has correct action plan for erc-20', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) + +// await myPortfolioPage.clickWithdrawButtonAction('rETH') + +// const withdrawDialog = new DialogPageObject(page, headerRegExp) +// await withdrawDialog.fillAmountAction(1) +// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) +// await actionsContainer.expectActions([{ type: 'withdraw', asset: 'rETH' }]) +// }) + +// test('can withdraw erc-20', async ({ page }) => { +// const withdraw = { +// asset: 'rETH', +// amount: 1, +// } as const + +// const myPortfolioPage = new MyPortfolioPageObject(page) + +// await myPortfolioPage.clickWithdrawButtonAction(withdraw.asset) + +// const withdrawDialog = new DialogPageObject(page, headerRegExp) +// await withdrawDialog.fillAmountAction(withdraw.amount) +// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(1) +// await withdrawDialog.expectSuccessPage([withdraw], fork) + +// await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-erc-20-success') + +// await withdrawDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.expectDepositTable({ +// ...initialDeposits, +// [withdraw.asset]: initialDeposits[withdraw.asset] - withdraw.amount, +// }) +// }) +// }) + +// test.describe('Form validation', () => { +// const initialDeposits = { +// wstETH: 5, +// rETH: 1, +// } as const +// const daiToBorrow = 4500 + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ...initialBalances }, +// }, +// }) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) +// await borrowPage.viewInMyPortfolioAction() + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// // @todo This waits for the refetch of the data after successful borrow transaction to happen. +// // This is no ideal, probably we need to refactor expectDepositTable so it takes advantage from +// // playwright's timeouts instead of parsing it's current state. Then we would be able to +// // easily wait for the table to be updated. +// await myPortfolioPage.expectAssetToBeInDepositTable('DAI') +// }) + +// test('cannot withdraw amount that will result in health factor under 1', async ({ page }) => { +// const withdrawAsset = 'wstETH' +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.expectDepositTable(initialDeposits) +// await myPortfolioPage.clickWithdrawButtonAction(withdrawAsset) + +// const withdrawDialog = new DialogPageObject(page, headerRegExp) +// await withdrawDialog.expectHealthFactorBefore('2.75') +// await withdrawDialog.fillAmountAction(initialDeposits[withdrawAsset] - 0.1) // we subtract small amount to ensure that we have enough balance in test, which may not be the case due to timestamp issues +// await withdrawDialog.expectAssetInputError('Remaining collateral cannot support the loan') + +// await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-cannot-support-loan') +// }) + +// test('cannot withdraw more than deposited', async ({ page }) => { +// const withdrawAsset = 'rETH' +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.expectDepositTable(initialDeposits) +// await myPortfolioPage.clickWithdrawButtonAction(withdrawAsset) + +// const withdrawDialog = new DialogPageObject(page, headerRegExp) +// await withdrawDialog.expectHealthFactorBefore('2.75') +// await withdrawDialog.fillAmountAction(initialDeposits[withdrawAsset] + 1) +// await withdrawDialog.expectAssetInputError(withdrawalValidationIssueToMessage['exceeds-balance']) + +// await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-more-than-deposited') +// }) +// }) + +// test.describe('Position with native deposit and borrow', () => { +// const ETHdeposit = { +// asset: 'ETH', +// amount: 10, +// } +// const borrow = { +// asset: 'DAI', +// amount: 1000, +// } + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ...initialBalances }, +// }, +// }) + +// const borrowPage = new BorrowPageObject(page) +// const actionsContainer = new ActionsPageObject(page) +// await borrowPage.fillDepositAssetAction(0, ETHdeposit.asset, ETHdeposit.amount) +// await borrowPage.fillBorrowAssetAction(borrow.amount) + +// await borrowPage.submitAction() + +// await actionsContainer.acceptAllActionsAction(2) + +// await borrowPage.expectSuccessPage([ETHdeposit], borrow, fork) + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.goToMyPortfolioAction() +// }) + +// // @note When ETH is deposited, deposit table shows WETH instead of ETH +// test('has correct action plan for native asset', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) + +// await myPortfolioPage.clickWithdrawButtonAction('WETH') + +// const withdrawDialog = new DialogPageObject(page, headerRegExp) +// await withdrawDialog.selectAssetAction('ETH') +// await withdrawDialog.fillAmountAction(1) +// await withdrawDialog.expectHealthFactorVisible() +// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) +// await actionsContainer.expectActions([ +// { type: 'approve', asset: 'aWETH' }, +// { type: 'withdraw', asset: 'ETH' }, +// ]) + +// await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-eth-action-plan') +// }) + +// // @note When ETH is deposited, deposit table shows WETH instead of ETH +// test('can withdraw native asset', async ({ page }) => { +// const withdrawAmount = 1 + +// const myPortfolioPage = new MyPortfolioPageObject(page) + +// await myPortfolioPage.clickWithdrawButtonAction('WETH') + +// const withdrawDialog = new DialogPageObject(page, headerRegExp) +// await withdrawDialog.selectAssetAction('ETH') +// await withdrawDialog.fillAmountAction(withdrawAmount) +// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) +// await withdrawDialog.expectSuccessPage( +// [ +// { +// asset: 'ETH', +// amount: withdrawAmount, +// }, +// ], +// fork, +// ) +// await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-eth-success') + +// await withdrawDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.expectDepositTable({ +// // @todo Figure out how WETH and ETH conversion should work +// WETH: ETHdeposit.amount - withdrawAmount, +// }) +// }) +// }) + +// test.describe('Position with only deposit', () => { +// const initialDeposits = { +// wstETH: 10, +// ETH: 2, +// } as const + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ...initialBalances }, +// }, +// }) + +// const borrowPage = new BorrowPageObject(page) +// // to simulate a position with only deposits, we go through the easy borrow flow +// // but interrupt it before the borrow action, going directly to the myPortfolio +// // this way we have deposit transactions executed, but no borrow transaction +// // resulting in a position with only deposits +// await borrowPage.fillDepositAssetAction(0, 'wstETH', initialDeposits.wstETH) +// await borrowPage.addNewDepositAssetAction() +// await borrowPage.fillBorrowAssetAction(1) // doesn't matter, we're not borrowing anything +// await borrowPage.fillDepositAssetAction(1, 'ETH', initialDeposits.ETH) +// await borrowPage.submitAction() + +// const actionsContainer = new ActionsPageObject(page) +// await actionsContainer.acceptAllActionsAction(3) +// await actionsContainer.expectEnabledActionAtIndex(3) + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.goToMyPortfolioAction() +// }) + +// test('can withdraw erc-20', async ({ page }) => { +// const withdraw = { +// asset: 'wstETH', +// amount: 1, +// } as const + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickWithdrawButtonAction(withdraw.asset) + +// const withdrawDialog = new DialogPageObject(page, headerRegExp) +// await withdrawDialog.fillAmountAction(withdraw.amount) +// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(1) +// await withdrawDialog.expectSuccessPage([withdraw], fork) + +// await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-only-deposit-erc-20-success') + +// await withdrawDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.expectDepositTable({ +// WETH: initialDeposits.ETH, +// [withdraw.asset]: initialDeposits[withdraw.asset] - withdraw.amount, +// }) +// }) + +// test('can fully withdraw erc-20', async ({ page }) => { +// const withdraw = { +// asset: 'wstETH', +// amount: 10, +// } as const + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickWithdrawButtonAction(withdraw.asset) + +// const withdrawDialog = new DialogPageObject(page, headerRegExp) +// await withdrawDialog.clickMaxAmountAction() +// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(1) +// await withdrawDialog.expectSuccessPage([withdraw], fork) + +// await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-only-deposit-erc-20-success') + +// await withdrawDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.expectDepositTable({ +// WETH: initialDeposits.ETH, +// [withdraw.asset]: 0, +// }) +// }) + +// test('does not display health factor', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickWithdrawButtonAction('wstETH') + +// const withdrawDialog = new DialogPageObject(page, headerRegExp) +// await withdrawDialog.fillAmountAction(1) + +// await withdrawDialog.expectHealthFactorNotVisible() + +// // @note this is needed for deterministic screenshots +// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) +// await actionsContainer.expectEnabledActionAtIndex(0) + +// await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-only-deposit-health-factor') +// }) + +// test('can fully withdraw native asset', async ({ page }) => { +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.clickWithdrawButtonAction('WETH') + +// const withdrawDialog = new DialogPageObject(page, headerRegExp) +// await withdrawDialog.selectAssetAction('ETH') +// await withdrawDialog.clickMaxAmountAction() +// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(2) +// await withdrawDialog.expectSuccessPage( +// [ +// { +// asset: 'ETH', +// amount: initialDeposits.ETH, +// }, +// ], +// fork, +// ) + +// await withdrawDialog.viewInMyPortfolioAction() + +// await myPortfolioPage.expectDepositTable({ +// WETH: 0, +// wstETH: initialDeposits.wstETH, +// }) +// }) +// }) + +// test.describe('Liquidation risk warning', () => { +// let withdrawDialog: DialogPageObject +// let myPortfolioPage: MyPortfolioPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, +// }, +// }) + +// withdrawDialog = new DialogPageObject(page, headerRegExp) +// myPortfolioPage = new MyPortfolioPageObject(page) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositWithoutBorrowActions({ rETH: 2, wstETH: 10 }) +// await myPortfolioPage.goToMyPortfolioAction() + +// await myPortfolioPage.clickBorrowButtonAction('WETH') +// const borrowDialog = new DialogPageObject(page, /Borrow/) +// await borrowDialog.fillAmountAction(7) +// await borrowDialog.actionsContainer.acceptAllActionsAction(1) +// await borrowDialog.expectSuccessPage([{ asset: 'WETH', amount: 7 }], fork) +// await borrowDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectAssetToBeInBorrowTable('WETH') +// }) + +// test('shows risk warning', async () => { +// await myPortfolioPage.clickWithdrawButtonAction('rETH') + +// await withdrawDialog.clickMaxAmountAction() +// await withdrawDialog.expectLiquidationRiskWarning( +// 'Withdrawing this amount puts you at risk of quick liquidation. You may lose part of your collateral.', +// ) +// }) + +// test('actions stay disabled until risk warning is acknowledged', async () => { +// await myPortfolioPage.clickWithdrawButtonAction('rETH') + +// await withdrawDialog.clickMaxAmountAction() +// await withdrawDialog.actionsContainer.expectDisabledActionAtIndex(0) +// await withdrawDialog.clickAcknowledgeRisk() +// await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) +// }) + +// test('hf above danger zone threshold; risk warning is not shown', async () => { +// await myPortfolioPage.clickWithdrawButtonAction('rETH') + +// await withdrawDialog.fillAmountAction(0.1) +// await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) +// await withdrawDialog.expectLiquidationRiskWarningNotVisible() +// }) + +// test('input validation error; risk warning is not shown', async () => { +// await myPortfolioPage.clickWithdrawButtonAction('rETH') + +// await withdrawDialog.fillAmountAction(0) +// await withdrawDialog.expectAssetInputError(withdrawValidationIssueToMessage['value-not-positive']) +// await withdrawDialog.expectLiquidationRiskWarningNotVisible() +// }) + +// test('hf in danger zone; asset not collateral; risk warning is not shown', async ({ page }) => { +// // disabling collateral and entering danger zone +// await myPortfolioPage.clickCollateralSwitchAction('rETH') +// const collateralDialog = new CollateralDialogPageObject(page) +// await collateralDialog.clickAcknowledgeRisk() +// await collateralDialog.actionsContainer.acceptAllActionsAction(1) +// await collateralDialog.expectSetUseAsCollateralSuccessPage('rETH', 'disabled') +// await myPortfolioPage.goToMyPortfolioAction() +// await myPortfolioPage.expectCollateralSwitch('rETH', false) + +// await myPortfolioPage.clickWithdrawButtonAction('rETH') +// await withdrawDialog.clickMaxAmountAction() +// await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) +// await withdrawDialog.expectLiquidationRiskWarningNotVisible() +// }) +// }) + +// test.describe('MAX button', () => { +// let withdrawDialog: DialogPageObject +// let borrowDialog: DialogPageObject +// let depositDialog: DialogPageObject +// let myPortfolioPage: MyPortfolioPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'myPortfolio', +// account: { +// type: 'connected-random', +// assetBalances: { ETH: 10, wstETH: 5, rETH: 1, WBTC: 1 }, +// }, +// }) + +// withdrawDialog = new DialogPageObject(page, headerRegExp) +// myPortfolioPage = new MyPortfolioPageObject(page) +// borrowDialog = new DialogPageObject(page, /Borrow/) + +// await myPortfolioPage.clickDepositButtonAction('wstETH') +// depositDialog = new DialogPageObject(page, /Deposit/) +// await depositDialog.fillAmountAction(5) +// await depositDialog.actionsContainer.acceptAllActionsAction(2, fork) +// await depositDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectDepositedAssets(13_104.84) +// }) + +// test('withdraws amount up to HF 1.01', async () => { +// await myPortfolioPage.clickBorrowButtonAction('DAI') +// await borrowDialog.fillAmountAction(5000) +// await borrowDialog.actionsContainer.acceptAllActionsAction(1) +// await borrowDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectHealthFactor('2.08') + +// await myPortfolioPage.clickWithdrawButtonAction('wstETH') + +// await withdrawDialog.clickMaxAmountAction() +// await withdrawDialog.clickAcknowledgeRisk() + +// await withdrawDialog.expectInputValue('2.576392') +// await withdrawDialog.expectHealthFactorBefore('2.08') +// await withdrawDialog.expectHealthFactorAfter('1.01') +// await withdrawDialog.actionsContainer.expectActions([{ type: 'withdraw', asset: 'wstETH' }]) +// await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) +// }) + +// test('works for collaterals with different liquidation thresholds', async () => { +// await myPortfolioPage.clickDepositButtonAction('WBTC') +// await depositDialog.fillAmountAction(1) +// await depositDialog.actionsContainer.acceptAllActionsAction(2) +// await depositDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectDepositedAssets(54_910) + +// await myPortfolioPage.clickBorrowButtonAction('DAI') +// await borrowDialog.fillAmountAction(35000) +// await borrowDialog.clickAcknowledgeRisk() +// await borrowDialog.actionsContainer.acceptAllActionsAction(1) +// await borrowDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectHealthFactor('1.19') + +// await myPortfolioPage.clickWithdrawButtonAction('WBTC') + +// await withdrawDialog.clickMaxAmountAction() +// await withdrawDialog.clickAcknowledgeRisk() + +// await withdrawDialog.expectInputValue('0.204922') +// await withdrawDialog.expectHealthFactorBefore('1.19') +// await withdrawDialog.expectHealthFactorAfter('1.01') +// await withdrawDialog.actionsContainer.expectActions([{ type: 'withdraw', asset: 'WBTC' }]) +// await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) +// }) + +// test('works in e-mode', async ({ page }) => { +// await myPortfolioPage.clickBorrowButtonAction('WETH') +// await borrowDialog.fillAmountAction(2) +// await borrowDialog.actionsContainer.acceptAllActionsAction(1) +// await borrowDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectHealthFactor('2.3') +// await myPortfolioPage.clickEModeButtonAction() +// const eModeDialog = new EModeDialogPageObject(page) +// await eModeDialog.clickEModeCategoryTileAction('ETH Correlated') +// await eModeDialog.actionsContainer.acceptAllActionsAction(1) +// await eModeDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectHealthFactor('2.69') + +// await myPortfolioPage.clickWithdrawButtonAction('wstETH') +// await withdrawDialog.clickMaxAmountAction() +// await withdrawDialog.clickAcknowledgeRisk() + +// await withdrawDialog.expectInputValue('3.119467') +// await withdrawDialog.expectHealthFactorBefore('2.69') +// await withdrawDialog.expectHealthFactorAfter('1.01') +// await withdrawDialog.actionsContainer.expectActions([{ type: 'withdraw', asset: 'wstETH' }]) +// await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) +// }) + +// test('works for asset with usage as collateral disabled', async ({ page }) => { +// await myPortfolioPage.clickBorrowButtonAction('DAI') +// await borrowDialog.clickMaxAmountAction() +// await borrowDialog.clickAcknowledgeRisk() +// await borrowDialog.actionsContainer.acceptAllActionsAction(1) +// await borrowDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectHealthFactor('1.17') + +// await myPortfolioPage.clickDepositButtonAction('rETH') +// const depositDialog = new DialogPageObject(page, /Deposit/) +// await depositDialog.fillAmountAction(1) +// await depositDialog.actionsContainer.acceptAllActionsAction(2) +// await depositDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectHealthFactor('1.39') + +// await myPortfolioPage.clickCollateralSwitchAction('rETH') +// const collateralDialog = new CollateralDialogPageObject(page) +// await collateralDialog.clickAcknowledgeRisk() +// await collateralDialog.setUseAsCollateralAction('rETH', 'disabled') +// await myPortfolioPage.goToMyPortfolioAction() +// await myPortfolioPage.expectHealthFactor('1.17') + +// await myPortfolioPage.clickWithdrawButtonAction('rETH') +// await withdrawDialog.clickMaxAmountAction() + +// await withdrawDialog.expectInputValue('1') +// await withdrawDialog.expectMaxButtonDisabled() +// await withdrawDialog.expectHealthFactorBefore('1.17') +// await withdrawDialog.expectHealthFactorAfter('1.17') +// await withdrawDialog.actionsContainer.expectActions([{ type: 'withdraw', asset: 'rETH' }]) +// await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) +// }) + +// test('native asset withdrawal requires enough approval', async () => { +// await myPortfolioPage.clickDepositButtonAction('WETH') +// await depositDialog.selectAssetAction('ETH') +// await depositDialog.fillAmountAction(5) +// await depositDialog.actionsContainer.acceptAllActionsAction(1, fork) +// await depositDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectDepositedAssets(24_450) + +// await myPortfolioPage.clickWithdrawButtonAction('WETH') +// await withdrawDialog.selectAssetAction('ETH') +// await withdrawDialog.clickMaxAmountAction() + +// await withdrawDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'aWETH' }, +// { type: 'withdraw', asset: 'ETH' }, +// ]) + +// await withdrawDialog.actionsContainer.acceptActionAtIndex(0, fork) +// await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(1) +// await withdrawDialog.closeDialog() + +// await myPortfolioPage.clickDepositButtonAction('WETH') +// await depositDialog.selectAssetAction('ETH') +// await depositDialog.fillAmountAction(4) +// await depositDialog.actionsContainer.acceptAllActionsAction(1) +// await depositDialog.viewInMyPortfolioAction() +// await myPortfolioPage.expectDepositedAssets(33_530) + +// // following checks leverage the fact that approval is cached, therefore we input different values to estimate the approval value +// await myPortfolioPage.clickWithdrawButtonAction('WETH') +// await withdrawDialog.selectAssetAction('ETH') +// await withdrawDialog.fillAmountAction(5.000001) +// await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(1) +// await withdrawDialog.fillAmountAction(5.000003) +// await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(1) +// await withdrawDialog.fillAmountAction(5.000004) +// await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) +// }) +// }) +// }) diff --git a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeDAI.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeDAI.test-e2e.ts index 055339d1d..54198e826 100644 --- a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeDAI.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeDAI.test-e2e.ts @@ -1,87 +1,87 @@ -import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { StakeDialogPageObject } from '../../StakeDialog.PageObject' +// import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { StakeDialogPageObject } from '../../StakeDialog.PageObject' -test.describe('Stake DAI to SKY farm', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let farmDetailsPage: FarmDetailsPageObject - let stakeDialog: StakeDialogPageObject +// test.describe('Stake DAI to SKY farm', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let farmDetailsPage: FarmDetailsPageObject +// let stakeDialog: StakeDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'farmDetails', - initialPageParams: { - chainId: mainnet.id.toString(), - address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', - }, - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - DAI: 10_000, - }, - }, - }) - await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'farmDetails', +// initialPageParams: { +// chainId: mainnet.id.toString(), +// address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', +// }, +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// DAI: 10_000, +// }, +// }, +// }) +// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) - farmDetailsPage = new FarmDetailsPageObject(page) - await farmDetailsPage.clickInfoPanelStakeButtonAction() - stakeDialog = new StakeDialogPageObject(page) - await stakeDialog.selectAssetAction('DAI') - await stakeDialog.fillAmountAction(10_000) - }) +// farmDetailsPage = new FarmDetailsPageObject(page) +// await farmDetailsPage.clickInfoPanelStakeButtonAction() +// stakeDialog = new StakeDialogPageObject(page) +// await stakeDialog.selectAssetAction('DAI') +// await stakeDialog.fillAmountAction(10_000) +// }) - test('has correct action plan', async () => { - await stakeDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'DAI' }, - { type: 'upgrade', fromToken: 'DAI', toToken: 'USDS' }, - { type: 'approve', asset: 'USDS' }, - { type: 'stake', stakingToken: 'USDS', rewardToken: 'SKY' }, - ]) - }) +// test('has correct action plan', async () => { +// await stakeDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'DAI' }, +// { type: 'upgrade', fromToken: 'DAI', toToken: 'USDS' }, +// { type: 'approve', asset: 'USDS' }, +// { type: 'stake', stakingToken: 'USDS', rewardToken: 'SKY' }, +// ]) +// }) - test('displays transaction overview', async () => { - await stakeDialog.expectTransactionOverview({ - estimatedRewards: { - apy: '778.72%', - description: 'Earn ~1,291,972.67 SKY/year', - }, - route: { - swaps: [ - { - tokenAmount: '10,000.00 DAI', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - ], - final: { - upperText: 'SKY Farm', - lowerText: 'Deposited', - }, - }, - outcome: '10,000.00 USD', - }) - }) +// test('displays transaction overview', async () => { +// await stakeDialog.expectTransactionOverview({ +// estimatedRewards: { +// apy: '778.72%', +// description: 'Earn ~1,291,972.67 SKY/year', +// }, +// route: { +// swaps: [ +// { +// tokenAmount: '10,000.00 DAI', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// final: { +// upperText: 'SKY Farm', +// lowerText: 'Deposited', +// }, +// }, +// outcome: '10,000.00 USD', +// }) +// }) - test('executes transaction', async () => { - await stakeDialog.actionsContainer.acceptAllActionsAction(4) +// test('executes transaction', async () => { +// await stakeDialog.actionsContainer.acceptAllActionsAction(4) - await stakeDialog.expectSuccessPage() - await stakeDialog.clickBackToFarmAction() +// await stakeDialog.expectSuccessPage() +// await stakeDialog.clickBackToFarmAction() - await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') - await farmDetailsPage.expectReward({ - reward: '0.1', - rewardUsd: '<$0.01', - }) - await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) - }) -}) +// await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') +// await farmDetailsPage.expectReward({ +// reward: '0.1', +// rewardUsd: '<$0.01', +// }) +// await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) +// }) +// }) diff --git a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSDAI.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSDAI.test-e2e.ts index 22ef1e9f5..cd5ce13e4 100644 --- a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSDAI.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSDAI.test-e2e.ts @@ -1,89 +1,89 @@ -import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { StakeDialogPageObject } from '../../StakeDialog.PageObject' +// import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { StakeDialogPageObject } from '../../StakeDialog.PageObject' -test.describe('Stake sDAI to SKY farm', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let farmDetailsPage: FarmDetailsPageObject - let stakeDialog: StakeDialogPageObject +// test.describe('Stake sDAI to SKY farm', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let farmDetailsPage: FarmDetailsPageObject +// let stakeDialog: StakeDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'farmDetails', - initialPageParams: { - chainId: mainnet.id.toString(), - address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', - }, - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - sDAI: 1_000, - }, - }, - }) - await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'farmDetails', +// initialPageParams: { +// chainId: mainnet.id.toString(), +// address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', +// }, +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// sDAI: 1_000, +// }, +// }, +// }) +// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) - farmDetailsPage = new FarmDetailsPageObject(page) - await farmDetailsPage.clickInfoPanelStakeButtonAction() - stakeDialog = new StakeDialogPageObject(page) - await stakeDialog.selectAssetAction('sDAI') - await stakeDialog.fillAmountAction(1_000) - }) +// farmDetailsPage = new FarmDetailsPageObject(page) +// await farmDetailsPage.clickInfoPanelStakeButtonAction() +// stakeDialog = new StakeDialogPageObject(page) +// await stakeDialog.selectAssetAction('sDAI') +// await stakeDialog.fillAmountAction(1_000) +// }) - test('has correct action plan', async () => { - await stakeDialog.actionsContainer.expectEnabledActionAtIndex(0) - await stakeDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'sDAI' }, - { type: 'withdrawFromSavings', savingsAsset: 'sDAI', asset: 'USDS', mode: 'withdraw' }, - { type: 'approve', asset: 'USDS' }, - { type: 'stake', stakingToken: 'USDS', rewardToken: 'SKY' }, - ]) - }) +// test('has correct action plan', async () => { +// await stakeDialog.actionsContainer.expectEnabledActionAtIndex(0) +// await stakeDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'sDAI' }, +// { type: 'withdrawFromSavings', savingsAsset: 'sDAI', asset: 'USDS', mode: 'withdraw' }, +// { type: 'approve', asset: 'USDS' }, +// { type: 'stake', stakingToken: 'USDS', rewardToken: 'SKY' }, +// ]) +// }) - test('displays transaction overview', async () => { - await stakeDialog.expectTransactionOverview({ - estimatedRewards: { - apy: '780.23%', - description: 'Earn ~143,505.01 SKY/year', - }, - route: { - swaps: [ - { - tokenAmount: '1,000.00 sDAI', - tokenUsdValue: '$1,108.59', - }, - { - tokenAmount: '1,108.59 USDS', - tokenUsdValue: '$1,108.59', - }, - ], - final: { - upperText: 'SKY Farm', - lowerText: 'Deposited', - }, - }, - outcome: '1,108.59 USDS', - }) - }) +// test('displays transaction overview', async () => { +// await stakeDialog.expectTransactionOverview({ +// estimatedRewards: { +// apy: '780.23%', +// description: 'Earn ~143,505.01 SKY/year', +// }, +// route: { +// swaps: [ +// { +// tokenAmount: '1,000.00 sDAI', +// tokenUsdValue: '$1,108.59', +// }, +// { +// tokenAmount: '1,108.59 USDS', +// tokenUsdValue: '$1,108.59', +// }, +// ], +// final: { +// upperText: 'SKY Farm', +// lowerText: 'Deposited', +// }, +// }, +// outcome: '1,108.59 USDS', +// }) +// }) - test('executes transaction', async () => { - await stakeDialog.actionsContainer.acceptAllActionsAction(4) +// test('executes transaction', async () => { +// await stakeDialog.actionsContainer.acceptAllActionsAction(4) - await stakeDialog.expectSuccessPage() - await stakeDialog.clickBackToFarmAction() +// await stakeDialog.expectSuccessPage() +// await stakeDialog.clickBackToFarmAction() - await farmDetailsPage.expectTokenToDepositBalance('sDAI', '-') - await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') // no dust left - await farmDetailsPage.expectReward({ - reward: '0.01', - rewardUsd: '<$0.01', - }) - await farmDetailsPage.expectStaked({ amount: '1,108.59', asset: 'USDS' }) - }) -}) +// await farmDetailsPage.expectTokenToDepositBalance('sDAI', '-') +// await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') // no dust left +// await farmDetailsPage.expectReward({ +// reward: '0.01', +// rewardUsd: '<$0.01', +// }) +// await farmDetailsPage.expectStaked({ amount: '1,108.59', asset: 'USDS' }) +// }) +// }) diff --git a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSUSDS.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSUSDS.test-e2e.ts index 08310fa66..97151d40f 100644 --- a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSUSDS.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSUSDS.test-e2e.ts @@ -1,99 +1,99 @@ -import { SavingsDialogPageObject } from '@/features/dialogs/savings/common/e2e/SavingsDialog.PageObject' -import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -import { SavingsPageObject } from '@/pages/Savings.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -import { buildUrl, setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { StakeDialogPageObject } from '../../StakeDialog.PageObject' +// import { SavingsDialogPageObject } from '@/features/dialogs/savings/common/e2e/SavingsDialog.PageObject' +// import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' +// import { SavingsPageObject } from '@/pages/Savings.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +// import { buildUrl, setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { StakeDialogPageObject } from '../../StakeDialog.PageObject' -test.describe('Stake sDAI to SKY farm', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let farmDetailsPage: FarmDetailsPageObject - let stakeDialog: StakeDialogPageObject +// test.describe('Stake sDAI to SKY farm', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let farmDetailsPage: FarmDetailsPageObject +// let stakeDialog: StakeDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDS: 1_100, - }, - }, - }) - await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// USDS: 1_100, +// }, +// }, +// }) +// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) - // deposit some tokens to sUSDS first so we're able to withdraw them next - const savingsPage = new SavingsPageObject(page) - await savingsPage.clickDepositButtonAction('USDS') - const depositToSavingsDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) - await depositToSavingsDialog.clickMaxAmountAction() - await depositToSavingsDialog.actionsContainer.acceptAllActionsAction(2) - await depositToSavingsDialog.clickBackToSavingsButton() - await page.goto( - buildUrl('farmDetails', { - chainId: mainnet.id.toString(), - address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', - }), - ) +// // deposit some tokens to sUSDS first so we're able to withdraw them next +// const savingsPage = new SavingsPageObject(page) +// await savingsPage.clickDepositButtonAction('USDS') +// const depositToSavingsDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) +// await depositToSavingsDialog.clickMaxAmountAction() +// await depositToSavingsDialog.actionsContainer.acceptAllActionsAction(2) +// await depositToSavingsDialog.clickBackToSavingsButton() +// await page.goto( +// buildUrl('farmDetails', { +// chainId: mainnet.id.toString(), +// address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', +// }), +// ) - farmDetailsPage = new FarmDetailsPageObject(page) - await farmDetailsPage.clickInfoPanelStakeButtonAction() - stakeDialog = new StakeDialogPageObject(page) - await stakeDialog.selectAssetAction('sUSDS') - await stakeDialog.fillAmountAction(1_000) - }) +// farmDetailsPage = new FarmDetailsPageObject(page) +// await farmDetailsPage.clickInfoPanelStakeButtonAction() +// stakeDialog = new StakeDialogPageObject(page) +// await stakeDialog.selectAssetAction('sUSDS') +// await stakeDialog.fillAmountAction(1_000) +// }) - test('has correct action plan', async () => { - await stakeDialog.actionsContainer.expectEnabledActionAtIndex(0) - await stakeDialog.actionsContainer.expectActions([ - { type: 'withdrawFromSavings', savingsAsset: 'sUSDS', asset: 'USDS', mode: 'withdraw' }, - { type: 'approve', asset: 'USDS' }, - { type: 'stake', stakingToken: 'USDS', rewardToken: 'SKY' }, - ]) - }) +// test('has correct action plan', async () => { +// await stakeDialog.actionsContainer.expectEnabledActionAtIndex(0) +// await stakeDialog.actionsContainer.expectActions([ +// { type: 'withdrawFromSavings', savingsAsset: 'sUSDS', asset: 'USDS', mode: 'withdraw' }, +// { type: 'approve', asset: 'USDS' }, +// { type: 'stake', stakingToken: 'USDS', rewardToken: 'SKY' }, +// ]) +// }) - test('displays transaction overview', async () => { - await stakeDialog.expectTransactionOverview({ - estimatedRewards: { - apy: '780.23%', - description: 'Earn ~129,451.12 SKY/year', - }, - route: { - swaps: [ - { - tokenAmount: '1,000.00 sUSDS', - tokenUsdValue: '$1,000.02', - }, - { - tokenAmount: '1,000.02 USDS', - tokenUsdValue: '$1,000.02', - }, - ], - final: { - upperText: 'SKY Farm', - lowerText: 'Deposited', - }, - }, - outcome: '1,000.02 USDS', - }) - }) +// test('displays transaction overview', async () => { +// await stakeDialog.expectTransactionOverview({ +// estimatedRewards: { +// apy: '780.23%', +// description: 'Earn ~129,451.12 SKY/year', +// }, +// route: { +// swaps: [ +// { +// tokenAmount: '1,000.00 sUSDS', +// tokenUsdValue: '$1,000.02', +// }, +// { +// tokenAmount: '1,000.02 USDS', +// tokenUsdValue: '$1,000.02', +// }, +// ], +// final: { +// upperText: 'SKY Farm', +// lowerText: 'Deposited', +// }, +// }, +// outcome: '1,000.02 USDS', +// }) +// }) - test('executes transaction', async () => { - await stakeDialog.actionsContainer.acceptAllActionsAction(3) +// test('executes transaction', async () => { +// await stakeDialog.actionsContainer.acceptAllActionsAction(3) - await stakeDialog.expectSuccessPage() - await stakeDialog.clickBackToFarmAction() +// await stakeDialog.expectSuccessPage() +// await stakeDialog.clickBackToFarmAction() - await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') // no dust left - await farmDetailsPage.expectReward({ - reward: '0.01', - rewardUsd: '<$0.01', - }) - await farmDetailsPage.expectStaked({ amount: '1,000.02', asset: 'USDS' }) - }) -}) +// await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') // no dust left +// await farmDetailsPage.expectReward({ +// reward: '0.01', +// rewardUsd: '<$0.01', +// }) +// await farmDetailsPage.expectStaked({ amount: '1,000.02', asset: 'USDS' }) +// }) +// }) diff --git a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDC.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDC.test-e2e.ts index 18d542fb0..c49daf9a3 100644 --- a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDC.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDC.test-e2e.ts @@ -1,87 +1,87 @@ -import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { StakeDialogPageObject } from '../../StakeDialog.PageObject' +// import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { StakeDialogPageObject } from '../../StakeDialog.PageObject' -test.describe('Stake USDC to SKY farm', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let farmDetailsPage: FarmDetailsPageObject - let stakeDialog: StakeDialogPageObject +// test.describe('Stake USDC to SKY farm', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let farmDetailsPage: FarmDetailsPageObject +// let stakeDialog: StakeDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'farmDetails', - initialPageParams: { - chainId: mainnet.id.toString(), - address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', - }, - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDC: 10_000, - }, - }, - }) - await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'farmDetails', +// initialPageParams: { +// chainId: mainnet.id.toString(), +// address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', +// }, +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// USDC: 10_000, +// }, +// }, +// }) +// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) - farmDetailsPage = new FarmDetailsPageObject(page) - await farmDetailsPage.clickInfoPanelStakeButtonAction() - stakeDialog = new StakeDialogPageObject(page) - await stakeDialog.selectAssetAction('USDC') - await stakeDialog.fillAmountAction(10_000) - }) +// farmDetailsPage = new FarmDetailsPageObject(page) +// await farmDetailsPage.clickInfoPanelStakeButtonAction() +// stakeDialog = new StakeDialogPageObject(page) +// await stakeDialog.selectAssetAction('USDC') +// await stakeDialog.fillAmountAction(10_000) +// }) - test('has correct action plan', async () => { - await stakeDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'USDC' }, - { type: 'psmConvert', inToken: 'USDC', outToken: 'USDS' }, - { type: 'approve', asset: 'USDS' }, - { type: 'stake', stakingToken: 'USDS', rewardToken: 'SKY' }, - ]) - }) +// test('has correct action plan', async () => { +// await stakeDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'USDC' }, +// { type: 'psmConvert', inToken: 'USDC', outToken: 'USDS' }, +// { type: 'approve', asset: 'USDS' }, +// { type: 'stake', stakingToken: 'USDS', rewardToken: 'SKY' }, +// ]) +// }) - test('displays transaction overview', async () => { - await stakeDialog.expectTransactionOverview({ - estimatedRewards: { - apy: '778.72%', - description: 'Earn ~1,291,972.67 SKY/year', - }, - route: { - swaps: [ - { - tokenAmount: '10,000.00 USDC', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - ], - final: { - upperText: 'SKY Farm', - lowerText: 'Deposited', - }, - }, - outcome: '10,000.00 USD', - }) - }) +// test('displays transaction overview', async () => { +// await stakeDialog.expectTransactionOverview({ +// estimatedRewards: { +// apy: '778.72%', +// description: 'Earn ~1,291,972.67 SKY/year', +// }, +// route: { +// swaps: [ +// { +// tokenAmount: '10,000.00 USDC', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// final: { +// upperText: 'SKY Farm', +// lowerText: 'Deposited', +// }, +// }, +// outcome: '10,000.00 USD', +// }) +// }) - test('executes transaction', async () => { - await stakeDialog.actionsContainer.acceptAllActionsAction(4) +// test('executes transaction', async () => { +// await stakeDialog.actionsContainer.acceptAllActionsAction(4) - await stakeDialog.expectSuccessPage() - await stakeDialog.clickBackToFarmAction() +// await stakeDialog.expectSuccessPage() +// await stakeDialog.clickBackToFarmAction() - await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') - await farmDetailsPage.expectReward({ - reward: '0.1', - rewardUsd: '<$0.01', - }) - await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) - }) -}) +// await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') +// await farmDetailsPage.expectReward({ +// reward: '0.1', +// rewardUsd: '<$0.01', +// }) +// await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) +// }) +// }) diff --git a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDS.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDS.test-e2e.ts index e256efaa0..75cc656b9 100644 --- a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDS.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDS.test-e2e.ts @@ -1,162 +1,162 @@ -import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { privateKeyToAddress } from 'viem/accounts' -import { mainnet } from 'viem/chains' -import { StakeDialogPageObject } from '../../StakeDialog.PageObject' - -test.describe('Stake USDS to SKY farm', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let farmDetailsPage: FarmDetailsPageObject - let stakeDialog: StakeDialogPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'farmDetails', - initialPageParams: { - chainId: mainnet.id.toString(), - address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', - }, - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDS: 10_000, - }, - }, - }) - await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) - - farmDetailsPage = new FarmDetailsPageObject(page) - await farmDetailsPage.clickInfoPanelStakeButtonAction() - stakeDialog = new StakeDialogPageObject(page) - await stakeDialog.fillAmountAction(10_000) - }) - - test('has correct action plan', async () => { - await stakeDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'USDS' }, - { type: 'stake', stakingToken: 'USDS', rewardToken: 'SKY' }, - ]) - }) - - test('displays transaction overview', async () => { - await stakeDialog.expectTransactionOverview({ - estimatedRewards: { - apy: '778.72%', - description: 'Earn ~1,291,972.67 SKY/year', - }, - route: { - swaps: [ - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - ], - final: { - upperText: 'SKY Farm', - lowerText: 'Deposited', - }, - }, - outcome: '10,000.00 USD', - }) - }) - - test('executes transaction', async () => { - await stakeDialog.actionsContainer.acceptAllActionsAction(2) - - await stakeDialog.expectSuccessPage() - await stakeDialog.clickBackToFarmAction() - - await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') - await farmDetailsPage.expectReward({ - reward: '0.1', - rewardUsd: '<$0.01', - }) - await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) - }) -}) - -test.describe('Stake USDS to CLE farm', () => { - const testUserPKey = '0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5' - const testUserAddress = privateKeyToAddress('0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5') - const harSuffix = testUserAddress.slice(0, 10) - - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let farmDetailsPage: FarmDetailsPageObject - let stakeDialog: StakeDialogPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'farmDetails', - initialPageParams: { - chainId: mainnet.id.toString(), - address: '0x10ab606B067C9C461d8893c47C7512472E19e2Ce', - }, - account: { - type: 'connected-pkey', - privateKey: testUserPKey, - assetBalances: { - ETH: 1, - USDS: 10_000, - }, - }, - }) - await overrideInfoSkyRouteWithHAR({ page, key: `2-cle-farm-0-balance-${harSuffix}` }) - - farmDetailsPage = new FarmDetailsPageObject(page) - await farmDetailsPage.clickInfoPanelStakeButtonAction() - stakeDialog = new StakeDialogPageObject(page) - await stakeDialog.fillAmountAction(10_000) - }) - - test('has correct action plan', async () => { - await stakeDialog.actionsContainer.expectActions([ - { type: 'approve', asset: 'USDS' }, - { type: 'stake', stakingToken: 'USDS', rewardToken: 'CLE' }, - ]) - }) - - test('displays transaction overview', async () => { - await stakeDialog.expectTransactionOverview({ - route: { - swaps: [ - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - ], - final: { - upperText: 'CLE Farm', - lowerText: 'Deposited', - }, - }, - outcome: '10,000.00 USDS', - }) - }) - - test('executes transaction', async ({ page }) => { - await stakeDialog.actionsContainer.acceptAllActionsAction(2) - - await stakeDialog.expectSuccessPage() - await stakeDialog.clickBackToFarmAction() - - await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') - await farmDetailsPage.expectReward({ - reward: '0.0', - }) - await farmDetailsPage.expectPointsSyncWarning() - await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) - - await overrideInfoSkyRouteWithHAR({ page, key: `3-cle-farm-10000-balance-${harSuffix}` }) - - await farmDetailsPage.expectReward({ - reward: '257.6', - }) - await farmDetailsPage.expectPointsSyncWarningToBeHidden() - await farmDetailsPage.expectInfoPanelClaimButtonToBeHidden() - }) -}) +// import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { privateKeyToAddress } from 'viem/accounts' +// import { mainnet } from 'viem/chains' +// import { StakeDialogPageObject } from '../../StakeDialog.PageObject' + +// test.describe('Stake USDS to SKY farm', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let farmDetailsPage: FarmDetailsPageObject +// let stakeDialog: StakeDialogPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'farmDetails', +// initialPageParams: { +// chainId: mainnet.id.toString(), +// address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', +// }, +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// USDS: 10_000, +// }, +// }, +// }) +// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) + +// farmDetailsPage = new FarmDetailsPageObject(page) +// await farmDetailsPage.clickInfoPanelStakeButtonAction() +// stakeDialog = new StakeDialogPageObject(page) +// await stakeDialog.fillAmountAction(10_000) +// }) + +// test('has correct action plan', async () => { +// await stakeDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'USDS' }, +// { type: 'stake', stakingToken: 'USDS', rewardToken: 'SKY' }, +// ]) +// }) + +// test('displays transaction overview', async () => { +// await stakeDialog.expectTransactionOverview({ +// estimatedRewards: { +// apy: '778.72%', +// description: 'Earn ~1,291,972.67 SKY/year', +// }, +// route: { +// swaps: [ +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// final: { +// upperText: 'SKY Farm', +// lowerText: 'Deposited', +// }, +// }, +// outcome: '10,000.00 USD', +// }) +// }) + +// test('executes transaction', async () => { +// await stakeDialog.actionsContainer.acceptAllActionsAction(2) + +// await stakeDialog.expectSuccessPage() +// await stakeDialog.clickBackToFarmAction() + +// await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') +// await farmDetailsPage.expectReward({ +// reward: '0.1', +// rewardUsd: '<$0.01', +// }) +// await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) +// }) +// }) + +// test.describe('Stake USDS to CLE farm', () => { +// const testUserPKey = '0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5' +// const testUserAddress = privateKeyToAddress('0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5') +// const harSuffix = testUserAddress.slice(0, 10) + +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let farmDetailsPage: FarmDetailsPageObject +// let stakeDialog: StakeDialogPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'farmDetails', +// initialPageParams: { +// chainId: mainnet.id.toString(), +// address: '0x10ab606B067C9C461d8893c47C7512472E19e2Ce', +// }, +// account: { +// type: 'connected-pkey', +// privateKey: testUserPKey, +// assetBalances: { +// ETH: 1, +// USDS: 10_000, +// }, +// }, +// }) +// await overrideInfoSkyRouteWithHAR({ page, key: `2-cle-farm-0-balance-${harSuffix}` }) + +// farmDetailsPage = new FarmDetailsPageObject(page) +// await farmDetailsPage.clickInfoPanelStakeButtonAction() +// stakeDialog = new StakeDialogPageObject(page) +// await stakeDialog.fillAmountAction(10_000) +// }) + +// test('has correct action plan', async () => { +// await stakeDialog.actionsContainer.expectActions([ +// { type: 'approve', asset: 'USDS' }, +// { type: 'stake', stakingToken: 'USDS', rewardToken: 'CLE' }, +// ]) +// }) + +// test('displays transaction overview', async () => { +// await stakeDialog.expectTransactionOverview({ +// route: { +// swaps: [ +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// final: { +// upperText: 'CLE Farm', +// lowerText: 'Deposited', +// }, +// }, +// outcome: '10,000.00 USDS', +// }) +// }) + +// test('executes transaction', async ({ page }) => { +// await stakeDialog.actionsContainer.acceptAllActionsAction(2) + +// await stakeDialog.expectSuccessPage() +// await stakeDialog.clickBackToFarmAction() + +// await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') +// await farmDetailsPage.expectReward({ +// reward: '0.0', +// }) +// await farmDetailsPage.expectPointsSyncWarning() +// await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) + +// await overrideInfoSkyRouteWithHAR({ page, key: `3-cle-farm-10000-balance-${harSuffix}` }) + +// await farmDetailsPage.expectReward({ +// reward: '257.6', +// }) +// await farmDetailsPage.expectPointsSyncWarningToBeHidden() +// await farmDetailsPage.expectInfoPanelClaimButtonToBeHidden() +// }) +// }) diff --git a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeDAI.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeDAI.test-e2e.ts index a1ec4e704..71313a5c5 100644 --- a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeDAI.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeDAI.test-e2e.ts @@ -1,99 +1,99 @@ -import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' -import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' +// import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' +// import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' -test.describe('Unstake DAI from SKY farm', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let farmDetailsPage: FarmDetailsPageObject - let unstakeDialog: UnstakeDialogPageObject - let stakeDialog: StakeDialogPageObject +// test.describe('Unstake DAI from SKY farm', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let farmDetailsPage: FarmDetailsPageObject +// let unstakeDialog: UnstakeDialogPageObject +// let stakeDialog: StakeDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'farmDetails', - initialPageParams: { - chainId: mainnet.id.toString(), - address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', - }, - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - DAI: 10_000, - USDS: 10_000, - }, - }, - }) - await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'farmDetails', +// initialPageParams: { +// chainId: mainnet.id.toString(), +// address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', +// }, +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// DAI: 10_000, +// USDS: 10_000, +// }, +// }, +// }) +// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) - farmDetailsPage = new FarmDetailsPageObject(page) - await farmDetailsPage.clickInfoPanelStakeButtonAction() - stakeDialog = new StakeDialogPageObject(page) +// farmDetailsPage = new FarmDetailsPageObject(page) +// await farmDetailsPage.clickInfoPanelStakeButtonAction() +// stakeDialog = new StakeDialogPageObject(page) - await stakeDialog.selectAssetAction('USDS') - await stakeDialog.fillAmountAction(10_000) - await stakeDialog.actionsContainer.acceptAllActionsAction(2) +// await stakeDialog.selectAssetAction('USDS') +// await stakeDialog.fillAmountAction(10_000) +// await stakeDialog.actionsContainer.acceptAllActionsAction(2) - await stakeDialog.clickBackToFarmAction() +// await stakeDialog.clickBackToFarmAction() - await fork.progressSimulation(page, 24 * 60 * 60) // 24 hours - await page.reload() +// await fork.progressSimulation(page, 24 * 60 * 60) // 24 hours +// await page.reload() - await farmDetailsPage.clickInfoPanelUnstakeButtonAction() - unstakeDialog = new UnstakeDialogPageObject(page) +// await farmDetailsPage.clickInfoPanelUnstakeButtonAction() +// unstakeDialog = new UnstakeDialogPageObject(page) - await unstakeDialog.selectAssetAction('DAI') - await unstakeDialog.fillAmountAction(5_000) - }) +// await unstakeDialog.selectAssetAction('DAI') +// await unstakeDialog.fillAmountAction(5_000) +// }) - test('has correct action plan', async () => { - await unstakeDialog.actionsContainer.expectActions([ - { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, - { type: 'approve', asset: 'USDS' }, - { type: 'downgrade', fromToken: 'USDS', toToken: 'DAI' }, - ]) - }) +// test('has correct action plan', async () => { +// await unstakeDialog.actionsContainer.expectActions([ +// { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, +// { type: 'approve', asset: 'USDS' }, +// { type: 'downgrade', fromToken: 'USDS', toToken: 'DAI' }, +// ]) +// }) - test('displays transaction overview', async () => { - await unstakeDialog.expectTransactionOverview({ - route: { - swaps: [ - { - tokenAmount: '5,000.00 USDS', - tokenUsdValue: '$5,000.00', - }, - { - tokenAmount: '5,000.00 DAI', - tokenUsdValue: '$5,000.00', - }, - ], - farm: { - upperText: 'SKY Farm', - lowerText: 'Deposited', - }, - }, - outcome: '5,000.00 DAI', - }) - }) +// test('displays transaction overview', async () => { +// await unstakeDialog.expectTransactionOverview({ +// route: { +// swaps: [ +// { +// tokenAmount: '5,000.00 USDS', +// tokenUsdValue: '$5,000.00', +// }, +// { +// tokenAmount: '5,000.00 DAI', +// tokenUsdValue: '$5,000.00', +// }, +// ], +// farm: { +// upperText: 'SKY Farm', +// lowerText: 'Deposited', +// }, +// }, +// outcome: '5,000.00 DAI', +// }) +// }) - test('executes transaction', async () => { - await unstakeDialog.actionsContainer.acceptAllActionsAction(3) +// test('executes transaction', async () => { +// await unstakeDialog.actionsContainer.acceptAllActionsAction(3) - await unstakeDialog.expectSuccessPage() - await unstakeDialog.clickBackToFarmAction() +// await unstakeDialog.expectSuccessPage() +// await unstakeDialog.clickBackToFarmAction() - await farmDetailsPage.expectTokenToDepositBalance('DAI', '15,000.00') - await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') - await farmDetailsPage.expectReward({ - reward: '3,539', - rewardUsd: '$213', - }) - await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) - }) -}) +// await farmDetailsPage.expectTokenToDepositBalance('DAI', '15,000.00') +// await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') +// await farmDetailsPage.expectReward({ +// reward: '3,539', +// rewardUsd: '$213', +// }) +// await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) +// }) +// }) diff --git a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDC.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDC.test-e2e.ts index 55d33303d..3e6c3559d 100644 --- a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDC.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDC.test-e2e.ts @@ -1,99 +1,99 @@ -import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' -import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' +// import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' +// import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' -test.describe('Unstake USDC from SKY farm', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let farmDetailsPage: FarmDetailsPageObject - let unstakeDialog: UnstakeDialogPageObject - let stakeDialog: StakeDialogPageObject +// test.describe('Unstake USDC from SKY farm', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let farmDetailsPage: FarmDetailsPageObject +// let unstakeDialog: UnstakeDialogPageObject +// let stakeDialog: StakeDialogPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'farmDetails', - initialPageParams: { - chainId: mainnet.id.toString(), - address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', - }, - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDC: 10_000, - USDS: 10_000, - }, - }, - }) - await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'farmDetails', +// initialPageParams: { +// chainId: mainnet.id.toString(), +// address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', +// }, +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// USDC: 10_000, +// USDS: 10_000, +// }, +// }, +// }) +// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) - farmDetailsPage = new FarmDetailsPageObject(page) - await farmDetailsPage.clickInfoPanelStakeButtonAction() - stakeDialog = new StakeDialogPageObject(page) +// farmDetailsPage = new FarmDetailsPageObject(page) +// await farmDetailsPage.clickInfoPanelStakeButtonAction() +// stakeDialog = new StakeDialogPageObject(page) - await stakeDialog.selectAssetAction('USDS') - await stakeDialog.fillAmountAction(10_000) - await stakeDialog.actionsContainer.acceptAllActionsAction(2) +// await stakeDialog.selectAssetAction('USDS') +// await stakeDialog.fillAmountAction(10_000) +// await stakeDialog.actionsContainer.acceptAllActionsAction(2) - await stakeDialog.clickBackToFarmAction() +// await stakeDialog.clickBackToFarmAction() - await fork.progressSimulation(page, 24 * 60 * 60) // 24 hours - await page.reload() +// await fork.progressSimulation(page, 24 * 60 * 60) // 24 hours +// await page.reload() - await farmDetailsPage.clickInfoPanelUnstakeButtonAction() - unstakeDialog = new UnstakeDialogPageObject(page) +// await farmDetailsPage.clickInfoPanelUnstakeButtonAction() +// unstakeDialog = new UnstakeDialogPageObject(page) - await unstakeDialog.selectAssetAction('USDC') - await unstakeDialog.fillAmountAction(5_000) - }) +// await unstakeDialog.selectAssetAction('USDC') +// await unstakeDialog.fillAmountAction(5_000) +// }) - test('has correct action plan', async () => { - await unstakeDialog.actionsContainer.expectActions([ - { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, - { type: 'approve', asset: 'USDS' }, - { type: 'psmConvert', inToken: 'USDS', outToken: 'USDC' }, - ]) - }) +// test('has correct action plan', async () => { +// await unstakeDialog.actionsContainer.expectActions([ +// { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, +// { type: 'approve', asset: 'USDS' }, +// { type: 'psmConvert', inToken: 'USDS', outToken: 'USDC' }, +// ]) +// }) - test('displays transaction overview', async () => { - await unstakeDialog.expectTransactionOverview({ - route: { - swaps: [ - { - tokenAmount: '5,000.00 USDS', - tokenUsdValue: '$5,000.00', - }, - { - tokenAmount: '5,000.00 USDC', - tokenUsdValue: '$5,000.00', - }, - ], - farm: { - upperText: 'SKY Farm', - lowerText: 'Deposited', - }, - }, - outcome: '5,000.00 USDC', - }) - }) +// test('displays transaction overview', async () => { +// await unstakeDialog.expectTransactionOverview({ +// route: { +// swaps: [ +// { +// tokenAmount: '5,000.00 USDS', +// tokenUsdValue: '$5,000.00', +// }, +// { +// tokenAmount: '5,000.00 USDC', +// tokenUsdValue: '$5,000.00', +// }, +// ], +// farm: { +// upperText: 'SKY Farm', +// lowerText: 'Deposited', +// }, +// }, +// outcome: '5,000.00 USDC', +// }) +// }) - test('executes transaction', async () => { - await unstakeDialog.actionsContainer.acceptAllActionsAction(3) +// test('executes transaction', async () => { +// await unstakeDialog.actionsContainer.acceptAllActionsAction(3) - await unstakeDialog.expectSuccessPage() - await unstakeDialog.clickBackToFarmAction() +// await unstakeDialog.expectSuccessPage() +// await unstakeDialog.clickBackToFarmAction() - await farmDetailsPage.expectTokenToDepositBalance('USDC', '15,000.00') - await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') - await farmDetailsPage.expectReward({ - reward: '3,539', - rewardUsd: '$213', - }) - await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) - }) -}) +// await farmDetailsPage.expectTokenToDepositBalance('USDC', '15,000.00') +// await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') +// await farmDetailsPage.expectReward({ +// reward: '3,539', +// rewardUsd: '$213', +// }) +// await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) +// }) +// }) diff --git a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDS.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDS.test-e2e.ts index 4335e96d0..0a4aa2c5f 100644 --- a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDS.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDS.test-e2e.ts @@ -1,188 +1,188 @@ -import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { privateKeyToAddress } from 'viem/accounts' -import { mainnet } from 'viem/chains' -import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' -import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' - -test.describe('Unstake USDS from SKY farm', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let farmDetailsPage: FarmDetailsPageObject - let unstakeDialog: UnstakeDialogPageObject - let stakeDialog: StakeDialogPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'farmDetails', - initialPageParams: { - chainId: mainnet.id.toString(), - address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', - }, - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - DAI: 10_000, - USDS: 10_000, - }, - }, - }) - await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) - - farmDetailsPage = new FarmDetailsPageObject(page) - await farmDetailsPage.clickInfoPanelStakeButtonAction() - stakeDialog = new StakeDialogPageObject(page) - - await stakeDialog.selectAssetAction('DAI') - await stakeDialog.fillAmountAction(10_000) - await stakeDialog.actionsContainer.acceptAllActionsAction(4) - - await stakeDialog.clickBackToFarmAction() - - await fork.progressSimulation(page, 24 * 60 * 60) // 24 hours - await page.reload() - - await farmDetailsPage.clickInfoPanelUnstakeButtonAction() - unstakeDialog = new UnstakeDialogPageObject(page) - - await unstakeDialog.selectAssetAction('USDS') - await unstakeDialog.fillAmountAction(5_000) - }) - - test('has exit farm switch hidden', async () => { - await unstakeDialog.expectExitFarmSwitchToBeHidden() - }) - - test('has correct action plan', async () => { - await unstakeDialog.actionsContainer.expectActions([ - { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, - ]) - }) - - test('displays transaction overview', async () => { - await unstakeDialog.expectTransactionOverview({ - route: { - swaps: [ - { - tokenAmount: '5,000.00 USDS', - tokenUsdValue: '$5,000.00', - }, - ], - farm: { - upperText: 'SKY Farm', - lowerText: 'Deposited', - }, - }, - outcome: '5,000.00 USDS', - }) - }) - - test('executes transaction', async () => { - await unstakeDialog.actionsContainer.acceptAllActionsAction(1) - - await unstakeDialog.expectSuccessPage() - await unstakeDialog.clickBackToFarmAction() - - await farmDetailsPage.expectTokenToDepositBalance('USDS', '15,000.00') - await farmDetailsPage.expectTokenToDepositBalance('DAI', '-') - await farmDetailsPage.expectReward({ - reward: '3,539', - rewardUsd: '$213', - }) - await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) - }) -}) - -test.describe('Unstake USDS from CLE farm', () => { - const testUserPKey = '0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5' - const testUserAddress = privateKeyToAddress('0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5') - const harSuffix = testUserAddress.slice(0, 10) - - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let farmDetailsPage: FarmDetailsPageObject - let unstakeDialog: UnstakeDialogPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'farmDetails', - initialPageParams: { - chainId: mainnet.id.toString(), - address: '0x10ab606B067C9C461d8893c47C7512472E19e2Ce', - }, - account: { - type: 'connected-pkey', - privateKey: testUserPKey, - assetBalances: { - ETH: 1, - USDS: 10_000, - }, - }, - }) - await overrideInfoSkyRouteWithHAR({ page, key: `2-cle-farm-0-balance-${harSuffix}` }) - - farmDetailsPage = new FarmDetailsPageObject(page) - await farmDetailsPage.clickInfoPanelStakeButtonAction() - const stakeDialog = new StakeDialogPageObject(page) - await stakeDialog.fillAmountAction(10_000) - await stakeDialog.actionsContainer.acceptAllActionsAction(2) - await stakeDialog.clickBackToFarmAction() - - await overrideInfoSkyRouteWithHAR({ page, key: `3-cle-farm-10000-balance-${harSuffix}` }) - await farmDetailsPage.clickInfoPanelUnstakeButtonAction() - unstakeDialog = new UnstakeDialogPageObject(page) - - await unstakeDialog.selectAssetAction('USDS') - await unstakeDialog.fillAmountAction(5_000) - }) - - test('has correct action plan', async () => { - await unstakeDialog.actionsContainer.expectActions([ - { type: 'unstake', stakingToken: 'USDS', rewardToken: 'CLE', exit: false }, - ]) - }) - - test('displays transaction overview', async () => { - await unstakeDialog.expectTransactionOverview({ - route: { - swaps: [ - { - tokenAmount: '5,000.00 USDS', - tokenUsdValue: '$5,000.00', - }, - ], - farm: { - upperText: 'CLE Farm', - lowerText: 'Deposited', - }, - }, - outcome: '5,000.00 USDS', - }) - }) - - test('executes transaction', async ({ page }) => { - await unstakeDialog.actionsContainer.acceptAllActionsAction(1) - - await unstakeDialog.expectSuccessPage() - await unstakeDialog.clickBackToFarmAction() - - await farmDetailsPage.expectTokenToDepositBalance('USDS', '5,000.00') - await farmDetailsPage.expectReward({ - reward: '257.6', - }) - await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) - await farmDetailsPage.expectPointsSyncWarning() - - await overrideInfoSkyRouteWithHAR({ page, key: `4-cle-farm-5000-balance-${harSuffix}` }) - - await farmDetailsPage.expectReward({ - reward: '257.6', - }) - await farmDetailsPage.expectPointsSyncWarningToBeHidden() - await farmDetailsPage.expectInfoPanelClaimButtonToBeHidden() - await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) - }) -}) +// import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { privateKeyToAddress } from 'viem/accounts' +// import { mainnet } from 'viem/chains' +// import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' +// import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' + +// test.describe('Unstake USDS from SKY farm', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let farmDetailsPage: FarmDetailsPageObject +// let unstakeDialog: UnstakeDialogPageObject +// let stakeDialog: StakeDialogPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'farmDetails', +// initialPageParams: { +// chainId: mainnet.id.toString(), +// address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', +// }, +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// DAI: 10_000, +// USDS: 10_000, +// }, +// }, +// }) +// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) + +// farmDetailsPage = new FarmDetailsPageObject(page) +// await farmDetailsPage.clickInfoPanelStakeButtonAction() +// stakeDialog = new StakeDialogPageObject(page) + +// await stakeDialog.selectAssetAction('DAI') +// await stakeDialog.fillAmountAction(10_000) +// await stakeDialog.actionsContainer.acceptAllActionsAction(4) + +// await stakeDialog.clickBackToFarmAction() + +// await fork.progressSimulation(page, 24 * 60 * 60) // 24 hours +// await page.reload() + +// await farmDetailsPage.clickInfoPanelUnstakeButtonAction() +// unstakeDialog = new UnstakeDialogPageObject(page) + +// await unstakeDialog.selectAssetAction('USDS') +// await unstakeDialog.fillAmountAction(5_000) +// }) + +// test('has exit farm switch hidden', async () => { +// await unstakeDialog.expectExitFarmSwitchToBeHidden() +// }) + +// test('has correct action plan', async () => { +// await unstakeDialog.actionsContainer.expectActions([ +// { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, +// ]) +// }) + +// test('displays transaction overview', async () => { +// await unstakeDialog.expectTransactionOverview({ +// route: { +// swaps: [ +// { +// tokenAmount: '5,000.00 USDS', +// tokenUsdValue: '$5,000.00', +// }, +// ], +// farm: { +// upperText: 'SKY Farm', +// lowerText: 'Deposited', +// }, +// }, +// outcome: '5,000.00 USDS', +// }) +// }) + +// test('executes transaction', async () => { +// await unstakeDialog.actionsContainer.acceptAllActionsAction(1) + +// await unstakeDialog.expectSuccessPage() +// await unstakeDialog.clickBackToFarmAction() + +// await farmDetailsPage.expectTokenToDepositBalance('USDS', '15,000.00') +// await farmDetailsPage.expectTokenToDepositBalance('DAI', '-') +// await farmDetailsPage.expectReward({ +// reward: '3,539', +// rewardUsd: '$213', +// }) +// await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) +// }) +// }) + +// test.describe('Unstake USDS from CLE farm', () => { +// const testUserPKey = '0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5' +// const testUserAddress = privateKeyToAddress('0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5') +// const harSuffix = testUserAddress.slice(0, 10) + +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let farmDetailsPage: FarmDetailsPageObject +// let unstakeDialog: UnstakeDialogPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'farmDetails', +// initialPageParams: { +// chainId: mainnet.id.toString(), +// address: '0x10ab606B067C9C461d8893c47C7512472E19e2Ce', +// }, +// account: { +// type: 'connected-pkey', +// privateKey: testUserPKey, +// assetBalances: { +// ETH: 1, +// USDS: 10_000, +// }, +// }, +// }) +// await overrideInfoSkyRouteWithHAR({ page, key: `2-cle-farm-0-balance-${harSuffix}` }) + +// farmDetailsPage = new FarmDetailsPageObject(page) +// await farmDetailsPage.clickInfoPanelStakeButtonAction() +// const stakeDialog = new StakeDialogPageObject(page) +// await stakeDialog.fillAmountAction(10_000) +// await stakeDialog.actionsContainer.acceptAllActionsAction(2) +// await stakeDialog.clickBackToFarmAction() + +// await overrideInfoSkyRouteWithHAR({ page, key: `3-cle-farm-10000-balance-${harSuffix}` }) +// await farmDetailsPage.clickInfoPanelUnstakeButtonAction() +// unstakeDialog = new UnstakeDialogPageObject(page) + +// await unstakeDialog.selectAssetAction('USDS') +// await unstakeDialog.fillAmountAction(5_000) +// }) + +// test('has correct action plan', async () => { +// await unstakeDialog.actionsContainer.expectActions([ +// { type: 'unstake', stakingToken: 'USDS', rewardToken: 'CLE', exit: false }, +// ]) +// }) + +// test('displays transaction overview', async () => { +// await unstakeDialog.expectTransactionOverview({ +// route: { +// swaps: [ +// { +// tokenAmount: '5,000.00 USDS', +// tokenUsdValue: '$5,000.00', +// }, +// ], +// farm: { +// upperText: 'CLE Farm', +// lowerText: 'Deposited', +// }, +// }, +// outcome: '5,000.00 USDS', +// }) +// }) + +// test('executes transaction', async ({ page }) => { +// await unstakeDialog.actionsContainer.acceptAllActionsAction(1) + +// await unstakeDialog.expectSuccessPage() +// await unstakeDialog.clickBackToFarmAction() + +// await farmDetailsPage.expectTokenToDepositBalance('USDS', '5,000.00') +// await farmDetailsPage.expectReward({ +// reward: '257.6', +// }) +// await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) +// await farmDetailsPage.expectPointsSyncWarning() + +// await overrideInfoSkyRouteWithHAR({ page, key: `4-cle-farm-5000-balance-${harSuffix}` }) + +// await farmDetailsPage.expectReward({ +// reward: '257.6', +// }) +// await farmDetailsPage.expectPointsSyncWarningToBeHidden() +// await farmDetailsPage.expectInfoPanelClaimButtonToBeHidden() +// await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) +// }) +// }) diff --git a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxDai.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxDai.test-e2e.ts index 26d11da6b..11832558e 100644 --- a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxDai.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxDai.test-e2e.ts @@ -1,162 +1,162 @@ -import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { Address } from 'viem' -import { mainnet } from 'viem/chains' -import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' -import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' - -test.describe('Withdraw max DAI from SKY farm', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let farmDetailsPage: FarmDetailsPageObject - let unstakeDialog: UnstakeDialogPageObject - let stakeDialog: StakeDialogPageObject - let account: Address - - test.beforeEach(async ({ page }) => { - ;({ account } = await setup(page, fork, { - initialPage: 'farmDetails', - initialPageParams: { - chainId: mainnet.id.toString(), - address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', - }, - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDS: 10_000, - DAI: 10_000, - USDC: 10_000, - }, - }, - })) - - await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) - - farmDetailsPage = new FarmDetailsPageObject(page) - await farmDetailsPage.clickInfoPanelStakeButtonAction() - stakeDialog = new StakeDialogPageObject(page) - - await stakeDialog.selectAssetAction('USDS') - await stakeDialog.fillAmountAction(10_000) - await stakeDialog.actionsContainer.acceptAllActionsAction(2) - - await stakeDialog.clickBackToFarmAction() - - await fork.progressSimulation(page, 24 * 60 * 60) // 24 hours - await page.reload() - - await farmDetailsPage.clickInfoPanelUnstakeButtonAction() - unstakeDialog = new UnstakeDialogPageObject(page) - - await unstakeDialog.selectAssetAction('DAI') - await unstakeDialog.clickMaxAmountAction() - }) - - test('has correct action plan', async () => { - await unstakeDialog.actionsContainer.expectActions([ - { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, - { type: 'approve', asset: 'USDS' }, - { type: 'downgrade', fromToken: 'USDS', toToken: 'DAI' }, - ]) - }) - - test('has correct action plan when exiting', async () => { - await unstakeDialog.clickExitFarmSwitchAction() - await unstakeDialog.actionsContainer.expectActions([ - { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: true }, - { type: 'approve', asset: 'USDS' }, - { type: 'downgrade', fromToken: 'USDS', toToken: 'DAI' }, - ]) - }) - - test('displays transaction overview', async () => { - await unstakeDialog.expectTransactionOverview({ - route: { - swaps: [ - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '10,000.00 DAI', - tokenUsdValue: '$10,000.00', - }, - ], - farm: { - upperText: 'SKY Farm', - lowerText: 'Deposited', - }, - }, - outcome: '10,000.00 DAI', - }) - }) - - test('displays transaction overview when exiting', async () => { - await unstakeDialog.clickExitFarmSwitchAction() - await unstakeDialog.expectExitTransactionOverview({ - route: { - swaps: [ - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '10,000.00 DAI', - tokenUsdValue: '$10,000.00', - }, - ], - farm: { - upperText: 'SKY Farm', - lowerText: 'Deposited', - }, - }, - outcome: { - amount: '10,000.00', - token: 'DAI', - usdValue: '10,000.00', - }, - reward: { - min: 3538, - max: 3541, - usdValue: '213', - token: 'SKY', - }, - }) - }) - - test('executes transaction', async () => { - await unstakeDialog.actionsContainer.acceptAllActionsAction(3) - - await unstakeDialog.expectSuccessPage() - await unstakeDialog.clickBackToFarmAction() - - await farmDetailsPage.expectTokenToDepositBalance('DAI', '20,000.00') - await farmDetailsPage.expectReward({ - reward: '3,539', - rewardUsd: '$213', - }) - }) - - test('executes exit transaction', async () => { - await unstakeDialog.clickExitFarmSwitchAction() - await unstakeDialog.actionsContainer.acceptAllActionsAction(3) - - await unstakeDialog.expectSuccessPage() - await unstakeDialog.clickBackToFarmAction() - - await farmDetailsPage.expectTokenToDepositBalance('DAI', '20,000.00') - await farmDetailsPage.expectInfoPanelToBeVisible() - - await farmDetailsPage.expectTokenBalance({ - address: account, - fork, - symbol: 'SKY', - minBalance: 3_525, - maxBalance: 3_545, - }) - }) -}) +// import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { Address } from 'viem' +// import { mainnet } from 'viem/chains' +// import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' +// import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' + +// test.describe('Withdraw max DAI from SKY farm', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let farmDetailsPage: FarmDetailsPageObject +// let unstakeDialog: UnstakeDialogPageObject +// let stakeDialog: StakeDialogPageObject +// let account: Address + +// test.beforeEach(async ({ page }) => { +// ;({ account } = await setup(page, fork, { +// initialPage: 'farmDetails', +// initialPageParams: { +// chainId: mainnet.id.toString(), +// address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', +// }, +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// USDS: 10_000, +// DAI: 10_000, +// USDC: 10_000, +// }, +// }, +// })) + +// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) + +// farmDetailsPage = new FarmDetailsPageObject(page) +// await farmDetailsPage.clickInfoPanelStakeButtonAction() +// stakeDialog = new StakeDialogPageObject(page) + +// await stakeDialog.selectAssetAction('USDS') +// await stakeDialog.fillAmountAction(10_000) +// await stakeDialog.actionsContainer.acceptAllActionsAction(2) + +// await stakeDialog.clickBackToFarmAction() + +// await fork.progressSimulation(page, 24 * 60 * 60) // 24 hours +// await page.reload() + +// await farmDetailsPage.clickInfoPanelUnstakeButtonAction() +// unstakeDialog = new UnstakeDialogPageObject(page) + +// await unstakeDialog.selectAssetAction('DAI') +// await unstakeDialog.clickMaxAmountAction() +// }) + +// test('has correct action plan', async () => { +// await unstakeDialog.actionsContainer.expectActions([ +// { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, +// { type: 'approve', asset: 'USDS' }, +// { type: 'downgrade', fromToken: 'USDS', toToken: 'DAI' }, +// ]) +// }) + +// test('has correct action plan when exiting', async () => { +// await unstakeDialog.clickExitFarmSwitchAction() +// await unstakeDialog.actionsContainer.expectActions([ +// { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: true }, +// { type: 'approve', asset: 'USDS' }, +// { type: 'downgrade', fromToken: 'USDS', toToken: 'DAI' }, +// ]) +// }) + +// test('displays transaction overview', async () => { +// await unstakeDialog.expectTransactionOverview({ +// route: { +// swaps: [ +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '10,000.00 DAI', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// farm: { +// upperText: 'SKY Farm', +// lowerText: 'Deposited', +// }, +// }, +// outcome: '10,000.00 DAI', +// }) +// }) + +// test('displays transaction overview when exiting', async () => { +// await unstakeDialog.clickExitFarmSwitchAction() +// await unstakeDialog.expectExitTransactionOverview({ +// route: { +// swaps: [ +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '10,000.00 DAI', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// farm: { +// upperText: 'SKY Farm', +// lowerText: 'Deposited', +// }, +// }, +// outcome: { +// amount: '10,000.00', +// token: 'DAI', +// usdValue: '10,000.00', +// }, +// reward: { +// min: 3538, +// max: 3541, +// usdValue: '213', +// token: 'SKY', +// }, +// }) +// }) + +// test('executes transaction', async () => { +// await unstakeDialog.actionsContainer.acceptAllActionsAction(3) + +// await unstakeDialog.expectSuccessPage() +// await unstakeDialog.clickBackToFarmAction() + +// await farmDetailsPage.expectTokenToDepositBalance('DAI', '20,000.00') +// await farmDetailsPage.expectReward({ +// reward: '3,539', +// rewardUsd: '$213', +// }) +// }) + +// test('executes exit transaction', async () => { +// await unstakeDialog.clickExitFarmSwitchAction() +// await unstakeDialog.actionsContainer.acceptAllActionsAction(3) + +// await unstakeDialog.expectSuccessPage() +// await unstakeDialog.clickBackToFarmAction() + +// await farmDetailsPage.expectTokenToDepositBalance('DAI', '20,000.00') +// await farmDetailsPage.expectInfoPanelToBeVisible() + +// await farmDetailsPage.expectTokenBalance({ +// address: account, +// fork, +// symbol: 'SKY', +// minBalance: 3_525, +// maxBalance: 3_545, +// }) +// }) +// }) diff --git a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts index ae7fd30fe..a50a12d22 100644 --- a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts @@ -1,162 +1,162 @@ -import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { Address } from 'viem' -import { mainnet } from 'viem/chains' -import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' -import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' - -test.describe('Withdraw max USDC from SKY farm', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let farmDetailsPage: FarmDetailsPageObject - let unstakeDialog: UnstakeDialogPageObject - let stakeDialog: StakeDialogPageObject - let account: Address - - test.beforeEach(async ({ page }) => { - ;({ account } = await setup(page, fork, { - initialPage: 'farmDetails', - initialPageParams: { - chainId: mainnet.id.toString(), - address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', - }, - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDS: 10_000, - DAI: 10_000, - USDC: 10_000, - }, - }, - })) - - await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) - - farmDetailsPage = new FarmDetailsPageObject(page) - await farmDetailsPage.clickInfoPanelStakeButtonAction() - stakeDialog = new StakeDialogPageObject(page) - - await stakeDialog.selectAssetAction('USDS') - await stakeDialog.fillAmountAction(10_000) - await stakeDialog.actionsContainer.acceptAllActionsAction(2) - - await stakeDialog.clickBackToFarmAction() - - await fork.progressSimulation(page, 24 * 60 * 60) // 24 hours - await page.reload() - - await farmDetailsPage.clickInfoPanelUnstakeButtonAction() - unstakeDialog = new UnstakeDialogPageObject(page) - - await unstakeDialog.selectAssetAction('USDC') - await unstakeDialog.clickMaxAmountAction() - }) - - test('has correct action plan', async () => { - await unstakeDialog.actionsContainer.expectActions([ - { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, - { type: 'approve', asset: 'USDS' }, - { type: 'psmConvert', inToken: 'USDS', outToken: 'USDC' }, - ]) - }) - - test('has correct action plan when exiting', async () => { - await unstakeDialog.clickExitFarmSwitchAction() - await unstakeDialog.actionsContainer.expectActions([ - { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: true }, - { type: 'approve', asset: 'USDS' }, - { type: 'psmConvert', inToken: 'USDS', outToken: 'USDC' }, - ]) - }) - - test('displays transaction overview', async () => { - await unstakeDialog.expectTransactionOverview({ - route: { - swaps: [ - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '10,000.00 USDC', - tokenUsdValue: '$10,000.00', - }, - ], - farm: { - upperText: 'SKY Farm', - lowerText: 'Deposited', - }, - }, - outcome: '10,000.00 USDC', - }) - }) - - test('displays transaction overview when exiting', async () => { - await unstakeDialog.clickExitFarmSwitchAction() - await unstakeDialog.expectExitTransactionOverview({ - route: { - swaps: [ - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - { - tokenAmount: '10,000.00 USDC', - tokenUsdValue: '$10,000.00', - }, - ], - farm: { - upperText: 'SKY Farm', - lowerText: 'Deposited', - }, - }, - outcome: { - amount: '10,000.00', - token: 'USDC', - usdValue: '10,000.00', - }, - reward: { - min: 3538, - max: 3541, - usdValue: '213', - token: 'SKY', - }, - }) - }) - - test('executes transaction', async () => { - await unstakeDialog.actionsContainer.acceptAllActionsAction(3) - - await unstakeDialog.expectSuccessPage() - await unstakeDialog.clickBackToFarmAction() - - await farmDetailsPage.expectTokenToDepositBalance('USDC', '20,000.00') - await farmDetailsPage.expectReward({ - reward: '3,539', - rewardUsd: '$213', - }) - }) - - test('executes exit transaction', async () => { - await unstakeDialog.clickExitFarmSwitchAction() - await unstakeDialog.actionsContainer.acceptAllActionsAction(3) - - await unstakeDialog.expectSuccessPage() - await unstakeDialog.clickBackToFarmAction() - - await farmDetailsPage.expectTokenToDepositBalance('USDC', '20,000.00') - await farmDetailsPage.expectInfoPanelToBeVisible() - - await farmDetailsPage.expectTokenBalance({ - address: account, - fork, - symbol: 'SKY', - minBalance: 3_525, - maxBalance: 3_545, - }) - }) -}) +// import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { Address } from 'viem' +// import { mainnet } from 'viem/chains' +// import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' +// import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' + +// test.describe('Withdraw max USDC from SKY farm', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let farmDetailsPage: FarmDetailsPageObject +// let unstakeDialog: UnstakeDialogPageObject +// let stakeDialog: StakeDialogPageObject +// let account: Address + +// test.beforeEach(async ({ page }) => { +// ;({ account } = await setup(page, fork, { +// initialPage: 'farmDetails', +// initialPageParams: { +// chainId: mainnet.id.toString(), +// address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', +// }, +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// USDS: 10_000, +// DAI: 10_000, +// USDC: 10_000, +// }, +// }, +// })) + +// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) + +// farmDetailsPage = new FarmDetailsPageObject(page) +// await farmDetailsPage.clickInfoPanelStakeButtonAction() +// stakeDialog = new StakeDialogPageObject(page) + +// await stakeDialog.selectAssetAction('USDS') +// await stakeDialog.fillAmountAction(10_000) +// await stakeDialog.actionsContainer.acceptAllActionsAction(2) + +// await stakeDialog.clickBackToFarmAction() + +// await fork.progressSimulation(page, 24 * 60 * 60) // 24 hours +// await page.reload() + +// await farmDetailsPage.clickInfoPanelUnstakeButtonAction() +// unstakeDialog = new UnstakeDialogPageObject(page) + +// await unstakeDialog.selectAssetAction('USDC') +// await unstakeDialog.clickMaxAmountAction() +// }) + +// test('has correct action plan', async () => { +// await unstakeDialog.actionsContainer.expectActions([ +// { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, +// { type: 'approve', asset: 'USDS' }, +// { type: 'psmConvert', inToken: 'USDS', outToken: 'USDC' }, +// ]) +// }) + +// test('has correct action plan when exiting', async () => { +// await unstakeDialog.clickExitFarmSwitchAction() +// await unstakeDialog.actionsContainer.expectActions([ +// { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: true }, +// { type: 'approve', asset: 'USDS' }, +// { type: 'psmConvert', inToken: 'USDS', outToken: 'USDC' }, +// ]) +// }) + +// test('displays transaction overview', async () => { +// await unstakeDialog.expectTransactionOverview({ +// route: { +// swaps: [ +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '10,000.00 USDC', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// farm: { +// upperText: 'SKY Farm', +// lowerText: 'Deposited', +// }, +// }, +// outcome: '10,000.00 USDC', +// }) +// }) + +// test('displays transaction overview when exiting', async () => { +// await unstakeDialog.clickExitFarmSwitchAction() +// await unstakeDialog.expectExitTransactionOverview({ +// route: { +// swaps: [ +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// { +// tokenAmount: '10,000.00 USDC', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// farm: { +// upperText: 'SKY Farm', +// lowerText: 'Deposited', +// }, +// }, +// outcome: { +// amount: '10,000.00', +// token: 'USDC', +// usdValue: '10,000.00', +// }, +// reward: { +// min: 3538, +// max: 3541, +// usdValue: '213', +// token: 'SKY', +// }, +// }) +// }) + +// test('executes transaction', async () => { +// await unstakeDialog.actionsContainer.acceptAllActionsAction(3) + +// await unstakeDialog.expectSuccessPage() +// await unstakeDialog.clickBackToFarmAction() + +// await farmDetailsPage.expectTokenToDepositBalance('USDC', '20,000.00') +// await farmDetailsPage.expectReward({ +// reward: '3,539', +// rewardUsd: '$213', +// }) +// }) + +// test('executes exit transaction', async () => { +// await unstakeDialog.clickExitFarmSwitchAction() +// await unstakeDialog.actionsContainer.acceptAllActionsAction(3) + +// await unstakeDialog.expectSuccessPage() +// await unstakeDialog.clickBackToFarmAction() + +// await farmDetailsPage.expectTokenToDepositBalance('USDC', '20,000.00') +// await farmDetailsPage.expectInfoPanelToBeVisible() + +// await farmDetailsPage.expectTokenBalance({ +// address: account, +// fork, +// symbol: 'SKY', +// minBalance: 3_525, +// maxBalance: 3_545, +// }) +// }) +// }) diff --git a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts index a7a50a0f9..cbf7b0898 100644 --- a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts @@ -1,217 +1,217 @@ -import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { Address } from 'viem' -import { privateKeyToAddress } from 'viem/accounts' -import { mainnet } from 'viem/chains' -import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' -import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' - -test.describe('Withdraw max USDS from SKY farm', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let farmDetailsPage: FarmDetailsPageObject - let unstakeDialog: UnstakeDialogPageObject - let stakeDialog: StakeDialogPageObject - let account: Address - - test.beforeEach(async ({ page }) => { - ;({ account } = await setup(page, fork, { - initialPage: 'farmDetails', - initialPageParams: { - chainId: mainnet.id.toString(), - address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', - }, - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDS: 10_000, - DAI: 10_000, - USDC: 10_000, - }, - }, - })) - - await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) - - farmDetailsPage = new FarmDetailsPageObject(page) - await farmDetailsPage.clickInfoPanelStakeButtonAction() - stakeDialog = new StakeDialogPageObject(page) - - await stakeDialog.selectAssetAction('USDS') - await stakeDialog.fillAmountAction(10_000) - await stakeDialog.actionsContainer.acceptAllActionsAction(2) - - await stakeDialog.clickBackToFarmAction() - - await fork.progressSimulation(page, 24 * 60 * 60) // 24 hours - await page.reload() - - await farmDetailsPage.clickInfoPanelUnstakeButtonAction() - unstakeDialog = new UnstakeDialogPageObject(page) - - await unstakeDialog.selectAssetAction('USDS') - await unstakeDialog.clickMaxAmountAction() - }) - - test('has reward displayed on exit farm switch', async () => { - await unstakeDialog.expectExitFarmSwitchToBeVisible() - await unstakeDialog.expectExitFarmSwitchNotChecked() - await unstakeDialog.expectExitFarmSwitchReward({ - min: 3538, - max: 3541, - token: 'SKY', - usdValue: '213', - }) - }) - - test('has correct action plan', async () => { - await unstakeDialog.actionsContainer.expectActions([ - { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, - ]) - }) - - test('has correct action plan when exiting', async () => { - await unstakeDialog.clickExitFarmSwitchAction() - await unstakeDialog.actionsContainer.expectActions([ - { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: true }, - ]) - }) - - test('displays transaction overview', async () => { - await unstakeDialog.expectTransactionOverview({ - route: { - swaps: [ - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - ], - farm: { - upperText: 'SKY Farm', - lowerText: 'Deposited', - }, - }, - outcome: '10,000.00 USDS', - }) - }) - - test('displays transaction overview when exiting', async () => { - await unstakeDialog.clickExitFarmSwitchAction() - await unstakeDialog.expectExitTransactionOverview({ - route: { - swaps: [ - { - tokenAmount: '10,000.00 USDS', - tokenUsdValue: '$10,000.00', - }, - ], - farm: { - upperText: 'SKY Farm', - lowerText: 'Deposited', - }, - }, - outcome: { - amount: '10,000.00', - token: 'USDS', - usdValue: '10,000.00', - }, - reward: { - min: 3538, - max: 3541, - usdValue: '213', - token: 'SKY', - }, - }) - }) - - test('executes transaction', async () => { - await unstakeDialog.actionsContainer.acceptAllActionsAction(1) - - await unstakeDialog.expectSuccessPage() - await unstakeDialog.clickBackToFarmAction() - - await farmDetailsPage.expectTokenToDepositBalance('USDS', '10,000.00') - await farmDetailsPage.expectReward({ - reward: '3,539', - rewardUsd: '$213', - }) - }) - - test('executes exit transaction', async () => { - await unstakeDialog.clickExitFarmSwitchAction() - await unstakeDialog.actionsContainer.acceptAllActionsAction(1) - - await unstakeDialog.expectSuccessPage() - await unstakeDialog.clickBackToFarmAction() - - await farmDetailsPage.expectTokenToDepositBalance('USDS', '10,000.00') - await farmDetailsPage.expectInfoPanelToBeVisible() - - await farmDetailsPage.expectTokenBalance({ - address: account, - fork, - symbol: 'SKY', - minBalance: 3_525, - maxBalance: 3_545, - }) - }) -}) - -test.describe('Withdraw max USDS from CLE farm', () => { - const testUserPKey = '0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5' - const testUserAddress = privateKeyToAddress('0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5') - const harSuffix = testUserAddress.slice(0, 10) - - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let farmDetailsPage: FarmDetailsPageObject - let unstakeDialog: UnstakeDialogPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'farmDetails', - initialPageParams: { - chainId: mainnet.id.toString(), - address: '0x10ab606B067C9C461d8893c47C7512472E19e2Ce', - }, - account: { - type: 'connected-pkey', - privateKey: testUserPKey, - assetBalances: { - ETH: 1, - USDS: 10_000, - }, - }, - }) - await overrideInfoSkyRouteWithHAR({ page, key: `2-cle-farm-0-balance-${harSuffix}` }) - - farmDetailsPage = new FarmDetailsPageObject(page) - await farmDetailsPage.clickInfoPanelStakeButtonAction() - const stakeDialog = new StakeDialogPageObject(page) - await stakeDialog.fillAmountAction(10_000) - await stakeDialog.actionsContainer.acceptAllActionsAction(2) - await stakeDialog.clickBackToFarmAction() - await overrideInfoSkyRouteWithHAR({ page, key: `3-cle-farm-10000-balance-${harSuffix}` }) - - await farmDetailsPage.clickInfoPanelUnstakeButtonAction() - unstakeDialog = new UnstakeDialogPageObject(page) - - await unstakeDialog.selectAssetAction('USDS') - await unstakeDialog.clickMaxAmountAction() - }) - - test('keeps the exit switch hidden', async () => { - await unstakeDialog.actionsContainer.expectEnabledActionAtIndex(0) - await unstakeDialog.expectExitFarmSwitchToBeHidden() - }) - - test('has correct action plan', async () => { - await unstakeDialog.actionsContainer.expectEnabledActionAtIndex(0) - await unstakeDialog.actionsContainer.expectActions([ - { type: 'unstake', stakingToken: 'USDS', rewardToken: 'CLE', exit: false }, - ]) - }) -}) +// import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { Address } from 'viem' +// import { privateKeyToAddress } from 'viem/accounts' +// import { mainnet } from 'viem/chains' +// import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' +// import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' + +// test.describe('Withdraw max USDS from SKY farm', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let farmDetailsPage: FarmDetailsPageObject +// let unstakeDialog: UnstakeDialogPageObject +// let stakeDialog: StakeDialogPageObject +// let account: Address + +// test.beforeEach(async ({ page }) => { +// ;({ account } = await setup(page, fork, { +// initialPage: 'farmDetails', +// initialPageParams: { +// chainId: mainnet.id.toString(), +// address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', +// }, +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 1, +// USDS: 10_000, +// DAI: 10_000, +// USDC: 10_000, +// }, +// }, +// })) + +// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) + +// farmDetailsPage = new FarmDetailsPageObject(page) +// await farmDetailsPage.clickInfoPanelStakeButtonAction() +// stakeDialog = new StakeDialogPageObject(page) + +// await stakeDialog.selectAssetAction('USDS') +// await stakeDialog.fillAmountAction(10_000) +// await stakeDialog.actionsContainer.acceptAllActionsAction(2) + +// await stakeDialog.clickBackToFarmAction() + +// await fork.progressSimulation(page, 24 * 60 * 60) // 24 hours +// await page.reload() + +// await farmDetailsPage.clickInfoPanelUnstakeButtonAction() +// unstakeDialog = new UnstakeDialogPageObject(page) + +// await unstakeDialog.selectAssetAction('USDS') +// await unstakeDialog.clickMaxAmountAction() +// }) + +// test('has reward displayed on exit farm switch', async () => { +// await unstakeDialog.expectExitFarmSwitchToBeVisible() +// await unstakeDialog.expectExitFarmSwitchNotChecked() +// await unstakeDialog.expectExitFarmSwitchReward({ +// min: 3538, +// max: 3541, +// token: 'SKY', +// usdValue: '213', +// }) +// }) + +// test('has correct action plan', async () => { +// await unstakeDialog.actionsContainer.expectActions([ +// { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, +// ]) +// }) + +// test('has correct action plan when exiting', async () => { +// await unstakeDialog.clickExitFarmSwitchAction() +// await unstakeDialog.actionsContainer.expectActions([ +// { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: true }, +// ]) +// }) + +// test('displays transaction overview', async () => { +// await unstakeDialog.expectTransactionOverview({ +// route: { +// swaps: [ +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// farm: { +// upperText: 'SKY Farm', +// lowerText: 'Deposited', +// }, +// }, +// outcome: '10,000.00 USDS', +// }) +// }) + +// test('displays transaction overview when exiting', async () => { +// await unstakeDialog.clickExitFarmSwitchAction() +// await unstakeDialog.expectExitTransactionOverview({ +// route: { +// swaps: [ +// { +// tokenAmount: '10,000.00 USDS', +// tokenUsdValue: '$10,000.00', +// }, +// ], +// farm: { +// upperText: 'SKY Farm', +// lowerText: 'Deposited', +// }, +// }, +// outcome: { +// amount: '10,000.00', +// token: 'USDS', +// usdValue: '10,000.00', +// }, +// reward: { +// min: 3538, +// max: 3541, +// usdValue: '213', +// token: 'SKY', +// }, +// }) +// }) + +// test('executes transaction', async () => { +// await unstakeDialog.actionsContainer.acceptAllActionsAction(1) + +// await unstakeDialog.expectSuccessPage() +// await unstakeDialog.clickBackToFarmAction() + +// await farmDetailsPage.expectTokenToDepositBalance('USDS', '10,000.00') +// await farmDetailsPage.expectReward({ +// reward: '3,539', +// rewardUsd: '$213', +// }) +// }) + +// test('executes exit transaction', async () => { +// await unstakeDialog.clickExitFarmSwitchAction() +// await unstakeDialog.actionsContainer.acceptAllActionsAction(1) + +// await unstakeDialog.expectSuccessPage() +// await unstakeDialog.clickBackToFarmAction() + +// await farmDetailsPage.expectTokenToDepositBalance('USDS', '10,000.00') +// await farmDetailsPage.expectInfoPanelToBeVisible() + +// await farmDetailsPage.expectTokenBalance({ +// address: account, +// fork, +// symbol: 'SKY', +// minBalance: 3_525, +// maxBalance: 3_545, +// }) +// }) +// }) + +// test.describe('Withdraw max USDS from CLE farm', () => { +// const testUserPKey = '0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5' +// const testUserAddress = privateKeyToAddress('0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5') +// const harSuffix = testUserAddress.slice(0, 10) + +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let farmDetailsPage: FarmDetailsPageObject +// let unstakeDialog: UnstakeDialogPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'farmDetails', +// initialPageParams: { +// chainId: mainnet.id.toString(), +// address: '0x10ab606B067C9C461d8893c47C7512472E19e2Ce', +// }, +// account: { +// type: 'connected-pkey', +// privateKey: testUserPKey, +// assetBalances: { +// ETH: 1, +// USDS: 10_000, +// }, +// }, +// }) +// await overrideInfoSkyRouteWithHAR({ page, key: `2-cle-farm-0-balance-${harSuffix}` }) + +// farmDetailsPage = new FarmDetailsPageObject(page) +// await farmDetailsPage.clickInfoPanelStakeButtonAction() +// const stakeDialog = new StakeDialogPageObject(page) +// await stakeDialog.fillAmountAction(10_000) +// await stakeDialog.actionsContainer.acceptAllActionsAction(2) +// await stakeDialog.clickBackToFarmAction() +// await overrideInfoSkyRouteWithHAR({ page, key: `3-cle-farm-10000-balance-${harSuffix}` }) + +// await farmDetailsPage.clickInfoPanelUnstakeButtonAction() +// unstakeDialog = new UnstakeDialogPageObject(page) + +// await unstakeDialog.selectAssetAction('USDS') +// await unstakeDialog.clickMaxAmountAction() +// }) + +// test('keeps the exit switch hidden', async () => { +// await unstakeDialog.actionsContainer.expectEnabledActionAtIndex(0) +// await unstakeDialog.expectExitFarmSwitchToBeHidden() +// }) + +// test('has correct action plan', async () => { +// await unstakeDialog.actionsContainer.expectEnabledActionAtIndex(0) +// await unstakeDialog.actionsContainer.expectActions([ +// { type: 'unstake', stakingToken: 'USDS', rewardToken: 'CLE', exit: false }, +// ]) +// }) +// }) diff --git a/packages/app/src/features/topbar/Topbar.test-e2e.ts b/packages/app/src/features/topbar/Topbar.test-e2e.ts index 8ec70d6b3..2b5666f85 100644 --- a/packages/app/src/features/topbar/Topbar.test-e2e.ts +++ b/packages/app/src/features/topbar/Topbar.test-e2e.ts @@ -1,164 +1,164 @@ -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' - -import { overrideAirdropInfoRoute } from '@/test/e2e/airdropInfo' -import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' - -import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' -import { TopbarPageObject } from './Topbar.PageObject' - -test.describe('Topbar', () => { - const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) - - test.describe('Airdrop counter', () => { - test('Disconnected', async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'not-connected', - }, - }) - - const topbar = new TopbarPageObject(page) - await topbar.expectAirdropCompactValue('0') - await topbar.openAirdropDropdown() - await topbar.expectAirdropPreciseValue('0.00 SPK') - }) - - test('Connected', async ({ page }) => { - const { account } = await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - }, - }) - - await overrideAirdropInfoRoute(page, { account }) - - const topbar = new TopbarPageObject(page) - await topbar.expectAirdropCompactValue('7.841M') - await topbar.openAirdropDropdown() - await topbar.expectAirdropPreciseValue('7,840,591') - }) - - test('Api error', async ({ page }) => { - const { account } = await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - }, - }) - - await overrideAirdropInfoRoute(page, { account, shouldFail: true }) - - const topbar = new TopbarPageObject(page) - await topbar.expectAirdropBadgeNotVisible() - }) - - test('Wallet with no airdrop', async ({ page }) => { - const { account } = await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - }, - }) - - await overrideAirdropInfoRoute(page, { account, noAirdrop: true }) - - const topbar = new TopbarPageObject(page) - await topbar.expectAirdropCompactValue('0') - await topbar.openAirdropDropdown() - await topbar.expectAirdropPreciseValue('0.00 SPK') - }) - }) - - test.describe('Rewards badge', () => { - const fork = setupFork({ - blockNumber: 20189272n, // block number where the reward program is finished - chainId: mainnet.id, - }) - - test('Displays total rewards in badge', async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-address', - address: '0xf8de75c7b95edb6f1e639751318f117663021cf0', - }, - }) - - const topbar = new TopbarPageObject(page) - await topbar.expectClaimableRewardsValue('$25.58K') - }) - - test('Displays details in dropdown', async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-address', - address: '0xf8de75c7b95edb6f1e639751318f117663021cf0', - }, - }) - - const topbar = new TopbarPageObject(page) - await topbar.openRewardsDropdown() - - await topbar.expectRewards([ - { - tokenSymbol: 'wstETH', - amount: '6.3697', - amountUSD: '$25,583.20', - }, - ]) - }) - - test('Does not display badge when no rewards', async ({ page }) => { - await setup(page, fork, { - initialPage: 'myPortfolio', - account: { - type: 'connected-random', - }, - }) - - const topbar = new TopbarPageObject(page) - const myPortfolioPage = new MyPortfolioPageObject(page) - - await myPortfolioPage.expectPositionToBeEmpty() // waiting for reserves to load - await topbar.expectRewardsBadgeNotVisible() // asserting that after reserves are loaded, rewards badge is not visible - }) - }) - - test.describe('Malformed localStorage', () => { - test('Sandbox info in wagmi.store but not in zustand-app-store', async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'not-connected', - }, - skipInjectingNetwork: true, - }) - await page.evaluate(() => { - localStorage.setItem('wagmi.recentConnectorId', 'mock') - localStorage.setItem('wagmi.io.metamask.disconnected', 'true') - localStorage.setItem('wagmi.io.rabby.disconnected', 'true') - localStorage.setItem('zustand-app-store', JSON.stringify({ state: {}, sandbox: {} })) - localStorage.setItem('actionSettings', JSON.stringify({ preferPermits: true, exchangeMaxSlippage: '0.001' })) - localStorage.setItem('compliance', JSON.stringify({ agreedToSAdresses: [] })) - localStorage.setItem( - 'wagmi.store', - JSON.stringify({ - state: { connections: { _type: 'Map', value: [] }, chainId: '30301713953503', current: null }, - version: 2, - }), - ) - }) - - await page.reload() - - const topbar = new TopbarPageObject(page) - await topbar.expectSavingsLinkVisible() - }) - }) -}) +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' + +// import { overrideAirdropInfoRoute } from '@/test/e2e/airdropInfo' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' + +// import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' +// import { TopbarPageObject } from './Topbar.PageObject' + +// test.describe('Topbar', () => { +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) + +// test.describe('Airdrop counter', () => { +// test('Disconnected', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'not-connected', +// }, +// }) + +// const topbar = new TopbarPageObject(page) +// await topbar.expectAirdropCompactValue('0') +// await topbar.openAirdropDropdown() +// await topbar.expectAirdropPreciseValue('0.00 SPK') +// }) + +// test('Connected', async ({ page }) => { +// const { account } = await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// }, +// }) + +// await overrideAirdropInfoRoute(page, { account }) + +// const topbar = new TopbarPageObject(page) +// await topbar.expectAirdropCompactValue('7.841M') +// await topbar.openAirdropDropdown() +// await topbar.expectAirdropPreciseValue('7,840,591') +// }) + +// test('Api error', async ({ page }) => { +// const { account } = await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// }, +// }) + +// await overrideAirdropInfoRoute(page, { account, shouldFail: true }) + +// const topbar = new TopbarPageObject(page) +// await topbar.expectAirdropBadgeNotVisible() +// }) + +// test('Wallet with no airdrop', async ({ page }) => { +// const { account } = await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// }, +// }) + +// await overrideAirdropInfoRoute(page, { account, noAirdrop: true }) + +// const topbar = new TopbarPageObject(page) +// await topbar.expectAirdropCompactValue('0') +// await topbar.openAirdropDropdown() +// await topbar.expectAirdropPreciseValue('0.00 SPK') +// }) +// }) + +// test.describe('Rewards badge', () => { +// const fork = setupFork({ +// blockNumber: 20189272n, // block number where the reward program is finished +// chainId: mainnet.id, +// }) + +// test('Displays total rewards in badge', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-address', +// address: '0xf8de75c7b95edb6f1e639751318f117663021cf0', +// }, +// }) + +// const topbar = new TopbarPageObject(page) +// await topbar.expectClaimableRewardsValue('$25.58K') +// }) + +// test('Displays details in dropdown', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-address', +// address: '0xf8de75c7b95edb6f1e639751318f117663021cf0', +// }, +// }) + +// const topbar = new TopbarPageObject(page) +// await topbar.openRewardsDropdown() + +// await topbar.expectRewards([ +// { +// tokenSymbol: 'wstETH', +// amount: '6.3697', +// amountUSD: '$25,583.20', +// }, +// ]) +// }) + +// test('Does not display badge when no rewards', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'myPortfolio', +// account: { +// type: 'connected-random', +// }, +// }) + +// const topbar = new TopbarPageObject(page) +// const myPortfolioPage = new MyPortfolioPageObject(page) + +// await myPortfolioPage.expectPositionToBeEmpty() // waiting for reserves to load +// await topbar.expectRewardsBadgeNotVisible() // asserting that after reserves are loaded, rewards badge is not visible +// }) +// }) + +// test.describe('Malformed localStorage', () => { +// test('Sandbox info in wagmi.store but not in zustand-app-store', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'not-connected', +// }, +// skipInjectingNetwork: true, +// }) +// await page.evaluate(() => { +// localStorage.setItem('wagmi.recentConnectorId', 'mock') +// localStorage.setItem('wagmi.io.metamask.disconnected', 'true') +// localStorage.setItem('wagmi.io.rabby.disconnected', 'true') +// localStorage.setItem('zustand-app-store', JSON.stringify({ state: {}, sandbox: {} })) +// localStorage.setItem('actionSettings', JSON.stringify({ preferPermits: true, exchangeMaxSlippage: '0.001' })) +// localStorage.setItem('compliance', JSON.stringify({ agreedToSAdresses: [] })) +// localStorage.setItem( +// 'wagmi.store', +// JSON.stringify({ +// state: { connections: { _type: 'Map', value: [] }, chainId: '30301713953503', current: null }, +// version: 2, +// }), +// ) +// }) + +// await page.reload() + +// const topbar = new TopbarPageObject(page) +// await topbar.expectSavingsLinkVisible() +// }) +// }) +// }) diff --git a/packages/app/src/pages/Borrow.test-e2e.ts b/packages/app/src/pages/Borrow.test-e2e.ts index 5d8945c40..664158bde 100644 --- a/packages/app/src/pages/Borrow.test-e2e.ts +++ b/packages/app/src/pages/Borrow.test-e2e.ts @@ -1,570 +1,570 @@ -import { borrowValidationIssueToMessage } from '@/domain/market-validators/validateBorrow' -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { CollateralDialogPageObject } from '@/features/dialogs/collateral/CollateralDialog.PageObject' -import { DEFAULT_BLOCK_NUMBER, USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { buildUrl, setup } from '@/test/e2e/setup' -import { screenshot } from '@/test/e2e/utils' -import { Page, test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { BorrowPageObject } from './Borrow.PageObject' -import { MyPortfolioPageObject } from './MyPortfolio.PageObject' -import { SavingsPageObject } from './Savings.PageObject' - -test.describe('Borrow page', () => { - const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) - - test.describe('deposit ETH, borrow DAI', () => { - let borrowPage: BorrowPageObject - let actionsContainer: ActionsPageObject - const deposit = { - asset: 'ETH', - amount: 1, - } - const borrow = { - asset: 'DAI', - amount: 1000, - } - const expectedLtv = '44.07%' - const expectedHealthFactor = '1.87' - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { - ETH: 10, - }, - }, - }) - - borrowPage = new BorrowPageObject(page) - actionsContainer = new ActionsPageObject(page) - }) - - test('calculates LTV correctly', async () => { - await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) - await borrowPage.fillBorrowAssetAction(borrow.amount) - - await borrowPage.submitAction() - - await borrowPage.expectLtv(expectedLtv) - await borrowPage.expectHealthFactor(expectedHealthFactor) - }) - - test('builds action plan', async ({ page }) => { - await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) - await borrowPage.fillBorrowAssetAction(borrow.amount) - - await borrowPage.submitAction() - - await actionsContainer.expectExtendedActions([ - { type: 'deposit', asset: 'ETH', amount: '1.00' }, - { type: 'borrow', asset: 'DAI', amount: '1,000.00' }, - ]) - await screenshot(page, 'deposit-eth-actions-plan') - }) - - test('successfully builds position', async ({ page }) => { - await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) - await borrowPage.fillBorrowAssetAction(borrow.amount) - - await borrowPage.submitAction() - - await actionsContainer.acceptAllActionsAction(2) - - await borrowPage.expectSuccessPage([deposit], borrow, fork) - await screenshot(page, 'deposit-eth-success') - }) - - test('HF matches after position is created', async ({ page }) => { - await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) - await borrowPage.fillBorrowAssetAction(borrow.amount) - - await borrowPage.submitAction() - await actionsContainer.acceptAllActionsAction(2) - - await expectHFOnMyPortfolio(page, borrowPage, expectedHealthFactor) - }) - }) - - test.describe('deposit wstETH and rETH, borrow DAI', () => { - let borrowPage: BorrowPageObject - let actionsContainer: ActionsPageObject - const wstETHdeposit = { - asset: 'wstETH', - amount: 1, - } - const rETHdeposit = { - asset: 'rETH', - amount: 1, - } - const borrow = { - asset: 'DAI', - amount: 1000, - } - const expectedLTV = '19.57%' - const expectedHealthFactor = '4.06' - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { - wstETH: 10, - rETH: 10, - }, - }, - }) - - borrowPage = new BorrowPageObject(page) - actionsContainer = new ActionsPageObject(page) - }) - - test('calculates LTV correctly', async () => { - await borrowPage.addNewDepositAssetAction() - await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) - await borrowPage.fillDepositAssetAction(1, rETHdeposit.asset, rETHdeposit.amount) - await borrowPage.fillBorrowAssetAction(borrow.amount) - - await borrowPage.submitAction() - - await borrowPage.expectLtv(expectedLTV) - await borrowPage.expectHealthFactor(expectedHealthFactor) - }) - - test('uses permits in action plan for assets with permit support', async ({ page }) => { - await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) - await borrowPage.fillBorrowAssetAction(borrow.amount) - - await borrowPage.submitAction() - - await actionsContainer.expectExtendedActions([ - { type: 'permit', asset: 'wstETH', amount: '1.00' }, - { type: 'deposit', asset: 'wstETH', amount: '1.00' }, - { type: 'borrow', asset: 'DAI', amount: '1,000.00' }, - ]) - await screenshot(page, 'deposit-wsteth-permit-actions-plan') - }) - - test('uses approve in action plan for assets with no permit support', async ({ page }) => { - await borrowPage.fillDepositAssetAction(0, rETHdeposit.asset, rETHdeposit.amount) - await borrowPage.fillBorrowAssetAction(borrow.amount) - - await borrowPage.submitAction() - - await actionsContainer.expectExtendedActions([ - { type: 'approve', asset: 'rETH', amount: '1.00' }, - { type: 'deposit', asset: 'rETH', amount: '1.00' }, - { type: 'borrow', asset: 'DAI', amount: '1,000.00' }, - ]) - await screenshot(page, 'deposit-reth-approve-actions-plan') - }) - - test('can switch to approves in action plan', async ({ page }) => { - await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) - await borrowPage.fillBorrowAssetAction(borrow.amount) - - await borrowPage.submitAction() - - await actionsContainer.switchPreferPermitsAction() - await actionsContainer.expectExtendedActions([ - { type: 'approve', asset: 'wstETH', amount: '1.00' }, - { type: 'deposit', asset: 'wstETH', amount: '1.00' }, - { type: 'borrow', asset: 'DAI', amount: '1,000.00' }, - ]) - await screenshot(page, 'deposit-wsteth-approve-actions-plan') - }) - - test('builds action plan for 2 assets', async ({ page }) => { - await borrowPage.addNewDepositAssetAction() - await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) - await borrowPage.fillDepositAssetAction(1, rETHdeposit.asset, rETHdeposit.amount) - await borrowPage.fillBorrowAssetAction(borrow.amount) - - await borrowPage.submitAction() - - await actionsContainer.expectExtendedActions([ - { type: 'permit', asset: 'wstETH', amount: '1.00' }, - { type: 'deposit', asset: 'wstETH', amount: '1.00' }, - { type: 'approve', asset: 'rETH', amount: '1.00' }, - { type: 'deposit', asset: 'rETH', amount: '1.00' }, - { type: 'borrow', asset: 'DAI', amount: '1,000.00' }, - ]) - await screenshot(page, 'deposit-wsteth-reth-actions-plan') - }) - - test('successfully builds position', async ({ page }) => { - await borrowPage.addNewDepositAssetAction() - await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) - await borrowPage.fillDepositAssetAction(1, rETHdeposit.asset, rETHdeposit.amount) - await borrowPage.fillBorrowAssetAction(borrow.amount) - - await borrowPage.submitAction() - - await actionsContainer.acceptAllActionsAction(5) - - await borrowPage.expectSuccessPage([wstETHdeposit, rETHdeposit], borrow, fork) - await screenshot(page, 'deposit-wsteth-reth-success') - }) - - test('successfully builds position using only approves', async ({ page }) => { - await borrowPage.addNewDepositAssetAction() - await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) - await borrowPage.fillDepositAssetAction(1, rETHdeposit.asset, rETHdeposit.amount) - await borrowPage.fillBorrowAssetAction(borrow.amount) - - await borrowPage.submitAction() - - await actionsContainer.switchPreferPermitsAction() - await actionsContainer.acceptAllActionsAction(5) - - await borrowPage.expectSuccessPage([wstETHdeposit, rETHdeposit], borrow, fork) - await screenshot(page, 'deposit-wsteth-reth-success') - }) - - test('HF matches after position is created', async ({ page }) => { - await borrowPage.addNewDepositAssetAction() - await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) - await borrowPage.fillDepositAssetAction(1, rETHdeposit.asset, rETHdeposit.amount) - await borrowPage.fillBorrowAssetAction(borrow.amount) - - await borrowPage.submitAction() - await actionsContainer.acceptAllActionsAction(5) - - await expectHFOnMyPortfolio(page, borrowPage, expectedHealthFactor) - }) - }) - - test.describe('no new deposit, existing position, borrow DAI', () => { - let borrowPage: BorrowPageObject - let actionsContainer: ActionsPageObject - - const borrow = { - asset: 'DAI', - amount: 1000, - } - const expectedLTV = '8.04%' - const expectedHealthFactor = '9.89' - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { - ETH: 10, - rETH: 10, - }, - }, - }) - - borrowPage = new BorrowPageObject(page) - actionsContainer = new ActionsPageObject(page) - await borrowPage.depositAssetsActions({ rETH: 5 }, 1000) - await page.reload() - }) - - test('calculates LTV correctly', async () => { - await borrowPage.fillBorrowAssetAction(borrow.amount) - - await borrowPage.submitAction() - - await borrowPage.expectLtv(expectedLTV) - await borrowPage.expectHealthFactor(expectedHealthFactor) - }) - - test('builds action plan', async ({ page }) => { - await borrowPage.fillBorrowAssetAction(borrow.amount) - - await borrowPage.submitAction() - - await actionsContainer.expectExtendedActions([{ type: 'borrow', asset: 'DAI', amount: '1,000.00' }]) - await screenshot(page, 'borrow-with-no-deposit-actions-plan') - }) - - test('successfully borrows', async ({ page }) => { - await borrowPage.fillBorrowAssetAction(borrow.amount) - - await borrowPage.submitAction() - - await actionsContainer.acceptAllActionsAction(1) - - await borrowPage.expectSuccessPage([], borrow, fork) - await screenshot(page, 'borrow-with-no-deposit-success') - }) - - test('HF matches after position is created', async ({ page }) => { - await borrowPage.fillBorrowAssetAction(borrow.amount) - - await borrowPage.submitAction() - await actionsContainer.acceptAllActionsAction(1) - - await expectHFOnMyPortfolio(page, borrowPage, expectedHealthFactor) - }) - }) - - test.describe('no wallet connected', () => { - let borrowPage: BorrowPageObject - const deposit = { - asset: 'rETH', - amount: 1, - } - const borrow = { - asset: 'DAI', - amount: 1000, - } - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'not-connected', - }, - }) - - borrowPage = new BorrowPageObject(page) - }) - - test('shows borrow rate correctly', async ({ page }) => { - await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) - await borrowPage.fillBorrowAssetAction(borrow.amount) - await borrowPage.expectLtv('40.19%') - await screenshot(page, 'borrow-form-not-connected-correct-ltv') - }) - - test('form is interactive', async ({ page }) => { - await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) - await borrowPage.fillBorrowAssetAction(borrow.amount) - await screenshot(page, 'borrow-form-not-connected-interactive') - }) - }) - - test.describe('form validation', () => { - let borrowPage: BorrowPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { - ETH: 10, - rETH: 10, - WBTC: 10_000, - }, - }, - }) - - borrowPage = new BorrowPageObject(page) - }) - - test('is invalid when depositing more than available', async ({ page }) => { - const deposit = { - asset: 'ETH', - amount: 100, - } - await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) - await borrowPage.expectAssetInputInvalid('Exceeds your balance') - await screenshot(page, 'borrow-form-deposit-more-than-available') - }) - - test('is invalid when borrowing more than collateral', async ({ page }) => { - const deposit = { - asset: 'ETH', - amount: 1, - } - const borrow = { - asset: 'DAI', - amount: 10_000, - } - await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) - await borrowPage.fillBorrowAssetAction(borrow.amount) - await borrowPage.expectAssetInputInvalid(borrowValidationIssueToMessage['insufficient-collateral']) - await screenshot(page, 'borrow-form-borrow-more-than-available') - }) - - test('is invalid when borrowing more than available', async ({ page }) => { - const deposit = { - asset: 'ETH', - amount: 1, - } - const borrow = { - asset: 'DAI', - amount: 100_000_000, - } - await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) - await borrowPage.fillBorrowAssetAction(borrow.amount) - await borrowPage.expectAssetInputInvalid(borrowValidationIssueToMessage['exceeds-liquidity']) - await screenshot(page, 'borrow-form-borrow-more-than-available') - }) - - test('is valid when not depositing anything but having existing position', async ({ page }) => { - await borrowPage.depositAssetsActions({ rETH: 5 }, 1000) - await page.reload() - - await borrowPage.fillBorrowAssetAction(1000) - await borrowPage.expectBorrowButtonActive() - await screenshot(page, 'borrow-form-has-position') - }) - - test('is invalid when breaching supply cap', async () => { - await borrowPage.fillDepositAssetAction(0, 'WBTC', 10_000) - await borrowPage.expectAssetInputInvalid('Deposit cap reached') - }) - }) - - test.describe('depositable assets', () => { - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { wstETH: 10 }, - }, - }) - }) - - test('deposit asset, turn off usage as collateral, try to deposit again', async ({ page }) => { - const collateral = 'wstETH' - - // Only depositing asset - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositWithoutBorrowActions({ [collateral]: 5 }) - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.goToMyPortfolioAction() - - // Turning off usage as collateral at myPortfolio - await myPortfolioPage.expectCollateralSwitch(collateral, true) - await myPortfolioPage.clickCollateralSwitchAction(collateral) - const collateralDialog = new CollateralDialogPageObject(page) - await collateralDialog.expectDialogHeader('Collateral') - await collateralDialog.expectHealthFactorNotVisible() - const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(1) - await collateralDialog.expectSetUseAsCollateralSuccessPage(collateral, 'disabled') - - // Expecting asset not listed in deposit selector after turning off usage as collateral - await borrowPage.goToEasyBorrowAction() - await borrowPage.expectAssetNotListedInDepositSelector(collateral) - }) - }) - - test.describe('Liquidation risk warning', () => { - let borrowPage: BorrowPageObject - - test.describe('In danger zone', () => { - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ETH: 1, rETH: 100 }, - }, - }) - - borrowPage = new BorrowPageObject(page) - await borrowPage.fillDepositAssetAction(0, 'rETH', 1) - await borrowPage.fillBorrowAssetAction(1500) - await borrowPage.submitAction() - }) - - test('shows risk warning', async () => { - await borrowPage.expectLiquidationRiskWarning( - 'Borrowing this amount puts you at risk of quick liquidation. You may lose part of your collateral.', - ) - }) - - test('actions stay disabled until risk warning is acknowledged', async () => { - const actionsContainer = new ActionsPageObject(borrowPage.locatePanelByHeader('Actions')) - await actionsContainer.expectDisabledActionAtIndex(0) - await borrowPage.clickAcknowledgeRisk() - await actionsContainer.expectEnabledActionAtIndex(0) - }) - }) - - test('hf above danger zone threshold; risk warning is not shown', async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ETH: 1, rETH: 100 }, - }, - }) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.fillDepositAssetAction(0, 'rETH', 1) - await borrowPage.fillBorrowAssetAction(1000) - await borrowPage.submitAction() - - await borrowPage.expectLiquidationRiskWarningNotVisible() - }) - }) -}) - -test.describe('Borrow page (usds deployed)', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let borrowPage: BorrowPageObject - let actionsContainer: ActionsPageObject - - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { - wstETH: 10, - }, - }, - }) - - borrowPage = new BorrowPageObject(page) - actionsContainer = new ActionsPageObject(page) - }) - - test('borrows usds', async ({ page }) => { - await borrowPage.fillDepositAssetAction(0, 'wstETH', 10) - await borrowPage.selectBorrowAction('USDS') - await borrowPage.fillBorrowAssetAction(10_000) - await borrowPage.submitAction() - - await borrowPage.expectUsdsBorrowAlert() - await actionsContainer.acceptAllActionsAction(5) - await borrowPage.expectSuccessPage( - [ - { - asset: 'wstETH', - amount: 10, - }, - ], - { - asset: 'USDS', - amount: 10_000, - }, - fork, - { - wstETH: 27_843.94, - USDS: 10_000, - }, - ) - - await expectHFOnMyPortfolio(page, borrowPage, '2.23') - - await page.goto(buildUrl('savings')) - const savingsPage = new SavingsPageObject(page) - await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000') - }) -}) - -async function expectHFOnMyPortfolio( - page: Page, - borrowPage: BorrowPageObject, - expectedHealthFactor: string, -): Promise { - await borrowPage.viewInMyPortfolioAction() - const myPortfolioPage = new MyPortfolioPageObject(page) - - await myPortfolioPage.expectHealthFactor(expectedHealthFactor) -} +// import { borrowValidationIssueToMessage } from '@/domain/market-validators/validateBorrow' +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { CollateralDialogPageObject } from '@/features/dialogs/collateral/CollateralDialog.PageObject' +// import { DEFAULT_BLOCK_NUMBER, USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { buildUrl, setup } from '@/test/e2e/setup' +// import { screenshot } from '@/test/e2e/utils' +// import { Page, test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { BorrowPageObject } from './Borrow.PageObject' +// import { MyPortfolioPageObject } from './MyPortfolio.PageObject' +// import { SavingsPageObject } from './Savings.PageObject' + +// test.describe('Borrow page', () => { +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) + +// test.describe('deposit ETH, borrow DAI', () => { +// let borrowPage: BorrowPageObject +// let actionsContainer: ActionsPageObject +// const deposit = { +// asset: 'ETH', +// amount: 1, +// } +// const borrow = { +// asset: 'DAI', +// amount: 1000, +// } +// const expectedLtv = '44.07%' +// const expectedHealthFactor = '1.87' + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 10, +// }, +// }, +// }) + +// borrowPage = new BorrowPageObject(page) +// actionsContainer = new ActionsPageObject(page) +// }) + +// test('calculates LTV correctly', async () => { +// await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) +// await borrowPage.fillBorrowAssetAction(borrow.amount) + +// await borrowPage.submitAction() + +// await borrowPage.expectLtv(expectedLtv) +// await borrowPage.expectHealthFactor(expectedHealthFactor) +// }) + +// test('builds action plan', async ({ page }) => { +// await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) +// await borrowPage.fillBorrowAssetAction(borrow.amount) + +// await borrowPage.submitAction() + +// await actionsContainer.expectExtendedActions([ +// { type: 'deposit', asset: 'ETH', amount: '1.00' }, +// { type: 'borrow', asset: 'DAI', amount: '1,000.00' }, +// ]) +// await screenshot(page, 'deposit-eth-actions-plan') +// }) + +// test('successfully builds position', async ({ page }) => { +// await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) +// await borrowPage.fillBorrowAssetAction(borrow.amount) + +// await borrowPage.submitAction() + +// await actionsContainer.acceptAllActionsAction(2) + +// await borrowPage.expectSuccessPage([deposit], borrow, fork) +// await screenshot(page, 'deposit-eth-success') +// }) + +// test('HF matches after position is created', async ({ page }) => { +// await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) +// await borrowPage.fillBorrowAssetAction(borrow.amount) + +// await borrowPage.submitAction() +// await actionsContainer.acceptAllActionsAction(2) + +// await expectHFOnMyPortfolio(page, borrowPage, expectedHealthFactor) +// }) +// }) + +// test.describe('deposit wstETH and rETH, borrow DAI', () => { +// let borrowPage: BorrowPageObject +// let actionsContainer: ActionsPageObject +// const wstETHdeposit = { +// asset: 'wstETH', +// amount: 1, +// } +// const rETHdeposit = { +// asset: 'rETH', +// amount: 1, +// } +// const borrow = { +// asset: 'DAI', +// amount: 1000, +// } +// const expectedLTV = '19.57%' +// const expectedHealthFactor = '4.06' + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { +// wstETH: 10, +// rETH: 10, +// }, +// }, +// }) + +// borrowPage = new BorrowPageObject(page) +// actionsContainer = new ActionsPageObject(page) +// }) + +// test('calculates LTV correctly', async () => { +// await borrowPage.addNewDepositAssetAction() +// await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) +// await borrowPage.fillDepositAssetAction(1, rETHdeposit.asset, rETHdeposit.amount) +// await borrowPage.fillBorrowAssetAction(borrow.amount) + +// await borrowPage.submitAction() + +// await borrowPage.expectLtv(expectedLTV) +// await borrowPage.expectHealthFactor(expectedHealthFactor) +// }) + +// test('uses permits in action plan for assets with permit support', async ({ page }) => { +// await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) +// await borrowPage.fillBorrowAssetAction(borrow.amount) + +// await borrowPage.submitAction() + +// await actionsContainer.expectExtendedActions([ +// { type: 'permit', asset: 'wstETH', amount: '1.00' }, +// { type: 'deposit', asset: 'wstETH', amount: '1.00' }, +// { type: 'borrow', asset: 'DAI', amount: '1,000.00' }, +// ]) +// await screenshot(page, 'deposit-wsteth-permit-actions-plan') +// }) + +// test('uses approve in action plan for assets with no permit support', async ({ page }) => { +// await borrowPage.fillDepositAssetAction(0, rETHdeposit.asset, rETHdeposit.amount) +// await borrowPage.fillBorrowAssetAction(borrow.amount) + +// await borrowPage.submitAction() + +// await actionsContainer.expectExtendedActions([ +// { type: 'approve', asset: 'rETH', amount: '1.00' }, +// { type: 'deposit', asset: 'rETH', amount: '1.00' }, +// { type: 'borrow', asset: 'DAI', amount: '1,000.00' }, +// ]) +// await screenshot(page, 'deposit-reth-approve-actions-plan') +// }) + +// test('can switch to approves in action plan', async ({ page }) => { +// await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) +// await borrowPage.fillBorrowAssetAction(borrow.amount) + +// await borrowPage.submitAction() + +// await actionsContainer.switchPreferPermitsAction() +// await actionsContainer.expectExtendedActions([ +// { type: 'approve', asset: 'wstETH', amount: '1.00' }, +// { type: 'deposit', asset: 'wstETH', amount: '1.00' }, +// { type: 'borrow', asset: 'DAI', amount: '1,000.00' }, +// ]) +// await screenshot(page, 'deposit-wsteth-approve-actions-plan') +// }) + +// test('builds action plan for 2 assets', async ({ page }) => { +// await borrowPage.addNewDepositAssetAction() +// await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) +// await borrowPage.fillDepositAssetAction(1, rETHdeposit.asset, rETHdeposit.amount) +// await borrowPage.fillBorrowAssetAction(borrow.amount) + +// await borrowPage.submitAction() + +// await actionsContainer.expectExtendedActions([ +// { type: 'permit', asset: 'wstETH', amount: '1.00' }, +// { type: 'deposit', asset: 'wstETH', amount: '1.00' }, +// { type: 'approve', asset: 'rETH', amount: '1.00' }, +// { type: 'deposit', asset: 'rETH', amount: '1.00' }, +// { type: 'borrow', asset: 'DAI', amount: '1,000.00' }, +// ]) +// await screenshot(page, 'deposit-wsteth-reth-actions-plan') +// }) + +// test('successfully builds position', async ({ page }) => { +// await borrowPage.addNewDepositAssetAction() +// await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) +// await borrowPage.fillDepositAssetAction(1, rETHdeposit.asset, rETHdeposit.amount) +// await borrowPage.fillBorrowAssetAction(borrow.amount) + +// await borrowPage.submitAction() + +// await actionsContainer.acceptAllActionsAction(5) + +// await borrowPage.expectSuccessPage([wstETHdeposit, rETHdeposit], borrow, fork) +// await screenshot(page, 'deposit-wsteth-reth-success') +// }) + +// test('successfully builds position using only approves', async ({ page }) => { +// await borrowPage.addNewDepositAssetAction() +// await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) +// await borrowPage.fillDepositAssetAction(1, rETHdeposit.asset, rETHdeposit.amount) +// await borrowPage.fillBorrowAssetAction(borrow.amount) + +// await borrowPage.submitAction() + +// await actionsContainer.switchPreferPermitsAction() +// await actionsContainer.acceptAllActionsAction(5) + +// await borrowPage.expectSuccessPage([wstETHdeposit, rETHdeposit], borrow, fork) +// await screenshot(page, 'deposit-wsteth-reth-success') +// }) + +// test('HF matches after position is created', async ({ page }) => { +// await borrowPage.addNewDepositAssetAction() +// await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) +// await borrowPage.fillDepositAssetAction(1, rETHdeposit.asset, rETHdeposit.amount) +// await borrowPage.fillBorrowAssetAction(borrow.amount) + +// await borrowPage.submitAction() +// await actionsContainer.acceptAllActionsAction(5) + +// await expectHFOnMyPortfolio(page, borrowPage, expectedHealthFactor) +// }) +// }) + +// test.describe('no new deposit, existing position, borrow DAI', () => { +// let borrowPage: BorrowPageObject +// let actionsContainer: ActionsPageObject + +// const borrow = { +// asset: 'DAI', +// amount: 1000, +// } +// const expectedLTV = '8.04%' +// const expectedHealthFactor = '9.89' + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 10, +// rETH: 10, +// }, +// }, +// }) + +// borrowPage = new BorrowPageObject(page) +// actionsContainer = new ActionsPageObject(page) +// await borrowPage.depositAssetsActions({ rETH: 5 }, 1000) +// await page.reload() +// }) + +// test('calculates LTV correctly', async () => { +// await borrowPage.fillBorrowAssetAction(borrow.amount) + +// await borrowPage.submitAction() + +// await borrowPage.expectLtv(expectedLTV) +// await borrowPage.expectHealthFactor(expectedHealthFactor) +// }) + +// test('builds action plan', async ({ page }) => { +// await borrowPage.fillBorrowAssetAction(borrow.amount) + +// await borrowPage.submitAction() + +// await actionsContainer.expectExtendedActions([{ type: 'borrow', asset: 'DAI', amount: '1,000.00' }]) +// await screenshot(page, 'borrow-with-no-deposit-actions-plan') +// }) + +// test('successfully borrows', async ({ page }) => { +// await borrowPage.fillBorrowAssetAction(borrow.amount) + +// await borrowPage.submitAction() + +// await actionsContainer.acceptAllActionsAction(1) + +// await borrowPage.expectSuccessPage([], borrow, fork) +// await screenshot(page, 'borrow-with-no-deposit-success') +// }) + +// test('HF matches after position is created', async ({ page }) => { +// await borrowPage.fillBorrowAssetAction(borrow.amount) + +// await borrowPage.submitAction() +// await actionsContainer.acceptAllActionsAction(1) + +// await expectHFOnMyPortfolio(page, borrowPage, expectedHealthFactor) +// }) +// }) + +// test.describe('no wallet connected', () => { +// let borrowPage: BorrowPageObject +// const deposit = { +// asset: 'rETH', +// amount: 1, +// } +// const borrow = { +// asset: 'DAI', +// amount: 1000, +// } + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'not-connected', +// }, +// }) + +// borrowPage = new BorrowPageObject(page) +// }) + +// test('shows borrow rate correctly', async ({ page }) => { +// await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) +// await borrowPage.fillBorrowAssetAction(borrow.amount) +// await borrowPage.expectLtv('40.19%') +// await screenshot(page, 'borrow-form-not-connected-correct-ltv') +// }) + +// test('form is interactive', async ({ page }) => { +// await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) +// await borrowPage.fillBorrowAssetAction(borrow.amount) +// await screenshot(page, 'borrow-form-not-connected-interactive') +// }) +// }) + +// test.describe('form validation', () => { +// let borrowPage: BorrowPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { +// ETH: 10, +// rETH: 10, +// WBTC: 10_000, +// }, +// }, +// }) + +// borrowPage = new BorrowPageObject(page) +// }) + +// test('is invalid when depositing more than available', async ({ page }) => { +// const deposit = { +// asset: 'ETH', +// amount: 100, +// } +// await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) +// await borrowPage.expectAssetInputInvalid('Exceeds your balance') +// await screenshot(page, 'borrow-form-deposit-more-than-available') +// }) + +// test('is invalid when borrowing more than collateral', async ({ page }) => { +// const deposit = { +// asset: 'ETH', +// amount: 1, +// } +// const borrow = { +// asset: 'DAI', +// amount: 10_000, +// } +// await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) +// await borrowPage.fillBorrowAssetAction(borrow.amount) +// await borrowPage.expectAssetInputInvalid(borrowValidationIssueToMessage['insufficient-collateral']) +// await screenshot(page, 'borrow-form-borrow-more-than-available') +// }) + +// test('is invalid when borrowing more than available', async ({ page }) => { +// const deposit = { +// asset: 'ETH', +// amount: 1, +// } +// const borrow = { +// asset: 'DAI', +// amount: 100_000_000, +// } +// await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) +// await borrowPage.fillBorrowAssetAction(borrow.amount) +// await borrowPage.expectAssetInputInvalid(borrowValidationIssueToMessage['exceeds-liquidity']) +// await screenshot(page, 'borrow-form-borrow-more-than-available') +// }) + +// test('is valid when not depositing anything but having existing position', async ({ page }) => { +// await borrowPage.depositAssetsActions({ rETH: 5 }, 1000) +// await page.reload() + +// await borrowPage.fillBorrowAssetAction(1000) +// await borrowPage.expectBorrowButtonActive() +// await screenshot(page, 'borrow-form-has-position') +// }) + +// test('is invalid when breaching supply cap', async () => { +// await borrowPage.fillDepositAssetAction(0, 'WBTC', 10_000) +// await borrowPage.expectAssetInputInvalid('Deposit cap reached') +// }) +// }) + +// test.describe('depositable assets', () => { +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { wstETH: 10 }, +// }, +// }) +// }) + +// test('deposit asset, turn off usage as collateral, try to deposit again', async ({ page }) => { +// const collateral = 'wstETH' + +// // Only depositing asset +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositWithoutBorrowActions({ [collateral]: 5 }) +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.goToMyPortfolioAction() + +// // Turning off usage as collateral at myPortfolio +// await myPortfolioPage.expectCollateralSwitch(collateral, true) +// await myPortfolioPage.clickCollateralSwitchAction(collateral) +// const collateralDialog = new CollateralDialogPageObject(page) +// await collateralDialog.expectDialogHeader('Collateral') +// await collateralDialog.expectHealthFactorNotVisible() +// const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(1) +// await collateralDialog.expectSetUseAsCollateralSuccessPage(collateral, 'disabled') + +// // Expecting asset not listed in deposit selector after turning off usage as collateral +// await borrowPage.goToEasyBorrowAction() +// await borrowPage.expectAssetNotListedInDepositSelector(collateral) +// }) +// }) + +// test.describe('Liquidation risk warning', () => { +// let borrowPage: BorrowPageObject + +// test.describe('In danger zone', () => { +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ETH: 1, rETH: 100 }, +// }, +// }) + +// borrowPage = new BorrowPageObject(page) +// await borrowPage.fillDepositAssetAction(0, 'rETH', 1) +// await borrowPage.fillBorrowAssetAction(1500) +// await borrowPage.submitAction() +// }) + +// test('shows risk warning', async () => { +// await borrowPage.expectLiquidationRiskWarning( +// 'Borrowing this amount puts you at risk of quick liquidation. You may lose part of your collateral.', +// ) +// }) + +// test('actions stay disabled until risk warning is acknowledged', async () => { +// const actionsContainer = new ActionsPageObject(borrowPage.locatePanelByHeader('Actions')) +// await actionsContainer.expectDisabledActionAtIndex(0) +// await borrowPage.clickAcknowledgeRisk() +// await actionsContainer.expectEnabledActionAtIndex(0) +// }) +// }) + +// test('hf above danger zone threshold; risk warning is not shown', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ETH: 1, rETH: 100 }, +// }, +// }) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.fillDepositAssetAction(0, 'rETH', 1) +// await borrowPage.fillBorrowAssetAction(1000) +// await borrowPage.submitAction() + +// await borrowPage.expectLiquidationRiskWarningNotVisible() +// }) +// }) +// }) + +// test.describe('Borrow page (usds deployed)', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let borrowPage: BorrowPageObject +// let actionsContainer: ActionsPageObject + +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { +// wstETH: 10, +// }, +// }, +// }) + +// borrowPage = new BorrowPageObject(page) +// actionsContainer = new ActionsPageObject(page) +// }) + +// test('borrows usds', async ({ page }) => { +// await borrowPage.fillDepositAssetAction(0, 'wstETH', 10) +// await borrowPage.selectBorrowAction('USDS') +// await borrowPage.fillBorrowAssetAction(10_000) +// await borrowPage.submitAction() + +// await borrowPage.expectUsdsBorrowAlert() +// await actionsContainer.acceptAllActionsAction(5) +// await borrowPage.expectSuccessPage( +// [ +// { +// asset: 'wstETH', +// amount: 10, +// }, +// ], +// { +// asset: 'USDS', +// amount: 10_000, +// }, +// fork, +// { +// wstETH: 27_843.94, +// USDS: 10_000, +// }, +// ) + +// await expectHFOnMyPortfolio(page, borrowPage, '2.23') + +// await page.goto(buildUrl('savings')) +// const savingsPage = new SavingsPageObject(page) +// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000') +// }) +// }) + +// async function expectHFOnMyPortfolio( +// page: Page, +// borrowPage: BorrowPageObject, +// expectedHealthFactor: string, +// ): Promise { +// await borrowPage.viewInMyPortfolioAction() +// const myPortfolioPage = new MyPortfolioPageObject(page) + +// await myPortfolioPage.expectHealthFactor(expectedHealthFactor) +// } diff --git a/packages/app/src/pages/Farms.test-e2e.ts b/packages/app/src/pages/Farms.test-e2e.ts index 4dfe19bbc..23b98c873 100644 --- a/packages/app/src/pages/Farms.test-e2e.ts +++ b/packages/app/src/pages/Farms.test-e2e.ts @@ -1,33 +1,33 @@ -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { FarmsPageObject } from './Farms.PageObject' +// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { FarmsPageObject } from './Farms.PageObject' -test.describe('Farms', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - let farmsPage: FarmsPageObject +// test.describe('Farms', () => { +// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// let farmsPage: FarmsPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'farms', - account: { - type: 'not-connected', - }, - }) - await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'farms', +// account: { +// type: 'not-connected', +// }, +// }) +// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) - farmsPage = new FarmsPageObject(page) - }) +// farmsPage = new FarmsPageObject(page) +// }) - test('farms list', async () => { - await farmsPage.expectInactiveFarms([ - { apy: '8.51%', staked: '0', rewardText: 'Earn SKY', stakeText: 'Deposit Stablecoins' }, - { staked: '0', rewardText: 'Earn Chronicle points', stakeText: 'Deposit Stablecoins' }, - ]) +// test('farms list', async () => { +// await farmsPage.expectInactiveFarms([ +// { apy: '8.51%', staked: '0', rewardText: 'Earn SKY', stakeText: 'Deposit Stablecoins' }, +// { staked: '0', rewardText: 'Earn Chronicle points', stakeText: 'Deposit Stablecoins' }, +// ]) - await farmsPage.expectActiveFarmsListToBeEmpty() - }) -}) +// await farmsPage.expectActiveFarmsListToBeEmpty() +// }) +// }) diff --git a/packages/app/src/pages/MarketDetails.test-e2e.ts b/packages/app/src/pages/MarketDetails.test-e2e.ts index b356b6037..183f1f0f8 100644 --- a/packages/app/src/pages/MarketDetails.test-e2e.ts +++ b/packages/app/src/pages/MarketDetails.test-e2e.ts @@ -1,589 +1,589 @@ -import { test } from '@playwright/test' -import { gnosis, mainnet } from 'viem/chains' - -import { DialogPageObject } from '@/features/dialogs/common/Dialog.PageObject' -import { CAP_AUTOMATOR_BLOCK_NUMBER, GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { buildUrl, setup } from '@/test/e2e/setup' -import { screenshot } from '@/test/e2e/utils' - -import { BorrowPageObject } from './Borrow.PageObject' -import { MarketDetailsPageObject } from './MarketDetails.PageObject' - -test.describe('Market details Mainnet', () => { - const DAI = '0x6B175474E89094C44Da98b954EedeAC495271d0F' - const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' - const WEETH = '0xcd5fe23c85820f7b72d0926fc9b05b43e359b7ee' - const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' - const WBTC = '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599' - - const fork = setupFork({ - blockNumber: CAP_AUTOMATOR_BLOCK_NUMBER, - chainId: mainnet.id, - simulationDateOverride: new Date('2024-09-04T14:21:19Z'), - }) - - test.describe('Market overview', () => { - test('DAI', async ({ page }) => { - await setup(page, fork, { - initialPage: 'marketDetails', - initialPageParams: { asset: DAI, chainId: fork.chainId.toString() }, - account: { - type: 'not-connected', - }, - }) - - const marketDetailsPage = new MarketDetailsPageObject(page) - await marketDetailsPage.expectMarketOverviewValue('Borrowed', '$910.8M') - await marketDetailsPage.expectMarketOverviewValue('Instantly available', '$44.01M') - await marketDetailsPage.expectMarketOverviewValue('Sky capacity', '$1.586B') - - await screenshot(page, 'market-details-dai') - }) - - test('WETH', async ({ page }) => { - await setup(page, fork, { - initialPage: 'marketDetails', - initialPageParams: { asset: WETH, chainId: fork.chainId.toString() }, - account: { - type: 'not-connected', - }, - }) - - const marketDetailsPage = new MarketDetailsPageObject(page) - await marketDetailsPage.expectMarketOverviewValue('Borrowed', '$571.1M') - await marketDetailsPage.expectMarketOverviewValue('Instantly available', '$125.4M') - - await screenshot(page, 'market-details-weth') - }) - - test.describe('token that cannot be borrowed', () => { - test('overview is visible when borrowed balance greater than non-zero', async ({ page }) => { - await setup(page, fork, { - initialPage: 'marketDetails', - initialPageParams: { asset: WBTC, chainId: fork.chainId.toString() }, - account: { - type: 'not-connected', - }, - }) - - const marketDetailsPage = new MarketDetailsPageObject(page) - await marketDetailsPage.expectToBeLoaded() - }) - - test('overview is hidden when borrowed balance equal zero', async ({ page }) => { - await setup(page, fork, { - initialPage: 'marketDetails', - initialPageParams: { asset: WEETH, chainId: fork.chainId.toString() }, - account: { - type: 'not-connected', - }, - }) - - const marketDetailsPage = new MarketDetailsPageObject(page) - await marketDetailsPage.expectMarketOverviewToBeHidden() - }) - }) - }) - - test.describe('Dialogs', () => { - const initialDeposits = { - wstETH: 10, - } - - test('guest state', async ({ page }) => { - await setup(page, fork, { - initialPage: 'marketDetails', - initialPageParams: { asset: DAI, chainId: fork.chainId.toString() }, - account: { - type: 'not-connected', - }, - }) - - const marketDetailsPage = new MarketDetailsPageObject(page) - - await marketDetailsPage.expectToBeLoaded() - - await marketDetailsPage.expectConnectWalletButton() - await marketDetailsPage.expectDialogButtonToBeInvisible('Lend') - await marketDetailsPage.expectDialogButtonToBeInvisible('Deposit') - await marketDetailsPage.expectDialogButtonToBeInvisible('Borrow') - }) - - test("can't deposit if not enough balance", async ({ page }) => { - await setup(page, fork, { - initialPage: 'marketDetails', - initialPageParams: { asset: WETH, chainId: fork.chainId.toString() }, - account: { - type: 'connected-random', - }, - }) - - const marketDetailsPage = new MarketDetailsPageObject(page) - - await marketDetailsPage.expectToBeLoaded() - - await marketDetailsPage.expectDialogButtonToBeInactive('Deposit') - }) - - test("can't lend if not enough balance", async ({ page }) => { - await setup(page, fork, { - initialPage: 'marketDetails', - initialPageParams: { asset: DAI, chainId: fork.chainId.toString() }, - account: { - type: 'connected-random', - }, - }) - - const marketDetailsPage = new MarketDetailsPageObject(page) - - await marketDetailsPage.expectToBeLoaded() - - await marketDetailsPage.expectDialogButtonToBeInactive('Lend') - }) - - test("can't borrow if not enough balance", async ({ page }) => { - await setup(page, fork, { - initialPage: 'marketDetails', - initialPageParams: { asset: DAI, chainId: fork.chainId.toString() }, - account: { - type: 'connected-random', - }, - }) - - const marketDetailsPage = new MarketDetailsPageObject(page) - - await marketDetailsPage.expectToBeLoaded() - - await marketDetailsPage.expectBorrowNotAvailableDisclaimer() - await marketDetailsPage.expectDialogButtonToBeInvisible('Borrow') - }) - - test('opens dialogs for DAI', async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { - ...initialDeposits, - DAI: 1000, - sDAI: 1000, - }, - }, - }) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositWithoutBorrowActions({ ...initialDeposits }) - - await page.goto(buildUrl('marketDetails', { asset: DAI, chainId: fork.chainId.toString() })) - - const marketDetailsPage = new MarketDetailsPageObject(page) - - await marketDetailsPage.openDialogAction('Lend') - const lendDialog = new DialogPageObject(page, /Deposit/i) - await lendDialog.expectDialogHeader('Deposit DAI') - await lendDialog.closeDialog() - - await marketDetailsPage.openDialogAction('Deposit') - const depositDialog = new DialogPageObject(page, /Deposit/i) - await depositDialog.expectDialogHeader('Deposit sDAI') - await depositDialog.closeDialog() - - await marketDetailsPage.openDialogAction('Borrow') - const borrowDialog = new DialogPageObject(page, /Borrow/i) - await borrowDialog.expectDialogHeader('Borrow DAI') - await borrowDialog.closeDialog() - }) - - test('opens dialogs for WETH', async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { - ...initialDeposits, - WETH: 10, - }, - }, - }) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositWithoutBorrowActions({ ...initialDeposits }) - - await page.goto(buildUrl('marketDetails', { asset: WETH, chainId: fork.chainId.toString() })) - - const marketDetailsPage = new MarketDetailsPageObject(page) - - await marketDetailsPage.openDialogAction('Deposit') - const lendDialog = new DialogPageObject(page, /Deposit/i) - await lendDialog.expectDialogHeader('Deposit WETH') - await lendDialog.closeDialog() - - await marketDetailsPage.openDialogAction('Borrow') - const borrowDialog = new DialogPageObject(page, /Borrow/i) - await borrowDialog.expectDialogHeader('Borrow WETH') - await borrowDialog.closeDialog() - }) - - // @todo: this scenario is inaccurate, because user has only ETH - in future dialog should open on ETH tab - test('opens dialogs for WETH when having only ETH', async ({ page }) => { - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { - ...initialDeposits, - ETH: 5, - }, - }, - }) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositWithoutBorrowActions({ ...initialDeposits }) - - await page.goto(buildUrl('marketDetails', { asset: WETH, chainId: fork.chainId.toString() })) - - const marketDetailsPage = new MarketDetailsPageObject(page) - - await marketDetailsPage.expectWalletBalance('5.00 WETH') - - await marketDetailsPage.openDialogAction('Deposit') - const lendDialog = new DialogPageObject(page, /Deposit/i) - await lendDialog.expectDialogHeader('Deposit WETH') - await lendDialog.closeDialog() - - await marketDetailsPage.openDialogAction('Borrow') - const borrowDialog = new DialogPageObject(page, /Borrow/i) - await borrowDialog.expectDialogHeader('Borrow WETH') - await borrowDialog.closeDialog() - }) - - test('wallet displays sum of WETH and ETH', async ({ page }) => { - await setup(page, fork, { - initialPage: 'marketDetails', - initialPageParams: { - asset: WETH, - chainId: fork.chainId.toString(), - }, - account: { - type: 'connected-random', - assetBalances: { - ...initialDeposits, - ETH: 5, - WETH: 10, - }, - }, - }) - - const marketDetailsPage = new MarketDetailsPageObject(page) - - await marketDetailsPage.expectWalletBalance('15.00 WETH') - }) - }) - - test.describe('Isolated assets', () => { - const BLOCK_NUMBER_WITH_WEETH = 20118125n - const fork = setupFork({ blockNumber: BLOCK_NUMBER_WITH_WEETH, chainId: mainnet.id }) - - test('Correctly displays debt ceiling', async ({ page }) => { - await setup(page, fork, { - initialPage: 'marketDetails', - initialPageParams: { asset: WEETH, chainId: fork.chainId.toString() }, - account: { - type: 'not-connected', - }, - }) - - const marketDetailsPage = new MarketDetailsPageObject(page) - await marketDetailsPage.expectDebt('$3.17M') - await marketDetailsPage.expectDebtCeiling('$50M') - }) - }) - - test.describe('Errors', () => { - const NOT_A_RESERVE = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266' - - test('displays 404 page for unknown chain', async ({ page }) => { - await setup(page, fork, { - initialPage: 'marketDetails', - initialPageParams: { asset: DAI, chainId: '12345' }, - account: { - type: 'not-connected', - }, - }) - - const marketDetailsPage = new MarketDetailsPageObject(page) - await marketDetailsPage.expect404() - }) - - test('displays 404 page for unknown asset', async ({ page }) => { - await setup(page, fork, { - initialPage: 'marketDetails', - initialPageParams: { asset: NOT_A_RESERVE, chainId: fork.chainId.toString() }, - account: { - type: 'not-connected', - }, - }) - - const marketDetailsPage = new MarketDetailsPageObject(page) - await marketDetailsPage.expect404() - }) - }) - - test.describe('Cap automator', () => { - test('WETH', async ({ page }) => { - await setup(page, fork, { - initialPage: 'marketDetails', - initialPageParams: { asset: WETH, chainId: fork.chainId.toString() }, - account: { - type: 'not-connected', - }, - }) - - const marketDetailsPage = new MarketDetailsPageObject(page) - - await marketDetailsPage.expectSupplyCap('403.2K WETH') - await marketDetailsPage.expectSupplyMaxCap('2M WETH') - await marketDetailsPage.expectSupplyCapCooldown('0h 00m 00s') - - await marketDetailsPage.expectBorrowCap('256K WETH') - await marketDetailsPage.expectBorrowMaxCap('1M WETH') - await marketDetailsPage.expectBorrowCapCooldown('0h 00m 00s') - }) - - test('USDC', async ({ page }) => { - await setup(page, fork, { - initialPage: 'marketDetails', - initialPageParams: { asset: USDC, chainId: fork.chainId.toString() }, - account: { - type: 'not-connected', - }, - }) - - const marketDetailsPage = new MarketDetailsPageObject(page) - - await marketDetailsPage.expectSupplyPanelNotVisible() - - await marketDetailsPage.expectBorrowCap('7.678M USDC') - await marketDetailsPage.expectBorrowMaxCap('57M USDC') - await marketDetailsPage.expectBorrowCapCooldown('0h 00m 00s') - }) - - test('WBTC', async ({ page }) => { - await setup(page, fork, { - initialPage: 'marketDetails', - initialPageParams: { asset: WBTC, chainId: fork.chainId.toString() }, - account: { - type: 'not-connected', - }, - }) - - const marketDetailsPage = new MarketDetailsPageObject(page) - - await marketDetailsPage.expectSupplyCap('4,780 WBTC') - await marketDetailsPage.expectSupplyMaxCap('10K WBTC') - await marketDetailsPage.expectSupplyCapCooldown('0h 00m 00s') - - await marketDetailsPage.expectBorrowPanelNotVisible() - await marketDetailsPage.expectToBeDisabledAsCollateral() - await marketDetailsPage.expectDisabledCollateralInfoVisible() - }) - }) - - test.describe('Oracles', () => { - test('Fixed price', async ({ page }) => { - await setup(page, fork, { - initialPage: 'marketDetails', - initialPageParams: { asset: DAI, chainId: fork.chainId.toString() }, - account: { - type: 'not-connected', - }, - }) - - const marketDetailsPage = new MarketDetailsPageObject(page) - - await marketDetailsPage.expectOraclePanelToHaveTitle('Fixed Price') - - await marketDetailsPage.expectOracleInfo({ - price: '$1.00', - asset: 'DAI', - oracleContract: '0x42a03F81dd8A1cEcD746dc262e4d1CD9fD39F777', - }) - }) - test('Market price - not redundant', async ({ page }) => { - await setup(page, fork, { - initialPage: 'marketDetails', - initialPageParams: { asset: WBTC, chainId: fork.chainId.toString() }, - account: { - type: 'not-connected', - }, - }) - - const marketDetailsPage = new MarketDetailsPageObject(page) - - await marketDetailsPage.expectOraclePanelToHaveTitle('Market Price') - await marketDetailsPage.expectOracleToBeNotRedundant() - - await marketDetailsPage.expectOracleInfo({ - price: '$58,229.82', - asset: 'WBTC', - oracleContract: '0x230E0321Cf38F09e247e50Afc7801EA2351fe56F', - }) - }) - - test('Yielding fixed price - redundant', async ({ page }) => { - await setup(page, fork, { - initialPage: 'marketDetails', - initialPageParams: { asset: WEETH, chainId: fork.chainId.toString() }, - account: { - type: 'not-connected', - }, - }) - - const marketDetailsPage = new MarketDetailsPageObject(page) - - await marketDetailsPage.expectOraclePanelToHaveTitle('Yielding Fixed Price') - await marketDetailsPage.expectOracleToBeRedundant() - - await marketDetailsPage.expectOracleInfo({ - price: '$2,576.50', - asset: 'weETH', - oracleContract: '0x1A6BDB22b9d7a454D20EAf12DB55D6B5F058183D', - }) - await marketDetailsPage.expectYieldingFixedOracleBaseAssetInfo({ - asset: 'WETH', - price: '$2,460.69', - oracleContract: '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419', - }) - await marketDetailsPage.expectYieldingFixedOracleRatioInfo({ - ratio: '1.0471', - ratioContract: '0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee', - }) - }) - }) -}) - -test.describe('Market details Gnosis', () => { - const XDAI = '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d' - const EURe = '0xcB444e90D8198415266c6a2724b7900fb12FC56E' - const WETH = '0x6A023CCd1ff6F2045C3309768eAd9E68F978f6e1' - const sDAI = '0xaf204776c7245bF4147c2612BF6e5972Ee483701' - - const fork = setupFork({ - blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, - chainId: gnosis.id, - useTenderlyVnet: true, - }) - - test.describe('Cap automator', () => { - test('WETH', async ({ page }) => { - await setup(page, fork, { - initialPage: 'marketDetails', - initialPageParams: { asset: WETH, chainId: fork.chainId.toString() }, - account: { - type: 'not-connected', - }, - }) - - const marketDetailsPage = new MarketDetailsPageObject(page) - - await marketDetailsPage.expectSupplyCap('5,000 WETH') - await marketDetailsPage.expectSupplyMaxCapNotVisible() - - await marketDetailsPage.expectBorrowCap('3,000 WETH') - await marketDetailsPage.expectBorrowMaxCapNotVisible() - }) - - test('XDAI', async ({ page }) => { - await setup(page, fork, { - initialPage: 'marketDetails', - initialPageParams: { asset: XDAI, chainId: fork.chainId.toString() }, - account: { - type: 'not-connected', - }, - }) - - const marketDetailsPage = new MarketDetailsPageObject(page) - - await marketDetailsPage.expectSupplyCap('20M WXDAI') - await marketDetailsPage.expectSupplyMaxCapNotVisible() - - await marketDetailsPage.expectBorrowCap('16M WXDAI') - await marketDetailsPage.expectBorrowMaxCapNotVisible() - - await marketDetailsPage.expectCollateralPanelNotVisible() - }) - }) - - test.describe('Oracles', () => { - test('Fixed price', async ({ page }) => { - await setup(page, fork, { - initialPage: 'marketDetails', - initialPageParams: { asset: XDAI, chainId: fork.chainId.toString() }, - account: { - type: 'not-connected', - }, - }) - - const marketDetailsPage = new MarketDetailsPageObject(page) - - await marketDetailsPage.expectOraclePanelToHaveTitle('Fixed Price') - - await marketDetailsPage.expectOracleInfo({ - price: '$1.00', - asset: 'WXDAI', - oracleContract: '0x6FC2871B6d9A94866B7260896257Fd5b50c09900', - }) - }) - - test('Underlying asset price', async ({ page }) => { - await setup(page, fork, { - initialPage: 'marketDetails', - initialPageParams: { asset: EURe, chainId: fork.chainId.toString() }, - account: { - type: 'not-connected', - }, - }) - - const marketDetailsPage = new MarketDetailsPageObject(page) - - await marketDetailsPage.expectOraclePanelToHaveTitle('Underlying Asset Price') - - await marketDetailsPage.expectOracleInfo({ - price: '$1.07', - asset: 'EUR', - oracleContract: '0xab70BCB260073d036d1660201e9d5405F5829b7a', - }) - }) - - test('Yielding fixed price - not redundant', async ({ page }) => { - await setup(page, fork, { - initialPage: 'marketDetails', - initialPageParams: { asset: sDAI, chainId: fork.chainId.toString() }, - account: { - type: 'not-connected', - }, - }) - - const marketDetailsPage = new MarketDetailsPageObject(page) - - await marketDetailsPage.expectOraclePanelToHaveTitle('Yielding Fixed Price') - await marketDetailsPage.expectOracleToBeNotRedundant() - - await marketDetailsPage.expectOracleInfo({ - price: '$1.0875', - asset: 'sDAI', - oracleContract: '0x1D0f881Ce1a646E2f27Dec3c57Fa056cB838BCC2', - }) - await marketDetailsPage.expectYieldingFixedOracleBaseAssetInfo({ - asset: 'DAI', - price: '$0.9997', - oracleContract: '0x678df3415fc31947dA4324eC63212874be5a82f8', - }) - await marketDetailsPage.expectYieldingFixedOracleRatioInfo({ - ratio: '1.0878', - ratioContract: '0xaf204776c7245bF4147c2612BF6e5972Ee483701', - }) - }) - }) -}) +// import { test } from '@playwright/test' +// import { gnosis, mainnet } from 'viem/chains' + +// import { DialogPageObject } from '@/features/dialogs/common/Dialog.PageObject' +// import { CAP_AUTOMATOR_BLOCK_NUMBER, GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { buildUrl, setup } from '@/test/e2e/setup' +// import { screenshot } from '@/test/e2e/utils' + +// import { BorrowPageObject } from './Borrow.PageObject' +// import { MarketDetailsPageObject } from './MarketDetails.PageObject' + +// test.describe('Market details Mainnet', () => { +// const DAI = '0x6B175474E89094C44Da98b954EedeAC495271d0F' +// const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' +// const WEETH = '0xcd5fe23c85820f7b72d0926fc9b05b43e359b7ee' +// const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' +// const WBTC = '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599' + +// const fork = setupFork({ +// blockNumber: CAP_AUTOMATOR_BLOCK_NUMBER, +// chainId: mainnet.id, +// simulationDateOverride: new Date('2024-09-04T14:21:19Z'), +// }) + +// test.describe('Market overview', () => { +// test('DAI', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'marketDetails', +// initialPageParams: { asset: DAI, chainId: fork.chainId.toString() }, +// account: { +// type: 'not-connected', +// }, +// }) + +// const marketDetailsPage = new MarketDetailsPageObject(page) +// await marketDetailsPage.expectMarketOverviewValue('Borrowed', '$910.8M') +// await marketDetailsPage.expectMarketOverviewValue('Instantly available', '$44.01M') +// await marketDetailsPage.expectMarketOverviewValue('Sky capacity', '$1.586B') + +// await screenshot(page, 'market-details-dai') +// }) + +// test('WETH', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'marketDetails', +// initialPageParams: { asset: WETH, chainId: fork.chainId.toString() }, +// account: { +// type: 'not-connected', +// }, +// }) + +// const marketDetailsPage = new MarketDetailsPageObject(page) +// await marketDetailsPage.expectMarketOverviewValue('Borrowed', '$571.1M') +// await marketDetailsPage.expectMarketOverviewValue('Instantly available', '$125.4M') + +// await screenshot(page, 'market-details-weth') +// }) + +// test.describe('token that cannot be borrowed', () => { +// test('overview is visible when borrowed balance greater than non-zero', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'marketDetails', +// initialPageParams: { asset: WBTC, chainId: fork.chainId.toString() }, +// account: { +// type: 'not-connected', +// }, +// }) + +// const marketDetailsPage = new MarketDetailsPageObject(page) +// await marketDetailsPage.expectToBeLoaded() +// }) + +// test('overview is hidden when borrowed balance equal zero', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'marketDetails', +// initialPageParams: { asset: WEETH, chainId: fork.chainId.toString() }, +// account: { +// type: 'not-connected', +// }, +// }) + +// const marketDetailsPage = new MarketDetailsPageObject(page) +// await marketDetailsPage.expectMarketOverviewToBeHidden() +// }) +// }) +// }) + +// test.describe('Dialogs', () => { +// const initialDeposits = { +// wstETH: 10, +// } + +// test('guest state', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'marketDetails', +// initialPageParams: { asset: DAI, chainId: fork.chainId.toString() }, +// account: { +// type: 'not-connected', +// }, +// }) + +// const marketDetailsPage = new MarketDetailsPageObject(page) + +// await marketDetailsPage.expectToBeLoaded() + +// await marketDetailsPage.expectConnectWalletButton() +// await marketDetailsPage.expectDialogButtonToBeInvisible('Lend') +// await marketDetailsPage.expectDialogButtonToBeInvisible('Deposit') +// await marketDetailsPage.expectDialogButtonToBeInvisible('Borrow') +// }) + +// test("can't deposit if not enough balance", async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'marketDetails', +// initialPageParams: { asset: WETH, chainId: fork.chainId.toString() }, +// account: { +// type: 'connected-random', +// }, +// }) + +// const marketDetailsPage = new MarketDetailsPageObject(page) + +// await marketDetailsPage.expectToBeLoaded() + +// await marketDetailsPage.expectDialogButtonToBeInactive('Deposit') +// }) + +// test("can't lend if not enough balance", async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'marketDetails', +// initialPageParams: { asset: DAI, chainId: fork.chainId.toString() }, +// account: { +// type: 'connected-random', +// }, +// }) + +// const marketDetailsPage = new MarketDetailsPageObject(page) + +// await marketDetailsPage.expectToBeLoaded() + +// await marketDetailsPage.expectDialogButtonToBeInactive('Lend') +// }) + +// test("can't borrow if not enough balance", async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'marketDetails', +// initialPageParams: { asset: DAI, chainId: fork.chainId.toString() }, +// account: { +// type: 'connected-random', +// }, +// }) + +// const marketDetailsPage = new MarketDetailsPageObject(page) + +// await marketDetailsPage.expectToBeLoaded() + +// await marketDetailsPage.expectBorrowNotAvailableDisclaimer() +// await marketDetailsPage.expectDialogButtonToBeInvisible('Borrow') +// }) + +// test('opens dialogs for DAI', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { +// ...initialDeposits, +// DAI: 1000, +// sDAI: 1000, +// }, +// }, +// }) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositWithoutBorrowActions({ ...initialDeposits }) + +// await page.goto(buildUrl('marketDetails', { asset: DAI, chainId: fork.chainId.toString() })) + +// const marketDetailsPage = new MarketDetailsPageObject(page) + +// await marketDetailsPage.openDialogAction('Lend') +// const lendDialog = new DialogPageObject(page, /Deposit/i) +// await lendDialog.expectDialogHeader('Deposit DAI') +// await lendDialog.closeDialog() + +// await marketDetailsPage.openDialogAction('Deposit') +// const depositDialog = new DialogPageObject(page, /Deposit/i) +// await depositDialog.expectDialogHeader('Deposit sDAI') +// await depositDialog.closeDialog() + +// await marketDetailsPage.openDialogAction('Borrow') +// const borrowDialog = new DialogPageObject(page, /Borrow/i) +// await borrowDialog.expectDialogHeader('Borrow DAI') +// await borrowDialog.closeDialog() +// }) + +// test('opens dialogs for WETH', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { +// ...initialDeposits, +// WETH: 10, +// }, +// }, +// }) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositWithoutBorrowActions({ ...initialDeposits }) + +// await page.goto(buildUrl('marketDetails', { asset: WETH, chainId: fork.chainId.toString() })) + +// const marketDetailsPage = new MarketDetailsPageObject(page) + +// await marketDetailsPage.openDialogAction('Deposit') +// const lendDialog = new DialogPageObject(page, /Deposit/i) +// await lendDialog.expectDialogHeader('Deposit WETH') +// await lendDialog.closeDialog() + +// await marketDetailsPage.openDialogAction('Borrow') +// const borrowDialog = new DialogPageObject(page, /Borrow/i) +// await borrowDialog.expectDialogHeader('Borrow WETH') +// await borrowDialog.closeDialog() +// }) + +// // @todo: this scenario is inaccurate, because user has only ETH - in future dialog should open on ETH tab +// test('opens dialogs for WETH when having only ETH', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { +// ...initialDeposits, +// ETH: 5, +// }, +// }, +// }) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositWithoutBorrowActions({ ...initialDeposits }) + +// await page.goto(buildUrl('marketDetails', { asset: WETH, chainId: fork.chainId.toString() })) + +// const marketDetailsPage = new MarketDetailsPageObject(page) + +// await marketDetailsPage.expectWalletBalance('5.00 WETH') + +// await marketDetailsPage.openDialogAction('Deposit') +// const lendDialog = new DialogPageObject(page, /Deposit/i) +// await lendDialog.expectDialogHeader('Deposit WETH') +// await lendDialog.closeDialog() + +// await marketDetailsPage.openDialogAction('Borrow') +// const borrowDialog = new DialogPageObject(page, /Borrow/i) +// await borrowDialog.expectDialogHeader('Borrow WETH') +// await borrowDialog.closeDialog() +// }) + +// test('wallet displays sum of WETH and ETH', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'marketDetails', +// initialPageParams: { +// asset: WETH, +// chainId: fork.chainId.toString(), +// }, +// account: { +// type: 'connected-random', +// assetBalances: { +// ...initialDeposits, +// ETH: 5, +// WETH: 10, +// }, +// }, +// }) + +// const marketDetailsPage = new MarketDetailsPageObject(page) + +// await marketDetailsPage.expectWalletBalance('15.00 WETH') +// }) +// }) + +// test.describe('Isolated assets', () => { +// const BLOCK_NUMBER_WITH_WEETH = 20118125n +// const fork = setupFork({ blockNumber: BLOCK_NUMBER_WITH_WEETH, chainId: mainnet.id }) + +// test('Correctly displays debt ceiling', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'marketDetails', +// initialPageParams: { asset: WEETH, chainId: fork.chainId.toString() }, +// account: { +// type: 'not-connected', +// }, +// }) + +// const marketDetailsPage = new MarketDetailsPageObject(page) +// await marketDetailsPage.expectDebt('$3.17M') +// await marketDetailsPage.expectDebtCeiling('$50M') +// }) +// }) + +// test.describe('Errors', () => { +// const NOT_A_RESERVE = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266' + +// test('displays 404 page for unknown chain', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'marketDetails', +// initialPageParams: { asset: DAI, chainId: '12345' }, +// account: { +// type: 'not-connected', +// }, +// }) + +// const marketDetailsPage = new MarketDetailsPageObject(page) +// await marketDetailsPage.expect404() +// }) + +// test('displays 404 page for unknown asset', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'marketDetails', +// initialPageParams: { asset: NOT_A_RESERVE, chainId: fork.chainId.toString() }, +// account: { +// type: 'not-connected', +// }, +// }) + +// const marketDetailsPage = new MarketDetailsPageObject(page) +// await marketDetailsPage.expect404() +// }) +// }) + +// test.describe('Cap automator', () => { +// test('WETH', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'marketDetails', +// initialPageParams: { asset: WETH, chainId: fork.chainId.toString() }, +// account: { +// type: 'not-connected', +// }, +// }) + +// const marketDetailsPage = new MarketDetailsPageObject(page) + +// await marketDetailsPage.expectSupplyCap('403.2K WETH') +// await marketDetailsPage.expectSupplyMaxCap('2M WETH') +// await marketDetailsPage.expectSupplyCapCooldown('0h 00m 00s') + +// await marketDetailsPage.expectBorrowCap('256K WETH') +// await marketDetailsPage.expectBorrowMaxCap('1M WETH') +// await marketDetailsPage.expectBorrowCapCooldown('0h 00m 00s') +// }) + +// test('USDC', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'marketDetails', +// initialPageParams: { asset: USDC, chainId: fork.chainId.toString() }, +// account: { +// type: 'not-connected', +// }, +// }) + +// const marketDetailsPage = new MarketDetailsPageObject(page) + +// await marketDetailsPage.expectSupplyPanelNotVisible() + +// await marketDetailsPage.expectBorrowCap('7.678M USDC') +// await marketDetailsPage.expectBorrowMaxCap('57M USDC') +// await marketDetailsPage.expectBorrowCapCooldown('0h 00m 00s') +// }) + +// test('WBTC', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'marketDetails', +// initialPageParams: { asset: WBTC, chainId: fork.chainId.toString() }, +// account: { +// type: 'not-connected', +// }, +// }) + +// const marketDetailsPage = new MarketDetailsPageObject(page) + +// await marketDetailsPage.expectSupplyCap('4,780 WBTC') +// await marketDetailsPage.expectSupplyMaxCap('10K WBTC') +// await marketDetailsPage.expectSupplyCapCooldown('0h 00m 00s') + +// await marketDetailsPage.expectBorrowPanelNotVisible() +// await marketDetailsPage.expectToBeDisabledAsCollateral() +// await marketDetailsPage.expectDisabledCollateralInfoVisible() +// }) +// }) + +// test.describe('Oracles', () => { +// test('Fixed price', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'marketDetails', +// initialPageParams: { asset: DAI, chainId: fork.chainId.toString() }, +// account: { +// type: 'not-connected', +// }, +// }) + +// const marketDetailsPage = new MarketDetailsPageObject(page) + +// await marketDetailsPage.expectOraclePanelToHaveTitle('Fixed Price') + +// await marketDetailsPage.expectOracleInfo({ +// price: '$1.00', +// asset: 'DAI', +// oracleContract: '0x42a03F81dd8A1cEcD746dc262e4d1CD9fD39F777', +// }) +// }) +// test('Market price - not redundant', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'marketDetails', +// initialPageParams: { asset: WBTC, chainId: fork.chainId.toString() }, +// account: { +// type: 'not-connected', +// }, +// }) + +// const marketDetailsPage = new MarketDetailsPageObject(page) + +// await marketDetailsPage.expectOraclePanelToHaveTitle('Market Price') +// await marketDetailsPage.expectOracleToBeNotRedundant() + +// await marketDetailsPage.expectOracleInfo({ +// price: '$58,229.82', +// asset: 'WBTC', +// oracleContract: '0x230E0321Cf38F09e247e50Afc7801EA2351fe56F', +// }) +// }) + +// test('Yielding fixed price - redundant', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'marketDetails', +// initialPageParams: { asset: WEETH, chainId: fork.chainId.toString() }, +// account: { +// type: 'not-connected', +// }, +// }) + +// const marketDetailsPage = new MarketDetailsPageObject(page) + +// await marketDetailsPage.expectOraclePanelToHaveTitle('Yielding Fixed Price') +// await marketDetailsPage.expectOracleToBeRedundant() + +// await marketDetailsPage.expectOracleInfo({ +// price: '$2,576.50', +// asset: 'weETH', +// oracleContract: '0x1A6BDB22b9d7a454D20EAf12DB55D6B5F058183D', +// }) +// await marketDetailsPage.expectYieldingFixedOracleBaseAssetInfo({ +// asset: 'WETH', +// price: '$2,460.69', +// oracleContract: '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419', +// }) +// await marketDetailsPage.expectYieldingFixedOracleRatioInfo({ +// ratio: '1.0471', +// ratioContract: '0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee', +// }) +// }) +// }) +// }) + +// test.describe('Market details Gnosis', () => { +// const XDAI = '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d' +// const EURe = '0xcB444e90D8198415266c6a2724b7900fb12FC56E' +// const WETH = '0x6A023CCd1ff6F2045C3309768eAd9E68F978f6e1' +// const sDAI = '0xaf204776c7245bF4147c2612BF6e5972Ee483701' + +// const fork = setupFork({ +// blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, +// chainId: gnosis.id, +// useTenderlyVnet: true, +// }) + +// test.describe('Cap automator', () => { +// test('WETH', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'marketDetails', +// initialPageParams: { asset: WETH, chainId: fork.chainId.toString() }, +// account: { +// type: 'not-connected', +// }, +// }) + +// const marketDetailsPage = new MarketDetailsPageObject(page) + +// await marketDetailsPage.expectSupplyCap('5,000 WETH') +// await marketDetailsPage.expectSupplyMaxCapNotVisible() + +// await marketDetailsPage.expectBorrowCap('3,000 WETH') +// await marketDetailsPage.expectBorrowMaxCapNotVisible() +// }) + +// test('XDAI', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'marketDetails', +// initialPageParams: { asset: XDAI, chainId: fork.chainId.toString() }, +// account: { +// type: 'not-connected', +// }, +// }) + +// const marketDetailsPage = new MarketDetailsPageObject(page) + +// await marketDetailsPage.expectSupplyCap('20M WXDAI') +// await marketDetailsPage.expectSupplyMaxCapNotVisible() + +// await marketDetailsPage.expectBorrowCap('16M WXDAI') +// await marketDetailsPage.expectBorrowMaxCapNotVisible() + +// await marketDetailsPage.expectCollateralPanelNotVisible() +// }) +// }) + +// test.describe('Oracles', () => { +// test('Fixed price', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'marketDetails', +// initialPageParams: { asset: XDAI, chainId: fork.chainId.toString() }, +// account: { +// type: 'not-connected', +// }, +// }) + +// const marketDetailsPage = new MarketDetailsPageObject(page) + +// await marketDetailsPage.expectOraclePanelToHaveTitle('Fixed Price') + +// await marketDetailsPage.expectOracleInfo({ +// price: '$1.00', +// asset: 'WXDAI', +// oracleContract: '0x6FC2871B6d9A94866B7260896257Fd5b50c09900', +// }) +// }) + +// test('Underlying asset price', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'marketDetails', +// initialPageParams: { asset: EURe, chainId: fork.chainId.toString() }, +// account: { +// type: 'not-connected', +// }, +// }) + +// const marketDetailsPage = new MarketDetailsPageObject(page) + +// await marketDetailsPage.expectOraclePanelToHaveTitle('Underlying Asset Price') + +// await marketDetailsPage.expectOracleInfo({ +// price: '$1.07', +// asset: 'EUR', +// oracleContract: '0xab70BCB260073d036d1660201e9d5405F5829b7a', +// }) +// }) + +// test('Yielding fixed price - not redundant', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'marketDetails', +// initialPageParams: { asset: sDAI, chainId: fork.chainId.toString() }, +// account: { +// type: 'not-connected', +// }, +// }) + +// const marketDetailsPage = new MarketDetailsPageObject(page) + +// await marketDetailsPage.expectOraclePanelToHaveTitle('Yielding Fixed Price') +// await marketDetailsPage.expectOracleToBeNotRedundant() + +// await marketDetailsPage.expectOracleInfo({ +// price: '$1.0875', +// asset: 'sDAI', +// oracleContract: '0x1D0f881Ce1a646E2f27Dec3c57Fa056cB838BCC2', +// }) +// await marketDetailsPage.expectYieldingFixedOracleBaseAssetInfo({ +// asset: 'DAI', +// price: '$0.9997', +// oracleContract: '0x678df3415fc31947dA4324eC63212874be5a82f8', +// }) +// await marketDetailsPage.expectYieldingFixedOracleRatioInfo({ +// ratio: '1.0878', +// ratioContract: '0xaf204776c7245bF4147c2612BF6e5972Ee483701', +// }) +// }) +// }) +// }) diff --git a/packages/app/src/pages/Markets.test-e2e.ts b/packages/app/src/pages/Markets.test-e2e.ts index 6cd2c120a..a70f04a14 100644 --- a/packages/app/src/pages/Markets.test-e2e.ts +++ b/packages/app/src/pages/Markets.test-e2e.ts @@ -1,280 +1,280 @@ -import { WEETH_ACTIVE_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' -import { MarketsPageObject } from './Markets.PageObject' +// import { WEETH_ACTIVE_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' +// import { MarketsPageObject } from './Markets.PageObject' -test.describe('Markets', () => { - const fork = setupFork({ blockNumber: WEETH_ACTIVE_BLOCK_NUMBER, chainId: mainnet.id }) - let marketsPage: MarketsPageObject +// test.describe('Markets', () => { +// const fork = setupFork({ blockNumber: WEETH_ACTIVE_BLOCK_NUMBER, chainId: mainnet.id }) +// let marketsPage: MarketsPageObject - test.beforeEach(async ({ page }) => { - await setup(page, fork, { - initialPage: 'markets', - account: { - type: 'not-connected', - }, - }) +// test.beforeEach(async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'markets', +// account: { +// type: 'not-connected', +// }, +// }) - marketsPage = new MarketsPageObject(page) - }) +// marketsPage = new MarketsPageObject(page) +// }) - test('summary', async () => { - await marketsPage.expectSummary([ - { description: 'Total market size', value: '$4.441B' }, - { description: 'Total value locked', value: '$2.869B' }, - { description: 'Total available', value: '$2.904B' }, - { description: 'Total borrows', value: '$1.537B' }, - ]) - }) +// test('summary', async () => { +// await marketsPage.expectSummary([ +// { description: 'Total market size', value: '$4.441B' }, +// { description: 'Total value locked', value: '$2.869B' }, +// { description: 'Total available', value: '$2.904B' }, +// { description: 'Total borrows', value: '$1.537B' }, +// ]) +// }) - test('active markets table', async () => { - await marketsPage.expectActiveMarketsTable([ - { - asset: { - name: 'Lido Staked ETH', - symbol: 'wstETH', - }, - totalSupplied: { - tokenAmount: '519K', - usdValue: '$2.06B', - }, - depositAPY: { - value: '<0.01%', - }, - totalBorrowed: { - tokenAmount: '51.56', - usdValue: '$204.7K', - }, - borrowAPY: { - value: '0.25%', - }, - status: { - supply: 'Can be supplied', - collateral: 'Can be used as collateral', - borrow: 'Can be borrowed', - }, - }, - { - asset: { - name: 'DAI Stablecoin', - symbol: 'DAI', - }, - totalSupplied: { - tokenAmount: '962.8M', - usdValue: '$962.8M', - }, - depositAPY: { - // @note: This value is different in production since VITE_FEATURE_DISABLE_DAI_LEND is disabled in playwright tests - value: '8.52%', - }, - totalBorrowed: { - tokenAmount: '913.6M', - usdValue: '$913.6M', - }, - borrowAPY: { - value: '9.00%', - hasAirDrop: true, - }, - status: { - // @note: This value is different in production since VITE_FEATURE_DISABLE_DAI_LEND is disabled in playwright tests - supply: 'Can be supplied', - collateral: 'Cannot be used as collateral', - borrow: 'Can be borrowed', - }, - }, - { - asset: { - name: 'Ethereum', - symbol: 'ETH', - }, - totalSupplied: { - tokenAmount: '252.1K', - usdValue: '$854.8M', - }, - depositAPY: { - value: '1.31%', - hasAirDrop: true, - }, - totalBorrowed: { - tokenAmount: '177K', - usdValue: '$600M', - }, - borrowAPY: { - value: '1.97%', - }, - status: { - supply: 'Can be supplied', - collateral: 'Can be used as collateral', - borrow: 'Can be borrowed', - }, - }, - { - asset: { - name: 'Wrapped BTC', - symbol: 'WBTC', - }, - totalSupplied: { - tokenAmount: '5,790', - usdValue: '$358M', - }, - depositAPY: { - value: '<0.01%', - }, - totalBorrowed: { - tokenAmount: '332.8', - usdValue: '$20.58M', - }, - borrowAPY: { - value: '0.19%', - }, - status: { - supply: 'Can be supplied', - collateral: 'Can be used as collateral', - borrow: 'Can be borrowed', - }, - }, - { - asset: { - name: 'Rocket Pool Staked ETH', - symbol: 'rETH', - }, - totalSupplied: { - tokenAmount: '38.95K', - usdValue: '$146.5M', - }, - depositAPY: { - value: '<0.01%', - }, - totalBorrowed: { - tokenAmount: '6.271', - usdValue: '$23.59K', - }, - borrowAPY: { - value: '0.25%', - }, - status: { - supply: 'Can be supplied', - collateral: 'Can be used as collateral', - borrow: 'Can be borrowed', - }, - }, - { - asset: { - name: 'Ether.fi Staked ETH', - symbol: 'weETH', - }, - totalSupplied: { - tokenAmount: '11.66K', - usdValue: '$41.17M', - }, - depositAPY: { - value: '0.00%', - }, - totalBorrowed: undefined, - borrowAPY: undefined, - status: { - supply: 'Can be supplied', - collateral: 'Can be used as collateral only in isolation mode', - borrow: 'Cannot be borrowed', - }, - }, - { - asset: { - name: 'Savings Dai', - symbol: 'sDAI', - }, - totalSupplied: { - tokenAmount: '13.49M', - usdValue: '$14.73M', - }, - depositAPY: { - value: '0.00%', - }, - totalBorrowed: undefined, - borrowAPY: undefined, - status: { - supply: 'Can be supplied', - collateral: 'Can be used as collateral', - borrow: 'Cannot be borrowed', - }, - }, - { - asset: { - name: 'Circle USD', - symbol: 'USDC', - }, - totalSupplied: { - tokenAmount: '2.559M', - usdValue: '$2.559M', - }, - depositAPY: { - value: '5.90%', - }, - totalBorrowed: { - tokenAmount: '2.077M', - usdValue: '$2.077M', - }, - borrowAPY: { - value: '7.72%', - }, - status: { - supply: 'Can be supplied', - collateral: 'Cannot be used as collateral', - borrow: 'Can be borrowed', - }, - }, - { - asset: { - name: 'Tether USD', - symbol: 'USDT', - }, - totalSupplied: { - tokenAmount: '316.6K', - usdValue: '$316.6K', - }, - depositAPY: { - value: '4.03%', - }, - totalBorrowed: { - tokenAmount: '213.2K', - usdValue: '$213.2K', - }, - borrowAPY: { - value: '6.36%', - }, - status: { - supply: 'Can be supplied', - collateral: 'Cannot be used as collateral', - borrow: 'Can be borrowed', - }, - }, - ]) - }) +// test('active markets table', async () => { +// await marketsPage.expectActiveMarketsTable([ +// { +// asset: { +// name: 'Lido Staked ETH', +// symbol: 'wstETH', +// }, +// totalSupplied: { +// tokenAmount: '519K', +// usdValue: '$2.06B', +// }, +// depositAPY: { +// value: '<0.01%', +// }, +// totalBorrowed: { +// tokenAmount: '51.56', +// usdValue: '$204.7K', +// }, +// borrowAPY: { +// value: '0.25%', +// }, +// status: { +// supply: 'Can be supplied', +// collateral: 'Can be used as collateral', +// borrow: 'Can be borrowed', +// }, +// }, +// { +// asset: { +// name: 'DAI Stablecoin', +// symbol: 'DAI', +// }, +// totalSupplied: { +// tokenAmount: '962.8M', +// usdValue: '$962.8M', +// }, +// depositAPY: { +// // @note: This value is different in production since VITE_FEATURE_DISABLE_DAI_LEND is disabled in playwright tests +// value: '8.52%', +// }, +// totalBorrowed: { +// tokenAmount: '913.6M', +// usdValue: '$913.6M', +// }, +// borrowAPY: { +// value: '9.00%', +// hasAirDrop: true, +// }, +// status: { +// // @note: This value is different in production since VITE_FEATURE_DISABLE_DAI_LEND is disabled in playwright tests +// supply: 'Can be supplied', +// collateral: 'Cannot be used as collateral', +// borrow: 'Can be borrowed', +// }, +// }, +// { +// asset: { +// name: 'Ethereum', +// symbol: 'ETH', +// }, +// totalSupplied: { +// tokenAmount: '252.1K', +// usdValue: '$854.8M', +// }, +// depositAPY: { +// value: '1.31%', +// hasAirDrop: true, +// }, +// totalBorrowed: { +// tokenAmount: '177K', +// usdValue: '$600M', +// }, +// borrowAPY: { +// value: '1.97%', +// }, +// status: { +// supply: 'Can be supplied', +// collateral: 'Can be used as collateral', +// borrow: 'Can be borrowed', +// }, +// }, +// { +// asset: { +// name: 'Wrapped BTC', +// symbol: 'WBTC', +// }, +// totalSupplied: { +// tokenAmount: '5,790', +// usdValue: '$358M', +// }, +// depositAPY: { +// value: '<0.01%', +// }, +// totalBorrowed: { +// tokenAmount: '332.8', +// usdValue: '$20.58M', +// }, +// borrowAPY: { +// value: '0.19%', +// }, +// status: { +// supply: 'Can be supplied', +// collateral: 'Can be used as collateral', +// borrow: 'Can be borrowed', +// }, +// }, +// { +// asset: { +// name: 'Rocket Pool Staked ETH', +// symbol: 'rETH', +// }, +// totalSupplied: { +// tokenAmount: '38.95K', +// usdValue: '$146.5M', +// }, +// depositAPY: { +// value: '<0.01%', +// }, +// totalBorrowed: { +// tokenAmount: '6.271', +// usdValue: '$23.59K', +// }, +// borrowAPY: { +// value: '0.25%', +// }, +// status: { +// supply: 'Can be supplied', +// collateral: 'Can be used as collateral', +// borrow: 'Can be borrowed', +// }, +// }, +// { +// asset: { +// name: 'Ether.fi Staked ETH', +// symbol: 'weETH', +// }, +// totalSupplied: { +// tokenAmount: '11.66K', +// usdValue: '$41.17M', +// }, +// depositAPY: { +// value: '0.00%', +// }, +// totalBorrowed: undefined, +// borrowAPY: undefined, +// status: { +// supply: 'Can be supplied', +// collateral: 'Can be used as collateral only in isolation mode', +// borrow: 'Cannot be borrowed', +// }, +// }, +// { +// asset: { +// name: 'Savings Dai', +// symbol: 'sDAI', +// }, +// totalSupplied: { +// tokenAmount: '13.49M', +// usdValue: '$14.73M', +// }, +// depositAPY: { +// value: '0.00%', +// }, +// totalBorrowed: undefined, +// borrowAPY: undefined, +// status: { +// supply: 'Can be supplied', +// collateral: 'Can be used as collateral', +// borrow: 'Cannot be borrowed', +// }, +// }, +// { +// asset: { +// name: 'Circle USD', +// symbol: 'USDC', +// }, +// totalSupplied: { +// tokenAmount: '2.559M', +// usdValue: '$2.559M', +// }, +// depositAPY: { +// value: '5.90%', +// }, +// totalBorrowed: { +// tokenAmount: '2.077M', +// usdValue: '$2.077M', +// }, +// borrowAPY: { +// value: '7.72%', +// }, +// status: { +// supply: 'Can be supplied', +// collateral: 'Cannot be used as collateral', +// borrow: 'Can be borrowed', +// }, +// }, +// { +// asset: { +// name: 'Tether USD', +// symbol: 'USDT', +// }, +// totalSupplied: { +// tokenAmount: '316.6K', +// usdValue: '$316.6K', +// }, +// depositAPY: { +// value: '4.03%', +// }, +// totalBorrowed: { +// tokenAmount: '213.2K', +// usdValue: '$213.2K', +// }, +// borrowAPY: { +// value: '6.36%', +// }, +// status: { +// supply: 'Can be supplied', +// collateral: 'Cannot be used as collateral', +// borrow: 'Can be borrowed', +// }, +// }, +// ]) +// }) - test('frozen markets table', async () => { - await marketsPage.showFrozenMarkets() - await marketsPage.expectFrozenMarketsTable([ - { - asset: { - name: 'Gnosis Token', - symbol: 'GNO', - isFrozen: true, - }, - totalSupplied: { - tokenAmount: '55.1', - usdValue: '$15.91K', - }, - depositAPY: undefined, - totalBorrowed: undefined, - borrowAPY: undefined, - status: { - supply: 'Cannot be supplied', - collateral: 'Cannot be used as collateral', - borrow: 'Cannot be borrowed', - }, - }, - ]) - }) -}) +// test('frozen markets table', async () => { +// await marketsPage.showFrozenMarkets() +// await marketsPage.expectFrozenMarketsTable([ +// { +// asset: { +// name: 'Gnosis Token', +// symbol: 'GNO', +// isFrozen: true, +// }, +// totalSupplied: { +// tokenAmount: '55.1', +// usdValue: '$15.91K', +// }, +// depositAPY: undefined, +// totalBorrowed: undefined, +// borrowAPY: undefined, +// status: { +// supply: 'Cannot be supplied', +// collateral: 'Cannot be used as collateral', +// borrow: 'Cannot be borrowed', +// }, +// }, +// ]) +// }) +// }) diff --git a/packages/app/src/pages/MyPortfolio.test-e2e.ts b/packages/app/src/pages/MyPortfolio.test-e2e.ts index c2423985f..0d633b43f 100644 --- a/packages/app/src/pages/MyPortfolio.test-e2e.ts +++ b/packages/app/src/pages/MyPortfolio.test-e2e.ts @@ -1,101 +1,101 @@ -import { test } from '@playwright/test' -import { mainnet } from 'viem/chains' - -import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' -import { calculateAssetsWorth, screenshot } from '@/test/e2e/utils' - -import { BorrowPageObject } from './Borrow.PageObject' -import { MyPortfolioPageObject } from './MyPortfolio.PageObject' - -test.describe('MyPortfolio', () => { - const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) - - test.skip('guest state', async ({ page }) => { - await setup(page, fork, { - account: { - type: 'not-connected', - }, - initialPage: 'myPortfolio', - }) - const myPortfolioPage = new MyPortfolioPageObject(page) - - await myPortfolioPage.expectGuestScreen() - - await screenshot(page, 'myPortfolio-guest') - }) - - test('empty account', async ({ page }) => { - await setup(page, fork, { - initialPage: 'myPortfolio', - account: { - type: 'connected-random', - }, - }) - const myPortfolioPage = new MyPortfolioPageObject(page) - - await myPortfolioPage.expectPositionToBeEmpty() - - await screenshot(page, 'myPortfolio-empty-account') - }) - - test('no position', async ({ page }) => { - const assetBalances = { - ETH: 1, - DAI: 200, - sDAI: 300, - USDC: 400, - WETH: 1, - } - await setup(page, fork, { - initialPage: 'myPortfolio', - account: { - type: 'connected-random', - assetBalances, - }, - }) - const myPortfolioPage = new MyPortfolioPageObject(page) - - await myPortfolioPage.expectPositionToBeEmpty() - await myPortfolioPage.expectBalancesInDepositTable({ - WETH: 2, - DAI: 200, - sDAI: 300, - USDC: 400, - }) - - await screenshot(page, 'myPortfolio-no-position') - }) - - test('with open position', async ({ page }) => { - const assetsToDeposit = { - wstETH: 2, - rETH: 2, - } - const daiToBorrow = 1500 - await setup(page, fork, { - initialPage: 'easyBorrow', - account: { - type: 'connected-random', - assetBalances: { ...assetsToDeposit, ETH: 0.1 }, - }, - }) - - const borrowPage = new BorrowPageObject(page) - await borrowPage.depositAssetsActions(assetsToDeposit, daiToBorrow) - await borrowPage.viewInMyPortfolioAction() - - const myPortfolioPage = new MyPortfolioPageObject(page) - await myPortfolioPage.expectHealthFactor('5.42') - await myPortfolioPage.expectDepositedAssets((await calculateAssetsWorth(fork.forkUrl, assetsToDeposit)).total) - await myPortfolioPage.expectBorrowedAssets((await calculateAssetsWorth(fork.forkUrl, { DAI: daiToBorrow })).total) - - await myPortfolioPage.expectDepositTable(assetsToDeposit) - await myPortfolioPage.expectBalancesInDepositTable({ - DAI: daiToBorrow, - }) - - await screenshot(page, 'myPortfolio-open-position') - }) -}) +// import { test } from '@playwright/test' +// import { mainnet } from 'viem/chains' + +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' +// import { calculateAssetsWorth, screenshot } from '@/test/e2e/utils' + +// import { BorrowPageObject } from './Borrow.PageObject' +// import { MyPortfolioPageObject } from './MyPortfolio.PageObject' + +// test.describe('MyPortfolio', () => { +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) + +// test.skip('guest state', async ({ page }) => { +// await setup(page, fork, { +// account: { +// type: 'not-connected', +// }, +// initialPage: 'myPortfolio', +// }) +// const myPortfolioPage = new MyPortfolioPageObject(page) + +// await myPortfolioPage.expectGuestScreen() + +// await screenshot(page, 'myPortfolio-guest') +// }) + +// test('empty account', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'myPortfolio', +// account: { +// type: 'connected-random', +// }, +// }) +// const myPortfolioPage = new MyPortfolioPageObject(page) + +// await myPortfolioPage.expectPositionToBeEmpty() + +// await screenshot(page, 'myPortfolio-empty-account') +// }) + +// test('no position', async ({ page }) => { +// const assetBalances = { +// ETH: 1, +// DAI: 200, +// sDAI: 300, +// USDC: 400, +// WETH: 1, +// } +// await setup(page, fork, { +// initialPage: 'myPortfolio', +// account: { +// type: 'connected-random', +// assetBalances, +// }, +// }) +// const myPortfolioPage = new MyPortfolioPageObject(page) + +// await myPortfolioPage.expectPositionToBeEmpty() +// await myPortfolioPage.expectBalancesInDepositTable({ +// WETH: 2, +// DAI: 200, +// sDAI: 300, +// USDC: 400, +// }) + +// await screenshot(page, 'myPortfolio-no-position') +// }) + +// test('with open position', async ({ page }) => { +// const assetsToDeposit = { +// wstETH: 2, +// rETH: 2, +// } +// const daiToBorrow = 1500 +// await setup(page, fork, { +// initialPage: 'easyBorrow', +// account: { +// type: 'connected-random', +// assetBalances: { ...assetsToDeposit, ETH: 0.1 }, +// }, +// }) + +// const borrowPage = new BorrowPageObject(page) +// await borrowPage.depositAssetsActions(assetsToDeposit, daiToBorrow) +// await borrowPage.viewInMyPortfolioAction() + +// const myPortfolioPage = new MyPortfolioPageObject(page) +// await myPortfolioPage.expectHealthFactor('5.42') +// await myPortfolioPage.expectDepositedAssets((await calculateAssetsWorth(fork.forkUrl, assetsToDeposit)).total) +// await myPortfolioPage.expectBorrowedAssets((await calculateAssetsWorth(fork.forkUrl, { DAI: daiToBorrow })).total) + +// await myPortfolioPage.expectDepositTable(assetsToDeposit) +// await myPortfolioPage.expectBalancesInDepositTable({ +// DAI: daiToBorrow, +// }) + +// await screenshot(page, 'myPortfolio-open-position') +// }) +// }) diff --git a/packages/app/src/pages/Savings.test-e2e.ts b/packages/app/src/pages/Savings.test-e2e.ts index 3bf32dcee..4d6d9e2e6 100644 --- a/packages/app/src/pages/Savings.test-e2e.ts +++ b/packages/app/src/pages/Savings.test-e2e.ts @@ -1,220 +1,220 @@ -import { test } from '@playwright/test' -import { base, gnosis, mainnet } from 'viem/chains' - -import { DEFAULT_BLOCK_NUMBER, GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { setup } from '@/test/e2e/setup' - -import { SavingsPageObject } from './Savings.PageObject' - -test.describe('Savings Mainnet', () => { - const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) - - test('guest state', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'not-connected', - }, - }) - - const savingsPage = new SavingsPageObject(page) - - await savingsPage.expectAPY('5%') - await savingsPage.expectConnectWalletCTA() - }) - - test('calculates current value', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - sDAI: 100, - }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - - await savingsPage.expectSavingsDaiBalance({ - sdaiBalance: '100.00', - estimatedDaiValue: '107.1505', - }) - }) - - test('calculates current projections', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - sDAI: 100, - }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - - await savingsPage.expectSavingDaiCurrentProjection('$0.43', '30-day') - await savingsPage.expectSavingDaiCurrentProjection('$5.36', '1-year') - }) - - test('displays the total value of stablecoins in the wallet', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - DAI: 100, - USDC: 100, - }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - - await savingsPage.expectOpportunityStablecoinsAmount('~$200.00') - }) -}) - -test.describe('Savings Gnosis', () => { - const fork = setupFork({ blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id, useTenderlyVnet: true }) - - test('guest state', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'not-connected', - }, - }) - - const savingsPage = new SavingsPageObject(page) - - await savingsPage.expectAPY('10.6%') - await savingsPage.expectConnectWalletCTA() - }) - - test('calculates current value', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - sDAI: 100, - }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - - await savingsPage.expectSavingsDaiBalance({ - sdaiBalance: '100.00', - estimatedDaiValue: '108.780942', - }) - }) - - test('calculates current projections', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - sDAI: 100, - }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - - await savingsPage.expectSavingDaiCurrentProjection('$0.95', '30-day') - await savingsPage.expectSavingDaiCurrentProjection('$11.53', '1-year') - }) - - test('displays the total value of stablecoins in the wallet', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - XDAI: 100, - }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - - await savingsPage.expectOpportunityStablecoinsAmount('~$100.00') - }) -}) - -test.describe('Savings Base', () => { - const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) - - test('guest state', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'not-connected', - }, - }) - - const savingsPage = new SavingsPageObject(page) - - await savingsPage.expectAPY('6.5%') - await savingsPage.expectConnectWalletCTA() - }) - - test('calculates current value', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - sUSDS: 100, - }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - - await savingsPage.expectSavingsUsdsBalance({ - susdsBalance: '100.00', - estimatedUsdsValue: '100.8901', - }) - }) - - test('calculates current projections', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - sUSDS: 100, - }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - - await savingsPage.expectSavingUsdsCurrentProjection('$0.52', '30-day') - await savingsPage.expectSavingUsdsCurrentProjection('$6.56', '1-year') - }) - - test('displays the total value of stablecoins in the wallet', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - assetBalances: { - USDC: 100, - USDS: 100, - }, - }, - }) - - const savingsPage = new SavingsPageObject(page) - - await savingsPage.expectOpportunityStablecoinsAmount('~$200.00') - }) -}) +// import { test } from '@playwright/test' +// import { base, gnosis, mainnet } from 'viem/chains' + +// import { DEFAULT_BLOCK_NUMBER, GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { setup } from '@/test/e2e/setup' + +// import { SavingsPageObject } from './Savings.PageObject' + +// test.describe('Savings Mainnet', () => { +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) + +// test('guest state', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'not-connected', +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// await savingsPage.expectAPY('5%') +// await savingsPage.expectConnectWalletCTA() +// }) + +// test('calculates current value', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// sDAI: 100, +// }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// await savingsPage.expectSavingsDaiBalance({ +// sdaiBalance: '100.00', +// estimatedDaiValue: '107.1505', +// }) +// }) + +// test('calculates current projections', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// sDAI: 100, +// }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// await savingsPage.expectSavingDaiCurrentProjection('$0.43', '30-day') +// await savingsPage.expectSavingDaiCurrentProjection('$5.36', '1-year') +// }) + +// test('displays the total value of stablecoins in the wallet', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// DAI: 100, +// USDC: 100, +// }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// await savingsPage.expectOpportunityStablecoinsAmount('~$200.00') +// }) +// }) + +// test.describe('Savings Gnosis', () => { +// const fork = setupFork({ blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id, useTenderlyVnet: true }) + +// test('guest state', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'not-connected', +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// await savingsPage.expectAPY('10.6%') +// await savingsPage.expectConnectWalletCTA() +// }) + +// test('calculates current value', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// sDAI: 100, +// }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// await savingsPage.expectSavingsDaiBalance({ +// sdaiBalance: '100.00', +// estimatedDaiValue: '108.780942', +// }) +// }) + +// test('calculates current projections', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// sDAI: 100, +// }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// await savingsPage.expectSavingDaiCurrentProjection('$0.95', '30-day') +// await savingsPage.expectSavingDaiCurrentProjection('$11.53', '1-year') +// }) + +// test('displays the total value of stablecoins in the wallet', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// XDAI: 100, +// }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// await savingsPage.expectOpportunityStablecoinsAmount('~$100.00') +// }) +// }) + +// test.describe('Savings Base', () => { +// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) + +// test('guest state', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'not-connected', +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// await savingsPage.expectAPY('6.5%') +// await savingsPage.expectConnectWalletCTA() +// }) + +// test('calculates current value', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// sUSDS: 100, +// }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// await savingsPage.expectSavingsUsdsBalance({ +// susdsBalance: '100.00', +// estimatedUsdsValue: '100.8901', +// }) +// }) + +// test('calculates current projections', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// sUSDS: 100, +// }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// await savingsPage.expectSavingUsdsCurrentProjection('$0.52', '30-day') +// await savingsPage.expectSavingUsdsCurrentProjection('$6.56', '1-year') +// }) + +// test('displays the total value of stablecoins in the wallet', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// assetBalances: { +// USDC: 100, +// USDS: 100, +// }, +// }, +// }) + +// const savingsPage = new SavingsPageObject(page) + +// await savingsPage.expectOpportunityStablecoinsAmount('~$200.00') +// }) +// }) diff --git a/packages/app/src/ui/layouts/app-layout/components/PageNotSupportedWarning.PageObject.ts b/packages/app/src/ui/layouts/app-layout/components/PageNotSupportedWarning.PageObject.ts index 80e957f42..f775bfea1 100644 --- a/packages/app/src/ui/layouts/app-layout/components/PageNotSupportedWarning.PageObject.ts +++ b/packages/app/src/ui/layouts/app-layout/components/PageNotSupportedWarning.PageObject.ts @@ -1,22 +1,22 @@ -import { Locator, expect } from '@playwright/test' +// import { Locator, expect } from '@playwright/test' -import { BasePageObject } from '@/test/e2e/BasePageObject' -import { testIds } from '@/ui/utils/testIds' +// import { BasePageObject } from '@/test/e2e/BasePageObject' +// import { testIds } from '@/ui/utils/testIds' -export class PageNotSupportedWarningPageObject extends BasePageObject { - // #region locators - locateSwitchNetworkButton(): Locator { - return this.page.getByTestId(testIds.component.SwitchNotSupportedNetworkButton) - } - // #endregion +// export class PageNotSupportedWarningPageObject extends BasePageObject { +// // #region locators +// locateSwitchNetworkButton(): Locator { +// return this.page.getByTestId(testIds.component.SwitchNotSupportedNetworkButton) +// } +// // #endregion - // #region assertions - async expectSwitchNetworkVisible(): Promise { - await expect(this.locateSwitchNetworkButton()).toBeVisible() - } +// // #region assertions +// async expectSwitchNetworkVisible(): Promise { +// await expect(this.locateSwitchNetworkButton()).toBeVisible() +// } - async expectSwitchNetworkNotVisible(): Promise { - await expect(this.locateSwitchNetworkButton()).not.toBeVisible() - } - // #endregion -} +// async expectSwitchNetworkNotVisible(): Promise { +// await expect(this.locateSwitchNetworkButton()).not.toBeVisible() +// } +// // #endregion +// } diff --git a/packages/app/src/ui/layouts/app-layout/components/PageNotSupportedWarning.test-e2e.ts b/packages/app/src/ui/layouts/app-layout/components/PageNotSupportedWarning.test-e2e.ts index 471b0fb96..83bb77f5d 100644 --- a/packages/app/src/ui/layouts/app-layout/components/PageNotSupportedWarning.test-e2e.ts +++ b/packages/app/src/ui/layouts/app-layout/components/PageNotSupportedWarning.test-e2e.ts @@ -1,41 +1,41 @@ -import { test } from '@playwright/test' -import { gnosis } from 'viem/chains' +// import { test } from '@playwright/test' +// import { gnosis } from 'viem/chains' -import { GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' -import { buildUrl, setup } from '@/test/e2e/setup' -import { PageNotSupportedWarningPageObject } from './PageNotSupportedWarning.PageObject' +// import { GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { setupFork } from '@/test/e2e/forking/setupFork' +// import { buildUrl, setup } from '@/test/e2e/setup' +// import { PageNotSupportedWarningPageObject } from './PageNotSupportedWarning.PageObject' -test.describe('PageNotSupportedWarning', () => { - const fork = setupFork({ blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id, useTenderlyVnet: true }) +// test.describe('PageNotSupportedWarning', () => { +// const fork = setupFork({ blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id, useTenderlyVnet: true }) - test('Displays not supported warning on unsupported page', async ({ page }) => { - await setup(page, fork, { - initialPage: 'farms', - account: { - type: 'connected-random', - }, - }) +// test('Displays not supported warning on unsupported page', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'farms', +// account: { +// type: 'connected-random', +// }, +// }) - const warning = new PageNotSupportedWarningPageObject(page) +// const warning = new PageNotSupportedWarningPageObject(page) - await warning.expectSwitchNetworkVisible() - }) +// await warning.expectSwitchNetworkVisible() +// }) - test('Displays not supported warning on entering the unsupported page', async ({ page }) => { - await setup(page, fork, { - initialPage: 'savings', - account: { - type: 'connected-random', - }, - }) +// test('Displays not supported warning on entering the unsupported page', async ({ page }) => { +// await setup(page, fork, { +// initialPage: 'savings', +// account: { +// type: 'connected-random', +// }, +// }) - const warning = new PageNotSupportedWarningPageObject(page) +// const warning = new PageNotSupportedWarningPageObject(page) - await warning.expectSwitchNetworkNotVisible() +// await warning.expectSwitchNetworkNotVisible() - await page.goto(buildUrl('farms')) +// await page.goto(buildUrl('farms')) - await warning.expectSwitchNetworkVisible() - }) -}) +// await warning.expectSwitchNetworkVisible() +// }) +// }) From 2ab70120b2da9e2a178304f2c244698468a6c0ee Mon Sep 17 00:00:00 2001 From: yivlad Date: Fri, 13 Dec 2024 12:51:20 +0100 Subject: [PATCH 02/29] wip --- packages/app/package.json | 2 + .../claim/e2e/mainnet/ClaimSKY.test-e2e.ts | 123 +++++++++--------- .../claim/e2e/mainnet/ClaimSky2.test-e2e.ts | 93 +++++++++++++ .../dialogs/claim/e2e/mainnet/utils.ts | 15 +++ packages/app/src/test/e2e/setup.ts | 11 +- packages/app/src/test/e2e/testnet-cache.ts | 52 ++++++++ pnpm-lock.yaml | 6 + 7 files changed, 243 insertions(+), 59 deletions(-) create mode 100644 packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSky2.test-e2e.ts create mode 100644 packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/utils.ts create mode 100644 packages/app/src/test/e2e/testnet-cache.ts diff --git a/packages/app/package.json b/packages/app/package.json index 60f4e0d15..5b4f1add7 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -81,6 +81,8 @@ "zustand": "^4.4.1" }, "devDependencies": { + "@marsfoundation/common-nodejs": "workspace:^", + "@marsfoundation/common-testnets": "workspace:^", "@chromatic-com/storybook": "^1.5.0", "@playwright/test": "^1.47.2", "@sentry/react": "^7.114.0", diff --git a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts index 0e7b7c4c7..54f8be152 100644 --- a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts @@ -1,83 +1,90 @@ import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' import { StakeDialogPageObject } from '@/features/farm-details/dialogs/stake/StakeDialog.PageObject' import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setupFork } from '@/test/e2e/forking/setupFork' import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' import { setup } from '@/test/e2e/setup' import { test } from '@playwright/test' import { Address } from 'viem' import { mainnet } from 'viem/chains' import { ClaimDialogPageObject } from '../../ClaimDialog.PageObject' +import { someObject } from './utils' + +console.log('Global test', someObject) test.describe('Claim SKY rewards', () => { - const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) let farmDetailsPage: FarmDetailsPageObject let claimDialog: ClaimDialogPageObject let account: Address - test.beforeEach(async ({ page }) => { - ;({ account } = await setup(page, fork, { - initialPage: 'farmDetails', - initialPageParams: { - chainId: mainnet.id.toString(), - address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', - }, - account: { - type: 'connected-random', - assetBalances: { - ETH: 1, - USDS: 10_000, - }, - }, - })) - await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) + // test.beforeEach(async ({ page }) => { + // ;({ account } = await setup(page, { + // blockchain: { + // chainId: mainnet.id, + // blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, + // }, + // initialPage: 'farmDetails', + // initialPageParams: { + // chainId: mainnet.id.toString(), + // address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', + // }, + // account: { + // type: 'connected-random', + // assetBalances: { + // ETH: 1, + // USDS: 10_000, + // }, + // }, + // })) + // await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) - farmDetailsPage = new FarmDetailsPageObject(page) - await farmDetailsPage.clickInfoPanelStakeButtonAction() - const stakeDialog = new StakeDialogPageObject(page) - await stakeDialog.fillAmountAction(10_000) - await stakeDialog.actionsContainer.acceptAllActionsAction(2) - await stakeDialog.clickBackToFarmAction() - await fork.progressSimulation(page, 24 * 60 * 60) // 24 hours - await page.reload() + // farmDetailsPage = new FarmDetailsPageObject(page) + // await farmDetailsPage.clickInfoPanelStakeButtonAction() + // const stakeDialog = new StakeDialogPageObject(page) + // await stakeDialog.fillAmountAction(10_000) + // await stakeDialog.actionsContainer.acceptAllActionsAction(2) + // await stakeDialog.clickBackToFarmAction() + // await fork.progressSimulation(page, 24 * 60 * 60) // 24 hours + // await page.reload() - await farmDetailsPage.clickInfoPanelClaimButtonAction() - claimDialog = new ClaimDialogPageObject(page) - }) + // await farmDetailsPage.clickInfoPanelClaimButtonAction() + // claimDialog = new ClaimDialogPageObject(page) + // }) test('has correct action plan', async () => { - await claimDialog.actionsContainer.expectEnabledActionAtIndex(0) - await claimDialog.actionsContainer.expectActions([{ type: 'claimFarmRewards', asset: 'SKY' }]) - }) + // await claimDialog.actionsContainer.expectEnabledActionAtIndex(0) + // await claimDialog.actionsContainer.expectActions([{ type: 'claimFarmRewards', asset: 'SKY' }]) - test('displays transaction overview', async () => { - await claimDialog.expectTransactionOverview({ - reward: { - // amount is imprecise because of timing issues in e2e tests - amount: '3,539', - amountUSD: '$213', - }, - }) + console.log('Test 1', new Date().toISOString()) }) - test('executes transaction', async () => { - await claimDialog.actionsContainer.acceptAllActionsAction(1) + // test('displays transaction overview', async () => { + // await claimDialog.expectTransactionOverview({ + // reward: { + // // amount is imprecise because of timing issues in e2e tests + // amount: '3,539', + // amountUSD: '$213', + // }, + // }) + // }) - await claimDialog.expectSuccessPage() - await claimDialog.clickBackToFarmAction() + // test('executes transaction', async () => { + // await claimDialog.actionsContainer.acceptAllActionsAction(1) - await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') - await farmDetailsPage.expectReward({ - reward: '0', - rewardUsd: '$0.00', - }) - await farmDetailsPage.expectTokenBalance({ - address: account, - fork, - symbol: 'SKY', - minBalance: 3_525, - maxBalance: 3_545, - }) - await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) - }) + // await claimDialog.expectSuccessPage() + // await claimDialog.clickBackToFarmAction() + + // await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') + // await farmDetailsPage.expectReward({ + // reward: '0', + // rewardUsd: '$0.00', + // }) + // await farmDetailsPage.expectTokenBalance({ + // address: account, + // fork, + // symbol: 'SKY', + // minBalance: 3_525, + // maxBalance: 3_545, + // }) + // await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) + // }) }) diff --git a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSky2.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSky2.test-e2e.ts new file mode 100644 index 000000000..134bc56e8 --- /dev/null +++ b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSky2.test-e2e.ts @@ -0,0 +1,93 @@ +import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' +import { StakeDialogPageObject } from '@/features/farm-details/dialogs/stake/StakeDialog.PageObject' +import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { Address } from 'viem' +import { mainnet } from 'viem/chains' +import { ClaimDialogPageObject } from '../../ClaimDialog.PageObject' +import { someObject } from './utils' + +console.log('Global test', someObject) + +test.describe('Claim SKY rewards 2', () => { + let farmDetailsPage: FarmDetailsPageObject + let claimDialog: ClaimDialogPageObject + let account: Address + test.beforeEach(() => { + console.log('Starting test 2') + }) + + // test.beforeEach(async ({ page }) => { + // ;({ account } = await setup(page, { + // blockchain: { + // chainId: mainnet.id, + // blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, + // }, + // initialPage: 'farmDetails', + // initialPageParams: { + // chainId: mainnet.id.toString(), + // address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', + // }, + // account: { + // type: 'connected-random', + // assetBalances: { + // ETH: 1, + // USDS: 10_000, + // }, + // }, + // })) + // await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) + + // farmDetailsPage = new FarmDetailsPageObject(page) + // await farmDetailsPage.clickInfoPanelStakeButtonAction() + // const stakeDialog = new StakeDialogPageObject(page) + // await stakeDialog.fillAmountAction(10_000) + // await stakeDialog.actionsContainer.acceptAllActionsAction(2) + // await stakeDialog.clickBackToFarmAction() + // await fork.progressSimulation(page, 24 * 60 * 60) // 24 hours + // await page.reload() + + // await farmDetailsPage.clickInfoPanelClaimButtonAction() + // claimDialog = new ClaimDialogPageObject(page) + // }) + + test('has correct action plan', async () => { + // await claimDialog.actionsContainer.expectEnabledActionAtIndex(0) + // await claimDialog.actionsContainer.expectActions([{ type: 'claimFarmRewards', asset: 'SKY' }]) + + console.log('Test 2', new Date().toISOString()) + }) + + // test('displays transaction overview', async () => { + // await claimDialog.expectTransactionOverview({ + // reward: { + // // amount is imprecise because of timing issues in e2e tests + // amount: '3,539', + // amountUSD: '$213', + // }, + // }) + // }) + + // test('executes transaction', async () => { + // await claimDialog.actionsContainer.acceptAllActionsAction(1) + + // await claimDialog.expectSuccessPage() + // await claimDialog.clickBackToFarmAction() + + // await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') + // await farmDetailsPage.expectReward({ + // reward: '0', + // rewardUsd: '$0.00', + // }) + // await farmDetailsPage.expectTokenBalance({ + // address: account, + // fork, + // symbol: 'SKY', + // minBalance: 3_525, + // maxBalance: 3_545, + // }) + // await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) + // }) +}) diff --git a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/utils.ts b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/utils.ts new file mode 100644 index 000000000..401e03c3d --- /dev/null +++ b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/utils.ts @@ -0,0 +1,15 @@ +import test from "@playwright/test"; + +test.afterAll(async () => { + console.log('Global after all', new Date().toISOString()) +}) + +// ;([`exit`, `SIGINT`, `SIGUSR1`, `SIGUSR2`, `uncaughtException`, `SIGTERM`].forEach((eventType) => { +// console.log(`Listening for ${eventType}`); +// process.on(eventType, () => { +// console.log(`Received ${eventType}. Exiting...`); +// }); +// })) + +// console.log('Global test') +export const someObject = {} diff --git a/packages/app/src/test/e2e/setup.ts b/packages/app/src/test/e2e/setup.ts index eb1249286..dd25e7a63 100644 --- a/packages/app/src/test/e2e/setup.ts +++ b/packages/app/src/test/e2e/setup.ts @@ -10,6 +10,8 @@ import { AssetsInTests, TOKENS_ON_FORK } from './constants' import { ForkContext } from './forking/setupFork' import { injectFixedDate, injectFlags, injectNetworkConfiguration, injectWalletConfiguration } from './injectSetup' import { generateAccount } from './utils' +import { TenderlyTestnetFactory } from '@marsfoundation/common-testnets' +import { getTestnetContext } from './testnet-cache' export type InjectableWallet = { address: Address } | { privateKey: string } @@ -43,7 +45,13 @@ export type AccountOptions = T extends 'not-connected' } : never + +export interface BlockchainOptions { + chainId: number + blockNumber: bigint +} export interface SetupOptions { + blockchain: BlockchainOptions initialPage: K initialPageParams?: PathParams account: AccountOptions @@ -62,9 +70,10 @@ export type SetupReturn = T extends 'not-connected' // should be called at the beginning of any test export async function setup( page: Page, - forkContext: ForkContext, options: SetupOptions, ): Promise> { + const { client } = await getTestnetContext(options.blockchain) + if (options.skipInjectingNetwork === true) { // if explicitly disabled, do not inject network config abort all network requests to RPC providers await page.route(/alchemy/, (route) => route.abort()) diff --git a/packages/app/src/test/e2e/testnet-cache.ts b/packages/app/src/test/e2e/testnet-cache.ts new file mode 100644 index 000000000..a87f6d8bb --- /dev/null +++ b/packages/app/src/test/e2e/testnet-cache.ts @@ -0,0 +1,52 @@ +import { randomHexId } from "@/utils/random" +import { TenderlyTestnetFactory, TestnetClient } from "@marsfoundation/common-testnets" +import { getEnv } from "@marsfoundation/common-nodejs/env" +import test from "@playwright/test" + +interface TestnetContext { + client: TestnetClient + initialSnapshotId: string + cleanup: () => Promise +} + +const testnetCache = new Map() + +test.afterAll(async () => { + await Promise.all(Array.from(testnetCache.values()).map(({ cleanup }) => cleanup())) +}) + +export async function getTestnetContext({ chainId, blockNumber }: { chainId: number, blockNumber: bigint }) { + const key = `${chainId}-${blockNumber.toString()}` + if (testnetCache.has(key)) { + return testnetCache.get(key)! + } + + const env = getEnv() + const factory = new TenderlyTestnetFactory({ + account: env.string('TENDERLY_ACCOUNT'), + project: env.string('TENDERLY_PROJECT'), + apiKey: env.string('TENDERLY_API_KEY'), + }) + + const testnetId = randomHexId() + const { client, cleanup } = await factory.create({ + id: `test-e2e-${testnetId}`, + displayName: `Spark E2E Testnet ${testnetId}`, + forkChainId: chainId, + originChainId: chainId, + blockNumber, + }) + + const initialSnapshotId = await client.snapshot() + + const context: TestnetContext = { + client, + initialSnapshotId, + cleanup, + } + + testnetCache.set(key, context) + + return context +} + diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cc5e79f56..35d830003 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -216,6 +216,12 @@ importers: '@chromatic-com/storybook': specifier: ^1.5.0 version: 1.5.0(react@18.2.0) + '@marsfoundation/common-nodejs': + specifier: workspace:^ + version: link:../common-nodejs + '@marsfoundation/common-testnets': + specifier: workspace:^ + version: link:../common-testnets '@playwright/test': specifier: ^1.47.2 version: 1.47.2 From 2f2c31fde4add1b28c531f9ce06f5203f3117923 Mon Sep 17 00:00:00 2001 From: yivlad Date: Fri, 13 Dec 2024 13:46:39 +0100 Subject: [PATCH 03/29] Wip --- .../actions/ActionsContainer.PageObject.ts | 15 +- .../claim/e2e/mainnet/ClaimSKY.test-e2e.ts | 74 +++++---- .../claim/e2e/mainnet/ClaimSky2.test-e2e.ts | 93 ----------- .../dialogs/claim/e2e/mainnet/utils.ts | 15 -- .../app/src/test/e2e/forking/setupFork.ts | 145 ------------------ packages/app/src/test/e2e/injectSetup.ts | 22 +-- packages/app/src/test/e2e/setup.ts | 95 +++++------- packages/app/src/test/e2e/testnet-cache.ts | 14 +- 8 files changed, 95 insertions(+), 378 deletions(-) delete mode 100644 packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSky2.test-e2e.ts delete mode 100644 packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/utils.ts delete mode 100644 packages/app/src/test/e2e/forking/setupFork.ts diff --git a/packages/app/src/features/actions/ActionsContainer.PageObject.ts b/packages/app/src/features/actions/ActionsContainer.PageObject.ts index 204f87a41..fc258fc98 100644 --- a/packages/app/src/features/actions/ActionsContainer.PageObject.ts +++ b/packages/app/src/features/actions/ActionsContainer.PageObject.ts @@ -2,7 +2,6 @@ import { Locator, Page, expect } from '@playwright/test' import { formatPercentage } from '@/domain/common/format' import { BasePageObject } from '@/test/e2e/BasePageObject' -import { ForkContext } from '@/test/e2e/forking/setupFork' import { isPage } from '@/test/e2e/utils' import { testIds } from '@/ui/utils/testIds' import { Percentage } from '@marsfoundation/common-universal' @@ -27,27 +26,21 @@ export class ActionsPageObject extends BasePageObject { } // #region actions - async acceptAllActionsAction(expectedNumberOfActions: number, forkContext?: ForkContext): Promise { + async acceptAllActionsAction(expectedNumberOfActions: number, progressSimulation: (seconds: number) => Promise): Promise { for (let index = 0; index < expectedNumberOfActions; index++) { const row = this.region.getByTestId(testIds.actions.row(index)) await row.getByRole('button', { name: actionButtonRegex }).click() // @note: we are setting block timestamp of the next tx (especially after executing all txs) - if (forkContext?.isVnet) { - await expect(row.getByRole('button', { name: actionButtonRegex })).not.toBeVisible() - await forkContext.progressSimulation(this.page, 5) - } + await progressSimulation(5) } } - async acceptActionAtIndex(index: number, forkContext?: ForkContext): Promise { + async acceptActionAtIndex(index: number, progressSimulation: (seconds: number) => Promise): Promise { const row = this.region.getByTestId(testIds.actions.row(index)) await row.getByRole('button', { name: actionButtonRegex }).click() // @note: we are setting block timestamp of the next tx (especially after executing all txs) - if (forkContext?.isVnet) { - await expect(row.getByRole('button', { name: actionButtonRegex })).not.toBeVisible() - await forkContext.progressSimulation(this.page, 5) - } + await progressSimulation(5) } async switchPreferPermitsAction(): Promise { diff --git a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts index 54f8be152..f14cbf37e 100644 --- a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts @@ -3,58 +3,54 @@ import { StakeDialogPageObject } from '@/features/farm-details/dialogs/stake/Sta import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' import { Address } from 'viem' +import { test } from '@playwright/test' import { mainnet } from 'viem/chains' import { ClaimDialogPageObject } from '../../ClaimDialog.PageObject' -import { someObject } from './utils' - -console.log('Global test', someObject) test.describe('Claim SKY rewards', () => { let farmDetailsPage: FarmDetailsPageObject let claimDialog: ClaimDialogPageObject let account: Address + let progressSimulation: (seconds: number) => Promise - // test.beforeEach(async ({ page }) => { - // ;({ account } = await setup(page, { - // blockchain: { - // chainId: mainnet.id, - // blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, - // }, - // initialPage: 'farmDetails', - // initialPageParams: { - // chainId: mainnet.id.toString(), - // address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', - // }, - // account: { - // type: 'connected-random', - // assetBalances: { - // ETH: 1, - // USDS: 10_000, - // }, - // }, - // })) - // await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) + test.beforeEach(async ({ page }) => { + ;({ account, progressSimulation } = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, + }, + initialPage: 'farmDetails', + initialPageParams: { + chainId: mainnet.id.toString(), + address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', + }, + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDS: 10_000, + }, + }, + })) + await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) - // farmDetailsPage = new FarmDetailsPageObject(page) - // await farmDetailsPage.clickInfoPanelStakeButtonAction() - // const stakeDialog = new StakeDialogPageObject(page) - // await stakeDialog.fillAmountAction(10_000) - // await stakeDialog.actionsContainer.acceptAllActionsAction(2) - // await stakeDialog.clickBackToFarmAction() - // await fork.progressSimulation(page, 24 * 60 * 60) // 24 hours - // await page.reload() + farmDetailsPage = new FarmDetailsPageObject(page) + await farmDetailsPage.clickInfoPanelStakeButtonAction() + const stakeDialog = new StakeDialogPageObject(page) + await stakeDialog.fillAmountAction(10_000) + await stakeDialog.actionsContainer.acceptAllActionsAction(2, progressSimulation) + await stakeDialog.clickBackToFarmAction() + await progressSimulation(24 * 60 * 60) // 24 hours + await page.reload() - // await farmDetailsPage.clickInfoPanelClaimButtonAction() - // claimDialog = new ClaimDialogPageObject(page) - // }) + await farmDetailsPage.clickInfoPanelClaimButtonAction() + claimDialog = new ClaimDialogPageObject(page) + }) test('has correct action plan', async () => { - // await claimDialog.actionsContainer.expectEnabledActionAtIndex(0) - // await claimDialog.actionsContainer.expectActions([{ type: 'claimFarmRewards', asset: 'SKY' }]) - - console.log('Test 1', new Date().toISOString()) + await claimDialog.actionsContainer.expectEnabledActionAtIndex(0) + await claimDialog.actionsContainer.expectActions([{ type: 'claimFarmRewards', asset: 'SKY' }]) }) // test('displays transaction overview', async () => { diff --git a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSky2.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSky2.test-e2e.ts deleted file mode 100644 index 134bc56e8..000000000 --- a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSky2.test-e2e.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -import { StakeDialogPageObject } from '@/features/farm-details/dialogs/stake/StakeDialog.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -import { setup } from '@/test/e2e/setup' -import { test } from '@playwright/test' -import { Address } from 'viem' -import { mainnet } from 'viem/chains' -import { ClaimDialogPageObject } from '../../ClaimDialog.PageObject' -import { someObject } from './utils' - -console.log('Global test', someObject) - -test.describe('Claim SKY rewards 2', () => { - let farmDetailsPage: FarmDetailsPageObject - let claimDialog: ClaimDialogPageObject - let account: Address - test.beforeEach(() => { - console.log('Starting test 2') - }) - - // test.beforeEach(async ({ page }) => { - // ;({ account } = await setup(page, { - // blockchain: { - // chainId: mainnet.id, - // blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, - // }, - // initialPage: 'farmDetails', - // initialPageParams: { - // chainId: mainnet.id.toString(), - // address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', - // }, - // account: { - // type: 'connected-random', - // assetBalances: { - // ETH: 1, - // USDS: 10_000, - // }, - // }, - // })) - // await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) - - // farmDetailsPage = new FarmDetailsPageObject(page) - // await farmDetailsPage.clickInfoPanelStakeButtonAction() - // const stakeDialog = new StakeDialogPageObject(page) - // await stakeDialog.fillAmountAction(10_000) - // await stakeDialog.actionsContainer.acceptAllActionsAction(2) - // await stakeDialog.clickBackToFarmAction() - // await fork.progressSimulation(page, 24 * 60 * 60) // 24 hours - // await page.reload() - - // await farmDetailsPage.clickInfoPanelClaimButtonAction() - // claimDialog = new ClaimDialogPageObject(page) - // }) - - test('has correct action plan', async () => { - // await claimDialog.actionsContainer.expectEnabledActionAtIndex(0) - // await claimDialog.actionsContainer.expectActions([{ type: 'claimFarmRewards', asset: 'SKY' }]) - - console.log('Test 2', new Date().toISOString()) - }) - - // test('displays transaction overview', async () => { - // await claimDialog.expectTransactionOverview({ - // reward: { - // // amount is imprecise because of timing issues in e2e tests - // amount: '3,539', - // amountUSD: '$213', - // }, - // }) - // }) - - // test('executes transaction', async () => { - // await claimDialog.actionsContainer.acceptAllActionsAction(1) - - // await claimDialog.expectSuccessPage() - // await claimDialog.clickBackToFarmAction() - - // await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') - // await farmDetailsPage.expectReward({ - // reward: '0', - // rewardUsd: '$0.00', - // }) - // await farmDetailsPage.expectTokenBalance({ - // address: account, - // fork, - // symbol: 'SKY', - // minBalance: 3_525, - // maxBalance: 3_545, - // }) - // await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) - // }) -}) diff --git a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/utils.ts b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/utils.ts deleted file mode 100644 index 401e03c3d..000000000 --- a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/utils.ts +++ /dev/null @@ -1,15 +0,0 @@ -import test from "@playwright/test"; - -test.afterAll(async () => { - console.log('Global after all', new Date().toISOString()) -}) - -// ;([`exit`, `SIGINT`, `SIGUSR1`, `SIGUSR2`, `uncaughtException`, `SIGTERM`].forEach((eventType) => { -// console.log(`Listening for ${eventType}`); -// process.on(eventType, () => { -// console.log(`Received ${eventType}. Exiting...`); -// }); -// })) - -// console.log('Global test') -export const someObject = {} diff --git a/packages/app/src/test/e2e/forking/setupFork.ts b/packages/app/src/test/e2e/forking/setupFork.ts deleted file mode 100644 index a404ece2d..000000000 --- a/packages/app/src/test/e2e/forking/setupFork.ts +++ /dev/null @@ -1,145 +0,0 @@ -import { basePsm3Address } from '@/config/contracts-generated' -import { tenderlyRpcActions } from '@/domain/tenderly/TenderlyRpcActions' -import { Page, test } from '@playwright/test' -import { http, createPublicClient } from 'viem' -import { base, gnosis, mainnet } from 'viem/chains' -import { injectUpdatedDate } from '../injectSetup' -import { processEnv } from '../processEnv' -import { injectFunds } from '../setup' -import { ITestForkService } from './ITestForkService' -import { TestTenderlyForkService } from './TestTenderlyForkService' -import { TestTenderlyVnetService } from './TestTenderlyVnetService' - -export interface ForkContext { - forkUrl: string - forkService: ITestForkService - initialSnapshotId: string - initialSimulationDate: Date - isVnet: boolean - chainId: number - simulationDate: Date - - progressSimulation(page: Page, seconds: number): Promise -} - -// @note: https://github.com/marsfoundation/app#deterministic-time-in-e2e-tests -// used only with tenderly forks (not vnets) -export const _simulationDate = new Date('2024-06-04T10:21:19Z') - -type AvailableChainId = typeof mainnet.id | typeof gnosis.id | typeof base.id -/** - * Fork is shared across the whole test file and is fixed to a single block number. - * It's created once and deleted after all tests are finished but after each test it's reverted to the initial state. - */ -export type SetupForkOptions = - | { - blockNumber: bigint - chainId: AvailableChainId - useTenderlyVnet?: false // using tenderly forks is the default - simulationDateOverride?: Date - } - | { - blockNumber: bigint - chainId: AvailableChainId - useTenderlyVnet: true // vnets are more powerful forks alternative provided by Tenderly - } - -export function setupFork(options: SetupForkOptions): ForkContext { - const apiKey = processEnv('TENDERLY_API_KEY') - const tenderlyAccount = processEnv('TENDERLY_ACCOUNT') - const tenderlyProject = processEnv('TENDERLY_PROJECT') - - const isVnet = !!options.useTenderlyVnet - const chainId = options.chainId - const simulationDateOverride = !isVnet ? options.simulationDateOverride : undefined - - const forkService: ITestForkService = isVnet - ? new TestTenderlyVnetService({ apiKey, account: tenderlyAccount, project: tenderlyProject }) - : new TestTenderlyForkService({ apiKey, tenderlyAccount, tenderlyProject }) - - const simulationDate = simulationDateOverride ?? (!isVnet ? _simulationDate : undefined) // undefined means get it based on block number - - const forkContext: ForkContext = { - forkService, - // we lie to typescript here, because it will be set in beforeAll - forkUrl: undefined as any, - isVnet, - initialSnapshotId: undefined as any, - initialSimulationDate: undefined as any, - simulationDate: simulationDate as any, - chainId, - - async progressSimulation(page: Page, seconds: number): Promise { - this.simulationDate = new Date(this.simulationDate.getTime() + seconds * 1000) - const newTimestamp = Math.floor(this.simulationDate.getTime() / 1000) - - await injectUpdatedDate(page, this.simulationDate) - await tenderlyRpcActions.evmSetNextBlockTimestamp(forkContext.forkUrl, Number(newTimestamp)) - }, - } - // @todo refactor after dropping tenderly fork support - - test.beforeAll(async () => { - forkContext.forkUrl = await forkService.createFork({ - blockNumber: options.blockNumber, - originChainId: chainId, - forkChainId: chainId, - }) - - if (simulationDate) { - const deltaTimeForward = Math.floor((simulationDate.getTime() - Date.now()) / 1000) - await tenderlyRpcActions.evmIncreaseTime(forkContext.forkUrl, deltaTimeForward) - forkContext.simulationDate = simulationDate - forkContext.initialSimulationDate = simulationDate - await tenderlyRpcActions.evmSetNextBlockTimestamp( - forkContext.forkUrl, - Math.floor(simulationDate.getTime() / 1000), - ) - } else { - const client = createPublicClient({ - chain: mainnet, // @todo select chain based on chainId - transport: http(forkContext.forkUrl), - }) - - const latestBlock = await client.getBlock() - // We select the block before the latest one to avoid including the vnet creation block, - // which has the current timestamp instead of the timestamp from the latest block on the chain. - // After this we create a new block with the timestamp of next to the latest block, and the - // forked chain is operable in a normal way. - const block = await client.getBlock({ blockNumber: latestBlock.number - 1n }) - forkContext.simulationDate = new Date(Number(block.timestamp) * 1000) - forkContext.initialSimulationDate = forkContext.simulationDate - await tenderlyRpcActions.evmSetNextBlockTimestamp(forkContext.forkUrl, Number(block.timestamp)) - } - - if (options.chainId === base.id) { - // inject liquidity for psm on base - await injectFunds(forkContext, basePsm3Address[base.id], { - USDS: 10_000_000, - sUSDS: 10_000_000, - USDC: 10_000_000, - }) - } - - forkContext.initialSnapshotId = await tenderlyRpcActions.snapshot(forkContext.forkUrl) - }) - - test.beforeEach(async () => { - await tenderlyRpcActions.revertToSnapshot(forkContext.forkUrl, forkContext.initialSnapshotId) - if (forkContext.isVnet) { - forkContext.simulationDate = forkContext.initialSimulationDate - } - }) - - test.afterAll(async () => { - if (processEnv.optionalBoolean('TENDERLY_PERSIST_FORK')) { - return - } - - if (forkContext.forkUrl) { - await forkService.deleteFork(forkContext.forkUrl) - } - }) - - return forkContext -} diff --git a/packages/app/src/test/e2e/injectSetup.ts b/packages/app/src/test/e2e/injectSetup.ts index a53849fc2..3ca85a714 100644 --- a/packages/app/src/test/e2e/injectSetup.ts +++ b/packages/app/src/test/e2e/injectSetup.ts @@ -8,10 +8,10 @@ import { PLAYWRIGHT_WALLET_PRIVATE_KEY_KEY, } from '@/config/wagmi/config.e2e' -import { http, createPublicClient, zeroAddress } from 'viem' +import { zeroAddress } from 'viem' import { base, mainnet } from 'viem/chains' -import { ForkContext } from './forking/setupFork' import { InjectableWallet } from './setup' +import { TestnetClient } from '@marsfoundation/common-testnets' export async function injectWalletConfiguration(page: Page, wallet: InjectableWallet): Promise { await page.addInitScript( @@ -86,8 +86,8 @@ function overrideDateClass(fakeNow: number): void { // Date.now = () => fakeNow } -export async function injectFlags(page: Page, forkContext: ForkContext): Promise { - const susdsDeployed = await isSudsDeployed(forkContext) +export async function injectFlags(page: Page, testnetClient: TestnetClient): Promise { + const susdsDeployed = await isSudsDeployed(testnetClient) await page.addInitScript( ({ PLAYWRIGHT_USDS_CONTRACTS_NOT_AVAILABLE_KEY, susdsDeployed }) => { @@ -99,22 +99,22 @@ export async function injectFlags(page: Page, forkContext: ForkContext): Promise ) } -async function isSudsDeployed(forkContext: ForkContext): Promise { +// @todo: Consider deleting this after rewriting tests with vnets +async function isSudsDeployed(testnetClient: TestnetClient): Promise { + const chainId = await testnetClient.getChainId() + const susdsAddress = (() => { - if (forkContext.chainId === mainnet.id) { + if (chainId === mainnet.id) { return '0xa3931d71877C0E7a3148CB7Eb4463524FEc27fbD' } - if (forkContext.chainId === base.id) { + if (chainId === base.id) { return '0x5875eEE11Cf8398102FdAd704C9E96607675467a' } return zeroAddress })() - const publicClient = createPublicClient({ - transport: http(forkContext.forkUrl), - }) - const susdsBytecode = await publicClient.getBytecode({ address: susdsAddress }) + const susdsBytecode = await testnetClient.getCode({ address: susdsAddress }) return susdsBytecode !== undefined && susdsBytecode.length > 2 } diff --git a/packages/app/src/test/e2e/setup.ts b/packages/app/src/test/e2e/setup.ts index dd25e7a63..ef7277ce4 100644 --- a/packages/app/src/test/e2e/setup.ts +++ b/packages/app/src/test/e2e/setup.ts @@ -3,14 +3,11 @@ import { generatePath } from 'react-router-dom' import { Address, Hash, parseEther, parseUnits } from 'viem' import { Path, paths } from '@/config/paths' -import { BaseUnitNumber } from '@marsfoundation/common-universal' -import { tenderlyRpcActions } from '@/domain/tenderly/TenderlyRpcActions' import { AssetsInTests, TOKENS_ON_FORK } from './constants' -import { ForkContext } from './forking/setupFork' -import { injectFixedDate, injectFlags, injectNetworkConfiguration, injectWalletConfiguration } from './injectSetup' +import { injectFixedDate, injectFlags, injectNetworkConfiguration, injectUpdatedDate, injectWalletConfiguration } from './injectSetup' import { generateAccount } from './utils' -import { TenderlyTestnetFactory } from '@marsfoundation/common-testnets' +import { getUrlFromClient, TestnetClient } from '@marsfoundation/common-testnets' import { getTestnetContext } from './testnet-cache' export type InjectableWallet = { address: Address } | { privateKey: string } @@ -58,31 +55,27 @@ export interface SetupOptions { skipInjectingNetwork?: boolean } -export type SetupReturn = T extends 'not-connected' - ? { - getLogs: () => string[] - } - : { - account: Address - getLogs: () => string[] - } +export type SetupReturn = (T extends 'not-connected' + ? {} : { account: Address }) & { getLogs: () => string[], progressSimulation: () => Promise } // should be called at the beginning of any test export async function setup( page: Page, options: SetupOptions, ): Promise> { - const { client } = await getTestnetContext(options.blockchain) + const { client, initialSnapshotId } = await getTestnetContext(options.blockchain) + await client.revert(initialSnapshotId) + const blockchainTimestamp = (await client.getBlock()).timestamp if (options.skipInjectingNetwork === true) { // if explicitly disabled, do not inject network config abort all network requests to RPC providers await page.route(/alchemy/, (route) => route.abort()) await page.route(/rpc.ankr/, (route) => route.abort()) } else { - await injectNetworkConfiguration(page, forkContext.forkUrl, forkContext.chainId) + await injectNetworkConfiguration(page, getUrlFromClient(client), options.blockchain.chainId) } - await injectFixedDate(page, forkContext.simulationDate) - await injectFlags(page, forkContext) + await injectFixedDate(page, new Date(Number(blockchainTimestamp) * 1000)) + await injectFlags(page, client) let address: Address | undefined if (options.account.type !== 'not-connected') { @@ -90,13 +83,13 @@ export async function setup( const account = generateAccount({ privateKey: undefined }) address = account.address await injectWalletConfiguration(page, account) - await injectFunds(forkContext, account.address, options.account.assetBalances) + await injectFunds(client, account.address, options.account.assetBalances) } if (options.account.type === 'connected-pkey') { const account = generateAccount({ privateKey: options.account.privateKey }) address = account.address await injectWalletConfiguration(page, account) - await injectFunds(forkContext, account.address, options.account.assetBalances) + await injectFunds(client, account.address, options.account.assetBalances) } if (options.account.type === 'connected-address') { address = options.account.address @@ -114,14 +107,23 @@ export async function setup( await page.goto(buildUrl(options.initialPage, options.initialPageParams)) + async function progressSimulation(seconds: number): Promise { + const currentTimestamp = (await client.getBlock()).timestamp + const progressedTimestamp = currentTimestamp + BigInt(seconds) + await client.setNextBlockTimestamp(progressedTimestamp) + await client.mineBlocks(1n) + await injectUpdatedDate(page, new Date(Number(progressedTimestamp) * 1000)) + } + return { account: address, getLogs: () => errorLogs, + progressSimulation, } as any } export async function injectFunds( - forkContext: ForkContext, + testnetClient: TestnetClient, address: Address, assetBalances?: AssetBalances, ): Promise { @@ -129,45 +131,18 @@ export async function injectFunds( return } - if (forkContext.isVnet) { - const promises = Object.entries(assetBalances).map(async ([tokenName, balance]) => { - if (tokenName === 'ETH' || tokenName === 'XDAI') { - await tenderlyRpcActions.setBalance( - forkContext.forkUrl, - address, - BaseUnitNumber(parseEther(balance.toString())), - ) - } else { - await tenderlyRpcActions.setTokenBalance( - forkContext.forkUrl, - (TOKENS_ON_FORK as any)[forkContext.chainId][tokenName].address, - address, - BaseUnitNumber( - parseUnits(balance.toString(), (TOKENS_ON_FORK as any)[forkContext.chainId][tokenName].decimals), - ), - ) - } - }) - await Promise.all(promises) - } else { - // todo remove once we only support vnets - for (const [tokenName, balance] of Object.entries(assetBalances)) { - if (tokenName === 'ETH' || tokenName === 'XDAI') { - await tenderlyRpcActions.setBalance( - forkContext.forkUrl, - address, - BaseUnitNumber(parseEther(balance.toString())), - ) - } else { - await tenderlyRpcActions.setTokenBalance( - forkContext.forkUrl, - (TOKENS_ON_FORK as any)[forkContext.chainId][tokenName].address, - address, - BaseUnitNumber( - parseUnits(balance.toString(), (TOKENS_ON_FORK as any)[forkContext.chainId][tokenName].decimals), - ), - ) - } + const chainId = await testnetClient.getChainId() + + const promises = Object.entries(assetBalances).map(async ([tokenName, balance]) => { + if (tokenName === 'ETH' || tokenName === 'XDAI') { + await testnetClient.setBalance(address, parseEther(balance.toString())) + } else { + await testnetClient.setErc20Balance( + (TOKENS_ON_FORK as any)[chainId][tokenName].address, + address, + parseUnits(balance.toString(), (TOKENS_ON_FORK as any)[chainId][tokenName].decimals), + ) } - } + }) + await Promise.all(promises) } diff --git a/packages/app/src/test/e2e/testnet-cache.ts b/packages/app/src/test/e2e/testnet-cache.ts index a87f6d8bb..25d1732f4 100644 --- a/packages/app/src/test/e2e/testnet-cache.ts +++ b/packages/app/src/test/e2e/testnet-cache.ts @@ -1,7 +1,6 @@ import { randomHexId } from "@/utils/random" import { TenderlyTestnetFactory, TestnetClient } from "@marsfoundation/common-testnets" import { getEnv } from "@marsfoundation/common-nodejs/env" -import test from "@playwright/test" interface TestnetContext { client: TestnetClient @@ -11,9 +10,16 @@ interface TestnetContext { const testnetCache = new Map() -test.afterAll(async () => { - await Promise.all(Array.from(testnetCache.values()).map(({ cleanup }) => cleanup())) -}) +;([`exit`, `SIGINT`, `SIGUSR1`, `SIGUSR2`, `uncaughtException`, `SIGTERM`].forEach((eventType) => { + process.on(eventType, () => { + const keys = Array.from(testnetCache.keys()) + keys.forEach(key => { + const context = testnetCache.get(key)! + testnetCache.delete(key) + context.cleanup() + }) + }); +})) export async function getTestnetContext({ chainId, blockNumber }: { chainId: number, blockNumber: bigint }) { const key = `${chainId}-${blockNumber.toString()}` From 5346d0dcbfdc57aecf5b2c01165ec4bb0f51ebbf Mon Sep 17 00:00:00 2001 From: yivlad Date: Fri, 13 Dec 2024 17:01:13 +0100 Subject: [PATCH 04/29] Make claim tests deterministic Co-authored-by: Oskar --- .../actions/ActionsContainer.PageObject.ts | 10 +-- .../collateral/CollateralDialog.PageObject.ts | 4 +- .../dialogs/common/Dialog.PageObject.ts | 14 +++-- .../dialogs/e-mode/EModeDialog.PageObject.ts | 4 +- .../farm-details/FarmDetails.PageObject.ts | 22 +++---- .../claim/e2e/mainnet/ClaimSKY.test-e2e.ts | 63 ++++++++++--------- packages/app/src/pages/Borrow.PageObject.ts | 44 ++++++++----- packages/app/src/test/e2e/setup.ts | 35 ++++++++--- 8 files changed, 117 insertions(+), 79 deletions(-) diff --git a/packages/app/src/features/actions/ActionsContainer.PageObject.ts b/packages/app/src/features/actions/ActionsContainer.PageObject.ts index fc258fc98..fdefd612a 100644 --- a/packages/app/src/features/actions/ActionsContainer.PageObject.ts +++ b/packages/app/src/features/actions/ActionsContainer.PageObject.ts @@ -26,21 +26,23 @@ export class ActionsPageObject extends BasePageObject { } // #region actions - async acceptAllActionsAction(expectedNumberOfActions: number, progressSimulation: (seconds: number) => Promise): Promise { + async acceptAllActionsAction(expectedNumberOfActions: number, updateBrowserAndNextBlockTime: (seconds: number) => Promise): Promise { for (let index = 0; index < expectedNumberOfActions; index++) { const row = this.region.getByTestId(testIds.actions.row(index)) await row.getByRole('button', { name: actionButtonRegex }).click() + await expect(row.getByRole('button', { name: actionButtonRegex })).not.toBeVisible() // @note: we are setting block timestamp of the next tx (especially after executing all txs) - await progressSimulation(5) + await updateBrowserAndNextBlockTime(5) } } - async acceptActionAtIndex(index: number, progressSimulation: (seconds: number) => Promise): Promise { + async acceptActionAtIndex(index: number, updateBrowserAndNextBlockTime: (seconds: number) => Promise): Promise { const row = this.region.getByTestId(testIds.actions.row(index)) await row.getByRole('button', { name: actionButtonRegex }).click() + await expect(row.getByRole('button', { name: actionButtonRegex })).not.toBeVisible() // @note: we are setting block timestamp of the next tx (especially after executing all txs) - await progressSimulation(5) + await updateBrowserAndNextBlockTime(5) } async switchPreferPermitsAction(): Promise { diff --git a/packages/app/src/features/dialogs/collateral/CollateralDialog.PageObject.ts b/packages/app/src/features/dialogs/collateral/CollateralDialog.PageObject.ts index 89b0db666..76017af9a 100644 --- a/packages/app/src/features/dialogs/collateral/CollateralDialog.PageObject.ts +++ b/packages/app/src/features/dialogs/collateral/CollateralDialog.PageObject.ts @@ -13,9 +13,9 @@ export class CollateralDialogPageObject extends DialogPageObject { } // #region actions - async setUseAsCollateralAction(assetName: string, setting: CollateralSetting): Promise { + async setUseAsCollateralAction({assetName, setting, updateBrowserAndNextBlockTime}: {assetName: string; setting: CollateralSetting, updateBrowserAndNextBlockTime: () => Promise}): Promise { const actionsContainer = new ActionsPageObject(this.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(1) + await actionsContainer.acceptAllActionsAction(1, updateBrowserAndNextBlockTime) // assertion used for waiting if (setting === 'enabled') { diff --git a/packages/app/src/features/dialogs/common/Dialog.PageObject.ts b/packages/app/src/features/dialogs/common/Dialog.PageObject.ts index d1a7fd7c4..06a51161c 100644 --- a/packages/app/src/features/dialogs/common/Dialog.PageObject.ts +++ b/packages/app/src/features/dialogs/common/Dialog.PageObject.ts @@ -3,9 +3,9 @@ import { Locator, Page, expect } from '@playwright/test' import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' import { BasePageObject } from '@/test/e2e/BasePageObject' import { TestTokenWithValue, expectAssets } from '@/test/e2e/assertions' -import { ForkContext } from '@/test/e2e/forking/setupFork' import { calculateAssetsWorth, isPage } from '@/test/e2e/utils' import { testIds } from '@/ui/utils/testIds' +import { getUrlFromClient, TestnetClient } from '@marsfoundation/common-testnets' export class DialogPageObject extends BasePageObject { public readonly actionsContainer: ActionsPageObject @@ -53,16 +53,20 @@ export class DialogPageObject extends BasePageObject { // #endregion actions // #region assertions - async expectSuccessPage( + async expectSuccessPage({ + tokenWithValue, + testnetClient, + assetWorthOverrides, + }: { tokenWithValue: TestTokenWithValue[], - fork: ForkContext, + testnetClient: TestnetClient, assetWorthOverrides?: Record, - ): Promise { + }): Promise { await expect(this.region.getByText('Congrats, all done!')).toBeVisible() const transformed = tokenWithValue.reduce((acc, { asset, amount: value }) => ({ ...acc, [asset]: value }), {}) - const { assetsWorth } = await calculateAssetsWorth(fork.forkUrl, transformed) + const { assetsWorth } = await calculateAssetsWorth(getUrlFromClient(testnetClient), transformed) const mergedAssetsWorth = { ...assetsWorth, ...assetWorthOverrides } const summary = await this.region.getByTestId(testIds.dialog.success).textContent() diff --git a/packages/app/src/features/dialogs/e-mode/EModeDialog.PageObject.ts b/packages/app/src/features/dialogs/e-mode/EModeDialog.PageObject.ts index 02530e113..9cfff046a 100644 --- a/packages/app/src/features/dialogs/e-mode/EModeDialog.PageObject.ts +++ b/packages/app/src/features/dialogs/e-mode/EModeDialog.PageObject.ts @@ -20,10 +20,10 @@ export class EModeDialogPageObject extends DialogPageObject { await this.locateEModeCategoryTile(eModeCategoryName).click() } - async setEModeAction(eModeCategoryName: EModeCategoryName): Promise { + async setEModeAction({ eModeCategoryName, updateBrowserAndNextBlockTime }: { eModeCategoryName: EModeCategoryName, updateBrowserAndNextBlockTime: () => Promise }): Promise { await this.clickEModeCategoryTileAction(eModeCategoryName) await this.acknowledgeIfRiskIsPresent() - await this.actionsContainer.acceptAllActionsAction(1) + await this.actionsContainer.acceptAllActionsAction(1, updateBrowserAndNextBlockTime) await this.expectEModeSuccessPage(eModeCategoryName) await this.viewInMyPortfolioAction() } diff --git a/packages/app/src/features/farm-details/FarmDetails.PageObject.ts b/packages/app/src/features/farm-details/FarmDetails.PageObject.ts index 54f461cb3..965cfdf4a 100644 --- a/packages/app/src/features/farm-details/FarmDetails.PageObject.ts +++ b/packages/app/src/features/farm-details/FarmDetails.PageObject.ts @@ -1,8 +1,8 @@ import { BasePageObject } from '@/test/e2e/BasePageObject' import { AssetsInTests, TOKENS_ON_FORK } from '@/test/e2e/constants' -import { ForkContext } from '@/test/e2e/forking/setupFork' import { getTokenBalance } from '@/test/e2e/utils' import { testIds } from '@/ui/utils/testIds' +import { getUrlFromClient, TestnetClient } from '@marsfoundation/common-testnets' import { Locator, expect } from '@playwright/test' import { Address } from 'viem' @@ -54,26 +54,24 @@ export class FarmDetailsPageObject extends BasePageObject { } async expectTokenBalance({ - fork, + testnetClient, symbol, - minBalance, - maxBalance, + balance, address, }: { - fork: ForkContext + testnetClient: TestnetClient symbol: AssetsInTests - minBalance: number - maxBalance: number + balance: string address: Address }): Promise { - const token: { address: Address; decimals: number } = (TOKENS_ON_FORK as any)[fork.chainId][symbol] - const balance = await getTokenBalance({ + const chainId = await testnetClient.getChainId() + const token: { address: Address; decimals: number } = (TOKENS_ON_FORK as any)[chainId][symbol] + const actualBalance = await getTokenBalance({ address, - forkUrl: fork.forkUrl, + forkUrl: getUrlFromClient(testnetClient), token, }) - expect(balance.toNumber()).toBeGreaterThanOrEqual(minBalance) - expect(balance.toNumber()).toBeLessThanOrEqual(maxBalance) + expect(balance).toBe(actualBalance.toFixed()) } async expectPointsSyncWarning(): Promise { diff --git a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts index f14cbf37e..eabc75b14 100644 --- a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts @@ -7,15 +7,18 @@ import { Address } from 'viem' import { test } from '@playwright/test' import { mainnet } from 'viem/chains' import { ClaimDialogPageObject } from '../../ClaimDialog.PageObject' +import { TestnetClient } from '@marsfoundation/common-testnets' test.describe('Claim SKY rewards', () => { let farmDetailsPage: FarmDetailsPageObject let claimDialog: ClaimDialogPageObject let account: Address - let progressSimulation: (seconds: number) => Promise + let updateBrowserAndNextBlockTime: (seconds: number) => Promise + let incrementTime: (seconds: number) => Promise + let testnetClient: TestnetClient test.beforeEach(async ({ page }) => { - ;({ account, progressSimulation } = await setup(page, { + ;({ account, testnetClient, updateBrowserAndNextBlockTime, incrementTime } = await setup(page, { blockchain: { chainId: mainnet.id, blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, @@ -39,9 +42,9 @@ test.describe('Claim SKY rewards', () => { await farmDetailsPage.clickInfoPanelStakeButtonAction() const stakeDialog = new StakeDialogPageObject(page) await stakeDialog.fillAmountAction(10_000) - await stakeDialog.actionsContainer.acceptAllActionsAction(2, progressSimulation) + await stakeDialog.actionsContainer.acceptAllActionsAction(2, updateBrowserAndNextBlockTime) await stakeDialog.clickBackToFarmAction() - await progressSimulation(24 * 60 * 60) // 24 hours + await incrementTime(24 * 60 * 60) // 24 hours await page.reload() await farmDetailsPage.clickInfoPanelClaimButtonAction() @@ -53,34 +56,32 @@ test.describe('Claim SKY rewards', () => { await claimDialog.actionsContainer.expectActions([{ type: 'claimFarmRewards', asset: 'SKY' }]) }) - // test('displays transaction overview', async () => { - // await claimDialog.expectTransactionOverview({ - // reward: { - // // amount is imprecise because of timing issues in e2e tests - // amount: '3,539', - // amountUSD: '$213', - // }, - // }) - // }) + test('displays transaction overview', async () => { + await claimDialog.expectTransactionOverview({ + reward: { + amount: '3,539.65', + amountUSD: '$213.35', + }, + }) + }) - // test('executes transaction', async () => { - // await claimDialog.actionsContainer.acceptAllActionsAction(1) + test('executes transaction', async () => { + await claimDialog.actionsContainer.acceptAllActionsAction(1, updateBrowserAndNextBlockTime ) - // await claimDialog.expectSuccessPage() - // await claimDialog.clickBackToFarmAction() + await claimDialog.expectSuccessPage() + await claimDialog.clickBackToFarmAction() - // await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') - // await farmDetailsPage.expectReward({ - // reward: '0', - // rewardUsd: '$0.00', - // }) - // await farmDetailsPage.expectTokenBalance({ - // address: account, - // fork, - // symbol: 'SKY', - // minBalance: 3_525, - // maxBalance: 3_545, - // }) - // await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) - // }) + await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') + await farmDetailsPage.expectReward({ + reward: '0.1', + rewardUsd: '<$0.01', + }) + await farmDetailsPage.expectTokenBalance({ + address: account, + testnetClient, + symbol: 'SKY', + balance: '3539.85599931941984', + }) + await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) + }) }) diff --git a/packages/app/src/pages/Borrow.PageObject.ts b/packages/app/src/pages/Borrow.PageObject.ts index d9047ebd2..57b376f35 100644 --- a/packages/app/src/pages/Borrow.PageObject.ts +++ b/packages/app/src/pages/Borrow.PageObject.ts @@ -3,10 +3,10 @@ import { expect } from '@playwright/test' import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' import { BasePageObject } from '@/test/e2e/BasePageObject' import { TestTokenWithValue, expectAssets } from '@/test/e2e/assertions' -import { ForkContext } from '@/test/e2e/forking/setupFork' import { buildUrl } from '@/test/e2e/setup' import { calculateAssetsWorth } from '@/test/e2e/utils' import { testIds } from '@/ui/utils/testIds' +import { getUrlFromClient, TestnetClient } from '@marsfoundation/common-testnets' export class BorrowPageObject extends BasePageObject { // #region actions @@ -51,17 +51,28 @@ export class BorrowPageObject extends BasePageObject { await this.page.getByRole('link', { name: 'View in Savings' }).click() } - async depositAssetsActions(assetsToDeposit: Record, daiToBorrow: number): Promise { + async depositAssetsActions({ assetsToDeposit, daiToBorrow, updateBrowserAndNextBlockTime }: { assetsToDeposit: Record, daiToBorrow: number, updateBrowserAndNextBlockTime: () => Promise }): Promise { const actionsContainer = new ActionsPageObject(this.locatePanelByHeader('Actions')) - await this.depositWithoutBorrowActions(assetsToDeposit, daiToBorrow, actionsContainer) - await actionsContainer.acceptActionAtIndex(Object.entries(assetsToDeposit).length * 2) // accept final borrow action - } - - async depositWithoutBorrowActions( + await this.depositWithoutBorrowActions({ + assetsToDeposit, + daiToBorrow, + actionsContainer, + updateBrowserAndNextBlockTime, + }) + await actionsContainer.acceptActionAtIndex(Object.entries(assetsToDeposit).length * 2, updateBrowserAndNextBlockTime) // accept final borrow action + } + + async depositWithoutBorrowActions({ + assetsToDeposit, + daiToBorrow, + actionsContainer: _actionsContainer, + updateBrowserAndNextBlockTime, + }: { assetsToDeposit: Record, daiToBorrow?: number, - _actionsContainer?: ActionsPageObject, - ): Promise { + actionsContainer?: ActionsPageObject, + updateBrowserAndNextBlockTime: () => Promise + }): Promise { const actionsContainer = _actionsContainer ?? new ActionsPageObject(this.locatePanelByHeader('Actions')) let index = 0 @@ -74,7 +85,7 @@ export class BorrowPageObject extends BasePageObject { } await this.fillBorrowAssetAction(daiToBorrow ?? 1) // defaulted value won't matter, if only depositing await this.submitAction() - await actionsContainer.acceptAllActionsAction(2 * index) // omitting the borrow action + await actionsContainer.acceptAllActionsAction(2 * index, updateBrowserAndNextBlockTime) // omitting the borrow action await actionsContainer.expectEnabledActionAtIndex(2 * index) } @@ -115,12 +126,17 @@ export class BorrowPageObject extends BasePageObject { await expect(this.page.getByTestId(testIds.easyBorrow.form.usdsBorrowAlert)).toBeVisible() } - async expectSuccessPage( + async expectSuccessPage({ + deposited, + borrowed, + testnetClient, + assetsWorthOverride, + }: { deposited: TestTokenWithValue[], borrowed: TestTokenWithValue, - fork: ForkContext, + testnetClient: TestnetClient, assetsWorthOverride?: Record, - ): Promise { + }): Promise { await expect(this.page.getByText('Congrats, all done!')).toBeVisible() const transformed = [...deposited, borrowed].reduce( @@ -133,7 +149,7 @@ export class BorrowPageObject extends BasePageObject { return assetsWorthOverride } - const { assetsWorth } = await calculateAssetsWorth(fork.forkUrl, transformed) + const { assetsWorth } = await calculateAssetsWorth(getUrlFromClient(testnetClient), transformed) return assetsWorth })() diff --git a/packages/app/src/test/e2e/setup.ts b/packages/app/src/test/e2e/setup.ts index ef7277ce4..0819cc841 100644 --- a/packages/app/src/test/e2e/setup.ts +++ b/packages/app/src/test/e2e/setup.ts @@ -56,7 +56,12 @@ export interface SetupOptions { } export type SetupReturn = (T extends 'not-connected' - ? {} : { account: Address }) & { getLogs: () => string[], progressSimulation: () => Promise } + ? {} : { account: Address }) & { + getLogs: () => string[], + testnetClient: TestnetClient, + updateBrowserAndNextBlockTime: (seconds: number) => Promise, + incrementTime: (seconds: number) => Promise, + } // should be called at the beginning of any test export async function setup( @@ -107,18 +112,30 @@ export async function setup( await page.goto(buildUrl(options.initialPage, options.initialPageParams)) - async function progressSimulation(seconds: number): Promise { - const currentTimestamp = (await client.getBlock()).timestamp + async function updateBrowserAndNextBlockTime(seconds: number): Promise { + const { timestamp: currentTimestamp } = await client.getBlock() + const progressedTimestamp = currentTimestamp + BigInt(seconds) await client.setNextBlockTimestamp(progressedTimestamp) + await injectUpdatedDate(page, new Date(Number(currentTimestamp) * 1000)) + } + + // @note: Sync time in browser with current time on blockchain, + // set next block to be mined timestamp to be 5 seconds more. + await updateBrowserAndNextBlockTime(5) + + async function incrementTime(seconds: number): Promise { + await updateBrowserAndNextBlockTime(seconds) await client.mineBlocks(1n) - await injectUpdatedDate(page, new Date(Number(progressedTimestamp) * 1000)) + await updateBrowserAndNextBlockTime(5) } return { account: address, + testnetClient: client, getLogs: () => errorLogs, - progressSimulation, + updateBrowserAndNextBlockTime, + incrementTime, } as any } @@ -132,8 +149,9 @@ export async function injectFunds( } const chainId = await testnetClient.getChainId() - - const promises = Object.entries(assetBalances).map(async ([tokenName, balance]) => { + for(const [tokenName, balance] of Object.entries(assetBalances)) { + const { timestamp } = await testnetClient.getBlock() + await testnetClient.setNextBlockTimestamp(timestamp + 1n) if (tokenName === 'ETH' || tokenName === 'XDAI') { await testnetClient.setBalance(address, parseEther(balance.toString())) } else { @@ -143,6 +161,5 @@ export async function injectFunds( parseUnits(balance.toString(), (TOKENS_ON_FORK as any)[chainId][tokenName].decimals), ) } - }) - await Promise.all(promises) + } } From 26074fa765e91e6e21db095cf053cf3237f5f822 Mon Sep 17 00:00:00 2001 From: oskarvu Date: Mon, 16 Dec 2024 14:29:56 +0700 Subject: [PATCH 05/29] Fix eslint and biome errors --- .../actions/ActionsContainer.PageObject.ts | 10 ++++-- .../collateral/CollateralDialog.PageObject.ts | 10 +++++- .../dialogs/common/Dialog.PageObject.ts | 8 ++--- .../dialogs/e-mode/EModeDialog.PageObject.ts | 5 ++- .../farm-details/FarmDetails.PageObject.ts | 2 +- .../claim/e2e/mainnet/ClaimSKY.test-e2e.ts | 6 ++-- packages/app/src/pages/Borrow.PageObject.ts | 31 +++++++++++++------ packages/app/src/test/e2e/injectSetup.ts | 2 +- packages/app/src/test/e2e/setup.ts | 28 ++++++++++------- packages/app/src/test/e2e/testnet-cache.ts | 25 ++++++++------- 10 files changed, 80 insertions(+), 47 deletions(-) diff --git a/packages/app/src/features/actions/ActionsContainer.PageObject.ts b/packages/app/src/features/actions/ActionsContainer.PageObject.ts index fdefd612a..c153359a6 100644 --- a/packages/app/src/features/actions/ActionsContainer.PageObject.ts +++ b/packages/app/src/features/actions/ActionsContainer.PageObject.ts @@ -26,7 +26,10 @@ export class ActionsPageObject extends BasePageObject { } // #region actions - async acceptAllActionsAction(expectedNumberOfActions: number, updateBrowserAndNextBlockTime: (seconds: number) => Promise): Promise { + async acceptAllActionsAction( + expectedNumberOfActions: number, + updateBrowserAndNextBlockTime: (seconds: number) => Promise, + ): Promise { for (let index = 0; index < expectedNumberOfActions; index++) { const row = this.region.getByTestId(testIds.actions.row(index)) @@ -37,7 +40,10 @@ export class ActionsPageObject extends BasePageObject { } } - async acceptActionAtIndex(index: number, updateBrowserAndNextBlockTime: (seconds: number) => Promise): Promise { + async acceptActionAtIndex( + index: number, + updateBrowserAndNextBlockTime: (seconds: number) => Promise, + ): Promise { const row = this.region.getByTestId(testIds.actions.row(index)) await row.getByRole('button', { name: actionButtonRegex }).click() await expect(row.getByRole('button', { name: actionButtonRegex })).not.toBeVisible() diff --git a/packages/app/src/features/dialogs/collateral/CollateralDialog.PageObject.ts b/packages/app/src/features/dialogs/collateral/CollateralDialog.PageObject.ts index 76017af9a..001997a65 100644 --- a/packages/app/src/features/dialogs/collateral/CollateralDialog.PageObject.ts +++ b/packages/app/src/features/dialogs/collateral/CollateralDialog.PageObject.ts @@ -13,7 +13,15 @@ export class CollateralDialogPageObject extends DialogPageObject { } // #region actions - async setUseAsCollateralAction({assetName, setting, updateBrowserAndNextBlockTime}: {assetName: string; setting: CollateralSetting, updateBrowserAndNextBlockTime: () => Promise}): Promise { + async setUseAsCollateralAction({ + assetName, + setting, + updateBrowserAndNextBlockTime, + }: { + assetName: string + setting: CollateralSetting + updateBrowserAndNextBlockTime: () => Promise + }): Promise { const actionsContainer = new ActionsPageObject(this.locatePanelByHeader('Actions')) await actionsContainer.acceptAllActionsAction(1, updateBrowserAndNextBlockTime) diff --git a/packages/app/src/features/dialogs/common/Dialog.PageObject.ts b/packages/app/src/features/dialogs/common/Dialog.PageObject.ts index 06a51161c..ce5749236 100644 --- a/packages/app/src/features/dialogs/common/Dialog.PageObject.ts +++ b/packages/app/src/features/dialogs/common/Dialog.PageObject.ts @@ -5,7 +5,7 @@ import { BasePageObject } from '@/test/e2e/BasePageObject' import { TestTokenWithValue, expectAssets } from '@/test/e2e/assertions' import { calculateAssetsWorth, isPage } from '@/test/e2e/utils' import { testIds } from '@/ui/utils/testIds' -import { getUrlFromClient, TestnetClient } from '@marsfoundation/common-testnets' +import { TestnetClient, getUrlFromClient } from '@marsfoundation/common-testnets' export class DialogPageObject extends BasePageObject { public readonly actionsContainer: ActionsPageObject @@ -58,9 +58,9 @@ export class DialogPageObject extends BasePageObject { testnetClient, assetWorthOverrides, }: { - tokenWithValue: TestTokenWithValue[], - testnetClient: TestnetClient, - assetWorthOverrides?: Record, + tokenWithValue: TestTokenWithValue[] + testnetClient: TestnetClient + assetWorthOverrides?: Record }): Promise { await expect(this.region.getByText('Congrats, all done!')).toBeVisible() diff --git a/packages/app/src/features/dialogs/e-mode/EModeDialog.PageObject.ts b/packages/app/src/features/dialogs/e-mode/EModeDialog.PageObject.ts index 9cfff046a..f6d3cd130 100644 --- a/packages/app/src/features/dialogs/e-mode/EModeDialog.PageObject.ts +++ b/packages/app/src/features/dialogs/e-mode/EModeDialog.PageObject.ts @@ -20,7 +20,10 @@ export class EModeDialogPageObject extends DialogPageObject { await this.locateEModeCategoryTile(eModeCategoryName).click() } - async setEModeAction({ eModeCategoryName, updateBrowserAndNextBlockTime }: { eModeCategoryName: EModeCategoryName, updateBrowserAndNextBlockTime: () => Promise }): Promise { + async setEModeAction({ + eModeCategoryName, + updateBrowserAndNextBlockTime, + }: { eModeCategoryName: EModeCategoryName; updateBrowserAndNextBlockTime: () => Promise }): Promise { await this.clickEModeCategoryTileAction(eModeCategoryName) await this.acknowledgeIfRiskIsPresent() await this.actionsContainer.acceptAllActionsAction(1, updateBrowserAndNextBlockTime) diff --git a/packages/app/src/features/farm-details/FarmDetails.PageObject.ts b/packages/app/src/features/farm-details/FarmDetails.PageObject.ts index 965cfdf4a..ba03b6ba1 100644 --- a/packages/app/src/features/farm-details/FarmDetails.PageObject.ts +++ b/packages/app/src/features/farm-details/FarmDetails.PageObject.ts @@ -2,7 +2,7 @@ import { BasePageObject } from '@/test/e2e/BasePageObject' import { AssetsInTests, TOKENS_ON_FORK } from '@/test/e2e/constants' import { getTokenBalance } from '@/test/e2e/utils' import { testIds } from '@/ui/utils/testIds' -import { getUrlFromClient, TestnetClient } from '@marsfoundation/common-testnets' +import { TestnetClient, getUrlFromClient } from '@marsfoundation/common-testnets' import { Locator, expect } from '@playwright/test' import { Address } from 'viem' diff --git a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts index eabc75b14..bd03e8eeb 100644 --- a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts @@ -3,11 +3,11 @@ import { StakeDialogPageObject } from '@/features/farm-details/dialogs/stake/Sta import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' import { setup } from '@/test/e2e/setup' -import { Address } from 'viem' +import { TestnetClient } from '@marsfoundation/common-testnets' import { test } from '@playwright/test' +import { Address } from 'viem' import { mainnet } from 'viem/chains' import { ClaimDialogPageObject } from '../../ClaimDialog.PageObject' -import { TestnetClient } from '@marsfoundation/common-testnets' test.describe('Claim SKY rewards', () => { let farmDetailsPage: FarmDetailsPageObject @@ -66,7 +66,7 @@ test.describe('Claim SKY rewards', () => { }) test('executes transaction', async () => { - await claimDialog.actionsContainer.acceptAllActionsAction(1, updateBrowserAndNextBlockTime ) + await claimDialog.actionsContainer.acceptAllActionsAction(1, updateBrowserAndNextBlockTime) await claimDialog.expectSuccessPage() await claimDialog.clickBackToFarmAction() diff --git a/packages/app/src/pages/Borrow.PageObject.ts b/packages/app/src/pages/Borrow.PageObject.ts index 57b376f35..f5ea41c2b 100644 --- a/packages/app/src/pages/Borrow.PageObject.ts +++ b/packages/app/src/pages/Borrow.PageObject.ts @@ -6,7 +6,7 @@ import { TestTokenWithValue, expectAssets } from '@/test/e2e/assertions' import { buildUrl } from '@/test/e2e/setup' import { calculateAssetsWorth } from '@/test/e2e/utils' import { testIds } from '@/ui/utils/testIds' -import { getUrlFromClient, TestnetClient } from '@marsfoundation/common-testnets' +import { TestnetClient, getUrlFromClient } from '@marsfoundation/common-testnets' export class BorrowPageObject extends BasePageObject { // #region actions @@ -51,7 +51,15 @@ export class BorrowPageObject extends BasePageObject { await this.page.getByRole('link', { name: 'View in Savings' }).click() } - async depositAssetsActions({ assetsToDeposit, daiToBorrow, updateBrowserAndNextBlockTime }: { assetsToDeposit: Record, daiToBorrow: number, updateBrowserAndNextBlockTime: () => Promise }): Promise { + async depositAssetsActions({ + assetsToDeposit, + daiToBorrow, + updateBrowserAndNextBlockTime, + }: { + assetsToDeposit: Record + daiToBorrow: number + updateBrowserAndNextBlockTime: () => Promise + }): Promise { const actionsContainer = new ActionsPageObject(this.locatePanelByHeader('Actions')) await this.depositWithoutBorrowActions({ assetsToDeposit, @@ -59,7 +67,10 @@ export class BorrowPageObject extends BasePageObject { actionsContainer, updateBrowserAndNextBlockTime, }) - await actionsContainer.acceptActionAtIndex(Object.entries(assetsToDeposit).length * 2, updateBrowserAndNextBlockTime) // accept final borrow action + await actionsContainer.acceptActionAtIndex( + Object.entries(assetsToDeposit).length * 2, + updateBrowserAndNextBlockTime, + ) // accept final borrow action } async depositWithoutBorrowActions({ @@ -68,9 +79,9 @@ export class BorrowPageObject extends BasePageObject { actionsContainer: _actionsContainer, updateBrowserAndNextBlockTime, }: { - assetsToDeposit: Record, - daiToBorrow?: number, - actionsContainer?: ActionsPageObject, + assetsToDeposit: Record + daiToBorrow?: number + actionsContainer?: ActionsPageObject updateBrowserAndNextBlockTime: () => Promise }): Promise { const actionsContainer = _actionsContainer ?? new ActionsPageObject(this.locatePanelByHeader('Actions')) @@ -132,10 +143,10 @@ export class BorrowPageObject extends BasePageObject { testnetClient, assetsWorthOverride, }: { - deposited: TestTokenWithValue[], - borrowed: TestTokenWithValue, - testnetClient: TestnetClient, - assetsWorthOverride?: Record, + deposited: TestTokenWithValue[] + borrowed: TestTokenWithValue + testnetClient: TestnetClient + assetsWorthOverride?: Record }): Promise { await expect(this.page.getByText('Congrats, all done!')).toBeVisible() diff --git a/packages/app/src/test/e2e/injectSetup.ts b/packages/app/src/test/e2e/injectSetup.ts index 3ca85a714..9c7ef61ba 100644 --- a/packages/app/src/test/e2e/injectSetup.ts +++ b/packages/app/src/test/e2e/injectSetup.ts @@ -8,10 +8,10 @@ import { PLAYWRIGHT_WALLET_PRIVATE_KEY_KEY, } from '@/config/wagmi/config.e2e' +import { TestnetClient } from '@marsfoundation/common-testnets' import { zeroAddress } from 'viem' import { base, mainnet } from 'viem/chains' import { InjectableWallet } from './setup' -import { TestnetClient } from '@marsfoundation/common-testnets' export async function injectWalletConfiguration(page: Page, wallet: InjectableWallet): Promise { await page.addInitScript( diff --git a/packages/app/src/test/e2e/setup.ts b/packages/app/src/test/e2e/setup.ts index 0819cc841..8868a8285 100644 --- a/packages/app/src/test/e2e/setup.ts +++ b/packages/app/src/test/e2e/setup.ts @@ -3,12 +3,18 @@ import { generatePath } from 'react-router-dom' import { Address, Hash, parseEther, parseUnits } from 'viem' import { Path, paths } from '@/config/paths' +import { TestnetClient, getUrlFromClient } from '@marsfoundation/common-testnets' import { AssetsInTests, TOKENS_ON_FORK } from './constants' -import { injectFixedDate, injectFlags, injectNetworkConfiguration, injectUpdatedDate, injectWalletConfiguration } from './injectSetup' -import { generateAccount } from './utils' -import { getUrlFromClient, TestnetClient } from '@marsfoundation/common-testnets' +import { + injectFixedDate, + injectFlags, + injectNetworkConfiguration, + injectUpdatedDate, + injectWalletConfiguration, +} from './injectSetup' import { getTestnetContext } from './testnet-cache' +import { generateAccount } from './utils' export type InjectableWallet = { address: Address } | { privateKey: string } @@ -42,7 +48,6 @@ export type AccountOptions = T extends 'not-connected' } : never - export interface BlockchainOptions { chainId: number blockNumber: bigint @@ -55,13 +60,12 @@ export interface SetupOptions { skipInjectingNetwork?: boolean } -export type SetupReturn = (T extends 'not-connected' - ? {} : { account: Address }) & { - getLogs: () => string[], - testnetClient: TestnetClient, - updateBrowserAndNextBlockTime: (seconds: number) => Promise, - incrementTime: (seconds: number) => Promise, - } +export type SetupReturn = (T extends 'not-connected' ? {} : { account: Address }) & { + getLogs: () => string[] + testnetClient: TestnetClient + updateBrowserAndNextBlockTime: (seconds: number) => Promise + incrementTime: (seconds: number) => Promise +} // should be called at the beginning of any test export async function setup( @@ -149,7 +153,7 @@ export async function injectFunds( } const chainId = await testnetClient.getChainId() - for(const [tokenName, balance] of Object.entries(assetBalances)) { + for (const [tokenName, balance] of Object.entries(assetBalances)) { const { timestamp } = await testnetClient.getBlock() await testnetClient.setNextBlockTimestamp(timestamp + 1n) if (tokenName === 'ETH' || tokenName === 'XDAI') { diff --git a/packages/app/src/test/e2e/testnet-cache.ts b/packages/app/src/test/e2e/testnet-cache.ts index 25d1732f4..1648e61e8 100644 --- a/packages/app/src/test/e2e/testnet-cache.ts +++ b/packages/app/src/test/e2e/testnet-cache.ts @@ -1,6 +1,6 @@ -import { randomHexId } from "@/utils/random" -import { TenderlyTestnetFactory, TestnetClient } from "@marsfoundation/common-testnets" -import { getEnv } from "@marsfoundation/common-nodejs/env" +import { randomHexId } from '@/utils/random' +import { getEnv } from '@marsfoundation/common-nodejs/env' +import { TenderlyTestnetFactory, TestnetClient } from '@marsfoundation/common-testnets' interface TestnetContext { client: TestnetClient @@ -9,19 +9,21 @@ interface TestnetContext { } const testnetCache = new Map() - -;([`exit`, `SIGINT`, `SIGUSR1`, `SIGUSR2`, `uncaughtException`, `SIGTERM`].forEach((eventType) => { +for (const eventType of ['exit', 'SIGINT', 'SIGUSR1', 'SIGUSR2', 'uncaughtException', 'SIGTERM']) { process.on(eventType, () => { const keys = Array.from(testnetCache.keys()) - keys.forEach(key => { + for (const key of keys) { const context = testnetCache.get(key)! testnetCache.delete(key) - context.cleanup() - }) - }); -})) + return context.cleanup() + } + }) +} -export async function getTestnetContext({ chainId, blockNumber }: { chainId: number, blockNumber: bigint }) { +export async function getTestnetContext({ + chainId, + blockNumber, +}: { chainId: number; blockNumber: bigint }): Promise { const key = `${chainId}-${blockNumber.toString()}` if (testnetCache.has(key)) { return testnetCache.get(key)! @@ -55,4 +57,3 @@ export async function getTestnetContext({ chainId, blockNumber }: { chainId: num return context } - From 1d37353378d6b3d901f5a8427bacff5f5d31f977 Mon Sep 17 00:00:00 2001 From: oskarvu Date: Mon, 16 Dec 2024 14:59:44 +0700 Subject: [PATCH 06/29] Extract account creation to helper function and simplify --- packages/app/src/test/e2e/setup.ts | 60 ++++++++++++++++++------------ 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/packages/app/src/test/e2e/setup.ts b/packages/app/src/test/e2e/setup.ts index 8868a8285..3c95c4ecd 100644 --- a/packages/app/src/test/e2e/setup.ts +++ b/packages/app/src/test/e2e/setup.ts @@ -1,10 +1,9 @@ +import { Path, paths } from '@/config/paths' +import { TestnetClient, getUrlFromClient } from '@marsfoundation/common-testnets' +import { assertNever } from '@marsfoundation/common-universal' import { Page } from '@playwright/test' import { generatePath } from 'react-router-dom' import { Address, Hash, parseEther, parseUnits } from 'viem' - -import { Path, paths } from '@/config/paths' -import { TestnetClient, getUrlFromClient } from '@marsfoundation/common-testnets' - import { AssetsInTests, TOKENS_ON_FORK } from './constants' import { injectFixedDate, @@ -85,26 +84,8 @@ export async function setup( } await injectFixedDate(page, new Date(Number(blockchainTimestamp) * 1000)) await injectFlags(page, client) - let address: Address | undefined - if (options.account.type !== 'not-connected') { - if (options.account.type === 'connected-random') { - const account = generateAccount({ privateKey: undefined }) - address = account.address - await injectWalletConfiguration(page, account) - await injectFunds(client, account.address, options.account.assetBalances) - } - if (options.account.type === 'connected-pkey') { - const account = generateAccount({ privateKey: options.account.privateKey }) - address = account.address - await injectWalletConfiguration(page, account) - await injectFunds(client, account.address, options.account.assetBalances) - } - if (options.account.type === 'connected-address') { - address = options.account.address - await injectWalletConfiguration(page, { address }) - } - } + const address = await setupAccount(page, client, options.account) const errorLogs = [] as string[] @@ -167,3 +148,36 @@ export async function injectFunds( } } } + +async function setupAccount( + page: Page, + client: TestnetClient, + options: AccountOptions, +): Promise
{ + switch (options.type) { + case 'connected-random': { + const account = generateAccount({ privateKey: undefined }) + await injectWalletConfiguration(page, account) + await injectFunds(client, account.address, options.assetBalances) + return account.address + } + + case 'connected-pkey': { + const account = generateAccount({ privateKey: options.privateKey }) + await injectWalletConfiguration(page, account) + await injectFunds(client, account.address, options.assetBalances) + return account.address + } + + case 'connected-address': { + await injectWalletConfiguration(page, { address: options.address }) + return options.address + } + + case 'not-connected': + return undefined + + default: + assertNever(options) + } +} From 0532c677b447e047fb1db49be960e69b8320152e Mon Sep 17 00:00:00 2001 From: yivlad Date: Mon, 16 Dec 2024 11:11:28 +0100 Subject: [PATCH 07/29] Simplify setup function Co-authored-by: Oskar --- .../farm-details/FarmDetails.PageObject.ts | 5 +- .../claim/e2e/mainnet/ClaimSKY.test-e2e.ts | 3 +- .../src/test/e2e/forking/ITestForkService.ts | 10 --- .../e2e/forking/TestTenderlyForkService.ts | 38 --------- .../e2e/forking/TestTenderlyVnetService.ts | 26 ------ packages/app/src/test/e2e/setup.ts | 85 ++++++++++--------- 6 files changed, 50 insertions(+), 117 deletions(-) delete mode 100644 packages/app/src/test/e2e/forking/ITestForkService.ts delete mode 100644 packages/app/src/test/e2e/forking/TestTenderlyForkService.ts delete mode 100644 packages/app/src/test/e2e/forking/TestTenderlyVnetService.ts diff --git a/packages/app/src/features/farm-details/FarmDetails.PageObject.ts b/packages/app/src/features/farm-details/FarmDetails.PageObject.ts index ba03b6ba1..6bed8c3a3 100644 --- a/packages/app/src/features/farm-details/FarmDetails.PageObject.ts +++ b/packages/app/src/features/farm-details/FarmDetails.PageObject.ts @@ -3,6 +3,7 @@ import { AssetsInTests, TOKENS_ON_FORK } from '@/test/e2e/constants' import { getTokenBalance } from '@/test/e2e/utils' import { testIds } from '@/ui/utils/testIds' import { TestnetClient, getUrlFromClient } from '@marsfoundation/common-testnets' +import { NormalizedUnitNumber } from '@marsfoundation/common-universal' import { Locator, expect } from '@playwright/test' import { Address } from 'viem' @@ -61,7 +62,7 @@ export class FarmDetailsPageObject extends BasePageObject { }: { testnetClient: TestnetClient symbol: AssetsInTests - balance: string + balance: NormalizedUnitNumber address: Address }): Promise { const chainId = await testnetClient.getChainId() @@ -71,7 +72,7 @@ export class FarmDetailsPageObject extends BasePageObject { forkUrl: getUrlFromClient(testnetClient), token, }) - expect(balance).toBe(actualBalance.toFixed()) + expect(balance.eq(actualBalance)).toBe(true) } async expectPointsSyncWarning(): Promise { diff --git a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts index bd03e8eeb..2b8f5f4b5 100644 --- a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts @@ -4,6 +4,7 @@ import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' import { setup } from '@/test/e2e/setup' import { TestnetClient } from '@marsfoundation/common-testnets' +import { NormalizedUnitNumber } from '@marsfoundation/common-universal' import { test } from '@playwright/test' import { Address } from 'viem' import { mainnet } from 'viem/chains' @@ -80,7 +81,7 @@ test.describe('Claim SKY rewards', () => { address: account, testnetClient, symbol: 'SKY', - balance: '3539.85599931941984', + balance: NormalizedUnitNumber('3539.85599931941984'), }) await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) }) diff --git a/packages/app/src/test/e2e/forking/ITestForkService.ts b/packages/app/src/test/e2e/forking/ITestForkService.ts deleted file mode 100644 index db9810bf6..000000000 --- a/packages/app/src/test/e2e/forking/ITestForkService.ts +++ /dev/null @@ -1,10 +0,0 @@ -export interface ITestForkService { - createFork: (args: CreateForkArgs) => Promise - deleteFork: (forkUrl: string) => Promise -} - -export interface CreateForkArgs { - originChainId: number - forkChainId: number - blockNumber: bigint -} diff --git a/packages/app/src/test/e2e/forking/TestTenderlyForkService.ts b/packages/app/src/test/e2e/forking/TestTenderlyForkService.ts deleted file mode 100644 index 4b5c7ac4d..000000000 --- a/packages/app/src/test/e2e/forking/TestTenderlyForkService.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { createTenderlyFork } from '@/domain/sandbox/createTenderlyFork' -import { solidFetch } from '@/utils/solidFetch' -import { CreateForkArgs, ITestForkService } from './ITestForkService' - -export class TestTenderlyForkService implements ITestForkService { - private readonly baseUrl = 'https://api.tenderly.co/api/v1' - - constructor(private readonly opts: { apiKey: string; tenderlyAccount: string; tenderlyProject: string }) {} - - private getProjectUrl(): string { - return `${this.baseUrl}/account/${this.opts.tenderlyAccount}/project/${this.opts.tenderlyProject}` - } - - async createFork({ originChainId, forkChainId, blockNumber }: CreateForkArgs): Promise { - const { rpcUrl } = await createTenderlyFork({ - apiUrl: `${this.getProjectUrl()}/fork`, - originChainId, - forkChainId, - namePrefix: 'test-e2e', - blockNumber, - headers: { - 'X-Access-Key': this.opts.apiKey, - }, - }) - - return rpcUrl - } - - async deleteFork(forkUrl: string): Promise { - const forkId = forkUrl.split('/').pop() - await solidFetch(`${this.getProjectUrl()}/fork/${forkId}`, { - method: 'delete', - headers: { - 'X-Access-Key': this.opts.apiKey, - }, - }) - } -} diff --git a/packages/app/src/test/e2e/forking/TestTenderlyVnetService.ts b/packages/app/src/test/e2e/forking/TestTenderlyVnetService.ts deleted file mode 100644 index a0cf5573f..000000000 --- a/packages/app/src/test/e2e/forking/TestTenderlyVnetService.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { randomHexId } from '@/utils/random' -import { TenderlyVnetClient } from '../../../domain/tenderly/TenderlyVnetClient' -import { CreateForkArgs, ITestForkService } from './ITestForkService' - -export class TestTenderlyVnetService implements ITestForkService { - private readonly client: TenderlyVnetClient - - constructor(opts: { apiKey: string; account: string; project: string }) { - this.client = new TenderlyVnetClient(opts) - } - - async createFork({ originChainId, forkChainId, blockNumber }: CreateForkArgs): Promise { - const { rpcUrl } = await this.client.create({ - forkChainId, - originChainId, - blockNumber, - name: `test-e2e-${randomHexId()}`, - }) - - return rpcUrl - } - - async deleteFork(_forkUrl: string): Promise { - // doesn't support deleting vnets yet - } -} diff --git a/packages/app/src/test/e2e/setup.ts b/packages/app/src/test/e2e/setup.ts index 3c95c4ecd..30c346118 100644 --- a/packages/app/src/test/e2e/setup.ts +++ b/packages/app/src/test/e2e/setup.ts @@ -60,7 +60,6 @@ export interface SetupOptions { } export type SetupReturn = (T extends 'not-connected' ? {} : { account: Address }) & { - getLogs: () => string[] testnetClient: TestnetClient updateBrowserAndNextBlockTime: (seconds: number) => Promise incrementTime: (seconds: number) => Promise @@ -71,54 +70,34 @@ export async function setup( page: Page, options: SetupOptions, ): Promise> { - const { client, initialSnapshotId } = await getTestnetContext(options.blockchain) - await client.revert(initialSnapshotId) - const blockchainTimestamp = (await client.getBlock()).timestamp - - if (options.skipInjectingNetwork === true) { - // if explicitly disabled, do not inject network config abort all network requests to RPC providers - await page.route(/alchemy/, (route) => route.abort()) - await page.route(/rpc.ankr/, (route) => route.abort()) - } else { - await injectNetworkConfiguration(page, getUrlFromClient(client), options.blockchain.chainId) - } - await injectFixedDate(page, new Date(Number(blockchainTimestamp) * 1000)) - await injectFlags(page, client) - - const address = await setupAccount(page, client, options.account) - - const errorLogs = [] as string[] - - page.on('console', (message) => { - if (message.type() === 'error') { - errorLogs.push(message.text()) - } - }) + const { client: testnetClient, initialSnapshotId } = await getTestnetContext(options.blockchain) + await testnetClient.revert(initialSnapshotId) + await injectPageSetup({ page, testnetClient, options }) + const address = await setupAccount({ page, testnetClient, options: options.account }) await page.goto(buildUrl(options.initialPage, options.initialPageParams)) async function updateBrowserAndNextBlockTime(seconds: number): Promise { - const { timestamp: currentTimestamp } = await client.getBlock() + const { timestamp: currentTimestamp } = await testnetClient.getBlock() const progressedTimestamp = currentTimestamp + BigInt(seconds) - await client.setNextBlockTimestamp(progressedTimestamp) + await testnetClient.setNextBlockTimestamp(progressedTimestamp) await injectUpdatedDate(page, new Date(Number(currentTimestamp) * 1000)) } - // @note: Sync time in browser with current time on blockchain, - // set next block to be mined timestamp to be 5 seconds more. - await updateBrowserAndNextBlockTime(5) - async function incrementTime(seconds: number): Promise { await updateBrowserAndNextBlockTime(seconds) - await client.mineBlocks(1n) + await testnetClient.mineBlocks(1n) await updateBrowserAndNextBlockTime(5) } + // @note: Sync time in browser with current time on blockchain, + // set next block to be mined timestamp to be 5 seconds more. + await updateBrowserAndNextBlockTime(5) + return { account: address, - testnetClient: client, - getLogs: () => errorLogs, + testnetClient, updateBrowserAndNextBlockTime, incrementTime, } as any @@ -149,23 +128,27 @@ export async function injectFunds( } } -async function setupAccount( - page: Page, - client: TestnetClient, - options: AccountOptions, -): Promise
{ +async function setupAccount({ + page, + testnetClient, + options, +}: { + page: Page + testnetClient: TestnetClient + options: AccountOptions +}): Promise
{ switch (options.type) { case 'connected-random': { const account = generateAccount({ privateKey: undefined }) await injectWalletConfiguration(page, account) - await injectFunds(client, account.address, options.assetBalances) + await injectFunds(testnetClient, account.address, options.assetBalances) return account.address } case 'connected-pkey': { const account = generateAccount({ privateKey: options.privateKey }) await injectWalletConfiguration(page, account) - await injectFunds(client, account.address, options.assetBalances) + await injectFunds(testnetClient, account.address, options.assetBalances) return account.address } @@ -181,3 +164,25 @@ async function setupAccount( assertNever(options) } } + +async function injectPageSetup({ + page, + testnetClient, + options, +}: { + page: Page + testnetClient: TestnetClient + options: SetupOptions +}): Promise { + const blockchainTimestamp = (await testnetClient.getBlock()).timestamp + + if (options.skipInjectingNetwork === true) { + // if explicitly disabled, do not inject network config abort all network requests to RPC providers + await page.route(/alchemy/, (route) => route.abort()) + await page.route(/rpc.ankr/, (route) => route.abort()) + } else { + await injectNetworkConfiguration(page, getUrlFromClient(testnetClient), options.blockchain.chainId) + } + await injectFixedDate(page, new Date(Number(blockchainTimestamp) * 1000)) + await injectFlags(page, testnetClient) +} From f359307cb6ba664703f702835a9636d52e1b254b Mon Sep 17 00:00:00 2001 From: yivlad Date: Tue, 17 Dec 2024 12:36:53 +0100 Subject: [PATCH 08/29] Introduce test context Co-authored-by: Oskar --- .../actions/ActionsContainer.PageObject.ts | 26 +- .../ClaimRewardsDialog.PageObject.ts | 68 ++-- .../collateral/CollateralDialog.PageObject.ts | 76 ++-- .../dialogs/common/Dialog.PageObject.ts | 22 +- .../ConvertStablesDialog.PageObject.ts | 246 ++++++------ .../dialogs/e-mode/EModeDialog.PageObject.ts | 224 +++++------ .../common/e2e/SavingsDialog.PageObject.ts | 302 +++++++-------- .../downgrade/DowngradeDialog.PageObject.ts | 68 ++-- .../upgrade/UpgradeDialog.PageObject.ts | 98 ++--- .../farm-details/FarmDetails.PageObject.ts | 8 +- .../dialogs/claim/ClaimDialog.PageObject.ts | 10 +- .../claim/e2e/mainnet/ClaimSKY.test-e2e.ts | 25 +- .../dialogs/stake/StakeDialog.PageObject.ts | 10 +- .../unstake/UnstakeDialog.PageObject.ts | 292 +++++++-------- packages/app/src/pages/Borrow.PageObject.ts | 352 +++++++++--------- packages/app/src/test/e2e/BasePageObject.ts | 15 +- packages/app/src/test/e2e/setup.ts | 40 +- 17 files changed, 945 insertions(+), 937 deletions(-) diff --git a/packages/app/src/features/actions/ActionsContainer.PageObject.ts b/packages/app/src/features/actions/ActionsContainer.PageObject.ts index c153359a6..0cd3c5e25 100644 --- a/packages/app/src/features/actions/ActionsContainer.PageObject.ts +++ b/packages/app/src/features/actions/ActionsContainer.PageObject.ts @@ -1,19 +1,17 @@ -import { Locator, Page, expect } from '@playwright/test' +import { Locator, expect } from '@playwright/test' import { formatPercentage } from '@/domain/common/format' import { BasePageObject } from '@/test/e2e/BasePageObject' -import { isPage } from '@/test/e2e/utils' +import { TestContext } from '@/test/e2e/setup' import { testIds } from '@/ui/utils/testIds' import { Percentage } from '@marsfoundation/common-universal' import { ActionType } from './logic/types' export class ActionsPageObject extends BasePageObject { - constructor(pageOrLocator: Page | Locator) { - if (isPage(pageOrLocator)) { - super(pageOrLocator) + constructor(testContext: TestContext, locator?: Locator) { + super(testContext, locator) + if (!locator) { this.region = this.locatePanelByHeader('Actions') - } else { - super(pageOrLocator) } } @@ -26,29 +24,23 @@ export class ActionsPageObject extends BasePageObject { } // #region actions - async acceptAllActionsAction( - expectedNumberOfActions: number, - updateBrowserAndNextBlockTime: (seconds: number) => Promise, - ): Promise { + async acceptAllActionsAction(expectedNumberOfActions: number): Promise { for (let index = 0; index < expectedNumberOfActions; index++) { const row = this.region.getByTestId(testIds.actions.row(index)) await row.getByRole('button', { name: actionButtonRegex }).click() await expect(row.getByRole('button', { name: actionButtonRegex })).not.toBeVisible() // @note: we are setting block timestamp of the next tx (especially after executing all txs) - await updateBrowserAndNextBlockTime(5) + await this.testContext.testnetController.progressSimulation(5) } } - async acceptActionAtIndex( - index: number, - updateBrowserAndNextBlockTime: (seconds: number) => Promise, - ): Promise { + async acceptActionAtIndex(index: number): Promise { const row = this.region.getByTestId(testIds.actions.row(index)) await row.getByRole('button', { name: actionButtonRegex }).click() await expect(row.getByRole('button', { name: actionButtonRegex })).not.toBeVisible() // @note: we are setting block timestamp of the next tx (especially after executing all txs) - await updateBrowserAndNextBlockTime(5) + await this.testContext.testnetController.progressSimulation(5) } async switchPreferPermitsAction(): Promise { diff --git a/packages/app/src/features/dialogs/claim-rewards/ClaimRewardsDialog.PageObject.ts b/packages/app/src/features/dialogs/claim-rewards/ClaimRewardsDialog.PageObject.ts index 86f024bd9..ca66a4daf 100644 --- a/packages/app/src/features/dialogs/claim-rewards/ClaimRewardsDialog.PageObject.ts +++ b/packages/app/src/features/dialogs/claim-rewards/ClaimRewardsDialog.PageObject.ts @@ -1,41 +1,41 @@ -import { Locator, Page, expect } from '@playwright/test' +// import { Locator, Page, expect } from '@playwright/test' -import { testIds } from '@/ui/utils/testIds' +// import { testIds } from '@/ui/utils/testIds' -import { DialogPageObject } from '../common/Dialog.PageObject' +// import { DialogPageObject } from '../common/Dialog.PageObject' -export class ClaimRewardsDialogPageObject extends DialogPageObject { - constructor(page: Page) { - super(page, /.*/) - this.region = this.locateDialogByHeader('Claim rewards') - } +// export class ClaimRewardsDialogPageObject extends DialogPageObject { +// constructor(page: Page) { +// super(page, /.*/) +// this.region = this.locateDialogByHeader('Claim rewards') +// } - // #region assertions - async expectRewards(rows: Reward[], locator?: Locator): Promise { - if (!locator) { - locator = this.region - } +// // #region assertions +// async expectRewards(rows: Reward[], locator?: Locator): Promise { +// if (!locator) { +// locator = this.region +// } - for (const [index, row] of rows.entries()) { - const rowLocator = this.page.getByTestId(testIds.dialog.claimRewards.transactionOverview.row(index)).first() - await expect(rowLocator.getByTestId(testIds.dialog.claimRewards.transactionOverview.amount)).toHaveText( - `${row.amount} ${row.tokenSymbol}`, - ) - await expect(rowLocator.getByTestId(testIds.dialog.claimRewards.transactionOverview.amountUSD)).toHaveText( - row.amountUSD, - ) - } - } +// for (const [index, row] of rows.entries()) { +// const rowLocator = this.page.getByTestId(testIds.dialog.claimRewards.transactionOverview.row(index)).first() +// await expect(rowLocator.getByTestId(testIds.dialog.claimRewards.transactionOverview.amount)).toHaveText( +// `${row.amount} ${row.tokenSymbol}`, +// ) +// await expect(rowLocator.getByTestId(testIds.dialog.claimRewards.transactionOverview.amountUSD)).toHaveText( +// row.amountUSD, +// ) +// } +// } - async expectClaimRewardsSuccessPage(rows: Reward[]): Promise { - await expect(this.page.getByRole('heading', { name: 'Congrats, all done!' })).toBeVisible() - await this.expectRewards(rows, this.page.getByTestId(testIds.dialog.success)) - } - // #endregion assertions -} +// async expectClaimRewardsSuccessPage(rows: Reward[]): Promise { +// await expect(this.page.getByRole('heading', { name: 'Congrats, all done!' })).toBeVisible() +// await this.expectRewards(rows, this.page.getByTestId(testIds.dialog.success)) +// } +// // #endregion assertions +// } -interface Reward { - tokenSymbol: string - amount: string - amountUSD: string -} +// interface Reward { +// tokenSymbol: string +// amount: string +// amountUSD: string +// } diff --git a/packages/app/src/features/dialogs/collateral/CollateralDialog.PageObject.ts b/packages/app/src/features/dialogs/collateral/CollateralDialog.PageObject.ts index 001997a65..a85392026 100644 --- a/packages/app/src/features/dialogs/collateral/CollateralDialog.PageObject.ts +++ b/packages/app/src/features/dialogs/collateral/CollateralDialog.PageObject.ts @@ -1,44 +1,44 @@ -import { Page, expect } from '@playwright/test' +// import { Page, expect } from '@playwright/test' -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { testIds } from '@/ui/utils/testIds' +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { testIds } from '@/ui/utils/testIds' -import { CollateralSetting } from '../collateral/types' -import { DialogPageObject } from '../common/Dialog.PageObject' +// import { CollateralSetting } from '../collateral/types' +// import { DialogPageObject } from '../common/Dialog.PageObject' -export class CollateralDialogPageObject extends DialogPageObject { - constructor(page: Page) { - super(page, /.*/) - this.region = this.locateDialogByHeader('Collateral') - } +// export class CollateralDialogPageObject extends DialogPageObject { +// constructor(page: Page) { +// super(page, /.*/) +// this.region = this.locateDialogByHeader('Collateral') +// } - // #region actions - async setUseAsCollateralAction({ - assetName, - setting, - updateBrowserAndNextBlockTime, - }: { - assetName: string - setting: CollateralSetting - updateBrowserAndNextBlockTime: () => Promise - }): Promise { - const actionsContainer = new ActionsPageObject(this.locatePanelByHeader('Actions')) - await actionsContainer.acceptAllActionsAction(1, updateBrowserAndNextBlockTime) +// // #region actions +// async setUseAsCollateralAction({ +// assetName, +// setting, +// updateBrowserAndNextBlockTime, +// }: { +// assetName: string +// setting: CollateralSetting +// updateBrowserAndNextBlockTime: () => Promise +// }): Promise { +// const actionsContainer = new ActionsPageObject(this.locatePanelByHeader('Actions')) +// await actionsContainer.acceptAllActionsAction(1, updateBrowserAndNextBlockTime) - // assertion used for waiting - if (setting === 'enabled') { - await this.expectSetUseAsCollateralSuccessPage(assetName, 'enabled') - } else { - await this.expectSetUseAsCollateralSuccessPage(assetName, 'disabled') - } - } - // #endregion actions +// // assertion used for waiting +// if (setting === 'enabled') { +// await this.expectSetUseAsCollateralSuccessPage(assetName, 'enabled') +// } else { +// await this.expectSetUseAsCollateralSuccessPage(assetName, 'disabled') +// } +// } +// // #endregion actions - // #region assertions - async expectSetUseAsCollateralSuccessPage(assetName: string, setting: CollateralSetting): Promise { - await expect(this.region.getByRole('heading', { name: 'Congrats, all done!' })).toBeVisible() - await expect(this.region.getByTestId(testIds.dialog.success)).toContainText(assetName) - await expect(this.region.getByTestId(testIds.dialog.success)).toContainText(`Collateral ${setting}`) - } - // #endregion assertions -} +// // #region assertions +// async expectSetUseAsCollateralSuccessPage(assetName: string, setting: CollateralSetting): Promise { +// await expect(this.region.getByRole('heading', { name: 'Congrats, all done!' })).toBeVisible() +// await expect(this.region.getByTestId(testIds.dialog.success)).toContainText(assetName) +// await expect(this.region.getByTestId(testIds.dialog.success)).toContainText(`Collateral ${setting}`) +// } +// // #endregion assertions +// } diff --git a/packages/app/src/features/dialogs/common/Dialog.PageObject.ts b/packages/app/src/features/dialogs/common/Dialog.PageObject.ts index ce5749236..2f74c63b3 100644 --- a/packages/app/src/features/dialogs/common/Dialog.PageObject.ts +++ b/packages/app/src/features/dialogs/common/Dialog.PageObject.ts @@ -1,22 +1,24 @@ -import { Locator, Page, expect } from '@playwright/test' +import { Locator, expect } from '@playwright/test' import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' import { BasePageObject } from '@/test/e2e/BasePageObject' import { TestTokenWithValue, expectAssets } from '@/test/e2e/assertions' -import { calculateAssetsWorth, isPage } from '@/test/e2e/utils' +import { TestContext } from '@/test/e2e/setup' +import { calculateAssetsWorth } from '@/test/e2e/utils' import { testIds } from '@/ui/utils/testIds' import { TestnetClient, getUrlFromClient } from '@marsfoundation/common-testnets' +export interface DialogPageObjectParams { + testContext: TestContext + header: RegExp +} + export class DialogPageObject extends BasePageObject { public readonly actionsContainer: ActionsPageObject - constructor(pageOrLocator: Page | Locator, header: RegExp) { - if (isPage(pageOrLocator)) { - super(pageOrLocator) - this.region = this.locateDialogByHeader(header) - } else { - super(pageOrLocator) - } - this.actionsContainer = new ActionsPageObject(this.locatePanelByHeader('Actions')) + constructor({ testContext, header }: DialogPageObjectParams) { + super(testContext) + this.region = this.locateDialogByHeader(header) + this.actionsContainer = new ActionsPageObject(testContext, this.locatePanelByHeader('Actions')) } getDialog(): Locator { diff --git a/packages/app/src/features/dialogs/convert-stables/ConvertStablesDialog.PageObject.ts b/packages/app/src/features/dialogs/convert-stables/ConvertStablesDialog.PageObject.ts index 7441df320..24e7bab72 100644 --- a/packages/app/src/features/dialogs/convert-stables/ConvertStablesDialog.PageObject.ts +++ b/packages/app/src/features/dialogs/convert-stables/ConvertStablesDialog.PageObject.ts @@ -1,123 +1,123 @@ -import { DialogPageObject, TxOverviewWithRoute } from '@/features/dialogs/common/Dialog.PageObject' -import { testIds } from '@/ui/utils/testIds' -import { Locator, Page, expect } from '@playwright/test' - -export class ConvertStablesDialogPageObject extends DialogPageObject { - constructor(page: Page) { - super(page, /Convert Tokens/) - } - - // # region locators - locateAssetInSelector(): Locator { - return this.region.getByTestId(testIds.component.AssetSelector.trigger).first() - } - - locateAssetOutSelector(): Locator { - return this.region.getByTestId(testIds.component.AssetSelector.trigger).last() - } - - locateAssetInInput(): Locator { - return this.region.getByTestId(testIds.component.AssetInput.input).first() - } - - locateAssetOutInput(): Locator { - return this.region.getByTestId(testIds.component.AssetInput.input).last() - } - - locateAssetInMaxButton(): Locator { - return this.region.getByTestId(testIds.component.AssetInput.maxButton).first() - } - - locateAssetOutMaxButton(): Locator { - return this.region.getByTestId(testIds.component.AssetInput.maxButton).last() - } - // #endregion locators - - // #region actions - async selectAssetInAction(asset: string): Promise { - const selector = this.locateAssetInSelector() - await this.selectOptionByLabelAction(selector, asset) - } - - async selectAssetOutAction(asset: string): Promise { - const selector = this.locateAssetOutSelector() - await this.selectOptionByLabelAction(selector, asset) - } - - async openAssetInSelectorAction(): Promise { - await this.locateAssetInSelector().click() - } - - async openAssetOutSelectorAction(): Promise { - await this.locateAssetOutSelector().click() - } - - async fillAmountInAction(amount: number): Promise { - await this.locateAssetInInput().fill(amount.toString()) - } - - async fillAmountOutAction(amount: number): Promise { - await this.locateAssetOutInput().fill(amount.toString()) - } - - async clickMaxAmountInAction(): Promise { - await this.locateAssetInMaxButton().click() - } - - async clickMaxAmountOutAction(): Promise { - await this.locateAssetOutMaxButton().click() - } - - async clickBackToSavingsButton(): Promise { - await this.page.getByRole('button', { name: 'Back to Savings' }).click() - await this.region.waitFor({ - state: 'detached', - }) - } - // #endregion actions - - // #region assertions - async expectSuccessPage(): Promise { - await expect(this.page.getByText('Congrats, all done!')).toBeVisible() - } - - async expectTransactionOverview(transactionOverview: TxOverviewWithRoute): Promise { - await this.expectTransactionOverviewRoute(transactionOverview.routeItems) - await this.expectOutcomeText(transactionOverview.outcome) - if (transactionOverview.outcomeUsd) { - await this.expectOutcomeUsdText(transactionOverview.outcomeUsd) - } - } - - async expectAssetInSelectorSelectedOption(option: string): Promise { - await expect(this.locateAssetInSelector()).toHaveText(option) - } - - async expectAssetOutSelectorSelectedOption(option: string): Promise { - await expect(this.locateAssetOutSelector()).toHaveText(option) - } - - async expectSelectorOptions(options: string[]): Promise { - const selectorOptions = await this.page.getByTestId(testIds.component.AssetSelector.option).all() - expect(selectorOptions).toHaveLength(options.length) - - for (const [index, option] of selectorOptions.entries()) { - await expect(option).toContainText(options[index]!) - } - } - - async expectAssetInInputValue(value: string): Promise { - await expect(this.locateAssetInInput()).toHaveValue(value) - } - - async expectAssetOutInputValue(value: string): Promise { - await expect(this.locateAssetOutInput()).toHaveValue(value) - } - - async expectSingleInputError(error: string): Promise { - const inputError = this.page.getByTestId(testIds.component.AssetInput.error) - await expect(inputError).toHaveCount(1) - await expect(inputError).toHaveText(error) - } - // #endregion assertions -} +// import { DialogPageObject, TxOverviewWithRoute } from '@/features/dialogs/common/Dialog.PageObject' +// import { testIds } from '@/ui/utils/testIds' +// import { Locator, Page, expect } from '@playwright/test' + +// export class ConvertStablesDialogPageObject extends DialogPageObject { +// constructor(page: Page) { +// super(page, /Convert Tokens/) +// } + +// // # region locators +// locateAssetInSelector(): Locator { +// return this.region.getByTestId(testIds.component.AssetSelector.trigger).first() +// } + +// locateAssetOutSelector(): Locator { +// return this.region.getByTestId(testIds.component.AssetSelector.trigger).last() +// } + +// locateAssetInInput(): Locator { +// return this.region.getByTestId(testIds.component.AssetInput.input).first() +// } + +// locateAssetOutInput(): Locator { +// return this.region.getByTestId(testIds.component.AssetInput.input).last() +// } + +// locateAssetInMaxButton(): Locator { +// return this.region.getByTestId(testIds.component.AssetInput.maxButton).first() +// } + +// locateAssetOutMaxButton(): Locator { +// return this.region.getByTestId(testIds.component.AssetInput.maxButton).last() +// } +// // #endregion locators + +// // #region actions +// async selectAssetInAction(asset: string): Promise { +// const selector = this.locateAssetInSelector() +// await this.selectOptionByLabelAction(selector, asset) +// } + +// async selectAssetOutAction(asset: string): Promise { +// const selector = this.locateAssetOutSelector() +// await this.selectOptionByLabelAction(selector, asset) +// } + +// async openAssetInSelectorAction(): Promise { +// await this.locateAssetInSelector().click() +// } + +// async openAssetOutSelectorAction(): Promise { +// await this.locateAssetOutSelector().click() +// } + +// async fillAmountInAction(amount: number): Promise { +// await this.locateAssetInInput().fill(amount.toString()) +// } + +// async fillAmountOutAction(amount: number): Promise { +// await this.locateAssetOutInput().fill(amount.toString()) +// } + +// async clickMaxAmountInAction(): Promise { +// await this.locateAssetInMaxButton().click() +// } + +// async clickMaxAmountOutAction(): Promise { +// await this.locateAssetOutMaxButton().click() +// } + +// async clickBackToSavingsButton(): Promise { +// await this.page.getByRole('button', { name: 'Back to Savings' }).click() +// await this.region.waitFor({ +// state: 'detached', +// }) +// } +// // #endregion actions + +// // #region assertions +// async expectSuccessPage(): Promise { +// await expect(this.page.getByText('Congrats, all done!')).toBeVisible() +// } + +// async expectTransactionOverview(transactionOverview: TxOverviewWithRoute): Promise { +// await this.expectTransactionOverviewRoute(transactionOverview.routeItems) +// await this.expectOutcomeText(transactionOverview.outcome) +// if (transactionOverview.outcomeUsd) { +// await this.expectOutcomeUsdText(transactionOverview.outcomeUsd) +// } +// } + +// async expectAssetInSelectorSelectedOption(option: string): Promise { +// await expect(this.locateAssetInSelector()).toHaveText(option) +// } + +// async expectAssetOutSelectorSelectedOption(option: string): Promise { +// await expect(this.locateAssetOutSelector()).toHaveText(option) +// } + +// async expectSelectorOptions(options: string[]): Promise { +// const selectorOptions = await this.page.getByTestId(testIds.component.AssetSelector.option).all() +// expect(selectorOptions).toHaveLength(options.length) + +// for (const [index, option] of selectorOptions.entries()) { +// await expect(option).toContainText(options[index]!) +// } +// } + +// async expectAssetInInputValue(value: string): Promise { +// await expect(this.locateAssetInInput()).toHaveValue(value) +// } + +// async expectAssetOutInputValue(value: string): Promise { +// await expect(this.locateAssetOutInput()).toHaveValue(value) +// } + +// async expectSingleInputError(error: string): Promise { +// const inputError = this.page.getByTestId(testIds.component.AssetInput.error) +// await expect(inputError).toHaveCount(1) +// await expect(inputError).toHaveText(error) +// } +// // #endregion assertions +// } diff --git a/packages/app/src/features/dialogs/e-mode/EModeDialog.PageObject.ts b/packages/app/src/features/dialogs/e-mode/EModeDialog.PageObject.ts index f6d3cd130..49bdd937f 100644 --- a/packages/app/src/features/dialogs/e-mode/EModeDialog.PageObject.ts +++ b/packages/app/src/features/dialogs/e-mode/EModeDialog.PageObject.ts @@ -1,122 +1,122 @@ -import { EModeCategoryName } from '@/domain/e-mode/types' -import { testIds } from '@/ui/utils/testIds' -import { Locator, Page, expect } from '@playwright/test' -import { DialogPageObject } from '../common/Dialog.PageObject' +// import { EModeCategoryName } from '@/domain/e-mode/types' +// import { testIds } from '@/ui/utils/testIds' +// import { Locator, Page, expect } from '@playwright/test' +// import { DialogPageObject } from '../common/Dialog.PageObject' -export class EModeDialogPageObject extends DialogPageObject { - constructor(page: Page) { - super(page, /.*/) - this.region = this.locateDialogByHeader('Set E-Mode Category') - } +// export class EModeDialogPageObject extends DialogPageObject { +// constructor(page: Page) { +// super(page, /.*/) +// this.region = this.locateDialogByHeader('Set E-Mode Category') +// } - // #region locators - locateEModeCategoryTile(eModeCategoryName: EModeCategoryName): Locator { - return this.region.getByRole('button', { name: eModeCategoryName }) - } - // #endregion locators +// // #region locators +// locateEModeCategoryTile(eModeCategoryName: EModeCategoryName): Locator { +// return this.region.getByRole('button', { name: eModeCategoryName }) +// } +// // #endregion locators - // #region actions - async clickEModeCategoryTileAction(eModeCategoryName: EModeCategoryName): Promise { - await this.locateEModeCategoryTile(eModeCategoryName).click() - } +// // #region actions +// async clickEModeCategoryTileAction(eModeCategoryName: EModeCategoryName): Promise { +// await this.locateEModeCategoryTile(eModeCategoryName).click() +// } - async setEModeAction({ - eModeCategoryName, - updateBrowserAndNextBlockTime, - }: { eModeCategoryName: EModeCategoryName; updateBrowserAndNextBlockTime: () => Promise }): Promise { - await this.clickEModeCategoryTileAction(eModeCategoryName) - await this.acknowledgeIfRiskIsPresent() - await this.actionsContainer.acceptAllActionsAction(1, updateBrowserAndNextBlockTime) - await this.expectEModeSuccessPage(eModeCategoryName) - await this.viewInMyPortfolioAction() - } - // #endregion actions +// async setEModeAction({ +// eModeCategoryName, +// updateBrowserAndNextBlockTime, +// }: { eModeCategoryName: EModeCategoryName; updateBrowserAndNextBlockTime: () => Promise }): Promise { +// await this.clickEModeCategoryTileAction(eModeCategoryName) +// await this.acknowledgeIfRiskIsPresent() +// await this.actionsContainer.acceptAllActionsAction(1, updateBrowserAndNextBlockTime) +// await this.expectEModeSuccessPage(eModeCategoryName) +// await this.viewInMyPortfolioAction() +// } +// // #endregion actions - // #region assertions - async expectEModeCategoryTileStatus( - eModeCategoryName: EModeCategoryName, - status: 'Active' | 'Inactive', - ): Promise { - const tile = this.locateEModeCategoryTile(eModeCategoryName) - await expect(tile).toContainText(status) - } - async expectEModeSuccessPage(eModeCategoryName: EModeCategoryName): Promise { - await expect(this.page.getByTestId(testIds.component.SuccessViewContent)).toContainText('Congrats, all done!') - await expect(this.page.getByTestId(testIds.dialog.success)).toContainText(eModeCategoryName) - await expect(this.page.getByTestId(testIds.dialog.success)).toContainText('Option activated') - } +// // #region assertions +// async expectEModeCategoryTileStatus( +// eModeCategoryName: EModeCategoryName, +// status: 'Active' | 'Inactive', +// ): Promise { +// const tile = this.locateEModeCategoryTile(eModeCategoryName) +// await expect(tile).toContainText(status) +// } +// async expectEModeSuccessPage(eModeCategoryName: EModeCategoryName): Promise { +// await expect(this.page.getByTestId(testIds.component.SuccessViewContent)).toContainText('Congrats, all done!') +// await expect(this.page.getByTestId(testIds.dialog.success)).toContainText(eModeCategoryName) +// await expect(this.page.getByTestId(testIds.dialog.success)).toContainText('Option activated') +// } - async expectEModeTransactionOverview(txOverview: EModeTransactionOverview): Promise { - const overviewPanel = this.locatePanelByHeader('Transaction overview') - await expect(overviewPanel).toBeVisible() - const ids = testIds.dialog.eMode.transactionOverview - const { availableAssets, maxLtv, variant } = txOverview +// async expectEModeTransactionOverview(txOverview: EModeTransactionOverview): Promise { +// const overviewPanel = this.locatePanelByHeader('Transaction overview') +// await expect(overviewPanel).toBeVisible() +// const ids = testIds.dialog.eMode.transactionOverview +// const { availableAssets, maxLtv, variant } = txOverview - if (variant === 'e-mode-no-change') { - if (availableAssets.category) { - await expect(this.page.getByTestId(ids.availableAssets.category)).toHaveText(availableAssets.category) - } - await expect(this.page.getByTestId(ids.availableAssets.assets)).toHaveText(availableAssets.assets) - await expect(this.page.getByTestId(ids.maxLtv.before)).toHaveText(maxLtv) - await expect(this.page.getByTestId(testIds.dialog.healthFactor.before)).toContainText(txOverview.hf) - } +// if (variant === 'e-mode-no-change') { +// if (availableAssets.category) { +// await expect(this.page.getByTestId(ids.availableAssets.category)).toHaveText(availableAssets.category) +// } +// await expect(this.page.getByTestId(ids.availableAssets.assets)).toHaveText(availableAssets.assets) +// await expect(this.page.getByTestId(ids.maxLtv.before)).toHaveText(maxLtv) +// await expect(this.page.getByTestId(testIds.dialog.healthFactor.before)).toContainText(txOverview.hf) +// } - if (variant === 'e-mode-change') { - if (availableAssets.category) { - await expect(this.page.getByTestId(ids.availableAssets.category)).toHaveText(availableAssets.category) - } - await expect(this.page.getByTestId(ids.availableAssets.assets)).toHaveText(availableAssets.assets) - await expect(this.page.getByTestId(ids.maxLtv.before)).toHaveText(maxLtv.before) - await expect(this.page.getByTestId(ids.maxLtv.after)).toHaveText(maxLtv.after) - await expect(this.page.getByTestId(testIds.dialog.healthFactor.before)).toContainText(txOverview.hf.before) - await expect(this.page.getByTestId(testIds.dialog.healthFactor.after)).toContainText(txOverview.hf.after) - } +// if (variant === 'e-mode-change') { +// if (availableAssets.category) { +// await expect(this.page.getByTestId(ids.availableAssets.category)).toHaveText(availableAssets.category) +// } +// await expect(this.page.getByTestId(ids.availableAssets.assets)).toHaveText(availableAssets.assets) +// await expect(this.page.getByTestId(ids.maxLtv.before)).toHaveText(maxLtv.before) +// await expect(this.page.getByTestId(ids.maxLtv.after)).toHaveText(maxLtv.after) +// await expect(this.page.getByTestId(testIds.dialog.healthFactor.before)).toContainText(txOverview.hf.before) +// await expect(this.page.getByTestId(testIds.dialog.healthFactor.after)).toContainText(txOverview.hf.after) +// } - if (variant === 'no-borrow') { - if (availableAssets.category) { - await expect(this.page.getByTestId(ids.availableAssets.category)).toHaveText(availableAssets.category) - } - await expect(this.page.getByTestId(ids.availableAssets.assets)).toHaveText(availableAssets.assets) - await expect(this.page.getByTestId(ids.maxLtv.before)).toHaveText(maxLtv.before) - await expect(this.page.getByTestId(ids.maxLtv.after)).toHaveText(maxLtv.after) - } - } - // #endregion assertions -} +// if (variant === 'no-borrow') { +// if (availableAssets.category) { +// await expect(this.page.getByTestId(ids.availableAssets.category)).toHaveText(availableAssets.category) +// } +// await expect(this.page.getByTestId(ids.availableAssets.assets)).toHaveText(availableAssets.assets) +// await expect(this.page.getByTestId(ids.maxLtv.before)).toHaveText(maxLtv.before) +// await expect(this.page.getByTestId(ids.maxLtv.after)).toHaveText(maxLtv.after) +// } +// } +// // #endregion assertions +// } -type EModeTransactionOverview = - | { - variant: 'e-mode-change' - availableAssets: { - category?: string - assets: string - } - maxLtv: { - before: string - after: string - } - hf: { - before: string - after: string - } - } - | { - variant: 'e-mode-no-change' - availableAssets: { - category?: string - assets: string - } - maxLtv: string - hf: string - } - | { - variant: 'no-borrow' - availableAssets: { - category?: string - assets: string - } - maxLtv: { - before: string - after: string - } - } +// type EModeTransactionOverview = +// | { +// variant: 'e-mode-change' +// availableAssets: { +// category?: string +// assets: string +// } +// maxLtv: { +// before: string +// after: string +// } +// hf: { +// before: string +// after: string +// } +// } +// | { +// variant: 'e-mode-no-change' +// availableAssets: { +// category?: string +// assets: string +// } +// maxLtv: string +// hf: string +// } +// | { +// variant: 'no-borrow' +// availableAssets: { +// category?: string +// assets: string +// } +// maxLtv: { +// before: string +// after: string +// } +// } diff --git a/packages/app/src/features/dialogs/savings/common/e2e/SavingsDialog.PageObject.ts b/packages/app/src/features/dialogs/savings/common/e2e/SavingsDialog.PageObject.ts index 83363a605..8575aec90 100644 --- a/packages/app/src/features/dialogs/savings/common/e2e/SavingsDialog.PageObject.ts +++ b/packages/app/src/features/dialogs/savings/common/e2e/SavingsDialog.PageObject.ts @@ -1,151 +1,151 @@ -import { getBalance, getTokenBalance } from '@/test/e2e/utils' -import { testIds } from '@/ui/utils/testIds' -import { Locator, Page, expect } from '@playwright/test' -import { Address } from 'viem' -import { DialogPageObject, TxOverviewWithRoute } from '../../../common/Dialog.PageObject' - -export class SavingsDialogPageObject extends DialogPageObject { - private readonly type: 'deposit' | 'withdraw' | 'send' - - constructor({ page, type }: { page: Page; type: 'deposit' | 'withdraw' | 'send' }) { - super( - page, - new RegExp(`${type === 'deposit' ? 'Deposit to' : type === 'send' ? 'Send from' : 'Withdraw from'} Savings`), - ) - this.type = type - } - - // # region locators - locateUpgradeSwitch(): Locator { - return this.page.getByTestId(testIds.dialog.savings.upgradeSwitch) - } - // #endregion locators - - // #region actions - async clickBackToSavingsButton(): Promise { - await this.page.getByRole('button', { name: 'Back to Savings' }).click() - await this.region.waitFor({ - state: 'detached', - }) - } - - async fillReceiverAction(receiver: string): Promise { - await this.region.getByTestId(testIds.component.AddressInput.input).fill(receiver) - } - - // #endregion actions - - // #region assertions - async expectDiscrepancyWarning(discrepancy: string): Promise { - const explanation = - this.type === 'deposit' - ? 'The final amount received may be less than the deposit amount by up to' - : 'You may be charged more than the withdraw amount by up to' - await expect( - this.region.getByText(`Market fluctuations can impact your transaction value. ${explanation} ${discrepancy}`), - ).toBeVisible() - } - - async expectTransactionOverviewToBeVisible(): Promise { - await expect(this.locatePanelByHeader('Transaction overview')).toBeVisible() - } - - async expectAssetSelectorOptions(options: string[]): Promise { - const selectorOptions = await this.page.getByTestId(testIds.component.AssetSelector.option).all() - expect(selectorOptions).toHaveLength(options.length) - - for (const [index, option] of selectorOptions.entries()) { - await expect(option).toContainText(options[index]!) - } - } - - async expectTransactionOverview(transactionOverview: TransactionOverview): Promise { - const panel = this.locatePanelByHeader('Transaction overview') - await expect(panel).toBeVisible() - - for (const [index, [label, value]] of transactionOverview.entries()) { - const row = panel.getByTestId(testIds.dialog.depositSavings.transactionDetailsRow(index)) - await expect(row).toBeVisible() - await expect(row).toContainText(label) - await expect(row).toContainText(value) - } - } - - async expectNativeRouteTransactionOverview(transactionOverview: NativeRouteTransactionOverview): Promise { - const panel = this.locatePanelByHeader('Transaction overview') - await expect(panel).toBeVisible() - const savingsTxOverviewTestIds = testIds.dialog.savings.transactionOverview - - if (transactionOverview.apy) { - const apyValue = panel.getByTestId(savingsTxOverviewTestIds.apy.value) - const apyDescription = panel.getByTestId(savingsTxOverviewTestIds.apy.description) - await expect(apyValue).toContainText(transactionOverview.apy.value) - await expect(apyDescription).toContainText(transactionOverview.apy.description) - } - - await this.expectTransactionOverviewRoute(transactionOverview.routeItems) - if (transactionOverview.badgeTokens) { - await this.expectSkyBadgeForTokens(transactionOverview.badgeTokens) - } - await this.expectOutcomeText(transactionOverview.outcome) - } - - async expectSuccessPage(): Promise { - // for now we only check if the success message is visible - await expect(this.page.getByText('Congrats, all done!')).toBeVisible() - } - - async expectAddressInputError(error: string): Promise { - await expect(this.page.getByTestId(testIds.component.AddressInput.error)).toHaveText(error) - } - - async expectReceiverIsSmartContractWarning(): Promise { - await expect(this.page.getByTestId(testIds.dialog.savings.send.addressIsSmartContractWarning)).toBeVisible() - } - - async expectReceiverBalance({ - forkUrl, - receiver, - expectedBalance, - }: { - forkUrl: string - receiver: Address - expectedBalance: number - }): Promise { - const currentBalance = await getBalance({ forkUrl, address: receiver }) - expect(currentBalance.isEqualTo(expectedBalance)).toBe(true) - } - - async expectReceiverTokenBalance({ - forkUrl, - receiver, - token, - expectedBalance, - }: { - forkUrl: string - receiver: Address - token: { address: Address; decimals: number } - expectedBalance: number - }): Promise { - const currentTokenBalance = await getTokenBalance({ forkUrl, address: receiver, token }) - expect(currentTokenBalance.isEqualTo(expectedBalance)).toBe(true) - } - - expectUpgradeSwitchToBeHidden(): Promise { - return expect(this.locateUpgradeSwitch()).toBeHidden() - } - - clickUpgradeSwitch(): Promise { - return this.locateUpgradeSwitch().click() - } - // #endregion assertions -} - -type TransactionOverview = [string, string][] - -interface NativeRouteTransactionOverview extends TxOverviewWithRoute { - apy?: { - value: string - description: string - } -} +// import { getBalance, getTokenBalance } from '@/test/e2e/utils' +// import { testIds } from '@/ui/utils/testIds' +// import { Locator, Page, expect } from '@playwright/test' +// import { Address } from 'viem' +// import { DialogPageObject, TxOverviewWithRoute } from '../../../common/Dialog.PageObject' + +// export class SavingsDialogPageObject extends DialogPageObject { +// private readonly type: 'deposit' | 'withdraw' | 'send' + +// constructor({ page, type }: { page: Page; type: 'deposit' | 'withdraw' | 'send' }) { +// super( +// page, +// new RegExp(`${type === 'deposit' ? 'Deposit to' : type === 'send' ? 'Send from' : 'Withdraw from'} Savings`), +// ) +// this.type = type +// } + +// // # region locators +// locateUpgradeSwitch(): Locator { +// return this.page.getByTestId(testIds.dialog.savings.upgradeSwitch) +// } +// // #endregion locators + +// // #region actions +// async clickBackToSavingsButton(): Promise { +// await this.page.getByRole('button', { name: 'Back to Savings' }).click() +// await this.region.waitFor({ +// state: 'detached', +// }) +// } + +// async fillReceiverAction(receiver: string): Promise { +// await this.region.getByTestId(testIds.component.AddressInput.input).fill(receiver) +// } + +// // #endregion actions + +// // #region assertions +// async expectDiscrepancyWarning(discrepancy: string): Promise { +// const explanation = +// this.type === 'deposit' +// ? 'The final amount received may be less than the deposit amount by up to' +// : 'You may be charged more than the withdraw amount by up to' +// await expect( +// this.region.getByText(`Market fluctuations can impact your transaction value. ${explanation} ${discrepancy}`), +// ).toBeVisible() +// } + +// async expectTransactionOverviewToBeVisible(): Promise { +// await expect(this.locatePanelByHeader('Transaction overview')).toBeVisible() +// } + +// async expectAssetSelectorOptions(options: string[]): Promise { +// const selectorOptions = await this.page.getByTestId(testIds.component.AssetSelector.option).all() +// expect(selectorOptions).toHaveLength(options.length) + +// for (const [index, option] of selectorOptions.entries()) { +// await expect(option).toContainText(options[index]!) +// } +// } + +// async expectTransactionOverview(transactionOverview: TransactionOverview): Promise { +// const panel = this.locatePanelByHeader('Transaction overview') +// await expect(panel).toBeVisible() + +// for (const [index, [label, value]] of transactionOverview.entries()) { +// const row = panel.getByTestId(testIds.dialog.depositSavings.transactionDetailsRow(index)) +// await expect(row).toBeVisible() +// await expect(row).toContainText(label) +// await expect(row).toContainText(value) +// } +// } + +// async expectNativeRouteTransactionOverview(transactionOverview: NativeRouteTransactionOverview): Promise { +// const panel = this.locatePanelByHeader('Transaction overview') +// await expect(panel).toBeVisible() +// const savingsTxOverviewTestIds = testIds.dialog.savings.transactionOverview + +// if (transactionOverview.apy) { +// const apyValue = panel.getByTestId(savingsTxOverviewTestIds.apy.value) +// const apyDescription = panel.getByTestId(savingsTxOverviewTestIds.apy.description) +// await expect(apyValue).toContainText(transactionOverview.apy.value) +// await expect(apyDescription).toContainText(transactionOverview.apy.description) +// } + +// await this.expectTransactionOverviewRoute(transactionOverview.routeItems) +// if (transactionOverview.badgeTokens) { +// await this.expectSkyBadgeForTokens(transactionOverview.badgeTokens) +// } +// await this.expectOutcomeText(transactionOverview.outcome) +// } + +// async expectSuccessPage(): Promise { +// // for now we only check if the success message is visible +// await expect(this.page.getByText('Congrats, all done!')).toBeVisible() +// } + +// async expectAddressInputError(error: string): Promise { +// await expect(this.page.getByTestId(testIds.component.AddressInput.error)).toHaveText(error) +// } + +// async expectReceiverIsSmartContractWarning(): Promise { +// await expect(this.page.getByTestId(testIds.dialog.savings.send.addressIsSmartContractWarning)).toBeVisible() +// } + +// async expectReceiverBalance({ +// forkUrl, +// receiver, +// expectedBalance, +// }: { +// forkUrl: string +// receiver: Address +// expectedBalance: number +// }): Promise { +// const currentBalance = await getBalance({ forkUrl, address: receiver }) +// expect(currentBalance.isEqualTo(expectedBalance)).toBe(true) +// } + +// async expectReceiverTokenBalance({ +// forkUrl, +// receiver, +// token, +// expectedBalance, +// }: { +// forkUrl: string +// receiver: Address +// token: { address: Address; decimals: number } +// expectedBalance: number +// }): Promise { +// const currentTokenBalance = await getTokenBalance({ forkUrl, address: receiver, token }) +// expect(currentTokenBalance.isEqualTo(expectedBalance)).toBe(true) +// } + +// expectUpgradeSwitchToBeHidden(): Promise { +// return expect(this.locateUpgradeSwitch()).toBeHidden() +// } + +// clickUpgradeSwitch(): Promise { +// return this.locateUpgradeSwitch().click() +// } +// // #endregion assertions +// } + +// type TransactionOverview = [string, string][] + +// interface NativeRouteTransactionOverview extends TxOverviewWithRoute { +// apy?: { +// value: string +// description: string +// } +// } diff --git a/packages/app/src/features/dialogs/savings/migrate/downgrade/DowngradeDialog.PageObject.ts b/packages/app/src/features/dialogs/savings/migrate/downgrade/DowngradeDialog.PageObject.ts index 2cca555d3..98640b5db 100644 --- a/packages/app/src/features/dialogs/savings/migrate/downgrade/DowngradeDialog.PageObject.ts +++ b/packages/app/src/features/dialogs/savings/migrate/downgrade/DowngradeDialog.PageObject.ts @@ -1,38 +1,38 @@ -import { DialogPageObject, TxOverviewWithRoute } from '@/features/dialogs/common/Dialog.PageObject' -import { testIds } from '@/ui/utils/testIds' -import { Page, expect } from '@playwright/test' +// import { DialogPageObject, TxOverviewWithRoute } from '@/features/dialogs/common/Dialog.PageObject' +// import { testIds } from '@/ui/utils/testIds' +// import { Page, expect } from '@playwright/test' -export class DowngradeDialogPageObject extends DialogPageObject { - constructor(page: Page) { - super(page, /Downgrade/) - } +// export class DowngradeDialogPageObject extends DialogPageObject { +// constructor(page: Page) { +// super(page, /Downgrade/) +// } - // #region actions - async clickBackToSavingsButton(): Promise { - await this.page.getByRole('button', { name: 'Back to Savings' }).click() - await this.region.waitFor({ - state: 'detached', - }) - } - // #endregion actions +// // #region actions +// async clickBackToSavingsButton(): Promise { +// await this.page.getByRole('button', { name: 'Back to Savings' }).click() +// await this.region.waitFor({ +// state: 'detached', +// }) +// } +// // #endregion actions - // #region assertions - async expectTransactionOverview(transactionOverview: TxOverviewWithRoute): Promise { - await this.expectTransactionOverviewRoute(transactionOverview.routeItems) - if (transactionOverview.badgeTokens) { - await this.expectSkyBadgeForTokens(transactionOverview.badgeTokens) - } - await this.expectOutcomeText(transactionOverview.outcome) - } +// // #region assertions +// async expectTransactionOverview(transactionOverview: TxOverviewWithRoute): Promise { +// await this.expectTransactionOverviewRoute(transactionOverview.routeItems) +// if (transactionOverview.badgeTokens) { +// await this.expectSkyBadgeForTokens(transactionOverview.badgeTokens) +// } +// await this.expectOutcomeText(transactionOverview.outcome) +// } - async expectDowngradeSuccessPage({ - token, - amount, - usdValue, - }: { token: string; amount: string; usdValue: string }): Promise { - await expect(this.region.getByText('Congrats, all done!')).toBeVisible() - const summary = await this.region.getByTestId(testIds.dialog.success).textContent() - await expect(summary).toMatch(`${token}${amount} ${usdValue}`) - } - // #endregion assertions -} +// async expectDowngradeSuccessPage({ +// token, +// amount, +// usdValue, +// }: { token: string; amount: string; usdValue: string }): Promise { +// await expect(this.region.getByText('Congrats, all done!')).toBeVisible() +// const summary = await this.region.getByTestId(testIds.dialog.success).textContent() +// await expect(summary).toMatch(`${token}${amount} ${usdValue}`) +// } +// // #endregion assertions +// } diff --git a/packages/app/src/features/dialogs/savings/migrate/upgrade/UpgradeDialog.PageObject.ts b/packages/app/src/features/dialogs/savings/migrate/upgrade/UpgradeDialog.PageObject.ts index 3fcb75986..3e59932a2 100644 --- a/packages/app/src/features/dialogs/savings/migrate/upgrade/UpgradeDialog.PageObject.ts +++ b/packages/app/src/features/dialogs/savings/migrate/upgrade/UpgradeDialog.PageObject.ts @@ -1,56 +1,56 @@ -import { DialogPageObject, TxOverviewWithRoute } from '@/features/dialogs/common/Dialog.PageObject' -import { testIds } from '@/ui/utils/testIds' -import { Page, expect } from '@playwright/test' +// import { DialogPageObject, TxOverviewWithRoute } from '@/features/dialogs/common/Dialog.PageObject' +// import { testIds } from '@/ui/utils/testIds' +// import { Page, expect } from '@playwright/test' -export class UpgradeDialogPageObject extends DialogPageObject { - constructor(page: Page) { - super(page, /Upgrade/) - } +// export class UpgradeDialogPageObject extends DialogPageObject { +// constructor(page: Page) { +// super(page, /Upgrade/) +// } - // #region actions - async clickBackToSavingsButton(): Promise { - await this.page.getByRole('button', { name: 'Back to Savings' }).click() - await this.region.waitFor({ - state: 'detached', - }) - } - // #endregion actions +// // #region actions +// async clickBackToSavingsButton(): Promise { +// await this.page.getByRole('button', { name: 'Back to Savings' }).click() +// await this.region.waitFor({ +// state: 'detached', +// }) +// } +// // #endregion actions - // #region assertions - async expectTransactionOverview(transactionOverview: UpgradeTxOverview): Promise { - const panel = this.locatePanelByHeader('Transaction overview') - await expect(panel).toBeVisible() - const savingsTxOverviewTestIds = testIds.dialog.savings.transactionOverview +// // #region assertions +// async expectTransactionOverview(transactionOverview: UpgradeTxOverview): Promise { +// const panel = this.locatePanelByHeader('Transaction overview') +// await expect(panel).toBeVisible() +// const savingsTxOverviewTestIds = testIds.dialog.savings.transactionOverview - if (transactionOverview.apyChange) { - const currentApyValue = panel.getByTestId(savingsTxOverviewTestIds.apyChange.before) - const updatedApyValue = panel.getByTestId(savingsTxOverviewTestIds.apyChange.after) - await expect(currentApyValue).toContainText(transactionOverview.apyChange.current) - await expect(updatedApyValue).toContainText(transactionOverview.apyChange.updated) - } +// if (transactionOverview.apyChange) { +// const currentApyValue = panel.getByTestId(savingsTxOverviewTestIds.apyChange.before) +// const updatedApyValue = panel.getByTestId(savingsTxOverviewTestIds.apyChange.after) +// await expect(currentApyValue).toContainText(transactionOverview.apyChange.current) +// await expect(updatedApyValue).toContainText(transactionOverview.apyChange.updated) +// } - await this.expectTransactionOverviewRoute(transactionOverview.routeItems) - if (transactionOverview.badgeTokens) { - await this.expectSkyBadgeForTokens(transactionOverview.badgeTokens) - } - await this.expectOutcomeText(transactionOverview.outcome) - } +// await this.expectTransactionOverviewRoute(transactionOverview.routeItems) +// if (transactionOverview.badgeTokens) { +// await this.expectSkyBadgeForTokens(transactionOverview.badgeTokens) +// } +// await this.expectOutcomeText(transactionOverview.outcome) +// } - async expectUpgradeSuccessPage({ - token, - amount, - usdValue, - }: { token: string; amount: string; usdValue: string }): Promise { - await expect(this.region.getByText('Congrats, all done!')).toBeVisible() - const summary = await this.region.getByTestId(testIds.dialog.success).textContent() - await expect(summary).toMatch(`${token}${amount} ${usdValue}`) - } - // #endregion assertions -} +// async expectUpgradeSuccessPage({ +// token, +// amount, +// usdValue, +// }: { token: string; amount: string; usdValue: string }): Promise { +// await expect(this.region.getByText('Congrats, all done!')).toBeVisible() +// const summary = await this.region.getByTestId(testIds.dialog.success).textContent() +// await expect(summary).toMatch(`${token}${amount} ${usdValue}`) +// } +// // #endregion assertions +// } -interface UpgradeTxOverview extends TxOverviewWithRoute { - apyChange?: { - current: string - updated: string - } -} +// interface UpgradeTxOverview extends TxOverviewWithRoute { +// apyChange?: { +// current: string +// updated: string +// } +// } diff --git a/packages/app/src/features/farm-details/FarmDetails.PageObject.ts b/packages/app/src/features/farm-details/FarmDetails.PageObject.ts index 6bed8c3a3..57f5925c9 100644 --- a/packages/app/src/features/farm-details/FarmDetails.PageObject.ts +++ b/packages/app/src/features/farm-details/FarmDetails.PageObject.ts @@ -2,7 +2,7 @@ import { BasePageObject } from '@/test/e2e/BasePageObject' import { AssetsInTests, TOKENS_ON_FORK } from '@/test/e2e/constants' import { getTokenBalance } from '@/test/e2e/utils' import { testIds } from '@/ui/utils/testIds' -import { TestnetClient, getUrlFromClient } from '@marsfoundation/common-testnets' +import { getUrlFromClient } from '@marsfoundation/common-testnets' import { NormalizedUnitNumber } from '@marsfoundation/common-universal' import { Locator, expect } from '@playwright/test' import { Address } from 'viem' @@ -55,21 +55,19 @@ export class FarmDetailsPageObject extends BasePageObject { } async expectTokenBalance({ - testnetClient, symbol, balance, address, }: { - testnetClient: TestnetClient symbol: AssetsInTests balance: NormalizedUnitNumber address: Address }): Promise { - const chainId = await testnetClient.getChainId() + const chainId = await this.testContext.testnetController.client.getChainId() const token: { address: Address; decimals: number } = (TOKENS_ON_FORK as any)[chainId][symbol] const actualBalance = await getTokenBalance({ address, - forkUrl: getUrlFromClient(testnetClient), + forkUrl: getUrlFromClient(this.testContext.testnetController.client), token, }) expect(balance.eq(actualBalance)).toBe(true) diff --git a/packages/app/src/features/farm-details/dialogs/claim/ClaimDialog.PageObject.ts b/packages/app/src/features/farm-details/dialogs/claim/ClaimDialog.PageObject.ts index 1bfcedfb6..4ef286f78 100644 --- a/packages/app/src/features/farm-details/dialogs/claim/ClaimDialog.PageObject.ts +++ b/packages/app/src/features/farm-details/dialogs/claim/ClaimDialog.PageObject.ts @@ -1,10 +1,14 @@ import { DialogPageObject } from '@/features/dialogs/common/Dialog.PageObject' +import { TestContext } from '@/test/e2e/setup' import { testIds } from '@/ui/utils/testIds' -import { Page, expect } from '@playwright/test' +import { expect } from '@playwright/test' export class ClaimDialogPageObject extends DialogPageObject { - constructor(page: Page) { - super(page, /Claim/) + constructor(testContext: TestContext) { + super({ + testContext, + header: /Claim/, + }) } // #region actions diff --git a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts index 2b8f5f4b5..bb17be487 100644 --- a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts @@ -3,7 +3,6 @@ import { StakeDialogPageObject } from '@/features/farm-details/dialogs/stake/Sta import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' import { setup } from '@/test/e2e/setup' -import { TestnetClient } from '@marsfoundation/common-testnets' import { NormalizedUnitNumber } from '@marsfoundation/common-universal' import { test } from '@playwright/test' import { Address } from 'viem' @@ -14,12 +13,9 @@ test.describe('Claim SKY rewards', () => { let farmDetailsPage: FarmDetailsPageObject let claimDialog: ClaimDialogPageObject let account: Address - let updateBrowserAndNextBlockTime: (seconds: number) => Promise - let incrementTime: (seconds: number) => Promise - let testnetClient: TestnetClient test.beforeEach(async ({ page }) => { - ;({ account, testnetClient, updateBrowserAndNextBlockTime, incrementTime } = await setup(page, { + const testContext = await setup(page, { blockchain: { chainId: mainnet.id, blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, @@ -36,20 +32,22 @@ test.describe('Claim SKY rewards', () => { USDS: 10_000, }, }, - })) + }) + account = testContext.account + await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) - farmDetailsPage = new FarmDetailsPageObject(page) + farmDetailsPage = new FarmDetailsPageObject(testContext) await farmDetailsPage.clickInfoPanelStakeButtonAction() - const stakeDialog = new StakeDialogPageObject(page) + const stakeDialog = new StakeDialogPageObject(testContext) await stakeDialog.fillAmountAction(10_000) - await stakeDialog.actionsContainer.acceptAllActionsAction(2, updateBrowserAndNextBlockTime) + await stakeDialog.actionsContainer.acceptAllActionsAction(2) await stakeDialog.clickBackToFarmAction() - await incrementTime(24 * 60 * 60) // 24 hours + await testContext.testnetController.progressSimulationAndMine(24 * 60 * 60) // 24 hours await page.reload() await farmDetailsPage.clickInfoPanelClaimButtonAction() - claimDialog = new ClaimDialogPageObject(page) + claimDialog = new ClaimDialogPageObject(testContext) }) test('has correct action plan', async () => { @@ -67,7 +65,7 @@ test.describe('Claim SKY rewards', () => { }) test('executes transaction', async () => { - await claimDialog.actionsContainer.acceptAllActionsAction(1, updateBrowserAndNextBlockTime) + await claimDialog.actionsContainer.acceptAllActionsAction(1) await claimDialog.expectSuccessPage() await claimDialog.clickBackToFarmAction() @@ -79,9 +77,8 @@ test.describe('Claim SKY rewards', () => { }) await farmDetailsPage.expectTokenBalance({ address: account, - testnetClient, symbol: 'SKY', - balance: NormalizedUnitNumber('3539.85599931941984'), + balance: NormalizedUnitNumber('3539.69212658060522'), }) await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) }) diff --git a/packages/app/src/features/farm-details/dialogs/stake/StakeDialog.PageObject.ts b/packages/app/src/features/farm-details/dialogs/stake/StakeDialog.PageObject.ts index 546a238af..dc39e160e 100644 --- a/packages/app/src/features/farm-details/dialogs/stake/StakeDialog.PageObject.ts +++ b/packages/app/src/features/farm-details/dialogs/stake/StakeDialog.PageObject.ts @@ -1,10 +1,14 @@ import { DialogPageObject } from '@/features/dialogs/common/Dialog.PageObject' +import { TestContext } from '@/test/e2e/setup' import { testIds } from '@/ui/utils/testIds' -import { Page, expect } from '@playwright/test' +import { expect } from '@playwright/test' export class StakeDialogPageObject extends DialogPageObject { - constructor(page: Page) { - super(page, /Deposit/) + constructor(testContext: TestContext) { + super({ + testContext, + header: /Deposit/, + }) } // #region actions diff --git a/packages/app/src/features/farm-details/dialogs/unstake/UnstakeDialog.PageObject.ts b/packages/app/src/features/farm-details/dialogs/unstake/UnstakeDialog.PageObject.ts index d338b5a4c..3c701638f 100644 --- a/packages/app/src/features/farm-details/dialogs/unstake/UnstakeDialog.PageObject.ts +++ b/packages/app/src/features/farm-details/dialogs/unstake/UnstakeDialog.PageObject.ts @@ -1,146 +1,146 @@ -import { DialogPageObject } from '@/features/dialogs/common/Dialog.PageObject' -import { testIds } from '@/ui/utils/testIds' -import { Page, expect } from '@playwright/test' - -export class UnstakeDialogPageObject extends DialogPageObject { - constructor(page: Page) { - super(page, /Withdraw/) - } - - // #region actions - async clickBackToFarmAction(): Promise { - await this.page.getByRole('button', { name: 'Back to Farm' }).click() - await this.region.waitFor({ - state: 'detached', - }) - } - - async clickExitFarmSwitchAction(): Promise { - await this.page.getByTestId(testIds.farmDetails.unstakeDialog.exitFarmSwitchPanel.switch).click() - } - // - - // #region assertions - async expectExitFarmSwitchToBeHidden(): Promise { - await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.exitFarmSwitchPanel.switch)).toBeHidden() - } - - async expectExitFarmSwitchToBeVisible(): Promise { - await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.exitFarmSwitchPanel.switch)).toBeVisible() - } - - async expectExitFarmSwitchNotChecked(): Promise { - await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.exitFarmSwitchPanel.switch)).not.toBeChecked() - } - - async expectExitFarmSwitchReward({ min, max, token, usdValue }: Reward): Promise { - const regexp = /~([\d,\.]+) (\w+) \(~\$([\d,\.]+)\)/ - const rewardRowText = await this.page - .getByTestId(testIds.farmDetails.unstakeDialog.exitFarmSwitchPanel.reward) - .textContent() - - const match = rewardRowText?.match(regexp) - expect(match).toBeDefined() - - const [rewardAmount, rewardToken, rewardUsdValue] = match!.slice(1) - const rewardNumber = Number(rewardAmount?.replace(/,/g, '')) - expect(rewardNumber).toBeGreaterThanOrEqual(min) - expect(rewardNumber).toBeLessThanOrEqual(max) - expect(rewardToken).toBe(token) - expect(rewardUsdValue).toContain(usdValue) - } - - async expectRoutesOverview(route: Route): Promise { - const routeItemTestIds = testIds.dialog.transactionOverview.routeItem - const txOverviewTestIds = testIds.farmDetails.unstakeDialog.transactionOverview - - for (let i = 0; i < route.swaps.length; i++) { - // i + 1 because the first item in route is farm itself - await expect(this.page.getByTestId(routeItemTestIds.tokenWithAmount(i + 1))).toContainText( - route.swaps[i]!.tokenAmount, - ) - await expect(this.page.getByTestId(routeItemTestIds.tokenUsdValue(i + 1))).toContainText( - route.swaps[i]!.tokenUsdValue, - ) - } - - await expect(this.page.getByTestId(txOverviewTestIds.route.farm.farmName)).toContainText(route.farm.upperText) - await expect(this.page.getByTestId(txOverviewTestIds.route.farm.stakingToken)).toContainText(route.farm.lowerText) - } - - async expectTransactionOverview({ route, outcome }: TransactionOverview): Promise { - await this.expectRoutesOverview(route) - await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.outcome)).toContainText( - outcome, - ) - } - - async expectExitTransactionOverview({ route, reward, outcome }: ExitTransactionOverview): Promise { - await this.expectRoutesOverview(route) - - await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.outcome)).toContainText( - outcome.amount, - ) - await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.outcome)).toContainText( - outcome.token, - ) - await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.outcomeUsd)).toContainText( - outcome.usdValue, - ) - - const rewardAmount = await this.page - .getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.rewardOutcome) - .textContent() - const rewardNumber = Number(rewardAmount?.replace(/[^0-9.]/g, '')) - - expect(rewardNumber).toBeGreaterThanOrEqual(reward.min) - expect(rewardNumber).toBeLessThanOrEqual(reward.max) - await expect( - this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.rewardOutcome), - ).toContainText(reward.token) - await expect( - this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.rewardOutcomeUsd), - ).toContainText(reward.usdValue) - } - - async expectSuccessPage(): Promise { - // for now we only check if the success message is visible - await expect(this.page.getByText('Congrats, all done!')).toBeVisible() - } - // #endregion -} - -export interface Reward { - min: number - max: number - token: string - usdValue: string -} - -export interface Outome { - amount: string - token: string - usdValue: string -} - -export interface Route { - swaps: { - tokenAmount: string - tokenUsdValue: string - }[] - farm: { - upperText: string - lowerText: string - } -} - -export interface TransactionOverview { - route: Route - outcome: string -} - -export interface ExitTransactionOverview { - route: Route - reward: Reward - outcome: Outome -} +// import { DialogPageObject } from '@/features/dialogs/common/Dialog.PageObject' +// import { testIds } from '@/ui/utils/testIds' +// import { Page, expect } from '@playwright/test' + +// export class UnstakeDialogPageObject extends DialogPageObject { +// constructor(page: Page) { +// super(page, /Withdraw/) +// } + +// // #region actions +// async clickBackToFarmAction(): Promise { +// await this.page.getByRole('button', { name: 'Back to Farm' }).click() +// await this.region.waitFor({ +// state: 'detached', +// }) +// } + +// async clickExitFarmSwitchAction(): Promise { +// await this.page.getByTestId(testIds.farmDetails.unstakeDialog.exitFarmSwitchPanel.switch).click() +// } +// // + +// // #region assertions +// async expectExitFarmSwitchToBeHidden(): Promise { +// await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.exitFarmSwitchPanel.switch)).toBeHidden() +// } + +// async expectExitFarmSwitchToBeVisible(): Promise { +// await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.exitFarmSwitchPanel.switch)).toBeVisible() +// } + +// async expectExitFarmSwitchNotChecked(): Promise { +// await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.exitFarmSwitchPanel.switch)).not.toBeChecked() +// } + +// async expectExitFarmSwitchReward({ min, max, token, usdValue }: Reward): Promise { +// const regexp = /~([\d,\.]+) (\w+) \(~\$([\d,\.]+)\)/ +// const rewardRowText = await this.page +// .getByTestId(testIds.farmDetails.unstakeDialog.exitFarmSwitchPanel.reward) +// .textContent() + +// const match = rewardRowText?.match(regexp) +// expect(match).toBeDefined() + +// const [rewardAmount, rewardToken, rewardUsdValue] = match!.slice(1) +// const rewardNumber = Number(rewardAmount?.replace(/,/g, '')) +// expect(rewardNumber).toBeGreaterThanOrEqual(min) +// expect(rewardNumber).toBeLessThanOrEqual(max) +// expect(rewardToken).toBe(token) +// expect(rewardUsdValue).toContain(usdValue) +// } + +// async expectRoutesOverview(route: Route): Promise { +// const routeItemTestIds = testIds.dialog.transactionOverview.routeItem +// const txOverviewTestIds = testIds.farmDetails.unstakeDialog.transactionOverview + +// for (let i = 0; i < route.swaps.length; i++) { +// // i + 1 because the first item in route is farm itself +// await expect(this.page.getByTestId(routeItemTestIds.tokenWithAmount(i + 1))).toContainText( +// route.swaps[i]!.tokenAmount, +// ) +// await expect(this.page.getByTestId(routeItemTestIds.tokenUsdValue(i + 1))).toContainText( +// route.swaps[i]!.tokenUsdValue, +// ) +// } + +// await expect(this.page.getByTestId(txOverviewTestIds.route.farm.farmName)).toContainText(route.farm.upperText) +// await expect(this.page.getByTestId(txOverviewTestIds.route.farm.stakingToken)).toContainText(route.farm.lowerText) +// } + +// async expectTransactionOverview({ route, outcome }: TransactionOverview): Promise { +// await this.expectRoutesOverview(route) +// await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.outcome)).toContainText( +// outcome, +// ) +// } + +// async expectExitTransactionOverview({ route, reward, outcome }: ExitTransactionOverview): Promise { +// await this.expectRoutesOverview(route) + +// await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.outcome)).toContainText( +// outcome.amount, +// ) +// await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.outcome)).toContainText( +// outcome.token, +// ) +// await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.outcomeUsd)).toContainText( +// outcome.usdValue, +// ) + +// const rewardAmount = await this.page +// .getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.rewardOutcome) +// .textContent() +// const rewardNumber = Number(rewardAmount?.replace(/[^0-9.]/g, '')) + +// expect(rewardNumber).toBeGreaterThanOrEqual(reward.min) +// expect(rewardNumber).toBeLessThanOrEqual(reward.max) +// await expect( +// this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.rewardOutcome), +// ).toContainText(reward.token) +// await expect( +// this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.rewardOutcomeUsd), +// ).toContainText(reward.usdValue) +// } + +// async expectSuccessPage(): Promise { +// // for now we only check if the success message is visible +// await expect(this.page.getByText('Congrats, all done!')).toBeVisible() +// } +// // #endregion +// } + +// export interface Reward { +// min: number +// max: number +// token: string +// usdValue: string +// } + +// export interface Outome { +// amount: string +// token: string +// usdValue: string +// } + +// export interface Route { +// swaps: { +// tokenAmount: string +// tokenUsdValue: string +// }[] +// farm: { +// upperText: string +// lowerText: string +// } +// } + +// export interface TransactionOverview { +// route: Route +// outcome: string +// } + +// export interface ExitTransactionOverview { +// route: Route +// reward: Reward +// outcome: Outome +// } diff --git a/packages/app/src/pages/Borrow.PageObject.ts b/packages/app/src/pages/Borrow.PageObject.ts index f5ea41c2b..1884a53c8 100644 --- a/packages/app/src/pages/Borrow.PageObject.ts +++ b/packages/app/src/pages/Borrow.PageObject.ts @@ -1,176 +1,176 @@ -import { expect } from '@playwright/test' - -import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -import { BasePageObject } from '@/test/e2e/BasePageObject' -import { TestTokenWithValue, expectAssets } from '@/test/e2e/assertions' -import { buildUrl } from '@/test/e2e/setup' -import { calculateAssetsWorth } from '@/test/e2e/utils' -import { testIds } from '@/ui/utils/testIds' -import { TestnetClient, getUrlFromClient } from '@marsfoundation/common-testnets' - -export class BorrowPageObject extends BasePageObject { - // #region actions - async fillDepositAssetAction(index: number, asset: string, amount: number): Promise { - const inputGroup = this.page - .getByTestId(testIds.easyBorrow.form.deposits) - .getByTestId(testIds.component.MultiAssetSelector.group) - .nth(index) - - const selector = inputGroup.getByTestId(testIds.component.AssetSelector.trigger) - await this.selectOptionByLabelAction(selector, asset) - - await inputGroup.getByRole('textbox').fill(amount.toString()) - } - - async selectBorrowAction(assetName: string): Promise { - const borrowSelector = this.page - .getByTestId(testIds.easyBorrow.form.borrow) - .getByTestId(testIds.component.AssetSelector.trigger) - await this.selectOptionByLabelAction(borrowSelector, assetName) - } - - async fillBorrowAssetAction(amount: number): Promise { - const borrowForm = this.page.getByTestId(testIds.easyBorrow.form.borrow) - - await borrowForm.getByRole('textbox').fill(amount.toString()) - } - - async submitAction(): Promise { - await this.page.locator('main').getByRole('button', { name: 'Borrow' }).click() - } - - async addNewDepositAssetAction(): Promise { - return this.page.getByRole('button', { name: 'Add more' }).click() - } - - async viewInMyPortfolioAction(): Promise { - await this.page.getByRole('link', { name: 'View in portfolio' }).click() - } - - async viewInSavingsAction(): Promise { - await this.page.getByRole('link', { name: 'View in Savings' }).click() - } - - async depositAssetsActions({ - assetsToDeposit, - daiToBorrow, - updateBrowserAndNextBlockTime, - }: { - assetsToDeposit: Record - daiToBorrow: number - updateBrowserAndNextBlockTime: () => Promise - }): Promise { - const actionsContainer = new ActionsPageObject(this.locatePanelByHeader('Actions')) - await this.depositWithoutBorrowActions({ - assetsToDeposit, - daiToBorrow, - actionsContainer, - updateBrowserAndNextBlockTime, - }) - await actionsContainer.acceptActionAtIndex( - Object.entries(assetsToDeposit).length * 2, - updateBrowserAndNextBlockTime, - ) // accept final borrow action - } - - async depositWithoutBorrowActions({ - assetsToDeposit, - daiToBorrow, - actionsContainer: _actionsContainer, - updateBrowserAndNextBlockTime, - }: { - assetsToDeposit: Record - daiToBorrow?: number - actionsContainer?: ActionsPageObject - updateBrowserAndNextBlockTime: () => Promise - }): Promise { - const actionsContainer = _actionsContainer ?? new ActionsPageObject(this.locatePanelByHeader('Actions')) - - let index = 0 - for (const [asset, amount] of Object.entries(assetsToDeposit)) { - if (index !== 0) { - await this.addNewDepositAssetAction() - } - await this.fillDepositAssetAction(index, asset, amount) - index++ - } - await this.fillBorrowAssetAction(daiToBorrow ?? 1) // defaulted value won't matter, if only depositing - await this.submitAction() - await actionsContainer.acceptAllActionsAction(2 * index, updateBrowserAndNextBlockTime) // omitting the borrow action - await actionsContainer.expectEnabledActionAtIndex(2 * index) - } - - async goToEasyBorrowAction(): Promise { - await this.page.goto(buildUrl('easyBorrow')) - } - // #endregion actions - - // #region assertions - async expectLtv(ltv: string): Promise { - await expect(this.page.getByTestId(testIds.easyBorrow.form.ltv)).toHaveText(ltv) - } - - async expectHealthFactor(hf: string): Promise { - const locator = this.page.getByTestId(testIds.component.HealthFactorGauge.value).nth(0) // is rendered twice because of mobile view - await expect(locator).toHaveText(hf) - } - - async expectAssetInputInvalid(errorText: string): Promise { - const locator = this.page.getByTestId(testIds.component.AssetInput.error) - await expect(locator).toHaveText(errorText) - } - - async expectAssetNotListedInDepositSelector(asset: string): Promise { - const depositSelector = this.page - .getByTestId(testIds.easyBorrow.form.deposits) - .getByTestId(testIds.component.MultiAssetSelector.group) - .getByTestId(testIds.component.AssetSelector.trigger) - await depositSelector.click() - await expect(this.page.getByRole('listbox')).not.toHaveText(asset) - } - - async expectBorrowButtonActive(): Promise { - await expect(this.page.locator('main').getByRole('button', { name: 'Borrow' })).toBeEnabled() - } - - async expectUsdsBorrowAlert(): Promise { - await expect(this.page.getByTestId(testIds.easyBorrow.form.usdsBorrowAlert)).toBeVisible() - } - - async expectSuccessPage({ - deposited, - borrowed, - testnetClient, - assetsWorthOverride, - }: { - deposited: TestTokenWithValue[] - borrowed: TestTokenWithValue - testnetClient: TestnetClient - assetsWorthOverride?: Record - }): Promise { - await expect(this.page.getByText('Congrats, all done!')).toBeVisible() - - const transformed = [...deposited, borrowed].reduce( - (acc, { asset, amount: value }) => ({ ...acc, [asset]: value }), - {}, - ) - - const assetsWorth = await (async () => { - if (assetsWorthOverride) { - return assetsWorthOverride - } - - const { assetsWorth } = await calculateAssetsWorth(getUrlFromClient(testnetClient), transformed) - return assetsWorth - })() - - if (deposited.length > 0) { - const depositSummary = await this.page.getByTestId(testIds.easyBorrow.success.deposited).textContent() - expectAssets(depositSummary!, deposited, assetsWorth) - } - - const borrowSummary = await this.page.getByTestId(testIds.easyBorrow.success.borrowed).textContent() - expectAssets(borrowSummary!, [borrowed], assetsWorth) - } - // #endregion -} +// import { expect } from '@playwright/test' + +// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +// import { BasePageObject } from '@/test/e2e/BasePageObject' +// import { TestTokenWithValue, expectAssets } from '@/test/e2e/assertions' +// import { buildUrl } from '@/test/e2e/setup' +// import { calculateAssetsWorth } from '@/test/e2e/utils' +// import { testIds } from '@/ui/utils/testIds' +// import { TestnetClient, getUrlFromClient } from '@marsfoundation/common-testnets' + +// export class BorrowPageObject extends BasePageObject { +// // #region actions +// async fillDepositAssetAction(index: number, asset: string, amount: number): Promise { +// const inputGroup = this.page +// .getByTestId(testIds.easyBorrow.form.deposits) +// .getByTestId(testIds.component.MultiAssetSelector.group) +// .nth(index) + +// const selector = inputGroup.getByTestId(testIds.component.AssetSelector.trigger) +// await this.selectOptionByLabelAction(selector, asset) + +// await inputGroup.getByRole('textbox').fill(amount.toString()) +// } + +// async selectBorrowAction(assetName: string): Promise { +// const borrowSelector = this.page +// .getByTestId(testIds.easyBorrow.form.borrow) +// .getByTestId(testIds.component.AssetSelector.trigger) +// await this.selectOptionByLabelAction(borrowSelector, assetName) +// } + +// async fillBorrowAssetAction(amount: number): Promise { +// const borrowForm = this.page.getByTestId(testIds.easyBorrow.form.borrow) + +// await borrowForm.getByRole('textbox').fill(amount.toString()) +// } + +// async submitAction(): Promise { +// await this.page.locator('main').getByRole('button', { name: 'Borrow' }).click() +// } + +// async addNewDepositAssetAction(): Promise { +// return this.page.getByRole('button', { name: 'Add more' }).click() +// } + +// async viewInMyPortfolioAction(): Promise { +// await this.page.getByRole('link', { name: 'View in portfolio' }).click() +// } + +// async viewInSavingsAction(): Promise { +// await this.page.getByRole('link', { name: 'View in Savings' }).click() +// } + +// async depositAssetsActions({ +// assetsToDeposit, +// daiToBorrow, +// updateBrowserAndNextBlockTime, +// }: { +// assetsToDeposit: Record +// daiToBorrow: number +// updateBrowserAndNextBlockTime: () => Promise +// }): Promise { +// const actionsContainer = new ActionsPageObject(this.locatePanelByHeader('Actions')) +// await this.depositWithoutBorrowActions({ +// assetsToDeposit, +// daiToBorrow, +// actionsContainer, +// updateBrowserAndNextBlockTime, +// }) +// await actionsContainer.acceptActionAtIndex( +// Object.entries(assetsToDeposit).length * 2, +// updateBrowserAndNextBlockTime, +// ) // accept final borrow action +// } + +// async depositWithoutBorrowActions({ +// assetsToDeposit, +// daiToBorrow, +// actionsContainer: _actionsContainer, +// updateBrowserAndNextBlockTime, +// }: { +// assetsToDeposit: Record +// daiToBorrow?: number +// actionsContainer?: ActionsPageObject +// updateBrowserAndNextBlockTime: () => Promise +// }): Promise { +// const actionsContainer = _actionsContainer ?? new ActionsPageObject(this.locatePanelByHeader('Actions')) + +// let index = 0 +// for (const [asset, amount] of Object.entries(assetsToDeposit)) { +// if (index !== 0) { +// await this.addNewDepositAssetAction() +// } +// await this.fillDepositAssetAction(index, asset, amount) +// index++ +// } +// await this.fillBorrowAssetAction(daiToBorrow ?? 1) // defaulted value won't matter, if only depositing +// await this.submitAction() +// await actionsContainer.acceptAllActionsAction(2 * index, updateBrowserAndNextBlockTime) // omitting the borrow action +// await actionsContainer.expectEnabledActionAtIndex(2 * index) +// } + +// async goToEasyBorrowAction(): Promise { +// await this.page.goto(buildUrl('easyBorrow')) +// } +// // #endregion actions + +// // #region assertions +// async expectLtv(ltv: string): Promise { +// await expect(this.page.getByTestId(testIds.easyBorrow.form.ltv)).toHaveText(ltv) +// } + +// async expectHealthFactor(hf: string): Promise { +// const locator = this.page.getByTestId(testIds.component.HealthFactorGauge.value).nth(0) // is rendered twice because of mobile view +// await expect(locator).toHaveText(hf) +// } + +// async expectAssetInputInvalid(errorText: string): Promise { +// const locator = this.page.getByTestId(testIds.component.AssetInput.error) +// await expect(locator).toHaveText(errorText) +// } + +// async expectAssetNotListedInDepositSelector(asset: string): Promise { +// const depositSelector = this.page +// .getByTestId(testIds.easyBorrow.form.deposits) +// .getByTestId(testIds.component.MultiAssetSelector.group) +// .getByTestId(testIds.component.AssetSelector.trigger) +// await depositSelector.click() +// await expect(this.page.getByRole('listbox')).not.toHaveText(asset) +// } + +// async expectBorrowButtonActive(): Promise { +// await expect(this.page.locator('main').getByRole('button', { name: 'Borrow' })).toBeEnabled() +// } + +// async expectUsdsBorrowAlert(): Promise { +// await expect(this.page.getByTestId(testIds.easyBorrow.form.usdsBorrowAlert)).toBeVisible() +// } + +// async expectSuccessPage({ +// deposited, +// borrowed, +// testnetClient, +// assetsWorthOverride, +// }: { +// deposited: TestTokenWithValue[] +// borrowed: TestTokenWithValue +// testnetClient: TestnetClient +// assetsWorthOverride?: Record +// }): Promise { +// await expect(this.page.getByText('Congrats, all done!')).toBeVisible() + +// const transformed = [...deposited, borrowed].reduce( +// (acc, { asset, amount: value }) => ({ ...acc, [asset]: value }), +// {}, +// ) + +// const assetsWorth = await (async () => { +// if (assetsWorthOverride) { +// return assetsWorthOverride +// } + +// const { assetsWorth } = await calculateAssetsWorth(getUrlFromClient(testnetClient), transformed) +// return assetsWorth +// })() + +// if (deposited.length > 0) { +// const depositSummary = await this.page.getByTestId(testIds.easyBorrow.success.deposited).textContent() +// expectAssets(depositSummary!, deposited, assetsWorth) +// } + +// const borrowSummary = await this.page.getByTestId(testIds.easyBorrow.success.borrowed).textContent() +// expectAssets(borrowSummary!, [borrowed], assetsWorth) +// } +// // #endregion +// } diff --git a/packages/app/src/test/e2e/BasePageObject.ts b/packages/app/src/test/e2e/BasePageObject.ts index 7052138d0..6d24bef75 100644 --- a/packages/app/src/test/e2e/BasePageObject.ts +++ b/packages/app/src/test/e2e/BasePageObject.ts @@ -1,21 +1,22 @@ import { testIds } from '@/ui/utils/testIds' import { Locator, Page, expect } from '@playwright/test' -import { isPage } from './utils' +import { TestContext } from './setup' /** * BasePageObject is a class that contains common selectors and actions that are shared across the whole app. */ export class BasePageObject { + protected readonly testContext: TestContext protected readonly page: Page protected region: Locator - constructor(pageOrLocator: Page | Locator) { - if (isPage(pageOrLocator)) { - this.page = pageOrLocator - this.region = pageOrLocator.locator('body') + constructor(testContext: TestContext, locator?: Locator) { + this.testContext = testContext + this.page = testContext.page + if (locator) { + this.region = locator } else { - this.page = pageOrLocator.page() - this.region = pageOrLocator + this.region = this.page.locator('body') } } diff --git a/packages/app/src/test/e2e/setup.ts b/packages/app/src/test/e2e/setup.ts index 30c346118..3414a87de 100644 --- a/packages/app/src/test/e2e/setup.ts +++ b/packages/app/src/test/e2e/setup.ts @@ -59,17 +59,23 @@ export interface SetupOptions { skipInjectingNetwork?: boolean } -export type SetupReturn = (T extends 'not-connected' ? {} : { account: Address }) & { - testnetClient: TestnetClient - updateBrowserAndNextBlockTime: (seconds: number) => Promise - incrementTime: (seconds: number) => Promise +export type ProgressSimulation = (seconds: number) => Promise +export interface TestnetController { + client: TestnetClient + progressSimulation: ProgressSimulation + progressSimulationAndMine: ProgressSimulation +} + +export type TestContext = (T extends 'not-connected' ? {} : { account: Address }) & { + testnetController: TestnetController + page: Page } // should be called at the beginning of any test export async function setup( page: Page, options: SetupOptions, -): Promise> { +): Promise> { const { client: testnetClient, initialSnapshotId } = await getTestnetContext(options.blockchain) await testnetClient.revert(initialSnapshotId) @@ -77,7 +83,7 @@ export async function setup( const address = await setupAccount({ page, testnetClient, options: options.account }) await page.goto(buildUrl(options.initialPage, options.initialPageParams)) - async function updateBrowserAndNextBlockTime(seconds: number): Promise { + async function progressSimulation(seconds: number): Promise { const { timestamp: currentTimestamp } = await testnetClient.getBlock() const progressedTimestamp = currentTimestamp + BigInt(seconds) @@ -85,21 +91,25 @@ export async function setup( await injectUpdatedDate(page, new Date(Number(currentTimestamp) * 1000)) } - async function incrementTime(seconds: number): Promise { - await updateBrowserAndNextBlockTime(seconds) + async function progressSimulationAndMine(seconds: number): Promise { + await progressSimulation(seconds) await testnetClient.mineBlocks(1n) - await updateBrowserAndNextBlockTime(5) + await progressSimulation(1) } - // @note: Sync time in browser with current time on blockchain, - // set next block to be mined timestamp to be 5 seconds more. - await updateBrowserAndNextBlockTime(5) + // @note: Set next block to be mined timestamp to be 5 seconds more. + await progressSimulation(5) + + const testnetController = { + client: testnetClient, + progressSimulation, + progressSimulationAndMine, + } return { + page, account: address, - testnetClient, - updateBrowserAndNextBlockTime, - incrementTime, + testnetController, } as any } From 6b47fca67173105037fe02f5b0a5a816f4820c97 Mon Sep 17 00:00:00 2001 From: oskarvu Date: Tue, 17 Dec 2024 21:27:02 +0700 Subject: [PATCH 09/29] Rename file --- .../app/src/test/e2e/{testnet-cache.ts => getTestnetContext.ts} | 0 packages/app/src/test/e2e/setup.ts | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename packages/app/src/test/e2e/{testnet-cache.ts => getTestnetContext.ts} (100%) diff --git a/packages/app/src/test/e2e/testnet-cache.ts b/packages/app/src/test/e2e/getTestnetContext.ts similarity index 100% rename from packages/app/src/test/e2e/testnet-cache.ts rename to packages/app/src/test/e2e/getTestnetContext.ts diff --git a/packages/app/src/test/e2e/setup.ts b/packages/app/src/test/e2e/setup.ts index 3414a87de..edd8a292c 100644 --- a/packages/app/src/test/e2e/setup.ts +++ b/packages/app/src/test/e2e/setup.ts @@ -5,6 +5,7 @@ import { Page } from '@playwright/test' import { generatePath } from 'react-router-dom' import { Address, Hash, parseEther, parseUnits } from 'viem' import { AssetsInTests, TOKENS_ON_FORK } from './constants' +import { getTestnetContext } from './getTestnetContext' import { injectFixedDate, injectFlags, @@ -12,7 +13,6 @@ import { injectUpdatedDate, injectWalletConfiguration, } from './injectSetup' -import { getTestnetContext } from './testnet-cache' import { generateAccount } from './utils' export type InjectableWallet = { address: Address } | { privateKey: string } From df5350cc89c4e6ed57ed8ea46d7d4a217feb0e1a Mon Sep 17 00:00:00 2001 From: Oskar <43062492+oskarvu@users.noreply.github.com> Date: Wed, 18 Dec 2024 18:39:50 +0700 Subject: [PATCH 10/29] Rewrite easy borrow e2e tests (#499) * Uncomment files * Rewrite easy borrow tests * Explicitly set blockchain options for each test * Use newer block default block number * Update claim sky tests * Update easy borrow tests * Simplify success dialog checks * Simplify dialog success assets check --- packages/app/src/config/chain/index.ts | 50 +- .../config/feature-flags/appConfig.default.ts | 4 + packages/app/src/config/wagmi/config.e2e.ts | 1 - .../collateral/CollateralDialog.PageObject.ts | 74 +- .../dialogs/common/Dialog.PageObject.ts | 14 +- .../ConvertStablesDialog.test-e2e.ts | 4 +- .../e2e/mainnet/DaiToUsdc.test-e2e.ts | 4 +- .../e2e/mainnet/DaiToUsds.test-e2e.ts | 4 +- .../e2e/mainnet/UsdcToDai.test-e2e.ts | 4 +- .../e2e/mainnet/UsdcToUsds.test-e2e.ts | 4 +- .../e2e/mainnet/UsdsToDai.test-e2e.ts | 4 +- .../e2e/mainnet/UsdsToUsdc.test-e2e.ts | 4 +- .../deposit/SavingsDepositDialog.test-e2e.ts | 4 +- .../e2e/mainnet/DepositDAI.test-e2e.ts | 4 +- .../e2e/mainnet/DepositUSDC.test-e2e.ts | 4 +- .../e2e/mainnet/DepositUSDS.test-e2e.ts | 4 +- .../deposit/e2e/mainnet/General.test-e2e.ts | 4 +- .../downgrade/e2e/UsdsToDai.test-e2e.ts | 4 +- .../migrate/upgrade/e2e/DaiToUsds.test-e2e.ts | 4 +- .../upgrade/e2e/sDaiToSUsds.test-e2e.ts | 4 +- .../SavingsWithdrawDialog.test-e2e.ts | 4 +- .../withdraw/e2e/mainnet/SendUSDC.test-e2e.ts | 6 +- .../withdraw/e2e/mainnet/SendUSDS.test-e2e.ts | 6 +- .../e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts | 6 +- .../e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts | 6 +- .../e2e/mainnet/WithdrawUSDC.test-e2e.ts | 6 +- .../e2e/mainnet/WithdrawUSDS.test-e2e.ts | 6 +- .../claim/e2e/mainnet/ClaimSKY.test-e2e.ts | 12 +- .../stake/e2e/mainnet/StakeDAI.test-e2e.ts | 4 +- .../stake/e2e/mainnet/StakeSDAI.test-e2e.ts | 4 +- .../stake/e2e/mainnet/StakeSUSDS.test-e2e.ts | 4 +- .../stake/e2e/mainnet/StakeUSDC.test-e2e.ts | 4 +- .../stake/e2e/mainnet/StakeUSDS.test-e2e.ts | 6 +- .../e2e/mainnet/UnstakeDAI.test-e2e.ts | 4 +- .../e2e/mainnet/UnstakeUSDC.test-e2e.ts | 4 +- .../e2e/mainnet/UnstakeUSDS.test-e2e.ts | 6 +- .../e2e/mainnet/WithdrawMaxDai.test-e2e.ts | 4 +- .../e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts | 4 +- .../e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts | 6 +- packages/app/src/pages/Borrow.PageObject.ts | 324 +++-- packages/app/src/pages/Borrow.test-e2e.ts | 1167 +++++++++-------- packages/app/src/pages/Farms.test-e2e.ts | 4 +- .../app/src/pages/MarketDetails.test-e2e.ts | 4 +- packages/app/src/pages/Markets.test-e2e.ts | 4 +- packages/app/src/test/e2e/assertions.ts | 17 +- packages/app/src/test/e2e/constants.ts | 26 +- packages/app/src/test/e2e/injectSetup.ts | 38 - packages/app/src/test/e2e/setup.ts | 2 - 48 files changed, 906 insertions(+), 985 deletions(-) diff --git a/packages/app/src/config/chain/index.ts b/packages/app/src/config/chain/index.ts index 94630321c..1b77fd5ee 100644 --- a/packages/app/src/config/chain/index.ts +++ b/packages/app/src/config/chain/index.ts @@ -18,7 +18,6 @@ import { zeroAddress } from 'viem' import { base, gnosis, mainnet } from 'viem/chains' import { NATIVE_ASSET_MOCK_ADDRESS, infoSkyApiUrl } from '../consts' import { AppConfig } from '../feature-flags' -import { PLAYWRIGHT_USDS_CONTRACTS_NOT_AVAILABLE_KEY } from '../wagmi/config.e2e' import { SUPPORTED_CHAINS, farmAddresses, farmStablecoinsEntryGroup, susdsAddresses } from './constants' import { ChainConfigEntry, ChainMeta, SupportedChainId } from './types' @@ -32,16 +31,13 @@ const commonTokenSymbolToReplacedName = { [TokenSymbol('weETH')]: { name: 'Ether.fi Staked ETH', symbol: TokenSymbol('weETH') }, } -const PLAYWRIGHT_MAINNET_USDS_CONTRACTS_NOT_AVAILABLE = - import.meta.env.VITE_PLAYWRIGHT === '1' && (window as any)[PLAYWRIGHT_USDS_CONTRACTS_NOT_AVAILABLE_KEY] === true - const chainConfig: Record = { [mainnet.id]: { originChainId: mainnet.id, daiSymbol: TokenSymbol('DAI'), sdaiSymbol: TokenSymbol('sDAI'), - usdsSymbol: PLAYWRIGHT_MAINNET_USDS_CONTRACTS_NOT_AVAILABLE ? undefined : TokenSymbol('USDS'), - susdsSymbol: PLAYWRIGHT_MAINNET_USDS_CONTRACTS_NOT_AVAILABLE ? undefined : TokenSymbol('sUSDS'), + usdsSymbol: TokenSymbol('USDS'), + susdsSymbol: TokenSymbol('sUSDS'), psmStables: [TokenSymbol('DAI'), TokenSymbol('USDC'), TokenSymbol('USDS')], meta: { name: 'Ethereum Mainnet', @@ -89,25 +85,21 @@ const chainConfig: Record = { oracleType: 'vault', address: CheckedAddress('0x83f20f44975d03b1b09e64809b757c47f942beea'), }, - ...(PLAYWRIGHT_MAINNET_USDS_CONTRACTS_NOT_AVAILABLE - ? [] - : ([ - { - symbol: TokenSymbol('sUSDS'), - oracleType: 'vault', - address: susdsAddresses[mainnet.id], - }, - { - symbol: TokenSymbol('USDS'), - oracleType: 'fixed-usd', - address: CheckedAddress('0xdC035D45d973E3EC169d2276DDab16f1e407384F'), - }, - { - symbol: TokenSymbol('SKY'), - oracleType: 'zero-price', - address: CheckedAddress('0x56072C95FAA701256059aa122697B133aDEd9279'), - }, - ] as const)), + { + symbol: TokenSymbol('sUSDS'), + oracleType: 'vault', + address: susdsAddresses[mainnet.id], + }, + { + symbol: TokenSymbol('USDS'), + oracleType: 'fixed-usd', + address: CheckedAddress('0xdC035D45d973E3EC169d2276DDab16f1e407384F'), + }, + { + symbol: TokenSymbol('SKY'), + oracleType: 'zero-price', + address: CheckedAddress('0x56072C95FAA701256059aa122697B133aDEd9279'), + }, ], markets: { defaultAssetToBorrow: TokenSymbol('DAI'), @@ -165,12 +157,8 @@ const chainConfig: Record = { }, savings: { savingsDaiInfoQuery: mainnetSavingsDaiInfoQuery, - savingsUsdsInfoQuery: PLAYWRIGHT_MAINNET_USDS_CONTRACTS_NOT_AVAILABLE ? undefined : mainnetSavingsUsdsInfoQuery, - inputTokens: [ - TokenSymbol('DAI'), - TokenSymbol('USDC'), - ...(PLAYWRIGHT_MAINNET_USDS_CONTRACTS_NOT_AVAILABLE ? [] : [TokenSymbol('USDS')]), - ], + savingsUsdsInfoQuery: mainnetSavingsUsdsInfoQuery, + inputTokens: [TokenSymbol('DAI'), TokenSymbol('USDC'), TokenSymbol('USDS')], getEarningsApiUrl: (address) => `${infoSkyApiUrl}/savings-rate/wallets/${address.toLowerCase()}/?days_ago=9999`, savingsRateApiUrl: `${infoSkyApiUrl}/savings-rate/`, }, diff --git a/packages/app/src/config/feature-flags/appConfig.default.ts b/packages/app/src/config/feature-flags/appConfig.default.ts index e4d8e21ba..dde19f807 100644 --- a/packages/app/src/config/feature-flags/appConfig.default.ts +++ b/packages/app/src/config/feature-flags/appConfig.default.ts @@ -49,6 +49,10 @@ export function getDefaultAppConfig(): AppConfig { address: '0xdC035D45d973E3EC169d2276DDab16f1e407384F', decimals: 18, }, + cbBTC: { + address: '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf', + decimals: 8, + }, }, }, }, diff --git a/packages/app/src/config/wagmi/config.e2e.ts b/packages/app/src/config/wagmi/config.e2e.ts index 1dd78a1ce..50a018624 100644 --- a/packages/app/src/config/wagmi/config.e2e.ts +++ b/packages/app/src/config/wagmi/config.e2e.ts @@ -14,7 +14,6 @@ export const PLAYWRIGHT_CHAIN_ID = '__PLAYWRIGHT_CHAIN_ID' as const export const PLAYWRIGHT_WALLET_ADDRESS_KEY = '__PLAYWRIGHT_WALLET_ADDRESS' as const export const PLAYWRIGHT_WALLET_PRIVATE_KEY_KEY = '__PLAYWRIGHT_WALLET_PRIVATE_KEY' as const export const PLAYWRIGHT_WALLET_FORK_URL_KEY = '__PLAYWRIGHT_WALLET_FORK_URL_KEY' as const -export const PLAYWRIGHT_USDS_CONTRACTS_NOT_AVAILABLE_KEY = '__PLAYWRIGHT_USDS_CONTRACTS_NOT_AVAILABLE' as const export const VIEM_TIMEOUT_ON_FORKS = 60_000 // forks tend to be slow. This improves reliability/performance. Default is 10_000 diff --git a/packages/app/src/features/dialogs/collateral/CollateralDialog.PageObject.ts b/packages/app/src/features/dialogs/collateral/CollateralDialog.PageObject.ts index a85392026..36055ccae 100644 --- a/packages/app/src/features/dialogs/collateral/CollateralDialog.PageObject.ts +++ b/packages/app/src/features/dialogs/collateral/CollateralDialog.PageObject.ts @@ -1,44 +1,38 @@ -// import { Page, expect } from '@playwright/test' +import { TestContext } from '@/test/e2e/setup' +import { testIds } from '@/ui/utils/testIds' +import { expect } from '@playwright/test' +import { CollateralSetting } from '../collateral/types' +import { DialogPageObject } from '../common/Dialog.PageObject' -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { testIds } from '@/ui/utils/testIds' +export class CollateralDialogPageObject extends DialogPageObject { + constructor(testContext: TestContext) { + super({ testContext, header: /Collateral/ }) + } -// import { CollateralSetting } from '../collateral/types' -// import { DialogPageObject } from '../common/Dialog.PageObject' + // #region actions + async setUseAsCollateralAction({ + assetName, + setting, + }: { + assetName: string + setting: CollateralSetting + }): Promise { + await this.actionsContainer.acceptAllActionsAction(1) -// export class CollateralDialogPageObject extends DialogPageObject { -// constructor(page: Page) { -// super(page, /.*/) -// this.region = this.locateDialogByHeader('Collateral') -// } + // assertion used for waiting + if (setting === 'enabled') { + await this.expectSetUseAsCollateralSuccessPage(assetName, 'enabled') + } else { + await this.expectSetUseAsCollateralSuccessPage(assetName, 'disabled') + } + } + // #endregion actions -// // #region actions -// async setUseAsCollateralAction({ -// assetName, -// setting, -// updateBrowserAndNextBlockTime, -// }: { -// assetName: string -// setting: CollateralSetting -// updateBrowserAndNextBlockTime: () => Promise -// }): Promise { -// const actionsContainer = new ActionsPageObject(this.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(1, updateBrowserAndNextBlockTime) - -// // assertion used for waiting -// if (setting === 'enabled') { -// await this.expectSetUseAsCollateralSuccessPage(assetName, 'enabled') -// } else { -// await this.expectSetUseAsCollateralSuccessPage(assetName, 'disabled') -// } -// } -// // #endregion actions - -// // #region assertions -// async expectSetUseAsCollateralSuccessPage(assetName: string, setting: CollateralSetting): Promise { -// await expect(this.region.getByRole('heading', { name: 'Congrats, all done!' })).toBeVisible() -// await expect(this.region.getByTestId(testIds.dialog.success)).toContainText(assetName) -// await expect(this.region.getByTestId(testIds.dialog.success)).toContainText(`Collateral ${setting}`) -// } -// // #endregion assertions -// } + // #region assertions + async expectSetUseAsCollateralSuccessPage(assetName: string, setting: CollateralSetting): Promise { + await expect(this.region.getByRole('heading', { name: 'Congrats, all done!' })).toBeVisible() + await expect(this.region.getByTestId(testIds.dialog.success)).toContainText(assetName) + await expect(this.region.getByTestId(testIds.dialog.success)).toContainText(`Collateral ${setting}`) + } + // #endregion assertions +} diff --git a/packages/app/src/features/dialogs/common/Dialog.PageObject.ts b/packages/app/src/features/dialogs/common/Dialog.PageObject.ts index 2f74c63b3..e487c75ef 100644 --- a/packages/app/src/features/dialogs/common/Dialog.PageObject.ts +++ b/packages/app/src/features/dialogs/common/Dialog.PageObject.ts @@ -4,9 +4,7 @@ import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObjec import { BasePageObject } from '@/test/e2e/BasePageObject' import { TestTokenWithValue, expectAssets } from '@/test/e2e/assertions' import { TestContext } from '@/test/e2e/setup' -import { calculateAssetsWorth } from '@/test/e2e/utils' import { testIds } from '@/ui/utils/testIds' -import { TestnetClient, getUrlFromClient } from '@marsfoundation/common-testnets' export interface DialogPageObjectParams { testContext: TestContext @@ -57,22 +55,12 @@ export class DialogPageObject extends BasePageObject { // #region assertions async expectSuccessPage({ tokenWithValue, - testnetClient, - assetWorthOverrides, }: { tokenWithValue: TestTokenWithValue[] - testnetClient: TestnetClient - assetWorthOverrides?: Record }): Promise { await expect(this.region.getByText('Congrats, all done!')).toBeVisible() - - const transformed = tokenWithValue.reduce((acc, { asset, amount: value }) => ({ ...acc, [asset]: value }), {}) - - const { assetsWorth } = await calculateAssetsWorth(getUrlFromClient(testnetClient), transformed) - const mergedAssetsWorth = { ...assetsWorth, ...assetWorthOverrides } - const summary = await this.region.getByTestId(testIds.dialog.success).textContent() - expectAssets(summary!, tokenWithValue, mergedAssetsWorth) + expectAssets(summary!, tokenWithValue) } async expectRiskLevelBefore(riskLevel: string): Promise { diff --git a/packages/app/src/features/dialogs/convert-stables/ConvertStablesDialog.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/ConvertStablesDialog.test-e2e.ts index 19eb2bed9..66920cc48 100644 --- a/packages/app/src/features/dialogs/convert-stables/ConvertStablesDialog.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/ConvertStablesDialog.test-e2e.ts @@ -1,5 +1,5 @@ // import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { setup } from '@/test/e2e/setup' // import { test } from '@playwright/test' @@ -7,7 +7,7 @@ // import { ConvertStablesDialogPageObject } from './ConvertStablesDialog.PageObject' // test.describe('Convert Stables Dialog', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let savingsPage: SavingsPageObject // let convertStablesDialog: ConvertStablesDialogPageObject diff --git a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsdc.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsdc.test-e2e.ts index ec1a69f57..29f46ec5d 100644 --- a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsdc.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsdc.test-e2e.ts @@ -1,5 +1,5 @@ // import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { setup } from '@/test/e2e/setup' // import { test } from '@playwright/test' @@ -7,7 +7,7 @@ // import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' // test.describe('Convert DAI to USDC', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let savingsPage: SavingsPageObject // let convertStablesDialog: ConvertStablesDialogPageObject diff --git a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsds.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsds.test-e2e.ts index 20477c59e..4951bab59 100644 --- a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsds.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsds.test-e2e.ts @@ -1,5 +1,5 @@ // import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { setup } from '@/test/e2e/setup' // import { test } from '@playwright/test' @@ -7,7 +7,7 @@ // import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' // test.describe('Convert DAI to USDS', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let savingsPage: SavingsPageObject // let convertStablesDialog: ConvertStablesDialogPageObject diff --git a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToDai.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToDai.test-e2e.ts index 5359f831c..8efceca4a 100644 --- a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToDai.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToDai.test-e2e.ts @@ -1,5 +1,5 @@ // import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { setup } from '@/test/e2e/setup' // import { test } from '@playwright/test' @@ -7,7 +7,7 @@ // import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' // test.describe('Convert USDC to DAI', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let savingsPage: SavingsPageObject // let convertStablesDialog: ConvertStablesDialogPageObject diff --git a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToUsds.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToUsds.test-e2e.ts index b9906ae96..92ecc0188 100644 --- a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToUsds.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToUsds.test-e2e.ts @@ -1,5 +1,5 @@ // import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { setup } from '@/test/e2e/setup' // import { test } from '@playwright/test' @@ -7,7 +7,7 @@ // import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' // test.describe('Convert USDC to USDS', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let savingsPage: SavingsPageObject // let convertStablesDialog: ConvertStablesDialogPageObject diff --git a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToDai.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToDai.test-e2e.ts index c5c321126..e9bbf16df 100644 --- a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToDai.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToDai.test-e2e.ts @@ -1,5 +1,5 @@ // import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { setup } from '@/test/e2e/setup' // import { test } from '@playwright/test' @@ -7,7 +7,7 @@ // import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' // test.describe('Convert USDS to DAI', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let savingsPage: SavingsPageObject // let convertStablesDialog: ConvertStablesDialogPageObject diff --git a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToUsdc.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToUsdc.test-e2e.ts index 08a9405c6..ce075748b 100644 --- a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToUsdc.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToUsdc.test-e2e.ts @@ -1,5 +1,5 @@ // import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { setup } from '@/test/e2e/setup' // import { test } from '@playwright/test' @@ -7,7 +7,7 @@ // import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' // test.describe('Convert USDS to USDC', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let savingsPage: SavingsPageObject // let convertStablesDialog: ConvertStablesDialogPageObject diff --git a/packages/app/src/features/dialogs/savings/deposit/SavingsDepositDialog.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/SavingsDepositDialog.test-e2e.ts index 303428dc4..2b8993b94 100644 --- a/packages/app/src/features/dialogs/savings/deposit/SavingsDepositDialog.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/deposit/SavingsDepositDialog.test-e2e.ts @@ -1,6 +1,6 @@ // import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' // import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { GNOSIS_DEFAULT_BLOCK_NUMBER, LITE_PSM_ACTIONS_OPERABLE } from '@/test/e2e/constants' +// import { GNOSIS_DEFAULT_BLOCK_NUMBER, DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { setup } from '@/test/e2e/setup' // import { test } from '@playwright/test' @@ -10,7 +10,7 @@ // test.describe('Savings deposit dialog', () => { // test.describe('Mainnet', () => { // const fork = setupFork({ -// blockNumber: LITE_PSM_ACTIONS_OPERABLE, +// blockNumber: DEFAULT_BLOCK_NUMBER, // chainId: mainnet.id, // useTenderlyVnet: true, // }) diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositDAI.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositDAI.test-e2e.ts index f9d0e7f27..17dfb8af3 100644 --- a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositDAI.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositDAI.test-e2e.ts @@ -1,6 +1,6 @@ // import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' // import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { setup } from '@/test/e2e/setup' // import { test } from '@playwright/test' @@ -8,7 +8,7 @@ // import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' // test.describe('Deposit DAI', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let savingsPage: SavingsPageObject // let depositDialog: SavingsDialogPageObject diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDC.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDC.test-e2e.ts index b6d3a53dd..10f44f77f 100644 --- a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDC.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDC.test-e2e.ts @@ -1,6 +1,6 @@ // import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' // import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { setup } from '@/test/e2e/setup' // import { test } from '@playwright/test' @@ -8,7 +8,7 @@ // import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' // test.describe('Deposit USDC', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let savingsPage: SavingsPageObject // let depositDialog: SavingsDialogPageObject diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDS.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDS.test-e2e.ts index 31e924a25..e5d6f7a63 100644 --- a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDS.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDS.test-e2e.ts @@ -1,6 +1,6 @@ // import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' // import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { setup } from '@/test/e2e/setup' // import { test } from '@playwright/test' @@ -8,7 +8,7 @@ // import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' // test.describe('Deposit USDS', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let savingsPage: SavingsPageObject // let depositDialog: SavingsDialogPageObject diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/General.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/General.test-e2e.ts index 7fc03389e..cb111a865 100644 --- a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/General.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/General.test-e2e.ts @@ -1,6 +1,6 @@ // import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' // import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { LITE_PSM_ACTIONS_OPERABLE } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { setup } from '@/test/e2e/setup' // import { test } from '@playwright/test' @@ -9,7 +9,7 @@ // test.describe('General dialog behavior', () => { // const fork = setupFork({ -// blockNumber: LITE_PSM_ACTIONS_OPERABLE, +// blockNumber: DEFAULT_BLOCK_NUMBER, // chainId: mainnet.id, // useTenderlyVnet: true, // }) diff --git a/packages/app/src/features/dialogs/savings/migrate/downgrade/e2e/UsdsToDai.test-e2e.ts b/packages/app/src/features/dialogs/savings/migrate/downgrade/e2e/UsdsToDai.test-e2e.ts index a536683ef..f0715c43a 100644 --- a/packages/app/src/features/dialogs/savings/migrate/downgrade/e2e/UsdsToDai.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/migrate/downgrade/e2e/UsdsToDai.test-e2e.ts @@ -1,5 +1,5 @@ // import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { setup } from '@/test/e2e/setup' // import { test } from '@playwright/test' @@ -7,7 +7,7 @@ // import { DowngradeDialogPageObject } from '../DowngradeDialog.PageObject' // test.describe('Downgrade USDS to DAI', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // test('downgrade to DAI is disabled when USDS balance is 0', async ({ page }) => { // await setup(page, fork, { diff --git a/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/DaiToUsds.test-e2e.ts b/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/DaiToUsds.test-e2e.ts index e3c85e862..5ba3183d8 100644 --- a/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/DaiToUsds.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/DaiToUsds.test-e2e.ts @@ -1,5 +1,5 @@ // import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { setup } from '@/test/e2e/setup' // import { test } from '@playwright/test' @@ -7,7 +7,7 @@ // import { UpgradeDialogPageObject } from '../UpgradeDialog.PageObject' // test.describe('Upgrade DAI to USDS', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // test('does not show upgrade button when DAI balance is 0', async ({ page }) => { // await setup(page, fork, { diff --git a/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/sDaiToSUsds.test-e2e.ts b/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/sDaiToSUsds.test-e2e.ts index 2d8ce9a16..397001c77 100644 --- a/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/sDaiToSUsds.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/sDaiToSUsds.test-e2e.ts @@ -1,5 +1,5 @@ // import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { setup } from '@/test/e2e/setup' // import { test } from '@playwright/test' @@ -7,7 +7,7 @@ // import { UpgradeDialogPageObject } from '../UpgradeDialog.PageObject' // test.describe('Upgrade sDAI to sUSDS', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // test('does not show upgrade banner when sDai balance is 0', async ({ page }) => { // await setup(page, fork, { diff --git a/packages/app/src/features/dialogs/savings/withdraw/SavingsWithdrawDialog.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/SavingsWithdrawDialog.test-e2e.ts index 8ec2ba3ee..fe04f75b2 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/SavingsWithdrawDialog.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/SavingsWithdrawDialog.test-e2e.ts @@ -1,6 +1,6 @@ // import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' // import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER, GNOSIS_DEFAULT_BLOCK_NUMBER, LITE_PSM_ACTIONS_OPERABLE } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER, GNOSIS_DEFAULT_BLOCK_NUMBER, DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { setup } from '@/test/e2e/setup' // import { test } from '@playwright/test' @@ -10,7 +10,7 @@ // test.describe('Savings withdraw dialog', () => { // test.describe('Mainnet', () => { // const fork = setupFork({ -// blockNumber: LITE_PSM_ACTIONS_OPERABLE, +// blockNumber: DEFAULT_BLOCK_NUMBER, // chainId: mainnet.id, // useTenderlyVnet: true, // }) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDC.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDC.test-e2e.ts index dc5aae60b..fefc60510 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDC.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDC.test-e2e.ts @@ -1,5 +1,5 @@ // import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { TOKENS_ON_FORK, USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { TOKENS_ON_FORK, DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { setup } from '@/test/e2e/setup' // import { randomAddress } from '@/test/utils/addressUtils' @@ -8,7 +8,7 @@ // import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' // test.describe('Send USDC (withdrawing from sUSDS)', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let savingsPage: SavingsPageObject // let sendDialog: SavingsDialogPageObject // const receiver = randomAddress('bob') @@ -95,7 +95,7 @@ // }) // test.describe('Send USDC (withdrawing from sDAI)', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let savingsPage: SavingsPageObject // let sendDialog: SavingsDialogPageObject // const receiver = randomAddress('bob') diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDS.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDS.test-e2e.ts index dc6b64c90..23d3d2d85 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDS.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDS.test-e2e.ts @@ -1,5 +1,5 @@ // import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { TOKENS_ON_FORK, USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { TOKENS_ON_FORK, DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { setup } from '@/test/e2e/setup' // import { randomAddress } from '@/test/utils/addressUtils' @@ -8,7 +8,7 @@ // import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' // test.describe('Send USDS (withdrawing from sUSDS)', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let savingsPage: SavingsPageObject // let sendDialog: SavingsDialogPageObject // const receiver = randomAddress('bob') @@ -89,7 +89,7 @@ // }) // test.describe('Send USDS (withdrawing from sDAI)', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let savingsPage: SavingsPageObject // let sendDialog: SavingsDialogPageObject // const receiver = randomAddress('bob') diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts index fd9b7fe46..765d73a49 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts @@ -1,6 +1,6 @@ // import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' // import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { setup } from '@/test/e2e/setup' // import { test } from '@playwright/test' @@ -8,7 +8,7 @@ // import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' // test.describe('Withdraw USDC from sUSDS', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let savingsPage: SavingsPageObject // let withdrawDialog: SavingsDialogPageObject @@ -81,7 +81,7 @@ // }) // test.describe('Withdraw USDC from sDAI', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let savingsPage: SavingsPageObject // let withdrawDialog: SavingsDialogPageObject diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts index 762a7d556..2dcd77bab 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts @@ -1,6 +1,6 @@ // import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' // import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { setup } from '@/test/e2e/setup' // import { test } from '@playwright/test' @@ -8,7 +8,7 @@ // import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' // test.describe('Withdraw USDS from sUSDS', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let savingsPage: SavingsPageObject // let withdrawDialog: SavingsDialogPageObject @@ -75,7 +75,7 @@ // }) // test.describe('Withdraw USDS from sDAI', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let savingsPage: SavingsPageObject // let withdrawDialog: SavingsDialogPageObject diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDC.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDC.test-e2e.ts index cd6c88b23..f1aad43ef 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDC.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDC.test-e2e.ts @@ -1,6 +1,6 @@ // import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' // import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { setup } from '@/test/e2e/setup' // import { test } from '@playwright/test' @@ -8,7 +8,7 @@ // import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' // test.describe('Withdraw USDC from sUSDS', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let savingsPage: SavingsPageObject // let withdrawDialog: SavingsDialogPageObject @@ -81,7 +81,7 @@ // }) // test.describe('Withdraw USDC from sDAI', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let savingsPage: SavingsPageObject // let withdrawDialog: SavingsDialogPageObject diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDS.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDS.test-e2e.ts index c533d88a0..f8fef0553 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDS.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDS.test-e2e.ts @@ -1,6 +1,6 @@ // import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' // import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { setup } from '@/test/e2e/setup' // import { test } from '@playwright/test' @@ -8,7 +8,7 @@ // import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' // test.describe('Withdraw USDS from sUSDS', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let savingsPage: SavingsPageObject // let withdrawDialog: SavingsDialogPageObject @@ -75,7 +75,7 @@ // }) // test.describe('Withdraw USDS from sDAI', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let savingsPage: SavingsPageObject // let withdrawDialog: SavingsDialogPageObject diff --git a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts index bb17be487..fdd9f0de6 100644 --- a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts @@ -1,6 +1,6 @@ import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' import { StakeDialogPageObject } from '@/features/farm-details/dialogs/stake/StakeDialog.PageObject' -import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' import { setup } from '@/test/e2e/setup' import { NormalizedUnitNumber } from '@marsfoundation/common-universal' @@ -18,7 +18,7 @@ test.describe('Claim SKY rewards', () => { const testContext = await setup(page, { blockchain: { chainId: mainnet.id, - blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, + blockNumber: DEFAULT_BLOCK_NUMBER, }, initialPage: 'farmDetails', initialPageParams: { @@ -58,8 +58,8 @@ test.describe('Claim SKY rewards', () => { test('displays transaction overview', async () => { await claimDialog.expectTransactionOverview({ reward: { - amount: '3,539.65', - amountUSD: '$213.35', + amount: '49.44', + amountUSD: '$2.98', }, }) }) @@ -72,13 +72,13 @@ test.describe('Claim SKY rewards', () => { await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') await farmDetailsPage.expectReward({ - reward: '0.1', + reward: '0.001', rewardUsd: '<$0.01', }) await farmDetailsPage.expectTokenBalance({ address: account, symbol: 'SKY', - balance: NormalizedUnitNumber('3539.69212658060522'), + balance: NormalizedUnitNumber('49.4365427929088'), }) await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) }) diff --git a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeDAI.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeDAI.test-e2e.ts index 54198e826..7f9c6d7db 100644 --- a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeDAI.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeDAI.test-e2e.ts @@ -1,5 +1,5 @@ // import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' // import { setup } from '@/test/e2e/setup' @@ -8,7 +8,7 @@ // import { StakeDialogPageObject } from '../../StakeDialog.PageObject' // test.describe('Stake DAI to SKY farm', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let farmDetailsPage: FarmDetailsPageObject // let stakeDialog: StakeDialogPageObject diff --git a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSDAI.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSDAI.test-e2e.ts index cd5ce13e4..d7d3635dd 100644 --- a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSDAI.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSDAI.test-e2e.ts @@ -1,5 +1,5 @@ // import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' // import { setup } from '@/test/e2e/setup' @@ -8,7 +8,7 @@ // import { StakeDialogPageObject } from '../../StakeDialog.PageObject' // test.describe('Stake sDAI to SKY farm', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let farmDetailsPage: FarmDetailsPageObject // let stakeDialog: StakeDialogPageObject diff --git a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSUSDS.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSUSDS.test-e2e.ts index 97151d40f..76c4c2be4 100644 --- a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSUSDS.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSUSDS.test-e2e.ts @@ -1,7 +1,7 @@ // import { SavingsDialogPageObject } from '@/features/dialogs/savings/common/e2e/SavingsDialog.PageObject' // import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' // import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' // import { buildUrl, setup } from '@/test/e2e/setup' @@ -10,7 +10,7 @@ // import { StakeDialogPageObject } from '../../StakeDialog.PageObject' // test.describe('Stake sDAI to SKY farm', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let farmDetailsPage: FarmDetailsPageObject // let stakeDialog: StakeDialogPageObject diff --git a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDC.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDC.test-e2e.ts index c49daf9a3..44664c8d1 100644 --- a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDC.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDC.test-e2e.ts @@ -1,5 +1,5 @@ // import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' // import { setup } from '@/test/e2e/setup' @@ -8,7 +8,7 @@ // import { StakeDialogPageObject } from '../../StakeDialog.PageObject' // test.describe('Stake USDC to SKY farm', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let farmDetailsPage: FarmDetailsPageObject // let stakeDialog: StakeDialogPageObject diff --git a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDS.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDS.test-e2e.ts index 75cc656b9..3526c182c 100644 --- a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDS.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDS.test-e2e.ts @@ -1,5 +1,5 @@ // import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' // import { setup } from '@/test/e2e/setup' @@ -9,7 +9,7 @@ // import { StakeDialogPageObject } from '../../StakeDialog.PageObject' // test.describe('Stake USDS to SKY farm', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let farmDetailsPage: FarmDetailsPageObject // let stakeDialog: StakeDialogPageObject @@ -85,7 +85,7 @@ // const testUserAddress = privateKeyToAddress('0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5') // const harSuffix = testUserAddress.slice(0, 10) -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let farmDetailsPage: FarmDetailsPageObject // let stakeDialog: StakeDialogPageObject diff --git a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeDAI.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeDAI.test-e2e.ts index 71313a5c5..3973db2a1 100644 --- a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeDAI.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeDAI.test-e2e.ts @@ -1,5 +1,5 @@ // import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' // import { setup } from '@/test/e2e/setup' @@ -9,7 +9,7 @@ // import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' // test.describe('Unstake DAI from SKY farm', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let farmDetailsPage: FarmDetailsPageObject // let unstakeDialog: UnstakeDialogPageObject // let stakeDialog: StakeDialogPageObject diff --git a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDC.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDC.test-e2e.ts index 3e6c3559d..eaa8366d9 100644 --- a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDC.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDC.test-e2e.ts @@ -1,5 +1,5 @@ // import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' // import { setup } from '@/test/e2e/setup' @@ -9,7 +9,7 @@ // import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' // test.describe('Unstake USDC from SKY farm', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let farmDetailsPage: FarmDetailsPageObject // let unstakeDialog: UnstakeDialogPageObject // let stakeDialog: StakeDialogPageObject diff --git a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDS.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDS.test-e2e.ts index 0a4aa2c5f..8dcd2e47f 100644 --- a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDS.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDS.test-e2e.ts @@ -1,5 +1,5 @@ // import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' // import { setup } from '@/test/e2e/setup' @@ -10,7 +10,7 @@ // import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' // test.describe('Unstake USDS from SKY farm', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let farmDetailsPage: FarmDetailsPageObject // let unstakeDialog: UnstakeDialogPageObject // let stakeDialog: StakeDialogPageObject @@ -102,7 +102,7 @@ // const testUserAddress = privateKeyToAddress('0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5') // const harSuffix = testUserAddress.slice(0, 10) -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let farmDetailsPage: FarmDetailsPageObject // let unstakeDialog: UnstakeDialogPageObject diff --git a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxDai.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxDai.test-e2e.ts index 11832558e..aec8adb76 100644 --- a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxDai.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxDai.test-e2e.ts @@ -1,5 +1,5 @@ // import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' // import { setup } from '@/test/e2e/setup' @@ -10,7 +10,7 @@ // import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' // test.describe('Withdraw max DAI from SKY farm', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let farmDetailsPage: FarmDetailsPageObject // let unstakeDialog: UnstakeDialogPageObject // let stakeDialog: StakeDialogPageObject diff --git a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts index a50a12d22..9a5b2bde7 100644 --- a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts @@ -1,5 +1,5 @@ // import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' // import { setup } from '@/test/e2e/setup' @@ -10,7 +10,7 @@ // import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' // test.describe('Withdraw max USDC from SKY farm', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let farmDetailsPage: FarmDetailsPageObject // let unstakeDialog: UnstakeDialogPageObject // let stakeDialog: StakeDialogPageObject diff --git a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts index cbf7b0898..b91a183bb 100644 --- a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts @@ -1,5 +1,5 @@ // import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' // import { setup } from '@/test/e2e/setup' @@ -11,7 +11,7 @@ // import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' // test.describe('Withdraw max USDS from SKY farm', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let farmDetailsPage: FarmDetailsPageObject // let unstakeDialog: UnstakeDialogPageObject // let stakeDialog: StakeDialogPageObject @@ -166,7 +166,7 @@ // const testUserAddress = privateKeyToAddress('0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5') // const harSuffix = testUserAddress.slice(0, 10) -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let farmDetailsPage: FarmDetailsPageObject // let unstakeDialog: UnstakeDialogPageObject diff --git a/packages/app/src/pages/Borrow.PageObject.ts b/packages/app/src/pages/Borrow.PageObject.ts index 1884a53c8..18ca5fc5b 100644 --- a/packages/app/src/pages/Borrow.PageObject.ts +++ b/packages/app/src/pages/Borrow.PageObject.ts @@ -1,176 +1,148 @@ -// import { expect } from '@playwright/test' - -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { BasePageObject } from '@/test/e2e/BasePageObject' -// import { TestTokenWithValue, expectAssets } from '@/test/e2e/assertions' -// import { buildUrl } from '@/test/e2e/setup' -// import { calculateAssetsWorth } from '@/test/e2e/utils' -// import { testIds } from '@/ui/utils/testIds' -// import { TestnetClient, getUrlFromClient } from '@marsfoundation/common-testnets' - -// export class BorrowPageObject extends BasePageObject { -// // #region actions -// async fillDepositAssetAction(index: number, asset: string, amount: number): Promise { -// const inputGroup = this.page -// .getByTestId(testIds.easyBorrow.form.deposits) -// .getByTestId(testIds.component.MultiAssetSelector.group) -// .nth(index) - -// const selector = inputGroup.getByTestId(testIds.component.AssetSelector.trigger) -// await this.selectOptionByLabelAction(selector, asset) - -// await inputGroup.getByRole('textbox').fill(amount.toString()) -// } - -// async selectBorrowAction(assetName: string): Promise { -// const borrowSelector = this.page -// .getByTestId(testIds.easyBorrow.form.borrow) -// .getByTestId(testIds.component.AssetSelector.trigger) -// await this.selectOptionByLabelAction(borrowSelector, assetName) -// } - -// async fillBorrowAssetAction(amount: number): Promise { -// const borrowForm = this.page.getByTestId(testIds.easyBorrow.form.borrow) - -// await borrowForm.getByRole('textbox').fill(amount.toString()) -// } - -// async submitAction(): Promise { -// await this.page.locator('main').getByRole('button', { name: 'Borrow' }).click() -// } - -// async addNewDepositAssetAction(): Promise { -// return this.page.getByRole('button', { name: 'Add more' }).click() -// } - -// async viewInMyPortfolioAction(): Promise { -// await this.page.getByRole('link', { name: 'View in portfolio' }).click() -// } - -// async viewInSavingsAction(): Promise { -// await this.page.getByRole('link', { name: 'View in Savings' }).click() -// } - -// async depositAssetsActions({ -// assetsToDeposit, -// daiToBorrow, -// updateBrowserAndNextBlockTime, -// }: { -// assetsToDeposit: Record -// daiToBorrow: number -// updateBrowserAndNextBlockTime: () => Promise -// }): Promise { -// const actionsContainer = new ActionsPageObject(this.locatePanelByHeader('Actions')) -// await this.depositWithoutBorrowActions({ -// assetsToDeposit, -// daiToBorrow, -// actionsContainer, -// updateBrowserAndNextBlockTime, -// }) -// await actionsContainer.acceptActionAtIndex( -// Object.entries(assetsToDeposit).length * 2, -// updateBrowserAndNextBlockTime, -// ) // accept final borrow action -// } - -// async depositWithoutBorrowActions({ -// assetsToDeposit, -// daiToBorrow, -// actionsContainer: _actionsContainer, -// updateBrowserAndNextBlockTime, -// }: { -// assetsToDeposit: Record -// daiToBorrow?: number -// actionsContainer?: ActionsPageObject -// updateBrowserAndNextBlockTime: () => Promise -// }): Promise { -// const actionsContainer = _actionsContainer ?? new ActionsPageObject(this.locatePanelByHeader('Actions')) - -// let index = 0 -// for (const [asset, amount] of Object.entries(assetsToDeposit)) { -// if (index !== 0) { -// await this.addNewDepositAssetAction() -// } -// await this.fillDepositAssetAction(index, asset, amount) -// index++ -// } -// await this.fillBorrowAssetAction(daiToBorrow ?? 1) // defaulted value won't matter, if only depositing -// await this.submitAction() -// await actionsContainer.acceptAllActionsAction(2 * index, updateBrowserAndNextBlockTime) // omitting the borrow action -// await actionsContainer.expectEnabledActionAtIndex(2 * index) -// } - -// async goToEasyBorrowAction(): Promise { -// await this.page.goto(buildUrl('easyBorrow')) -// } -// // #endregion actions - -// // #region assertions -// async expectLtv(ltv: string): Promise { -// await expect(this.page.getByTestId(testIds.easyBorrow.form.ltv)).toHaveText(ltv) -// } - -// async expectHealthFactor(hf: string): Promise { -// const locator = this.page.getByTestId(testIds.component.HealthFactorGauge.value).nth(0) // is rendered twice because of mobile view -// await expect(locator).toHaveText(hf) -// } - -// async expectAssetInputInvalid(errorText: string): Promise { -// const locator = this.page.getByTestId(testIds.component.AssetInput.error) -// await expect(locator).toHaveText(errorText) -// } - -// async expectAssetNotListedInDepositSelector(asset: string): Promise { -// const depositSelector = this.page -// .getByTestId(testIds.easyBorrow.form.deposits) -// .getByTestId(testIds.component.MultiAssetSelector.group) -// .getByTestId(testIds.component.AssetSelector.trigger) -// await depositSelector.click() -// await expect(this.page.getByRole('listbox')).not.toHaveText(asset) -// } - -// async expectBorrowButtonActive(): Promise { -// await expect(this.page.locator('main').getByRole('button', { name: 'Borrow' })).toBeEnabled() -// } - -// async expectUsdsBorrowAlert(): Promise { -// await expect(this.page.getByTestId(testIds.easyBorrow.form.usdsBorrowAlert)).toBeVisible() -// } - -// async expectSuccessPage({ -// deposited, -// borrowed, -// testnetClient, -// assetsWorthOverride, -// }: { -// deposited: TestTokenWithValue[] -// borrowed: TestTokenWithValue -// testnetClient: TestnetClient -// assetsWorthOverride?: Record -// }): Promise { -// await expect(this.page.getByText('Congrats, all done!')).toBeVisible() - -// const transformed = [...deposited, borrowed].reduce( -// (acc, { asset, amount: value }) => ({ ...acc, [asset]: value }), -// {}, -// ) - -// const assetsWorth = await (async () => { -// if (assetsWorthOverride) { -// return assetsWorthOverride -// } - -// const { assetsWorth } = await calculateAssetsWorth(getUrlFromClient(testnetClient), transformed) -// return assetsWorth -// })() - -// if (deposited.length > 0) { -// const depositSummary = await this.page.getByTestId(testIds.easyBorrow.success.deposited).textContent() -// expectAssets(depositSummary!, deposited, assetsWorth) -// } - -// const borrowSummary = await this.page.getByTestId(testIds.easyBorrow.success.borrowed).textContent() -// expectAssets(borrowSummary!, [borrowed], assetsWorth) -// } -// // #endregion -// } +import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +import { BasePageObject } from '@/test/e2e/BasePageObject' +import { TestTokenWithValue, expectAssets } from '@/test/e2e/assertions' +import { TestContext, buildUrl } from '@/test/e2e/setup' +import { testIds } from '@/ui/utils/testIds' +import { expect } from '@playwright/test' + +export class BorrowPageObject extends BasePageObject { + public readonly actionsContainer: ActionsPageObject + + constructor(testContext: TestContext) { + super(testContext) + this.actionsContainer = new ActionsPageObject(testContext, this.locatePanelByHeader('Actions')) + } + + // #region actions + async fillDepositAssetAction(index: number, asset: string, amount: number): Promise { + const inputGroup = this.page + .getByTestId(testIds.easyBorrow.form.deposits) + .getByTestId(testIds.component.MultiAssetSelector.group) + .nth(index) + + const selector = inputGroup.getByTestId(testIds.component.AssetSelector.trigger) + await this.selectOptionByLabelAction(selector, asset) + + await inputGroup.getByRole('textbox').fill(amount.toString()) + } + + async selectBorrowAction(assetName: string): Promise { + const borrowSelector = this.page + .getByTestId(testIds.easyBorrow.form.borrow) + .getByTestId(testIds.component.AssetSelector.trigger) + await this.selectOptionByLabelAction(borrowSelector, assetName) + } + + async fillBorrowAssetAction(amount: number): Promise { + const borrowForm = this.page.getByTestId(testIds.easyBorrow.form.borrow) + + await borrowForm.getByRole('textbox').fill(amount.toString()) + } + + async submitAction(): Promise { + await this.page.locator('main').getByRole('button', { name: 'Borrow' }).click() + } + + async addNewDepositAssetAction(): Promise { + return this.page.getByRole('button', { name: 'Add more' }).click() + } + + async viewInMyPortfolioAction(): Promise { + await this.page.getByRole('link', { name: 'View in portfolio' }).click() + } + + async viewInSavingsAction(): Promise { + await this.page.getByRole('link', { name: 'View in Savings' }).click() + } + + async depositAssetsActions({ + assetsToDeposit, + daiToBorrow, + }: { + assetsToDeposit: Record + daiToBorrow: number + }): Promise { + await this.depositWithoutBorrowActions({ + assetsToDeposit, + daiToBorrow, + }) + await this.actionsContainer.acceptActionAtIndex(Object.entries(assetsToDeposit).length * 2) // accept final borrow action + } + + async depositWithoutBorrowActions({ + assetsToDeposit, + daiToBorrow, + }: { + assetsToDeposit: Record + daiToBorrow?: number + }): Promise { + let index = 0 + for (const [asset, amount] of Object.entries(assetsToDeposit)) { + if (index !== 0) { + await this.addNewDepositAssetAction() + } + await this.fillDepositAssetAction(index, asset, amount) + index++ + } + await this.fillBorrowAssetAction(daiToBorrow ?? 1) // defaulted value won't matter, if only depositing + await this.submitAction() + await this.actionsContainer.acceptAllActionsAction(2 * index) // omitting the borrow action + await this.actionsContainer.expectEnabledActionAtIndex(2 * index) + } + + async goToEasyBorrowAction(): Promise { + await this.page.goto(buildUrl('easyBorrow')) + } + // #endregion actions + + // #region assertions + async expectLtv(ltv: string): Promise { + await expect(this.page.getByTestId(testIds.easyBorrow.form.ltv)).toHaveText(ltv) + } + + async expectHealthFactor(hf: string): Promise { + const locator = this.page.getByTestId(testIds.component.HealthFactorGauge.value).nth(0) // is rendered twice because of mobile view + await expect(locator).toHaveText(hf) + } + + async expectAssetInputInvalid(errorText: string): Promise { + const locator = this.page.getByTestId(testIds.component.AssetInput.error) + await expect(locator).toHaveText(errorText) + } + + async expectAssetNotListedInDepositSelector(asset: string): Promise { + const depositSelector = this.page + .getByTestId(testIds.easyBorrow.form.deposits) + .getByTestId(testIds.component.MultiAssetSelector.group) + .getByTestId(testIds.component.AssetSelector.trigger) + await depositSelector.click() + await expect(this.page.getByRole('listbox')).not.toHaveText(asset) + } + + async expectBorrowButtonActive(): Promise { + await expect(this.page.locator('main').getByRole('button', { name: 'Borrow' })).toBeEnabled() + } + + async expectUsdsBorrowAlert(): Promise { + await expect(this.page.getByTestId(testIds.easyBorrow.form.usdsBorrowAlert)).toBeVisible() + } + + async expectSuccessPage({ + deposited, + borrowed, + }: { + deposited: TestTokenWithValue[] + borrowed: TestTokenWithValue + }): Promise { + await expect(this.page.getByText('Congrats, all done!')).toBeVisible() + + if (deposited.length > 0) { + const depositSummary = await this.page.getByTestId(testIds.easyBorrow.success.deposited).textContent() + expectAssets(depositSummary!, deposited) + } + + const borrowSummary = await this.page.getByTestId(testIds.easyBorrow.success.borrowed).textContent() + expectAssets(borrowSummary!, [borrowed]) + } + // #endregion +} diff --git a/packages/app/src/pages/Borrow.test-e2e.ts b/packages/app/src/pages/Borrow.test-e2e.ts index 664158bde..0257f85d9 100644 --- a/packages/app/src/pages/Borrow.test-e2e.ts +++ b/packages/app/src/pages/Borrow.test-e2e.ts @@ -1,570 +1,597 @@ -// import { borrowValidationIssueToMessage } from '@/domain/market-validators/validateBorrow' -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { CollateralDialogPageObject } from '@/features/dialogs/collateral/CollateralDialog.PageObject' -// import { DEFAULT_BLOCK_NUMBER, USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { buildUrl, setup } from '@/test/e2e/setup' -// import { screenshot } from '@/test/e2e/utils' -// import { Page, test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { BorrowPageObject } from './Borrow.PageObject' -// import { MyPortfolioPageObject } from './MyPortfolio.PageObject' -// import { SavingsPageObject } from './Savings.PageObject' - -// test.describe('Borrow page', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) - -// test.describe('deposit ETH, borrow DAI', () => { -// let borrowPage: BorrowPageObject -// let actionsContainer: ActionsPageObject -// const deposit = { -// asset: 'ETH', -// amount: 1, -// } -// const borrow = { -// asset: 'DAI', -// amount: 1000, -// } -// const expectedLtv = '44.07%' -// const expectedHealthFactor = '1.87' - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 10, -// }, -// }, -// }) - -// borrowPage = new BorrowPageObject(page) -// actionsContainer = new ActionsPageObject(page) -// }) - -// test('calculates LTV correctly', async () => { -// await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) -// await borrowPage.fillBorrowAssetAction(borrow.amount) - -// await borrowPage.submitAction() - -// await borrowPage.expectLtv(expectedLtv) -// await borrowPage.expectHealthFactor(expectedHealthFactor) -// }) - -// test('builds action plan', async ({ page }) => { -// await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) -// await borrowPage.fillBorrowAssetAction(borrow.amount) - -// await borrowPage.submitAction() - -// await actionsContainer.expectExtendedActions([ -// { type: 'deposit', asset: 'ETH', amount: '1.00' }, -// { type: 'borrow', asset: 'DAI', amount: '1,000.00' }, -// ]) -// await screenshot(page, 'deposit-eth-actions-plan') -// }) - -// test('successfully builds position', async ({ page }) => { -// await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) -// await borrowPage.fillBorrowAssetAction(borrow.amount) - -// await borrowPage.submitAction() - -// await actionsContainer.acceptAllActionsAction(2) - -// await borrowPage.expectSuccessPage([deposit], borrow, fork) -// await screenshot(page, 'deposit-eth-success') -// }) - -// test('HF matches after position is created', async ({ page }) => { -// await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) -// await borrowPage.fillBorrowAssetAction(borrow.amount) - -// await borrowPage.submitAction() -// await actionsContainer.acceptAllActionsAction(2) - -// await expectHFOnMyPortfolio(page, borrowPage, expectedHealthFactor) -// }) -// }) - -// test.describe('deposit wstETH and rETH, borrow DAI', () => { -// let borrowPage: BorrowPageObject -// let actionsContainer: ActionsPageObject -// const wstETHdeposit = { -// asset: 'wstETH', -// amount: 1, -// } -// const rETHdeposit = { -// asset: 'rETH', -// amount: 1, -// } -// const borrow = { -// asset: 'DAI', -// amount: 1000, -// } -// const expectedLTV = '19.57%' -// const expectedHealthFactor = '4.06' - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { -// wstETH: 10, -// rETH: 10, -// }, -// }, -// }) - -// borrowPage = new BorrowPageObject(page) -// actionsContainer = new ActionsPageObject(page) -// }) - -// test('calculates LTV correctly', async () => { -// await borrowPage.addNewDepositAssetAction() -// await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) -// await borrowPage.fillDepositAssetAction(1, rETHdeposit.asset, rETHdeposit.amount) -// await borrowPage.fillBorrowAssetAction(borrow.amount) - -// await borrowPage.submitAction() - -// await borrowPage.expectLtv(expectedLTV) -// await borrowPage.expectHealthFactor(expectedHealthFactor) -// }) - -// test('uses permits in action plan for assets with permit support', async ({ page }) => { -// await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) -// await borrowPage.fillBorrowAssetAction(borrow.amount) - -// await borrowPage.submitAction() - -// await actionsContainer.expectExtendedActions([ -// { type: 'permit', asset: 'wstETH', amount: '1.00' }, -// { type: 'deposit', asset: 'wstETH', amount: '1.00' }, -// { type: 'borrow', asset: 'DAI', amount: '1,000.00' }, -// ]) -// await screenshot(page, 'deposit-wsteth-permit-actions-plan') -// }) - -// test('uses approve in action plan for assets with no permit support', async ({ page }) => { -// await borrowPage.fillDepositAssetAction(0, rETHdeposit.asset, rETHdeposit.amount) -// await borrowPage.fillBorrowAssetAction(borrow.amount) - -// await borrowPage.submitAction() - -// await actionsContainer.expectExtendedActions([ -// { type: 'approve', asset: 'rETH', amount: '1.00' }, -// { type: 'deposit', asset: 'rETH', amount: '1.00' }, -// { type: 'borrow', asset: 'DAI', amount: '1,000.00' }, -// ]) -// await screenshot(page, 'deposit-reth-approve-actions-plan') -// }) - -// test('can switch to approves in action plan', async ({ page }) => { -// await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) -// await borrowPage.fillBorrowAssetAction(borrow.amount) - -// await borrowPage.submitAction() - -// await actionsContainer.switchPreferPermitsAction() -// await actionsContainer.expectExtendedActions([ -// { type: 'approve', asset: 'wstETH', amount: '1.00' }, -// { type: 'deposit', asset: 'wstETH', amount: '1.00' }, -// { type: 'borrow', asset: 'DAI', amount: '1,000.00' }, -// ]) -// await screenshot(page, 'deposit-wsteth-approve-actions-plan') -// }) - -// test('builds action plan for 2 assets', async ({ page }) => { -// await borrowPage.addNewDepositAssetAction() -// await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) -// await borrowPage.fillDepositAssetAction(1, rETHdeposit.asset, rETHdeposit.amount) -// await borrowPage.fillBorrowAssetAction(borrow.amount) - -// await borrowPage.submitAction() - -// await actionsContainer.expectExtendedActions([ -// { type: 'permit', asset: 'wstETH', amount: '1.00' }, -// { type: 'deposit', asset: 'wstETH', amount: '1.00' }, -// { type: 'approve', asset: 'rETH', amount: '1.00' }, -// { type: 'deposit', asset: 'rETH', amount: '1.00' }, -// { type: 'borrow', asset: 'DAI', amount: '1,000.00' }, -// ]) -// await screenshot(page, 'deposit-wsteth-reth-actions-plan') -// }) - -// test('successfully builds position', async ({ page }) => { -// await borrowPage.addNewDepositAssetAction() -// await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) -// await borrowPage.fillDepositAssetAction(1, rETHdeposit.asset, rETHdeposit.amount) -// await borrowPage.fillBorrowAssetAction(borrow.amount) - -// await borrowPage.submitAction() - -// await actionsContainer.acceptAllActionsAction(5) - -// await borrowPage.expectSuccessPage([wstETHdeposit, rETHdeposit], borrow, fork) -// await screenshot(page, 'deposit-wsteth-reth-success') -// }) - -// test('successfully builds position using only approves', async ({ page }) => { -// await borrowPage.addNewDepositAssetAction() -// await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) -// await borrowPage.fillDepositAssetAction(1, rETHdeposit.asset, rETHdeposit.amount) -// await borrowPage.fillBorrowAssetAction(borrow.amount) - -// await borrowPage.submitAction() - -// await actionsContainer.switchPreferPermitsAction() -// await actionsContainer.acceptAllActionsAction(5) - -// await borrowPage.expectSuccessPage([wstETHdeposit, rETHdeposit], borrow, fork) -// await screenshot(page, 'deposit-wsteth-reth-success') -// }) - -// test('HF matches after position is created', async ({ page }) => { -// await borrowPage.addNewDepositAssetAction() -// await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) -// await borrowPage.fillDepositAssetAction(1, rETHdeposit.asset, rETHdeposit.amount) -// await borrowPage.fillBorrowAssetAction(borrow.amount) - -// await borrowPage.submitAction() -// await actionsContainer.acceptAllActionsAction(5) - -// await expectHFOnMyPortfolio(page, borrowPage, expectedHealthFactor) -// }) -// }) - -// test.describe('no new deposit, existing position, borrow DAI', () => { -// let borrowPage: BorrowPageObject -// let actionsContainer: ActionsPageObject - -// const borrow = { -// asset: 'DAI', -// amount: 1000, -// } -// const expectedLTV = '8.04%' -// const expectedHealthFactor = '9.89' - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 10, -// rETH: 10, -// }, -// }, -// }) - -// borrowPage = new BorrowPageObject(page) -// actionsContainer = new ActionsPageObject(page) -// await borrowPage.depositAssetsActions({ rETH: 5 }, 1000) -// await page.reload() -// }) - -// test('calculates LTV correctly', async () => { -// await borrowPage.fillBorrowAssetAction(borrow.amount) - -// await borrowPage.submitAction() - -// await borrowPage.expectLtv(expectedLTV) -// await borrowPage.expectHealthFactor(expectedHealthFactor) -// }) - -// test('builds action plan', async ({ page }) => { -// await borrowPage.fillBorrowAssetAction(borrow.amount) - -// await borrowPage.submitAction() - -// await actionsContainer.expectExtendedActions([{ type: 'borrow', asset: 'DAI', amount: '1,000.00' }]) -// await screenshot(page, 'borrow-with-no-deposit-actions-plan') -// }) - -// test('successfully borrows', async ({ page }) => { -// await borrowPage.fillBorrowAssetAction(borrow.amount) - -// await borrowPage.submitAction() - -// await actionsContainer.acceptAllActionsAction(1) - -// await borrowPage.expectSuccessPage([], borrow, fork) -// await screenshot(page, 'borrow-with-no-deposit-success') -// }) - -// test('HF matches after position is created', async ({ page }) => { -// await borrowPage.fillBorrowAssetAction(borrow.amount) - -// await borrowPage.submitAction() -// await actionsContainer.acceptAllActionsAction(1) - -// await expectHFOnMyPortfolio(page, borrowPage, expectedHealthFactor) -// }) -// }) - -// test.describe('no wallet connected', () => { -// let borrowPage: BorrowPageObject -// const deposit = { -// asset: 'rETH', -// amount: 1, -// } -// const borrow = { -// asset: 'DAI', -// amount: 1000, -// } - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'not-connected', -// }, -// }) - -// borrowPage = new BorrowPageObject(page) -// }) - -// test('shows borrow rate correctly', async ({ page }) => { -// await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) -// await borrowPage.fillBorrowAssetAction(borrow.amount) -// await borrowPage.expectLtv('40.19%') -// await screenshot(page, 'borrow-form-not-connected-correct-ltv') -// }) - -// test('form is interactive', async ({ page }) => { -// await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) -// await borrowPage.fillBorrowAssetAction(borrow.amount) -// await screenshot(page, 'borrow-form-not-connected-interactive') -// }) -// }) - -// test.describe('form validation', () => { -// let borrowPage: BorrowPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 10, -// rETH: 10, -// WBTC: 10_000, -// }, -// }, -// }) - -// borrowPage = new BorrowPageObject(page) -// }) - -// test('is invalid when depositing more than available', async ({ page }) => { -// const deposit = { -// asset: 'ETH', -// amount: 100, -// } -// await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) -// await borrowPage.expectAssetInputInvalid('Exceeds your balance') -// await screenshot(page, 'borrow-form-deposit-more-than-available') -// }) - -// test('is invalid when borrowing more than collateral', async ({ page }) => { -// const deposit = { -// asset: 'ETH', -// amount: 1, -// } -// const borrow = { -// asset: 'DAI', -// amount: 10_000, -// } -// await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) -// await borrowPage.fillBorrowAssetAction(borrow.amount) -// await borrowPage.expectAssetInputInvalid(borrowValidationIssueToMessage['insufficient-collateral']) -// await screenshot(page, 'borrow-form-borrow-more-than-available') -// }) - -// test('is invalid when borrowing more than available', async ({ page }) => { -// const deposit = { -// asset: 'ETH', -// amount: 1, -// } -// const borrow = { -// asset: 'DAI', -// amount: 100_000_000, -// } -// await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) -// await borrowPage.fillBorrowAssetAction(borrow.amount) -// await borrowPage.expectAssetInputInvalid(borrowValidationIssueToMessage['exceeds-liquidity']) -// await screenshot(page, 'borrow-form-borrow-more-than-available') -// }) - -// test('is valid when not depositing anything but having existing position', async ({ page }) => { -// await borrowPage.depositAssetsActions({ rETH: 5 }, 1000) -// await page.reload() - -// await borrowPage.fillBorrowAssetAction(1000) -// await borrowPage.expectBorrowButtonActive() -// await screenshot(page, 'borrow-form-has-position') -// }) - -// test('is invalid when breaching supply cap', async () => { -// await borrowPage.fillDepositAssetAction(0, 'WBTC', 10_000) -// await borrowPage.expectAssetInputInvalid('Deposit cap reached') -// }) -// }) - -// test.describe('depositable assets', () => { -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { wstETH: 10 }, -// }, -// }) -// }) - -// test('deposit asset, turn off usage as collateral, try to deposit again', async ({ page }) => { -// const collateral = 'wstETH' - -// // Only depositing asset -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositWithoutBorrowActions({ [collateral]: 5 }) -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.goToMyPortfolioAction() - -// // Turning off usage as collateral at myPortfolio -// await myPortfolioPage.expectCollateralSwitch(collateral, true) -// await myPortfolioPage.clickCollateralSwitchAction(collateral) -// const collateralDialog = new CollateralDialogPageObject(page) -// await collateralDialog.expectDialogHeader('Collateral') -// await collateralDialog.expectHealthFactorNotVisible() -// const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(1) -// await collateralDialog.expectSetUseAsCollateralSuccessPage(collateral, 'disabled') - -// // Expecting asset not listed in deposit selector after turning off usage as collateral -// await borrowPage.goToEasyBorrowAction() -// await borrowPage.expectAssetNotListedInDepositSelector(collateral) -// }) -// }) - -// test.describe('Liquidation risk warning', () => { -// let borrowPage: BorrowPageObject - -// test.describe('In danger zone', () => { -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ETH: 1, rETH: 100 }, -// }, -// }) - -// borrowPage = new BorrowPageObject(page) -// await borrowPage.fillDepositAssetAction(0, 'rETH', 1) -// await borrowPage.fillBorrowAssetAction(1500) -// await borrowPage.submitAction() -// }) - -// test('shows risk warning', async () => { -// await borrowPage.expectLiquidationRiskWarning( -// 'Borrowing this amount puts you at risk of quick liquidation. You may lose part of your collateral.', -// ) -// }) - -// test('actions stay disabled until risk warning is acknowledged', async () => { -// const actionsContainer = new ActionsPageObject(borrowPage.locatePanelByHeader('Actions')) -// await actionsContainer.expectDisabledActionAtIndex(0) -// await borrowPage.clickAcknowledgeRisk() -// await actionsContainer.expectEnabledActionAtIndex(0) -// }) -// }) - -// test('hf above danger zone threshold; risk warning is not shown', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ETH: 1, rETH: 100 }, -// }, -// }) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.fillDepositAssetAction(0, 'rETH', 1) -// await borrowPage.fillBorrowAssetAction(1000) -// await borrowPage.submitAction() - -// await borrowPage.expectLiquidationRiskWarningNotVisible() -// }) -// }) -// }) - -// test.describe('Borrow page (usds deployed)', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let borrowPage: BorrowPageObject -// let actionsContainer: ActionsPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { -// wstETH: 10, -// }, -// }, -// }) - -// borrowPage = new BorrowPageObject(page) -// actionsContainer = new ActionsPageObject(page) -// }) - -// test('borrows usds', async ({ page }) => { -// await borrowPage.fillDepositAssetAction(0, 'wstETH', 10) -// await borrowPage.selectBorrowAction('USDS') -// await borrowPage.fillBorrowAssetAction(10_000) -// await borrowPage.submitAction() - -// await borrowPage.expectUsdsBorrowAlert() -// await actionsContainer.acceptAllActionsAction(5) -// await borrowPage.expectSuccessPage( -// [ -// { -// asset: 'wstETH', -// amount: 10, -// }, -// ], -// { -// asset: 'USDS', -// amount: 10_000, -// }, -// fork, -// { -// wstETH: 27_843.94, -// USDS: 10_000, -// }, -// ) - -// await expectHFOnMyPortfolio(page, borrowPage, '2.23') - -// await page.goto(buildUrl('savings')) -// const savingsPage = new SavingsPageObject(page) -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000') -// }) -// }) - -// async function expectHFOnMyPortfolio( -// page: Page, -// borrowPage: BorrowPageObject, -// expectedHealthFactor: string, -// ): Promise { -// await borrowPage.viewInMyPortfolioAction() -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// await myPortfolioPage.expectHealthFactor(expectedHealthFactor) -// } +import { borrowValidationIssueToMessage } from '@/domain/market-validators/validateBorrow' +import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +import { CollateralDialogPageObject } from '@/features/dialogs/collateral/CollateralDialog.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { TestContext, buildUrl, setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { BorrowPageObject } from './Borrow.PageObject' +import { MyPortfolioPageObject } from './MyPortfolio.PageObject' +import { SavingsPageObject } from './Savings.PageObject' + +test.describe('Borrow page', () => { + test.describe('deposit ETH, borrow DAI', () => { + let borrowPage: BorrowPageObject + let actionsContainer: ActionsPageObject + let testContext: TestContext<'connected-random'> + + const deposit = { + asset: 'ETH', + amount: 1, + } + const borrow = { + asset: 'DAI', + amount: 1000, + } + const expectedLtv = '25.46%' + const expectedHealthFactor = '3.26' + + test.beforeEach(async ({ page }) => { + testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { + ETH: 10, + }, + }, + }) + + borrowPage = new BorrowPageObject(testContext) + actionsContainer = new ActionsPageObject(testContext) + }) + + test('calculates LTV correctly', async () => { + await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) + await borrowPage.fillBorrowAssetAction(borrow.amount) + + await borrowPage.submitAction() + + await borrowPage.expectLtv(expectedLtv) + await borrowPage.expectHealthFactor(expectedHealthFactor) + }) + + test('builds action plan', async () => { + await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) + await borrowPage.fillBorrowAssetAction(borrow.amount) + + await borrowPage.submitAction() + + await actionsContainer.expectExtendedActions([ + { type: 'deposit', asset: 'ETH', amount: '1.00' }, + { type: 'borrow', asset: 'DAI', amount: '1,000.00' }, + ]) + }) + + test('successfully builds position', async () => { + await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) + await borrowPage.fillBorrowAssetAction(borrow.amount) + + await borrowPage.submitAction() + + await actionsContainer.acceptAllActionsAction(2) + + await borrowPage.expectSuccessPage({ + deposited: [{ asset: 'ETH', amount: '1.00', usdValue: '$3,928.31' }], + borrowed: { asset: 'DAI', amount: '1,000.00', usdValue: '$1,000.00' }, + }) + }) + + test('HF matches after position is created', async () => { + await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) + await borrowPage.fillBorrowAssetAction(borrow.amount) + + await borrowPage.submitAction() + await actionsContainer.acceptAllActionsAction(2) + + await expectHFOnMyPortfolio(testContext, borrowPage, expectedHealthFactor) + }) + }) + + test.describe('deposit wstETH and rETH, borrow DAI', () => { + let borrowPage: BorrowPageObject + let actionsContainer: ActionsPageObject + let testContext: TestContext<'connected-random'> + + const wstETHdeposit = { + asset: 'wstETH', + amount: 1, + } + const rETHdeposit = { + asset: 'rETH', + amount: 1, + } + const borrow = { + asset: 'DAI', + amount: 1000, + } + const expectedLTV = '11.01%' + const expectedHealthFactor = '7.26' + + test.beforeEach(async ({ page }) => { + testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { + wstETH: 10, + rETH: 10, + }, + }, + }) + + borrowPage = new BorrowPageObject(testContext) + actionsContainer = new ActionsPageObject(testContext) + }) + + test('calculates LTV correctly', async () => { + await borrowPage.addNewDepositAssetAction() + await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) + await borrowPage.fillDepositAssetAction(1, rETHdeposit.asset, rETHdeposit.amount) + await borrowPage.fillBorrowAssetAction(borrow.amount) + + await borrowPage.submitAction() + + await borrowPage.expectLtv(expectedLTV) + await borrowPage.expectHealthFactor(expectedHealthFactor) + }) + + test('uses permits in action plan for assets with permit support', async () => { + await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) + await borrowPage.fillBorrowAssetAction(borrow.amount) + + await borrowPage.submitAction() + + await actionsContainer.expectExtendedActions([ + { type: 'permit', asset: 'wstETH', amount: '1.00' }, + { type: 'deposit', asset: 'wstETH', amount: '1.00' }, + { type: 'borrow', asset: 'DAI', amount: '1,000.00' }, + ]) + }) + + test('uses approve in action plan for assets with no permit support', async () => { + await borrowPage.fillDepositAssetAction(0, rETHdeposit.asset, rETHdeposit.amount) + await borrowPage.fillBorrowAssetAction(borrow.amount) + + await borrowPage.submitAction() + + await actionsContainer.expectExtendedActions([ + { type: 'approve', asset: 'rETH', amount: '1.00' }, + { type: 'deposit', asset: 'rETH', amount: '1.00' }, + { type: 'borrow', asset: 'DAI', amount: '1,000.00' }, + ]) + }) + + test('can switch to approves in action plan', async () => { + await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) + await borrowPage.fillBorrowAssetAction(borrow.amount) + + await borrowPage.submitAction() + + await actionsContainer.switchPreferPermitsAction() + await actionsContainer.expectExtendedActions([ + { type: 'approve', asset: 'wstETH', amount: '1.00' }, + { type: 'deposit', asset: 'wstETH', amount: '1.00' }, + { type: 'borrow', asset: 'DAI', amount: '1,000.00' }, + ]) + }) + + test('builds action plan for 2 assets', async () => { + await borrowPage.addNewDepositAssetAction() + await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) + await borrowPage.fillDepositAssetAction(1, rETHdeposit.asset, rETHdeposit.amount) + await borrowPage.fillBorrowAssetAction(borrow.amount) + + await borrowPage.submitAction() + + await actionsContainer.expectExtendedActions([ + { type: 'permit', asset: 'wstETH', amount: '1.00' }, + { type: 'deposit', asset: 'wstETH', amount: '1.00' }, + { type: 'approve', asset: 'rETH', amount: '1.00' }, + { type: 'deposit', asset: 'rETH', amount: '1.00' }, + { type: 'borrow', asset: 'DAI', amount: '1,000.00' }, + ]) + }) + + test('successfully builds position', async () => { + await borrowPage.addNewDepositAssetAction() + await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) + await borrowPage.fillDepositAssetAction(1, rETHdeposit.asset, rETHdeposit.amount) + await borrowPage.fillBorrowAssetAction(borrow.amount) + + await borrowPage.submitAction() + + await actionsContainer.acceptAllActionsAction(5) + + await borrowPage.expectSuccessPage({ + deposited: [ + { asset: 'wstETH', amount: '1.00', usdValue: '$4,665.46' }, + { asset: 'rETH', amount: '1.00', usdValue: '$4,413.26' }, + ], + borrowed: { asset: 'DAI', amount: '1,000.00', usdValue: '$1,000.00' }, + }) + }) + + test('successfully builds position using only approves', async () => { + await borrowPage.addNewDepositAssetAction() + await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) + await borrowPage.fillDepositAssetAction(1, rETHdeposit.asset, rETHdeposit.amount) + await borrowPage.fillBorrowAssetAction(borrow.amount) + + await borrowPage.submitAction() + + await actionsContainer.switchPreferPermitsAction() + await actionsContainer.acceptAllActionsAction(5) + + await borrowPage.expectSuccessPage({ + deposited: [ + { asset: 'wstETH', amount: '1.00', usdValue: '$4,665.46' }, + { asset: 'rETH', amount: '1.00', usdValue: '$4,413.26' }, + ], + borrowed: { asset: 'DAI', amount: '1,000.00', usdValue: '$1,000.00' }, + }) + }) + + test('HF matches after position is created', async () => { + await borrowPage.addNewDepositAssetAction() + await borrowPage.fillDepositAssetAction(0, wstETHdeposit.asset, wstETHdeposit.amount) + await borrowPage.fillDepositAssetAction(1, rETHdeposit.asset, rETHdeposit.amount) + await borrowPage.fillBorrowAssetAction(borrow.amount) + + await borrowPage.submitAction() + await actionsContainer.acceptAllActionsAction(5) + + await expectHFOnMyPortfolio(testContext, borrowPage, expectedHealthFactor) + }) + }) + + test.describe('no new deposit, existing position, borrow DAI', () => { + let borrowPage: BorrowPageObject + let actionsContainer: ActionsPageObject + let testContext: TestContext<'connected-random'> + + const borrow = { + asset: 'DAI', + amount: 1000, + } + const expectedLTV = '9.06%' + const expectedHealthFactor = '8.83' + + test.beforeEach(async ({ page }) => { + testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { + ETH: 10, + rETH: 10, + }, + }, + }) + + borrowPage = new BorrowPageObject(testContext) + actionsContainer = new ActionsPageObject(testContext) + await borrowPage.depositAssetsActions({ assetsToDeposit: { rETH: 5 }, daiToBorrow: 1000 }) + await page.reload() + }) + + test('calculates LTV correctly', async () => { + await borrowPage.fillBorrowAssetAction(borrow.amount) + + await borrowPage.submitAction() + + await borrowPage.expectLtv(expectedLTV) + await borrowPage.expectHealthFactor(expectedHealthFactor) + }) + + test('builds action plan', async () => { + await borrowPage.fillBorrowAssetAction(borrow.amount) + + await borrowPage.submitAction() + + await actionsContainer.expectExtendedActions([{ type: 'borrow', asset: 'DAI', amount: '1,000.00' }]) + }) + + test('successfully borrows', async () => { + await borrowPage.fillBorrowAssetAction(borrow.amount) + + await borrowPage.submitAction() + + await actionsContainer.acceptAllActionsAction(1) + + await borrowPage.expectSuccessPage({ + deposited: [], + borrowed: { asset: 'DAI', amount: '1,000.00', usdValue: '$1,000.00' }, + }) + }) + + test('HF matches after position is created', async () => { + await borrowPage.fillBorrowAssetAction(borrow.amount) + + await borrowPage.submitAction() + await actionsContainer.acceptAllActionsAction(1) + + await expectHFOnMyPortfolio(testContext, borrowPage, expectedHealthFactor) + }) + }) + + test('borrows usds', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { + wstETH: 10, + }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + const actionsContainer = new ActionsPageObject(testContext) + + await borrowPage.fillDepositAssetAction(0, 'wstETH', 10) + await borrowPage.selectBorrowAction('USDS') + await borrowPage.fillBorrowAssetAction(10_000) + await borrowPage.submitAction() + + await borrowPage.expectUsdsBorrowAlert() + await actionsContainer.acceptAllActionsAction(5) + await borrowPage.expectSuccessPage({ + deposited: [ + { + asset: 'wstETH', + amount: '10.00', + usdValue: '$46,654.64', + }, + ], + borrowed: { + asset: 'USDS', + amount: '10,000.00', + usdValue: '$10,000.00', + }, + }) + + await expectHFOnMyPortfolio(testContext, borrowPage, '3.73') + + await page.goto(buildUrl('savings')) + const savingsPage = new SavingsPageObject(testContext) + await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000') + }) + + test.describe('no wallet connected', () => { + let borrowPage: BorrowPageObject + const deposit = { + asset: 'rETH', + amount: 1, + } + const borrow = { + asset: 'DAI', + amount: 1000, + } + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'easyBorrow', + account: { + type: 'not-connected', + }, + }) + + borrowPage = new BorrowPageObject(testContext) + }) + + test('shows borrow rate correctly', async () => { + await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) + await borrowPage.fillBorrowAssetAction(borrow.amount) + await borrowPage.expectLtv('22.66%') + }) + + test('form is interactive', async () => { + await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) + await borrowPage.fillBorrowAssetAction(borrow.amount) + }) + }) + + test.describe('form validation', () => { + let borrowPage: BorrowPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { + ETH: 10, + rETH: 10, + cbBTC: 100, + }, + }, + }) + + borrowPage = new BorrowPageObject(testContext) + }) + + test('is invalid when depositing more than available', async () => { + const deposit = { + asset: 'ETH', + amount: 100, + } + await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) + await borrowPage.expectAssetInputInvalid('Exceeds your balance') + }) + + test('is invalid when borrowing more than collateral', async () => { + const deposit = { + asset: 'ETH', + amount: 1, + } + const borrow = { + asset: 'DAI', + amount: 10_000, + } + await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) + await borrowPage.fillBorrowAssetAction(borrow.amount) + await borrowPage.expectAssetInputInvalid(borrowValidationIssueToMessage['insufficient-collateral']) + }) + + test('is invalid when borrowing more than available', async () => { + const deposit = { + asset: 'ETH', + amount: 1, + } + const borrow = { + asset: 'DAI', + amount: 1_000_000_000, + } + await borrowPage.fillDepositAssetAction(0, deposit.asset, deposit.amount) + await borrowPage.fillBorrowAssetAction(borrow.amount) + await borrowPage.expectAssetInputInvalid(borrowValidationIssueToMessage['exceeds-liquidity']) + }) + + test('is valid when not depositing anything but having existing position', async ({ page }) => { + await borrowPage.depositAssetsActions({ assetsToDeposit: { rETH: 5 }, daiToBorrow: 1000 }) + await page.reload() + + await borrowPage.fillBorrowAssetAction(1000) + await borrowPage.expectBorrowButtonActive() + }) + + test('is invalid when breaching supply cap', async () => { + await borrowPage.fillDepositAssetAction(0, 'cbBTC', 100) + await borrowPage.expectAssetInputInvalid('Deposit cap reached') + }) + }) + + test.describe('depositable assets', () => { + let testContext: TestContext<'connected-random'> + test.beforeEach(async ({ page }) => { + testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { wstETH: 10 }, + }, + }) + }) + + test('deposit asset, turn off usage as collateral, try to deposit again', async () => { + const collateral = 'wstETH' + + // Only depositing asset + const borrowPage = new BorrowPageObject(testContext) + await borrowPage.depositWithoutBorrowActions({ assetsToDeposit: { [collateral]: 5 } }) + const myPortfolioPage = new MyPortfolioPageObject(testContext) + await myPortfolioPage.goToMyPortfolioAction() + + // Turning off usage as collateral at myPortfolio + await myPortfolioPage.expectCollateralSwitch(collateral, true) + await myPortfolioPage.clickCollateralSwitchAction(collateral) + const collateralDialog = new CollateralDialogPageObject(testContext) + await collateralDialog.expectDialogHeader('Collateral') + await collateralDialog.expectHealthFactorNotVisible() + await collateralDialog.actionsContainer.acceptAllActionsAction(1) + await collateralDialog.expectSetUseAsCollateralSuccessPage(collateral, 'disabled') + + // Expecting asset not listed in deposit selector after turning off usage as collateral + await borrowPage.goToEasyBorrowAction() + await borrowPage.expectAssetNotListedInDepositSelector(collateral) + }) + }) + + test.describe('Liquidation risk warning', () => { + let borrowPage: BorrowPageObject + + test.describe('In danger zone', () => { + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ETH: 1, rETH: 100 }, + }, + }) + + borrowPage = new BorrowPageObject(testContext) + await borrowPage.fillDepositAssetAction(0, 'rETH', 1) + await borrowPage.fillBorrowAssetAction(3400) + await borrowPage.submitAction() + }) + + test('shows risk warning', async () => { + await borrowPage.expectLiquidationRiskWarning( + 'Borrowing this amount puts you at risk of quick liquidation. You may lose part of your collateral.', + ) + }) + + test('actions stay disabled until risk warning is acknowledged', async () => { + await borrowPage.actionsContainer.expectDisabledActionAtIndex(0) + await borrowPage.clickAcknowledgeRisk() + await borrowPage.actionsContainer.expectEnabledActionAtIndex(0) + }) + }) + + test('hf above danger zone threshold; risk warning is not shown', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ETH: 1, rETH: 100 }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + await borrowPage.fillDepositAssetAction(0, 'rETH', 1) + await borrowPage.fillBorrowAssetAction(1000) + await borrowPage.submitAction() + + await borrowPage.expectLiquidationRiskWarningNotVisible() + }) + }) +}) + +async function expectHFOnMyPortfolio( + testContext: TestContext, + borrowPage: BorrowPageObject, + expectedHealthFactor: string, +): Promise { + await borrowPage.viewInMyPortfolioAction() + const myPortfolioPage = new MyPortfolioPageObject(testContext) + + await myPortfolioPage.expectHealthFactor(expectedHealthFactor) +} diff --git a/packages/app/src/pages/Farms.test-e2e.ts b/packages/app/src/pages/Farms.test-e2e.ts index 23b98c873..802417fdb 100644 --- a/packages/app/src/pages/Farms.test-e2e.ts +++ b/packages/app/src/pages/Farms.test-e2e.ts @@ -1,4 +1,4 @@ -// import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' // import { setup } from '@/test/e2e/setup' @@ -7,7 +7,7 @@ // import { FarmsPageObject } from './Farms.PageObject' // test.describe('Farms', () => { -// const fork = setupFork({ blockNumber: USDS_ACTIVATED_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) // let farmsPage: FarmsPageObject // test.beforeEach(async ({ page }) => { diff --git a/packages/app/src/pages/MarketDetails.test-e2e.ts b/packages/app/src/pages/MarketDetails.test-e2e.ts index 183f1f0f8..559b406a3 100644 --- a/packages/app/src/pages/MarketDetails.test-e2e.ts +++ b/packages/app/src/pages/MarketDetails.test-e2e.ts @@ -2,7 +2,7 @@ // import { gnosis, mainnet } from 'viem/chains' // import { DialogPageObject } from '@/features/dialogs/common/Dialog.PageObject' -// import { CAP_AUTOMATOR_BLOCK_NUMBER, GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER, GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { buildUrl, setup } from '@/test/e2e/setup' // import { screenshot } from '@/test/e2e/utils' @@ -18,7 +18,7 @@ // const WBTC = '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599' // const fork = setupFork({ -// blockNumber: CAP_AUTOMATOR_BLOCK_NUMBER, +// blockNumber: DEFAULT_BLOCK_NUMBER, // chainId: mainnet.id, // simulationDateOverride: new Date('2024-09-04T14:21:19Z'), // }) diff --git a/packages/app/src/pages/Markets.test-e2e.ts b/packages/app/src/pages/Markets.test-e2e.ts index a70f04a14..20faee6e4 100644 --- a/packages/app/src/pages/Markets.test-e2e.ts +++ b/packages/app/src/pages/Markets.test-e2e.ts @@ -1,4 +1,4 @@ -// import { WEETH_ACTIVE_BLOCK_NUMBER } from '@/test/e2e/constants' +// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' // import { setupFork } from '@/test/e2e/forking/setupFork' // import { setup } from '@/test/e2e/setup' // import { test } from '@playwright/test' @@ -6,7 +6,7 @@ // import { MarketsPageObject } from './Markets.PageObject' // test.describe('Markets', () => { -// const fork = setupFork({ blockNumber: WEETH_ACTIVE_BLOCK_NUMBER, chainId: mainnet.id }) +// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) // let marketsPage: MarketsPageObject // test.beforeEach(async ({ page }) => { diff --git a/packages/app/src/test/e2e/assertions.ts b/packages/app/src/test/e2e/assertions.ts index ef4d41ab2..a79908839 100644 --- a/packages/app/src/test/e2e/assertions.ts +++ b/packages/app/src/test/e2e/assertions.ts @@ -1,25 +1,16 @@ import { Page, expect } from '@playwright/test' - -import { USD_MOCK_TOKEN } from '@/domain/types/Token' -import { NormalizedUnitNumber } from '@marsfoundation/common-universal' import { Abi, ContractFunctionName, ContractFunctionParameters, encodeFunctionData } from 'viem' import { __TX_LIST_KEY } from './constants' export interface TestTokenWithValue { asset: string - amount: number + amount: string + usdValue: string } -export function expectAssets(summary: string, assets: TestTokenWithValue[], assetsWorth: Record): void { +export function expectAssets(summary: string, assets: TestTokenWithValue[]): void { for (const asset of assets) { - const worth = assetsWorth[asset.asset]! - const amountFormatted = new Intl.NumberFormat('en-US', { - minimumFractionDigits: 2, - maximumFractionDigits: 18, // 18 is the maximum number of decimals for a token - }).format(asset.amount) - const usdValueFormatted = USD_MOCK_TOKEN.formatUSD(NormalizedUnitNumber(worth)) - - expect(summary).toMatch(`${asset.asset}${amountFormatted} ${usdValueFormatted}`) + expect(summary).toMatch(`${asset.asset}${asset.amount} ${asset.usdValue}`) } } diff --git a/packages/app/src/test/e2e/constants.ts b/packages/app/src/test/e2e/constants.ts index fd75ecc15..a64582591 100644 --- a/packages/app/src/test/e2e/constants.ts +++ b/packages/app/src/test/e2e/constants.ts @@ -56,6 +56,10 @@ const TOKENS_ON_MAINNET = { address: '0x56072c95faa701256059aa122697b133aded9279', decimals: 18, }, + cbBTC: { + address: '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf', + decimals: 8, + }, } as const export const TOKENS_ON_FORK = { @@ -118,22 +122,16 @@ type NonNativeTokens = | keyof (typeof TOKENS_ON_FORK)[8453] export type AssetsInTests = 'ETH' | 'XDAI' | NonNativeTokens -// @note At this block number: -// DAI oracle returns exactly 1 -// GNO is offboarded -export const DEFAULT_BLOCK_NUMBER = 19092430n -export const GNOSIS_DEFAULT_BLOCK_NUMBER = 34543308n -export const USDS_ACTIVATED_BLOCK_NUMBER = 20771186n +export const __TX_LIST_KEY = '__PLAYWRIGHT_TX_LIST' as any -export const LITE_PSM_ACTIONS_OPERABLE = 20618776n -export const LITE_PSM_ACTIONS_OPERABLE_DATE = new Date('2024-08-27T08:40:00Z') +// @note: Block from 14 December 2024: +// Stable oracles returning exactly 1 +// GNO is offboarded +// USDS, PSM light are deployed +export const DEFAULT_BLOCK_NUMBER = 21400000n +// Edge cases export const WBTC_SUPPLY_CAP_REACHED_BLOCK_NUMBER = 19034436n - export const GNO_ACTIVE_BLOCK_NUMBER = 18365842n -export const WEETH_ACTIVE_BLOCK_NUMBER = 20173717n - -export const __TX_LIST_KEY = '__PLAYWRIGHT_TX_LIST' as any - -export const CAP_AUTOMATOR_BLOCK_NUMBER = 20670518n +export const GNOSIS_DEFAULT_BLOCK_NUMBER = 34543308n diff --git a/packages/app/src/test/e2e/injectSetup.ts b/packages/app/src/test/e2e/injectSetup.ts index 9c7ef61ba..988877ea4 100644 --- a/packages/app/src/test/e2e/injectSetup.ts +++ b/packages/app/src/test/e2e/injectSetup.ts @@ -2,15 +2,10 @@ import { Page } from '@playwright/test' import { PLAYWRIGHT_CHAIN_ID, - PLAYWRIGHT_USDS_CONTRACTS_NOT_AVAILABLE_KEY, PLAYWRIGHT_WALLET_ADDRESS_KEY, PLAYWRIGHT_WALLET_FORK_URL_KEY, PLAYWRIGHT_WALLET_PRIVATE_KEY_KEY, } from '@/config/wagmi/config.e2e' - -import { TestnetClient } from '@marsfoundation/common-testnets' -import { zeroAddress } from 'viem' -import { base, mainnet } from 'viem/chains' import { InjectableWallet } from './setup' export async function injectWalletConfiguration(page: Page, wallet: InjectableWallet): Promise { @@ -85,36 +80,3 @@ function overrideDateClass(fakeNow: number): void { // @todo: When we are able to set timestamps for transactions, make tests that use vnets use line below instead of the overriding Date.now with offset // Date.now = () => fakeNow } - -export async function injectFlags(page: Page, testnetClient: TestnetClient): Promise { - const susdsDeployed = await isSudsDeployed(testnetClient) - - await page.addInitScript( - ({ PLAYWRIGHT_USDS_CONTRACTS_NOT_AVAILABLE_KEY, susdsDeployed }) => { - if (!susdsDeployed) { - ;(window as any)[PLAYWRIGHT_USDS_CONTRACTS_NOT_AVAILABLE_KEY] = true - } - }, - { PLAYWRIGHT_USDS_CONTRACTS_NOT_AVAILABLE_KEY, susdsDeployed }, - ) -} - -// @todo: Consider deleting this after rewriting tests with vnets -async function isSudsDeployed(testnetClient: TestnetClient): Promise { - const chainId = await testnetClient.getChainId() - - const susdsAddress = (() => { - if (chainId === mainnet.id) { - return '0xa3931d71877C0E7a3148CB7Eb4463524FEc27fbD' - } - - if (chainId === base.id) { - return '0x5875eEE11Cf8398102FdAd704C9E96607675467a' - } - - return zeroAddress - })() - const susdsBytecode = await testnetClient.getCode({ address: susdsAddress }) - - return susdsBytecode !== undefined && susdsBytecode.length > 2 -} diff --git a/packages/app/src/test/e2e/setup.ts b/packages/app/src/test/e2e/setup.ts index edd8a292c..00c83a157 100644 --- a/packages/app/src/test/e2e/setup.ts +++ b/packages/app/src/test/e2e/setup.ts @@ -8,7 +8,6 @@ import { AssetsInTests, TOKENS_ON_FORK } from './constants' import { getTestnetContext } from './getTestnetContext' import { injectFixedDate, - injectFlags, injectNetworkConfiguration, injectUpdatedDate, injectWalletConfiguration, @@ -194,5 +193,4 @@ async function injectPageSetup({ await injectNetworkConfiguration(page, getUrlFromClient(testnetClient), options.blockchain.chainId) } await injectFixedDate(page, new Date(Number(blockchainTimestamp) * 1000)) - await injectFlags(page, testnetClient) } From 3ff97d25fd017721e631a99de42b7f2d8384fdf6 Mon Sep 17 00:00:00 2001 From: Oskar <43062492+oskarvu@users.noreply.github.com> Date: Wed, 18 Dec 2024 19:27:43 +0700 Subject: [PATCH 11/29] Rewrite markets and market details tests (#500) * Rewrite markets page tests * Uncomment market details test file * Update markets tests * Update market details tests * Remove screenshot helper --- .../app/src/pages/MarketDetails.test-e2e.ts | 1188 +++++++++-------- packages/app/src/pages/Markets.test-e2e.ts | 593 ++++---- packages/app/src/test/e2e/utils.ts | 48 - 3 files changed, 918 insertions(+), 911 deletions(-) diff --git a/packages/app/src/pages/MarketDetails.test-e2e.ts b/packages/app/src/pages/MarketDetails.test-e2e.ts index 559b406a3..91aeeffca 100644 --- a/packages/app/src/pages/MarketDetails.test-e2e.ts +++ b/packages/app/src/pages/MarketDetails.test-e2e.ts @@ -1,589 +1,599 @@ -// import { test } from '@playwright/test' -// import { gnosis, mainnet } from 'viem/chains' - -// import { DialogPageObject } from '@/features/dialogs/common/Dialog.PageObject' -// import { DEFAULT_BLOCK_NUMBER, GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { buildUrl, setup } from '@/test/e2e/setup' -// import { screenshot } from '@/test/e2e/utils' - -// import { BorrowPageObject } from './Borrow.PageObject' -// import { MarketDetailsPageObject } from './MarketDetails.PageObject' - -// test.describe('Market details Mainnet', () => { -// const DAI = '0x6B175474E89094C44Da98b954EedeAC495271d0F' -// const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' -// const WEETH = '0xcd5fe23c85820f7b72d0926fc9b05b43e359b7ee' -// const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' -// const WBTC = '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599' - -// const fork = setupFork({ -// blockNumber: DEFAULT_BLOCK_NUMBER, -// chainId: mainnet.id, -// simulationDateOverride: new Date('2024-09-04T14:21:19Z'), -// }) - -// test.describe('Market overview', () => { -// test('DAI', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'marketDetails', -// initialPageParams: { asset: DAI, chainId: fork.chainId.toString() }, -// account: { -// type: 'not-connected', -// }, -// }) - -// const marketDetailsPage = new MarketDetailsPageObject(page) -// await marketDetailsPage.expectMarketOverviewValue('Borrowed', '$910.8M') -// await marketDetailsPage.expectMarketOverviewValue('Instantly available', '$44.01M') -// await marketDetailsPage.expectMarketOverviewValue('Sky capacity', '$1.586B') - -// await screenshot(page, 'market-details-dai') -// }) - -// test('WETH', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'marketDetails', -// initialPageParams: { asset: WETH, chainId: fork.chainId.toString() }, -// account: { -// type: 'not-connected', -// }, -// }) - -// const marketDetailsPage = new MarketDetailsPageObject(page) -// await marketDetailsPage.expectMarketOverviewValue('Borrowed', '$571.1M') -// await marketDetailsPage.expectMarketOverviewValue('Instantly available', '$125.4M') - -// await screenshot(page, 'market-details-weth') -// }) - -// test.describe('token that cannot be borrowed', () => { -// test('overview is visible when borrowed balance greater than non-zero', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'marketDetails', -// initialPageParams: { asset: WBTC, chainId: fork.chainId.toString() }, -// account: { -// type: 'not-connected', -// }, -// }) - -// const marketDetailsPage = new MarketDetailsPageObject(page) -// await marketDetailsPage.expectToBeLoaded() -// }) - -// test('overview is hidden when borrowed balance equal zero', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'marketDetails', -// initialPageParams: { asset: WEETH, chainId: fork.chainId.toString() }, -// account: { -// type: 'not-connected', -// }, -// }) - -// const marketDetailsPage = new MarketDetailsPageObject(page) -// await marketDetailsPage.expectMarketOverviewToBeHidden() -// }) -// }) -// }) - -// test.describe('Dialogs', () => { -// const initialDeposits = { -// wstETH: 10, -// } - -// test('guest state', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'marketDetails', -// initialPageParams: { asset: DAI, chainId: fork.chainId.toString() }, -// account: { -// type: 'not-connected', -// }, -// }) - -// const marketDetailsPage = new MarketDetailsPageObject(page) - -// await marketDetailsPage.expectToBeLoaded() - -// await marketDetailsPage.expectConnectWalletButton() -// await marketDetailsPage.expectDialogButtonToBeInvisible('Lend') -// await marketDetailsPage.expectDialogButtonToBeInvisible('Deposit') -// await marketDetailsPage.expectDialogButtonToBeInvisible('Borrow') -// }) - -// test("can't deposit if not enough balance", async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'marketDetails', -// initialPageParams: { asset: WETH, chainId: fork.chainId.toString() }, -// account: { -// type: 'connected-random', -// }, -// }) - -// const marketDetailsPage = new MarketDetailsPageObject(page) - -// await marketDetailsPage.expectToBeLoaded() - -// await marketDetailsPage.expectDialogButtonToBeInactive('Deposit') -// }) - -// test("can't lend if not enough balance", async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'marketDetails', -// initialPageParams: { asset: DAI, chainId: fork.chainId.toString() }, -// account: { -// type: 'connected-random', -// }, -// }) - -// const marketDetailsPage = new MarketDetailsPageObject(page) - -// await marketDetailsPage.expectToBeLoaded() - -// await marketDetailsPage.expectDialogButtonToBeInactive('Lend') -// }) - -// test("can't borrow if not enough balance", async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'marketDetails', -// initialPageParams: { asset: DAI, chainId: fork.chainId.toString() }, -// account: { -// type: 'connected-random', -// }, -// }) - -// const marketDetailsPage = new MarketDetailsPageObject(page) - -// await marketDetailsPage.expectToBeLoaded() - -// await marketDetailsPage.expectBorrowNotAvailableDisclaimer() -// await marketDetailsPage.expectDialogButtonToBeInvisible('Borrow') -// }) - -// test('opens dialogs for DAI', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { -// ...initialDeposits, -// DAI: 1000, -// sDAI: 1000, -// }, -// }, -// }) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositWithoutBorrowActions({ ...initialDeposits }) - -// await page.goto(buildUrl('marketDetails', { asset: DAI, chainId: fork.chainId.toString() })) - -// const marketDetailsPage = new MarketDetailsPageObject(page) - -// await marketDetailsPage.openDialogAction('Lend') -// const lendDialog = new DialogPageObject(page, /Deposit/i) -// await lendDialog.expectDialogHeader('Deposit DAI') -// await lendDialog.closeDialog() - -// await marketDetailsPage.openDialogAction('Deposit') -// const depositDialog = new DialogPageObject(page, /Deposit/i) -// await depositDialog.expectDialogHeader('Deposit sDAI') -// await depositDialog.closeDialog() - -// await marketDetailsPage.openDialogAction('Borrow') -// const borrowDialog = new DialogPageObject(page, /Borrow/i) -// await borrowDialog.expectDialogHeader('Borrow DAI') -// await borrowDialog.closeDialog() -// }) - -// test('opens dialogs for WETH', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { -// ...initialDeposits, -// WETH: 10, -// }, -// }, -// }) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositWithoutBorrowActions({ ...initialDeposits }) - -// await page.goto(buildUrl('marketDetails', { asset: WETH, chainId: fork.chainId.toString() })) - -// const marketDetailsPage = new MarketDetailsPageObject(page) - -// await marketDetailsPage.openDialogAction('Deposit') -// const lendDialog = new DialogPageObject(page, /Deposit/i) -// await lendDialog.expectDialogHeader('Deposit WETH') -// await lendDialog.closeDialog() - -// await marketDetailsPage.openDialogAction('Borrow') -// const borrowDialog = new DialogPageObject(page, /Borrow/i) -// await borrowDialog.expectDialogHeader('Borrow WETH') -// await borrowDialog.closeDialog() -// }) - -// // @todo: this scenario is inaccurate, because user has only ETH - in future dialog should open on ETH tab -// test('opens dialogs for WETH when having only ETH', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { -// ...initialDeposits, -// ETH: 5, -// }, -// }, -// }) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositWithoutBorrowActions({ ...initialDeposits }) - -// await page.goto(buildUrl('marketDetails', { asset: WETH, chainId: fork.chainId.toString() })) - -// const marketDetailsPage = new MarketDetailsPageObject(page) - -// await marketDetailsPage.expectWalletBalance('5.00 WETH') - -// await marketDetailsPage.openDialogAction('Deposit') -// const lendDialog = new DialogPageObject(page, /Deposit/i) -// await lendDialog.expectDialogHeader('Deposit WETH') -// await lendDialog.closeDialog() - -// await marketDetailsPage.openDialogAction('Borrow') -// const borrowDialog = new DialogPageObject(page, /Borrow/i) -// await borrowDialog.expectDialogHeader('Borrow WETH') -// await borrowDialog.closeDialog() -// }) - -// test('wallet displays sum of WETH and ETH', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'marketDetails', -// initialPageParams: { -// asset: WETH, -// chainId: fork.chainId.toString(), -// }, -// account: { -// type: 'connected-random', -// assetBalances: { -// ...initialDeposits, -// ETH: 5, -// WETH: 10, -// }, -// }, -// }) - -// const marketDetailsPage = new MarketDetailsPageObject(page) - -// await marketDetailsPage.expectWalletBalance('15.00 WETH') -// }) -// }) - -// test.describe('Isolated assets', () => { -// const BLOCK_NUMBER_WITH_WEETH = 20118125n -// const fork = setupFork({ blockNumber: BLOCK_NUMBER_WITH_WEETH, chainId: mainnet.id }) - -// test('Correctly displays debt ceiling', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'marketDetails', -// initialPageParams: { asset: WEETH, chainId: fork.chainId.toString() }, -// account: { -// type: 'not-connected', -// }, -// }) - -// const marketDetailsPage = new MarketDetailsPageObject(page) -// await marketDetailsPage.expectDebt('$3.17M') -// await marketDetailsPage.expectDebtCeiling('$50M') -// }) -// }) - -// test.describe('Errors', () => { -// const NOT_A_RESERVE = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266' - -// test('displays 404 page for unknown chain', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'marketDetails', -// initialPageParams: { asset: DAI, chainId: '12345' }, -// account: { -// type: 'not-connected', -// }, -// }) - -// const marketDetailsPage = new MarketDetailsPageObject(page) -// await marketDetailsPage.expect404() -// }) - -// test('displays 404 page for unknown asset', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'marketDetails', -// initialPageParams: { asset: NOT_A_RESERVE, chainId: fork.chainId.toString() }, -// account: { -// type: 'not-connected', -// }, -// }) - -// const marketDetailsPage = new MarketDetailsPageObject(page) -// await marketDetailsPage.expect404() -// }) -// }) - -// test.describe('Cap automator', () => { -// test('WETH', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'marketDetails', -// initialPageParams: { asset: WETH, chainId: fork.chainId.toString() }, -// account: { -// type: 'not-connected', -// }, -// }) - -// const marketDetailsPage = new MarketDetailsPageObject(page) - -// await marketDetailsPage.expectSupplyCap('403.2K WETH') -// await marketDetailsPage.expectSupplyMaxCap('2M WETH') -// await marketDetailsPage.expectSupplyCapCooldown('0h 00m 00s') - -// await marketDetailsPage.expectBorrowCap('256K WETH') -// await marketDetailsPage.expectBorrowMaxCap('1M WETH') -// await marketDetailsPage.expectBorrowCapCooldown('0h 00m 00s') -// }) - -// test('USDC', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'marketDetails', -// initialPageParams: { asset: USDC, chainId: fork.chainId.toString() }, -// account: { -// type: 'not-connected', -// }, -// }) - -// const marketDetailsPage = new MarketDetailsPageObject(page) - -// await marketDetailsPage.expectSupplyPanelNotVisible() - -// await marketDetailsPage.expectBorrowCap('7.678M USDC') -// await marketDetailsPage.expectBorrowMaxCap('57M USDC') -// await marketDetailsPage.expectBorrowCapCooldown('0h 00m 00s') -// }) - -// test('WBTC', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'marketDetails', -// initialPageParams: { asset: WBTC, chainId: fork.chainId.toString() }, -// account: { -// type: 'not-connected', -// }, -// }) - -// const marketDetailsPage = new MarketDetailsPageObject(page) - -// await marketDetailsPage.expectSupplyCap('4,780 WBTC') -// await marketDetailsPage.expectSupplyMaxCap('10K WBTC') -// await marketDetailsPage.expectSupplyCapCooldown('0h 00m 00s') - -// await marketDetailsPage.expectBorrowPanelNotVisible() -// await marketDetailsPage.expectToBeDisabledAsCollateral() -// await marketDetailsPage.expectDisabledCollateralInfoVisible() -// }) -// }) - -// test.describe('Oracles', () => { -// test('Fixed price', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'marketDetails', -// initialPageParams: { asset: DAI, chainId: fork.chainId.toString() }, -// account: { -// type: 'not-connected', -// }, -// }) - -// const marketDetailsPage = new MarketDetailsPageObject(page) - -// await marketDetailsPage.expectOraclePanelToHaveTitle('Fixed Price') - -// await marketDetailsPage.expectOracleInfo({ -// price: '$1.00', -// asset: 'DAI', -// oracleContract: '0x42a03F81dd8A1cEcD746dc262e4d1CD9fD39F777', -// }) -// }) -// test('Market price - not redundant', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'marketDetails', -// initialPageParams: { asset: WBTC, chainId: fork.chainId.toString() }, -// account: { -// type: 'not-connected', -// }, -// }) - -// const marketDetailsPage = new MarketDetailsPageObject(page) - -// await marketDetailsPage.expectOraclePanelToHaveTitle('Market Price') -// await marketDetailsPage.expectOracleToBeNotRedundant() - -// await marketDetailsPage.expectOracleInfo({ -// price: '$58,229.82', -// asset: 'WBTC', -// oracleContract: '0x230E0321Cf38F09e247e50Afc7801EA2351fe56F', -// }) -// }) - -// test('Yielding fixed price - redundant', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'marketDetails', -// initialPageParams: { asset: WEETH, chainId: fork.chainId.toString() }, -// account: { -// type: 'not-connected', -// }, -// }) - -// const marketDetailsPage = new MarketDetailsPageObject(page) - -// await marketDetailsPage.expectOraclePanelToHaveTitle('Yielding Fixed Price') -// await marketDetailsPage.expectOracleToBeRedundant() - -// await marketDetailsPage.expectOracleInfo({ -// price: '$2,576.50', -// asset: 'weETH', -// oracleContract: '0x1A6BDB22b9d7a454D20EAf12DB55D6B5F058183D', -// }) -// await marketDetailsPage.expectYieldingFixedOracleBaseAssetInfo({ -// asset: 'WETH', -// price: '$2,460.69', -// oracleContract: '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419', -// }) -// await marketDetailsPage.expectYieldingFixedOracleRatioInfo({ -// ratio: '1.0471', -// ratioContract: '0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee', -// }) -// }) -// }) -// }) - -// test.describe('Market details Gnosis', () => { -// const XDAI = '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d' -// const EURe = '0xcB444e90D8198415266c6a2724b7900fb12FC56E' -// const WETH = '0x6A023CCd1ff6F2045C3309768eAd9E68F978f6e1' -// const sDAI = '0xaf204776c7245bF4147c2612BF6e5972Ee483701' - -// const fork = setupFork({ -// blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, -// chainId: gnosis.id, -// useTenderlyVnet: true, -// }) - -// test.describe('Cap automator', () => { -// test('WETH', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'marketDetails', -// initialPageParams: { asset: WETH, chainId: fork.chainId.toString() }, -// account: { -// type: 'not-connected', -// }, -// }) - -// const marketDetailsPage = new MarketDetailsPageObject(page) - -// await marketDetailsPage.expectSupplyCap('5,000 WETH') -// await marketDetailsPage.expectSupplyMaxCapNotVisible() - -// await marketDetailsPage.expectBorrowCap('3,000 WETH') -// await marketDetailsPage.expectBorrowMaxCapNotVisible() -// }) - -// test('XDAI', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'marketDetails', -// initialPageParams: { asset: XDAI, chainId: fork.chainId.toString() }, -// account: { -// type: 'not-connected', -// }, -// }) - -// const marketDetailsPage = new MarketDetailsPageObject(page) - -// await marketDetailsPage.expectSupplyCap('20M WXDAI') -// await marketDetailsPage.expectSupplyMaxCapNotVisible() - -// await marketDetailsPage.expectBorrowCap('16M WXDAI') -// await marketDetailsPage.expectBorrowMaxCapNotVisible() - -// await marketDetailsPage.expectCollateralPanelNotVisible() -// }) -// }) - -// test.describe('Oracles', () => { -// test('Fixed price', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'marketDetails', -// initialPageParams: { asset: XDAI, chainId: fork.chainId.toString() }, -// account: { -// type: 'not-connected', -// }, -// }) - -// const marketDetailsPage = new MarketDetailsPageObject(page) - -// await marketDetailsPage.expectOraclePanelToHaveTitle('Fixed Price') - -// await marketDetailsPage.expectOracleInfo({ -// price: '$1.00', -// asset: 'WXDAI', -// oracleContract: '0x6FC2871B6d9A94866B7260896257Fd5b50c09900', -// }) -// }) - -// test('Underlying asset price', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'marketDetails', -// initialPageParams: { asset: EURe, chainId: fork.chainId.toString() }, -// account: { -// type: 'not-connected', -// }, -// }) - -// const marketDetailsPage = new MarketDetailsPageObject(page) - -// await marketDetailsPage.expectOraclePanelToHaveTitle('Underlying Asset Price') - -// await marketDetailsPage.expectOracleInfo({ -// price: '$1.07', -// asset: 'EUR', -// oracleContract: '0xab70BCB260073d036d1660201e9d5405F5829b7a', -// }) -// }) - -// test('Yielding fixed price - not redundant', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'marketDetails', -// initialPageParams: { asset: sDAI, chainId: fork.chainId.toString() }, -// account: { -// type: 'not-connected', -// }, -// }) - -// const marketDetailsPage = new MarketDetailsPageObject(page) - -// await marketDetailsPage.expectOraclePanelToHaveTitle('Yielding Fixed Price') -// await marketDetailsPage.expectOracleToBeNotRedundant() - -// await marketDetailsPage.expectOracleInfo({ -// price: '$1.0875', -// asset: 'sDAI', -// oracleContract: '0x1D0f881Ce1a646E2f27Dec3c57Fa056cB838BCC2', -// }) -// await marketDetailsPage.expectYieldingFixedOracleBaseAssetInfo({ -// asset: 'DAI', -// price: '$0.9997', -// oracleContract: '0x678df3415fc31947dA4324eC63212874be5a82f8', -// }) -// await marketDetailsPage.expectYieldingFixedOracleRatioInfo({ -// ratio: '1.0878', -// ratioContract: '0xaf204776c7245bF4147c2612BF6e5972Ee483701', -// }) -// }) -// }) -// }) +import { DialogPageObject } from '@/features/dialogs/common/Dialog.PageObject' +import { DEFAULT_BLOCK_NUMBER, GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { buildUrl, setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { gnosis, mainnet } from 'viem/chains' + +import { BorrowPageObject } from './Borrow.PageObject' +import { MarketDetailsPageObject } from './MarketDetails.PageObject' + +test.describe('Market details Mainnet', () => { + const DAI = '0x6B175474E89094C44Da98b954EedeAC495271d0F' + const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' + const WEETH = '0xcd5fe23c85820f7b72d0926fc9b05b43e359b7ee' + const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' + const WBTC = '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599' + + test.describe('Market overview', () => { + test('DAI', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'marketDetails', + initialPageParams: { asset: DAI, chainId: mainnet.id.toString() }, + account: { + type: 'not-connected', + }, + }) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + await marketDetailsPage.expectMarketOverviewValue('Borrowed', '$1.626B') + await marketDetailsPage.expectMarketOverviewValue('Instantly available', '$112.8M') + await marketDetailsPage.expectMarketOverviewValue('Sky capacity', '$793.4M') + }) + + test('WETH', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'marketDetails', + initialPageParams: { asset: WETH, chainId: mainnet.id.toString() }, + account: { + type: 'not-connected', + }, + }) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + await marketDetailsPage.expectMarketOverviewValue('Borrowed', '$1.365B') + await marketDetailsPage.expectMarketOverviewValue('Instantly available', '$171M') + }) + + test.describe('token that cannot be borrowed', () => { + test('overview is visible when borrowed balance greater than non-zero', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'marketDetails', + initialPageParams: { asset: WBTC, chainId: mainnet.id.toString() }, + account: { + type: 'not-connected', + }, + }) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + await marketDetailsPage.expectToBeLoaded() + }) + + test('overview is hidden when borrowed balance equal zero', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'marketDetails', + initialPageParams: { asset: WEETH, chainId: mainnet.id.toString() }, + account: { + type: 'not-connected', + }, + }) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + await marketDetailsPage.expectMarketOverviewToBeHidden() + }) + }) + }) + + test.describe('Dialogs', () => { + const initialDeposits = { + wstETH: 10, + } + + test('guest state', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'marketDetails', + initialPageParams: { asset: DAI, chainId: mainnet.id.toString() }, + account: { + type: 'not-connected', + }, + }) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + + await marketDetailsPage.expectToBeLoaded() + + await marketDetailsPage.expectConnectWalletButton() + await marketDetailsPage.expectDialogButtonToBeInvisible('Lend') + await marketDetailsPage.expectDialogButtonToBeInvisible('Deposit') + await marketDetailsPage.expectDialogButtonToBeInvisible('Borrow') + }) + + test("can't deposit if not enough balance", async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'marketDetails', + initialPageParams: { asset: WETH, chainId: mainnet.id.toString() }, + account: { + type: 'connected-random', + }, + }) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + + await marketDetailsPage.expectToBeLoaded() + + await marketDetailsPage.expectDialogButtonToBeInactive('Deposit') + }) + + test("can't lend if not enough balance", async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'marketDetails', + initialPageParams: { asset: DAI, chainId: mainnet.id.toString() }, + account: { + type: 'connected-random', + }, + }) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + + await marketDetailsPage.expectToBeLoaded() + + await marketDetailsPage.expectDialogButtonToBeInactive('Lend') + }) + + test("can't borrow if not enough balance", async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'marketDetails', + initialPageParams: { asset: DAI, chainId: mainnet.id.toString() }, + account: { + type: 'connected-random', + }, + }) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + + await marketDetailsPage.expectToBeLoaded() + + await marketDetailsPage.expectBorrowNotAvailableDisclaimer() + await marketDetailsPage.expectDialogButtonToBeInvisible('Borrow') + }) + + test('opens dialogs for DAI', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { + ...initialDeposits, + DAI: 1000, + sDAI: 1000, + }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + await borrowPage.depositWithoutBorrowActions({ assetsToDeposit: initialDeposits }) + + await page.goto(buildUrl('marketDetails', { asset: DAI, chainId: mainnet.id.toString() })) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + + await marketDetailsPage.openDialogAction('Lend') + const lendDialog = new DialogPageObject({ testContext, header: /Deposit/i }) + await lendDialog.expectDialogHeader('Deposit DAI') + await lendDialog.closeDialog() + + await marketDetailsPage.openDialogAction('Deposit') + const depositDialog = new DialogPageObject({ testContext, header: /Deposit/i }) + await depositDialog.expectDialogHeader('Deposit sDAI') + await depositDialog.closeDialog() + + await marketDetailsPage.openDialogAction('Borrow') + const borrowDialog = new DialogPageObject({ testContext, header: /Borrow/i }) + await borrowDialog.expectDialogHeader('Borrow DAI') + await borrowDialog.closeDialog() + }) + + test('opens dialogs for WETH', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { + ...initialDeposits, + WETH: 10, + }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + await borrowPage.depositWithoutBorrowActions({ assetsToDeposit: initialDeposits }) + + await page.goto(buildUrl('marketDetails', { asset: WETH, chainId: mainnet.id.toString() })) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + + await marketDetailsPage.openDialogAction('Deposit') + const lendDialog = new DialogPageObject({ testContext, header: /Deposit/i }) + await lendDialog.expectDialogHeader('Deposit WETH') + await lendDialog.closeDialog() + + await marketDetailsPage.openDialogAction('Borrow') + const borrowDialog = new DialogPageObject({ testContext, header: /Borrow/i }) + await borrowDialog.expectDialogHeader('Borrow WETH') + await borrowDialog.closeDialog() + }) + + // @todo: this scenario is inaccurate, because user has only ETH - in future dialog should open on ETH tab + test('opens dialogs for WETH when having only ETH', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { + ...initialDeposits, + ETH: 5, + }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + await borrowPage.depositWithoutBorrowActions({ assetsToDeposit: initialDeposits }) + + await page.goto(buildUrl('marketDetails', { asset: WETH, chainId: mainnet.id.toString() })) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + + await marketDetailsPage.expectWalletBalance('5.00 WETH') + + await marketDetailsPage.openDialogAction('Deposit') + const lendDialog = new DialogPageObject({ testContext, header: /Deposit/i }) + await lendDialog.expectDialogHeader('Deposit WETH') + await lendDialog.closeDialog() + + await marketDetailsPage.openDialogAction('Borrow') + const borrowDialog = new DialogPageObject({ testContext, header: /Borrow/i }) + await borrowDialog.expectDialogHeader('Borrow WETH') + await borrowDialog.closeDialog() + }) + + test('wallet displays sum of WETH and ETH', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'marketDetails', + initialPageParams: { + asset: WETH, + chainId: mainnet.id.toString(), + }, + account: { + type: 'connected-random', + assetBalances: { + ...initialDeposits, + ETH: 5, + WETH: 10, + }, + }, + }) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + + await marketDetailsPage.expectWalletBalance('15.00 WETH') + }) + }) + + test.describe('Isolated assets', () => { + test('Correctly displays debt ceiling', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'marketDetails', + initialPageParams: { asset: WEETH, chainId: mainnet.id.toString() }, + account: { + type: 'not-connected', + }, + }) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + await marketDetailsPage.expectDebt('$89M') + await marketDetailsPage.expectDebtCeiling('$200M') + }) + }) + + test.describe('Errors', () => { + const NOT_A_RESERVE = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266' + + test('displays 404 page for unknown chain', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'marketDetails', + initialPageParams: { asset: DAI, chainId: '12345' }, + account: { + type: 'not-connected', + }, + }) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + await marketDetailsPage.expect404() + }) + + test('displays 404 page for unknown asset', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'marketDetails', + initialPageParams: { asset: NOT_A_RESERVE, chainId: mainnet.id.toString() }, + account: { + type: 'not-connected', + }, + }) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + await marketDetailsPage.expect404() + }) + }) + + test.describe('Cap automator', () => { + test('WETH', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'marketDetails', + initialPageParams: { asset: WETH, chainId: mainnet.id.toString() }, + account: { + type: 'not-connected', + }, + }) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + + await marketDetailsPage.expectSupplyCap('569.9K WETH') + await marketDetailsPage.expectSupplyMaxCap('2M WETH') + await marketDetailsPage.expectSupplyCapCooldown('0h 00m 00s') + + await marketDetailsPage.expectBorrowCap('368.2K WETH') + await marketDetailsPage.expectBorrowMaxCap('1M WETH') + await marketDetailsPage.expectBorrowCapCooldown('0h 00m 00s') + }) + + test('USDC', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'marketDetails', + initialPageParams: { asset: USDC, chainId: mainnet.id.toString() }, + account: { + type: 'not-connected', + }, + }) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + + await marketDetailsPage.expectSupplyPanelNotVisible() + + await marketDetailsPage.expectBorrowCap('7.678M USDC') + await marketDetailsPage.expectBorrowMaxCap('57M USDC') + await marketDetailsPage.expectBorrowCapCooldown('0h 00m 00s') + }) + + test('WBTC', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'marketDetails', + initialPageParams: { asset: WBTC, chainId: mainnet.id.toString() }, + account: { + type: 'not-connected', + }, + }) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + + await marketDetailsPage.expectSupplyCap('1,941 WBTC') + await marketDetailsPage.expectSupplyMaxCap('5,000 WBTC') + await marketDetailsPage.expectSupplyCapCooldown('0h 00m 00s') + + await marketDetailsPage.expectBorrowPanelNotVisible() + await marketDetailsPage.expectToBeDisabledAsCollateral() + await marketDetailsPage.expectDisabledCollateralInfoVisible() + }) + }) + + test.describe('Oracles', () => { + test('Fixed price', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'marketDetails', + initialPageParams: { asset: DAI, chainId: mainnet.id.toString() }, + account: { + type: 'not-connected', + }, + }) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + + await marketDetailsPage.expectOraclePanelToHaveTitle('Fixed Price') + + await marketDetailsPage.expectOracleInfo({ + price: '$1.00', + asset: 'DAI', + oracleContract: '0x42a03F81dd8A1cEcD746dc262e4d1CD9fD39F777', + }) + }) + test('Market price - not redundant', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'marketDetails', + initialPageParams: { asset: WBTC, chainId: mainnet.id.toString() }, + account: { + type: 'not-connected', + }, + }) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + + await marketDetailsPage.expectOraclePanelToHaveTitle('Market Price') + await marketDetailsPage.expectOracleToBeNotRedundant() + + await marketDetailsPage.expectOracleInfo({ + price: '$101,496.42', + asset: 'WBTC', + oracleContract: '0x230E0321Cf38F09e247e50Afc7801EA2351fe56F', + }) + }) + + test('Yielding fixed price - redundant', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'marketDetails', + initialPageParams: { asset: WEETH, chainId: mainnet.id.toString() }, + account: { + type: 'not-connected', + }, + }) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + + await marketDetailsPage.expectOraclePanelToHaveTitle('Yielding Fixed Price') + await marketDetailsPage.expectOracleToBeRedundant() + + await marketDetailsPage.expectOracleInfo({ + price: '$4,145.06', + asset: 'weETH', + oracleContract: '0x28897036f8459bFBa886083dD6b4Ce4d2f14a57F', + }) + await marketDetailsPage.expectYieldingFixedOracleBaseAssetInfo({ + asset: 'WETH', + price: '$3,928.31', + oracleContract: '0xb20A1374EfCaFa32F701Ab14316fA2E5b3400eD5', + }) + await marketDetailsPage.expectYieldingFixedOracleRatioInfo({ + ratio: '1.0552', + ratioContract: '0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee', + }) + }) + }) +}) + +test.describe('Market details Gnosis', () => { + const XDAI = '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d' + const EURe = '0xcB444e90D8198415266c6a2724b7900fb12FC56E' + const WETH = '0x6A023CCd1ff6F2045C3309768eAd9E68F978f6e1' + const sDAI = '0xaf204776c7245bF4147c2612BF6e5972Ee483701' + + test.describe('Cap automator', () => { + test('WETH', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id }, + initialPage: 'marketDetails', + initialPageParams: { asset: WETH, chainId: gnosis.id.toString() }, + account: { + type: 'not-connected', + }, + }) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + + await marketDetailsPage.expectSupplyCap('5,000 WETH') + await marketDetailsPage.expectSupplyMaxCapNotVisible() + + await marketDetailsPage.expectBorrowCap('3,000 WETH') + await marketDetailsPage.expectBorrowMaxCapNotVisible() + }) + + test('XDAI', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id }, + initialPage: 'marketDetails', + initialPageParams: { asset: XDAI, chainId: gnosis.id.toString() }, + account: { + type: 'not-connected', + }, + }) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + + await marketDetailsPage.expectSupplyCap('20M WXDAI') + await marketDetailsPage.expectSupplyMaxCapNotVisible() + + await marketDetailsPage.expectBorrowCap('16M WXDAI') + await marketDetailsPage.expectBorrowMaxCapNotVisible() + + await marketDetailsPage.expectCollateralPanelNotVisible() + }) + }) + + test.describe('Oracles', () => { + test('Fixed price', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id }, + initialPage: 'marketDetails', + initialPageParams: { asset: XDAI, chainId: gnosis.id.toString() }, + account: { + type: 'not-connected', + }, + }) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + + await marketDetailsPage.expectOraclePanelToHaveTitle('Fixed Price') + + await marketDetailsPage.expectOracleInfo({ + price: '$1.00', + asset: 'WXDAI', + oracleContract: '0x6FC2871B6d9A94866B7260896257Fd5b50c09900', + }) + }) + + test('Underlying asset price', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id }, + initialPage: 'marketDetails', + initialPageParams: { asset: EURe, chainId: gnosis.id.toString() }, + account: { + type: 'not-connected', + }, + }) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + + await marketDetailsPage.expectOraclePanelToHaveTitle('Underlying Asset Price') + + await marketDetailsPage.expectOracleInfo({ + price: '$1.07', + asset: 'EUR', + oracleContract: '0xab70BCB260073d036d1660201e9d5405F5829b7a', + }) + }) + + test('Yielding fixed price - not redundant', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id }, + initialPage: 'marketDetails', + initialPageParams: { asset: sDAI, chainId: gnosis.id.toString() }, + account: { + type: 'not-connected', + }, + }) + + const marketDetailsPage = new MarketDetailsPageObject(testContext) + + await marketDetailsPage.expectOraclePanelToHaveTitle('Yielding Fixed Price') + await marketDetailsPage.expectOracleToBeNotRedundant() + + await marketDetailsPage.expectOracleInfo({ + price: '$1.0875', + asset: 'sDAI', + oracleContract: '0x1D0f881Ce1a646E2f27Dec3c57Fa056cB838BCC2', + }) + await marketDetailsPage.expectYieldingFixedOracleBaseAssetInfo({ + asset: 'DAI', + price: '$0.9997', + oracleContract: '0x678df3415fc31947dA4324eC63212874be5a82f8', + }) + await marketDetailsPage.expectYieldingFixedOracleRatioInfo({ + ratio: '1.0878', + ratioContract: '0xaf204776c7245bF4147c2612BF6e5972Ee483701', + }) + }) + }) +}) diff --git a/packages/app/src/pages/Markets.test-e2e.ts b/packages/app/src/pages/Markets.test-e2e.ts index 20faee6e4..fb69d5f40 100644 --- a/packages/app/src/pages/Markets.test-e2e.ts +++ b/packages/app/src/pages/Markets.test-e2e.ts @@ -1,280 +1,325 @@ -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { MarketsPageObject } from './Markets.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { MarketsPageObject } from './Markets.PageObject' -// test.describe('Markets', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) -// let marketsPage: MarketsPageObject +test.describe('Markets', () => { + let marketsPage: MarketsPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'markets', -// account: { -// type: 'not-connected', -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'markets', + account: { + type: 'not-connected', + }, + }) -// marketsPage = new MarketsPageObject(page) -// }) + marketsPage = new MarketsPageObject(testContext) + }) -// test('summary', async () => { -// await marketsPage.expectSummary([ -// { description: 'Total market size', value: '$4.441B' }, -// { description: 'Total value locked', value: '$2.869B' }, -// { description: 'Total available', value: '$2.904B' }, -// { description: 'Total borrows', value: '$1.537B' }, -// ]) -// }) + test('summary', async () => { + await marketsPage.expectSummary([ + { description: 'Total market size', value: '$8.145B' }, + { description: 'Total value locked', value: '$5.068B' }, + { description: 'Total available', value: '$5.149B' }, + { description: 'Total borrows', value: '$2.997B' }, + ]) + }) -// test('active markets table', async () => { -// await marketsPage.expectActiveMarketsTable([ -// { -// asset: { -// name: 'Lido Staked ETH', -// symbol: 'wstETH', -// }, -// totalSupplied: { -// tokenAmount: '519K', -// usdValue: '$2.06B', -// }, -// depositAPY: { -// value: '<0.01%', -// }, -// totalBorrowed: { -// tokenAmount: '51.56', -// usdValue: '$204.7K', -// }, -// borrowAPY: { -// value: '0.25%', -// }, -// status: { -// supply: 'Can be supplied', -// collateral: 'Can be used as collateral', -// borrow: 'Can be borrowed', -// }, -// }, -// { -// asset: { -// name: 'DAI Stablecoin', -// symbol: 'DAI', -// }, -// totalSupplied: { -// tokenAmount: '962.8M', -// usdValue: '$962.8M', -// }, -// depositAPY: { -// // @note: This value is different in production since VITE_FEATURE_DISABLE_DAI_LEND is disabled in playwright tests -// value: '8.52%', -// }, -// totalBorrowed: { -// tokenAmount: '913.6M', -// usdValue: '$913.6M', -// }, -// borrowAPY: { -// value: '9.00%', -// hasAirDrop: true, -// }, -// status: { -// // @note: This value is different in production since VITE_FEATURE_DISABLE_DAI_LEND is disabled in playwright tests -// supply: 'Can be supplied', -// collateral: 'Cannot be used as collateral', -// borrow: 'Can be borrowed', -// }, -// }, -// { -// asset: { -// name: 'Ethereum', -// symbol: 'ETH', -// }, -// totalSupplied: { -// tokenAmount: '252.1K', -// usdValue: '$854.8M', -// }, -// depositAPY: { -// value: '1.31%', -// hasAirDrop: true, -// }, -// totalBorrowed: { -// tokenAmount: '177K', -// usdValue: '$600M', -// }, -// borrowAPY: { -// value: '1.97%', -// }, -// status: { -// supply: 'Can be supplied', -// collateral: 'Can be used as collateral', -// borrow: 'Can be borrowed', -// }, -// }, -// { -// asset: { -// name: 'Wrapped BTC', -// symbol: 'WBTC', -// }, -// totalSupplied: { -// tokenAmount: '5,790', -// usdValue: '$358M', -// }, -// depositAPY: { -// value: '<0.01%', -// }, -// totalBorrowed: { -// tokenAmount: '332.8', -// usdValue: '$20.58M', -// }, -// borrowAPY: { -// value: '0.19%', -// }, -// status: { -// supply: 'Can be supplied', -// collateral: 'Can be used as collateral', -// borrow: 'Can be borrowed', -// }, -// }, -// { -// asset: { -// name: 'Rocket Pool Staked ETH', -// symbol: 'rETH', -// }, -// totalSupplied: { -// tokenAmount: '38.95K', -// usdValue: '$146.5M', -// }, -// depositAPY: { -// value: '<0.01%', -// }, -// totalBorrowed: { -// tokenAmount: '6.271', -// usdValue: '$23.59K', -// }, -// borrowAPY: { -// value: '0.25%', -// }, -// status: { -// supply: 'Can be supplied', -// collateral: 'Can be used as collateral', -// borrow: 'Can be borrowed', -// }, -// }, -// { -// asset: { -// name: 'Ether.fi Staked ETH', -// symbol: 'weETH', -// }, -// totalSupplied: { -// tokenAmount: '11.66K', -// usdValue: '$41.17M', -// }, -// depositAPY: { -// value: '0.00%', -// }, -// totalBorrowed: undefined, -// borrowAPY: undefined, -// status: { -// supply: 'Can be supplied', -// collateral: 'Can be used as collateral only in isolation mode', -// borrow: 'Cannot be borrowed', -// }, -// }, -// { -// asset: { -// name: 'Savings Dai', -// symbol: 'sDAI', -// }, -// totalSupplied: { -// tokenAmount: '13.49M', -// usdValue: '$14.73M', -// }, -// depositAPY: { -// value: '0.00%', -// }, -// totalBorrowed: undefined, -// borrowAPY: undefined, -// status: { -// supply: 'Can be supplied', -// collateral: 'Can be used as collateral', -// borrow: 'Cannot be borrowed', -// }, -// }, -// { -// asset: { -// name: 'Circle USD', -// symbol: 'USDC', -// }, -// totalSupplied: { -// tokenAmount: '2.559M', -// usdValue: '$2.559M', -// }, -// depositAPY: { -// value: '5.90%', -// }, -// totalBorrowed: { -// tokenAmount: '2.077M', -// usdValue: '$2.077M', -// }, -// borrowAPY: { -// value: '7.72%', -// }, -// status: { -// supply: 'Can be supplied', -// collateral: 'Cannot be used as collateral', -// borrow: 'Can be borrowed', -// }, -// }, -// { -// asset: { -// name: 'Tether USD', -// symbol: 'USDT', -// }, -// totalSupplied: { -// tokenAmount: '316.6K', -// usdValue: '$316.6K', -// }, -// depositAPY: { -// value: '4.03%', -// }, -// totalBorrowed: { -// tokenAmount: '213.2K', -// usdValue: '$213.2K', -// }, -// borrowAPY: { -// value: '6.36%', -// }, -// status: { -// supply: 'Can be supplied', -// collateral: 'Cannot be used as collateral', -// borrow: 'Can be borrowed', -// }, -// }, -// ]) -// }) + test('active markets table', async () => { + await marketsPage.expectActiveMarketsTable([ + { + asset: { + name: 'Lido Staked ETH', + symbol: 'wstETH', + }, + totalSupplied: { + tokenAmount: '861.3K', + usdValue: '$4.018B', + }, + depositAPY: { + value: '<0.01%', + }, + totalBorrowed: { + tokenAmount: '98.42', + usdValue: '$459.2K', + }, + borrowAPY: { + value: '0.25%', + }, + status: { + supply: 'Can be supplied', + collateral: 'Can be used as collateral', + borrow: 'Can be borrowed', + }, + }, + { + asset: { + name: 'DAI Stablecoin', + symbol: 'DAI', + }, + totalSupplied: { + tokenAmount: '1.739B', + usdValue: '$1.739B', + }, + depositAPY: { + // @note: This value is different in production since VITE_FEATURE_DISABLE_DAI_LEND is disabled in playwright tests + value: '11.69%', + }, + totalBorrowed: { + tokenAmount: '1.626B', + usdValue: '$1.626B', + }, + borrowAPY: { + value: '12.55%', + hasAirDrop: true, + }, + status: { + // @note: This value is different in production since VITE_FEATURE_DISABLE_DAI_LEND is disabled in playwright tests + supply: 'Can be supplied', + collateral: 'Cannot be used as collateral', + borrow: 'Can be borrowed', + }, + }, + { + asset: { + name: 'Ethereum', + symbol: 'ETH', + }, + totalSupplied: { + tokenAmount: '391.1K', + usdValue: '$1.536B', + }, + depositAPY: { + value: '2.03%', + hasAirDrop: true, + }, + totalBorrowed: { + tokenAmount: '347.6K', + usdValue: '$1.365B', + }, + borrowAPY: { + value: '2.41%', + }, + status: { + supply: 'Can be supplied', + collateral: 'Can be used as collateral', + borrow: 'Can be borrowed', + }, + }, + { + asset: { + name: 'Coinbase Wrapped BTC', + symbol: 'cbBTC', + }, + totalSupplied: { + tokenAmount: '2,950', + usdValue: '$300M', + }, + depositAPY: { + value: '<0.01%', + }, + totalBorrowed: { + tokenAmount: '5.65', + usdValue: '$574.6K', + }, + borrowAPY: { + value: '0.01%', + }, + status: { + supply: 'Can be supplied', + collateral: 'Can be used as collateral', + borrow: 'Can be borrowed', + }, + }, + { + asset: { + name: 'Ether.fi Staked ETH', + symbol: 'weETH', + }, + totalSupplied: { + tokenAmount: '51.75', + usdValue: '$214.5M', + }, + depositAPY: { + value: '0.00%', + }, + totalBorrowed: undefined, + borrowAPY: undefined, + status: { + supply: 'Can be supplied', + collateral: 'Can be used as collateral only in isolation mode', + borrow: 'Cannot be borrowed', + }, + }, + { + asset: { + name: 'Wrapped BTC', + symbol: 'WBTC', + }, + totalSupplied: { + tokenAmount: '1,742', + usdValue: '$176.8', + }, + depositAPY: { + value: '<0.01%', + }, + totalBorrowed: { + tokenAmount: '18.12', + usdValue: '$1.839M', + }, + borrowAPY: undefined, + status: { + supply: 'Can be supplied', + collateral: 'Cannot be used as collateral', + borrow: 'Cannot be borrowed', + }, + }, + { + asset: { + name: 'Rocket Pool Staked ETH', + symbol: 'rETH', + }, + totalSupplied: { + tokenAmount: '34.47K', + usdValue: '$152.1M', + }, + depositAPY: { + value: '<0.01%', + }, + totalBorrowed: { + tokenAmount: '7.991', + usdValue: '$35.26K', + }, + borrowAPY: { + value: '0.25%', + }, + status: { + supply: 'Can be supplied', + collateral: 'Can be used as collateral', + borrow: 'Can be borrowed', + }, + }, + { + asset: { + name: 'Savings USDS', + symbol: 'sUSDS', + }, + totalSupplied: { + tokenAmount: '4.154M', + usdValue: '$4.226M', + }, + depositAPY: { + value: '0.00%', + }, + totalBorrowed: undefined, + borrowAPY: undefined, + status: { + supply: 'Can be supplied', + collateral: 'Can be used as collateral', + borrow: 'Cannot be borrowed', + }, + }, + { + asset: { + name: 'Circle USD', + symbol: 'USDC', + }, + totalSupplied: { + tokenAmount: '1.916M', + usdValue: '$1.916M', + }, + depositAPY: { + value: '16.20%', + }, + totalBorrowed: { + tokenAmount: '1.849M', + usdValue: '$1.849M', + }, + borrowAPY: { + value: '17.79%', + }, + status: { + supply: 'Can be supplied', + collateral: 'Cannot be used as collateral', + borrow: 'Can be borrowed', + }, + }, + { + asset: { + name: 'Savings Dai', + symbol: 'sDAI', + }, + totalSupplied: { + tokenAmount: '1.25M', + usdValue: '$1.407M', + }, + depositAPY: { + value: '0.00%', + }, + totalBorrowed: undefined, + borrowAPY: undefined, + status: { + supply: 'Can be supplied', + collateral: 'Can be used as collateral', + borrow: 'Cannot be borrowed', + }, + }, + { + asset: { + name: 'Tether USD', + symbol: 'USDT', + }, + totalSupplied: { + tokenAmount: '579.3K', + usdValue: '$579.3K', + }, + depositAPY: { + value: '6.58%', + }, + totalBorrowed: { + tokenAmount: '424.3K', + usdValue: '$424.3K', + }, + borrowAPY: { + value: '9.60%', + }, + status: { + supply: 'Can be supplied', + collateral: 'Cannot be used as collateral', + borrow: 'Can be borrowed', + }, + }, + ]) + }) -// test('frozen markets table', async () => { -// await marketsPage.showFrozenMarkets() -// await marketsPage.expectFrozenMarketsTable([ -// { -// asset: { -// name: 'Gnosis Token', -// symbol: 'GNO', -// isFrozen: true, -// }, -// totalSupplied: { -// tokenAmount: '55.1', -// usdValue: '$15.91K', -// }, -// depositAPY: undefined, -// totalBorrowed: undefined, -// borrowAPY: undefined, -// status: { -// supply: 'Cannot be supplied', -// collateral: 'Cannot be used as collateral', -// borrow: 'Cannot be borrowed', -// }, -// }, -// ]) -// }) -// }) + test('frozen markets table', async () => { + await marketsPage.showFrozenMarkets() + await marketsPage.expectFrozenMarketsTable([ + { + asset: { + name: 'Gnosis Token', + symbol: 'GNO', + isFrozen: true, + }, + totalSupplied: { + tokenAmount: '5', + usdValue: '$1,459', + }, + depositAPY: undefined, + totalBorrowed: undefined, + borrowAPY: undefined, + status: { + supply: 'Cannot be supplied', + collateral: 'Cannot be used as collateral', + borrow: 'Cannot be borrowed', + }, + }, + ]) + }) +}) diff --git a/packages/app/src/test/e2e/utils.ts b/packages/app/src/test/e2e/utils.ts index 98c53e708..8e96ab494 100644 --- a/packages/app/src/test/e2e/utils.ts +++ b/packages/app/src/test/e2e/utils.ts @@ -10,54 +10,6 @@ import { Locator, Page } from '@playwright/test' import { http, Address, createPublicClient, erc20Abi, weiUnits } from 'viem' import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts' -/** - * Helper function to take deterministic screenshots. - */ -export async function screenshot(pageOrLocator: Page | Locator, name: string): Promise { - const page = isPage(pageOrLocator) ? pageOrLocator : pageOrLocator.page() - const locator = isPage(pageOrLocator) ? page.locator('html') : pageOrLocator - - // note: hide entirely elements that can change in size - const selectorsToHide = [ - `[data-testid="wallet-button"]`, // hide address because it can change - '.toast-notifications', // hide notifications because sometimes they are fast to disappear and can't be captured deterministically - `[data-testid="react-confetti"]`, - ] - // note: mask elements that can change but not in size - const selectorsToMask: string[] = [] - - // hide elements - await page.evaluate((selectors) => { - for (const selector of selectors) { - const element: any = document.querySelector(selector) - if (!element) { - continue // skip if element not found - } - - element.__oldDisplay = element.style.display - element.style.display = 'none' - } - }, selectorsToHide) - - await locator.screenshot({ - path: `__screenshots-e2e__/${name}-${page.viewportSize()?.width}.png`, - animations: 'disabled', - mask: selectorsToMask.map((selector) => page.locator(selector)), - }) - - // unhide elements - await page.evaluate((selectors) => { - for (const selector of selectors) { - const element: any = document.querySelector(selector) - if (!element) { - return - } - - element.style.display = element.__oldDisplay - } - }, selectorsToHide) -} - export async function waitForButtonEnabled(page: Page, name: string): Promise { await page.waitForFunction((name) => { const buttons = document.querySelectorAll('button') From 058fdd09789f276d3d501b0c94579ad42931deda Mon Sep 17 00:00:00 2001 From: Vladyslav Yatsenko <52505649+yivlad@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:53:45 +0100 Subject: [PATCH 12/29] Rewrite app layout E2E tests (#502) --- .../PageNotSupportedWarning.PageObject.ts | 36 ++++---- .../PageNotSupportedWarning.test-e2e.ts | 87 ++++++++++--------- 2 files changed, 64 insertions(+), 59 deletions(-) diff --git a/packages/app/src/ui/layouts/app-layout/components/PageNotSupportedWarning.PageObject.ts b/packages/app/src/ui/layouts/app-layout/components/PageNotSupportedWarning.PageObject.ts index f775bfea1..80e957f42 100644 --- a/packages/app/src/ui/layouts/app-layout/components/PageNotSupportedWarning.PageObject.ts +++ b/packages/app/src/ui/layouts/app-layout/components/PageNotSupportedWarning.PageObject.ts @@ -1,22 +1,22 @@ -// import { Locator, expect } from '@playwright/test' +import { Locator, expect } from '@playwright/test' -// import { BasePageObject } from '@/test/e2e/BasePageObject' -// import { testIds } from '@/ui/utils/testIds' +import { BasePageObject } from '@/test/e2e/BasePageObject' +import { testIds } from '@/ui/utils/testIds' -// export class PageNotSupportedWarningPageObject extends BasePageObject { -// // #region locators -// locateSwitchNetworkButton(): Locator { -// return this.page.getByTestId(testIds.component.SwitchNotSupportedNetworkButton) -// } -// // #endregion +export class PageNotSupportedWarningPageObject extends BasePageObject { + // #region locators + locateSwitchNetworkButton(): Locator { + return this.page.getByTestId(testIds.component.SwitchNotSupportedNetworkButton) + } + // #endregion -// // #region assertions -// async expectSwitchNetworkVisible(): Promise { -// await expect(this.locateSwitchNetworkButton()).toBeVisible() -// } + // #region assertions + async expectSwitchNetworkVisible(): Promise { + await expect(this.locateSwitchNetworkButton()).toBeVisible() + } -// async expectSwitchNetworkNotVisible(): Promise { -// await expect(this.locateSwitchNetworkButton()).not.toBeVisible() -// } -// // #endregion -// } + async expectSwitchNetworkNotVisible(): Promise { + await expect(this.locateSwitchNetworkButton()).not.toBeVisible() + } + // #endregion +} diff --git a/packages/app/src/ui/layouts/app-layout/components/PageNotSupportedWarning.test-e2e.ts b/packages/app/src/ui/layouts/app-layout/components/PageNotSupportedWarning.test-e2e.ts index 83bb77f5d..7d0b8367d 100644 --- a/packages/app/src/ui/layouts/app-layout/components/PageNotSupportedWarning.test-e2e.ts +++ b/packages/app/src/ui/layouts/app-layout/components/PageNotSupportedWarning.test-e2e.ts @@ -1,41 +1,46 @@ -// import { test } from '@playwright/test' -// import { gnosis } from 'viem/chains' - -// import { GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { buildUrl, setup } from '@/test/e2e/setup' -// import { PageNotSupportedWarningPageObject } from './PageNotSupportedWarning.PageObject' - -// test.describe('PageNotSupportedWarning', () => { -// const fork = setupFork({ blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id, useTenderlyVnet: true }) - -// test('Displays not supported warning on unsupported page', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'farms', -// account: { -// type: 'connected-random', -// }, -// }) - -// const warning = new PageNotSupportedWarningPageObject(page) - -// await warning.expectSwitchNetworkVisible() -// }) - -// test('Displays not supported warning on entering the unsupported page', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// }, -// }) - -// const warning = new PageNotSupportedWarningPageObject(page) - -// await warning.expectSwitchNetworkNotVisible() - -// await page.goto(buildUrl('farms')) - -// await warning.expectSwitchNetworkVisible() -// }) -// }) +import { test } from '@playwright/test' +import { gnosis } from 'viem/chains' + +import { GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { buildUrl, setup } from '@/test/e2e/setup' +import { PageNotSupportedWarningPageObject } from './PageNotSupportedWarning.PageObject' + +test.describe('PageNotSupportedWarning', () => { + test('Displays not supported warning on unsupported page', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, + chainId: gnosis.id, + }, + initialPage: 'farms', + account: { + type: 'connected-random', + }, + }) + + const warning = new PageNotSupportedWarningPageObject(testContext) + + await warning.expectSwitchNetworkVisible() + }) + + test('Displays not supported warning on entering the unsupported page', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, + chainId: gnosis.id, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + }, + }) + + const warning = new PageNotSupportedWarningPageObject(testContext) + + await warning.expectSwitchNetworkNotVisible() + + await page.goto(buildUrl('farms')) + + await warning.expectSwitchNetworkVisible() + }) +}) From 49ebaf81aad62deec03e1c5268586235c1ea6115 Mon Sep 17 00:00:00 2001 From: Oskar <43062492+oskarvu@users.noreply.github.com> Date: Wed, 18 Dec 2024 22:17:49 +0700 Subject: [PATCH 13/29] Rewrite savings, farm and my portfolio pages tests (#501) * Uncomment test file * Update savings page tests * Update farms page test * Update my portfolio page test --- packages/app/src/pages/Farms.test-e2e.ts | 58 +-- .../app/src/pages/MyPortfolio.PageObject.ts | 13 +- .../app/src/pages/MyPortfolio.test-e2e.ts | 204 ++++---- packages/app/src/pages/Savings.test-e2e.ts | 444 +++++++++--------- packages/app/src/test/e2e/constants.ts | 2 +- packages/app/src/test/e2e/utils.ts | 45 -- 6 files changed, 364 insertions(+), 402 deletions(-) diff --git a/packages/app/src/pages/Farms.test-e2e.ts b/packages/app/src/pages/Farms.test-e2e.ts index 802417fdb..249b04ed7 100644 --- a/packages/app/src/pages/Farms.test-e2e.ts +++ b/packages/app/src/pages/Farms.test-e2e.ts @@ -1,33 +1,35 @@ -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { FarmsPageObject } from './Farms.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { FarmsPageObject } from './Farms.PageObject' -// test.describe('Farms', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let farmsPage: FarmsPageObject +test.describe('Farms', () => { + let farmsPage: FarmsPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'farms', -// account: { -// type: 'not-connected', -// }, -// }) -// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'farms', + account: { + type: 'not-connected', + }, + }) + await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) -// farmsPage = new FarmsPageObject(page) -// }) + farmsPage = new FarmsPageObject(testContext) + }) -// test('farms list', async () => { -// await farmsPage.expectInactiveFarms([ -// { apy: '8.51%', staked: '0', rewardText: 'Earn SKY', stakeText: 'Deposit Stablecoins' }, -// { staked: '0', rewardText: 'Earn Chronicle points', stakeText: 'Deposit Stablecoins' }, -// ]) + test('farms list', async () => { + await farmsPage.expectInactiveFarms([ + { apy: '8.51%', staked: '0', rewardText: 'Earn SKY', stakeText: 'Deposit Stablecoins' }, + { staked: '0', rewardText: 'Earn Chronicle points', stakeText: 'Deposit Stablecoins' }, + ]) -// await farmsPage.expectActiveFarmsListToBeEmpty() -// }) -// }) + await farmsPage.expectActiveFarmsListToBeEmpty() + }) +}) diff --git a/packages/app/src/pages/MyPortfolio.PageObject.ts b/packages/app/src/pages/MyPortfolio.PageObject.ts index e7cff4d41..e88841d52 100644 --- a/packages/app/src/pages/MyPortfolio.PageObject.ts +++ b/packages/app/src/pages/MyPortfolio.PageObject.ts @@ -1,10 +1,8 @@ -import { USD_MOCK_TOKEN } from '@/domain/types/Token' import { BasePageObject } from '@/test/e2e/BasePageObject' import { buildUrl } from '@/test/e2e/setup' import { parseTable } from '@/test/e2e/utils' import { testIds } from '@/ui/utils/testIds' import { assert } from '@/utils/assert' -import { NormalizedUnitNumber } from '@marsfoundation/common-universal' import { expect } from '@playwright/test' import { z } from 'zod' @@ -99,21 +97,22 @@ export class MyPortfolioPageObject extends BasePageObject { await expect(locator).toHaveText(hf) } - async expectDepositedAssets(total: number): Promise { + async expectDepositedAssets(total: string): Promise { const locator = this.page.getByTestId(testIds.myPortfolio.deposited) - await expect(locator).toHaveText(USD_MOCK_TOKEN.formatUSD(NormalizedUnitNumber(total), { compact: true })) + await expect(locator).toHaveText(total) } - async expectBorrowedAssets(total: number): Promise { + async expectBorrowedAssets(total: string): Promise { const locator = this.page.getByTestId(testIds.myPortfolio.borrowed) - await expect(locator).toHaveText(USD_MOCK_TOKEN.formatUSD(NormalizedUnitNumber(total), { compact: true })) + await expect(locator).toHaveText(total) } async expectGuestScreen(): Promise { await expect( - this.page.getByRole('heading', { name: 'This page is available ony for connected users', exact: true }), + this.page.getByRole('heading', { name: 'Connect your wallet to use Spark', exact: true }), ).toBeVisible() await expect(this.page.getByRole('button', { name: 'Connect wallet', exact: true })).toBeVisible() + await expect(this.page.getByRole('button', { name: 'Try in Sandbox Mode', exact: true })).toBeVisible() } async expectDepositTable(assets: Record): Promise { diff --git a/packages/app/src/pages/MyPortfolio.test-e2e.ts b/packages/app/src/pages/MyPortfolio.test-e2e.ts index 0d633b43f..a2cdc5253 100644 --- a/packages/app/src/pages/MyPortfolio.test-e2e.ts +++ b/packages/app/src/pages/MyPortfolio.test-e2e.ts @@ -1,101 +1,103 @@ -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' - -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { calculateAssetsWorth, screenshot } from '@/test/e2e/utils' - -// import { BorrowPageObject } from './Borrow.PageObject' -// import { MyPortfolioPageObject } from './MyPortfolio.PageObject' - -// test.describe('MyPortfolio', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) - -// test.skip('guest state', async ({ page }) => { -// await setup(page, fork, { -// account: { -// type: 'not-connected', -// }, -// initialPage: 'myPortfolio', -// }) -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// await myPortfolioPage.expectGuestScreen() - -// await screenshot(page, 'myPortfolio-guest') -// }) - -// test('empty account', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'myPortfolio', -// account: { -// type: 'connected-random', -// }, -// }) -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// await myPortfolioPage.expectPositionToBeEmpty() - -// await screenshot(page, 'myPortfolio-empty-account') -// }) - -// test('no position', async ({ page }) => { -// const assetBalances = { -// ETH: 1, -// DAI: 200, -// sDAI: 300, -// USDC: 400, -// WETH: 1, -// } -// await setup(page, fork, { -// initialPage: 'myPortfolio', -// account: { -// type: 'connected-random', -// assetBalances, -// }, -// }) -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// await myPortfolioPage.expectPositionToBeEmpty() -// await myPortfolioPage.expectBalancesInDepositTable({ -// WETH: 2, -// DAI: 200, -// sDAI: 300, -// USDC: 400, -// }) - -// await screenshot(page, 'myPortfolio-no-position') -// }) - -// test('with open position', async ({ page }) => { -// const assetsToDeposit = { -// wstETH: 2, -// rETH: 2, -// } -// const daiToBorrow = 1500 -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ...assetsToDeposit, ETH: 0.1 }, -// }, -// }) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositAssetsActions(assetsToDeposit, daiToBorrow) -// await borrowPage.viewInMyPortfolioAction() - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.expectHealthFactor('5.42') -// await myPortfolioPage.expectDepositedAssets((await calculateAssetsWorth(fork.forkUrl, assetsToDeposit)).total) -// await myPortfolioPage.expectBorrowedAssets((await calculateAssetsWorth(fork.forkUrl, { DAI: daiToBorrow })).total) - -// await myPortfolioPage.expectDepositTable(assetsToDeposit) -// await myPortfolioPage.expectBalancesInDepositTable({ -// DAI: daiToBorrow, -// }) - -// await screenshot(page, 'myPortfolio-open-position') -// }) -// }) +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { BorrowPageObject } from './Borrow.PageObject' +import { MyPortfolioPageObject } from './MyPortfolio.PageObject' + +test.describe('MyPortfolio', () => { + test('guest state', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + account: { + type: 'not-connected', + }, + initialPage: 'myPortfolio', + }) + const myPortfolioPage = new MyPortfolioPageObject(testContext) + + await myPortfolioPage.expectGuestScreen() + }) + + test('empty account', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'myPortfolio', + account: { + type: 'connected-random', + }, + }) + const myPortfolioPage = new MyPortfolioPageObject(testContext) + + await myPortfolioPage.expectPositionToBeEmpty() + }) + + test('no position', async ({ page }) => { + const assetBalances = { + ETH: 1, + DAI: 200, + sDAI: 300, + USDC: 400, + WETH: 1, + } + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'myPortfolio', + account: { + type: 'connected-random', + assetBalances, + }, + }) + const myPortfolioPage = new MyPortfolioPageObject(testContext) + + await myPortfolioPage.expectPositionToBeEmpty() + await myPortfolioPage.expectBalancesInDepositTable({ + WETH: 2, + DAI: 200, + sDAI: 300, + USDC: 400, + }) + }) + + test('with open position', async ({ page }) => { + const assetsToDeposit = { + wstETH: 2, + rETH: 2, + } + const daiToBorrow = 1500 + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ...assetsToDeposit, ETH: 0.1 }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + await borrowPage.depositAssetsActions({ assetsToDeposit, daiToBorrow }) + await borrowPage.viewInMyPortfolioAction() + + const myPortfolioPage = new MyPortfolioPageObject(testContext) + await myPortfolioPage.expectHealthFactor('9.68') + await myPortfolioPage.expectDepositedAssets('$18.16K') + await myPortfolioPage.expectBorrowedAssets('$1,500') + + await myPortfolioPage.expectDepositTable(assetsToDeposit) + await myPortfolioPage.expectBalancesInDepositTable({ + DAI: daiToBorrow, + }) + }) +}) diff --git a/packages/app/src/pages/Savings.test-e2e.ts b/packages/app/src/pages/Savings.test-e2e.ts index 4d6d9e2e6..31504b895 100644 --- a/packages/app/src/pages/Savings.test-e2e.ts +++ b/packages/app/src/pages/Savings.test-e2e.ts @@ -1,220 +1,224 @@ -// import { test } from '@playwright/test' -// import { base, gnosis, mainnet } from 'viem/chains' - -// import { DEFAULT_BLOCK_NUMBER, GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' - -// import { SavingsPageObject } from './Savings.PageObject' - -// test.describe('Savings Mainnet', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) - -// test('guest state', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'not-connected', -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.expectAPY('5%') -// await savingsPage.expectConnectWalletCTA() -// }) - -// test('calculates current value', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// sDAI: 100, -// }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.expectSavingsDaiBalance({ -// sdaiBalance: '100.00', -// estimatedDaiValue: '107.1505', -// }) -// }) - -// test('calculates current projections', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// sDAI: 100, -// }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.expectSavingDaiCurrentProjection('$0.43', '30-day') -// await savingsPage.expectSavingDaiCurrentProjection('$5.36', '1-year') -// }) - -// test('displays the total value of stablecoins in the wallet', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// DAI: 100, -// USDC: 100, -// }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.expectOpportunityStablecoinsAmount('~$200.00') -// }) -// }) - -// test.describe('Savings Gnosis', () => { -// const fork = setupFork({ blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id, useTenderlyVnet: true }) - -// test('guest state', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'not-connected', -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.expectAPY('10.6%') -// await savingsPage.expectConnectWalletCTA() -// }) - -// test('calculates current value', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// sDAI: 100, -// }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.expectSavingsDaiBalance({ -// sdaiBalance: '100.00', -// estimatedDaiValue: '108.780942', -// }) -// }) - -// test('calculates current projections', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// sDAI: 100, -// }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.expectSavingDaiCurrentProjection('$0.95', '30-day') -// await savingsPage.expectSavingDaiCurrentProjection('$11.53', '1-year') -// }) - -// test('displays the total value of stablecoins in the wallet', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// XDAI: 100, -// }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.expectOpportunityStablecoinsAmount('~$100.00') -// }) -// }) - -// test.describe('Savings Base', () => { -// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) - -// test('guest state', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'not-connected', -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.expectAPY('6.5%') -// await savingsPage.expectConnectWalletCTA() -// }) - -// test('calculates current value', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// sUSDS: 100, -// }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.expectSavingsUsdsBalance({ -// susdsBalance: '100.00', -// estimatedUsdsValue: '100.8901', -// }) -// }) - -// test('calculates current projections', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// sUSDS: 100, -// }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.expectSavingUsdsCurrentProjection('$0.52', '30-day') -// await savingsPage.expectSavingUsdsCurrentProjection('$6.56', '1-year') -// }) - -// test('displays the total value of stablecoins in the wallet', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// USDC: 100, -// USDS: 100, -// }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.expectOpportunityStablecoinsAmount('~$200.00') -// }) -// }) +import { BASE_DEFAULT_BLOCK_NUMBER, DEFAULT_BLOCK_NUMBER, GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { base, gnosis, mainnet } from 'viem/chains' + +import { SavingsPageObject } from './Savings.PageObject' + +test.describe('Savings Mainnet', () => { + test('guest state', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'savings', + account: { + type: 'not-connected', + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.expectAPY('12.5%') + await savingsPage.expectConnectWalletCTA() + }) + + test('calculates current value', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + sDAI: 100, + }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.expectSavingsDaiBalance({ + sdaiBalance: '100.00', + estimatedDaiValue: '112.55991', + }) + }) + + test('calculates current projections', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + sDAI: 100, + }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.expectSavingDaiCurrentProjection('$1.01', '30-day') + await savingsPage.expectSavingDaiCurrentProjection('$12.94', '1-year') + }) + + test('displays the total value of stablecoins in the wallet', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + DAI: 100, + USDC: 100, + }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.expectOpportunityStablecoinsAmount('~$200.00') + }) +}) + +test.describe('Savings Gnosis', () => { + test('guest state', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id }, + initialPage: 'savings', + account: { + type: 'not-connected', + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.expectAPY('10.6%') + await savingsPage.expectConnectWalletCTA() + }) + + test('calculates current value', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + sDAI: 100, + }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.expectSavingsDaiBalance({ + sdaiBalance: '100.00', + estimatedDaiValue: '108.780942', + }) + }) + + test('calculates current projections', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + sDAI: 100, + }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.expectSavingDaiCurrentProjection('$0.95', '30-day') + await savingsPage.expectSavingDaiCurrentProjection('$11.53', '1-year') + }) + + test('displays the total value of stablecoins in the wallet', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + XDAI: 100, + }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.expectOpportunityStablecoinsAmount('~$100.00') + }) +}) + +test.describe('Savings Base', () => { + test('guest state', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: BASE_DEFAULT_BLOCK_NUMBER, chainId: base.id }, + initialPage: 'savings', + account: { + type: 'not-connected', + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.expectAPY('8.5%') + await savingsPage.expectConnectWalletCTA() + }) + + test('calculates current value', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: BASE_DEFAULT_BLOCK_NUMBER, chainId: base.id }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + sUSDS: 100, + }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.expectSavingsUsdsBalance({ + susdsBalance: '100.00', + estimatedUsdsValue: '101.286547', + }) + }) + + test('calculates current projections', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: BASE_DEFAULT_BLOCK_NUMBER, chainId: base.id }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + sUSDS: 100, + }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.expectSavingUsdsCurrentProjection('$0.68', '30-day') + await savingsPage.expectSavingUsdsCurrentProjection('$8.61', '1-year') + }) + + test('displays the total value of stablecoins in the wallet', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: BASE_DEFAULT_BLOCK_NUMBER, chainId: base.id }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + USDC: 100, + USDS: 100, + }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.expectOpportunityStablecoinsAmount('~$200.00') + }) +}) diff --git a/packages/app/src/test/e2e/constants.ts b/packages/app/src/test/e2e/constants.ts index a64582591..39a5168c7 100644 --- a/packages/app/src/test/e2e/constants.ts +++ b/packages/app/src/test/e2e/constants.ts @@ -131,7 +131,7 @@ export const __TX_LIST_KEY = '__PLAYWRIGHT_TX_LIST' as any export const DEFAULT_BLOCK_NUMBER = 21400000n // Edge cases -export const WBTC_SUPPLY_CAP_REACHED_BLOCK_NUMBER = 19034436n export const GNO_ACTIVE_BLOCK_NUMBER = 18365842n +export const BASE_DEFAULT_BLOCK_NUMBER = 23000000n export const GNOSIS_DEFAULT_BLOCK_NUMBER = 34543308n diff --git a/packages/app/src/test/e2e/utils.ts b/packages/app/src/test/e2e/utils.ts index 8e96ab494..ff60025f2 100644 --- a/packages/app/src/test/e2e/utils.ts +++ b/packages/app/src/test/e2e/utils.ts @@ -1,8 +1,3 @@ -import { - lendingPoolAddressProviderAddress, - uiPoolDataProviderAbi, - uiPoolDataProviderAddress, -} from '@/config/contracts-generated' import { USD_MOCK_TOKEN } from '@/domain/types/Token' import { bigNumberify } from '@/utils/bigNumber' import { BaseUnitNumber, NormalizedUnitNumber } from '@marsfoundation/common-universal' @@ -65,46 +60,6 @@ export async function parseTable(tableLocator: Locator, parseRow: (row: strin return table } -export async function calculateAssetsWorth( - forkUrl: string, - balances: Record, -): Promise<{ total: number; assetsWorth: Record }> { - const publicClient = createPublicClient({ - transport: http(forkUrl), - }) - const chainId = await publicClient.getChainId() - - const uiPoolDataProvider = uiPoolDataProviderAddress[chainId as keyof typeof uiPoolDataProviderAddress] - const lendingPoolAddressProvider = - lendingPoolAddressProviderAddress[chainId as keyof typeof lendingPoolAddressProviderAddress] - if (!uiPoolDataProvider || !lendingPoolAddressProvider) { - throw new Error(`Couldn't find addresses for chain ${chainId}`) - } - - const [reserves, baseCurrencyInfo] = await publicClient.readContract({ - address: uiPoolDataProvider, - functionName: 'getReservesData', - args: [lendingPoolAddressProvider], - abi: uiPoolDataProviderAbi, - }) - - let total = 0 - const assetsWorth: Record = {} - for (const [asset, amount] of Object.entries(balances)) { - const price = reserves.find( - (reserve) => reserve.symbol === asset || (asset === 'ETH' && reserve.symbol === 'WETH'), - )?.priceInMarketReferenceCurrency - if (!price) { - throw new Error(`Couldn't find price for ${asset}`) - } - - total += Number(price) * amount - assetsWorth[asset] = (Number(price) * amount) / Number(baseCurrencyInfo.marketReferenceCurrencyPriceInUsd) - } - - return { total: total / Number(baseCurrencyInfo.marketReferenceCurrencyPriceInUsd), assetsWorth } -} - export function isPage(pageOrLocator: Page | Locator): pageOrLocator is Page { return 'addInitScript' in pageOrLocator } From 0a2e07c977858c3caf348bdde6b0f79e4de9621e Mon Sep 17 00:00:00 2001 From: Vladyslav Yatsenko <52505649+yivlad@users.noreply.github.com> Date: Thu, 19 Dec 2024 10:27:23 +0100 Subject: [PATCH 14/29] Rewrite e-Mode E2E tests (#503) --- .../dialogs/e-mode/EModeDialog.PageObject.ts | 224 ++-- .../dialogs/e-mode/EModeDialog.test-e2e.ts | 1104 +++++++++-------- 2 files changed, 684 insertions(+), 644 deletions(-) diff --git a/packages/app/src/features/dialogs/e-mode/EModeDialog.PageObject.ts b/packages/app/src/features/dialogs/e-mode/EModeDialog.PageObject.ts index 49bdd937f..538edf970 100644 --- a/packages/app/src/features/dialogs/e-mode/EModeDialog.PageObject.ts +++ b/packages/app/src/features/dialogs/e-mode/EModeDialog.PageObject.ts @@ -1,122 +1,122 @@ -// import { EModeCategoryName } from '@/domain/e-mode/types' -// import { testIds } from '@/ui/utils/testIds' -// import { Locator, Page, expect } from '@playwright/test' -// import { DialogPageObject } from '../common/Dialog.PageObject' +import { EModeCategoryName } from '@/domain/e-mode/types' +import { TestContext } from '@/test/e2e/setup' +import { testIds } from '@/ui/utils/testIds' +import { Locator, expect } from '@playwright/test' +import { DialogPageObject } from '../common/Dialog.PageObject' -// export class EModeDialogPageObject extends DialogPageObject { -// constructor(page: Page) { -// super(page, /.*/) -// this.region = this.locateDialogByHeader('Set E-Mode Category') -// } +export class EModeDialogPageObject extends DialogPageObject { + constructor(testContext: TestContext) { + super({ + testContext, + header: /Set E-Mode Category/, + }) + } -// // #region locators -// locateEModeCategoryTile(eModeCategoryName: EModeCategoryName): Locator { -// return this.region.getByRole('button', { name: eModeCategoryName }) -// } -// // #endregion locators + // #region locators + locateEModeCategoryTile(eModeCategoryName: EModeCategoryName): Locator { + return this.region.getByRole('button', { name: eModeCategoryName }) + } + // #endregion locators -// // #region actions -// async clickEModeCategoryTileAction(eModeCategoryName: EModeCategoryName): Promise { -// await this.locateEModeCategoryTile(eModeCategoryName).click() -// } + // #region actions + async clickEModeCategoryTileAction(eModeCategoryName: EModeCategoryName): Promise { + await this.locateEModeCategoryTile(eModeCategoryName).click() + } -// async setEModeAction({ -// eModeCategoryName, -// updateBrowserAndNextBlockTime, -// }: { eModeCategoryName: EModeCategoryName; updateBrowserAndNextBlockTime: () => Promise }): Promise { -// await this.clickEModeCategoryTileAction(eModeCategoryName) -// await this.acknowledgeIfRiskIsPresent() -// await this.actionsContainer.acceptAllActionsAction(1, updateBrowserAndNextBlockTime) -// await this.expectEModeSuccessPage(eModeCategoryName) -// await this.viewInMyPortfolioAction() -// } -// // #endregion actions + async setEModeAction(eModeCategoryName: EModeCategoryName): Promise { + await this.clickEModeCategoryTileAction(eModeCategoryName) + await this.acknowledgeIfRiskIsPresent() + await this.actionsContainer.acceptAllActionsAction(1) + await this.expectEModeSuccessPage(eModeCategoryName) + await this.viewInMyPortfolioAction() + } + // #endregion actions -// // #region assertions -// async expectEModeCategoryTileStatus( -// eModeCategoryName: EModeCategoryName, -// status: 'Active' | 'Inactive', -// ): Promise { -// const tile = this.locateEModeCategoryTile(eModeCategoryName) -// await expect(tile).toContainText(status) -// } -// async expectEModeSuccessPage(eModeCategoryName: EModeCategoryName): Promise { -// await expect(this.page.getByTestId(testIds.component.SuccessViewContent)).toContainText('Congrats, all done!') -// await expect(this.page.getByTestId(testIds.dialog.success)).toContainText(eModeCategoryName) -// await expect(this.page.getByTestId(testIds.dialog.success)).toContainText('Option activated') -// } + // #region assertions + async expectEModeCategoryTileStatus( + eModeCategoryName: EModeCategoryName, + status: 'Active' | 'Inactive', + ): Promise { + const tile = this.locateEModeCategoryTile(eModeCategoryName) + await expect(tile).toContainText(status) + } + async expectEModeSuccessPage(eModeCategoryName: EModeCategoryName): Promise { + await expect(this.page.getByTestId(testIds.component.SuccessViewContent)).toContainText('Congrats, all done!') + await expect(this.page.getByTestId(testIds.dialog.success)).toContainText(eModeCategoryName) + await expect(this.page.getByTestId(testIds.dialog.success)).toContainText('Option activated') + } -// async expectEModeTransactionOverview(txOverview: EModeTransactionOverview): Promise { -// const overviewPanel = this.locatePanelByHeader('Transaction overview') -// await expect(overviewPanel).toBeVisible() -// const ids = testIds.dialog.eMode.transactionOverview -// const { availableAssets, maxLtv, variant } = txOverview + async expectEModeTransactionOverview(txOverview: EModeTransactionOverview): Promise { + const overviewPanel = this.locatePanelByHeader('Transaction overview') + await expect(overviewPanel).toBeVisible() + const ids = testIds.dialog.eMode.transactionOverview + const { availableAssets, maxLtv, variant } = txOverview -// if (variant === 'e-mode-no-change') { -// if (availableAssets.category) { -// await expect(this.page.getByTestId(ids.availableAssets.category)).toHaveText(availableAssets.category) -// } -// await expect(this.page.getByTestId(ids.availableAssets.assets)).toHaveText(availableAssets.assets) -// await expect(this.page.getByTestId(ids.maxLtv.before)).toHaveText(maxLtv) -// await expect(this.page.getByTestId(testIds.dialog.healthFactor.before)).toContainText(txOverview.hf) -// } + if (variant === 'e-mode-no-change') { + if (availableAssets.category) { + await expect(this.page.getByTestId(ids.availableAssets.category)).toHaveText(availableAssets.category) + } + await expect(this.page.getByTestId(ids.availableAssets.assets)).toHaveText(availableAssets.assets) + await expect(this.page.getByTestId(ids.maxLtv.before)).toHaveText(maxLtv) + await expect(this.page.getByTestId(testIds.dialog.healthFactor.before)).toContainText(txOverview.hf) + } -// if (variant === 'e-mode-change') { -// if (availableAssets.category) { -// await expect(this.page.getByTestId(ids.availableAssets.category)).toHaveText(availableAssets.category) -// } -// await expect(this.page.getByTestId(ids.availableAssets.assets)).toHaveText(availableAssets.assets) -// await expect(this.page.getByTestId(ids.maxLtv.before)).toHaveText(maxLtv.before) -// await expect(this.page.getByTestId(ids.maxLtv.after)).toHaveText(maxLtv.after) -// await expect(this.page.getByTestId(testIds.dialog.healthFactor.before)).toContainText(txOverview.hf.before) -// await expect(this.page.getByTestId(testIds.dialog.healthFactor.after)).toContainText(txOverview.hf.after) -// } + if (variant === 'e-mode-change') { + if (availableAssets.category) { + await expect(this.page.getByTestId(ids.availableAssets.category)).toHaveText(availableAssets.category) + } + await expect(this.page.getByTestId(ids.availableAssets.assets)).toHaveText(availableAssets.assets) + await expect(this.page.getByTestId(ids.maxLtv.before)).toHaveText(maxLtv.before) + await expect(this.page.getByTestId(ids.maxLtv.after)).toHaveText(maxLtv.after) + await expect(this.page.getByTestId(testIds.dialog.healthFactor.before)).toContainText(txOverview.hf.before) + await expect(this.page.getByTestId(testIds.dialog.healthFactor.after)).toContainText(txOverview.hf.after) + } -// if (variant === 'no-borrow') { -// if (availableAssets.category) { -// await expect(this.page.getByTestId(ids.availableAssets.category)).toHaveText(availableAssets.category) -// } -// await expect(this.page.getByTestId(ids.availableAssets.assets)).toHaveText(availableAssets.assets) -// await expect(this.page.getByTestId(ids.maxLtv.before)).toHaveText(maxLtv.before) -// await expect(this.page.getByTestId(ids.maxLtv.after)).toHaveText(maxLtv.after) -// } -// } -// // #endregion assertions -// } + if (variant === 'no-borrow') { + if (availableAssets.category) { + await expect(this.page.getByTestId(ids.availableAssets.category)).toHaveText(availableAssets.category) + } + await expect(this.page.getByTestId(ids.availableAssets.assets)).toHaveText(availableAssets.assets) + await expect(this.page.getByTestId(ids.maxLtv.before)).toHaveText(maxLtv.before) + await expect(this.page.getByTestId(ids.maxLtv.after)).toHaveText(maxLtv.after) + } + } + // #endregion assertions +} -// type EModeTransactionOverview = -// | { -// variant: 'e-mode-change' -// availableAssets: { -// category?: string -// assets: string -// } -// maxLtv: { -// before: string -// after: string -// } -// hf: { -// before: string -// after: string -// } -// } -// | { -// variant: 'e-mode-no-change' -// availableAssets: { -// category?: string -// assets: string -// } -// maxLtv: string -// hf: string -// } -// | { -// variant: 'no-borrow' -// availableAssets: { -// category?: string -// assets: string -// } -// maxLtv: { -// before: string -// after: string -// } -// } +type EModeTransactionOverview = + | { + variant: 'e-mode-change' + availableAssets: { + category?: string + assets: string + } + maxLtv: { + before: string + after: string + } + hf: { + before: string + after: string + } + } + | { + variant: 'e-mode-no-change' + availableAssets: { + category?: string + assets: string + } + maxLtv: string + hf: string + } + | { + variant: 'no-borrow' + availableAssets: { + category?: string + assets: string + } + maxLtv: { + before: string + after: string + } + } diff --git a/packages/app/src/features/dialogs/e-mode/EModeDialog.test-e2e.ts b/packages/app/src/features/dialogs/e-mode/EModeDialog.test-e2e.ts index b9520ddfc..c4734d2cc 100644 --- a/packages/app/src/features/dialogs/e-mode/EModeDialog.test-e2e.ts +++ b/packages/app/src/features/dialogs/e-mode/EModeDialog.test-e2e.ts @@ -1,532 +1,572 @@ -// import { setUserEModeValidationIssueToMessage } from '@/domain/market-validators/validateSetUserEMode' -// import { BorrowPageObject } from '@/pages/Borrow.PageObject' -// import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { DialogPageObject } from '../common/Dialog.PageObject' -// import { EModeDialogPageObject } from './EModeDialog.PageObject' - -// test.describe('E-Mode dialog', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - -// test.describe('ETH correlated assets borrowed', () => { -// let eModeDialog: EModeDialogPageObject -// let borrowDialog: DialogPageObject -// let myPortfolioPage: MyPortfolioPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ETH: 1, wstETH: 100 }, -// }, -// }) - -// eModeDialog = new EModeDialogPageObject(page) -// borrowDialog = new DialogPageObject(page, /Borrow/) -// myPortfolioPage = new MyPortfolioPageObject(page) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositWithoutBorrowActions({ wstETH: 20 }) -// await myPortfolioPage.goToMyPortfolioAction() - -// await myPortfolioPage.clickBorrowButtonAction('rETH') -// await borrowDialog.fillAmountAction(5) -// await borrowDialog.actionsContainer.acceptAllActionsAction(1) -// await borrowDialog.viewInMyPortfolioAction() -// await myPortfolioPage.clickBorrowButtonAction('WETH') -// await borrowDialog.fillAmountAction(5) -// await borrowDialog.actionsContainer.acceptAllActionsAction(1) -// await borrowDialog.viewInMyPortfolioAction() -// }) - -// test('can switch from no e-mode to eth correlated', async () => { -// await myPortfolioPage.clickEModeButtonAction() -// await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') -// await eModeDialog.expectEModeCategoryTileStatus('ETH Correlated', 'Inactive') -// await eModeDialog.expectEModeTransactionOverview({ -// variant: 'e-mode-no-change', -// availableAssets: { -// assets: 'All assets', -// }, -// hf: '1.75', -// maxLtv: '68.50%', -// }) - -// await eModeDialog.clickEModeCategoryTileAction('ETH Correlated') -// await eModeDialog.actionsContainer.expectActions([{ type: 'setUserEMode', eModeCategoryId: 1 }]) -// await eModeDialog.expectEModeTransactionOverview({ -// variant: 'e-mode-change', -// availableAssets: { -// category: 'ETH Correlated', -// assets: 'WETH, wstETH, rETH', -// }, -// hf: { -// before: '1.75', -// after: '2.05', -// }, -// maxLtv: { -// before: '68.50%', -// after: '90.00%', -// }, -// }) - -// await eModeDialog.actionsContainer.acceptAllActionsAction(1) -// await eModeDialog.expectEModeSuccessPage('ETH Correlated') -// await eModeDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectEModeBadgeText('ETH Correlated') -// }) - -// test('cannot switch from no e-mode to stablecoins', async () => { -// await myPortfolioPage.clickEModeButtonAction() -// await eModeDialog.clickEModeCategoryTileAction('Stablecoins') -// await eModeDialog.expectAlertMessage( -// setUserEModeValidationIssueToMessage['borrowed-assets-emode-category-mismatch'], -// ) -// await eModeDialog.actionsContainer.expectDisabledActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) -// }) - -// test('can enter eth correlated e-mode and switch back to no e-mode', async () => { -// await myPortfolioPage.clickEModeButtonAction() -// await eModeDialog.setEModeAction('ETH Correlated') -// await myPortfolioPage.expectEModeBadgeText('ETH Correlated') -// await myPortfolioPage.clickEModeButtonAction() - -// await eModeDialog.expectEModeCategoryTileStatus('ETH Correlated', 'Active') -// await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Inactive') -// await eModeDialog.clickEModeCategoryTileAction('No E-Mode') - -// await eModeDialog.expectEModeTransactionOverview({ -// variant: 'e-mode-change', -// availableAssets: { -// assets: 'All assets', -// }, -// hf: { -// before: '2.05', -// after: '1.75', -// }, -// maxLtv: { -// before: '90.00%', -// after: '68.50%', -// }, -// }) -// await eModeDialog.actionsContainer.acceptAllActionsAction(1) -// await eModeDialog.expectEModeSuccessPage('No E-Mode') -// await eModeDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectEModeBadgeText('E-Mode Off') -// }) - -// test('cannot switch back to no e-mode if hf below 1', async () => { -// await myPortfolioPage.clickEModeButtonAction() -// await eModeDialog.setEModeAction('ETH Correlated') -// await myPortfolioPage.expectEModeBadgeText('ETH Correlated') - -// await myPortfolioPage.clickBorrowButtonAction('WETH') -// await borrowDialog.fillAmountAction(10) -// await eModeDialog.clickAcknowledgeRisk() -// await borrowDialog.actionsContainer.acceptAllActionsAction(1) -// await borrowDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.clickEModeButtonAction() -// await eModeDialog.clickEModeCategoryTileAction('No E-Mode') -// await eModeDialog.expectAlertMessage(setUserEModeValidationIssueToMessage['exceeds-ltv']) -// await eModeDialog.actionsContainer.expectDisabledActions([{ type: 'setUserEMode', eModeCategoryId: 0 }]) -// }) -// }) - -// test.describe('Stablecoins borrowed', () => { -// let eModeDialog: EModeDialogPageObject -// let borrowDialog: DialogPageObject -// let myPortfolioPage: MyPortfolioPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ETH: 1, wstETH: 100 }, -// }, -// }) - -// eModeDialog = new EModeDialogPageObject(page) -// borrowDialog = new DialogPageObject(page, /Borrow/) -// myPortfolioPage = new MyPortfolioPageObject(page) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositWithoutBorrowActions({ wstETH: 1 }) -// await myPortfolioPage.goToMyPortfolioAction() - -// await myPortfolioPage.clickBorrowButtonAction('USDC') -// await borrowDialog.fillAmountAction(1000) -// await borrowDialog.actionsContainer.acceptAllActionsAction(1) -// await borrowDialog.viewInMyPortfolioAction() -// }) - -// test('can switch from no e-mode to stablecoins', async () => { -// await myPortfolioPage.clickEModeButtonAction() -// await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') -// await eModeDialog.expectEModeCategoryTileStatus('Stablecoins', 'Inactive') -// await eModeDialog.expectEModeTransactionOverview({ -// variant: 'e-mode-no-change', -// availableAssets: { -// assets: 'All assets', -// }, -// hf: '2.08', -// maxLtv: '68.50%', -// }) - -// await eModeDialog.clickEModeCategoryTileAction('Stablecoins') -// await eModeDialog.actionsContainer.expectActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) -// await eModeDialog.expectEModeTransactionOverview({ -// variant: 'e-mode-change', -// availableAssets: { -// category: 'Stablecoins', -// assets: 'sDAI, USDC, USDT', -// }, -// hf: { -// before: '2.08', -// after: '2.08', -// }, -// maxLtv: { -// before: '68.50%', -// after: '68.50%', -// }, -// }) - -// await eModeDialog.actionsContainer.acceptAllActionsAction(1) -// await eModeDialog.expectEModeSuccessPage('Stablecoins') -// await eModeDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectEModeBadgeText('Stablecoins') -// }) - -// test('cannot switch from no e-mode to eth correlated', async () => { -// await myPortfolioPage.clickEModeButtonAction() -// await eModeDialog.clickEModeCategoryTileAction('ETH Correlated') -// await eModeDialog.expectAlertMessage( -// setUserEModeValidationIssueToMessage['borrowed-assets-emode-category-mismatch'], -// ) -// await eModeDialog.actionsContainer.expectDisabledActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) -// }) - -// test('can enter stablecoins e-mode and switch back to no e-mode', async () => { -// await myPortfolioPage.clickEModeButtonAction() -// await eModeDialog.setEModeAction('Stablecoins') -// await myPortfolioPage.expectEModeBadgeText('Stablecoins') -// await myPortfolioPage.clickEModeButtonAction() - -// await eModeDialog.expectEModeCategoryTileStatus('Stablecoins', 'Active') -// await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Inactive') -// await eModeDialog.clickEModeCategoryTileAction('No E-Mode') - -// await eModeDialog.expectEModeTransactionOverview({ -// variant: 'e-mode-change', -// availableAssets: { -// assets: 'All assets', -// }, -// hf: { -// before: '2.08', -// after: '2.08', -// }, -// maxLtv: { -// before: '68.50%', -// after: '68.50%', -// }, -// }) -// await eModeDialog.actionsContainer.acceptAllActionsAction(1) -// await eModeDialog.expectEModeSuccessPage('No E-Mode') -// await eModeDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectEModeBadgeText('E-Mode Off') -// }) -// }) - -// test.describe('Assets from multiple categories borrowed', () => { -// let eModeDialog: EModeDialogPageObject -// let borrowDialog: DialogPageObject -// let myPortfolioPage: MyPortfolioPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ETH: 1, wstETH: 100 }, -// }, -// }) - -// eModeDialog = new EModeDialogPageObject(page) -// borrowDialog = new DialogPageObject(page, /Borrow/) -// myPortfolioPage = new MyPortfolioPageObject(page) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositWithoutBorrowActions({ wstETH: 10 }) -// await myPortfolioPage.goToMyPortfolioAction() - -// await myPortfolioPage.clickBorrowButtonAction('rETH') -// await borrowDialog.fillAmountAction(1) -// await borrowDialog.actionsContainer.acceptAllActionsAction(1) -// await borrowDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.clickBorrowButtonAction('WBTC') -// await borrowDialog.fillAmountAction(0.1) -// await borrowDialog.actionsContainer.acceptAllActionsAction(1) -// await borrowDialog.viewInMyPortfolioAction() -// }) - -// test('cannot switch from no e-mode to stablecoins', async () => { -// await myPortfolioPage.clickEModeButtonAction() -// await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') -// await eModeDialog.expectEModeCategoryTileStatus('Stablecoins', 'Inactive') - -// await eModeDialog.clickEModeCategoryTileAction('Stablecoins') - -// await eModeDialog.expectAlertMessage( -// setUserEModeValidationIssueToMessage['borrowed-assets-emode-category-mismatch'], -// ) -// await eModeDialog.expectEModeTransactionOverview({ -// variant: 'e-mode-change', -// availableAssets: { -// category: 'Stablecoins', -// assets: 'sDAI, USDC, USDT', -// }, -// hf: { -// before: '3.12', -// after: '3.12', -// }, -// maxLtv: { -// before: '68.50%', -// after: '68.50%', -// }, -// }) -// await eModeDialog.actionsContainer.expectDisabledActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) -// }) - -// test('cannot switch from no e-mode to eth correlated', async () => { -// await myPortfolioPage.clickEModeButtonAction() -// await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') -// await eModeDialog.expectEModeCategoryTileStatus('ETH Correlated', 'Inactive') - -// await eModeDialog.clickEModeCategoryTileAction('ETH Correlated') -// await eModeDialog.expectEModeTransactionOverview({ -// variant: 'e-mode-change', -// availableAssets: { -// category: 'ETH Correlated', -// assets: 'WETH, wstETH, rETH', -// }, -// hf: { -// before: '3.12', -// after: '3.65', -// }, -// maxLtv: { -// before: '68.50%', -// after: '90.00%', -// }, -// }) -// await eModeDialog.expectAlertMessage( -// setUserEModeValidationIssueToMessage['borrowed-assets-emode-category-mismatch'], -// ) -// await eModeDialog.actionsContainer.expectDisabledActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) -// }) -// }) - -// test.describe('Nothing borrowed', () => { -// let eModeDialog: EModeDialogPageObject -// let myPortfolioPage: MyPortfolioPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ETH: 1, wstETH: 100 }, -// }, -// }) - -// eModeDialog = new EModeDialogPageObject(page) -// myPortfolioPage = new MyPortfolioPageObject(page) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositWithoutBorrowActions({ wstETH: 20 }) -// await myPortfolioPage.goToMyPortfolioAction() -// }) - -// test('can switch from no e-mode to eth correleated', async () => { -// await myPortfolioPage.clickEModeButtonAction() -// await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') -// await eModeDialog.expectEModeCategoryTileStatus('ETH Correlated', 'Inactive') - -// await eModeDialog.clickEModeCategoryTileAction('ETH Correlated') -// await eModeDialog.actionsContainer.expectActions([{ type: 'setUserEMode', eModeCategoryId: 1 }]) -// await eModeDialog.expectEModeTransactionOverview({ -// variant: 'no-borrow', -// availableAssets: { -// category: 'ETH Correlated', -// assets: 'WETH, wstETH, rETH', -// }, -// maxLtv: { -// before: '68.50%', -// after: '90.00%', -// }, -// }) - -// await eModeDialog.actionsContainer.acceptAllActionsAction(1) -// await eModeDialog.expectEModeSuccessPage('ETH Correlated') -// await eModeDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectEModeBadgeText('ETH Correlated') -// }) - -// test('can switch from no e-mode to stablecoins', async () => { -// await myPortfolioPage.clickEModeButtonAction() -// await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') - -// await eModeDialog.expectEModeCategoryTileStatus('Stablecoins', 'Inactive') -// await eModeDialog.clickEModeCategoryTileAction('Stablecoins') -// await eModeDialog.actionsContainer.expectActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) -// await eModeDialog.expectEModeTransactionOverview({ -// variant: 'no-borrow', -// availableAssets: { -// category: 'Stablecoins', -// assets: 'sDAI, USDC, USDT', -// }, -// maxLtv: { -// before: '68.50%', -// after: '68.50%', -// }, -// }) - -// await eModeDialog.actionsContainer.acceptAllActionsAction(1) -// await eModeDialog.expectEModeSuccessPage('Stablecoins') -// await eModeDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectEModeBadgeText('Stablecoins') -// }) - -// test('can enter e-mode and switch back to no e-mode', async () => { -// await myPortfolioPage.clickEModeButtonAction() -// await eModeDialog.setEModeAction('Stablecoins') -// await myPortfolioPage.expectEModeBadgeText('Stablecoins') -// await myPortfolioPage.clickEModeButtonAction() - -// await eModeDialog.expectEModeCategoryTileStatus('Stablecoins', 'Active') -// await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Inactive') -// await eModeDialog.clickEModeCategoryTileAction('No E-Mode') - -// await eModeDialog.expectEModeTransactionOverview({ -// variant: 'no-borrow', -// availableAssets: { -// assets: 'All assets', -// }, -// maxLtv: { -// before: '68.50%', -// after: '68.50%', -// }, -// }) -// await eModeDialog.actionsContainer.acceptAllActionsAction(1) -// await eModeDialog.expectEModeSuccessPage('No E-Mode') -// await eModeDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectEModeBadgeText('E-Mode Off') -// }) -// }) - -// test.describe('Liquidation risk warning', () => { -// test.describe('In danger zone', () => { -// let eModeDialog: EModeDialogPageObject -// let myPortfolioPage: MyPortfolioPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, -// }, -// }) - -// eModeDialog = new EModeDialogPageObject(page) -// myPortfolioPage = new MyPortfolioPageObject(page) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositWithoutBorrowActions({ rETH: 2, wstETH: 10 }) -// await myPortfolioPage.goToMyPortfolioAction() - -// await myPortfolioPage.clickBorrowButtonAction('WETH') -// const borrowDialog = new DialogPageObject(page, /Borrow/) -// await borrowDialog.fillAmountAction(8) -// await borrowDialog.clickAcknowledgeRisk() -// await borrowDialog.actionsContainer.acceptAllActionsAction(1) -// await borrowDialog.expectSuccessPage([{ asset: 'WETH', amount: 8 }], fork) -// await borrowDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectAssetToBeInBorrowTable('WETH') - -// await myPortfolioPage.clickEModeButtonAction() -// await eModeDialog.setEModeAction('ETH Correlated') -// await myPortfolioPage.expectEModeBadgeText('ETH Correlated') -// }) - -// test('shows risk warning', async () => { -// await myPortfolioPage.clickEModeButtonAction() -// await eModeDialog.clickEModeCategoryTileAction('No E-Mode') -// await eModeDialog.expectLiquidationRiskWarning( -// 'Disabling E-Mode decreases health factor of your position and puts you at risk of quick liquidation. You may lose part of your collateral.', -// ) -// }) - -// test('actions stay disabled until risk warning is acknowledged', async () => { -// await myPortfolioPage.clickEModeButtonAction() - -// await eModeDialog.clickEModeCategoryTileAction('No E-Mode') -// await eModeDialog.actionsContainer.expectDisabledActionAtIndex(0) -// await eModeDialog.clickAcknowledgeRisk() -// await eModeDialog.actionsContainer.expectEnabledActionAtIndex(0) -// }) - -// test('validation error; risk warning is not shown', async () => { -// await myPortfolioPage.clickEModeButtonAction() - -// await eModeDialog.clickEModeCategoryTileAction('Stablecoins') -// await eModeDialog.expectAlertMessage( -// setUserEModeValidationIssueToMessage['borrowed-assets-emode-category-mismatch'], -// ) -// await eModeDialog.expectLiquidationRiskWarningNotVisible() -// }) -// }) - -// test.describe('Not in danger zone', () => { -// let eModeDialog: EModeDialogPageObject -// let myPortfolioPage: MyPortfolioPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, -// }, -// }) - -// eModeDialog = new EModeDialogPageObject(page) -// myPortfolioPage = new MyPortfolioPageObject(page) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositWithoutBorrowActions({ rETH: 2, wstETH: 10 }) -// await myPortfolioPage.goToMyPortfolioAction() - -// await myPortfolioPage.clickBorrowButtonAction('WETH') -// const borrowDialog = new DialogPageObject(page, /Borrow/) -// await borrowDialog.fillAmountAction(2) -// await borrowDialog.actionsContainer.acceptAllActionsAction(1) -// await borrowDialog.expectSuccessPage([{ asset: 'WETH', amount: 2 }], fork) -// await borrowDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectAssetToBeInBorrowTable('WETH') -// }) - -// test('hf above danger zone threshold; risk warning is not shown', async () => { -// await myPortfolioPage.clickEModeButtonAction() -// await eModeDialog.clickEModeCategoryTileAction('No E-Mode') -// await eModeDialog.expectLiquidationRiskWarningNotVisible() -// }) -// }) -// }) -// }) +import { setUserEModeValidationIssueToMessage } from '@/domain/market-validators/validateSetUserEMode' +import { BorrowPageObject } from '@/pages/Borrow.PageObject' +import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { DialogPageObject } from '../common/Dialog.PageObject' +import { EModeDialogPageObject } from './EModeDialog.PageObject' + +test.describe('E-Mode dialog', () => { + test.describe('ETH correlated assets borrowed', () => { + let eModeDialog: EModeDialogPageObject + let borrowDialog: DialogPageObject + let myPortfolioPage: MyPortfolioPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ETH: 1, wstETH: 100 }, + }, + }) + + eModeDialog = new EModeDialogPageObject(testContext) + borrowDialog = new DialogPageObject({ + testContext, + header: /Borrow/, + }) + myPortfolioPage = new MyPortfolioPageObject(testContext) + + const borrowPage = new BorrowPageObject(testContext) + await borrowPage.depositWithoutBorrowActions({ assetsToDeposit: { wstETH: 20 } }) + await myPortfolioPage.goToMyPortfolioAction() + + await myPortfolioPage.clickBorrowButtonAction('rETH') + await borrowDialog.fillAmountAction(5) + await borrowDialog.actionsContainer.acceptAllActionsAction(1) + await borrowDialog.viewInMyPortfolioAction() + await myPortfolioPage.clickBorrowButtonAction('WETH') + await borrowDialog.fillAmountAction(5) + await borrowDialog.actionsContainer.acceptAllActionsAction(1) + await borrowDialog.viewInMyPortfolioAction() + }) + + test('can switch from no e-mode to eth correlated', async () => { + await myPortfolioPage.clickEModeButtonAction() + await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') + await eModeDialog.expectEModeCategoryTileStatus('ETH Correlated', 'Inactive') + await eModeDialog.expectEModeTransactionOverview({ + variant: 'e-mode-no-change', + availableAssets: { + assets: 'All assets', + }, + hf: '1.79', + maxLtv: '79.00%', + }) + + await eModeDialog.clickEModeCategoryTileAction('ETH Correlated') + await eModeDialog.actionsContainer.expectActions([{ type: 'setUserEMode', eModeCategoryId: 1 }]) + await eModeDialog.expectEModeTransactionOverview({ + variant: 'e-mode-change', + availableAssets: { + category: 'ETH Correlated', + assets: 'WETH, wstETH, rETH', + }, + hf: { + before: '1.79', + after: '2.08', + }, + maxLtv: { + before: '79.00%', + after: '92.00%', + }, + }) + + await eModeDialog.actionsContainer.acceptAllActionsAction(1) + await eModeDialog.expectEModeSuccessPage('ETH Correlated') + await eModeDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectEModeBadgeText('ETH Correlated') + }) + + test('cannot switch from no e-mode to stablecoins', async () => { + await myPortfolioPage.clickEModeButtonAction() + await eModeDialog.clickEModeCategoryTileAction('Stablecoins') + await eModeDialog.expectAlertMessage( + setUserEModeValidationIssueToMessage['borrowed-assets-emode-category-mismatch'], + ) + await eModeDialog.actionsContainer.expectDisabledActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) + }) + + test('can enter eth correlated e-mode and switch back to no e-mode', async () => { + await myPortfolioPage.clickEModeButtonAction() + await eModeDialog.setEModeAction('ETH Correlated') + await myPortfolioPage.expectEModeBadgeText('ETH Correlated') + await myPortfolioPage.clickEModeButtonAction() + + await eModeDialog.expectEModeCategoryTileStatus('ETH Correlated', 'Active') + await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Inactive') + await eModeDialog.clickEModeCategoryTileAction('No E-Mode') + + await eModeDialog.expectEModeTransactionOverview({ + variant: 'e-mode-change', + availableAssets: { + assets: 'All assets', + }, + hf: { + before: '2.08', + after: '1.79', + }, + maxLtv: { + before: '92.00%', + after: '79.00%', + }, + }) + await eModeDialog.actionsContainer.acceptAllActionsAction(1) + await eModeDialog.expectEModeSuccessPage('No E-Mode') + await eModeDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectEModeBadgeText('E-Mode Off') + }) + + test('cannot switch back to no e-mode if hf below 1', async () => { + await myPortfolioPage.clickEModeButtonAction() + await eModeDialog.setEModeAction('ETH Correlated') + await myPortfolioPage.expectEModeBadgeText('ETH Correlated') + + await myPortfolioPage.clickBorrowButtonAction('WETH') + await borrowDialog.fillAmountAction(10) + await eModeDialog.clickAcknowledgeRisk() + await borrowDialog.actionsContainer.acceptAllActionsAction(1) + await borrowDialog.viewInMyPortfolioAction() + + await myPortfolioPage.clickEModeButtonAction() + await eModeDialog.clickEModeCategoryTileAction('No E-Mode') + await eModeDialog.expectAlertMessage(setUserEModeValidationIssueToMessage['exceeds-ltv']) + await eModeDialog.actionsContainer.expectDisabledActions([{ type: 'setUserEMode', eModeCategoryId: 0 }]) + }) + }) + + test.describe('Stablecoins borrowed', () => { + let eModeDialog: EModeDialogPageObject + let borrowDialog: DialogPageObject + let myPortfolioPage: MyPortfolioPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ETH: 1, wstETH: 100 }, + }, + }) + + eModeDialog = new EModeDialogPageObject(testContext) + borrowDialog = new DialogPageObject({ + testContext, + header: /Borrow/, + }) + myPortfolioPage = new MyPortfolioPageObject(testContext) + + const borrowPage = new BorrowPageObject(testContext) + await borrowPage.depositWithoutBorrowActions({ assetsToDeposit: { wstETH: 1 } }) + await myPortfolioPage.goToMyPortfolioAction() + + await myPortfolioPage.clickBorrowButtonAction('USDC') + await borrowDialog.fillAmountAction(1000) + await borrowDialog.actionsContainer.acceptAllActionsAction(1) + await borrowDialog.viewInMyPortfolioAction() + }) + + test('can switch from no e-mode to stablecoins', async () => { + await myPortfolioPage.clickEModeButtonAction() + await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') + await eModeDialog.expectEModeCategoryTileStatus('Stablecoins', 'Inactive') + await eModeDialog.expectEModeTransactionOverview({ + variant: 'e-mode-no-change', + availableAssets: { + assets: 'All assets', + }, + hf: '3.73', + maxLtv: '79.00%', + }) + + await eModeDialog.clickEModeCategoryTileAction('Stablecoins') + await eModeDialog.actionsContainer.expectActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) + await eModeDialog.expectEModeTransactionOverview({ + variant: 'e-mode-change', + availableAssets: { + category: 'Stablecoins', + assets: 'sDAI, USDC, USDT', + }, + hf: { + before: '3.73', + after: '3.73', + }, + maxLtv: { + before: '79.00%', + after: '79.00%', + }, + }) + + await eModeDialog.actionsContainer.acceptAllActionsAction(1) + await eModeDialog.expectEModeSuccessPage('Stablecoins') + await eModeDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectEModeBadgeText('Stablecoins') + }) + + test('cannot switch from no e-mode to eth correlated', async () => { + await myPortfolioPage.clickEModeButtonAction() + await eModeDialog.clickEModeCategoryTileAction('ETH Correlated') + await eModeDialog.expectAlertMessage( + setUserEModeValidationIssueToMessage['borrowed-assets-emode-category-mismatch'], + ) + await eModeDialog.actionsContainer.expectDisabledActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) + }) + + test('can enter stablecoins e-mode and switch back to no e-mode', async () => { + await myPortfolioPage.clickEModeButtonAction() + await eModeDialog.setEModeAction('Stablecoins') + await myPortfolioPage.expectEModeBadgeText('Stablecoins') + await myPortfolioPage.clickEModeButtonAction() + + await eModeDialog.expectEModeCategoryTileStatus('Stablecoins', 'Active') + await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Inactive') + await eModeDialog.clickEModeCategoryTileAction('No E-Mode') + + await eModeDialog.expectEModeTransactionOverview({ + variant: 'e-mode-change', + availableAssets: { + assets: 'All assets', + }, + hf: { + before: '3.73', + after: '3.73', + }, + maxLtv: { + before: '79.00%', + after: '79.00%', + }, + }) + await eModeDialog.actionsContainer.acceptAllActionsAction(1) + await eModeDialog.expectEModeSuccessPage('No E-Mode') + await eModeDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectEModeBadgeText('E-Mode Off') + }) + }) + + test.describe('Assets from multiple categories borrowed', () => { + let eModeDialog: EModeDialogPageObject + let borrowDialog: DialogPageObject + let myPortfolioPage: MyPortfolioPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ETH: 1, wstETH: 100 }, + }, + }) + + eModeDialog = new EModeDialogPageObject(testContext) + borrowDialog = new DialogPageObject({ + testContext, + header: /Borrow/, + }) + myPortfolioPage = new MyPortfolioPageObject(testContext) + + const borrowPage = new BorrowPageObject(testContext) + await borrowPage.depositWithoutBorrowActions({ assetsToDeposit: { wstETH: 10 } }) + await myPortfolioPage.goToMyPortfolioAction() + + await myPortfolioPage.clickBorrowButtonAction('rETH') + await borrowDialog.fillAmountAction(1) + await borrowDialog.actionsContainer.acceptAllActionsAction(1) + await borrowDialog.viewInMyPortfolioAction() + + await myPortfolioPage.clickBorrowButtonAction('cbBTC') + await borrowDialog.fillAmountAction(0.1) + await borrowDialog.actionsContainer.acceptAllActionsAction(1) + await borrowDialog.viewInMyPortfolioAction() + }) + + test('cannot switch from no e-mode to stablecoins', async () => { + await myPortfolioPage.clickEModeButtonAction() + await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') + await eModeDialog.expectEModeCategoryTileStatus('Stablecoins', 'Inactive') + + await eModeDialog.clickEModeCategoryTileAction('Stablecoins') + + await eModeDialog.expectAlertMessage( + setUserEModeValidationIssueToMessage['borrowed-assets-emode-category-mismatch'], + ) + await eModeDialog.expectEModeTransactionOverview({ + variant: 'e-mode-change', + availableAssets: { + category: 'Stablecoins', + assets: 'sDAI, USDC, USDT', + }, + hf: { + before: '2.56', + after: '2.56', + }, + maxLtv: { + before: '79.00%', + after: '79.00%', + }, + }) + await eModeDialog.actionsContainer.expectDisabledActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) + }) + + test('cannot switch from no e-mode to eth correlated', async () => { + await myPortfolioPage.clickEModeButtonAction() + await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') + await eModeDialog.expectEModeCategoryTileStatus('ETH Correlated', 'Inactive') + + await eModeDialog.clickEModeCategoryTileAction('ETH Correlated') + await eModeDialog.expectEModeTransactionOverview({ + variant: 'e-mode-change', + availableAssets: { + category: 'ETH Correlated', + assets: 'WETH, wstETH, rETH', + }, + hf: { + before: '2.56', + after: '2.98', + }, + maxLtv: { + before: '79.00%', + after: '92.00%', + }, + }) + await eModeDialog.expectAlertMessage( + setUserEModeValidationIssueToMessage['borrowed-assets-emode-category-mismatch'], + ) + await eModeDialog.actionsContainer.expectDisabledActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) + }) + }) + + test.describe('Nothing borrowed', () => { + let eModeDialog: EModeDialogPageObject + let myPortfolioPage: MyPortfolioPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ETH: 1, wstETH: 100 }, + }, + }) + + eModeDialog = new EModeDialogPageObject(testContext) + myPortfolioPage = new MyPortfolioPageObject(testContext) + + const borrowPage = new BorrowPageObject(testContext) + await borrowPage.depositWithoutBorrowActions({ assetsToDeposit: { wstETH: 20 } }) + await myPortfolioPage.goToMyPortfolioAction() + }) + + test('can switch from no e-mode to eth correleated', async () => { + await myPortfolioPage.clickEModeButtonAction() + await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') + await eModeDialog.expectEModeCategoryTileStatus('ETH Correlated', 'Inactive') + + await eModeDialog.clickEModeCategoryTileAction('ETH Correlated') + await eModeDialog.actionsContainer.expectActions([{ type: 'setUserEMode', eModeCategoryId: 1 }]) + await eModeDialog.expectEModeTransactionOverview({ + variant: 'no-borrow', + availableAssets: { + category: 'ETH Correlated', + assets: 'WETH, wstETH, rETH', + }, + maxLtv: { + before: '79.00%', + after: '92.00%', + }, + }) + + await eModeDialog.actionsContainer.acceptAllActionsAction(1) + await eModeDialog.expectEModeSuccessPage('ETH Correlated') + await eModeDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectEModeBadgeText('ETH Correlated') + }) + + test('can switch from no e-mode to stablecoins', async () => { + await myPortfolioPage.clickEModeButtonAction() + await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Active') + + await eModeDialog.expectEModeCategoryTileStatus('Stablecoins', 'Inactive') + await eModeDialog.clickEModeCategoryTileAction('Stablecoins') + await eModeDialog.actionsContainer.expectActions([{ type: 'setUserEMode', eModeCategoryId: 2 }]) + await eModeDialog.expectEModeTransactionOverview({ + variant: 'no-borrow', + availableAssets: { + category: 'Stablecoins', + assets: 'sDAI, USDC, USDT', + }, + maxLtv: { + before: '79.00%', + after: '79.00%', + }, + }) + + await eModeDialog.actionsContainer.acceptAllActionsAction(1) + await eModeDialog.expectEModeSuccessPage('Stablecoins') + await eModeDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectEModeBadgeText('Stablecoins') + }) + + test('can enter e-mode and switch back to no e-mode', async () => { + await myPortfolioPage.clickEModeButtonAction() + await eModeDialog.setEModeAction('Stablecoins') + await myPortfolioPage.expectEModeBadgeText('Stablecoins') + await myPortfolioPage.clickEModeButtonAction() + + await eModeDialog.expectEModeCategoryTileStatus('Stablecoins', 'Active') + await eModeDialog.expectEModeCategoryTileStatus('No E-Mode', 'Inactive') + await eModeDialog.clickEModeCategoryTileAction('No E-Mode') + + await eModeDialog.expectEModeTransactionOverview({ + variant: 'no-borrow', + availableAssets: { + assets: 'All assets', + }, + maxLtv: { + before: '79.00%', + after: '79.00%', + }, + }) + await eModeDialog.actionsContainer.acceptAllActionsAction(1) + await eModeDialog.expectEModeSuccessPage('No E-Mode') + await eModeDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectEModeBadgeText('E-Mode Off') + }) + }) + + test.describe('Liquidation risk warning', () => { + test.describe('In danger zone', () => { + let eModeDialog: EModeDialogPageObject + let myPortfolioPage: MyPortfolioPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, + }, + }) + + eModeDialog = new EModeDialogPageObject(testContext) + myPortfolioPage = new MyPortfolioPageObject(testContext) + + const borrowPage = new BorrowPageObject(testContext) + await borrowPage.depositWithoutBorrowActions({ assetsToDeposit: { rETH: 2, wstETH: 10 } }) + await myPortfolioPage.goToMyPortfolioAction() + + await myPortfolioPage.clickBorrowButtonAction('WETH') + const borrowDialog = new DialogPageObject({ + testContext, + header: /Borrow/, + }) + await borrowDialog.fillAmountAction(8) + await borrowDialog.clickAcknowledgeRisk() + await borrowDialog.actionsContainer.acceptAllActionsAction(1) + await borrowDialog.expectSuccessPage({ + tokenWithValue: [{ asset: 'WETH', amount: '8.00', usdValue: '$31,426.51' }], + }) + await borrowDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectAssetToBeInBorrowTable('WETH') + + await myPortfolioPage.clickEModeButtonAction() + await eModeDialog.setEModeAction('ETH Correlated') + await myPortfolioPage.expectEModeBadgeText('ETH Correlated') + }) + + test('shows risk warning', async () => { + await myPortfolioPage.clickEModeButtonAction() + await eModeDialog.clickEModeCategoryTileAction('No E-Mode') + await eModeDialog.expectLiquidationRiskWarning( + 'Disabling E-Mode decreases health factor of your position and puts you at risk of quick liquidation. You may lose part of your collateral.', + ) + }) + + test('actions stay disabled until risk warning is acknowledged', async () => { + await myPortfolioPage.clickEModeButtonAction() + + await eModeDialog.clickEModeCategoryTileAction('No E-Mode') + await eModeDialog.actionsContainer.expectDisabledActionAtIndex(0) + await eModeDialog.clickAcknowledgeRisk() + await eModeDialog.actionsContainer.expectEnabledActionAtIndex(0) + }) + + test('validation error; risk warning is not shown', async () => { + await myPortfolioPage.clickEModeButtonAction() + + await eModeDialog.clickEModeCategoryTileAction('Stablecoins') + await eModeDialog.expectAlertMessage( + setUserEModeValidationIssueToMessage['borrowed-assets-emode-category-mismatch'], + ) + await eModeDialog.expectLiquidationRiskWarningNotVisible() + }) + }) + + test.describe('Not in danger zone', () => { + let eModeDialog: EModeDialogPageObject + let myPortfolioPage: MyPortfolioPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, + }, + }) + + eModeDialog = new EModeDialogPageObject(testContext) + myPortfolioPage = new MyPortfolioPageObject(testContext) + + const borrowPage = new BorrowPageObject(testContext) + await borrowPage.depositWithoutBorrowActions({ assetsToDeposit: { rETH: 2, wstETH: 10 } }) + await myPortfolioPage.goToMyPortfolioAction() + + await myPortfolioPage.clickBorrowButtonAction('WETH') + const borrowDialog = new DialogPageObject({ + testContext, + header: /Borrow/, + }) + await borrowDialog.fillAmountAction(2) + await borrowDialog.actionsContainer.acceptAllActionsAction(1) + await borrowDialog.expectSuccessPage({ + tokenWithValue: [{ asset: 'WETH', amount: '2.00', usdValue: '$7,856.63' }], + }) + await borrowDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectAssetToBeInBorrowTable('WETH') + }) + + test('hf above danger zone threshold; risk warning is not shown', async () => { + await myPortfolioPage.clickEModeButtonAction() + await eModeDialog.clickEModeCategoryTileAction('No E-Mode') + await eModeDialog.expectLiquidationRiskWarningNotVisible() + }) + }) + }) +}) From f86cf6bea98a69178854d5a4e8c4f1ef574bba37 Mon Sep 17 00:00:00 2001 From: Vladyslav Yatsenko <52505649+yivlad@users.noreply.github.com> Date: Thu, 19 Dec 2024 10:27:35 +0100 Subject: [PATCH 15/29] Rewrite deposit dialog E2E tests (#505) --- .../dialogs/deposit/DepositDialog.test-e2e.ts | 888 +++++++++--------- packages/app/src/ui/assets/index.ts | 1 + 2 files changed, 421 insertions(+), 468 deletions(-) diff --git a/packages/app/src/features/dialogs/deposit/DepositDialog.test-e2e.ts b/packages/app/src/features/dialogs/deposit/DepositDialog.test-e2e.ts index a89b2c3ab..70c90e19a 100644 --- a/packages/app/src/features/dialogs/deposit/DepositDialog.test-e2e.ts +++ b/packages/app/src/features/dialogs/deposit/DepositDialog.test-e2e.ts @@ -1,468 +1,420 @@ -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' - -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { BorrowPageObject } from '@/pages/Borrow.PageObject' -// import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { screenshot } from '@/test/e2e/utils' - -// import { tenderlyRpcActions } from '@/domain/tenderly/TenderlyRpcActions' -// import { DialogPageObject } from '../common/Dialog.PageObject' - -// const headerRegExp = /Deposit */ - -// test.describe('Deposit dialog', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) -// const initialBalances = { -// wstETH: 100, -// rETH: 100, -// ETH: 100, -// } - -// test.describe('Position with deposit and borrow', () => { -// const initialDeposits = { -// wstETH: 1, -// rETH: 2, -// } -// const daiToBorrow = 1500 -// const expectedInitialHealthFactor = '4.03' -// const expectedHealthFactor = '5.35' - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ...initialBalances }, -// }, -// }) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) -// await borrowPage.viewInMyPortfolioAction() - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// // @todo This waits for the refetch of the data after successful borrow transaction to happen. -// // This is no ideal, probably we need to refactor expectDepositTable so it takes advantage from -// // playwright's timeouts instead of parsing it's current state. Then we would be able to -// // easily wait for the table to be updated. -// await myPortfolioPage.expectAssetToBeInDepositTable('DAI') -// }) - -// test('opens dialog with selected asset', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickDepositButtonAction('rETH') - -// const depositDialog = new DialogPageObject(page, headerRegExp) -// await depositDialog.expectSelectedAsset('rETH') -// await depositDialog.expectDialogHeader('Deposit rETH') -// await depositDialog.expectHealthFactorBeforeVisible() - -// await screenshot(depositDialog.getDialog(), 'deposit-dialog-default-view') -// }) - -// test('calculates health factor changes correctly', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickDepositButtonAction('rETH') - -// const depositDialog = new DialogPageObject(page, headerRegExp) -// await depositDialog.fillAmountAction(1) - -// await depositDialog.expectRiskLevelBefore('Healthy') -// await depositDialog.expectHealthFactorBefore(expectedInitialHealthFactor) -// await depositDialog.expectRiskLevelAfter('Healthy') -// await depositDialog.expectHealthFactorAfter(expectedHealthFactor) - -// // @note this is needed for deterministic screenshots -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await actionsContainer.expectEnabledActionAtIndex(0) - -// await screenshot(depositDialog.getDialog(), 'deposit-dialog-health-factor') -// }) - -// test('after deposit, health factor matches myPortfolio', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickDepositButtonAction('rETH') - -// const depositDialog = new DialogPageObject(page, headerRegExp) -// await depositDialog.fillAmountAction(1) - -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) - -// await depositDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectHealthFactor(expectedHealthFactor) -// }) - -// test('has correct action plan for erc-20 with permit support', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.expectDepositTable(initialDeposits) - -// await myPortfolioPage.clickDepositButtonAction('wstETH') - -// const depositDialog = new DialogPageObject(page, headerRegExp) -// await depositDialog.fillAmountAction(1) -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await actionsContainer.expectActions([ -// { type: 'permit', asset: 'wstETH' }, -// { type: 'deposit', asset: 'wstETH' }, -// ]) -// }) - -// test('can switch to approves in action plan', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.expectDepositTable(initialDeposits) - -// await myPortfolioPage.clickDepositButtonAction('wstETH') - -// const depositDialog = new DialogPageObject(page, headerRegExp) -// await depositDialog.fillAmountAction(1) -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - -// await actionsContainer.expectEnabledActionAtIndex(0) -// await actionsContainer.expectActions([ -// { type: 'permit', asset: 'wstETH' }, -// { type: 'deposit', asset: 'wstETH' }, -// ]) - -// await actionsContainer.switchPreferPermitsAction() - -// await actionsContainer.expectEnabledActionAtIndex(0) -// await actionsContainer.expectActions([ -// { type: 'approve', asset: 'wstETH' }, -// { type: 'deposit', asset: 'wstETH' }, -// ]) -// }) - -// test('has correct action plan for erc-20 with no permit support', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.expectDepositTable(initialDeposits) - -// await myPortfolioPage.clickDepositButtonAction('rETH') - -// const depositDialog = new DialogPageObject(page, headerRegExp) -// await depositDialog.fillAmountAction(1) -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await actionsContainer.expectActions([ -// { type: 'approve', asset: 'rETH' }, -// { type: 'deposit', asset: 'rETH' }, -// ]) -// }) - -// test('can deposit erc-20 using permits', async ({ page }) => { -// const deposit = { -// asset: 'wstETH', -// amount: 1, -// } - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.expectDepositTable(initialDeposits) - -// await myPortfolioPage.clickDepositButtonAction(deposit.asset) - -// const depositDialog = new DialogPageObject(page, headerRegExp) -// await depositDialog.fillAmountAction(deposit.amount) -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) -// await depositDialog.expectSuccessPage([deposit], fork) - -// await screenshot(depositDialog.getDialog(), 'deposit-dialog-wsteth-success') - -// await depositDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.expectDepositTable({ -// ...initialDeposits, -// wstETH: initialDeposits.wstETH + 1, -// }) -// }) - -// test('can deposit erc-20 using approves', async ({ page }) => { -// const deposit = { -// asset: 'rETH', -// amount: 1, -// } - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.expectDepositTable(initialDeposits) - -// await myPortfolioPage.clickDepositButtonAction(deposit.asset) - -// const depositDialog = new DialogPageObject(page, headerRegExp) -// await depositDialog.fillAmountAction(deposit.amount) -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) -// await depositDialog.expectSuccessPage([deposit], fork) - -// await screenshot(depositDialog.getDialog(), 'deposit-dialog-reth-success') - -// await depositDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.expectDepositTable({ -// ...initialDeposits, -// rETH: initialDeposits.rETH + 1, -// }) -// }) - -// test('has correct action plan for native asset', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.expectDepositTable(initialDeposits) - -// await myPortfolioPage.clickDepositButtonAction('WETH') - -// const depositDialog = new DialogPageObject(page, headerRegExp) -// await depositDialog.selectAssetAction('ETH') -// await depositDialog.fillAmountAction(1) -// await depositDialog.expectHealthFactorVisible() -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await actionsContainer.expectActions([{ type: 'deposit', asset: 'ETH' }]) - -// await screenshot(depositDialog.getDialog(), 'deposit-dialog-eth-action-plan') -// }) - -// test('can deposit native asset', async ({ page }) => { -// const deposit = { -// asset: 'WETH', -// amount: 1, -// } - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.expectDepositTable(initialDeposits) - -// await myPortfolioPage.clickDepositButtonAction(deposit.asset) - -// const depositDialog = new DialogPageObject(page, headerRegExp) -// await depositDialog.selectAssetAction('ETH') -// await depositDialog.fillAmountAction(deposit.amount) -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(1) -// await depositDialog.expectSuccessPage( -// [ -// { -// asset: 'ETH', -// amount: deposit.amount, -// }, -// ], -// fork, -// ) -// await screenshot(depositDialog.getDialog(), 'deposit-dialog-eth-success') - -// await depositDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.expectDepositTable({ -// ...initialDeposits, -// // @todo Figure out how WETH and ETH conversion should work -// WETH: 1, -// }) -// }) - -// test("can't deposit more than wallet balance", async ({ page }) => { -// const depositAsset = 'rETH' -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickDepositButtonAction(depositAsset) - -// const depositDialog = new DialogPageObject(page, headerRegExp) -// await depositDialog.fillAmountAction(initialBalances[depositAsset] - initialDeposits[depositAsset] + 1) - -// await depositDialog.expectAssetInputError('Exceeds your balance') -// await depositDialog.expectHealthFactorBeforeVisible() -// await screenshot(depositDialog.getDialog(), 'deposit-dialog-exceeds-balance') -// }) - -// test('requires new approve when the input value is increased', async ({ page }) => { -// const depositAsset = 'rETH' -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickDepositButtonAction(depositAsset) - -// const depositDialog = new DialogPageObject(page, headerRegExp) -// await depositDialog.fillAmountAction(1) - -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - -// await actionsContainer.acceptActionAtIndex(0) -// await actionsContainer.expectEnabledActionAtIndex(1, { type: 'deposit', asset: depositAsset }) - -// await depositDialog.fillAmountAction(2) - -// await actionsContainer.expectEnabledActionAtIndex(0, { type: 'approve', asset: depositAsset }) -// }) - -// test('requires new permit when the input value is changed', async ({ page }) => { -// const depositAsset = 'wstETH' -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickDepositButtonAction(depositAsset) - -// const depositDialog = new DialogPageObject(page, headerRegExp) -// await depositDialog.fillAmountAction(2) - -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - -// await actionsContainer.acceptActionAtIndex(0) -// await actionsContainer.expectEnabledActionAtIndex(1, { type: 'deposit', asset: depositAsset }) - -// await depositDialog.fillAmountAction(1) - -// await actionsContainer.expectEnabledActionAtIndex(0, { type: 'permit', asset: depositAsset }) -// }) -// }) - -// test.describe('Position with only deposit', () => { -// const initialDeposits = { -// wstETH: 10, -// rETH: 2, -// } - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ...initialBalances }, -// }, -// }) - -// const borrowPage = new BorrowPageObject(page) -// // to simulate a position with only deposits, we go through the easy borrow flow -// // but interrupt it before the borrow action, going directly to the myPortfolio -// // this way we have deposit transactions executed, but no borrow transaction -// // resulting in a position with only deposits -// await borrowPage.fillDepositAssetAction(0, 'wstETH', initialDeposits.wstETH) -// await borrowPage.addNewDepositAssetAction() -// await borrowPage.fillBorrowAssetAction(1) // doesn't matter, we're not borrowing anything -// await borrowPage.fillDepositAssetAction(1, 'rETH', initialDeposits.rETH) -// await borrowPage.submitAction() - -// const actionsContainer = new ActionsPageObject(page) -// for (let i = 0; i < 4; i++) { -// await actionsContainer.acceptActionAtIndex(i) -// } -// await actionsContainer.expectEnabledActionAtIndex(4) - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.goToMyPortfolioAction() -// }) - -// test('does not display health factor', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickDepositButtonAction('rETH') - -// const depositDialog = new DialogPageObject(page, headerRegExp) -// await depositDialog.fillAmountAction(1) - -// await depositDialog.expectHealthFactorNotVisible() - -// // @note this is needed for deterministic screenshots -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await actionsContainer.expectEnabledActionAtIndex(0) - -// await screenshot(depositDialog.getDialog(), 'deposit-dialog-only-deposit-health-factor') -// }) -// }) - -// test.describe('No position', () => { -// const fork = setupFork({ blockNumber: 19588510n, chainId: mainnet.id }) // block number with WBTC supply close to cap - -// test('can deposit up to max cap', async ({ page }) => { -// const initialBalances = { -// ETH: 1, -// WBTC: 1000, -// } - -// await setup(page, fork, { -// initialPage: 'myPortfolio', -// account: { -// type: 'connected-random', -// assetBalances: { ...initialBalances }, -// }, -// }) - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickDepositButtonAction('WBTC') - -// const depositDialog = new DialogPageObject(page, headerRegExp) -// await depositDialog.clickMaxAmountAction() -// await tenderlyRpcActions.evmIncreaseTime(fork.forkUrl, 5 * 60) - -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) -// await depositDialog.expectSuccessPage( -// [ -// { -// asset: 'WBTC', -// amount: 507.527307, -// }, -// ], -// fork, -// { -// WBTC: 34_087_363.63, -// }, -// ) - -// await depositDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectDepositTable({ -// WBTC: 507.527307, -// }) -// }) - -// test('can deposit asset that cannot be used as collateral', async ({ page }) => { -// const initialBalances = { -// ETH: 1, -// USDT: 10000, -// } - -// await setup(page, fork, { -// initialPage: 'myPortfolio', -// account: { -// type: 'connected-random', -// assetBalances: { ...initialBalances }, -// }, -// }) - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickDepositButtonAction('USDT') - -// const depositDialog = new DialogPageObject(page, headerRegExp) -// await depositDialog.fillAmountAction(initialBalances.USDT) - -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) -// await depositDialog.expectSuccessPage( -// [ -// { -// asset: 'USDT', -// amount: initialBalances.USDT, -// }, -// ], -// fork, -// ) - -// await depositDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectDepositTable({ -// USDT: initialBalances.USDT, -// }) -// }) - -// test('retains some native asset when depositing max', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'myPortfolio', -// account: { -// type: 'connected-random', -// assetBalances: { ETH: 1 }, -// }, -// }) - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickDepositButtonAction('WETH') -// const depositDialog = new DialogPageObject(page, headerRegExp) -// await depositDialog.selectAssetAction('ETH') -// await depositDialog.clickMaxAmountAction() - -// await depositDialog.expectInputValue('0.999') -// await depositDialog.expectMaxButtonDisabled() -// await depositDialog.actionsContainer.expectEnabledActionAtIndex(0) -// await depositDialog.actionsContainer.expectActions([{ type: 'deposit', asset: 'ETH' }]) -// }) -// }) -// }) +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' + +import { BorrowPageObject } from '@/pages/Borrow.PageObject' +import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' + +import { TestTokenWithValue } from '@/test/e2e/assertions' +import { DialogPageObject } from '../common/Dialog.PageObject' + +const headerRegExp = /Deposit */ + +test.describe('Deposit dialog', () => { + const initialBalances = { + wstETH: 100, + rETH: 100, + ETH: 100, + } + + test.describe('Position with deposit and borrow', () => { + const initialDeposits = { + wstETH: 1, + rETH: 2, + } + const daiToBorrow = 1500 + const expectedInitialHealthFactor = '7.2' + const expectedHealthFactor = '9.55' + + let myPortfolioPage: MyPortfolioPageObject + let depositDialog: DialogPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ...initialBalances }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + await borrowPage.depositAssetsActions({ assetsToDeposit: initialDeposits, daiToBorrow }) + await borrowPage.viewInMyPortfolioAction() + + myPortfolioPage = new MyPortfolioPageObject(testContext) + // @todo This waits for the refetch of the data after successful borrow transaction to happen. + // This is no ideal, probably we need to refactor expectDepositTable so it takes advantage from + // playwright's timeouts instead of parsing it's current state. Then we would be able to + // easily wait for the table to be updated. + await myPortfolioPage.expectAssetToBeInDepositTable('DAI') + await myPortfolioPage.expectDepositTable(initialDeposits) + + depositDialog = new DialogPageObject({ + testContext, + header: headerRegExp, + }) + }) + + test('opens dialog with selected asset', async () => { + await myPortfolioPage.clickDepositButtonAction('rETH') + + await depositDialog.expectSelectedAsset('rETH') + await depositDialog.expectDialogHeader('Deposit rETH') + await depositDialog.expectHealthFactorBeforeVisible() + }) + + test('calculates health factor changes correctly', async () => { + await myPortfolioPage.clickDepositButtonAction('rETH') + await depositDialog.fillAmountAction(1) + + await depositDialog.expectRiskLevelBefore('Healthy') + await depositDialog.expectHealthFactorBefore(expectedInitialHealthFactor) + await depositDialog.expectRiskLevelAfter('Healthy') + await depositDialog.expectHealthFactorAfter(expectedHealthFactor) + }) + + test('after deposit, health factor matches myPortfolio', async () => { + await myPortfolioPage.clickDepositButtonAction('rETH') + await depositDialog.fillAmountAction(1) + await depositDialog.actionsContainer.acceptAllActionsAction(2) + + await depositDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectHealthFactor(expectedHealthFactor) + }) + + test('has correct action plan for erc-20 with permit support', async () => { + await myPortfolioPage.clickDepositButtonAction('wstETH') + await depositDialog.fillAmountAction(1) + + await depositDialog.actionsContainer.expectActions([ + { type: 'permit', asset: 'wstETH' }, + { type: 'deposit', asset: 'wstETH' }, + ]) + }) + + test('can switch to approves in action plan', async () => { + await myPortfolioPage.clickDepositButtonAction('wstETH') + await depositDialog.fillAmountAction(1) + + await depositDialog.actionsContainer.expectEnabledActionAtIndex(0) + await depositDialog.actionsContainer.expectActions([ + { type: 'permit', asset: 'wstETH' }, + { type: 'deposit', asset: 'wstETH' }, + ]) + + await depositDialog.actionsContainer.switchPreferPermitsAction() + + await depositDialog.actionsContainer.expectEnabledActionAtIndex(0) + await depositDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'wstETH' }, + { type: 'deposit', asset: 'wstETH' }, + ]) + }) + + test('has correct action plan for erc-20 with no permit support', async () => { + await myPortfolioPage.clickDepositButtonAction('rETH') + + await depositDialog.fillAmountAction(1) + await depositDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'rETH' }, + { type: 'deposit', asset: 'rETH' }, + ]) + }) + + test('can deposit erc-20 using permits', async () => { + const deposit: TestTokenWithValue = { + asset: 'wstETH', + amount: '1.00', + usdValue: '$4,665.46', + } + + await myPortfolioPage.clickDepositButtonAction(deposit.asset) + await depositDialog.fillAmountAction(Number(deposit.amount)) + await depositDialog.actionsContainer.acceptAllActionsAction(2) + await depositDialog.expectSuccessPage({ tokenWithValue: [deposit] }) + + await depositDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectDepositTable({ + ...initialDeposits, + wstETH: initialDeposits.wstETH + 1, + }) + }) + + test('can deposit erc-20 using approves', async () => { + const deposit: TestTokenWithValue = { + asset: 'rETH', + amount: '1.00', + usdValue: '$4,413.26', + } + + await myPortfolioPage.clickDepositButtonAction(deposit.asset) + await depositDialog.fillAmountAction(Number(deposit.amount)) + await depositDialog.actionsContainer.acceptAllActionsAction(2) + await depositDialog.expectSuccessPage({ tokenWithValue: [deposit] }) + + await depositDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectDepositTable({ + ...initialDeposits, + rETH: initialDeposits.rETH + 1, + }) + }) + + test('has correct action plan for native asset', async () => { + await myPortfolioPage.clickDepositButtonAction('WETH') + await depositDialog.selectAssetAction('ETH') + await depositDialog.fillAmountAction(1) + await depositDialog.expectHealthFactorVisible() + await depositDialog.actionsContainer.expectActions([{ type: 'deposit', asset: 'ETH' }]) + }) + + test('can deposit native asset', async () => { + const deposit: TestTokenWithValue = { + asset: 'WETH', + amount: '1.00', + usdValue: '$3,928.31', + } + + await myPortfolioPage.clickDepositButtonAction(deposit.asset) + + await depositDialog.selectAssetAction('ETH') + await depositDialog.fillAmountAction(Number(deposit.amount)) + await depositDialog.actionsContainer.acceptAllActionsAction(1) + await depositDialog.expectSuccessPage({ + tokenWithValue: [ + { + asset: 'ETH', + amount: deposit.amount, + usdValue: deposit.usdValue, + }, + ], + }) + + await depositDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectDepositTable({ + ...initialDeposits, + // @todo Figure out how WETH and ETH conversion should work + WETH: 1, + }) + }) + + test("can't deposit more than wallet balance", async () => { + const depositAsset = 'rETH' + await myPortfolioPage.clickDepositButtonAction(depositAsset) + + await depositDialog.fillAmountAction(initialBalances[depositAsset] - initialDeposits[depositAsset] + 1) + + await depositDialog.expectAssetInputError('Exceeds your balance') + await depositDialog.expectHealthFactorBeforeVisible() + }) + + test('requires new approve when the input value is increased', async () => { + const depositAsset = 'rETH' + await myPortfolioPage.clickDepositButtonAction(depositAsset) + await depositDialog.fillAmountAction(1) + + await depositDialog.actionsContainer.acceptActionAtIndex(0) + await depositDialog.actionsContainer.expectEnabledActionAtIndex(1, { type: 'deposit', asset: depositAsset }) + + await depositDialog.fillAmountAction(2) + + await depositDialog.actionsContainer.expectEnabledActionAtIndex(0, { type: 'approve', asset: depositAsset }) + }) + + test('requires new permit when the input value is changed', async () => { + const depositAsset = 'wstETH' + await myPortfolioPage.clickDepositButtonAction(depositAsset) + + await depositDialog.fillAmountAction(2) + + await depositDialog.actionsContainer.acceptActionAtIndex(0) + await depositDialog.actionsContainer.expectEnabledActionAtIndex(1, { type: 'deposit', asset: depositAsset }) + + await depositDialog.fillAmountAction(1) + + await depositDialog.actionsContainer.expectEnabledActionAtIndex(0, { type: 'permit', asset: depositAsset }) + }) + }) + + test.describe('Position with only deposit', () => { + const initialDeposits = { + wstETH: 10, + rETH: 2, + } + + let myPortfolioPage: MyPortfolioPageObject + let depositDialog: DialogPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ...initialBalances }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + // to simulate a position with only deposits, we go through the easy borrow flow + // but interrupt it before the borrow action, going directly to the myPortfolio + // this way we have deposit transactions executed, but no borrow transaction + // resulting in a position with only deposits + await borrowPage.fillDepositAssetAction(0, 'wstETH', initialDeposits.wstETH) + await borrowPage.addNewDepositAssetAction() + await borrowPage.fillBorrowAssetAction(1) // doesn't matter, we're not borrowing anything + await borrowPage.fillDepositAssetAction(1, 'rETH', initialDeposits.rETH) + await borrowPage.submitAction() + + for (let i = 0; i < 4; i++) { + await borrowPage.actionsContainer.acceptActionAtIndex(i) + } + await borrowPage.actionsContainer.expectEnabledActionAtIndex(4) + + myPortfolioPage = new MyPortfolioPageObject(testContext) + await myPortfolioPage.goToMyPortfolioAction() + + depositDialog = new DialogPageObject({ + testContext, + header: headerRegExp, + }) + }) + + test('does not display health factor', async () => { + await myPortfolioPage.clickDepositButtonAction('rETH') + await depositDialog.fillAmountAction(1) + + await depositDialog.expectHealthFactorNotVisible() + }) + }) + + test.describe('No position', () => { + test('can deposit up to max cap', async ({ page }) => { + const initialBalances = { + ETH: 1, + cbBTC: 52, + } + + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'myPortfolio', + account: { + type: 'connected-random', + assetBalances: { ...initialBalances }, + }, + }) + + const myPortfolioPage = new MyPortfolioPageObject(testContext) + await myPortfolioPage.clickDepositButtonAction('cbBTC') + + const depositDialog = new DialogPageObject({ + testContext, + header: headerRegExp, + }) + await depositDialog.clickMaxAmountAction() + await testContext.testnetController.progressSimulationAndMine(5 * 60) + + await depositDialog.actionsContainer.acceptAllActionsAction(2) + await depositDialog.expectSuccessPage({ + tokenWithValue: [ + { + asset: 'cbBTC', + amount: '50.0464443', + usdValue: '$5,088,872.59', + }, + ], + }) + + await depositDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectDepositTable({ + cbBTC: 50.0464443, + }) + }) + + test('can deposit asset that cannot be used as collateral', async ({ page }) => { + const initialBalances = { + ETH: 1, + USDT: 10000, + } + + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'myPortfolio', + account: { + type: 'connected-random', + assetBalances: { ...initialBalances }, + }, + }) + + const myPortfolioPage = new MyPortfolioPageObject(testContext) + await myPortfolioPage.clickDepositButtonAction('USDT') + + const depositDialog = new DialogPageObject({ + testContext, + header: headerRegExp, + }) + await depositDialog.fillAmountAction(initialBalances.USDT) + + await depositDialog.actionsContainer.acceptAllActionsAction(2) + await depositDialog.expectSuccessPage({ + tokenWithValue: [ + { + asset: 'USDT', + amount: '10,000.00', + usdValue: '$10,000.00', + }, + ], + }) + + await depositDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectDepositTable({ + USDT: initialBalances.USDT, + }) + }) + + test('retains some native asset when depositing max', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'myPortfolio', + account: { + type: 'connected-random', + assetBalances: { ETH: 1 }, + }, + }) + + const myPortfolioPage = new MyPortfolioPageObject(testContext) + await myPortfolioPage.clickDepositButtonAction('WETH') + const depositDialog = new DialogPageObject({ + testContext, + header: headerRegExp, + }) + await depositDialog.selectAssetAction('ETH') + await depositDialog.clickMaxAmountAction() + + await depositDialog.expectInputValue('0.999') + await depositDialog.expectMaxButtonDisabled() + await depositDialog.actionsContainer.expectEnabledActionAtIndex(0) + await depositDialog.actionsContainer.expectActions([{ type: 'deposit', asset: 'ETH' }]) + }) + }) +}) diff --git a/packages/app/src/ui/assets/index.ts b/packages/app/src/ui/assets/index.ts index 4efe2854e..914cbd15b 100644 --- a/packages/app/src/ui/assets/index.ts +++ b/packages/app/src/ui/assets/index.ts @@ -267,4 +267,5 @@ const tokenColors: Record = { [TokenSymbol('WXDAI')]: '253 177 31', [TokenSymbol('XDAI')]: '255 192 70', [TokenSymbol('CLE')]: '47 208 91', + [TokenSymbol('cbBTC')]: '0 82 255', } From 4b26e8eb76a8320ff92225258ac2c85b9ce40162 Mon Sep 17 00:00:00 2001 From: Oskar <43062492+oskarvu@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:48:56 +0700 Subject: [PATCH 16/29] Update topbar tests (#504) * Update topbar tests * Use default block to check rewards --- .../src/features/topbar/Topbar.test-e2e.ts | 335 +++++++++--------- 1 file changed, 171 insertions(+), 164 deletions(-) diff --git a/packages/app/src/features/topbar/Topbar.test-e2e.ts b/packages/app/src/features/topbar/Topbar.test-e2e.ts index 2b5666f85..5850fced9 100644 --- a/packages/app/src/features/topbar/Topbar.test-e2e.ts +++ b/packages/app/src/features/topbar/Topbar.test-e2e.ts @@ -1,164 +1,171 @@ -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' - -// import { overrideAirdropInfoRoute } from '@/test/e2e/airdropInfo' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' - -// import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' -// import { TopbarPageObject } from './Topbar.PageObject' - -// test.describe('Topbar', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) - -// test.describe('Airdrop counter', () => { -// test('Disconnected', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'not-connected', -// }, -// }) - -// const topbar = new TopbarPageObject(page) -// await topbar.expectAirdropCompactValue('0') -// await topbar.openAirdropDropdown() -// await topbar.expectAirdropPreciseValue('0.00 SPK') -// }) - -// test('Connected', async ({ page }) => { -// const { account } = await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// }, -// }) - -// await overrideAirdropInfoRoute(page, { account }) - -// const topbar = new TopbarPageObject(page) -// await topbar.expectAirdropCompactValue('7.841M') -// await topbar.openAirdropDropdown() -// await topbar.expectAirdropPreciseValue('7,840,591') -// }) - -// test('Api error', async ({ page }) => { -// const { account } = await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// }, -// }) - -// await overrideAirdropInfoRoute(page, { account, shouldFail: true }) - -// const topbar = new TopbarPageObject(page) -// await topbar.expectAirdropBadgeNotVisible() -// }) - -// test('Wallet with no airdrop', async ({ page }) => { -// const { account } = await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// }, -// }) - -// await overrideAirdropInfoRoute(page, { account, noAirdrop: true }) - -// const topbar = new TopbarPageObject(page) -// await topbar.expectAirdropCompactValue('0') -// await topbar.openAirdropDropdown() -// await topbar.expectAirdropPreciseValue('0.00 SPK') -// }) -// }) - -// test.describe('Rewards badge', () => { -// const fork = setupFork({ -// blockNumber: 20189272n, // block number where the reward program is finished -// chainId: mainnet.id, -// }) - -// test('Displays total rewards in badge', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-address', -// address: '0xf8de75c7b95edb6f1e639751318f117663021cf0', -// }, -// }) - -// const topbar = new TopbarPageObject(page) -// await topbar.expectClaimableRewardsValue('$25.58K') -// }) - -// test('Displays details in dropdown', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-address', -// address: '0xf8de75c7b95edb6f1e639751318f117663021cf0', -// }, -// }) - -// const topbar = new TopbarPageObject(page) -// await topbar.openRewardsDropdown() - -// await topbar.expectRewards([ -// { -// tokenSymbol: 'wstETH', -// amount: '6.3697', -// amountUSD: '$25,583.20', -// }, -// ]) -// }) - -// test('Does not display badge when no rewards', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'myPortfolio', -// account: { -// type: 'connected-random', -// }, -// }) - -// const topbar = new TopbarPageObject(page) -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// await myPortfolioPage.expectPositionToBeEmpty() // waiting for reserves to load -// await topbar.expectRewardsBadgeNotVisible() // asserting that after reserves are loaded, rewards badge is not visible -// }) -// }) - -// test.describe('Malformed localStorage', () => { -// test('Sandbox info in wagmi.store but not in zustand-app-store', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'not-connected', -// }, -// skipInjectingNetwork: true, -// }) -// await page.evaluate(() => { -// localStorage.setItem('wagmi.recentConnectorId', 'mock') -// localStorage.setItem('wagmi.io.metamask.disconnected', 'true') -// localStorage.setItem('wagmi.io.rabby.disconnected', 'true') -// localStorage.setItem('zustand-app-store', JSON.stringify({ state: {}, sandbox: {} })) -// localStorage.setItem('actionSettings', JSON.stringify({ preferPermits: true, exchangeMaxSlippage: '0.001' })) -// localStorage.setItem('compliance', JSON.stringify({ agreedToSAdresses: [] })) -// localStorage.setItem( -// 'wagmi.store', -// JSON.stringify({ -// state: { connections: { _type: 'Map', value: [] }, chainId: '30301713953503', current: null }, -// version: 2, -// }), -// ) -// }) - -// await page.reload() - -// const topbar = new TopbarPageObject(page) -// await topbar.expectSavingsLinkVisible() -// }) -// }) -// }) +import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' +import { overrideAirdropInfoRoute } from '@/test/e2e/airdropInfo' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { TopbarPageObject } from './Topbar.PageObject' + +test.describe('Topbar', () => { + test.describe('Airdrop counter', () => { + test('Disconnected', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'easyBorrow', + account: { + type: 'not-connected', + }, + }) + + const topbar = new TopbarPageObject(testContext) + await topbar.expectAirdropCompactValue('0') + await topbar.openAirdropDropdown() + await topbar.expectAirdropPreciseValue('0.00 SPK') + }) + + test('Connected', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + }, + }) + + await overrideAirdropInfoRoute(page, { account: testContext.account }) + + const topbar = new TopbarPageObject(testContext) + await topbar.expectAirdropCompactValue('8.227M') + await topbar.openAirdropDropdown() + await topbar.expectAirdropPreciseValue('8,227,011.154') + }) + + test('Api error', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + }, + }) + + await overrideAirdropInfoRoute(page, { account: testContext.account, shouldFail: true }) + + const topbar = new TopbarPageObject(testContext) + await topbar.expectAirdropBadgeNotVisible() + }) + + test('Wallet with no airdrop', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + }, + }) + + await overrideAirdropInfoRoute(page, { account: testContext.account, noAirdrop: true }) + + const topbar = new TopbarPageObject(testContext) + await topbar.expectAirdropCompactValue('0') + await topbar.openAirdropDropdown() + await topbar.expectAirdropPreciseValue('0.00 SPK') + }) + }) + + test.describe('Rewards badge', () => { + test('Displays total rewards in badge', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-address', + address: '0xf8de75c7b95edb6f1e639751318f117663021cf0', + }, + }) + + const topbar = new TopbarPageObject(testContext) + await topbar.expectClaimableRewardsValue('$29.72K') + }) + + test('Displays details in dropdown', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-address', + address: '0xf8de75c7b95edb6f1e639751318f117663021cf0', + }, + }) + + const topbar = new TopbarPageObject(testContext) + await topbar.openRewardsDropdown() + + await topbar.expectRewards([ + { + tokenSymbol: 'wstETH', + amount: '6.3697', + amountUSD: '$29,717.60', + }, + ]) + }) + + test('Does not display badge when no rewards', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'myPortfolio', + account: { + type: 'connected-random', + }, + }) + + const topbar = new TopbarPageObject(testContext) + const myPortfolioPage = new MyPortfolioPageObject(testContext) + + await myPortfolioPage.expectPositionToBeEmpty() // waiting for reserves to load + await topbar.expectRewardsBadgeNotVisible() // asserting that after reserves are loaded, rewards badge is not visible + }) + }) + + test.describe('Malformed localStorage', () => { + test('Sandbox info in wagmi.store but not in zustand-app-store', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'easyBorrow', + account: { + type: 'not-connected', + }, + skipInjectingNetwork: true, + }) + await page.evaluate(() => { + localStorage.setItem('wagmi.recentConnectorId', 'mock') + localStorage.setItem('wagmi.io.metamask.disconnected', 'true') + localStorage.setItem('wagmi.io.rabby.disconnected', 'true') + localStorage.setItem('zustand-app-store', JSON.stringify({ state: {}, sandbox: {} })) + localStorage.setItem('actionSettings', JSON.stringify({ preferPermits: true, exchangeMaxSlippage: '0.001' })) + localStorage.setItem('compliance', JSON.stringify({ agreedToSAdresses: [] })) + localStorage.setItem( + 'wagmi.store', + JSON.stringify({ + state: { connections: { _type: 'Map', value: [] }, chainId: '30301713953503', current: null }, + version: 2, + }), + ) + }) + + await page.reload() + + const topbar = new TopbarPageObject(testContext) + await topbar.expectSavingsLinkVisible() + }) + }) +}) From 5ef23d27c50c02904b11b2e79901b235eab34e9a Mon Sep 17 00:00:00 2001 From: Oskar <43062492+oskarvu@users.noreply.github.com> Date: Thu, 19 Dec 2024 17:19:49 +0700 Subject: [PATCH 17/29] Farm unstake tests (#506) * Update dai farm unstake * Set progressed timestamp in browser * Use progress and mine and reload * Add withdraw max dai tests * Add withdraw max usds tests * Add unstake usdc tests --- .../claim/e2e/mainnet/ClaimSKY.test-e2e.ts | 2 +- .../unstake/UnstakeDialog.PageObject.ts | 290 ++++++------ .../e2e/mainnet/UnstakeDAI.test-e2e.ts | 174 +++---- .../e2e/mainnet/UnstakeUSDC.test-e2e.ts | 174 +++---- .../e2e/mainnet/UnstakeUSDS.test-e2e.ts | 381 +++++++-------- .../e2e/mainnet/WithdrawMaxDai.test-e2e.ts | 322 +++++++------ .../e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts | 322 +++++++------ .../e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts | 437 +++++++++--------- 8 files changed, 1054 insertions(+), 1048 deletions(-) diff --git a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts index fdd9f0de6..bc8e65910 100644 --- a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts @@ -59,7 +59,7 @@ test.describe('Claim SKY rewards', () => { await claimDialog.expectTransactionOverview({ reward: { amount: '49.44', - amountUSD: '$2.98', + amountUSD: '2.98', }, }) }) diff --git a/packages/app/src/features/farm-details/dialogs/unstake/UnstakeDialog.PageObject.ts b/packages/app/src/features/farm-details/dialogs/unstake/UnstakeDialog.PageObject.ts index 3c701638f..cc6cf29f3 100644 --- a/packages/app/src/features/farm-details/dialogs/unstake/UnstakeDialog.PageObject.ts +++ b/packages/app/src/features/farm-details/dialogs/unstake/UnstakeDialog.PageObject.ts @@ -1,146 +1,144 @@ -// import { DialogPageObject } from '@/features/dialogs/common/Dialog.PageObject' -// import { testIds } from '@/ui/utils/testIds' -// import { Page, expect } from '@playwright/test' - -// export class UnstakeDialogPageObject extends DialogPageObject { -// constructor(page: Page) { -// super(page, /Withdraw/) -// } - -// // #region actions -// async clickBackToFarmAction(): Promise { -// await this.page.getByRole('button', { name: 'Back to Farm' }).click() -// await this.region.waitFor({ -// state: 'detached', -// }) -// } - -// async clickExitFarmSwitchAction(): Promise { -// await this.page.getByTestId(testIds.farmDetails.unstakeDialog.exitFarmSwitchPanel.switch).click() -// } -// // - -// // #region assertions -// async expectExitFarmSwitchToBeHidden(): Promise { -// await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.exitFarmSwitchPanel.switch)).toBeHidden() -// } - -// async expectExitFarmSwitchToBeVisible(): Promise { -// await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.exitFarmSwitchPanel.switch)).toBeVisible() -// } - -// async expectExitFarmSwitchNotChecked(): Promise { -// await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.exitFarmSwitchPanel.switch)).not.toBeChecked() -// } - -// async expectExitFarmSwitchReward({ min, max, token, usdValue }: Reward): Promise { -// const regexp = /~([\d,\.]+) (\w+) \(~\$([\d,\.]+)\)/ -// const rewardRowText = await this.page -// .getByTestId(testIds.farmDetails.unstakeDialog.exitFarmSwitchPanel.reward) -// .textContent() - -// const match = rewardRowText?.match(regexp) -// expect(match).toBeDefined() - -// const [rewardAmount, rewardToken, rewardUsdValue] = match!.slice(1) -// const rewardNumber = Number(rewardAmount?.replace(/,/g, '')) -// expect(rewardNumber).toBeGreaterThanOrEqual(min) -// expect(rewardNumber).toBeLessThanOrEqual(max) -// expect(rewardToken).toBe(token) -// expect(rewardUsdValue).toContain(usdValue) -// } - -// async expectRoutesOverview(route: Route): Promise { -// const routeItemTestIds = testIds.dialog.transactionOverview.routeItem -// const txOverviewTestIds = testIds.farmDetails.unstakeDialog.transactionOverview - -// for (let i = 0; i < route.swaps.length; i++) { -// // i + 1 because the first item in route is farm itself -// await expect(this.page.getByTestId(routeItemTestIds.tokenWithAmount(i + 1))).toContainText( -// route.swaps[i]!.tokenAmount, -// ) -// await expect(this.page.getByTestId(routeItemTestIds.tokenUsdValue(i + 1))).toContainText( -// route.swaps[i]!.tokenUsdValue, -// ) -// } - -// await expect(this.page.getByTestId(txOverviewTestIds.route.farm.farmName)).toContainText(route.farm.upperText) -// await expect(this.page.getByTestId(txOverviewTestIds.route.farm.stakingToken)).toContainText(route.farm.lowerText) -// } - -// async expectTransactionOverview({ route, outcome }: TransactionOverview): Promise { -// await this.expectRoutesOverview(route) -// await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.outcome)).toContainText( -// outcome, -// ) -// } - -// async expectExitTransactionOverview({ route, reward, outcome }: ExitTransactionOverview): Promise { -// await this.expectRoutesOverview(route) - -// await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.outcome)).toContainText( -// outcome.amount, -// ) -// await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.outcome)).toContainText( -// outcome.token, -// ) -// await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.outcomeUsd)).toContainText( -// outcome.usdValue, -// ) - -// const rewardAmount = await this.page -// .getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.rewardOutcome) -// .textContent() -// const rewardNumber = Number(rewardAmount?.replace(/[^0-9.]/g, '')) - -// expect(rewardNumber).toBeGreaterThanOrEqual(reward.min) -// expect(rewardNumber).toBeLessThanOrEqual(reward.max) -// await expect( -// this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.rewardOutcome), -// ).toContainText(reward.token) -// await expect( -// this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.rewardOutcomeUsd), -// ).toContainText(reward.usdValue) -// } - -// async expectSuccessPage(): Promise { -// // for now we only check if the success message is visible -// await expect(this.page.getByText('Congrats, all done!')).toBeVisible() -// } -// // #endregion -// } - -// export interface Reward { -// min: number -// max: number -// token: string -// usdValue: string -// } - -// export interface Outome { -// amount: string -// token: string -// usdValue: string -// } - -// export interface Route { -// swaps: { -// tokenAmount: string -// tokenUsdValue: string -// }[] -// farm: { -// upperText: string -// lowerText: string -// } -// } - -// export interface TransactionOverview { -// route: Route -// outcome: string -// } - -// export interface ExitTransactionOverview { -// route: Route -// reward: Reward -// outcome: Outome -// } +import { DialogPageObject } from '@/features/dialogs/common/Dialog.PageObject' +import { TestContext } from '@/test/e2e/setup' +import { testIds } from '@/ui/utils/testIds' +import { expect } from '@playwright/test' + +export class UnstakeDialogPageObject extends DialogPageObject { + constructor(testContext: TestContext) { + super({ testContext, header: /Withdraw/ }) + } + + // #region actions + async clickBackToFarmAction(): Promise { + await this.page.getByRole('button', { name: 'Back to Farm' }).click() + await this.region.waitFor({ + state: 'detached', + }) + } + + async clickExitFarmSwitchAction(): Promise { + await this.page.getByTestId(testIds.farmDetails.unstakeDialog.exitFarmSwitchPanel.switch).click() + } + // + + // #region assertions + async expectExitFarmSwitchToBeHidden(): Promise { + await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.exitFarmSwitchPanel.switch)).toBeHidden() + } + + async expectExitFarmSwitchToBeVisible(): Promise { + await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.exitFarmSwitchPanel.switch)).toBeVisible() + } + + async expectExitFarmSwitchNotChecked(): Promise { + await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.exitFarmSwitchPanel.switch)).not.toBeChecked() + } + + async expectExitFarmSwitchReward({ amount, token, usdValue }: Reward): Promise { + const regexp = /~([\d,\.]+) (\w+) \(~\$([\d,\.]+)\)/ + const rewardRowText = await this.page + .getByTestId(testIds.farmDetails.unstakeDialog.exitFarmSwitchPanel.reward) + .textContent() + + const match = rewardRowText?.match(regexp) + expect(match).toBeDefined() + + const [rewardAmount, rewardToken, rewardUsdValue] = match!.slice(1) + const rewardNumber = Number(rewardAmount?.replace(/,/g, '')) + expect(rewardNumber).toBe(amount) + expect(rewardToken).toBe(token) + expect(rewardUsdValue).toContain(usdValue) + } + + async expectRoutesOverview(route: Route): Promise { + const routeItemTestIds = testIds.dialog.transactionOverview.routeItem + const txOverviewTestIds = testIds.farmDetails.unstakeDialog.transactionOverview + + for (let i = 0; i < route.swaps.length; i++) { + // i + 1 because the first item in route is farm itself + await expect(this.page.getByTestId(routeItemTestIds.tokenWithAmount(i + 1))).toContainText( + route.swaps[i]!.tokenAmount, + ) + await expect(this.page.getByTestId(routeItemTestIds.tokenUsdValue(i + 1))).toContainText( + route.swaps[i]!.tokenUsdValue, + ) + } + + await expect(this.page.getByTestId(txOverviewTestIds.route.farm.farmName)).toContainText(route.farm.upperText) + await expect(this.page.getByTestId(txOverviewTestIds.route.farm.stakingToken)).toContainText(route.farm.lowerText) + } + + async expectTransactionOverview({ route, outcome }: TransactionOverview): Promise { + await this.expectRoutesOverview(route) + await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.outcome)).toContainText( + outcome, + ) + } + + async expectExitTransactionOverview({ route, reward, outcome }: ExitTransactionOverview): Promise { + await this.expectRoutesOverview(route) + + await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.outcome)).toContainText( + outcome.amount, + ) + await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.outcome)).toContainText( + outcome.token, + ) + await expect(this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.outcomeUsd)).toContainText( + outcome.usdValue, + ) + + const rewardAmount = await this.page + .getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.rewardOutcome) + .textContent() + const rewardNumber = Number(rewardAmount?.replace(/[^0-9.]/g, '')) + expect(rewardNumber).toBe(reward.amount) + + await expect( + this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.rewardOutcome), + ).toContainText(reward.token) + await expect( + this.page.getByTestId(testIds.farmDetails.unstakeDialog.transactionOverview.rewardOutcomeUsd), + ).toContainText(reward.usdValue) + } + + async expectSuccessPage(): Promise { + // for now we only check if the success message is visible + await expect(this.page.getByText('Congrats, all done!')).toBeVisible() + } + // #endregion +} + +export interface Reward { + amount: number + token: string + usdValue: string +} + +export interface Outome { + amount: string + token: string + usdValue: string +} + +export interface Route { + swaps: { + tokenAmount: string + tokenUsdValue: string + }[] + farm: { + upperText: string + lowerText: string + } +} + +export interface TransactionOverview { + route: Route + outcome: string +} + +export interface ExitTransactionOverview { + route: Route + reward: Reward + outcome: Outome +} diff --git a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeDAI.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeDAI.test-e2e.ts index 3973db2a1..cca32d77e 100644 --- a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeDAI.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeDAI.test-e2e.ts @@ -1,99 +1,101 @@ -// import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' -// import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' +import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' +import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' -// test.describe('Unstake DAI from SKY farm', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let farmDetailsPage: FarmDetailsPageObject -// let unstakeDialog: UnstakeDialogPageObject -// let stakeDialog: StakeDialogPageObject +test.describe('Unstake DAI from SKY farm', () => { + let farmDetailsPage: FarmDetailsPageObject + let unstakeDialog: UnstakeDialogPageObject + let stakeDialog: StakeDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'farmDetails', -// initialPageParams: { -// chainId: mainnet.id.toString(), -// address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', -// }, -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// DAI: 10_000, -// USDS: 10_000, -// }, -// }, -// }) -// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'farmDetails', + initialPageParams: { + chainId: mainnet.id.toString(), + address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', + }, + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + DAI: 10_000, + USDS: 10_000, + }, + }, + }) + await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) -// farmDetailsPage = new FarmDetailsPageObject(page) -// await farmDetailsPage.clickInfoPanelStakeButtonAction() -// stakeDialog = new StakeDialogPageObject(page) + farmDetailsPage = new FarmDetailsPageObject(testContext) + await farmDetailsPage.clickInfoPanelStakeButtonAction() + stakeDialog = new StakeDialogPageObject(testContext) -// await stakeDialog.selectAssetAction('USDS') -// await stakeDialog.fillAmountAction(10_000) -// await stakeDialog.actionsContainer.acceptAllActionsAction(2) + await stakeDialog.selectAssetAction('USDS') + await stakeDialog.fillAmountAction(10_000) + await stakeDialog.actionsContainer.acceptAllActionsAction(2) -// await stakeDialog.clickBackToFarmAction() + await stakeDialog.clickBackToFarmAction() -// await fork.progressSimulation(page, 24 * 60 * 60) // 24 hours -// await page.reload() + await testContext.testnetController.progressSimulationAndMine(24 * 60 * 60) // 24 hours + await page.reload() -// await farmDetailsPage.clickInfoPanelUnstakeButtonAction() -// unstakeDialog = new UnstakeDialogPageObject(page) + await farmDetailsPage.clickInfoPanelUnstakeButtonAction() + unstakeDialog = new UnstakeDialogPageObject(testContext) -// await unstakeDialog.selectAssetAction('DAI') -// await unstakeDialog.fillAmountAction(5_000) -// }) + await unstakeDialog.selectAssetAction('DAI') + await unstakeDialog.fillAmountAction(5_000) + }) -// test('has correct action plan', async () => { -// await unstakeDialog.actionsContainer.expectActions([ -// { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, -// { type: 'approve', asset: 'USDS' }, -// { type: 'downgrade', fromToken: 'USDS', toToken: 'DAI' }, -// ]) -// }) + test('has correct action plan', async () => { + await unstakeDialog.actionsContainer.expectActions([ + { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, + { type: 'approve', asset: 'USDS' }, + { type: 'downgrade', fromToken: 'USDS', toToken: 'DAI' }, + ]) + }) -// test('displays transaction overview', async () => { -// await unstakeDialog.expectTransactionOverview({ -// route: { -// swaps: [ -// { -// tokenAmount: '5,000.00 USDS', -// tokenUsdValue: '$5,000.00', -// }, -// { -// tokenAmount: '5,000.00 DAI', -// tokenUsdValue: '$5,000.00', -// }, -// ], -// farm: { -// upperText: 'SKY Farm', -// lowerText: 'Deposited', -// }, -// }, -// outcome: '5,000.00 DAI', -// }) -// }) + test('displays transaction overview', async () => { + await unstakeDialog.expectTransactionOverview({ + route: { + swaps: [ + { + tokenAmount: '5,000.00 USDS', + tokenUsdValue: '$5,000.00', + }, + { + tokenAmount: '5,000.00 DAI', + tokenUsdValue: '$5,000.00', + }, + ], + farm: { + upperText: 'SKY Farm', + lowerText: 'Deposited', + }, + }, + outcome: '5,000.00 DAI', + }) + }) -// test('executes transaction', async () => { -// await unstakeDialog.actionsContainer.acceptAllActionsAction(3) + test('executes transaction', async () => { + await unstakeDialog.actionsContainer.acceptAllActionsAction(3) -// await unstakeDialog.expectSuccessPage() -// await unstakeDialog.clickBackToFarmAction() + await unstakeDialog.expectSuccessPage() + await unstakeDialog.clickBackToFarmAction() -// await farmDetailsPage.expectTokenToDepositBalance('DAI', '15,000.00') -// await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') -// await farmDetailsPage.expectReward({ -// reward: '3,539', -// rewardUsd: '$213', -// }) -// await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) -// }) -// }) + await farmDetailsPage.expectTokenToDepositBalance('DAI', '15,000.00') + await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') + await farmDetailsPage.expectReward({ + reward: '49.441', + rewardUsd: '2.98', + }) + await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) + }) +}) diff --git a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDC.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDC.test-e2e.ts index eaa8366d9..e5788c604 100644 --- a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDC.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDC.test-e2e.ts @@ -1,99 +1,101 @@ -// import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' -// import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' +import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' +import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' -// test.describe('Unstake USDC from SKY farm', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let farmDetailsPage: FarmDetailsPageObject -// let unstakeDialog: UnstakeDialogPageObject -// let stakeDialog: StakeDialogPageObject +test.describe('Unstake USDC from SKY farm', () => { + let farmDetailsPage: FarmDetailsPageObject + let unstakeDialog: UnstakeDialogPageObject + let stakeDialog: StakeDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'farmDetails', -// initialPageParams: { -// chainId: mainnet.id.toString(), -// address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', -// }, -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// USDC: 10_000, -// USDS: 10_000, -// }, -// }, -// }) -// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'farmDetails', + initialPageParams: { + chainId: mainnet.id.toString(), + address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', + }, + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDC: 10_000, + USDS: 10_000, + }, + }, + }) + await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) -// farmDetailsPage = new FarmDetailsPageObject(page) -// await farmDetailsPage.clickInfoPanelStakeButtonAction() -// stakeDialog = new StakeDialogPageObject(page) + farmDetailsPage = new FarmDetailsPageObject(testContext) + await farmDetailsPage.clickInfoPanelStakeButtonAction() + stakeDialog = new StakeDialogPageObject(testContext) -// await stakeDialog.selectAssetAction('USDS') -// await stakeDialog.fillAmountAction(10_000) -// await stakeDialog.actionsContainer.acceptAllActionsAction(2) + await stakeDialog.selectAssetAction('USDS') + await stakeDialog.fillAmountAction(10_000) + await stakeDialog.actionsContainer.acceptAllActionsAction(2) -// await stakeDialog.clickBackToFarmAction() + await stakeDialog.clickBackToFarmAction() -// await fork.progressSimulation(page, 24 * 60 * 60) // 24 hours -// await page.reload() + await testContext.testnetController.progressSimulationAndMine(24 * 60 * 60) // 24 hours + await page.reload() -// await farmDetailsPage.clickInfoPanelUnstakeButtonAction() -// unstakeDialog = new UnstakeDialogPageObject(page) + await farmDetailsPage.clickInfoPanelUnstakeButtonAction() + unstakeDialog = new UnstakeDialogPageObject(testContext) -// await unstakeDialog.selectAssetAction('USDC') -// await unstakeDialog.fillAmountAction(5_000) -// }) + await unstakeDialog.selectAssetAction('USDC') + await unstakeDialog.fillAmountAction(5_000) + }) -// test('has correct action plan', async () => { -// await unstakeDialog.actionsContainer.expectActions([ -// { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, -// { type: 'approve', asset: 'USDS' }, -// { type: 'psmConvert', inToken: 'USDS', outToken: 'USDC' }, -// ]) -// }) + test('has correct action plan', async () => { + await unstakeDialog.actionsContainer.expectActions([ + { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, + { type: 'approve', asset: 'USDS' }, + { type: 'psmConvert', inToken: 'USDS', outToken: 'USDC' }, + ]) + }) -// test('displays transaction overview', async () => { -// await unstakeDialog.expectTransactionOverview({ -// route: { -// swaps: [ -// { -// tokenAmount: '5,000.00 USDS', -// tokenUsdValue: '$5,000.00', -// }, -// { -// tokenAmount: '5,000.00 USDC', -// tokenUsdValue: '$5,000.00', -// }, -// ], -// farm: { -// upperText: 'SKY Farm', -// lowerText: 'Deposited', -// }, -// }, -// outcome: '5,000.00 USDC', -// }) -// }) + test('displays transaction overview', async () => { + await unstakeDialog.expectTransactionOverview({ + route: { + swaps: [ + { + tokenAmount: '5,000.00 USDS', + tokenUsdValue: '$5,000.00', + }, + { + tokenAmount: '5,000.00 USDC', + tokenUsdValue: '$5,000.00', + }, + ], + farm: { + upperText: 'SKY Farm', + lowerText: 'Deposited', + }, + }, + outcome: '5,000.00 USDC', + }) + }) -// test('executes transaction', async () => { -// await unstakeDialog.actionsContainer.acceptAllActionsAction(3) + test('executes transaction', async () => { + await unstakeDialog.actionsContainer.acceptAllActionsAction(3) -// await unstakeDialog.expectSuccessPage() -// await unstakeDialog.clickBackToFarmAction() + await unstakeDialog.expectSuccessPage() + await unstakeDialog.clickBackToFarmAction() -// await farmDetailsPage.expectTokenToDepositBalance('USDC', '15,000.00') -// await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') -// await farmDetailsPage.expectReward({ -// reward: '3,539', -// rewardUsd: '$213', -// }) -// await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) -// }) -// }) + await farmDetailsPage.expectTokenToDepositBalance('USDC', '15,000.00') + await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') + await farmDetailsPage.expectReward({ + reward: '49.441', + rewardUsd: '2.98', + }) + await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) + }) +}) diff --git a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDS.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDS.test-e2e.ts index 8dcd2e47f..f8c831a76 100644 --- a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDS.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDS.test-e2e.ts @@ -1,188 +1,193 @@ -// import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { privateKeyToAddress } from 'viem/accounts' -// import { mainnet } from 'viem/chains' -// import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' -// import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' - -// test.describe('Unstake USDS from SKY farm', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let farmDetailsPage: FarmDetailsPageObject -// let unstakeDialog: UnstakeDialogPageObject -// let stakeDialog: StakeDialogPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'farmDetails', -// initialPageParams: { -// chainId: mainnet.id.toString(), -// address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', -// }, -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// DAI: 10_000, -// USDS: 10_000, -// }, -// }, -// }) -// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) - -// farmDetailsPage = new FarmDetailsPageObject(page) -// await farmDetailsPage.clickInfoPanelStakeButtonAction() -// stakeDialog = new StakeDialogPageObject(page) - -// await stakeDialog.selectAssetAction('DAI') -// await stakeDialog.fillAmountAction(10_000) -// await stakeDialog.actionsContainer.acceptAllActionsAction(4) - -// await stakeDialog.clickBackToFarmAction() - -// await fork.progressSimulation(page, 24 * 60 * 60) // 24 hours -// await page.reload() - -// await farmDetailsPage.clickInfoPanelUnstakeButtonAction() -// unstakeDialog = new UnstakeDialogPageObject(page) - -// await unstakeDialog.selectAssetAction('USDS') -// await unstakeDialog.fillAmountAction(5_000) -// }) - -// test('has exit farm switch hidden', async () => { -// await unstakeDialog.expectExitFarmSwitchToBeHidden() -// }) - -// test('has correct action plan', async () => { -// await unstakeDialog.actionsContainer.expectActions([ -// { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, -// ]) -// }) - -// test('displays transaction overview', async () => { -// await unstakeDialog.expectTransactionOverview({ -// route: { -// swaps: [ -// { -// tokenAmount: '5,000.00 USDS', -// tokenUsdValue: '$5,000.00', -// }, -// ], -// farm: { -// upperText: 'SKY Farm', -// lowerText: 'Deposited', -// }, -// }, -// outcome: '5,000.00 USDS', -// }) -// }) - -// test('executes transaction', async () => { -// await unstakeDialog.actionsContainer.acceptAllActionsAction(1) - -// await unstakeDialog.expectSuccessPage() -// await unstakeDialog.clickBackToFarmAction() - -// await farmDetailsPage.expectTokenToDepositBalance('USDS', '15,000.00') -// await farmDetailsPage.expectTokenToDepositBalance('DAI', '-') -// await farmDetailsPage.expectReward({ -// reward: '3,539', -// rewardUsd: '$213', -// }) -// await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) -// }) -// }) - -// test.describe('Unstake USDS from CLE farm', () => { -// const testUserPKey = '0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5' -// const testUserAddress = privateKeyToAddress('0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5') -// const harSuffix = testUserAddress.slice(0, 10) - -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let farmDetailsPage: FarmDetailsPageObject -// let unstakeDialog: UnstakeDialogPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'farmDetails', -// initialPageParams: { -// chainId: mainnet.id.toString(), -// address: '0x10ab606B067C9C461d8893c47C7512472E19e2Ce', -// }, -// account: { -// type: 'connected-pkey', -// privateKey: testUserPKey, -// assetBalances: { -// ETH: 1, -// USDS: 10_000, -// }, -// }, -// }) -// await overrideInfoSkyRouteWithHAR({ page, key: `2-cle-farm-0-balance-${harSuffix}` }) - -// farmDetailsPage = new FarmDetailsPageObject(page) -// await farmDetailsPage.clickInfoPanelStakeButtonAction() -// const stakeDialog = new StakeDialogPageObject(page) -// await stakeDialog.fillAmountAction(10_000) -// await stakeDialog.actionsContainer.acceptAllActionsAction(2) -// await stakeDialog.clickBackToFarmAction() - -// await overrideInfoSkyRouteWithHAR({ page, key: `3-cle-farm-10000-balance-${harSuffix}` }) -// await farmDetailsPage.clickInfoPanelUnstakeButtonAction() -// unstakeDialog = new UnstakeDialogPageObject(page) - -// await unstakeDialog.selectAssetAction('USDS') -// await unstakeDialog.fillAmountAction(5_000) -// }) - -// test('has correct action plan', async () => { -// await unstakeDialog.actionsContainer.expectActions([ -// { type: 'unstake', stakingToken: 'USDS', rewardToken: 'CLE', exit: false }, -// ]) -// }) - -// test('displays transaction overview', async () => { -// await unstakeDialog.expectTransactionOverview({ -// route: { -// swaps: [ -// { -// tokenAmount: '5,000.00 USDS', -// tokenUsdValue: '$5,000.00', -// }, -// ], -// farm: { -// upperText: 'CLE Farm', -// lowerText: 'Deposited', -// }, -// }, -// outcome: '5,000.00 USDS', -// }) -// }) - -// test('executes transaction', async ({ page }) => { -// await unstakeDialog.actionsContainer.acceptAllActionsAction(1) - -// await unstakeDialog.expectSuccessPage() -// await unstakeDialog.clickBackToFarmAction() - -// await farmDetailsPage.expectTokenToDepositBalance('USDS', '5,000.00') -// await farmDetailsPage.expectReward({ -// reward: '257.6', -// }) -// await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) -// await farmDetailsPage.expectPointsSyncWarning() - -// await overrideInfoSkyRouteWithHAR({ page, key: `4-cle-farm-5000-balance-${harSuffix}` }) - -// await farmDetailsPage.expectReward({ -// reward: '257.6', -// }) -// await farmDetailsPage.expectPointsSyncWarningToBeHidden() -// await farmDetailsPage.expectInfoPanelClaimButtonToBeHidden() -// await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) -// }) -// }) +import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { privateKeyToAddress } from 'viem/accounts' +import { mainnet } from 'viem/chains' +import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' +import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' + +test.describe('Unstake USDS from SKY farm', () => { + let farmDetailsPage: FarmDetailsPageObject + let unstakeDialog: UnstakeDialogPageObject + let stakeDialog: StakeDialogPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'farmDetails', + initialPageParams: { + chainId: mainnet.id.toString(), + address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', + }, + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + DAI: 10_000, + USDS: 10_000, + }, + }, + }) + await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) + + farmDetailsPage = new FarmDetailsPageObject(testContext) + await farmDetailsPage.clickInfoPanelStakeButtonAction() + stakeDialog = new StakeDialogPageObject(testContext) + + await stakeDialog.selectAssetAction('DAI') + await stakeDialog.fillAmountAction(10_000) + await stakeDialog.actionsContainer.acceptAllActionsAction(4) + + await stakeDialog.clickBackToFarmAction() + + await testContext.testnetController.progressSimulationAndMine(24 * 60 * 60) // 24 hours + await page.reload() + + await farmDetailsPage.clickInfoPanelUnstakeButtonAction() + unstakeDialog = new UnstakeDialogPageObject(testContext) + + await unstakeDialog.selectAssetAction('USDS') + await unstakeDialog.fillAmountAction(5_000) + }) + + test('has exit farm switch hidden', async () => { + await unstakeDialog.expectExitFarmSwitchToBeHidden() + }) + + test('has correct action plan', async () => { + await unstakeDialog.actionsContainer.expectActions([ + { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, + ]) + }) + + test('displays transaction overview', async () => { + await unstakeDialog.expectTransactionOverview({ + route: { + swaps: [ + { + tokenAmount: '5,000.00 USDS', + tokenUsdValue: '$5,000.00', + }, + ], + farm: { + upperText: 'SKY Farm', + lowerText: 'Deposited', + }, + }, + outcome: '5,000.00 USDS', + }) + }) + + test('executes transaction', async () => { + await unstakeDialog.actionsContainer.acceptAllActionsAction(1) + + await unstakeDialog.expectSuccessPage() + await unstakeDialog.clickBackToFarmAction() + + await farmDetailsPage.expectTokenToDepositBalance('USDS', '15,000.00') + await farmDetailsPage.expectTokenToDepositBalance('DAI', '-') + await farmDetailsPage.expectReward({ + reward: '49.438', + rewardUsd: '2.98', + }) + await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) + }) +}) + +test.describe('Unstake USDS from CLE farm', () => { + const testUserPKey = '0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5' + const testUserAddress = privateKeyToAddress('0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5') + const harSuffix = testUserAddress.slice(0, 10) + + let farmDetailsPage: FarmDetailsPageObject + let unstakeDialog: UnstakeDialogPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'farmDetails', + initialPageParams: { + chainId: mainnet.id.toString(), + address: '0x10ab606B067C9C461d8893c47C7512472E19e2Ce', + }, + account: { + type: 'connected-pkey', + privateKey: testUserPKey, + assetBalances: { + ETH: 1, + USDS: 10_000, + }, + }, + }) + await overrideInfoSkyRouteWithHAR({ page, key: `2-cle-farm-0-balance-${harSuffix}` }) + + farmDetailsPage = new FarmDetailsPageObject(testContext) + await farmDetailsPage.clickInfoPanelStakeButtonAction() + const stakeDialog = new StakeDialogPageObject(testContext) + await stakeDialog.fillAmountAction(10_000) + await stakeDialog.actionsContainer.acceptAllActionsAction(2) + await stakeDialog.clickBackToFarmAction() + + await overrideInfoSkyRouteWithHAR({ page, key: `3-cle-farm-10000-balance-${harSuffix}` }) + await farmDetailsPage.clickInfoPanelUnstakeButtonAction() + unstakeDialog = new UnstakeDialogPageObject(testContext) + + await unstakeDialog.selectAssetAction('USDS') + await unstakeDialog.fillAmountAction(5_000) + }) + + test('has correct action plan', async () => { + await unstakeDialog.actionsContainer.expectActions([ + { type: 'unstake', stakingToken: 'USDS', rewardToken: 'CLE', exit: false }, + ]) + }) + + test('displays transaction overview', async () => { + await unstakeDialog.expectTransactionOverview({ + route: { + swaps: [ + { + tokenAmount: '5,000.00 USDS', + tokenUsdValue: '$5,000.00', + }, + ], + farm: { + upperText: 'CLE Farm', + lowerText: 'Deposited', + }, + }, + outcome: '5,000.00 USDS', + }) + }) + + test('executes transaction', async ({ page }) => { + await unstakeDialog.actionsContainer.acceptAllActionsAction(1) + + await unstakeDialog.expectSuccessPage() + await unstakeDialog.clickBackToFarmAction() + + await farmDetailsPage.expectTokenToDepositBalance('USDS', '5,000.00') + await farmDetailsPage.expectReward({ + reward: '257.6', + }) + await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) + await farmDetailsPage.expectPointsSyncWarning() + + await overrideInfoSkyRouteWithHAR({ page, key: `4-cle-farm-5000-balance-${harSuffix}` }) + + await farmDetailsPage.expectReward({ + reward: '257.6', + }) + await farmDetailsPage.expectPointsSyncWarningToBeHidden() + await farmDetailsPage.expectInfoPanelClaimButtonToBeHidden() + await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) + }) +}) diff --git a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxDai.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxDai.test-e2e.ts index aec8adb76..d47cc7769 100644 --- a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxDai.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxDai.test-e2e.ts @@ -1,162 +1,160 @@ -// import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { Address } from 'viem' -// import { mainnet } from 'viem/chains' -// import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' -// import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' - -// test.describe('Withdraw max DAI from SKY farm', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let farmDetailsPage: FarmDetailsPageObject -// let unstakeDialog: UnstakeDialogPageObject -// let stakeDialog: StakeDialogPageObject -// let account: Address - -// test.beforeEach(async ({ page }) => { -// ;({ account } = await setup(page, fork, { -// initialPage: 'farmDetails', -// initialPageParams: { -// chainId: mainnet.id.toString(), -// address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', -// }, -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// USDS: 10_000, -// DAI: 10_000, -// USDC: 10_000, -// }, -// }, -// })) - -// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) - -// farmDetailsPage = new FarmDetailsPageObject(page) -// await farmDetailsPage.clickInfoPanelStakeButtonAction() -// stakeDialog = new StakeDialogPageObject(page) - -// await stakeDialog.selectAssetAction('USDS') -// await stakeDialog.fillAmountAction(10_000) -// await stakeDialog.actionsContainer.acceptAllActionsAction(2) - -// await stakeDialog.clickBackToFarmAction() - -// await fork.progressSimulation(page, 24 * 60 * 60) // 24 hours -// await page.reload() - -// await farmDetailsPage.clickInfoPanelUnstakeButtonAction() -// unstakeDialog = new UnstakeDialogPageObject(page) - -// await unstakeDialog.selectAssetAction('DAI') -// await unstakeDialog.clickMaxAmountAction() -// }) - -// test('has correct action plan', async () => { -// await unstakeDialog.actionsContainer.expectActions([ -// { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, -// { type: 'approve', asset: 'USDS' }, -// { type: 'downgrade', fromToken: 'USDS', toToken: 'DAI' }, -// ]) -// }) - -// test('has correct action plan when exiting', async () => { -// await unstakeDialog.clickExitFarmSwitchAction() -// await unstakeDialog.actionsContainer.expectActions([ -// { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: true }, -// { type: 'approve', asset: 'USDS' }, -// { type: 'downgrade', fromToken: 'USDS', toToken: 'DAI' }, -// ]) -// }) - -// test('displays transaction overview', async () => { -// await unstakeDialog.expectTransactionOverview({ -// route: { -// swaps: [ -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '10,000.00 DAI', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// farm: { -// upperText: 'SKY Farm', -// lowerText: 'Deposited', -// }, -// }, -// outcome: '10,000.00 DAI', -// }) -// }) - -// test('displays transaction overview when exiting', async () => { -// await unstakeDialog.clickExitFarmSwitchAction() -// await unstakeDialog.expectExitTransactionOverview({ -// route: { -// swaps: [ -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '10,000.00 DAI', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// farm: { -// upperText: 'SKY Farm', -// lowerText: 'Deposited', -// }, -// }, -// outcome: { -// amount: '10,000.00', -// token: 'DAI', -// usdValue: '10,000.00', -// }, -// reward: { -// min: 3538, -// max: 3541, -// usdValue: '213', -// token: 'SKY', -// }, -// }) -// }) - -// test('executes transaction', async () => { -// await unstakeDialog.actionsContainer.acceptAllActionsAction(3) - -// await unstakeDialog.expectSuccessPage() -// await unstakeDialog.clickBackToFarmAction() - -// await farmDetailsPage.expectTokenToDepositBalance('DAI', '20,000.00') -// await farmDetailsPage.expectReward({ -// reward: '3,539', -// rewardUsd: '$213', -// }) -// }) - -// test('executes exit transaction', async () => { -// await unstakeDialog.clickExitFarmSwitchAction() -// await unstakeDialog.actionsContainer.acceptAllActionsAction(3) - -// await unstakeDialog.expectSuccessPage() -// await unstakeDialog.clickBackToFarmAction() - -// await farmDetailsPage.expectTokenToDepositBalance('DAI', '20,000.00') -// await farmDetailsPage.expectInfoPanelToBeVisible() - -// await farmDetailsPage.expectTokenBalance({ -// address: account, -// fork, -// symbol: 'SKY', -// minBalance: 3_525, -// maxBalance: 3_545, -// }) -// }) -// }) +import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +import { setup } from '@/test/e2e/setup' +import { NormalizedUnitNumber } from '@marsfoundation/common-universal' +import { test } from '@playwright/test' +import { Address } from 'viem' +import { mainnet } from 'viem/chains' +import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' +import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' + +test.describe('Withdraw max DAI from SKY farm', () => { + let farmDetailsPage: FarmDetailsPageObject + let unstakeDialog: UnstakeDialogPageObject + let stakeDialog: StakeDialogPageObject + let account: Address + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'farmDetails', + initialPageParams: { + chainId: mainnet.id.toString(), + address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', + }, + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDS: 10_000, + DAI: 10_000, + USDC: 10_000, + }, + }, + }) + + await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) + + farmDetailsPage = new FarmDetailsPageObject(testContext) + await farmDetailsPage.clickInfoPanelStakeButtonAction() + stakeDialog = new StakeDialogPageObject(testContext) + account = testContext.account + + await stakeDialog.selectAssetAction('USDS') + await stakeDialog.fillAmountAction(10_000) + await stakeDialog.actionsContainer.acceptAllActionsAction(2) + + await stakeDialog.clickBackToFarmAction() + + await testContext.testnetController.progressSimulationAndMine(24 * 60 * 60) // 24 hours + await page.reload() + + await farmDetailsPage.clickInfoPanelUnstakeButtonAction() + unstakeDialog = new UnstakeDialogPageObject(testContext) + + await unstakeDialog.selectAssetAction('DAI') + await unstakeDialog.clickMaxAmountAction() + }) + + test('has correct action plan', async () => { + await unstakeDialog.actionsContainer.expectActions([ + { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, + { type: 'approve', asset: 'USDS' }, + { type: 'downgrade', fromToken: 'USDS', toToken: 'DAI' }, + ]) + }) + + test('has correct action plan when exiting', async () => { + await unstakeDialog.clickExitFarmSwitchAction() + await unstakeDialog.actionsContainer.expectActions([ + { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: true }, + { type: 'approve', asset: 'USDS' }, + { type: 'downgrade', fromToken: 'USDS', toToken: 'DAI' }, + ]) + }) + + test('displays transaction overview', async () => { + await unstakeDialog.expectTransactionOverview({ + route: { + swaps: [ + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '10,000.00 DAI', + tokenUsdValue: '$10,000.00', + }, + ], + farm: { + upperText: 'SKY Farm', + lowerText: 'Deposited', + }, + }, + outcome: '10,000.00 DAI', + }) + }) + + test('displays transaction overview when exiting', async () => { + await unstakeDialog.clickExitFarmSwitchAction() + await unstakeDialog.expectExitTransactionOverview({ + route: { + swaps: [ + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '10,000.00 DAI', + tokenUsdValue: '$10,000.00', + }, + ], + farm: { + upperText: 'SKY Farm', + lowerText: 'Deposited', + }, + }, + outcome: { + amount: '10,000.00', + token: 'DAI', + usdValue: '10,000.00', + }, + reward: { + amount: 49.44, + usdValue: '2.98', + token: 'SKY', + }, + }) + }) + + test('executes transaction', async () => { + await unstakeDialog.actionsContainer.acceptAllActionsAction(3) + + await unstakeDialog.expectSuccessPage() + await unstakeDialog.clickBackToFarmAction() + + await farmDetailsPage.expectTokenToDepositBalance('DAI', '20,000.00') + await farmDetailsPage.expectReward({ + reward: '49.436543', + rewardUsd: '2.98', + }) + }) + + test('executes exit transaction', async () => { + await unstakeDialog.clickExitFarmSwitchAction() + await unstakeDialog.actionsContainer.acceptAllActionsAction(3) + + await unstakeDialog.expectSuccessPage() + await unstakeDialog.clickBackToFarmAction() + + await farmDetailsPage.expectTokenToDepositBalance('DAI', '20,000.00') + await farmDetailsPage.expectInfoPanelToBeVisible() + + await farmDetailsPage.expectTokenBalance({ + address: account, + symbol: 'SKY', + balance: NormalizedUnitNumber('49.4365427929088'), + }) + }) +}) diff --git a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts index 9a5b2bde7..4fcc6fb87 100644 --- a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts @@ -1,162 +1,160 @@ -// import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { Address } from 'viem' -// import { mainnet } from 'viem/chains' -// import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' -// import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' - -// test.describe('Withdraw max USDC from SKY farm', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let farmDetailsPage: FarmDetailsPageObject -// let unstakeDialog: UnstakeDialogPageObject -// let stakeDialog: StakeDialogPageObject -// let account: Address - -// test.beforeEach(async ({ page }) => { -// ;({ account } = await setup(page, fork, { -// initialPage: 'farmDetails', -// initialPageParams: { -// chainId: mainnet.id.toString(), -// address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', -// }, -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// USDS: 10_000, -// DAI: 10_000, -// USDC: 10_000, -// }, -// }, -// })) - -// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) - -// farmDetailsPage = new FarmDetailsPageObject(page) -// await farmDetailsPage.clickInfoPanelStakeButtonAction() -// stakeDialog = new StakeDialogPageObject(page) - -// await stakeDialog.selectAssetAction('USDS') -// await stakeDialog.fillAmountAction(10_000) -// await stakeDialog.actionsContainer.acceptAllActionsAction(2) - -// await stakeDialog.clickBackToFarmAction() - -// await fork.progressSimulation(page, 24 * 60 * 60) // 24 hours -// await page.reload() - -// await farmDetailsPage.clickInfoPanelUnstakeButtonAction() -// unstakeDialog = new UnstakeDialogPageObject(page) - -// await unstakeDialog.selectAssetAction('USDC') -// await unstakeDialog.clickMaxAmountAction() -// }) - -// test('has correct action plan', async () => { -// await unstakeDialog.actionsContainer.expectActions([ -// { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, -// { type: 'approve', asset: 'USDS' }, -// { type: 'psmConvert', inToken: 'USDS', outToken: 'USDC' }, -// ]) -// }) - -// test('has correct action plan when exiting', async () => { -// await unstakeDialog.clickExitFarmSwitchAction() -// await unstakeDialog.actionsContainer.expectActions([ -// { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: true }, -// { type: 'approve', asset: 'USDS' }, -// { type: 'psmConvert', inToken: 'USDS', outToken: 'USDC' }, -// ]) -// }) - -// test('displays transaction overview', async () => { -// await unstakeDialog.expectTransactionOverview({ -// route: { -// swaps: [ -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '10,000.00 USDC', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// farm: { -// upperText: 'SKY Farm', -// lowerText: 'Deposited', -// }, -// }, -// outcome: '10,000.00 USDC', -// }) -// }) - -// test('displays transaction overview when exiting', async () => { -// await unstakeDialog.clickExitFarmSwitchAction() -// await unstakeDialog.expectExitTransactionOverview({ -// route: { -// swaps: [ -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '10,000.00 USDC', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// farm: { -// upperText: 'SKY Farm', -// lowerText: 'Deposited', -// }, -// }, -// outcome: { -// amount: '10,000.00', -// token: 'USDC', -// usdValue: '10,000.00', -// }, -// reward: { -// min: 3538, -// max: 3541, -// usdValue: '213', -// token: 'SKY', -// }, -// }) -// }) - -// test('executes transaction', async () => { -// await unstakeDialog.actionsContainer.acceptAllActionsAction(3) - -// await unstakeDialog.expectSuccessPage() -// await unstakeDialog.clickBackToFarmAction() - -// await farmDetailsPage.expectTokenToDepositBalance('USDC', '20,000.00') -// await farmDetailsPage.expectReward({ -// reward: '3,539', -// rewardUsd: '$213', -// }) -// }) - -// test('executes exit transaction', async () => { -// await unstakeDialog.clickExitFarmSwitchAction() -// await unstakeDialog.actionsContainer.acceptAllActionsAction(3) - -// await unstakeDialog.expectSuccessPage() -// await unstakeDialog.clickBackToFarmAction() - -// await farmDetailsPage.expectTokenToDepositBalance('USDC', '20,000.00') -// await farmDetailsPage.expectInfoPanelToBeVisible() - -// await farmDetailsPage.expectTokenBalance({ -// address: account, -// fork, -// symbol: 'SKY', -// minBalance: 3_525, -// maxBalance: 3_545, -// }) -// }) -// }) +import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +import { setup } from '@/test/e2e/setup' +import { NormalizedUnitNumber } from '@marsfoundation/common-universal' +import { test } from '@playwright/test' +import { Address } from 'viem' +import { mainnet } from 'viem/chains' +import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' +import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' + +test.describe('Withdraw max USDC from SKY farm', () => { + let farmDetailsPage: FarmDetailsPageObject + let unstakeDialog: UnstakeDialogPageObject + let stakeDialog: StakeDialogPageObject + let account: Address + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }, + initialPage: 'farmDetails', + initialPageParams: { + chainId: mainnet.id.toString(), + address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', + }, + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDS: 10_000, + DAI: 10_000, + USDC: 10_000, + }, + }, + }) + + await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) + + farmDetailsPage = new FarmDetailsPageObject(testContext) + await farmDetailsPage.clickInfoPanelStakeButtonAction() + stakeDialog = new StakeDialogPageObject(testContext) + account = testContext.account + + await stakeDialog.selectAssetAction('USDS') + await stakeDialog.fillAmountAction(10_000) + await stakeDialog.actionsContainer.acceptAllActionsAction(2) + + await stakeDialog.clickBackToFarmAction() + + await testContext.testnetController.progressSimulationAndMine(24 * 60 * 60) // 24 hours + await page.reload() + + await farmDetailsPage.clickInfoPanelUnstakeButtonAction() + unstakeDialog = new UnstakeDialogPageObject(testContext) + + await unstakeDialog.selectAssetAction('USDC') + await unstakeDialog.clickMaxAmountAction() + }) + + test('has correct action plan', async () => { + await unstakeDialog.actionsContainer.expectActions([ + { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, + { type: 'approve', asset: 'USDS' }, + { type: 'psmConvert', inToken: 'USDS', outToken: 'USDC' }, + ]) + }) + + test('has correct action plan when exiting', async () => { + await unstakeDialog.clickExitFarmSwitchAction() + await unstakeDialog.actionsContainer.expectActions([ + { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: true }, + { type: 'approve', asset: 'USDS' }, + { type: 'psmConvert', inToken: 'USDS', outToken: 'USDC' }, + ]) + }) + + test('displays transaction overview', async () => { + await unstakeDialog.expectTransactionOverview({ + route: { + swaps: [ + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '10,000.00 USDC', + tokenUsdValue: '$10,000.00', + }, + ], + farm: { + upperText: 'SKY Farm', + lowerText: 'Deposited', + }, + }, + outcome: '10,000.00 USDC', + }) + }) + + test('displays transaction overview when exiting', async () => { + await unstakeDialog.clickExitFarmSwitchAction() + await unstakeDialog.expectExitTransactionOverview({ + route: { + swaps: [ + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '10,000.00 USDC', + tokenUsdValue: '$10,000.00', + }, + ], + farm: { + upperText: 'SKY Farm', + lowerText: 'Deposited', + }, + }, + outcome: { + amount: '10,000.00', + token: 'USDC', + usdValue: '10,000.00', + }, + reward: { + amount: 49.44, + usdValue: '2.98', + token: 'SKY', + }, + }) + }) + + test('executes transaction', async () => { + await unstakeDialog.actionsContainer.acceptAllActionsAction(3) + + await unstakeDialog.expectSuccessPage() + await unstakeDialog.clickBackToFarmAction() + + await farmDetailsPage.expectTokenToDepositBalance('USDC', '20,000.00') + await farmDetailsPage.expectReward({ + reward: '49.436543', + rewardUsd: '2.98', + }) + }) + + test('executes exit transaction', async () => { + await unstakeDialog.clickExitFarmSwitchAction() + await unstakeDialog.actionsContainer.acceptAllActionsAction(3) + + await unstakeDialog.expectSuccessPage() + await unstakeDialog.clickBackToFarmAction() + + await farmDetailsPage.expectTokenToDepositBalance('USDC', '20,000.00') + await farmDetailsPage.expectInfoPanelToBeVisible() + + await farmDetailsPage.expectTokenBalance({ + symbol: 'SKY', + balance: NormalizedUnitNumber('49.4365427929088'), + address: account, + }) + }) +}) diff --git a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts index b91a183bb..88e08f073 100644 --- a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts @@ -1,217 +1,220 @@ -// import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { Address } from 'viem' -// import { privateKeyToAddress } from 'viem/accounts' -// import { mainnet } from 'viem/chains' -// import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' -// import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' - -// test.describe('Withdraw max USDS from SKY farm', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let farmDetailsPage: FarmDetailsPageObject -// let unstakeDialog: UnstakeDialogPageObject -// let stakeDialog: StakeDialogPageObject -// let account: Address - -// test.beforeEach(async ({ page }) => { -// ;({ account } = await setup(page, fork, { -// initialPage: 'farmDetails', -// initialPageParams: { -// chainId: mainnet.id.toString(), -// address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', -// }, -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// USDS: 10_000, -// DAI: 10_000, -// USDC: 10_000, -// }, -// }, -// })) - -// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) - -// farmDetailsPage = new FarmDetailsPageObject(page) -// await farmDetailsPage.clickInfoPanelStakeButtonAction() -// stakeDialog = new StakeDialogPageObject(page) - -// await stakeDialog.selectAssetAction('USDS') -// await stakeDialog.fillAmountAction(10_000) -// await stakeDialog.actionsContainer.acceptAllActionsAction(2) - -// await stakeDialog.clickBackToFarmAction() - -// await fork.progressSimulation(page, 24 * 60 * 60) // 24 hours -// await page.reload() - -// await farmDetailsPage.clickInfoPanelUnstakeButtonAction() -// unstakeDialog = new UnstakeDialogPageObject(page) - -// await unstakeDialog.selectAssetAction('USDS') -// await unstakeDialog.clickMaxAmountAction() -// }) - -// test('has reward displayed on exit farm switch', async () => { -// await unstakeDialog.expectExitFarmSwitchToBeVisible() -// await unstakeDialog.expectExitFarmSwitchNotChecked() -// await unstakeDialog.expectExitFarmSwitchReward({ -// min: 3538, -// max: 3541, -// token: 'SKY', -// usdValue: '213', -// }) -// }) - -// test('has correct action plan', async () => { -// await unstakeDialog.actionsContainer.expectActions([ -// { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, -// ]) -// }) - -// test('has correct action plan when exiting', async () => { -// await unstakeDialog.clickExitFarmSwitchAction() -// await unstakeDialog.actionsContainer.expectActions([ -// { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: true }, -// ]) -// }) - -// test('displays transaction overview', async () => { -// await unstakeDialog.expectTransactionOverview({ -// route: { -// swaps: [ -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// farm: { -// upperText: 'SKY Farm', -// lowerText: 'Deposited', -// }, -// }, -// outcome: '10,000.00 USDS', -// }) -// }) - -// test('displays transaction overview when exiting', async () => { -// await unstakeDialog.clickExitFarmSwitchAction() -// await unstakeDialog.expectExitTransactionOverview({ -// route: { -// swaps: [ -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// farm: { -// upperText: 'SKY Farm', -// lowerText: 'Deposited', -// }, -// }, -// outcome: { -// amount: '10,000.00', -// token: 'USDS', -// usdValue: '10,000.00', -// }, -// reward: { -// min: 3538, -// max: 3541, -// usdValue: '213', -// token: 'SKY', -// }, -// }) -// }) - -// test('executes transaction', async () => { -// await unstakeDialog.actionsContainer.acceptAllActionsAction(1) - -// await unstakeDialog.expectSuccessPage() -// await unstakeDialog.clickBackToFarmAction() - -// await farmDetailsPage.expectTokenToDepositBalance('USDS', '10,000.00') -// await farmDetailsPage.expectReward({ -// reward: '3,539', -// rewardUsd: '$213', -// }) -// }) - -// test('executes exit transaction', async () => { -// await unstakeDialog.clickExitFarmSwitchAction() -// await unstakeDialog.actionsContainer.acceptAllActionsAction(1) - -// await unstakeDialog.expectSuccessPage() -// await unstakeDialog.clickBackToFarmAction() - -// await farmDetailsPage.expectTokenToDepositBalance('USDS', '10,000.00') -// await farmDetailsPage.expectInfoPanelToBeVisible() - -// await farmDetailsPage.expectTokenBalance({ -// address: account, -// fork, -// symbol: 'SKY', -// minBalance: 3_525, -// maxBalance: 3_545, -// }) -// }) -// }) - -// test.describe('Withdraw max USDS from CLE farm', () => { -// const testUserPKey = '0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5' -// const testUserAddress = privateKeyToAddress('0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5') -// const harSuffix = testUserAddress.slice(0, 10) - -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let farmDetailsPage: FarmDetailsPageObject -// let unstakeDialog: UnstakeDialogPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'farmDetails', -// initialPageParams: { -// chainId: mainnet.id.toString(), -// address: '0x10ab606B067C9C461d8893c47C7512472E19e2Ce', -// }, -// account: { -// type: 'connected-pkey', -// privateKey: testUserPKey, -// assetBalances: { -// ETH: 1, -// USDS: 10_000, -// }, -// }, -// }) -// await overrideInfoSkyRouteWithHAR({ page, key: `2-cle-farm-0-balance-${harSuffix}` }) - -// farmDetailsPage = new FarmDetailsPageObject(page) -// await farmDetailsPage.clickInfoPanelStakeButtonAction() -// const stakeDialog = new StakeDialogPageObject(page) -// await stakeDialog.fillAmountAction(10_000) -// await stakeDialog.actionsContainer.acceptAllActionsAction(2) -// await stakeDialog.clickBackToFarmAction() -// await overrideInfoSkyRouteWithHAR({ page, key: `3-cle-farm-10000-balance-${harSuffix}` }) - -// await farmDetailsPage.clickInfoPanelUnstakeButtonAction() -// unstakeDialog = new UnstakeDialogPageObject(page) - -// await unstakeDialog.selectAssetAction('USDS') -// await unstakeDialog.clickMaxAmountAction() -// }) - -// test('keeps the exit switch hidden', async () => { -// await unstakeDialog.actionsContainer.expectEnabledActionAtIndex(0) -// await unstakeDialog.expectExitFarmSwitchToBeHidden() -// }) - -// test('has correct action plan', async () => { -// await unstakeDialog.actionsContainer.expectEnabledActionAtIndex(0) -// await unstakeDialog.actionsContainer.expectActions([ -// { type: 'unstake', stakingToken: 'USDS', rewardToken: 'CLE', exit: false }, -// ]) -// }) -// }) +import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +import { setup } from '@/test/e2e/setup' +import { NormalizedUnitNumber } from '@marsfoundation/common-universal' +import { test } from '@playwright/test' +import { Address } from 'viem' +import { privateKeyToAddress } from 'viem/accounts' +import { mainnet } from 'viem/chains' +import { StakeDialogPageObject } from '../../../stake/StakeDialog.PageObject' +import { UnstakeDialogPageObject } from '../../UnstakeDialog.PageObject' + +test.describe('Withdraw max USDS from SKY farm', () => { + let farmDetailsPage: FarmDetailsPageObject + let unstakeDialog: UnstakeDialogPageObject + let stakeDialog: StakeDialogPageObject + let account: Address + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'farmDetails', + initialPageParams: { + chainId: mainnet.id.toString(), + address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', + }, + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDS: 10_000, + DAI: 10_000, + USDC: 10_000, + }, + }, + }) + + await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) + + farmDetailsPage = new FarmDetailsPageObject(testContext) + await farmDetailsPage.clickInfoPanelStakeButtonAction() + stakeDialog = new StakeDialogPageObject(testContext) + account = testContext.account + + await stakeDialog.selectAssetAction('USDS') + await stakeDialog.fillAmountAction(10_000) + await stakeDialog.actionsContainer.acceptAllActionsAction(2) + + await stakeDialog.clickBackToFarmAction() + + await testContext.testnetController.progressSimulationAndMine(24 * 60 * 60) // 24 hours + await page.reload() + + await farmDetailsPage.clickInfoPanelUnstakeButtonAction() + unstakeDialog = new UnstakeDialogPageObject(testContext) + + await unstakeDialog.selectAssetAction('USDS') + await unstakeDialog.clickMaxAmountAction() + }) + + test('has reward displayed on exit farm switch', async () => { + await unstakeDialog.expectExitFarmSwitchToBeVisible() + await unstakeDialog.expectExitFarmSwitchNotChecked() + await unstakeDialog.expectExitFarmSwitchReward({ + amount: 49.44, + token: 'SKY', + usdValue: '2.98', + }) + }) + + test('has correct action plan', async () => { + await unstakeDialog.actionsContainer.expectActions([ + { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: false }, + ]) + }) + + test('has correct action plan when exiting', async () => { + await unstakeDialog.clickExitFarmSwitchAction() + await unstakeDialog.actionsContainer.expectActions([ + { type: 'unstake', stakingToken: 'USDS', rewardToken: 'SKY', exit: true }, + ]) + }) + + test('displays transaction overview', async () => { + await unstakeDialog.expectTransactionOverview({ + route: { + swaps: [ + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + ], + farm: { + upperText: 'SKY Farm', + lowerText: 'Deposited', + }, + }, + outcome: '10,000.00 USDS', + }) + }) + + test('displays transaction overview when exiting', async () => { + await unstakeDialog.clickExitFarmSwitchAction() + await unstakeDialog.expectExitTransactionOverview({ + route: { + swaps: [ + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + ], + farm: { + upperText: 'SKY Farm', + lowerText: 'Deposited', + }, + }, + outcome: { + amount: '10,000.00', + token: 'USDS', + usdValue: '10,000.00', + }, + reward: { + amount: 49.44, + usdValue: '2.98', + token: 'SKY', + }, + }) + }) + + test('executes transaction', async () => { + await unstakeDialog.actionsContainer.acceptAllActionsAction(1) + + await unstakeDialog.expectSuccessPage() + await unstakeDialog.clickBackToFarmAction() + + await farmDetailsPage.expectTokenToDepositBalance('USDS', '10,000.00') + await farmDetailsPage.expectReward({ + reward: '49.436543', + rewardUsd: '2.98', + }) + }) + + test('executes exit transaction', async () => { + await unstakeDialog.clickExitFarmSwitchAction() + await unstakeDialog.actionsContainer.acceptAllActionsAction(1) + + await unstakeDialog.expectSuccessPage() + await unstakeDialog.clickBackToFarmAction() + + await farmDetailsPage.expectTokenToDepositBalance('USDS', '10,000.00') + await farmDetailsPage.expectInfoPanelToBeVisible() + + await farmDetailsPage.expectTokenBalance({ + address: account, + symbol: 'SKY', + balance: NormalizedUnitNumber('49.4365427929088'), + }) + }) +}) + +test.describe('Withdraw max USDS from CLE farm', () => { + const testUserPKey = '0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5' + const testUserAddress = privateKeyToAddress('0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5') + const harSuffix = testUserAddress.slice(0, 10) + + let farmDetailsPage: FarmDetailsPageObject + let unstakeDialog: UnstakeDialogPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'farmDetails', + initialPageParams: { + chainId: mainnet.id.toString(), + address: '0x10ab606B067C9C461d8893c47C7512472E19e2Ce', + }, + account: { + type: 'connected-pkey', + privateKey: testUserPKey, + assetBalances: { + ETH: 1, + USDS: 10_000, + }, + }, + }) + await overrideInfoSkyRouteWithHAR({ page, key: `2-cle-farm-0-balance-${harSuffix}` }) + + farmDetailsPage = new FarmDetailsPageObject(testContext) + await farmDetailsPage.clickInfoPanelStakeButtonAction() + const stakeDialog = new StakeDialogPageObject(testContext) + await stakeDialog.fillAmountAction(10_000) + await stakeDialog.actionsContainer.acceptAllActionsAction(2) + await stakeDialog.clickBackToFarmAction() + await overrideInfoSkyRouteWithHAR({ page, key: `3-cle-farm-10000-balance-${harSuffix}` }) + + await farmDetailsPage.clickInfoPanelUnstakeButtonAction() + unstakeDialog = new UnstakeDialogPageObject(testContext) + + await unstakeDialog.selectAssetAction('USDS') + await unstakeDialog.clickMaxAmountAction() + }) + + test('keeps the exit switch hidden', async () => { + await unstakeDialog.actionsContainer.expectEnabledActionAtIndex(0) + await unstakeDialog.expectExitFarmSwitchToBeHidden() + }) + + test('has correct action plan', async () => { + await unstakeDialog.actionsContainer.expectEnabledActionAtIndex(0) + await unstakeDialog.actionsContainer.expectActions([ + { type: 'unstake', stakingToken: 'USDS', rewardToken: 'CLE', exit: false }, + ]) + }) +}) From cb7177911c9782a4b289c5f89d6884164a3894a2 Mon Sep 17 00:00:00 2001 From: Oskar <43062492+oskarvu@users.noreply.github.com> Date: Thu, 19 Dec 2024 19:38:54 +0700 Subject: [PATCH 18/29] Rewrite farm stake dialog tests (#507) * Rewrite stake usds tests * Add stake sdai test * Add stake susds tests * Add stake dai tests * Add stake usdc tests --- .../common/e2e/SavingsDialog.PageObject.ts | 314 +++++++++-------- .../stake/e2e/mainnet/StakeDAI.test-e2e.ts | 160 ++++----- .../stake/e2e/mainnet/StakeSDAI.test-e2e.ts | 164 ++++----- .../stake/e2e/mainnet/StakeSUSDS.test-e2e.ts | 182 +++++----- .../stake/e2e/mainnet/StakeUSDC.test-e2e.ts | 160 ++++----- .../stake/e2e/mainnet/StakeUSDS.test-e2e.ts | 329 +++++++++--------- 6 files changed, 667 insertions(+), 642 deletions(-) diff --git a/packages/app/src/features/dialogs/savings/common/e2e/SavingsDialog.PageObject.ts b/packages/app/src/features/dialogs/savings/common/e2e/SavingsDialog.PageObject.ts index 8575aec90..f06877568 100644 --- a/packages/app/src/features/dialogs/savings/common/e2e/SavingsDialog.PageObject.ts +++ b/packages/app/src/features/dialogs/savings/common/e2e/SavingsDialog.PageObject.ts @@ -1,151 +1,163 @@ -// import { getBalance, getTokenBalance } from '@/test/e2e/utils' -// import { testIds } from '@/ui/utils/testIds' -// import { Locator, Page, expect } from '@playwright/test' -// import { Address } from 'viem' -// import { DialogPageObject, TxOverviewWithRoute } from '../../../common/Dialog.PageObject' - -// export class SavingsDialogPageObject extends DialogPageObject { -// private readonly type: 'deposit' | 'withdraw' | 'send' - -// constructor({ page, type }: { page: Page; type: 'deposit' | 'withdraw' | 'send' }) { -// super( -// page, -// new RegExp(`${type === 'deposit' ? 'Deposit to' : type === 'send' ? 'Send from' : 'Withdraw from'} Savings`), -// ) -// this.type = type -// } - -// // # region locators -// locateUpgradeSwitch(): Locator { -// return this.page.getByTestId(testIds.dialog.savings.upgradeSwitch) -// } -// // #endregion locators - -// // #region actions -// async clickBackToSavingsButton(): Promise { -// await this.page.getByRole('button', { name: 'Back to Savings' }).click() -// await this.region.waitFor({ -// state: 'detached', -// }) -// } - -// async fillReceiverAction(receiver: string): Promise { -// await this.region.getByTestId(testIds.component.AddressInput.input).fill(receiver) -// } - -// // #endregion actions - -// // #region assertions -// async expectDiscrepancyWarning(discrepancy: string): Promise { -// const explanation = -// this.type === 'deposit' -// ? 'The final amount received may be less than the deposit amount by up to' -// : 'You may be charged more than the withdraw amount by up to' -// await expect( -// this.region.getByText(`Market fluctuations can impact your transaction value. ${explanation} ${discrepancy}`), -// ).toBeVisible() -// } - -// async expectTransactionOverviewToBeVisible(): Promise { -// await expect(this.locatePanelByHeader('Transaction overview')).toBeVisible() -// } - -// async expectAssetSelectorOptions(options: string[]): Promise { -// const selectorOptions = await this.page.getByTestId(testIds.component.AssetSelector.option).all() -// expect(selectorOptions).toHaveLength(options.length) - -// for (const [index, option] of selectorOptions.entries()) { -// await expect(option).toContainText(options[index]!) -// } -// } - -// async expectTransactionOverview(transactionOverview: TransactionOverview): Promise { -// const panel = this.locatePanelByHeader('Transaction overview') -// await expect(panel).toBeVisible() - -// for (const [index, [label, value]] of transactionOverview.entries()) { -// const row = panel.getByTestId(testIds.dialog.depositSavings.transactionDetailsRow(index)) -// await expect(row).toBeVisible() -// await expect(row).toContainText(label) -// await expect(row).toContainText(value) -// } -// } - -// async expectNativeRouteTransactionOverview(transactionOverview: NativeRouteTransactionOverview): Promise { -// const panel = this.locatePanelByHeader('Transaction overview') -// await expect(panel).toBeVisible() -// const savingsTxOverviewTestIds = testIds.dialog.savings.transactionOverview - -// if (transactionOverview.apy) { -// const apyValue = panel.getByTestId(savingsTxOverviewTestIds.apy.value) -// const apyDescription = panel.getByTestId(savingsTxOverviewTestIds.apy.description) -// await expect(apyValue).toContainText(transactionOverview.apy.value) -// await expect(apyDescription).toContainText(transactionOverview.apy.description) -// } - -// await this.expectTransactionOverviewRoute(transactionOverview.routeItems) -// if (transactionOverview.badgeTokens) { -// await this.expectSkyBadgeForTokens(transactionOverview.badgeTokens) -// } -// await this.expectOutcomeText(transactionOverview.outcome) -// } - -// async expectSuccessPage(): Promise { -// // for now we only check if the success message is visible -// await expect(this.page.getByText('Congrats, all done!')).toBeVisible() -// } - -// async expectAddressInputError(error: string): Promise { -// await expect(this.page.getByTestId(testIds.component.AddressInput.error)).toHaveText(error) -// } - -// async expectReceiverIsSmartContractWarning(): Promise { -// await expect(this.page.getByTestId(testIds.dialog.savings.send.addressIsSmartContractWarning)).toBeVisible() -// } - -// async expectReceiverBalance({ -// forkUrl, -// receiver, -// expectedBalance, -// }: { -// forkUrl: string -// receiver: Address -// expectedBalance: number -// }): Promise { -// const currentBalance = await getBalance({ forkUrl, address: receiver }) -// expect(currentBalance.isEqualTo(expectedBalance)).toBe(true) -// } - -// async expectReceiverTokenBalance({ -// forkUrl, -// receiver, -// token, -// expectedBalance, -// }: { -// forkUrl: string -// receiver: Address -// token: { address: Address; decimals: number } -// expectedBalance: number -// }): Promise { -// const currentTokenBalance = await getTokenBalance({ forkUrl, address: receiver, token }) -// expect(currentTokenBalance.isEqualTo(expectedBalance)).toBe(true) -// } - -// expectUpgradeSwitchToBeHidden(): Promise { -// return expect(this.locateUpgradeSwitch()).toBeHidden() -// } - -// clickUpgradeSwitch(): Promise { -// return this.locateUpgradeSwitch().click() -// } -// // #endregion assertions -// } - -// type TransactionOverview = [string, string][] - -// interface NativeRouteTransactionOverview extends TxOverviewWithRoute { -// apy?: { -// value: string -// description: string -// } -// } +import { TestContext } from '@/test/e2e/setup' +import { getBalance, getTokenBalance } from '@/test/e2e/utils' +import { testIds } from '@/ui/utils/testIds' +import { getUrlFromClient } from '@marsfoundation/common-testnets' +import { Locator, expect } from '@playwright/test' +import { Address } from 'viem' +import { DialogPageObject, TxOverviewWithRoute } from '../../../common/Dialog.PageObject' + +export interface SavingsDialogPageObjectParams { + testContext: TestContext + type: 'deposit' | 'withdraw' | 'send' +} + +export class SavingsDialogPageObject extends DialogPageObject { + private readonly type: 'deposit' | 'withdraw' | 'send' + + constructor({ testContext, type }: SavingsDialogPageObjectParams) { + super({ + testContext, + header: new RegExp( + `${type === 'deposit' ? 'Deposit to' : type === 'send' ? 'Send from' : 'Withdraw from'} Savings`, + ), + }) + this.type = type + } + + // # region locators + locateUpgradeSwitch(): Locator { + return this.page.getByTestId(testIds.dialog.savings.upgradeSwitch) + } + // #endregion locators + + // #region actions + async clickBackToSavingsButton(): Promise { + await this.page.getByRole('button', { name: 'Back to Savings' }).click() + await this.region.waitFor({ + state: 'detached', + }) + } + + async fillReceiverAction(receiver: string): Promise { + await this.region.getByTestId(testIds.component.AddressInput.input).fill(receiver) + } + + // #endregion actions + + // #region assertions + async expectDiscrepancyWarning(discrepancy: string): Promise { + const explanation = + this.type === 'deposit' + ? 'The final amount received may be less than the deposit amount by up to' + : 'You may be charged more than the withdraw amount by up to' + await expect( + this.region.getByText(`Market fluctuations can impact your transaction value. ${explanation} ${discrepancy}`), + ).toBeVisible() + } + + async expectTransactionOverviewToBeVisible(): Promise { + await expect(this.locatePanelByHeader('Transaction overview')).toBeVisible() + } + + async expectAssetSelectorOptions(options: string[]): Promise { + const selectorOptions = await this.page.getByTestId(testIds.component.AssetSelector.option).all() + expect(selectorOptions).toHaveLength(options.length) + + for (const [index, option] of selectorOptions.entries()) { + await expect(option).toContainText(options[index]!) + } + } + + async expectTransactionOverview(transactionOverview: TransactionOverview): Promise { + const panel = this.locatePanelByHeader('Transaction overview') + await expect(panel).toBeVisible() + + for (const [index, [label, value]] of transactionOverview.entries()) { + const row = panel.getByTestId(testIds.dialog.depositSavings.transactionDetailsRow(index)) + await expect(row).toBeVisible() + await expect(row).toContainText(label) + await expect(row).toContainText(value) + } + } + + async expectNativeRouteTransactionOverview(transactionOverview: NativeRouteTransactionOverview): Promise { + const panel = this.locatePanelByHeader('Transaction overview') + await expect(panel).toBeVisible() + const savingsTxOverviewTestIds = testIds.dialog.savings.transactionOverview + + if (transactionOverview.apy) { + const apyValue = panel.getByTestId(savingsTxOverviewTestIds.apy.value) + const apyDescription = panel.getByTestId(savingsTxOverviewTestIds.apy.description) + await expect(apyValue).toContainText(transactionOverview.apy.value) + await expect(apyDescription).toContainText(transactionOverview.apy.description) + } + + await this.expectTransactionOverviewRoute(transactionOverview.routeItems) + if (transactionOverview.badgeTokens) { + await this.expectSkyBadgeForTokens(transactionOverview.badgeTokens) + } + await this.expectOutcomeText(transactionOverview.outcome) + } + + async expectSuccessPage(): Promise { + // for now we only check if the success message is visible + await expect(this.page.getByText('Congrats, all done!')).toBeVisible() + } + + async expectAddressInputError(error: string): Promise { + await expect(this.page.getByTestId(testIds.component.AddressInput.error)).toHaveText(error) + } + + async expectReceiverIsSmartContractWarning(): Promise { + await expect(this.page.getByTestId(testIds.dialog.savings.send.addressIsSmartContractWarning)).toBeVisible() + } + + async expectReceiverBalance({ + receiver, + expectedBalance, + }: { + receiver: Address + expectedBalance: number + }): Promise { + const currentBalance = await getBalance({ + forkUrl: getUrlFromClient(this.testContext.testnetController.client), + address: receiver, + }) + expect(currentBalance.isEqualTo(expectedBalance)).toBe(true) + } + + async expectReceiverTokenBalance({ + receiver, + token, + expectedBalance, + }: { + receiver: Address + token: { address: Address; decimals: number } + expectedBalance: number + }): Promise { + const currentTokenBalance = await getTokenBalance({ + forkUrl: getUrlFromClient(this.testContext.testnetController.client), + address: receiver, + token, + }) + expect(currentTokenBalance.isEqualTo(expectedBalance)).toBe(true) + } + + expectUpgradeSwitchToBeHidden(): Promise { + return expect(this.locateUpgradeSwitch()).toBeHidden() + } + + clickUpgradeSwitch(): Promise { + return this.locateUpgradeSwitch().click() + } + // #endregion assertions +} + +type TransactionOverview = [string, string][] + +interface NativeRouteTransactionOverview extends TxOverviewWithRoute { + apy?: { + value: string + description: string + } +} diff --git a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeDAI.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeDAI.test-e2e.ts index 7f9c6d7db..36b4156e3 100644 --- a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeDAI.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeDAI.test-e2e.ts @@ -1,87 +1,89 @@ -// import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { StakeDialogPageObject } from '../../StakeDialog.PageObject' +import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { StakeDialogPageObject } from '../../StakeDialog.PageObject' -// test.describe('Stake DAI to SKY farm', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let farmDetailsPage: FarmDetailsPageObject -// let stakeDialog: StakeDialogPageObject +test.describe('Stake DAI to SKY farm', () => { + let farmDetailsPage: FarmDetailsPageObject + let stakeDialog: StakeDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'farmDetails', -// initialPageParams: { -// chainId: mainnet.id.toString(), -// address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', -// }, -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// DAI: 10_000, -// }, -// }, -// }) -// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'farmDetails', + initialPageParams: { + chainId: mainnet.id.toString(), + address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', + }, + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + DAI: 10_000, + }, + }, + }) + await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) -// farmDetailsPage = new FarmDetailsPageObject(page) -// await farmDetailsPage.clickInfoPanelStakeButtonAction() -// stakeDialog = new StakeDialogPageObject(page) -// await stakeDialog.selectAssetAction('DAI') -// await stakeDialog.fillAmountAction(10_000) -// }) + farmDetailsPage = new FarmDetailsPageObject(testContext) + await farmDetailsPage.clickInfoPanelStakeButtonAction() + stakeDialog = new StakeDialogPageObject(testContext) + await stakeDialog.selectAssetAction('DAI') + await stakeDialog.fillAmountAction(10_000) + }) -// test('has correct action plan', async () => { -// await stakeDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'DAI' }, -// { type: 'upgrade', fromToken: 'DAI', toToken: 'USDS' }, -// { type: 'approve', asset: 'USDS' }, -// { type: 'stake', stakingToken: 'USDS', rewardToken: 'SKY' }, -// ]) -// }) + test('has correct action plan', async () => { + await stakeDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'DAI' }, + { type: 'upgrade', fromToken: 'DAI', toToken: 'USDS' }, + { type: 'approve', asset: 'USDS' }, + { type: 'stake', stakingToken: 'USDS', rewardToken: 'SKY' }, + ]) + }) -// test('displays transaction overview', async () => { -// await stakeDialog.expectTransactionOverview({ -// estimatedRewards: { -// apy: '778.72%', -// description: 'Earn ~1,291,972.67 SKY/year', -// }, -// route: { -// swaps: [ -// { -// tokenAmount: '10,000.00 DAI', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// final: { -// upperText: 'SKY Farm', -// lowerText: 'Deposited', -// }, -// }, -// outcome: '10,000.00 USD', -// }) -// }) + test('displays transaction overview', async () => { + await stakeDialog.expectTransactionOverview({ + estimatedRewards: { + apy: '10.88%', + description: 'Earn ~18,044.13 SKY/year', + }, + route: { + swaps: [ + { + tokenAmount: '10,000.00 DAI', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + ], + final: { + upperText: 'SKY Farm', + lowerText: 'Deposited', + }, + }, + outcome: '10,000.00 USD', + }) + }) -// test('executes transaction', async () => { -// await stakeDialog.actionsContainer.acceptAllActionsAction(4) + test('executes transaction', async () => { + await stakeDialog.actionsContainer.acceptAllActionsAction(4) -// await stakeDialog.expectSuccessPage() -// await stakeDialog.clickBackToFarmAction() + await stakeDialog.expectSuccessPage() + await stakeDialog.clickBackToFarmAction() -// await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') -// await farmDetailsPage.expectReward({ -// reward: '0.1', -// rewardUsd: '<$0.01', -// }) -// await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) -// }) -// }) + await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') + await farmDetailsPage.expectReward({ + reward: '0.001', + rewardUsd: '<$0.01', + }) + await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) + }) +}) diff --git a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSDAI.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSDAI.test-e2e.ts index d7d3635dd..02d707781 100644 --- a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSDAI.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSDAI.test-e2e.ts @@ -1,89 +1,91 @@ -// import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { StakeDialogPageObject } from '../../StakeDialog.PageObject' +import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { StakeDialogPageObject } from '../../StakeDialog.PageObject' -// test.describe('Stake sDAI to SKY farm', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let farmDetailsPage: FarmDetailsPageObject -// let stakeDialog: StakeDialogPageObject +test.describe('Stake sDAI to SKY farm', () => { + let farmDetailsPage: FarmDetailsPageObject + let stakeDialog: StakeDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'farmDetails', -// initialPageParams: { -// chainId: mainnet.id.toString(), -// address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', -// }, -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sDAI: 1_000, -// }, -// }, -// }) -// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'farmDetails', + initialPageParams: { + chainId: mainnet.id.toString(), + address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', + }, + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sDAI: 1_000, + }, + }, + }) + await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) -// farmDetailsPage = new FarmDetailsPageObject(page) -// await farmDetailsPage.clickInfoPanelStakeButtonAction() -// stakeDialog = new StakeDialogPageObject(page) -// await stakeDialog.selectAssetAction('sDAI') -// await stakeDialog.fillAmountAction(1_000) -// }) + farmDetailsPage = new FarmDetailsPageObject(testContext) + await farmDetailsPage.clickInfoPanelStakeButtonAction() + stakeDialog = new StakeDialogPageObject(testContext) + await stakeDialog.selectAssetAction('sDAI') + await stakeDialog.fillAmountAction(1_000) + }) -// test('has correct action plan', async () => { -// await stakeDialog.actionsContainer.expectEnabledActionAtIndex(0) -// await stakeDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'sDAI' }, -// { type: 'withdrawFromSavings', savingsAsset: 'sDAI', asset: 'USDS', mode: 'withdraw' }, -// { type: 'approve', asset: 'USDS' }, -// { type: 'stake', stakingToken: 'USDS', rewardToken: 'SKY' }, -// ]) -// }) + test('has correct action plan', async () => { + await stakeDialog.actionsContainer.expectEnabledActionAtIndex(0) + await stakeDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sDAI' }, + { type: 'withdrawFromSavings', savingsAsset: 'sDAI', asset: 'USDS', mode: 'withdraw' }, + { type: 'approve', asset: 'USDS' }, + { type: 'stake', stakingToken: 'USDS', rewardToken: 'SKY' }, + ]) + }) -// test('displays transaction overview', async () => { -// await stakeDialog.expectTransactionOverview({ -// estimatedRewards: { -// apy: '780.23%', -// description: 'Earn ~143,505.01 SKY/year', -// }, -// route: { -// swaps: [ -// { -// tokenAmount: '1,000.00 sDAI', -// tokenUsdValue: '$1,108.59', -// }, -// { -// tokenAmount: '1,108.59 USDS', -// tokenUsdValue: '$1,108.59', -// }, -// ], -// final: { -// upperText: 'SKY Farm', -// lowerText: 'Deposited', -// }, -// }, -// outcome: '1,108.59 USDS', -// }) -// }) + test('displays transaction overview', async () => { + await stakeDialog.expectTransactionOverview({ + estimatedRewards: { + apy: '10.88%', + description: 'Earn ~2,031.10 SKY/year', + }, + route: { + swaps: [ + { + tokenAmount: '1,000.00 sDAI', + tokenUsdValue: '$1,125.60', + }, + { + tokenAmount: '1,125.60 USDS', + tokenUsdValue: '$1,125.60', + }, + ], + final: { + upperText: 'SKY Farm', + lowerText: 'Deposited', + }, + }, + outcome: '1,125.60 USDS', + }) + }) -// test('executes transaction', async () => { -// await stakeDialog.actionsContainer.acceptAllActionsAction(4) + test('executes transaction', async () => { + await stakeDialog.actionsContainer.acceptAllActionsAction(4) -// await stakeDialog.expectSuccessPage() -// await stakeDialog.clickBackToFarmAction() + await stakeDialog.expectSuccessPage() + await stakeDialog.clickBackToFarmAction() -// await farmDetailsPage.expectTokenToDepositBalance('sDAI', '-') -// await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') // no dust left -// await farmDetailsPage.expectReward({ -// reward: '0.01', -// rewardUsd: '<$0.01', -// }) -// await farmDetailsPage.expectStaked({ amount: '1,108.59', asset: 'USDS' }) -// }) -// }) + await farmDetailsPage.expectTokenToDepositBalance('sDAI', '-') + await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') // no dust left + await farmDetailsPage.expectReward({ + reward: '0.0001', + rewardUsd: '<$0.01', + }) + await farmDetailsPage.expectStaked({ amount: '1,125.60', asset: 'USDS' }) + }) +}) diff --git a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSUSDS.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSUSDS.test-e2e.ts index 76c4c2be4..93facee94 100644 --- a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSUSDS.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSUSDS.test-e2e.ts @@ -1,99 +1,101 @@ -// import { SavingsDialogPageObject } from '@/features/dialogs/savings/common/e2e/SavingsDialog.PageObject' -// import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -// import { buildUrl, setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { StakeDialogPageObject } from '../../StakeDialog.PageObject' +import { SavingsDialogPageObject } from '@/features/dialogs/savings/common/e2e/SavingsDialog.PageObject' +import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +import { buildUrl, setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { StakeDialogPageObject } from '../../StakeDialog.PageObject' -// test.describe('Stake sDAI to SKY farm', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let farmDetailsPage: FarmDetailsPageObject -// let stakeDialog: StakeDialogPageObject +test.describe('Stake sUSDS to SKY farm', () => { + let farmDetailsPage: FarmDetailsPageObject + let stakeDialog: StakeDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// USDS: 1_100, -// }, -// }, -// }) -// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDS: 1_100, + }, + }, + }) + await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) -// // deposit some tokens to sUSDS first so we're able to withdraw them next -// const savingsPage = new SavingsPageObject(page) -// await savingsPage.clickDepositButtonAction('USDS') -// const depositToSavingsDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) -// await depositToSavingsDialog.clickMaxAmountAction() -// await depositToSavingsDialog.actionsContainer.acceptAllActionsAction(2) -// await depositToSavingsDialog.clickBackToSavingsButton() -// await page.goto( -// buildUrl('farmDetails', { -// chainId: mainnet.id.toString(), -// address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', -// }), -// ) + // deposit some tokens to sUSDS first so we're able to withdraw them next + const savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickDepositButtonAction('USDS') + const depositToSavingsDialog = new SavingsDialogPageObject({ testContext, type: 'deposit' }) + await depositToSavingsDialog.clickMaxAmountAction() + await depositToSavingsDialog.actionsContainer.acceptAllActionsAction(2) + await depositToSavingsDialog.clickBackToSavingsButton() + await page.goto( + buildUrl('farmDetails', { + chainId: mainnet.id.toString(), + address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', + }), + ) -// farmDetailsPage = new FarmDetailsPageObject(page) -// await farmDetailsPage.clickInfoPanelStakeButtonAction() -// stakeDialog = new StakeDialogPageObject(page) -// await stakeDialog.selectAssetAction('sUSDS') -// await stakeDialog.fillAmountAction(1_000) -// }) + farmDetailsPage = new FarmDetailsPageObject(testContext) + await farmDetailsPage.clickInfoPanelStakeButtonAction() + stakeDialog = new StakeDialogPageObject(testContext) + await stakeDialog.selectAssetAction('sUSDS') + await stakeDialog.fillAmountAction(1_000) + }) -// test('has correct action plan', async () => { -// await stakeDialog.actionsContainer.expectEnabledActionAtIndex(0) -// await stakeDialog.actionsContainer.expectActions([ -// { type: 'withdrawFromSavings', savingsAsset: 'sUSDS', asset: 'USDS', mode: 'withdraw' }, -// { type: 'approve', asset: 'USDS' }, -// { type: 'stake', stakingToken: 'USDS', rewardToken: 'SKY' }, -// ]) -// }) + test('has correct action plan', async () => { + await stakeDialog.actionsContainer.expectEnabledActionAtIndex(0) + await stakeDialog.actionsContainer.expectActions([ + { type: 'withdrawFromSavings', savingsAsset: 'sUSDS', asset: 'USDS', mode: 'withdraw' }, + { type: 'approve', asset: 'USDS' }, + { type: 'stake', stakingToken: 'USDS', rewardToken: 'SKY' }, + ]) + }) -// test('displays transaction overview', async () => { -// await stakeDialog.expectTransactionOverview({ -// estimatedRewards: { -// apy: '780.23%', -// description: 'Earn ~129,451.12 SKY/year', -// }, -// route: { -// swaps: [ -// { -// tokenAmount: '1,000.00 sUSDS', -// tokenUsdValue: '$1,000.02', -// }, -// { -// tokenAmount: '1,000.02 USDS', -// tokenUsdValue: '$1,000.02', -// }, -// ], -// final: { -// upperText: 'SKY Farm', -// lowerText: 'Deposited', -// }, -// }, -// outcome: '1,000.02 USDS', -// }) -// }) + test('displays transaction overview', async () => { + await stakeDialog.expectTransactionOverview({ + estimatedRewards: { + apy: '10.88%', + description: 'Earn ~1,835.60 SKY/year', + }, + route: { + swaps: [ + { + tokenAmount: '1,000.00 sUSDS', + tokenUsdValue: '$1,017.26', + }, + { + tokenAmount: '1,017.26 USDS', + tokenUsdValue: '$1,017.26', + }, + ], + final: { + upperText: 'SKY Farm', + lowerText: 'Deposited', + }, + }, + outcome: '1,017.26 USDS', + }) + }) -// test('executes transaction', async () => { -// await stakeDialog.actionsContainer.acceptAllActionsAction(3) + test('executes transaction', async () => { + await stakeDialog.actionsContainer.acceptAllActionsAction(3) -// await stakeDialog.expectSuccessPage() -// await stakeDialog.clickBackToFarmAction() + await stakeDialog.expectSuccessPage() + await stakeDialog.clickBackToFarmAction() -// await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') // no dust left -// await farmDetailsPage.expectReward({ -// reward: '0.01', -// rewardUsd: '<$0.01', -// }) -// await farmDetailsPage.expectStaked({ amount: '1,000.02', asset: 'USDS' }) -// }) -// }) + await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') // no dust left + await farmDetailsPage.expectReward({ + reward: '0.0001', + rewardUsd: '<$0.01', + }) + await farmDetailsPage.expectStaked({ amount: '1,017.26', asset: 'USDS' }) + }) +}) diff --git a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDC.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDC.test-e2e.ts index 44664c8d1..df1bff1ef 100644 --- a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDC.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDC.test-e2e.ts @@ -1,87 +1,89 @@ -// import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { StakeDialogPageObject } from '../../StakeDialog.PageObject' +import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { StakeDialogPageObject } from '../../StakeDialog.PageObject' -// test.describe('Stake USDC to SKY farm', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let farmDetailsPage: FarmDetailsPageObject -// let stakeDialog: StakeDialogPageObject +test.describe('Stake USDC to SKY farm', () => { + let farmDetailsPage: FarmDetailsPageObject + let stakeDialog: StakeDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'farmDetails', -// initialPageParams: { -// chainId: mainnet.id.toString(), -// address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', -// }, -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// USDC: 10_000, -// }, -// }, -// }) -// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'farmDetails', + initialPageParams: { + chainId: mainnet.id.toString(), + address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', + }, + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDC: 10_000, + }, + }, + }) + await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) -// farmDetailsPage = new FarmDetailsPageObject(page) -// await farmDetailsPage.clickInfoPanelStakeButtonAction() -// stakeDialog = new StakeDialogPageObject(page) -// await stakeDialog.selectAssetAction('USDC') -// await stakeDialog.fillAmountAction(10_000) -// }) + farmDetailsPage = new FarmDetailsPageObject(testContext) + await farmDetailsPage.clickInfoPanelStakeButtonAction() + stakeDialog = new StakeDialogPageObject(testContext) + await stakeDialog.selectAssetAction('USDC') + await stakeDialog.fillAmountAction(10_000) + }) -// test('has correct action plan', async () => { -// await stakeDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'USDC' }, -// { type: 'psmConvert', inToken: 'USDC', outToken: 'USDS' }, -// { type: 'approve', asset: 'USDS' }, -// { type: 'stake', stakingToken: 'USDS', rewardToken: 'SKY' }, -// ]) -// }) + test('has correct action plan', async () => { + await stakeDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'USDC' }, + { type: 'psmConvert', inToken: 'USDC', outToken: 'USDS' }, + { type: 'approve', asset: 'USDS' }, + { type: 'stake', stakingToken: 'USDS', rewardToken: 'SKY' }, + ]) + }) -// test('displays transaction overview', async () => { -// await stakeDialog.expectTransactionOverview({ -// estimatedRewards: { -// apy: '778.72%', -// description: 'Earn ~1,291,972.67 SKY/year', -// }, -// route: { -// swaps: [ -// { -// tokenAmount: '10,000.00 USDC', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// final: { -// upperText: 'SKY Farm', -// lowerText: 'Deposited', -// }, -// }, -// outcome: '10,000.00 USD', -// }) -// }) + test('displays transaction overview', async () => { + await stakeDialog.expectTransactionOverview({ + estimatedRewards: { + apy: '10.88%', + description: 'Earn ~18,044.13 SKY/year', + }, + route: { + swaps: [ + { + tokenAmount: '10,000.00 USDC', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + ], + final: { + upperText: 'SKY Farm', + lowerText: 'Deposited', + }, + }, + outcome: '10,000.00 USD', + }) + }) -// test('executes transaction', async () => { -// await stakeDialog.actionsContainer.acceptAllActionsAction(4) + test('executes transaction', async () => { + await stakeDialog.actionsContainer.acceptAllActionsAction(4) -// await stakeDialog.expectSuccessPage() -// await stakeDialog.clickBackToFarmAction() + await stakeDialog.expectSuccessPage() + await stakeDialog.clickBackToFarmAction() -// await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') -// await farmDetailsPage.expectReward({ -// reward: '0.1', -// rewardUsd: '<$0.01', -// }) -// await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) -// }) -// }) + await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') + await farmDetailsPage.expectReward({ + reward: '0.001', + rewardUsd: '<$0.01', + }) + await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) + }) +}) diff --git a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDS.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDS.test-e2e.ts index 3526c182c..4dea525ce 100644 --- a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDS.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDS.test-e2e.ts @@ -1,162 +1,167 @@ -// import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { privateKeyToAddress } from 'viem/accounts' -// import { mainnet } from 'viem/chains' -// import { StakeDialogPageObject } from '../../StakeDialog.PageObject' - -// test.describe('Stake USDS to SKY farm', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let farmDetailsPage: FarmDetailsPageObject -// let stakeDialog: StakeDialogPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'farmDetails', -// initialPageParams: { -// chainId: mainnet.id.toString(), -// address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', -// }, -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// USDS: 10_000, -// }, -// }, -// }) -// await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) - -// farmDetailsPage = new FarmDetailsPageObject(page) -// await farmDetailsPage.clickInfoPanelStakeButtonAction() -// stakeDialog = new StakeDialogPageObject(page) -// await stakeDialog.fillAmountAction(10_000) -// }) - -// test('has correct action plan', async () => { -// await stakeDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'USDS' }, -// { type: 'stake', stakingToken: 'USDS', rewardToken: 'SKY' }, -// ]) -// }) - -// test('displays transaction overview', async () => { -// await stakeDialog.expectTransactionOverview({ -// estimatedRewards: { -// apy: '778.72%', -// description: 'Earn ~1,291,972.67 SKY/year', -// }, -// route: { -// swaps: [ -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// final: { -// upperText: 'SKY Farm', -// lowerText: 'Deposited', -// }, -// }, -// outcome: '10,000.00 USD', -// }) -// }) - -// test('executes transaction', async () => { -// await stakeDialog.actionsContainer.acceptAllActionsAction(2) - -// await stakeDialog.expectSuccessPage() -// await stakeDialog.clickBackToFarmAction() - -// await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') -// await farmDetailsPage.expectReward({ -// reward: '0.1', -// rewardUsd: '<$0.01', -// }) -// await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) -// }) -// }) - -// test.describe('Stake USDS to CLE farm', () => { -// const testUserPKey = '0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5' -// const testUserAddress = privateKeyToAddress('0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5') -// const harSuffix = testUserAddress.slice(0, 10) - -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let farmDetailsPage: FarmDetailsPageObject -// let stakeDialog: StakeDialogPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'farmDetails', -// initialPageParams: { -// chainId: mainnet.id.toString(), -// address: '0x10ab606B067C9C461d8893c47C7512472E19e2Ce', -// }, -// account: { -// type: 'connected-pkey', -// privateKey: testUserPKey, -// assetBalances: { -// ETH: 1, -// USDS: 10_000, -// }, -// }, -// }) -// await overrideInfoSkyRouteWithHAR({ page, key: `2-cle-farm-0-balance-${harSuffix}` }) - -// farmDetailsPage = new FarmDetailsPageObject(page) -// await farmDetailsPage.clickInfoPanelStakeButtonAction() -// stakeDialog = new StakeDialogPageObject(page) -// await stakeDialog.fillAmountAction(10_000) -// }) - -// test('has correct action plan', async () => { -// await stakeDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'USDS' }, -// { type: 'stake', stakingToken: 'USDS', rewardToken: 'CLE' }, -// ]) -// }) - -// test('displays transaction overview', async () => { -// await stakeDialog.expectTransactionOverview({ -// route: { -// swaps: [ -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// final: { -// upperText: 'CLE Farm', -// lowerText: 'Deposited', -// }, -// }, -// outcome: '10,000.00 USDS', -// }) -// }) - -// test('executes transaction', async ({ page }) => { -// await stakeDialog.actionsContainer.acceptAllActionsAction(2) - -// await stakeDialog.expectSuccessPage() -// await stakeDialog.clickBackToFarmAction() - -// await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') -// await farmDetailsPage.expectReward({ -// reward: '0.0', -// }) -// await farmDetailsPage.expectPointsSyncWarning() -// await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) - -// await overrideInfoSkyRouteWithHAR({ page, key: `3-cle-farm-10000-balance-${harSuffix}` }) - -// await farmDetailsPage.expectReward({ -// reward: '257.6', -// }) -// await farmDetailsPage.expectPointsSyncWarningToBeHidden() -// await farmDetailsPage.expectInfoPanelClaimButtonToBeHidden() -// }) -// }) +import { FarmDetailsPageObject } from '@/features/farm-details/FarmDetails.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { privateKeyToAddress } from 'viem/accounts' +import { mainnet } from 'viem/chains' +import { StakeDialogPageObject } from '../../StakeDialog.PageObject' + +test.describe('Stake USDS to SKY farm', () => { + let farmDetailsPage: FarmDetailsPageObject + let stakeDialog: StakeDialogPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'farmDetails', + initialPageParams: { + chainId: mainnet.id.toString(), + address: '0x0650CAF159C5A49f711e8169D4336ECB9b950275', + }, + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDS: 10_000, + }, + }, + }) + await overrideInfoSkyRouteWithHAR({ page, key: '1-sky-farm-with-8_51-apy' }) + + farmDetailsPage = new FarmDetailsPageObject(testContext) + await farmDetailsPage.clickInfoPanelStakeButtonAction() + stakeDialog = new StakeDialogPageObject(testContext) + await stakeDialog.fillAmountAction(10_000) + }) + + test('has correct action plan', async () => { + await stakeDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'USDS' }, + { type: 'stake', stakingToken: 'USDS', rewardToken: 'SKY' }, + ]) + }) + + test('displays transaction overview', async () => { + await stakeDialog.expectTransactionOverview({ + estimatedRewards: { + apy: '10.88%', + description: 'Earn ~18,044.13 SKY/year', + }, + route: { + swaps: [ + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + ], + final: { + upperText: 'SKY Farm', + lowerText: 'Deposited', + }, + }, + outcome: '10,000.00 USD', + }) + }) + + test('executes transaction', async () => { + await stakeDialog.actionsContainer.acceptAllActionsAction(2) + + await stakeDialog.expectSuccessPage() + await stakeDialog.clickBackToFarmAction() + + await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') + await farmDetailsPage.expectReward({ + reward: '0.001', + rewardUsd: '<$0.01', + }) + await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) + }) +}) + +test.describe('Stake USDS to CLE farm', () => { + const testUserPKey = '0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5' + const testUserAddress = privateKeyToAddress('0xa9f2d3eda4403df2fe54b97291d65d69824e0e2b3134c33b7145cf9b912966d5') + const harSuffix = testUserAddress.slice(0, 10) + + let farmDetailsPage: FarmDetailsPageObject + let stakeDialog: StakeDialogPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'farmDetails', + initialPageParams: { + chainId: mainnet.id.toString(), + address: '0x10ab606B067C9C461d8893c47C7512472E19e2Ce', + }, + account: { + type: 'connected-pkey', + privateKey: testUserPKey, + assetBalances: { + ETH: 1, + USDS: 10_000, + }, + }, + }) + await overrideInfoSkyRouteWithHAR({ page, key: `2-cle-farm-0-balance-${harSuffix}` }) + + farmDetailsPage = new FarmDetailsPageObject(testContext) + await farmDetailsPage.clickInfoPanelStakeButtonAction() + stakeDialog = new StakeDialogPageObject(testContext) + await stakeDialog.fillAmountAction(10_000) + }) + + test('has correct action plan', async () => { + await stakeDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'USDS' }, + { type: 'stake', stakingToken: 'USDS', rewardToken: 'CLE' }, + ]) + }) + + test('displays transaction overview', async () => { + await stakeDialog.expectTransactionOverview({ + route: { + swaps: [ + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + ], + final: { + upperText: 'CLE Farm', + lowerText: 'Deposited', + }, + }, + outcome: '10,000.00 USDS', + }) + }) + + test('executes transaction', async ({ page }) => { + await stakeDialog.actionsContainer.acceptAllActionsAction(2) + + await stakeDialog.expectSuccessPage() + await stakeDialog.clickBackToFarmAction() + + await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') + await farmDetailsPage.expectReward({ + reward: '0.0', + }) + await farmDetailsPage.expectPointsSyncWarning() + await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) + + await overrideInfoSkyRouteWithHAR({ page, key: `3-cle-farm-10000-balance-${harSuffix}` }) + + await farmDetailsPage.expectReward({ + reward: '257.6', + }) + await farmDetailsPage.expectPointsSyncWarningToBeHidden() + await farmDetailsPage.expectInfoPanelClaimButtonToBeHidden() + }) +}) From c068e8f5cd89910f4023576569418fe2e4368d81 Mon Sep 17 00:00:00 2001 From: Oskar <43062492+oskarvu@users.noreply.github.com> Date: Thu, 19 Dec 2024 19:39:06 +0700 Subject: [PATCH 19/29] Rewrite claim rewards dialog tests (#508) --- .../ClaimRewardsDialog.PageObject.ts | 70 +++++----- .../ClaimRewardsDialog.test-e2e.ts | 125 +++++++++--------- 2 files changed, 95 insertions(+), 100 deletions(-) diff --git a/packages/app/src/features/dialogs/claim-rewards/ClaimRewardsDialog.PageObject.ts b/packages/app/src/features/dialogs/claim-rewards/ClaimRewardsDialog.PageObject.ts index ca66a4daf..e7ba2d752 100644 --- a/packages/app/src/features/dialogs/claim-rewards/ClaimRewardsDialog.PageObject.ts +++ b/packages/app/src/features/dialogs/claim-rewards/ClaimRewardsDialog.PageObject.ts @@ -1,41 +1,39 @@ -// import { Locator, Page, expect } from '@playwright/test' +import { TestContext } from '@/test/e2e/setup' +import { testIds } from '@/ui/utils/testIds' +import { Locator, expect } from '@playwright/test' +import { DialogPageObject } from '../common/Dialog.PageObject' -// import { testIds } from '@/ui/utils/testIds' +export class ClaimRewardsDialogPageObject extends DialogPageObject { + constructor(testContext: TestContext) { + super({ testContext, header: /Claim rewards/ }) + } -// import { DialogPageObject } from '../common/Dialog.PageObject' + // #region assertions + async expectRewards(rows: Reward[], locator?: Locator): Promise { + if (!locator) { + locator = this.region + } -// export class ClaimRewardsDialogPageObject extends DialogPageObject { -// constructor(page: Page) { -// super(page, /.*/) -// this.region = this.locateDialogByHeader('Claim rewards') -// } + for (const [index, row] of rows.entries()) { + const rowLocator = this.page.getByTestId(testIds.dialog.claimRewards.transactionOverview.row(index)).first() + await expect(rowLocator.getByTestId(testIds.dialog.claimRewards.transactionOverview.amount)).toHaveText( + `${row.amount} ${row.tokenSymbol}`, + ) + await expect(rowLocator.getByTestId(testIds.dialog.claimRewards.transactionOverview.amountUSD)).toHaveText( + row.amountUSD, + ) + } + } -// // #region assertions -// async expectRewards(rows: Reward[], locator?: Locator): Promise { -// if (!locator) { -// locator = this.region -// } + async expectClaimRewardsSuccessPage(rows: Reward[]): Promise { + await expect(this.page.getByRole('heading', { name: 'Congrats, all done!' })).toBeVisible() + await this.expectRewards(rows, this.page.getByTestId(testIds.dialog.success)) + } + // #endregion assertions +} -// for (const [index, row] of rows.entries()) { -// const rowLocator = this.page.getByTestId(testIds.dialog.claimRewards.transactionOverview.row(index)).first() -// await expect(rowLocator.getByTestId(testIds.dialog.claimRewards.transactionOverview.amount)).toHaveText( -// `${row.amount} ${row.tokenSymbol}`, -// ) -// await expect(rowLocator.getByTestId(testIds.dialog.claimRewards.transactionOverview.amountUSD)).toHaveText( -// row.amountUSD, -// ) -// } -// } - -// async expectClaimRewardsSuccessPage(rows: Reward[]): Promise { -// await expect(this.page.getByRole('heading', { name: 'Congrats, all done!' })).toBeVisible() -// await this.expectRewards(rows, this.page.getByTestId(testIds.dialog.success)) -// } -// // #endregion assertions -// } - -// interface Reward { -// tokenSymbol: string -// amount: string -// amountUSD: string -// } +interface Reward { + tokenSymbol: string + amount: string + amountUSD: string +} diff --git a/packages/app/src/features/dialogs/claim-rewards/ClaimRewardsDialog.test-e2e.ts b/packages/app/src/features/dialogs/claim-rewards/ClaimRewardsDialog.test-e2e.ts index 7d1de43c6..c807d0c0e 100644 --- a/packages/app/src/features/dialogs/claim-rewards/ClaimRewardsDialog.test-e2e.ts +++ b/packages/app/src/features/dialogs/claim-rewards/ClaimRewardsDialog.test-e2e.ts @@ -1,75 +1,72 @@ -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' +import { TopbarPageObject } from '@/features/topbar/Topbar.PageObject' +import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { TestContext, setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { ClaimRewardsDialogPageObject } from './ClaimRewardsDialog.PageObject' -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { TopbarPageObject } from '@/features/topbar/Topbar.PageObject' -// import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { ClaimRewardsDialogPageObject } from './ClaimRewardsDialog.PageObject' +test.describe('Claim rewards dialog', () => { + let navbar: TopbarPageObject + let claimRewardsDialog: ClaimRewardsDialogPageObject + let testContext: TestContext<'connected-address'> -// test.describe('Claim rewards dialog', () => { -// const fork = setupFork({ -// blockNumber: 20189272n, // block number where the reward program is finished -// chainId: mainnet.id, -// }) -// let navbar: TopbarPageObject -// let claimRewardsDialog: ClaimRewardsDialogPageObject -// let actionsContainer: ActionsPageObject + test.beforeEach(async ({ page }) => { + testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-address', + address: '0xf8de75c7b95edb6f1e639751318f117663021cf0', + }, + }) -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-address', -// address: '0xf8de75c7b95edb6f1e639751318f117663021cf0', -// }, -// }) + navbar = new TopbarPageObject(testContext) + await navbar.openClaimRewardsDialog() -// navbar = new TopbarPageObject(page) -// await navbar.openClaimRewardsDialog() + claimRewardsDialog = new ClaimRewardsDialogPageObject(testContext) + }) -// claimRewardsDialog = new ClaimRewardsDialogPageObject(page) -// actionsContainer = new ActionsPageObject(claimRewardsDialog.locatePanelByHeader('Actions')) -// }) + test('displays correct transaction overview', async () => { + await claimRewardsDialog.expectRewards([ + { + tokenSymbol: 'wstETH', + amount: '6.3697', + amountUSD: '$29,717.60', + }, + ]) + }) -// test('displays correct transaction overview', async () => { -// await claimRewardsDialog.expectRewards([ -// { -// tokenSymbol: 'wstETH', -// amount: '6.3697', -// amountUSD: '$25,583.20', -// }, -// ]) -// }) + test('has correct action plan', async () => { + await claimRewardsDialog.actionsContainer.expectActions([ + { + type: 'claimMarketRewards', + asset: 'wstETH', + }, + ]) + }) -// test('has correct action plan', async () => { -// await actionsContainer.expectActions([ -// { -// type: 'claimMarketRewards', -// asset: 'wstETH', -// }, -// ]) -// }) + test('executes transaction', async () => { + await claimRewardsDialog.actionsContainer.acceptAllActionsAction(1) -// test('executes transaction', async ({ page }) => { -// await actionsContainer.acceptAllActionsAction(1) + await claimRewardsDialog.expectClaimRewardsSuccessPage([ + { + tokenSymbol: 'wstETH', + amount: '6.3697', + amountUSD: '$29,717.60', + }, + ]) -// await claimRewardsDialog.expectClaimRewardsSuccessPage([ -// { -// tokenSymbol: 'wstETH', -// amount: '6.3697', -// amountUSD: '$25,583.20', -// }, -// ]) + const myPortfolioPage = new MyPortfolioPageObject(testContext) + await myPortfolioPage.goToMyPortfolioAction() -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.goToMyPortfolioAction() + await myPortfolioPage.expectBalancesInDepositTable({ + wstETH: 6.3697, + }) -// await myPortfolioPage.expectBalancesInDepositTable({ -// wstETH: 6.3697, -// }) - -// await navbar.expectRewardsBadgeNotVisible() -// }) -// }) + await navbar.expectRewardsBadgeNotVisible() + }) +}) From 846543d71ac3efad929545ae206449deac851e62 Mon Sep 17 00:00:00 2001 From: Vladyslav Yatsenko <52505649+yivlad@users.noreply.github.com> Date: Fri, 20 Dec 2024 10:41:44 +0100 Subject: [PATCH 20/29] Rewrite deposit to savings E2E tests (#511) --- .../deposit/SavingsDepositDialog.test-e2e.ts | 157 --------- .../savings/deposit/e2e/General.test-e2e.ts | 154 +++++++++ .../deposit/e2e/Validation.test-e2e.ts | 95 ++++++ .../e2e/mainnet/DepositDAI.test-e2e.ts | 313 +++++++++--------- .../e2e/mainnet/DepositUSDC.test-e2e.ts | 223 +++++++------ .../e2e/mainnet/DepositUSDS.test-e2e.ts | 128 +++---- .../deposit/e2e/mainnet/General.test-e2e.ts | 60 ---- .../e2e/mainnet/Validation.test-e2e.ts | 89 ----- 8 files changed, 580 insertions(+), 639 deletions(-) delete mode 100644 packages/app/src/features/dialogs/savings/deposit/SavingsDepositDialog.test-e2e.ts create mode 100644 packages/app/src/features/dialogs/savings/deposit/e2e/General.test-e2e.ts create mode 100644 packages/app/src/features/dialogs/savings/deposit/e2e/Validation.test-e2e.ts delete mode 100644 packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/General.test-e2e.ts delete mode 100644 packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/Validation.test-e2e.ts diff --git a/packages/app/src/features/dialogs/savings/deposit/SavingsDepositDialog.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/SavingsDepositDialog.test-e2e.ts deleted file mode 100644 index 2b8993b94..000000000 --- a/packages/app/src/features/dialogs/savings/deposit/SavingsDepositDialog.test-e2e.ts +++ /dev/null @@ -1,157 +0,0 @@ -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { GNOSIS_DEFAULT_BLOCK_NUMBER, DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { base, gnosis, mainnet } from 'viem/chains' -// import { SavingsDialogPageObject } from '../common/e2e/SavingsDialog.PageObject' - -// test.describe('Savings deposit dialog', () => { -// test.describe('Mainnet', () => { -// const fork = setupFork({ -// blockNumber: DEFAULT_BLOCK_NUMBER, -// chainId: mainnet.id, -// useTenderlyVnet: true, -// }) - -// let depositDialog: SavingsDialogPageObject -// let savingsPage: SavingsPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// DAI: 10_000, -// USDC: 10_000, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickStartSavingButtonAction() - -// depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) -// }) - -// test('can switch between tokens', async () => { -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - -// await depositDialog.fillAmountAction(1000) -// await actionsContainer.expectEnabledActionAtIndex(0) -// await actionsContainer.expectActions([ -// { type: 'approve', asset: 'DAI' }, -// { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sDAI' }, -// ]) - -// await depositDialog.selectAssetAction('USDC') -// await depositDialog.fillAmountAction(1000) -// await actionsContainer.expectEnabledActionAtIndex(0) -// await actionsContainer.expectActions([ -// { type: 'approve', asset: 'USDC' }, -// { type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sDAI' }, -// ]) - -// await depositDialog.selectAssetAction('DAI') -// await depositDialog.fillAmountAction(1000) -// await actionsContainer.expectEnabledActionAtIndex(0) -// await actionsContainer.expectActions([ -// { type: 'approve', asset: 'DAI' }, -// { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sDAI' }, -// ]) -// }) - -// test('can select only supported assets', async () => { -// await depositDialog.openAssetSelectorAction() -// await depositDialog.expectAssetSelectorOptions(['DAI', 'USDC']) -// }) -// }) - -// test.describe('Gnosis', () => { -// const fork = setupFork({ blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let depositDialog: SavingsDialogPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// XDAI: 100, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickStartSavingButtonAction() - -// depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) -// }) - -// test('can select only supported assets', async () => { -// await depositDialog.openAssetSelectorAction() -// await depositDialog.expectAssetSelectorOptions(['XDAI']) -// }) -// }) - -// test.describe('Base', () => { -// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) - -// let depositDialog: SavingsDialogPageObject -// let savingsPage: SavingsPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// USDC: 1000, -// USDS: 10_000, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickStartSavingButtonAction() - -// depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) -// }) - -// test('can switch between tokens', async () => { -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - -// await depositDialog.fillAmountAction(1000) -// await actionsContainer.expectEnabledActionAtIndex(0) -// await actionsContainer.expectActions([ -// { type: 'approve', asset: 'USDS' }, -// { type: 'depositToSavings', asset: 'USDS', savingsAsset: 'sUSDS' }, -// ]) - -// await depositDialog.selectAssetAction('USDC') -// await depositDialog.fillAmountAction(1000) -// await actionsContainer.expectEnabledActionAtIndex(0) -// await actionsContainer.expectActions([ -// { type: 'approve', asset: 'USDC' }, -// { type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sUSDS' }, -// ]) - -// await depositDialog.selectAssetAction('USDS') -// await depositDialog.fillAmountAction(1000) -// await actionsContainer.expectEnabledActionAtIndex(0) -// await actionsContainer.expectActions([ -// { type: 'approve', asset: 'USDS' }, -// { type: 'depositToSavings', asset: 'USDS', savingsAsset: 'sUSDS' }, -// ]) -// }) - -// test('can select only supported assets', async () => { -// await depositDialog.openAssetSelectorAction() -// await depositDialog.expectAssetSelectorOptions(['USDC', 'USDS']) -// }) -// }) -// }) diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/General.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/General.test-e2e.ts new file mode 100644 index 000000000..262bdd9d4 --- /dev/null +++ b/packages/app/src/features/dialogs/savings/deposit/e2e/General.test-e2e.ts @@ -0,0 +1,154 @@ +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { BASE_DEFAULT_BLOCK_NUMBER, DEFAULT_BLOCK_NUMBER, GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { base, gnosis, mainnet } from 'viem/chains' +import { SavingsDialogPageObject } from '../../common/e2e/SavingsDialog.PageObject' + +test.describe('Savings deposit dialog', () => { + test.describe('Mainnet', () => { + let depositDialog: SavingsDialogPageObject + let savingsPage: SavingsPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + DAI: 10_000, + USDC: 10_000, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickStartSavingButtonAction() + + depositDialog = new SavingsDialogPageObject({ testContext, type: 'deposit' }) + }) + + test('can switch between tokens', async () => { + await depositDialog.fillAmountAction(1000) + await depositDialog.actionsContainer.expectEnabledActionAtIndex(0) + await depositDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'DAI' }, + { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sUSDS' }, + ]) + + await depositDialog.selectAssetAction('USDC') + await depositDialog.fillAmountAction(1000) + await depositDialog.actionsContainer.expectEnabledActionAtIndex(0) + await depositDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'USDC' }, + { type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sUSDS' }, + ]) + + await depositDialog.selectAssetAction('DAI') + await depositDialog.fillAmountAction(1000) + await depositDialog.actionsContainer.expectEnabledActionAtIndex(0) + await depositDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'DAI' }, + { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sUSDS' }, + ]) + }) + + test('can select only supported assets', async () => { + await depositDialog.openAssetSelectorAction() + await depositDialog.expectAssetSelectorOptions(['DAI', 'USDC', 'USDS']) + }) + }) + + test.describe('Gnosis', () => { + let savingsPage: SavingsPageObject + let depositDialog: SavingsDialogPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: gnosis.id, + blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + XDAI: 100, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickStartSavingButtonAction() + + depositDialog = new SavingsDialogPageObject({ testContext, type: 'deposit' }) + }) + + test('can select only supported assets', async () => { + await depositDialog.openAssetSelectorAction() + await depositDialog.expectAssetSelectorOptions(['XDAI']) + }) + }) + + test.describe('Base', () => { + let depositDialog: SavingsDialogPageObject + let savingsPage: SavingsPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: base.id, + blockNumber: BASE_DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + USDC: 1000, + USDS: 10_000, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickStartSavingButtonAction() + + depositDialog = new SavingsDialogPageObject({ testContext, type: 'deposit' }) + }) + + test('can switch between tokens', async () => { + await depositDialog.fillAmountAction(1000) + await depositDialog.actionsContainer.expectEnabledActionAtIndex(0) + await depositDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'USDS' }, + { type: 'depositToSavings', asset: 'USDS', savingsAsset: 'sUSDS' }, + ]) + + await depositDialog.selectAssetAction('USDC') + await depositDialog.fillAmountAction(1000) + await depositDialog.actionsContainer.expectEnabledActionAtIndex(0) + await depositDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'USDC' }, + { type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sUSDS' }, + ]) + + await depositDialog.selectAssetAction('USDS') + await depositDialog.fillAmountAction(1000) + await depositDialog.actionsContainer.expectEnabledActionAtIndex(0) + await depositDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'USDS' }, + { type: 'depositToSavings', asset: 'USDS', savingsAsset: 'sUSDS' }, + ]) + }) + + test('can select only supported assets', async () => { + await depositDialog.openAssetSelectorAction() + await depositDialog.expectAssetSelectorOptions(['USDC', 'USDS']) + }) + }) +}) diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/Validation.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/Validation.test-e2e.ts new file mode 100644 index 000000000..5e6a00166 --- /dev/null +++ b/packages/app/src/features/dialogs/savings/deposit/e2e/Validation.test-e2e.ts @@ -0,0 +1,95 @@ +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { SavingsDialogPageObject } from '../../common/e2e/SavingsDialog.PageObject' +import { depositValidationIssueToMessage } from '../logic/validation' + +test.describe('Validation', () => { + let savingsPage: SavingsPageObject + let depositDialog: SavingsDialogPageObject + + test.describe('Input value exceeds balance', () => { + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDS: 100, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickDepositButtonAction('USDS') + + depositDialog = new SavingsDialogPageObject({ testContext, type: 'deposit' }) + await depositDialog.fillAmountAction(10_000) + }) + + test('displays validation error', async () => { + await depositDialog.expectAssetInputError(depositValidationIssueToMessage['exceeds-balance']) + }) + + test('actions are disabled', async () => { + await depositDialog.actionsContainer.expectDisabledActions([ + { type: 'approve', asset: 'USDS' }, + { type: 'depositToSavings', asset: 'USDS', savingsAsset: 'sUSDS' }, + ]) + }) + + test('displays sensible tx overview', async () => { + await depositDialog.expectNativeRouteTransactionOverview({ + apy: { + value: '12.50%', + description: 'Earn ~1,250.00 USDS/year', + }, + routeItems: [ + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '9,830.34 sUSDS', + tokenUsdValue: '$10,000.00', + }, + ], + outcome: '9,830.34 sUSDS', + outcomeUsd: '$10,000.00', + }) + }) + }) + + test('displays validation error for dirty input with 0 value', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDS: 100, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickDepositButtonAction('USDS') + depositDialog = new SavingsDialogPageObject({ testContext, type: 'deposit' }) + + await depositDialog.fillAmountAction(10) + await depositDialog.fillAmountAction(0) + + await depositDialog.expectAssetInputError(depositValidationIssueToMessage['value-not-positive']) + }) +}) diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositDAI.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositDAI.test-e2e.ts index 17dfb8af3..edcff50d1 100644 --- a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositDAI.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositDAI.test-e2e.ts @@ -1,157 +1,156 @@ -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' - -// test.describe('Deposit DAI', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let depositDialog: SavingsDialogPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// DAI: 10_000, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickDepositButtonAction('DAI') - -// depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) -// await depositDialog.fillAmountAction(10_000) -// }) - -// test.describe('To sUSDS', () => { -// test('uses PSM actions native deposit', async () => { -// await depositDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'DAI' }, -// { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sUSDS' }, -// ]) -// }) - -// test('displays transaction overview', async () => { -// await depositDialog.expectNativeRouteTransactionOverview({ -// apy: { -// value: '6.25%', -// description: 'Earn ~625.00 USDS/year', -// }, -// routeItems: [ -// { -// tokenAmount: '10,000.00 DAI', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '9,999.77 sUSDS', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// outcome: '9,999.77 sUSDS', -// outcomeUsd: '$10,000.00', -// }) -// }) - -// test('executes deposit', async () => { -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) - -// await depositDialog.expectSuccessPage() -// await depositDialog.clickBackToSavingsButton() - -// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,999.77 sUSDS', estimatedUsdsValue: '10,000' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') -// }) -// }) - -// test.describe('To sDAI', () => { -// test.beforeEach(async () => { -// await depositDialog.clickUpgradeSwitch() -// }) - -// test('uses PSM actions native deposit', async () => { -// await depositDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'DAI' }, -// { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sDAI' }, -// ]) -// }) - -// test('displays transaction overview', async () => { -// await depositDialog.expectNativeRouteTransactionOverview({ -// apy: { -// value: '6.00%', -// description: 'Earn ~600.00 DAI/year', -// }, -// routeItems: [ -// { -// tokenAmount: '10,000.00 DAI', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '9,020.46 sDAI', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// outcome: '9,020.46 sDAI', -// outcomeUsd: '$10,000.00', -// }) -// }) - -// test('executes deposit', async () => { -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) - -// await depositDialog.expectSuccessPage() -// await depositDialog.clickBackToSavingsButton() - -// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '9,020.46 sDAI', estimatedDaiValue: '10,000' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') -// }) -// }) - -// test('executes sDai deposit after switching from already approved sUsds', async () => { -// // accepting only approve -// await depositDialog.actionsContainer.acceptAllActionsAction(1) -// await depositDialog.actionsContainer.expectEnabledActionAtIndex(1) -// // switching to sDai deposit when already approved sUsds -// await depositDialog.clickUpgradeSwitch() -// // actions should reset and new approval is required -// await depositDialog.actionsContainer.acceptAllActionsAction(2) - -// await depositDialog.expectSuccessPage() -// await depositDialog.clickBackToSavingsButton() - -// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '9,020.46 sDAI', estimatedDaiValue: '10,000' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') -// }) - -// test('executes sUsds deposit after switching from already approved sUsds and back', async () => { -// // accepting only approve -// await depositDialog.actionsContainer.acceptAllActionsAction(1) -// await depositDialog.actionsContainer.expectEnabledActionAtIndex(1) -// // switching to sDai deposit and back to sUsds -// await depositDialog.clickUpgradeSwitch() -// await depositDialog.actionsContainer.expectEnabledActionAtIndex(0) -// await depositDialog.clickUpgradeSwitch() -// // approval should be already successful, only deposit needed -// await depositDialog.actionsContainer.acceptActionAtIndex(1) - -// await depositDialog.expectSuccessPage() -// await depositDialog.clickBackToSavingsButton() - -// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,999.77 sUSDS', estimatedUsdsValue: '10,000' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') -// }) -// }) +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' + +test.describe('Deposit DAI', () => { + let savingsPage: SavingsPageObject + let depositDialog: SavingsDialogPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + DAI: 10_000, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickDepositButtonAction('DAI') + + depositDialog = new SavingsDialogPageObject({ testContext, type: 'deposit' }) + await depositDialog.fillAmountAction(10_000) + }) + + test.describe('To sUSDS', () => { + test('uses PSM actions native deposit', async () => { + await depositDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'DAI' }, + { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sUSDS' }, + ]) + }) + + test('displays transaction overview', async () => { + await depositDialog.expectNativeRouteTransactionOverview({ + apy: { + value: '12.50%', + description: 'Earn ~1,250.00 USDS/year', + }, + routeItems: [ + { + tokenAmount: '10,000.00 DAI', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '9,830.34 sUSDS', + tokenUsdValue: '$10,000.00', + }, + ], + outcome: '9,830.34 sUSDS', + outcomeUsd: '$10,000.00', + }) + }) + + test('executes deposit', async () => { + await depositDialog.actionsContainer.acceptAllActionsAction(2) + + await depositDialog.expectSuccessPage() + await depositDialog.clickBackToSavingsButton() + + await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,830.34 sUSDS', estimatedUsdsValue: '10,000' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') + }) + }) + + test.describe('To sDAI', () => { + test.beforeEach(async () => { + await depositDialog.clickUpgradeSwitch() + }) + + test('uses PSM actions native deposit', async () => { + await depositDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'DAI' }, + { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sDAI' }, + ]) + }) + + test('displays transaction overview', async () => { + await depositDialog.expectNativeRouteTransactionOverview({ + apy: { + value: '11.50%', + description: 'Earn ~1,150.00 DAI/year', + }, + routeItems: [ + { + tokenAmount: '10,000.00 DAI', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '8,884.16 sDAI', + tokenUsdValue: '$10,000.00', + }, + ], + outcome: '8,884.16 sDAI', + outcomeUsd: '$10,000.00', + }) + }) + + test('executes deposit', async () => { + await depositDialog.actionsContainer.acceptAllActionsAction(2) + + await depositDialog.expectSuccessPage() + await depositDialog.clickBackToSavingsButton() + + await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '8,884.16 sDAI', estimatedDaiValue: '10,000' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') + }) + }) + + test('executes sDai deposit after switching from already approved sUsds', async () => { + // accepting only approve + await depositDialog.actionsContainer.acceptAllActionsAction(1) + await depositDialog.actionsContainer.expectEnabledActionAtIndex(1) + // switching to sDai deposit when already approved sUsds + await depositDialog.clickUpgradeSwitch() + // actions should reset and new approval is required + await depositDialog.actionsContainer.acceptAllActionsAction(2) + + await depositDialog.expectSuccessPage() + await depositDialog.clickBackToSavingsButton() + + await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '8,884.16 sDAI', estimatedDaiValue: '10,000' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') + }) + + test('executes sUsds deposit after switching from already approved sUsds and back', async () => { + // accepting only approve + await depositDialog.actionsContainer.acceptAllActionsAction(1) + await depositDialog.actionsContainer.expectEnabledActionAtIndex(1) + // switching to sDai deposit and back to sUsds + await depositDialog.clickUpgradeSwitch() + await depositDialog.actionsContainer.expectEnabledActionAtIndex(0) + await depositDialog.clickUpgradeSwitch() + // approval should be already successful, only deposit needed + await depositDialog.actionsContainer.acceptActionAtIndex(1) + + await depositDialog.expectSuccessPage() + await depositDialog.clickBackToSavingsButton() + + await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,830.34 sUSDS', estimatedUsdsValue: '10,000' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDC.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDC.test-e2e.ts index 10f44f77f..d5f627c79 100644 --- a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDC.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDC.test-e2e.ts @@ -1,127 +1,126 @@ -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -// test.describe('Deposit USDC', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let depositDialog: SavingsDialogPageObject +test.describe('Deposit USDC', () => { + let savingsPage: SavingsPageObject + let depositDialog: SavingsDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// USDC: 10_000, -// }, -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDC: 10_000, + }, + }, + }) -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickDepositButtonAction('USDC') + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickDepositButtonAction('USDC') -// depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) -// await depositDialog.fillAmountAction(10_000) -// }) + depositDialog = new SavingsDialogPageObject({ testContext, type: 'deposit' }) + await depositDialog.fillAmountAction(10_000) + }) -// test.describe('To sUSDS', () => { -// test('uses PSM actions native deposit', async () => { -// await depositDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'USDC' }, -// { type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sUSDS' }, -// ]) -// }) + test.describe('To sUSDS', () => { + test('uses PSM actions native deposit', async () => { + await depositDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'USDC' }, + { type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sUSDS' }, + ]) + }) -// test('displays transaction overview', async () => { -// await depositDialog.expectNativeRouteTransactionOverview({ -// apy: { -// value: '6.25%', -// description: 'Earn ~625.00 USDS/year', -// }, -// routeItems: [ -// { -// tokenAmount: '10,000.00 USDC', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '9,999.77 sUSDS', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// outcome: '9,999.77 sUSDS', -// outcomeUsd: '$10,000.00', -// }) -// }) + test('displays transaction overview', async () => { + await depositDialog.expectNativeRouteTransactionOverview({ + apy: { + value: '12.50%', + description: 'Earn ~1,250.00 USDS/year', + }, + routeItems: [ + { + tokenAmount: '10,000.00 USDC', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '9,830.34 sUSDS', + tokenUsdValue: '$10,000.00', + }, + ], + outcome: '9,830.34 sUSDS', + outcomeUsd: '$10,000.00', + }) + }) -// test('executes deposit', async () => { -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) + test('executes deposit', async () => { + await depositDialog.actionsContainer.acceptAllActionsAction(2) -// await depositDialog.expectSuccessPage() -// await depositDialog.clickBackToSavingsButton() + await depositDialog.expectSuccessPage() + await depositDialog.clickBackToSavingsButton() -// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,999.77 sUSDS', estimatedUsdsValue: '10,000' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') -// }) -// }) + await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,830.34 sUSDS', estimatedUsdsValue: '10,000' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') + }) + }) -// test.describe('To sDAI', () => { -// test.beforeEach(async () => { -// await depositDialog.clickUpgradeSwitch() -// }) + test.describe('To sDAI', () => { + test.beforeEach(async () => { + await depositDialog.clickUpgradeSwitch() + }) -// test('uses PSM actions native deposit', async () => { -// await depositDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'USDC' }, -// { type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sDAI' }, -// ]) -// }) + test('uses PSM actions native deposit', async () => { + await depositDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'USDC' }, + { type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sDAI' }, + ]) + }) -// test('displays transaction overview', async () => { -// await depositDialog.expectNativeRouteTransactionOverview({ -// apy: { -// value: '6.00%', -// description: 'Earn ~600.00 DAI/year', -// }, -// routeItems: [ -// { -// tokenAmount: '10,000.00 USDC', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '10,000.00 DAI', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '9,020.46 sDAI', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// outcome: '9,020.46 sDAI', -// outcomeUsd: '$10,000.00', -// }) -// }) + test('displays transaction overview', async () => { + await depositDialog.expectNativeRouteTransactionOverview({ + apy: { + value: '11.50%', + description: 'Earn ~1,150.00 DAI/year', + }, + routeItems: [ + { + tokenAmount: '10,000.00 USDC', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '10,000.00 DAI', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '8,884.16 sDAI', + tokenUsdValue: '$10,000.00', + }, + ], + outcome: '8,884.16 sDAI', + outcomeUsd: '$10,000.00', + }) + }) -// test('executes deposit', async () => { -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) + test('executes deposit', async () => { + await depositDialog.actionsContainer.acceptAllActionsAction(2) -// await depositDialog.expectSuccessPage() -// await depositDialog.clickBackToSavingsButton() + await depositDialog.expectSuccessPage() + await depositDialog.clickBackToSavingsButton() -// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '9,020.46 sDAI', estimatedDaiValue: '10,000' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') -// }) -// }) -// }) + await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '8,884.16 sDAI', estimatedDaiValue: '10,000' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') + }) + }) +}) diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDS.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDS.test-e2e.ts index e5d6f7a63..46680e5ec 100644 --- a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDS.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDS.test-e2e.ts @@ -1,74 +1,74 @@ -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -// test.describe('Deposit USDS', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let depositDialog: SavingsDialogPageObject +test.describe('Deposit USDS', () => { + let savingsPage: SavingsPageObject + let depositDialog: SavingsDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// USDS: 10_000, -// }, -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDS: 10_000, + }, + }, + }) -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickDepositButtonAction('USDS') + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickDepositButtonAction('USDS') -// depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) -// await depositDialog.fillAmountAction(10_000) -// }) + depositDialog = new SavingsDialogPageObject({ testContext, type: 'deposit' }) + await depositDialog.fillAmountAction(10_000) + }) -// test('uses native sUSDS deposit', async () => { -// await depositDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'USDS' }, -// { type: 'depositToSavings', asset: 'USDS', savingsAsset: 'sUSDS' }, -// ]) -// }) + test('uses native sUSDS deposit', async () => { + await depositDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'USDS' }, + { type: 'depositToSavings', asset: 'USDS', savingsAsset: 'sUSDS' }, + ]) + }) -// test('displays transaction overview', async () => { -// await depositDialog.expectNativeRouteTransactionOverview({ -// apy: { -// value: '6.25%', -// description: 'Earn ~625.00 USDS/year', -// }, -// routeItems: [ -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '9,999.77 sUSDS', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// outcome: '9,999.77 sUSDS', -// outcomeUsd: '$10,000.00', -// }) + test('displays transaction overview', async () => { + await depositDialog.expectNativeRouteTransactionOverview({ + apy: { + value: '12.50%', + description: 'Earn ~1,250.00 USDS/year', + }, + routeItems: [ + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '9,830.34 sUSDS', + tokenUsdValue: '$10,000.00', + }, + ], + outcome: '9,830.34 sUSDS', + outcomeUsd: '$10,000.00', + }) -// await depositDialog.expectUpgradeSwitchToBeHidden() -// }) + await depositDialog.expectUpgradeSwitchToBeHidden() + }) -// test('executes deposit', async () => { -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2, fork) + test('executes deposit', async () => { + await depositDialog.actionsContainer.acceptAllActionsAction(2) -// await depositDialog.expectSuccessPage() -// await depositDialog.clickBackToSavingsButton() + await depositDialog.expectSuccessPage() + await depositDialog.clickBackToSavingsButton() -// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,999.77 sUSDS', estimatedUsdsValue: '10,000' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') -// }) -// }) + await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,830.34 sUSDS', estimatedUsdsValue: '10,000' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/General.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/General.test-e2e.ts deleted file mode 100644 index cb111a865..000000000 --- a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/General.test-e2e.ts +++ /dev/null @@ -1,60 +0,0 @@ -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' - -// test.describe('General dialog behavior', () => { -// const fork = setupFork({ -// blockNumber: DEFAULT_BLOCK_NUMBER, -// chainId: mainnet.id, -// useTenderlyVnet: true, -// }) - -// test('can switch between tokens', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// DAI: 100, -// USDC: 100, -// }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickDepositButtonAction('DAI') - -// const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) - -// await depositDialog.fillAmountAction(100) -// await actionsContainer.expectEnabledActionAtIndex(0) -// await actionsContainer.expectActions([ -// { type: 'approve', asset: 'DAI' }, -// { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sDAI' }, -// ]) - -// await depositDialog.selectAssetAction('USDC') -// await depositDialog.fillAmountAction(100) -// await actionsContainer.expectEnabledActionAtIndex(0) -// await actionsContainer.expectActions([ -// { type: 'approve', asset: 'USDC' }, -// { type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sDAI' }, -// ]) - -// await depositDialog.selectAssetAction('DAI') -// await depositDialog.fillAmountAction(100) -// await actionsContainer.expectEnabledActionAtIndex(0) -// await actionsContainer.expectActions([ -// { type: 'approve', asset: 'DAI' }, -// { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sDAI' }, -// ]) -// }) -// }) diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/Validation.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/Validation.test-e2e.ts deleted file mode 100644 index bb6a23a62..000000000 --- a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/Validation.test-e2e.ts +++ /dev/null @@ -1,89 +0,0 @@ -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -// import { depositValidationIssueToMessage } from '../../logic/validation' - -// test.describe('Validation', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) -// let savingsPage: SavingsPageObject -// let depositDialog: SavingsDialogPageObject - -// test.describe('Input value exceeds balance', () => { -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// DAI: 100, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickDepositButtonAction('DAI') - -// depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) -// await depositDialog.fillAmountAction(10_000) -// }) - -// test('displays validation error', async () => { -// await depositDialog.expectAssetInputError(depositValidationIssueToMessage['exceeds-balance']) -// }) - -// test('actions are disabled', async () => { -// await depositDialog.actionsContainer.expectDisabledActions([ -// { type: 'approve', asset: 'DAI' }, -// { type: 'depositToSavings', asset: 'DAI', savingsAsset: 'sDAI' }, -// ]) -// }) - -// test('displays sensible tx overview', async () => { -// await depositDialog.expectNativeRouteTransactionOverview({ -// apy: { -// value: '5.00%', -// description: 'Earn ~500.00 DAI/year', -// }, -// routeItems: [ -// { -// tokenAmount: '10,000.00 DAI', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '9,332.66 sDAI', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// outcome: '9,332.66 sDAI', -// outcomeUsd: '$10,000.00', -// }) -// }) -// }) - -// test('displays validation error for dirty input with 0 value', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// DAI: 100, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickDepositButtonAction('DAI') -// depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) - -// await depositDialog.fillAmountAction(10) -// await depositDialog.fillAmountAction(0) - -// await depositDialog.expectAssetInputError(depositValidationIssueToMessage['value-not-positive']) -// }) -// }) From 048e5d9b4c045a2fea21f68a4012381389be4e1f Mon Sep 17 00:00:00 2001 From: Oskar <43062492+oskarvu@users.noreply.github.com> Date: Sat, 21 Dec 2024 00:14:07 +0700 Subject: [PATCH 21/29] Fix browser time management in tests and rewrite repay tests (#512) * Uncomment file * Rewrite repay dialog tests * return promise * Stash pop * Introduce syncBrowserTime * Add fetchWithRetry * Update some part of assertions * Fix growing balance * Lint * Update savings assertions * Fix approve * Fix topbar assertion * abort calls to blockanalitica * Use page.clock * Lint * Fix base assertion --------- Co-authored-by: yivlad --- .../flavours/approve/logic/approveAction.ts | 4 +- .../dialogs/repay/RepayDialog.test-e2e.ts | 1335 ++++++++--------- .../e2e/mainnet/DepositDAI.test-e2e.ts | 16 +- .../e2e/mainnet/DepositUSDC.test-e2e.ts | 12 +- .../e2e/mainnet/DepositUSDS.test-e2e.ts | 7 +- .../claim/e2e/mainnet/ClaimSKY.test-e2e.ts | 4 +- .../stake/e2e/mainnet/StakeDAI.test-e2e.ts | 4 +- .../stake/e2e/mainnet/StakeSDAI.test-e2e.ts | 4 +- .../stake/e2e/mainnet/StakeSUSDS.test-e2e.ts | 4 +- .../stake/e2e/mainnet/StakeUSDC.test-e2e.ts | 4 +- .../stake/e2e/mainnet/StakeUSDS.test-e2e.ts | 6 +- .../e2e/mainnet/UnstakeDAI.test-e2e.ts | 2 +- .../e2e/mainnet/UnstakeUSDC.test-e2e.ts | 2 +- .../e2e/mainnet/UnstakeUSDS.test-e2e.ts | 6 +- .../farm-details/logic/calculateReward.ts | 1 + .../growing-balance/GrowingBalance.tsx | 4 +- .../src/features/topbar/Topbar.test-e2e.ts | 2 +- packages/app/src/pages/Savings.test-e2e.ts | 2 +- packages/app/src/test/e2e/injectSetup.ts | 38 - packages/app/src/test/e2e/setup.ts | 18 +- 20 files changed, 691 insertions(+), 784 deletions(-) diff --git a/packages/app/src/features/actions/flavours/approve/logic/approveAction.ts b/packages/app/src/features/actions/flavours/approve/logic/approveAction.ts index e5325424d..fc25d2eb4 100644 --- a/packages/app/src/features/actions/flavours/approve/logic/approveAction.ts +++ b/packages/app/src/features/actions/flavours/approve/logic/approveAction.ts @@ -19,7 +19,9 @@ export function createApproveActionConfig(action: ApproveAction, context: Action account, chainId, }), - select: (data) => ({ canBeSkipped: data >= toBigInt(action.token.toBaseUnit(action.value)) }), + select: (data) => ({ + canBeSkipped: data >= toBigInt(action.token.toBaseUnit(action.requiredValue ?? action.value)), + }), }) }, diff --git a/packages/app/src/features/dialogs/repay/RepayDialog.test-e2e.ts b/packages/app/src/features/dialogs/repay/RepayDialog.test-e2e.ts index 696114a55..84ccaec5e 100644 --- a/packages/app/src/features/dialogs/repay/RepayDialog.test-e2e.ts +++ b/packages/app/src/features/dialogs/repay/RepayDialog.test-e2e.ts @@ -1,700 +1,635 @@ -// import { Page, test } from '@playwright/test' -// import { mainnet } from 'viem/chains' - -// import { repayValidationIssueToMessage } from '@/domain/market-validators/validateRepay' -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { BorrowPageObject } from '@/pages/Borrow.PageObject' -// import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { screenshot } from '@/test/e2e/utils' - -// import { tenderlyRpcActions } from '@/domain/tenderly/TenderlyRpcActions' -// import { injectFixedDate } from '@/test/e2e/injectSetup' -// import { BaseUnitNumber, NormalizedUnitNumber } from '@marsfoundation/common-universal' -// import { http, Address, createPublicClient } from 'viem' -// import { DialogPageObject } from '../common/Dialog.PageObject' - -// const headerRegExp = /Repa*/ - -// test.describe('Repay dialog', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) -// const initialBalances = { -// wstETH: 100, -// rETH: 100, -// WETH: 100, -// DAI: 10000, -// } -// const expectedInitialHealthFactor = '5.65' -// const expectedHealthFactor = '5.82' - -// test.describe('Position with borrowed DAI', () => { -// const initialDeposits = { -// rETH: 10, -// } as const -// const daiToBorrow = 3500 - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ...initialBalances }, -// }, -// }) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) -// await borrowPage.viewInMyPortfolioAction() - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// // @todo This waits for the refetch of the data after successful borrow transaction to happen. -// // This is no ideal, probably we need to refactor expectDepositTable so it takes advantage from -// // playwright's timeouts instead of parsing it's current state. Then we would be able to -// // easily wait for the table to be updated. -// await myPortfolioPage.expectAssetToBeInDepositTable('DAI') -// }) - -// test('opens dialog with selected asset', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickRepayButtonAction('DAI') - -// const repayDialog = new DialogPageObject(page, headerRegExp) -// await repayDialog.expectSelectedAsset('DAI') -// await repayDialog.expectDialogHeader('Repay DAI') -// await repayDialog.expectHealthFactorBeforeVisible() - -// await screenshot(repayDialog.getDialog(), 'repay-dialog-default-view') -// }) - -// test('calculates health factor changes correctly when repaying part', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickRepayButtonAction('DAI') - -// const repayDialog = new DialogPageObject(page, headerRegExp) -// await repayDialog.fillAmountAction(100) - -// await repayDialog.expectRiskLevelBefore('Healthy') -// await repayDialog.expectHealthFactorBefore(expectedInitialHealthFactor) -// await repayDialog.expectRiskLevelAfter('Healthy') -// await repayDialog.expectHealthFactorAfter(expectedHealthFactor) - -// // @note this is needed for deterministic screenshots -// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) -// await actionsContainer.expectEnabledActionAtIndex(0) - -// await screenshot(repayDialog.getDialog(), 'repay-dialog-health-factor-partial-repay') -// }) - -// test('calculates health factor changes correctly when repaying all', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickRepayButtonAction('DAI') - -// const repayDialog = new DialogPageObject(page, headerRegExp) -// await repayDialog.clickMaxAmountAction() - -// await repayDialog.expectRiskLevelBefore('Healthy') -// await repayDialog.expectHealthFactorBefore(expectedInitialHealthFactor) -// await repayDialog.expectRiskLevelAfter('No debt') -// await repayDialog.expectHealthFactorAfter(String.fromCharCode(0x221e)) - -// // @note this is needed for deterministic screenshots -// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) -// await actionsContainer.expectEnabledActionAtIndex(0) - -// await screenshot(repayDialog.getDialog(), 'repay-dialog-health-factor-full-repay') -// }) - -// test('after repay, health factor matches myPortfolio', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickRepayButtonAction('DAI') - -// const repayDialog = new DialogPageObject(page, headerRegExp) -// await repayDialog.fillAmountAction(100) - -// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) - -// await repayDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectHealthFactor(expectedHealthFactor) -// }) - -// test('has correct action plan for DAI', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// await myPortfolioPage.clickRepayButtonAction('DAI') - -// const repayDialog = new DialogPageObject(page, headerRegExp) -// await repayDialog.fillAmountAction(100) -// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) -// await actionsContainer.expectActions([ -// { type: 'approve', asset: 'DAI' }, -// { type: 'repay', asset: 'DAI' }, -// ]) -// }) - -// test('can repay DAI', async ({ page }) => { -// const repay = { -// asset: 'DAI', -// amount: 100, -// } as const - -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// await myPortfolioPage.clickRepayButtonAction(repay.asset) - -// const repayDialog = new DialogPageObject(page, headerRegExp) -// await repayDialog.fillAmountAction(repay.amount) -// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) -// await repayDialog.expectSuccessPage([repay], fork) - -// await screenshot(repayDialog.getDialog(), 'repay-dialog-dai-success') - -// await repayDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.expectBorrowTable({ -// [repay.asset]: daiToBorrow - repay.amount, -// }) -// }) - -// test('can fully repay DAI', async ({ page }) => { -// const repay = { -// asset: 'DAI', -// amount: 3500, -// } as const - -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// await myPortfolioPage.clickRepayButtonAction(repay.asset) - -// const repayDialog = new DialogPageObject(page, headerRegExp) -// await repayDialog.clickMaxAmountAction() -// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) -// await repayDialog.expectSuccessPage([repay], fork) - -// await screenshot(repayDialog.getDialog(), 'repay-dialog-dai-success') - -// await repayDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.expectBorrowTable({ -// [repay.asset]: 0, -// }) -// }) - -// // @todo: doesn't work properly because of fixed date or something -// test.skip('exact approvals are not required when repaying all', async ({ page }) => { -// const repay = { -// asset: 'DAI', -// amount: 3500, -// } as const - -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// await myPortfolioPage.clickRepayButtonAction(repay.asset) - -// const repayDialog = new DialogPageObject(page, headerRegExp) -// await repayDialog.clickMaxAmountAction() -// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) -// // (1) first approval with extra buffer -// await actionsContainer.acceptActionAtIndex(0) -// await actionsContainer.expectEnabledActionAtIndex(1) - -// await page.reload() -// await myPortfolioPage.clickRepayButtonAction(repay.asset) -// await repayDialog.clickMaxAmountAction() - -// // exact amount of debt slightly increased but approval (1) has a buffer so it should be enough -// // this should be rewrite to assert whole action plan and then accept -// // await actionsContainer.acceptActionAtIndex(1, { type: 'repay', asset: repay.asset }) -// // await actionsContainer.acceptNextActionAction() - -// await repayDialog.expectSuccessPage([repay], fork) -// }) -// }) - -// test.describe('Position when borrowed asset was not in user wallet before', () => { -// const DAI_ADDRESS = '0x6B175474E89094C44Da98b954EedeAC495271d0F' -// const DAI_DECIMALS = 18 - -// const initialDeposits = { -// wstETH: 10, -// } as const - -// const daiToBorrow = 10_000 -// const daiDebtIncreaseIn1Epoch = 1.0000029476774694 // hardcoded for DAI borrow rate 5.53% -// const daiDebtIncreaseIn2Epochs = 1.0000058953636277 // hardcoded for DAI borrow rate 5.53% - -// let account: Address -// let myPortfolioPage: MyPortfolioPageObject -// let repayDialog: DialogPageObject - -// async function overrideDaiBalance({ balance, page }: { balance: BaseUnitNumber; page: Page }): Promise { -// await tenderlyRpcActions.setTokenBalance(fork.forkUrl, DAI_ADDRESS, account, balance) -// await page.reload() -// } - -// test.beforeEach(async ({ page }) => { -// ;({ account } = await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { wstETH: 10 }, -// }, -// })) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) -// await borrowPage.viewInMyPortfolioAction() - -// myPortfolioPage = new MyPortfolioPageObject(page) -// repayDialog = new DialogPageObject(page, headerRegExp) - -// await myPortfolioPage.expectHealthFactor('2.08') - -// // forcefully set browser time to the timestamp of borrow transaction -// const publicClient = createPublicClient({ -// transport: http(fork.forkUrl), -// }) -// const block = await publicClient.getBlock() -// await injectFixedDate(page, new Date(Number(block.timestamp) * 1000)) -// await page.reload() -// }) - -// test('can repay if balance is less than debt', async ({ page }) => { -// const newBalance = 0.9 * daiToBorrow -// const repay = { -// asset: 'DAI', -// amount: newBalance, -// } as const - -// await overrideDaiBalance({ -// balance: BaseUnitNumber(NormalizedUnitNumber(newBalance).shiftedBy(DAI_DECIMALS)), -// page, -// }) - -// await myPortfolioPage.clickRepayButtonAction(repay.asset) - -// await repayDialog.clickMaxAmountAction() -// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) -// await repayDialog.expectSuccessPage([repay], fork) - -// await repayDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.expectNonZeroAmountInBorrowTable(repay.asset) -// }) - -// test('can repay if balance gt debt but lt debt after 1 epoch', async ({ page }) => { -// // The test asserts and edge case where user's balance is greater than debt, but less than debt after 1 epoch (30 minutes). -// // In this case the current implementation does not try to repay the debt including the interest accrued in the following time period -// // before the repay transaction is mined. Only the current debt is repaid. Therefore after the repay transaction some dust -// // (accrued interest) is left in the user's borrow table. -// const repay = { -// asset: 'DAI', -// amount: daiToBorrow, -// } as const - -// const daiDebtIn1Epoch = NormalizedUnitNumber(daiToBorrow).times(daiDebtIncreaseIn1Epoch) -// // newBalance = (daiToBorrow, daiDebtIn1Epoch) / 2 - a number somewhere between daiToBorrow and daiDebtIn1Epoch -// const newBalance = BaseUnitNumber(daiDebtIn1Epoch.plus(daiToBorrow).div(2).shiftedBy(DAI_DECIMALS)) -// await overrideDaiBalance({ -// balance: newBalance, -// page, -// }) - -// await myPortfolioPage.clickRepayButtonAction(repay.asset) - -// await repayDialog.clickMaxAmountAction() -// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) -// await repayDialog.expectSuccessPage( -// [ -// { -// asset: repay.asset, -// amount: daiToBorrow, -// }, -// ], -// fork, -// ) - -// await repayDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.expectNonZeroAmountInBorrowTable(repay.asset) -// }) - -// test('can repay if balance gt debt after 1 epoch but lt debt after 2 epochs', async ({ page }) => { -// const repay = { -// asset: 'DAI', -// amount: daiToBorrow, -// } as const - -// const daiDebtIn1Epoch = NormalizedUnitNumber(daiToBorrow).times(daiDebtIncreaseIn1Epoch) -// const daiDebtIn2Epochs = NormalizedUnitNumber(daiToBorrow).times(daiDebtIncreaseIn2Epochs) -// // newBalance = (daiDebtIn1Epoch + daiDebtIn2Epochs) / 2 - a number somewhere between daiDebtIn1Epoch and daiDebtIn2Epochs -// const newBalance = BaseUnitNumber(daiDebtIn2Epochs.plus(daiDebtIn1Epoch).div(2).shiftedBy(DAI_DECIMALS)) -// await overrideDaiBalance({ -// balance: newBalance, -// page, -// }) - -// await myPortfolioPage.clickRepayButtonAction(repay.asset) - -// const repayDialog = new DialogPageObject(page, headerRegExp) -// await repayDialog.clickMaxAmountAction() -// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) -// await repayDialog.expectSuccessPage( -// [ -// { -// asset: repay.asset, -// amount: daiToBorrow, -// }, -// ], -// fork, -// ) - -// await repayDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.expectBorrowTable({ -// [repay.asset]: 0, -// }) -// }) -// }) - -// test.describe('Position with multiple borrowed assets', () => { -// const initialDeposits = { -// wstETH: initialBalances.wstETH, // deposit whole balance -// } as const - -// const wstETHBorrow = { -// asset: 'wstETH', -// amount: 10, -// } - -// const WETHBorrow = { -// asset: 'WETH', -// amount: 10, -// } - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ...initialBalances }, -// }, -// }) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositWithoutBorrowActions(initialDeposits) // deposit whole wallet balance -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.goToMyPortfolioAction() - -// // borrow wstETH and WETH -// const borrowDialog = new DialogPageObject(page, /Borrow */) -// const borrowActionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) -// // borrow wstETH -// await myPortfolioPage.clickBorrowButtonAction(wstETHBorrow.asset) -// await borrowDialog.fillAmountAction(wstETHBorrow.amount) -// await borrowActionsContainer.acceptAllActionsAction(1) -// await borrowDialog.viewInMyPortfolioAction() -// // borrow WETH -// await myPortfolioPage.clickBorrowButtonAction(WETHBorrow.asset) -// await borrowDialog.fillAmountAction(WETHBorrow.amount) -// await borrowActionsContainer.acceptAllActionsAction(1) -// await borrowDialog.viewInMyPortfolioAction() -// }) - -// test('can change asset to aToken', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickRepayButtonAction('wstETH') - -// const repayDialog = new DialogPageObject(page, headerRegExp) -// await repayDialog.selectAssetAction('awstETH') -// await repayDialog.expectSelectedAsset('awstETH') -// await repayDialog.expectDialogHeader('Repay wstETH') -// await repayDialog.expectHealthFactorBeforeVisible() -// }) - -// test('has correct action plan for repaying erc-20 using aToken', async ({ page }) => { -// const repay = { -// asset: 'awstETH', -// amount: 5, -// } as const - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickRepayButtonAction('wstETH') - -// const repayDialog = new DialogPageObject(page, headerRegExp) -// await repayDialog.selectAssetAction(repay.asset) -// await repayDialog.fillAmountAction(repay.amount) - -// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) -// await actionsContainer.expectActions([{ type: 'repay', asset: repay.asset }]) - -// await screenshot(repayDialog.getDialog(), 'repay-dialog-erc20-atoken-action-plan') -// }) - -// test('can repay erc-20 using aToken', async ({ page }) => { -// const repay = { -// asset: 'awstETH', -// amount: 5, -// } as const - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickRepayButtonAction('wstETH') - -// const repayDialog = new DialogPageObject(page, headerRegExp) -// await repayDialog.selectAssetAction(repay.asset) -// await repayDialog.fillAmountAction(repay.amount) - -// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(1) - -// await screenshot(repayDialog.getDialog(), 'repay-dialog-erc20-atoken-success') - -// await repayDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.expectBorrowTable({ -// wstETH: wstETHBorrow.amount - repay.amount, -// }) -// }) - -// test('has correct action plan for erc-20 repay with permits', async ({ page }) => { -// const repay = { -// asset: 'wstETH', -// amount: 5, -// } as const - -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// await myPortfolioPage.clickRepayButtonAction(repay.asset) - -// const repayDialog = new DialogPageObject(page, headerRegExp) -// await repayDialog.fillAmountAction(repay.amount) -// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) -// await actionsContainer.expectActions([ -// { type: 'permit', asset: repay.asset }, -// { type: 'repay', asset: repay.asset }, -// ]) - -// await screenshot(repayDialog.getDialog(), 'repay-dialog-erc20-permit-action-plan') -// }) - -// test('has correct action plan for erc-20 repay with approves', async ({ page }) => { -// const repay = { -// asset: 'wstETH', -// amount: 5, -// } as const - -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// await myPortfolioPage.clickRepayButtonAction(repay.asset) - -// const repayDialog = new DialogPageObject(page, headerRegExp) -// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) -// await actionsContainer.switchPreferPermitsAction() - -// await repayDialog.fillAmountAction(repay.amount) -// await actionsContainer.expectActions([ -// { type: 'approve', asset: repay.asset }, -// { type: 'repay', asset: repay.asset }, -// ]) - -// await screenshot(repayDialog.getDialog(), 'repay-dialog-erc20-approve-action-plan') -// }) - -// test('can repay erc-20 using permits', async ({ page }) => { -// const repay = { -// asset: 'wstETH', -// amount: 5, -// } as const - -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// await myPortfolioPage.clickRepayButtonAction(repay.asset) - -// const repayDialog = new DialogPageObject(page, headerRegExp) -// await repayDialog.fillAmountAction(repay.amount) -// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) -// await repayDialog.expectSuccessPage([repay], fork) - -// await screenshot(repayDialog.getDialog(), 'repay-dialog-erc20-success') - -// await repayDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.expectBorrowTable({ -// [repay.asset]: wstETHBorrow.amount - repay.amount, -// }) -// }) - -// test('can repay erc-20 using approves', async ({ page }) => { -// const repay = { -// asset: 'wstETH', -// amount: 5, -// } as const - -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// await myPortfolioPage.clickRepayButtonAction(repay.asset) - -// const repayDialog = new DialogPageObject(page, headerRegExp) -// const actionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) -// await actionsContainer.switchPreferPermitsAction() -// await repayDialog.fillAmountAction(repay.amount) -// await actionsContainer.acceptAllActionsAction(2) -// await repayDialog.expectSuccessPage([repay], fork) - -// await repayDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.expectBorrowTable({ -// [repay.asset]: wstETHBorrow.amount - repay.amount, -// }) -// }) -// }) - -// test.describe('Form validation', () => { -// const initialDeposits = { -// wstETH: initialBalances.wstETH, // deposit whole balance -// } as const - -// const wstETHBorrow = { -// asset: 'wstETH', -// amount: 50, -// } - -// const wstETHDeposit = { -// asset: 'wstETH', -// amount: 50, -// } - -// const WETHBorrow = { -// asset: 'WETH', -// amount: 10, -// } - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ...initialBalances }, -// }, -// }) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositWithoutBorrowActions(initialDeposits) // deposit whole wallet balance -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.goToMyPortfolioAction() - -// // borrow wstETH and WETH -// const borrowDialog = new DialogPageObject(page, /Borrow */) -// const borrowActionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) -// // borrow wstETH -// await myPortfolioPage.clickBorrowButtonAction(wstETHBorrow.asset) -// await borrowDialog.fillAmountAction(wstETHBorrow.amount) -// await borrowActionsContainer.acceptAllActionsAction(1) -// await borrowDialog.viewInMyPortfolioAction() -// // borrow WETH -// await myPortfolioPage.clickBorrowButtonAction(WETHBorrow.asset) -// await borrowDialog.fillAmountAction(WETHBorrow.amount) -// await borrowDialog.clickAcknowledgeRisk() -// await borrowActionsContainer.acceptAllActionsAction(1) -// await borrowDialog.viewInMyPortfolioAction() - -// // deposit wstETH to have balance not enough to later repay debt using wstETH -// const depositDialog = new DialogPageObject(page, /Deposit */) -// const depositActionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await myPortfolioPage.clickDepositButtonAction(wstETHDeposit.asset) -// await depositDialog.fillAmountAction(wstETHDeposit.amount) -// await depositActionsContainer.acceptAllActionsAction(2) -// await depositDialog.viewInMyPortfolioAction() -// }) - -// test('cannot repay repay more than owe', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickRepayButtonAction(WETHBorrow.asset) - -// const repayDialog = new DialogPageObject(page, headerRegExp) -// await repayDialog.expectHealthFactorBefore('2.03') -// await repayDialog.fillAmountAction(WETHBorrow.amount + 1) -// await repayDialog.expectAssetInputError(repayValidationIssueToMessage['exceeds-debt']) - -// await screenshot(repayDialog.getDialog(), 'repay-dialog-more-than-owe') -// }) - -// test('cannot repay more than wallet balance', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickRepayButtonAction(wstETHBorrow.asset) - -// const repayDialog = new DialogPageObject(page, headerRegExp) -// await repayDialog.expectHealthFactorBefore('2.03') -// await repayDialog.fillAmountAction(1) -// await repayDialog.expectAssetInputError(repayValidationIssueToMessage['exceeds-balance']) - -// await screenshot(repayDialog.getDialog(), 'repay-dialog-more-than-balance') -// }) -// }) - -// // @note Add tests when problem with native asset deposit is solved -// test.describe('Position with native token debt', () => {}) - -// test.describe('Position with only deposit', () => { -// const initialDeposits = { -// wstETH: 10, -// } as const - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ...initialBalances }, -// }, -// }) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositWithoutBorrowActions(initialDeposits) -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.goToMyPortfolioAction() -// }) - -// test('nothing to repay', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.expectBorrowedAssetsToBeEmpty() -// await screenshot(page, 'repay-dialog-nothing-to-repay') -// }) - -// test('when repaying native asset retain some in wallet', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickBorrowButtonAction('WETH') - -// const borrowDialog = new DialogPageObject(page, /Borrow */) -// await borrowDialog.selectAssetAction('ETH') -// await borrowDialog.fillAmountAction(5) -// const borrowActionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) -// await borrowActionsContainer.acceptAllActionsAction(2) -// await borrowDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectBorrowTable({ WETH: 5 }) - -// await myPortfolioPage.clickRepayButtonAction('WETH') -// const repayDialog = new DialogPageObject(page, headerRegExp) -// await repayDialog.selectAssetAction('ETH') -// const repayActionsContainer = new ActionsPageObject(repayDialog.locatePanelByHeader('Actions')) -// // wait for select to switch to ETH -// await repayActionsContainer.expectActions([ -// { -// type: 'repay', -// asset: 'ETH', -// }, -// ]) -// await repayDialog.clickMaxAmountAction() - -// await repayDialog.expectInputValue('4.999') -// }) -// }) -// }) +import { repayValidationIssueToMessage } from '@/domain/market-validators/validateRepay' +import { BorrowPageObject } from '@/pages/Borrow.PageObject' +import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' +import { DEFAULT_BLOCK_NUMBER, TOKENS_ON_FORK } from '@/test/e2e/constants' +import { TestContext, setup } from '@/test/e2e/setup' +import { BaseUnitNumber, NormalizedUnitNumber, toBigInt } from '@marsfoundation/common-universal' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { DialogPageObject } from '../common/Dialog.PageObject' + +const headerRegExp = /Repa*/ + +test.describe('Repay dialog', () => { + const initialBalances = { + wstETH: 100, + rETH: 100, + WETH: 100, + ETH: 100, + DAI: 100000, + } + + test.describe('Position with borrowed DAI', () => { + const initialDeposits = { + rETH: 10, + } as const + const daiToBorrow = 3500 + + let testContext: TestContext<'connected-random'> + let repayDialog: DialogPageObject + let myPortfolioPage: MyPortfolioPageObject + + test.beforeEach(async ({ page }) => { + testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ...initialBalances }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + await borrowPage.depositAssetsActions({ assetsToDeposit: initialDeposits, daiToBorrow }) + await borrowPage.viewInMyPortfolioAction() + repayDialog = new DialogPageObject({ testContext, header: headerRegExp }) + myPortfolioPage = new MyPortfolioPageObject(testContext) + await myPortfolioPage.expectAssetToBeInDepositTable('DAI') + }) + + test('opens dialog with selected asset', async () => { + await myPortfolioPage.clickRepayButtonAction('DAI') + + await repayDialog.expectSelectedAsset('DAI') + await repayDialog.expectDialogHeader('Repay DAI') + await repayDialog.expectHealthFactorBeforeVisible() + }) + + test('calculates health factor changes correctly when repaying part', async () => { + await myPortfolioPage.clickRepayButtonAction('DAI') + + await repayDialog.fillAmountAction(100) + await repayDialog.expectRiskLevelBefore('Healthy') + await repayDialog.expectHealthFactorBefore('10.09') + await repayDialog.expectRiskLevelAfter('Healthy') + await repayDialog.expectHealthFactorAfter('10.38') + }) + + test('calculates health factor changes correctly when repaying all', async () => { + await myPortfolioPage.clickRepayButtonAction('DAI') + + await repayDialog.clickMaxAmountAction() + await repayDialog.expectRiskLevelBefore('Healthy') + await repayDialog.expectHealthFactorBefore('10.09') + await repayDialog.expectRiskLevelAfter('No debt') + await repayDialog.expectHealthFactorAfter(String.fromCharCode(0x221e)) + }) + + test('after repay, health factor matches myPortfolio', async () => { + await myPortfolioPage.clickRepayButtonAction('DAI') + + await repayDialog.fillAmountAction(100) + await repayDialog.actionsContainer.acceptAllActionsAction(2) + await repayDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectHealthFactor('10.38') + }) + + test('has correct action plan for DAI', async () => { + await myPortfolioPage.clickRepayButtonAction('DAI') + + await repayDialog.fillAmountAction(100) + await repayDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'DAI' }, + { type: 'repay', asset: 'DAI' }, + ]) + }) + + test('can repay DAI', async () => { + const repay = { + asset: 'DAI', + amount: 100, + } as const + + await myPortfolioPage.clickRepayButtonAction(repay.asset) + + await repayDialog.fillAmountAction(repay.amount) + await repayDialog.actionsContainer.acceptAllActionsAction(2) + await repayDialog.expectSuccessPage({ tokenWithValue: [{ asset: 'DAI', amount: '100.00', usdValue: '$100.00' }] }) + await repayDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectBorrowTable({ + [repay.asset]: daiToBorrow - repay.amount, + }) + }) + + test('can fully repay DAI', async () => { + const repay = { + asset: 'DAI', + amount: 3500, + } as const + + await myPortfolioPage.clickRepayButtonAction(repay.asset) + + await repayDialog.clickMaxAmountAction() + await repayDialog.actionsContainer.acceptAllActionsAction(2) + await repayDialog.expectSuccessPage({ + tokenWithValue: [{ asset: 'DAI', amount: '3,500.00', usdValue: '$3,500.00' }], + }) + await repayDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectBorrowTable({ + [repay.asset]: 0, + }) + }) + + test('exact approvals are not required when repaying all', async ({ page }) => { + const repay = { + asset: 'DAI', + amount: 3500, + } as const + + await myPortfolioPage.clickRepayButtonAction(repay.asset) + await repayDialog.clickMaxAmountAction() + await repayDialog.actionsContainer.acceptActionAtIndex(0) + await repayDialog.actionsContainer.expectEnabledActionAtIndex(1) + + await page.reload() + await myPortfolioPage.clickRepayButtonAction(repay.asset) + await repayDialog.clickMaxAmountAction() + await repayDialog.actionsContainer.acceptActionAtIndex(1) + + await repayDialog.expectSuccessPage({ + tokenWithValue: [{ asset: 'DAI', amount: '3,500.00', usdValue: '$3,500.00' }], + }) + }) + }) + + test.describe('Position when borrowed asset was not in user wallet before', () => { + const initialDeposits = { + wstETH: 10, + } as const + + const daiToBorrow = 10_000 + const daiDebtIncreaseIn1Epoch = 1.0000067529 // hardcoded for DAI borrow rate 12.55% + const daiDebtIncreaseIn2Epochs = 1.000013502 // hardcoded for DAI borrow rate 12.55% + + let myPortfolioPage: MyPortfolioPageObject + let repayDialog: DialogPageObject + let testContext: TestContext<'connected-random'> + + test.beforeEach(async ({ page }) => { + testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { wstETH: 10 }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + await borrowPage.depositAssetsActions({ assetsToDeposit: initialDeposits, daiToBorrow }) + await borrowPage.viewInMyPortfolioAction() + + myPortfolioPage = new MyPortfolioPageObject(testContext) + repayDialog = new DialogPageObject({ testContext, header: headerRegExp }) + + await myPortfolioPage.expectHealthFactor('3.73') + + // forcefully set browser time to the timestamp of borrow transaction + // const block = await testContext.testnetController.client.getBlock() + // await injectFixedDate(page, new Date(Number(block.timestamp) * 1000)) + // await page.reload() + }) + + test('can repay if balance is less than debt', async ({ page }) => { + const newBalance = 0.9 * daiToBorrow + const repay = { + asset: 'DAI', + amount: newBalance, + } as const + + await overrideDaiBalance({ + balance: NormalizedUnitNumber(newBalance), + testContext, + }) + await page.reload() + + await myPortfolioPage.clickRepayButtonAction(repay.asset) + + await repayDialog.clickMaxAmountAction() + await repayDialog.actionsContainer.acceptAllActionsAction(2) + await repayDialog.expectSuccessPage({ + tokenWithValue: [{ asset: 'DAI', amount: '9,000.00', usdValue: '$9,000.00' }], + }) + await repayDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectNonZeroAmountInBorrowTable(repay.asset) + }) + + test('can repay if balance gt debt but lt debt after 1 epoch', async ({ page }) => { + // The test asserts and edge case where user's balance is greater than debt, but less than debt after 1 epoch (30 minutes). + // In this case the current implementation does not try to repay the debt including the interest accrued in the following time period + // before the repay transaction is mined. Only the current debt is repaid. Therefore after the repay transaction some dust + // (accrued interest) is left in the user's borrow table. + const repay = { + asset: 'DAI', + amount: daiToBorrow, + } as const + const daiDebtIn1Epoch = NormalizedUnitNumber(daiToBorrow).times(daiDebtIncreaseIn1Epoch) + // newBalance = (daiToBorrow, daiDebtIn1Epoch) / 2 - a number somewhere between daiToBorrow and daiDebtIn1Epoch + const newBalance = NormalizedUnitNumber(daiDebtIn1Epoch.plus(daiToBorrow).div(2)) + await overrideDaiBalance({ + balance: newBalance, + testContext, + }) + await page.reload() + + await myPortfolioPage.clickRepayButtonAction(repay.asset) + + await repayDialog.clickMaxAmountAction() + await repayDialog.actionsContainer.acceptAllActionsAction(2) + await repayDialog.expectSuccessPage({ + tokenWithValue: [ + { + asset: 'DAI', + amount: '10,000.00', + usdValue: '$10,000.00', + }, + ], + }) + + await repayDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectNonZeroAmountInBorrowTable(repay.asset) + }) + + test('can repay if balance gt debt after 1 epoch but lt debt after 2 epochs', async ({ page }) => { + const repay = { + asset: 'DAI', + amount: daiToBorrow, + } as const + + const daiDebtIn1Epoch = NormalizedUnitNumber(daiToBorrow).times(daiDebtIncreaseIn1Epoch) + const daiDebtIn2Epochs = NormalizedUnitNumber(daiToBorrow).times(daiDebtIncreaseIn2Epochs) + // newBalance = (daiDebtIn1Epoch + daiDebtIn2Epochs) / 2 - a number somewhere between daiDebtIn1Epoch and daiDebtIn2Epochs + const newBalance = NormalizedUnitNumber(daiDebtIn2Epochs.plus(daiDebtIn1Epoch).div(2)) + await overrideDaiBalance({ + balance: newBalance, + testContext, + }) + await page.reload() + + await myPortfolioPage.clickRepayButtonAction(repay.asset) + + await repayDialog.clickMaxAmountAction() + await repayDialog.actionsContainer.acceptAllActionsAction(2) + await repayDialog.expectSuccessPage({ + tokenWithValue: [ + { + asset: 'DAI', + amount: '10,000.00', + usdValue: '$10,000.00', + }, + ], + }) + + await repayDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectBorrowTable({ + [repay.asset]: 0, + }) + }) + }) + + test.describe('Position with multiple borrowed assets', () => { + const initialDeposits = { + wstETH: initialBalances.wstETH, // deposit whole balance + } as const + + const wstETHBorrow = { + asset: 'wstETH', + amount: 10, + } + + const WETHBorrow = { + asset: 'WETH', + amount: 10, + } + + let testContext: TestContext<'connected-random'> + let repayDialog: DialogPageObject + let myPortfolioPage: MyPortfolioPageObject + + test.beforeEach(async ({ page }) => { + testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ...initialBalances }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + myPortfolioPage = new MyPortfolioPageObject(testContext) + repayDialog = new DialogPageObject({ testContext, header: headerRegExp }) + + await borrowPage.depositWithoutBorrowActions({ assetsToDeposit: initialDeposits }) // deposit whole wallet balance + await myPortfolioPage.goToMyPortfolioAction() + + // borrow wstETH and WETH + const borrowDialog = new DialogPageObject({ testContext, header: /Borrow */ }) + // borrow wstETH + await myPortfolioPage.clickBorrowButtonAction(wstETHBorrow.asset) + await borrowDialog.fillAmountAction(wstETHBorrow.amount) + await borrowDialog.actionsContainer.acceptAllActionsAction(1) + await borrowDialog.viewInMyPortfolioAction() + // borrow WETH + await myPortfolioPage.clickBorrowButtonAction(WETHBorrow.asset) + await borrowDialog.fillAmountAction(WETHBorrow.amount) + await borrowDialog.actionsContainer.acceptAllActionsAction(1) + await borrowDialog.viewInMyPortfolioAction() + }) + + test('can change asset to aToken', async () => { + await myPortfolioPage.clickRepayButtonAction('wstETH') + + await repayDialog.selectAssetAction('awstETH') + await repayDialog.expectSelectedAsset('awstETH') + await repayDialog.expectDialogHeader('Repay wstETH') + await repayDialog.expectHealthFactorBeforeVisible() + }) + + test('has correct action plan for repaying erc-20 using aToken', async () => { + const repay = { + asset: 'awstETH', + amount: 5, + } as const + + await myPortfolioPage.clickRepayButtonAction('wstETH') + + await repayDialog.selectAssetAction(repay.asset) + await repayDialog.fillAmountAction(repay.amount) + await repayDialog.actionsContainer.expectActions([{ type: 'repay', asset: repay.asset }]) + }) + + test('can repay erc-20 using aToken', async () => { + const repay = { + asset: 'awstETH', + amount: 5, + } as const + + await myPortfolioPage.clickRepayButtonAction('wstETH') + + await repayDialog.selectAssetAction(repay.asset) + await repayDialog.fillAmountAction(repay.amount) + await repayDialog.actionsContainer.acceptAllActionsAction(1) + await repayDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectBorrowTable({ + wstETH: wstETHBorrow.amount - repay.amount, + }) + }) + + test('can repay debt using native asset', async () => { + const repay = { + asset: 'ETH', + amount: 1, + } as const + + await myPortfolioPage.clickRepayButtonAction('WETH') + + await repayDialog.selectAssetAction(repay.asset) + await repayDialog.fillAmountAction(repay.amount) + await repayDialog.actionsContainer.acceptAllActionsAction(1) + await repayDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectBorrowTable({ + WETH: WETHBorrow.amount - repay.amount, + }) + }) + + test('has correct action plan for erc-20 repay with permits', async () => { + const repay = { + asset: 'wstETH', + amount: 5, + } as const + + await myPortfolioPage.clickRepayButtonAction(repay.asset) + + await repayDialog.fillAmountAction(repay.amount) + await repayDialog.actionsContainer.expectActions([ + { type: 'permit', asset: repay.asset }, + { type: 'repay', asset: repay.asset }, + ]) + }) + + test('has correct action plan for erc-20 repay with approves', async () => { + const repay = { + asset: 'wstETH', + amount: 5, + } as const + + await myPortfolioPage.clickRepayButtonAction(repay.asset) + + await repayDialog.actionsContainer.switchPreferPermitsAction() + await repayDialog.fillAmountAction(repay.amount) + await repayDialog.actionsContainer.expectActions([ + { type: 'approve', asset: repay.asset }, + { type: 'repay', asset: repay.asset }, + ]) + }) + + test('can repay erc-20 using permits', async () => { + const repay = { + asset: 'wstETH', + amount: 5, + } as const + + await myPortfolioPage.clickRepayButtonAction(repay.asset) + + await repayDialog.fillAmountAction(repay.amount) + await repayDialog.actionsContainer.acceptAllActionsAction(2) + await repayDialog.expectSuccessPage({ + tokenWithValue: [{ asset: 'wstETH', amount: '5.00', usdValue: '$23,327.32' }], + }) + await repayDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectBorrowTable({ + [repay.asset]: wstETHBorrow.amount - repay.amount, + }) + }) + + test('can repay erc-20 using approves', async () => { + const repay = { + asset: 'wstETH', + amount: 5, + } as const + + await myPortfolioPage.clickRepayButtonAction(repay.asset) + + await repayDialog.actionsContainer.switchPreferPermitsAction() + await repayDialog.fillAmountAction(repay.amount) + await repayDialog.actionsContainer.acceptAllActionsAction(2) + await repayDialog.expectSuccessPage({ + tokenWithValue: [{ asset: 'wstETH', amount: '5.00', usdValue: '$23,327.32' }], + }) + await repayDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectBorrowTable({ + [repay.asset]: wstETHBorrow.amount - repay.amount, + }) + }) + }) + + test.describe('Form validation', () => { + const initialDeposits = { + wstETH: initialBalances.wstETH, // deposit whole balance + } as const + + const wstETHBorrow = { + asset: 'wstETH', + amount: 50, + } + + const wstETHDeposit = { + asset: 'wstETH', + amount: 50, + } + + const WETHBorrow = { + asset: 'WETH', + amount: 10, + } + + let testContext: TestContext<'connected-random'> + let repayDialog: DialogPageObject + let myPortfolioPage: MyPortfolioPageObject + + test.beforeEach(async ({ page }) => { + testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ...initialBalances }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + repayDialog = new DialogPageObject({ testContext, header: headerRegExp }) + myPortfolioPage = new MyPortfolioPageObject(testContext) + + await borrowPage.depositWithoutBorrowActions({ assetsToDeposit: initialDeposits }) // deposit whole wallet balance + await myPortfolioPage.goToMyPortfolioAction() + + // borrow wstETH and WETH + const borrowDialog = new DialogPageObject({ testContext, header: /Borrow */ }) + // borrow wstETH + await myPortfolioPage.clickBorrowButtonAction(wstETHBorrow.asset) + await borrowDialog.fillAmountAction(wstETHBorrow.amount) + await borrowDialog.actionsContainer.acceptAllActionsAction(1) + await borrowDialog.viewInMyPortfolioAction() + // borrow WETH + await myPortfolioPage.clickBorrowButtonAction(WETHBorrow.asset) + await borrowDialog.fillAmountAction(WETHBorrow.amount) + await borrowDialog.clickAcknowledgeRisk() + await borrowDialog.actionsContainer.acceptAllActionsAction(1) + await borrowDialog.viewInMyPortfolioAction() + + // deposit wstETH to have balance not enough to later repay debt using wstETH + const depositDialog = new DialogPageObject({ testContext, header: /Deposit */ }) + await myPortfolioPage.clickDepositButtonAction(wstETHDeposit.asset) + await depositDialog.fillAmountAction(wstETHDeposit.amount) + await depositDialog.actionsContainer.acceptAllActionsAction(2) + await depositDialog.viewInMyPortfolioAction() + }) + + test('cannot repay repay more than owe', async () => { + await myPortfolioPage.clickRepayButtonAction(WETHBorrow.asset) + + await repayDialog.expectHealthFactorBefore('2.05') + await repayDialog.fillAmountAction(WETHBorrow.amount + 1) + await repayDialog.expectAssetInputError(repayValidationIssueToMessage['exceeds-debt']) + }) + + test('cannot repay more than wallet balance', async () => { + await myPortfolioPage.clickRepayButtonAction(wstETHBorrow.asset) + + await repayDialog.expectHealthFactorBefore('2.05') + await repayDialog.fillAmountAction(1) + await repayDialog.expectAssetInputError(repayValidationIssueToMessage['exceeds-balance']) + }) + }) + + test.describe('Position with only deposit', () => { + const initialDeposits = { + wstETH: 10, + } as const + + let testContext: TestContext<'connected-random'> + let repayDialog: DialogPageObject + let myPortfolioPage: MyPortfolioPageObject + + test.beforeEach(async ({ page }) => { + testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ...initialBalances, ETH: 0 }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + myPortfolioPage = new MyPortfolioPageObject(testContext) + repayDialog = new DialogPageObject({ testContext, header: headerRegExp }) + + await borrowPage.depositWithoutBorrowActions({ assetsToDeposit: initialDeposits }) + await myPortfolioPage.goToMyPortfolioAction() + }) + + test('nothing to repay', async () => { + await myPortfolioPage.expectBorrowedAssetsToBeEmpty() + }) + + test('when repaying native asset retain some in wallet', async () => { + await myPortfolioPage.clickBorrowButtonAction('WETH') + + const borrowDialog = new DialogPageObject({ testContext, header: /Borrow */ }) + await borrowDialog.selectAssetAction('ETH') + await borrowDialog.fillAmountAction(5) + await borrowDialog.actionsContainer.acceptAllActionsAction(2) + await borrowDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectBorrowTable({ WETH: 5 }) + + await myPortfolioPage.clickRepayButtonAction('WETH') + await repayDialog.selectAssetAction('ETH') + // wait for select to switch to ETH + await repayDialog.actionsContainer.expectActions([ + { + type: 'repay', + asset: 'ETH', + }, + ]) + await repayDialog.clickMaxAmountAction() + + await repayDialog.expectInputValue('4.999') + }) + }) +}) + +async function overrideDaiBalance({ + balance, + testContext, +}: { balance: NormalizedUnitNumber; testContext: TestContext<'connected-random'> }): Promise { + const dai = TOKENS_ON_FORK[mainnet.id].DAI + const daiBalance = toBigInt(BaseUnitNumber(balance.shiftedBy(dai.decimals))) + return testContext.testnetController.client.setErc20Balance(dai.address, testContext.account, daiBalance) +} diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositDAI.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositDAI.test-e2e.ts index edcff50d1..2f33df811 100644 --- a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositDAI.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositDAI.test-e2e.ts @@ -1,6 +1,6 @@ import { SavingsPageObject } from '@/pages/Savings.PageObject' import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setup } from '@/test/e2e/setup' +import { TestContext, setup } from '@/test/e2e/setup' import { test } from '@playwright/test' import { mainnet } from 'viem/chains' import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' @@ -8,9 +8,10 @@ import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageO test.describe('Deposit DAI', () => { let savingsPage: SavingsPageObject let depositDialog: SavingsDialogPageObject + let testContext: TestContext<'connected-random'> test.beforeEach(async ({ page }) => { - const testContext = await setup(page, { + testContext = await setup(page, { blockchain: { chainId: mainnet.id, blockNumber: DEFAULT_BLOCK_NUMBER, @@ -71,7 +72,10 @@ test.describe('Deposit DAI', () => { await depositDialog.expectSuccessPage() await depositDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,830.34 sUSDS', estimatedUsdsValue: '10,000' }) + await savingsPage.expectSavingsUsdsBalance({ + susdsBalance: '9,830.34 sUSDS', + estimatedUsdsValue: '10,000.000000', + }) await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') }) }) @@ -115,7 +119,7 @@ test.describe('Deposit DAI', () => { await depositDialog.expectSuccessPage() await depositDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '8,884.16 sDAI', estimatedDaiValue: '10,000' }) + await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '8,884.16 sDAI', estimatedDaiValue: '10,000.000000' }) await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') }) }) @@ -132,7 +136,7 @@ test.describe('Deposit DAI', () => { await depositDialog.expectSuccessPage() await depositDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '8,884.16 sDAI', estimatedDaiValue: '10,000' }) + await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '8,884.16 sDAI', estimatedDaiValue: '10,000.000000' }) await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') }) @@ -150,7 +154,7 @@ test.describe('Deposit DAI', () => { await depositDialog.expectSuccessPage() await depositDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,830.34 sUSDS', estimatedUsdsValue: '10,000' }) + await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,830.34 sUSDS', estimatedUsdsValue: '10,000.000000' }) await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') }) }) diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDC.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDC.test-e2e.ts index d5f627c79..e31a3ca3a 100644 --- a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDC.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDC.test-e2e.ts @@ -1,6 +1,6 @@ import { SavingsPageObject } from '@/pages/Savings.PageObject' import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setup } from '@/test/e2e/setup' +import { TestContext, setup } from '@/test/e2e/setup' import { test } from '@playwright/test' import { mainnet } from 'viem/chains' import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' @@ -8,9 +8,10 @@ import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageO test.describe('Deposit USDC', () => { let savingsPage: SavingsPageObject let depositDialog: SavingsDialogPageObject + let testContext: TestContext<'connected-random'> test.beforeEach(async ({ page }) => { - const testContext = await setup(page, { + testContext = await setup(page, { blockchain: { chainId: mainnet.id, blockNumber: DEFAULT_BLOCK_NUMBER, @@ -71,7 +72,10 @@ test.describe('Deposit USDC', () => { await depositDialog.expectSuccessPage() await depositDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,830.34 sUSDS', estimatedUsdsValue: '10,000' }) + await savingsPage.expectSavingsUsdsBalance({ + susdsBalance: '9,830.34 sUSDS', + estimatedUsdsValue: '10,000.000000', + }) await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') }) }) @@ -119,7 +123,7 @@ test.describe('Deposit USDC', () => { await depositDialog.expectSuccessPage() await depositDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '8,884.16 sDAI', estimatedDaiValue: '10,000' }) + await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '8,884.16 sDAI', estimatedDaiValue: '10,000.000000' }) await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') }) }) diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDS.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDS.test-e2e.ts index 46680e5ec..5d468a171 100644 --- a/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDS.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/deposit/e2e/mainnet/DepositUSDS.test-e2e.ts @@ -1,6 +1,6 @@ import { SavingsPageObject } from '@/pages/Savings.PageObject' import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -import { setup } from '@/test/e2e/setup' +import { TestContext, setup } from '@/test/e2e/setup' import { test } from '@playwright/test' import { mainnet } from 'viem/chains' import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' @@ -8,9 +8,10 @@ import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageO test.describe('Deposit USDS', () => { let savingsPage: SavingsPageObject let depositDialog: SavingsDialogPageObject + let testContext: TestContext<'connected-random'> test.beforeEach(async ({ page }) => { - const testContext = await setup(page, { + testContext = await setup(page, { blockchain: { chainId: mainnet.id, blockNumber: DEFAULT_BLOCK_NUMBER, @@ -68,7 +69,7 @@ test.describe('Deposit USDS', () => { await depositDialog.expectSuccessPage() await depositDialog.clickBackToSavingsButton() - await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,830.34 sUSDS', estimatedUsdsValue: '10,000' }) + await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,830.34 sUSDS', estimatedUsdsValue: '10,000.000000' }) await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') }) }) diff --git a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts index bc8e65910..3a28e05ed 100644 --- a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts @@ -72,8 +72,8 @@ test.describe('Claim SKY rewards', () => { await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') await farmDetailsPage.expectReward({ - reward: '0.001', - rewardUsd: '<$0.01', + reward: '0.00000', + rewardUsd: '$0.00', }) await farmDetailsPage.expectTokenBalance({ address: account, diff --git a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeDAI.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeDAI.test-e2e.ts index 36b4156e3..aa075dfb6 100644 --- a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeDAI.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeDAI.test-e2e.ts @@ -81,8 +81,8 @@ test.describe('Stake DAI to SKY farm', () => { await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') await farmDetailsPage.expectReward({ - reward: '0.001', - rewardUsd: '<$0.01', + reward: '0.00000', + rewardUsd: '$0.00', }) await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) }) diff --git a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSDAI.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSDAI.test-e2e.ts index 02d707781..191c67710 100644 --- a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSDAI.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSDAI.test-e2e.ts @@ -83,8 +83,8 @@ test.describe('Stake sDAI to SKY farm', () => { await farmDetailsPage.expectTokenToDepositBalance('sDAI', '-') await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') // no dust left await farmDetailsPage.expectReward({ - reward: '0.0001', - rewardUsd: '<$0.01', + reward: '0.00000', + rewardUsd: '$0.00', }) await farmDetailsPage.expectStaked({ amount: '1,125.60', asset: 'USDS' }) }) diff --git a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSUSDS.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSUSDS.test-e2e.ts index 93facee94..a2cc3e1f8 100644 --- a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSUSDS.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeSUSDS.test-e2e.ts @@ -93,8 +93,8 @@ test.describe('Stake sUSDS to SKY farm', () => { await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') // no dust left await farmDetailsPage.expectReward({ - reward: '0.0001', - rewardUsd: '<$0.01', + reward: '0.00000', + rewardUsd: '$0.00', }) await farmDetailsPage.expectStaked({ amount: '1,017.26', asset: 'USDS' }) }) diff --git a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDC.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDC.test-e2e.ts index df1bff1ef..08c340136 100644 --- a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDC.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDC.test-e2e.ts @@ -81,8 +81,8 @@ test.describe('Stake USDC to SKY farm', () => { await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') await farmDetailsPage.expectReward({ - reward: '0.001', - rewardUsd: '<$0.01', + reward: '0.00000', + rewardUsd: '$0.00', }) await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) }) diff --git a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDS.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDS.test-e2e.ts index 4dea525ce..6447b1fe2 100644 --- a/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDS.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/stake/e2e/mainnet/StakeUSDS.test-e2e.ts @@ -75,8 +75,8 @@ test.describe('Stake USDS to SKY farm', () => { await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') await farmDetailsPage.expectReward({ - reward: '0.001', - rewardUsd: '<$0.01', + reward: '0.00000', + rewardUsd: '$0.00', }) await farmDetailsPage.expectStaked({ amount: '10,000.00', asset: 'USDS' }) }) @@ -159,7 +159,7 @@ test.describe('Stake USDS to CLE farm', () => { await overrideInfoSkyRouteWithHAR({ page, key: `3-cle-farm-10000-balance-${harSuffix}` }) await farmDetailsPage.expectReward({ - reward: '257.6', + reward: '257.460', }) await farmDetailsPage.expectPointsSyncWarningToBeHidden() await farmDetailsPage.expectInfoPanelClaimButtonToBeHidden() diff --git a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeDAI.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeDAI.test-e2e.ts index cca32d77e..204c86c2e 100644 --- a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeDAI.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeDAI.test-e2e.ts @@ -93,7 +93,7 @@ test.describe('Unstake DAI from SKY farm', () => { await farmDetailsPage.expectTokenToDepositBalance('DAI', '15,000.00') await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') await farmDetailsPage.expectReward({ - reward: '49.441', + reward: '49.43940', rewardUsd: '2.98', }) await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) diff --git a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDC.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDC.test-e2e.ts index e5788c604..1fe1a4aed 100644 --- a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDC.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDC.test-e2e.ts @@ -93,7 +93,7 @@ test.describe('Unstake USDC from SKY farm', () => { await farmDetailsPage.expectTokenToDepositBalance('USDC', '15,000.00') await farmDetailsPage.expectTokenToDepositBalance('USDS', '-') await farmDetailsPage.expectReward({ - reward: '49.441', + reward: '49.43940', rewardUsd: '2.98', }) await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) diff --git a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDS.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDS.test-e2e.ts index f8c831a76..077f7df99 100644 --- a/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDS.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/unstake/e2e/mainnet/UnstakeUSDS.test-e2e.ts @@ -92,7 +92,7 @@ test.describe('Unstake USDS from SKY farm', () => { await farmDetailsPage.expectTokenToDepositBalance('USDS', '15,000.00') await farmDetailsPage.expectTokenToDepositBalance('DAI', '-') await farmDetailsPage.expectReward({ - reward: '49.438', + reward: '49.43654', rewardUsd: '2.98', }) await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) @@ -176,7 +176,7 @@ test.describe('Unstake USDS from CLE farm', () => { await farmDetailsPage.expectTokenToDepositBalance('USDS', '5,000.00') await farmDetailsPage.expectReward({ - reward: '257.6', + reward: '257.460', }) await farmDetailsPage.expectStaked({ amount: '5,000.00', asset: 'USDS' }) await farmDetailsPage.expectPointsSyncWarning() @@ -184,7 +184,7 @@ test.describe('Unstake USDS from CLE farm', () => { await overrideInfoSkyRouteWithHAR({ page, key: `4-cle-farm-5000-balance-${harSuffix}` }) await farmDetailsPage.expectReward({ - reward: '257.6', + reward: '257.460', }) await farmDetailsPage.expectPointsSyncWarningToBeHidden() await farmDetailsPage.expectInfoPanelClaimButtonToBeHidden() diff --git a/packages/app/src/features/farm-details/logic/calculateReward.ts b/packages/app/src/features/farm-details/logic/calculateReward.ts index 5f6053e0b..209ff3fff 100644 --- a/packages/app/src/features/farm-details/logic/calculateReward.ts +++ b/packages/app/src/features/farm-details/logic/calculateReward.ts @@ -28,6 +28,7 @@ export function calculateReward({ const earnedTimestampInMs = earnedTimestamp * 1000 const timeDiff = ((timestampInMs > periodFinishInMs ? periodFinishInMs : timestampInMs) - earnedTimestampInMs) / 1000 + const accruedEarned = staked.multipliedBy(rewardRate).multipliedBy(BigNumber.max(timeDiff, 0)).dividedBy(totalSupply) const earnedInTotal = NormalizedUnitNumber(earned.plus(accruedEarned)) diff --git a/packages/app/src/features/savings/components/growing-balance/GrowingBalance.tsx b/packages/app/src/features/savings/components/growing-balance/GrowingBalance.tsx index 067fab3c4..a89faf843 100644 --- a/packages/app/src/features/savings/components/growing-balance/GrowingBalance.tsx +++ b/packages/app/src/features/savings/components/growing-balance/GrowingBalance.tsx @@ -5,6 +5,7 @@ import { cn } from '@/ui/utils/style' import { testIds } from '@/ui/utils/testIds' import { getFractionalPart, getWholePart } from '@/utils/bigNumber' import { useTimestamp } from '@/utils/useTimestamp' +import { NormalizedUnitNumber } from '@marsfoundation/common-universal' import { SavingsOverview } from '../../logic/makeSavingsOverview' export interface GrowingBalanceProps { @@ -23,7 +24,8 @@ export function GrowingBalance({ savingsType, }: GrowingBalanceProps) { const { timestampInMs } = useTimestamp({ refreshIntervalInMs: balanceRefreshIntervalInMs }) - const { depositedAssets, depositedAssetsPrecision } = calculateSavingsBalance(timestampInMs) + const { depositedAssets: _depositedAssets, depositedAssetsPrecision } = calculateSavingsBalance(timestampInMs) + const depositedAssets = NormalizedUnitNumber(_depositedAssets.toFixed(depositedAssetsPrecision)) return (
diff --git a/packages/app/src/features/topbar/Topbar.test-e2e.ts b/packages/app/src/features/topbar/Topbar.test-e2e.ts index 5850fced9..467401555 100644 --- a/packages/app/src/features/topbar/Topbar.test-e2e.ts +++ b/packages/app/src/features/topbar/Topbar.test-e2e.ts @@ -37,7 +37,7 @@ test.describe('Topbar', () => { const topbar = new TopbarPageObject(testContext) await topbar.expectAirdropCompactValue('8.227M') await topbar.openAirdropDropdown() - await topbar.expectAirdropPreciseValue('8,227,011.154') + await topbar.expectAirdropPreciseValue('8,227,011.131') }) test('Api error', async ({ page }) => { diff --git a/packages/app/src/pages/Savings.test-e2e.ts b/packages/app/src/pages/Savings.test-e2e.ts index 31504b895..7c74f5780 100644 --- a/packages/app/src/pages/Savings.test-e2e.ts +++ b/packages/app/src/pages/Savings.test-e2e.ts @@ -182,7 +182,7 @@ test.describe('Savings Base', () => { await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '100.00', - estimatedUsdsValue: '101.286547', + estimatedUsdsValue: '101.28654604', }) }) diff --git a/packages/app/src/test/e2e/injectSetup.ts b/packages/app/src/test/e2e/injectSetup.ts index 988877ea4..a96e1feff 100644 --- a/packages/app/src/test/e2e/injectSetup.ts +++ b/packages/app/src/test/e2e/injectSetup.ts @@ -42,41 +42,3 @@ export async function injectNetworkConfiguration(page: Page, rpcUrl: string, cha }, ) } - -export async function injectFixedDate(page: Page, date: Date): Promise { - // setup fake Date for deterministic tests - // https://github.com/microsoft/playwright/issues/6347#issuecomment-1085850728 - const fakeNow = date.valueOf() - await page.addInitScript(overrideDateClass, fakeNow) -} - -// the only difference between this and injectFixedDate is the use of page.evaluate instead of page.addInitScript -export async function injectUpdatedDate(page: Page, date: Date): Promise { - // setup fake Date for deterministic tests - // https://github.com/microsoft/playwright/issues/6347#issuecomment-1085850728 - const fakeNow = date.valueOf() - await page.evaluate(overrideDateClass, fakeNow) -} - -function overrideDateClass(fakeNow: number): void { - // biome-ignore lint/suspicious/noGlobalAssign: - // @ts-ignore - Date = class extends Date { - // @ts-ignore - constructor(...args) { - if (args.length === 0) { - super(fakeNow) - } else { - // @ts-ignore - super(...args) - } - } - } - // Override Date.now() to start from fakeNow - const __DateNowOffset = fakeNow - Date.now() - const __DateNow = Date.now - Date.now = () => __DateNow() + __DateNowOffset - - // @todo: When we are able to set timestamps for transactions, make tests that use vnets use line below instead of the overriding Date.now with offset - // Date.now = () => fakeNow -} diff --git a/packages/app/src/test/e2e/setup.ts b/packages/app/src/test/e2e/setup.ts index 00c83a157..bd4be0ade 100644 --- a/packages/app/src/test/e2e/setup.ts +++ b/packages/app/src/test/e2e/setup.ts @@ -6,12 +6,7 @@ import { generatePath } from 'react-router-dom' import { Address, Hash, parseEther, parseUnits } from 'viem' import { AssetsInTests, TOKENS_ON_FORK } from './constants' import { getTestnetContext } from './getTestnetContext' -import { - injectFixedDate, - injectNetworkConfiguration, - injectUpdatedDate, - injectWalletConfiguration, -} from './injectSetup' +import { injectNetworkConfiguration, injectWalletConfiguration } from './injectSetup' import { generateAccount } from './utils' export type InjectableWallet = { address: Address } | { privateKey: string } @@ -87,7 +82,7 @@ export async function setup( const progressedTimestamp = currentTimestamp + BigInt(seconds) await testnetClient.setNextBlockTimestamp(progressedTimestamp) - await injectUpdatedDate(page, new Date(Number(currentTimestamp) * 1000)) + await page.clock.setFixedTime(Number(currentTimestamp) * 1000) } async function progressSimulationAndMine(seconds: number): Promise { @@ -99,7 +94,7 @@ export async function setup( // @note: Set next block to be mined timestamp to be 5 seconds more. await progressSimulation(5) - const testnetController = { + const testnetController: TestnetController = { client: testnetClient, progressSimulation, progressSimulationAndMine, @@ -183,14 +178,15 @@ async function injectPageSetup({ testnetClient: TestnetClient options: SetupOptions }): Promise { - const blockchainTimestamp = (await testnetClient.getBlock()).timestamp - if (options.skipInjectingNetwork === true) { // if explicitly disabled, do not inject network config abort all network requests to RPC providers await page.route(/alchemy/, (route) => route.abort()) await page.route(/rpc.ankr/, (route) => route.abort()) + await page.route(/blockanalitica.com/, (route) => route.abort()) } else { await injectNetworkConfiguration(page, getUrlFromClient(testnetClient), options.blockchain.chainId) } - await injectFixedDate(page, new Date(Number(blockchainTimestamp) * 1000)) + + const { timestamp } = await testnetClient.getBlock() + await page.clock.setFixedTime(Number(timestamp) * 1000) } From 070568f55654d914f9541e48f01f4e27770e3f39 Mon Sep 17 00:00:00 2001 From: Vladyslav Yatsenko <52505649+yivlad@users.noreply.github.com> Date: Fri, 20 Dec 2024 18:43:31 +0100 Subject: [PATCH 22/29] Rewrite migrate E2E tests (#515) * Rewrite migrate E2E tests * Fix assertion --------- Co-authored-by: oskarvu --- .../downgrade/DowngradeDialog.PageObject.ts | 72 +++--- .../downgrade/e2e/UsdsToDai.test-e2e.ts | 221 +++++++++-------- .../upgrade/UpgradeDialog.PageObject.ts | 102 ++++---- .../migrate/upgrade/e2e/DaiToUsds.test-e2e.ts | 233 +++++++++--------- .../upgrade/e2e/sDaiToSUsds.test-e2e.ts | 223 +++++++++-------- 5 files changed, 449 insertions(+), 402 deletions(-) diff --git a/packages/app/src/features/dialogs/savings/migrate/downgrade/DowngradeDialog.PageObject.ts b/packages/app/src/features/dialogs/savings/migrate/downgrade/DowngradeDialog.PageObject.ts index 98640b5db..61d1f99a6 100644 --- a/packages/app/src/features/dialogs/savings/migrate/downgrade/DowngradeDialog.PageObject.ts +++ b/packages/app/src/features/dialogs/savings/migrate/downgrade/DowngradeDialog.PageObject.ts @@ -1,38 +1,42 @@ -// import { DialogPageObject, TxOverviewWithRoute } from '@/features/dialogs/common/Dialog.PageObject' -// import { testIds } from '@/ui/utils/testIds' -// import { Page, expect } from '@playwright/test' +import { DialogPageObject, TxOverviewWithRoute } from '@/features/dialogs/common/Dialog.PageObject' +import { TestContext } from '@/test/e2e/setup' +import { testIds } from '@/ui/utils/testIds' +import { expect } from '@playwright/test' -// export class DowngradeDialogPageObject extends DialogPageObject { -// constructor(page: Page) { -// super(page, /Downgrade/) -// } +export class DowngradeDialogPageObject extends DialogPageObject { + constructor(testContext: TestContext) { + super({ + testContext, + header: /Downgrade/, + }) + } -// // #region actions -// async clickBackToSavingsButton(): Promise { -// await this.page.getByRole('button', { name: 'Back to Savings' }).click() -// await this.region.waitFor({ -// state: 'detached', -// }) -// } -// // #endregion actions + // #region actions + async clickBackToSavingsButton(): Promise { + await this.page.getByRole('button', { name: 'Back to Savings' }).click() + await this.region.waitFor({ + state: 'detached', + }) + } + // #endregion actions -// // #region assertions -// async expectTransactionOverview(transactionOverview: TxOverviewWithRoute): Promise { -// await this.expectTransactionOverviewRoute(transactionOverview.routeItems) -// if (transactionOverview.badgeTokens) { -// await this.expectSkyBadgeForTokens(transactionOverview.badgeTokens) -// } -// await this.expectOutcomeText(transactionOverview.outcome) -// } + // #region assertions + async expectTransactionOverview(transactionOverview: TxOverviewWithRoute): Promise { + await this.expectTransactionOverviewRoute(transactionOverview.routeItems) + if (transactionOverview.badgeTokens) { + await this.expectSkyBadgeForTokens(transactionOverview.badgeTokens) + } + await this.expectOutcomeText(transactionOverview.outcome) + } -// async expectDowngradeSuccessPage({ -// token, -// amount, -// usdValue, -// }: { token: string; amount: string; usdValue: string }): Promise { -// await expect(this.region.getByText('Congrats, all done!')).toBeVisible() -// const summary = await this.region.getByTestId(testIds.dialog.success).textContent() -// await expect(summary).toMatch(`${token}${amount} ${usdValue}`) -// } -// // #endregion assertions -// } + async expectDowngradeSuccessPage({ + token, + amount, + usdValue, + }: { token: string; amount: string; usdValue: string }): Promise { + await expect(this.region.getByText('Congrats, all done!')).toBeVisible() + const summary = await this.region.getByTestId(testIds.dialog.success).textContent() + await expect(summary).toMatch(`${token}${amount} ${usdValue}`) + } + // #endregion assertions +} diff --git a/packages/app/src/features/dialogs/savings/migrate/downgrade/e2e/UsdsToDai.test-e2e.ts b/packages/app/src/features/dialogs/savings/migrate/downgrade/e2e/UsdsToDai.test-e2e.ts index f0715c43a..ebe145dd2 100644 --- a/packages/app/src/features/dialogs/savings/migrate/downgrade/e2e/UsdsToDai.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/migrate/downgrade/e2e/UsdsToDai.test-e2e.ts @@ -1,104 +1,117 @@ -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { DowngradeDialogPageObject } from '../DowngradeDialog.PageObject' - -// test.describe('Downgrade USDS to DAI', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - -// test('downgrade to DAI is disabled when USDS balance is 0', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { USDS: 0 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.expectDowngradeToDaiToBeDisabled() -// }) - -// test('uses downgrade action', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { USDS: 10_000 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickDowngradeUsdsToDaiOption() - -// const downgradeDialog = new DowngradeDialogPageObject(page) -// await downgradeDialog.fillAmountAction(100) - -// await downgradeDialog.actionsContainer.expectEnabledActionAtIndex(0) -// await downgradeDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'USDS' }, -// { type: 'downgrade', fromToken: 'USDS', toToken: 'DAI' }, -// ]) -// }) - -// test('displays transaction overview', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { USDS: 10_000 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickDowngradeUsdsToDaiOption() - -// const downgradeDialog = new DowngradeDialogPageObject(page) -// await downgradeDialog.fillAmountAction(100) - -// await downgradeDialog.expectTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '100.00 USDS', -// tokenUsdValue: '$100.00', -// }, -// { -// tokenAmount: '100.00 DAI', -// tokenUsdValue: '$100.00', -// }, -// ], -// outcome: '100.00 DAI', -// outcomeUsd: '$100.00', -// }) -// }) - -// test('executes transaction', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { USDS: 10_000 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') -// await savingsPage.clickDowngradeUsdsToDaiOption() - -// const downgradeDialog = new DowngradeDialogPageObject(page) -// await downgradeDialog.fillAmountAction(10_000) - -// await downgradeDialog.actionsContainer.acceptAllActionsAction(2, fork) -// await downgradeDialog.expectDowngradeSuccessPage({ token: 'USDS', amount: '10,000.00', usdValue: '$10,000.00' }) -// await downgradeDialog.clickBackToSavingsButton() - -// await savingsPage.expectUpgradableDaiBalance('10,000.00') -// }) -// }) +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { DowngradeDialogPageObject } from '../DowngradeDialog.PageObject' + +test.describe('Downgrade USDS to DAI', () => { + test('downgrade to DAI is disabled when USDS balance is 0', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { USDS: 0 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.expectDowngradeToDaiToBeDisabled() + }) + + test('uses downgrade action', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { USDS: 10_000 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickDowngradeUsdsToDaiOption() + + const downgradeDialog = new DowngradeDialogPageObject(testContext) + await downgradeDialog.fillAmountAction(100) + + await downgradeDialog.actionsContainer.expectEnabledActionAtIndex(0) + await downgradeDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'USDS' }, + { type: 'downgrade', fromToken: 'USDS', toToken: 'DAI' }, + ]) + }) + + test('displays transaction overview', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { USDS: 10_000 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickDowngradeUsdsToDaiOption() + + const downgradeDialog = new DowngradeDialogPageObject(testContext) + await downgradeDialog.fillAmountAction(100) + + await downgradeDialog.expectTransactionOverview({ + routeItems: [ + { + tokenAmount: '100.00 USDS', + tokenUsdValue: '$100.00', + }, + { + tokenAmount: '100.00 DAI', + tokenUsdValue: '$100.00', + }, + ], + outcome: '100.00 DAI', + outcomeUsd: '$100.00', + }) + }) + + test('executes transaction', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { USDS: 10_000 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') + await savingsPage.clickDowngradeUsdsToDaiOption() + + const downgradeDialog = new DowngradeDialogPageObject(testContext) + await downgradeDialog.fillAmountAction(10_000) + + await downgradeDialog.actionsContainer.acceptAllActionsAction(2) + await downgradeDialog.expectDowngradeSuccessPage({ token: 'USDS', amount: '10,000.00', usdValue: '$10,000.00' }) + await downgradeDialog.clickBackToSavingsButton() + + await savingsPage.expectUpgradableDaiBalance('10,000.00') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/migrate/upgrade/UpgradeDialog.PageObject.ts b/packages/app/src/features/dialogs/savings/migrate/upgrade/UpgradeDialog.PageObject.ts index 3e59932a2..a4075f18b 100644 --- a/packages/app/src/features/dialogs/savings/migrate/upgrade/UpgradeDialog.PageObject.ts +++ b/packages/app/src/features/dialogs/savings/migrate/upgrade/UpgradeDialog.PageObject.ts @@ -1,56 +1,60 @@ -// import { DialogPageObject, TxOverviewWithRoute } from '@/features/dialogs/common/Dialog.PageObject' -// import { testIds } from '@/ui/utils/testIds' -// import { Page, expect } from '@playwright/test' +import { DialogPageObject, TxOverviewWithRoute } from '@/features/dialogs/common/Dialog.PageObject' +import { TestContext } from '@/test/e2e/setup' +import { testIds } from '@/ui/utils/testIds' +import { expect } from '@playwright/test' -// export class UpgradeDialogPageObject extends DialogPageObject { -// constructor(page: Page) { -// super(page, /Upgrade/) -// } +export class UpgradeDialogPageObject extends DialogPageObject { + constructor(testContext: TestContext) { + super({ + testContext, + header: /Upgrade/, + }) + } -// // #region actions -// async clickBackToSavingsButton(): Promise { -// await this.page.getByRole('button', { name: 'Back to Savings' }).click() -// await this.region.waitFor({ -// state: 'detached', -// }) -// } -// // #endregion actions + // #region actions + async clickBackToSavingsButton(): Promise { + await this.page.getByRole('button', { name: 'Back to Savings' }).click() + await this.region.waitFor({ + state: 'detached', + }) + } + // #endregion actions -// // #region assertions -// async expectTransactionOverview(transactionOverview: UpgradeTxOverview): Promise { -// const panel = this.locatePanelByHeader('Transaction overview') -// await expect(panel).toBeVisible() -// const savingsTxOverviewTestIds = testIds.dialog.savings.transactionOverview + // #region assertions + async expectTransactionOverview(transactionOverview: UpgradeTxOverview): Promise { + const panel = this.locatePanelByHeader('Transaction overview') + await expect(panel).toBeVisible() + const savingsTxOverviewTestIds = testIds.dialog.savings.transactionOverview -// if (transactionOverview.apyChange) { -// const currentApyValue = panel.getByTestId(savingsTxOverviewTestIds.apyChange.before) -// const updatedApyValue = panel.getByTestId(savingsTxOverviewTestIds.apyChange.after) -// await expect(currentApyValue).toContainText(transactionOverview.apyChange.current) -// await expect(updatedApyValue).toContainText(transactionOverview.apyChange.updated) -// } + if (transactionOverview.apyChange) { + const currentApyValue = panel.getByTestId(savingsTxOverviewTestIds.apyChange.before) + const updatedApyValue = panel.getByTestId(savingsTxOverviewTestIds.apyChange.after) + await expect(currentApyValue).toContainText(transactionOverview.apyChange.current) + await expect(updatedApyValue).toContainText(transactionOverview.apyChange.updated) + } -// await this.expectTransactionOverviewRoute(transactionOverview.routeItems) -// if (transactionOverview.badgeTokens) { -// await this.expectSkyBadgeForTokens(transactionOverview.badgeTokens) -// } -// await this.expectOutcomeText(transactionOverview.outcome) -// } + await this.expectTransactionOverviewRoute(transactionOverview.routeItems) + if (transactionOverview.badgeTokens) { + await this.expectSkyBadgeForTokens(transactionOverview.badgeTokens) + } + await this.expectOutcomeText(transactionOverview.outcome) + } -// async expectUpgradeSuccessPage({ -// token, -// amount, -// usdValue, -// }: { token: string; amount: string; usdValue: string }): Promise { -// await expect(this.region.getByText('Congrats, all done!')).toBeVisible() -// const summary = await this.region.getByTestId(testIds.dialog.success).textContent() -// await expect(summary).toMatch(`${token}${amount} ${usdValue}`) -// } -// // #endregion assertions -// } + async expectUpgradeSuccessPage({ + token, + amount, + usdValue, + }: { token: string; amount: string; usdValue: string }): Promise { + await expect(this.region.getByText('Congrats, all done!')).toBeVisible() + const summary = await this.region.getByTestId(testIds.dialog.success).textContent() + await expect(summary).toMatch(`${token}${amount} ${usdValue}`) + } + // #endregion assertions +} -// interface UpgradeTxOverview extends TxOverviewWithRoute { -// apyChange?: { -// current: string -// updated: string -// } -// } +interface UpgradeTxOverview extends TxOverviewWithRoute { + apyChange?: { + current: string + updated: string + } +} diff --git a/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/DaiToUsds.test-e2e.ts b/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/DaiToUsds.test-e2e.ts index 5ba3183d8..dbc46b945 100644 --- a/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/DaiToUsds.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/DaiToUsds.test-e2e.ts @@ -1,110 +1,123 @@ -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { UpgradeDialogPageObject } from '../UpgradeDialog.PageObject' - -// test.describe('Upgrade DAI to USDS', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - -// test('does not show upgrade button when DAI balance is 0', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { USDS: 10_000 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// // wait to load -// await savingsPage.expectOpportunityStablecoinsAmount('~$10,000.00') - -// await savingsPage.expectUpgradeDaiToUsdsButtonToBeHidden() -// }) - -// test('uses upgrade action', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { DAI: 10_000 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickUpgradeDaiToUsdsButtonAction() - -// const upgradeDialog = new UpgradeDialogPageObject(page) - -// await upgradeDialog.actionsContainer.expectEnabledActionAtIndex(0) -// await upgradeDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'DAI' }, -// { type: 'upgrade', fromToken: 'DAI', toToken: 'USDS' }, -// ]) -// }) - -// test('displays transaction overview', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { DAI: 10_000 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) -// await savingsPage.clickUpgradeDaiToUsdsButtonAction() -// const upgradeDialog = new UpgradeDialogPageObject(page) - -// await upgradeDialog.expectTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '10,000.00 DAI', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// outcome: '10,000.00 USDS', -// outcomeUsd: '$10,000.00', -// }) -// }) - -// test('executes transaction', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { DAI: 10_000 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') -// await savingsPage.clickUpgradeDaiToUsdsButtonAction() - -// const upgradeDialog = new UpgradeDialogPageObject(page) - -// await upgradeDialog.actionsContainer.acceptAllActionsAction(2, fork) -// await upgradeDialog.expectSuccessPage( -// [ -// { -// asset: 'DAI', -// amount: 10_000, -// }, -// ], -// fork, -// ) -// await upgradeDialog.clickBackToSavingsButton() - -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000') -// }) -// }) +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { UpgradeDialogPageObject } from '../UpgradeDialog.PageObject' + +test.describe('Upgrade DAI to USDS', () => { + test('does not show upgrade button when DAI balance is 0', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { USDS: 10_000 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + // wait to load + await savingsPage.expectOpportunityStablecoinsAmount('~$10,000.00') + + await savingsPage.expectUpgradeDaiToUsdsButtonToBeHidden() + }) + + test('uses upgrade action', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { DAI: 10_000 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickUpgradeDaiToUsdsButtonAction() + + const upgradeDialog = new UpgradeDialogPageObject(testContext) + + await upgradeDialog.actionsContainer.expectEnabledActionAtIndex(0) + await upgradeDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'DAI' }, + { type: 'upgrade', fromToken: 'DAI', toToken: 'USDS' }, + ]) + }) + + test('displays transaction overview', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { DAI: 10_000 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickUpgradeDaiToUsdsButtonAction() + const upgradeDialog = new UpgradeDialogPageObject(testContext) + + await upgradeDialog.expectTransactionOverview({ + routeItems: [ + { + tokenAmount: '10,000.00 DAI', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + ], + outcome: '10,000.00 USDS', + outcomeUsd: '$10,000.00', + }) + }) + + test('executes transaction', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { DAI: 10_000 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') + await savingsPage.clickUpgradeDaiToUsdsButtonAction() + + const upgradeDialog = new UpgradeDialogPageObject(testContext) + + await upgradeDialog.actionsContainer.acceptAllActionsAction(2) + await upgradeDialog.expectSuccessPage({ + tokenWithValue: [ + { + asset: 'DAI', + amount: '10,000.00', + usdValue: '$10,000.00', + }, + ], + }) + await upgradeDialog.clickBackToSavingsButton() + + await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/sDaiToSUsds.test-e2e.ts b/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/sDaiToSUsds.test-e2e.ts index 397001c77..811c3518a 100644 --- a/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/sDaiToSUsds.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/sDaiToSUsds.test-e2e.ts @@ -1,105 +1,118 @@ -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { UpgradeDialogPageObject } from '../UpgradeDialog.PageObject' - -// test.describe('Upgrade sDAI to sUSDS', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - -// test('does not show upgrade banner when sDai balance is 0', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { sDAI: 0, sUSDS: 10_000 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// // wait to load -// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '10,000.00 sUSDS', estimatedUsdsValue: '10,000.23' }) - -// await savingsPage.expectUpgradeDaiToUsdsButtonToBeHidden() -// }) - -// test('uses upgrade action', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { sDAI: 10_000 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickUpgradeSDaiButtonAction() - -// const upgradeDialog = new UpgradeDialogPageObject(page) - -// await upgradeDialog.actionsContainer.expectEnabledActionAtIndex(0) -// await upgradeDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'sDAI' }, -// { type: 'upgrade', fromToken: 'sDAI', toToken: 'sUSDS' }, -// ]) -// }) - -// test('displays transaction overview', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { sDAI: 10_000 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickUpgradeSDaiButtonAction() - -// const upgradeDialog = new UpgradeDialogPageObject(page) - -// await upgradeDialog.expectTransactionOverview({ -// apyChange: { -// current: '6.00%', -// updated: '6.25%', -// }, -// routeItems: [ -// { -// tokenAmount: '10,000.00 sDAI', -// tokenUsdValue: '$11,085.91', -// }, -// { -// tokenAmount: '11,085.65 sUSDS', -// tokenUsdValue: '$11,085.91', -// }, -// ], -// outcome: '11,085.65 sUSDS', -// outcomeUsd: '$11,085.91', -// }) -// }) - -// test('executes transaction', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { sDAI: 10_000, sUSDS: 10_000 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) -// await savingsPage.clickUpgradeSDaiButtonAction() - -// const upgradeDialog = new UpgradeDialogPageObject(page) -// await upgradeDialog.actionsContainer.acceptAllActionsAction(2, fork) -// await upgradeDialog.expectUpgradeSuccessPage({ token: 'sDAI', amount: '10,000.00', usdValue: '$11,085.91' }) -// await upgradeDialog.clickBackToSavingsButton() - -// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '21,085.65 sUSDS', estimatedUsdsValue: '21,086.13' }) -// }) -// }) +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { UpgradeDialogPageObject } from '../UpgradeDialog.PageObject' + +test.describe('Upgrade sDAI to sUSDS', () => { + test('does not show upgrade banner when sDai balance is 0', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { sDAI: 0, sUSDS: 10_000 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + // wait to load + await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '10,000.00 sUSDS', estimatedUsdsValue: '10,172.58' }) + + await savingsPage.expectUpgradeDaiToUsdsButtonToBeHidden() + }) + + test('uses upgrade action', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { sDAI: 10_000 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickUpgradeSDaiButtonAction() + + const upgradeDialog = new UpgradeDialogPageObject(testContext) + + await upgradeDialog.actionsContainer.expectEnabledActionAtIndex(0) + await upgradeDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sDAI' }, + { type: 'upgrade', fromToken: 'sDAI', toToken: 'sUSDS' }, + ]) + }) + + test('displays transaction overview', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { sDAI: 10_000 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickUpgradeSDaiButtonAction() + + const upgradeDialog = new UpgradeDialogPageObject(testContext) + + await upgradeDialog.expectTransactionOverview({ + apyChange: { + current: '11.50%', + updated: '12.50%', + }, + routeItems: [ + { + tokenAmount: '10,000.00 sDAI', + tokenUsdValue: '$11,255.99', + }, + { + tokenAmount: '11,065.02 sUSDS', + tokenUsdValue: '$11,255.99', + }, + ], + outcome: '11,065.02 sUSDS', + outcomeUsd: '$11,255.99', + }) + }) + + test('executes transaction', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { sDAI: 10_000, sUSDS: 10_000 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickUpgradeSDaiButtonAction() + + const upgradeDialog = new UpgradeDialogPageObject(testContext) + await upgradeDialog.actionsContainer.acceptAllActionsAction(2) + await upgradeDialog.expectUpgradeSuccessPage({ token: 'sDAI', amount: '10,000.00', usdValue: '$11,255.99' }) + await upgradeDialog.clickBackToSavingsButton() + + await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '21,065.02 sUSDS', estimatedUsdsValue: '21,428.579836' }) + }) +}) From 3a8aa846a0307936c0b17dba5c7c305c372577f3 Mon Sep 17 00:00:00 2001 From: Oskar <43062492+oskarvu@users.noreply.github.com> Date: Sat, 21 Dec 2024 21:31:22 +0700 Subject: [PATCH 23/29] Rewrite convert stables tests (#517) --- .../ConvertStablesDialog.PageObject.ts | 247 +++++++++--------- .../ConvertStablesDialog.test-e2e.ts | 126 ++++----- .../e2e/base/UsdcToUsds.test-e2e.ts | 121 ++++----- .../e2e/base/UsdsToUsdc.test-e2e.ts | 121 ++++----- .../e2e/mainnet/DaiToUsdc.test-e2e.ts | 122 ++++----- .../e2e/mainnet/DaiToUsds.test-e2e.ts | 122 ++++----- .../e2e/mainnet/UsdcToDai.test-e2e.ts | 122 ++++----- .../e2e/mainnet/UsdcToUsds.test-e2e.ts | 122 ++++----- .../e2e/mainnet/UsdsToDai.test-e2e.ts | 122 ++++----- .../e2e/mainnet/UsdsToUsdc.test-e2e.ts | 122 ++++----- 10 files changed, 684 insertions(+), 663 deletions(-) diff --git a/packages/app/src/features/dialogs/convert-stables/ConvertStablesDialog.PageObject.ts b/packages/app/src/features/dialogs/convert-stables/ConvertStablesDialog.PageObject.ts index 24e7bab72..d75088ad3 100644 --- a/packages/app/src/features/dialogs/convert-stables/ConvertStablesDialog.PageObject.ts +++ b/packages/app/src/features/dialogs/convert-stables/ConvertStablesDialog.PageObject.ts @@ -1,123 +1,124 @@ -// import { DialogPageObject, TxOverviewWithRoute } from '@/features/dialogs/common/Dialog.PageObject' -// import { testIds } from '@/ui/utils/testIds' -// import { Locator, Page, expect } from '@playwright/test' - -// export class ConvertStablesDialogPageObject extends DialogPageObject { -// constructor(page: Page) { -// super(page, /Convert Tokens/) -// } - -// // # region locators -// locateAssetInSelector(): Locator { -// return this.region.getByTestId(testIds.component.AssetSelector.trigger).first() -// } - -// locateAssetOutSelector(): Locator { -// return this.region.getByTestId(testIds.component.AssetSelector.trigger).last() -// } - -// locateAssetInInput(): Locator { -// return this.region.getByTestId(testIds.component.AssetInput.input).first() -// } - -// locateAssetOutInput(): Locator { -// return this.region.getByTestId(testIds.component.AssetInput.input).last() -// } - -// locateAssetInMaxButton(): Locator { -// return this.region.getByTestId(testIds.component.AssetInput.maxButton).first() -// } - -// locateAssetOutMaxButton(): Locator { -// return this.region.getByTestId(testIds.component.AssetInput.maxButton).last() -// } -// // #endregion locators - -// // #region actions -// async selectAssetInAction(asset: string): Promise { -// const selector = this.locateAssetInSelector() -// await this.selectOptionByLabelAction(selector, asset) -// } - -// async selectAssetOutAction(asset: string): Promise { -// const selector = this.locateAssetOutSelector() -// await this.selectOptionByLabelAction(selector, asset) -// } - -// async openAssetInSelectorAction(): Promise { -// await this.locateAssetInSelector().click() -// } - -// async openAssetOutSelectorAction(): Promise { -// await this.locateAssetOutSelector().click() -// } - -// async fillAmountInAction(amount: number): Promise { -// await this.locateAssetInInput().fill(amount.toString()) -// } - -// async fillAmountOutAction(amount: number): Promise { -// await this.locateAssetOutInput().fill(amount.toString()) -// } - -// async clickMaxAmountInAction(): Promise { -// await this.locateAssetInMaxButton().click() -// } - -// async clickMaxAmountOutAction(): Promise { -// await this.locateAssetOutMaxButton().click() -// } - -// async clickBackToSavingsButton(): Promise { -// await this.page.getByRole('button', { name: 'Back to Savings' }).click() -// await this.region.waitFor({ -// state: 'detached', -// }) -// } -// // #endregion actions - -// // #region assertions -// async expectSuccessPage(): Promise { -// await expect(this.page.getByText('Congrats, all done!')).toBeVisible() -// } - -// async expectTransactionOverview(transactionOverview: TxOverviewWithRoute): Promise { -// await this.expectTransactionOverviewRoute(transactionOverview.routeItems) -// await this.expectOutcomeText(transactionOverview.outcome) -// if (transactionOverview.outcomeUsd) { -// await this.expectOutcomeUsdText(transactionOverview.outcomeUsd) -// } -// } - -// async expectAssetInSelectorSelectedOption(option: string): Promise { -// await expect(this.locateAssetInSelector()).toHaveText(option) -// } - -// async expectAssetOutSelectorSelectedOption(option: string): Promise { -// await expect(this.locateAssetOutSelector()).toHaveText(option) -// } - -// async expectSelectorOptions(options: string[]): Promise { -// const selectorOptions = await this.page.getByTestId(testIds.component.AssetSelector.option).all() -// expect(selectorOptions).toHaveLength(options.length) - -// for (const [index, option] of selectorOptions.entries()) { -// await expect(option).toContainText(options[index]!) -// } -// } - -// async expectAssetInInputValue(value: string): Promise { -// await expect(this.locateAssetInInput()).toHaveValue(value) -// } - -// async expectAssetOutInputValue(value: string): Promise { -// await expect(this.locateAssetOutInput()).toHaveValue(value) -// } - -// async expectSingleInputError(error: string): Promise { -// const inputError = this.page.getByTestId(testIds.component.AssetInput.error) -// await expect(inputError).toHaveCount(1) -// await expect(inputError).toHaveText(error) -// } -// // #endregion assertions -// } +import { DialogPageObject, TxOverviewWithRoute } from '@/features/dialogs/common/Dialog.PageObject' +import { TestContext } from '@/test/e2e/setup' +import { testIds } from '@/ui/utils/testIds' +import { Locator, expect } from '@playwright/test' + +export class ConvertStablesDialogPageObject extends DialogPageObject { + constructor(testContext: TestContext) { + super({ testContext, header: /Convert Tokens/ }) + } + + // # region locators + locateAssetInSelector(): Locator { + return this.region.getByTestId(testIds.component.AssetSelector.trigger).first() + } + + locateAssetOutSelector(): Locator { + return this.region.getByTestId(testIds.component.AssetSelector.trigger).last() + } + + locateAssetInInput(): Locator { + return this.region.getByTestId(testIds.component.AssetInput.input).first() + } + + locateAssetOutInput(): Locator { + return this.region.getByTestId(testIds.component.AssetInput.input).last() + } + + locateAssetInMaxButton(): Locator { + return this.region.getByTestId(testIds.component.AssetInput.maxButton).first() + } + + locateAssetOutMaxButton(): Locator { + return this.region.getByTestId(testIds.component.AssetInput.maxButton).last() + } + // #endregion locators + + // #region actions + async selectAssetInAction(asset: string): Promise { + const selector = this.locateAssetInSelector() + await this.selectOptionByLabelAction(selector, asset) + } + + async selectAssetOutAction(asset: string): Promise { + const selector = this.locateAssetOutSelector() + await this.selectOptionByLabelAction(selector, asset) + } + + async openAssetInSelectorAction(): Promise { + await this.locateAssetInSelector().click() + } + + async openAssetOutSelectorAction(): Promise { + await this.locateAssetOutSelector().click() + } + + async fillAmountInAction(amount: number): Promise { + await this.locateAssetInInput().fill(amount.toString()) + } + + async fillAmountOutAction(amount: number): Promise { + await this.locateAssetOutInput().fill(amount.toString()) + } + + async clickMaxAmountInAction(): Promise { + await this.locateAssetInMaxButton().click() + } + + async clickMaxAmountOutAction(): Promise { + await this.locateAssetOutMaxButton().click() + } + + async clickBackToSavingsButton(): Promise { + await this.page.getByRole('button', { name: 'Back to Savings' }).click() + await this.region.waitFor({ + state: 'detached', + }) + } + // #endregion actions + + // #region assertions + async expectSuccessPage(): Promise { + await expect(this.page.getByText('Congrats, all done!')).toBeVisible() + } + + async expectTransactionOverview(transactionOverview: TxOverviewWithRoute): Promise { + await this.expectTransactionOverviewRoute(transactionOverview.routeItems) + await this.expectOutcomeText(transactionOverview.outcome) + if (transactionOverview.outcomeUsd) { + await this.expectOutcomeUsdText(transactionOverview.outcomeUsd) + } + } + + async expectAssetInSelectorSelectedOption(option: string): Promise { + await expect(this.locateAssetInSelector()).toHaveText(option) + } + + async expectAssetOutSelectorSelectedOption(option: string): Promise { + await expect(this.locateAssetOutSelector()).toHaveText(option) + } + + async expectSelectorOptions(options: string[]): Promise { + const selectorOptions = await this.page.getByTestId(testIds.component.AssetSelector.option).all() + expect(selectorOptions).toHaveLength(options.length) + + for (const [index, option] of selectorOptions.entries()) { + await expect(option).toContainText(options[index]!) + } + } + + async expectAssetInInputValue(value: string): Promise { + await expect(this.locateAssetInInput()).toHaveValue(value) + } + + async expectAssetOutInputValue(value: string): Promise { + await expect(this.locateAssetOutInput()).toHaveValue(value) + } + + async expectSingleInputError(error: string): Promise { + const inputError = this.page.getByTestId(testIds.component.AssetInput.error) + await expect(inputError).toHaveCount(1) + await expect(inputError).toHaveText(error) + } + // #endregion assertions +} diff --git a/packages/app/src/features/dialogs/convert-stables/ConvertStablesDialog.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/ConvertStablesDialog.test-e2e.ts index 66920cc48..9a31dd640 100644 --- a/packages/app/src/features/dialogs/convert-stables/ConvertStablesDialog.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/ConvertStablesDialog.test-e2e.ts @@ -1,75 +1,77 @@ -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { ConvertStablesDialogPageObject } from './ConvertStablesDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { ConvertStablesDialogPageObject } from './ConvertStablesDialog.PageObject' -// test.describe('Convert Stables Dialog', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let convertStablesDialog: ConvertStablesDialogPageObject +test.describe('Convert Stables Dialog', () => { + let savingsPage: SavingsPageObject + let convertStablesDialog: ConvertStablesDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// DAI: 10_000, -// }, -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + DAI: 10_000, + }, + }, + }) -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickConvertStablesButtonAction() -// convertStablesDialog = new ConvertStablesDialogPageObject(page) -// }) + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickConvertStablesButtonAction() + convertStablesDialog = new ConvertStablesDialogPageObject(testContext) + }) -// test('has correct selectors configuration', async ({ page }) => { -// await convertStablesDialog.expectAssetInSelectorSelectedOption('DAI') -// await convertStablesDialog.openAssetInSelectorAction() -// await convertStablesDialog.expectSelectorOptions(['USDC', 'USDS']) -// await page.keyboard.press('Escape') // closing selector + test('has correct selectors configuration', async ({ page }) => { + await convertStablesDialog.expectAssetInSelectorSelectedOption('DAI') + await convertStablesDialog.openAssetInSelectorAction() + await convertStablesDialog.expectSelectorOptions(['USDC', 'USDS']) + await page.keyboard.press('Escape') // closing selector -// await convertStablesDialog.expectAssetOutSelectorSelectedOption('USDC') -// await convertStablesDialog.openAssetOutSelectorAction() -// await convertStablesDialog.expectSelectorOptions(['USDS']) // no DAI option cause already selected in first selector -// }) + await convertStablesDialog.expectAssetOutSelectorSelectedOption('USDC') + await convertStablesDialog.openAssetOutSelectorAction() + await convertStablesDialog.expectSelectorOptions(['USDS']) // no DAI option cause already selected in first selector + }) -// test('first selector can override second selector', async () => { -// await convertStablesDialog.expectAssetInSelectorSelectedOption('DAI') -// await convertStablesDialog.expectAssetOutSelectorSelectedOption('USDC') + test('first selector can override second selector', async () => { + await convertStablesDialog.expectAssetInSelectorSelectedOption('DAI') + await convertStablesDialog.expectAssetOutSelectorSelectedOption('USDC') -// await convertStablesDialog.selectAssetInAction('USDC') // choosing already selected in second selector option + await convertStablesDialog.selectAssetInAction('USDC') // choosing already selected in second selector option -// await convertStablesDialog.expectAssetOutSelectorSelectedOption('DAI') // fist selector can override second -// await convertStablesDialog.openAssetOutSelectorAction() -// await convertStablesDialog.expectSelectorOptions(['USDS']) -// }) + await convertStablesDialog.expectAssetOutSelectorSelectedOption('DAI') // fist selector can override second + await convertStablesDialog.openAssetOutSelectorAction() + await convertStablesDialog.expectSelectorOptions(['USDS']) + }) -// test('changing value of any input updates both inputs', async () => { -// await convertStablesDialog.fillAmountInAction(5000) -// await convertStablesDialog.expectAssetInInputValue('5000') -// await convertStablesDialog.expectAssetOutInputValue('5000') + test('changing value of any input updates both inputs', async () => { + await convertStablesDialog.fillAmountInAction(5000) + await convertStablesDialog.expectAssetInInputValue('5000') + await convertStablesDialog.expectAssetOutInputValue('5000') -// await convertStablesDialog.clickMaxAmountInAction() -// await convertStablesDialog.expectAssetInInputValue('10000') -// await convertStablesDialog.expectAssetOutInputValue('10000') + await convertStablesDialog.clickMaxAmountInAction() + await convertStablesDialog.expectAssetInInputValue('10000') + await convertStablesDialog.expectAssetOutInputValue('10000') -// await convertStablesDialog.fillAmountOutAction(8_000) -// await convertStablesDialog.expectAssetInInputValue('8000') -// await convertStablesDialog.expectAssetOutInputValue('8000') + await convertStablesDialog.fillAmountOutAction(8_000) + await convertStablesDialog.expectAssetInInputValue('8000') + await convertStablesDialog.expectAssetOutInputValue('8000') -// await convertStablesDialog.clickMaxAmountOutAction() -// await convertStablesDialog.expectAssetInInputValue('10000') -// await convertStablesDialog.expectAssetOutInputValue('10000') -// }) + await convertStablesDialog.clickMaxAmountOutAction() + await convertStablesDialog.expectAssetInInputValue('10000') + await convertStablesDialog.expectAssetOutInputValue('10000') + }) -// test('displays validation error only for first input', async () => { -// await convertStablesDialog.fillAmountInAction(20_000) -// await convertStablesDialog.expectSingleInputError('Exceeds your balance') -// }) -// }) + test('displays validation error only for first input', async () => { + await convertStablesDialog.fillAmountInAction(20_000) + await convertStablesDialog.expectSingleInputError('Exceeds your balance') + }) +}) diff --git a/packages/app/src/features/dialogs/convert-stables/e2e/base/UsdcToUsds.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/e2e/base/UsdcToUsds.test-e2e.ts index e3b5f98e7..0ac9048ad 100644 --- a/packages/app/src/features/dialogs/convert-stables/e2e/base/UsdcToUsds.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/e2e/base/UsdcToUsds.test-e2e.ts @@ -1,66 +1,69 @@ -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { base } from 'viem/chains' -// import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { BASE_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { base } from 'viem/chains' +import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' -// test.describe('Convert USDC to USDS', () => { -// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let convertStablesDialog: ConvertStablesDialogPageObject +test.describe('Convert USDC to USDS', () => { + let savingsPage: SavingsPageObject + let convertStablesDialog: ConvertStablesDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// USDC: 10_000, -// }, -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: BASE_DEFAULT_BLOCK_NUMBER, + chainId: base.id, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDC: 10_000, + }, + }, + }) -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickConvertStablesButtonAction() + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickConvertStablesButtonAction() -// convertStablesDialog = new ConvertStablesDialogPageObject(page) -// await convertStablesDialog.selectAssetInAction('USDC') -// await convertStablesDialog.selectAssetOutAction('USDS') -// await convertStablesDialog.fillAmountInAction(10_000) -// }) + convertStablesDialog = new ConvertStablesDialogPageObject(testContext) + await convertStablesDialog.selectAssetInAction('USDC') + await convertStablesDialog.selectAssetOutAction('USDS') + await convertStablesDialog.fillAmountInAction(10_000) + }) -// test('uses psm convert action', async () => { -// await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) -// await convertStablesDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'USDC' }, -// { type: 'psmConvert', inToken: 'USDC', outToken: 'USDS' }, -// ]) -// }) + test('uses psm convert action', async () => { + await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) + await convertStablesDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'USDC' }, + { type: 'psmConvert', inToken: 'USDC', outToken: 'USDS' }, + ]) + }) -// test('displays transaction overview', async () => { -// await convertStablesDialog.expectTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '10,000.00 USDC', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// outcome: '10,000.00 USDS', -// outcomeUsd: '$10,000.00', -// }) -// }) + test('displays transaction overview', async () => { + await convertStablesDialog.expectTransactionOverview({ + routeItems: [ + { + tokenAmount: '10,000.00 USDC', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + ], + outcome: '10,000.00 USDS', + outcomeUsd: '$10,000.00', + }) + }) -// test('executes conversion', async () => { -// await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) -// await convertStablesDialog.expectSuccessPage() -// await convertStablesDialog.clickBackToSavingsButton() -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000.00') -// }) -// }) + test('executes conversion', async () => { + await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) + await convertStablesDialog.expectSuccessPage() + await convertStablesDialog.clickBackToSavingsButton() + await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') + await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000.00') + }) +}) diff --git a/packages/app/src/features/dialogs/convert-stables/e2e/base/UsdsToUsdc.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/e2e/base/UsdsToUsdc.test-e2e.ts index 0591f3253..bd59d4e1e 100644 --- a/packages/app/src/features/dialogs/convert-stables/e2e/base/UsdsToUsdc.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/e2e/base/UsdsToUsdc.test-e2e.ts @@ -1,66 +1,69 @@ -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { base } from 'viem/chains' -// import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { BASE_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { base } from 'viem/chains' +import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' -// test.describe('Convert USDS to USDC', () => { -// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let convertStablesDialog: ConvertStablesDialogPageObject +test.describe('Convert USDS to USDC', () => { + let savingsPage: SavingsPageObject + let convertStablesDialog: ConvertStablesDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// USDS: 10_000, -// }, -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: BASE_DEFAULT_BLOCK_NUMBER, + chainId: base.id, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDS: 10_000, + }, + }, + }) -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickConvertStablesButtonAction() + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickConvertStablesButtonAction() -// convertStablesDialog = new ConvertStablesDialogPageObject(page) -// await convertStablesDialog.selectAssetInAction('USDS') -// await convertStablesDialog.selectAssetOutAction('USDC') -// await convertStablesDialog.fillAmountInAction(10_000) -// }) + convertStablesDialog = new ConvertStablesDialogPageObject(testContext) + await convertStablesDialog.selectAssetInAction('USDS') + await convertStablesDialog.selectAssetOutAction('USDC') + await convertStablesDialog.fillAmountInAction(10_000) + }) -// test('uses psm convert action', async () => { -// await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) -// await convertStablesDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'USDS' }, -// { type: 'psmConvert', inToken: 'USDS', outToken: 'USDC' }, -// ]) -// }) + test('uses psm convert action', async () => { + await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) + await convertStablesDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'USDS' }, + { type: 'psmConvert', inToken: 'USDS', outToken: 'USDC' }, + ]) + }) -// test('displays transaction overview', async () => { -// await convertStablesDialog.expectTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '10,000.00 USDC', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// outcome: '10,000.00 USDC', -// outcomeUsd: '$10,000.00', -// }) -// }) + test('displays transaction overview', async () => { + await convertStablesDialog.expectTransactionOverview({ + routeItems: [ + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '10,000.00 USDC', + tokenUsdValue: '$10,000.00', + }, + ], + outcome: '10,000.00 USDC', + outcomeUsd: '$10,000.00', + }) + }) -// test('executes conversion', async () => { -// await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) -// await convertStablesDialog.expectSuccessPage() -// await convertStablesDialog.clickBackToSavingsButton() -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '10,000.00') -// }) -// }) + test('executes conversion', async () => { + await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) + await convertStablesDialog.expectSuccessPage() + await convertStablesDialog.clickBackToSavingsButton() + await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') + await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '10,000.00') + }) +}) diff --git a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsdc.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsdc.test-e2e.ts index 29f46ec5d..fd535b167 100644 --- a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsdc.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsdc.test-e2e.ts @@ -1,67 +1,69 @@ -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' -// test.describe('Convert DAI to USDC', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let convertStablesDialog: ConvertStablesDialogPageObject +test.describe('Convert DAI to USDC', () => { + let savingsPage: SavingsPageObject + let convertStablesDialog: ConvertStablesDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// DAI: 10_000, -// }, -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + DAI: 10_000, + }, + }, + }) -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickConvertStablesButtonAction() + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickConvertStablesButtonAction() -// convertStablesDialog = new ConvertStablesDialogPageObject(page) -// await convertStablesDialog.selectAssetInAction('DAI') -// await convertStablesDialog.selectAssetOutAction('USDC') -// await convertStablesDialog.fillAmountInAction(10_000) -// }) + convertStablesDialog = new ConvertStablesDialogPageObject(testContext) + await convertStablesDialog.selectAssetInAction('DAI') + await convertStablesDialog.selectAssetOutAction('USDC') + await convertStablesDialog.fillAmountInAction(10_000) + }) -// test('uses psm convert action', async () => { -// await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) -// await convertStablesDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'DAI' }, -// { type: 'psmConvert', inToken: 'DAI', outToken: 'USDC' }, -// ]) -// }) + test('uses psm convert action', async () => { + await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) + await convertStablesDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'DAI' }, + { type: 'psmConvert', inToken: 'DAI', outToken: 'USDC' }, + ]) + }) -// test('displays transaction overview', async () => { -// await convertStablesDialog.expectTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '10,000.00 DAI', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '10,000.00 USDC', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// outcome: '10,000.00 USDC', -// outcomeUsd: '$10,000.00', -// }) -// }) + test('displays transaction overview', async () => { + await convertStablesDialog.expectTransactionOverview({ + routeItems: [ + { + tokenAmount: '10,000.00 DAI', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '10,000.00 USDC', + tokenUsdValue: '$10,000.00', + }, + ], + outcome: '10,000.00 USDC', + outcomeUsd: '$10,000.00', + }) + }) -// test('executes conversion', async () => { -// await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) -// await convertStablesDialog.expectSuccessPage() -// await convertStablesDialog.clickBackToSavingsButton() -// await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '10,000.00') -// }) -// }) + test('executes conversion', async () => { + await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) + await convertStablesDialog.expectSuccessPage() + await convertStablesDialog.clickBackToSavingsButton() + await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') + await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '10,000.00') + }) +}) diff --git a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsds.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsds.test-e2e.ts index 4951bab59..df67ccb42 100644 --- a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsds.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/DaiToUsds.test-e2e.ts @@ -1,67 +1,69 @@ -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' -// test.describe('Convert DAI to USDS', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let convertStablesDialog: ConvertStablesDialogPageObject +test.describe('Convert DAI to USDS', () => { + let savingsPage: SavingsPageObject + let convertStablesDialog: ConvertStablesDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// DAI: 10_000, -// }, -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + DAI: 10_000, + }, + }, + }) -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickConvertStablesButtonAction() + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickConvertStablesButtonAction() -// convertStablesDialog = new ConvertStablesDialogPageObject(page) -// await convertStablesDialog.selectAssetInAction('DAI') -// await convertStablesDialog.selectAssetOutAction('USDS') -// await convertStablesDialog.fillAmountInAction(10_000) -// }) + convertStablesDialog = new ConvertStablesDialogPageObject(testContext) + await convertStablesDialog.selectAssetInAction('DAI') + await convertStablesDialog.selectAssetOutAction('USDS') + await convertStablesDialog.fillAmountInAction(10_000) + }) -// test('uses upgrade action', async () => { -// await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) -// await convertStablesDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'DAI' }, -// { type: 'upgrade', fromToken: 'DAI', toToken: 'USDS' }, -// ]) -// }) + test('uses upgrade action', async () => { + await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) + await convertStablesDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'DAI' }, + { type: 'upgrade', fromToken: 'DAI', toToken: 'USDS' }, + ]) + }) -// test('displays transaction overview', async () => { -// await convertStablesDialog.expectTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '10,000.00 DAI', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// outcome: '10,000.00 USDS', -// outcomeUsd: '$10,000.00', -// }) -// }) + test('displays transaction overview', async () => { + await convertStablesDialog.expectTransactionOverview({ + routeItems: [ + { + tokenAmount: '10,000.00 DAI', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + ], + outcome: '10,000.00 USDS', + outcomeUsd: '$10,000.00', + }) + }) -// test('executes conversion', async () => { -// await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) -// await convertStablesDialog.expectSuccessPage() -// await convertStablesDialog.clickBackToSavingsButton() -// await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000.00') -// }) -// }) + test('executes conversion', async () => { + await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) + await convertStablesDialog.expectSuccessPage() + await convertStablesDialog.clickBackToSavingsButton() + await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') + await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000.00') + }) +}) diff --git a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToDai.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToDai.test-e2e.ts index 8efceca4a..15f35e0eb 100644 --- a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToDai.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToDai.test-e2e.ts @@ -1,67 +1,69 @@ -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' -// test.describe('Convert USDC to DAI', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let convertStablesDialog: ConvertStablesDialogPageObject +test.describe('Convert USDC to DAI', () => { + let savingsPage: SavingsPageObject + let convertStablesDialog: ConvertStablesDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// USDC: 10_000, -// }, -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDC: 10_000, + }, + }, + }) -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickConvertStablesButtonAction() + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickConvertStablesButtonAction() -// convertStablesDialog = new ConvertStablesDialogPageObject(page) -// await convertStablesDialog.selectAssetInAction('USDC') -// await convertStablesDialog.selectAssetOutAction('DAI') -// await convertStablesDialog.fillAmountInAction(10_000) -// }) + convertStablesDialog = new ConvertStablesDialogPageObject(testContext) + await convertStablesDialog.selectAssetInAction('USDC') + await convertStablesDialog.selectAssetOutAction('DAI') + await convertStablesDialog.fillAmountInAction(10_000) + }) -// test('uses psm convert action', async () => { -// await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) -// await convertStablesDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'USDC' }, -// { type: 'psmConvert', inToken: 'USDC', outToken: 'DAI' }, -// ]) -// }) + test('uses psm convert action', async () => { + await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) + await convertStablesDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'USDC' }, + { type: 'psmConvert', inToken: 'USDC', outToken: 'DAI' }, + ]) + }) -// test('displays transaction overview', async () => { -// await convertStablesDialog.expectTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '10,000.00 USDC', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '10,000.00 DAI', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// outcome: '10,000.00 DAI', -// outcomeUsd: '$10,000.00', -// }) -// }) + test('displays transaction overview', async () => { + await convertStablesDialog.expectTransactionOverview({ + routeItems: [ + { + tokenAmount: '10,000.00 USDC', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '10,000.00 DAI', + tokenUsdValue: '$10,000.00', + }, + ], + outcome: '10,000.00 DAI', + outcomeUsd: '$10,000.00', + }) + }) -// test('executes conversion', async () => { -// await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) -// await convertStablesDialog.expectSuccessPage() -// await convertStablesDialog.clickBackToSavingsButton() -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') -// await savingsPage.expectUpgradableDaiBalance('10,000.00') -// }) -// }) + test('executes conversion', async () => { + await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) + await convertStablesDialog.expectSuccessPage() + await convertStablesDialog.clickBackToSavingsButton() + await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') + await savingsPage.expectUpgradableDaiBalance('10,000.00') + }) +}) diff --git a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToUsds.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToUsds.test-e2e.ts index 92ecc0188..7c8568311 100644 --- a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToUsds.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdcToUsds.test-e2e.ts @@ -1,67 +1,69 @@ -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' -// test.describe('Convert USDC to USDS', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let convertStablesDialog: ConvertStablesDialogPageObject +test.describe('Convert USDC to USDS', () => { + let savingsPage: SavingsPageObject + let convertStablesDialog: ConvertStablesDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// USDC: 10_000, -// }, -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDC: 10_000, + }, + }, + }) -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickConvertStablesButtonAction() + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickConvertStablesButtonAction() -// convertStablesDialog = new ConvertStablesDialogPageObject(page) -// await convertStablesDialog.selectAssetInAction('USDC') -// await convertStablesDialog.selectAssetOutAction('USDS') -// await convertStablesDialog.fillAmountInAction(10_000) -// }) + convertStablesDialog = new ConvertStablesDialogPageObject(testContext) + await convertStablesDialog.selectAssetInAction('USDC') + await convertStablesDialog.selectAssetOutAction('USDS') + await convertStablesDialog.fillAmountInAction(10_000) + }) -// test('uses psm convert action', async () => { -// await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) -// await convertStablesDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'USDC' }, -// { type: 'psmConvert', inToken: 'USDC', outToken: 'USDS' }, -// ]) -// }) + test('uses psm convert action', async () => { + await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) + await convertStablesDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'USDC' }, + { type: 'psmConvert', inToken: 'USDC', outToken: 'USDS' }, + ]) + }) -// test('displays transaction overview', async () => { -// await convertStablesDialog.expectTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '10,000.00 USDC', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// outcome: '10,000.00 USDS', -// outcomeUsd: '$10,000.00', -// }) -// }) + test('displays transaction overview', async () => { + await convertStablesDialog.expectTransactionOverview({ + routeItems: [ + { + tokenAmount: '10,000.00 USDC', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + ], + outcome: '10,000.00 USDS', + outcomeUsd: '$10,000.00', + }) + }) -// test('executes conversion', async () => { -// await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) -// await convertStablesDialog.expectSuccessPage() -// await convertStablesDialog.clickBackToSavingsButton() -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000.00') -// }) -// }) + test('executes conversion', async () => { + await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) + await convertStablesDialog.expectSuccessPage() + await convertStablesDialog.clickBackToSavingsButton() + await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') + await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000.00') + }) +}) diff --git a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToDai.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToDai.test-e2e.ts index e9bbf16df..9c04e05f4 100644 --- a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToDai.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToDai.test-e2e.ts @@ -1,67 +1,69 @@ -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' -// test.describe('Convert USDS to DAI', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let convertStablesDialog: ConvertStablesDialogPageObject +test.describe('Convert USDS to DAI', () => { + let savingsPage: SavingsPageObject + let convertStablesDialog: ConvertStablesDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// USDS: 10_000, -// }, -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDS: 10_000, + }, + }, + }) -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickConvertStablesButtonAction() + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickConvertStablesButtonAction() -// convertStablesDialog = new ConvertStablesDialogPageObject(page) -// await convertStablesDialog.selectAssetInAction('USDS') -// await convertStablesDialog.selectAssetOutAction('DAI') -// await convertStablesDialog.fillAmountInAction(10_000) -// }) + convertStablesDialog = new ConvertStablesDialogPageObject(testContext) + await convertStablesDialog.selectAssetInAction('USDS') + await convertStablesDialog.selectAssetOutAction('DAI') + await convertStablesDialog.fillAmountInAction(10_000) + }) -// test('uses downgrade action', async () => { -// await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) -// await convertStablesDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'USDS' }, -// { type: 'downgrade', fromToken: 'USDS', toToken: 'DAI' }, -// ]) -// }) + test('uses downgrade action', async () => { + await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) + await convertStablesDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'USDS' }, + { type: 'downgrade', fromToken: 'USDS', toToken: 'DAI' }, + ]) + }) -// test('displays transaction overview', async () => { -// await convertStablesDialog.expectTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '10,000.00 DAI', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// outcome: '10,000.00 DAI', -// outcomeUsd: '$10,000.00', -// }) -// }) + test('displays transaction overview', async () => { + await convertStablesDialog.expectTransactionOverview({ + routeItems: [ + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '10,000.00 DAI', + tokenUsdValue: '$10,000.00', + }, + ], + outcome: '10,000.00 DAI', + outcomeUsd: '$10,000.00', + }) + }) -// test('executes conversion', async () => { -// await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) -// await convertStablesDialog.expectSuccessPage() -// await convertStablesDialog.clickBackToSavingsButton() -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') -// await savingsPage.expectUpgradableDaiBalance('10,000.00') -// }) -// }) + test('executes conversion', async () => { + await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) + await convertStablesDialog.expectSuccessPage() + await convertStablesDialog.clickBackToSavingsButton() + await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') + await savingsPage.expectUpgradableDaiBalance('10,000.00') + }) +}) diff --git a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToUsdc.test-e2e.ts b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToUsdc.test-e2e.ts index ce075748b..1e84f5d25 100644 --- a/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToUsdc.test-e2e.ts +++ b/packages/app/src/features/dialogs/convert-stables/e2e/mainnet/UsdsToUsdc.test-e2e.ts @@ -1,67 +1,69 @@ -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { ConvertStablesDialogPageObject } from '../../ConvertStablesDialog.PageObject' -// test.describe('Convert USDS to USDC', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let convertStablesDialog: ConvertStablesDialogPageObject +test.describe('Convert USDS to USDC', () => { + let savingsPage: SavingsPageObject + let convertStablesDialog: ConvertStablesDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// USDS: 10_000, -// }, -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDS: 10_000, + }, + }, + }) -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickConvertStablesButtonAction() + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickConvertStablesButtonAction() -// convertStablesDialog = new ConvertStablesDialogPageObject(page) -// await convertStablesDialog.selectAssetInAction('USDS') -// await convertStablesDialog.selectAssetOutAction('USDC') -// await convertStablesDialog.fillAmountInAction(10_000) -// }) + convertStablesDialog = new ConvertStablesDialogPageObject(testContext) + await convertStablesDialog.selectAssetInAction('USDS') + await convertStablesDialog.selectAssetOutAction('USDC') + await convertStablesDialog.fillAmountInAction(10_000) + }) -// test('uses psm convert action', async () => { -// await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) -// await convertStablesDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'USDS' }, -// { type: 'psmConvert', inToken: 'USDS', outToken: 'USDC' }, -// ]) -// }) + test('uses psm convert action', async () => { + await convertStablesDialog.actionsContainer.expectEnabledActionAtIndex(0) + await convertStablesDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'USDS' }, + { type: 'psmConvert', inToken: 'USDS', outToken: 'USDC' }, + ]) + }) -// test('displays transaction overview', async () => { -// await convertStablesDialog.expectTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '10,000.00 USDC', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// outcome: '10,000.00 USDC', -// outcomeUsd: '$10,000.00', -// }) -// }) + test('displays transaction overview', async () => { + await convertStablesDialog.expectTransactionOverview({ + routeItems: [ + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '10,000.00 USDC', + tokenUsdValue: '$10,000.00', + }, + ], + outcome: '10,000.00 USDC', + outcomeUsd: '$10,000.00', + }) + }) -// test('executes conversion', async () => { -// await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) -// await convertStablesDialog.expectSuccessPage() -// await convertStablesDialog.clickBackToSavingsButton() -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '10,000.00') -// }) -// }) + test('executes conversion', async () => { + await convertStablesDialog.actionsContainer.acceptAllActionsAction(2) + await convertStablesDialog.expectSuccessPage() + await convertStablesDialog.clickBackToSavingsButton() + await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') + await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '10,000.00') + }) +}) From 891b8edb6246c2e7f0eba5ba584a683bbadd012e Mon Sep 17 00:00:00 2001 From: Oskar <43062492+oskarvu@users.noreply.github.com> Date: Sat, 21 Dec 2024 21:36:12 +0700 Subject: [PATCH 24/29] Rewrite collateral dialog tests (#518) --- .../collateral/CollateralDialog.test-e2e.ts | 862 +++++++++--------- 1 file changed, 443 insertions(+), 419 deletions(-) diff --git a/packages/app/src/features/dialogs/collateral/CollateralDialog.test-e2e.ts b/packages/app/src/features/dialogs/collateral/CollateralDialog.test-e2e.ts index 2b3be99b4..afc20407d 100644 --- a/packages/app/src/features/dialogs/collateral/CollateralDialog.test-e2e.ts +++ b/packages/app/src/features/dialogs/collateral/CollateralDialog.test-e2e.ts @@ -1,419 +1,443 @@ -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' - -// import { setUseAsCollateralValidationIssueToMessage } from '@/domain/market-validators/validateSetUseAsCollateral' -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { BorrowPageObject } from '@/pages/Borrow.PageObject' -// import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' -// import { DEFAULT_BLOCK_NUMBER, GNO_ACTIVE_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' - -// import { DialogPageObject } from '../common/Dialog.PageObject' -// import { CollateralDialogPageObject } from './CollateralDialog.PageObject' - -// test.describe('Collateral dialog', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) -// const initialBalances = { -// wstETH: 100, -// rETH: 100, -// DAI: 10000, -// GNO: 100, -// } - -// test.describe('Deposited multiple assets, no borrow', () => { -// const initialDeposits = { -// wstETH: 1, -// } -// const myPortfolioDesposits = { -// DAI: 1000, // cannot be used as collateral -// } - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ...initialBalances }, -// }, -// }) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositWithoutBorrowActions(initialDeposits) -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.goToMyPortfolioAction() - -// // Depositing DAI in myPortfolio -// await myPortfolioPage.clickDepositButtonAction('DAI') -// const depositDialog = new DialogPageObject(page, /Deposit/) -// await depositDialog.fillAmountAction(myPortfolioDesposits.DAI) -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) -// await depositDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.expectDepositTable({ -// wstETH: initialDeposits.wstETH, -// DAI: myPortfolioDesposits.DAI, -// }) -// }) - -// test('disables collateral', async ({ page }) => { -// const collateral = 'wstETH' - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.expectCollateralSwitch(collateral, true) -// await myPortfolioPage.clickCollateralSwitchAction(collateral) - -// const collateralDialog = new CollateralDialogPageObject(page) -// await collateralDialog.expectDialogHeader('Collateral') -// await collateralDialog.expectHealthFactorNotVisible() -// const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(1) -// await collateralDialog.expectSetUseAsCollateralSuccessPage(collateral, 'disabled') - -// await myPortfolioPage.goToMyPortfolioAction() -// await myPortfolioPage.expectCollateralSwitch('wstETH', false) -// }) - -// test('enables collateral', async ({ page }) => { -// const collateral = 'wstETH' - -// // disabling collateral -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickCollateralSwitchAction(collateral) -// const collateralDialog = new CollateralDialogPageObject(page) -// await collateralDialog.setUseAsCollateralAction(collateral, 'disabled') -// await myPortfolioPage.goToMyPortfolioAction() - -// // enabling collateral -// await myPortfolioPage.expectCollateralSwitch(collateral, false) -// await myPortfolioPage.clickCollateralSwitchAction(collateral) -// await collateralDialog.expectDialogHeader('Collateral') -// await collateralDialog.expectHealthFactorNotVisible() -// const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(1) -// await collateralDialog.expectSetUseAsCollateralSuccessPage(collateral, 'enabled') - -// await myPortfolioPage.goToMyPortfolioAction() -// await myPortfolioPage.expectCollateralSwitch(collateral, true) -// }) - -// test('cannot enable collateral for asset that cannot be used as collateral', async ({ page }) => { -// const asset = 'DAI' - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.expectCollateralSwitch(asset, false) -// await myPortfolioPage.clickCollateralSwitchAction(asset) - -// const collateralDialog = new CollateralDialogPageObject(page) -// await collateralDialog.expectDialogHeader('Collateral') -// await collateralDialog.expectHealthFactorNotVisible() -// await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['zero-ltv-asset']) -// const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) -// await actionsContainer.expectDisabledActionAtIndex(0) - -// await myPortfolioPage.goToMyPortfolioAction() -// await myPortfolioPage.expectCollateralSwitch(asset, false) -// }) - -// test('cannot enable collateral for not deposited asset', async ({ page }) => { -// const asset = 'WBTC' - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.expectCollateralSwitch(asset, false) -// await myPortfolioPage.clickCollateralSwitchAction(asset) - -// const collateralDialog = new CollateralDialogPageObject(page) -// await collateralDialog.expectDialogHeader('Collateral') -// await collateralDialog.expectHealthFactorNotVisible() -// await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['zero-deposit-asset']) -// const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) -// await actionsContainer.expectDisabledActionAtIndex(0) - -// await myPortfolioPage.goToMyPortfolioAction() -// await myPortfolioPage.expectCollateralSwitch(asset, false) -// }) -// }) - -// test.describe('Single collateral, DAI borrow', () => { -// const initialDeposits = { -// wstETH: 1, -// } -// const daiToBorrow = 1000 - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ...initialBalances }, -// }, -// }) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) -// await borrowPage.viewInMyPortfolioAction() - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.goToMyPortfolioAction() - -// await myPortfolioPage.expectDepositTable({ -// wstETH: initialDeposits.wstETH, -// }) -// }) - -// test('cannot disable sole collateral', async ({ page }) => { -// const collateral = 'wstETH' - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.expectCollateralSwitch(collateral, true) -// await myPortfolioPage.clickCollateralSwitchAction(collateral) - -// const collateralDialog = new CollateralDialogPageObject(page) -// await collateralDialog.expectDialogHeader('Collateral') -// await collateralDialog.expectHealthFactorBefore('2.08') -// await collateralDialog.expectHealthFactorAfter('0') -// await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['exceeds-ltv']) -// const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) -// await actionsContainer.expectDisabledActionAtIndex(0) - -// await myPortfolioPage.goToMyPortfolioAction() -// await myPortfolioPage.expectCollateralSwitch(collateral, true) -// }) -// }) - -// test.describe('Multiple collaterals, DAI borrow', () => { -// const initialDeposits = { -// wstETH: 1, -// rETH: 0.01, -// } -// const daiToBorrow = 1000 - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ...initialBalances }, -// }, -// }) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) -// await borrowPage.viewInMyPortfolioAction() - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.goToMyPortfolioAction() - -// await myPortfolioPage.expectDepositTable({ -// wstETH: initialDeposits.wstETH, -// rETH: initialDeposits.rETH, -// }) -// }) - -// test('disables collateral', async ({ page }) => { -// const collateral = 'rETH' - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.expectCollateralSwitch(collateral, true) -// await myPortfolioPage.clickCollateralSwitchAction(collateral) - -// const collateralDialog = new CollateralDialogPageObject(page) -// await collateralDialog.expectDialogHeader('Collateral') -// await collateralDialog.expectHealthFactorBefore('2.1') -// await collateralDialog.expectHealthFactorAfter('2.08') -// const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(1) - -// await collateralDialog.expectSetUseAsCollateralSuccessPage(collateral, 'disabled') -// await myPortfolioPage.goToMyPortfolioAction() -// await myPortfolioPage.expectCollateralSwitch('rETH', false) -// }) - -// test('cannot disable collateral when second one would not cover loan', async ({ page }) => { -// const collateral = 'wstETH' - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.expectCollateralSwitch(collateral, true) -// await myPortfolioPage.clickCollateralSwitchAction(collateral) - -// const collateralDialog = new CollateralDialogPageObject(page) -// await collateralDialog.expectDialogHeader('Collateral') -// await collateralDialog.expectHealthFactorBefore('2.1') -// await collateralDialog.expectHealthFactorAfter('0.02') -// await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['exceeds-ltv']) -// const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) -// await actionsContainer.expectDisabledActionAtIndex(0) - -// await myPortfolioPage.goToMyPortfolioAction() -// await myPortfolioPage.expectCollateralSwitch(collateral, true) -// }) -// }) - -// test.describe('Isolation mode', () => { -// const fork = setupFork({ blockNumber: GNO_ACTIVE_BLOCK_NUMBER, chainId: mainnet.id }) -// const isolatedAsset = 'GNO' -// const regularAsset = 'rETH' -// const initialDeposits = { -// [regularAsset]: 1, -// } -// const myPortfolioDesposits = { -// [isolatedAsset]: 100, -// } - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ...initialBalances }, -// }, -// }) - -// // Depositing regular asset at borrow page to show myPortfolio positions -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositWithoutBorrowActions(initialDeposits) -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.goToMyPortfolioAction() - -// await myPortfolioPage.expectDepositTable({ -// [regularAsset]: initialDeposits[regularAsset], -// }) - -// // Depositing isolated asset at myPortfolio -// await myPortfolioPage.clickDepositButtonAction(isolatedAsset) -// const depositDialog = new DialogPageObject(page, /Deposit/) -// await depositDialog.fillAmountAction(myPortfolioDesposits[isolatedAsset]) -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) -// await depositDialog.viewInMyPortfolioAction() - -// const collateralDialog = new CollateralDialogPageObject(page) -// // Disabling regular asset as collateral -// await myPortfolioPage.clickCollateralSwitchAction(regularAsset) -// await collateralDialog.setUseAsCollateralAction(regularAsset, 'disabled') -// await myPortfolioPage.goToMyPortfolioAction() -// await myPortfolioPage.expectCollateralSwitch(isolatedAsset, false) - -// // Entering isolation mode -// await myPortfolioPage.clickCollateralSwitchAction(isolatedAsset) -// await collateralDialog.setUseAsCollateralAction(isolatedAsset, 'enabled') -// await myPortfolioPage.goToMyPortfolioAction() - -// await myPortfolioPage.expectCollateralSwitch(isolatedAsset, true) -// }) - -// test('cannot enable asset as collateral in isolation mode', async ({ page }) => { -// const collateral = 'rETH' - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.expectCollateralSwitch(collateral, false) -// await myPortfolioPage.clickCollateralSwitchAction(collateral) - -// const collateralDialog = new CollateralDialogPageObject(page) -// await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['isolation-mode-active']) -// const actionsContainer = new ActionsPageObject(collateralDialog.locatePanelByHeader('Actions')) -// await actionsContainer.expectDisabledActionAtIndex(0) - -// await myPortfolioPage.goToMyPortfolioAction() -// await myPortfolioPage.expectCollateralSwitch(collateral, false) -// }) -// }) - -// test.describe('Liquidation risk warning', () => { -// test.describe('In danger zone', () => { -// let collateralDialog: CollateralDialogPageObject -// let myPortfolioPage: MyPortfolioPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, -// }, -// }) - -// collateralDialog = new CollateralDialogPageObject(page) -// myPortfolioPage = new MyPortfolioPageObject(page) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositWithoutBorrowActions({ rETH: 2, wstETH: 10 }) -// await myPortfolioPage.goToMyPortfolioAction() - -// await myPortfolioPage.clickBorrowButtonAction('WETH') -// const borrowDialog = new DialogPageObject(page, /Borrow/) -// await borrowDialog.fillAmountAction(7) -// await borrowDialog.actionsContainer.acceptAllActionsAction(1) -// await borrowDialog.expectSuccessPage([{ asset: 'WETH', amount: 7 }], fork) -// await borrowDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectAssetToBeInBorrowTable('WETH') -// }) - -// test('shows risk warning', async () => { -// await myPortfolioPage.clickCollateralSwitchAction('rETH') -// await collateralDialog.expectLiquidationRiskWarning( -// 'Disabling this asset as collateral puts you at risk of quick liquidation. You may lose part of your remaining collateral.', -// ) -// }) - -// test('actions stay disabled until risk warning is acknowledged', async () => { -// await myPortfolioPage.clickCollateralSwitchAction('rETH') - -// await collateralDialog.actionsContainer.expectDisabledActionAtIndex(0) -// await collateralDialog.clickAcknowledgeRisk() -// await collateralDialog.actionsContainer.expectEnabledActionAtIndex(0) -// }) -// }) - -// test.describe('Not in danger zone', () => { -// let collateralDialog: CollateralDialogPageObject -// let myPortfolioPage: MyPortfolioPageObject - -// const rETHDeposit = { asset: 'rETH', amount: 1 } -// const wstETHDeposit = { asset: 'wstETH', amount: 1 } -// const daiBorrow = { asset: 'DAI', amount: 500 } - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, -// }, -// }) - -// collateralDialog = new CollateralDialogPageObject(page) -// myPortfolioPage = new MyPortfolioPageObject(page) -// }) - -// test('validation issue; risk warning is not shown', async ({ page }) => { -// // depositing single asset as collateral, so turing off will trigger validation -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositAssetsActions({ rETH: rETHDeposit.amount }, daiBorrow.amount) -// await borrowPage.expectSuccessPage([rETHDeposit], daiBorrow, fork) -// await myPortfolioPage.goToMyPortfolioAction() -// await myPortfolioPage.expectAssetToBeInBorrowTable('DAI') - -// await myPortfolioPage.clickCollateralSwitchAction('rETH') -// await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['exceeds-ltv']) -// await collateralDialog.expectLiquidationRiskWarningNotVisible() -// }) - -// test('no validation issue; risk warning is not shown', async ({ page }) => { -// // depositing multiple assets as collateral, so turning off single asset will not trigger validation -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositAssetsActions( -// { wstETH: wstETHDeposit.amount, rETH: rETHDeposit.amount }, -// daiBorrow.amount, -// ) -// await borrowPage.expectSuccessPage([wstETHDeposit, rETHDeposit], daiBorrow, fork) -// await myPortfolioPage.goToMyPortfolioAction() -// await myPortfolioPage.expectAssetToBeInBorrowTable('DAI') - -// await myPortfolioPage.clickCollateralSwitchAction('rETH') -// await collateralDialog.expectLiquidationRiskWarningNotVisible() -// }) -// }) -// }) -// }) +import { setUseAsCollateralValidationIssueToMessage } from '@/domain/market-validators/validateSetUseAsCollateral' +import { BorrowPageObject } from '@/pages/Borrow.PageObject' +import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { DialogPageObject } from '../common/Dialog.PageObject' +import { CollateralDialogPageObject } from './CollateralDialog.PageObject' + +test.describe('Collateral dialog', () => { + const initialBalances = { + wstETH: 100, + rETH: 100, + DAI: 10000, + weETH: 100, + } + + test.describe('Deposited multiple assets, no borrow', () => { + const initialDeposits = { + wstETH: 1, + } + const myPortfolioDesposits = { + DAI: 1000, // cannot be used as collateral + } + + let collateralDialog: CollateralDialogPageObject + let myPortfolioPage: MyPortfolioPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ...initialBalances }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + const depositDialog = new DialogPageObject({ testContext, header: /Deposit/ }) + myPortfolioPage = new MyPortfolioPageObject(testContext) + collateralDialog = new CollateralDialogPageObject(testContext) + + await borrowPage.depositWithoutBorrowActions({ assetsToDeposit: initialDeposits }) + await myPortfolioPage.goToMyPortfolioAction() + + // Depositing DAI in myPortfolio + await myPortfolioPage.clickDepositButtonAction('DAI') + await depositDialog.fillAmountAction(myPortfolioDesposits.DAI) + await depositDialog.actionsContainer.acceptAllActionsAction(2) + await depositDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectDepositTable({ + wstETH: initialDeposits.wstETH, + DAI: myPortfolioDesposits.DAI, + }) + }) + + test('disables collateral', async () => { + const collateral = 'wstETH' + + await myPortfolioPage.expectCollateralSwitch(collateral, true) + await myPortfolioPage.clickCollateralSwitchAction(collateral) + + await collateralDialog.expectDialogHeader('Collateral') + await collateralDialog.expectHealthFactorNotVisible() + await collateralDialog.actionsContainer.acceptAllActionsAction(1) + await collateralDialog.expectSetUseAsCollateralSuccessPage(collateral, 'disabled') + + await myPortfolioPage.goToMyPortfolioAction() + await myPortfolioPage.expectCollateralSwitch('wstETH', false) + }) + + test('enables collateral', async () => { + const collateral = 'wstETH' + + // disabling collateral + await myPortfolioPage.clickCollateralSwitchAction(collateral) + await collateralDialog.setUseAsCollateralAction({ assetName: collateral, setting: 'disabled' }) + await myPortfolioPage.goToMyPortfolioAction() + + // enabling collateral + await myPortfolioPage.expectCollateralSwitch(collateral, false) + await myPortfolioPage.clickCollateralSwitchAction(collateral) + await collateralDialog.expectDialogHeader('Collateral') + await collateralDialog.expectHealthFactorNotVisible() + await collateralDialog.actionsContainer.acceptAllActionsAction(1) + await collateralDialog.expectSetUseAsCollateralSuccessPage(collateral, 'enabled') + + await myPortfolioPage.goToMyPortfolioAction() + await myPortfolioPage.expectCollateralSwitch(collateral, true) + }) + + test('cannot enable collateral for asset that cannot be used as collateral', async () => { + const asset = 'DAI' + + await myPortfolioPage.expectCollateralSwitch(asset, false) + await myPortfolioPage.clickCollateralSwitchAction(asset) + + await collateralDialog.expectDialogHeader('Collateral') + await collateralDialog.expectHealthFactorNotVisible() + await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['zero-ltv-asset']) + await collateralDialog.actionsContainer.expectDisabledActionAtIndex(0) + + await myPortfolioPage.goToMyPortfolioAction() + await myPortfolioPage.expectCollateralSwitch(asset, false) + }) + + test('cannot enable collateral for not deposited asset', async () => { + const asset = 'WBTC' + + await myPortfolioPage.expectCollateralSwitch(asset, false) + await myPortfolioPage.clickCollateralSwitchAction(asset) + + await collateralDialog.expectDialogHeader('Collateral') + await collateralDialog.expectHealthFactorNotVisible() + await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['zero-deposit-asset']) + await collateralDialog.actionsContainer.expectDisabledActionAtIndex(0) + + await myPortfolioPage.goToMyPortfolioAction() + await myPortfolioPage.expectCollateralSwitch(asset, false) + }) + }) + + test.describe('Single collateral, DAI borrow', () => { + const initialDeposits = { + wstETH: 1, + } + const daiToBorrow = 1000 + let collateralDialog: CollateralDialogPageObject + let myPortfolioPage: MyPortfolioPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ...initialBalances }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + myPortfolioPage = new MyPortfolioPageObject(testContext) + collateralDialog = new CollateralDialogPageObject(testContext) + + await borrowPage.depositAssetsActions({ assetsToDeposit: initialDeposits, daiToBorrow }) + await borrowPage.viewInMyPortfolioAction() + + await myPortfolioPage.goToMyPortfolioAction() + await myPortfolioPage.expectDepositTable({ + wstETH: initialDeposits.wstETH, + }) + }) + + test('cannot disable sole collateral', async () => { + const collateral = 'wstETH' + + await myPortfolioPage.expectCollateralSwitch(collateral, true) + await myPortfolioPage.clickCollateralSwitchAction(collateral) + + await collateralDialog.expectDialogHeader('Collateral') + await collateralDialog.expectHealthFactorBefore('3.73') + await collateralDialog.expectHealthFactorAfter('0') + await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['exceeds-ltv']) + await collateralDialog.actionsContainer.expectDisabledActionAtIndex(0) + + await myPortfolioPage.goToMyPortfolioAction() + await myPortfolioPage.expectCollateralSwitch(collateral, true) + }) + }) + + test.describe('Multiple collaterals, DAI borrow', () => { + const initialDeposits = { + wstETH: 1, + rETH: 0.01, + } + const daiToBorrow = 1000 + let collateralDialog: CollateralDialogPageObject + let myPortfolioPage: MyPortfolioPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ...initialBalances }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + myPortfolioPage = new MyPortfolioPageObject(testContext) + collateralDialog = new CollateralDialogPageObject(testContext) + + await borrowPage.depositAssetsActions({ assetsToDeposit: initialDeposits, daiToBorrow }) + await borrowPage.viewInMyPortfolioAction() + + await myPortfolioPage.goToMyPortfolioAction() + await myPortfolioPage.expectDepositTable({ + wstETH: initialDeposits.wstETH, + rETH: initialDeposits.rETH, + }) + }) + + test('disables collateral', async () => { + const collateral = 'rETH' + + await myPortfolioPage.expectCollateralSwitch(collateral, true) + await myPortfolioPage.clickCollateralSwitchAction(collateral) + + await collateralDialog.expectDialogHeader('Collateral') + await collateralDialog.expectHealthFactorBefore('3.77') + await collateralDialog.expectHealthFactorAfter('3.73') + await collateralDialog.actionsContainer.acceptAllActionsAction(1) + await collateralDialog.expectSetUseAsCollateralSuccessPage(collateral, 'disabled') + + await myPortfolioPage.goToMyPortfolioAction() + await myPortfolioPage.expectCollateralSwitch('rETH', false) + }) + + test('cannot disable collateral when second one would not cover loan', async () => { + const collateral = 'wstETH' + + await myPortfolioPage.expectCollateralSwitch(collateral, true) + await myPortfolioPage.clickCollateralSwitchAction(collateral) + + await collateralDialog.expectDialogHeader('Collateral') + await collateralDialog.expectHealthFactorBefore('3.77') + await collateralDialog.expectHealthFactorAfter('0.04') + await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['exceeds-ltv']) + await collateralDialog.actionsContainer.expectDisabledActionAtIndex(0) + + await myPortfolioPage.goToMyPortfolioAction() + await myPortfolioPage.expectCollateralSwitch(collateral, true) + }) + }) + + test.describe('Isolation mode', () => { + const isolatedAsset = 'weETH' + const regularAsset = 'rETH' + const initialDeposits = { + [regularAsset]: 1, + } + const myPortfolioDesposits = { + [isolatedAsset]: 100, + } + + let collateralDialog: CollateralDialogPageObject + let myPortfolioPage: MyPortfolioPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ...initialBalances }, + }, + }) + + // Depositing regular asset at borrow page to show myPortfolio positions + const borrowPage = new BorrowPageObject(testContext) + myPortfolioPage = new MyPortfolioPageObject(testContext) + collateralDialog = new CollateralDialogPageObject(testContext) + + await borrowPage.depositWithoutBorrowActions({ assetsToDeposit: initialDeposits }) + + await myPortfolioPage.goToMyPortfolioAction() + await myPortfolioPage.expectDepositTable({ + [regularAsset]: initialDeposits[regularAsset], + }) + + // Depositing isolated asset at myPortfolio + await myPortfolioPage.clickDepositButtonAction(isolatedAsset) + const depositDialog = new DialogPageObject({ testContext, header: /Deposit/ }) + await depositDialog.fillAmountAction(myPortfolioDesposits[isolatedAsset]) + await depositDialog.actionsContainer.acceptAllActionsAction(2) + await depositDialog.viewInMyPortfolioAction() + + // Disabling regular asset as collateral + await myPortfolioPage.clickCollateralSwitchAction(regularAsset) + await collateralDialog.setUseAsCollateralAction({ assetName: regularAsset, setting: 'disabled' }) + await myPortfolioPage.goToMyPortfolioAction() + await myPortfolioPage.expectCollateralSwitch(isolatedAsset, false) + + // Entering isolation mode + await myPortfolioPage.clickCollateralSwitchAction(isolatedAsset) + await collateralDialog.setUseAsCollateralAction({ assetName: isolatedAsset, setting: 'enabled' }) + await myPortfolioPage.goToMyPortfolioAction() + + await myPortfolioPage.expectCollateralSwitch(isolatedAsset, true) + }) + + test('cannot enable asset as collateral in isolation mode', async () => { + const collateral = 'rETH' + + await myPortfolioPage.expectCollateralSwitch(collateral, false) + await myPortfolioPage.clickCollateralSwitchAction(collateral) + + await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['isolation-mode-active']) + await collateralDialog.actionsContainer.expectDisabledActionAtIndex(0) + + await myPortfolioPage.goToMyPortfolioAction() + await myPortfolioPage.expectCollateralSwitch(collateral, false) + }) + }) + + test.describe('Liquidation risk warning', () => { + test.describe('In danger zone', () => { + let collateralDialog: CollateralDialogPageObject + let myPortfolioPage: MyPortfolioPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + const borrowDialog = new DialogPageObject({ testContext, header: /Borrow/ }) + collateralDialog = new CollateralDialogPageObject(testContext) + myPortfolioPage = new MyPortfolioPageObject(testContext) + + await borrowPage.depositWithoutBorrowActions({ assetsToDeposit: { rETH: 2, wstETH: 10 } }) + + await myPortfolioPage.goToMyPortfolioAction() + await myPortfolioPage.clickBorrowButtonAction('WETH') + + await borrowDialog.fillAmountAction(7) + await borrowDialog.actionsContainer.acceptAllActionsAction(1) + await borrowDialog.expectSuccessPage({ + tokenWithValue: [{ asset: 'WETH', amount: '7.00', usdValue: '$27,498.19' }], + }) + await borrowDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectAssetToBeInBorrowTable('WETH') + }) + + test('shows risk warning', async () => { + await myPortfolioPage.clickCollateralSwitchAction('rETH') + await collateralDialog.expectLiquidationRiskWarning( + 'Disabling this asset as collateral puts you at risk of quick liquidation. You may lose part of your remaining collateral.', + ) + }) + + test('actions stay disabled until risk warning is acknowledged', async () => { + await myPortfolioPage.clickCollateralSwitchAction('rETH') + + await collateralDialog.actionsContainer.expectDisabledActionAtIndex(0) + await collateralDialog.clickAcknowledgeRisk() + await collateralDialog.actionsContainer.expectEnabledActionAtIndex(0) + }) + }) + + test.describe('Not in danger zone', () => { + let collateralDialog: CollateralDialogPageObject + let myPortfolioPage: MyPortfolioPageObject + let borrowPage: BorrowPageObject + + const rETHDeposit = { asset: 'rETH', amount: 1 } + const wstETHDeposit = { asset: 'wstETH', amount: 1 } + const daiBorrow = { asset: 'DAI', amount: 500 } + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, + }, + }) + + collateralDialog = new CollateralDialogPageObject(testContext) + myPortfolioPage = new MyPortfolioPageObject(testContext) + borrowPage = new BorrowPageObject(testContext) + }) + + test('validation issue; risk warning is not shown', async () => { + // depositing single asset as collateral, so turing off will trigger validation + await borrowPage.depositAssetsActions({ + assetsToDeposit: { rETH: rETHDeposit.amount }, + daiToBorrow: daiBorrow.amount, + }) + await borrowPage.expectSuccessPage({ + deposited: [{ asset: 'rETH', amount: '1.00', usdValue: '$4,413.26' }], + borrowed: { asset: 'DAI', amount: '500.00', usdValue: '$500.00' }, + }) + await myPortfolioPage.goToMyPortfolioAction() + await myPortfolioPage.expectAssetToBeInBorrowTable('DAI') + + await myPortfolioPage.clickCollateralSwitchAction('rETH') + await collateralDialog.expectAlertMessage(setUseAsCollateralValidationIssueToMessage['exceeds-ltv']) + await collateralDialog.expectLiquidationRiskWarningNotVisible() + }) + + test('no validation issue; risk warning is not shown', async () => { + // depositing multiple assets as collateral, so turning off single asset will not trigger validation + await borrowPage.depositAssetsActions({ + assetsToDeposit: { wstETH: wstETHDeposit.amount, rETH: rETHDeposit.amount }, + daiToBorrow: daiBorrow.amount, + }) + await borrowPage.expectSuccessPage({ + deposited: [ + { asset: 'wstETH', amount: '1.00', usdValue: '$4,665.46' }, + { asset: 'rETH', amount: '1.00', usdValue: '$4,413.26' }, + ], + borrowed: { asset: 'DAI', amount: '500.00', usdValue: '$500.00' }, + }) + + await myPortfolioPage.goToMyPortfolioAction() + await myPortfolioPage.expectAssetToBeInBorrowTable('DAI') + + await myPortfolioPage.clickCollateralSwitchAction('rETH') + await collateralDialog.expectLiquidationRiskWarningNotVisible() + }) + }) + }) +}) From 65dc12e44149b9b4447cf10c8f82a3ffca764c04 Mon Sep 17 00:00:00 2001 From: Oskar <43062492+oskarvu@users.noreply.github.com> Date: Sat, 21 Dec 2024 21:36:33 +0700 Subject: [PATCH 25/29] Rewrite withdraw dialog tests (#516) Co-authored-by: yivlad --- .../withdraw/WithdrawDialog.test-e2e.ts | 1255 ++++++++--------- 1 file changed, 611 insertions(+), 644 deletions(-) diff --git a/packages/app/src/features/dialogs/withdraw/WithdrawDialog.test-e2e.ts b/packages/app/src/features/dialogs/withdraw/WithdrawDialog.test-e2e.ts index f82c9914e..769290b01 100644 --- a/packages/app/src/features/dialogs/withdraw/WithdrawDialog.test-e2e.ts +++ b/packages/app/src/features/dialogs/withdraw/WithdrawDialog.test-e2e.ts @@ -1,644 +1,611 @@ -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' - -// import { withdrawalValidationIssueToMessage } from '@/domain/market-validators/validateWithdraw' -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { BorrowPageObject } from '@/pages/Borrow.PageObject' -// import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { screenshot } from '@/test/e2e/utils' - -// import { CollateralDialogPageObject } from '../collateral/CollateralDialog.PageObject' -// import { DialogPageObject } from '../common/Dialog.PageObject' -// import { EModeDialogPageObject } from '../e-mode/EModeDialog.PageObject' -// import { withdrawValidationIssueToMessage } from '../savings/withdraw/logic/validation' - -// const headerRegExp = /Withdr*/ - -// test.describe('Withdraw dialog', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) -// const initialBalances = { -// wstETH: 100, -// rETH: 100, -// ETH: 100, -// } - -// test.describe('Position with deposit and borrow', () => { -// const initialDeposits = { -// wstETH: 2, -// rETH: 2, -// } as const -// const daiToBorrow = 3500 - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ...initialBalances }, -// }, -// }) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) -// await borrowPage.viewInMyPortfolioAction() - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// // @todo This waits for the refetch of the data after successful borrow transaction to happen. -// // This is no ideal, probably we need to refactor expectDepositTable so it takes advantage from -// // playwright's timeouts instead of parsing it's current state. Then we would be able to -// // easily wait for the table to be updated. -// await myPortfolioPage.expectAssetToBeInDepositTable('DAI') -// }) - -// test('opens dialog with selected asset', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickWithdrawButtonAction('rETH') - -// const withdrawDialog = new DialogPageObject(page, headerRegExp) -// await withdrawDialog.expectSelectedAsset('rETH') -// await withdrawDialog.expectDialogHeader('Withdraw rETH') -// await withdrawDialog.expectHealthFactorBeforeVisible() - -// await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-default-view') -// }) - -// test('calculates health factor changes correctly', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickWithdrawButtonAction('rETH') - -// const withdrawDialog = new DialogPageObject(page, headerRegExp) -// await withdrawDialog.fillAmountAction(1) - -// await withdrawDialog.expectRiskLevelBefore('Moderate') -// await withdrawDialog.expectHealthFactorBefore('2.32') -// await withdrawDialog.expectRiskLevelAfter('Risky') -// await withdrawDialog.expectHealthFactorAfter('1.76') - -// // @note this is needed for deterministic screenshots -// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) -// await actionsContainer.expectEnabledActionAtIndex(0) - -// await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-health-factor') -// }) - -// test('has correct action plan for erc-20', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// await myPortfolioPage.clickWithdrawButtonAction('rETH') - -// const withdrawDialog = new DialogPageObject(page, headerRegExp) -// await withdrawDialog.fillAmountAction(1) -// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) -// await actionsContainer.expectActions([{ type: 'withdraw', asset: 'rETH' }]) -// }) - -// test('can withdraw erc-20', async ({ page }) => { -// const withdraw = { -// asset: 'rETH', -// amount: 1, -// } as const - -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// await myPortfolioPage.clickWithdrawButtonAction(withdraw.asset) - -// const withdrawDialog = new DialogPageObject(page, headerRegExp) -// await withdrawDialog.fillAmountAction(withdraw.amount) -// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(1) -// await withdrawDialog.expectSuccessPage([withdraw], fork) - -// await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-erc-20-success') - -// await withdrawDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.expectDepositTable({ -// ...initialDeposits, -// [withdraw.asset]: initialDeposits[withdraw.asset] - withdraw.amount, -// }) -// }) -// }) - -// test.describe('Form validation', () => { -// const initialDeposits = { -// wstETH: 5, -// rETH: 1, -// } as const -// const daiToBorrow = 4500 - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ...initialBalances }, -// }, -// }) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) -// await borrowPage.viewInMyPortfolioAction() - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// // @todo This waits for the refetch of the data after successful borrow transaction to happen. -// // This is no ideal, probably we need to refactor expectDepositTable so it takes advantage from -// // playwright's timeouts instead of parsing it's current state. Then we would be able to -// // easily wait for the table to be updated. -// await myPortfolioPage.expectAssetToBeInDepositTable('DAI') -// }) - -// test('cannot withdraw amount that will result in health factor under 1', async ({ page }) => { -// const withdrawAsset = 'wstETH' -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.expectDepositTable(initialDeposits) -// await myPortfolioPage.clickWithdrawButtonAction(withdrawAsset) - -// const withdrawDialog = new DialogPageObject(page, headerRegExp) -// await withdrawDialog.expectHealthFactorBefore('2.75') -// await withdrawDialog.fillAmountAction(initialDeposits[withdrawAsset] - 0.1) // we subtract small amount to ensure that we have enough balance in test, which may not be the case due to timestamp issues -// await withdrawDialog.expectAssetInputError('Remaining collateral cannot support the loan') - -// await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-cannot-support-loan') -// }) - -// test('cannot withdraw more than deposited', async ({ page }) => { -// const withdrawAsset = 'rETH' -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.expectDepositTable(initialDeposits) -// await myPortfolioPage.clickWithdrawButtonAction(withdrawAsset) - -// const withdrawDialog = new DialogPageObject(page, headerRegExp) -// await withdrawDialog.expectHealthFactorBefore('2.75') -// await withdrawDialog.fillAmountAction(initialDeposits[withdrawAsset] + 1) -// await withdrawDialog.expectAssetInputError(withdrawalValidationIssueToMessage['exceeds-balance']) - -// await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-more-than-deposited') -// }) -// }) - -// test.describe('Position with native deposit and borrow', () => { -// const ETHdeposit = { -// asset: 'ETH', -// amount: 10, -// } -// const borrow = { -// asset: 'DAI', -// amount: 1000, -// } - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ...initialBalances }, -// }, -// }) - -// const borrowPage = new BorrowPageObject(page) -// const actionsContainer = new ActionsPageObject(page) -// await borrowPage.fillDepositAssetAction(0, ETHdeposit.asset, ETHdeposit.amount) -// await borrowPage.fillBorrowAssetAction(borrow.amount) - -// await borrowPage.submitAction() - -// await actionsContainer.acceptAllActionsAction(2) - -// await borrowPage.expectSuccessPage([ETHdeposit], borrow, fork) - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.goToMyPortfolioAction() -// }) - -// // @note When ETH is deposited, deposit table shows WETH instead of ETH -// test('has correct action plan for native asset', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// await myPortfolioPage.clickWithdrawButtonAction('WETH') - -// const withdrawDialog = new DialogPageObject(page, headerRegExp) -// await withdrawDialog.selectAssetAction('ETH') -// await withdrawDialog.fillAmountAction(1) -// await withdrawDialog.expectHealthFactorVisible() -// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) -// await actionsContainer.expectActions([ -// { type: 'approve', asset: 'aWETH' }, -// { type: 'withdraw', asset: 'ETH' }, -// ]) - -// await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-eth-action-plan') -// }) - -// // @note When ETH is deposited, deposit table shows WETH instead of ETH -// test('can withdraw native asset', async ({ page }) => { -// const withdrawAmount = 1 - -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// await myPortfolioPage.clickWithdrawButtonAction('WETH') - -// const withdrawDialog = new DialogPageObject(page, headerRegExp) -// await withdrawDialog.selectAssetAction('ETH') -// await withdrawDialog.fillAmountAction(withdrawAmount) -// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) -// await withdrawDialog.expectSuccessPage( -// [ -// { -// asset: 'ETH', -// amount: withdrawAmount, -// }, -// ], -// fork, -// ) -// await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-eth-success') - -// await withdrawDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.expectDepositTable({ -// // @todo Figure out how WETH and ETH conversion should work -// WETH: ETHdeposit.amount - withdrawAmount, -// }) -// }) -// }) - -// test.describe('Position with only deposit', () => { -// const initialDeposits = { -// wstETH: 10, -// ETH: 2, -// } as const - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ...initialBalances }, -// }, -// }) - -// const borrowPage = new BorrowPageObject(page) -// // to simulate a position with only deposits, we go through the easy borrow flow -// // but interrupt it before the borrow action, going directly to the myPortfolio -// // this way we have deposit transactions executed, but no borrow transaction -// // resulting in a position with only deposits -// await borrowPage.fillDepositAssetAction(0, 'wstETH', initialDeposits.wstETH) -// await borrowPage.addNewDepositAssetAction() -// await borrowPage.fillBorrowAssetAction(1) // doesn't matter, we're not borrowing anything -// await borrowPage.fillDepositAssetAction(1, 'ETH', initialDeposits.ETH) -// await borrowPage.submitAction() - -// const actionsContainer = new ActionsPageObject(page) -// await actionsContainer.acceptAllActionsAction(3) -// await actionsContainer.expectEnabledActionAtIndex(3) - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.goToMyPortfolioAction() -// }) - -// test('can withdraw erc-20', async ({ page }) => { -// const withdraw = { -// asset: 'wstETH', -// amount: 1, -// } as const - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickWithdrawButtonAction(withdraw.asset) - -// const withdrawDialog = new DialogPageObject(page, headerRegExp) -// await withdrawDialog.fillAmountAction(withdraw.amount) -// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(1) -// await withdrawDialog.expectSuccessPage([withdraw], fork) - -// await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-only-deposit-erc-20-success') - -// await withdrawDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.expectDepositTable({ -// WETH: initialDeposits.ETH, -// [withdraw.asset]: initialDeposits[withdraw.asset] - withdraw.amount, -// }) -// }) - -// test('can fully withdraw erc-20', async ({ page }) => { -// const withdraw = { -// asset: 'wstETH', -// amount: 10, -// } as const - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickWithdrawButtonAction(withdraw.asset) - -// const withdrawDialog = new DialogPageObject(page, headerRegExp) -// await withdrawDialog.clickMaxAmountAction() -// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(1) -// await withdrawDialog.expectSuccessPage([withdraw], fork) - -// await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-only-deposit-erc-20-success') - -// await withdrawDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.expectDepositTable({ -// WETH: initialDeposits.ETH, -// [withdraw.asset]: 0, -// }) -// }) - -// test('does not display health factor', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickWithdrawButtonAction('wstETH') - -// const withdrawDialog = new DialogPageObject(page, headerRegExp) -// await withdrawDialog.fillAmountAction(1) - -// await withdrawDialog.expectHealthFactorNotVisible() - -// // @note this is needed for deterministic screenshots -// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) -// await actionsContainer.expectEnabledActionAtIndex(0) - -// await screenshot(withdrawDialog.getDialog(), 'withdraw-dialog-only-deposit-health-factor') -// }) - -// test('can fully withdraw native asset', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickWithdrawButtonAction('WETH') - -// const withdrawDialog = new DialogPageObject(page, headerRegExp) -// await withdrawDialog.selectAssetAction('ETH') -// await withdrawDialog.clickMaxAmountAction() -// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) -// await withdrawDialog.expectSuccessPage( -// [ -// { -// asset: 'ETH', -// amount: initialDeposits.ETH, -// }, -// ], -// fork, -// ) - -// await withdrawDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.expectDepositTable({ -// WETH: 0, -// wstETH: initialDeposits.wstETH, -// }) -// }) -// }) - -// test.describe('Liquidation risk warning', () => { -// let withdrawDialog: DialogPageObject -// let myPortfolioPage: MyPortfolioPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, -// }, -// }) - -// withdrawDialog = new DialogPageObject(page, headerRegExp) -// myPortfolioPage = new MyPortfolioPageObject(page) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositWithoutBorrowActions({ rETH: 2, wstETH: 10 }) -// await myPortfolioPage.goToMyPortfolioAction() - -// await myPortfolioPage.clickBorrowButtonAction('WETH') -// const borrowDialog = new DialogPageObject(page, /Borrow/) -// await borrowDialog.fillAmountAction(7) -// await borrowDialog.actionsContainer.acceptAllActionsAction(1) -// await borrowDialog.expectSuccessPage([{ asset: 'WETH', amount: 7 }], fork) -// await borrowDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectAssetToBeInBorrowTable('WETH') -// }) - -// test('shows risk warning', async () => { -// await myPortfolioPage.clickWithdrawButtonAction('rETH') - -// await withdrawDialog.clickMaxAmountAction() -// await withdrawDialog.expectLiquidationRiskWarning( -// 'Withdrawing this amount puts you at risk of quick liquidation. You may lose part of your collateral.', -// ) -// }) - -// test('actions stay disabled until risk warning is acknowledged', async () => { -// await myPortfolioPage.clickWithdrawButtonAction('rETH') - -// await withdrawDialog.clickMaxAmountAction() -// await withdrawDialog.actionsContainer.expectDisabledActionAtIndex(0) -// await withdrawDialog.clickAcknowledgeRisk() -// await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) -// }) - -// test('hf above danger zone threshold; risk warning is not shown', async () => { -// await myPortfolioPage.clickWithdrawButtonAction('rETH') - -// await withdrawDialog.fillAmountAction(0.1) -// await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) -// await withdrawDialog.expectLiquidationRiskWarningNotVisible() -// }) - -// test('input validation error; risk warning is not shown', async () => { -// await myPortfolioPage.clickWithdrawButtonAction('rETH') - -// await withdrawDialog.fillAmountAction(0) -// await withdrawDialog.expectAssetInputError(withdrawValidationIssueToMessage['value-not-positive']) -// await withdrawDialog.expectLiquidationRiskWarningNotVisible() -// }) - -// test('hf in danger zone; asset not collateral; risk warning is not shown', async ({ page }) => { -// // disabling collateral and entering danger zone -// await myPortfolioPage.clickCollateralSwitchAction('rETH') -// const collateralDialog = new CollateralDialogPageObject(page) -// await collateralDialog.clickAcknowledgeRisk() -// await collateralDialog.actionsContainer.acceptAllActionsAction(1) -// await collateralDialog.expectSetUseAsCollateralSuccessPage('rETH', 'disabled') -// await myPortfolioPage.goToMyPortfolioAction() -// await myPortfolioPage.expectCollateralSwitch('rETH', false) - -// await myPortfolioPage.clickWithdrawButtonAction('rETH') -// await withdrawDialog.clickMaxAmountAction() -// await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) -// await withdrawDialog.expectLiquidationRiskWarningNotVisible() -// }) -// }) - -// test.describe('MAX button', () => { -// let withdrawDialog: DialogPageObject -// let borrowDialog: DialogPageObject -// let depositDialog: DialogPageObject -// let myPortfolioPage: MyPortfolioPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'myPortfolio', -// account: { -// type: 'connected-random', -// assetBalances: { ETH: 10, wstETH: 5, rETH: 1, WBTC: 1 }, -// }, -// }) - -// withdrawDialog = new DialogPageObject(page, headerRegExp) -// myPortfolioPage = new MyPortfolioPageObject(page) -// borrowDialog = new DialogPageObject(page, /Borrow/) - -// await myPortfolioPage.clickDepositButtonAction('wstETH') -// depositDialog = new DialogPageObject(page, /Deposit/) -// await depositDialog.fillAmountAction(5) -// await depositDialog.actionsContainer.acceptAllActionsAction(2, fork) -// await depositDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectDepositedAssets(13_104.84) -// }) - -// test('withdraws amount up to HF 1.01', async () => { -// await myPortfolioPage.clickBorrowButtonAction('DAI') -// await borrowDialog.fillAmountAction(5000) -// await borrowDialog.actionsContainer.acceptAllActionsAction(1) -// await borrowDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectHealthFactor('2.08') - -// await myPortfolioPage.clickWithdrawButtonAction('wstETH') - -// await withdrawDialog.clickMaxAmountAction() -// await withdrawDialog.clickAcknowledgeRisk() - -// await withdrawDialog.expectInputValue('2.576392') -// await withdrawDialog.expectHealthFactorBefore('2.08') -// await withdrawDialog.expectHealthFactorAfter('1.01') -// await withdrawDialog.actionsContainer.expectActions([{ type: 'withdraw', asset: 'wstETH' }]) -// await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) -// }) - -// test('works for collaterals with different liquidation thresholds', async () => { -// await myPortfolioPage.clickDepositButtonAction('WBTC') -// await depositDialog.fillAmountAction(1) -// await depositDialog.actionsContainer.acceptAllActionsAction(2) -// await depositDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectDepositedAssets(54_910) - -// await myPortfolioPage.clickBorrowButtonAction('DAI') -// await borrowDialog.fillAmountAction(35000) -// await borrowDialog.clickAcknowledgeRisk() -// await borrowDialog.actionsContainer.acceptAllActionsAction(1) -// await borrowDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectHealthFactor('1.19') - -// await myPortfolioPage.clickWithdrawButtonAction('WBTC') - -// await withdrawDialog.clickMaxAmountAction() -// await withdrawDialog.clickAcknowledgeRisk() - -// await withdrawDialog.expectInputValue('0.204922') -// await withdrawDialog.expectHealthFactorBefore('1.19') -// await withdrawDialog.expectHealthFactorAfter('1.01') -// await withdrawDialog.actionsContainer.expectActions([{ type: 'withdraw', asset: 'WBTC' }]) -// await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) -// }) - -// test('works in e-mode', async ({ page }) => { -// await myPortfolioPage.clickBorrowButtonAction('WETH') -// await borrowDialog.fillAmountAction(2) -// await borrowDialog.actionsContainer.acceptAllActionsAction(1) -// await borrowDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectHealthFactor('2.3') -// await myPortfolioPage.clickEModeButtonAction() -// const eModeDialog = new EModeDialogPageObject(page) -// await eModeDialog.clickEModeCategoryTileAction('ETH Correlated') -// await eModeDialog.actionsContainer.acceptAllActionsAction(1) -// await eModeDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectHealthFactor('2.69') - -// await myPortfolioPage.clickWithdrawButtonAction('wstETH') -// await withdrawDialog.clickMaxAmountAction() -// await withdrawDialog.clickAcknowledgeRisk() - -// await withdrawDialog.expectInputValue('3.119467') -// await withdrawDialog.expectHealthFactorBefore('2.69') -// await withdrawDialog.expectHealthFactorAfter('1.01') -// await withdrawDialog.actionsContainer.expectActions([{ type: 'withdraw', asset: 'wstETH' }]) -// await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) -// }) - -// test('works for asset with usage as collateral disabled', async ({ page }) => { -// await myPortfolioPage.clickBorrowButtonAction('DAI') -// await borrowDialog.clickMaxAmountAction() -// await borrowDialog.clickAcknowledgeRisk() -// await borrowDialog.actionsContainer.acceptAllActionsAction(1) -// await borrowDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectHealthFactor('1.17') - -// await myPortfolioPage.clickDepositButtonAction('rETH') -// const depositDialog = new DialogPageObject(page, /Deposit/) -// await depositDialog.fillAmountAction(1) -// await depositDialog.actionsContainer.acceptAllActionsAction(2) -// await depositDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectHealthFactor('1.39') - -// await myPortfolioPage.clickCollateralSwitchAction('rETH') -// const collateralDialog = new CollateralDialogPageObject(page) -// await collateralDialog.clickAcknowledgeRisk() -// await collateralDialog.setUseAsCollateralAction('rETH', 'disabled') -// await myPortfolioPage.goToMyPortfolioAction() -// await myPortfolioPage.expectHealthFactor('1.17') - -// await myPortfolioPage.clickWithdrawButtonAction('rETH') -// await withdrawDialog.clickMaxAmountAction() - -// await withdrawDialog.expectInputValue('1') -// await withdrawDialog.expectMaxButtonDisabled() -// await withdrawDialog.expectHealthFactorBefore('1.17') -// await withdrawDialog.expectHealthFactorAfter('1.17') -// await withdrawDialog.actionsContainer.expectActions([{ type: 'withdraw', asset: 'rETH' }]) -// await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) -// }) - -// test('native asset withdrawal requires enough approval', async () => { -// await myPortfolioPage.clickDepositButtonAction('WETH') -// await depositDialog.selectAssetAction('ETH') -// await depositDialog.fillAmountAction(5) -// await depositDialog.actionsContainer.acceptAllActionsAction(1, fork) -// await depositDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectDepositedAssets(24_450) - -// await myPortfolioPage.clickWithdrawButtonAction('WETH') -// await withdrawDialog.selectAssetAction('ETH') -// await withdrawDialog.clickMaxAmountAction() - -// await withdrawDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'aWETH' }, -// { type: 'withdraw', asset: 'ETH' }, -// ]) - -// await withdrawDialog.actionsContainer.acceptActionAtIndex(0, fork) -// await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(1) -// await withdrawDialog.closeDialog() - -// await myPortfolioPage.clickDepositButtonAction('WETH') -// await depositDialog.selectAssetAction('ETH') -// await depositDialog.fillAmountAction(4) -// await depositDialog.actionsContainer.acceptAllActionsAction(1) -// await depositDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectDepositedAssets(33_530) - -// // following checks leverage the fact that approval is cached, therefore we input different values to estimate the approval value -// await myPortfolioPage.clickWithdrawButtonAction('WETH') -// await withdrawDialog.selectAssetAction('ETH') -// await withdrawDialog.fillAmountAction(5.000001) -// await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(1) -// await withdrawDialog.fillAmountAction(5.000003) -// await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(1) -// await withdrawDialog.fillAmountAction(5.000004) -// await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) -// }) -// }) -// }) +import { withdrawalValidationIssueToMessage } from '@/domain/market-validators/validateWithdraw' +import { BorrowPageObject } from '@/pages/Borrow.PageObject' +import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { TestContext, setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { CollateralDialogPageObject } from '../collateral/CollateralDialog.PageObject' +import { DialogPageObject } from '../common/Dialog.PageObject' +import { EModeDialogPageObject } from '../e-mode/EModeDialog.PageObject' +import { withdrawValidationIssueToMessage } from '../savings/withdraw/logic/validation' + +test.describe('Withdraw dialog', () => { + const initialBalances = { + wstETH: 100, + rETH: 100, + ETH: 100, + } + + const header = /Withdr*/ + + test.describe('Position with deposit and borrow', () => { + const initialDeposits = { + wstETH: 2, + rETH: 2, + } as const + const daiToBorrow = 3500 + + let withdrawDialog: DialogPageObject + let myPortfolioPage: MyPortfolioPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ...initialBalances }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + myPortfolioPage = new MyPortfolioPageObject(testContext) + withdrawDialog = new DialogPageObject({ testContext, header }) + + await borrowPage.depositAssetsActions({ assetsToDeposit: initialDeposits, daiToBorrow }) + await borrowPage.viewInMyPortfolioAction() + + // @todo This waits for the refetch of the data after successful borrow transaction to happen. + // This is no ideal, probably we need to refactor expectDepositTable so it takes advantage from + // playwright's timeouts instead of parsing it's current state. Then we would be able to + // easily wait for the table to be updated. + await myPortfolioPage.expectAssetToBeInDepositTable('DAI') + }) + + test('opens dialog with selected asset', async () => { + await myPortfolioPage.clickWithdrawButtonAction('rETH') + + await withdrawDialog.expectSelectedAsset('rETH') + await withdrawDialog.expectDialogHeader('Withdraw rETH') + await withdrawDialog.expectHealthFactorBeforeVisible() + }) + + test('calculates health factor changes correctly', async () => { + await myPortfolioPage.clickWithdrawButtonAction('rETH') + + await withdrawDialog.fillAmountAction(1) + await withdrawDialog.expectRiskLevelBefore('Healthy') + await withdrawDialog.expectHealthFactorBefore('4.15') + await withdrawDialog.expectRiskLevelAfter('Healthy') + await withdrawDialog.expectHealthFactorAfter('3.14') + }) + + test('has correct action plan for erc-20', async () => { + await myPortfolioPage.clickWithdrawButtonAction('rETH') + + await withdrawDialog.fillAmountAction(1) + await withdrawDialog.actionsContainer.expectActions([{ type: 'withdraw', asset: 'rETH' }]) + }) + + test('can withdraw erc-20', async () => { + const withdraw = { + asset: 'rETH', + amount: 1, + } as const + + await myPortfolioPage.clickWithdrawButtonAction(withdraw.asset) + + await withdrawDialog.fillAmountAction(withdraw.amount) + await withdrawDialog.actionsContainer.acceptAllActionsAction(1) + await withdrawDialog.expectSuccessPage({ + tokenWithValue: [{ asset: 'rETH', amount: '1.00', usdValue: '$4,413.26' }], + }) + await withdrawDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectDepositTable({ + ...initialDeposits, + [withdraw.asset]: initialDeposits[withdraw.asset] - withdraw.amount, + }) + }) + }) + + test.describe('Form validation', () => { + const initialDeposits = { + wstETH: 5, + rETH: 1, + } as const + const daiToBorrow = 4500 + + let withdrawDialog: DialogPageObject + let myPortfolioPage: MyPortfolioPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ...initialBalances }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + myPortfolioPage = new MyPortfolioPageObject(testContext) + withdrawDialog = new DialogPageObject({ testContext, header }) + + await borrowPage.depositAssetsActions({ assetsToDeposit: initialDeposits, daiToBorrow }) + await borrowPage.viewInMyPortfolioAction() + + await myPortfolioPage.expectAssetToBeInDepositTable('DAI') + }) + + test('cannot withdraw amount that will result in health factor under 1', async () => { + const withdrawAsset = 'wstETH' + await myPortfolioPage.expectDepositTable(initialDeposits) + await myPortfolioPage.clickWithdrawButtonAction(withdrawAsset) + + await withdrawDialog.expectHealthFactorBefore('4.93') + await withdrawDialog.fillAmountAction(initialDeposits[withdrawAsset] - 0.1) // we subtract small amount to ensure that we have enough balance in test, which may not be the case due to timestamp issues + await withdrawDialog.expectAssetInputError('Remaining collateral cannot support the loan') + }) + + test('cannot withdraw more than deposited', async () => { + const withdrawAsset = 'rETH' + await myPortfolioPage.expectDepositTable(initialDeposits) + await myPortfolioPage.clickWithdrawButtonAction(withdrawAsset) + + await withdrawDialog.expectHealthFactorBefore('4.93') + await withdrawDialog.fillAmountAction(initialDeposits[withdrawAsset] + 1) + await withdrawDialog.expectAssetInputError(withdrawalValidationIssueToMessage['exceeds-balance']) + }) + }) + + test.describe('Position with native deposit and borrow', () => { + const ETHdeposit = { + asset: 'ETH', + amount: 10, + } + const borrow = { + asset: 'DAI', + amount: 1000, + } + + let withdrawDialog: DialogPageObject + let myPortfolioPage: MyPortfolioPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ...initialBalances }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + myPortfolioPage = new MyPortfolioPageObject(testContext) + withdrawDialog = new DialogPageObject({ testContext, header }) + + await borrowPage.fillDepositAssetAction(0, ETHdeposit.asset, ETHdeposit.amount) + await borrowPage.fillBorrowAssetAction(borrow.amount) + await borrowPage.submitAction() + await borrowPage.actionsContainer.acceptAllActionsAction(2) + await borrowPage.expectSuccessPage({ + deposited: [{ asset: 'ETH', amount: '10.00', usdValue: '$39,283.13' }], + borrowed: { asset: 'DAI', amount: '1,000.00', usdValue: '$1,000.00' }, + }) + + await myPortfolioPage.goToMyPortfolioAction() + }) + + // @note When ETH is deposited, deposit table shows WETH instead of ETH + test('has correct action plan for native asset', async () => { + await myPortfolioPage.clickWithdrawButtonAction('WETH') + + await withdrawDialog.selectAssetAction('ETH') + await withdrawDialog.fillAmountAction(1) + await withdrawDialog.expectHealthFactorVisible() + await withdrawDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'aWETH' }, + { type: 'withdraw', asset: 'ETH' }, + ]) + }) + + // @note When ETH is deposited, deposit table shows WETH instead of ETH + test('can withdraw native asset', async () => { + const withdrawAmount = 1 + + await myPortfolioPage.clickWithdrawButtonAction('WETH') + + await withdrawDialog.selectAssetAction('ETH') + await withdrawDialog.fillAmountAction(withdrawAmount) + await withdrawDialog.actionsContainer.acceptAllActionsAction(2) + await withdrawDialog.expectSuccessPage({ + tokenWithValue: [ + { + asset: 'ETH', + amount: '1.00', + usdValue: '$3,928.31', + }, + ], + }) + await withdrawDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectDepositTable({ + WETH: ETHdeposit.amount - withdrawAmount, + }) + }) + }) + + test.describe('Position with only deposit', () => { + const initialDeposits = { + wstETH: 10, + ETH: 2, + } as const + + let withdrawDialog: DialogPageObject + let myPortfolioPage: MyPortfolioPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ...initialBalances }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + myPortfolioPage = new MyPortfolioPageObject(testContext) + withdrawDialog = new DialogPageObject({ testContext, header }) + // to simulate a position with only deposits, we go through the easy borrow flow + // but interrupt it before the borrow action, going directly to the myPortfolio + // this way we have deposit transactions executed, but no borrow transaction + // resulting in a position with only deposits + await borrowPage.fillDepositAssetAction(0, 'wstETH', initialDeposits.wstETH) + await borrowPage.addNewDepositAssetAction() + await borrowPage.fillBorrowAssetAction(1) // doesn't matter, we're not borrowing anything + await borrowPage.fillDepositAssetAction(1, 'ETH', initialDeposits.ETH) + await borrowPage.submitAction() + + await borrowPage.actionsContainer.acceptAllActionsAction(3) + await borrowPage.actionsContainer.expectEnabledActionAtIndex(3) + + await myPortfolioPage.goToMyPortfolioAction() + }) + + test('can withdraw erc-20', async () => { + const withdraw = { + asset: 'wstETH', + amount: 1, + } as const + + await myPortfolioPage.clickWithdrawButtonAction(withdraw.asset) + + await withdrawDialog.fillAmountAction(withdraw.amount) + await withdrawDialog.actionsContainer.acceptAllActionsAction(1) + await withdrawDialog.expectSuccessPage({ + tokenWithValue: [{ asset: 'wstETH', amount: '1.00', usdValue: '$4,665.46' }], + }) + await withdrawDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectDepositTable({ + WETH: initialDeposits.ETH, + [withdraw.asset]: initialDeposits[withdraw.asset] - withdraw.amount, + }) + }) + + test('can fully withdraw erc-20', async () => { + const withdraw = { + asset: 'wstETH', + amount: 10, + } as const + + await myPortfolioPage.clickWithdrawButtonAction(withdraw.asset) + + await withdrawDialog.clickMaxAmountAction() + await withdrawDialog.actionsContainer.acceptAllActionsAction(1) + await withdrawDialog.expectSuccessPage({ + tokenWithValue: [{ asset: 'wstETH', amount: '10.00', usdValue: '$46,654.64' }], + }) + await withdrawDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectDepositTable({ + WETH: initialDeposits.ETH, + [withdraw.asset]: 0, + }) + }) + + test('does not display health factor', async () => { + await myPortfolioPage.clickWithdrawButtonAction('wstETH') + + await withdrawDialog.fillAmountAction(1) + await withdrawDialog.expectHealthFactorNotVisible() + }) + + test('can fully withdraw native asset', async () => { + await myPortfolioPage.clickWithdrawButtonAction('WETH') + + await withdrawDialog.selectAssetAction('ETH') + await withdrawDialog.clickMaxAmountAction() + await withdrawDialog.actionsContainer.acceptAllActionsAction(2) + await withdrawDialog.expectSuccessPage({ + tokenWithValue: [{ asset: 'ETH', amount: '2.00', usdValue: '$7,856.63' }], + }) + + await withdrawDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectDepositTable({ + WETH: 0, + wstETH: initialDeposits.wstETH, + }) + }) + }) + + test.describe('Liquidation risk warning', () => { + let testContext: TestContext<'connected-random'> + let withdrawDialog: DialogPageObject + let myPortfolioPage: MyPortfolioPageObject + + test.beforeEach(async ({ page }) => { + testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, + }, + }) + + withdrawDialog = new DialogPageObject({ testContext, header }) + myPortfolioPage = new MyPortfolioPageObject(testContext) + + const borrowPage = new BorrowPageObject(testContext) + await borrowPage.depositWithoutBorrowActions({ assetsToDeposit: { rETH: 2, wstETH: 10 } }) + await myPortfolioPage.goToMyPortfolioAction() + + await myPortfolioPage.clickBorrowButtonAction('WETH') + const borrowDialog = new DialogPageObject({ testContext, header: /Borrow/ }) + await borrowDialog.fillAmountAction(7) + await borrowDialog.actionsContainer.acceptAllActionsAction(1) + await borrowDialog.expectSuccessPage({ + tokenWithValue: [{ asset: 'WETH', amount: '7.00', usdValue: '$27,498.19' }], + }) + await borrowDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectAssetToBeInBorrowTable('WETH') + }) + + test('shows risk warning', async () => { + await myPortfolioPage.clickWithdrawButtonAction('rETH') + + await withdrawDialog.clickMaxAmountAction() + await withdrawDialog.expectLiquidationRiskWarning( + 'Withdrawing this amount puts you at risk of quick liquidation. You may lose part of your collateral.', + ) + }) + + test('actions stay disabled until risk warning is acknowledged', async () => { + await myPortfolioPage.clickWithdrawButtonAction('rETH') + + await withdrawDialog.clickMaxAmountAction() + await withdrawDialog.actionsContainer.expectDisabledActionAtIndex(0) + await withdrawDialog.clickAcknowledgeRisk() + await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) + }) + + test('hf above danger zone threshold; risk warning is not shown', async () => { + await myPortfolioPage.clickWithdrawButtonAction('rETH') + + await withdrawDialog.fillAmountAction(0.1) + await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) + await withdrawDialog.expectLiquidationRiskWarningNotVisible() + }) + + test('input validation error; risk warning is not shown', async () => { + await myPortfolioPage.clickWithdrawButtonAction('rETH') + + await withdrawDialog.fillAmountAction(0) + await withdrawDialog.expectAssetInputError(withdrawValidationIssueToMessage['value-not-positive']) + await withdrawDialog.expectLiquidationRiskWarningNotVisible() + }) + + test('hf in danger zone; asset not collateral; risk warning is not shown', async () => { + // disabling collateral and entering danger zone + await myPortfolioPage.clickCollateralSwitchAction('rETH') + + const collateralDialog = new CollateralDialogPageObject(testContext) + await collateralDialog.clickAcknowledgeRisk() + await collateralDialog.actionsContainer.acceptAllActionsAction(1) + await collateralDialog.expectSetUseAsCollateralSuccessPage('rETH', 'disabled') + + await myPortfolioPage.goToMyPortfolioAction() + await myPortfolioPage.expectCollateralSwitch('rETH', false) + await myPortfolioPage.clickWithdrawButtonAction('rETH') + + await withdrawDialog.clickMaxAmountAction() + await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) + await withdrawDialog.expectLiquidationRiskWarningNotVisible() + }) + }) + + test.describe('MAX button', () => { + let withdrawDialog: DialogPageObject + let borrowDialog: DialogPageObject + let depositDialog: DialogPageObject + let myPortfolioPage: MyPortfolioPageObject + let collateralDialog: CollateralDialogPageObject + let testContext: TestContext<'connected-random'> + + test.beforeEach(async ({ page }) => { + testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'myPortfolio', + account: { + type: 'connected-random', + assetBalances: { ETH: 10, wstETH: 5, rETH: 1, cbBTC: 1 }, + }, + }) + + withdrawDialog = new DialogPageObject({ testContext, header }) + myPortfolioPage = new MyPortfolioPageObject(testContext) + borrowDialog = new DialogPageObject({ testContext, header: /Borrow/ }) + depositDialog = new DialogPageObject({ testContext, header: /Deposit/ }) + collateralDialog = new CollateralDialogPageObject(testContext) + + await myPortfolioPage.clickDepositButtonAction('wstETH') + await depositDialog.fillAmountAction(5) + await depositDialog.actionsContainer.acceptAllActionsAction(2) + await depositDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectDepositedAssets('$23.33K') + }) + + test('withdraws amount up to HF 1.01', async () => { + await myPortfolioPage.clickBorrowButtonAction('DAI') + await borrowDialog.fillAmountAction(5000) + await borrowDialog.actionsContainer.acceptAllActionsAction(1) + await borrowDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectHealthFactor('3.73') + + await myPortfolioPage.clickWithdrawButtonAction('wstETH') + + await withdrawDialog.clickMaxAmountAction() + await withdrawDialog.clickAcknowledgeRisk() + + await withdrawDialog.expectInputValue('3.646973') + await withdrawDialog.expectHealthFactorBefore('3.73') + await withdrawDialog.expectHealthFactorAfter('1.01') + await withdrawDialog.actionsContainer.expectActions([{ type: 'withdraw', asset: 'wstETH' }]) + await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) + }) + + test('works for collaterals with different liquidation thresholds', async () => { + await myPortfolioPage.clickDepositButtonAction('cbBTC') + await depositDialog.fillAmountAction(1) + await depositDialog.actionsContainer.acceptAllActionsAction(2) + await depositDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectDepositedAssets('$125K') + + await myPortfolioPage.clickBorrowButtonAction('DAI') + await borrowDialog.fillAmountAction(35000) + await borrowDialog.actionsContainer.acceptAllActionsAction(1) + await borrowDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectHealthFactor('2.71') + + await myPortfolioPage.clickWithdrawButtonAction('cbBTC') + + await withdrawDialog.clickMaxAmountAction() + await withdrawDialog.clickAcknowledgeRisk() + + await withdrawDialog.expectInputValue('0.781174') + await withdrawDialog.expectHealthFactorBefore('2.71') + await withdrawDialog.expectHealthFactorAfter('1.01') + await withdrawDialog.actionsContainer.expectActions([{ type: 'withdraw', asset: 'cbBTC' }]) + await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) + }) + + test('works in e-mode', async () => { + await myPortfolioPage.clickBorrowButtonAction('WETH') + await borrowDialog.fillAmountAction(2) + await borrowDialog.actionsContainer.acceptAllActionsAction(1) + await borrowDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectHealthFactor('2.38') + await myPortfolioPage.clickEModeButtonAction() + const eModeDialog = new EModeDialogPageObject(testContext) + await eModeDialog.clickEModeCategoryTileAction('ETH Correlated') + await eModeDialog.actionsContainer.acceptAllActionsAction(1) + await eModeDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectHealthFactor('2.76') + + await myPortfolioPage.clickWithdrawButtonAction('wstETH') + await withdrawDialog.clickMaxAmountAction() + await withdrawDialog.clickAcknowledgeRisk() + + await withdrawDialog.expectInputValue('3.171143') + await withdrawDialog.expectHealthFactorBefore('2.76') + await withdrawDialog.expectHealthFactorAfter('1.01') + await withdrawDialog.actionsContainer.expectActions([{ type: 'withdraw', asset: 'wstETH' }]) + await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) + }) + + test('works for asset with usage as collateral disabled', async () => { + await myPortfolioPage.clickBorrowButtonAction('DAI') + await borrowDialog.clickMaxAmountAction() + await borrowDialog.clickAcknowledgeRisk() + await borrowDialog.actionsContainer.acceptAllActionsAction(1) + await borrowDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectHealthFactor('1.02') + + await myPortfolioPage.clickDepositButtonAction('rETH') + await depositDialog.fillAmountAction(1) + await depositDialog.actionsContainer.acceptAllActionsAction(2) + await depositDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectHealthFactor('1.22') + + await myPortfolioPage.clickCollateralSwitchAction('rETH') + await collateralDialog.clickAcknowledgeRisk() + await collateralDialog.setUseAsCollateralAction({ assetName: 'rETH', setting: 'disabled' }) + await myPortfolioPage.goToMyPortfolioAction() + await myPortfolioPage.expectHealthFactor('1.02') + + await myPortfolioPage.clickWithdrawButtonAction('rETH') + await withdrawDialog.clickMaxAmountAction() + + await withdrawDialog.expectInputValue('1') + await withdrawDialog.expectMaxButtonDisabled() + await withdrawDialog.expectHealthFactorBefore('1.02') + await withdrawDialog.expectHealthFactorAfter('1.02') + await withdrawDialog.actionsContainer.expectActions([{ type: 'withdraw', asset: 'rETH' }]) + await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) + }) + + test('native asset withdrawal requires enough approval', async () => { + await myPortfolioPage.clickDepositButtonAction('WETH') + await depositDialog.selectAssetAction('ETH') + await depositDialog.fillAmountAction(5) + await depositDialog.actionsContainer.acceptAllActionsAction(1) + await depositDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectDepositedAssets('$42.97K') + + await myPortfolioPage.clickWithdrawButtonAction('WETH') + await withdrawDialog.selectAssetAction('ETH') + await withdrawDialog.clickMaxAmountAction() + + await withdrawDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'aWETH' }, + { type: 'withdraw', asset: 'ETH' }, + ]) + + await withdrawDialog.actionsContainer.acceptActionAtIndex(0) + await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(1) + await withdrawDialog.closeDialog() + + await myPortfolioPage.clickDepositButtonAction('WETH') + await depositDialog.selectAssetAction('ETH') + await depositDialog.fillAmountAction(4) + await depositDialog.actionsContainer.acceptAllActionsAction(1) + await depositDialog.viewInMyPortfolioAction() + await myPortfolioPage.expectDepositedAssets('$58.68K') + + // following checks leverage the fact that approval is cached, therefore we input different values to estimate the approval value + await myPortfolioPage.clickWithdrawButtonAction('WETH') + await withdrawDialog.selectAssetAction('ETH') + await withdrawDialog.fillAmountAction(5.000004) + await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(1) + await withdrawDialog.fillAmountAction(5.000005) + await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(1) + await withdrawDialog.fillAmountAction(5.00006) + await withdrawDialog.actionsContainer.expectEnabledActionAtIndex(0) + }) + }) +}) From 440a6a7acf5a5c6ff684f422b32762363da6618c Mon Sep 17 00:00:00 2001 From: Oskar <43062492+oskarvu@users.noreply.github.com> Date: Sat, 21 Dec 2024 21:57:57 +0700 Subject: [PATCH 26/29] Rewrite borrow dialog tests (#519) Co-authored-by: yivlad --- .../dialogs/borrow/BorrowDialog.test-e2e.ts | 932 ++++++++---------- 1 file changed, 432 insertions(+), 500 deletions(-) diff --git a/packages/app/src/features/dialogs/borrow/BorrowDialog.test-e2e.ts b/packages/app/src/features/dialogs/borrow/BorrowDialog.test-e2e.ts index cee34ce0d..87098e233 100644 --- a/packages/app/src/features/dialogs/borrow/BorrowDialog.test-e2e.ts +++ b/packages/app/src/features/dialogs/borrow/BorrowDialog.test-e2e.ts @@ -1,500 +1,432 @@ -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' - -// import { borrowValidationIssueToMessage } from '@/domain/market-validators/validateBorrow' -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { BorrowPageObject } from '@/pages/Borrow.PageObject' -// import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { screenshot } from '@/test/e2e/utils' - -// import { CollateralDialogPageObject } from '../collateral/CollateralDialog.PageObject' -// import { DialogPageObject } from '../common/Dialog.PageObject' - -// const headerRegExp = /Borrow */ - -// test.describe('Borrow dialog', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) -// const initialBalances = { -// rETH: 100, -// wstETH: 100, -// } - -// test.describe('Position with deposit and borrow', () => { -// const initialDeposits = { -// rETH: 2, -// wstETH: 2, -// } -// const daiToBorrow = 1500 -// const expectedInitialHealthFactor = '5.42' -// const expectedHealthFactor = '2.04' - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ...initialBalances }, -// }, -// }) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositAssetsActions(initialDeposits, daiToBorrow) -// await borrowPage.viewInMyPortfolioAction() - -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// // wait for all transactions to be executed -// await myPortfolioPage.expectHealthFactor(expectedInitialHealthFactor) -// }) - -// test('opens dialog with selected asset', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickBorrowButtonAction('rETH') - -// const borrowDialog = new DialogPageObject(page, headerRegExp) -// await borrowDialog.expectSelectedAsset('rETH') -// await borrowDialog.expectDialogHeader('Borrow rETH') -// await borrowDialog.expectHealthFactorBeforeVisible() - -// await screenshot(borrowDialog.getDialog(), 'borrow-dialog-default-view') -// }) - -// test('calculates health factor changes correctly', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickBorrowButtonAction('rETH') - -// const borrowDialog = new DialogPageObject(page, headerRegExp) -// await borrowDialog.fillAmountAction(1) - -// await borrowDialog.expectRiskLevelBefore('Healthy') -// await borrowDialog.expectHealthFactorBefore(expectedInitialHealthFactor) -// await borrowDialog.expectRiskLevelAfter('Moderate') -// await borrowDialog.expectHealthFactorAfter(expectedHealthFactor) - -// // @note this is needed for deterministic screenshots -// const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) -// await actionsContainer.expectEnabledActionAtIndex(0) - -// await screenshot(borrowDialog.getDialog(), 'borrow-dialog-health-factor') -// }) - -// test('after borrow, health factor matches myPortfolio', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickBorrowButtonAction('rETH') - -// const borrowDialog = new DialogPageObject(page, headerRegExp) -// await borrowDialog.fillAmountAction(1) -// const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(1) - -// await borrowDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectHealthFactor(expectedHealthFactor) -// }) - -// test('has correct action plan for erc-20', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// await myPortfolioPage.clickBorrowButtonAction('rETH') - -// const borrowDialog = new DialogPageObject(page, headerRegExp) -// await borrowDialog.fillAmountAction(1) -// const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) -// await actionsContainer.expectActions([{ type: 'borrow', asset: 'rETH' }]) -// }) - -// test('can borrow erc-20', async ({ page }) => { -// const borrow = { -// asset: 'rETH', -// amount: 1, -// } - -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// await myPortfolioPage.clickBorrowButtonAction(borrow.asset) - -// const borrowDialog = new DialogPageObject(page, headerRegExp) -// await borrowDialog.fillAmountAction(borrow.amount) -// const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(1) -// await borrowDialog.expectSuccessPage([borrow], fork) - -// await screenshot(borrowDialog.getDialog(), 'borrow-dialog-erc-20-success') - -// await borrowDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.expectBorrowTable({ -// [borrow.asset]: borrow.amount, -// }) -// }) - -// test('has correct action plan for native asset', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// await myPortfolioPage.clickBorrowButtonAction('WETH') - -// const borrowDialog = new DialogPageObject(page, headerRegExp) -// await borrowDialog.selectAssetAction('ETH') -// await borrowDialog.fillAmountAction(1) - -// await borrowDialog.expectHealthFactorVisible() - -// const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) -// await actionsContainer.expectActions([ -// { type: 'approveDelegation', asset: 'ETH' }, -// { type: 'borrow', asset: 'ETH' }, -// ]) - -// await screenshot(borrowDialog.getDialog(), 'borrow-dialog-eth-action-plan') -// }) - -// test('can borrow native asset', async ({ page }) => { -// const borrow = { -// asset: 'ETH', -// amount: 1, -// } - -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// await myPortfolioPage.clickBorrowButtonAction('WETH') - -// const borrowDialog = new DialogPageObject(page, headerRegExp) -// await borrowDialog.selectAssetAction(borrow.asset) -// await borrowDialog.fillAmountAction(1) -// const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) -// await borrowDialog.expectSuccessPage([borrow], fork) -// await screenshot(borrowDialog.getDialog(), 'borrow-dialog-eth-success') - -// await borrowDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.expectBorrowTable({ -// WETH: borrow.amount, -// }) -// }) - -// test('can borrow same asset again', async ({ page }) => { -// const borrow = { -// asset: 'DAI', -// amount: 1500, -// } - -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// await myPortfolioPage.clickBorrowButtonAction(borrow.asset) - -// const borrowDialog = new DialogPageObject(page, headerRegExp) -// await borrowDialog.fillAmountAction(borrow.amount) -// const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(1) -// await borrowDialog.expectSuccessPage([borrow], fork) - -// await screenshot(borrowDialog.getDialog(), 'borrow-dialog-borrow-twice-success') - -// await borrowDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.expectBorrowTable({ -// [borrow.asset]: borrow.amount + daiToBorrow, -// }) -// }) - -// test("can't borrow more than allowed", async ({ page }) => { -// const borrowAsset = 'wstETH' -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickBorrowButtonAction(borrowAsset) - -// const borrowDialog = new DialogPageObject(page, headerRegExp) -// await borrowDialog.fillAmountAction(initialDeposits[borrowAsset] * 10) - -// await borrowDialog.expectAssetInputError(borrowValidationIssueToMessage['insufficient-collateral']) -// await borrowDialog.expectHealthFactorBeforeVisible() -// await screenshot(borrowDialog.getDialog(), 'borrow-dialog-exceeds-max-amount') -// }) -// }) - -// test.describe('Position with only deposit', () => { -// const initialDeposits = { -// wstETH: 2, -// rETH: 2, -// } - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ...initialBalances }, -// }, -// }) - -// const borrowPage = new BorrowPageObject(page) -// // to simulate a position with only deposits, we go through the easy borrow flow -// // but interrupt it before the borrow action, going directly to the myPortfolio -// // this way we have deposit transactions executed, but no borrow transaction -// // resulting in a position with only deposits -// await borrowPage.fillDepositAssetAction(0, 'wstETH', initialDeposits.wstETH) -// await borrowPage.addNewDepositAssetAction() -// await borrowPage.fillBorrowAssetAction(1) // doesn't matter, we're not borrowing anything -// await borrowPage.fillDepositAssetAction(1, 'rETH', initialDeposits.rETH) -// await borrowPage.submitAction() - -// const actionsContainer = new ActionsPageObject(page) -// for (let i = 0; i < 4; i++) { -// await actionsContainer.acceptActionAtIndex(i) -// } -// await actionsContainer.expectEnabledActionAtIndex(4) - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.goToMyPortfolioAction() -// await myPortfolioPage.expectDepositedAssets(10_220) -// }) - -// test('can borrow erc-20', async ({ page }) => { -// const borrow = { -// asset: 'wstETH', -// amount: 1, -// } - -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickBorrowButtonAction(borrow.asset) - -// const borrowDialog = new DialogPageObject(page, headerRegExp) -// await borrowDialog.fillAmountAction(borrow.amount) -// const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(1) -// await borrowDialog.expectSuccessPage([borrow], fork) - -// await screenshot(borrowDialog.getDialog(), 'borrow-dialog-only-deposit-erc-20-success') - -// await borrowDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.expectBorrowTable({ -// [borrow.asset]: borrow.amount, -// }) -// }) - -// test('can borrow USDC', async ({ page }) => { -// const borrow = { -// asset: 'USDC', -// amount: 100, -// } - -// const myPortfolioPage = new MyPortfolioPageObject(page) - -// await myPortfolioPage.clickBorrowButtonAction(borrow.asset) - -// const borrowDialog = new DialogPageObject(page, headerRegExp) -// await borrowDialog.fillAmountAction(borrow.amount) -// const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(1) -// await borrowDialog.expectSuccessPage([borrow], fork) - -// await screenshot(borrowDialog.getDialog(), 'borrow-dialog-USDC-success') - -// await borrowDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.expectBorrowTable({ -// [borrow.asset]: borrow.amount, -// }) -// }) - -// test('displays health factor', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickBorrowButtonAction('rETH') - -// const borrowDialog = new DialogPageObject(page, headerRegExp) -// await borrowDialog.fillAmountAction(1) -// await borrowDialog.expectHealthFactorAfterVisible() - -// // @note this is needed for deterministic screenshots -// const actionsContainer = new ActionsPageObject(borrowDialog.locatePanelByHeader('Actions')) -// await actionsContainer.expectEnabledActionAtIndex(0) - -// await screenshot(borrowDialog.getDialog(), 'borrow-dialog-only-deposit-health-factor') -// }) - -// test('clicking MAX sets input to 99% of possible borrow', async ({ page }) => { -// const myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickBorrowButtonAction('DAI') - -// const borrowDialog = new DialogPageObject(page, headerRegExp) -// await borrowDialog.clickMaxAmountAction() - -// await borrowDialog.expectInputValue('6929.369808') -// await borrowDialog.expectMaxButtonDisabled() -// await borrowDialog.expectLiquidationRiskWarning( -// 'Borrowing this amount puts you at risk of quick liquidation. You may lose part of your collateral.', -// ) - -// await borrowDialog.clickAcknowledgeRisk() - -// await borrowDialog.actionsContainer.expectActions([{ type: 'borrow', asset: 'DAI' }]) -// await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) -// }) -// }) - -// test.describe('Position in isolation mode', () => { -// const fork = setupFork({ -// blockNumber: 20230000n, -// chainId: mainnet.id, -// simulationDateOverride: new Date('2024-07-04T15:32:19Z'), -// }) -// const initialDeposits = { -// weETH: 200, -// } - -// let myPortfolioPage: MyPortfolioPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'myPortfolio', -// account: { -// type: 'connected-random', -// assetBalances: { ...initialDeposits }, -// }, -// }) - -// myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickDepositButtonAction('weETH') -// const depositDialog = new DialogPageObject(page, /Deposit weETH/) -// await depositDialog.fillAmountAction(initialDeposits.weETH) -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) -// await depositDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.clickCollateralSwitchAction('weETH') - -// const collateralDialog = new CollateralDialogPageObject(page) -// await collateralDialog.setUseAsCollateralAction('weETH', 'enabled') -// await collateralDialog.viewInMyPortfolioAction() - -// await myPortfolioPage.expectDepositedAssets(671_900) -// }) - -// test('MAX borrow accounts for isolation debt ceiling', async ({ page }) => { -// await myPortfolioPage.clickBorrowButtonAction('DAI') - -// const borrowDialog = new DialogPageObject(page, headerRegExp) -// await borrowDialog.clickMaxAmountAction() - -// await borrowDialog.expectInputValue('110616.31') -// await borrowDialog.expectMaxButtonDisabled() -// await borrowDialog.actionsContainer.expectActions([{ type: 'borrow', asset: 'DAI' }]) -// await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) -// }) -// }) - -// test.describe('Position with large deposit', () => { -// const fork = setupFork({ -// blockNumber: 20235425n, -// chainId: mainnet.id, -// simulationDateOverride: new Date('2024-07-04T21:26:19Z'), -// }) -// const initialDeposits = { -// WETH: 100_000, -// } - -// let myPortfolioPage: MyPortfolioPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'myPortfolio', -// account: { -// type: 'connected-random', -// assetBalances: { ...initialDeposits }, -// }, -// }) - -// myPortfolioPage = new MyPortfolioPageObject(page) -// await myPortfolioPage.clickDepositButtonAction('WETH') -// const depositDialog = new DialogPageObject(page, /Deposit WETH/) -// await depositDialog.fillAmountAction(initialDeposits.WETH) -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) -// await depositDialog.viewInMyPortfolioAction() -// await myPortfolioPage.expectDepositedAssets(313_328_590) -// }) - -// test('MAX borrow accounts for borrow cap', async ({ page }) => { -// await myPortfolioPage.clickBorrowButtonAction('wstETH') - -// const borrowDialog = new DialogPageObject(page, headerRegExp) -// await borrowDialog.clickMaxAmountAction() - -// await borrowDialog.expectInputValue('99.323398') -// await borrowDialog.expectMaxButtonDisabled() -// await borrowDialog.actionsContainer.expectActions([{ type: 'borrow', asset: 'wstETH' }]) -// await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) -// }) - -// test('MAX borrow accounts for available liquidity', async ({ page }) => { -// await myPortfolioPage.clickBorrowButtonAction('USDC') - -// const borrowDialog = new DialogPageObject(page, headerRegExp) -// await borrowDialog.clickMaxAmountAction() - -// await borrowDialog.expectInputValue('409207.097251') -// await borrowDialog.expectMaxButtonDisabled() -// await borrowDialog.actionsContainer.expectActions([{ type: 'borrow', asset: 'USDC' }]) -// await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) -// }) -// }) - -// test.describe('Liquidation risk warning', () => { -// let borrowDialog: DialogPageObject -// let myPortfolioPage: MyPortfolioPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'easyBorrow', -// account: { -// type: 'connected-random', -// assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, -// }, -// }) - -// borrowDialog = new DialogPageObject(page, headerRegExp) -// myPortfolioPage = new MyPortfolioPageObject(page) - -// const borrowPage = new BorrowPageObject(page) -// await borrowPage.depositWithoutBorrowActions({ rETH: 2, wstETH: 10 }) -// await myPortfolioPage.goToMyPortfolioAction() -// }) - -// test('shows risk warning', async () => { -// await myPortfolioPage.clickBorrowButtonAction('WETH') - -// await borrowDialog.fillAmountAction(8) -// await borrowDialog.expectLiquidationRiskWarning( -// 'Borrowing this amount puts you at risk of quick liquidation. You may lose part of your collateral.', -// ) -// }) - -// test('actions stay disabled until risk warning is acknowledged', async () => { -// await myPortfolioPage.clickBorrowButtonAction('WETH') - -// await borrowDialog.fillAmountAction(8) -// await borrowDialog.actionsContainer.expectDisabledActionAtIndex(0) -// await borrowDialog.clickAcknowledgeRisk() -// await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) -// }) - -// test('hf above danger zone threshold; risk warning is not shown', async () => { -// await myPortfolioPage.clickBorrowButtonAction('WETH') - -// await borrowDialog.fillAmountAction(0.1) -// await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) -// await borrowDialog.expectLiquidationRiskWarningNotVisible() -// }) - -// test('input validation error; risk warning is not shown', async () => { -// await myPortfolioPage.clickBorrowButtonAction('WETH') - -// await borrowDialog.fillAmountAction(0) -// await borrowDialog.expectAssetInputError(borrowValidationIssueToMessage['value-not-positive']) -// await borrowDialog.expectLiquidationRiskWarningNotVisible() -// }) -// }) -// }) +import { borrowValidationIssueToMessage } from '@/domain/market-validators/validateBorrow' +import { BorrowPageObject } from '@/pages/Borrow.PageObject' +import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { CollateralDialogPageObject } from '../collateral/CollateralDialog.PageObject' +import { DialogPageObject } from '../common/Dialog.PageObject' + +const header = /Borrow */ + +test.describe('Borrow dialog', () => { + const initialBalances = { + rETH: 100, + wstETH: 100, + } + + test.describe('Position with deposit and borrow', () => { + const initialDeposits = { + rETH: 2, + wstETH: 2, + } + const daiToBorrow = 1500 + const expectedInitialHealthFactor = '9.68' + const expectedHealthFactor = '2.46' + + let myPortfolioPage: MyPortfolioPageObject + let borrowDialog: DialogPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ...initialBalances }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + myPortfolioPage = new MyPortfolioPageObject(testContext) + borrowDialog = new DialogPageObject({ testContext, header }) + + await borrowPage.depositAssetsActions({ assetsToDeposit: initialDeposits, daiToBorrow }) + await borrowPage.viewInMyPortfolioAction() + + // wait for all transactions to be executed + await myPortfolioPage.expectHealthFactor(expectedInitialHealthFactor) + }) + + test('opens dialog with selected asset', async () => { + await myPortfolioPage.clickBorrowButtonAction('rETH') + + await borrowDialog.expectSelectedAsset('rETH') + await borrowDialog.expectDialogHeader('Borrow rETH') + await borrowDialog.expectHealthFactorBeforeVisible() + }) + + test('calculates health factor changes correctly', async () => { + await myPortfolioPage.clickBorrowButtonAction('rETH') + + await borrowDialog.fillAmountAction(1) + await borrowDialog.expectRiskLevelBefore('Healthy') + await borrowDialog.expectHealthFactorBefore(expectedInitialHealthFactor) + await borrowDialog.expectRiskLevelAfter('Moderate') + await borrowDialog.expectHealthFactorAfter(expectedHealthFactor) + }) + + test('after borrow, health factor matches myPortfolio', async () => { + await myPortfolioPage.clickBorrowButtonAction('rETH') + + await borrowDialog.fillAmountAction(1) + await borrowDialog.actionsContainer.acceptAllActionsAction(1) + await borrowDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectHealthFactor(expectedHealthFactor) + }) + + test('has correct action plan for erc-20', async () => { + await myPortfolioPage.clickBorrowButtonAction('rETH') + + await borrowDialog.fillAmountAction(1) + await borrowDialog.actionsContainer.expectActions([{ type: 'borrow', asset: 'rETH' }]) + }) + + test('can borrow erc-20', async () => { + const borrow = { + asset: 'rETH', + amount: 1, + } + + await myPortfolioPage.clickBorrowButtonAction(borrow.asset) + + await borrowDialog.fillAmountAction(borrow.amount) + await borrowDialog.actionsContainer.acceptAllActionsAction(1) + await borrowDialog.expectSuccessPage({ + tokenWithValue: [{ asset: 'rETH', amount: '1.00', usdValue: '$4,413.26' }], + }) + await borrowDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectBorrowTable({ + [borrow.asset]: borrow.amount, + }) + }) + + test('has correct action plan for native asset', async () => { + await myPortfolioPage.clickBorrowButtonAction('WETH') + + await borrowDialog.selectAssetAction('ETH') + await borrowDialog.fillAmountAction(1) + await borrowDialog.expectHealthFactorVisible() + await borrowDialog.actionsContainer.expectActions([ + { type: 'approveDelegation', asset: 'ETH' }, + { type: 'borrow', asset: 'ETH' }, + ]) + }) + + test('can borrow native asset', async () => { + const borrow = { + asset: 'ETH', + amount: 1, + } + + await myPortfolioPage.clickBorrowButtonAction('WETH') + + await borrowDialog.selectAssetAction(borrow.asset) + await borrowDialog.fillAmountAction(1) + await borrowDialog.actionsContainer.acceptAllActionsAction(2) + await borrowDialog.expectSuccessPage({ + tokenWithValue: [{ asset: 'ETH', amount: '1.00', usdValue: '$3,928.31' }], + }) + await borrowDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectBorrowTable({ + WETH: borrow.amount, + }) + }) + + test('can borrow same asset again', async () => { + const borrow = { + asset: 'DAI', + amount: 1500, + } + + await myPortfolioPage.clickBorrowButtonAction(borrow.asset) + + await borrowDialog.fillAmountAction(borrow.amount) + await borrowDialog.actionsContainer.acceptAllActionsAction(1) + await borrowDialog.expectSuccessPage({ + tokenWithValue: [{ asset: 'DAI', amount: '1,500.00', usdValue: '$1,500.00' }], + }) + await borrowDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectBorrowTable({ + [borrow.asset]: borrow.amount + daiToBorrow, + }) + }) + + test("can't borrow more than allowed", async () => { + const borrowAsset = 'wstETH' + await myPortfolioPage.clickBorrowButtonAction(borrowAsset) + + await borrowDialog.fillAmountAction(initialDeposits[borrowAsset] * 10) + await borrowDialog.expectAssetInputError(borrowValidationIssueToMessage['insufficient-collateral']) + }) + }) + + test.describe('Position with only deposit', () => { + const initialDeposits = { + wstETH: 2, + rETH: 2, + } + + let myPortfolioPage: MyPortfolioPageObject + let borrowDialog: DialogPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ...initialBalances }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + myPortfolioPage = new MyPortfolioPageObject(testContext) + borrowDialog = new DialogPageObject({ testContext, header }) + await borrowPage.depositWithoutBorrowActions({ + assetsToDeposit: { ...initialDeposits }, + }) + + await myPortfolioPage.goToMyPortfolioAction() + await myPortfolioPage.expectDepositedAssets('$18.16K') + }) + + test('can borrow erc-20', async () => { + const borrow = { + asset: 'wstETH', + amount: 1, + } + + await myPortfolioPage.clickBorrowButtonAction(borrow.asset) + + await borrowDialog.fillAmountAction(borrow.amount) + await borrowDialog.actionsContainer.acceptAllActionsAction(1) + await borrowDialog.expectSuccessPage({ + tokenWithValue: [{ asset: 'wstETH', amount: '1.00', usdValue: '$4,665.46' }], + }) + await borrowDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectBorrowTable({ + [borrow.asset]: borrow.amount, + }) + }) + + test('can borrow USDC', async () => { + const borrow = { + asset: 'USDC', + amount: 100, + } + + await myPortfolioPage.clickBorrowButtonAction(borrow.asset) + + await borrowDialog.fillAmountAction(borrow.amount) + await borrowDialog.actionsContainer.acceptAllActionsAction(1) + await borrowDialog.expectSuccessPage({ + tokenWithValue: [{ asset: 'USDC', amount: '100.00', usdValue: '$100.00' }], + }) + await borrowDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectBorrowTable({ + [borrow.asset]: borrow.amount, + }) + }) + + test('displays health factor', async () => { + await myPortfolioPage.clickBorrowButtonAction('rETH') + + await borrowDialog.fillAmountAction(1) + await borrowDialog.expectHealthFactorAfterVisible() + }) + + test('clicking MAX sets input to 99% of possible borrow', async () => { + await myPortfolioPage.clickBorrowButtonAction('DAI') + + await borrowDialog.clickMaxAmountAction() + await borrowDialog.expectInputValue('14200.947199') + await borrowDialog.expectMaxButtonDisabled() + await borrowDialog.expectLiquidationRiskWarning( + 'Borrowing this amount puts you at risk of quick liquidation. You may lose part of your collateral.', + ) + await borrowDialog.clickAcknowledgeRisk() + await borrowDialog.actionsContainer.expectActions([{ type: 'borrow', asset: 'DAI' }]) + await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) + }) + }) + + test.describe('Position in isolation mode', () => { + const initialDeposits = { + weETH: 200, + } + + let myPortfolioPage: MyPortfolioPageObject + let borrowDialog: DialogPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: 20230000n, + chainId: mainnet.id, + }, + initialPage: 'myPortfolio', + account: { + type: 'connected-random', + assetBalances: { ...initialDeposits }, + }, + }) + + const depositDialog = new DialogPageObject({ testContext, header: /Deposit weETH/ }) + const collateralDialog = new CollateralDialogPageObject(testContext) + myPortfolioPage = new MyPortfolioPageObject(testContext) + borrowDialog = new DialogPageObject({ testContext, header }) + + await myPortfolioPage.clickDepositButtonAction('weETH') + + await depositDialog.fillAmountAction(initialDeposits.weETH) + await depositDialog.actionsContainer.acceptAllActionsAction(2) + await depositDialog.viewInMyPortfolioAction() + + await myPortfolioPage.clickCollateralSwitchAction('weETH') + + await collateralDialog.setUseAsCollateralAction({ assetName: 'weETH', setting: 'enabled' }) + await collateralDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectDepositedAssets('$671.9K') + }) + + test('MAX borrow accounts for isolation debt ceiling', async () => { + await myPortfolioPage.clickBorrowButtonAction('DAI') + + await borrowDialog.clickMaxAmountAction() + await borrowDialog.expectInputValue('110616.31') + await borrowDialog.expectMaxButtonDisabled() + await borrowDialog.actionsContainer.expectActions([{ type: 'borrow', asset: 'DAI' }]) + await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) + }) + }) + + test.describe('Position with large deposit', () => { + const initialDeposits = { + WETH: 100_000, + } + + let myPortfolioPage: MyPortfolioPageObject + let borrowDialog: DialogPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'myPortfolio', + account: { + type: 'connected-random', + assetBalances: { ...initialDeposits }, + }, + }) + + const depositDialog = new DialogPageObject({ testContext, header: /Deposit WETH/ }) + myPortfolioPage = new MyPortfolioPageObject(testContext) + borrowDialog = new DialogPageObject({ testContext, header }) + + await myPortfolioPage.clickDepositButtonAction('WETH') + + await depositDialog.fillAmountAction(initialDeposits.WETH) + await depositDialog.actionsContainer.acceptAllActionsAction(2) + await depositDialog.viewInMyPortfolioAction() + + await myPortfolioPage.expectDepositedAssets('$392.8M') + }) + + test('MAX borrow accounts for borrow cap', async () => { + await myPortfolioPage.clickBorrowButtonAction('wstETH') + + await borrowDialog.clickMaxAmountAction() + await borrowDialog.expectInputValue('5064.577659') + await borrowDialog.expectMaxButtonDisabled() + await borrowDialog.actionsContainer.expectActions([{ type: 'borrow', asset: 'wstETH' }]) + await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) + }) + + test('MAX borrow accounts for available liquidity', async () => { + await myPortfolioPage.clickBorrowButtonAction('USDC') + + await borrowDialog.clickMaxAmountAction() + await borrowDialog.expectInputValue('67115.418673') + await borrowDialog.expectMaxButtonDisabled() + await borrowDialog.actionsContainer.expectActions([{ type: 'borrow', asset: 'USDC' }]) + await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) + }) + }) + + test.describe('Liquidation risk warning', () => { + let borrowDialog: DialogPageObject + let myPortfolioPage: MyPortfolioPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + blockNumber: DEFAULT_BLOCK_NUMBER, + chainId: mainnet.id, + }, + initialPage: 'easyBorrow', + account: { + type: 'connected-random', + assetBalances: { ETH: 1, rETH: 100, wstETH: 100 }, + }, + }) + + const borrowPage = new BorrowPageObject(testContext) + borrowDialog = new DialogPageObject({ testContext, header }) + myPortfolioPage = new MyPortfolioPageObject(testContext) + + await borrowPage.depositWithoutBorrowActions({ assetsToDeposit: { rETH: 2, wstETH: 10 } }) + await myPortfolioPage.goToMyPortfolioAction() + }) + + test('shows risk warning', async () => { + await myPortfolioPage.clickBorrowButtonAction('WETH') + + await borrowDialog.fillAmountAction(8) + await borrowDialog.expectLiquidationRiskWarning( + 'Borrowing this amount puts you at risk of quick liquidation. You may lose part of your collateral.', + ) + }) + + test('actions stay disabled until risk warning is acknowledged', async () => { + await myPortfolioPage.clickBorrowButtonAction('WETH') + + await borrowDialog.fillAmountAction(8) + await borrowDialog.actionsContainer.expectDisabledActionAtIndex(0) + await borrowDialog.clickAcknowledgeRisk() + await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) + }) + + test('hf above danger zone threshold; risk warning is not shown', async () => { + await myPortfolioPage.clickBorrowButtonAction('WETH') + + await borrowDialog.fillAmountAction(0.1) + await borrowDialog.actionsContainer.expectEnabledActionAtIndex(0) + await borrowDialog.expectLiquidationRiskWarningNotVisible() + }) + + test('input validation error; risk warning is not shown', async () => { + await myPortfolioPage.clickBorrowButtonAction('WETH') + + await borrowDialog.fillAmountAction(0) + await borrowDialog.expectAssetInputError(borrowValidationIssueToMessage['value-not-positive']) + await borrowDialog.expectLiquidationRiskWarningNotVisible() + }) + }) +}) From 08c5e329bc217df0e2c54e52c87f40873ce11178 Mon Sep 17 00:00:00 2001 From: Vladyslav Yatsenko <52505649+yivlad@users.noreply.github.com> Date: Sat, 21 Dec 2024 16:57:21 +0100 Subject: [PATCH 27/29] Finish savings deposit E2E tests rewrite (#520) --- .../deposit/e2e/base/DepositUSDC.test-e2e.ts | 137 +++++++++--------- .../deposit/e2e/base/DepositUSDS.test-e2e.ts | 127 ++++++++-------- .../e2e/gnosis/DepositXDAI.test-e2e.ts | 126 ++++++++-------- 3 files changed, 195 insertions(+), 195 deletions(-) diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/base/DepositUSDC.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/base/DepositUSDC.test-e2e.ts index 25de60173..ba97bedf2 100644 --- a/packages/app/src/features/dialogs/savings/deposit/e2e/base/DepositUSDC.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/deposit/e2e/base/DepositUSDC.test-e2e.ts @@ -1,76 +1,79 @@ -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { base } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { BASE_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { base } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -// test.describe('Deposit USDC', () => { -// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) +test.describe('Deposit USDC', () => { + let savingsPage: SavingsPageObject + let depositDialog: SavingsDialogPageObject -// let savingsPage: SavingsPageObject -// let depositDialog: SavingsDialogPageObject + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: base.id, + blockNumber: BASE_DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDC: 10_000, + }, + }, + }) -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// USDC: 10_000, -// }, -// }, -// }) + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickDepositButtonAction('USDC') -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickDepositButtonAction('USDC') + depositDialog = new SavingsDialogPageObject({ testContext, type: 'deposit' }) + await depositDialog.fillAmountAction(10_000) + }) -// depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) -// await depositDialog.fillAmountAction(10_000) -// }) + test('has correct action plan', async () => { + await depositDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'USDC' }, + { type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sUSDS' }, + ]) + }) -// test('has correct action plan', async () => { -// await depositDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'USDC' }, -// { type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sUSDS' }, -// ]) -// }) + test('displays transaction overview', async () => { + await depositDialog.expectNativeRouteTransactionOverview({ + apy: { + value: '8.50%', + description: 'Earn ~850.00 USDS/year', + }, + routeItems: [ + { + tokenAmount: '10,000.00 USDC', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '9,872.98 sUSDS', + tokenUsdValue: '$10,000.00', + }, + ], + outcome: '9,872.98 sUSDS', + outcomeUsd: '$10,000.00', + }) + }) -// test('displays transaction overview', async () => { -// await depositDialog.expectNativeRouteTransactionOverview({ -// apy: { -// value: '6.50%', -// description: 'Earn ~650.00 USDS/year', -// }, -// routeItems: [ -// { -// tokenAmount: '10,000.00 USDC', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '9,911.77 sUSDS', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// outcome: '9,911.77 sUSDS', -// outcomeUsd: '$10,000.00', -// }) -// }) + test('executes deposit', async () => { + await depositDialog.actionsContainer.acceptAllActionsAction(2) -// test('executes deposit', async () => { -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2) + await depositDialog.expectSuccessPage() + await depositDialog.clickBackToSavingsButton() -// await depositDialog.expectSuccessPage() -// await depositDialog.clickBackToSavingsButton() - -// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,911.77 sUSDS', estimatedUsdsValue: '10,000' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') -// }) -// }) + await savingsPage.expectSavingsUsdsBalance({ + susdsBalance: '9,872.98 sUSDS', + estimatedUsdsValue: '9,999.999999', // USDC has 6 decimals, so the value is rounded down. This is consistent with the data in the smart contract + }) + await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/base/DepositUSDS.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/base/DepositUSDS.test-e2e.ts index 6fcb732b1..6c5b9f1b7 100644 --- a/packages/app/src/features/dialogs/savings/deposit/e2e/base/DepositUSDS.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/deposit/e2e/base/DepositUSDS.test-e2e.ts @@ -1,73 +1,74 @@ -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { base } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { BASE_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { base } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -// test.describe('Deposit USDS', () => { -// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let depositDialog: SavingsDialogPageObject +test.describe('Deposit USDS', () => { + let savingsPage: SavingsPageObject + let depositDialog: SavingsDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// USDS: 10_000, -// }, -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: base.id, + blockNumber: BASE_DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDS: 10_000, + }, + }, + }) -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickDepositButtonAction('USDS') + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickDepositButtonAction('USDS') -// depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) -// await depositDialog.fillAmountAction(10_000) -// }) + depositDialog = new SavingsDialogPageObject({ testContext, type: 'deposit' }) + await depositDialog.fillAmountAction(10_000) + }) -// test('has correct action plan', async () => { -// await depositDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'USDS' }, -// { type: 'depositToSavings', asset: 'USDS', savingsAsset: 'sUSDS' }, -// ]) -// }) + test('has correct action plan', async () => { + await depositDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'USDS' }, + { type: 'depositToSavings', asset: 'USDS', savingsAsset: 'sUSDS' }, + ]) + }) -// test('displays transaction overview', async () => { -// await depositDialog.expectNativeRouteTransactionOverview({ -// apy: { -// value: '6.50%', -// description: 'Earn ~650.00 USDS/year', -// }, -// routeItems: [ -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '9,911.77 sUSDS', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// outcome: '9,911.77 sUSDS', -// outcomeUsd: '$10,000.00', -// }) + test('displays transaction overview', async () => { + await depositDialog.expectNativeRouteTransactionOverview({ + apy: { + value: '8.50%', + description: 'Earn ~850.00 USDS/year', + }, + routeItems: [ + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '9,872.98 sUSDS', + tokenUsdValue: '$10,000.00', + }, + ], + outcome: '9,872.98 sUSDS', + outcomeUsd: '$10,000.00', + }) -// await depositDialog.expectUpgradeSwitchToBeHidden() -// }) + await depositDialog.expectUpgradeSwitchToBeHidden() + }) -// test('executes deposit', async () => { -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2, fork) + test('executes deposit', async () => { + await depositDialog.actionsContainer.acceptAllActionsAction(2) -// await depositDialog.expectSuccessPage() -// await depositDialog.clickBackToSavingsButton() + await depositDialog.expectSuccessPage() + await depositDialog.clickBackToSavingsButton() -// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,911.77 sUSDS', estimatedUsdsValue: '10,000' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') -// }) -// }) + await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,872.98 sUSDS', estimatedUsdsValue: '10,000' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/deposit/e2e/gnosis/DepositXDAI.test-e2e.ts b/packages/app/src/features/dialogs/savings/deposit/e2e/gnosis/DepositXDAI.test-e2e.ts index e08da542e..9ae4949e7 100644 --- a/packages/app/src/features/dialogs/savings/deposit/e2e/gnosis/DepositXDAI.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/deposit/e2e/gnosis/DepositXDAI.test-e2e.ts @@ -1,74 +1,70 @@ -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { gnosis } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { gnosis } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -// test.describe('Deposit XDAI on Gnosis', () => { -// const fork = setupFork({ -// blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, -// chainId: gnosis.id, -// useTenderlyVnet: true, -// }) -// let savingsPage: SavingsPageObject -// let depositDialog: SavingsDialogPageObject +test.describe('Deposit XDAI on Gnosis', () => { + let savingsPage: SavingsPageObject + let depositDialog: SavingsDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// XDAI: 10_100, -// }, -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: gnosis.id, + blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + XDAI: 10_100, + }, + }, + }) -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickDepositButtonAction('XDAI') + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickDepositButtonAction('XDAI') -// depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) -// await depositDialog.fillAmountAction(10_000) -// }) + depositDialog = new SavingsDialogPageObject({ testContext, type: 'deposit' }) + await depositDialog.fillAmountAction(10_000) + }) -// test('uses native sDai deposit', async () => { -// await depositDialog.actionsContainer.expectActions([ -// { type: 'depositToSavings', asset: 'XDAI', savingsAsset: 'sDAI' }, -// ]) -// }) + test('uses native sDai deposit', async () => { + await depositDialog.actionsContainer.expectActions([ + { type: 'depositToSavings', asset: 'XDAI', savingsAsset: 'sDAI' }, + ]) + }) -// test('displays transaction overview', async () => { -// await depositDialog.expectNativeRouteTransactionOverview({ -// apy: { -// value: '10.60%', -// description: 'Earn ~1,059.80 XDAI/year', -// }, -// routeItems: [ -// { -// tokenAmount: '10,000.00 XDAI', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '9,192.79 sDAI', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// outcome: '9,192.79 sDAI', -// outcomeUsd: '$10,000.00', -// }) -// }) + test('displays transaction overview', async () => { + await depositDialog.expectNativeRouteTransactionOverview({ + apy: { + value: '10.60%', + description: 'Earn ~1,059.80 XDAI/year', + }, + routeItems: [ + { + tokenAmount: '10,000.00 XDAI', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '9,192.79 sDAI', + tokenUsdValue: '$10,000.00', + }, + ], + outcome: '9,192.79 sDAI', + outcomeUsd: '$10,000.00', + }) + }) -// test('executes deposit', async () => { -// const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(1, fork) + test('executes deposit', async () => { + await depositDialog.actionsContainer.acceptAllActionsAction(1) -// await depositDialog.expectSuccessPage() -// await depositDialog.clickBackToSavingsButton() + await depositDialog.expectSuccessPage() + await depositDialog.clickBackToSavingsButton() -// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '9,192.32 sDAI', estimatedDaiValue: '9,999.48' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('XDAI', '100') -// }) -// }) + await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '9,192.32 sDAI', estimatedDaiValue: '9,999.48' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('XDAI', '100') + }) +}) From 70d2d7b7427ae744253215dae631e554d8bbb095 Mon Sep 17 00:00:00 2001 From: Vladyslav Yatsenko <52505649+yivlad@users.noreply.github.com> Date: Sat, 21 Dec 2024 22:01:24 +0100 Subject: [PATCH 28/29] Rewrite savings withdraw E2E tests (#521) --- .../dialogs/repay/RepayDialog.test-e2e.ts | 5 - .../SavingsWithdrawDialog.test-e2e.ts | 195 ------- .../withdraw/e2e/base/General.test-e2e.ts | 81 +++ .../withdraw/e2e/base/SendUSDC.test-e2e.ts | 159 +++--- .../withdraw/e2e/base/SendUSDS.test-e2e.ts | 148 ++--- .../e2e/base/WithdrawMaxUSDC.test-e2e.ts | 121 ++--- .../e2e/base/WithdrawMaxUSDS.test-e2e.ts | 119 ++-- .../e2e/base/WithdrawUSDC.test-e2e.ts | 129 ++--- .../e2e/base/WithdrawUSDS.test-e2e.ts | 119 ++-- .../withdraw/e2e/gnosis/General.test-e2e.ts | 33 ++ .../withdraw/e2e/gnosis/SendXDAI.test-e2e.ts | 142 ++--- .../e2e/gnosis/WithdrawMaxXDAI.test-e2e.ts | 122 ++--- .../e2e/gnosis/WithdrawXDAI.test-e2e.ts | 122 ++--- .../withdraw/e2e/mainnet/General.test-e2e.ts | 79 +++ .../withdraw/e2e/mainnet/SendDAI.test-e2e.ts | 147 ++--- .../e2e/mainnet/SendDAIValidation.test-e2e.ts | 508 +++++++++--------- .../withdraw/e2e/mainnet/SendUSDC.test-e2e.ts | 353 ++++++------ .../withdraw/e2e/mainnet/SendUSDS.test-e2e.ts | 341 ++++++------ .../e2e/mainnet/WithdrawDAI.test-e2e.ts | 295 +++++----- .../e2e/mainnet/WithdrawMaxDAI.test-e2e.ts | 116 ++-- .../e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts | 298 +++++----- .../e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts | 286 +++++----- .../e2e/mainnet/WithdrawUSDC.test-e2e.ts | 298 +++++----- .../e2e/mainnet/WithdrawUSDS.test-e2e.ts | 286 +++++----- packages/app/src/pages/Savings.PageObject.ts | 11 +- 25 files changed, 2272 insertions(+), 2241 deletions(-) delete mode 100644 packages/app/src/features/dialogs/savings/withdraw/SavingsWithdrawDialog.test-e2e.ts create mode 100644 packages/app/src/features/dialogs/savings/withdraw/e2e/base/General.test-e2e.ts create mode 100644 packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/General.test-e2e.ts create mode 100644 packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/General.test-e2e.ts diff --git a/packages/app/src/features/dialogs/repay/RepayDialog.test-e2e.ts b/packages/app/src/features/dialogs/repay/RepayDialog.test-e2e.ts index 84ccaec5e..a77a3c983 100644 --- a/packages/app/src/features/dialogs/repay/RepayDialog.test-e2e.ts +++ b/packages/app/src/features/dialogs/repay/RepayDialog.test-e2e.ts @@ -191,11 +191,6 @@ test.describe('Repay dialog', () => { repayDialog = new DialogPageObject({ testContext, header: headerRegExp }) await myPortfolioPage.expectHealthFactor('3.73') - - // forcefully set browser time to the timestamp of borrow transaction - // const block = await testContext.testnetController.client.getBlock() - // await injectFixedDate(page, new Date(Number(block.timestamp) * 1000)) - // await page.reload() }) test('can repay if balance is less than debt', async ({ page }) => { diff --git a/packages/app/src/features/dialogs/savings/withdraw/SavingsWithdrawDialog.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/SavingsWithdrawDialog.test-e2e.ts deleted file mode 100644 index fe04f75b2..000000000 --- a/packages/app/src/features/dialogs/savings/withdraw/SavingsWithdrawDialog.test-e2e.ts +++ /dev/null @@ -1,195 +0,0 @@ -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER, GNOSIS_DEFAULT_BLOCK_NUMBER, DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { base, gnosis, mainnet } from 'viem/chains' -// import { SavingsDialogPageObject } from '../common/e2e/SavingsDialog.PageObject' - -// test.describe('Savings withdraw dialog', () => { -// test.describe('Mainnet', () => { -// const fork = setupFork({ -// blockNumber: DEFAULT_BLOCK_NUMBER, -// chainId: mainnet.id, -// useTenderlyVnet: true, -// }) - -// test('can switch between tokens', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sDAI: 1000, -// }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickWithdrawSDaiButtonAction() - -// const withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) -// const actionsContainer = new ActionsPageObject(withdrawalDialog.locatePanelByHeader('Actions')) - -// await withdrawalDialog.fillAmountAction(1000) -// await actionsContainer.expectEnabledActionAtIndex(0) -// await actionsContainer.expectActions([ -// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'withdraw' }, -// ]) - -// await withdrawalDialog.selectAssetAction('USDC') -// await withdrawalDialog.fillAmountAction(1000) -// await actionsContainer.expectEnabledActionAtIndex(0) -// await actionsContainer.expectActions([ -// { type: 'approve', asset: 'sDAI' }, -// { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sDAI', mode: 'withdraw' }, -// ]) - -// await withdrawalDialog.selectAssetAction('DAI') -// await withdrawalDialog.fillAmountAction(1000) -// await actionsContainer.expectEnabledActionAtIndex(0) -// await actionsContainer.expectActions([ -// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'withdraw' }, -// ]) -// }) -// }) - -// test.describe('Base', () => { -// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) - -// test('can switch between tokens', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sUSDS: 1000, -// }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickWithdrawSUsdsButtonAction() - -// const withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) -// const actionsContainer = new ActionsPageObject(withdrawalDialog.locatePanelByHeader('Actions')) - -// await withdrawalDialog.fillAmountAction(1000) -// await actionsContainer.expectEnabledActionAtIndex(0) -// await actionsContainer.expectActions([ -// { type: 'approve', asset: 'sUSDS' }, -// { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, -// ]) - -// await withdrawalDialog.selectAssetAction('USDC') -// await withdrawalDialog.fillAmountAction(1000) -// await actionsContainer.expectEnabledActionAtIndex(0) -// await actionsContainer.expectActions([ -// { type: 'approve', asset: 'sUSDS' }, -// { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'withdraw' }, -// ]) - -// await withdrawalDialog.selectAssetAction('USDS') -// await withdrawalDialog.fillAmountAction(1000) -// await actionsContainer.expectEnabledActionAtIndex(0) -// await actionsContainer.expectActions([ -// { type: 'approve', asset: 'sUSDS' }, -// { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, -// ]) -// }) -// }) -// }) - -// test.describe('Savings withdraw dialog send mode', () => { -// test.describe('Mainnet', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let sendDialog: SavingsDialogPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sDAI: 10_000, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickSendSDaiButtonAction() - -// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) -// }) - -// test('can select only supported assets', async () => { -// await sendDialog.openAssetSelectorAction() -// await sendDialog.expectAssetSelectorOptions(['DAI', 'USDC']) -// }) -// }) - -// test.describe('Gnosis', () => { -// const fork = setupFork({ blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let sendDialog: SavingsDialogPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// XDAI: 100, -// sDAI: 10_000, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickSendSDaiButtonAction() - -// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) -// }) - -// test('can select only supported assets', async () => { -// await sendDialog.openAssetSelectorAction() -// await sendDialog.expectAssetSelectorOptions(['XDAI']) -// }) -// }) - -// test.describe('Base', () => { -// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let sendDialog: SavingsDialogPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// USDS: 100, -// sUSDS: 10_000, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickSendSUsdsButtonAction() - -// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) -// }) - -// test('can select only supported assets', async () => { -// await sendDialog.openAssetSelectorAction() -// await sendDialog.expectAssetSelectorOptions(['USDC', 'USDS']) -// }) -// }) -// }) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/General.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/General.test-e2e.ts new file mode 100644 index 000000000..fb0c0587d --- /dev/null +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/General.test-e2e.ts @@ -0,0 +1,81 @@ +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { BASE_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { base } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' + +test.describe('Without send mode', () => { + test('can switch between tokens', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: base.id, + blockNumber: BASE_DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sUSDS: 1000, + }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickWithdrawSUsdsButtonAction() + + const withdrawalDialog = new SavingsDialogPageObject({ testContext, type: 'withdraw' }) + + await withdrawalDialog.fillAmountAction(1000) + await withdrawalDialog.actionsContainer.expectEnabledActionAtIndex(0) + await withdrawalDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sUSDS' }, + { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, + ]) + + await withdrawalDialog.selectAssetAction('USDC') + await withdrawalDialog.fillAmountAction(1000) + await withdrawalDialog.actionsContainer.expectEnabledActionAtIndex(0) + await withdrawalDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sUSDS' }, + { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'withdraw' }, + ]) + + await withdrawalDialog.selectAssetAction('USDS') + await withdrawalDialog.fillAmountAction(1000) + await withdrawalDialog.actionsContainer.expectEnabledActionAtIndex(0) + await withdrawalDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sUSDS' }, + { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, + ]) + }) +}) + +test.describe('With send mode', () => { + test('can select only supported assets', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: base.id, + blockNumber: BASE_DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + USDS: 100, + sUSDS: 10_000, + }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickSendSUsdsButtonAction() + + const sendDialog = new SavingsDialogPageObject({ testContext, type: 'send' }) + + await sendDialog.openAssetSelectorAction() + await sendDialog.expectAssetSelectorOptions(['USDC', 'USDS']) + }) +}) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/SendUSDC.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/SendUSDC.test-e2e.ts index d4f72a627..04d7220f9 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/SendUSDC.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/SendUSDC.test-e2e.ts @@ -1,92 +1,91 @@ -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { TOKENS_ON_FORK } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { randomAddress } from '@/test/utils/addressUtils' -// import { test } from '@playwright/test' -// import { base } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { BASE_DEFAULT_BLOCK_NUMBER, TOKENS_ON_FORK } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { randomAddress } from '@/test/utils/addressUtils' +import { test } from '@playwright/test' +import { base } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -// test.describe('Send USDC', () => { -// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) +test.describe('Send USDC', () => { + let savingsPage: SavingsPageObject + let sendDialog: SavingsDialogPageObject -// let savingsPage: SavingsPageObject -// let sendDialog: SavingsDialogPageObject + const receiver = randomAddress('bob') + const amount = 7000 + const usdc = TOKENS_ON_FORK[base.id].USDC -// const receiver = randomAddress('bob') -// const amount = 7000 -// const usdc = TOKENS_ON_FORK[base.id].USDC + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: base.id, + blockNumber: BASE_DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sUSDS: 10_000, + }, + }, + }) -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sUSDS: 10_000, -// }, -// }, -// }) + savingsPage = new SavingsPageObject(testContext) -// savingsPage = new SavingsPageObject(page) + await savingsPage.clickSendSUsdsButtonAction() + sendDialog = new SavingsDialogPageObject({ testContext, type: 'send' }) -// await savingsPage.clickSendSUsdsButtonAction() -// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) + await sendDialog.selectAssetAction('USDC') + await sendDialog.fillAmountAction(amount) + await sendDialog.fillReceiverAction(receiver) + }) -// await sendDialog.selectAssetAction('USDC') -// await sendDialog.fillAmountAction(amount) -// await sendDialog.fillReceiverAction(receiver) -// }) + test('has correct action plan', async () => { + await sendDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sUSDS' }, + { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'send' }, + ]) + }) -// test('has correct action plan', async () => { -// await sendDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'sUSDS' }, -// { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'send' }, -// ]) -// }) + test('displays transaction overview', async () => { + await sendDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '6,911.09 sUSDS', + tokenUsdValue: '$7,000.00', + }, + { + tokenAmount: '7,000.00 USDS', + tokenUsdValue: '$7,000.00', + }, + { + tokenAmount: '7,000.00 USDC', + tokenUsdValue: '$7,000.00', + }, + ], + outcome: '7,000.00 USDC', + outcomeUsd: '$7,000.00', + }) + }) -// test('displays transaction overview', async () => { -// await sendDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '6,938.24 sUSDS', -// tokenUsdValue: '$7,000.00', -// }, -// { -// tokenAmount: '7,000.00 USDS', -// tokenUsdValue: '$7,000.00', -// }, -// { -// tokenAmount: '7,000.00 USDC', -// tokenUsdValue: '$7,000.00', -// }, -// ], -// outcome: '7,000.00 USDC', -// outcomeUsd: '$7,000.00', -// }) -// }) + test('executes send', async () => { + await sendDialog.expectReceiverTokenBalance({ + receiver, + token: usdc, + expectedBalance: 0, + }) -// test('executes send', async () => { -// await sendDialog.expectReceiverTokenBalance({ -// forkUrl: fork.forkUrl, -// receiver, -// token: usdc, -// expectedBalance: 0, -// }) + await sendDialog.actionsContainer.acceptAllActionsAction(2) + await sendDialog.expectSuccessPage() -// await sendDialog.actionsContainer.acceptAllActionsAction(2, fork) -// await sendDialog.expectSuccessPage() + await sendDialog.expectReceiverTokenBalance({ + receiver, + token: usdc, + expectedBalance: amount, + }) -// await sendDialog.expectReceiverTokenBalance({ -// forkUrl: fork.forkUrl, -// receiver, -// token: usdc, -// expectedBalance: amount, -// }) - -// await sendDialog.clickBackToSavingsButton() -// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '3,061.76 sUSDS', estimatedUsdsValue: '3,089' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') -// }) -// }) + await sendDialog.clickBackToSavingsButton() + await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '3,088.91 sUSDS', estimatedUsdsValue: '3,128.6548910' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/SendUSDS.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/SendUSDS.test-e2e.ts index f19ec24bf..95ab0d43c 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/SendUSDS.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/SendUSDS.test-e2e.ts @@ -1,84 +1,84 @@ -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { TOKENS_ON_FORK } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { randomAddress } from '@/test/utils/addressUtils' -// import { test } from '@playwright/test' -// import { base } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { BASE_DEFAULT_BLOCK_NUMBER, TOKENS_ON_FORK } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { randomAddress } from '@/test/utils/addressUtils' +import { test } from '@playwright/test' +import { base } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -// test.describe('Send USDS', () => { -// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let sendDialog: SavingsDialogPageObject -// const receiver = randomAddress('bob') -// const amount = 7000 -// const usds = TOKENS_ON_FORK[base.id].USDS +test.describe('Send USDS', () => { + let savingsPage: SavingsPageObject + let sendDialog: SavingsDialogPageObject + const receiver = randomAddress('bob') + const amount = 7000 + const usds = TOKENS_ON_FORK[base.id].USDS -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sUSDS: 10_000, -// }, -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: base.id, + blockNumber: BASE_DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sUSDS: 10_000, + }, + }, + }) -// savingsPage = new SavingsPageObject(page) + savingsPage = new SavingsPageObject(testContext) -// await savingsPage.clickSendSUsdsButtonAction() -// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) -// await sendDialog.fillAmountAction(amount) -// await sendDialog.fillReceiverAction(receiver) -// }) + await savingsPage.clickSendSUsdsButtonAction() + sendDialog = new SavingsDialogPageObject({ testContext, type: 'send' }) + await sendDialog.fillAmountAction(amount) + await sendDialog.fillReceiverAction(receiver) + }) -// test('has correct action plan', async () => { -// await sendDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'sUSDS' }, -// { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'send' }, -// ]) -// }) + test('has correct action plan', async () => { + await sendDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sUSDS' }, + { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'send' }, + ]) + }) -// test('displays transaction overview', async () => { -// await sendDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '6,938.24 sUSDS', -// tokenUsdValue: '$7,000.00', -// }, -// { -// tokenAmount: '7,000.00 USDS', -// tokenUsdValue: '$7,000.00', -// }, -// ], -// outcome: '7,000.00 USDS', -// outcomeUsd: '$7,000.00', -// }) -// }) + test('displays transaction overview', async () => { + await sendDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '6,911.09 sUSDS', + tokenUsdValue: '$7,000.00', + }, + { + tokenAmount: '7,000.00 USDS', + tokenUsdValue: '$7,000.00', + }, + ], + outcome: '7,000.00 USDS', + outcomeUsd: '$7,000.00', + }) + }) -// test('executes send', async () => { -// await sendDialog.expectReceiverTokenBalance({ -// forkUrl: fork.forkUrl, -// receiver, -// token: usds, -// expectedBalance: 0, -// }) + test('executes send', async () => { + await sendDialog.expectReceiverTokenBalance({ + receiver, + token: usds, + expectedBalance: 0, + }) -// await sendDialog.actionsContainer.acceptAllActionsAction(2, fork) -// await sendDialog.expectSuccessPage() + await sendDialog.actionsContainer.acceptAllActionsAction(2) + await sendDialog.expectSuccessPage() -// await sendDialog.expectReceiverTokenBalance({ -// forkUrl: fork.forkUrl, -// receiver, -// token: usds, -// expectedBalance: amount, -// }) + await sendDialog.expectReceiverTokenBalance({ + receiver, + token: usds, + expectedBalance: amount, + }) -// await sendDialog.clickBackToSavingsButton() -// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '3,061.76 sUSDS', estimatedUsdsValue: '3,089' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') -// }) -// }) + await sendDialog.clickBackToSavingsButton() + await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '3,088.91 sUSDS', estimatedUsdsValue: '3,128.6548917' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawMaxUSDC.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawMaxUSDC.test-e2e.ts index 2f3a16501..fc32b9368 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawMaxUSDC.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawMaxUSDC.test-e2e.ts @@ -1,70 +1,71 @@ -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { base } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { BASE_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { base } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -// test.describe('Withdraw Max USDC', () => { -// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let withdrawDialog: SavingsDialogPageObject +test.describe('Withdraw Max USDC', () => { + let savingsPage: SavingsPageObject + let withdrawDialog: SavingsDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sUSDS: 10_000, -// }, -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: base.id, + blockNumber: BASE_DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sUSDS: 10_000, + }, + }, + }) -// savingsPage = new SavingsPageObject(page) + savingsPage = new SavingsPageObject(testContext) -// await savingsPage.clickWithdrawSUsdsButtonAction() -// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) -// await withdrawDialog.selectAssetAction('USDC') -// await withdrawDialog.clickMaxAmountAction() -// }) + await savingsPage.clickWithdrawSUsdsButtonAction() + withdrawDialog = new SavingsDialogPageObject({ testContext, type: 'withdraw' }) + await withdrawDialog.selectAssetAction('USDC') + await withdrawDialog.clickMaxAmountAction() + }) -// test('has correct action plan', async () => { -// await withdrawDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'sUSDS' }, -// { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'withdraw' }, -// ]) -// }) + test('has correct action plan', async () => { + await withdrawDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sUSDS' }, + { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'withdraw' }, + ]) + }) -// test('displays transaction overview', async () => { -// await withdrawDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '10,000.00 sUSDS', -// tokenUsdValue: '$10,089.01', -// }, -// { -// tokenAmount: '10,089.01 USDS', -// tokenUsdValue: '$10,089.01', -// }, -// ], -// outcome: '10,089.01 USDC', -// outcomeUsd: '$10,089.01', -// }) + test('displays transaction overview', async () => { + await withdrawDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '10,000.00 sUSDS', + tokenUsdValue: '$10,128.65', + }, + { + tokenAmount: '10,128.65 USDS', + tokenUsdValue: '$10,128.65', + }, + ], + outcome: '10,128.65 USDC', + outcomeUsd: '$10,128.65', + }) -// await withdrawDialog.expectUpgradeSwitchToBeHidden() -// }) + await withdrawDialog.expectUpgradeSwitchToBeHidden() + }) -// test('executes withdraw', async () => { -// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2, fork) + test('executes withdraw', async () => { + await withdrawDialog.actionsContainer.acceptAllActionsAction(2) -// await withdrawDialog.expectSuccessPage() -// await withdrawDialog.clickBackToSavingsButton() + await withdrawDialog.expectSuccessPage() + await withdrawDialog.clickBackToSavingsButton() -// await savingsPage.expectOpportunityStablecoinsAmount('~$10,089.01') -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '10,089.01') -// }) -// }) + await savingsPage.expectOpportunityStablecoinsAmount('~$10,128.65') + await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '10,128.65') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawMaxUSDS.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawMaxUSDS.test-e2e.ts index 9128574f7..09d6075db 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawMaxUSDS.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawMaxUSDS.test-e2e.ts @@ -1,69 +1,70 @@ -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { base } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { BASE_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { base } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -// test.describe('Withdraw Max USDS', () => { -// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let withdrawDialog: SavingsDialogPageObject +test.describe('Withdraw Max USDS', () => { + let savingsPage: SavingsPageObject + let withdrawDialog: SavingsDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sUSDS: 10_000, -// }, -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: base.id, + blockNumber: BASE_DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sUSDS: 10_000, + }, + }, + }) -// savingsPage = new SavingsPageObject(page) + savingsPage = new SavingsPageObject(testContext) -// await savingsPage.clickWithdrawSUsdsButtonAction() -// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) -// await withdrawDialog.clickMaxAmountAction() -// }) + await savingsPage.clickWithdrawSUsdsButtonAction() + withdrawDialog = new SavingsDialogPageObject({ testContext, type: 'withdraw' }) + await withdrawDialog.clickMaxAmountAction() + }) -// test('has correct action plan', async () => { -// await withdrawDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'sUSDS' }, -// { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, -// ]) -// }) + test('has correct action plan', async () => { + await withdrawDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sUSDS' }, + { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, + ]) + }) -// test('displays transaction overview', async () => { -// await withdrawDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '10,000.00 sUSDS', -// tokenUsdValue: '$10,089.01', -// }, -// { -// tokenAmount: '10,089.01 USDS', -// tokenUsdValue: '$10,089.01', -// }, -// ], -// outcome: '10,089.01 USDS', -// outcomeUsd: '$10,089.01', -// }) + test('displays transaction overview', async () => { + await withdrawDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '10,000.00 sUSDS', + tokenUsdValue: '$10,128.65', + }, + { + tokenAmount: '10,128.65 USDS', + tokenUsdValue: '$10,128.65', + }, + ], + outcome: '10,128.65 USDS', + outcomeUsd: '$10,128.65', + }) -// await withdrawDialog.expectUpgradeSwitchToBeHidden() -// }) + await withdrawDialog.expectUpgradeSwitchToBeHidden() + }) -// test('executes withdraw', async () => { -// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2, fork) + test('executes withdraw', async () => { + await withdrawDialog.actionsContainer.acceptAllActionsAction(2) -// await withdrawDialog.expectSuccessPage() -// await withdrawDialog.clickBackToSavingsButton() + await withdrawDialog.expectSuccessPage() + await withdrawDialog.clickBackToSavingsButton() -// await savingsPage.expectOpportunityStablecoinsAmount('~$10,089.01') -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,089.01') -// }) -// }) + await savingsPage.expectOpportunityStablecoinsAmount('~$10,128.65') + await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,128.65') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawUSDC.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawUSDC.test-e2e.ts index 702a0eb28..43c2ae911 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawUSDC.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawUSDC.test-e2e.ts @@ -1,74 +1,75 @@ -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { base } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { BASE_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { base } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -// test.describe('Withdraw USDC', () => { -// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let withdrawDialog: SavingsDialogPageObject +test.describe('Withdraw USDC', () => { + let savingsPage: SavingsPageObject + let withdrawDialog: SavingsDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sUSDS: 10_000, -// }, -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: base.id, + blockNumber: BASE_DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sUSDS: 10_000, + }, + }, + }) -// savingsPage = new SavingsPageObject(page) + savingsPage = new SavingsPageObject(testContext) -// await savingsPage.clickWithdrawSUsdsButtonAction() -// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) -// await withdrawDialog.selectAssetAction('USDC') -// await withdrawDialog.fillAmountAction(1000) -// }) + await savingsPage.clickWithdrawSUsdsButtonAction() + withdrawDialog = new SavingsDialogPageObject({ testContext, type: 'withdraw' }) + await withdrawDialog.selectAssetAction('USDC') + await withdrawDialog.fillAmountAction(1000) + }) -// test('has correct action plan', async () => { -// await withdrawDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'sUSDS' }, -// { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'withdraw' }, -// ]) -// }) + test('has correct action plan', async () => { + await withdrawDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sUSDS' }, + { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'withdraw' }, + ]) + }) -// test('displays transaction overview', async () => { -// await withdrawDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '991.18 sUSDS', -// tokenUsdValue: '$1,000.00', -// }, -// { -// tokenAmount: '1,000.00 USDS', -// tokenUsdValue: '$1,000.00', -// }, -// { -// tokenAmount: '1,000.00 USDC', -// tokenUsdValue: '$1,000.00', -// }, -// ], -// outcome: '1,000.00 USDC', -// outcomeUsd: '$1,000.00', -// }) + test('displays transaction overview', async () => { + await withdrawDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '987.30 sUSDS', + tokenUsdValue: '$1,000.00', + }, + { + tokenAmount: '1,000.00 USDS', + tokenUsdValue: '$1,000.00', + }, + { + tokenAmount: '1,000.00 USDC', + tokenUsdValue: '$1,000.00', + }, + ], + outcome: '1,000.00 USDC', + outcomeUsd: '$1,000.00', + }) -// await withdrawDialog.expectUpgradeSwitchToBeHidden() -// }) + await withdrawDialog.expectUpgradeSwitchToBeHidden() + }) -// test('executes withdraw', async () => { -// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2, fork) + test('executes withdraw', async () => { + await withdrawDialog.actionsContainer.acceptAllActionsAction(2) -// await withdrawDialog.expectSuccessPage() -// await withdrawDialog.clickBackToSavingsButton() + await withdrawDialog.expectSuccessPage() + await withdrawDialog.clickBackToSavingsButton() -// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,008.82 sUSDS', estimatedUsdsValue: '9,089' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '1,000') -// }) -// }) + await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,012.70 sUSDS', estimatedUsdsValue: '9,128.654891' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '1,000') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawUSDS.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawUSDS.test-e2e.ts index 06c3348a3..7e8c47ab1 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawUSDS.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/base/WithdrawUSDS.test-e2e.ts @@ -1,69 +1,70 @@ -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { base } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { BASE_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { base } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -// test.describe('Withdraw USDS', () => { -// const fork = setupFork({ chainId: base.id, blockNumber: 22143788n, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let withdrawDialog: SavingsDialogPageObject +test.describe('Withdraw USDS', () => { + let savingsPage: SavingsPageObject + let withdrawDialog: SavingsDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sUSDS: 10_000, -// }, -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: base.id, + blockNumber: BASE_DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sUSDS: 10_000, + }, + }, + }) -// savingsPage = new SavingsPageObject(page) + savingsPage = new SavingsPageObject(testContext) -// await savingsPage.clickWithdrawSUsdsButtonAction() -// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) -// await withdrawDialog.fillAmountAction(1000) -// }) + await savingsPage.clickWithdrawSUsdsButtonAction() + withdrawDialog = new SavingsDialogPageObject({ testContext, type: 'withdraw' }) + await withdrawDialog.fillAmountAction(1000) + }) -// test('has correct action plan', async () => { -// await withdrawDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'sUSDS' }, -// { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, -// ]) -// }) + test('has correct action plan', async () => { + await withdrawDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sUSDS' }, + { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, + ]) + }) -// test('displays transaction overview', async () => { -// await withdrawDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '991.18 sUSDS', -// tokenUsdValue: '$1,000.00', -// }, -// { -// tokenAmount: '1,000.00 USDS', -// tokenUsdValue: '$1,000.00', -// }, -// ], -// outcome: '1,000.00 USDS', -// outcomeUsd: '$1,000.00', -// }) + test('displays transaction overview', async () => { + await withdrawDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '987.30 sUSDS', + tokenUsdValue: '$1,000.00', + }, + { + tokenAmount: '1,000.00 USDS', + tokenUsdValue: '$1,000.00', + }, + ], + outcome: '1,000.00 USDS', + outcomeUsd: '$1,000.00', + }) -// await withdrawDialog.expectUpgradeSwitchToBeHidden() -// }) + await withdrawDialog.expectUpgradeSwitchToBeHidden() + }) -// test('executes withdraw', async () => { -// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2, fork) + test('executes withdraw', async () => { + await withdrawDialog.actionsContainer.acceptAllActionsAction(2) -// await withdrawDialog.expectSuccessPage() -// await withdrawDialog.clickBackToSavingsButton() + await withdrawDialog.expectSuccessPage() + await withdrawDialog.clickBackToSavingsButton() -// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,008.82 sUSDS', estimatedUsdsValue: '9,089' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '1,000') -// }) -// }) + await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '9,012.70 sUSDS', estimatedUsdsValue: '9,128.654892' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '1,000') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/General.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/General.test-e2e.ts new file mode 100644 index 000000000..97c9249e0 --- /dev/null +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/General.test-e2e.ts @@ -0,0 +1,33 @@ +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { gnosis } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' + +test.describe('With send mode', () => { + test('can select only supported assets', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: gnosis.id, + blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + XDAI: 100, + sDAI: 10_000, + }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickSendSDaiButtonAction() + + const sendDialog = new SavingsDialogPageObject({ testContext, type: 'send' }) + + await sendDialog.openAssetSelectorAction() + await sendDialog.expectAssetSelectorOptions(['XDAI']) + }) +}) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/SendXDAI.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/SendXDAI.test-e2e.ts index a9bbb8987..4a353bb42 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/SendXDAI.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/SendXDAI.test-e2e.ts @@ -1,81 +1,81 @@ -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { randomAddress } from '@/test/utils/addressUtils' -// import { test } from '@playwright/test' -// import { gnosis } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { randomAddress } from '@/test/utils/addressUtils' +import { test } from '@playwright/test' +import { gnosis } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -// test.describe('Send XDAI on Gnosis', () => { -// const fork = setupFork({ blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, chainId: gnosis.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let sendDialog: SavingsDialogPageObject -// const receiver = randomAddress('bob') -// const amount = 7000 +test.describe('Send XDAI on Gnosis', () => { + let savingsPage: SavingsPageObject + let sendDialog: SavingsDialogPageObject + const receiver = randomAddress('bob') + const amount = 7000 -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// XDAI: 100, -// sDAI: 10_000, -// }, -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: gnosis.id, + blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + XDAI: 100, + sDAI: 10_000, + }, + }, + }) -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickSendSDaiButtonAction() + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickSendSDaiButtonAction() -// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) -// await sendDialog.fillAmountAction(amount) -// await sendDialog.fillReceiverAction(receiver) -// }) + sendDialog = new SavingsDialogPageObject({ testContext, type: 'send' }) + await sendDialog.fillAmountAction(amount) + await sendDialog.fillReceiverAction(receiver) + }) -// test('uses native sDai withdraw and send', async () => { -// await sendDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'sDAI' }, -// { type: 'withdrawFromSavings', asset: 'XDAI', savingsAsset: 'sDAI', mode: 'send' }, -// ]) -// }) + test('uses native sDai withdraw and send', async () => { + await sendDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sDAI' }, + { type: 'withdrawFromSavings', asset: 'XDAI', savingsAsset: 'sDAI', mode: 'send' }, + ]) + }) -// test('displays transaction overview', async () => { -// await sendDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '6,434.95 sDAI', -// tokenUsdValue: '$7,000.00', -// }, -// { -// tokenAmount: '7,000.00 XDAI', -// tokenUsdValue: '$7,000.00', -// }, -// ], -// outcome: '7,000.00 XDAI', -// outcomeUsd: '$7,000.00', -// }) -// }) + test('displays transaction overview', async () => { + await sendDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '6,434.95 sDAI', + tokenUsdValue: '$7,000.00', + }, + { + tokenAmount: '7,000.00 XDAI', + tokenUsdValue: '$7,000.00', + }, + ], + outcome: '7,000.00 XDAI', + outcomeUsd: '$7,000.00', + }) + }) -// test('executes send', async () => { -// await sendDialog.expectReceiverBalance({ -// forkUrl: fork.forkUrl, -// receiver, -// expectedBalance: 0, -// }) + test('executes send', async () => { + await sendDialog.expectReceiverBalance({ + receiver, + expectedBalance: 0, + }) -// await sendDialog.actionsContainer.acceptAllActionsAction(2, fork) -// await sendDialog.expectSuccessPage() + await sendDialog.actionsContainer.acceptAllActionsAction(2) + await sendDialog.expectSuccessPage() -// await sendDialog.expectReceiverBalance({ -// forkUrl: fork.forkUrl, -// receiver, -// expectedBalance: amount, -// }) + await sendDialog.expectReceiverBalance({ + receiver, + expectedBalance: amount, + }) -// await sendDialog.clickBackToSavingsButton() -// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,565.05 sDAI', estimatedDaiValue: '3,878.094168' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('XDAI', '100') -// }) -// }) + await sendDialog.clickBackToSavingsButton() + await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,565.05 sDAI', estimatedDaiValue: '3,878.094168' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('XDAI', '100') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/WithdrawMaxXDAI.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/WithdrawMaxXDAI.test-e2e.ts index 77f590f44..4a1988ffe 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/WithdrawMaxXDAI.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/WithdrawMaxXDAI.test-e2e.ts @@ -1,72 +1,68 @@ -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { gnosis } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { gnosis } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -// test.describe('Withdraw max XDAI on Gnosis', () => { -// const fork = setupFork({ -// blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, -// chainId: gnosis.id, -// useTenderlyVnet: true, -// }) -// let savingsPage: SavingsPageObject -// let withdrawalDialog: SavingsDialogPageObject +test.describe('Withdraw max XDAI on Gnosis', () => { + let savingsPage: SavingsPageObject + let withdrawalDialog: SavingsDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// XDAI: 100, -// sDAI: 10_000, -// }, -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: gnosis.id, + blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + XDAI: 100, + sDAI: 10_000, + }, + }, + }) -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickWithdrawSDaiButtonAction() + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickWithdrawSDaiButtonAction() -// withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) -// await withdrawalDialog.clickMaxAmountAction() -// }) + withdrawalDialog = new SavingsDialogPageObject({ testContext, type: 'withdraw' }) + await withdrawalDialog.clickMaxAmountAction() + }) -// test('uses native sDai withdrawal', async () => { -// await withdrawalDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'sDAI' }, -// { type: 'withdrawFromSavings', asset: 'XDAI', savingsAsset: 'sDAI', mode: 'withdraw' }, -// ]) -// }) + test('uses native sDai withdrawal', async () => { + await withdrawalDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sDAI' }, + { type: 'withdrawFromSavings', asset: 'XDAI', savingsAsset: 'sDAI', mode: 'withdraw' }, + ]) + }) -// test('displays transaction overview', async () => { -// await withdrawalDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '10,000.00 sDAI', -// tokenUsdValue: '$10,878.09', -// }, -// { -// tokenAmount: '10,878.09 XDAI', -// tokenUsdValue: '$10,878.09', -// }, -// ], -// outcome: '10,878.09 XDAI', -// outcomeUsd: '$10,878.09', -// }) -// }) + test('displays transaction overview', async () => { + await withdrawalDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '10,000.00 sDAI', + tokenUsdValue: '$10,878.09', + }, + { + tokenAmount: '10,878.09 XDAI', + tokenUsdValue: '$10,878.09', + }, + ], + outcome: '10,878.09 XDAI', + outcomeUsd: '$10,878.09', + }) + }) -// test('executes max withdrawal', async () => { -// const actionsContainer = new ActionsPageObject(withdrawalDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2, fork) + test('executes max withdrawal', async () => { + await withdrawalDialog.actionsContainer.acceptAllActionsAction(2) -// await withdrawalDialog.expectSuccessPage() -// await withdrawalDialog.clickBackToSavingsButton() + await withdrawalDialog.expectSuccessPage() + await withdrawalDialog.clickBackToSavingsButton() -// await savingsPage.expectOpportunityStablecoinsAmount('~$10,978.09') -// await savingsPage.expectStablecoinsInWalletAssetBalance('XDAI', '10,978.09') -// }) -// }) + await savingsPage.expectOpportunityStablecoinsAmount('~$10,978.09') + await savingsPage.expectStablecoinsInWalletAssetBalance('XDAI', '10,978.09') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/WithdrawXDAI.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/WithdrawXDAI.test-e2e.ts index 45583c809..a2ec24281 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/WithdrawXDAI.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/gnosis/WithdrawXDAI.test-e2e.ts @@ -1,72 +1,68 @@ -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { gnosis } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { GNOSIS_DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { gnosis } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -// test.describe('Withdraw XDAI on Gnosis', () => { -// const fork = setupFork({ -// blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, -// chainId: gnosis.id, -// useTenderlyVnet: true, -// }) -// let savingsPage: SavingsPageObject -// let withdrawalDialog: SavingsDialogPageObject +test.describe('Withdraw XDAI on Gnosis', () => { + let savingsPage: SavingsPageObject + let withdrawalDialog: SavingsDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// XDAI: 100, -// sDAI: 10_000, -// }, -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: gnosis.id, + blockNumber: GNOSIS_DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + XDAI: 100, + sDAI: 10_000, + }, + }, + }) -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickWithdrawSDaiButtonAction() + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickWithdrawSDaiButtonAction() -// withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) -// await withdrawalDialog.fillAmountAction(7000) -// }) + withdrawalDialog = new SavingsDialogPageObject({ testContext, type: 'withdraw' }) + await withdrawalDialog.fillAmountAction(7000) + }) -// test('uses native sDai withdrawal', async () => { -// await withdrawalDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'sDAI' }, -// { type: 'withdrawFromSavings', asset: 'XDAI', savingsAsset: 'sDAI', mode: 'withdraw' }, -// ]) -// }) + test('uses native sDai withdrawal', async () => { + await withdrawalDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sDAI' }, + { type: 'withdrawFromSavings', asset: 'XDAI', savingsAsset: 'sDAI', mode: 'withdraw' }, + ]) + }) -// test('displays transaction overview', async () => { -// await withdrawalDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '6,434.95 sDAI', -// tokenUsdValue: '$7,000.00', -// }, -// { -// tokenAmount: '7,000.00 XDAI', -// tokenUsdValue: '$7,000.00', -// }, -// ], -// outcome: '7,000.00 XDAI', -// outcomeUsd: '$7,000.00', -// }) -// }) + test('displays transaction overview', async () => { + await withdrawalDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '6,434.95 sDAI', + tokenUsdValue: '$7,000.00', + }, + { + tokenAmount: '7,000.00 XDAI', + tokenUsdValue: '$7,000.00', + }, + ], + outcome: '7,000.00 XDAI', + outcomeUsd: '$7,000.00', + }) + }) -// test('executes withdrawal', async () => { -// const actionsContainer = new ActionsPageObject(withdrawalDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2, fork) + test('executes withdrawal', async () => { + await withdrawalDialog.actionsContainer.acceptAllActionsAction(2) -// await withdrawalDialog.expectSuccessPage() -// await withdrawalDialog.clickBackToSavingsButton() + await withdrawalDialog.expectSuccessPage() + await withdrawalDialog.clickBackToSavingsButton() -// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,565.05 sDAI', estimatedDaiValue: '3,878.09' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('XDAI', '7,100.00') -// }) -// }) + await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,565.05 sDAI', estimatedDaiValue: '3,878.09' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('XDAI', '7,100.00') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/General.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/General.test-e2e.ts new file mode 100644 index 000000000..eb3a0e5dd --- /dev/null +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/General.test-e2e.ts @@ -0,0 +1,79 @@ +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' + +test.describe('Without send mode', () => { + test('can switch between tokens', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sDAI: 1000, + }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickWithdrawSDaiButtonAction() + + const withdrawalDialog = new SavingsDialogPageObject({ testContext, type: 'withdraw' }) + + await withdrawalDialog.fillAmountAction(1000) + await withdrawalDialog.actionsContainer.expectEnabledActionAtIndex(0) + await withdrawalDialog.actionsContainer.expectActions([ + { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'withdraw' }, + ]) + + await withdrawalDialog.selectAssetAction('USDC') + await withdrawalDialog.fillAmountAction(1000) + await withdrawalDialog.actionsContainer.expectEnabledActionAtIndex(0) + await withdrawalDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sDAI' }, + { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sDAI', mode: 'withdraw' }, + ]) + + await withdrawalDialog.selectAssetAction('DAI') + await withdrawalDialog.fillAmountAction(1000) + await withdrawalDialog.actionsContainer.expectEnabledActionAtIndex(0) + await withdrawalDialog.actionsContainer.expectActions([ + { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'withdraw' }, + ]) + }) +}) + +test.describe('With send mode', () => { + test('can select only supported assets', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sDAI: 10_000, + }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickSendSDaiButtonAction() + + const sendDialog = new SavingsDialogPageObject({ testContext, type: 'send' }) + + await sendDialog.openAssetSelectorAction() + await sendDialog.expectAssetSelectorOptions(['DAI', 'USDC', 'USDS']) + }) +}) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendDAI.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendDAI.test-e2e.ts index 4ab4fcf46..f4e211b1f 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendDAI.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendDAI.test-e2e.ts @@ -1,83 +1,84 @@ -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER, TOKENS_ON_FORK } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { randomAddress } from '@/test/utils/addressUtils' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER, TOKENS_ON_FORK } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { randomAddress } from '@/test/utils/addressUtils' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -// test.describe('Send DAI on Mainnet', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let sendDialog: SavingsDialogPageObject -// const receiver = randomAddress('bob') -// const amount = 7000 -// const dai = TOKENS_ON_FORK[mainnet.id].DAI +test.describe('Send DAI on Mainnet', () => { + let savingsPage: SavingsPageObject + let sendDialog: SavingsDialogPageObject + const receiver = randomAddress('bob') + const amount = 7000 + const dai = TOKENS_ON_FORK[mainnet.id].DAI -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sDAI: 10_000, -// }, -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sDAI: 10_000, + }, + }, + }) -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickSendSDaiButtonAction() + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickSendSDaiButtonAction() -// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) -// await sendDialog.fillAmountAction(amount) -// await sendDialog.fillReceiverAction(receiver) -// }) + sendDialog = new SavingsDialogPageObject({ testContext, type: 'send' }) + await sendDialog.fillAmountAction(amount) + await sendDialog.fillReceiverAction(receiver) + }) -// test('uses native sDai withdraw and send', async () => { -// await sendDialog.actionsContainer.expectActions([ -// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, -// ]) -// }) + test('uses native sDai withdraw and send', async () => { + await sendDialog.actionsContainer.expectActions([ + { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, + ]) + }) -// test('displays transaction overview', async () => { -// await sendDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '6,647.10 sDAI', -// tokenUsdValue: '$7,000.00', -// }, -// { -// tokenAmount: '7,000.00 DAI', -// tokenUsdValue: '$7,000.00', -// }, -// ], -// outcome: '7,000.00 DAI', -// outcomeUsd: '$7,000.00', -// }) -// }) + test('displays transaction overview', async () => { + await sendDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '6,218.91 sDAI', + tokenUsdValue: '$7,000.00', + }, + { + tokenAmount: '7,000.00 DAI', + tokenUsdValue: '$7,000.00', + }, + ], + outcome: '7,000.00 DAI', + outcomeUsd: '$7,000.00', + }) + }) -// test('executes send', async () => { -// await sendDialog.expectReceiverTokenBalance({ -// forkUrl: fork.forkUrl, -// receiver, -// token: dai, -// expectedBalance: 0, -// }) + test('executes send', async () => { + await sendDialog.expectReceiverTokenBalance({ + receiver, + token: dai, + expectedBalance: 0, + }) -// await sendDialog.actionsContainer.acceptAllActionsAction(1, fork) -// await sendDialog.expectSuccessPage() + await sendDialog.actionsContainer.acceptAllActionsAction(1) + await sendDialog.expectSuccessPage() -// await sendDialog.expectReceiverTokenBalance({ -// forkUrl: fork.forkUrl, -// receiver, -// token: dai, -// expectedBalance: amount, -// }) + await sendDialog.expectReceiverTokenBalance({ + receiver, + token: dai, + expectedBalance: amount, + }) -// await sendDialog.clickBackToSavingsButton() -// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,352.90 sDAI', estimatedDaiValue: '3,530.91' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') -// }) -// }) + await sendDialog.clickBackToSavingsButton() + + await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,781.09 sDAI', estimatedDaiValue: '4,255.9918184' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendDAIValidation.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendDAIValidation.test-e2e.ts index f6f2be2bf..847220463 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendDAIValidation.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendDAIValidation.test-e2e.ts @@ -1,246 +1,262 @@ -// import { receiverValidationIssueToMessage } from '@/domain/savings/validateReceiver' -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { Address, zeroAddress } from 'viem' -// import { mainnet } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -// import { withdrawValidationIssueToMessage } from '../../logic/validation' - -// test.describe('Asset input validation', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let sendDialog: SavingsDialogPageObject -// const receiver = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' - -// test.describe('Input value exceeds sDAI value', () => { -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sDAI: 100, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickSendSDaiButtonAction() - -// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) -// await sendDialog.fillAmountAction(200) -// await sendDialog.fillReceiverAction(receiver) -// }) - -// test('displays validation error', async () => { -// await sendDialog.expectAssetInputError(withdrawValidationIssueToMessage['exceeds-balance']) -// }) - -// test('actions are disabled', async () => { -// await sendDialog.actionsContainer.expectDisabledActions([ -// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, -// ]) -// }) - -// test('displays sensible tx overview', async () => { -// await sendDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '189.92 sDAI', -// tokenUsdValue: '$200.00', -// }, -// { -// tokenAmount: '200.00 DAI', -// tokenUsdValue: '$200.00', -// }, -// ], -// outcome: '200.00 DAI', -// outcomeUsd: '$200.00', -// }) -// }) -// }) - -// test('displays validation error for dirty input with 0 value', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sDAI: 100, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickSendSDaiButtonAction() -// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) - -// await sendDialog.fillAmountAction(10) -// await sendDialog.fillAmountAction(0) - -// await sendDialog.expectAssetInputError(withdrawValidationIssueToMessage['value-not-positive']) -// }) -// }) - -// test.describe('Receiver input validation', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let sendDialog: SavingsDialogPageObject -// let selfAddress: Address - -// test.describe('Incorrect receiver address', () => { -// test.beforeEach(async ({ page }) => { -// const { account } = await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sDAI: 100, -// }, -// }, -// }) - -// selfAddress = account - -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickSendSDaiButtonAction() - -// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) -// await sendDialog.fillAmountAction(50) // valid input amount -// }) - -// test('displays validation error', async () => { -// // invalid address is not valid -// await sendDialog.fillReceiverAction('0x0') -// await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['invalid-address']) -// await sendDialog.fillReceiverAction('not-an-address') -// await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['invalid-address']) -// await sendDialog.fillReceiverAction('0XD8DA6BF26964AF9D7EED9E03E53415D37AA96045') // uppercase -// await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['invalid-address']) - -// // zero address is not valid -// await sendDialog.fillReceiverAction(zeroAddress) -// await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['zero-address']) - -// // reserve address is not valid -// await sendDialog.fillReceiverAction('0x6B175474E89094C44Da98b954EedeAC495271d0F') // dai -// await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['token-address']) - -// // self address is not valid -// await sendDialog.fillReceiverAction(selfAddress) -// await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['self-address']) - -// // empty address is not valid -// await sendDialog.fillReceiverAction('') -// await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['undefined-receiver']) -// }) - -// test('actions are disabled when receiver input is invalid', async () => { -// await sendDialog.fillReceiverAction('not-an-address') -// await sendDialog.actionsContainer.expectDisabledActions([ -// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, -// ]) -// }) - -// test('displays sensible tx overview when amount is provided and receiver is invalid', async () => { -// await sendDialog.fillReceiverAction('not-an-address') -// await sendDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '47.48 sDAI', -// tokenUsdValue: '$50.00', -// }, -// { -// tokenAmount: '50.00 DAI', -// tokenUsdValue: '$50.00', -// }, -// ], -// outcome: '50.00 DAI', -// outcomeUsd: '$50.00', -// }) -// }) -// }) - -// test('displays warning when receiver is smart contract address', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sDAI: 100, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickSendSDaiButtonAction() -// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) -// await sendDialog.fillAmountAction(50) // valid input amount - -// await sendDialog.fillReceiverAction('0x197E90f9FAD81970bA7976f33CbD77088E5D7cf7') // pot address -// await sendDialog.expectReceiverIsSmartContractWarning() -// }) -// }) - -// test.describe('Form validation', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let sendDialog: SavingsDialogPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sDAI: 100, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickSendSDaiButtonAction() - -// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) -// }) - -// test('actions are disabled when amount is invalid, but receiver is valid', async () => { -// await sendDialog.fillAmountAction(200) -// await sendDialog.fillReceiverAction('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045') -// await sendDialog.actionsContainer.expectDisabledActions([ -// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, -// ]) -// }) - -// test('actions are disabled when amount is valid, but receiver is invalid', async () => { -// await sendDialog.fillAmountAction(50) -// await sendDialog.fillReceiverAction('not-an-address') -// await sendDialog.actionsContainer.expectDisabledActions([ -// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, -// ]) -// }) - -// test('actions are disabled when both amount and receiver are invalid', async () => { -// await sendDialog.fillAmountAction(200) -// await sendDialog.fillReceiverAction('not-an-address') -// await sendDialog.actionsContainer.expectDisabledActions([ -// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, -// ]) -// }) - -// test('actions are enabled when amount and receiver are valid', async () => { -// await sendDialog.fillAmountAction(50) -// await sendDialog.fillReceiverAction('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045') -// await sendDialog.actionsContainer.expectActions([ -// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, -// ]) -// }) -// }) +import { receiverValidationIssueToMessage } from '@/domain/savings/validateReceiver' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { Address, zeroAddress } from 'viem' +import { mainnet } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +import { withdrawValidationIssueToMessage } from '../../logic/validation' + +test.describe('Asset input validation', () => { + let savingsPage: SavingsPageObject + let sendDialog: SavingsDialogPageObject + const receiver = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' + + test.describe('Input value exceeds sDAI value', () => { + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sDAI: 100, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickSendSDaiButtonAction() + + sendDialog = new SavingsDialogPageObject({ testContext, type: 'send' }) + await sendDialog.fillAmountAction(200) + await sendDialog.fillReceiverAction(receiver) + }) + + test('displays validation error', async () => { + await sendDialog.expectAssetInputError(withdrawValidationIssueToMessage['exceeds-balance']) + }) + + test('actions are disabled', async () => { + await sendDialog.actionsContainer.expectDisabledActions([ + { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, + ]) + }) + + test('displays sensible tx overview', async () => { + await sendDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '177.68 sDAI', + tokenUsdValue: '$200.00', + }, + { + tokenAmount: '200.00 DAI', + tokenUsdValue: '$200.00', + }, + ], + outcome: '200.00 DAI', + outcomeUsd: '$200.00', + }) + }) + }) + + test('displays validation error for dirty input with 0 value', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sDAI: 100, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickSendSDaiButtonAction() + sendDialog = new SavingsDialogPageObject({ testContext, type: 'send' }) + + await sendDialog.fillAmountAction(10) + await sendDialog.fillAmountAction(0) + + await sendDialog.expectAssetInputError(withdrawValidationIssueToMessage['value-not-positive']) + }) +}) + +test.describe('Receiver input validation', () => { + let savingsPage: SavingsPageObject + let sendDialog: SavingsDialogPageObject + let selfAddress: Address + + test.describe('Incorrect receiver address', () => { + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sDAI: 100, + }, + }, + }) + + selfAddress = testContext.account + + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickSendSDaiButtonAction() + + sendDialog = new SavingsDialogPageObject({ testContext, type: 'send' }) + await sendDialog.fillAmountAction(50) // valid input amount + }) + + test('displays validation error', async () => { + // invalid address is not valid + await sendDialog.fillReceiverAction('0x0') + await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['invalid-address']) + await sendDialog.fillReceiverAction('not-an-address') + await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['invalid-address']) + await sendDialog.fillReceiverAction('0XD8DA6BF26964AF9D7EED9E03E53415D37AA96045') // uppercase + await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['invalid-address']) + + // zero address is not valid + await sendDialog.fillReceiverAction(zeroAddress) + await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['zero-address']) + + // reserve address is not valid + await sendDialog.fillReceiverAction('0x6B175474E89094C44Da98b954EedeAC495271d0F') // dai + await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['token-address']) + + // self address is not valid + await sendDialog.fillReceiverAction(selfAddress) + await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['self-address']) + + // empty address is not valid + await sendDialog.fillReceiverAction('') + await sendDialog.expectAddressInputError(receiverValidationIssueToMessage['undefined-receiver']) + }) + + test('actions are disabled when receiver input is invalid', async () => { + await sendDialog.fillReceiverAction('not-an-address') + await sendDialog.actionsContainer.expectDisabledActions([ + { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, + ]) + }) + + test('displays sensible tx overview when amount is provided and receiver is invalid', async () => { + await sendDialog.fillReceiverAction('not-an-address') + await sendDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '44.42 sDAI', + tokenUsdValue: '$50.00', + }, + { + tokenAmount: '50.00 DAI', + tokenUsdValue: '$50.00', + }, + ], + outcome: '50.00 DAI', + outcomeUsd: '$50.00', + }) + }) + }) + + test('displays warning when receiver is smart contract address', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sDAI: 100, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickSendSDaiButtonAction() + sendDialog = new SavingsDialogPageObject({ testContext, type: 'send' }) + await sendDialog.fillAmountAction(50) // valid input amount + + await sendDialog.fillReceiverAction('0x197E90f9FAD81970bA7976f33CbD77088E5D7cf7') // pot address + await sendDialog.expectReceiverIsSmartContractWarning() + }) +}) + +test.describe('Form validation', () => { + let savingsPage: SavingsPageObject + let sendDialog: SavingsDialogPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sDAI: 100, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickSendSDaiButtonAction() + + sendDialog = new SavingsDialogPageObject({ testContext, type: 'send' }) + }) + + test('actions are disabled when amount is invalid, but receiver is valid', async () => { + await sendDialog.fillAmountAction(200) + await sendDialog.fillReceiverAction('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045') + await sendDialog.actionsContainer.expectDisabledActions([ + { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, + ]) + }) + + test('actions are disabled when amount is valid, but receiver is invalid', async () => { + await sendDialog.fillAmountAction(50) + await sendDialog.fillReceiverAction('not-an-address') + await sendDialog.actionsContainer.expectDisabledActions([ + { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, + ]) + }) + + test('actions are disabled when both amount and receiver are invalid', async () => { + await sendDialog.fillAmountAction(200) + await sendDialog.fillReceiverAction('not-an-address') + await sendDialog.actionsContainer.expectDisabledActions([ + { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, + ]) + }) + + test('actions are enabled when amount and receiver are valid', async () => { + await sendDialog.fillAmountAction(50) + await sendDialog.fillReceiverAction('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045') + await sendDialog.actionsContainer.expectActions([ + { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'send' }, + ]) + }) +}) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDC.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDC.test-e2e.ts index fefc60510..c356bba8f 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDC.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDC.test-e2e.ts @@ -1,176 +1,177 @@ -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { TOKENS_ON_FORK, DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { randomAddress } from '@/test/utils/addressUtils' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' - -// test.describe('Send USDC (withdrawing from sUSDS)', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let sendDialog: SavingsDialogPageObject -// const receiver = randomAddress('bob') -// const amount = 7000 -// const usdc = TOKENS_ON_FORK[mainnet.id].USDC - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// USDS: 10_000, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickDepositButtonAction('USDS') -// const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) -// await depositDialog.fillAmountAction(10_000) -// await depositDialog.actionsContainer.acceptAllActionsAction(2, fork) -// await depositDialog.clickBackToSavingsButton() - -// await savingsPage.clickSendSUsdsButtonAction() -// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) -// await sendDialog.selectAssetAction('USDC') -// await sendDialog.fillAmountAction(amount) -// await sendDialog.fillReceiverAction(receiver) -// }) - -// test('has correct action plan', async () => { -// await sendDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'sUSDS' }, -// { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'send' }, -// ]) -// }) - -// test('displays transaction overview', async () => { -// await sendDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '6,999.84 sUSDS', -// tokenUsdValue: '$7,000.00', -// }, -// { -// tokenAmount: '7,000.00 USDS', -// tokenUsdValue: '$7,000.00', -// }, -// { -// tokenAmount: '7,000.00 USDC', -// tokenUsdValue: '$7,000.00', -// }, -// ], -// outcome: '7,000.00 USDC', -// outcomeUsd: '$7,000.00', -// }) -// }) - -// test('executes send', async () => { -// await sendDialog.expectReceiverTokenBalance({ -// forkUrl: fork.forkUrl, -// receiver, -// token: usdc, -// expectedBalance: 0, -// }) - -// await sendDialog.actionsContainer.acceptAllActionsAction(2, fork) -// await sendDialog.expectSuccessPage() - -// await sendDialog.expectReceiverTokenBalance({ -// forkUrl: fork.forkUrl, -// receiver, -// token: usdc, -// expectedBalance: amount, -// }) - -// await sendDialog.clickBackToSavingsButton() -// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '2,999.93 sUSDS', estimatedUsdsValue: '3,000' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') -// }) -// }) - -// test.describe('Send USDC (withdrawing from sDAI)', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let sendDialog: SavingsDialogPageObject -// const receiver = randomAddress('bob') -// const amount = 7000 -// const usdc = TOKENS_ON_FORK[mainnet.id].USDC - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sDAI: 10_000, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickSendSDaiButtonAction() -// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) -// await sendDialog.selectAssetAction('USDC') -// await sendDialog.fillAmountAction(amount) -// await sendDialog.fillReceiverAction(receiver) -// }) - -// test('uses convert sDAI to USDS action', async () => { -// await sendDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'sDAI' }, -// { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sDAI', mode: 'send' }, -// ]) -// }) - -// test('displays transaction overview', async () => { -// await sendDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '6,314.32 sDAI', -// tokenUsdValue: '$7,000.00', -// }, -// { -// tokenAmount: '7,000.00 DAI', -// tokenUsdValue: '$7,000.00', -// }, -// { -// tokenAmount: '7,000.00 USDC', -// tokenUsdValue: '$7,000.00', -// }, -// ], -// outcome: '7,000.00 USDC', -// outcomeUsd: '$7,000.00', -// }) -// }) - -// test('executes send', async () => { -// await sendDialog.expectReceiverTokenBalance({ -// forkUrl: fork.forkUrl, -// receiver, -// token: usdc, -// expectedBalance: 0, -// }) - -// await sendDialog.actionsContainer.acceptAllActionsAction(2, fork) -// await sendDialog.expectSuccessPage() - -// await sendDialog.expectReceiverTokenBalance({ -// forkUrl: fork.forkUrl, -// receiver, -// token: usdc, -// expectedBalance: amount, -// }) - -// await sendDialog.clickBackToSavingsButton() -// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,685.68 sDAI', estimatedDaiValue: '4,085.90' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') -// }) -// }) +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER, TOKENS_ON_FORK } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { randomAddress } from '@/test/utils/addressUtils' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' + +test.describe('Send USDC (withdrawing from sUSDS)', () => { + let savingsPage: SavingsPageObject + let sendDialog: SavingsDialogPageObject + const receiver = randomAddress('bob') + const amount = 7000 + const usdc = TOKENS_ON_FORK[mainnet.id].USDC + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDS: 10_000, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickDepositButtonAction('USDS') + const depositDialog = new SavingsDialogPageObject({ testContext, type: 'deposit' }) + await depositDialog.fillAmountAction(10_000) + await depositDialog.actionsContainer.acceptAllActionsAction(2) + await depositDialog.clickBackToSavingsButton() + + await savingsPage.clickSendSUsdsButtonAction() + sendDialog = new SavingsDialogPageObject({ testContext, type: 'send' }) + await sendDialog.selectAssetAction('USDC') + await sendDialog.fillAmountAction(amount) + await sendDialog.fillReceiverAction(receiver) + }) + + test('has correct action plan', async () => { + await sendDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sUSDS' }, + { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'send' }, + ]) + }) + + test('displays transaction overview', async () => { + await sendDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '6,881.24 sUSDS', + tokenUsdValue: '$7,000.00', + }, + { + tokenAmount: '7,000.00 USDS', + tokenUsdValue: '$7,000.00', + }, + { + tokenAmount: '7,000.00 USDC', + tokenUsdValue: '$7,000.00', + }, + ], + outcome: '7,000.00 USDC', + outcomeUsd: '$7,000.00', + }) + }) + + test('executes send', async () => { + await sendDialog.expectReceiverTokenBalance({ + receiver, + token: usdc, + expectedBalance: 0, + }) + + await sendDialog.actionsContainer.acceptAllActionsAction(2) + await sendDialog.expectSuccessPage() + + await sendDialog.expectReceiverTokenBalance({ + receiver, + token: usdc, + expectedBalance: amount, + }) + + await sendDialog.clickBackToSavingsButton() + await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '2,949.10 sUSDS', estimatedUsdsValue: '3,000.0003735' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') + }) +}) + +test.describe('Send USDC (withdrawing from sDAI)', () => { + let savingsPage: SavingsPageObject + let sendDialog: SavingsDialogPageObject + const receiver = randomAddress('bob') + const amount = 7000 + const usdc = TOKENS_ON_FORK[mainnet.id].USDC + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sDAI: 10_000, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickSendSDaiButtonAction() + sendDialog = new SavingsDialogPageObject({ testContext, type: 'send' }) + await sendDialog.selectAssetAction('USDC') + await sendDialog.fillAmountAction(amount) + await sendDialog.fillReceiverAction(receiver) + }) + + test('uses convert sDAI to USDS action', async () => { + await sendDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sDAI' }, + { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sDAI', mode: 'send' }, + ]) + }) + + test('displays transaction overview', async () => { + await sendDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '6,218.91 sDAI', + tokenUsdValue: '$7,000.00', + }, + { + tokenAmount: '7,000.00 DAI', + tokenUsdValue: '$7,000.00', + }, + { + tokenAmount: '7,000.00 USDC', + tokenUsdValue: '$7,000.00', + }, + ], + outcome: '7,000.00 USDC', + outcomeUsd: '$7,000.00', + }) + }) + + test('executes send', async () => { + await sendDialog.expectReceiverTokenBalance({ + receiver, + token: usdc, + expectedBalance: 0, + }) + + await sendDialog.actionsContainer.acceptAllActionsAction(2) + await sendDialog.expectSuccessPage() + + await sendDialog.expectReceiverTokenBalance({ + receiver, + token: usdc, + expectedBalance: amount, + }) + + await sendDialog.clickBackToSavingsButton() + await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,781.09 sDAI', estimatedDaiValue: '4,255.9920127' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '-') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDS.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDS.test-e2e.ts index 23d3d2d85..7b29d1cd4 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDS.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/SendUSDS.test-e2e.ts @@ -1,170 +1,171 @@ -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { TOKENS_ON_FORK, DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { randomAddress } from '@/test/utils/addressUtils' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' - -// test.describe('Send USDS (withdrawing from sUSDS)', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let sendDialog: SavingsDialogPageObject -// const receiver = randomAddress('bob') -// const amount = 7000 -// const usds = TOKENS_ON_FORK[mainnet.id].USDS - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// USDS: 10_000, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickDepositButtonAction('USDS') -// const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) -// await depositDialog.fillAmountAction(10_000) -// await depositDialog.actionsContainer.acceptAllActionsAction(2, fork) -// await depositDialog.clickBackToSavingsButton() - -// await savingsPage.clickSendSUsdsButtonAction() -// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) -// await sendDialog.fillAmountAction(amount) -// await sendDialog.fillReceiverAction(receiver) -// }) - -// test('uses native sUSDS withdraw and send', async () => { -// await sendDialog.actionsContainer.expectActions([ -// { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'send' }, -// ]) -// }) - -// test('displays transaction overview', async () => { -// await sendDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '6,999.84 sUSDS', -// tokenUsdValue: '$7,000.00', -// }, -// { -// tokenAmount: '7,000.00 USDS', -// tokenUsdValue: '$7,000.00', -// }, -// ], -// outcome: '7,000.00 USDS', -// outcomeUsd: '$7,000.00', -// }) -// }) - -// test('executes send', async () => { -// await sendDialog.expectReceiverTokenBalance({ -// forkUrl: fork.forkUrl, -// receiver, -// token: usds, -// expectedBalance: 0, -// }) - -// await sendDialog.actionsContainer.acceptAllActionsAction(1, fork) -// await sendDialog.expectSuccessPage() - -// await sendDialog.expectReceiverTokenBalance({ -// forkUrl: fork.forkUrl, -// receiver, -// token: usds, -// expectedBalance: amount, -// }) - -// await sendDialog.clickBackToSavingsButton() -// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '2,999.93 sUSDS', estimatedUsdsValue: '3,000' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') -// }) -// }) - -// test.describe('Send USDS (withdrawing from sDAI)', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let sendDialog: SavingsDialogPageObject -// const receiver = randomAddress('bob') -// const amount = 7000 -// const usds = TOKENS_ON_FORK[mainnet.id].USDS - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sDAI: 10_000, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickSendSDaiButtonAction() -// sendDialog = new SavingsDialogPageObject({ page, type: 'send' }) -// await sendDialog.selectAssetAction('USDS') -// await sendDialog.fillAmountAction(amount) -// await sendDialog.fillReceiverAction(receiver) -// }) - -// test('uses migrate sDAI to USDS action', async () => { -// await sendDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'sDAI' }, -// { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sDAI', mode: 'send' }, -// ]) -// }) - -// test('displays transaction overview', async () => { -// await sendDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '6,314.32 sDAI', -// tokenUsdValue: '$7,000.00', -// }, -// { -// tokenAmount: '7,000.00 DAI', -// tokenUsdValue: '$7,000.00', -// }, -// { -// tokenAmount: '7,000.00 USDS', -// tokenUsdValue: '$7,000.00', -// }, -// ], -// outcome: '7,000.00 USDS', -// outcomeUsd: '$7,000.00', -// }) -// }) - -// test('executes send', async () => { -// await sendDialog.expectReceiverTokenBalance({ -// forkUrl: fork.forkUrl, -// receiver, -// token: usds, -// expectedBalance: 0, -// }) - -// await sendDialog.actionsContainer.acceptAllActionsAction(2, fork) -// await sendDialog.expectSuccessPage() - -// await sendDialog.expectReceiverTokenBalance({ -// forkUrl: fork.forkUrl, -// receiver, -// token: usds, -// expectedBalance: amount, -// }) - -// await sendDialog.clickBackToSavingsButton() -// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,685.68 sDAI', estimatedDaiValue: '4,085.90' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') -// }) -// }) +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER, TOKENS_ON_FORK } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { randomAddress } from '@/test/utils/addressUtils' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' + +test.describe('Send USDS (withdrawing from sUSDS)', () => { + let savingsPage: SavingsPageObject + let sendDialog: SavingsDialogPageObject + const receiver = randomAddress('bob') + const amount = 7000 + const usds = TOKENS_ON_FORK[mainnet.id].USDS + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDS: 10_000, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickDepositButtonAction('USDS') + const depositDialog = new SavingsDialogPageObject({ testContext, type: 'deposit' }) + await depositDialog.fillAmountAction(10_000) + await depositDialog.actionsContainer.acceptAllActionsAction(2) + await depositDialog.clickBackToSavingsButton() + + await savingsPage.clickSendSUsdsButtonAction() + sendDialog = new SavingsDialogPageObject({ testContext, type: 'send' }) + await sendDialog.fillAmountAction(amount) + await sendDialog.fillReceiverAction(receiver) + }) + + test('uses native sUSDS withdraw and send', async () => { + await sendDialog.actionsContainer.expectActions([ + { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'send' }, + ]) + }) + + test('displays transaction overview', async () => { + await sendDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '6,881.24 sUSDS', + tokenUsdValue: '$7,000.00', + }, + { + tokenAmount: '7,000.00 USDS', + tokenUsdValue: '$7,000.00', + }, + ], + outcome: '7,000.00 USDS', + outcomeUsd: '$7,000.00', + }) + }) + + test('executes send', async () => { + await sendDialog.expectReceiverTokenBalance({ + receiver, + token: usds, + expectedBalance: 0, + }) + + await sendDialog.actionsContainer.acceptAllActionsAction(1) + await sendDialog.expectSuccessPage() + + await sendDialog.expectReceiverTokenBalance({ + receiver, + token: usds, + expectedBalance: amount, + }) + + await sendDialog.clickBackToSavingsButton() + await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '2,949.10 sUSDS', estimatedUsdsValue: '3,000.0001867' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') + }) +}) + +test.describe('Send USDS (withdrawing from sDAI)', () => { + let savingsPage: SavingsPageObject + let sendDialog: SavingsDialogPageObject + const receiver = randomAddress('bob') + const amount = 7000 + const usds = TOKENS_ON_FORK[mainnet.id].USDS + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sDAI: 10_000, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickSendSDaiButtonAction() + sendDialog = new SavingsDialogPageObject({ testContext, type: 'send' }) + await sendDialog.selectAssetAction('USDS') + await sendDialog.fillAmountAction(amount) + await sendDialog.fillReceiverAction(receiver) + }) + + test('uses migrate sDAI to USDS action', async () => { + await sendDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sDAI' }, + { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sDAI', mode: 'send' }, + ]) + }) + + test('displays transaction overview', async () => { + await sendDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '6,218.91 sDAI', + tokenUsdValue: '$7,000.00', + }, + { + tokenAmount: '7,000.00 DAI', + tokenUsdValue: '$7,000.00', + }, + { + tokenAmount: '7,000.00 USDS', + tokenUsdValue: '$7,000.00', + }, + ], + outcome: '7,000.00 USDS', + outcomeUsd: '$7,000.00', + }) + }) + + test('executes send', async () => { + await sendDialog.expectReceiverTokenBalance({ + receiver, + token: usds, + expectedBalance: 0, + }) + + await sendDialog.actionsContainer.acceptAllActionsAction(2) + await sendDialog.expectSuccessPage() + + await sendDialog.expectReceiverTokenBalance({ + receiver, + token: usds, + expectedBalance: amount, + }) + + await sendDialog.clickBackToSavingsButton() + await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,781.09 sDAI', estimatedDaiValue: '4,255.9920127' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawDAI.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawDAI.test-e2e.ts index 4a3fb69cd..c48cc1e5b 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawDAI.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawDAI.test-e2e.ts @@ -1,144 +1,151 @@ -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -// import { withdrawValidationIssueToMessage } from '../../logic/validation' - -// test.describe('Withdraw DAI on Mainnet', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) -// let savingsPage: SavingsPageObject -// let withdrawalDialog: SavingsDialogPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sDAI: 10_000, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickWithdrawSDaiButtonAction() - -// withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) -// await withdrawalDialog.fillAmountAction(7000) -// }) - -// test('uses native sDai withdrawal', async () => { -// await withdrawalDialog.actionsContainer.expectActions([ -// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'withdraw' }, -// ]) -// }) - -// test('displays transaction overview', async () => { -// await withdrawalDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '6,532.86 sDAI', -// tokenUsdValue: '$7,000.00', -// }, -// { -// tokenAmount: '7,000.00 DAI', -// tokenUsdValue: '$7,000.00', -// }, -// ], -// outcome: '7,000.00 DAI', -// outcomeUsd: '$7,000.00', -// }) -// }) - -// test('executes withdrawal', async () => { -// const actionsContainer = new ActionsPageObject(withdrawalDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(1) - -// await withdrawalDialog.expectSuccessPage() -// await withdrawalDialog.clickBackToSavingsButton() - -// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,467.14 sDAI', estimatedDaiValue: '3,715.05' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '7,000.00') -// }) -// }) - -// test.describe('Validation', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) -// let savingsPage: SavingsPageObject -// let withdrawalDialog: SavingsDialogPageObject - -// test.describe('Input value exceeds sDAI value', () => { -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sDAI: 100, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickWithdrawSDaiButtonAction() - -// withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) -// await withdrawalDialog.fillAmountAction(200) -// }) - -// test('displays validation error', async () => { -// await withdrawalDialog.expectAssetInputError(withdrawValidationIssueToMessage['exceeds-balance']) -// }) - -// test('actions are disabled', async () => { -// await withdrawalDialog.actionsContainer.expectDisabledActions([ -// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'withdraw' }, -// ]) -// }) - -// test('displays sensible tx overview', async () => { -// await withdrawalDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '186.65 sDAI', -// tokenUsdValue: '$200.00', -// }, -// { -// tokenAmount: '200.00 DAI', -// tokenUsdValue: '$200.00', -// }, -// ], -// outcome: '200.00 DAI', -// outcomeUsd: '$200.00', -// }) -// }) -// }) - -// test('displays validation error for dirty input with 0 value', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sDAI: 100, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickWithdrawSDaiButtonAction() -// withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) - -// await withdrawalDialog.fillAmountAction(10) -// await withdrawalDialog.fillAmountAction(0) - -// await withdrawalDialog.expectAssetInputError(withdrawValidationIssueToMessage['value-not-positive']) -// }) -// }) +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +import { withdrawValidationIssueToMessage } from '../../logic/validation' + +test.describe('Withdraw DAI on Mainnet', () => { + let savingsPage: SavingsPageObject + let withdrawalDialog: SavingsDialogPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sDAI: 10_000, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickWithdrawSDaiButtonAction() + + withdrawalDialog = new SavingsDialogPageObject({ testContext, type: 'withdraw' }) + await withdrawalDialog.fillAmountAction(7000) + }) + + test('uses native sDai withdrawal', async () => { + await withdrawalDialog.actionsContainer.expectActions([ + { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'withdraw' }, + ]) + }) + + test('displays transaction overview', async () => { + await withdrawalDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '6,218.91 sDAI', + tokenUsdValue: '$7,000.00', + }, + { + tokenAmount: '7,000.00 DAI', + tokenUsdValue: '$7,000.00', + }, + ], + outcome: '7,000.00 DAI', + outcomeUsd: '$7,000.00', + }) + }) + + test('executes withdrawal', async () => { + await withdrawalDialog.actionsContainer.acceptAllActionsAction(1) + + await withdrawalDialog.expectSuccessPage() + await withdrawalDialog.clickBackToSavingsButton() + + await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '3,781.09 sDAI', estimatedDaiValue: '4,255.9918184' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '7,000.00') + }) +}) + +test.describe('Validation', () => { + let savingsPage: SavingsPageObject + let withdrawalDialog: SavingsDialogPageObject + + test.describe('Input value exceeds sDAI value', () => { + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sDAI: 100, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickWithdrawSDaiButtonAction() + + withdrawalDialog = new SavingsDialogPageObject({ testContext, type: 'withdraw' }) + await withdrawalDialog.fillAmountAction(200) + }) + + test('displays validation error', async () => { + await withdrawalDialog.expectAssetInputError(withdrawValidationIssueToMessage['exceeds-balance']) + }) + + test('actions are disabled', async () => { + await withdrawalDialog.actionsContainer.expectDisabledActions([ + { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'withdraw' }, + ]) + }) + + test('displays sensible tx overview', async () => { + await withdrawalDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '177.68 sDAI', + tokenUsdValue: '$200.00', + }, + { + tokenAmount: '200.00 DAI', + tokenUsdValue: '$200.00', + }, + ], + outcome: '200.00 DAI', + outcomeUsd: '$200.00', + }) + }) + }) + + test('displays validation error for dirty input with 0 value', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sDAI: 100, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickWithdrawSDaiButtonAction() + withdrawalDialog = new SavingsDialogPageObject({ testContext, type: 'withdraw' }) + + await withdrawalDialog.fillAmountAction(10) + await withdrawalDialog.fillAmountAction(0) + + await withdrawalDialog.expectAssetInputError(withdrawValidationIssueToMessage['value-not-positive']) + }) +}) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxDAI.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxDAI.test-e2e.ts index 754cc9b65..8e888384e 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxDAI.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxDAI.test-e2e.ts @@ -1,67 +1,67 @@ -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' -// test.describe('Withdraw max DAI on Mainnet', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) -// let savingsPage: SavingsPageObject -// let withdrawalDialog: SavingsDialogPageObject +test.describe('Withdraw max DAI on Mainnet', () => { + let savingsPage: SavingsPageObject + let withdrawalDialog: SavingsDialogPageObject -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sDAI: 10_000, -// }, -// }, -// }) + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sDAI: 10_000, + }, + }, + }) -// savingsPage = new SavingsPageObject(page) -// await savingsPage.clickWithdrawSDaiButtonAction() + savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickWithdrawSDaiButtonAction() -// withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) -// await withdrawalDialog.clickMaxAmountAction() -// }) + withdrawalDialog = new SavingsDialogPageObject({ testContext, type: 'withdraw' }) + await withdrawalDialog.clickMaxAmountAction() + }) -// test('uses native sDai withdrawal', async () => { -// await withdrawalDialog.actionsContainer.expectActions([ -// { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'withdraw' }, -// ]) -// }) + test('uses native sDai withdrawal', async () => { + await withdrawalDialog.actionsContainer.expectActions([ + { type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'withdraw' }, + ]) + }) -// test('displays transaction overview', async () => { -// await withdrawalDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '10,000.00 sDAI', -// tokenUsdValue: '$10,715.05', -// }, -// { -// tokenAmount: '10,715.05 DAI', -// tokenUsdValue: '$10,715.05', -// }, -// ], -// outcome: '10,715.05 DAI', -// outcomeUsd: '$10,715.05', -// }) -// }) + test('displays transaction overview', async () => { + await withdrawalDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '10,000.00 sDAI', + tokenUsdValue: '$11,255.99', + }, + { + tokenAmount: '11,255.99 DAI', + tokenUsdValue: '$11,255.99', + }, + ], + outcome: '11,255.99 DAI', + outcomeUsd: '$11,255.99', + }) + }) -// test('executes max withdrawal', async () => { -// const actionsContainer = new ActionsPageObject(withdrawalDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(1) + test('executes max withdrawal', async () => { + await withdrawalDialog.actionsContainer.acceptAllActionsAction(1) -// await withdrawalDialog.expectSuccessPage() -// await withdrawalDialog.clickBackToSavingsButton() + await withdrawalDialog.expectSuccessPage() + await withdrawalDialog.clickBackToSavingsButton() -// await savingsPage.expectOpportunityStablecoinsAmount('~$10,715.05') -// await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '10,715.05') -// }) -// }) + await savingsPage.expectOpportunityStablecoinsAmount('~$11,255.99') + await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '11,255.99') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts index 765d73a49..29239802b 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDC.test-e2e.ts @@ -1,148 +1,150 @@ -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' - -// test.describe('Withdraw USDC from sUSDS', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let withdrawDialog: SavingsDialogPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// USDS: 10_000, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickDepositButtonAction('USDS') -// const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) -// await depositDialog.fillAmountAction(10_000) -// await depositDialog.actionsContainer.acceptAllActionsAction(2, fork) -// await depositDialog.clickBackToSavingsButton() - -// await savingsPage.clickWithdrawSUsdsButtonAction() -// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) -// await withdrawDialog.selectAssetAction('USDC') -// await withdrawDialog.clickMaxAmountAction() -// }) - -// test('has correct action plan', async () => { -// await withdrawDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'sUSDS' }, -// { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'withdraw' }, -// ]) -// }) - -// test('displays transaction overview', async () => { -// await withdrawDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '9,999.77 sUSDS', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '10,000.00 USDC', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// outcome: '10,000.00 USDC', -// outcomeUsd: '$10,000.00', -// }) - -// await withdrawDialog.expectUpgradeSwitchToBeHidden() -// }) - -// test('executes withdraw', async () => { -// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2, fork) - -// await withdrawDialog.expectSuccessPage() -// await withdrawDialog.clickBackToSavingsButton() - -// await savingsPage.expectOpportunityStablecoinsAmount('~$10,000.00') -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '10,000') -// }) -// }) - -// test.describe('Withdraw USDC from sDAI', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let withdrawDialog: SavingsDialogPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sDAI: 10_000, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickWithdrawSDaiButtonAction() -// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) -// await withdrawDialog.selectAssetAction('USDC') -// await withdrawDialog.clickMaxAmountAction() -// }) - -// test('has correct action plan', async () => { -// await withdrawDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'sDAI' }, -// { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sDAI', mode: 'withdraw' }, -// ]) -// }) - -// test('displays transaction overview', async () => { -// await withdrawDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '10,000.00 sDAI', -// tokenUsdValue: '$11,085.91', -// }, -// { -// tokenAmount: '11,085.91 DAI', -// tokenUsdValue: '$11,085.91', -// }, -// { -// tokenAmount: '11,085.91 USDC', -// tokenUsdValue: '$11,085.91', -// }, -// ], -// outcome: '11,085.91 USDC', -// outcomeUsd: '$11,085.91', -// }) - -// await withdrawDialog.expectUpgradeSwitchToBeHidden() -// }) - -// test('executes withdraw', async () => { -// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2, fork) - -// await withdrawDialog.expectSuccessPage() -// await withdrawDialog.clickBackToSavingsButton() - -// await savingsPage.expectOpportunityStablecoinsAmount('~$11,085.91') -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '11,085.91') -// }) -// }) +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' + +test.describe('Withdraw USDC from sUSDS', () => { + let savingsPage: SavingsPageObject + let withdrawDialog: SavingsDialogPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDS: 10_000, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickDepositButtonAction('USDS') + const depositDialog = new SavingsDialogPageObject({ testContext, type: 'deposit' }) + await depositDialog.fillAmountAction(10_000) + await depositDialog.actionsContainer.acceptAllActionsAction(2) + await depositDialog.clickBackToSavingsButton() + + await savingsPage.clickWithdrawSUsdsButtonAction() + withdrawDialog = new SavingsDialogPageObject({ testContext, type: 'withdraw' }) + await withdrawDialog.selectAssetAction('USDC') + await withdrawDialog.clickMaxAmountAction() + }) + + test('has correct action plan', async () => { + await withdrawDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sUSDS' }, + { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'withdraw' }, + ]) + }) + + test('displays transaction overview', async () => { + await withdrawDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '9,830.34 sUSDS', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '10,000.00 USDC', + tokenUsdValue: '$10,000.00', + }, + ], + outcome: '10,000.00 USDC', + outcomeUsd: '$10,000.00', + }) + + await withdrawDialog.expectUpgradeSwitchToBeHidden() + }) + + test('executes withdraw', async () => { + await withdrawDialog.actionsContainer.acceptAllActionsAction(2) + + await withdrawDialog.expectSuccessPage() + await withdrawDialog.clickBackToSavingsButton() + + await savingsPage.expectOpportunityStablecoinsAmount('~$10,000.00') + await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '10,000') + }) +}) + +test.describe('Withdraw USDC from sDAI', () => { + let savingsPage: SavingsPageObject + let withdrawDialog: SavingsDialogPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sDAI: 10_000, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickWithdrawSDaiButtonAction() + withdrawDialog = new SavingsDialogPageObject({ testContext, type: 'withdraw' }) + await withdrawDialog.selectAssetAction('USDC') + await withdrawDialog.clickMaxAmountAction() + }) + + test('has correct action plan', async () => { + await withdrawDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sDAI' }, + { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sDAI', mode: 'withdraw' }, + ]) + }) + + test('displays transaction overview', async () => { + await withdrawDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '10,000.00 sDAI', + tokenUsdValue: '$11,255.99', + }, + { + tokenAmount: '11,255.99 DAI', + tokenUsdValue: '$11,255.99', + }, + { + tokenAmount: '11,255.99 USDC', + tokenUsdValue: '$11,255.99', + }, + ], + outcome: '11,255.99 USDC', + outcomeUsd: '$11,255.99', + }) + + await withdrawDialog.expectUpgradeSwitchToBeHidden() + }) + + test('executes withdraw', async () => { + await withdrawDialog.actionsContainer.acceptAllActionsAction(2) + + await withdrawDialog.expectSuccessPage() + await withdrawDialog.clickBackToSavingsButton() + + await savingsPage.expectOpportunityStablecoinsAmount('~$11,255.99') + await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '11,255.99') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts index 2dcd77bab..82ea1b76a 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawMaxUSDS.test-e2e.ts @@ -1,142 +1,144 @@ -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' - -// test.describe('Withdraw USDS from sUSDS', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let withdrawDialog: SavingsDialogPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// USDS: 10_000, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickDepositButtonAction('USDS') -// const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) -// await depositDialog.fillAmountAction(10_000) -// await depositDialog.actionsContainer.acceptAllActionsAction(2, fork) -// await depositDialog.clickBackToSavingsButton() - -// await savingsPage.clickWithdrawSUsdsButtonAction() -// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) -// await withdrawDialog.clickMaxAmountAction() -// }) - -// test('uses native sUSDS withdraw', async () => { -// await withdrawDialog.actionsContainer.expectActions([ -// { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, -// ]) -// }) - -// test('displays transaction overview', async () => { -// await withdrawDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '9,999.77 sUSDS', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// outcome: '10,000.00 USDS', -// outcomeUsd: '$10,000.00', -// }) - -// await withdrawDialog.expectUpgradeSwitchToBeHidden() -// }) - -// test('executes withdraw', async () => { -// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(1, fork) - -// await withdrawDialog.expectSuccessPage() -// await withdrawDialog.clickBackToSavingsButton() - -// await savingsPage.expectOpportunityStablecoinsAmount('~$10,000.00') -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000') -// }) -// }) - -// test.describe('Withdraw USDS from sDAI', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let withdrawDialog: SavingsDialogPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sDAI: 10_000, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickWithdrawSDaiButtonAction() -// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) -// await withdrawDialog.selectAssetAction('USDS') -// await withdrawDialog.clickMaxAmountAction() -// }) - -// test('uses migrate sDAI to USDS action', async () => { -// await withdrawDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'sDAI' }, -// { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sDAI', mode: 'withdraw' }, -// ]) -// }) - -// test('displays transaction overview', async () => { -// await withdrawDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '10,000.00 sDAI', -// tokenUsdValue: '$11,085.91', -// }, -// { -// tokenAmount: '11,085.91 DAI', -// tokenUsdValue: '$11,085.91', -// }, -// { -// tokenAmount: '11,085.91 USDS', -// tokenUsdValue: '$11,085.91', -// }, -// ], -// outcome: '11,085.91 USDS', -// outcomeUsd: '$11,085.91', -// }) - -// await withdrawDialog.expectUpgradeSwitchToBeHidden() -// }) - -// test('executes withdraw', async () => { -// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2, fork) - -// await withdrawDialog.expectSuccessPage() -// await withdrawDialog.clickBackToSavingsButton() - -// await savingsPage.expectOpportunityStablecoinsAmount('~$11,085.91') -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '11,085.91') -// }) -// }) +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' + +test.describe('Withdraw USDS from sUSDS', () => { + let savingsPage: SavingsPageObject + let withdrawDialog: SavingsDialogPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDS: 10_000, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickDepositButtonAction('USDS') + const depositDialog = new SavingsDialogPageObject({ testContext, type: 'deposit' }) + await depositDialog.fillAmountAction(10_000) + await depositDialog.actionsContainer.acceptAllActionsAction(2) + await depositDialog.clickBackToSavingsButton() + + await savingsPage.clickWithdrawSUsdsButtonAction() + withdrawDialog = new SavingsDialogPageObject({ testContext, type: 'withdraw' }) + await withdrawDialog.clickMaxAmountAction() + }) + + test('uses native sUSDS withdraw', async () => { + await withdrawDialog.actionsContainer.expectActions([ + { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, + ]) + }) + + test('displays transaction overview', async () => { + await withdrawDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '9,830.34 sUSDS', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + ], + outcome: '10,000.00 USDS', + outcomeUsd: '$10,000.00', + }) + + await withdrawDialog.expectUpgradeSwitchToBeHidden() + }) + + test('executes withdraw', async () => { + await withdrawDialog.actionsContainer.acceptAllActionsAction(1) + + await withdrawDialog.expectSuccessPage() + await withdrawDialog.clickBackToSavingsButton() + + await savingsPage.expectOpportunityStablecoinsAmount('~$10,000.00') + await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000') + }) +}) + +test.describe('Withdraw USDS from sDAI', () => { + let savingsPage: SavingsPageObject + let withdrawDialog: SavingsDialogPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sDAI: 10_000, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickWithdrawSDaiButtonAction() + withdrawDialog = new SavingsDialogPageObject({ testContext, type: 'withdraw' }) + await withdrawDialog.selectAssetAction('USDS') + await withdrawDialog.clickMaxAmountAction() + }) + + test('uses migrate sDAI to USDS action', async () => { + await withdrawDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sDAI' }, + { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sDAI', mode: 'withdraw' }, + ]) + }) + + test('displays transaction overview', async () => { + await withdrawDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '10,000.00 sDAI', + tokenUsdValue: '$11,255.99', + }, + { + tokenAmount: '11,255.99 DAI', + tokenUsdValue: '$11,255.99', + }, + { + tokenAmount: '11,255.99 USDS', + tokenUsdValue: '$11,255.99', + }, + ], + outcome: '11,255.99 USDS', + outcomeUsd: '$11,255.99', + }) + + await withdrawDialog.expectUpgradeSwitchToBeHidden() + }) + + test('executes withdraw', async () => { + await withdrawDialog.actionsContainer.acceptAllActionsAction(2) + + await withdrawDialog.expectSuccessPage() + await withdrawDialog.clickBackToSavingsButton() + + await savingsPage.expectOpportunityStablecoinsAmount('~$11,255.99') + await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '11,255.99') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDC.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDC.test-e2e.ts index f1aad43ef..bf58c3d99 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDC.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDC.test-e2e.ts @@ -1,148 +1,150 @@ -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' - -// test.describe('Withdraw USDC from sUSDS', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let withdrawDialog: SavingsDialogPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// USDC: 10_000, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickDepositButtonAction('USDC') -// const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) -// await depositDialog.fillAmountAction(10_000) -// await depositDialog.actionsContainer.acceptAllActionsAction(2, fork) -// await depositDialog.clickBackToSavingsButton() - -// await savingsPage.clickWithdrawSUsdsButtonAction() -// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) -// await withdrawDialog.selectAssetAction('USDC') -// await withdrawDialog.fillAmountAction(1000) -// }) - -// test('has correct action plan', async () => { -// await withdrawDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'sUSDS' }, -// { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'withdraw' }, -// ]) -// }) - -// test('displays transaction overview', async () => { -// await withdrawDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '999.98 sUSDS', -// tokenUsdValue: '$1,000.00', -// }, -// { -// tokenAmount: '1,000.00 USDS', -// tokenUsdValue: '$1,000.00', -// }, -// { -// tokenAmount: '1,000.00 USDC', -// tokenUsdValue: '$1,000.00', -// }, -// ], -// outcome: '1,000.00 USDC', -// outcomeUsd: '$1,000.00', -// }) - -// await withdrawDialog.expectUpgradeSwitchToBeHidden() -// }) - -// test('executes withdraw', async () => { -// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2, fork) - -// await withdrawDialog.expectSuccessPage() -// await withdrawDialog.clickBackToSavingsButton() - -// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '8,999.79 sUSDS', estimatedUsdsValue: '9,000' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '1,000') -// }) -// }) - -// test.describe('Withdraw USDC from sDAI', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let withdrawDialog: SavingsDialogPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sDAI: 10_000, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickWithdrawSDaiButtonAction() -// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) -// await withdrawDialog.selectAssetAction('USDC') -// await withdrawDialog.fillAmountAction(1000) -// }) - -// test('has correct action plan', async () => { -// await withdrawDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'sDAI' }, -// { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sDAI', mode: 'withdraw' }, -// ]) -// }) - -// test('displays transaction overview', async () => { -// await withdrawDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '902.05 sDAI', -// tokenUsdValue: '$1,000.00', -// }, -// { -// tokenAmount: '1,000.00 DAI', -// tokenUsdValue: '$1,000.00', -// }, -// { -// tokenAmount: '1,000.00 USDC', -// tokenUsdValue: '$1,000.00', -// }, -// ], -// outcome: '1,000.00 USDC', -// outcomeUsd: '$1,000.00', -// }) - -// await withdrawDialog.expectUpgradeSwitchToBeHidden() -// }) - -// test('executes withdraw', async () => { -// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2, fork) - -// await withdrawDialog.expectSuccessPage() -// await withdrawDialog.clickBackToSavingsButton() - -// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '9,097.95 sDAI', estimatedDaiValue: '10,085.90' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '1,000') -// }) -// }) +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' + +test.describe('Withdraw USDC from sUSDS', () => { + let savingsPage: SavingsPageObject + let withdrawDialog: SavingsDialogPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDC: 10_000, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickDepositButtonAction('USDC') + const depositDialog = new SavingsDialogPageObject({ testContext, type: 'deposit' }) + await depositDialog.fillAmountAction(10_000) + await depositDialog.actionsContainer.acceptAllActionsAction(2) + await depositDialog.clickBackToSavingsButton() + + await savingsPage.clickWithdrawSUsdsButtonAction() + withdrawDialog = new SavingsDialogPageObject({ testContext, type: 'withdraw' }) + await withdrawDialog.selectAssetAction('USDC') + await withdrawDialog.fillAmountAction(1000) + }) + + test('has correct action plan', async () => { + await withdrawDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sUSDS' }, + { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sUSDS', mode: 'withdraw' }, + ]) + }) + + test('displays transaction overview', async () => { + await withdrawDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '983.03 sUSDS', + tokenUsdValue: '$1,000.00', + }, + { + tokenAmount: '1,000.00 USDS', + tokenUsdValue: '$1,000.00', + }, + { + tokenAmount: '1,000.00 USDC', + tokenUsdValue: '$1,000.00', + }, + ], + outcome: '1,000.00 USDC', + outcomeUsd: '$1,000.00', + }) + + await withdrawDialog.expectUpgradeSwitchToBeHidden() + }) + + test('executes withdraw', async () => { + await withdrawDialog.actionsContainer.acceptAllActionsAction(2) + + await withdrawDialog.expectSuccessPage() + await withdrawDialog.clickBackToSavingsButton() + + await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '8,847.31 sUSDS', estimatedUsdsValue: '9,000.000373' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '1,000') + }) +}) + +test.describe('Withdraw USDC from sDAI', () => { + let savingsPage: SavingsPageObject + let withdrawDialog: SavingsDialogPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sDAI: 10_000, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickWithdrawSDaiButtonAction() + withdrawDialog = new SavingsDialogPageObject({ testContext, type: 'withdraw' }) + await withdrawDialog.selectAssetAction('USDC') + await withdrawDialog.fillAmountAction(1000) + }) + + test('has correct action plan', async () => { + await withdrawDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sDAI' }, + { type: 'withdrawFromSavings', asset: 'USDC', savingsAsset: 'sDAI', mode: 'withdraw' }, + ]) + }) + + test('displays transaction overview', async () => { + await withdrawDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '888.42 sDAI', + tokenUsdValue: '$1,000.00', + }, + { + tokenAmount: '1,000.00 DAI', + tokenUsdValue: '$1,000.00', + }, + { + tokenAmount: '1,000.00 USDC', + tokenUsdValue: '$1,000.00', + }, + ], + outcome: '1,000.00 USDC', + outcomeUsd: '$1,000.00', + }) + + await withdrawDialog.expectUpgradeSwitchToBeHidden() + }) + + test('executes withdraw', async () => { + await withdrawDialog.actionsContainer.acceptAllActionsAction(2) + + await withdrawDialog.expectSuccessPage() + await withdrawDialog.clickBackToSavingsButton() + + await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '9,111.58 sDAI', estimatedDaiValue: '10,255.992013' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('USDC', '1,000') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDS.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDS.test-e2e.ts index f8fef0553..0382178d0 100644 --- a/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDS.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/mainnet/WithdrawUSDS.test-e2e.ts @@ -1,142 +1,144 @@ -// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' - -// test.describe('Withdraw USDS from sUSDS', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let withdrawDialog: SavingsDialogPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// USDS: 10_000, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickDepositButtonAction('USDS') -// const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' }) -// await depositDialog.fillAmountAction(10_000) -// await depositDialog.actionsContainer.acceptAllActionsAction(2, fork) -// await depositDialog.clickBackToSavingsButton() - -// await savingsPage.clickWithdrawSUsdsButtonAction() -// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) -// await withdrawDialog.fillAmountAction(1000) -// }) - -// test('uses native sUSDS withdraw', async () => { -// await withdrawDialog.actionsContainer.expectActions([ -// { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, -// ]) -// }) - -// test('displays transaction overview', async () => { -// await withdrawDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '999.98 sUSDS', -// tokenUsdValue: '$1,000.00', -// }, -// { -// tokenAmount: '1,000.00 USDS', -// tokenUsdValue: '$1,000.00', -// }, -// ], -// outcome: '1,000.00 USDS', -// outcomeUsd: '$1,000.00', -// }) - -// await withdrawDialog.expectUpgradeSwitchToBeHidden() -// }) - -// test('executes withdraw', async () => { -// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(1, fork) - -// await withdrawDialog.expectSuccessPage() -// await withdrawDialog.clickBackToSavingsButton() - -// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '8,999.79 sUSDS', estimatedUsdsValue: '9,000' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '1,000') -// }) -// }) - -// test.describe('Withdraw USDS from sDAI', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) -// let savingsPage: SavingsPageObject -// let withdrawDialog: SavingsDialogPageObject - -// test.beforeEach(async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { -// ETH: 1, -// sDAI: 10_000, -// }, -// }, -// }) - -// savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickWithdrawSDaiButtonAction() -// withdrawDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) -// await withdrawDialog.selectAssetAction('USDS') -// await withdrawDialog.fillAmountAction(1000) -// }) - -// test('uses migrate sDAI to USDS action', async () => { -// await withdrawDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'sDAI' }, -// { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sDAI', mode: 'withdraw' }, -// ]) -// }) - -// test('displays transaction overview', async () => { -// await withdrawDialog.expectNativeRouteTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '902.05 sDAI', -// tokenUsdValue: '$1,000.00', -// }, -// { -// tokenAmount: '1,000.00 DAI', -// tokenUsdValue: '$1,000.00', -// }, -// { -// tokenAmount: '1,000.00 USDS', -// tokenUsdValue: '$1,000.00', -// }, -// ], -// outcome: '1,000.00 USDS', -// outcomeUsd: '$1,000.00', -// }) - -// await withdrawDialog.expectUpgradeSwitchToBeHidden() -// }) - -// test('executes withdraw', async () => { -// const actionsContainer = new ActionsPageObject(withdrawDialog.locatePanelByHeader('Actions')) -// await actionsContainer.acceptAllActionsAction(2, fork) - -// await withdrawDialog.expectSuccessPage() -// await withdrawDialog.clickBackToSavingsButton() - -// await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '9,097.95 sDAI', estimatedDaiValue: '10,085.90' }) -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '1,000') -// }) -// }) +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject' + +test.describe('Withdraw USDS from sUSDS', () => { + let savingsPage: SavingsPageObject + let withdrawDialog: SavingsDialogPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + USDS: 10_000, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickDepositButtonAction('USDS') + const depositDialog = new SavingsDialogPageObject({ testContext, type: 'deposit' }) + await depositDialog.fillAmountAction(10_000) + await depositDialog.actionsContainer.acceptAllActionsAction(2) + await depositDialog.clickBackToSavingsButton() + + await savingsPage.clickWithdrawSUsdsButtonAction() + withdrawDialog = new SavingsDialogPageObject({ testContext, type: 'withdraw' }) + await withdrawDialog.fillAmountAction(1000) + }) + + test('uses native sUSDS withdraw', async () => { + await withdrawDialog.actionsContainer.expectActions([ + { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sUSDS', mode: 'withdraw' }, + ]) + }) + + test('displays transaction overview', async () => { + await withdrawDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '983.03 sUSDS', + tokenUsdValue: '$1,000.00', + }, + { + tokenAmount: '1,000.00 USDS', + tokenUsdValue: '$1,000.00', + }, + ], + outcome: '1,000.00 USDS', + outcomeUsd: '$1,000.00', + }) + + await withdrawDialog.expectUpgradeSwitchToBeHidden() + }) + + test('executes withdraw', async () => { + await withdrawDialog.actionsContainer.acceptAllActionsAction(1) + + await withdrawDialog.expectSuccessPage() + await withdrawDialog.clickBackToSavingsButton() + + await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '8,847.31 sUSDS', estimatedUsdsValue: '9,000.000187' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '1,000') + }) +}) + +test.describe('Withdraw USDS from sDAI', () => { + let savingsPage: SavingsPageObject + let withdrawDialog: SavingsDialogPageObject + + test.beforeEach(async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { + ETH: 1, + sDAI: 10_000, + }, + }, + }) + + savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickWithdrawSDaiButtonAction() + withdrawDialog = new SavingsDialogPageObject({ testContext, type: 'withdraw' }) + await withdrawDialog.selectAssetAction('USDS') + await withdrawDialog.fillAmountAction(1000) + }) + + test('uses migrate sDAI to USDS action', async () => { + await withdrawDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sDAI' }, + { type: 'withdrawFromSavings', asset: 'USDS', savingsAsset: 'sDAI', mode: 'withdraw' }, + ]) + }) + + test('displays transaction overview', async () => { + await withdrawDialog.expectNativeRouteTransactionOverview({ + routeItems: [ + { + tokenAmount: '888.42 sDAI', + tokenUsdValue: '$1,000.00', + }, + { + tokenAmount: '1,000.00 DAI', + tokenUsdValue: '$1,000.00', + }, + { + tokenAmount: '1,000.00 USDS', + tokenUsdValue: '$1,000.00', + }, + ], + outcome: '1,000.00 USDS', + outcomeUsd: '$1,000.00', + }) + + await withdrawDialog.expectUpgradeSwitchToBeHidden() + }) + + test('executes withdraw', async () => { + await withdrawDialog.actionsContainer.acceptAllActionsAction(2) + + await withdrawDialog.expectSuccessPage() + await withdrawDialog.clickBackToSavingsButton() + + await savingsPage.expectSavingsDaiBalance({ sdaiBalance: '9,111.58 sDAI', estimatedDaiValue: '10,255.992013' }) + await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '1,000') + }) +}) diff --git a/packages/app/src/pages/Savings.PageObject.ts b/packages/app/src/pages/Savings.PageObject.ts index aad8491bf..5f461cfb7 100644 --- a/packages/app/src/pages/Savings.PageObject.ts +++ b/packages/app/src/pages/Savings.PageObject.ts @@ -158,7 +158,16 @@ export class SavingsPageObject extends BasePageObject { async expectStablecoinsInWalletAssetBalance(assetName: string, value: string): Promise { const panel = this.locateStablecoinsInWalletPanel() - const row = panel.getByRole('row').filter({ has: this.page.getByRole('cell', { name: assetName, exact: true }) }) + const row = (() => { + if (assetName === 'DAI' && value !== '-') { + return panel + .getByRole('row') + .filter({ has: this.page.getByTestId(testIds.savings.stablecoinsInWallet.upgradeDaiToUsdsCell) }) + } + + return panel.getByRole('row').filter({ has: this.page.getByRole('cell', { name: assetName, exact: true }) }) + })() + await expect(row.getByRole('cell', { name: value })).toBeVisible() } From b30f98d1d4df6735966a63dfc6b9e3240ea2a9ed Mon Sep 17 00:00:00 2001 From: yivlad Date: Sun, 22 Dec 2024 21:52:10 +0100 Subject: [PATCH 29/29] Fix cleanup on exit --- packages/app/src/test/e2e/getTestnetContext.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/app/src/test/e2e/getTestnetContext.ts b/packages/app/src/test/e2e/getTestnetContext.ts index 1648e61e8..1120bbc00 100644 --- a/packages/app/src/test/e2e/getTestnetContext.ts +++ b/packages/app/src/test/e2e/getTestnetContext.ts @@ -10,13 +10,15 @@ interface TestnetContext { const testnetCache = new Map() for (const eventType of ['exit', 'SIGINT', 'SIGUSR1', 'SIGUSR2', 'uncaughtException', 'SIGTERM']) { - process.on(eventType, () => { + process.on(eventType, async () => { const keys = Array.from(testnetCache.keys()) - for (const key of keys) { - const context = testnetCache.get(key)! - testnetCache.delete(key) - return context.cleanup() - } + return Promise.all( + keys.map(async (key) => { + const context = testnetCache.get(key)! + testnetCache.delete(key) + return context.cleanup() + }), + ) }) }