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:
Sebastian Falbesoner
2025-03-12 20:30:25 +01:00
parent 346a099fc1
commit a82829f37e
3 changed files with 9 additions and 13 deletions

View File

@@ -336,8 +336,7 @@ class SegWitTest(BitcoinTestFramework):
# Verify the hash with witness differs from the txid
# (otherwise our testing framework must be broken!)
tx.rehash()
assert tx.sha256 != tx.calc_sha256(with_witness=True)
assert tx.rehash() != tx.getwtxid()
# Construct a block that includes the transaction.
block = self.build_next_block()
@@ -1293,7 +1292,7 @@ class SegWitTest(BitcoinTestFramework):
# Test that getrawtransaction returns correct witness information
# hash, size, vsize
raw_tx = self.nodes[0].getrawtransaction(tx3.hash, 1)
assert_equal(int(raw_tx["hash"], 16), tx3.calc_sha256(True))
assert_equal(raw_tx["hash"], tx3.getwtxid())
assert_equal(raw_tx["size"], len(tx3.serialize_with_witness()))
vsize = tx3.get_vsize()
assert_equal(raw_tx["vsize"], vsize)