Changeset View
Changeset View
Standalone View
Standalone View
test/functional/mempool_updatefromblock.py
Show First 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | def transaction_graph_test(self, size, n_tx_to_mine=None, | ||||
# Create a new transaction. | # Create a new transaction. | ||||
unsigned_raw_tx = self.nodes[0].createrawtransaction( | unsigned_raw_tx = self.nodes[0].createrawtransaction( | ||||
inputs, outputs) | inputs, outputs) | ||||
signed_raw_tx = self.nodes[0].signrawtransactionwithwallet( | signed_raw_tx = self.nodes[0].signrawtransactionwithwallet( | ||||
unsigned_raw_tx) | unsigned_raw_tx) | ||||
tx_id.append( | tx_id.append( | ||||
self.nodes[0].sendrawtransaction( | self.nodes[0].sendrawtransaction( | ||||
signed_raw_tx['hex'])) | signed_raw_tx['hex'])) | ||||
tx_size.append(self.nodes[0].getrawmempool( | tx_size.append(self.nodes[0].getmempoolentry(tx_id[-1])['size']) | ||||
True)[tx_id[-1]]['size']) | |||||
if tx_count in n_tx_to_mine: | if tx_count in n_tx_to_mine: | ||||
# The created transactions are mined into blocks by batches. | # The created transactions are mined into blocks by batches. | ||||
self.log.info('The batch of {} transactions has been accepted' | self.log.info('The batch of {} transactions has been accepted' | ||||
' into the mempool.'.format(len(self.nodes[0].getrawmempool()))) | ' into the mempool.'.format(len(self.nodes[0].getrawmempool()))) | ||||
block_hash = self.nodes[0].generate(1)[0] | block_hash = self.nodes[0].generate(1)[0] | ||||
if not first_block_hash: | if not first_block_hash: | ||||
first_block_hash = block_hash | first_block_hash = block_hash | ||||
Show All 15 Lines | def transaction_graph_test(self, size, n_tx_to_mine=None, | ||||
'All of the recently mined transactions have been re-added' | 'All of the recently mined transactions have been re-added' | ||||
' into the mempool in {} seconds.'.format(end - start)) | ' into the mempool in {} seconds.'.format(end - start)) | ||||
self.log.info( | self.log.info( | ||||
'Checking descendants/ancestors properties of all of the' | 'Checking descendants/ancestors properties of all of the' | ||||
' in-mempool transactions...') | ' in-mempool transactions...') | ||||
for k, tx in enumerate(tx_id): | for k, tx in enumerate(tx_id): | ||||
self.log.debug('Check transaction #{}.'.format(k)) | self.log.debug('Check transaction #{}.'.format(k)) | ||||
assert_equal(self.nodes[0].getrawmempool(True)[ | entry = self.nodes[0].getmempoolentry(tx) | ||||
tx]['descendantcount'], size - k) | assert_equal(entry['descendantcount'], size - k) | ||||
assert_equal(self.nodes[0].getrawmempool(True)[ | assert_equal(entry['descendantsize'], sum(tx_size[k:size])) | ||||
tx]['descendantsize'], sum(tx_size[k:size])) | assert_equal(entry['ancestorcount'], k + 1) | ||||
assert_equal(self.nodes[0].getrawmempool( | assert_equal(entry['ancestorsize'], sum(tx_size[0:(k + 1)])) | ||||
True)[tx]['ancestorcount'], k + 1) | |||||
assert_equal(self.nodes[0].getrawmempool(True)[ | |||||
tx]['ancestorsize'], sum(tx_size[0:(k + 1)])) | |||||
def run_test(self): | def run_test(self): | ||||
# Use batch size limited by DEFAULT_ANCESTOR_LIMIT = 50 to not fire | # Use batch size limited by DEFAULT_ANCESTOR_LIMIT = 50 to not fire | ||||
# "too many unconfirmed parents" error. | # "too many unconfirmed parents" error. | ||||
self.transaction_graph_test(size=200, n_tx_to_mine=[50, 100, 150]) | self.transaction_graph_test(size=200, n_tx_to_mine=[50, 100, 150]) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
MempoolUpdateFromBlockTest().main() | MempoolUpdateFromBlockTest().main() |