Changeset View
Changeset View
Standalone View
Standalone View
test/functional/mempool_packages.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2014-2019 The Bitcoin Core developers | # Copyright (c) 2014-2019 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test descendant package tracking code.""" | """Test descendant package tracking code.""" | ||||
from decimal import Decimal | from decimal import Decimal | ||||
from test_framework.messages import COIN | from test_framework.messages import COIN | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
assert_raises_rpc_error, | assert_raises_rpc_error, | ||||
satoshi_round, | satoshi_round, | ||||
sync_blocks, | |||||
sync_mempools, | |||||
) | ) | ||||
# TODO: The activation code can be reverted after the new policy becomes | # TODO: The activation code can be reverted after the new policy becomes | ||||
# active. | # active. | ||||
# Phonon dummy activation time | # Phonon dummy activation time | ||||
ACTIVATION_TIME = 2000000000 | ACTIVATION_TIME = 2000000000 | ||||
▲ Show 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# Adding one more transaction on to the chain should fail. | # Adding one more transaction on to the chain should fail. | ||||
assert_raises_rpc_error(-26, "too-long-mempool-chain", | assert_raises_rpc_error(-26, "too-long-mempool-chain", | ||||
self.chain_transaction, self.nodes[0], txid, vout, value, fee, 1) | self.chain_transaction, self.nodes[0], txid, vout, value, fee, 1) | ||||
# Check that prioritising a tx before it's added to the mempool works | # Check that prioritising a tx before it's added to the mempool works | ||||
# First clear the mempool by mining a block. | # First clear the mempool by mining a block. | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
sync_blocks(self.nodes) | self.sync_blocks() | ||||
assert_equal(len(self.nodes[0].getrawmempool()), 0) | assert_equal(len(self.nodes[0].getrawmempool()), 0) | ||||
# Prioritise a transaction that has been mined, then add it back to the | # Prioritise a transaction that has been mined, then add it back to the | ||||
# mempool by using invalidateblock. | # mempool by using invalidateblock. | ||||
self.nodes[0].prioritisetransaction(txid=chain[-1], fee_delta=2000) | self.nodes[0].prioritisetransaction(txid=chain[-1], fee_delta=2000) | ||||
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | ||||
# Keep node1's tip synced with node0 | # Keep node1's tip synced with node0 | ||||
self.nodes[1].invalidateblock(self.nodes[1].getbestblockhash()) | self.nodes[1].invalidateblock(self.nodes[1].getbestblockhash()) | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# TODO: check that node1's mempool is as expected | # TODO: check that node1's mempool is as expected | ||||
# TODO: test descendant size limits | # TODO: test descendant size limits | ||||
# Test reorg handling | # Test reorg handling | ||||
# First, the basics: | # First, the basics: | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
sync_blocks(self.nodes) | self.sync_blocks() | ||||
self.nodes[1].invalidateblock(self.nodes[0].getbestblockhash()) | self.nodes[1].invalidateblock(self.nodes[0].getbestblockhash()) | ||||
self.nodes[1].reconsiderblock(self.nodes[0].getbestblockhash()) | self.nodes[1].reconsiderblock(self.nodes[0].getbestblockhash()) | ||||
# Now test the case where node1 has a transaction T in its mempool that | # Now test the case where node1 has a transaction T in its mempool that | ||||
# depends on transactions A and B which are in a mined block, and the | # depends on transactions A and B which are in a mined block, and the | ||||
# block containing A and B is disconnected, AND B is not accepted back | # block containing A and B is disconnected, AND B is not accepted back | ||||
# into node1's mempool because its ancestor count is too high. | # into node1's mempool because its ancestor count is too high. | ||||
Show All 40 Lines | def run_test(self): | ||||
self.sync_all() | self.sync_all() | ||||
# Now generate tx8, with a big fee | # Now generate tx8, with a big fee | ||||
inputs = [{'txid': tx1_id, 'vout': 0}, {'txid': txid, 'vout': 0}] | inputs = [{'txid': tx1_id, 'vout': 0}, {'txid': txid, 'vout': 0}] | ||||
outputs = {self.nodes[0].getnewaddress(): send_value + value - 4 * fee} | outputs = {self.nodes[0].getnewaddress(): send_value + value - 4 * fee} | ||||
rawtx = self.nodes[0].createrawtransaction(inputs, outputs) | rawtx = self.nodes[0].createrawtransaction(inputs, outputs) | ||||
signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx) | signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx) | ||||
txid = self.nodes[0].sendrawtransaction(signedtx['hex']) | txid = self.nodes[0].sendrawtransaction(signedtx['hex']) | ||||
sync_mempools(self.nodes) | self.sync_mempools() | ||||
# Now try to disconnect the tip on each node... | # Now try to disconnect the tip on each node... | ||||
self.nodes[1].invalidateblock(self.nodes[1].getbestblockhash()) | self.nodes[1].invalidateblock(self.nodes[1].getbestblockhash()) | ||||
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | ||||
sync_blocks(self.nodes) | self.sync_blocks() | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
MempoolPackagesTest().main() | MempoolPackagesTest().main() |