Verify that channel coin movements are triggered correctly.
(node_factory, bitcoind, chainparams)
| 2545 | @pytest.mark.openchannel('v1') |
| 2546 | @pytest.mark.openchannel('v2') |
| 2547 | def test_coin_movement_notices(node_factory, bitcoind, chainparams): |
| 2548 | """Verify that channel coin movements are triggered correctly. """ |
| 2549 | |
| 2550 | l1_l2_mvts = [ |
| 2551 | {'type': 'chain_mvt', 'credit_msat': 0, 'debit_msat': 0, 'tags': ['channel_open']}, |
| 2552 | {'type': 'channel_mvt', 'credit_msat': 100001001, 'debit_msat': 0, 'tags': ['routed'], 'fees_msat': '1001msat'}, |
| 2553 | {'type': 'channel_mvt', 'credit_msat': 0, 'debit_msat': 50000000, 'tags': ['routed'], 'fees_msat': '501msat'}, |
| 2554 | {'type': 'channel_mvt', 'credit_msat': 100000000, 'debit_msat': 0, 'tags': ['invoice'], 'fees_msat': '0msat'}, |
| 2555 | {'type': 'channel_mvt', 'credit_msat': 0, 'debit_msat': 50000000, 'tags': ['invoice'], 'fees_msat': '0msat'}, |
| 2556 | {'type': 'chain_mvt', 'credit_msat': 0, 'debit_msat': 100001001, 'tags': ['channel_close']}, |
| 2557 | ] |
| 2558 | |
| 2559 | l2_l3_mvts = [ |
| 2560 | {'type': 'chain_mvt', 'credit_msat': 1000000000, 'debit_msat': 0, 'tags': ['channel_open', 'opener']}, |
| 2561 | {'type': 'channel_mvt', 'credit_msat': 0, 'debit_msat': 100000000, 'tags': ['routed'], 'fees_msat': '1001msat'}, |
| 2562 | {'type': 'channel_mvt', 'credit_msat': 50000501, 'debit_msat': 0, 'tags': ['routed'], 'fees_msat': '501msat'}, |
| 2563 | {'type': 'chain_mvt', 'credit_msat': 0, 'debit_msat': 950000501, 'tags': ['channel_close']}, |
| 2564 | ] |
| 2565 | |
| 2566 | l3_l2_mvts = [ |
| 2567 | {'type': 'chain_mvt', 'credit_msat': 0, 'debit_msat': 0, 'tags': ['channel_open']}, |
| 2568 | {'type': 'channel_mvt', 'credit_msat': 100000000, 'debit_msat': 0, 'tags': ['invoice'], 'fees_msat': '0msat'}, |
| 2569 | {'type': 'channel_mvt', 'credit_msat': 0, 'debit_msat': 50000501, 'tags': ['invoice'], 'fees_msat': '501msat'}, |
| 2570 | {'type': 'chain_mvt', 'credit_msat': 0, 'debit_msat': 49999499, 'tags': ['channel_close']}, |
| 2571 | ] |
| 2572 | |
| 2573 | coin_plugin = os.path.join(os.getcwd(), 'tests/plugins/coin_movements.py') |
| 2574 | l1, l2, l3 = node_factory.line_graph(3, opts=[ |
| 2575 | {'may_reconnect': True}, |
| 2576 | {'may_reconnect': True, 'plugin': coin_plugin}, |
| 2577 | {'may_reconnect': True, 'plugin': coin_plugin}, |
| 2578 | ], wait_for_announce=True) |
| 2579 | |
| 2580 | mine_funding_to_announce(bitcoind, [l1, l2, l3]) |
| 2581 | wait_for(lambda: len(l1.rpc.listchannels()['channels']) == 4) |
| 2582 | amount = 10**8 |
| 2583 | |
| 2584 | inv = l3.rpc.invoice(amount, "first", "desc") |
| 2585 | payment_hash13 = inv['payment_hash'] |
| 2586 | route = l1.single_route(l3.info['id'], amount) |
| 2587 | |
| 2588 | # status: offered -> settled |
| 2589 | l1.rpc.sendpay(route, payment_hash13, payment_secret=inv['payment_secret']) |
| 2590 | l1.rpc.waitsendpay(payment_hash13) |
| 2591 | |
| 2592 | # status: offered -> failed |
| 2593 | route = l1.single_route(l3.info['id'], amount) |
| 2594 | payment_hash13 = "f" * 64 |
| 2595 | with pytest.raises(RpcError): |
| 2596 | l1.rpc.sendpay(route, payment_hash13, payment_secret=inv['payment_secret']) |
| 2597 | l1.rpc.waitsendpay(payment_hash13) |
| 2598 | |
| 2599 | # go the other direction |
| 2600 | inv = l1.rpc.invoice(amount // 2, "first", "desc") |
| 2601 | payment_hash31 = inv['payment_hash'] |
| 2602 | route = l3.single_route(l1.info['id'], amount // 2) |
| 2603 | l3.rpc.sendpay(route, payment_hash31, payment_secret=inv['payment_secret']) |
| 2604 | l3.rpc.waitsendpay(payment_hash31) |
nothing calls this directly
no test coverage detected