Skip to content

Commit 81af433

Browse files
committed
test: rename CTransaction .sha256 -> .txid_int for consistency
Note that we unfortunately can't use a scripted diff here, as the same property name is also used for `CBlockHeader`/`CBlock` instances.
1 parent ce83924 commit 81af433

File tree

13 files changed

+114
-114
lines changed

13 files changed

+114
-114
lines changed

contrib/signet/miner

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def signet_txs(block, challenge):
4040
txs[0].vout[-1].scriptPubKey += CScriptOp.encode_op_pushdata(SIGNET_HEADER)
4141
hashes = []
4242
for tx in txs:
43-
hashes.append(ser_uint256(tx.sha256))
43+
hashes.append(ser_uint256(tx.txid_int))
4444
mroot = block.get_merkle_root(hashes)
4545

4646
sd = b""
@@ -58,7 +58,7 @@ def signet_txs(block, challenge):
5858
spend = CTransaction()
5959
spend.version = 0
6060
spend.nLockTime = 0
61-
spend.vin = [CTxIn(COutPoint(to_spend.sha256, 0), b"", 0)]
61+
spend.vin = [CTxIn(COutPoint(to_spend.txid_int, 0), b"", 0)]
6262
spend.vout = [CTxOut(0, b"\x6a")]
6363

6464
return spend, to_spend

test/functional/data/invalid_txs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class BadTxTemplate:
8383
def __init__(self, *, spend_tx=None, spend_block=None):
8484
self.spend_tx = spend_block.vtx[0] if spend_block else spend_tx
8585
self.spend_avail = sum(o.nValue for o in self.spend_tx.vout)
86-
self.valid_txin = CTxIn(COutPoint(self.spend_tx.sha256, 0), b"", SEQUENCE_FINAL)
86+
self.valid_txin = CTxIn(COutPoint(self.spend_tx.txid_int, 0), b"", SEQUENCE_FINAL)
8787

8888
@abc.abstractmethod
8989
def get_tx(self, *args, **kwargs):
@@ -144,7 +144,7 @@ def get_tx(self):
144144
bad_idx = num_indices + 100
145145

146146
tx = CTransaction()
147-
tx.vin.append(CTxIn(COutPoint(self.spend_tx.sha256, bad_idx), b"", SEQUENCE_FINAL))
147+
tx.vin.append(CTxIn(COutPoint(self.spend_tx.txid_int, bad_idx), b"", SEQUENCE_FINAL))
148148
tx.vout.append(CTxOut(0, basic_p2sh))
149149
return tx
150150

@@ -181,7 +181,7 @@ class NonexistentInput(BadTxTemplate):
181181

182182
def get_tx(self):
183183
tx = CTransaction()
184-
tx.vin.append(CTxIn(COutPoint(self.spend_tx.sha256 + 1, 0), b"", SEQUENCE_FINAL))
184+
tx.vin.append(CTxIn(COutPoint(self.spend_tx.txid_int + 1, 0), b"", SEQUENCE_FINAL))
185185
tx.vin.append(self.valid_txin)
186186
tx.vout.append(CTxOut(1, basic_p2sh))
187187
return tx

test/functional/feature_assumevalid.py

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

118118
# Create a transaction spending the coinbase output with an invalid (null) signature
119119
tx = CTransaction()
120-
tx.vin.append(CTxIn(COutPoint(self.block1.vtx[0].sha256, 0), scriptSig=b""))
120+
tx.vin.append(CTxIn(COutPoint(self.block1.vtx[0].txid_int, 0), scriptSig=b""))
121121
tx.vout.append(CTxOut(49 * 100000000, CScript([OP_TRUE])))
122122

123123
block102 = create_block(self.tip, create_coinbase(height), self.block_time, txlist=[tx])

test/functional/feature_bip68_sequence.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def test_sequence_lock_unconfirmed_inputs(self):
224224
# Sequence lock of 0 should pass.
225225
tx2 = CTransaction()
226226
tx2.version = 2
227-
tx2.vin = [CTxIn(COutPoint(tx1.sha256, 0), nSequence=0)]
227+
tx2.vin = [CTxIn(COutPoint(tx1.txid_int, 0), nSequence=0)]
228228
tx2.vout = [CTxOut(int(tx1.vout[0].nValue - self.relayfee * COIN), SCRIPT_W0_SH_OP_TRUE)]
229229
self.wallet.sign_tx(tx=tx2)
230230
tx2_raw = tx2.serialize().hex()
@@ -241,7 +241,7 @@ def test_nonzero_locks(orig_tx, node, relayfee, use_height_lock):
241241

