Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Swap tests addition #29442

Merged
merged 3 commits into from
Jan 8, 2025
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
19 changes: 11 additions & 8 deletions test/e2e/playwright/shared/pageObjects/network-controller-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ export class NetworkController {

readonly dismissBtn: Locator;

readonly networkList: Locator;

readonly networkListEdit: Locator;

readonly rpcName: Locator;
Expand All @@ -39,9 +37,6 @@ export class NetworkController {
constructor(page: Page) {
this.page = page;
this.networkDisplay = this.page.getByTestId('network-display');
this.networkList = this.page.getByTestId(
'network-list-item-options-button-0x1',
);
this.networkListEdit = this.page.getByTestId(
'network-list-item-options-edit',
);
Expand Down Expand Up @@ -69,9 +64,14 @@ export class NetworkController {
}) {
let rpcName = options.name;
await this.networkDisplay.click();
if (options.name === Tenderly.Mainnet.name) {
if (
options.name === Tenderly.Mainnet.name ||
options.name === Tenderly.Linea.name
) {
rpcName = options.rpcName;
await this.networkList.click();
await this.page
.getByTestId(`network-list-item-options-button-${options.chainID}`)
.click();
await this.networkListEdit.click();
} else {
await this.addNetworkButton.click();
Expand All @@ -82,7 +82,10 @@ export class NetworkController {
await this.networkRpc.fill(options.url);
await this.rpcName.fill(rpcName);
await this.addURLBtn.click();
if (options.name !== Tenderly.Mainnet.name) {
if (
options.name !== Tenderly.Mainnet.name &&
options.name !== Tenderly.Linea.name
) {
await this.networkChainId.fill(options.chainID);
}
await this.networkTicker.fill(options.symbol);
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/playwright/shared/pageObjects/signup-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export class SignUpPage {

readonly skipSrpBackupBtn: Locator;

readonly popOverBtn: Locator;

constructor(page: Page) {
this.page = page;
this.getStartedBtn = page.locator('button:has-text("Get started")');
Expand Down Expand Up @@ -77,6 +79,7 @@ export class SignUpPage {
this.nextBtn = page.getByTestId('pin-extension-next');
this.agreeBtn = page.locator('button:has-text("I agree")');
this.enableBtn = page.locator('button:has-text("Enable")');
this.popOverBtn = page.getByTestId('popover-close');
}

async importWallet() {
Expand Down Expand Up @@ -114,5 +117,6 @@ export class SignUpPage {
await this.gotItBtn.click();
await this.nextBtn.click();
await this.doneBtn.click();
await this.popOverBtn.click();
}
}
9 changes: 7 additions & 2 deletions test/e2e/playwright/swap/pageObjects/swap-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ export class SwapPage {
);
}

async enterQuote(options: { from?: string; to: string; qty: string }) {
async enterQuote(options: {
from?: string;
to: string;
qty: string;
checkBalance: boolean;
}) {
// Enter source token
const native = await this.page.$(`text=/${options.from}/`);
if (!native && options.from) {
Expand All @@ -75,7 +80,7 @@ export class SwapPage {
.locator('[class*="balance"]')
.first()
.textContent();
if (balanceString) {
if (balanceString && options.checkBalance) {
if (parseFloat(balanceString.split(' ')[1]) <= parseFloat(options.qty)) {
await this.goBack();
// not enough balance so cancel out
Expand Down
55 changes: 48 additions & 7 deletions test/e2e/playwright/swap/specs/swap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let swapPage: SwapPage;
let networkController: NetworkController;
let walletPage: WalletPage;
let activityListPage: ActivityListPage;
let wallet: ethers.Wallet;

const testSet = [
{
Expand All @@ -23,6 +24,20 @@ const testSet = [
destination: 'DAI',
network: Tenderly.Mainnet,
},
{
quantity: '.5',
source: 'ETH',
type: 'native',
destination: 'DAI',
network: Tenderly.Linea,
},
{
quantity: '10',
source: 'DAI',
type: 'unapproved',
destination: 'USDC',
network: Tenderly.Linea,
},
{
quantity: '50',
source: 'DAI',
Expand Down Expand Up @@ -61,23 +76,48 @@ test.beforeAll(
const page = await extension.initExtension();
page.setDefaultTimeout(15000);

const wallet = ethers.Wallet.createRandom();
await addFundsToAccount(Tenderly.Mainnet.url, wallet.address);

const signUp = new SignUpPage(page);
await signUp.createWallet();

networkController = new NetworkController(page);
swapPage = new SwapPage(page);
activityListPage = new ActivityListPage(page);
walletPage = new WalletPage(page);

await networkController.addCustomNetwork(Tenderly.Mainnet);
await walletPage.importAccount(wallet.privateKey);
expect(walletPage.accountMenu).toHaveText('Account 2', { timeout: 30000 });
},
);

test(`Get quote on Mainnet Network`, async () => {
await walletPage.selectSwapAction();
await walletPage.page.waitForTimeout(3000);
chloeYue marked this conversation as resolved.
Show resolved Hide resolved
await swapPage.enterQuote({
from: 'ETH',
to: 'USDC',
qty: '.01',
checkBalance: false,
});
await walletPage.page.waitForTimeout(3000);
const quoteFound = await swapPage.waitForQuote();
expect(quoteFound).toBeTruthy();
await swapPage.goBack();
});

test(`Add Custom Networks and import test account`, async () => {
let response;
wallet = ethers.Wallet.createRandom();

response = await addFundsToAccount(Tenderly.Mainnet.url, wallet.address);
expect(response.error).toBeUndefined();

response = await addFundsToAccount(Tenderly.Linea.url, wallet.address);
expect(response.error).toBeUndefined();

await networkController.addCustomNetwork(Tenderly.Linea);
await networkController.addCustomNetwork(Tenderly.Mainnet);

await walletPage.importAccount(wallet.privateKey);
expect(walletPage.accountMenu).toHaveText('Account 2', { timeout: 30000 });
});

testSet.forEach((options) => {
test(`should swap ${options.type} token ${options.source} to ${options.destination} on ${options.network.name}'`, async () => {
await walletPage.selectTokenWallet();
Expand All @@ -94,6 +134,7 @@ testSet.forEach((options) => {
from: options.source,
to: options.destination,
qty: options.quantity,
checkBalance: true,
});

if (quoteEntered) {
Expand Down
16 changes: 9 additions & 7 deletions test/e2e/playwright/swap/tenderly-network.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import axios from 'axios';
import log from 'loglevel';

export const Tenderly = {
Mainnet: {
name: 'Ethereum Mainnet',
rpcName: 'Tenderly - Mainnet',
url: 'https://virtual.mainnet.rpc.tenderly.co/03bb8912-7505-4856-839f-52819a26d0cd',
chainID: '1',
chainID: '0x1',
symbol: 'ETH',
},
Optimism: {
Expand All @@ -23,6 +22,13 @@ export const Tenderly = {
chainID: '137',
symbol: 'ETH',
},
Linea: {
name: 'Linea',
rpcName: '',
url: 'https://virtual.linea.rpc.tenderly.co/2c429ceb-43db-45bc-9d84-21a40d21e0d2',
chainID: '0xe708',
symbol: 'ETH',
},
};

export async function addFundsToAccount(
Expand All @@ -42,9 +48,5 @@ export async function addFundsToAccount(
},
});

if (response.data.error) {
log.error(
`\tERROR: RROR: Failed to add funds to Tenderly VirtualTestNet\n${response.data.error}`,
);
}
return response.data;
}
Loading