mirror of
https://github.com/zhigang1992/xverse-web-extension.git
synced 2026-04-30 05:35:53 +08:00
Add Swapping flow and rename files
This commit is contained in:
@@ -15,7 +15,9 @@ test.describe('Swap Flow Exchange', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('Exchange token via DotSwap testnet', async ({ page, extensionId }) => {
|
||||
const marketplace = 'DotSwap';
|
||||
|
||||
test('Exchange token via DotSwap with standard fee testnet', async ({ page, extensionId }) => {
|
||||
// Restore wallet and setup Testnet network
|
||||
const wallet = new Wallet(page);
|
||||
await wallet.setupTest(extensionId, 'SEED_WORDS1', true);
|
||||
@@ -29,9 +31,6 @@ test.describe('Swap Flow Exchange', () => {
|
||||
|
||||
await wallet.checkVisualsStartpage();
|
||||
|
||||
// Save initial Balance for later Balance checks
|
||||
const initialBTCBalance = await wallet.getTokenBalance('Bitcoin');
|
||||
|
||||
await wallet.allUpperButtons.nth(2).click();
|
||||
await wallet.checkVisualsSwapPage();
|
||||
|
||||
@@ -74,7 +73,8 @@ test.describe('Swap Flow Exchange', () => {
|
||||
const numericQuoteValue = parseFloat(quoteAmount.replace(/[^0-9.]/g, ''));
|
||||
await expect(numericQuoteValue).toBeGreaterThan(0);
|
||||
|
||||
await wallet.buttonSwapPlace.first().click();
|
||||
// Click on DotSwap
|
||||
await wallet.buttonSwapPlace.filter({ hasText: marketplace }).click();
|
||||
|
||||
await wallet.checkVisualsQuotePage(tokenName1, true, numericQuoteValue, numericUSDValue);
|
||||
|
||||
@@ -86,32 +86,13 @@ test.describe('Swap Flow Exchange', () => {
|
||||
const numericOriginalFee = parseFloat(originalFee.replace(/[^0-9.]/g, ''));
|
||||
await expect(numericOriginalFee).toBeGreaterThan(0);
|
||||
|
||||
// Click on edit Fee button
|
||||
await wallet.buttonEditFee.click();
|
||||
await expect(wallet.buttonSelectFee.first()).toBeVisible();
|
||||
await expect(wallet.labelTotalFee.first()).toBeVisible();
|
||||
|
||||
// Compare medium fee to previous saved fee
|
||||
const mediumFee = await wallet.labelTotalFee.last().innerText();
|
||||
const numericMediumFee = parseFloat(mediumFee.replace(/[^0-9.]/g, ''));
|
||||
await expect(numericMediumFee).toBe(numericOriginalFee);
|
||||
|
||||
// Save high fee rate for comparison
|
||||
const highFee = await wallet.labelTotalFee.first().innerText();
|
||||
const numericHighFee = parseFloat(highFee.replace(/[^0-9.]/g, ''));
|
||||
|
||||
// Switch to high fee
|
||||
await wallet.buttonSelectFee.first().click();
|
||||
|
||||
const newFee = await wallet.feeAmount.innerText();
|
||||
const numericNewFee = parseFloat(newFee.replace(/[^0-9.]/g, ''));
|
||||
await expect(numericNewFee).toBe(numericHighFee);
|
||||
|
||||
await wallet.buttonSwap.click();
|
||||
await wallet.checkVisualsSendTransactionReview('swap', false, selfBTC);
|
||||
|
||||
// second confirm-balance is the same as swapAmount
|
||||
const swapSendAmount = await wallet.confirmBalance.last().innerText();
|
||||
// Confirm Amount is the same as swapAmount
|
||||
const swapSendAmount = await wallet.confirmAmount
|
||||
.filter({ hasText: swapAmount.toString() })
|
||||
.innerText();
|
||||
const numericValueSwap = parseFloat(swapSendAmount.replace(/[^0-9.]/g, ''));
|
||||
await expect(numericValueSwap).toEqual(swapAmount);
|
||||
|
||||
@@ -15,6 +15,8 @@ test.describe('Swap Flow Exchange', () => {
|
||||
});
|
||||
});
|
||||
|
||||
const marketplace = 'DotSwap';
|
||||
|
||||
test('Cancel exchange token via DotSwap', async ({ page, extensionId }) => {
|
||||
// Restore wallet and setup Testnet network
|
||||
const wallet = new Wallet(page);
|
||||
@@ -74,7 +76,8 @@ test.describe('Swap Flow Exchange', () => {
|
||||
const numericQuoteValue = parseFloat(quoteAmount.replace(/[^0-9.]/g, ''));
|
||||
await expect(numericQuoteValue).toBeGreaterThan(0);
|
||||
|
||||
await wallet.buttonSwapPlace.first().click();
|
||||
// Click on DotSwap
|
||||
await wallet.buttonSwapPlace.filter({ hasText: marketplace }).click();
|
||||
|
||||
await wallet.checkVisualsQuotePage(tokenName1, true, numericQuoteValue, numericUSDValue);
|
||||
|
||||
@@ -110,8 +113,12 @@ test.describe('Swap Flow Exchange', () => {
|
||||
await wallet.buttonSwap.click();
|
||||
await wallet.checkVisualsSendTransactionReview('swap', false, selfBTC);
|
||||
|
||||
// second confirm-balance is the same as swapAmount
|
||||
const swapSendAmount = await wallet.confirmBalance.last().innerText();
|
||||
await expect(await wallet.confirmAmount.count()).toBeGreaterThan(3);
|
||||
|
||||
// Confirm Amount is the same as swapAmount
|
||||
const swapSendAmount = await wallet.confirmAmount
|
||||
.filter({ hasText: swapAmount.toString() })
|
||||
.innerText();
|
||||
const numericValueSwap = parseFloat(swapSendAmount.replace(/[^0-9.]/g, ''));
|
||||
await expect(numericValueSwap).toEqual(swapAmount);
|
||||
|
||||
115
tests/specs/swapME.spec.ts
Normal file
115
tests/specs/swapME.spec.ts
Normal file
@@ -0,0 +1,115 @@
|
||||
import { expect, test } from '../fixtures/base';
|
||||
import Wallet from '../pages/wallet';
|
||||
|
||||
test.describe('Swap Flow ME', () => {
|
||||
// Enables the feature flag for Swap
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.route('https://api-3.xverse.app/v1/app-features', (route) => {
|
||||
route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
CROSS_CHAIN_SWAPS: { enabled: true },
|
||||
}),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const marketplace = 'Magic Eden';
|
||||
|
||||
test('Swap token via ME with standard fee mainnet', async ({ page, extensionId }) => {
|
||||
// Restore wallet and setup Testnet network
|
||||
const wallet = new Wallet(page);
|
||||
await wallet.setupTest(extensionId, 'SEED_WORDS1', false);
|
||||
|
||||
// get own BTC & Ordinals Address for address check on review page
|
||||
await wallet.allUpperButtons.nth(1).click();
|
||||
const selfBTC = await wallet.getAddress(wallet.buttonCopyBitcoinAddress);
|
||||
|
||||
// Reload the page to close the modal window for the addresses as the X button needs to have a better locator
|
||||
await page.reload();
|
||||
|
||||
await wallet.checkVisualsStartpage();
|
||||
|
||||
await wallet.allUpperButtons.nth(2).click();
|
||||
await wallet.checkVisualsSwapPage();
|
||||
|
||||
// Select the first Coin
|
||||
await wallet.buttonDownArrow.nth(0).click();
|
||||
|
||||
// Had problems with loading of all tokens so I check that 'Bitcoin' is loaded
|
||||
await expect(wallet.labelTokenSubtitle.getByText('Bitcoin').first()).toBeVisible();
|
||||
await expect(await wallet.divTokenRow.count()).toBeGreaterThan(0);
|
||||
await wallet.divTokenRow.first().click();
|
||||
await expect(wallet.nameToken.first()).not.toContainText('Select asset');
|
||||
await expect(wallet.imageToken.first()).toBeVisible();
|
||||
await expect(wallet.buttonGetQuotes).toBeDisabled();
|
||||
|
||||
// Select the second Coin
|
||||
await wallet.buttonDownArrow.nth(1).click();
|
||||
// Had problems with loading of all tokens so I check that a 'DOG' is loaded
|
||||
await expect(wallet.labelTokenSubtitle.getByText('DOG').first()).toBeVisible();
|
||||
await expect(await wallet.divTokenRow.count()).toBeGreaterThan(0);
|
||||
await wallet.divTokenRow.first().click();
|
||||
await expect(wallet.nameToken.last()).not.toContainText('Select asset');
|
||||
await expect(wallet.imageToken.last()).toBeVisible();
|
||||
await expect(wallet.buttonGetQuotes).toBeDisabled();
|
||||
|
||||
// tried a calculated value but had multiple problems with that, for now we stick to a specific value
|
||||
const swapAmount = 0.00000546;
|
||||
|
||||
await wallet.fillSwapAmount(swapAmount);
|
||||
|
||||
// Save rune token name
|
||||
const tokenName1 = await wallet.nameToken.last().innerText();
|
||||
|
||||
await wallet.buttonGetQuotes.click();
|
||||
await expect(wallet.nameSwapPlace.last()).toBeVisible();
|
||||
await expect(wallet.quoteAmount.last()).toBeVisible();
|
||||
await expect(wallet.infoMessage.last()).toBeVisible();
|
||||
await expect(wallet.buttonSwapPlace.last()).toBeVisible();
|
||||
|
||||
await wallet.buttonSwapPlace.filter({ hasText: marketplace }).click();
|
||||
await expect(wallet.itemUTXO.first()).toBeVisible();
|
||||
|
||||
// click only on a UTXO with value from 1000 e(not enough funds for higher)
|
||||
await wallet.itemUTXO.filter({ hasText: '1,000' }).first().locator('input').click();
|
||||
await expect(wallet.buttonNext).toBeVisible();
|
||||
await expect(wallet.textUSD).toBeVisible();
|
||||
await expect(wallet.quoteAmount).toBeVisible();
|
||||
|
||||
const quoteAmount = await wallet.quoteAmount.innerText();
|
||||
const numericQuoteValue = parseFloat(quoteAmount.replace(/[^0-9.]/g, ''));
|
||||
await expect(numericQuoteValue).toBeGreaterThan(0);
|
||||
|
||||
const usdAmount = await wallet.textUSD.innerText();
|
||||
const numericUSDValueSwap = parseFloat(usdAmount.replace(/[^0-9.]/g, ''));
|
||||
await expect(numericUSDValueSwap).toBeGreaterThan(0);
|
||||
|
||||
await wallet.buttonNext.click();
|
||||
|
||||
await wallet.checkVisualsQuotePage(tokenName1, false, numericQuoteValue, numericUSDValueSwap);
|
||||
|
||||
// We can only continue if the FeeRate is above 0
|
||||
await wallet.waitForTextAboveZero(wallet.feeAmount, 30000);
|
||||
|
||||
// Save the current fee amount for comparison
|
||||
const originalFee = await wallet.feeAmount.innerText();
|
||||
const numericOriginalFee = parseFloat(originalFee.replace(/[^0-9.]/g, ''));
|
||||
await expect(numericOriginalFee).toBeGreaterThan(0);
|
||||
|
||||
await wallet.buttonSwap.click();
|
||||
await wallet.checkVisualsSendTransactionReview('swap', false, selfBTC);
|
||||
|
||||
const sendRuneAmount = await wallet.sendRuneAmount.innerText();
|
||||
const sendAmountNumerical = parseFloat(sendRuneAmount.replace(/[^0-9.]/g, ''));
|
||||
await expect(numericQuoteValue).toEqual(sendAmountNumerical);
|
||||
|
||||
// Check Rune token name
|
||||
await expect(wallet.nameRune).toContainText(tokenName1);
|
||||
|
||||
await wallet.confirmSendTransaction();
|
||||
await wallet.checkVisualsStartpage();
|
||||
// TODO: locally check if transaction was successful, might need to wait for transaction to be processed
|
||||
});
|
||||
});
|
||||
@@ -15,6 +15,8 @@ test.describe('Swap Flow ME', () => {
|
||||
});
|
||||
});
|
||||
|
||||
const marketplace = 'Magic Eden';
|
||||
|
||||
test('Cancel swap token via ME', async ({ page, extensionId }) => {
|
||||
// Restore wallet and setup Testnet network
|
||||
const wallet = new Wallet(page);
|
||||
@@ -59,7 +61,7 @@ test.describe('Swap Flow ME', () => {
|
||||
// tried a calculated value but had multiple problems with that, for now we stick to a specific value
|
||||
const swapAmount = 0.00000546;
|
||||
|
||||
const numericUSDValue = await wallet.fillSwapAmount(swapAmount);
|
||||
await wallet.fillSwapAmount(swapAmount);
|
||||
|
||||
// Save rune token name
|
||||
const tokenName1 = await wallet.nameToken.last().innerText();
|
||||
@@ -70,7 +72,7 @@ test.describe('Swap Flow ME', () => {
|
||||
await expect(wallet.infoMessage.last()).toBeVisible();
|
||||
await expect(wallet.buttonSwapPlace.last()).toBeVisible();
|
||||
|
||||
await wallet.buttonSwapPlace.filter({ hasText: 'Magic Eden' }).click();
|
||||
await wallet.buttonSwapPlace.filter({ hasText: marketplace }).click();
|
||||
await expect(wallet.itemUTXO.first()).toBeVisible();
|
||||
|
||||
// click only on a UTXO with value from 1000 e(not enough funds for higher)
|
||||
@@ -18,7 +18,7 @@ test.describe('Swap Flow Visuals', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('Visual check swap page', async ({ page, extensionId }) => {
|
||||
test('Check swap page', async ({ page, extensionId }) => {
|
||||
const onboardingPage = new Onboarding(page);
|
||||
const wallet = new Wallet(page);
|
||||
await onboardingPage.createWalletSkipBackup(strongPW);
|
||||
Reference in New Issue
Block a user