0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-14 11:26:09 -05:00

test: use getmempoolentry instead of getrawmempool in functional tests when appropriate

This commit is contained in:
Michael Dietz 2021-08-16 18:29:07 +05:00
parent 86dbd54ae8
commit 77349713b1
No known key found for this signature in database
GPG key ID: 737FD5CDF1D146B9
6 changed files with 40 additions and 44 deletions

View file

@ -90,7 +90,7 @@ class MempoolWtxidTest(BitcoinTestFramework):
self.log.info("Submit child_one to the mempool") self.log.info("Submit child_one to the mempool")
txid_submitted = node.sendrawtransaction(child_one.serialize().hex()) txid_submitted = node.sendrawtransaction(child_one.serialize().hex())
assert_equal(node.getrawmempool(True)[txid_submitted]['wtxid'], child_one_wtxid) assert_equal(node.getmempoolentry(txid_submitted)['wtxid'], child_one_wtxid)
peer_wtxid_relay.wait_for_broadcast([child_one_wtxid]) peer_wtxid_relay.wait_for_broadcast([child_one_wtxid])
assert_equal(node.getmempoolinfo()["unbroadcastcount"], 0) assert_equal(node.getmempoolinfo()["unbroadcastcount"], 0)

View file

@ -65,8 +65,7 @@ class MempoolCompatibilityTest(BitcoinTestFramework):
self.log.info("Add unbroadcasted tx to mempool on new node and shutdown") self.log.info("Add unbroadcasted tx to mempool on new node and shutdown")
unbroadcasted_tx_hash = new_wallet.send_self_transfer(from_node=new_node)['txid'] unbroadcasted_tx_hash = new_wallet.send_self_transfer(from_node=new_node)['txid']
assert unbroadcasted_tx_hash in new_node.getrawmempool() assert unbroadcasted_tx_hash in new_node.getrawmempool()
mempool = new_node.getrawmempool(True) assert new_node.getmempoolentry(unbroadcasted_tx_hash)['unbroadcast']
assert mempool[unbroadcasted_tx_hash]['unbroadcast']
self.stop_node(1) self.stop_node(1)
self.log.info("Move mempool.dat from new to old node") self.log.info("Move mempool.dat from new to old node")

View file

@ -74,7 +74,7 @@ class MempoolPackageLimitsTest(BitcoinTestFramework):
txid = tx.rehash() txid = tx.rehash()
if i < mempool_count: if i < mempool_count:
node.sendrawtransaction(txhex) node.sendrawtransaction(txhex)
assert_equal(node.getrawmempool(verbose=True)[txid]["ancestorcount"], i + 1) assert_equal(node.getmempoolentry(txid)["ancestorcount"], i + 1)
else: else:
chain_hex.append(txhex) chain_hex.append(txhex)
chain_txns.append(tx) chain_txns.append(tx)

View file

