Changeset View
Changeset View
Standalone View
Standalone View
test/functional/mempool_packages.py
Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# Mine some blocks and have them mature. | # Mine some blocks and have them mature. | ||||
# keep track of invs | # keep track of invs | ||||
peer_inv_store = self.nodes[0].add_p2p_connection(P2PTxInvStore()) | peer_inv_store = self.nodes[0].add_p2p_connection(P2PTxInvStore()) | ||||
self.nodes[0].generate(101) | self.nodes[0].generate(101) | ||||
utxo = self.nodes[0].listunspent(10) | utxo = self.nodes[0].listunspent(10) | ||||
txid = utxo[0]['txid'] | txid = utxo[0]['txid'] | ||||
vout = utxo[0]['vout'] | vout = utxo[0]['vout'] | ||||
value = utxo[0]['amount'] | value = utxo[0]['amount'] | ||||
assert 'ancestorcount' not in utxo[0] | |||||
assert 'ancestorsize' not in utxo[0] | |||||
assert 'ancestorfees' not in utxo[0] | |||||
fee = Decimal("100") | fee = Decimal("100") | ||||
# MAX_ANCESTORS transactions off a confirmed tx should be fine | # MAX_ANCESTORS transactions off a confirmed tx should be fine | ||||
chain = [] | chain = [] | ||||
for _ in range(MAX_ANCESTORS): | ancestor_size = 0 | ||||
ancestor_fees = Decimal(0) | |||||
for i in range(MAX_ANCESTORS): | |||||
(txid, sent_value) = self.chain_transaction( | (txid, sent_value) = self.chain_transaction( | ||||
self.nodes[0], txid, 0, value, fee, 1) | self.nodes[0], txid, 0, value, fee, 1) | ||||
value = sent_value | value = sent_value | ||||
chain.append(txid) | chain.append(txid) | ||||
# Check that listunspent ancestor{count, size, fees} yield the | |||||
# correct results | |||||
wallet_unspent = self.nodes[0].listunspent(minconf=0) | |||||
this_unspent = next( | |||||
utxo_info for utxo_info in wallet_unspent if utxo_info['txid'] == txid) | |||||
assert_equal(this_unspent['ancestorcount'], i + 1) | |||||
ancestor_size += self.nodes[0].getrawtransaction( | |||||
txid=txid, verbose=True)['size'] | |||||
assert_equal(this_unspent['ancestorsize'], ancestor_size) | |||||
ancestor_fees -= self.nodes[0].gettransaction(txid=txid)['fee'] | |||||
assert_equal(this_unspent['ancestorfees'], ancestor_fees) | |||||
# Wait until mempool transactions have passed initial broadcast | # Wait until mempool transactions have passed initial broadcast | ||||
# (sent inv and received getdata) | # (sent inv and received getdata) | ||||
# Otherwise, getrawmempool may be inconsistent with getmempoolentry if | # Otherwise, getrawmempool may be inconsistent with getmempoolentry if | ||||
# unbroadcast changes in between | # unbroadcast changes in between | ||||
peer_inv_store.wait_for_broadcast(chain) | peer_inv_store.wait_for_broadcast(chain) | ||||
# Check mempool has MAX_ANCESTORS transactions in it, and descendant and ancestor | # Check mempool has MAX_ANCESTORS transactions in it, and descendant and ancestor | ||||
# count and fees should look correct | # count and fees should look correct | ||||
mempool = self.nodes[0].getrawmempool(True) | mempool = self.nodes[0].getrawmempool(True) | ||||
assert_equal(len(mempool), MAX_ANCESTORS) | assert_equal(len(mempool), MAX_ANCESTORS) | ||||
descendant_count = 1 | descendant_count = 1 | ||||
descendant_fees = 0 | descendant_fees = 0 | ||||
descendant_size = 0 | descendant_size = 0 | ||||
ancestor_size = sum([mempool[tx]['size'] for tx in mempool]) | assert_equal(ancestor_size, | ||||
sum([mempool[tx]['size'] for tx in mempool])) | |||||
ancestor_count = MAX_ANCESTORS | ancestor_count = MAX_ANCESTORS | ||||
ancestor_fees = sum([mempool[tx]['fee'] for tx in mempool]) | assert_equal(ancestor_fees, | ||||
sum([mempool[tx]['fee'] for tx in mempool])) | |||||
descendants = [] | descendants = [] | ||||
ancestors = list(chain) | ancestors = list(chain) | ||||
for x in reversed(chain): | for x in reversed(chain): | ||||
# Check that getmempoolentry is consistent with getrawmempool | # Check that getmempoolentry is consistent with getrawmempool | ||||
entry = self.nodes[0].getmempoolentry(x) | entry = self.nodes[0].getmempoolentry(x) | ||||
assert_equal(entry, mempool[x]) | assert_equal(entry, mempool[x]) | ||||
▲ Show 20 Lines • Show All 263 Lines • Show Last 20 Lines |