rpc: return block hash & height in getbalances, gettransaction & getwalletinfo JSONs

Co-authored-by: Aurèle Oulès <aurele@oules.com>
This commit is contained in:
Harris
2020-04-27 10:45:03 +02:00
committed by Aurèle Oulès
parent 91ccb62faa
commit 710b83938a
9 changed files with 70 additions and 6 deletions

View File

@@ -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()