|
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 |
|
@@ -183,8 +184,13 @@ def test_balances(*, fee_node_1=0): |
183 | 184 | 'untrusted_pending': Decimal('30.0') - fee_node_1}} # Doesn't include output of node 0's send since it was spent |
184 | 185 | if self.options.descriptors: |
185 | 186 | del expected_balances_0["watchonly"] |
186 | | - assert_equal(self.nodes[0].getbalances(), expected_balances_0) |
187 | | - assert_equal(self.nodes[1].getbalances(), expected_balances_1) |
| 187 | + balances_0 = self.nodes[0].getbalances() |
| 188 | + balances_1 = self.nodes[1].getbalances() |
| 189 | + # remove lastprocessedblock keys (they will be tested later) |
| 190 | + del balances_0['lastprocessedblock'] |
| 191 | + del balances_1['lastprocessedblock'] |
| 192 | + assert_equal(balances_0, expected_balances_0) |
| 193 | + assert_equal(balances_1, expected_balances_1) |
188 | 194 | # getbalance without any arguments includes unconfirmed transactions, but not untrusted transactions |
189 | 195 | assert_equal(self.nodes[0].getbalance(), Decimal('9.99')) # change from node 0's send |
190 | 196 | assert_equal(self.nodes[1].getbalance(), Decimal('0')) # node 1's send had an unsafe input |
@@ -309,5 +315,30 @@ def test_balances(*, fee_node_1=0): |
309 | 315 | assert_equal(self.nodes[0].getbalances()['mine']['untrusted_pending'], Decimal('0.1')) |
310 | 316 |
|
311 | 317 |
|
| 318 | + # Tests the lastprocessedblock JSON object in getbalances, getwalletinfo |
| 319 | + # and gettransaction by checking for valid hex strings and by comparing |
| 320 | + # the hashes & heights between generated blocks. |
| 321 | + self.log.info("Test getbalances returns expected lastprocessedblock json object") |
| 322 | + prev_hash = self.nodes[0].getbestblockhash() |
| 323 | + prev_height = self.nodes[0].getblock(prev_hash)['height'] |
| 324 | + self.generatetoaddress(self.nodes[0], 5, self.nodes[0].get_deterministic_priv_key().address) |
| 325 | + lastblock = self.nodes[0].getbalances()['lastprocessedblock'] |
| 326 | + assert_is_hash_string(lastblock['hash']) |
| 327 | + assert_equal((prev_hash == lastblock['hash']), False) |
| 328 | + assert_equal(lastblock['height'], prev_height + 5) |
| 329 | + |
| 330 | + prev_hash = self.nodes[0].getbestblockhash() |
| 331 | + prev_height = self.nodes[0].getblock(prev_hash)['height'] |
| 332 | + self.log.info("Test getwalletinfo returns expected lastprocessedblock json object") |
| 333 | + walletinfo = self.nodes[0].getwalletinfo() |
| 334 | + assert_equal(walletinfo['lastprocessedblock']['height'], prev_height) |
| 335 | + assert_equal(walletinfo['lastprocessedblock']['hash'], prev_hash) |
| 336 | + |
| 337 | + self.log.info("Test gettransaction returns expected lastprocessedblock json object") |
| 338 | + txid = self.nodes[1].sendtoaddress(self.nodes[1].getnewaddress(), 0.01) |
| 339 | + tx_info = self.nodes[1].gettransaction(txid) |
| 340 | + assert_equal(tx_info['lastprocessedblock']['height'], prev_height) |
| 341 | + assert_equal(tx_info['lastprocessedblock']['hash'], prev_hash) |
| 342 | + |
312 | 343 | if __name__ == '__main__': |
313 | 344 | WalletTest().main() |
0 commit comments