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

Function test_script_splice_out

tests/test_splice.py:16–101  ·  view source on GitHub ↗
(node_factory, bitcoind, chainparams)

Source from the content-addressed store, hash-verified

14@pytest.mark.openchannel('v2')
15@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
16def test_script_splice_out(node_factory, bitcoind, chainparams):
17 fundamt = 1000000
18
19 coin_mvt_plugin = Path(__file__).parent / "plugins" / "coin_movements.py"
20 l1, l2 = node_factory.line_graph(2, fundamount=fundamt, wait_for_announce=True,
21 opts={'plugin': coin_mvt_plugin})
22
23 initial_wallet_balance = Millisatoshi(bkpr_account_balance(l1, 'wallet'))
24 initial_channel_balance = Millisatoshi(bkpr_account_balance(l1, first_channel_id(l1, l2)))
25 assert initial_channel_balance == Millisatoshi(fundamt * 1000)
26
27 # Splice out 100k from first channel, explicitly putting result less fees into onchain wallet
28 spliceamt = 100000
29 l1.rpc.splice(f"*:? -> {spliceamt}; 100%-fee -> wallet", debug_log=True)
30 p1 = only_one(l1.rpc.listpeerchannels(peer_id=l2.info['id'])['channels'])
31 p2 = only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])
32
33 assert p1['inflight'][0]['splice_amount'] == -1 * spliceamt
34 assert p1['inflight'][0]['total_funding_msat'] == (fundamt - spliceamt) * 1000
35 assert p1['inflight'][0]['our_funding_msat'] == fundamt * 1000
36 assert p2['inflight'][0]['splice_amount'] == 0
37 assert p2['inflight'][0]['total_funding_msat'] == (fundamt - spliceamt) * 1000
38 assert p2['inflight'][0]['our_funding_msat'] == 0
39 bitcoind.generate_block(6, wait_for_mempool=1)
40 l2.daemon.wait_for_log(r'lightningd, splice_locked clearing inflights')
41
42 p1 = only_one(l1.rpc.listpeerchannels(peer_id=l2.info['id'])['channels'])
43 p2 = only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])
44 assert p1['to_us_msat'] == (fundamt - spliceamt) * 1000
45 assert p1['total_msat'] == (fundamt - spliceamt) * 1000
46 assert p2['to_us_msat'] == 0
47 assert p2['total_msat'] == (fundamt - spliceamt) * 1000
48 assert 'inflight' not in p1
49 assert 'inflight' not in p2
50
51 wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 2)
52 wait_for(lambda: len(l1.rpc.listfunds()['channels']) == 1)
53
54 # At the end we'd expect the balance of channel 1 to be down by the splice amount
55 end_channel_balance = Millisatoshi(bkpr_account_balance(l1, first_channel_id(l1, l2)))
56 end_wallet_balance = Millisatoshi(bkpr_account_balance(l1, 'wallet'))
57 assert initial_channel_balance - Millisatoshi(spliceamt * 1000) == end_channel_balance
58
59 # The fee is assumed to be the difference between the start+end balances?
60 fee_guess = initial_wallet_balance + initial_channel_balance - end_channel_balance - end_wallet_balance
61
62 # We'd expect the following coin movements
63 starting_wallet_msat = 2000000000
64 expected_wallet_moves = [
65 # initial deposit
66 {'type': 'chain_mvt', 'credit_msat': starting_wallet_msat, 'debit_msat': 0, 'tags': ['deposit']},
67 # channel open spend
68 {'type': 'chain_mvt', 'credit_msat': 0, 'debit_msat': starting_wallet_msat, 'tags': ['withdrawal']},
69 # channel open change
70 {'type': 'chain_mvt', 'credit_msat': initial_wallet_balance, 'debit_msat': 0, 'tags': ['deposit']},
71 # deposit of spliceamt - fees
72 {'type': 'chain_mvt', 'credit_msat': Millisatoshi(spliceamt * 1000) - fee_guess, 'debit_msat': 0, 'tags': ['deposit']},
73 ]

Callers

nothing calls this directly

Calls 14

MillisatoshiClass · 0.90
bkpr_account_balanceFunction · 0.90
first_channel_idFunction · 0.90
only_oneFunction · 0.90
wait_forFunction · 0.90
check_coin_movesFunction · 0.90
line_graphMethod · 0.80
spliceMethod · 0.80
listpeerchannelsMethod · 0.80
generate_blockMethod · 0.80
wait_for_logMethod · 0.80

Tested by

no test coverage detected