mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-30 16:58:56 +02:00
test: simplify (w)txid checks by avoiding .calc_sha256 calls
Calls on the tx.calc_sha256 method can be confusing, as they return the result (either txid or wtxid, depending on the with_witness boolean parameter) as integer rather than as actual (w)txid. Use .rehash() and .getwtxid() instead to improve readability and in some cases avoid a conversion from string-txid to an integer.
This commit is contained in:
@@ -347,13 +347,11 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
|
||||
# Check that all prefilled_txn entries match what's in the block.
|
||||
for entry in header_and_shortids.prefilled_txn:
|
||||
entry.tx.calc_sha256()
|
||||
# This checks the non-witness parts of the tx agree
|
||||
assert_equal(entry.tx.sha256, block.vtx[entry.index].sha256)
|
||||
assert_equal(entry.tx.rehash(), block.vtx[entry.index].rehash())
|
||||
|
||||
# And this checks the witness
|
||||
wtxid = entry.tx.calc_sha256(True)
|
||||
assert_equal(wtxid, block.vtx[entry.index].calc_sha256(True))
|
||||
assert_equal(entry.tx.getwtxid(), block.vtx[entry.index].getwtxid())
|
||||
|
||||
# Check that the cmpctblock message announced all the transactions.
|
||||
assert_equal(len(header_and_shortids.prefilled_txn) + len(header_and_shortids.shortids), len(block.vtx))
|
||||
@@ -590,10 +588,9 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
all_indices = msg.block_txn_request.to_absolute()
|
||||
for index in all_indices:
|
||||
tx = test_node.last_message["blocktxn"].block_transactions.transactions.pop(0)
|
||||
tx.calc_sha256()
|
||||
assert_equal(tx.sha256, block.vtx[index].sha256)
|
||||
assert_equal(tx.rehash(), block.vtx[index].rehash())
|
||||
# Check that the witness matches
|
||||
assert_equal(tx.calc_sha256(True), block.vtx[index].calc_sha256(True))
|
||||
assert_equal(tx.getwtxid(), block.vtx[index].getwtxid())
|
||||
test_node.last_message.pop("blocktxn", None)
|
||||
current_height -= 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user