mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
471c2cb211
a7599c80ebb9579df45e2d6ccf3168302cf42f03 test: run mempool_compatibility.py even with wallet disabled (Michael Dietz) Pull request description: Another functional test rewritten as proposed in https://github.com/bitcoin/bitcoin/issues/20078 ACKs for top commit: MarcoFalke: review ACK a7599c80ebb9579df45e2d6ccf3168302cf42f03 didn't test Tree-SHA512: cc7a617e5489ed27bbdbdee85a82fa08525375061f7f4524577a6b8ecb340396adac88419b51f513be22ca53edd0a3bd5d572d9f43ffc2c18550b0ef9069d238
85 lines
3.3 KiB
Python
Executable File
85 lines
3.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2017-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 that mempool.dat is both backward and forward compatible between versions
|
|
|
|
NOTE: The test is designed to prevent cases when compatibility is broken accidentally.
|
|
In case we need to break mempool compatibility we can continue to use the test by just bumping the version number.
|
|
|
|
The previous release v0.15.0.0 is required by this test, see test/README.md.
|
|
"""
|
|
|
|
import os
|
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
from test_framework.wallet import MiniWallet
|
|
|
|
|
|
class MempoolCompatibilityTest(BitcoinTestFramework):
|
|
def set_test_params(self):
|
|
self.num_nodes = 2
|
|
self.wallet_names = [None]
|
|
|
|
def skip_test_if_missing_module(self):
|
|
self.skip_if_no_previous_releases()
|
|
|
|
def setup_network(self):
|
|
self.add_nodes(self.num_nodes, versions=[
|
|
150000, # oldest version supported by the test framework
|
|
None,
|
|
])
|
|
self.extra_args = [
|
|
[],
|
|
[],
|
|
]
|
|
self.start_nodes()
|
|
self.import_deterministic_coinbase_privkeys()
|
|
|
|
def run_test(self):
|
|
self.log.info("Test that mempool.dat is compatible between versions")
|
|
|
|
old_node, new_node = self.nodes
|
|
new_wallet = MiniWallet(new_node)
|
|
new_wallet.generate(1)
|
|
new_node.generate(100)
|
|
# Sync the nodes to ensure old_node has the block that contains the coinbase that new_wallet will spend.
|
|
# Otherwise, because coinbases are only valid in a block and not as loose txns, if the nodes aren't synced
|
|
# unbroadcasted_tx won't pass old_node's `MemPoolAccept::PreChecks`.
|
|
self.connect_nodes(0, 1)
|
|
self.sync_blocks()
|
|
recipient = old_node.getnewaddress()
|
|
self.stop_node(1)
|
|
|
|
self.log.info("Add a transaction to mempool on old node and shutdown")
|
|
old_tx_hash = old_node.sendtoaddress(recipient, 0.0001)
|
|
assert old_tx_hash in old_node.getrawmempool()
|
|
self.stop_node(0)
|
|
|
|
self.log.info("Move mempool.dat from old to new node")
|
|
old_node_mempool = os.path.join(old_node.datadir, self.chain, 'mempool.dat')
|
|
new_node_mempool = os.path.join(new_node.datadir, self.chain, 'mempool.dat')
|
|
os.rename(old_node_mempool, new_node_mempool)
|
|
|
|
self.log.info("Start new node and verify mempool contains the tx")
|
|
self.start_node(1)
|
|
assert old_tx_hash in new_node.getrawmempool()
|
|
|
|
self.log.info("Add unbroadcasted tx to mempool on new node and shutdown")
|
|
unbroadcasted_tx_hash = new_wallet.send_self_transfer(from_node=new_node)['txid']
|
|
assert unbroadcasted_tx_hash in new_node.getrawmempool()
|
|
mempool = new_node.getrawmempool(True)
|
|
assert mempool[unbroadcasted_tx_hash]['unbroadcast']
|
|
self.stop_node(1)
|
|
|
|
self.log.info("Move mempool.dat from new to old node")
|
|
os.rename(new_node_mempool, old_node_mempool)
|
|
|
|
self.log.info("Start old node again and verify mempool contains both txs")
|
|
self.start_node(0, ['-nowallet'])
|
|
assert old_tx_hash in old_node.getrawmempool()
|
|
assert unbroadcasted_tx_hash in old_node.getrawmempool()
|
|
|
|
if __name__ == "__main__":
|
|
MempoolCompatibilityTest().main()
|