From 3ad51b9065663fd3408bb2d553f8220c94d5eac0 Mon Sep 17 00:00:00 2001 From: oskarvu Date: Thu, 19 Dec 2024 17:24:09 +0700 Subject: [PATCH 1/5] Rewrite stake usds tests --- .../stake/e2e/mainnet/StakeUSDS.test-e2e.ts | 329 +++++++++--------- 1 file changed, 167 insertions(+), 162 deletions(-) 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 791922867e6cfcde4b55a33d4cffa3fb9a55d7dc Mon Sep 17 00:00:00 2001 From: oskarvu Date: Thu, 19 Dec 2024 17:29:25 +0700 Subject: [PATCH 2/5] Add stake sdai test --- .../stake/e2e/mainnet/StakeSDAI.test-e2e.ts | 164 +++++++++--------- 1 file changed, 83 insertions(+), 81 deletions(-) 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' }) + }) +}) From 1d418d9997ce10f4f5bbff47db8f886582d457bc Mon Sep 17 00:00:00 2001 From: oskarvu Date: Thu, 19 Dec 2024 17:44:42 +0700 Subject: [PATCH 3/5] Add stake susds tests --- .../stake/e2e/mainnet/StakeSUSDS.test-e2e.ts | 182 +++++++++--------- 1 file changed, 92 insertions(+), 90 deletions(-) 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' }) + }) +}) From 24c11a5b192b5c16152dc74c5c6d57340f891d83 Mon Sep 17 00:00:00 2001 From: oskarvu Date: Thu, 19 Dec 2024 17:50:55 +0700 Subject: [PATCH 4/5] Add stake dai tests --- .../stake/e2e/mainnet/StakeDAI.test-e2e.ts | 160 +++++++++--------- 1 file changed, 81 insertions(+), 79 deletions(-) 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' }) + }) +}) From bd833221a6517fe94191b62e8bc3b8eb5d22a4b6 Mon Sep 17 00:00:00 2001 From: oskarvu Date: Thu, 19 Dec 2024 17:54:06 +0700 Subject: [PATCH 5/5] Add stake usdc tests --- .../common/e2e/SavingsDialog.PageObject.ts | 314 +++++++++--------- .../stake/e2e/mainnet/StakeUSDC.test-e2e.ts | 160 ++++----- 2 files changed, 244 insertions(+), 230 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/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' }) + }) +})