Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add savings USDC deposit and withdraw tests #102

Merged
merged 7 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/app/.env.playwright
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ VITE_FEATURE_CONFIGURABLE_SLIPPAGE=1

# development
VITE_DEV_DAI_NATIVE_ROUTES=1
VITE_DEV_USDC_NATIVE_ROUTES=0
VITE_DEV_USDC_NATIVE_ROUTES=1

VITE_WALLET_CONNECT_ID='bd1843f2419f5d4c758366c55f9a556c'
VITE_BLOCK_ANALITICA_API_URL=https://spark-api.blockanalitica.com/api
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,7 @@ export class SavingsDialogPageObject extends DialogPageObject {
await expect(outcome).toContainText(transactionOverview.outcome)
}

async expectToUseNativeSDaiAction({
asset,
amount,
}: {
asset: string
amount: number
}): Promise<void> {
async expectToUseNativeSDaiAction({ asset }: { asset: string }): Promise<void> {
const actionsContainer = new ActionsPageObject(this.locatePanelByHeader('Actions'))
if (this.type === 'deposit') {
await actionsContainer.expectActions([
Expand All @@ -92,6 +86,21 @@ export class SavingsDialogPageObject extends DialogPageObject {
}
}

async expectToUsePSMActionsAction({ asset }: { asset: string }): Promise<void> {
const actionsContainer = new ActionsPageObject(this.locatePanelByHeader('Actions'))
if (this.type === 'deposit') {
await actionsContainer.expectActions([
{ type: 'approve', asset },
{ type: 'nativeSDaiDeposit', asset },
])
} else {
await actionsContainer.expectActions([
{ type: 'approve', asset: 'sDAI' },
{ type: 'nativeSDaiWithdraw', asset },
])
}
}

async expectToUseLifiSwap(lifiSwapParams: LifiSwapParams): Promise<void> {
const exchangeRow = this.locatePanelByHeader('Actions').getByTestId(
testIds.actions.flavours.exchangeActionRow.wrapper,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject'
import { SavingsPageObject } from '@/pages/Savings.PageObject'
import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants'
import { LIFI_TEST_USER_PRIVATE_KEY, overrideLiFiRouteWithHAR } from '@/test/e2e/lifi'
import { setup } from '@/test/e2e/setup'
import { setupFork } from '@/test/e2e/setupFork'
Expand All @@ -12,37 +11,6 @@ test.describe('Savings deposit dialog', () => {
// The tests here are not independent.
// My guess is that reverting to snapshots in tenderly does not work properly - but for now couldn't debug that.
// For now tests use different forks.
test.describe('DAI', () => {
const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id })

test('wraps DAI', async ({ page }) => {
await setup(page, fork, {
initialPage: 'savings',
account: {
type: 'connected',
assetBalances: {
ETH: 1,
DAI: 100,
},
privateKey: LIFI_TEST_USER_PRIVATE_KEY,
},
})

const savingsPage = new SavingsPageObject(page)

await savingsPage.clickStartSavingButtonAction()

const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' })
await depositDialog.fillAmountAction(100)

const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions'))
await actionsContainer.acceptAllActionsAction(2)
await depositDialog.clickBackToSavingsButton()

await savingsPage.expectCurrentWorth('100')
})
})

test.describe('xDAI', () => {
// Block number has to be as close as possible to the block number when query was executed
const blockNumber = 34227645n
Expand Down Expand Up @@ -79,42 +47,6 @@ test.describe('Savings deposit dialog', () => {
})
})

test.describe('USDC', () => {
const blockNumber = 19990683n
const fork = setupFork({ blockNumber, chainId: mainnet.id })

test('wraps USDC', async ({ page }) => {
await setup(page, fork, {
initialPage: 'savings',
account: {
type: 'connected',
assetBalances: {
ETH: 1,
USDC: 100,
},
privateKey: LIFI_TEST_USER_PRIVATE_KEY,
},
})
await overrideLiFiRouteWithHAR({
page,
key: '100-usdc-to-sdai',
})

const savingsPage = new SavingsPageObject(page)

await savingsPage.clickDepositButtonAction('USDC')

const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' })
await depositDialog.fillAmountAction(100)

const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions'))
await actionsContainer.acceptAllActionsAction(2)
await depositDialog.clickBackToSavingsButton()

await savingsPage.expectCurrentWorth('99.85')
})
})

test.describe('USDC on Gnosis', () => {
// Block number has to be as close as possible to the block number when query was executed
const blockNumber = 34227645n
Expand Down Expand Up @@ -153,7 +85,7 @@ test.describe('Savings deposit dialog', () => {
})

test.describe('Slippage', () => {
const blockNumber = 19519583n
const blockNumber = 20089938n
const fork = setupFork({ blockNumber, chainId: mainnet.id })

test('default', async ({ page }) => {
Expand All @@ -163,7 +95,7 @@ test.describe('Savings deposit dialog', () => {
type: 'connected',
assetBalances: {
ETH: 1,
USDC: 100,
USDT: 100,
},
privateKey: LIFI_TEST_USER_PRIVATE_KEY,
},
Expand All @@ -172,12 +104,12 @@ test.describe('Savings deposit dialog', () => {

await overrideLiFiRouteWithHAR({
page,
key: '100-usdc-to-sdai-slippage-0.001',
key: '100-usdt-to-sdai-slippage-0.001',
})

const savingsPage = new SavingsPageObject(page)

await savingsPage.clickDepositButtonAction('USDC')
await savingsPage.clickDepositButtonAction('USDT')

const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' })
const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions'))
Expand All @@ -195,7 +127,7 @@ test.describe('Savings deposit dialog', () => {
type: 'connected',
assetBalances: {
ETH: 1,
USDC: 100,
USDT: 100,
},
privateKey: LIFI_TEST_USER_PRIVATE_KEY,
},
Expand All @@ -204,12 +136,12 @@ test.describe('Savings deposit dialog', () => {

await overrideLiFiRouteWithHAR({
page,
key: '100-usdc-to-sdai-slippage-0.005',
key: '100-usdt-to-sdai-slippage-0.005',
})

const savingsPage = new SavingsPageObject(page)

await savingsPage.clickDepositButtonAction('USDC')
await savingsPage.clickDepositButtonAction('USDT')

const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' })
const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions'))
Expand All @@ -227,7 +159,7 @@ test.describe('Savings deposit dialog', () => {
type: 'connected',
assetBalances: {
ETH: 1,
USDC: 100,
USDT: 100,
},
privateKey: LIFI_TEST_USER_PRIVATE_KEY,
},
Expand All @@ -236,12 +168,12 @@ test.describe('Savings deposit dialog', () => {

await overrideLiFiRouteWithHAR({
page,
key: '100-usdc-to-sdai-slippage-0.007',
key: '100-usdt-to-sdai-slippage-0.007',
})

const savingsPage = new SavingsPageObject(page)

await savingsPage.clickDepositButtonAction('USDC')
await savingsPage.clickDepositButtonAction('USDT')

const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' })
const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions'))
Expand All @@ -260,7 +192,7 @@ test.describe('Savings deposit dialog', () => {
type: 'connected',
assetBalances: {
ETH: 1,
USDC: 100,
USDT: 100,
},
privateKey: LIFI_TEST_USER_PRIVATE_KEY,
},
Expand All @@ -270,12 +202,12 @@ test.describe('Savings deposit dialog', () => {

await overrideLiFiRouteWithHAR({
page,
key: '100-usdc-to-sdai-slippage-0.001',
key: '100-usdt-to-sdai-slippage-0.001',
})

const savingsPage = new SavingsPageObject(page)

await savingsPage.clickDepositButtonAction('USDC')
await savingsPage.clickDepositButtonAction('USDT')

const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' })
const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions'))
Expand All @@ -299,7 +231,7 @@ test.describe('Savings deposit dialog', () => {
type: 'connected',
assetBalances: {
ETH: 1,
USDC: 100,
USDT: 100,
},
privateKey: LIFI_TEST_USER_PRIVATE_KEY,
},
Expand All @@ -309,12 +241,12 @@ test.describe('Savings deposit dialog', () => {

await overrideLiFiRouteWithHAR({
page,
key: '100-usdc-to-sdai-slippage-0.001',
key: '100-usdt-to-sdai-slippage-0.001',
})

const savingsPage = new SavingsPageObject(page)

await savingsPage.clickDepositButtonAction('USDC')
await savingsPage.clickDepositButtonAction('USDT')

const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' })
const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions'))
Expand All @@ -338,7 +270,7 @@ test.describe('Savings deposit dialog', () => {
type: 'connected',
assetBalances: {
ETH: 1,
USDC: 100,
USDT: 100,
},
privateKey: LIFI_TEST_USER_PRIVATE_KEY,
},
Expand All @@ -347,12 +279,12 @@ test.describe('Savings deposit dialog', () => {

await overrideLiFiRouteWithHAR({
page,
key: '100-usdc-to-sdai-slippage-0.001',
key: '100-usdt-to-sdai-slippage-0.001',
})

const savingsPage = new SavingsPageObject(page)

await savingsPage.clickDepositButtonAction('USDC')
await savingsPage.clickDepositButtonAction('USDT')

const depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' })
const actionsContainer = new ActionsPageObject(depositDialog.locatePanelByHeader('Actions'))
Expand Down Expand Up @@ -482,7 +414,7 @@ test.describe('Savings deposit dialog', () => {
await actionsContainer.expectNextActionEnabled()
await actionsContainer.expectActions([
{ type: 'approve', asset: 'USDC' },
{ type: 'exchange', inputAsset: 'USDC', outputAsset: 'sDAI' },
{ type: 'nativeSDaiDeposit', asset: 'USDC' },
])

await depositDialog.selectAssetAction('USDT')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test.describe('Deposit DAI on Mainnet', () => {
})

test('uses native sDai deposit', async () => {
await depositDialog.expectToUseNativeSDaiAction({ asset: 'DAI', amount: 10_000 })
await depositDialog.expectToUseNativeSDaiAction({ asset: 'DAI' })
})

test('displays transaction overview', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject'
import { SavingsPageObject } from '@/pages/Savings.PageObject'
import { PSM_ACTIONS_DEPLOYED, PSM_ACTIONS_DEPLOYED_DATE } from '@/test/e2e/constants'
import { setup } from '@/test/e2e/setup'
import { setupFork } from '@/test/e2e/setupFork'
import { test } from '@playwright/test'
import { mainnet } from 'viem/chains'
import { SavingsDialogPageObject } from '../../common/e2e/SavingsDialog.PageObject'

test.describe('Deposit USDC on Mainnet', () => {
const fork = setupFork({
blockNumber: PSM_ACTIONS_DEPLOYED,
simulationDateOverride: PSM_ACTIONS_DEPLOYED_DATE,
chainId: mainnet.id,
})
let savingsPage: SavingsPageObject
let depositDialog: SavingsDialogPageObject

test.beforeEach(async ({ page }) => {
await setup(page, fork, {
initialPage: 'savings',
account: {
type: 'connected',
assetBalances: {
ETH: 1,
USDC: 10_000,
},
},
})

savingsPage = new SavingsPageObject(page)
await savingsPage.clickDepositButtonAction('USDC')

depositDialog = new SavingsDialogPageObject({ page, type: 'deposit' })
await depositDialog.fillAmountAction(10_000)
})

test('uses PSM actions native deposit', async () => {
await depositDialog.expectToUsePSMActionsAction({ asset: 'USDC' })
})

test('displays transaction overview', async () => {
await depositDialog.expectNativeRouteTransactionOverview({
apy: {
value: '8.00%',
description: '~800.00 DAI per year',
},
routeItems: [
{
tokenAmount: '10,000.00 USDC',
tokenUsdValue: '$10,000.00',
},
{
tokenAmount: '10,000.00 DAI',
tokenUsdValue: '$10,000.00',
},
{
tokenAmount: '9,196.30 sDAI',
tokenUsdValue: '$10,000.00',
},
],
outcome: '9,196.30 sDAI worth $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.expectSavingsBalance({ sDaiBalance: '9,196.30 sDAI', estimatedDaiValue: '10,000' })
await savingsPage.expectCashInWalletAssetBalance('USDC', '-')
})
})
Loading
Loading