diff options
author | Michael Dietz <michael.dietz@waya.ai> | 2020-12-17 14:57:12 -0600 |
---|---|---|
committer | Michael Dietz <michael.dietz@waya.ai> | 2020-12-17 21:37:07 -0600 |
commit | 11a32722f09f1d81f34bd09b26248ba99f2e7f07 (patch) | |
tree | a95d18cb48e5a39ab8764ef8d6406f0876d11d6e /test/functional/mempool_resurrect.py | |
parent | 143bd108ed6626405b0361c9939a8e1bf6cfc3d2 (diff) |
test: run mempool_resurrect.py even with wallet disabled
Diffstat (limited to 'test/functional/mempool_resurrect.py')
-rwxr-xr-x | test/functional/mempool_resurrect.py | 61 |
1 files changed, 27 insertions, 34 deletions
diff --git a/test/functional/mempool_resurrect.py b/test/functional/mempool_resurrect.py index 187c9026f6..3a0db70f66 100755 --- a/test/functional/mempool_resurrect.py +++ b/test/functional/mempool_resurrect.py @@ -4,66 +4,59 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test resurrection of mined transactions when the blockchain is re-organized.""" -from test_framework.blocktools import create_raw_transaction from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal +from test_framework.wallet import MiniWallet class MempoolCoinbaseTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 1 - - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() + self.setup_clean_chain = True def run_test(self): - node0_address = self.nodes[0].getnewaddress() + node = self.nodes[0] + wallet = MiniWallet(node) + + # Add enough mature utxos to the wallet so that all txs spend confirmed coins + wallet.generate(3) + node.generate(100) + # Spend block 1/2/3's coinbase transactions - # Mine a block. + # Mine a block # Create three more transactions, spending the spends - # Mine another block. + # 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] - spends1_raw = [create_raw_transaction(self.nodes[0], txid, node0_address, amount=49.99) for txid in coinbase_txids] - spends1_id = [self.nodes[0].sendrawtransaction(tx) for tx in spends1_raw] - + # ... make sure all the transactions are confirmed again blocks = [] - blocks.extend(self.nodes[0].generate(1)) - - spends2_raw = [create_raw_transaction(self.nodes[0], txid, node0_address, amount=49.98) for txid in spends1_id] - spends2_id = [self.nodes[0].sendrawtransaction(tx) for tx in spends2_raw] + spends1_ids = [wallet.send_self_transfer(from_node=node)['txid'] for _ in range(3)] + blocks.extend(node.generate(1)) + spends2_ids = [wallet.send_self_transfer(from_node=node)['txid'] for _ in range(3)] + blocks.extend(node.generate(1)) - blocks.extend(self.nodes[0].generate(1)) + spends_ids = set(spends1_ids + spends2_ids) # 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 + assert_equal(set(node.getrawmempool()), set()) + confirmed_txns = set(node.getblock(blocks[0])['tx'] + node.getblock(blocks[1])['tx']) + # Checks that all spend txns are contained in the mined blocks + assert(spends_ids < confirmed_txns) # Use invalidateblock to re-org back - for node in self.nodes: - node.invalidateblock(blocks[0]) + node.invalidateblock(blocks[0]) # All txns should be back in mempool with 0 confirmations - 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 + assert_equal(set(node.getrawmempool()), spends_ids) # Generate another block, they should all get mined - self.nodes[0].generate(1) + node.generate(1) # 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 + assert_equal(set(node.getrawmempool()), set()) + confirmed_txns = set(node.getblock(blocks[0])['tx'] + node.getblock(blocks[1])['tx']) + assert(spends_ids < confirmed_txns) if __name__ == '__main__': |