242242
tx = CTransaction()
243243
tx.version = 2
244-
tx.vin = [CTxIn(COutPoint(orig_tx.sha256, 0), nSequence=sequence_value)]
244+
tx.vin = [CTxIn(COutPoint(orig_tx.txid_int, 0), nSequence=sequence_value)]
245245
tx.wit.vtxinwit = [CTxInWitness()]
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)]
@@ -353,7 +353,7 @@ def test_bip68_not_consensus(self):
353353
# Make an anyone-can-spend transaction
354354
tx2 = CTransaction()
355355
tx2.version = 1
356-
tx2.vin = [CTxIn(COutPoint(tx1.sha256, 0), nSequence=0)]
356+
tx2.vin = [CTxIn(COutPoint(tx1.txid_int, 0), nSequence=0)]
357357
tx2.vout = [CTxOut(int(tx1.vout[0].nValue - self.relayfee * COIN), SCRIPT_W0_SH_OP_TRUE)]
358358

359359
# sign tx2
@@ -368,7 +368,7 @@ def test_bip68_not_consensus(self):
368368

369369
tx3 = CTransaction()
370370
tx3.version = 2
371-
tx3.vin = [CTxIn(COutPoint(tx2.sha256, 0), nSequence=sequence_value)]
371+
tx3.vin = [CTxIn(COutPoint(tx2.txid_int, 0), nSequence=sequence_value)]
372372
tx3.wit.vtxinwit = [CTxInWitness()]
373373
tx3.wit.vtxinwit[0].scriptWitness.stack = [CScript([OP_TRUE])]
374374
tx3.vout = [CTxOut(int(tx2.vout[0].nValue - self.relayfee * COIN), SCRIPT_W0_SH_OP_TRUE)]

test/functional/feature_block.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ def run_test(self):
124124
self.send_blocks([b0])
125125

126126
# Will test spending once possibly-mature
127-
max_size_spendable_output = CTxIn(COutPoint(b0.vtx[0].sha256, 1))
128-
min_size_unspendable_output = CTxIn(COutPoint(b0.vtx[0].sha256, 2))
127+
max_size_spendable_output = CTxIn(COutPoint(b0.vtx[0].txid_int, 1))
128+
min_size_unspendable_output = CTxIn(COutPoint(b0.vtx[0].txid_int, 2))
129129

130130
# These constants chosen specifically to trigger an immature coinbase spend
131131
# at a certain time below.
@@ -354,7 +354,7 @@ def run_test(self):
354354
script_length = (MAX_BLOCK_WEIGHT - b23.get_weight() - 276) // 4
355355
script_output = CScript([b'\x00' * script_length])
356356
tx.vout.append(CTxOut(0, script_output))
357-
tx.vin.append(CTxIn(COutPoint(b23.vtx[1].sha256, 0)))
357+
tx.vin.append(CTxIn(COutPoint(b23.vtx[1].txid_int, 0)))
358358
b23 = self.update_block(23, [tx])
359359
# Make sure the math above worked out to produce a max-weighted block
360360
assert_equal(b23.get_weight(), MAX_BLOCK_WEIGHT)
@@ -554,19 +554,19 @@ def run_test(self):
554554
numTxes = (MAX_BLOCK_SIGOPS - sigops) // b39_sigops_per_output
555555
assert_equal(numTxes <= b39_outputs, True)
556556

557-
lastOutpoint = COutPoint(b40.vtx[1].sha256, 0)
557+
lastOutpoint = COutPoint(b40.vtx[1].txid_int, 0)
558558
new_txs = []
559559
for i in range(1, numTxes + 1):
560560
tx = CTransaction()
561561
tx.vout.append(CTxOut(1, CScript([OP_TRUE])))
562562
tx.vin.append(CTxIn(lastOutpoint, b''))
563563
# second input is corresponding P2SH output from b39
564-
tx.vin.append(CTxIn(COutPoint(b39.vtx[i].sha256, 0), b''))
564+
tx.vin.append(CTxIn(COutPoint(b39.vtx[i].txid_int, 0), b''))
565565
# Note: must pass the redeem_script (not p2sh_script) to the signature hash function
566566
tx.vin[1].scriptSig = CScript([redeem_script])
567567
sign_input_legacy(tx, 1, redeem_script, self.coinbase_key)
568568
new_txs.append(tx)
569-
lastOutpoint = COutPoint(tx.sha256, 0)
569+
lastOutpoint = COutPoint(tx.txid_int, 0)
570570

