(node_factory, bitcoind, chainparams)
| 105 | @pytest.mark.openchannel('v2') |
| 106 | @unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need') |
| 107 | def test_script_splice_in(node_factory, bitcoind, chainparams): |
| 108 | fundamt = 1000000 |
| 109 | |
| 110 | coin_mvt_plugin = Path(__file__).parent / "plugins" / "coin_movements.py" |
| 111 | l1, l2 = node_factory.line_graph(2, fundamount=fundamt, wait_for_announce=True, |
| 112 | opts={'plugin': coin_mvt_plugin}) |
| 113 | |
| 114 | initial_wallet_balance = Millisatoshi(bkpr_account_balance(l1, 'wallet')) |
| 115 | initial_channel_balance = Millisatoshi(bkpr_account_balance(l1, first_channel_id(l1, l2))) |
| 116 | assert initial_channel_balance == Millisatoshi(fundamt * 1000) |
| 117 | |
| 118 | # Splice in 100k sats into first channel, explicitly taking out 200k sats from wallet |
| 119 | # and letting change go automatically back to wallet (100k less onchain fees) |
| 120 | spliceamt = 100000 |
| 121 | withdraw_amt = 200000 |
| 122 | starting_wallet_msat = withdraw_amt * 10000 |
| 123 | |
| 124 | l1.rpc.splice(f"wallet -> {withdraw_amt}; {spliceamt} -> *:?", debug_log=True) |
| 125 | p1 = only_one(l1.rpc.listpeerchannels(peer_id=l2.info['id'])['channels']) |
| 126 | p2 = only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels']) |
| 127 | assert p1['inflight'][0]['splice_amount'] == spliceamt |
| 128 | assert p1['inflight'][0]['total_funding_msat'] == (fundamt + spliceamt) * 1000 |
| 129 | assert p1['inflight'][0]['our_funding_msat'] == fundamt * 1000 |
| 130 | assert p2['inflight'][0]['splice_amount'] == 0 |
| 131 | assert p2['inflight'][0]['total_funding_msat'] == (fundamt + spliceamt) * 1000 |
| 132 | assert p2['inflight'][0]['our_funding_msat'] == 0 |
| 133 | bitcoind.generate_block(6, wait_for_mempool=1) |
| 134 | l2.daemon.wait_for_log(r'lightningd, splice_locked clearing inflights') |
| 135 | |
| 136 | p1 = only_one(l1.rpc.listpeerchannels(peer_id=l2.info['id'])['channels']) |
| 137 | p2 = only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels']) |
| 138 | assert p1['to_us_msat'] == (fundamt + spliceamt) * 1000 |
| 139 | assert p1['total_msat'] == (fundamt + spliceamt) * 1000 |
| 140 | assert p2['to_us_msat'] == 0 |
| 141 | assert p2['total_msat'] == (fundamt + spliceamt) * 1000 |
| 142 | assert 'inflight' not in p1 |
| 143 | assert 'inflight' not in p2 |
| 144 | |
| 145 | wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 1) |
| 146 | wait_for(lambda: len(l1.rpc.listfunds()['channels']) == 1) |
| 147 | |
| 148 | # At the end we'd expect the balance of channel 1 to be up by the splice amount |
| 149 | end_channel_balance = Millisatoshi(bkpr_account_balance(l1, first_channel_id(l1, l2))) |
| 150 | end_wallet_balance = Millisatoshi(bkpr_account_balance(l1, 'wallet')) |
| 151 | assert initial_channel_balance + Millisatoshi(spliceamt * 1000) == end_channel_balance |
| 152 | |
| 153 | # The fee is assumed to be the difference between the start+end balances? |
| 154 | fee_guess = initial_wallet_balance + initial_channel_balance - end_channel_balance - end_wallet_balance |
| 155 | |
| 156 | # We'd expect the following coin movements |
| 157 | expected_wallet_moves = [ |
| 158 | # initial deposit |
| 159 | {'type': 'chain_mvt', 'credit_msat': starting_wallet_msat, 'debit_msat': 0, 'tags': ['deposit']}, |
| 160 | # channel open spend |
| 161 | {'type': 'chain_mvt', 'credit_msat': 0, 'debit_msat': starting_wallet_msat, 'tags': ['withdrawal']}, |
| 162 | # channel open change |
| 163 | {'type': 'chain_mvt', 'credit_msat': initial_wallet_balance, 'debit_msat': 0, 'tags': ['deposit']}, |
| 164 | # splice-in spend |
nothing calls this directly
no test coverage detected