Skip to content

Commit ce83924

Browse files
committed
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.
1 parent e9cdaef commit ce83924

30 files changed

+136
-141
lines changed

test/functional/feature_assumeutxo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ def check_tx_counts(final: bool) -> None:
605605
privkey = n0.get_deterministic_priv_key().key
606606
raw_tx = n1.createrawtransaction([prevout], {getnewdestination()[2]: 24.99})
607607
signed_tx = n1.signrawtransactionwithkey(raw_tx, [privkey], [prevout])['hex']
608-
signed_txid = tx_from_hex(signed_tx).rehash()
608+
signed_txid = tx_from_hex(signed_tx).txid_hex
609609

610610
assert n1.gettxout(prev_tx['txid'], 0) is not None
611611
n1.sendrawtransaction(signed_tx)

test/functional/feature_bip68_sequence.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def test_nonzero_locks(orig_tx, node, relayfee, use_height_lock):
246246
tx.wit.vtxinwit[0].scriptWitness.stack = [CScript([OP_TRUE])]
247247
tx.vout = [CTxOut(int(orig_tx.vout[0].nValue - relayfee * COIN), SCRIPT_W0_SH_OP_TRUE)]
248248

249-
if (orig_tx.hash in node.getrawmempool()):
249+
if (orig_tx.txid_hex in node.getrawmempool()):
250250
# sendrawtransaction should fail if the tx is in the mempool
251251
assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.wallet.sendrawtransaction, from_node=node, tx_hex=tx.serialize().hex())
252252
else:
@@ -260,43 +260,43 @@ def test_nonzero_locks(orig_tx, node, relayfee, use_height_lock):
260260

261261
# Now mine some blocks, but make sure tx2 doesn't get mined.
262262
# Use prioritisetransaction to lower the effective feerate to 0
263-
self.nodes[0].prioritisetransaction(txid=tx2.hash, fee_delta=int(-self.relayfee*COIN))
263+
self.nodes[0].prioritisetransaction(txid=tx2.txid_hex, fee_delta=int(-self.relayfee*COIN))
264264
cur_time = int(time.time())
265265
for _ in range(10):
266266
self.nodes[0].setmocktime(cur_time + 600)
267267
self.generate(self.wallet, 1, sync_fun=self.no_op)
268268
cur_time += 600
269269

270-
assert tx2.hash in self.nodes[0].getrawmempool()
270+
assert tx2.txid_hex in self.nodes[0].getrawmempool()
271271

272272
test_nonzero_locks(tx2, self.nodes[0], self.relayfee, use_height_lock=True)
273273
test_nonzero_locks(tx2, self.nodes[0], self.relayfee, use_height_lock=False)
274274

275275
# Mine tx2, and then try again
276-
self.nodes[0].prioritisetransaction(txid=tx2.hash, fee_delta=int(self.relayfee*COIN))
276+
self.nodes[0].prioritisetransaction(txid=tx2.txid_hex, fee_delta=int(self.relayfee*COIN))
277277

278278
# Advance the time on the node so that we can test timelocks
279279
self.nodes[0].setmocktime(cur_time+600)
280280
# Save block template now to use for the reorg later
281281
tmpl = self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
282282
self.generate(self.nodes[0], 1)
283-
assert tx2.hash not in self.nodes[0].getrawmempool()
283+
assert tx2.txid_hex not in self.nodes[0].getrawmempool()
284284

285285
# Now that tx2 is not in the mempool, a sequence locked spend should
286286
# succeed
287287
tx3 = test_nonzero_locks(tx2, self.nodes[0], self.relayfee, use_height_lock=False)
288-
assert tx3.hash in self.nodes[0].getrawmempool()
288+
assert tx3.txid_hex in self.nodes[0].getrawmempool()
289289

290290
self.generate(self.nodes[0], 1)
291-
assert tx3.hash not in self.nodes[0].getrawmempool()
291+
assert tx3.txid_hex not in self.nodes[0].getrawmempool()
292292

