Skip to content

Commit b0fa598

Browse files
committed
test: Check that orphaned coinbase unconf spend is still abandoned
When an orphaned coinbase is reorged back into the main chain, any unconfirmed ancestors should still be marked as abandoned due to the original reorg that orphaned that coinbase.
1 parent 9addbd7 commit b0fa598

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

test/functional/wallet_orphanedreward.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,40 @@ def run_test(self):
3131
# the existing balance and the block reward.
3232
self.generate(self.nodes[0], 150)
3333
assert_equal(self.nodes[1].getbalance(), 10 + 25)
34+
pre_reorg_conf_bals = self.nodes[1].getbalances()
3435
txid = self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 30)
36+
orig_chain_tip = self.nodes[0].getbestblockhash()
37+
self.sync_mempools()
3538

3639
# Orphan the block reward and make sure that the original coins
3740
# from the wallet can still be spent.
3841
self.nodes[0].invalidateblock(blk)
39-
self.generate(self.nodes[0], 152)
42+
blocks = self.generate(self.nodes[0], 152)
43+
conflict_block = blocks[0]
4044
# We expect the descendants of orphaned rewards to no longer be considered
4145
assert_equal(self.nodes[1].getbalances()["mine"], {
4246
"trusted": 10,
4347
"untrusted_pending": 0,
4448
"immature": 0,
4549
})
46-
self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 9)
50+
# And the unconfirmed tx to be abandoned
51+
assert_equal(self.nodes[1].gettransaction(txid)["details"][0]["abandoned"], True)
52+
53+
# The abandoning should persist through reloading
54+
self.nodes[1].unloadwallet(self.default_wallet_name)
55+
self.nodes[1].loadwallet(self.default_wallet_name)
56+
assert_equal(self.nodes[1].gettransaction(txid)["details"][0]["abandoned"], True)
57+
58+
# If the orphaned reward is reorged back into the main chain, any unconfirmed
59+
# descendant txs at the time of the original reorg remain abandoned.
60+
self.nodes[0].invalidateblock(conflict_block)
61+
self.nodes[0].reconsiderblock(blk)
62+
assert_equal(self.nodes[0].getbestblockhash(), orig_chain_tip)
63+
self.generate(self.nodes[0], 3)
64+
65+
assert_equal(self.nodes[1].getbalances(), pre_reorg_conf_bals)
66+
assert_equal(self.nodes[1].gettransaction(txid)["details"][0]["abandoned"], True)
67+
4768

4869
if __name__ == '__main__':
4970
OrphanedBlockRewardTest().main()

0 commit comments

Comments
 (0)