Skip to content

Commit

Permalink
Merge pull request #130 from OasisDEX/morphoblue-borrow-first-tests
Browse files Browse the repository at this point in the history
Morpho Blue Borrow - Simulating and opening a position tests
  • Loading branch information
juan-langa authored Jan 18, 2024
2 parents cf59e16 + cead6fb commit 99dd2ff
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 22 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/allTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
name: playwright-report-with-wallet-aave-other
path: playwright-reports/with-wallet-aave-other
retention-days: 30
with-wallet-ajna-tests:
with-wallet-ajna-and-morphoblue-tests:
name: 'With wallet - Ajna'
runs-on: ubuntu-latest
env:
Expand All @@ -130,12 +130,12 @@ jobs:
TENDERLY_ACCESS_KEY=${{ secrets.TENDERLY_ACCESS_KEY }} \
BASE_URL=${{ inputs.base_url }} \
FLAGS=${{ inputs.flags}} \
yarn nightly:with-wallet:ajna
yarn nightly:with-wallet:ajna-and-morphoblue
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report-with-wallet-ajna
path: playwright-reports/with-wallet-ajna
name: playwright-report-with-wallet-ajna-and-morphoblue
path: playwright-reports/with-wallet-ajna-and-morphoblue
retention-days: 30
with-wallet-maker-and-spark-tests:
name: 'With wallet - Maker & Spark'
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
name: playwright-report-with-wallet-aave-other
path: playwright-reports/with-wallet-aave-other
retention-days: 30
with-wallet-ajna-tests:
with-wallet-ajna-and-morphoblue-tests:
name: 'With wallet - Ajna'
runs-on: ubuntu-latest
env:
Expand All @@ -114,12 +114,13 @@ jobs:
TENDERLY_PROJECT=${{ secrets.TENDERLY_PROJECT }} \
TENDERLY_USER=${{ secrets.TENDERLY_USER }} \
TENDERLY_ACCESS_KEY=${{ secrets.TENDERLY_ACCESS_KEY }} \
yarn nightly:with-wallet:ajna
FLAGS='MorphoBlue:true' \
yarn nightly:with-wallet:ajna-and-morphoblue
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report-with-wallet-ajna
path: playwright-reports/with-wallet-ajna
name: playwright-report-with-wallet-ajna-and-morphoblue
path: playwright-reports/with-wallet-ajna-and-morphoblue
retention-days: 30
with-wallet-maker-and-spark-tests:
name: 'With wallet - Maker & Spark'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/regression.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
name: playwright-report-with-wallet-aave-other
path: playwright-reports/with-wallet-aave-other
retention-days: 30
with-wallet-ajna-tests:
with-wallet-ajna-and-morphoblue-tests:
name: 'With wallet - Ajna'
runs-on: ubuntu-latest
env:
Expand All @@ -130,12 +130,12 @@ jobs:
TENDERLY_ACCESS_KEY=${{ secrets.TENDERLY_ACCESS_KEY }} \
BASE_URL=${{ inputs.base_url }} \
FLAGS=${{ inputs.flags}} \
yarn ci:with-wallet:ajna:regression
yarn ci:with-wallet:ajna-and-morphoblue:regression
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report-with-wallet-ajna
path: playwright-reports/with-wallet-ajna
name: playwright-report-with-wallet-ajna-and-morphoblue
path: playwright-reports/with-wallet-ajna-and-morphoblue
retention-days: 30

