Skip to content

Commit 1dfb4e7

Browse files
committed
[Tests] Check output of parent/child tx list from getrawmempool, getmempooldescendants, getmempoolancestors, and REST interface
1 parent fc44cb1 commit 1dfb4e7

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

test/functional/interface_rest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,10 @@ def run_test(self):
295295
# check that there are our submitted transactions in the TX memory pool
296296
json_string = http_get_call(url.hostname, url.port, '/rest/mempool/contents'+self.FORMAT_SEPARATOR+'json')
297297
json_obj = json.loads(json_string)
298-
for tx in txs:
298+
for i, tx in enumerate(txs):
299299
assert_equal(tx in json_obj, True)
300+
assert_equal(json_obj[tx]['spentby'], txs[i+1:i+2])
301+
assert_equal(json_obj[tx]['depends'], txs[i-1:i])
300302

301303
# now mine the transactions
302304
newblockhash = self.nodes[1].generate(1)

test/functional/mempool_packages.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,18 @@ def run_test(self):
4747
value = sent_value
4848
chain.append(txid)
4949

50-
# Check mempool has MAX_ANCESTORS transactions in it, and descendant
50+
# Check mempool has MAX_ANCESTORS transactions in it, and descendant and ancestor
5151
# count and fees should look correct
5252
mempool = self.nodes[0].getrawmempool(True)
5353
assert_equal(len(mempool), MAX_ANCESTORS)
5454
descendant_count = 1
5555
descendant_fees = 0
5656
descendant_size = 0
5757

58+
ancestor_size = sum([mempool[tx]['size'] for tx in mempool])
59+
ancestor_count = MAX_ANCESTORS
60+
ancestor_fees = sum([mempool[tx]['fee'] for tx in mempool])
61+
5862
descendants = []
5963
ancestors = list(chain)
6064
for x in reversed(chain):
@@ -71,14 +75,43 @@ def run_test(self):
7175
assert_equal(mempool[x]['descendantsize'], descendant_size)
7276
descendant_count += 1
7377

78+
# Check that ancestor calculations are correct
79+
assert_equal(mempool[x]['ancestorcount'], ancestor_count)
80+
assert_equal(mempool[x]['ancestorfees'], ancestor_fees * COIN)
81+
assert_equal(mempool[x]['ancestorsize'], ancestor_size)
82+
ancestor_size -= mempool[x]['size']
83+
ancestor_fees -= mempool[x]['fee']
84+
ancestor_count -= 1
85+
86+
# Check that parent/child list is correct
87+
assert_equal(mempool[x]['spentby'], descendants[-1:])
88+
assert_equal(mempool[x]['depends'], ancestors[-2:-1])
89+
7490
# Check that getmempooldescendants is correct
7591
assert_equal(sorted(descendants), sorted(self.nodes[0].getmempooldescendants(x)))
92+
93+
# Check getmempooldescendants verbose output is correct
94+
for descendant, dinfo in self.nodes[0].getmempooldescendants(x, True).items():
95+
assert_equal(dinfo['depends'], [chain[chain.index(descendant)-1]])
96+
if dinfo['descendantcount'] > 1:
97+
assert_equal(dinfo['spentby'], [chain[chain.index(descendant)+1]])
98+
else:
99+
assert_equal(dinfo['spentby'], [])
76100
descendants.append(x)
77101

78102
# Check that getmempoolancestors is correct
79103
ancestors.remove(x)
80104
assert_equal(sorted(ancestors), sorted(self.nodes[0].getmempoolancestors(x)))
81105

106+
# Check that getmempoolancestors verbose output is correct
107+
for ancestor, ainfo in self.nodes[0].getmempoolancestors(x, True).items():
108+
assert_equal(ainfo['spentby'], [chain[chain.index(ancestor)+1]])
109+
if ainfo['ancestorcount'] > 1:
110+
assert_equal(ainfo['depends'], [chain[chain.index(ancestor)-1]])
111+
else:
112+
assert_equal(ainfo['depends'], [])
113+
114+
82115
# Check that getmempoolancestors/getmempooldescendants correctly handle verbose=true
83116
v_ancestors = self.nodes[0].getmempoolancestors(chain[-1], True)
84117
assert_equal(len(v_ancestors), len(chain)-1)
@@ -100,7 +133,7 @@ def run_test(self):
100133
for x in chain:
101134
ancestor_fees += mempool[x]['fee']
102135
assert_equal(mempool[x]['ancestorfees'], ancestor_fees * COIN + 1000)
103-
136+
104137
# Undo the prioritisetransaction for later tests
105138
self.nodes[0].prioritisetransaction(txid=chain[0], fee_delta=-1000)
106139

@@ -149,6 +182,7 @@ def run_test(self):
149182
vout = utxo[1]['vout']
150183

151184
transaction_package = []
185+
tx_children = []
152186
# First create one parent tx with 10 children
153187
(txid, sent_value) = self.chain_transaction(self.nodes[0], txid, vout, value, fee, 10)
154188
parent_transaction = txid
@@ -159,11 +193,17 @@ def run_test(self):
159193
for i in range(MAX_DESCENDANTS - 1):
160194
utxo = transaction_package.pop(0)
161195
(txid, sent_value) = self.chain_transaction(self.nodes[0], utxo['txid'], utxo['vout'], utxo['amount'], fee, 10)
196+
if utxo['txid'] is parent_transaction:
197+
tx_children.append(txid)
162198
for j in range(10):
163199
transaction_package.append({'txid': txid, 'vout': j, 'amount': sent_value})
164200

165201
mempool = self.nodes[0].getrawmempool(True)
166202
assert_equal(mempool[parent_transaction]['descendantcount'], MAX_DESCENDANTS)
203+
assert_equal(sorted(mempool[parent_transaction]['spentby']), sorted(tx_children))
204+
205+
for child in tx_children:
206+
assert_equal(mempool[child]['depends'], [parent_transaction])
167207

168208
# Sending one more chained transaction will fail
169209
utxo = transaction_package.pop(0)
@@ -232,7 +272,7 @@ def run_test(self):
232272
signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx)
233273
txid = self.nodes[0].sendrawtransaction(signedtx['hex'])
234274
sync_mempools(self.nodes)
235-
275+
236276
# Now try to disconnect the tip on each node...
237277
self.nodes[1].invalidateblock(self.nodes[1].getbestblockhash())
238278
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())

0 commit comments

Comments
 (0)