Skip to content

Commit 3ac5209

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#18795: Test: wallet issue with orphaned rewards
e4356f6 Testcase for wallet issue with orphaned rewards. (Daniel Kraft) Pull request description: This adds a new test case demonstrating the wallet issue when block rewards are orphaned (#14148). ACKs for top commit: LarryRuane: ACK e4356f6 leonardojobim: reACK bitcoin/bitcoin@e4356f6 . Tree-SHA512: e9a2310ee1b3d52cfa302f431ed3d272bbc1b9195439ff318d9eb1006c0b28968dbe840e1600b6ff185e5d7ea57e4dcc837cef16051b5537445e10bc363b8c22
2 parents a748782 + e4356f6 commit 3ac5209

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

test/functional/test_runner.py

+1
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@
284284
'feature_logging.py',
285285
'feature_anchors.py',
286286
'feature_coinstatsindex.py',
287+
'wallet_orphanedreward.py',
287288
'p2p_node_network_limited.py',
288289
'p2p_permissions.py',
289290
'feature_blocksdir.py',
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2020-2021 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""Test orphaned block rewards in the wallet."""
6+
7+
from test_framework.test_framework import BitcoinTestFramework
8+
from test_framework.util import assert_equal
9+
10+
class OrphanedBlockRewardTest(BitcoinTestFramework):
11+
def set_test_params(self):
12+
self.setup_clean_chain = True
13+
self.num_nodes = 2
14+
15+
def skip_test_if_missing_module(self):
16+
self.skip_if_no_wallet()
17+
18+
def run_test(self):
19+
# Generate some blocks and obtain some coins on node 0. We send
20+
# some balance to node 1, which will hold it as a single coin.
21+
self.nodes[0].generate(150)
22+
self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 10)
23+
self.nodes[0].generate(1)
24+
25+
# Get a block reward with node 1 and remember the block so we can orphan
26+
# it later.
27+
self.sync_blocks()
28+
blk = self.nodes[1].generate(1)[0]
29+
self.sync_blocks()
30+
31+
# Let the block reward mature and send coins including both
32+
# the existing balance and the block reward.
33+
self.nodes[0].generate(150)
34+
assert_equal(self.nodes[1].getbalance(), 10 + 25)
35+
txid = self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 30)
36+
37+
# Orphan the block reward and make sure that the original coins
38+
# from the wallet can still be spent.
39+
self.nodes[0].invalidateblock(blk)
40+
self.nodes[0].generate(152)
41+
self.sync_blocks()
42+
# Without the following abandontransaction call, the coins are
43+
# not considered available yet.
44+
assert_equal(self.nodes[1].getbalances()["mine"], {
45+
"trusted": 0,
46+
"untrusted_pending": 0,
47+
"immature": 0,
48+
})
49+
# The following abandontransaction is necessary to make the later
50+
# lines succeed, and probably should not be needed; see
51+
# https://github.com/bitcoin/bitcoin/issues/14148.
52+
self.nodes[1].abandontransaction(txid)
53+
assert_equal(self.nodes[1].getbalances()["mine"], {
54+
"trusted": 10,
55+
"untrusted_pending": 0,
56+
"immature": 0,
57+
})
58+
self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 9)
59+
60+
if __name__ == '__main__':
61+
OrphanedBlockRewardTest().main()

0 commit comments

Comments
 (0)