Skip to content

Commit

Permalink
Merge pull request #105 from OasisDEX/fixes-19-dec
Browse files Browse the repository at this point in the history
Fixing broken tests
  • Loading branch information
juan-langa authored Dec 19, 2023
2 parents b12e850 + 589a08e commit 97bc121
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 52 deletions.
40 changes: 38 additions & 2 deletions src/pages/position/manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,49 @@ export class Manage {
.fill(amount);
}

@step
async deposit({ token, amount }: { token: string; amount: string }) {
await this.page
.getByText(`Deposit ${token}`)
.locator('../..')
.getByPlaceholder(`0 ${token}`)
.fill(amount);
}

@step
async withdraw({ token, amount }: { token: string; amount: string }) {
await this.page
.getByText(`Withdraw ${token}`)
.locator('../..')
.getByPlaceholder(`0 ${token}`)
.fill(amount);
}

@step
async borrow({ token, amount }: { token: string; amount: string }) {
await this.page
.getByText(`Borrow ${token}`)
.locator('../..')
.getByPlaceholder(`0 ${token}`)
.fill(amount);
}

@step
async payback({ token, amount }: { token: string; amount: string }) {
await this.page
.getByText(`Payback ${token}`)
.locator('../..')
.getByPlaceholder(`0 ${token}`)
.fill(amount);
}

@step
async withdrawCollateral() {
await this.page.getByRole('button', { name: 'Withdraw collateral' }).click();
await this.page.getByRole('button', { name: 'Withdraw' }).click();
}

