Skip to content

Commit

Permalink
Merge pull request #229 from OasisDEX/morpho-steakhouse
Browse files Browse the repository at this point in the history
Morpho Steakhouse tests
  • Loading branch information
juan-langa authored Apr 18, 2024
2 parents d4086ff + 402281e commit 9d72a03
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/pages/position/overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,21 @@ export class Overview {
}

@step
async shouldHaveAvailableToWithdraw({ amount, token }: { amount: string; token: string }) {
async shouldHaveAvailableToWithdraw({
amount,
token,
timeout,
}: {
amount: string;
token: string;
timeout?: number;
}) {
const regExp = new RegExp(`${amount} ${token}`);

await expect(this.page.locator('li:has-text("Available to Withdraw") p')).toContainText(
regExp,
{
timeout: positionTimeout,
timeout: timeout ?? expectDefaultTimeout,
}
);
}
Expand Down
14 changes: 14 additions & 0 deletions src/pages/position/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,4 +524,18 @@ export class Setup {
.getByRole('button', { name: 'Open new position' })
.click({ clickCount: 2, timeout: expectDefaultTimeout * 3 });
}

@step
async openTokenSelector() {
await this.page.getByTestId('deposit-token-selector').click();
}

@step
async selectDepositToken(token: 'USTD' | 'ETH') {
await this.page
.getByTestId('deposit-token-list')
.getByRole('listitem')
.filter({ hasText: token })
.click();
}
}
8 changes: 8 additions & 0 deletions tests/sharedTestSteps/positionManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ export const manageDebtOrCollateral = async ({
borrow,
payBack,
expectedCollateralDeposited,
expectedAvailableToWithdraw,
expectedCollateralExposure,
expectedDebt,
}: {
Expand All @@ -257,6 +258,7 @@ export const manageDebtOrCollateral = async ({
borrow?: ActionData;
payBack?: ActionData;
expectedCollateralDeposited?: { token: string; amount: string };
expectedAvailableToWithdraw?: { token: string; amount: string };
expectedCollateralExposure?: { token: string; amount: string };
expectedDebt?: { token: string; amount: string };
}) => {
Expand Down Expand Up @@ -308,6 +310,12 @@ export const manageDebtOrCollateral = async ({
...expectedCollateralDeposited,
});
}
if (expectedAvailableToWithdraw) {
await app.position.overview.shouldHaveAvailableToWithdraw({
timeout: positionTimeout,
...expectedAvailableToWithdraw,
});
}
if (expectedCollateralExposure) {
await app.position.overview.shouldHaveExposure({
timeout: positionTimeout,
Expand Down
125 changes: 125 additions & 0 deletions tests/withWallet/morphoBlue/morphoBlueEarn.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { BrowserContext, test } from '@playwright/test';
import { metamaskSetUp } from 'utils/setup';
import { resetState } from '@synthetixio/synpress/commands/synpress';
import * as tenderly from 'utils/tenderly';
import { setup } from 'utils/setup';
import { extremelyLongTestTimeout, longTestTimeout } from 'utils/config';
import { App } from 'src/app';
import { manageDebtOrCollateral, openPosition } from 'tests/sharedTestSteps/positionManagement';

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

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

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

await app.page.close();

await context.close();

await resetState();
});

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

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: 'USDT',
balance: '100000',
});
});

await app.page.goto('/ethereum/erc-4626/earn/steakhouse-USDT#setup');

await openPosition({
app,
forkId,
deposit: { token: 'USDT', amount: '20000' },
});
});

test('It should Deposit (same token - USDT) on an existing Morpho Blue Borrow position @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: 'xxxx',
});

test.setTimeout(longTestTimeout);

await manageDebtOrCollateral({
app,
forkId,
deposit: { token: 'USDT', amount: '10000' },
allowanceNotNeeded: true,
expectedAvailableToWithdraw: {
amount: '[2-3][0-9],[0-9]{3}.[0-9]{2}',
token: 'USDT',
},
});
});

test('It should Withdraw from an existing Morpho Blue Borrow position @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: 'xxxx',
});

test.setTimeout(longTestTimeout);

await app.position.manage.withdrawCollateral();

await manageDebtOrCollateral({
app,
forkId,
withdraw: { token: 'USDT', amount: '20000' },
allowanceNotNeeded: true,
expectedAvailableToWithdraw: {
amount: '(1)?[0-9],[0-9]{3}.[0-9]{2}',
token: 'USDT',
},
});
});

test('It should Deposit (different token - ETH) on an existing Morpho Blue Borrow position @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: 'xxxx',
});

test.setTimeout(longTestTimeout);

await app.position.setup.openTokenSelector();
await app.position.setup.selectDepositToken('ETH');

await manageDebtOrCollateral({
app,
forkId,
deposit: { token: 'ETH', amount: '80' },
allowanceNotNeeded: true,
expectedAvailableToWithdraw: {
amount: '[0-9]{3},[0-9]{3}.[0-9]{2}',
token: 'USDT',
},
});
});
});

0 comments on commit 9d72a03

Please sign in to comment.