Skip to content

Commit

Permalink
feat: test coverage for withdraw and switch functionality (#1774)
Browse files Browse the repository at this point in the history
  • Loading branch information
MareskoY authored Sep 5, 2023
1 parent db51b6e commit 63392cf
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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,
},
Expand All @@ -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);
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
repay,
supply,
withdraw,
withdrawAndSwitch,
} from '../../../../support/steps/main.steps';
import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps';

Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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);
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
repay,
supply,
withdraw,
withdrawAndSwitch,
} from '../../../../support/steps/main.steps';
import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps';

Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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);
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
repay,
supply,
withdraw,
withdrawAndSwitch,
} from '../../../../support/steps/main.steps';
import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps';

Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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);
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
repay,
supply,
withdraw,
withdrawAndSwitch,
} from '../../../../support/steps/main.steps';
import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps';

Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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);
});
93 changes: 93 additions & 0 deletions cypress/support/steps/main.steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

2 comments on commit 63392cf

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit was deployed on ipfs

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit was deployed on ipfs

Please sign in to comment.