MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_invalid_splice

Function test_invalid_splice

tests/test_splicing.py:520–571  ·  view source on GitHub ↗
(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

518@pytest.mark.openchannel('v2')
519@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
520def test_invalid_splice(node_factory, bitcoind):
521 # Here we do a splice but underfund it purposefully
522 l1, l2 = node_factory.line_graph(2, fundamount=1000000, wait_for_announce=True, opts={'may_reconnect': True,
523 'allow_warning': True})
524
525 chan_id = l1.get_channel_id(l2)
526
527 # We claim to add 100000 but in fact add nothing
528 result = l1.rpc.splice_init(chan_id, 100000)
529
530 with pytest.raises(RpcError) as rpc_error:
531 result = l1.rpc.splice_update(chan_id, result['psbt'])
532 assert(result['commitments_secured'] is False)
533 result = l1.rpc.splice_update(chan_id, result['psbt'])
534 assert(result['commitments_secured'] is True)
535
536 assert rpc_error.value.error["code"] == 357
537 assert rpc_error.value.error["message"] == "You provided 1000000000msat but committed to 1100000000msat."
538
539 # The splicing inflight should not have been left pending in the DB
540 assert l1.db_query("SELECT count(*) as c FROM channel_funding_inflights;")[0]['c'] == 0
541
542 l1.daemon.wait_for_log(r'Restarting channeld after tx_abort on CHANNELD_NORMAL channel')
543
544 assert l1.db_query("SELECT count(*) as c FROM channel_funding_inflights;")[0]['c'] == 0
545
546 # Now we do a real splice to confirm everything works after restart
547 funds_result = l1.rpc.fundpsbt("111722sat", 0, 0, excess_as_change=True)
548
549 result = l1.rpc.splice_init(chan_id, 100000, funds_result['psbt'])
550 result = l1.rpc.splice_update(chan_id, result['psbt'])
551 assert(result['commitments_secured'] is False)
552 result = l1.rpc.splice_update(chan_id, result['psbt'])
553 assert(result['commitments_secured'] is True)
554 result = l1.rpc.signpsbt(result['psbt'])
555 result = l1.rpc.splice_signed(chan_id, result['signed_psbt'])
556
557 wait_for(lambda: len(list(bitcoind.rpc.getrawmempool(True).keys())) == 1)
558 mempool = bitcoind.rpc.getrawmempool(True)
559 assert result['txid'] in list(mempool.keys())
560
561 bitcoind.generate_block(6, wait_for_mempool=1)
562
563 l2.daemon.wait_for_log(r'CHANNELD_AWAITING_SPLICE to CHANNELD_NORMAL')
564 l1.daemon.wait_for_log(r'CHANNELD_AWAITING_SPLICE to CHANNELD_NORMAL')
565
566 inv = l2.rpc.invoice(10**2, '3', 'no_3')
567 l1.rpc.xpay(inv['bolt11'])
568
569 # Check that the splice doesn't generate a unilateral close transaction
570 time.sleep(5)
571 assert l1.db_query("SELECT count(*) as c FROM channeltxs;")[0]['c'] == 0
572
573
574@pytest.mark.openchannel('v1')

Callers

nothing calls this directly

Calls 13

wait_forFunction · 0.90
line_graphMethod · 0.80
get_channel_idMethod · 0.80
db_queryMethod · 0.80
wait_for_logMethod · 0.80
fundpsbtMethod · 0.80
signpsbtMethod · 0.80
generate_blockMethod · 0.80
splice_initMethod · 0.45
splice_updateMethod · 0.45
splice_signedMethod · 0.45
invoiceMethod · 0.45

Tested by

no test coverage detected