(node_factory, bitcoind, chainparams)
| 304 | @pytest.mark.openchannel('v2') |
| 305 | @unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need') |
| 306 | def test_script_splice_msat_roundup(node_factory, bitcoind, chainparams): |
| 307 | # Test splices with msat level sats to confirm rounding, using an amount |
| 308 | # That would naturally round up (even though we always round down). |
| 309 | fundamt = 1000000 |
| 310 | |
| 311 | coin_mvt_plugin = Path(__file__).parent / "plugins" / "coin_movements.py" |
| 312 | l1, l2 = node_factory.line_graph(2, fundamount=fundamt, wait_for_announce=True, |
| 313 | opts={'plugin': coin_mvt_plugin}) |
| 314 | |
| 315 | initial_wallet_balance = Millisatoshi(bkpr_account_balance(l1, 'wallet')) |
| 316 | initial_channel_balance = Millisatoshi(bkpr_account_balance(l1, first_channel_id(l1, l2))) |
| 317 | assert initial_channel_balance == Millisatoshi(fundamt * 1000) |
| 318 | |
| 319 | # Splice in 100k sats into first channel, explicitly taking out 200k sats from wallet |
| 320 | # and letting change go automatically back to wallet (100k less onchain fees) |
| 321 | spliceamt = 100000 |
| 322 | withdraw_amt = 200000 |
| 323 | starting_wallet_msat = withdraw_amt * 10000 |
| 324 | |
| 325 | sent_msats = 1999 |
| 326 | # purposely pay in msats |
| 327 | inv = l2.rpc.invoice(sent_msats, '1', 'no_1') |
| 328 | l1.rpc.pay(inv['bolt11']) |
| 329 | initial_channel_balance -= sent_msats |
| 330 | |
| 331 | l1.rpc.splice(f"wallet -> {withdraw_amt}; {spliceamt} -> *:?", debug_log=True) |
| 332 | p1 = only_one(l1.rpc.listpeerchannels(peer_id=l2.info['id'])['channels']) |
| 333 | p2 = only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels']) |
| 334 | assert p1['inflight'][0]['splice_amount'] == spliceamt |
| 335 | assert p1['inflight'][0]['total_funding_msat'] == (fundamt + spliceamt) * 1000 |
| 336 | assert p1['inflight'][0]['our_funding_msat'] == fundamt * 1000 |
| 337 | assert p2['inflight'][0]['splice_amount'] == 0 |
| 338 | assert p2['inflight'][0]['total_funding_msat'] == (fundamt + spliceamt) * 1000 |
| 339 | assert p2['inflight'][0]['our_funding_msat'] == 0 |
| 340 | bitcoind.generate_block(6, wait_for_mempool=1) |
| 341 | l2.daemon.wait_for_log(r'lightningd, splice_locked clearing inflights') |
| 342 | |
| 343 | p1 = only_one(l1.rpc.listpeerchannels(peer_id=l2.info['id'])['channels']) |
| 344 | p2 = only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels']) |
| 345 | assert p1['to_us_msat'] == ((fundamt + spliceamt) * 1000) - sent_msats |
| 346 | assert p1['total_msat'] == (fundamt + spliceamt) * 1000 |
| 347 | assert p2['to_us_msat'] == sent_msats |
| 348 | assert p2['total_msat'] == (fundamt + spliceamt) * 1000 |
| 349 | assert 'inflight' not in p1 |
| 350 | assert 'inflight' not in p2 |
| 351 | |
| 352 | wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 1) |
| 353 | wait_for(lambda: len(l1.rpc.listfunds()['channels']) == 1) |
| 354 | |
| 355 | # At the end we'd expect the balance of channel 1 to be up by the splice amount |
| 356 | end_channel_balance = Millisatoshi(bkpr_account_balance(l1, first_channel_id(l1, l2))) |
| 357 | end_wallet_balance = Millisatoshi(bkpr_account_balance(l1, 'wallet')) |
| 358 | assert initial_channel_balance + Millisatoshi(spliceamt * 1000) == end_channel_balance |
| 359 | |
| 360 | # The fee is assumed to be the difference between the start+end balances? |
| 361 | fee_guess = initial_wallet_balance + initial_channel_balance - end_channel_balance - end_wallet_balance |
| 362 | |
| 363 | # We'd expect the following coin movements |
nothing calls this directly
no test coverage detected