with-wallet-maker-and-spark-tests:
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,43 @@
"no-wallet": "REPORT_FOLDER=no-wallet npx playwright test --project=no-wallet",
"with-wallet:aave:ethereum": "REPORT_FOLDER=with-wallet-aave-ethereum npx playwright test --project=with-wallet-aave-ethereum --workers=1",
"with-wallet:aave:other": "REPORT_FOLDER=with-wallet-aave-other npx playwright test --project=with-wallet-aave-other --workers=1",
"with-wallet:ajna": "REPORT_FOLDER=with-wallet-ajna npx playwright test --project=with-wallet-ajna --workers=1",
"with-wallet:ajna-and-morphoblue": "REPORT_FOLDER=with-wallet-ajna-and-morphoblue npx playwright test --project=with-wallet-ajna-and-morphoblue --workers=1",
"with-wallet:maker-and-spark": "REPORT_FOLDER=with-wallet-maker-and-spark npx playwright test --project=with-wallet-maker-and-spark --workers=1",
"with-wallet:all": "yarn with-wallet:aave:ethereum & yarn with-wallet:aave:other & yarn with-wallet:ajna & yarn with-wallet:maker-and-spark",
"with-wallet:all": "yarn with-wallet:aave:ethereum & yarn with-wallet:aave:other & yarn with-wallet:ajna-and-morphoblue & yarn with-wallet:maker-and-spark",
"test:e2e": "yarn no-wallet & yarn with-wallet:all",
"//-1a": "---------------------------------------------------------------",
"//-1b": "---------------------- REGRESSION TESTS -----------------------",
"//-1c": "---------------------------------------------------------------",
"no-wallet:regression": "REPORT_FOLDER=no-wallet npx playwright test --grep @regression --project=no-wallet",
"with-wallet:aave:ethereum:regression": "REPORT_FOLDER=with-wallet-aave-ethereum npx playwright test --grep @regression --project=with-wallet-aave-ethereum --workers=1",
"with-wallet:aave:other:regression": "REPORT_FOLDER=with-wallet-aave-other npx playwright test --grep @regression --project=with-wallet-aave-other --workers=1",
"with-wallet:ajna:regression": "REPORT_FOLDER=with-wallet-ajna npx playwright test --grep @regression --project=with-wallet-ajna --workers=1",
"with-wallet:ajna-and-morphoblue:regression": "REPORT_FOLDER=with-wallet-ajna-and-morphoblue npx playwright test --grep @regression --project=with-wallet-ajna-and-morphoblue --workers=1",
"with-wallet:maker-and-spark:regression": "REPORT_FOLDER=with-wallet-maker-and-spark npx playwright test --grep @regression --project=with-wallet-maker-and-spark --workers=1",
"with-wallet:all:regression": "yarn with-wallet:aave:ethereum:regression & yarn with-wallet:aave:other:regression & yarn with-wallet:ajna:regression & yarn with-wallet:maker-and-spark:regression",
"with-wallet:all:regression": "yarn with-wallet:aave:ethereum:regression & yarn with-wallet:aave:other:regression & yarn with-wallet:ajna-and-morphoblue:regression & yarn with-wallet:maker-and-spark:regression",
"test:e2e:regression": "yarn no-wallet:regression & yarn with-wallet:all:regression",
"//-2a": "---------------------------------------------------------------",
"//-2b": "---------------------- CI REGRESSION TESTS -----------------------",
"//-2c": "---------------------------------------------------------------",
"ci:no-wallet:regression": "WORKERS='2' FULLY_PARALLEL='true' RETRIES='2' yarn no-wallet:regression",
"ci:with-wallet:aave:ethereum:regression": "xvfb-run yarn with-wallet:aave:ethereum:regression",
"ci:with-wallet:aave:other:regression": "xvfb-run yarn with-wallet:aave:other:regression",
"ci:with-wallet:ajna:regression": "xvfb-run yarn with-wallet:ajna:regression",
"ci:with-wallet:ajna-and-morphoblue:regression": "xvfb-run yarn with-wallet:ajna-and-morphoblue:regression",
"ci:with-wallet:maker-and-spark:regression": "xvfb-run yarn with-wallet:maker-and-spark:regression",
"//-3a": "---------------------------------------------------------------",
"//-3b": "---------------------- NIGHTLY TESTS -----------------------",
"//-3c": "---------------------------------------------------------------",
"nightly:no-wallet": "WORKERS='2' FULLY_PARALLEL='true' RETRIES='2' yarn no-wallet",
"nightly:with-wallet:aave:ethereum": "RETRIES='2' xvfb-run yarn with-wallet:aave:ethereum",
"nightly:with-wallet:aave:other": "RETRIES='2' xvfb-run yarn with-wallet:aave:other",
"nightly:with-wallet:ajna": "RETRIES='2' xvfb-run yarn with-wallet:ajna",
"nightly:with-wallet:ajna-and-morphoblue": "RETRIES='2' xvfb-run yarn with-wallet:ajna-and-morphoblue",
"nightly:with-wallet:maker-and-spark": "RETRIES='2' xvfb-run yarn with-wallet:maker-and-spark",
"//-9a": "---------------------------------------------------------------",
"//-9b": "---------------------- REPORTS --------------------------------",
"//-9c": "---------------------------------------------------------------",
"test:report:no-wallet": "npx playwright show-report playwright-reports/no-wallet",
"test:report:with-wallet:aave:ethereum": "npx playwright show-report playwright-reports/with-wallet-aave-ethereum",
"test:report:with-wallet:aave:other": "npx playwright show-report playwright-reports/with-wallet-aave-other",
"test:report:with-wallet:ajna": "npx playwright show-report playwright-reports/with-wallet-ajna",
"test:report:with-wallet:ajna-and-morphoblue": "npx playwright show-report playwright-reports/with-wallet-ajna-and-morphoblue",
"test:report:with-wallet:maker-and-spark": "npx playwright show-report playwright-reports/with-wallet-maker-and-spark",
"//-10a": "---------------------------------------------------------------",
"//-10b": "---------------------- MANUAL TESTING UTILS --------------------------------",
Expand Down
4 changes: 2 additions & 2 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ const defaultConfig: PlaywrightTestConfig = {
},

