(node_factory, bitcoind, chainparams)
| 200 | @pytest.mark.openchannel('v2') |
| 201 | @unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need') |
| 202 | def test_script_splice_msat(node_factory, bitcoind, chainparams): |
| 203 | # Test splices with msat level sats to confirm rounding |
| 204 | fundamt = 1000000 |
| 205 | |
| 206 | coin_mvt_plugin = Path(__file__).parent / "plugins" / "coin_movements.py" |
| 207 | l1, l2 = node_factory.line_graph(2, fundamount=fundamt, wait_for_announce=True, |
| 208 | opts={'plugin': coin_mvt_plugin}) |
| 209 | |
| 210 | initial_wallet_balance = Millisatoshi(bkpr_account_balance(l1, 'wallet')) |
| 211 | initial_channel_balance = Millisatoshi(bkpr_account_balance(l1, first_channel_id(l1, l2))) |
| 212 | assert initial_channel_balance == Millisatoshi(fundamt * 1000) |
| 213 | |
| 214 | # Splice in 100k sats into first channel, explicitly taking out 200k sats from wallet |
| 215 | # and letting change go automatically back to wallet (100k less onchain fees) |
| 216 | spliceamt = 100000 |
| 217 | withdraw_amt = 200000 |
| 218 | starting_wallet_msat = withdraw_amt * 10000 |
| 219 | |
| 220 | sent_msats = 1111 |
| 221 | # purposely pay in msats |
| 222 | inv = l2.rpc.invoice(sent_msats, '1', 'no_1') |
| 223 | l1.rpc.pay(inv['bolt11']) |
| 224 | initial_channel_balance -= sent_msats |
| 225 | |
| 226 | l1.rpc.splice(f"wallet -> {withdraw_amt}; {spliceamt} -> *:?", debug_log=True) |
| 227 | p1 = only_one(l1.rpc.listpeerchannels(peer_id=l2.info['id'])['channels']) |
| 228 | p2 = only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels']) |
| 229 | assert p1['inflight'][0]['splice_amount'] == spliceamt |
| 230 | assert p1['inflight'][0]['total_funding_msat'] == (fundamt + spliceamt) * 1000 |
| 231 | assert p1['inflight'][0]['our_funding_msat'] == fundamt * 1000 |
| 232 | assert p2['inflight'][0]['splice_amount'] == 0 |
| 233 | assert p2['inflight'][0]['total_funding_msat'] == (fundamt + spliceamt) * 1000 |
| 234 | assert p2['inflight'][0]['our_funding_msat'] == 0 |
| 235 | bitcoind.generate_block(6, wait_for_mempool=1) |
| 236 | l2.daemon.wait_for_log(r'lightningd, splice_locked clearing inflights') |
| 237 | |
| 238 | p1 = only_one(l1.rpc.listpeerchannels(peer_id=l2.info['id'])['channels']) |
| 239 | p2 = only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels']) |
| 240 | assert p1['to_us_msat'] == ((fundamt + spliceamt) * 1000) - sent_msats |
| 241 | assert p1['total_msat'] == (fundamt + spliceamt) * 1000 |
| 242 | assert p2['to_us_msat'] == sent_msats |
| 243 | assert p2['total_msat'] == (fundamt + spliceamt) * 1000 |
| 244 | assert 'inflight' not in p1 |
| 245 | assert 'inflight' not in p2 |
| 246 | |
| 247 | wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 1) |
| 248 | wait_for(lambda: len(l1.rpc.listfunds()['channels']) == 1) |
| 249 | |
| 250 | # At the end we'd expect the balance of channel 1 to be up by the splice amount |
| 251 | end_channel_balance = Millisatoshi(bkpr_account_balance(l1, first_channel_id(l1, l2))) |
| 252 | end_wallet_balance = Millisatoshi(bkpr_account_balance(l1, 'wallet')) |
| 253 | assert initial_channel_balance + Millisatoshi(spliceamt * 1000) == end_channel_balance |
| 254 | |
| 255 | # The fee is assumed to be the difference between the start+end balances? |
| 256 | fee_guess = initial_wallet_balance + initial_channel_balance - end_channel_balance - end_wallet_balance |
| 257 | |
| 258 | # We'd expect the following coin movements |
| 259 | expected_wallet_moves = [ |
nothing calls this directly
no test coverage detected