Skip to content

Commit e534bac

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 56d1681 commit e534bac

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

tests/test_splicing.py

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
@pytest.mark.openchannel('v1')
1313
@pytest.mark.openchannel('v2')
1414
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
15-
@flaky
1615
def test_splice(node_factory, bitcoind):
1716
l1, l2 = node_factory.line_graph(2, fundamount=1000000, wait_for_announce=True, opts={'experimental-splicing': None})
1817

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

5150

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

0 commit comments

Comments
 (0)