571571
b40_sigops_to_fill = MAX_BLOCK_SIGOPS - (numTxes * b39_sigops_per_output + sigops) + 1
572572
tx = CTransaction()
@@ -822,7 +822,7 @@ def run_test(self):
822822
self.next_block(58, spend=out[17])
823823
tx = CTransaction()
824824
assert len(out[17].vout) < 42
825-
tx.vin.append(CTxIn(COutPoint(out[17].sha256, 42), CScript([OP_TRUE]), SEQUENCE_FINAL))
825+
tx.vin.append(CTxIn(COutPoint(out[17].txid_int, 42), CScript([OP_TRUE]), SEQUENCE_FINAL))
826826
tx.vout.append(CTxOut(0, b""))
827827
b58 = self.update_block(58, [tx])
828828
self.send_blocks([b58], success=False, reject_reason='bad-txns-inputs-missingorspent', reconnect=True)
@@ -868,7 +868,7 @@ def run_test(self):
868868
self.move_tip(57)
869869
self.next_block('spend_dup_cb')
870870
tx = CTransaction()
871-
tx.vin.append(CTxIn(COutPoint(duplicate_tx.sha256, 0)))
871+
tx.vin.append(CTxIn(COutPoint(duplicate_tx.txid_int, 0)))
872872
tx.vout.append(CTxOut(0, CScript([OP_TRUE])))
873873
self.sign_tx(tx, duplicate_tx)
874874
b_spend_dup_cb = self.update_block('spend_dup_cb', [tx])
@@ -893,7 +893,7 @@ def run_test(self):
893893
self.next_block(62)
894894
tx = CTransaction()
895895
tx.nLockTime = 0xffffffff # this locktime is non-final
896-
tx.vin.append(CTxIn(COutPoint(out[18].sha256, 0))) # don't set nSequence
896+
tx.vin.append(CTxIn(COutPoint(out[18].txid_int, 0))) # don't set nSequence
897897
tx.vout.append(CTxOut(0, CScript([OP_TRUE])))
898898
assert_greater_than(SEQUENCE_FINAL, tx.vin[0].nSequence)
899899
b62 = self.update_block(62, [tx])
@@ -941,7 +941,7 @@ def run_test(self):
941941
script_length = (MAX_BLOCK_WEIGHT - 4 * len(b64a.normal_serialize()) - 276) // 4
942942
script_output = CScript([b'\x00' * script_length])
943943
tx.vout.append(CTxOut(0, script_output))
944-
tx.vin.append(CTxIn(COutPoint(b64a.vtx[1].sha256, 0)))
944+
tx.vin.append(CTxIn(COutPoint(b64a.vtx[1].txid_int, 0)))
945945
b64a = self.update_block("64a", [tx])
946946
assert_equal(b64a.get_weight(), MAX_BLOCK_WEIGHT + 8 * 4)
947947
self.send_blocks([b64a], success=False, reject_reason='non-canonical ReadCompactSize()')
@@ -1294,7 +1294,7 @@ def run_test(self):
12941294
script_length = (MAX_BLOCK_WEIGHT - b.get_weight() - 276) // 4
12951295
script_output = CScript([b'\x00' * script_length])
12961296
tx.vout.append(CTxOut(0, script_output))
1297-
tx.vin.append(CTxIn(COutPoint(b.vtx[1].sha256, 0)))
1297+
tx.vin.append(CTxIn(COutPoint(b.vtx[1].txid_int, 0)))
12981298
b = self.update_block(i, [tx])
12991299
assert_equal(b.get_weight(), MAX_BLOCK_WEIGHT)
13001300
blocks.append(b)

