forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testcase for wallet issue with orphaned rewards.
This adds a new test case demonstrating the wallet issue when block rewards are orphaned (bitcoin#14148).
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2020 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
"""Test orphaned block rewards in the wallet.""" | ||
|
||
from test_framework.test_framework import BitcoinTestFramework | ||
from test_framework.util import assert_equal, assert_raises_rpc_error | ||
|
||
|
||
class OrphanedBlockRewardTest(BitcoinTestFramework): | ||
def set_test_params(self): | ||
self.setup_clean_chain = True | ||
self.num_nodes = 2 | ||
self.supports_cli = False | ||
|
||
def skip_test_if_missing_module(self): | ||
self.skip_if_no_wallet() | ||
|
||
def run_test(self): | ||
# Generate some blocks and obtain some coins on node 0. We send | ||
# some balance to node 1, which will hold it as a single coin. | ||
self.nodes[0].generate (150) | ||
self.nodes[0].sendtoaddress (self.nodes[1].getnewaddress (), 10) | ||
self.nodes[0].generate (50) | ||
|
||
# Get a block reward with node 1 and remember the block so we can orphan | ||
# it later. | ||
self.sync_blocks () | ||
blk = self.nodes[1].generate (1)[0] | ||
self.sync_blocks () | ||
|
||
# Let the block reward mature and send coins including both | ||
# the existing balance and the block reward. | ||
self.nodes[0].generate (150) | ||
assert_equal (self.nodes[1].getbalance (), 10 + 25) | ||
txid = self.nodes[1].sendtoaddress (self.nodes[0].getnewaddress (), 30) | ||
|
||
# Orphan the block reward and observe that also the original coins | ||
# from the wallet are still locked. | ||
self.nodes[0].invalidateblock (blk) | ||
self.nodes[0].generate (200) | ||
self.sync_blocks () | ||
assert_raises_rpc_error (-6, 'Insufficient funds', | ||
self.nodes[1].sendtoaddress, | ||
self.nodes[0].getnewaddress (), 9) | ||
|
||
# Abandoning the transaction frees the funds again. | ||
self.nodes[1].abandontransaction (txid) | ||
self.nodes[1].sendtoaddress (self.nodes[0].getnewaddress (), 9) | ||
|
||
|
||
if __name__ == '__main__': | ||
OrphanedBlockRewardTest().main() |