Skip to content

Commit

Permalink
enable firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
maybeast committed Aug 1, 2024
1 parent 8c1da4f commit 10b47b9
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 88 deletions.
100 changes: 61 additions & 39 deletions e2e/reverseSwap.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
21 changes: 14 additions & 7 deletions e2e/utils.ts
Original file line number Diff line number Diff line change
@@ -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<string> => {
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}`);
Expand All @@ -22,12 +25,16 @@ const execCommand = async (command: string): Promise<string> => {
};

export const getBitcoinAddress = async (): Promise<string> => {
return execCommand('bitcoin-cli-sim-client getnewaddress');
return execCommand("bitcoin-cli-sim-client getnewaddress");
};

export const generateBitcoinBlock = async (): Promise<string> => {
return execCommand("bitcoin-cli-sim-client -generate");
};

export const getBitcoinWalletTx = async (txId: string): Promise<string> => {
return execCommand(`bitcoin-cli-sim-client gettransaction ${txId}`);
}
};

export const payInvoiceLnd = async (invoice: string): Promise<string> => {
return execCommand(`lncli-sim 1 payinvoice -f ${invoice}`);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
51 changes: 11 additions & 40 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand All @@ -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',
Expand Down

0 comments on commit 10b47b9

Please sign in to comment.