Skip to content

Commit

Permalink
Merge pull request #324 from OasisDEX/refinance-more-tests
Browse files Browse the repository at this point in the history
Refinance - Aave V3, Morpho and Spark test
  • Loading branch information
juan-langa authored May 23, 2024
2 parents 4e0dc66 + b49478a commit a534e80
Show file tree
Hide file tree
Showing 5 changed files with 299 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { BrowserContext, test } from '@playwright/test';
import { resetState } from '@synthetixio/synpress/commands/synpress';
import { metamaskSetUp } from 'utils/setup';
import * as tenderly from 'utils/tenderly';
import { setup } from 'utils/setup';
import { extremelyLongTestTimeout } from 'utils/config';
import { App } from 'src/app';
import { openPosition, swapMakerToSpark } from 'tests/sharedTestSteps/positionManagement';

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

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

test.describe('Aave V3 Multiply - Swap to Spark', async () => {
test.afterAll(async () => {
await tenderly.deleteFork(forkId);

await app.page.close();

await context.close();

await resetState();
});

test.use({
viewport: { width: 1400, height: 720 },
});

// Create an Aave V3 position as part of the Swap tests setup
test('It should open an Aave V3 Multiply position', 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 } = await setup({
app,
network: 'mainnet',
extraFeaturesFlags: 'MakerTenderly:true EnableRefinance:true',
}));
});

await app.page.goto('/ethereum/aave/v3/multiply/ETH-WBTC#setup');

// Depositing collateral too quickly after loading page returns wrong simulation results
await app.position.overview.waitForComponentToBeStable();

await openPosition({
app,
forkId,
deposit: { token: 'ETH', amount: '10' },
});
});

