Skip to content

Commit

Permalink
Move import and watchonly tests to be legacy wallet only in wallet_ba…
Browse files Browse the repository at this point in the history
…lance.py

Summary:
Imports and watchonly behavior are legacy wallet only, so make them only run when the test is in legacy wallet mode.

This is a backport of [[bitcoin/bitcoin#18788 | core#18788]] [5/16]
bitcoin/bitcoin@a42652e

Test Plan: `test/functional/test_runner.py wallet_balance`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10657
  • Loading branch information
achow101 authored and PiRK committed Dec 13, 2021
1 parent 51cb39c commit 4a6f5db
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
1 change: 1 addition & 0 deletions test/functional/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"rpc_fundrawtransaction.py": [["--descriptors"]],
# FIXME: "rpc_psbt.py": [["--descriptors"]],
"wallet_avoidreuse.py": [["--descriptors"]],
"wallet_balance.py": [["--descriptors"]],
# FIXME: "wallet_basic.py": [["--descriptors"]],
"wallet_createwallet.py": [["--usecli"]],
"wallet_encryption.py": [["--descriptors"]],
Expand Down
60 changes: 38 additions & 22 deletions test/functional/wallet_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,17 @@ def skip_test_if_missing_module(self):
self.skip_if_no_wallet()

def run_test(self):
self.nodes[0].importaddress(ADDRESS_WATCHONLY)
# Check that nodes don't own any UTXOs
assert_equal(len(self.nodes[0].listunspent()), 0)
assert_equal(len(self.nodes[1].listunspent()), 0)

self.log.info("Check that only node 0 is watching an address")
assert 'watchonly' in self.nodes[0].getbalances()
assert 'watchonly' not in self.nodes[1].getbalances()
if not self.options.descriptors:
# Tests legacy watchonly behavior which is not present (and does
# not need to be tested) in descriptor wallets
self.nodes[0].importaddress(ADDRESS_WATCHONLY)
# Check that nodes don't own any UTXOs
assert_equal(len(self.nodes[0].listunspent()), 0)
assert_equal(len(self.nodes[1].listunspent()), 0)

self.log.info("Check that only node 0 is watching an address")
assert 'watchonly' in self.nodes[0].getbalances()
assert 'watchonly' not in self.nodes[1].getbalances()

self.log.info("Mining blocks ...")
self.nodes[0].generate(1)
Expand All @@ -75,27 +78,38 @@ def run_test(self):
self.nodes[1].generatetoaddress(101, ADDRESS_WATCHONLY)
self.sync_all()

assert_equal(self.nodes[0].getbalances()['mine']['trusted'], 50000000)
assert_equal(self.nodes[0].getwalletinfo()['balance'], 50000000)
assert_equal(self.nodes[1].getbalances()['mine']['trusted'], 50000000)
if not self.options.descriptors:
# Tests legacy watchonly behavior which is not present (and does not
# need to be tested) in descriptor wallets
assert_equal(self.nodes[0].getbalances()['mine']['trusted'],
50000000)
assert_equal(self.nodes[0].getwalletinfo()['balance'], 50000000)
assert_equal(self.nodes[1].getbalances()['mine']['trusted'],
50000000)

assert_equal(self.nodes[0].getbalances()[
'watchonly']['immature'], 5000000000)
assert 'watchonly' not in self.nodes[1].getbalances()
assert_equal(self.nodes[0].getbalances()['watchonly']['immature'],
5000000000)
assert 'watchonly' not in self.nodes[1].getbalances()

assert_equal(self.nodes[0].getbalance(), 50000000)
assert_equal(self.nodes[1].getbalance(), 50000000)
assert_equal(self.nodes[0].getbalance(), 50000000)
assert_equal(self.nodes[1].getbalance(), 50000000)

self.log.info("Test getbalance with different arguments")
assert_equal(self.nodes[0].getbalance("*"), 50000000)
assert_equal(self.nodes[0].getbalance("*", 1), 50000000)
assert_equal(self.nodes[0].getbalance("*", 1, True), 100000000)
assert_equal(self.nodes[0].getbalance(minconf=1), 50000000)
assert_equal(
self.nodes[0].getbalance(
minconf=0,
include_watchonly=True),
100000000)

if not self.options.descriptors:
assert_equal(self.nodes[0].getbalance(minconf=0,
include_watchonly=True),
100_000_000)
assert_equal(self.nodes[0].getbalance("*", 1, True), 100_000_000)
else:
assert_equal(self.nodes[0].getbalance(minconf=0,
include_watchonly=True),
50_000_000)
assert_equal(self.nodes[0].getbalance("*", 1, True), 50_000_000)

assert_equal(
self.nodes[1].getbalance(
minconf=0,
Expand Down Expand Up @@ -175,6 +189,8 @@ def test_balances(*, fee_node_1=0):
# Doesn't include output of node
# 0's send since it was spent
'untrusted_pending': Decimal('30000000.0') - fee_node_1}}
if self.options.descriptors:
del expected_balances_0["watchonly"]
assert_equal(self.nodes[0].getbalances(), expected_balances_0)
assert_equal(self.nodes[1].getbalances(), expected_balances_1)
# getbalance without any arguments includes unconfirmed transactions, but not untrusted transactions
Expand Down

0 comments on commit 4a6f5db

Please sign in to comment.