Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions e2e/mocks/localstorage.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE",
"0x2730d6FdC86C95a74253BefFaA8306B40feDecbb"
],
"tenderlyRpc": "https://virtual.mainnet.eu.rpc.tenderly.co/4c55c851-ae20-4726-a572-21e291d6bd57",
"carbonApi": "https://carbon-multi-endpoint-staging-152368584642.europe-west2.run.app/v1/proxy/d0852fd4-e587-4826-8765-9c80348cec8d/"
}
"tenderlyRpc": "https://virtual.mainnet.eu.rpc.tenderly.co/59b5cba7-408d-4ae7-94ad-a5972a5c3fee",
"carbonApi": ""
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified e2e/screenshots/strategy/overlapping/Overlapping/create/form.png
33 changes: 6 additions & 27 deletions e2e/setup.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,22 @@
import { chromium, firefox, webkit, type FullConfig } from '@playwright/test';
import { createBackend, waitForBackend } from './utils/api';

const browsers = { chromium, firefox, webkit };
type BrowserName = keyof typeof browsers;

const tenderlyId = 'd0852fd4-e587-4826-8765-9c80348cec8d';
const apiUrl = `${process.env.BACKEND_TENDERLY_API}/preview/backends`;

const doesBackendExist = async () => {
const res = await fetch(`${apiUrl}/${tenderlyId}`);
const result = await res.json();
return result.status === 'ready';
};

const waitForBackend = async () => {
const res = await fetch(apiUrl, {
method: 'POST',
body: JSON.stringify({ tenderlyId }),
});
if (!res.ok) throw new Error('Could not create backend');
const max = Date.now() + 10 * 60 * 1000; // in 10min
let ready = false;
while (!ready && max > Date.now()) {
await new Promise((res) => setTimeout(res, 30_000)); // every 30sec
ready = await doesBackendExist();
}
if (!ready)
throw new Error('Timedout: wait too long for backend to be creating');
};

