Skip to content

Commit 7734971

Browse files
committed
test: use getmempoolentry instead of getrawmempool in functional tests when appropriate
1 parent 86dbd54 commit 7734971

File tree

6 files changed

+40
-44
lines changed

6 files changed

+40
-44
lines changed

test/functional/mempool_accept_wtxid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def run_test(self):
9090

9191
self.log.info("Submit child_one to the mempool")
9292
txid_submitted = node.sendrawtransaction(child_one.serialize().hex())
93-
assert_equal(node.getrawmempool(True)[txid_submitted]['wtxid'], child_one_wtxid)
93+
assert_equal(node.getmempoolentry(txid_submitted)['wtxid'], child_one_wtxid)
9494

9595
peer_wtxid_relay.wait_for_broadcast([child_one_wtxid])
9696
assert_equal(node.getmempoolinfo()["unbroadcastcount"], 0)

test/functional/mempool_compatibility.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ def run_test(self):
6565
self.log.info("Add unbroadcasted tx to mempool on new node and shutdown")
6666
unbroadcasted_tx_hash = new_wallet.send_self_transfer(from_node=new_node)['txid']
6767
assert unbroadcasted_tx_hash in new_node.getrawmempool()
68-
mempool = new_node.getrawmempool(True)
69-
assert mempool[unbroadcasted_tx_hash]['unbroadcast']
68+
assert new_node.getmempoolentry(unbroadcasted_tx_hash)['unbroadcast']
7069
self.stop_node(1)
7170

7271
self.log.info("Move mempool.dat from new to old node")

test/functional/mempool_package_limits.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_chain_limits_helper(self, mempool_count, package_count):
7474
txid = tx.rehash()
7575
if i < mempool_count:
7676
node.sendrawtransaction(txhex)
77-
assert_equal(node.getrawmempool(verbose=True)[txid]["ancestorcount"], i + 1)
77+
assert_equal(node.getmempoolentry(txid)["ancestorcount"], i + 1)
7878
else:
7979
chain_hex.append(txhex)
8080
chain_txns.append(tx)

test/functional/mempool_packages.py

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -89,28 +89,28 @@ def run_test(self):
8989
assert_equal(entry, mempool[x])
9090

9191
# Check that the descendant calculations are correct
92-
assert_equal(mempool[x]['descendantcount'], descendant_count)
93-
descendant_fees += mempool[x]['fee']
94-
assert_equal(mempool[x]['modifiedfee'], mempool[x]['fee'])
95-
assert_equal(mempool[x]['fees']['base'], mempool[x]['fee'])
96-
assert_equal(mempool[x]['fees']['modified'], mempool[x]['modifiedfee'])
97-
assert_equal(mempool[x]['descendantfees'], descendant_fees * COIN)
98-
assert_equal(mempool[x]['fees']['descendant'], descendant_fees)
99-
descendant_vsize += mempool[x]['vsize']
100-
assert_equal(mempool[x]['descendantsize'], descendant_vsize)
92+
assert_equal(entry['descendantcount'], descendant_count)
93+
descendant_fees += entry['fee']
94+
assert_equal(entry['modifiedfee'], entry['fee'])
95+
assert_equal(entry['fees']['base'], entry['fee'])
96+
assert_equal(entry['fees']['modified'], entry['modifiedfee'])
97+
assert_equal(entry['descendantfees'], descendant_fees * COIN)
98+
assert_equal(entry['fees']['descendant'], descendant_fees)
99+
descendant_vsize += entry['vsize']
100+
assert_equal(entry['descendantsize'], descendant_vsize)
101101
descendant_count += 1
102102

103103
# Check that ancestor calculations are correct
104-
assert_equal(mempool[x]['ancestorcount'], ancestor_count)
105-
assert_equal(mempool[x]['ancestorfees'], ancestor_fees * COIN)
106-
assert_equal(mempool[x]['ancestorsize'], ancestor_vsize)
107-
ancestor_vsize -= mempool[x]['vsize']
108-
ancestor_fees -= mempool[x]['fee']
104+
assert_equal(entry['ancestorcount'], ancestor_count)
105+
assert_equal(entry['ancestorfees'], ancestor_fees * COIN)
106+
assert_equal(entry['ancestorsize'], ancestor_vsize)
107+
ancestor_vsize -= entry['vsize']
108+
ancestor_fees -= entry['fee']
109109
ancestor_count -= 1
110110

