test: rename CTransaction .rehash()/.hash -> .txid_hex for consistency

Note that we unfortunately can't use a scripted diff here, as the same
property and method name is also used for `CBlockHeader`/`CBlock` instances.
This commit is contained in:
Sebastian Falbesoner
2025-05-05 00:11:32 +02:00
parent e9cdaefb0a
commit ce83924237
30 changed files with 136 additions and 141 deletions

View File

@@ -34,7 +34,7 @@ def assert_mempool_contents(test_framework, node, expected=None, sync=True):
mempool = node.getrawmempool(verbose=False)
assert_equal(len(mempool), len(expected))
for tx in expected:
assert tx.rehash() in mempool
assert tx.txid_hex in mempool
def fill_mempool(test_framework, node, *, tx_sync_fun=None):
@@ -104,5 +104,5 @@ def fill_mempool(test_framework, node, *, tx_sync_fun=None):
def tx_in_orphanage(node, tx: CTransaction) -> bool:
"""Returns true if the transaction is in the orphanage."""
found = [o for o in node.getorphantxs(verbosity=1) if o["txid"] == tx.rehash() and o["wtxid"] == tx.getwtxid()]
found = [o for o in node.getorphantxs(verbosity=1) if o["txid"] == tx.txid_hex and o["wtxid"] == tx.getwtxid()]
return len(found) == 1

View File

@@ -667,7 +667,7 @@ class CTransaction:
return uint256_from_str(hash256(self.serialize_with_witness()))
@property
def hash(self):
def txid_hex(self):
"""Return txid (transaction hash without witness) as hex string."""
return hash256(self.serialize_without_witness())[::-1].hex()
@@ -676,11 +676,6 @@ class CTransaction:
"""Return txid (transaction hash without witness) as integer."""
return uint256_from_str(hash256(self.serialize_without_witness()))
# Recalculate the txid (transaction hash without witness)
# TODO: get rid of this method, replace call-sites by .hash access
def rehash(self):
return self.hash
def is_valid(self):
for tout in self.vout:
if tout.nValue < 0 or tout.nValue > 21000000 * COIN:

View File

@@ -619,7 +619,7 @@ class P2PInterface(P2PConnection):
def test_function():
if not self.last_message.get('tx'):
return False
return self.last_message['tx'].tx.rehash() == txid
return self.last_message['tx'].tx.txid_hex == txid
self.wait_until(test_function, timeout=timeout)
@@ -927,11 +927,11 @@ class P2PDataStore(P2PInterface):
if success:
# Check that all txs are now in the mempool
for tx in txs:
assert tx.hash in raw_mempool, "{} not found in mempool".format(tx.hash)
assert tx.txid_hex in raw_mempool, "{} not found in mempool".format(tx.txid_hex)
else:
# Check that none of the txs are now in the mempool
for tx in txs:
assert tx.hash not in raw_mempool, "{} tx found in mempool".format(tx.hash)
assert tx.txid_hex not in raw_mempool, "{} tx found in mempool".format(tx.txid_hex)
class P2PTxInvStore(P2PInterface):
"""A P2PInterface which stores a count of how many times each txid has been announced."""

View File

@@ -340,7 +340,7 @@ class MiniWallet:
if target_vsize:
self._bulk_tx(tx, target_vsize)
txid = tx.rehash()
txid = tx.txid_hex
return {
"new_utxos": [self._create_utxo(
txid=txid,