diff --git a/e2e/chainSwaps.spec.ts b/e2e/chainSwaps.spec.ts new file mode 100644 index 00000000..970dbc1e --- /dev/null +++ b/e2e/chainSwaps.spec.ts @@ -0,0 +1,60 @@ +import { expect, test } from "@playwright/test"; + +import { + elementsSendToAddress, + generateBitcoinBlock, + generateLiquidBlock, + getBitcoinAddress, +} from "./utils"; + +test.describe("Chain swap", () => { + test.beforeEach(async () => { + await generateBitcoinBlock(); + }); + + test("BTC/L-BTC", async ({ page }) => { + await page.goto("/"); + + const assetSelector = page.locator("div[class='asset asset-LN'] div"); + await assetSelector.click(); + + const lbtcAsset = page.locator("div[data-testid='select-L-BTC']"); + await lbtcAsset.click(); + + const receiveAmount = "0.01"; + const inputReceiveAmount = page.locator( + "input[data-testid='receiveAmount']", + ); + await inputReceiveAmount.fill(receiveAmount); + + const inputSendAmount = page.locator("input[data-testid='sendAmount']"); + const sendAmount = "0.0100168"; + await expect(inputSendAmount).toHaveValue(sendAmount); + + 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 skipDownload = page.getByText("Skip download"); + await skipDownload.click(); + + const buttons = page.locator("div[data-testid='pay-onchain-buttons']"); + const copyAddressButton = buttons.getByText("address"); + expect(copyAddressButton).toBeDefined(); + await copyAddressButton.click(); + + const sendAddress = await page.evaluate(() => { + return navigator.clipboard.readText(); + }); + expect(sendAddress).toBeDefined(); + + await elementsSendToAddress(sendAddress, sendAmount); + await generateLiquidBlock(); + }); +}); diff --git a/e2e/submarineSwap.spec.ts b/e2e/submarineSwap.spec.ts new file mode 100644 index 00000000..c237da1f --- /dev/null +++ b/e2e/submarineSwap.spec.ts @@ -0,0 +1,55 @@ +import { expect, test } from "@playwright/test"; + +import { + bitcoinSendToAddress, + generateBitcoinBlock, + generateInvoiceLnd, +} from "./utils"; + +test.describe("Submarine swap", () => { + test.beforeEach(async () => { + await generateBitcoinBlock(); + }); + + test("Submarine swap BTC/BTC", async ({ page }) => { + await page.goto("/"); + + const divFlipAssets = page.locator("#flip-assets"); + await divFlipAssets.click(); + + const receiveAmount = "0.01"; + const inputReceiveAmount = page.locator( + "input[data-testid='receiveAmount']", + ); + await inputReceiveAmount.fill(receiveAmount); + + const inputSendAmount = page.locator("input[data-testid='sendAmount']"); + const sendAmount = "0.01005302"; + await expect(inputSendAmount).toHaveValue(sendAmount); + + const invoiceInput = page.locator("textarea[data-testid='invoice']"); + await invoiceInput.fill( + JSON.parse(await generateInvoiceLnd(1000000)).payment_request, + ); + const buttonCreateSwap = page.locator( + "button[data-testid='create-swap-button']", + ); + await buttonCreateSwap.click(); + + const skipDownload = page.getByText("Skip download"); + await skipDownload.click(); + + const copyAddressButton = page.getByText("address"); + expect(copyAddressButton).toBeDefined(); + await copyAddressButton.click(); + + const sendAddress = await page.evaluate(() => { + return navigator.clipboard.readText(); + }); + expect(sendAddress).toBeDefined(); + await bitcoinSendToAddress(sendAddress, sendAmount); + + await generateBitcoinBlock(); + // TODO: verify amounts + }); +}); diff --git a/e2e/utils.ts b/e2e/utils.ts index abc01e25..15a5caa7 100644 --- a/e2e/utils.ts +++ b/e2e/utils.ts @@ -28,10 +28,32 @@ export const getBitcoinAddress = async (): Promise => { return execCommand("bitcoin-cli-sim-client getnewaddress"); }; +export const bitcoinSendToAddress = async ( + address: string, + amount: string, +): Promise => { + return execCommand( + `bitcoin-cli-sim-client sendtoaddress "${address}" ${amount}`, + ); +}; + +export const elementsSendToAddress = async ( + address: string, + amount: string, +): Promise => { + return execCommand( + `elements-cli-sim-client sendtoaddress "${address}" ${amount}`, + ); +}; + export const generateBitcoinBlock = async (): Promise => { return execCommand("bitcoin-cli-sim-client -generate"); }; +export const generateLiquidBlock = async (): Promise => { + return execCommand("elements-cli-sim-client -generate"); +}; + export const getBitcoinWalletTx = async (txId: string): Promise => { return execCommand(`bitcoin-cli-sim-client gettransaction ${txId}`); }; @@ -39,3 +61,7 @@ export const getBitcoinWalletTx = async (txId: string): Promise => { export const payInvoiceLnd = async (invoice: string): Promise => { return execCommand(`lncli-sim 1 payinvoice -f ${invoice}`); }; + +export const generateInvoiceLnd = async (amount: number): Promise => { + return execCommand(`lncli-sim 1 addinvoice --amt ${amount}`); +}; diff --git a/playwright.config.ts b/playwright.config.ts index ae8508d9..d1595345 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -39,10 +39,12 @@ export default defineConfig({ }, }, + /* { name: 'firefox', use: { ...devices['Desktop Firefox'] }, }, + */ ], /* Run your local dev server before starting the tests */