{
name: 'with-wallet-ajna',
testMatch: ['withWallet/ajna/**'],
name: 'with-wallet-ajna-and-morphoblue',
testMatch: ['withWallet/ajna/**', 'withWallet/morphoBlue/**'],
use: { ...devices['Desktop Chrome'] },
},

Expand Down
2 changes: 1 addition & 1 deletion src/pages/position/orderInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class OrderInformation {
}: {
current: string;
future: string;
protocol?: 'Ajna';
protocol?: 'Ajna' | 'Morpho Blue';
}) {
const regExp = new RegExp(`${current}%${protocol ? '' : ' '}${future}%`);

Expand Down
192 changes: 192 additions & 0 deletions tests/withWallet/morphoBlue/morphoBlueBorrow.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import { BrowserContext, test } from '@playwright/test';
import { expect, metamaskSetUp } from 'utils/setup';
import { resetState } from '@synthetixio/synpress/commands/synpress';
import * as metamask from '@synthetixio/synpress/commands/metamask';
import * as tenderly from 'utils/tenderly';
import { setup } from 'utils/setup';
import { extremelyLongTestTimeout, longTestTimeout } from 'utils/config';
import { App } from 'src/app';

let context: BrowserContext;
let app: App;
let forkId: string;
let walletAddress: string;

test.describe.configure({ mode: 'serial' });

test.describe('Morpho Blue Borrow - Wallet connected', async () => {
test.afterAll(async () => {
await tenderly.deleteFork(forkId);

await app.page.close();

await context.close();

await resetState();
});

test('It should allow to simulate a Morpho Blue Borrow position before opening it @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: 'xxxxxx',
});

test.setTimeout(extremelyLongTestTimeout);

await test.step('Test setup', async () => {
({ context } = await metamaskSetUp({ network: 'mainnet' }));
let page = await context.newPage();
app = new App(page);

({ forkId, walletAddress } = await setup({ app, network: 'mainnet' }));

await tenderly.setTokenBalance({
forkId,
network: 'mainnet',
walletAddress,
token: 'WSTETH',
balance: '10',
});
});

await app.page.goto('/ethereum/morphoblue/borrow/WSTETH-ETH#setup');

await app.position.setup.deposit({ token: 'WSTETH', amount: '10.12345' });

await app.position.overview.shouldHaveCollateralDepositedAfterPill('10.12 WSTETH');
await app.position.overview.shouldHaveNetValueAfterPill('\\$[0-9]{1,2},[0-9]{3}.[0-9]{2}');
// !!! BUG: vailableToWithdrawAfterPill showing 0.00 at the moment
// await app.position.overview.shouldHaveAvailableToWithdrawAfterPill({
// amount: '10.12',
// token: 'WSTETH',
// });
await app.position.overview.shouldHaveAvailableToBorrowAfterPill({
amount: '[0-9]{1,2}.[0-9]{2}',
token: 'ETH',
});

await app.position.setup.shouldHaveMaxBorrowingAmount({
token: 'ETH',
amount: '[0-9]{1,2}.[0-9]{2}',
});
await app.position.setup.orderInformation.shouldHaveCollateralLocked({
token: 'WSTETH',
current: '0.00',
future: '10.12',
});
await app.position.setup.orderInformation.shouldHaveMaxLTV({
current: '[0-9]{2,3}.[0-9]{2}',
future: '[0-9]{2,3}.[0-9]{2}',
});
// !!! BUG: vailableToWithdrawAfterPill showing 0.00 at the moment
// await app.position.setup.orderInformation.shouldHaveAvailableToWithdraw({
// token: 'WSTETH',
// current: '0.00',
// future: '10.12',
// });
await app.position.setup.orderInformation.shouldHaveAvailableToBorrow({
token: 'ETH',
current: '0.00',
future: '[0-9]{1,2}.[0-9]{2}',
});

await app.position.setup.borrow({ token: 'ETH', amount: '8.12345' });

await app.position.overview.shouldHaveLiquidationPriceAfterPill('[0-1].[0-9]{3,4} WSTETH/ETH');
await app.position.overview.shouldHaveLoanToValueAfterPill('[4-9][0-9].[0-9]{1,2}%');
await app.position.overview.shouldHaveDebtAfterPill({
amount: '8.1234',
token: 'ETH',
});
await app.position.overview.shouldHaveNetValueAfterPill('\\$[0-9]{1,2},[0-9]{3}.[0-9]{2}');
await app.position.overview.shouldHaveAvailableToWithdrawAfterPill({
amount: '[0-1].[0-9]{3,4}',
token: 'WSTETH',
});
await app.position.overview.shouldHaveAvailableToBorrowAfterPill({
amount: '[0-4].[0-9]{3,4}',
token: 'ETH',
});

await app.position.orderInformation.shouldHaveLiquidationPrice({
pair: 'WSTETH/ETH',
current: '0.00',
future: '[0-2].[0-9]{3,4}',
});
await app.position.orderInformation.shouldHaveLTV({
protocol: 'Morpho Blue',
current: '0.00',
future: '[1-9][0-9].[0-9]{2}',
});
await app.position.setup.orderInformation.shouldHaveMaxLTV({
current: '[0-9]{2,3}.[0-9]{2}',
future: '[0-9]{2,3}.[0-9]{2}',
});
await app.position.setup.orderInformation.shouldHaveDebt({
token: 'ETH',
current: '0.00',
future: '8.[0-9]{3,4}',
});
await app.position.setup.orderInformation.shouldHaveAvailableToWithdraw({
token: 'WSTETH',
current: '0.00',
future: '[0-5].[0-9]{3,4}',
});
await app.position.setup.orderInformation.shouldHaveAvailableToBorrow({
token: 'ETH',
current: '0.00',
future: '[0-5].[0-9]{3,4}',
});
});

