From 10b47b9c49993e5f0985ccb753e62d7e8833f837 Mon Sep 17 00:00:00 2001 From: maybeast <78227110+maybeast@users.noreply.github.com> Date: Thu, 1 Aug 2024 15:19:06 +0300 Subject: [PATCH] enable firefox --- e2e/reverseSwap.spec.ts | 100 ++++++++++++++++++++++++---------------- e2e/utils.ts | 21 ++++++--- package.json | 4 +- playwright.config.ts | 51 +++++--------------- 4 files changed, 88 insertions(+), 88 deletions(-) diff --git a/e2e/reverseSwap.spec.ts b/e2e/reverseSwap.spec.ts index 5f9dbe7e..cce23ba3 100644 --- a/e2e/reverseSwap.spec.ts +++ b/e2e/reverseSwap.spec.ts @@ -1,40 +1,62 @@ -import { test, expect } from '@playwright/test'; -import { getBitcoinAddress, getBitcoinWalletTx, payInvoiceLnd } from "./utils"; - -test('Reverse swap BTC/BTC', async ({ page }) => { - await page.goto('https://localhost:5173'); - - const receiveAmount = "0.01"; - const inputReceiveAmount = page.locator("input[data-testid='receiveAmount']"); - await inputReceiveAmount.fill(receiveAmount); - - const inputSendAmount = page.locator("input[data-testid='sendAmount']"); - await expect(inputSendAmount).toHaveValue('0.01005558'); - - const inputOnchainAddress = page.locator("input[data-testid='onchainAddress']"); - await inputOnchainAddress.fill(await getBitcoinAddress()); - - const buttonCreateSwap = page.locator("button[data-testid='create-swap-button']"); - await buttonCreateSwap.click(); - - const payInvoiceTitle = page.locator("h2[data-testid='pay-invoice-title']"); - await expect(payInvoiceTitle).toHaveText("Pay this invoice about 0.01005558 BTC"); - - const spanLightningInvoice = page.locator("span[class='btn']"); - await spanLightningInvoice.click(); - - const lightningInvoice = await page.evaluate(() => { - return navigator.clipboard.readText(); - }); - expect(lightningInvoice).toBeDefined(); - - await payInvoiceLnd(lightningInvoice) - - const txIdLink = page.getByText("open claim transaction"); - - const txId = (await txIdLink.getAttribute("href")).split("/").pop(); - expect(txId).toBeDefined(); - - const txInfo = JSON.parse(await getBitcoinWalletTx(txId)); - expect(txInfo.amount.toString()).toEqual(receiveAmount); +import { expect, test } from "@playwright/test"; + +import { + generateBitcoinBlock, + getBitcoinAddress, + getBitcoinWalletTx, + payInvoiceLnd, +} from "./utils"; + +test.describe("reverseSwap", () => { + test.beforeEach(async () => { + await generateBitcoinBlock(); + }); + + test("Reverse swap BTC/BTC", async ({ page }) => { + await page.goto("/"); + + const receiveAmount = "0.01"; + const inputReceiveAmount = page.locator( + "input[data-testid='receiveAmount']", + ); + await inputReceiveAmount.fill(receiveAmount); + + const inputSendAmount = page.locator("input[data-testid='sendAmount']"); + await expect(inputSendAmount).toHaveValue("0.01005558"); + + const inputOnchainAddress = page.locator( + "input[data-testid='onchainAddress']", + ); + await inputOnchainAddress.fill(await getBitcoinAddress()); + + const buttonCreateSwap = page.locator( + "button[data-testid='create-swap-button']", + ); + await buttonCreateSwap.click(); + + const payInvoiceTitle = page.locator( + "h2[data-testid='pay-invoice-title']", + ); + await expect(payInvoiceTitle).toHaveText( + "Pay this invoice about 0.01005558 BTC", + ); + + const spanLightningInvoice = page.locator("span[class='btn']"); + await spanLightningInvoice.click(); + + const lightningInvoice = await page.evaluate(() => { + return navigator.clipboard.readText(); + }); + expect(lightningInvoice).toBeDefined(); + + await payInvoiceLnd(lightningInvoice); + + const txIdLink = page.getByText("open claim transaction"); + + const txId = (await txIdLink.getAttribute("href")).split("/").pop(); + expect(txId).toBeDefined(); + + const txInfo = JSON.parse(await getBitcoinWalletTx(txId)); + expect(txInfo.amount.toString()).toEqual(receiveAmount); + }); }); diff --git a/e2e/utils.ts b/e2e/utils.ts index 324b6004..abc01e25 100644 --- a/e2e/utils.ts +++ b/e2e/utils.ts @@ -1,14 +1,17 @@ -import { exec } from 'child_process'; -import { promisify } from 'util'; +import { exec } from "child_process"; +import { promisify } from "util"; const execAsync = promisify(exec); -const executeInScriptsContainer = 'docker exec boltz-scripts bash -c "source /etc/profile.d/utils.sh && '; +const executeInScriptsContainer = + 'docker exec boltz-scripts bash -c "source /etc/profile.d/utils.sh && '; const execCommand = async (command: string): Promise => { try { - - const { stdout, stderr } = await execAsync(`${executeInScriptsContainer}${command}"`, { shell: '/bin/bash' }); + const { stdout, stderr } = await execAsync( + `${executeInScriptsContainer}${command}"`, + { shell: "/bin/bash" }, + ); if (stderr) { throw new Error(`Error executing command: ${stderr}`); @@ -22,12 +25,16 @@ const execCommand = async (command: string): Promise => { }; export const getBitcoinAddress = async (): Promise => { - return execCommand('bitcoin-cli-sim-client getnewaddress'); + return execCommand("bitcoin-cli-sim-client getnewaddress"); +}; + +export const generateBitcoinBlock = async (): Promise => { + return execCommand("bitcoin-cli-sim-client -generate"); }; export const getBitcoinWalletTx = async (txId: string): Promise => { return execCommand(`bitcoin-cli-sim-client gettransaction ${txId}`); -} +}; export const payInvoiceLnd = async (invoice: string): Promise => { return execCommand(`lncli-sim 1 payinvoice -f ${invoice}`); diff --git a/package.json b/package.json index e5babd8f..8912b574 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,8 @@ "mainnet": "cp src/configs/mainnet.json public/config.json", "beta": "cp src/configs/beta.json public/config.json", "testnet": "cp src/configs/testnet.json public/config.json", - "prettier": "prettier --write src tests", - "prettier-check": "prettier --check src tests", + "prettier": "prettier --write src tests e2e", + "prettier-check": "prettier --check src tests e2e", "tsc": "tsc", "changelog": "git-cliff -o CHANGELOG.md" }, diff --git a/playwright.config.ts b/playwright.config.ts index 84e962dc..66932ed1 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,12 +1,5 @@ import { defineConfig, devices } from '@playwright/test'; -/** - * Read environment variables from file. - * https://github.com/motdotla/dotenv - */ -// import dotenv from 'dotenv'; -// dotenv.config({ path: path.resolve(__dirname, '.env') }); - /** * See https://playwright.dev/docs/test-configuration. */ @@ -25,59 +18,37 @@ export default defineConfig({ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { /* Base URL to use in actions like `await page.goto('/')`. */ - // baseURL: 'http://127.0.0.1:3000', + baseURL: 'https://localhost:4173', ignoreHTTPSErrors: true, /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - headless: true, + headless: false, trace: 'on-first-retry', - permissions: ["clipboard-read", "clipboard-write"], }, /* Configure projects for major browsers */ projects: [ { name: 'chromium', - use: { ...devices['Desktop Chrome'] }, + use: { + ...devices['Desktop Chrome'], + contextOptions: { + // chromium-specific permissions + permissions: ['clipboard-read', 'clipboard-write'], + }, + }, }, - /* gfy { name: 'firefox', use: { ...devices['Desktop Firefox'] }, }, - - { - name: 'webkit', - use: { ...devices['Desktop Safari'] }, - }, - */ - - /* Test against mobile viewports. */ - // { - // name: 'Mobile Chrome', - // use: { ...devices['Pixel 5'] }, - // }, - // { - // name: 'Mobile Safari', - // use: { ...devices['iPhone 12'] }, - // }, - - /* Test against branded browsers. */ - // { - // name: 'Microsoft Edge', - // use: { ...devices['Desktop Edge'], channel: 'msedge' }, - // }, - // { - // name: 'Google Chrome', - // use: { ...devices['Desktop Chrome'], channel: 'chrome' }, - // }, ], /* Run your local dev server before starting the tests */ webServer: { - command: 'npm run start', - port: 5173, + command: 'npm run build && npm run preview', + port: 4173, reuseExistingServer: !process.env.CI, stdout: 'pipe', stderr: 'pipe',