Skip to content

Commit

Permalink
Rewrite easy borrow e2e tests (#499)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
oskarvu authored Dec 18, 2024
1 parent 6b47fca commit df5350c
Show file tree
Hide file tree
Showing 48 changed files with 906 additions and 985 deletions.
50 changes: 19 additions & 31 deletions packages/app/src/config/chain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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<SupportedChainId, ChainConfigEntry> = {
[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',
Expand Down Expand Up @@ -89,25 +85,21 @@ const chainConfig: Record<SupportedChainId, ChainConfigEntry> = {
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'),
Expand Down Expand Up @@ -165,12 +157,8 @@ const chainConfig: Record<SupportedChainId, ChainConfigEntry> = {
},
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/`,
},
Expand Down
4 changes: 4 additions & 0 deletions packages/app/src/config/feature-flags/appConfig.default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export function getDefaultAppConfig(): AppConfig {
address: '0xdC035D45d973E3EC169d2276DDab16f1e407384F',
decimals: 18,
},
cbBTC: {
address: '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf',
decimals: 8,
},
},
},
},
Expand Down
1 change: 0 additions & 1 deletion packages/app/src/config/wagmi/config.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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<any>) {
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<void> {
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<void>
// }): Promise<void> {
// 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<void> {
// 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<void> {
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
}
14 changes: 1 addition & 13 deletions packages/app/src/features/dialogs/common/Dialog.PageObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>
Expand Down Expand Up @@ -57,22 +55,12 @@ export class DialogPageObject extends BasePageObject {
// #region assertions
async expectSuccessPage({
tokenWithValue,
testnetClient,
assetWorthOverrides,
}: {
tokenWithValue: TestTokenWithValue[]
testnetClient: TestnetClient
assetWorthOverrides?: Record<string, number>
}): Promise<void> {
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<void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// 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'
// 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 })
// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true })
// let savingsPage: SavingsPageObject
// let convertStablesDialog: ConvertStablesDialogPageObject

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// 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'
// 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 })
// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true })
// let savingsPage: SavingsPageObject
// let convertStablesDialog: ConvertStablesDialogPageObject

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// 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'
// 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 })
// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true })
// let savingsPage: SavingsPageObject
// let convertStablesDialog: ConvertStablesDialogPageObject

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// 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'
// 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 })
// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true })
// let savingsPage: SavingsPageObject
// let convertStablesDialog: ConvertStablesDialogPageObject

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// 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'
// 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 })
// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true })
// let savingsPage: SavingsPageObject
// let convertStablesDialog: ConvertStablesDialogPageObject

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// 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'
// 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 })
// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true })
// let savingsPage: SavingsPageObject
// let convertStablesDialog: ConvertStablesDialogPageObject

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// 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'
// 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 })
// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true })
// let savingsPage: SavingsPageObject
// let convertStablesDialog: ConvertStablesDialogPageObject

Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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,
// })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// 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'
// 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 })
// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true })
// let savingsPage: SavingsPageObject
// let depositDialog: SavingsDialogPageObject

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// 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'
// 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 })
// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true })
// let savingsPage: SavingsPageObject
// let depositDialog: SavingsDialogPageObject

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// 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'
// 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 })
// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true })
// let savingsPage: SavingsPageObject
// let depositDialog: SavingsDialogPageObject

Expand Down
Loading

0 comments on commit df5350c

Please sign in to comment.