test('It should open a Morpho Blue Borrow position @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: 'xxx',
});

test.setTimeout(extremelyLongTestTimeout);

await app.page.goto('ethereum/morphoblue/borrow/WSTETH-USDC#setup');
await app.position.setup.deposit({ token: 'WSTETH', amount: '10' });
await app.position.setup.borrow({ token: 'USDC', amount: '8000.12' });

await app.position.setup.createSmartDeFiAccount();

// Smart DeFi Acount creation randomly fails - Retry until it's created.
await expect(async () => {
await app.position.setup.createSmartDeFiAccount();
await test.step('Metamask: ConfirmAddToken', async () => {
await metamask.confirmAddToken();
});
await app.position.setup.continueShouldBeVisible();
}).toPass({ timeout: longTestTimeout });

await app.position.setup.continue();

// Setting up allowance randomly fails - Retry until it's set.
await expect(async () => {
await app.position.setup.approveAllowance();
await test.step('Metamask: ConfirmAddToken', async () => {
await metamask.confirmAddToken();
});
await app.position.setup.continueShouldBeVisible();
}).toPass({ timeout: longTestTimeout });

await app.position.setup.continue();

// Position creation randomly fails - Retry until it's created.
await expect(async () => {
await app.position.setup.confirmOrRetry();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
});
await app.position.setup.goToPositionShouldBeVisible();
}).toPass({ timeout: longTestTimeout });

// !!!! BUG: Position is created but UI gets stuck
// await app.position.setup.goToPosition();
// await app.position.setup.continue();
// await app.position.manage.shouldBeVisible('Manage your XXX Borrow Position');
});
});

0 comments on commit 99dd2ff

Please sign in to comment.