From bc31a42097c2614cd028054374381f1d372c2d0d Mon Sep 17 00:00:00 2001 From: Fara Woolf Date: Mon, 18 Dec 2023 17:40:53 -0600 Subject: [PATCH] fix: swaps test, ref #4725 --- tests/page-object-models/swap.page.ts | 28 +++++++++--------- .../transaction-signing.spec.ts | 1 + tests/specs/swap/swap.spec.ts | 29 ++++++++++++------- tests/specs/transactions/transactions.spec.ts | 23 ++++++++++----- tests/utils.ts | 2 ++ 5 files changed, 51 insertions(+), 32 deletions(-) diff --git a/tests/page-object-models/swap.page.ts b/tests/page-object-models/swap.page.ts index 4ccad05b853..fc79e698690 100644 --- a/tests/page-object-models/swap.page.ts +++ b/tests/page-object-models/swap.page.ts @@ -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() { @@ -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'); } } diff --git a/tests/specs/rpc-stacks-transaction/transaction-signing.spec.ts b/tests/specs/rpc-stacks-transaction/transaction-signing.spec.ts index bde52856f5f..b5eefa57cf0 100644 --- a/tests/specs/rpc-stacks-transaction/transaction-signing.spec.ts +++ b/tests/specs/rpc-stacks-transaction/transaction-signing.spec.ts @@ -53,6 +53,7 @@ test.describe('Transaction signing', () => { const multiSignatureTxHex = await generateMultisigUnsignedStxTransfer( TEST_ACCOUNT_2_STX_ADDRESS, amount, + 100, 'mainnet', [TEST_ACCOUNT_3_PUBKEY, TEST_ACCOUNT_1_PUBKEY], 2, diff --git a/tests/specs/swap/swap.spec.ts b/tests/specs/swap/swap.spec.ts index 66e4c44747b..ede953fa972 100644 --- a/tests/specs/swap/swap.spec.ts +++ b/tests/specs/swap/swap.spec.ts @@ -1,12 +1,12 @@ import { test } from '../../fixtures/fixtures'; const alexSdkPostRoute = 'https://*.alexlab.co/v1/graphql'; +const hiroApiPostRoute = '*/**/v2/transactions'; 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(); }); @@ -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(); @@ -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(); diff --git a/tests/specs/transactions/transactions.spec.ts b/tests/specs/transactions/transactions.spec.ts index 3d37d04f9d3..612750835af 100644 --- a/tests/specs/transactions/transactions.spec.ts +++ b/tests/specs/transactions/transactions.spec.ts @@ -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 @@ -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(); + 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 = @@ -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')); diff --git a/tests/utils.ts b/tests/utils.ts index 4fd69f04390..26fa7d87fdf 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -45,6 +45,7 @@ export async function generateUnsignedStxTransfer( export async function generateMultisigUnsignedStxTransfer( recipient: string, amount: number, + fee: number, network: any, publicKeys: string[], threshold: number, @@ -53,6 +54,7 @@ export async function generateMultisigUnsignedStxTransfer( memo?: string ) { const options = { + fee, recipient, memo, publicKeys,