Changeset View
Changeset View
Standalone View
Standalone View
test/functional/mempool_updatefromblock.py
Show All 11 Lines | |||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import assert_equal | from test_framework.util import assert_equal | ||||
class MempoolUpdateFromBlockTest(BitcoinTestFramework): | class MempoolUpdateFromBlockTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
self.limit_ancestor_descendant_count = 60 | self.ancestor_descendant_count = 60 | ||||
self.extra_args = [ | |||||
[ | |||||
"-limitdescendantsize=5000", | |||||
"-limitancestorsize=5000", | |||||
f"-limitancestorcount={self.limit_ancestor_descendant_count}", | |||||
f"-limitdescendantcount={self.limit_ancestor_descendant_count}", | |||||
"-deprecatedrpc=mempool_ancestors_descendants", | |||||
], | |||||
] | |||||
def skip_test_if_missing_module(self): | def skip_test_if_missing_module(self): | ||||
self.skip_if_no_wallet() | self.skip_if_no_wallet() | ||||
def transaction_graph_test( | def transaction_graph_test( | ||||
self, | self, | ||||
size, | size, | ||||
n_tx_to_mine=None, | n_tx_to_mine=None, | ||||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | ): | ||||
self.nodes[0].invalidateblock(first_block_hash) | self.nodes[0].invalidateblock(first_block_hash) | ||||
end = time.time() | end = time.time() | ||||
assert_equal(len(self.nodes[0].getrawmempool()), size) | assert_equal(len(self.nodes[0].getrawmempool()), size) | ||||
self.log.info( | self.log.info( | ||||
"All of the recently mined transactions have been re-added into " | "All of the recently mined transactions have been re-added into " | ||||
f"the mempool in {end - start} seconds." | f"the mempool in {end - start} seconds." | ||||
) | ) | ||||
self.log.info( | |||||
"Checking descendants/ancestors properties of all of the" | |||||
" in-mempool transactions..." | |||||
) | |||||
for k, tx in enumerate(tx_id): | |||||
self.log.debug(f"Check transaction #{k}.") | |||||
entry = self.nodes[0].getmempoolentry(tx) | |||||
assert_equal(entry["descendantcount"], size - k) | |||||
assert_equal(entry["descendantsize"], sum(tx_size[k:size])) | |||||
assert_equal(entry["ancestorcount"], k + 1) | |||||
assert_equal(entry["ancestorsize"], sum(tx_size[0 : (k + 1)])) | |||||
def run_test(self): | def run_test(self): | ||||
# Mine the transactions in batches so we get reorg_depth blocks | # Mine the transactions in batches so we get reorg_depth blocks | ||||
# reorg'ed | # reorg'ed | ||||
reorg_depth = 4 | reorg_depth = 4 | ||||
self.transaction_graph_test( | self.transaction_graph_test( | ||||
size=self.limit_ancestor_descendant_count, | size=self.ancestor_descendant_count, | ||||
n_tx_to_mine=range( | n_tx_to_mine=range( | ||||
0, | 0, | ||||
self.limit_ancestor_descendant_count, | self.ancestor_descendant_count, | ||||
self.limit_ancestor_descendant_count // reorg_depth, | self.ancestor_descendant_count // reorg_depth, | ||||
), | ), | ||||
) | ) | ||||
if __name__ == "__main__": | if __name__ == "__main__": | ||||
MempoolUpdateFromBlockTest().main() | MempoolUpdateFromBlockTest().main() |