(node_factory, bitcoind, chainparams)
| 775 | @pytest.mark.developer("requres 'dev-queryrates'") |
| 776 | @pytest.mark.slow_test |
| 777 | def test_channel_lease_post_expiry(node_factory, bitcoind, chainparams): |
| 778 | |
| 779 | coin_mvt_plugin = os.path.join(os.getcwd(), 'tests/plugins/coin_movements.py') |
| 780 | opts = {'funder-policy': 'match', 'funder-policy-mod': 100, |
| 781 | 'lease-fee-base-sat': '100sat', 'lease-fee-basis': 100, |
| 782 | 'may_reconnect': True, 'plugin': coin_mvt_plugin, |
| 783 | 'dev-no-reconnect': None} |
| 784 | |
| 785 | l1, l2, = node_factory.get_nodes(2, opts=opts) |
| 786 | |
| 787 | feerate = 2000 |
| 788 | amount = 500000 |
| 789 | l1.fundwallet(20000000) |
| 790 | l2.fundwallet(20000000) |
| 791 | |
| 792 | # l1 leases a channel from l2 |
| 793 | l1.rpc.connect(l2.info['id'], 'localhost', l2.port) |
| 794 | rates = l1.rpc.dev_queryrates(l2.info['id'], amount, amount) |
| 795 | wait_for(lambda: len(l1.rpc.listpeers(l2.info['id'])['peers']) == 0) |
| 796 | l1.rpc.connect(l2.info['id'], 'localhost', l2.port) |
| 797 | l1.rpc.fundchannel(l2.info['id'], amount, request_amt=amount, |
| 798 | feerate='{}perkw'.format(feerate), |
| 799 | compact_lease=rates['compact_lease']) |
| 800 | |
| 801 | est_fees = calc_lease_fee(amount, feerate, rates) |
| 802 | |
| 803 | # This should be the accepter's amount |
| 804 | fundings = only_one(only_one(l1.rpc.listpeers()['peers'])['channels'])['funding'] |
| 805 | assert Millisatoshi(amount * 1000) == fundings['remote_funds_msat'] |
| 806 | assert Millisatoshi(est_fees + amount * 1000) == fundings['local_funds_msat'] |
| 807 | assert Millisatoshi(est_fees) == fundings['fee_paid_msat'] |
| 808 | |
| 809 | bitcoind.generate_block(6) |
| 810 | l1.daemon.wait_for_log('to CHANNELD_NORMAL') |
| 811 | channel_id = first_channel_id(l1, l2) |
| 812 | |
| 813 | wait_for(lambda: [c['active'] for c in l1.rpc.listchannels(l1.get_channel_scid(l2))['channels']] == [True, True]) |
| 814 | |
| 815 | # send some payments, mine a block or two |
| 816 | inv = l2.rpc.invoice(10**4, '1', 'no_1') |
| 817 | l1.rpc.pay(inv['bolt11']) |
| 818 | |
| 819 | # make sure it's completely resolved before we generate blocks, |
| 820 | # otherwise it can close HTLC! |
| 821 | wait_for(lambda: only_one(only_one(l2.rpc.listpeers()['peers'])['channels'])['htlcs'] == []) |
| 822 | |
| 823 | # l2 attempts to close a channel that it leased, should fail |
| 824 | with pytest.raises(RpcError, match=r'Peer leased this channel from us'): |
| 825 | l2.rpc.close(l1.get_channel_scid(l2)) |
| 826 | |
| 827 | bitcoind.generate_block(6) |
| 828 | sync_blockheight(bitcoind, [l1, l2]) |
| 829 | # make sure we're at the right place for the csv lock |
| 830 | l2.daemon.wait_for_log('Blockheight: SENT_ADD_ACK_COMMIT->RCVD_ADD_ACK_REVOCATION LOCAL now 115') |
| 831 | |
| 832 | # We need to give l1-l2 time to update their blockheights |
| 833 | bitcoind.generate_block(1000) |
| 834 | sync_blockheight(bitcoind, [l1, l2]) |
nothing calls this directly
no test coverage detected