111111
# Check that parent/child list is correct
112-
assert_equal(mempool[x]['spentby'], descendants[-1:])
113-
assert_equal(mempool[x]['depends'], ancestors[-2:-1])
112+
assert_equal(entry['spentby'], descendants[-1:])
113+
assert_equal(entry['depends'], ancestors[-2:-1])
114114

115115
# Check that getmempooldescendants is correct
116116
assert_equal(sorted(descendants), sorted(self.nodes[0].getmempooldescendants(x)))
@@ -153,26 +153,26 @@ def run_test(self):
153153
# Check that ancestor modified fees includes fee deltas from
154154
# prioritisetransaction
155155
self.nodes[0].prioritisetransaction(txid=chain[0], fee_delta=1000)
156-
mempool = self.nodes[0].getrawmempool(True)
157156
ancestor_fees = 0
158157
for x in chain:
159-
ancestor_fees += mempool[x]['fee']
160-
assert_equal(mempool[x]['fees']['ancestor'], ancestor_fees + Decimal('0.00001'))
161-
assert_equal(mempool[x]['ancestorfees'], ancestor_fees * COIN + 1000)
158+
entry = self.nodes[0].getmempoolentry(x)
159+
ancestor_fees += entry['fee']
160+
assert_equal(entry['fees']['ancestor'], ancestor_fees + Decimal('0.00001'))
161+
assert_equal(entry['ancestorfees'], ancestor_fees * COIN + 1000)
162162

163163
# Undo the prioritisetransaction for later tests
164164
self.nodes[0].prioritisetransaction(txid=chain[0], fee_delta=-1000)
165165

166166
# Check that descendant modified fees includes fee deltas from
167167
# prioritisetransaction
168168
self.nodes[0].prioritisetransaction(txid=chain[-1], fee_delta=1000)
169-
mempool = self.nodes[0].getrawmempool(True)
170169

171170
descendant_fees = 0
172171
for x in reversed(chain):
173-
descendant_fees += mempool[x]['fee']
174-
assert_equal(mempool[x]['fees']['descendant'], descendant_fees + Decimal('0.00001'))
175-
assert_equal(mempool[x]['descendantfees'], descendant_fees * COIN + 1000)
172+
entry = self.nodes[0].getmempoolentry(x)
173+
descendant_fees += entry['fee']
174+
assert_equal(entry['fees']['descendant'], descendant_fees + Decimal('0.00001'))
175+
assert_equal(entry['descendantfees'], descendant_fees * COIN + 1000)
176176

177177
# Adding one more transaction on to the chain should fail.
178178
assert_raises_rpc_error(-26, "too-long-mempool-chain", chain_transaction, self.nodes[0], [txid], [vout], value, fee, 1)
@@ -190,16 +190,15 @@ def run_test(self):
190190
self.nodes[1].invalidateblock(self.nodes[1].getbestblockhash())
191191

192192
# Now check that the transaction is in the mempool, with the right modified fee
193-
mempool = self.nodes[0].getrawmempool(True)
194-
195193
descendant_fees = 0
196194
for x in reversed(chain):
197-
descendant_fees += mempool[x]['fee']
195+
entry = self.nodes[0].getmempoolentry(x)
196+
descendant_fees += entry['fee']
198197
if (x == chain[-1]):
199-
assert_equal(mempool[x]['modifiedfee'], mempool[x]['fee']+satoshi_round(0.00002))
200-
assert_equal(mempool[x]['fees']['modified'], mempool[x]['fee']+satoshi_round(0.00002))
201-
assert_equal(mempool[x]['descendantfees'], descendant_fees * COIN + 2000)
202-
assert_equal(mempool[x]['fees']['descendant'], descendant_fees+satoshi_round(0.00002))
198+
assert_equal(entry['modifiedfee'], entry['fee']+satoshi_round(0.00002))
199+
assert_equal(entry['fees']['modified'], entry['fee']+satoshi_round(0.00002))
200+
assert_equal(entry['descendantfees'], descendant_fees * COIN + 2000)
201+
assert_equal(entry['fees']['descendant'], descendant_fees+satoshi_round(0.00002))
203202

