You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
3.1 KiB
78 lines
3.1 KiB
![]()
9 years ago
|
#!/usr/bin/env python3
|
||
|
# Copyright (c) 2014-2016 The Bitcoin Core developers
|
||
![]()
10 years ago
|
# Distributed under the MIT software license, see the accompanying
|
||
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||
![]()
8 years ago
|
"""Test resurrection of mined transactions when the blockchain is re-organized."""
|
||
![]()
10 years ago
|
|
||
![]()
9 years ago
|
from test_framework.test_framework import BitcoinTestFramework
|
||
|
from test_framework.util import *
|
||
![]()
10 years ago
|
|
||
|
# Create one-input, one-output, no-fee transaction:
|
||
|
class MempoolCoinbaseTest(BitcoinTestFramework):
|
||
|
|
||
![]()
8 years ago
|
def __init__(self):
|
||
|
super().__init__()
|
||
|
self.num_nodes = 1
|
||
|
self.setup_clean_chain = False
|
||
|
|
||
![]()
10 years ago
|
def setup_network(self):
|
||
|
# Just need one node for this test
|
||
![]()
8 years ago
|
args = ["-checkmempool"]
|
||
![]()
10 years ago
|
self.nodes = []
|
||
|
self.nodes.append(start_node(0, self.options.tmpdir, args))
|
||
|
self.is_network_split = False
|
||
|
|
||
|
def run_test(self):
|
||
|
node0_address = self.nodes[0].getnewaddress()
|
||
|
# Spend block 1/2/3's coinbase transactions
|
||
|
# Mine a block.
|
||
|
# Create three more transactions, spending the spends
|
||
|
# Mine another block.
|
||
|
# ... make sure all the transactions are confirmed
|
||
|
# Invalidate both blocks
|
||
|
# ... make sure all the transactions are put back in the mempool
|
||
|
# Mine a new block
|
||
|
# ... make sure all the transactions are confirmed again.
|
||
|
|
||
|
b = [ self.nodes[0].getblockhash(n) for n in range(1, 4) ]
|
||
|
coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ]
|
||
![]()
9 years ago
|
spends1_raw = [ create_tx(self.nodes[0], txid, node0_address, 49.99) for txid in coinbase_txids ]
|
||
![]()
10 years ago
|
spends1_id = [ self.nodes[0].sendrawtransaction(tx) for tx in spends1_raw ]
|
||
|
|
||
|
blocks = []
|
||
![]()
10 years ago
|
blocks.extend(self.nodes[0].generate(1))
|
||
![]()
10 years ago
|
|
||
![]()
9 years ago
|
spends2_raw = [ create_tx(self.nodes[0], txid, node0_address, 49.98) for txid in spends1_id ]
|
||
![]()
10 years ago
|
spends2_id = [ self.nodes[0].sendrawtransaction(tx) for tx in spends2_raw ]
|
||
|
|
||
![]()
10 years ago
|
blocks.extend(self.nodes[0].generate(1))
|
||
![]()
10 years ago
|
|
||
|
# mempool should be empty, all txns confirmed
|
||
|
assert_equal(set(self.nodes[0].getrawmempool()), set())
|
||
|
for txid in spends1_id+spends2_id:
|
||
|
tx = self.nodes[0].gettransaction(txid)
|
||
|
assert(tx["confirmations"] > 0)
|
||
|
|
||
|
# Use invalidateblock to re-org back; all transactions should
|
||
|
# end up unconfirmed and back in the mempool
|
||
|
for node in self.nodes:
|
||
|
node.invalidateblock(blocks[0])
|
||
|
|
||
|
# mempool should be empty, all txns confirmed
|
||
|
assert_equal(set(self.nodes[0].getrawmempool()), set(spends1_id+spends2_id))
|
||
|
for txid in spends1_id+spends2_id:
|
||
|
tx = self.nodes[0].gettransaction(txid)
|
||
|
assert(tx["confirmations"] == 0)
|
||
|
|
||
|
# Generate another block, they should all get mined
|
||
![]()
10 years ago
|
self.nodes[0].generate(1)
|
||
![]()
10 years ago
|
# mempool should be empty, all txns confirmed
|
||
|
assert_equal(set(self.nodes[0].getrawmempool()), set())
|
||
|
for txid in spends1_id+spends2_id:
|
||
|
tx = self.nodes[0].gettransaction(txid)
|
||
|
assert(tx["confirmations"] > 0)
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
MempoolCoinbaseTest().main()
|