test('It should swap an Aave V3 Multiply position (ETH/WBTC) to Spark Multiply (ETH/DAI)', async () => {
test.info().annotations.push({
type: 'Test case',
description: 'xxx',
});

test.setTimeout(extremelyLongTestTimeout);

// Wait an reload to avoid flakiness
await app.page.waitForTimeout(1000);
await app.page.reload();

await swapMakerToSpark({
app,
forkId,
reason: 'Switch to higher max Loan To Value',
targetPool: 'ETH/DAI',
expectedTargetExposure: {
amount: '1[0-9].[0-9]{2}',
token: 'ETH',
},
expectedTargetDebt: {
amount: '[2-8],[0-9]{3}.[0-9]{2}',
token: 'DAI',
},
originalPosition: { type: 'Multiply', collateralToken: 'ETH', debtToken: 'WBTC' },
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test.describe('Morpho Blue Multiply - Swap to Spark', async () => {
});

// Create a Morpho Blue position as part of the Swap tests setup
test('It should open a Morpho Blue Borrow position', async () => {
test('It should open a Morpho Blue Multiply position', async () => {
test.info().annotations.push({
type: 'Test case',
description: 'xxx',
Expand Down Expand Up @@ -88,11 +88,11 @@ test.describe('Morpho Blue Multiply - Swap to Spark', async () => {
reason: 'Switch to higher max Loan To Value',
targetPool: 'WSTETH/DAI',
expectedTargetExposure: {
amount: '[0-9]{1,2}.[0-9]{2}',
amount: '1[0-2].[0-9]{2}',
token: 'WSTETH',
},
expectedTargetDebt: {
amount: '[1][4-5],[0-9]{3}.[0-9]{2}',
amount: '[3-7],[0-9]{3}.[0-9]{2}',
token: 'DAI',
},
originalPosition: { type: 'Multiply', collateralToken: 'WSTETH', debtToken: 'USDC' },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { BrowserContext, test } from '@playwright/test';
import { resetState } from '@synthetixio/synpress/commands/synpress';
import { metamaskSetUp } from 'utils/setup';
import * as tenderly from 'utils/tenderly';
import { setup } from 'utils/setup';
import { extremelyLongTestTimeout } from 'utils/config';
import { App } from 'src/app';
import { openPosition, swapMakerToSpark } 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 Multiply - Swap to Spark', async () => {
test.afterAll(async () => {
await tenderly.deleteFork(forkId);

await app.page.close();

await context.close();

await resetState();
});

test.use({
viewport: { width: 1400, height: 720 },
});

// Create a Morpho Blue position as part of the Swap tests setup
test('It should open a Morpho Blue Multiply position', 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',
extraFeaturesFlags: 'MakerTenderly:true EnableRefinance:true',
}));

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

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

// Depositing collateral too quickly after loading page returns wrong simulation results
await app.position.overview.waitForComponentToBeStable();

await openPosition({
app,
forkId,
deposit: { token: 'WSTETH', amount: '10' },
});
});

test('It should swap a Morpho Blue Multiply position (WSTETH/USDT) to Spark Multiply (WBTC/DAI)', async () => {
test.info().annotations.push({
type: 'Test case',
description: 'xxx',
});

test.setTimeout(extremelyLongTestTimeout);

// Wait an reload to avoid flakiness
await app.page.waitForTimeout(1000);
await app.page.reload();

await swapMakerToSpark({
app,
forkId,
reason: 'Switch to higher max Loan To Value',
targetPool: 'WBTC/DAI',
expectedTargetExposure: {
amount: '[0-1].[0-9]{2}',
token: 'WBTC',
},
expectedTargetDebt: {
amount: '[3-7],[0-9]{3}.[0-9]{2}',
token: 'DAI',
},
originalPosition: { type: 'Multiply', collateralToken: 'WSTETH', debtToken: 'USDT' },
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let forkId: string;

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

test.describe('Spark Borrow - Swap', async () => {
test.describe('Spark Multiply - Swap to Spark', async () => {
test.afterAll(async () => {
await tenderly.deleteFork(forkId);

Expand Down Expand Up @@ -52,7 +52,7 @@ test.describe('Spark Borrow - Swap', async () => {
await app.page.goto('/ethereum/spark/multiply/ETH-DAI#setup');

// Depositing collateral too quickly after loading page returns wrong simulation results
await app.position.overview.waitForComponentToBeStable({ positionType: 'Maker' });
await app.position.overview.waitForComponentToBeStable();

await openPosition({
app,
Expand Down
101 changes: 101 additions & 0 deletions tests/withWallet/spark/swap/toSpark/multSdaiEthToMultEthDai.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { BrowserContext, test } from '@playwright/test';
import { resetState } from '@synthetixio/synpress/commands/synpress';
import { metamaskSetUp } from 'utils/setup';
import * as tenderly from 'utils/tenderly';
import { setup } from 'utils/setup';
import { extremelyLongTestTimeout } from 'utils/config';
import { App } from 'src/app';
import { openPosition, swapMakerToSpark } from 'tests/sharedTestSteps/positionManagement';

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

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

test.describe('Spark Multiply - Swap to Spark', async () => {
test.afterAll(async () => {
await tenderly.deleteFork(forkId);

await app.page.close();

await context.close();

await resetState();
});

test.use({
viewport: { width: 1400, height: 720 },
});

// Create a Maker position as part of the Swap tests setup
test('It should open a Spark Multiply position', 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',
extraFeaturesFlags: 'MakerTenderly:true EnableRefinance:true',
}));

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

await app.page.goto('/ethereum/spark/multiply/SDAI-ETH#setup');

// Depositing collateral too quickly after loading page returns wrong simulation results
await app.position.overview.waitForComponentToBeStable();

await openPosition({
app,
forkId,
deposit: { token: 'SDAI', amount: '30000' },
});
});

test('It should swap a Spark Multiply position (SDAI/ETH) to Spark Multiply (ETH/DAI)', async () => {
test.info().annotations.push({
type: 'Test case',
description: 'xxx',
});

test.setTimeout(extremelyLongTestTimeout);

// Wait an reload to avoid flakiness
await app.page.waitForTimeout(1000);
await app.page.reload();

await swapMakerToSpark({
app,
forkId,
reason: 'Change direction of my position',
targetPool: 'ETH/DAI',
expectedTargetExposure: {
amount: '[0-9]{1,2}.[0-9]{2}',
token: 'ETH',
},
expectedTargetDebt: {
amount: '[2-6],[0-9]{3}.[0-9]{2}',
token: 'DAI',
},
originalPosition: { type: 'Multiply', collateralToken: 'SDAI', debtToken: 'ETH' },
});
});
});

0 comments on commit a534e80

Please sign in to comment.