Verify that channel coin movements are triggered correctly.
(node_factory, bitcoind, chainparams)
| 2429 | @pytest.mark.openchannel('v1') |
| 2430 | @pytest.mark.openchannel('v2') |
| 2431 | def test_coin_movement_notices(node_factory, bitcoind, chainparams): |
| 2432 | """Verify that channel coin movements are triggered correctly. """ |
| 2433 | |
| 2434 | l1_l2_mvts = [ |
| 2435 | {'type': 'chain_mvt', 'credit_msat': 0, 'debit_msat': 0, 'tags': ['channel_open']}, |
| 2436 | {'type': 'channel_mvt', 'credit_msat': 100001001, 'debit_msat': 0, 'tags': ['routed'], 'fees_msat': '1001msat'}, |
| 2437 | {'type': 'channel_mvt', 'credit_msat': 0, 'debit_msat': 50000000, 'tags': ['routed'], 'fees_msat': '501msat'}, |
| 2438 | {'type': 'channel_mvt', 'credit_msat': 100000000, 'debit_msat': 0, 'tags': ['invoice'], 'fees_msat': '0msat'}, |
| 2439 | {'type': 'channel_mvt', 'credit_msat': 0, 'debit_msat': 50000000, 'tags': ['invoice'], 'fees_msat': '0msat'}, |
| 2440 | {'type': 'chain_mvt', 'credit_msat': 0, 'debit_msat': 100001001, 'tags': ['channel_close']}, |
| 2441 | ] |
| 2442 | |
| 2443 | l2_l3_mvts = [ |
| 2444 | {'type': 'chain_mvt', 'credit_msat': 1000000000, 'debit_msat': 0, 'tags': ['channel_open', 'opener']}, |
| 2445 | {'type': 'channel_mvt', 'credit_msat': 0, 'debit_msat': 100000000, 'tags': ['routed'], 'fees_msat': '1001msat'}, |
| 2446 | {'type': 'channel_mvt', 'credit_msat': 50000501, 'debit_msat': 0, 'tags': ['routed'], 'fees_msat': '501msat'}, |
| 2447 | {'type': 'chain_mvt', 'credit_msat': 0, 'debit_msat': 950000501, 'tags': ['channel_close']}, |
| 2448 | ] |
| 2449 | |
| 2450 | l3_l2_mvts = [ |
| 2451 | {'type': 'chain_mvt', 'credit_msat': 0, 'debit_msat': 0, 'tags': ['channel_open']}, |
| 2452 | {'type': 'channel_mvt', 'credit_msat': 100000000, 'debit_msat': 0, 'tags': ['invoice'], 'fees_msat': '0msat'}, |
| 2453 | {'type': 'channel_mvt', 'credit_msat': 0, 'debit_msat': 50000501, 'tags': ['invoice'], 'fees_msat': '501msat'}, |
| 2454 | {'type': 'chain_mvt', 'credit_msat': 0, 'debit_msat': 49999499, 'tags': ['channel_close']}, |
| 2455 | ] |
| 2456 | |
| 2457 | coin_plugin = os.path.join(os.getcwd(), 'tests/plugins/coin_movements.py') |
| 2458 | l1, l2, l3 = node_factory.line_graph(3, opts=[ |
| 2459 | {'may_reconnect': True}, |
| 2460 | {'may_reconnect': True, 'plugin': coin_plugin}, |
| 2461 | {'may_reconnect': True, 'plugin': coin_plugin}, |
| 2462 | ], wait_for_announce=True) |
| 2463 | |
| 2464 | mine_funding_to_announce(bitcoind, [l1, l2, l3]) |
| 2465 | wait_for(lambda: len(l1.rpc.listchannels()['channels']) == 4) |
| 2466 | amount = 10**8 |
| 2467 | |
| 2468 | inv = l3.rpc.invoice(amount, "first", "desc") |
| 2469 | payment_hash13 = inv['payment_hash'] |
| 2470 | route = l1.single_route(l3.info['id'], amount) |
| 2471 | |
| 2472 | # status: offered -> settled |
| 2473 | l1.rpc.sendpay(route, payment_hash13, payment_secret=inv['payment_secret']) |
| 2474 | l1.rpc.waitsendpay(payment_hash13) |
| 2475 | |
| 2476 | # status: offered -> failed |
| 2477 | route = l1.single_route(l3.info['id'], amount) |
| 2478 | payment_hash13 = "f" * 64 |
| 2479 | with pytest.raises(RpcError): |
| 2480 | l1.rpc.sendpay(route, payment_hash13, payment_secret=inv['payment_secret']) |
| 2481 | l1.rpc.waitsendpay(payment_hash13) |
| 2482 | |
| 2483 | # go the other direction |
| 2484 | inv = l1.rpc.invoice(amount // 2, "first", "desc") |
| 2485 | payment_hash31 = inv['payment_hash'] |
| 2486 | route = l3.single_route(l1.info['id'], amount // 2) |
| 2487 | l3.rpc.sendpay(route, payment_hash31, payment_secret=inv['payment_secret']) |
| 2488 | l3.rpc.waitsendpay(payment_hash31) |
nothing calls this directly
no test coverage detected