test/functional/feature_taproot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ def test_spenders(self, node, spenders, input_counts):
14241424
fund_tx = tx_from_hex(node.signrawtransactionwithwallet(fund_tx.serialize().hex())["hex"])
14251425
# Construct UTXOData entries
14261426
for i in range(count_this_tx):
1427-
utxodata = UTXOData(outpoint=COutPoint(fund_tx.sha256, i), output=fund_tx.vout[i], spender=spenders[done])
1427+
utxodata = UTXOData(outpoint=COutPoint(fund_tx.txid_int, i), output=fund_tx.vout[i], spender=spenders[done])
14281428
if utxodata.spender.need_vin_vout_mismatch:
14291429
mismatching_utxos.append(utxodata)
14301430
else:
@@ -1648,7 +1648,7 @@ def gen_test_vectors(self):
16481648
# Construct a deterministic chain of transactions creating UTXOs to the test's spk's (so that they
16491649
# come from distinct txids).
16501650
txn = []
1651-
lasttxid = coinbase.sha256
1651+
lasttxid = coinbase.txid_int
16521652
amount = 5000000000
16531653
for i, spk in enumerate(old_spks + tap_spks):
16541654
val = 42000000 * (i + 7)
@@ -1660,9 +1660,9 @@ def gen_test_vectors(self):
16601660
tx.vout = list(reversed(tx.vout))
16611661
tx.nLockTime = 0
16621662
amount -= val
1663-
lasttxid = tx.sha256
1663+
lasttxid = tx.txid_int
16641664
txn.append(tx)
1665-
spend_info[spk]['prevout'] = COutPoint(tx.sha256, i & 1)
1665+
spend_info[spk]['prevout'] = COutPoint(tx.txid_int, i & 1)
16661666
spend_info[spk]['utxo'] = CTxOut(val, spk)
16671667
# Mine those transactions
16681668
self.init_blockinfo(self.nodes[0])

test/functional/mempool_accept.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def run_test(self):
468468
self.generateblock(node, self.wallet.get_address(), [nested_anchor_tx.serialize().hex()])
469469

470470
nested_anchor_spend = CTransaction()
471-
nested_anchor_spend.vin.append(CTxIn(COutPoint(nested_anchor_tx.sha256, 0), b""))
471+
nested_anchor_spend.vin.append(CTxIn(COutPoint(nested_anchor_tx.txid_int, 0), b""))
472472
nested_anchor_spend.vin[0].scriptSig = CScript([bytes(PAY_TO_ANCHOR)])
473473
nested_anchor_spend.vout.append(CTxOut(nested_anchor_tx.vout[0].nValue - int(fee*COIN), script_to_p2wsh_script(CScript([OP_TRUE]))))
474474

@@ -487,7 +487,7 @@ def run_test(self):
487487
tx.vout[0].scriptPubKey = keys_to_multisig_script([pubkey] * 3, k=1) # Some bare multisig script (1-of-3)
488488
self.generateblock(node, address, [tx.serialize().hex()])
489489
tx_spend = CTransaction()
490-
tx_spend.vin.append(CTxIn(COutPoint(tx.sha256, 0), b""))
490+
tx_spend.vin.append(CTxIn(COutPoint(tx.txid_int, 0), b""))
491491
tx_spend.vout.append(CTxOut(tx.vout[0].nValue - int(fee*COIN), script_to_p2wsh_script(CScript([OP_TRUE]))))
492492
sign_input_legacy(tx_spend, 0, tx.vout[0].scriptPubKey, privkey, sighash_type=SIGHASH_ALL)
493493
tx_spend.vin[0].scriptSig = bytes(CScript([OP_0])) + tx_spend.vin[0].scriptSig

test/functional/p2p_compactblocks.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def make_utxos(self):
166166
total_value = block.vtx[0].vout[0].nValue
167167
out_value = total_value // 10
168168
tx = CTransaction()
169-
tx.vin.append(CTxIn(COutPoint(block.vtx[0].sha256, 0), b''))
169+
tx.vin.append(CTxIn(COutPoint(block.vtx[0].txid_int, 0), b''))
170170
for _ in range(10):
171171
tx.vout.append(CTxOut(out_value, CScript([OP_TRUE])))
172172

@@ -176,7 +176,7 @@ def make_utxos(self):
176176
block2.solve()
177177
self.segwit_node.send_and_ping(msg_no_witness_block(block2))
178178
assert_equal(int(self.nodes[0].getbestblockhash(), 16), block2.sha256)
179-
self.utxos.extend([[tx.sha256, i, out_value] for i in range(10)])
179+
self.utxos.extend([[tx.txid_int, i, out_value] for i in range(10)])
180180

181181

