Skip to content

Commit 7794d9d

Browse files
committed
Merge bitcoin/bitcoin#27735: test: Move test_chain_listunspent wallet check from mempool_packages to wallet_basic
ffffe62 test: Move test_chain_listunspent wallet check from mempool_packages to wallet_basic (MarcoFalke) Pull request description: This fixes a bug. On master: ``` $ ./test/functional/mempool_packages.py --legacy-wallet File "./test/functional/mempool_packages.py", line 52, in run_test self.nodes[0].importaddress(self.wallet.get_address()) test_framework.authproxy.JSONRPCException: Bech32m addresses cannot be imported into legacy wallets (-5) ``` On this pull, all tests pass. ACKs for top commit: glozow: ACK ffffe62, thanks for changing! Nice to remove wallet from another non-wallet test. Tree-SHA512: 842c3b7c2e90285a155b8ed9924ef0c99f7773892be4f1847e5d7ece79c914ea5acee0d71de2ce46c354ee95fb74a03c20c0afb5e49c0b8e1c0ce406df963650
2 parents 66b08e7 + ffffe62 commit 7794d9d

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

test/functional/mempool_packages.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from decimal import Decimal
88

99
from test_framework.messages import (
10-
COIN,
1110
DEFAULT_ANCESTOR_LIMIT,
1211
DEFAULT_DESCENDANT_LIMIT,
1312
)
@@ -26,9 +25,6 @@
2625

2726

2827
class MempoolPackagesTest(BitcoinTestFramework):
29-
def add_options(self, parser):
30-
self.add_wallet_options(parser)
31-
3228
def set_test_params(self):
3329
self.num_nodes = 2
3430
self.extra_args = [
@@ -47,10 +43,6 @@ def run_test(self):
4743
self.wallet = MiniWallet(self.nodes[0])
4844
self.wallet.rescan_utxos()
4945

50-
if self.is_specified_wallet_compiled():
51-
self.nodes[0].createwallet("watch_wallet", disable_private_keys=True)
52-
self.nodes[0].importaddress(self.wallet.get_address())
53-
5446
peer_inv_store = self.nodes[0].add_p2p_connection(P2PTxInvStore()) # keep track of invs
5547

5648
# DEFAULT_ANCESTOR_LIMIT transactions off a confirmed tx should be fine
@@ -63,13 +55,6 @@ def run_test(self):
6355
ancestor_vsize += t["tx"].get_vsize()
6456
ancestor_fees += t["fee"]
6557
self.wallet.sendrawtransaction(from_node=self.nodes[0], tx_hex=t["hex"])
66-
# Check that listunspent ancestor{count, size, fees} yield the correct results
67-
if self.is_specified_wallet_compiled():
68-
wallet_unspent = self.nodes[0].listunspent(minconf=0)
69-
this_unspent = next(utxo_info for utxo_info in wallet_unspent if utxo_info["txid"] == t["txid"])
70-
assert_equal(this_unspent['ancestorcount'], i + 1)
71-
assert_equal(this_unspent['ancestorsize'], ancestor_vsize)
72-
assert_equal(this_unspent['ancestorfees'], ancestor_fees * COIN)
7358

7459
# Wait until mempool transactions have passed initial broadcast (sent inv and received getdata)
7560
# Otherwise, getrawmempool may be inconsistent with getmempoolentry if unbroadcast changes in between

test/functional/wallet_basic.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
from test_framework.blocktools import COINBASE_MATURITY
1010
from test_framework.descriptors import descsum_create
11+
from test_framework.messages import (
12+
COIN,
13+
DEFAULT_ANCESTOR_LIMIT,
14+
)
1115
from test_framework.test_framework import BitcoinTestFramework
1216
from test_framework.util import (
1317
assert_array_result,
@@ -17,6 +21,7 @@
1721
find_vout_for_address,
1822
)
1923
from test_framework.wallet_util import test_address
24+
from test_framework.wallet import MiniWallet
2025

2126
NOT_A_NUMBER_OR_STRING = "Amount is not a number or string"
2227
OUT_OF_RANGE = "Amount out of range"
@@ -784,6 +789,34 @@ def run_test(self):
784789

785790
zeroconf_wallet.sendtoaddress(zeroconf_wallet.getnewaddress(), Decimal('0.5'))
786791

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+
787820

788821
if __name__ == '__main__':
789822
WalletTest().main()

0 commit comments

Comments
 (0)