mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 13:03:17 +01:00
f3bc9535da
7a681d61b0d98a310fbb1b8e095ab8fbc5d5741c Add sync_blocks in wallet_orphanedreward.py. (Daniel Kraft) Pull request description: Add an explicit `sync_blocks` call in `wallet_orphanedreward.py`, which was missing and could lead to intermittent failures of the test due to race conditions. This will presumably fix #22181. ACKs for top commit: MarcoFalke: review ACK 7a681d61b0d98a310fbb1b8e095ab8fbc5d5741c Tree-SHA512: bb226c31bf3f2e7c52beb829d7b67496e5b38781245db5f9184e3f28c93ac3aa4d21fcf5bf3055e79d384cfd0ed916e79dccb3d77486e86fe1fedb5e35f894ad
66 lines
2.6 KiB
Python
Executable File
66 lines
2.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2020-2021 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
|
|
from decimal import Decimal
|
|
|
|
class OrphanedBlockRewardTest(BitcoinTestFramework):
|
|
def set_test_params(self):
|
|
self.setup_clean_chain = True
|
|
self.num_nodes = 2
|
|
|
|
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(1)
|
|
|
|
# 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)
|
|
self.sync_blocks()
|
|
assert_equal(self.nodes[1].getbalance(), Decimal("474.28571429"))
|
|
txid = self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 30)
|
|
|
|
# Orphan the block reward and make sure that the original coins
|
|
# from the wallet can still be spent.
|
|
self.nodes[0].invalidateblock(blk)
|
|
self.nodes[0].generate(152)
|
|
self.sync_blocks()
|
|
# Without the following abandontransaction call, the coins are
|
|
# not considered available yet.
|
|
assert_equal(self.nodes[1].getbalances()["mine"], {
|
|
"trusted": Decimal('10.00000000'),
|
|
"untrusted_pending": Decimal('0E-8'),
|
|
"immature": Decimal('0E-8'),
|
|
"coinjoin": Decimal('0E-8'),
|
|
})
|
|
# The following abandontransaction is necessary to make the later
|
|
# lines succeed, and probably should not be needed; see
|
|
# https://github.com/bitcoin/bitcoin/issues/14148.
|
|
self.nodes[1].abandontransaction(txid)
|
|
assert_equal(self.nodes[1].getbalances()["mine"], {
|
|
"trusted": Decimal('10.00000000'),
|
|
"untrusted_pending": Decimal('0.00000000'),
|
|
"immature": Decimal('0.00000000'),
|
|
"coinjoin": Decimal('0E-8'),
|
|
})
|
|
self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 9)
|
|
|
|
if __name__ == '__main__':
|
|
OrphanedBlockRewardTest().main()
|