|
| 1 | +import { test, expect, createWallet, readClipboard, waitForPaymentReceived } from './utils' |
| 2 | +import { isValidLnUrl, checkLnUrlConditions, fetchInvoice } from '../../lib/lnurl' |
| 3 | +import { decodeInvoice } from '../../lib/bolt11' |
| 4 | +import { exec } from 'child_process' |
| 5 | +import { promisify } from 'util' |
| 6 | + |
| 7 | +const execAsync = promisify(exec) |
| 8 | + |
| 9 | +test('should have lnurl with no amount', async ({ page }) => { |
| 10 | + // create wallet |
| 11 | + await createWallet(page) |
| 12 | + |
| 13 | + // go to receive page |
| 14 | + await page.getByTestId('tab-wallet').click() |
| 15 | + await page.getByText('Receive', { exact: true }).click() |
| 16 | + |
| 17 | + // copy lnurl |
| 18 | + await page.getByText('Copy').click() |
| 19 | + await page.getByTestId('lnurl-address-copy').click() |
| 20 | + const lnurl = await readClipboard(page) |
| 21 | + |
| 22 | + expect(lnurl).toContain('LNURL') |
| 23 | + expect(lnurl.length).toBeGreaterThan(100) |
| 24 | + expect(isValidLnUrl(lnurl)).toBe(true) |
| 25 | +}) |
| 26 | + |
| 27 | +test('should check conditions from lnurl', async ({ page }) => { |
| 28 | + // create wallet |
| 29 | + await createWallet(page) |
| 30 | + |
| 31 | + // go to receive page |
| 32 | + await page.getByTestId('tab-wallet').click() |
| 33 | + await page.getByText('Receive', { exact: true }).click() |
| 34 | + |
| 35 | + // copy lnurl |
| 36 | + await page.getByText('Copy').click() |
| 37 | + await page.getByTestId('lnurl-address-copy').click() |
| 38 | + const lnurl = await readClipboard(page) |
| 39 | + |
| 40 | + expect(lnurl).toContain('LNURL') |
| 41 | + expect(lnurl.length).toBeGreaterThan(100) |
| 42 | + expect(isValidLnUrl(lnurl)).toBe(true) |
| 43 | + |
| 44 | + // check conditions |
| 45 | + const conditions = await checkLnUrlConditions(lnurl) |
| 46 | + expect(conditions).toHaveProperty('commentAllowed') |
| 47 | + expect(conditions).toHaveProperty('maxSendable') |
| 48 | + expect(conditions).toHaveProperty('minSendable') |
| 49 | + expect(conditions).toHaveProperty('callback') |
| 50 | + expect(conditions).toHaveProperty('metadata') |
| 51 | + expect(conditions).toHaveProperty('tag') |
| 52 | +}) |
| 53 | + |
| 54 | +test('should fetch invoice from lnurl', async ({ page }) => { |
| 55 | + // create wallet |
| 56 | + await createWallet(page) |
| 57 | + |
| 58 | + // go to receive page |
| 59 | + await page.getByTestId('tab-wallet').click() |
| 60 | + await page.getByText('Receive', { exact: true }).click() |
| 61 | + |
| 62 | + // copy lnurl |
| 63 | + await page.getByText('Copy').click() |
| 64 | + await page.getByTestId('lnurl-address-copy').click() |
| 65 | + const lnurl = await readClipboard(page) |
| 66 | + |
| 67 | + expect(lnurl).toContain('LNURL') |
| 68 | + expect(lnurl.length).toBeGreaterThan(100) |
| 69 | + expect(isValidLnUrl(lnurl)).toBe(true) |
| 70 | + |
| 71 | + // fetch invoice |
| 72 | + const invoice = await fetchInvoice(lnurl, 2000, 'Test payment') |
| 73 | + expect(invoice).toContain('lnbcrt') |
| 74 | + |
| 75 | + // decode invoice |
| 76 | + const decoded = decodeInvoice(invoice) |
| 77 | + expect(decoded).toHaveProperty('paymentHash') |
| 78 | + expect(decoded).toHaveProperty('amountSats') |
| 79 | + expect(decoded).toHaveProperty('expiry') |
| 80 | + expect(decoded).toHaveProperty('note') |
| 81 | + expect(decoded.amountSats).toBe(2000) |
| 82 | +}) |
| 83 | + |
| 84 | +test('should receive payment', async ({ page }) => { |
| 85 | + // create wallet |
| 86 | + await createWallet(page) |
| 87 | + |
| 88 | + // go to receive page |
| 89 | + await page.getByTestId('tab-wallet').click() |
| 90 | + await page.getByText('Receive', { exact: true }).click() |
| 91 | + |
| 92 | + // copy lnurl |
| 93 | + await page.getByText('Copy').click() |
| 94 | + await page.getByTestId('lnurl-address-copy').click() |
| 95 | + const lnurl = await readClipboard(page) |
| 96 | + |
| 97 | + expect(lnurl).toContain('LNURL') |
| 98 | + expect(lnurl.length).toBeGreaterThan(100) |
| 99 | + expect(isValidLnUrl(lnurl)).toBe(true) |
| 100 | + |
| 101 | + // fetch invoice |
| 102 | + const invoice = await fetchInvoice(lnurl, 2000, 'Test payment') |
| 103 | + expect(invoice).toContain('lnbcrt') |
| 104 | + |
| 105 | + // pay invoice with lnd |
| 106 | + await execAsync(`docker exec lnd lncli --network=regtest payinvoice ${invoice} --force`) |
| 107 | + |
| 108 | + // wait for payment received |
| 109 | + await waitForPaymentReceived(page) |
| 110 | + |
| 111 | + // transaction should be visible on main page |
| 112 | + await page.getByTestId('tab-wallet').click() |
| 113 | + await page.waitForSelector('text=Received', { timeout: 10000 }) |
| 114 | + await expect(page.getByText('1,992', { exact: true })).toBeVisible() |
| 115 | +}) |
0 commit comments