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

fix: swaps test and others #4726

Merged
merged 1 commit into from
Dec 19, 2023
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
28 changes: 14 additions & 14 deletions tests/page-object-models/swap.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,22 @@ import { createTestSelector } from '@tests/utils';

export class SwapPage {
readonly page: Page;
readonly chooseAssetList: Locator;
readonly chooseAssetListItem: Locator;
readonly selectAssetBtn: Locator;
readonly swapAmountInput: Locator;
readonly swapBtn: Locator;
readonly swapDetailsAmount: Locator;
readonly swapDetailsProtocol: Locator;
readonly swapDetailsSymbol: Locator;
readonly swapReviewBtn: Locator;
readonly chooseAssetList = createTestSelector(SwapSelectors.ChooseAssetList);
readonly chooseAssetListItem = createTestSelector(SwapSelectors.ChooseAssetListItem);
readonly selectAssetBtn = createTestSelector(SwapSelectors.SelectAssetTriggerBtn);
readonly swapAmountInput = createTestSelector(SwapSelectors.SwapAmountInput);
readonly swapReviewBtn = createTestSelector(SwapSelectors.SwapReviewBtn);

constructor(page: Page) {
this.page = page;
this.chooseAssetList = page.getByTestId(SwapSelectors.ChooseAssetList);
this.chooseAssetListItem = page.getByTestId(SwapSelectors.ChooseAssetListItem);
this.selectAssetBtn = page.getByTestId(SwapSelectors.SelectAssetTriggerBtn);
this.swapAmountInput = page.getByTestId(SwapSelectors.SwapAmountInput);
this.swapBtn = page.getByTestId(SwapSelectors.SwapBtn);
this.swapDetailsAmount = page.getByTestId(SwapSelectors.SwapDetailsAmount);
this.swapDetailsProtocol = page.getByTestId(SwapSelectors.SwapDetailsProtocol);
this.swapDetailsSymbol = page.getByTestId(SwapSelectors.SwapDetailsSymbol);
this.swapReviewBtn = page.getByTestId(SwapSelectors.SwapReviewBtn);
}

async waitForSwapPageReady() {
Expand All @@ -34,11 +29,16 @@ export class SwapPage {
}

async selectAssetToReceive() {
const swapAssetSelectors = await this.selectAssetBtn.all();
const swapAssetSelectors = await this.page.locator(this.selectAssetBtn).all();
await swapAssetSelectors[1].click();
await this.chooseAssetList.waitFor();
const swapAssets = await this.chooseAssetListItem.all();
await this.page.locator(this.chooseAssetList).waitFor();
const swapAssets = await this.page.locator(this.chooseAssetListItem).all();
await swapAssets[0].click();
await this.swapReviewBtn.click();
await this.page.locator(this.swapReviewBtn).click();
}

async inputSwapAmountFrom() {
const swapAmountInputs = await this.page.locator(this.swapAmountInput).all();
await swapAmountInputs[0].fill('1');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ test.describe('Transaction signing', () => {
const multiSignatureTxHex = await generateMultisigUnsignedStxTransfer(
TEST_ACCOUNT_2_STX_ADDRESS,
amount,
100,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was failing bc the high fee warning popup was being triggered w/out a fee provided.

'mainnet',
[TEST_ACCOUNT_3_PUBKEY, TEST_ACCOUNT_1_PUBKEY],
2,
Expand Down
29 changes: 18 additions & 11 deletions tests/specs/swap/swap.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { test } from '../../fixtures/fixtures';

const alexSdkPostRoute = 'https://*.alexlab.co/v1/graphql';
const hiroApiPostRoute = '*/**/v2/transactions';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also possible to be specific to Hiro api origin, too?


test.describe('Swaps', () => {
test.beforeEach(async ({ extensionId, globalPage, homePage, onboardingPage, swapPage }) => {
await globalPage.setupAndUseApiCalls(extensionId);
await onboardingPage.signInWithTestAccount(extensionId);
await homePage.enableTestMode();
await homePage.swapButton.click();
await swapPage.waitForSwapPageReady();
});
Expand All @@ -16,8 +16,7 @@ test.describe('Swaps', () => {
});

test('that it shows correct swap review details', async ({ swapPage }) => {
const swapAmountInputs = await swapPage.swapAmountInput.all();
await swapAmountInputs[0].fill('1');
await swapPage.inputSwapAmountFrom();
await swapPage.selectAssetToReceive();

const swapProtocol = await swapPage.swapDetailsProtocol.innerText();
Expand All @@ -37,14 +36,22 @@ test.describe('Swaps', () => {
});

test('that the swap is broadcast', async ({ swapPage }) => {
const requestPromise = swapPage.page.waitForRequest(alexSdkPostRoute);

await swapPage.page.route(alexSdkPostRoute, async route => {
await route.abort();
});

const swapAmountInputs = await swapPage.swapAmountInput.all();
await swapAmountInputs[0].fill('1');
let requestPromise;
const isSponsoredSwap = swapPage.page.getByText('Sponsored');

if (isSponsoredSwap) {
requestPromise = swapPage.page.waitForRequest(alexSdkPostRoute);
await swapPage.page.route(alexSdkPostRoute, async route => {
await route.abort();
});
} else {
requestPromise = swapPage.page.waitForRequest(hiroApiPostRoute);
await swapPage.page.route(alexSdkPostRoute, async route => {
await route.abort();
});
}

await swapPage.inputSwapAmountFrom();
await swapPage.selectAssetToReceive();

await swapPage.swapBtn.click();
Expand Down
23 changes: 16 additions & 7 deletions tests/specs/transactions/transactions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ test.describe('Transaction signing', () => {

testAppPage = await TestAppPage.openDemoPage(context);
await testAppPage.signIn();
const accountsPage = await context.waitForEvent('page');
await accountsPage.locator('text="Account 1"').click();
await testAppPage.page.bringToFront();
await testAppPage.page.click('text=Debugger', {
timeout: 30000,
});
await accountsPage.close();
});

// These tests often break if ran in parallel
Expand All @@ -31,6 +24,14 @@ test.describe('Transaction signing', () => {
test('that it validates against insufficient funds when performing a contract call', async ({
context,
}) => {
const accountsPage = await context.waitForEvent('page');
await accountsPage.locator('text="Account 2"').click();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Account 1 in the test account doesn't have a 0 balance atm so this was failing.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we fill it up instead of making this change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem was Account 1 has funds so clicking on Account 2 which doesn't solves it

await testAppPage.page.bringToFront();
await testAppPage.page.click('text=Debugger', {
timeout: 30000,
});
await accountsPage.close();

await testAppPage.clickContractCallButton();
const transactionRequestPage = new TransactionRequestPage(await context.waitForEvent('page'));
const error =
Expand All @@ -42,6 +43,14 @@ test.describe('Transaction signing', () => {

test.describe('App initiated STX transfer', () => {
test('that it broadcasts correctly with given fee and amount', async ({ context }) => {
const accountsPage = await context.waitForEvent('page');
await accountsPage.locator('text="Account 1"').click();
await testAppPage.page.bringToFront();
await testAppPage.page.click('text=Debugger', {
timeout: 30000,
});
await accountsPage.close();

await testAppPage.clickStxTransferButton();
const transactionRequestPage = new TransactionRequestPage(await context.waitForEvent('page'));

Expand Down
2 changes: 2 additions & 0 deletions tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export async function generateUnsignedStxTransfer(
export async function generateMultisigUnsignedStxTransfer(
recipient: string,
amount: number,
fee: number,
network: any,
publicKeys: string[],
threshold: number,
Expand All @@ -53,6 +54,7 @@ export async function generateMultisigUnsignedStxTransfer(
memo?: string
) {
const options = {
fee,
recipient,
memo,
publicKeys,
Expand Down
Loading