293293
# One more test, this time using height locks
294294
tx4 = test_nonzero_locks(tx3, self.nodes[0], self.relayfee, use_height_lock=True)
295-
assert tx4.hash in self.nodes[0].getrawmempool()
295+
assert tx4.txid_hex in self.nodes[0].getrawmempool()
296296

297297
# Now try combining confirmed and unconfirmed inputs
298298
tx5 = test_nonzero_locks(tx4, self.nodes[0], self.relayfee, use_height_lock=True)
299-
assert tx5.hash not in self.nodes[0].getrawmempool()
299+
assert tx5.txid_hex not in self.nodes[0].getrawmempool()
300300

301301
utxo = self.wallet.get_utxo()
302302
tx5.vin.append(CTxIn(COutPoint(int(utxo["txid"], 16), utxo["vout"]), nSequence=1))
@@ -315,8 +315,8 @@ def test_nonzero_locks(orig_tx, node, relayfee, use_height_lock):
315315
# If we invalidate the tip, tx3 should get added to the mempool, causing
316316
# tx4 to be removed (fails sequence-lock).
317317
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
318-
assert tx4.hash not in self.nodes[0].getrawmempool()
319-
assert tx3.hash in self.nodes[0].getrawmempool()
318+
assert tx4.txid_hex not in self.nodes[0].getrawmempool()
319+
assert tx3.txid_hex in self.nodes[0].getrawmempool()
320320

321321
# Now mine 2 empty blocks to reorg out the current tip (labeled tip-1 in
322322
# diagram above).
@@ -333,8 +333,8 @@ def test_nonzero_locks(orig_tx, node, relayfee, use_height_lock):
333333
cur_time += 1
334334

335335
mempool = self.nodes[0].getrawmempool()
336-
assert tx3.hash not in mempool
337-
assert tx2.hash in mempool
336+
assert tx3.txid_hex not in mempool
337+
assert tx2.txid_hex in mempool
338338

339339
# Reset the chain and get rid of the mocktimed-blocks
340340
self.nodes[0].setmocktime(0)

test/functional/feature_block.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def run_test(self):
150150

151151
# MAX_SCRIPT_SIZE + 1 wasn't added to the utxo set
152152
tx.vin[0] = min_size_unspendable_output
153-
assert_raises_rpc_error(-25, f'TestBlockValidity failed: bad-txns-inputs-missingorspent, CheckTxInputs: inputs missing/spent in transaction {tx.rehash()}', self.generateblock, self.nodes[0], output="raw(55)", transactions=[tx.serialize().hex()])
153+
assert_raises_rpc_error(-25, f'TestBlockValidity failed: bad-txns-inputs-missingorspent, CheckTxInputs: inputs missing/spent in transaction {tx.txid_hex}', self.generateblock, self.nodes[0], output="raw(55)", transactions=[tx.serialize().hex()])
154154

155155
# collect spendable outputs now to avoid cluttering the code later on
156156
out = []
@@ -878,10 +878,10 @@ def run_test(self):
878878
b_dup_2.vtx[0].vin[0].scriptSig = DUPLICATE_COINBASE_SCRIPT_SIG
879879
b_dup_2 = self.update_block('dup_2', [])
880880
assert_equal(duplicate_tx.serialize(), b_dup_2.vtx[0].serialize())
881-
assert_equal(self.nodes[0].gettxout(txid=duplicate_tx.hash, n=0)['confirmations'], 119)
881+
assert_equal(self.nodes[0].gettxout(txid=duplicate_tx.txid_hex, n=0)['confirmations'], 119)
882882
self.send_blocks([b_spend_dup_cb, b_dup_2], success=True)
883883
# The duplicate has less confirmations
884-
assert_equal(self.nodes[0].gettxout(txid=duplicate_tx.hash, n=0)['confirmations'], 1)
884+
assert_equal(self.nodes[0].gettxout(txid=duplicate_tx.txid_hex, n=0)['confirmations'], 1)
885885

