aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Chow <github@achow101.com>2023-05-02 11:42:50 -0400
committerAndrew Chow <github@achow101.com>2023-05-02 11:50:45 -0400
commitda9f62f912294de07a595df0b4898aba4be6b69c (patch)
tree2081d107a2613bc01bafe4dec178d9188ecc9a5e /test
parent7b45d171f549595a831489827c28e8493f36c00c (diff)
parent710b83938ab5bbc4bd324d8b2e69461a2a1d2eec (diff)
Merge bitcoin/bitcoin#26094: rpc: Return block hash & height in getbalances, gettransaction and getwalletinfo
710b83938ab5bbc4bd324d8b2e69461a2a1d2eec rpc: return block hash & height in getbalances, gettransaction & getwalletinfo JSONs (Harris) Pull request description: Reopens #18570 and closes #18567. I have rebased the original PR. Not sure why the original got closed as it was about to get merged. ACKs for top commit: achow101: ACK 710b83938ab5bbc4bd324d8b2e69461a2a1d2eec Tree-SHA512: d4478d990be98b1642e9ffb2930987f4a224e8bd64e2e35a5dda927a54c509ec9d712cd0eac35dc2bb89f00a1678e530ce14d7445f1dd93aa3a4cce2bc9b130d
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/wallet_balance.py35
-rwxr-xr-xtest/functional/wallet_basic.py2
-rwxr-xr-xtest/functional/wallet_orphanedreward.py5
3 files changed, 38 insertions, 4 deletions
diff --git a/test/functional/wallet_balance.py b/test/functional/wallet_balance.py
index 9ed2caefb7..af9270a321 100755
--- a/test/functional/wallet_balance.py
+++ b/test/functional/wallet_balance.py
@@ -11,6 +11,7 @@ from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
+ assert_is_hash_string,
assert_raises_rpc_error,
)
@@ -183,8 +184,13 @@ class WalletTest(BitcoinTestFramework):
'untrusted_pending': Decimal('30.0') - fee_node_1}} # Doesn't include output of node 0's send since it was spent
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)
+ balances_0 = self.nodes[0].getbalances()
+ balances_1 = self.nodes[1].getbalances()
+ # remove lastprocessedblock keys (they will be tested later)
+ del balances_0['lastprocessedblock']
+ del balances_1['lastprocessedblock']
+ assert_equal(balances_0, expected_balances_0)
+ assert_equal(balances_1, expected_balances_1)
# getbalance without any arguments includes unconfirmed transactions, but not untrusted transactions
assert_equal(self.nodes[0].getbalance(), Decimal('9.99')) # change from node 0's send
assert_equal(self.nodes[1].getbalance(), Decimal('0')) # node 1's send had an unsafe input
@@ -309,5 +315,30 @@ class WalletTest(BitcoinTestFramework):
assert_equal(self.nodes[0].getbalances()['mine']['untrusted_pending'], Decimal('0.1'))
+ # Tests the lastprocessedblock JSON object in getbalances, getwalletinfo
+ # and gettransaction by checking for valid hex strings and by comparing
+ # the hashes & heights between generated blocks.
+ self.log.info("Test getbalances returns expected lastprocessedblock json object")
+ prev_hash = self.nodes[0].getbestblockhash()
+ prev_height = self.nodes[0].getblock(prev_hash)['height']
+ self.generatetoaddress(self.nodes[0], 5, self.nodes[0].get_deterministic_priv_key().address)
+ lastblock = self.nodes[0].getbalances()['lastprocessedblock']
+ assert_is_hash_string(lastblock['hash'])
+ assert_equal((prev_hash == lastblock['hash']), False)
+ assert_equal(lastblock['height'], prev_height + 5)
+
+ prev_hash = self.nodes[0].getbestblockhash()
+ prev_height = self.nodes[0].getblock(prev_hash)['height']
+ self.log.info("Test getwalletinfo returns expected lastprocessedblock json object")
+ walletinfo = self.nodes[0].getwalletinfo()
+ assert_equal(walletinfo['lastprocessedblock']['height'], prev_height)
+ assert_equal(walletinfo['lastprocessedblock']['hash'], prev_hash)
+
+ self.log.info("Test gettransaction returns expected lastprocessedblock json object")
+ txid = self.nodes[1].sendtoaddress(self.nodes[1].getnewaddress(), 0.01)
+ tx_info = self.nodes[1].gettransaction(txid)
+ assert_equal(tx_info['lastprocessedblock']['height'], prev_height)
+ assert_equal(tx_info['lastprocessedblock']['hash'], prev_hash)
+
if __name__ == '__main__':
WalletTest().main()
diff --git a/test/functional/wallet_basic.py b/test/functional/wallet_basic.py
index 1f771dabe4..e23ec7bc01 100755
--- a/test/functional/wallet_basic.py
+++ b/test/functional/wallet_basic.py
@@ -680,7 +680,7 @@ class WalletTest(BitcoinTestFramework):
"category": baz["category"],
"vout": baz["vout"]}
expected_fields = frozenset({'amount', 'bip125-replaceable', 'confirmations', 'details', 'fee',
- 'hex', 'time', 'timereceived', 'trusted', 'txid', 'wtxid', 'walletconflicts'})
+ 'hex', 'lastprocessedblock', 'time', 'timereceived', 'trusted', 'txid', 'wtxid', 'walletconflicts'})
verbose_field = "decoded"
expected_verbose_fields = expected_fields | {verbose_field}
diff --git a/test/functional/wallet_orphanedreward.py b/test/functional/wallet_orphanedreward.py
index d8931fa620..451f8abb0a 100755
--- a/test/functional/wallet_orphanedreward.py
+++ b/test/functional/wallet_orphanedreward.py
@@ -65,7 +65,10 @@ class OrphanedBlockRewardTest(BitcoinTestFramework):
assert_equal(self.nodes[0].getbestblockhash(), orig_chain_tip)
self.generate(self.nodes[0], 3)
- assert_equal(self.nodes[1].getbalances(), pre_reorg_conf_bals)
+ balances = self.nodes[1].getbalances()
+ del balances["lastprocessedblock"]
+ del pre_reorg_conf_bals["lastprocessedblock"]
+ assert_equal(balances, pre_reorg_conf_bals)
assert_equal(self.nodes[1].gettransaction(txid)["details"][0]["abandoned"], True)