Skip to content

Commit

Permalink
submarine and chain swaps
Browse files Browse the repository at this point in the history
  • Loading branch information
maybeast committed Aug 1, 2024
1 parent 8da1bbf commit ab027f9
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 0 deletions.
60 changes: 60 additions & 0 deletions e2e/chainSwaps.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
55 changes: 55 additions & 0 deletions e2e/submarineSwap.spec.ts
Original file line number Diff line number Diff line change
@@ -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
});
});
26 changes: 26 additions & 0 deletions e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,40 @@ export const getBitcoinAddress = async (): Promise<string> => {
return execCommand("bitcoin-cli-sim-client getnewaddress");
};

export const bitcoinSendToAddress = async (
address: string,
amount: string,
): Promise<string> => {
return execCommand(
`bitcoin-cli-sim-client sendtoaddress "${address}" ${amount}`,
);
};

export const elementsSendToAddress = async (
address: string,
amount: string,
): Promise<string> => {
return execCommand(
`elements-cli-sim-client sendtoaddress "${address}" ${amount}`,
);
};

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

export const generateLiquidBlock = async (): Promise<string> => {
return execCommand("elements-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}`);
};

export const generateInvoiceLnd = async (amount: number): Promise<string> => {
return execCommand(`lncli-sim 1 addinvoice --amt ${amount}`);
};
2 changes: 2 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ export default defineConfig({
},
},

/*
{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},
*/
],

/* Run your local dev server before starting the tests */
Expand Down

0 comments on commit ab027f9

Please sign in to comment.