@ -89,28 +89,28 @@ class MempoolPackagesTest(BitcoinTestFramework):
assert_equal(entry, mempool[x]) assert_equal(entry, mempool[x])
# Check that the descendant calculations are correct # Check that the descendant calculations are correct
assert_equal(mempool[x]['descendantcount'], descendant_count) assert_equal(entry['descendantcount'], descendant_count)
descendant_fees += mempool[x]['fee'] descendant_fees += entry['fee']
assert_equal(mempool[x]['modifiedfee'], mempool[x]['fee']) assert_equal(entry['modifiedfee'], entry['fee'])
assert_equal(mempool[x]['fees']['base'], mempool[x]['fee']) assert_equal(entry['fees']['base'], entry['fee'])
assert_equal(mempool[x]['fees']['modified'], mempool[x]['modifiedfee']) assert_equal(entry['fees']['modified'], entry['modifiedfee'])
assert_equal(mempool[x]['descendantfees'], descendant_fees * COIN) assert_equal(entry['descendantfees'], descendant_fees * COIN)
assert_equal(mempool[x]['fees']['descendant'], descendant_fees) assert_equal(entry['fees']['descendant'], descendant_fees)
descendant_vsize += mempool[x]['vsize'] descendant_vsize += entry['vsize']
assert_equal(mempool[x]['descendantsize'], descendant_vsize) assert_equal(entry['descendantsize'], descendant_vsize)
descendant_count += 1 descendant_count += 1
# Check that ancestor calculations are correct # Check that ancestor calculations are correct
assert_equal(mempool[x]['ancestorcount'], ancestor_count) assert_equal(entry['ancestorcount'], ancestor_count)
assert_equal(mempool[x]['ancestorfees'], ancestor_fees * COIN) assert_equal(entry['ancestorfees'], ancestor_fees * COIN)
assert_equal(mempool[x]['ancestorsize'], ancestor_vsize) assert_equal(entry['ancestorsize'], ancestor_vsize)
ancestor_vsize -= mempool[x]['vsize'] ancestor_vsize -= entry['vsize']
ancestor_fees -= mempool[x]['fee'] ancestor_fees -= entry['fee']
ancestor_count -= 1 ancestor_count -= 1
# Check that parent/child list is correct # Check that parent/child list is correct
assert_equal(mempool[x]['spentby'], descendants[-1:]) assert_equal(entry['spentby'], descendants[-1:])
assert_equal(mempool[x]['depends'], ancestors[-2:-1]) assert_equal(entry['depends'], ancestors[-2:-1])
# Check that getmempooldescendants is correct # Check that getmempooldescendants is correct
assert_equal(sorted(descendants), sorted(self.nodes[0].getmempooldescendants(x))) assert_equal(sorted(descendants), sorted(self.nodes[0].getmempooldescendants(x)))
@ -153,12 +153,12 @@ class MempoolPackagesTest(BitcoinTestFramework):
# Check that ancestor modified fees includes fee deltas from # Check that ancestor modified fees includes fee deltas from
# prioritisetransaction # prioritisetransaction
self.nodes[0].prioritisetransaction(txid=chain[0], fee_delta=1000) self.nodes[0].prioritisetransaction(txid=chain[0], fee_delta=1000)
mempool = self.nodes[0].getrawmempool(True)
ancestor_fees = 0 ancestor_fees = 0
for x in chain: for x in chain:
ancestor_fees += mempool[x]['fee'] entry = self.nodes[0].getmempoolentry(x)
assert_equal(mempool[x]['fees']['ancestor'], ancestor_fees + Decimal('0.00001')) ancestor_fees += entry['fee']
assert_equal(mempool[x]['ancestorfees'], ancestor_fees * COIN + 1000) assert_equal(entry['fees']['ancestor'], ancestor_fees + Decimal('0.00001'))
assert_equal(entry['ancestorfees'], ancestor_fees * COIN + 1000)
# Undo the prioritisetransaction for later tests # Undo the prioritisetransaction for later tests
self.nodes[0].prioritisetransaction(txid=chain[0], fee_delta=-1000) self.nodes[0].prioritisetransaction(txid=chain[0], fee_delta=-1000)
@ -166,13 +166,13 @@ class MempoolPackagesTest(BitcoinTestFramework):
# Check that descendant modified fees includes fee deltas from # Check that descendant modified fees includes fee deltas from
# prioritisetransaction # prioritisetransaction
self.nodes[0].prioritisetransaction(txid=chain[-1], fee_delta=1000) self.nodes[0].prioritisetransaction(txid=chain[-1], fee_delta=1000)
mempool = self.nodes[0].getrawmempool(True)
descendant_fees = 0 descendant_fees = 0
for x in reversed(chain): for x in reversed(chain):
descendant_fees += mempool[x]['fee'] entry = self.nodes[0].getmempoolentry(x)
assert_equal(mempool[x]['fees']['descendant'], descendant_fees + Decimal('0.00001')) descendant_fees += entry['fee']
assert_equal(mempool[x]['descendantfees'], descendant_fees * COIN + 1000) assert_equal(entry['fees']['descendant'], descendant_fees + Decimal('0.00001'))
assert_equal(entry['descendantfees'], descendant_fees * COIN + 1000)
# Adding one more transaction on to the chain should fail. # Adding one more transaction on to the chain should fail.
assert_raises_rpc_error(-26, "too-long-mempool-chain", chain_transaction, self.nodes[0], [txid], [vout], value, fee, 1) assert_raises_rpc_error(-26, "too-long-mempool-chain", chain_transaction, self.nodes[0], [txid], [vout], value, fee, 1)
@ -190,16 +190,15 @@ class MempoolPackagesTest(BitcoinTestFramework):
self.nodes[1].invalidateblock(self.nodes[1].getbestblockhash()) self.nodes[1].invalidateblock(self.nodes[1].getbestblockhash())
# Now check that the transaction is in the mempool, with the right modified fee # Now check that the transaction is in the mempool, with the right modified fee
mempool = self.nodes[0].getrawmempool(True)
descendant_fees = 0 descendant_fees = 0
for x in reversed(chain): for x in reversed(chain):
descendant_fees += mempool[x]['fee'] entry = self.nodes[0].getmempoolentry(x)
descendant_fees += entry['fee']
if (x == chain[-1]): if (x == chain[-1]):
assert_equal(mempool[x]['modifiedfee'], mempool[x]['fee']+satoshi_round(0.00002)) assert_equal(entry['modifiedfee'], entry['fee']+satoshi_round(0.00002))
assert_equal(mempool[x]['fees']['modified'], mempool[x]['fee']+satoshi_round(0.00002)) assert_equal(entry['fees']['modified'], entry['fee']+satoshi_round(0.00002))
assert_equal(mempool[x]['descendantfees'], descendant_fees * COIN + 2000) assert_equal(entry['descendantfees'], descendant_fees * COIN + 2000)
assert_equal(mempool[x]['fees']['descendant'], descendant_fees+satoshi_round(0.00002)) assert_equal(entry['fees']['descendant'], descendant_fees+satoshi_round(0.00002))
# Check that node1's mempool is as expected (-> custom ancestor limit) # Check that node1's mempool is as expected (-> custom ancestor limit)
mempool0 = self.nodes[0].getrawmempool(False) mempool0 = self.nodes[0].getrawmempool(False)
@ -255,7 +254,7 @@ class MempoolPackagesTest(BitcoinTestFramework):
# - txs from previous ancestor test (-> custom ancestor limit) # - txs from previous ancestor test (-> custom ancestor limit)
# - parent tx for descendant test # - parent tx for descendant test
# - txs chained off parent tx (-> custom descendant limit) # - txs chained off parent tx (-> custom descendant limit)
self.wait_until(lambda: len(self.nodes[1].getrawmempool(False)) == self.wait_until(lambda: len(self.nodes[1].getrawmempool()) ==
MAX_ANCESTORS_CUSTOM + 1 + MAX_DESCENDANTS_CUSTOM, timeout=10) MAX_ANCESTORS_CUSTOM + 1 + MAX_DESCENDANTS_CUSTOM, timeout=10)
mempool0 = self.nodes[0].getrawmempool(False) mempool0 = self.nodes[0].getrawmempool(False)
mempool1 = self.nodes[1].getrawmempool(False) mempool1 = self.nodes[1].getrawmempool(False)

