Skip to content

Commit

Permalink
splice: Add test of “splice” script command
Browse files Browse the repository at this point in the history
Tests that splice-in and splice-out work through the scripting process and confirm the resulting balances are correct.
  • Loading branch information
ddustin committed Feb 15, 2024
1 parent 4d7d416 commit 42bdd4d
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
14 changes: 14 additions & 0 deletions contrib/pyln-client/pyln/client/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,20 @@ def openchannel_abort(self, channel_id):
}
return self.call("openchannel_abort", payload)

def splice(self, script, dryrun=None, psbt=None, user_provided_sats=None, force_feerate=None, json=None, debug_log=None, wetrun=None):
""" Execute a splice """
payload = {
"script": script,
"dryrun": dryrun,
"psbt": psbt,
"user_provided_sats": user_provided_sats,
"force_feerate": force_feerate,
"json": json,
"debug_log": debug_log,
"wetrun": wetrun,
}
return self.call("splice", payload)

def splice_init(self, chan_id, amount, initialpsbt=None, feerate_per_kw=None):
""" Initiate a splice """
payload = {
Expand Down
62 changes: 62 additions & 0 deletions tests/test_splice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from fixtures import * # noqa: F401,F403
import pytest
import unittest
import time
from pyln.testing.utils import EXPERIMENTAL_DUAL_FUND
from utils import (
TEST_NETWORK, only_one
)


@pytest.mark.openchannel('v1')
@pytest.mark.openchannel('v2')
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
def test_script_splice_out(node_factory, bitcoind):
l1, l2 = node_factory.line_graph(2, fundamount=1000000, wait_for_announce=True, opts={'experimental-splicing': None})
l1.rpc.splice("*:? -> 100000; 100%-fee -> wallet", force_feerate=True, debug_log=True)
p1 = only_one(l1.rpc.listpeerchannels(peer_id=l2.info['id'])['channels'])
p2 = only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])
assert p1['inflight'][0]['splice_amount'] == -100000
assert p1['inflight'][0]['total_funding_msat'] == 900000000
assert p1['inflight'][0]['our_funding_msat'] == 1000000000
assert p2['inflight'][0]['splice_amount'] == 0
assert p2['inflight'][0]['total_funding_msat'] == 900000000
assert p2['inflight'][0]['our_funding_msat'] == 0
bitcoind.generate_block(6, wait_for_mempool=1)
l2.daemon.wait_for_log(r'lightningd, splice_locked clearing inflights')

p1 = only_one(l1.rpc.listpeerchannels(peer_id=l2.info['id'])['channels'])
p2 = only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])
assert p1['to_us_msat'] == 900000000
assert p1['total_msat'] == 900000000
assert p2['to_us_msat'] == 0
assert p2['total_msat'] == 900000000
assert 'inflight' not in p1
assert 'inflight' not in p2


@pytest.mark.openchannel('v1')
@pytest.mark.openchannel('v2')
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
def test_script_splice_in(node_factory, bitcoind):
l1, l2 = node_factory.line_graph(2, fundamount=1000000, wait_for_announce=True, opts={'experimental-splicing': None})
l1.rpc.splice("wallet -> 200000; 100000 -> *:?", force_feerate=True, debug_log=True)
p1 = only_one(l1.rpc.listpeerchannels(peer_id=l2.info['id'])['channels'])
p2 = only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])
assert p1['inflight'][0]['splice_amount'] == 100000
assert p1['inflight'][0]['total_funding_msat'] == 1100000000
assert p1['inflight'][0]['our_funding_msat'] == 1000000000
assert p2['inflight'][0]['splice_amount'] == 0
assert p2['inflight'][0]['total_funding_msat'] == 1100000000
assert p2['inflight'][0]['our_funding_msat'] == 0
bitcoind.generate_block(6, wait_for_mempool=1)
l2.daemon.wait_for_log(r'lightningd, splice_locked clearing inflights')

p1 = only_one(l1.rpc.listpeerchannels(peer_id=l2.info['id'])['channels'])
p2 = only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])
assert p1['to_us_msat'] == 1100000000
assert p1['total_msat'] == 1100000000
assert p2['to_us_msat'] == 0
assert p2['total_msat'] == 1100000000
assert 'inflight' not in p1
assert 'inflight' not in p2

0 comments on commit 42bdd4d

Please sign in to comment.