|
11 | 11 | from test_framework.test_framework import BitcoinTestFramework |
12 | 12 | from test_framework.util import ( |
13 | 13 | assert_equal, |
| 14 | + assert_is_hash_string, |
14 | 15 | assert_raises_rpc_error, |
15 | 16 | ) |
16 | 17 |
|
@@ -174,8 +175,13 @@ def test_balances(*, fee_node_1=0): |
174 | 175 | 'untrusted_pending': Decimal('30.0') - fee_node_1}} # Doesn't include output of node 0's send since it was spent |
175 | 176 | if self.options.descriptors: |
176 | 177 | del expected_balances_0["watchonly"] |
177 | | - assert_equal(self.nodes[0].getbalances(), expected_balances_0) |
178 | | - assert_equal(self.nodes[1].getbalances(), expected_balances_1) |
| 178 | + balances_0 = self.nodes[0].getbalances() |
| 179 | + balances_1 = self.nodes[1].getbalances() |
| 180 | + # remove lastprocessedblock keys (they will be tested later) |
| 181 | + del balances_0['lastprocessedblock'] |
| 182 | + del balances_1['lastprocessedblock'] |
| 183 | + assert_equal(balances_0, expected_balances_0) |
| 184 | + assert_equal(balances_1, expected_balances_1) |
179 | 185 | # getbalance without any arguments includes unconfirmed transactions, but not untrusted transactions |
180 | 186 | assert_equal(self.nodes[0].getbalance(), Decimal('9.99')) # change from node 0's send |
181 | 187 | assert_equal(self.nodes[1].getbalance(), Decimal('0')) # node 1's send had an unsafe input |
@@ -304,5 +310,30 @@ def test_balances(*, fee_node_1=0): |
304 | 310 | assert_equal(self.nodes[0].getbalances()['mine']['untrusted_pending'], Decimal('0.1')) |
305 | 311 |
|
306 | 312 |
|
| 313 | + # Tests the lastprocessedblock JSON object in getbalances, getwalletinfo |
| 314 | + # and gettransaction by checking for valid hex strings and by comparing |
| 315 | + # the hashes & heights between generated blocks. |
| 316 | + self.log.info("Test getbalances returns expected lastprocessedblock json object") |
| 317 | + prev_hash = self.nodes[0].getbestblockhash() |
| 318 | + prev_height = self.nodes[0].getblock(prev_hash)['height'] |
| 319 | + self.generatetoaddress(self.nodes[0], 5, self.nodes[0].get_deterministic_priv_key().address) |
| 320 | + lastblock = self.nodes[0].getbalances()['lastprocessedblock'] |
| 321 | + assert_is_hash_string(lastblock['hash']) |
| 322 | + assert_equal((prev_hash == lastblock['hash']), False) |
| 323 | + assert_equal(lastblock['height'], prev_height + 5) |
| 324 | + |
| 325 | + prev_hash = self.nodes[0].getbestblockhash() |
| 326 | + prev_height = self.nodes[0].getblock(prev_hash)['height'] |
| 327 | + self.log.info("Test getwalletinfo returns expected lastprocessedblock json object") |
| 328 | + walletinfo = self.nodes[0].getwalletinfo() |
| 329 | + assert_equal(walletinfo['lastprocessedblock']['height'], prev_height) |
| 330 | + assert_equal(walletinfo['lastprocessedblock']['hash'], prev_hash) |
| 331 | + |
| 332 | + self.log.info("Test gettransaction returns expected lastprocessedblock json object") |
| 333 | + txid = self.nodes[1].sendtoaddress(self.nodes[1].getnewaddress(), 0.01) |
| 334 | + tx_info = self.nodes[1].gettransaction(txid) |
| 335 | + assert_equal(tx_info['lastprocessedblock']['height'], prev_height) |
| 336 | + assert_equal(tx_info['lastprocessedblock']['hash'], prev_hash) |
| 337 | + |
307 | 338 | if __name__ == '__main__': |
308 | 339 | WalletTest().main() |
0 commit comments