@step
async payBackDebt() {
await this.page.getByRole('button', { name: 'Pay back debt' }).click();
await this.page.getByRole('button', { name: 'Payback' }).click();
}
}
4 changes: 2 additions & 2 deletions tests/noWallet/aaveV3/base/aaveV3MultiplyBase.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ test.describe('Aave v3 Multiply Base', async () => {
token: 'WETH',
});
await app.position.setup.orderInformation.shouldHavePriceImpact({
amount: '[1-3],[0-9]{3}.[0-9]{2}',
percentage: '0.[0-9]{2}',
amount: '[1-6],[0-9]{3}.[0-9]{2}',
percentage: '[0-6].[0-9]{2}',
});
await app.position.setup.orderInformation.shouldHaveSlippageLimit('0.[0-9]{2}');
await app.position.setup.orderInformation.shouldHaveMultiply({
Expand Down
2 changes: 1 addition & 1 deletion tests/withWallet/aaveV2/aaveV2Multiply.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ test.describe('Aave v2 Multiply - Wallet connected', async () => {
await app.position.manage.shouldBeVisible('Manage Multiply position');
await app.position.manage.openManageOptions({ currentLabel: 'Adjust' });
await app.position.manage.select('Manage collateral');
await app.position.manage.enter({ token: 'ETH', amount: '15' });
await app.position.manage.deposit({ token: 'ETH', amount: '15' });

// Confirm action randomly fails - Retry until it's applied.
await expect(async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/withWallet/aaveV3/base/aaveV3BorrowBase.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ test.describe('Aave V3 Borrow - Base - Wallet connected', async () => {
await app.page.goto('/base/aave/v3/2#overview');

await app.position.manage.shouldBeVisible('Manage collateral');
await app.position.manage.enter({ token: 'ETH', amount: '15' });
await app.position.manage.deposit({ token: 'ETH', amount: '15' });

// Confirm action randomly fails - Retry until it's applied.
await expect(async () => {
Expand Down
8 changes: 4 additions & 4 deletions tests/withWallet/aaveV3/ethereum/aaveV3EarnEthereum.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ test.describe('Aave V3 Earn - Ethereum - Wallet connected', async () => {

await app.position.manage.openManageOptions({ currentLabel: 'Adjust' });
await app.position.manage.select('Manage collateral');
await app.position.manage.enter({ token: 'WSTETH', amount: '20' });
await app.position.manage.deposit({ token: 'WSTETH', amount: '20' });
await expect(async () => {
await app.position.setup.setupAllowance();
await app.position.setup.approveAllowance();
Expand Down Expand Up @@ -102,7 +102,7 @@ test.describe('Aave V3 Earn - Ethereum - Wallet connected', async () => {
await app.position.manage.openManageOptions({ currentLabel: 'Adjust' });
await app.position.manage.select('Manage collateral');
await app.position.manage.withdrawCollateral();
await app.position.manage.enter({ token: 'WSTETH', amount: '5' });
await app.position.manage.withdraw({ token: 'WSTETH', amount: '5' });

// Confirm action randomly fails - Retry until it's applied.
await expect(async () => {
Expand Down Expand Up @@ -131,7 +131,7 @@ test.describe('Aave V3 Earn - Ethereum - Wallet connected', async () => {

await app.position.manage.openManageOptions({ currentLabel: 'Adjust' });
await app.position.manage.select('Manage debt');
await app.position.manage.enter({ token: 'ETH', amount: '5' });
await app.position.manage.borrow({ token: 'ETH', amount: '5' });

// Confirm action randomly fails - Retry until it's applied.
await expect(async () => {
Expand Down Expand Up @@ -161,7 +161,7 @@ test.describe('Aave V3 Earn - Ethereum - Wallet connected', async () => {
await app.position.manage.openManageOptions({ currentLabel: 'Adjust' });
await app.position.manage.select('Manage debt');
await app.position.manage.payBackDebt();
await app.position.manage.enter({ token: 'ETH', amount: '2' });
await app.position.manage.payback({ token: 'ETH', amount: '2' });

// Confirm action randomly fails - Retry until it's applied.
await expect(async () => {
Expand Down
70 changes: 28 additions & 42 deletions tests/withWallet/spark/sparkBorrow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,17 @@ test.describe('Spark Borrow - Wallet connected', async () => {
app = new App(page);

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

await tenderly.setWbtcBalance({ forkId, walletAddress, wbtcBalance: '2' });
});

await tenderly.changeAccountOwner({
account: '0x648dd9e11414db57097903a3ed98f773af61ef09',
account: '0x3dc0f12ff0452cab029c3c185c9dc9061d1515c8',
newOwner: walletAddress,
forkId,
});

await app.page.goto('/ethereum/spark/v3/1669#overview');
await app.page.goto('/ethereum/spark/v3/1474#overview');
await app.position.manage.shouldBeVisible('Manage collateral');
await app.position.manage.enter({ token: 'WBTC', amount: '1' });

// Setting up allowance randomly fails - Retry until it's set.
await expect(async () => {
await app.position.setup.setupAllowance();
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();
await app.position.manage.deposit({ token: 'ETH', amount: '20' });

// Confirm action randomly fails - Retry until it's applied.
await expect(async () => {
Expand All @@ -85,7 +71,7 @@ test.describe('Spark Borrow - Wallet connected', async () => {
value: '[0-9]{2},[0-9]{3}.[0-9]{2}',
token: 'DAI',
});
await app.position.overview.shouldHaveExposure({ amount: '1.00000', token: 'WBTC' });
await app.position.overview.shouldHaveExposure({ amount: '20.[0-9]{5}', token: 'ETH' });
});

test('It should withdraw some collateral from an existent Spark Borrow position @regression', async () => {
Expand All @@ -97,10 +83,10 @@ test.describe('Spark Borrow - Wallet connected', async () => {
test.setTimeout(veryLongTestTimeout);

await app.position.manage.shouldBeVisible('Manage collateral');
await app.position.overview.shouldHaveExposure({ amount: '1.00000', token: 'WBTC' });
await app.position.overview.shouldHaveExposure({ amount: '20.[0-9]{5}', token: 'ETH' });

await app.position.manage.withdrawCollateral();
await app.position.manage.enter({ token: 'WBTC', amount: '0.1' });
await app.position.manage.withdraw({ token: 'ETH', amount: '5' });

// Confirm action randomly fails - Retry until it's applied.
await expect(async () => {
Expand All @@ -113,7 +99,7 @@ test.describe('Spark Borrow - Wallet connected', async () => {

await app.position.manage.ok();

await app.position.overview.shouldHaveExposure({ amount: '0.90000', token: 'WBTC' });
await app.position.overview.shouldHaveExposure({ amount: '15.[0-9]{5}', token: 'ETH' });
});

test('It should borrow more debt from an existing Spark Borrow position @regression', async () => {
Expand All @@ -125,11 +111,11 @@ test.describe('Spark Borrow - Wallet connected', async () => {
test.setTimeout(veryLongTestTimeout);

await app.position.manage.shouldBeVisible('Manage collateral');
await app.position.overview.shouldHaveDebt({ amount: '0.0000', token: 'DAI' });
await app.position.overview.shouldHaveDebt({ amount: '[0-9].[0-9]{4}', token: 'DAI' });

await app.position.manage.openManageOptions({ currentLabel: 'Manage WBTC' });
await app.position.manage.openManageOptions({ currentLabel: 'Manage ETH' });
await app.position.manage.select('Manage debt');
await app.position.manage.enter({ token: 'DAI', amount: '5000' });
await app.position.manage.borrow({ token: 'DAI', amount: '5000' });

// Confirm action randomly fails - Retry until it's applied.
await expect(async () => {
Expand All @@ -142,7 +128,7 @@ test.describe('Spark Borrow - Wallet connected', async () => {

await app.position.manage.ok();

await app.position.overview.shouldHaveDebt({ amount: '5,000.0000', token: 'DAI' });
await app.position.overview.shouldHaveDebt({ amount: '5,[0-9]{3}.[0-9]{4}', token: 'DAI' });
});

test('It should pay back some debt from an existing Spark Borrow position @regression', async () => {
Expand All @@ -154,18 +140,18 @@ test.describe('Spark Borrow - Wallet connected', async () => {
test.setTimeout(veryLongTestTimeout);

await app.position.manage.shouldBeVisible('Manage collateral');
await app.position.overview.shouldHaveDebt({ amount: '0.0000', token: 'DAI' });
await app.position.overview.shouldHaveDebt({ amount: '5,[0-9]{3}.[0-9]{4}', token: 'DAI' });

await app.position.manage.openManageOptions({ currentLabel: 'Manage WBTC' });
await app.position.manage.openManageOptions({ currentLabel: 'Manage ETH' });
await app.position.manage.select('Manage debt');
await app.position.manage.payBackDebt();
await app.position.manage.enter({ token: 'DAI', amount: '3000' });
await app.position.manage.payback({ token: 'DAI', amount: '3000' });
// Setting up allowance randomly fails - Retry until it's set.
await expect(async () => {
await app.position.setup.setupAllowance();
await app.position.setup.approveAllowance();
await test.step('Metamask: ConfirmAddToken', async () => {
await metamask.confirmAddToken();
await metamask.confirmAddToken({});
});
await app.position.setup.continueShouldBeVisible();
}).toPass({ timeout: longTestTimeout });
Expand All @@ -182,10 +168,10 @@ test.describe('Spark Borrow - Wallet connected', async () => {

await app.position.manage.ok();

await app.position.overview.shouldHaveDebt({ amount: '2,000.[0-9]{4}', token: 'DAI' });
await app.position.overview.shouldHaveDebt({ amount: '[2-3],[0-9]{3}.[0-9]{4}', token: 'DAI' });
});

test('It should adjust risk of an existent Spark Borrow position - Up (WBTC/DAI) @regression', async () => {
test('It should adjust risk of an existent Spark Borrow position - Up (ETH/DAI) @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: '13050',
Expand All @@ -194,7 +180,7 @@ test.describe('Spark Borrow - Wallet connected', async () => {
test.setTimeout(veryLongTestTimeout);

await app.position.manage.shouldBeVisible('Manage collateral');
await app.position.manage.openManageOptions({ currentLabel: 'Manage WBTC' });
await app.position.manage.openManageOptions({ currentLabel: 'Manage ETH' });
await app.position.manage.select('Adjust');

const initialLiqPrice = await app.position.manage.getLiquidationPrice();
Expand All @@ -217,15 +203,15 @@ test.describe('Spark Borrow - Wallet connected', async () => {
await app.position.manage.ok();

await app.position.manage.shouldBeVisible('Manage collateral');
await app.position.manage.openManageOptions({ currentLabel: 'Manage WBTC' });
await app.position.manage.openManageOptions({ currentLabel: 'Manage ETH' });
await app.position.manage.select('Adjust');
const updatedLiqPrice = await app.position.manage.getLiquidationPrice();
const updatedLoanToValue = await app.position.manage.getLoanToValue();
expect(updatedLiqPrice).toBeGreaterThan(initialLiqPrice);
expect(updatedLoanToValue).toBeGreaterThan(initialLoanToValue);
});

test('It should adjust risk of an existent Spark Borrow position - Down (WBTC/DAI) @regression', async () => {
test('It should adjust risk of an existent Spark Borrow position - Down (ETH/DAI) @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: '13051',
Expand Down Expand Up @@ -254,7 +240,7 @@ test.describe('Spark Borrow - Wallet connected', async () => {
await app.position.manage.ok();

await app.position.manage.shouldBeVisible('Manage collateral');
await app.position.manage.openManageOptions({ currentLabel: 'Manage WBTC' });
await app.position.manage.openManageOptions({ currentLabel: 'Manage ETH' });
await app.position.manage.select('Adjust');
const updatedLiqPrice = await app.position.manage.getLiquidationPrice();
const updatedLoanToValue = await app.position.manage.getLoanToValue();
Expand All @@ -263,7 +249,7 @@ test.describe('Spark Borrow - Wallet connected', async () => {
expect(updatedLoanToValue).toBeLessThan(initialLoanToValue);
});

test('It should close an existent Spark Borrow position - Close to collateral token (WBTC) @regression', async () => {
test('It should close an existent Spark Borrow position - Close to collateral token (ETH) @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: '13077',
Expand All @@ -274,10 +260,10 @@ test.describe('Spark Borrow - Wallet connected', async () => {
await app.position.manage.shouldBeVisible('Manage Borrow position');
await app.position.manage.openManageOptions({ currentLabel: 'Adjust' });
await app.position.manage.select('Close position');
await app.position.manage.closeTo('WBTC');
await app.position.manage.closeTo('ETH');
await app.position.manage.shouldHaveTokenAmountAfterClosing({
token: 'WBTC',
amount: '0.[0-9]{3,4}',
token: 'ETH',
amount: '[0-9]{1,2}.[0-9]{1,2}([0-9]{1,2})?',
});

// Confirm action randomly fails - Retry until it's applied.
Expand All @@ -291,12 +277,12 @@ test.describe('Spark Borrow - Wallet connected', async () => {

await app.position.manage.ok();

await app.page.goto('/ethereum/spark/v3/1669#overview');
await app.page.goto('/ethereum/spark/v3/1474#overview');
await app.position.overview.shouldHaveLiquidationPrice({ price: '0.00', token: 'DAI' });
await app.position.overview.shouldHaveLoanToValue('0.00');
await app.position.overview.shouldHaveBorrowCost('0.00');
await app.position.overview.shouldHaveNetValue({ value: '0.00', token: 'DAI' });
await app.position.overview.shouldHaveExposure({ amount: '0.00000', token: 'WBTC' });
await app.position.overview.shouldHaveExposure({ amount: '0.00000', token: 'ETH' });
await app.position.overview.shouldHaveDebt({ amount: '0.0000', token: 'DAI' });
});

Expand All @@ -321,7 +307,7 @@ test.describe('Spark Borrow - Wallet connected', async () => {
await app.position.manage.closeTo('DAI');
await app.position.manage.shouldHaveTokenAmountAfterClosing({
token: 'DAI',
amount: '[0-3].[0-9]{3,4}',
amount: '[0-9]{2},[0-9]{3}.[0-9]{1,2}([0-9]{1,2})?',
});

// Confirm action randomly fails - Retry until it's applied.
Expand Down

0 comments on commit 97bc121

Please sign in to comment.