async function globalSetup(config: FullConfig) {
const setupProjects = config.projects.map(async (project) => {
if (!(project.name in browsers)) return;
const { baseURL, storageState } = project.use;
if (!baseURL) return;

// create RPC if do not exist
const backendExist = doesBackendExist();
console.log('Check if backend exist');
const backendExist = await waitForBackend();
console.log({ backendExist });
if (!backendExist) {
await waitForBackend();
console.log('Create a new backend');
await createBackend();
}

const browser = await browsers[project.name as BrowserName].launch();
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/strategy/recurring/pause.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from '@playwright/test';
import { waitModalOpen } from './../../../utils/modal';
import { Page } from 'playwright-core';
import { Page } from '@playwright/test';
import { ManageStrategyDriver } from './../../../utils/strategy/ManageStrategyDriver';
import {
CreateStrategyTestCase,
Expand All @@ -10,7 +10,7 @@ import { TokenApprovalDriver } from '../../../utils/TokenApprovalDriver';

export const pauseStrategy = async (
page: Page,
testCase: CreateStrategyTestCase
testCase: CreateStrategyTestCase,
) => {
const manage = new ManageStrategyDriver(page);
const tokenApproval = new TokenApprovalDriver(page);
Expand Down
46 changes: 7 additions & 39 deletions e2e/utils/DebugDriver.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,21 @@
import { Page, TestInfo } from '@playwright/test';
import { Page } from '@playwright/test';
import { waitFor } from './../utils/operators';
import {
createVirtualNetwork,
deleteVirtualNetwork,
CreateVirtualNetworkBody,
} from './../utils/tenderly';
import { Wallet } from 'ethers';
import { CreateStrategyTestCase, toDebugStrategy } from './strategy';
import { TokenApprovalDriver } from './TokenApprovalDriver';
import mockLocalStorage from '../mocks/localstorage.json' with { type: 'json' };

const vNetConfig: CreateVirtualNetworkBody = {
slug: 'e2e-ci',
display_name: 'E2E-CI',
fork_config: {
network_id: 1,
block_number: '18120000',
},
virtual_network_config: {
chain_config: {
chain_id: 1,
},
},
sync_state_config: {
enabled: false,
},
explorer_page_config: {
enabled: false,
verification_visibility: 'bytecode',
},
};

export const setupVirtualNetwork = async (testInfo: TestInfo) => {
const vNet = await createVirtualNetwork(structuredClone(vNetConfig));
process.env[`TENDERLY_FORK_ID_TEST_${testInfo.testId}`] = vNet.id;
return vNet;
};
import { proxyUrl } from './api';

export const setupLocalStorage = async (page: Page) => {
// We need to be on a page to set localstorage so we create an empty page
await page.route('empty', (route) => {
return route.fulfill({ status: 200, contentType: 'text/plain', body: '' });
});
await page.goto('empty');
const mockStorage = {
...mockLocalStorage,
carbonApi: proxyUrl,
};
return page.evaluate((storage) => {
// each value is stringified to match lsservice
for (const [key, value] of Object.entries(storage)) {
Expand All @@ -51,12 +24,7 @@ export const setupLocalStorage = async (page: Page) => {
JSON.stringify(value),
);
}
}, mockLocalStorage);
};

export const removeFork = async (testInfo: TestInfo) => {
const id = process.env[`TENDERLY_FORK_ID_TEST_${testInfo.testId}`];
if (id) await deleteVirtualNetwork(id);
}, mockStorage);
};

interface ImposterConfig {
Expand Down
52 changes: 52 additions & 0 deletions e2e/utils/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const tenderlyId = '4a59c786-adf3-4d04-8e6c-e09ac4a029f2';
const apiUrl = `${process.env.BACKEND_TENDERLY_API}/preview/backends`;
export const proxyUrl = `${process.env.BACKEND_TENDERLY_API}/v1/proxy/${tenderlyId}/`;

const getBackendStatus = async () => {
const res = await fetch(`${apiUrl}/${tenderlyId}`);
if (!res.ok) return 'errir';
const result = await res.json();
return result.status;
};

export const doesBackendExist = async () => {
const status = await getBackendStatus();
return status === 'ready';
};

const waitUntilCreated = async () => {
const max = Date.now() + 10 * 60 * 1000; // in 10min
let ready = false;
while (!ready && max > Date.now()) {
await new Promise((res) => setTimeout(res, 30_000)); // every 30sec
ready = await doesBackendExist();
}
return ready;
};

export const waitForBackend = async () => {
const status = await getBackendStatus();
if (status === 'creating') {
const ready = await waitUntilCreated();
if (!ready) throw new Error('Timeout before creation');
} else {
return status === 'ready';
}
};

export const createBackend = async () => {
const res = await fetch(apiUrl, {
method: 'POST',
body: JSON.stringify({ tenderlyId }),
headers: {
accept: 'application/json',
'Content-Type': 'application/json',
},
});
if (!res.ok) {
const error = await res.json();
console.error(error);
throw new Error('Could not create backend');
}
await waitForBackend();
};
2 changes: 1 addition & 1 deletion e2e/utils/mock-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Page } from 'playwright-core';
import { Page } from '@playwright/test';
import marketRate from '../mocks/market-rates.json' with { type: 'json' };
import roi from '../mocks/roi.json' with { type: 'json' };
import historyPrices from '../mocks/history-prices.json' with { type: 'json' };
Expand Down
11 changes: 7 additions & 4 deletions e2e/utils/simulator/SimulationResultDriver.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { Page } from 'playwright-core';
import { Page } from '@playwright/test';
import { CreateStrategyTestCase, SimulatorChartTypes } from './types';
import { Direction } from '../types';
import { screenshot, waitFor } from '../operators';
import { screenshotPath } from './utils';
import { MainMenuDriver } from '../MainMenuDriver';

export class SimulationResultDriver {
constructor(private page: Page, private testCase: CreateStrategyTestCase) {}
constructor(
private page: Page,
private testCase: CreateStrategyTestCase,
) {}

waitForChartElement() {
return waitFor(this.page, 'chart-tab-animation');
Expand All @@ -28,7 +31,7 @@ export class SimulationResultDriver {
await mainMenu.hide();
await screenshot(
animationChart,
screenshotPath(this.testCase, 'simulator-results-animation')
screenshotPath(this.testCase, 'simulator-results-animation'),
);
await mainMenu.show();
}
Expand All @@ -41,7 +44,7 @@ export class SimulationResultDriver {
await mainMenu.hide();
await screenshot(
summaryChart,
screenshotPath(this.testCase, 'simulator-results-summary')
screenshotPath(this.testCase, 'simulator-results-summary'),
);
await mainMenu.show();
}
Expand Down
11 changes: 7 additions & 4 deletions e2e/utils/strategy/EditStrategyDriver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from '@playwright/test';
import { Page } from 'playwright-core';
import { Page } from '@playwright/test';
import { MainMenuDriver } from '../MainMenuDriver';
import { screenshot, shouldTakeScreenshot, waitFor } from '../operators';
import { CreateStrategyTestCase, StrategyType } from './types';
Expand All @@ -15,7 +15,10 @@ import { waitTooltipsClose } from '../modal';
type EditType = 'deposit' | 'withdraw' | 'renew' | 'editPrices';

export class EditStrategyDriver {
constructor(private page: Page, private testCase: CreateStrategyTestCase) {}
constructor(
private page: Page,
private testCase: CreateStrategyTestCase,
) {}

async waitForPage(strategyType: StrategyType, editType: EditType) {
const options = { timeout: 10_000 };
Expand All @@ -34,7 +37,7 @@ export class EditStrategyDriver {
async waitForLoading() {
const loadings = await this.page.locator('.loading-message').all();
return Promise.all(
loadings.map((loading) => loading.waitFor({ state: 'detached' }))
loadings.map((loading) => loading.waitFor({ state: 'detached' })),
);
}

Expand Down Expand Up @@ -113,7 +116,7 @@ export class EditStrategyDriver {
direction: Direction,
setting: Setting,
order: MinMax,
type: EditType
type: EditType,
) {
const form = this.getPriceSection(direction);
await form.setting(setting).click();
Expand Down
2 changes: 1 addition & 1 deletion e2e/utils/strategy/ManageStrategyDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from './../../utils/DebugDriver';
import { navigateTo } from './../../utils/operators';
import { MyStrategyDriver } from './../../utils/strategy/MyStrategyDriver';
import { Page } from 'playwright-core';
import { Page } from '@playwright/test';
import { CreateStrategyTestCase } from './types';
import { PortfolioDriver } from './PortfolioDriver';

Expand Down
2 changes: 1 addition & 1 deletion e2e/utils/strategy/MyStrategyDriver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { waitFor } from './../../utils/operators';
import { Page } from 'playwright-core';
import { Page } from '@playwright/test';
import { Direction } from '../types';
import { MainMenuDriver } from '../MainMenuDriver';

Expand Down
Loading