Skip to content

Commit 0be2f17

Browse files
committed
QA: Add tests for listunspent ancestor{count,size,fees} to mempool_packages
1 parent 6966e80 commit 0be2f17

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

test/functional/mempool_packages.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,17 @@ def run_test(self):
5151
txid = utxo[0]['txid']
5252
vout = utxo[0]['vout']
5353
value = utxo[0]['amount']
54+
assert 'ancestorcount' not in utxo[0]
55+
assert 'ancestorsize' not in utxo[0]
56+
assert 'ancestorfees' not in utxo[0]
5457

5558
fee = Decimal("0.0001")
5659
# MAX_ANCESTORS transactions off a confirmed tx should be fine
5760
chain = []
5861
witness_chain = []
59-
for _ in range(MAX_ANCESTORS):
62+
ancestor_vsize = 0
63+
ancestor_fees = Decimal(0)
64+
for i in range(MAX_ANCESTORS):
6065
(txid, sent_value) = chain_transaction(self.nodes[0], [txid], [0], value, fee, 1)
6166
value = sent_value
6267
chain.append(txid)
@@ -65,6 +70,15 @@ def run_test(self):
6570
witnesstx = self.nodes[0].decoderawtransaction(fulltx, True)
6671
witness_chain.append(witnesstx['hash'])
6772

73+
# Check that listunspent ancestor{count, size, fees} yield the correct results
74+
wallet_unspent = self.nodes[0].listunspent(minconf=0)
75+
this_unspent = next(utxo_info for utxo_info in wallet_unspent if utxo_info['txid'] == txid)
76+
assert_equal(this_unspent['ancestorcount'], i + 1)
77+
ancestor_vsize += self.nodes[0].getrawtransaction(txid=txid, verbose=True)['vsize']
78+
assert_equal(this_unspent['ancestorsize'], ancestor_vsize)
79+
ancestor_fees -= self.nodes[0].gettransaction(txid=txid)['fee']
80+
assert_equal(this_unspent['ancestorfees'], ancestor_fees * COIN)
81+
6882
# Wait until mempool transactions have passed initial broadcast (sent inv and received getdata)
6983
# Otherwise, getrawmempool may be inconsistent with getmempoolentry if unbroadcast changes in between
7084
peer_inv_store.wait_for_broadcast(witness_chain)
@@ -77,9 +91,9 @@ def run_test(self):
7791
descendant_fees = 0
7892
descendant_vsize = 0
7993

80-
ancestor_vsize = sum([mempool[tx]['vsize'] for tx in mempool])
94+
assert_equal(ancestor_vsize, sum([mempool[tx]['vsize'] for tx in mempool]))
8195
ancestor_count = MAX_ANCESTORS
82-
ancestor_fees = sum([mempool[tx]['fee'] for tx in mempool])
96+
assert_equal(ancestor_fees, sum([mempool[tx]['fee'] for tx in mempool]))
8397

8498
descendants = []
8599
ancestors = list(chain)

0 commit comments

Comments
 (0)