Skip to content

Commit a528923

Browse files
committed
splice: Add test for splice RBF
A test that does an RBF and a few HTLCs at various phases of the splice RBF
1 parent 537cfdf commit a528923

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

tests/test_splicing.py

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from fixtures import * # noqa: F401,F403
2-
from flaky import flaky
32
from pyln.client import RpcError
43
import pytest
54
import unittest
@@ -12,7 +11,6 @@
1211
@pytest.mark.openchannel('v1')
1312
@pytest.mark.openchannel('v2')
1413
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
15-
@flaky
1614
def test_splice(node_factory, bitcoind):
1715
l1, l2 = node_factory.line_graph(2, fundamount=1000000, wait_for_announce=True, opts={'experimental-splicing': None})
1816

@@ -49,6 +47,63 @@ def test_splice(node_factory, bitcoind):
4947
assert l1.db_query("SELECT count(*) as c FROM channeltxs;")[0]['c'] == 0
5048

5149

50+
@pytest.mark.openchannel('v1')
51+
@pytest.mark.openchannel('v2')
52+
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
53+
def test_splice_rbf(node_factory, bitcoind):
54+
l1, l2 = node_factory.line_graph(2, fundamount=1000000, wait_for_announce=True, opts={'experimental-splicing': None})
55+
56+
chan_id = l1.get_channel_id(l2)
57+
58+
funds_result = l1.rpc.addpsbtoutput(100000)
59+
60+
# Pay with fee by subjtracting 5000 from channel balance
61+
result = l1.rpc.splice_init(chan_id, -105000, funds_result['psbt'])
62+
result = l1.rpc.splice_update(chan_id, result['psbt'])
63+
assert(result['commitments_secured'] is False)
64+
result = l1.rpc.splice_update(chan_id, result['psbt'])
65+
assert(result['commitments_secured'] is True)
66+
result = l1.rpc.splice_signed(chan_id, result['psbt'])
67+
68+
l2.daemon.wait_for_log(r'CHANNELD_NORMAL to CHANNELD_AWAITING_SPLICE')
69+
l1.daemon.wait_for_log(r'CHANNELD_NORMAL to CHANNELD_AWAITING_SPLICE')
70+
71+
mempool = bitcoind.rpc.getrawmempool(True)
72+
assert len(list(mempool.keys())) == 1
73+
assert result['txid'] in list(mempool.keys())
74+
75+
inv = l2.rpc.invoice(10**2, '1', 'no_1')
76+
l1.rpc.pay(inv['bolt11'])
77+
78+
funds_result = l1.rpc.addpsbtoutput(100000)
79+
80+
# Pay with fee by subjtracting 5000 from channel balance
81+
result = l1.rpc.splice_init(chan_id, -110000, funds_result['psbt'])
82+
result = l1.rpc.splice_update(chan_id, result['psbt'])
83+
assert(result['commitments_secured'] is False)
84+
result = l1.rpc.splice_update(chan_id, result['psbt'])
85+
assert(result['commitments_secured'] is True)
86+
result = l1.rpc.splice_signed(chan_id, result['psbt'])
87+
88+
l2.daemon.wait_for_log(r'CHANNELD_AWAITING_SPLICE to CHANNELD_AWAITING_SPLICE')
89+
l1.daemon.wait_for_log(r'CHANNELD_AWAITING_SPLICE to CHANNELD_AWAITING_SPLICE')
90+
91+
inv = l2.rpc.invoice(10**2, '2', 'no_2')
92+
l1.rpc.pay(inv['bolt11'])
93+
94+
bitcoind.generate_block(6, wait_for_mempool=1)
95+
96+
l2.daemon.wait_for_log(r'CHANNELD_AWAITING_SPLICE to CHANNELD_NORMAL')
97+
l1.daemon.wait_for_log(r'CHANNELD_AWAITING_SPLICE to CHANNELD_NORMAL')
98+
99+
inv = l2.rpc.invoice(10**2, '3', 'no_3')
100+
l1.rpc.pay(inv['bolt11'])
101+
102+
# Check that the splice doesn't generate a unilateral close transaction
103+
time.sleep(5)
104+
assert l1.db_query("SELECT count(*) as c FROM channeltxs;")[0]['c'] == 0
105+
106+
52107
@pytest.mark.openchannel('v1')
53108
@pytest.mark.openchannel('v2')
54109
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')

0 commit comments

Comments
 (0)