|
8 | 8 |
|
9 | 9 | from test_framework.blocktools import COINBASE_MATURITY
|
10 | 10 | from test_framework.descriptors import descsum_create
|
| 11 | +from test_framework.messages import ( |
| 12 | + COIN, |
| 13 | + DEFAULT_ANCESTOR_LIMIT, |
| 14 | +) |
11 | 15 | from test_framework.test_framework import BitcoinTestFramework
|
12 | 16 | from test_framework.util import (
|
13 | 17 | assert_array_result,
|
|
17 | 21 | find_vout_for_address,
|
18 | 22 | )
|
19 | 23 | from test_framework.wallet_util import test_address
|
| 24 | +from test_framework.wallet import MiniWallet |
20 | 25 |
|
21 | 26 | NOT_A_NUMBER_OR_STRING = "Amount is not a number or string"
|
22 | 27 | OUT_OF_RANGE = "Amount out of range"
|
@@ -784,6 +789,34 @@ def run_test(self):
|
784 | 789 |
|
785 | 790 | zeroconf_wallet.sendtoaddress(zeroconf_wallet.getnewaddress(), Decimal('0.5'))
|
786 | 791 |
|
| 792 | + self.test_chain_listunspent() |
| 793 | + |
| 794 | + def test_chain_listunspent(self): |
| 795 | + if not self.options.descriptors: |
| 796 | + return |
| 797 | + self.wallet = MiniWallet(self.nodes[0]) |
| 798 | + self.nodes[0].get_wallet_rpc(self.default_wallet_name).sendtoaddress(self.wallet.get_address(), "5") |
| 799 | + self.generate(self.wallet, 1, sync_fun=self.no_op) |
| 800 | + self.nodes[0].createwallet("watch_wallet", disable_private_keys=True) |
| 801 | + watch_wallet = self.nodes[0].get_wallet_rpc("watch_wallet") |
| 802 | + watch_wallet.importaddress(self.wallet.get_address()) |
| 803 | + |
| 804 | + # DEFAULT_ANCESTOR_LIMIT transactions off a confirmed tx should be fine |
| 805 | + chain = self.wallet.create_self_transfer_chain(chain_length=DEFAULT_ANCESTOR_LIMIT) |
| 806 | + ancestor_vsize = 0 |
| 807 | + ancestor_fees = Decimal(0) |
| 808 | + |
| 809 | + for i, t in enumerate(chain): |
| 810 | + ancestor_vsize += t["tx"].get_vsize() |
| 811 | + ancestor_fees += t["fee"] |
| 812 | + self.wallet.sendrawtransaction(from_node=self.nodes[0], tx_hex=t["hex"]) |
| 813 | + # Check that listunspent ancestor{count, size, fees} yield the correct results |
| 814 | + wallet_unspent = watch_wallet.listunspent(minconf=0) |
| 815 | + this_unspent = next(utxo_info for utxo_info in wallet_unspent if utxo_info["txid"] == t["txid"]) |
| 816 | + assert_equal(this_unspent['ancestorcount'], i + 1) |
| 817 | + assert_equal(this_unspent['ancestorsize'], ancestor_vsize) |
| 818 | + assert_equal(this_unspent['ancestorfees'], ancestor_fees * COIN) |
| 819 | + |
787 | 820 |
|
788 | 821 | if __name__ == '__main__':
|
789 | 822 | WalletTest().main()
|
0 commit comments