View file

@ -94,9 +94,7 @@ class MempoolUnbroadcastTest(BitcoinTestFramework):
self.log.info("Rebroadcast transaction and ensure it is not added to unbroadcast set when already in mempool") self.log.info("Rebroadcast transaction and ensure it is not added to unbroadcast set when already in mempool")
rpc_tx_hsh = node.sendrawtransaction(txFS["hex"]) rpc_tx_hsh = node.sendrawtransaction(txFS["hex"])
mempool = node.getrawmempool(True) assert not node.getmempoolentry(rpc_tx_hsh)['unbroadcast']
assert rpc_tx_hsh in mempool
assert not mempool[rpc_tx_hsh]['unbroadcast']
def test_txn_removal(self): def test_txn_removal(self):
self.log.info("Test that transactions removed from mempool are removed from unbroadcast set") self.log.info("Test that transactions removed from mempool are removed from unbroadcast set")

View file

@ -379,7 +379,7 @@ class RawTransactionsTest(BitcoinTestFramework):
# Create same transaction over sendtoaddress. # Create same transaction over sendtoaddress.
txId = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1.1) txId = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1.1)
signedFee = self.nodes[0].getrawmempool(True)[txId]['fee'] signedFee = self.nodes[0].getmempoolentry(txId)['fee']
# Compare fee. # Compare fee.
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee) feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
@ -402,7 +402,7 @@ class RawTransactionsTest(BitcoinTestFramework):
# Create same transaction over sendtoaddress. # Create same transaction over sendtoaddress.
txId = self.nodes[0].sendmany("", outputs) txId = self.nodes[0].sendmany("", outputs)
signedFee = self.nodes[0].getrawmempool(True)[txId]['fee'] signedFee = self.nodes[0].getmempoolentry(txId)['fee']
# Compare fee. # Compare fee.
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee) feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
@ -426,7 +426,7 @@ class RawTransactionsTest(BitcoinTestFramework):
# Create same transaction over sendtoaddress. # Create same transaction over sendtoaddress.
txId = self.nodes[0].sendtoaddress(mSigObj, 1.1) txId = self.nodes[0].sendtoaddress(mSigObj, 1.1)
signedFee = self.nodes[0].getrawmempool(True)[txId]['fee'] signedFee = self.nodes[0].getmempoolentry(txId)['fee']
# Compare fee. # Compare fee.
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee) feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
@ -467,7 +467,7 @@ class RawTransactionsTest(BitcoinTestFramework):
# Create same transaction over sendtoaddress. # Create same transaction over sendtoaddress.
txId = self.nodes[0].sendtoaddress(mSigObj, 1.1) txId = self.nodes[0].sendtoaddress(mSigObj, 1.1)
signedFee = self.nodes[0].getrawmempool(True)[txId]['fee'] signedFee = self.nodes[0].getmempoolentry(txId)['fee']
# Compare fee. # Compare fee.
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee) feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
@ -599,7 +599,7 @@ class RawTransactionsTest(BitcoinTestFramework):
# Create same transaction over sendtoaddress. # Create same transaction over sendtoaddress.
txId = self.nodes[1].sendmany("", outputs) txId = self.nodes[1].sendmany("", outputs)
signedFee = self.nodes[1].getrawmempool(True)[txId]['fee'] signedFee = self.nodes[1].getmempoolentry(txId)['fee']
# Compare fee. # Compare fee.
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee) feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)