886886
# Test tx.isFinal is properly rejected (not an exhaustive tx.isFinal test, that should be in data-driven transaction tests)
887887
#
@@ -1211,8 +1211,8 @@ def run_test(self):
12111211
# now check that tx78 and tx79 have been put back into the peer's mempool
12121212
mempool = self.nodes[0].getrawmempool()
12131213
assert_equal(len(mempool), 2)
1214-
assert tx78.hash in mempool
1215-
assert tx79.hash in mempool
1214+
assert tx78.txid_hex in mempool
1215+
assert tx79.txid_hex in mempool
12161216

12171217
# Test invalid opcodes in dead execution paths.
12181218
#

test/functional/feature_cltv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def run_test(self):
162162
][i]
163163
# First we show that this tx is valid except for CLTV by getting it
164164
# rejected from the mempool for exactly that reason.
165-
spendtx_txid = spendtx.hash
165+
spendtx_txid = spendtx.txid_hex
166166
spendtx_wtxid = spendtx.getwtxid()
167167
assert_equal(
168168
[{

test/functional/feature_csv_activation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def set_test_params(self):
103103
self.supports_cli = False
104104

105105
def create_self_transfer_from_utxo(self, input_tx):
106-
utxo = self.miniwallet.get_utxo(txid=input_tx.rehash(), mark_as_spent=False)
106+
utxo = self.miniwallet.get_utxo(txid=input_tx.txid_hex, mark_as_spent=False)
107107
tx = self.miniwallet.create_self_transfer(utxo_to_spend=utxo)['tx']
108108
return tx
109109

test/functional/feature_dersig.py

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

115115
# First we show that this tx is valid except for DERSIG by getting it
116116
# rejected from the mempool for exactly that reason.
117-
spendtx_txid = spendtx.hash
117+
spendtx_txid = spendtx.txid_hex
118118
spendtx_wtxid = spendtx.getwtxid()
119119
assert_equal(
120120
[{

test/functional/feature_fee_estimation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def small_txpuzzle_randfee(
6161
tx.vout[0].nValue = int((total_in - amount - fee) * COIN)
6262
tx.vout.append(deepcopy(tx.vout[0]))
6363
tx.vout[1].nValue = int(amount * COIN)
64-
txid = tx.hash
64+
txid = tx.txid_hex
6565
tx_hex = tx.serialize().hex()
6666

6767
batch_reqs.append(from_node.sendrawtransaction.get_request(hexstring=tx_hex, maxfeerate=0))

test/functional/feature_nulldummy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def run_test(self):
110110
self.block_submit(self.nodes[0], [test2tx], accept=True)
111111

112112
self.log.info("Test 4: Non-NULLDUMMY base multisig transaction is invalid after activation")
113-
test4tx = self.create_transaction(txid=test2tx.hash, input_details=ms_unlock_details,
113+
test4tx = self.create_transaction(txid=test2tx.txid_hex, input_details=ms_unlock_details,
114114
addr=getnewdestination()[2], amount=46,
115115
privkey=self.privkey)
116116
test6txs = [CTransaction(test4tx)]

test/functional/feature_rbf.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def test_simple_doublespend(self):
110110

111111
# This will raise an exception due to insufficient fee
112112
reject_reason = "insufficient fee"
113-
reject_details = f"{reject_reason}, rejecting replacement {tx.hash}; new feerate 0.00300000 BTC/kvB <= old feerate 0.00300000 BTC/kvB"
113+
reject_details = f"{reject_reason}, rejecting replacement {tx.txid_hex}; new feerate 0.00300000 BTC/kvB <= old feerate 0.00300000 BTC/kvB"
114114
res = self.nodes[0].testmempoolaccept(rawtxs=[tx_hex])[0]
115115
assert_equal(res["reject-reason"], reject_reason)
116116
assert_equal(res["reject-details"], reject_details)
@@ -160,7 +160,7 @@ def test_doublespend_chain(self):
160160

161161
# This will raise an exception due to insufficient fee
162162
reject_reason = "insufficient fee"
163-
reject_details = f"{reject_reason}, rejecting replacement {dbl_tx.hash}, less fees than conflicting txs; 3.00 < 4.00"
163+
reject_details = f"{reject_reason}, rejecting replacement {dbl_tx.txid_hex}, less fees than conflicting txs; 3.00 < 4.00"
164164
res = self.nodes[0].testmempoolaccept(rawtxs=[dbl_tx_hex])[0]
165165
assert_equal(res["reject-reason"], reject_reason)
166166
assert_equal(res["reject-details"], reject_details)
@@ -303,7 +303,7 @@ def test_spends_of_conflicting_outputs(self):
303303

304304
# This will raise an exception
305305
reject_reason = "bad-txns-spends-conflicting-tx"
306-
reject_details = f"{reject_reason}, {tx2.hash} spends conflicting transaction {tx1a['tx'].hash}"
306+
reject_details = f"{reject_reason}, {tx2.txid_hex} spends conflicting transaction {tx1a['tx'].txid_hex}"
307307
res = self.nodes[0].testmempoolaccept(rawtxs=[tx2_hex])[0]
308308
assert_equal(res["reject-reason"], reject_reason)
309309
assert_equal(res["reject-details"], reject_details)
@@ -348,7 +348,7 @@ def test_new_unconfirmed_inputs(self):
348348

349349
# This will raise an exception
350350
reject_reason = "replacement-adds-unconfirmed"
351-
reject_details = f"{reject_reason}, replacement {tx2.hash} adds unconfirmed input, idx 1"
351+
reject_details = f"{reject_reason}, replacement {tx2.txid_hex} adds unconfirmed input, idx 1"
352352
res = self.nodes[0].testmempoolaccept(rawtxs=[tx2_hex])[0]
353353
assert_equal(res["reject-reason"], reject_reason)
354354
assert_equal(res["reject-details"], reject_details)
@@ -396,7 +396,7 @@ def test_too_many_replacements(self):
396396

397397
# This will raise an exception
398398
reject_reason = "too many potential replacements"
399-
reject_details = f"{reject_reason}, rejecting replacement {double_tx.hash}; too many potential replacements ({MAX_REPLACEMENT_LIMIT + 1} > {MAX_REPLACEMENT_LIMIT})"
399+
reject_details = f"{reject_reason}, rejecting replacement {double_tx.txid_hex}; too many potential replacements ({MAX_REPLACEMENT_LIMIT + 1} > {MAX_REPLACEMENT_LIMIT})"
400400
res = self.nodes[0].testmempoolaccept(rawtxs=[double_tx_hex])[0]
401401
assert_equal(res["reject-reason"], reject_reason)
402402
assert_equal(res["reject-details"], reject_details)

test/functional/feature_taproot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ def test_spenders(self, node, spenders, input_counts):
15401540
msg = ','.join(utxo.spender.comment + ("*" if n == fail_input else "") for n, utxo in enumerate(input_utxos))
15411541
if is_standard_tx:
15421542
node.sendrawtransaction(tx.serialize().hex(), 0)
1543-
assert node.getmempoolentry(tx.hash) is not None, "Failed to accept into mempool: " + msg
1543+
assert node.getmempoolentry(tx.txid_hex) is not None, "Failed to accept into mempool: " + msg
15441544
else:
15451545
assert_raises_rpc_error(-26, None, node.sendrawtransaction, tx.serialize().hex(), 0)
15461546
# Submit in a block
@@ -1566,7 +1566,7 @@ def gen_test_vectors(self):
15661566
coinbase.vin = [CTxIn(COutPoint(0, 0xffffffff), CScript([OP_1, OP_1]), SEQUENCE_FINAL)]
15671567
coinbase.vout = [CTxOut(5000000000, CScript([OP_1]))]
15681568
coinbase.nLockTime = 0
1569-
assert coinbase.hash == "f60c73405d499a956d3162e3483c395526ef78286458a4cb17b125aa92e49b20"
1569+
assert coinbase.txid_hex == "f60c73405d499a956d3162e3483c395526ef78286458a4cb17b125aa92e49b20"
15701570
# Mine it
15711571
block = create_block(hashprev=int(self.nodes[0].getbestblockhash(), 16), coinbase=coinbase)
15721572
block.rehash()

0 commit comments

Comments
 (0)