(node_factory, chainparams)
| 12 | |
| 13 | |
| 14 | def test_invoice(node_factory, chainparams): |
| 15 | l1, l2 = node_factory.line_graph(2, fundchannel=False, opts={'log-level': 'io'}) |
| 16 | |
| 17 | addr1 = l2.rpc.newaddr('bech32')['bech32'] |
| 18 | addr2 = '2MxqzNANJNAdMjHQq8ZLkwzooxAFiRzXvEz' if not chainparams['elements'] else 'XGx1E2JSTLZLmqYMAo3CGpsco85aS7so33' |
| 19 | before = int(time.time()) |
| 20 | inv = l1.rpc.invoice(123000, 'label', 'description', 3700, [addr1, addr2]) |
| 21 | |
| 22 | # Side note: invoice calls out to listincoming, so check JSON id is as expected |
| 23 | myname = os.path.splitext(os.path.basename(sys.argv[0]))[0] |
| 24 | l1.daemon.wait_for_log(r': "{}:invoice#[0-9]*/cln:listincoming#[0-9]*"\[OUT\]'.format(myname)) |
| 25 | |
| 26 | after = int(time.time()) |
| 27 | b11 = l1.rpc.decode(inv['bolt11']) |
| 28 | assert b11['type'] == 'bolt11 invoice' |
| 29 | assert b11['currency'] == chainparams['bip173_prefix'] |
| 30 | assert b11['created_at'] >= before |
| 31 | assert b11['created_at'] <= after |
| 32 | assert b11['payment_hash'] == inv['payment_hash'] |
| 33 | assert b11['description'] == 'description' |
| 34 | assert b11['expiry'] == 3700 |
| 35 | assert b11['payee'] == l1.info['id'] |
| 36 | assert len(b11['fallbacks']) == 2 |
| 37 | assert b11['fallbacks'][0]['addr'] == addr1 |
| 38 | assert b11['fallbacks'][0]['type'] == 'P2WPKH' |
| 39 | assert b11['fallbacks'][1]['addr'] == addr2 |
| 40 | assert b11['fallbacks'][1]['type'] == 'P2SH' |
| 41 | assert b11['min_final_cltv_expiry'] == 5 |
| 42 | # There's no incoming channel, so no routeboost |
| 43 | assert 'routes' not in b11 |
| 44 | assert 'warning_capacity' in inv |
| 45 | |
| 46 | # Check pay_index is null |
| 47 | outputs = l1.db_query('SELECT pay_index IS NULL AS q FROM invoices WHERE label="label";') |
| 48 | assert len(outputs) == 1 and outputs[0]['q'] != 0 |
| 49 | |
| 50 | # Check any-amount invoice |
| 51 | inv = l1.rpc.invoice("any", 'label2', 'description2') |
| 52 | b11 = inv['bolt11'] |
| 53 | # Amount usually comes after currency (bcrt in our case), |
| 54 | # but an any-amount invoices will have no amount |
| 55 | assert b11.startswith("ln" + chainparams['bip173_prefix']) |
| 56 | # By bech32 rules, the last '1' digit is the separator |
| 57 | # between the human-readable and data parts. We want |
| 58 | # to match the "lnbcrt1" above with the '1' digit as the |
| 59 | # separator, and not for example "lnbcrt1m1....". |
| 60 | assert b11.count('1') == 1 |
| 61 | # There's no incoming channel, so no routeboost |
| 62 | assert 'routes' not in b11 |
| 63 | assert 'warning_capacity' in inv |
| 64 | |
| 65 | # Test cltv option. |
| 66 | inv = l1.rpc.invoice(123000, 'label3', 'description', 3700, cltv=99) |
| 67 | b11 = l1.rpc.decode(inv['bolt11']) |
| 68 | assert b11['min_final_cltv_expiry'] == 99 |
| 69 | |
| 70 | |
| 71 | def test_invoice_zeroval(node_factory): |
nothing calls this directly
no test coverage detected