182182
# Test "sendcmpct" (between peers preferring the same version):
@@ -420,7 +420,7 @@ def build_block_with_transactions(self, node, utxo, num_transactions):
420420
tx = CTransaction()
421421
tx.vin.append(CTxIn(COutPoint(utxo[0], utxo[1]), b''))
422422
tx.vout.append(CTxOut(utxo[2] - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
423-
utxo = [tx.sha256, 0, tx.vout[0].nValue]
423+
utxo = [tx.txid_int, 0, tx.vout[0].nValue]
424424
block.vtx.append(tx)
425425

426426
block.hashMerkleRoot = block.calc_merkle_root()
@@ -450,7 +450,7 @@ def test_tip_after_message(node, peer, msg, tip):
450450
utxo = self.utxos.pop(0)
451451

452452
block = self.build_block_with_transactions(node, utxo, 5)
453-
self.utxos.append([block.vtx[-1].sha256, 0, block.vtx[-1].vout[0].nValue])
453+
self.utxos.append([block.vtx[-1].txid_int, 0, block.vtx[-1].vout[0].nValue])
454454
comp_block = HeaderAndShortIDs()
455455
comp_block.initialize_from_block(block, use_witness=True)
456456

@@ -463,7 +463,7 @@ def test_tip_after_message(node, peer, msg, tip):
463463

464464
utxo = self.utxos.pop(0)
465465
block = self.build_block_with_transactions(node, utxo, 5)
466-
self.utxos.append([block.vtx[-1].sha256, 0, block.vtx[-1].vout[0].nValue])
466+
self.utxos.append([block.vtx[-1].txid_int, 0, block.vtx[-1].vout[0].nValue])
467467

468468
# Now try interspersing the prefilled transactions
469469
comp_block.initialize_from_block(block, prefill_list=[0, 1, 5], use_witness=True)
@@ -474,7 +474,7 @@ def test_tip_after_message(node, peer, msg, tip):
474474
# Now try giving one transaction ahead of time.
475475
utxo = self.utxos.pop(0)
476476
block = self.build_block_with_transactions(node, utxo, 5)
477-
self.utxos.append([block.vtx[-1].sha256, 0, block.vtx[-1].vout[0].nValue])
477+
self.utxos.append([block.vtx[-1].txid_int, 0, block.vtx[-1].vout[0].nValue])
478478
test_node.send_and_ping(msg_tx(block.vtx[1]))
479479
assert block.vtx[1].txid_hex in node.getrawmempool()
480480

@@ -490,7 +490,7 @@ def test_tip_after_message(node, peer, msg, tip):
490490
# announced and verify reconstruction happens immediately.
491491
utxo = self.utxos.pop(0)
492492
block = self.build_block_with_transactions(node, utxo, 10)
493-
self.utxos.append([block.vtx[-1].sha256, 0, block.vtx[-1].vout[0].nValue])
493+
self.utxos.append([block.vtx[-1].txid_int, 0, block.vtx[-1].vout[0].nValue])
494494
for tx in block.vtx[1:]:
495495
test_node.send_without_ping(msg_tx(tx))
496496
test_node.sync_with_ping()
@@ -517,7 +517,7 @@ def test_incorrect_blocktxn_response(self, test_node):
517517
utxo = self.utxos.pop(0)
518518

519519
block = self.build_block_with_transactions(node, utxo, 10)
520-
self.utxos.append([block.vtx[-1].sha256, 0, block.vtx[-1].vout[0].nValue])
520+
self.utxos.append([block.vtx[-1].txid_int, 0, block.vtx[-1].vout[0].nValue])
521521
# Relay the first 5 transactions from the block in advance
522522
for tx in block.vtx[1:6]:
523523
test_node.send_without_ping(msg_tx(tx))
@@ -770,7 +770,7 @@ def announce_cmpct_block(node, peer):
770770
delivery_peer.send_and_ping(msg_cmpctblock(cmpct_block.to_p2p()))
771771
assert_equal(int(node.getbestblockhash(), 16), block.sha256)
772772

773-
self.utxos.append([block.vtx[-1].sha256, 0, block.vtx[-1].vout[0].nValue])
773+
self.utxos.append([block.vtx[-1].txid_int, 0, block.vtx[-1].vout[0].nValue])
774774

775775
# Now test that delivering an invalid compact block won't break relay
776776

@@ -884,7 +884,7 @@ def announce_cmpct_block(node, peer, txn_count):
884884

885885
# Nothing bad should happen if we get a late fill from the first peer...
886886
stalling_peer.send_and_ping(msg)
887-
self.utxos.append([block.vtx[-1].sha256, 0, block.vtx[-1].vout[0].nValue])
887+
self.utxos.append([block.vtx[-1].txid_int, 0, block.vtx[-1].vout[0].nValue])
888888

889889
delivery_peer.clear_getblocktxn()
890890
inbound_peer.clear_getblocktxn()

0 commit comments

Comments
 (0)