(node_factory, bitcoind, chainparams)
| 614 | |
| 615 | |
| 616 | def test_reserveinputs(node_factory, bitcoind, chainparams): |
| 617 | amount = 1000000 |
| 618 | total_outs = 12 |
| 619 | l1 = node_factory.get_node(feerates=(7500, 7500, 7500, 7500)) |
| 620 | |
| 621 | outputs = [] |
| 622 | # Add a medley of funds to withdraw |
| 623 | for i in range(total_outs): |
| 624 | txid = bitcoind.rpc.sendtoaddress(l1.rpc.newaddr('bech32')['bech32'], |
| 625 | amount / 10**8) |
| 626 | outputs.append((txid, bitcoind.rpc.gettransaction(txid)['details'][0]['vout'])) |
| 627 | |
| 628 | bitcoind.generate_block(1) |
| 629 | wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == total_outs) |
| 630 | |
| 631 | assert not any(o['reserved'] for o in l1.rpc.listfunds()['outputs']) |
| 632 | |
| 633 | # Try reserving one at a time. |
| 634 | for out in outputs: |
| 635 | psbt = bitcoind.rpc.createpsbt([{'txid': out[0], 'vout': out[1]}], []) |
| 636 | l1.rpc.reserveinputs(psbt) |
| 637 | |
| 638 | assert all(o['reserved'] for o in l1.rpc.listfunds()['outputs']) |
| 639 | reserveheight = bitcoind.rpc.getblockchaininfo()['blocks'] + 72 |
| 640 | assert all(o['reserved_to_block'] == reserveheight for o in l1.rpc.listfunds()['outputs']) |
| 641 | |
| 642 | # Unreserve as a batch. |
| 643 | psbt = bitcoind.rpc.createpsbt([{'txid': out[0], 'vout': out[1]} for out in outputs], []) |
| 644 | l1.rpc.unreserveinputs(psbt) |
| 645 | assert not any(o['reserved'] for o in l1.rpc.listfunds()['outputs']) |
| 646 | assert not any('reserved_to_block' in o for o in l1.rpc.listfunds()['outputs']) |
| 647 | |
| 648 | # Reserve twice fails unless exclusive. |
| 649 | l1.rpc.reserveinputs(psbt) |
| 650 | with pytest.raises(RpcError, match=r"already reserved"): |
| 651 | l1.rpc.reserveinputs(psbt) |
| 652 | l1.rpc.reserveinputs(psbt, False) |
| 653 | assert all(o['reserved_to_block'] == reserveheight + 72 for o in l1.rpc.listfunds()['outputs']) |
| 654 | l1.rpc.unreserveinputs(psbt) |
| 655 | assert all(o['reserved'] for o in l1.rpc.listfunds()['outputs']) |
| 656 | assert all(o['reserved_to_block'] == reserveheight for o in l1.rpc.listfunds()['outputs']) |
| 657 | |
| 658 | # Stays reserved across restarts. |
| 659 | l1.restart() |
| 660 | assert all(o['reserved'] for o in l1.rpc.listfunds()['outputs']) |
| 661 | assert all(o['reserved_to_block'] == reserveheight for o in l1.rpc.listfunds()['outputs']) |
| 662 | |
| 663 | # Final unreserve works. |
| 664 | l1.rpc.unreserveinputs(psbt) |
| 665 | assert not any(o['reserved'] for o in l1.rpc.listfunds()['outputs']) |
| 666 | assert not any('reserved_to_block' in o for o in l1.rpc.listfunds()['outputs']) |
| 667 | |
| 668 | |
| 669 | def test_fundpsbt(node_factory, bitcoind, chainparams): |
nothing calls this directly
no test coverage detected