|
4 | 4 | # file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
5 | 5 | """Test the wallet balance RPC methods."""
|
6 | 6 | from decimal import Decimal
|
| 7 | +import time |
7 | 8 |
|
8 | 9 | from test_framework.address import ADDRESS_BCRT1_UNSPENDABLE as ADDRESS_WATCHONLY
|
9 | 10 | from test_framework.blocktools import COINBASE_MATURITY
|
| 11 | +from test_framework.descriptors import descsum_create |
10 | 12 | from test_framework.test_framework import BitcoinTestFramework
|
11 | 13 | from test_framework.util import (
|
12 | 14 | assert_equal,
|
13 | 15 | assert_is_hash_string,
|
14 | 16 | assert_raises_rpc_error,
|
15 | 17 | )
|
| 18 | +from test_framework.wallet_util import get_generate_key |
16 | 19 |
|
17 | 20 |
|
18 | 21 | def create_transactions(node, address, amt, fees):
|
@@ -279,5 +282,30 @@ def test_balances(*, fee_node_1=0):
|
279 | 282 | assert_equal(tx_info['lastprocessedblock']['height'], prev_height)
|
280 | 283 | assert_equal(tx_info['lastprocessedblock']['hash'], prev_hash)
|
281 | 284 |
|
| 285 | + self.log.info("Test that the balance is updated by an import that makes an untracked output in an existing tx \"mine\"") |
| 286 | + default = self.nodes[0].get_wallet_rpc(self.default_wallet_name) |
| 287 | + self.nodes[0].createwallet("importupdate") |
| 288 | + wallet = self.nodes[0].get_wallet_rpc("importupdate") |
| 289 | + |
| 290 | + import_key1 = get_generate_key() |
| 291 | + import_key2 = get_generate_key() |
| 292 | + wallet.importdescriptors([{"desc": descsum_create(f"wpkh({import_key1.privkey})"), "timestamp": "now"}]) |
| 293 | + |
| 294 | + amount = 15 |
| 295 | + default.send([{import_key1.p2wpkh_addr: amount},{import_key2.p2wpkh_addr: amount}]) |
| 296 | + self.generate(self.nodes[0], 1) |
| 297 | + # Mock the time forward by 1 day so that "now" will exclude the block we just mined |
| 298 | + self.nodes[0].setmocktime(int(time.time()) + 86400) |
| 299 | + # Mine 11 blocks to move the MTP past the block we just mined |
| 300 | + self.generate(self.nodes[0], 11, sync_fun=self.no_op) |
| 301 | + |
| 302 | + balances = wallet.getbalances() |
| 303 | + assert_equal(balances["mine"]["trusted"], amount) |
| 304 | + |
| 305 | + # Don't rescan to make sure that the import updates the wallet txos |
| 306 | + wallet.importdescriptors([{"desc": descsum_create(f"wpkh({import_key2.privkey})"), "timestamp": "now"}]) |
| 307 | + balances = wallet.getbalances() |
| 308 | + assert_equal(balances["mine"]["trusted"], amount * 2) |
| 309 | + |
282 | 310 | if __name__ == '__main__':
|
283 | 311 | WalletTest(__file__).main()
|
0 commit comments