Skip to content

Commit 791e412

Browse files
ddustinsangbida
authored andcommitted
splice: Add splicein test
Tests the splicein command
1 parent 0762890 commit 791e412

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

contrib/pyln-client/pyln/client/lightning.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,14 @@ def splice(self, script_or_json, dryrun=None, force_feerate=None, debug_log=None
12281228
}
12291229
return self.call("dev-splice", payload)
12301230

1231+
def splicein(self, channel, amount):
1232+
""" Execute a splice """
1233+
payload = {
1234+
"channel": channel,
1235+
"amount": amount,
1236+
}
1237+
return self.call("splicein", payload)
1238+
12311239
def stfu_channels(self, channel_ids):
12321240
""" STFU multiple channels """
12331241
payload = {

tests/test_splice.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,46 @@ def test_script_two_chan_splice_inout(node_factory, bitcoind):
308308
l2.rpc.pay(inv['bolt11'])
309309

310310

311+
@pytest.mark.xfail(strict=True)
312+
@pytest.mark.openchannel('v1')
313+
@pytest.mark.openchannel('v2')
314+
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
315+
def test_easy_splice_in(node_factory, bitcoind, chainparams):
316+
fundamt = 1000000
317+
318+
coin_mvt_plugin = Path(__file__).parent / "plugins" / "coin_movements.py"
319+
l1, l2 = node_factory.line_graph(2, fundamount=fundamt, wait_for_announce=True,
320+
opts={'experimental-splicing': None,
321+
'plugin': coin_mvt_plugin})
322+
323+
# Splice in 100k sats into first channel
324+
spliceamt = 100000
325+
326+
l1.rpc.splicein("*:?", f"{spliceamt}")
327+
p1 = only_one(l1.rpc.listpeerchannels(peer_id=l2.info['id'])['channels'])
328+
p2 = only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])
329+
assert p1['inflight'][0]['splice_amount'] == spliceamt
330+
assert p1['inflight'][0]['total_funding_msat'] == (fundamt + spliceamt) * 1000
331+
assert p1['inflight'][0]['our_funding_msat'] == fundamt * 1000
332+
assert p2['inflight'][0]['splice_amount'] == 0
333+
assert p2['inflight'][0]['total_funding_msat'] == (fundamt + spliceamt) * 1000
334+
assert p2['inflight'][0]['our_funding_msat'] == 0
335+
bitcoind.generate_block(6, wait_for_mempool=1)
336+
l2.daemon.wait_for_log(r'lightningd, splice_locked clearing inflights')
337+
338+
p1 = only_one(l1.rpc.listpeerchannels(peer_id=l2.info['id'])['channels'])
339+
p2 = only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])
340+
assert p1['to_us_msat'] == (fundamt + spliceamt) * 1000
341+
assert p1['total_msat'] == (fundamt + spliceamt) * 1000
342+
assert p2['to_us_msat'] == 0
343+
assert p2['total_msat'] == (fundamt + spliceamt) * 1000
344+
assert 'inflight' not in p1
345+
assert 'inflight' not in p2
346+
347+
wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 1)
348+
wait_for(lambda: len(l1.rpc.listfunds()['channels']) == 1)
349+
350+
311351
# Makes channels going from node 1 -> 2, 2 -> 3, etc up to 'qty' number channels.
312352
# If balanced is True, than each channel will be balanced -- otherwise the lower
313353
# index channel will have funds in the channel to the higher indexed one.

0 commit comments

Comments
 (0)