From 63392cf16c7f84b05a165bf953f4f38dfd73d092 Mon Sep 17 00:00:00 2001 From: Nikita Date: Tue, 5 Sep 2023 16:37:10 +0100 Subject: [PATCH] feat: test coverage for withdraw and switch functionality (#1774) --- .../0-assets/dai.ethereum-v3.cy.ts | 18 +++- .../0-assets/dai.arbitrum-v3.cy.ts | 11 ++- .../0-assets/dai.avalanche-v3.cy.ts | 11 ++- .../0-assets/dai.polygon-v3.cy.ts | 11 ++- .../0-assets/dai.optimism-v3.cy.ts | 11 ++- cypress/support/steps/main.steps.ts | 93 +++++++++++++++++++ 6 files changed, 149 insertions(+), 6 deletions(-) diff --git a/cypress/e2e/1-v3-markets/0-ethereum-v3-market/0-assets/dai.ethereum-v3.cy.ts b/cypress/e2e/1-v3-markets/0-ethereum-v3-market/0-assets/dai.ethereum-v3.cy.ts index 9acb6c78d7..81842c1dc5 100644 --- a/cypress/e2e/1-v3-markets/0-ethereum-v3-market/0-assets/dai.ethereum-v3.cy.ts +++ b/cypress/e2e/1-v3-markets/0-ethereum-v3-market/0-assets/dai.ethereum-v3.cy.ts @@ -2,7 +2,13 @@ import assets from '../../../../fixtures/assets.json'; import constants from '../../../../fixtures/constans.json'; import { skipState } from '../../../../support/steps/common'; import { configEnvWithTenderlyAEthereumV3Fork } from '../../../../support/steps/configuration.steps'; -import { borrow, repay, supply, withdraw } from '../../../../support/steps/main.steps'; +import { + borrow, + repay, + supply, + withdraw, + withdrawAndSwitch, +} from '../../../../support/steps/main.steps'; import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps'; const testData = { @@ -55,13 +61,20 @@ const testData = { amount: 1, hasApproval: true, }, + withdrawAndSwitch: { + fromAsset: assets.ethereumV3Market.DAI, + toAsset: assets.ethereumV3Market.USDC, + isCollateralFromAsset: true, + amount: 5, + hasApproval: false, + }, }, verifications: { finalDashboard: [ { type: constants.dashboardTypes.deposit, assetName: assets.ethereumV3Market.DAI.shortName, - amount: 7.0, + amount: 2.0, collateralType: constants.collateralType.isCollateral, isCollateral: true, }, @@ -87,6 +100,7 @@ describe('DAI INTEGRATION SPEC, ETHEREUM V3 MARKET', () => { testData.testCases.repay.forEach((repayCase) => { repay(repayCase, skipTestState, false); }); + withdrawAndSwitch(testData.testCases.withdrawAndSwitch, skipTestState, false); withdraw(testData.testCases.withdraw, skipTestState, false); dashboardAssetValuesVerification(testData.verifications.finalDashboard, skipTestState); }); diff --git a/cypress/e2e/1-v3-markets/1-arbitrum-v3-market/0-assets/dai.arbitrum-v3.cy.ts b/cypress/e2e/1-v3-markets/1-arbitrum-v3-market/0-assets/dai.arbitrum-v3.cy.ts index c7087a3aed..acd9b0dba3 100644 --- a/cypress/e2e/1-v3-markets/1-arbitrum-v3-market/0-assets/dai.arbitrum-v3.cy.ts +++ b/cypress/e2e/1-v3-markets/1-arbitrum-v3-market/0-assets/dai.arbitrum-v3.cy.ts @@ -8,6 +8,7 @@ import { repay, supply, withdraw, + withdrawAndSwitch, } from '../../../../support/steps/main.steps'; import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps'; @@ -74,13 +75,20 @@ const testData = { amount: 1, hasApproval: true, }, + withdrawAndSwitch: { + fromAsset: assets.arbitrumMarket.DAI, + toAsset: assets.arbitrumMarket.USDC, + isCollateralFromAsset: true, + amount: 5, + hasApproval: false, + }, }, verifications: { finalDashboard: [ { type: constants.dashboardTypes.deposit, assetName: assets.arbitrumMarket.DAI.shortName, - amount: 7.0, + amount: 2.0, collateralType: constants.collateralType.isCollateral, isCollateral: true, }, @@ -109,6 +117,7 @@ describe('DAI INTEGRATION SPEC, ARBITRUM V3 MARKET', () => { testData.testCases.repay.forEach((repayCase) => { repay(repayCase, skipTestState, false); }); + withdrawAndSwitch(testData.testCases.withdrawAndSwitch, skipTestState, false); withdraw(testData.testCases.withdraw, skipTestState, false); dashboardAssetValuesVerification(testData.verifications.finalDashboard, skipTestState); }); diff --git a/cypress/e2e/1-v3-markets/2-avalanche-v3-market/0-assets/dai.avalanche-v3.cy.ts b/cypress/e2e/1-v3-markets/2-avalanche-v3-market/0-assets/dai.avalanche-v3.cy.ts index a474a50bb8..12c0be243a 100644 --- a/cypress/e2e/1-v3-markets/2-avalanche-v3-market/0-assets/dai.avalanche-v3.cy.ts +++ b/cypress/e2e/1-v3-markets/2-avalanche-v3-market/0-assets/dai.avalanche-v3.cy.ts @@ -8,6 +8,7 @@ import { repay, supply, withdraw, + withdrawAndSwitch, } from '../../../../support/steps/main.steps'; import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps'; @@ -74,13 +75,20 @@ const testData = { amount: 1, hasApproval: true, }, + withdrawAndSwitch: { + fromAsset: assets.avalancheV3Market.DAI, + toAsset: assets.avalancheV3Market.USDC, + isCollateralFromAsset: true, + amount: 5, + hasApproval: false, + }, }, verifications: { finalDashboard: [ { type: constants.dashboardTypes.deposit, assetName: assets.avalancheV3Market.DAI.shortName, - amount: 7.0, + amount: 2.0, collateralType: constants.collateralType.isCollateral, isCollateral: true, }, @@ -109,6 +117,7 @@ describe('DAI INTEGRATION SPEC, AVALANCHE V3 MARKET', () => { testData.testCases.repay.forEach((repayCase) => { repay(repayCase, skipTestState, false); }); + withdrawAndSwitch(testData.testCases.withdrawAndSwitch, skipTestState, false); withdraw(testData.testCases.withdraw, skipTestState, false); dashboardAssetValuesVerification(testData.verifications.finalDashboard, skipTestState); }); diff --git a/cypress/e2e/1-v3-markets/3-polygon-v3-market/0-assets/dai.polygon-v3.cy.ts b/cypress/e2e/1-v3-markets/3-polygon-v3-market/0-assets/dai.polygon-v3.cy.ts index 82cebbcce3..ccabd56611 100644 --- a/cypress/e2e/1-v3-markets/3-polygon-v3-market/0-assets/dai.polygon-v3.cy.ts +++ b/cypress/e2e/1-v3-markets/3-polygon-v3-market/0-assets/dai.polygon-v3.cy.ts @@ -8,6 +8,7 @@ import { repay, supply, withdraw, + withdrawAndSwitch, } from '../../../../support/steps/main.steps'; import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps'; @@ -74,13 +75,20 @@ const testData = { amount: 1, hasApproval: true, }, + withdrawAndSwitch: { + fromAsset: assets.polygonV3Market.DAI, + toAsset: assets.polygonV3Market.USDC, + isCollateralFromAsset: true, + amount: 5, + hasApproval: false, + }, }, verifications: { finalDashboard: [ { type: constants.dashboardTypes.deposit, assetName: assets.polygonV3Market.DAI.shortName, - amount: 7.0, + amount: 2.0, collateralType: constants.collateralType.isCollateral, isCollateral: true, }, @@ -109,6 +117,7 @@ describe('DAI INTEGRATION SPEC, POLYGON V3 MARKET', () => { testData.testCases.repay.forEach((repayCase) => { repay(repayCase, skipTestState, false); }); + withdrawAndSwitch(testData.testCases.withdrawAndSwitch, skipTestState, false); withdraw(testData.testCases.withdraw, skipTestState, false); dashboardAssetValuesVerification(testData.verifications.finalDashboard, skipTestState); }); diff --git a/cypress/e2e/1-v3-markets/4-optimism-v3-market/0-assets/dai.optimism-v3.cy.ts b/cypress/e2e/1-v3-markets/4-optimism-v3-market/0-assets/dai.optimism-v3.cy.ts index 01081e32bc..af3b573d89 100644 --- a/cypress/e2e/1-v3-markets/4-optimism-v3-market/0-assets/dai.optimism-v3.cy.ts +++ b/cypress/e2e/1-v3-markets/4-optimism-v3-market/0-assets/dai.optimism-v3.cy.ts @@ -8,6 +8,7 @@ import { repay, supply, withdraw, + withdrawAndSwitch, } from '../../../../support/steps/main.steps'; import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps'; @@ -74,13 +75,20 @@ const testData = { amount: 1, hasApproval: true, }, + withdrawAndSwitch: { + fromAsset: assets.optimismMarket.DAI, + toAsset: assets.optimismMarket.USDC, + isCollateralFromAsset: true, + amount: 5, + hasApproval: false, + }, }, verifications: { finalDashboard: [ { type: constants.dashboardTypes.deposit, assetName: assets.polygonV3Market.DAI.shortName, - amount: 7.0, + amount: 2.0, collateralType: constants.collateralType.isCollateral, isCollateral: true, }, @@ -109,6 +117,7 @@ describe('DAI INTEGRATION SPEC, OPTIMISM V3 MARKET', () => { testData.testCases.repay.forEach((repayCase) => { repay(repayCase, skipTestState, false); }); + withdrawAndSwitch(testData.testCases.withdrawAndSwitch, skipTestState, false); withdraw(testData.testCases.withdraw, skipTestState, false); dashboardAssetValuesVerification(testData.verifications.finalDashboard, skipTestState); }); diff --git a/cypress/support/steps/main.steps.ts b/cypress/support/steps/main.steps.ts index b5fa850afc..4e7e3a3d0c 100644 --- a/cypress/support/steps/main.steps.ts +++ b/cypress/support/steps/main.steps.ts @@ -336,6 +336,99 @@ export const withdraw = ( }); }; +/** + * This full step to swap assets from Dashboard view + * @example + *``` + * // Withdraw and switch from ETH to USDC + * // apyType options: Variable, Stable + * withdrawAndSwitch({ + * fromAsset:{shortName:'ETH', fullName:'Ethereum'}, + * toAsset:{shortName:'USDC', fullName:'USDC'}, + * isCollateralFromAsset: false, + * amount: 1.137, + * hasApproval: true + * }, + * skipTestState, + * false + * ) + * ``` + */ +export const withdrawAndSwitch = ( + { + fromAsset, + toAsset, + isBorrowed = false, + isVariableBorrowedAPY = true, + isCollateralFromAsset, + changeApprove = false, + amount, + hasApproval = true, + isMaxAmount = false, + }: { + fromAsset: { shortName: string; fullName: string }; + toAsset: { shortName: string; fullName: string }; + isBorrowed?: boolean; + isVariableBorrowedAPY?: boolean; + isCollateralFromAsset?: boolean; + changeApprove?: boolean; + amount: number; + hasApproval: boolean; + isMaxAmount?: boolean; + }, + skip: SkipType, + updateSkipStatus = false +) => { + const _shortNameFrom = fromAsset.shortName; + const _shortNameTo = toAsset.shortName; + const _actionName = 'Switch'; + const _switchType = isBorrowed ? 'Borrowed' : 'Supplied'; + const _apySwitchType = isVariableBorrowedAPY ? 'Variable' : 'Stable'; + + describe(`Withdraw and Switch for ${_switchType} ${_apySwitchType} ${amount} ${_shortNameFrom} to ${_shortNameTo}`, () => { + skipSetup({ skip, updateSkipStatus }); + it(`Open Withdraw and Switch modal for ${_shortNameFrom}`, () => { + cy.doSwitchToDashboardSupplyView(); + cy.getDashBoardSuppliedRow(_shortNameFrom, isCollateralFromAsset) + .find(`button:contains("Withdraw")`) + .click(); + + cy.get(`[data-cy=Modal] h2:contains("Withdraw ${_shortNameFrom}")`).should('be.visible'); + + cy.get('[data-cy=Modal] button') + .contains('Withdraw & Switch') + .click({ force: true }) + .should('not.be.disabled'); + }); + it(`Choose Switching ${_switchType} options: swap to asset`, () => { + cy.get('[data-cy=Modal]').as('Modal'); + cy.get('@Modal').find('[data-cy=assetSelect]').click(); + cy.get(`[data-cy="assetsSelectOption_${_shortNameTo.toUpperCase()}"]`, { timeout: 10000 }) + .scrollIntoView() + .should('be.visible') + .click({ force: true }); + cy.get(`[data-cy="assetsSelectedOption_${_shortNameTo.toUpperCase()}"]`, { + timeout: 10000, + }).should('be.visible', { timeout: 10000 }); + }); + it(`Make approve for ${isMaxAmount ? 'MAX' : amount} amount`, () => { + cy.setAmount(amount, isMaxAmount); + cy.get(`[data-cy="slippageButton_0.1"]`).click(); + cy.get('li[role="menuitem"][value="1"]').click(); + if (!changeApprove) { + cy.get('[data-cy=Modal]') + .find('[data-cy=approveButtonChange]') + .click() + .get('[data-cy=approveOption_Transaction]') + .click(); + } + cy.wait(2000); + cy.doConfirm(hasApproval, _actionName); + }); + doCloseModal(); + }); +}; + /** * This full step to change borrow apy from Dashboard view * @example