204203
# Check that node1's mempool is as expected (-> custom ancestor limit)
205204
mempool0 = self.nodes[0].getrawmempool(False)
@@ -255,7 +254,7 @@ def run_test(self):
255254
# - txs from previous ancestor test (-> custom ancestor limit)
256255
# - parent tx for descendant test
257256
# - txs chained off parent tx (-> custom descendant limit)
258-
self.wait_until(lambda: len(self.nodes[1].getrawmempool(False)) ==
257+
self.wait_until(lambda: len(self.nodes[1].getrawmempool()) ==
259258
MAX_ANCESTORS_CUSTOM + 1 + MAX_DESCENDANTS_CUSTOM, timeout=10)
260259
mempool0 = self.nodes[0].getrawmempool(False)
261260
mempool1 = self.nodes[1].getrawmempool(False)

test/functional/mempool_unbroadcast.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ def test_broadcast(self):
9494

9595
self.log.info("Rebroadcast transaction and ensure it is not added to unbroadcast set when already in mempool")
9696
rpc_tx_hsh = node.sendrawtransaction(txFS["hex"])
97-
mempool = node.getrawmempool(True)
98-
assert rpc_tx_hsh in mempool
99-
assert not mempool[rpc_tx_hsh]['unbroadcast']
97+
assert not node.getmempoolentry(rpc_tx_hsh)['unbroadcast']
10098

10199
def test_txn_removal(self):
102100
self.log.info("Test that transactions removed from mempool are removed from unbroadcast set")

test/functional/rpc_fundrawtransaction.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def test_fee_p2pkh(self):
379379

380380
# Create same transaction over sendtoaddress.
381381
txId = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1.1)
382-
signedFee = self.nodes[0].getrawmempool(True)[txId]['fee']
382+
signedFee = self.nodes[0].getmempoolentry(txId)['fee']
383383

384384
# Compare fee.
385385
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
@@ -402,7 +402,7 @@ def test_fee_p2pkh_multi_out(self):
402402

403403
# Create same transaction over sendtoaddress.
404404
txId = self.nodes[0].sendmany("", outputs)
405-
signedFee = self.nodes[0].getrawmempool(True)[txId]['fee']
405+
signedFee = self.nodes[0].getmempoolentry(txId)['fee']
406406

407407
# Compare fee.
408408
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
@@ -426,7 +426,7 @@ def test_fee_p2sh(self):
426426

427427
# Create same transaction over sendtoaddress.
428428
txId = self.nodes[0].sendtoaddress(mSigObj, 1.1)
429-
signedFee = self.nodes[0].getrawmempool(True)[txId]['fee']
429+
signedFee = self.nodes[0].getmempoolentry(txId)['fee']
430430

431431
# Compare fee.
432432
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
@@ -467,7 +467,7 @@ def test_fee_4of5(self):
467467

468468
# Create same transaction over sendtoaddress.
469469
txId = self.nodes[0].sendtoaddress(mSigObj, 1.1)
470-
signedFee = self.nodes[0].getrawmempool(True)[txId]['fee']
470+
signedFee = self.nodes[0].getmempoolentry(txId)['fee']
471471

472472
# Compare fee.
473473
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
@@ -599,7 +599,7 @@ def test_many_inputs_fee(self):
599599

600600
# Create same transaction over sendtoaddress.
601601
txId = self.nodes[1].sendmany("", outputs)
602-
signedFee = self.nodes[1].getrawmempool(True)[txId]['fee']
602+
signedFee = self.nodes[1].getmempoolentry(txId)['fee']
603603

604604
# Compare fee.
605605
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)

0 commit comments

Comments
 (0)