mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-31 10:41:08 +00:00
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.
This commit is contained in:
parent
ce83924237
commit
81af4334e8
@ -40,7 +40,7 @@ def signet_txs(block, challenge):
|
||||
txs[0].vout[-1].scriptPubKey += CScriptOp.encode_op_pushdata(SIGNET_HEADER)
|
||||
hashes = []
|
||||
for tx in txs:
|
||||
hashes.append(ser_uint256(tx.sha256))
|
||||
hashes.append(ser_uint256(tx.txid_int))
|
||||
mroot = block.get_merkle_root(hashes)
|
||||
|
||||
sd = b""
|
||||
@ -58,7 +58,7 @@ def signet_txs(block, challenge):
|
||||
spend = CTransaction()
|
||||
spend.version = 0
|
||||
spend.nLockTime = 0
|
||||
spend.vin = [CTxIn(COutPoint(to_spend.sha256, 0), b"", 0)]
|
||||
spend.vin = [CTxIn(COutPoint(to_spend.txid_int, 0), b"", 0)]
|
||||
spend.vout = [CTxOut(0, b"\x6a")]
|
||||
|
||||
return spend, to_spend
|
||||
|
||||
@ -83,7 +83,7 @@ class BadTxTemplate:
|
||||
def __init__(self, *, spend_tx=None, spend_block=None):
|
||||
self.spend_tx = spend_block.vtx[0] if spend_block else spend_tx
|
||||
self.spend_avail = sum(o.nValue for o in self.spend_tx.vout)
|
||||
self.valid_txin = CTxIn(COutPoint(self.spend_tx.sha256, 0), b"", SEQUENCE_FINAL)
|
||||
self.valid_txin = CTxIn(COutPoint(self.spend_tx.txid_int, 0), b"", SEQUENCE_FINAL)
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_tx(self, *args, **kwargs):
|
||||
@ -144,7 +144,7 @@ class BadInputOutpointIndex(BadTxTemplate):
|
||||
bad_idx = num_indices + 100
|
||||
|
||||
tx = CTransaction()
|
||||
tx.vin.append(CTxIn(COutPoint(self.spend_tx.sha256, bad_idx), b"", SEQUENCE_FINAL))
|
||||
tx.vin.append(CTxIn(COutPoint(self.spend_tx.txid_int, bad_idx), b"", SEQUENCE_FINAL))
|
||||
tx.vout.append(CTxOut(0, basic_p2sh))
|
||||
return tx
|
||||
|
||||
@ -181,7 +181,7 @@ class NonexistentInput(BadTxTemplate):
|
||||
|
||||
def get_tx(self):
|
||||
tx = CTransaction()
|
||||
tx.vin.append(CTxIn(COutPoint(self.spend_tx.sha256 + 1, 0), b"", SEQUENCE_FINAL))
|
||||
tx.vin.append(CTxIn(COutPoint(self.spend_tx.txid_int + 1, 0), b"", SEQUENCE_FINAL))
|
||||
tx.vin.append(self.valid_txin)
|
||||
tx.vout.append(CTxOut(1, basic_p2sh))
|
||||
return tx
|
||||
|
||||
@ -117,7 +117,7 @@ class AssumeValidTest(BitcoinTestFramework):
|
||||
|
||||
# Create a transaction spending the coinbase output with an invalid (null) signature
|
||||
tx = CTransaction()
|
||||
tx.vin.append(CTxIn(COutPoint(self.block1.vtx[0].sha256, 0), scriptSig=b""))
|
||||
tx.vin.append(CTxIn(COutPoint(self.block1.vtx[0].txid_int, 0), scriptSig=b""))
|
||||
tx.vout.append(CTxOut(49 * 100000000, CScript([OP_TRUE])))
|
||||
|
||||
block102 = create_block(self.tip, create_coinbase(height), self.block_time, txlist=[tx])
|
||||
|
||||
@ -224,7 +224,7 @@ class BIP68Test(BitcoinTestFramework):
|
||||
# Sequence lock of 0 should pass.
|
||||
tx2 = CTransaction()
|
||||
tx2.version = 2
|
||||
tx2.vin = [CTxIn(COutPoint(tx1.sha256, 0), nSequence=0)]
|
||||
tx2.vin = [CTxIn(COutPoint(tx1.txid_int, 0), nSequence=0)]
|
||||
tx2.vout = [CTxOut(int(tx1.vout[0].nValue - self.relayfee * COIN), SCRIPT_W0_SH_OP_TRUE)]
|
||||
self.wallet.sign_tx(tx=tx2)
|
||||
tx2_raw = tx2.serialize().hex()
|
||||
@ -241,7 +241,7 @@ class BIP68Test(BitcoinTestFramework):
|
||||
|
||||
tx = CTransaction()
|
||||
tx.version = 2
|
||||
tx.vin = [CTxIn(COutPoint(orig_tx.sha256, 0), nSequence=sequence_value)]
|
||||
tx.vin = [CTxIn(COutPoint(orig_tx.txid_int, 0), nSequence=sequence_value)]
|
||||
tx.wit.vtxinwit = [CTxInWitness()]
|
||||
tx.wit.vtxinwit[0].scriptWitness.stack = [CScript([OP_TRUE])]
|
||||
tx.vout = [CTxOut(int(orig_tx.vout[0].nValue - relayfee * COIN), SCRIPT_W0_SH_OP_TRUE)]
|
||||
@ -353,7 +353,7 @@ class BIP68Test(BitcoinTestFramework):
|
||||
# Make an anyone-can-spend transaction
|
||||
tx2 = CTransaction()
|
||||
tx2.version = 1
|
||||
tx2.vin = [CTxIn(COutPoint(tx1.sha256, 0), nSequence=0)]
|
||||
tx2.vin = [CTxIn(COutPoint(tx1.txid_int, 0), nSequence=0)]
|
||||
tx2.vout = [CTxOut(int(tx1.vout[0].nValue - self.relayfee * COIN), SCRIPT_W0_SH_OP_TRUE)]
|
||||
|
||||
# sign tx2
|
||||
@ -368,7 +368,7 @@ class BIP68Test(BitcoinTestFramework):
|
||||
|
||||
tx3 = CTransaction()
|
||||
tx3.version = 2
|
||||
tx3.vin = [CTxIn(COutPoint(tx2.sha256, 0), nSequence=sequence_value)]
|
||||
tx3.vin = [CTxIn(COutPoint(tx2.txid_int, 0), nSequence=sequence_value)]
|
||||
tx3.wit.vtxinwit = [CTxInWitness()]
|
||||
tx3.wit.vtxinwit[0].scriptWitness.stack = [CScript([OP_TRUE])]
|
||||
tx3.vout = [CTxOut(int(tx2.vout[0].nValue - self.relayfee * COIN), SCRIPT_W0_SH_OP_TRUE)]
|
||||
|
||||
@ -124,8 +124,8 @@ class FullBlockTest(BitcoinTestFramework):
|
||||
self.send_blocks([b0])
|
||||
|
||||
# Will test spending once possibly-mature
|
||||
max_size_spendable_output = CTxIn(COutPoint(b0.vtx[0].sha256, 1))
|
||||
min_size_unspendable_output = CTxIn(COutPoint(b0.vtx[0].sha256, 2))
|
||||
max_size_spendable_output = CTxIn(COutPoint(b0.vtx[0].txid_int, 1))
|
||||
min_size_unspendable_output = CTxIn(COutPoint(b0.vtx[0].txid_int, 2))
|
||||
|
||||
# These constants chosen specifically to trigger an immature coinbase spend
|
||||
# at a certain time below.
|
||||
@ -354,7 +354,7 @@ class FullBlockTest(BitcoinTestFramework):
|
||||
script_length = (MAX_BLOCK_WEIGHT - b23.get_weight() - 276) // 4
|
||||
script_output = CScript([b'\x00' * script_length])
|
||||
tx.vout.append(CTxOut(0, script_output))
|
||||
tx.vin.append(CTxIn(COutPoint(b23.vtx[1].sha256, 0)))
|
||||
tx.vin.append(CTxIn(COutPoint(b23.vtx[1].txid_int, 0)))
|
||||
b23 = self.update_block(23, [tx])
|
||||
# Make sure the math above worked out to produce a max-weighted block
|
||||
assert_equal(b23.get_weight(), MAX_BLOCK_WEIGHT)
|
||||
@ -554,19 +554,19 @@ class FullBlockTest(BitcoinTestFramework):
|
||||
numTxes = (MAX_BLOCK_SIGOPS - sigops) // b39_sigops_per_output
|
||||
assert_equal(numTxes <= b39_outputs, True)
|
||||
|
||||
lastOutpoint = COutPoint(b40.vtx[1].sha256, 0)
|
||||
lastOutpoint = COutPoint(b40.vtx[1].txid_int, 0)
|
||||
new_txs = []
|
||||
for i in range(1, numTxes + 1):
|
||||
tx = CTransaction()
|
||||
tx.vout.append(CTxOut(1, CScript([OP_TRUE])))
|
||||
tx.vin.append(CTxIn(lastOutpoint, b''))
|
||||
# second input is corresponding P2SH output from b39
|
||||
tx.vin.append(CTxIn(COutPoint(b39.vtx[i].sha256, 0), b''))
|
||||
tx.vin.append(CTxIn(COutPoint(b39.vtx[i].txid_int, 0), b''))
|
||||
# Note: must pass the redeem_script (not p2sh_script) to the signature hash function
|
||||
tx.vin[1].scriptSig = CScript([redeem_script])
|
||||
sign_input_legacy(tx, 1, redeem_script, self.coinbase_key)
|
||||
new_txs.append(tx)
|
||||
lastOutpoint = COutPoint(tx.sha256, 0)
|
||||
lastOutpoint = COutPoint(tx.txid_int, 0)
|
||||
|
||||
b40_sigops_to_fill = MAX_BLOCK_SIGOPS - (numTxes * b39_sigops_per_output + sigops) + 1
|
||||
tx = CTransaction()
|
||||
@ -822,7 +822,7 @@ class FullBlockTest(BitcoinTestFramework):
|
||||
self.next_block(58, spend=out[17])
|
||||
tx = CTransaction()
|
||||
assert len(out[17].vout) < 42
|
||||
tx.vin.append(CTxIn(COutPoint(out[17].sha256, 42), CScript([OP_TRUE]), SEQUENCE_FINAL))
|
||||
tx.vin.append(CTxIn(COutPoint(out[17].txid_int, 42), CScript([OP_TRUE]), SEQUENCE_FINAL))
|
||||
tx.vout.append(CTxOut(0, b""))
|
||||
b58 = self.update_block(58, [tx])
|
||||
self.send_blocks([b58], success=False, reject_reason='bad-txns-inputs-missingorspent', reconnect=True)
|
||||
@ -868,7 +868,7 @@ class FullBlockTest(BitcoinTestFramework):
|
||||
self.move_tip(57)
|
||||
self.next_block('spend_dup_cb')
|
||||
tx = CTransaction()
|
||||
tx.vin.append(CTxIn(COutPoint(duplicate_tx.sha256, 0)))
|
||||
tx.vin.append(CTxIn(COutPoint(duplicate_tx.txid_int, 0)))
|
||||
tx.vout.append(CTxOut(0, CScript([OP_TRUE])))
|
||||
self.sign_tx(tx, duplicate_tx)
|
||||
b_spend_dup_cb = self.update_block('spend_dup_cb', [tx])
|
||||
@ -893,7 +893,7 @@ class FullBlockTest(BitcoinTestFramework):
|
||||
self.next_block(62)
|
||||
tx = CTransaction()
|
||||
tx.nLockTime = 0xffffffff # this locktime is non-final
|
||||
tx.vin.append(CTxIn(COutPoint(out[18].sha256, 0))) # don't set nSequence
|
||||
tx.vin.append(CTxIn(COutPoint(out[18].txid_int, 0))) # don't set nSequence
|
||||
tx.vout.append(CTxOut(0, CScript([OP_TRUE])))
|
||||
assert_greater_than(SEQUENCE_FINAL, tx.vin[0].nSequence)
|
||||
b62 = self.update_block(62, [tx])
|
||||
@ -941,7 +941,7 @@ class FullBlockTest(BitcoinTestFramework):
|
||||
script_length = (MAX_BLOCK_WEIGHT - 4 * len(b64a.normal_serialize()) - 276) // 4
|
||||
script_output = CScript([b'\x00' * script_length])
|
||||
tx.vout.append(CTxOut(0, script_output))
|
||||
tx.vin.append(CTxIn(COutPoint(b64a.vtx[1].sha256, 0)))
|
||||
tx.vin.append(CTxIn(COutPoint(b64a.vtx[1].txid_int, 0)))
|
||||
b64a = self.update_block("64a", [tx])
|
||||
assert_equal(b64a.get_weight(), MAX_BLOCK_WEIGHT + 8 * 4)
|
||||
self.send_blocks([b64a], success=False, reject_reason='non-canonical ReadCompactSize()')
|
||||
@ -1294,7 +1294,7 @@ class FullBlockTest(BitcoinTestFramework):
|
||||
script_length = (MAX_BLOCK_WEIGHT - b.get_weight() - 276) // 4
|
||||
script_output = CScript([b'\x00' * script_length])
|
||||
tx.vout.append(CTxOut(0, script_output))
|
||||
tx.vin.append(CTxIn(COutPoint(b.vtx[1].sha256, 0)))
|
||||
tx.vin.append(CTxIn(COutPoint(b.vtx[1].txid_int, 0)))
|
||||
b = self.update_block(i, [tx])
|
||||
assert_equal(b.get_weight(), MAX_BLOCK_WEIGHT)
|
||||
blocks.append(b)
|
||||
|
||||
@ -1424,7 +1424,7 @@ class TaprootTest(BitcoinTestFramework):
|
||||
fund_tx = tx_from_hex(node.signrawtransactionwithwallet(fund_tx.serialize().hex())["hex"])
|
||||
# Construct UTXOData entries
|
||||
for i in range(count_this_tx):
|
||||
utxodata = UTXOData(outpoint=COutPoint(fund_tx.sha256, i), output=fund_tx.vout[i], spender=spenders[done])
|
||||
utxodata = UTXOData(outpoint=COutPoint(fund_tx.txid_int, i), output=fund_tx.vout[i], spender=spenders[done])
|
||||
if utxodata.spender.need_vin_vout_mismatch:
|
||||
mismatching_utxos.append(utxodata)
|
||||
else:
|
||||
@ -1648,7 +1648,7 @@ class TaprootTest(BitcoinTestFramework):
|
||||
# Construct a deterministic chain of transactions creating UTXOs to the test's spk's (so that they
|
||||
# come from distinct txids).
|
||||
txn = []
|
||||
lasttxid = coinbase.sha256
|
||||
lasttxid = coinbase.txid_int
|
||||
amount = 5000000000
|
||||
for i, spk in enumerate(old_spks + tap_spks):
|
||||
val = 42000000 * (i + 7)
|
||||
@ -1660,9 +1660,9 @@ class TaprootTest(BitcoinTestFramework):
|
||||
tx.vout = list(reversed(tx.vout))
|
||||
tx.nLockTime = 0
|
||||
amount -= val
|
||||
lasttxid = tx.sha256
|
||||
lasttxid = tx.txid_int
|
||||
txn.append(tx)
|
||||
spend_info[spk]['prevout'] = COutPoint(tx.sha256, i & 1)
|
||||
spend_info[spk]['prevout'] = COutPoint(tx.txid_int, i & 1)
|
||||
spend_info[spk]['utxo'] = CTxOut(val, spk)
|
||||
# Mine those transactions
|
||||
self.init_blockinfo(self.nodes[0])
|
||||
|
||||
@ -468,7 +468,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
|
||||
self.generateblock(node, self.wallet.get_address(), [nested_anchor_tx.serialize().hex()])
|
||||
|
||||
nested_anchor_spend = CTransaction()
|
||||
nested_anchor_spend.vin.append(CTxIn(COutPoint(nested_anchor_tx.sha256, 0), b""))
|
||||
nested_anchor_spend.vin.append(CTxIn(COutPoint(nested_anchor_tx.txid_int, 0), b""))
|
||||
nested_anchor_spend.vin[0].scriptSig = CScript([bytes(PAY_TO_ANCHOR)])
|
||||
nested_anchor_spend.vout.append(CTxOut(nested_anchor_tx.vout[0].nValue - int(fee*COIN), script_to_p2wsh_script(CScript([OP_TRUE]))))
|
||||
|
||||
@ -487,7 +487,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
|
||||
tx.vout[0].scriptPubKey = keys_to_multisig_script([pubkey] * 3, k=1) # Some bare multisig script (1-of-3)
|
||||
self.generateblock(node, address, [tx.serialize().hex()])
|
||||
tx_spend = CTransaction()
|
||||
tx_spend.vin.append(CTxIn(COutPoint(tx.sha256, 0), b""))
|
||||
tx_spend.vin.append(CTxIn(COutPoint(tx.txid_int, 0), b""))
|
||||
tx_spend.vout.append(CTxOut(tx.vout[0].nValue - int(fee*COIN), script_to_p2wsh_script(CScript([OP_TRUE]))))
|
||||
sign_input_legacy(tx_spend, 0, tx.vout[0].scriptPubKey, privkey, sighash_type=SIGHASH_ALL)
|
||||
tx_spend.vin[0].scriptSig = bytes(CScript([OP_0])) + tx_spend.vin[0].scriptSig
|
||||
|
||||
@ -166,7 +166,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
total_value = block.vtx[0].vout[0].nValue
|
||||
out_value = total_value // 10
|
||||
tx = CTransaction()
|
||||
tx.vin.append(CTxIn(COutPoint(block.vtx[0].sha256, 0), b''))
|
||||
tx.vin.append(CTxIn(COutPoint(block.vtx[0].txid_int, 0), b''))
|
||||
for _ in range(10):
|
||||
tx.vout.append(CTxOut(out_value, CScript([OP_TRUE])))
|
||||
|
||||
@ -176,7 +176,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
block2.solve()
|
||||
self.segwit_node.send_and_ping(msg_no_witness_block(block2))
|
||||
assert_equal(int(self.nodes[0].getbestblockhash(), 16), block2.sha256)
|
||||
self.utxos.extend([[tx.sha256, i, out_value] for i in range(10)])
|
||||
self.utxos.extend([[tx.txid_int, i, out_value] for i in range(10)])
|
||||
|
||||
|
||||
# Test "sendcmpct" (between peers preferring the same version):
|
||||
@ -420,7 +420,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
tx = CTransaction()
|
||||
tx.vin.append(CTxIn(COutPoint(utxo[0], utxo[1]), b''))
|
||||
tx.vout.append(CTxOut(utxo[2] - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
|
||||
utxo = [tx.sha256, 0, tx.vout[0].nValue]
|
||||
utxo = [tx.txid_int, 0, tx.vout[0].nValue]
|
||||
block.vtx.append(tx)
|
||||
|
||||
block.hashMerkleRoot = block.calc_merkle_root()
|
||||
@ -450,7 +450,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
utxo = self.utxos.pop(0)
|
||||
|
||||
block = self.build_block_with_transactions(node, utxo, 5)
|
||||
self.utxos.append([block.vtx[-1].sha256, 0, block.vtx[-1].vout[0].nValue])
|
||||
self.utxos.append([block.vtx[-1].txid_int, 0, block.vtx[-1].vout[0].nValue])
|
||||
comp_block = HeaderAndShortIDs()
|
||||
comp_block.initialize_from_block(block, use_witness=True)
|
||||
|
||||
@ -463,7 +463,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
|
||||
utxo = self.utxos.pop(0)
|
||||
block = self.build_block_with_transactions(node, utxo, 5)
|
||||
self.utxos.append([block.vtx[-1].sha256, 0, block.vtx[-1].vout[0].nValue])
|
||||
self.utxos.append([block.vtx[-1].txid_int, 0, block.vtx[-1].vout[0].nValue])
|
||||
|
||||
# Now try interspersing the prefilled transactions
|
||||
comp_block.initialize_from_block(block, prefill_list=[0, 1, 5], use_witness=True)
|
||||
@ -474,7 +474,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
# Now try giving one transaction ahead of time.
|
||||
utxo = self.utxos.pop(0)
|
||||
block = self.build_block_with_transactions(node, utxo, 5)
|
||||
self.utxos.append([block.vtx[-1].sha256, 0, block.vtx[-1].vout[0].nValue])
|
||||
self.utxos.append([block.vtx[-1].txid_int, 0, block.vtx[-1].vout[0].nValue])
|
||||
test_node.send_and_ping(msg_tx(block.vtx[1]))
|
||||
assert block.vtx[1].txid_hex in node.getrawmempool()
|
||||
|
||||
@ -490,7 +490,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
# announced and verify reconstruction happens immediately.
|
||||
utxo = self.utxos.pop(0)
|
||||
block = self.build_block_with_transactions(node, utxo, 10)
|
||||
self.utxos.append([block.vtx[-1].sha256, 0, block.vtx[-1].vout[0].nValue])
|
||||
self.utxos.append([block.vtx[-1].txid_int, 0, block.vtx[-1].vout[0].nValue])
|
||||
for tx in block.vtx[1:]:
|
||||
test_node.send_without_ping(msg_tx(tx))
|
||||
test_node.sync_with_ping()
|
||||
@ -517,7 +517,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
utxo = self.utxos.pop(0)
|
||||
|
||||
block = self.build_block_with_transactions(node, utxo, 10)
|
||||
self.utxos.append([block.vtx[-1].sha256, 0, block.vtx[-1].vout[0].nValue])
|
||||
self.utxos.append([block.vtx[-1].txid_int, 0, block.vtx[-1].vout[0].nValue])
|
||||
# Relay the first 5 transactions from the block in advance
|
||||
for tx in block.vtx[1:6]:
|
||||
test_node.send_without_ping(msg_tx(tx))
|
||||
@ -770,7 +770,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
delivery_peer.send_and_ping(msg_cmpctblock(cmpct_block.to_p2p()))
|
||||
assert_equal(int(node.getbestblockhash(), 16), block.sha256)
|
||||
|
||||
self.utxos.append([block.vtx[-1].sha256, 0, block.vtx[-1].vout[0].nValue])
|
||||
self.utxos.append([block.vtx[-1].txid_int, 0, block.vtx[-1].vout[0].nValue])
|
||||
|
||||
# Now test that delivering an invalid compact block won't break relay
|
||||
|
||||
@ -884,7 +884,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
||||
|
||||
# Nothing bad should happen if we get a late fill from the first peer...
|
||||
stalling_peer.send_and_ping(msg)
|
||||
self.utxos.append([block.vtx[-1].sha256, 0, block.vtx[-1].vout[0].nValue])
|
||||
self.utxos.append([block.vtx[-1].txid_int, 0, block.vtx[-1].vout[0].nValue])
|
||||
|
||||
delivery_peer.clear_getblocktxn()
|
||||
inbound_peer.clear_getblocktxn()
|
||||
|
||||
@ -91,27 +91,27 @@ class InvalidTxRequestTest(BitcoinTestFramework):
|
||||
# are sent out and in the orphan cache
|
||||
SCRIPT_PUB_KEY_OP_TRUE = b'\x51\x75' * 15 + b'\x51'
|
||||
tx_withhold = CTransaction()
|
||||
tx_withhold.vin.append(CTxIn(outpoint=COutPoint(block1.vtx[0].sha256, 0)))
|
||||
tx_withhold.vin.append(CTxIn(outpoint=COutPoint(block1.vtx[0].txid_int, 0)))
|
||||
tx_withhold.vout = [CTxOut(nValue=25 * COIN - 12000, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE)] * 2
|
||||
|
||||
# Our first orphan tx with some outputs to create further orphan txs
|
||||
tx_orphan_1 = CTransaction()
|
||||
tx_orphan_1.vin.append(CTxIn(outpoint=COutPoint(tx_withhold.sha256, 0)))
|
||||
tx_orphan_1.vin.append(CTxIn(outpoint=COutPoint(tx_withhold.txid_int, 0)))
|
||||
tx_orphan_1.vout = [CTxOut(nValue=8 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE)] * 3
|
||||
|
||||
# A valid transaction with low fee
|
||||
tx_orphan_2_no_fee = CTransaction()
|
||||
tx_orphan_2_no_fee.vin.append(CTxIn(outpoint=COutPoint(tx_orphan_1.sha256, 0)))
|
||||
tx_orphan_2_no_fee.vin.append(CTxIn(outpoint=COutPoint(tx_orphan_1.txid_int, 0)))
|
||||
tx_orphan_2_no_fee.vout.append(CTxOut(nValue=8 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))
|
||||
|
||||
# A valid transaction with sufficient fee
|
||||
tx_orphan_2_valid = CTransaction()
|
||||
tx_orphan_2_valid.vin.append(CTxIn(outpoint=COutPoint(tx_orphan_1.sha256, 1)))
|
||||
tx_orphan_2_valid.vin.append(CTxIn(outpoint=COutPoint(tx_orphan_1.txid_int, 1)))
|
||||
tx_orphan_2_valid.vout.append(CTxOut(nValue=8 * COIN - 12000, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))
|
||||
|
||||
# An invalid transaction with negative fee
|
||||
tx_orphan_2_invalid = CTransaction()
|
||||
tx_orphan_2_invalid.vin.append(CTxIn(outpoint=COutPoint(tx_orphan_1.sha256, 2)))
|
||||
tx_orphan_2_invalid.vin.append(CTxIn(outpoint=COutPoint(tx_orphan_1.txid_int, 2)))
|
||||
tx_orphan_2_invalid.vout.append(CTxOut(nValue=11 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))
|
||||
|
||||
self.log.info('Send the orphans ... ')
|
||||
@ -154,7 +154,7 @@ class InvalidTxRequestTest(BitcoinTestFramework):
|
||||
|
||||
self.log.info('Test orphan with rejected parents')
|
||||
rejected_parent = CTransaction()
|
||||
rejected_parent.vin.append(CTxIn(outpoint=COutPoint(tx_orphan_2_invalid.sha256, 0)))
|
||||
rejected_parent.vin.append(CTxIn(outpoint=COutPoint(tx_orphan_2_invalid.txid_int, 0)))
|
||||
rejected_parent.vout.append(CTxOut(nValue=11 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))
|
||||
with node.assert_debug_log(['not keeping orphan with rejected parents {}'.format(rejected_parent.txid_hex)]):
|
||||
node.p2ps[0].send_txs_and_test([rejected_parent], node, success=False)
|
||||
@ -165,11 +165,11 @@ class InvalidTxRequestTest(BitcoinTestFramework):
|
||||
|
||||
self.log.info('Test that a transaction in the orphan pool is included in a new tip block causes erase this transaction from the orphan pool')
|
||||
tx_withhold_until_block_A = CTransaction()
|
||||
tx_withhold_until_block_A.vin.append(CTxIn(outpoint=COutPoint(tx_withhold.sha256, 1)))
|
||||
tx_withhold_until_block_A.vin.append(CTxIn(outpoint=COutPoint(tx_withhold.txid_int, 1)))
|
||||
tx_withhold_until_block_A.vout = [CTxOut(nValue=12 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE)] * 2
|
||||
|
||||
tx_orphan_include_by_block_A = CTransaction()
|
||||
tx_orphan_include_by_block_A.vin.append(CTxIn(outpoint=COutPoint(tx_withhold_until_block_A.sha256, 0)))
|
||||
tx_orphan_include_by_block_A.vin.append(CTxIn(outpoint=COutPoint(tx_withhold_until_block_A.txid_int, 0)))
|
||||
tx_orphan_include_by_block_A.vout.append(CTxOut(nValue=12 * COIN - 12000, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))
|
||||
|
||||
self.log.info('Send the orphan ... ')
|
||||
@ -188,15 +188,15 @@ class InvalidTxRequestTest(BitcoinTestFramework):
|
||||
|
||||
self.log.info('Test that a transaction in the orphan pool conflicts with a new tip block causes erase this transaction from the orphan pool')
|
||||
tx_withhold_until_block_B = CTransaction()
|
||||
tx_withhold_until_block_B.vin.append(CTxIn(outpoint=COutPoint(tx_withhold_until_block_A.sha256, 1)))
|
||||
tx_withhold_until_block_B.vin.append(CTxIn(outpoint=COutPoint(tx_withhold_until_block_A.txid_int, 1)))
|
||||
tx_withhold_until_block_B.vout.append(CTxOut(nValue=11 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))
|
||||
|
||||
tx_orphan_include_by_block_B = CTransaction()
|
||||
tx_orphan_include_by_block_B.vin.append(CTxIn(outpoint=COutPoint(tx_withhold_until_block_B.sha256, 0)))
|
||||
tx_orphan_include_by_block_B.vin.append(CTxIn(outpoint=COutPoint(tx_withhold_until_block_B.txid_int, 0)))
|
||||
tx_orphan_include_by_block_B.vout.append(CTxOut(nValue=10 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))
|
||||
|
||||
tx_orphan_conflict_by_block_B = CTransaction()
|
||||
tx_orphan_conflict_by_block_B.vin.append(CTxIn(outpoint=COutPoint(tx_withhold_until_block_B.sha256, 0)))
|
||||
tx_orphan_conflict_by_block_B.vin.append(CTxIn(outpoint=COutPoint(tx_withhold_until_block_B.txid_int, 0)))
|
||||
tx_orphan_conflict_by_block_B.vout.append(CTxOut(nValue=9 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))
|
||||
self.log.info('Send the orphan ... ')
|
||||
node.p2ps[0].send_txs_and_test([tx_orphan_conflict_by_block_B], node, success=False)
|
||||
|
||||
@ -177,13 +177,13 @@ class TestP2PConn(P2PInterface):
|
||||
wtxid = tx.wtxid_int
|
||||
self.send_without_ping(msg_inv(inv=[CInv(MSG_WTX, wtxid)]))
|
||||
else:
|
||||
self.send_without_ping(msg_inv(inv=[CInv(MSG_TX, tx.sha256)]))
|
||||
self.send_without_ping(msg_inv(inv=[CInv(MSG_TX, tx.txid_int)]))
|
||||
|
||||
if success:
|
||||
if use_wtxid:
|
||||
self.wait_for_getdata([wtxid])
|
||||
else:
|
||||
self.wait_for_getdata([tx.sha256])
|
||||
self.wait_for_getdata([tx.txid_int])
|
||||
else:
|
||||
ensure_for(duration=5, f=lambda: not self.last_message.get("getdata"))
|
||||
|
||||
@ -305,7 +305,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
block = self.build_next_block()
|
||||
block.solve()
|
||||
self.test_node.send_and_ping(msg_no_witness_block(block)) # make sure the block was processed
|
||||
txid = block.vtx[0].sha256
|
||||
txid = block.vtx[0].txid_int
|
||||
|
||||
self.generate(self.wallet, 99) # let the block mature
|
||||
|
||||
@ -321,7 +321,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
self.test_node.send_and_ping(msg_tx(tx)) # make sure the block was processed
|
||||
assert tx.txid_hex in self.nodes[0].getrawmempool()
|
||||
# Save this transaction for later
|
||||
self.utxo.append(UTXO(tx.sha256, 0, 49 * 100000000))
|
||||
self.utxo.append(UTXO(tx.txid_int, 0, 49 * 100000000))
|
||||
self.generate(self.nodes[0], 1)
|
||||
|
||||
@subtest
|
||||
@ -352,7 +352,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
|
||||
# Update our utxo list; we spent the first entry.
|
||||
self.utxo.pop(0)
|
||||
self.utxo.append(UTXO(tx.sha256, 0, tx.vout[0].nValue))
|
||||
self.utxo.append(UTXO(tx.txid_int, 0, tx.vout[0].nValue))
|
||||
|
||||
@subtest
|
||||
def test_block_relay(self):
|
||||
@ -470,7 +470,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx.vin = [CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b'')]
|
||||
tx.vout = [CTxOut(value, script_pubkey), CTxOut(value, p2sh_script_pubkey)]
|
||||
tx.vout.append(CTxOut(value, CScript([OP_TRUE])))
|
||||
txid = tx.sha256
|
||||
txid = tx.txid_int
|
||||
|
||||
# Add it to a block
|
||||
block = self.build_next_block()
|
||||
@ -524,7 +524,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx.wit.vtxinwit.append(CTxInWitness())
|
||||
tx.wit.vtxinwit[0].scriptWitness.stack = [b'a']
|
||||
|
||||
tx_hash = tx.sha256
|
||||
tx_hash = tx.txid_int
|
||||
tx_value = tx.vout[0].nValue
|
||||
|
||||
# Verify that if a peer doesn't set nServices to include NODE_WITNESS,
|
||||
@ -576,7 +576,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
# Now test standardness of v0 P2WSH outputs.
|
||||
# Start by creating a transaction with two outputs.
|
||||
tx = CTransaction()
|
||||
tx.vin = [CTxIn(COutPoint(p2sh_tx.sha256, 0), CScript([witness_script]))]
|
||||
tx.vin = [CTxIn(COutPoint(p2sh_tx.txid_int, 0), CScript([witness_script]))]
|
||||
tx.vout = [CTxOut(p2sh_tx.vout[0].nValue - 10000, script_pubkey)]
|
||||
tx.vout.append(CTxOut(8000, script_pubkey)) # Might burn this later
|
||||
tx.vin[0].nSequence = MAX_BIP125_RBF_SEQUENCE # Just to have the option to bump this tx from the mempool
|
||||
@ -590,7 +590,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
script_pubkey = CScript([OP_0, hash160(witness_hash)])
|
||||
tx2 = CTransaction()
|
||||
# tx was accepted, so we spend the second output.
|
||||
tx2.vin = [CTxIn(COutPoint(tx.sha256, 1), b"")]
|
||||
tx2.vin = [CTxIn(COutPoint(tx.txid_int, 1), b"")]
|
||||
tx2.vout = [CTxOut(7000, script_pubkey)]
|
||||
tx2.wit.vtxinwit.append(CTxInWitness())
|
||||
tx2.wit.vtxinwit[0].scriptWitness.stack = [witness_script]
|
||||
@ -602,7 +602,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
# tx and tx2 were both accepted. Don't bother trying to reclaim the
|
||||
# P2PKH output; just send tx's first output back to an anyone-can-spend.
|
||||
self.sync_mempools([self.nodes[0], self.nodes[1]])
|
||||
tx3.vin = [CTxIn(COutPoint(tx.sha256, 0), b"")]
|
||||
tx3.vin = [CTxIn(COutPoint(tx.txid_int, 0), b"")]
|
||||
tx3.vout = [CTxOut(tx.vout[0].nValue - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE]))]
|
||||
tx3.wit.vtxinwit.append(CTxInWitness())
|
||||
tx3.wit.vtxinwit[0].scriptWitness.stack = [witness_script]
|
||||
@ -645,7 +645,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
|
||||
self.generate(self.nodes[0], 1)
|
||||
self.utxo.pop(0)
|
||||
self.utxo.append(UTXO(tx3.sha256, 0, tx3.vout[0].nValue))
|
||||
self.utxo.append(UTXO(tx3.txid_int, 0, tx3.vout[0].nValue))
|
||||
assert_equal(len(self.nodes[1].getrawmempool()), 0)
|
||||
|
||||
@subtest
|
||||
@ -683,7 +683,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
|
||||
# Now test attempts to spend the output.
|
||||
spend_tx = CTransaction()
|
||||
spend_tx.vin.append(CTxIn(COutPoint(tx.sha256, 0), script_sig))
|
||||
spend_tx.vin.append(CTxIn(COutPoint(tx.txid_int, 0), script_sig))
|
||||
spend_tx.vout.append(CTxOut(tx.vout[0].nValue - 1000, CScript([OP_TRUE])))
|
||||
|
||||
# This transaction should not be accepted into the mempool pre- or
|
||||
@ -720,7 +720,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
|
||||
# Update self.utxo
|
||||
self.utxo.pop(0)
|
||||
self.utxo.append(UTXO(spend_tx.sha256, 0, spend_tx.vout[0].nValue))
|
||||
self.utxo.append(UTXO(spend_tx.txid_int, 0, spend_tx.vout[0].nValue))
|
||||
|
||||
@subtest
|
||||
def test_witness_commitments(self):
|
||||
@ -761,7 +761,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
|
||||
# tx2 will spend tx1, and send back to a regular anyone-can-spend address
|
||||
tx2 = CTransaction()
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), b""))
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.txid_int, 0), b""))
|
||||
tx2.vout.append(CTxOut(tx.vout[0].nValue - 1000, witness_script))
|
||||
tx2.wit.vtxinwit.append(CTxInWitness())
|
||||
tx2.wit.vtxinwit[0].scriptWitness.stack = [witness_script]
|
||||
@ -793,7 +793,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
# omit the commitment.
|
||||
block_4 = self.build_next_block()
|
||||
tx3 = CTransaction()
|
||||
tx3.vin.append(CTxIn(COutPoint(tx2.sha256, 0), b""))
|
||||
tx3.vin.append(CTxIn(COutPoint(tx2.txid_int, 0), b""))
|
||||
tx3.vout.append(CTxOut(tx.vout[0].nValue - 1000, witness_script))
|
||||
block_4.vtx.append(tx3)
|
||||
block_4.hashMerkleRoot = block_4.calc_merkle_root()
|
||||
@ -802,7 +802,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
|
||||
# Update available utxo's for use in later test.
|
||||
self.utxo.pop(0)
|
||||
self.utxo.append(UTXO(tx3.sha256, 0, tx3.vout[0].nValue))
|
||||
self.utxo.append(UTXO(tx3.txid_int, 0, tx3.vout[0].nValue))
|
||||
|
||||
@subtest
|
||||
def test_block_malleability(self):
|
||||
@ -877,7 +877,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
|
||||
child_tx = CTransaction()
|
||||
for i in range(NUM_OUTPUTS):
|
||||
child_tx.vin.append(CTxIn(COutPoint(parent_tx.sha256, i), b""))
|
||||
child_tx.vin.append(CTxIn(COutPoint(parent_tx.txid_int, i), b""))
|
||||
child_tx.vout = [CTxOut(value - 100000, CScript([OP_TRUE]))]
|
||||
for _ in range(NUM_OUTPUTS):
|
||||
child_tx.wit.vtxinwit.append(CTxInWitness())
|
||||
@ -915,7 +915,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
|
||||
# Update available utxo's
|
||||
self.utxo.pop(0)
|
||||
self.utxo.append(UTXO(block.vtx[-1].sha256, 0, block.vtx[-1].vout[0].nValue))
|
||||
self.utxo.append(UTXO(block.vtx[-1].txid_int, 0, block.vtx[-1].vout[0].nValue))
|
||||
|
||||
@subtest
|
||||
def test_submit_block(self):
|
||||
@ -986,8 +986,8 @@ class SegWitTest(BitcoinTestFramework):
|
||||
# Now try extra witness/signature data on an input that DOES require a
|
||||
# witness
|
||||
tx2 = CTransaction()
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), b"")) # witness output
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.sha256, 1), b"")) # non-witness
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.txid_int, 0), b"")) # witness output
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.txid_int, 1), b"")) # non-witness
|
||||
tx2.vout.append(CTxOut(tx.vout[0].nValue, CScript([OP_TRUE])))
|
||||
tx2.wit.vtxinwit.extend([CTxInWitness(), CTxInWitness()])
|
||||
tx2.wit.vtxinwit[0].scriptWitness.stack = [CScript([CScriptNum(1)]), CScript([CScriptNum(1)]), witness_script]
|
||||
@ -1022,7 +1022,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
|
||||
# Update utxo for later tests
|
||||
self.utxo.pop(0)
|
||||
self.utxo.append(UTXO(tx2.sha256, 0, tx2.vout[0].nValue))
|
||||
self.utxo.append(UTXO(tx2.txid_int, 0, tx2.vout[0].nValue))
|
||||
|
||||
@subtest
|
||||
def test_max_witness_push_length(self):
|
||||
@ -1038,7 +1038,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx.vout.append(CTxOut(self.utxo[0].nValue - 1000, script_pubkey))
|
||||
|
||||
tx2 = CTransaction()
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), b""))
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.txid_int, 0), b""))
|
||||
tx2.vout.append(CTxOut(tx.vout[0].nValue - 1000, CScript([OP_TRUE])))
|
||||
tx2.wit.vtxinwit.append(CTxInWitness())
|
||||
# First try a 521-byte stack element
|
||||
@ -1057,7 +1057,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
|
||||
# Update the utxo for later tests
|
||||
self.utxo.pop()
|
||||
self.utxo.append(UTXO(tx2.sha256, 0, tx2.vout[0].nValue))
|
||||
self.utxo.append(UTXO(tx2.txid_int, 0, tx2.vout[0].nValue))
|
||||
|
||||
@subtest
|
||||
def test_max_witness_script_length(self):
|
||||
@ -1077,7 +1077,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx.vout.append(CTxOut(self.utxo[0].nValue - 1000, long_script_pubkey))
|
||||
|
||||
tx2 = CTransaction()
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), b""))
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.txid_int, 0), b""))
|
||||
tx2.vout.append(CTxOut(tx.vout[0].nValue - 1000, CScript([OP_TRUE])))
|
||||
tx2.wit.vtxinwit.append(CTxInWitness())
|
||||
tx2.wit.vtxinwit[0].scriptWitness.stack = [b'a'] * 44 + [long_witness_script]
|
||||
@ -1093,14 +1093,14 @@ class SegWitTest(BitcoinTestFramework):
|
||||
script_pubkey = script_to_p2wsh_script(witness_script)
|
||||
|
||||
tx.vout[0] = CTxOut(tx.vout[0].nValue, script_pubkey)
|
||||
tx2.vin[0].prevout.hash = tx.sha256
|
||||
tx2.vin[0].prevout.hash = tx.txid_int
|
||||
tx2.wit.vtxinwit[0].scriptWitness.stack = [b'a'] * 43 + [witness_script]
|
||||
block.vtx = [block.vtx[0]]
|
||||
self.update_witness_block_with_transactions(block, [tx, tx2])
|
||||
test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
|
||||
|
||||
self.utxo.pop()
|
||||
self.utxo.append(UTXO(tx2.sha256, 0, tx2.vout[0].nValue))
|
||||
self.utxo.append(UTXO(tx2.txid_int, 0, tx2.vout[0].nValue))
|
||||
|
||||
@subtest
|
||||
def test_witness_input_length(self):
|
||||
@ -1145,7 +1145,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
|
||||
tx2 = BrokenCTransaction()
|
||||
for i in range(10):
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.sha256, i), b""))
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.txid_int, i), b""))
|
||||
tx2.vout.append(CTxOut(value - 3000, CScript([OP_TRUE])))
|
||||
|
||||
# First try using a too long vtxinwit
|
||||
@ -1184,7 +1184,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
|
||||
|
||||
self.utxo.pop()
|
||||
self.utxo.append(UTXO(tx2.sha256, 0, tx2.vout[0].nValue))
|
||||
self.utxo.append(UTXO(tx2.txid_int, 0, tx2.vout[0].nValue))
|
||||
|
||||
@subtest
|
||||
def test_tx_relay_after_segwit_activation(self):
|
||||
@ -1204,7 +1204,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx.wit.vtxinwit.append(CTxInWitness())
|
||||
tx.wit.vtxinwit[0].scriptWitness.stack = [b'a']
|
||||
|
||||
tx_hash = tx.sha256
|
||||
tx_hash = tx.txid_int
|
||||
|
||||
# Verify that unnecessary witnesses are rejected.
|
||||
self.test_node.announce_tx_and_wait_for_getdata(tx)
|
||||
@ -1222,7 +1222,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx2.vout.append(CTxOut(tx.vout[0].nValue - 1000, script_pubkey))
|
||||
|
||||
tx3 = CTransaction()
|
||||
tx3.vin.append(CTxIn(COutPoint(tx2.sha256, 0), b""))
|
||||
tx3.vin.append(CTxIn(COutPoint(tx2.txid_int, 0), b""))
|
||||
tx3.wit.vtxinwit.append(CTxInWitness())
|
||||
|
||||
# Add too-large for IsStandard witness and check that it does not enter reject filter
|
||||
@ -1251,9 +1251,9 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx3.wit.vtxinwit[0].scriptWitness.stack = [witness_script]
|
||||
# Also check that old_node gets a tx announcement, even though this is
|
||||
# a witness transaction.
|
||||
self.old_node.wait_for_inv([CInv(MSG_TX, tx2.sha256)]) # wait until tx2 was inv'ed
|
||||
self.old_node.wait_for_inv([CInv(MSG_TX, tx2.txid_int)]) # wait until tx2 was inv'ed
|
||||
test_transaction_acceptance(self.nodes[0], self.test_node, tx3, with_witness=True, accepted=True)
|
||||
self.old_node.wait_for_inv([CInv(MSG_TX, tx3.sha256)])
|
||||
self.old_node.wait_for_inv([CInv(MSG_TX, tx3.txid_int)])
|
||||
|
||||
# Test that getrawtransaction returns correct witness information
|
||||
# hash, size, vsize
|
||||
@ -1272,7 +1272,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
assert_equal(len(self.nodes[0].getrawmempool()), 0)
|
||||
|
||||
self.utxo.pop(0)
|
||||
self.utxo.append(UTXO(tx3.sha256, 0, tx3.vout[0].nValue))
|
||||
self.utxo.append(UTXO(tx3.txid_int, 0, tx3.vout[0].nValue))
|
||||
|
||||
@subtest
|
||||
def test_segwit_versions(self):
|
||||
@ -1294,7 +1294,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
|
||||
self.utxo.pop(0)
|
||||
for i in range(NUM_SEGWIT_VERSIONS):
|
||||
self.utxo.append(UTXO(tx.sha256, i, split_value))
|
||||
self.utxo.append(UTXO(tx.txid_int, i, split_value))
|
||||
|
||||
self.sync_blocks()
|
||||
temp_utxo = []
|
||||
@ -1314,7 +1314,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
test_transaction_acceptance(self.nodes[1], self.std_node, tx, with_witness=True, accepted=False)
|
||||
test_transaction_acceptance(self.nodes[0], self.test_node, tx, with_witness=True, accepted=True)
|
||||
self.utxo.pop(0)
|
||||
temp_utxo.append(UTXO(tx.sha256, 0, tx.vout[0].nValue))
|
||||
temp_utxo.append(UTXO(tx.txid_int, 0, tx.vout[0].nValue))
|
||||
|
||||
self.generate(self.nodes[0], 1) # Mine all the transactions
|
||||
assert len(self.nodes[0].getrawmempool()) == 0
|
||||
@ -1323,7 +1323,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
# are standard
|
||||
script_pubkey = CScript([CScriptOp(OP_2), witness_hash])
|
||||
tx2 = CTransaction()
|
||||
tx2.vin = [CTxIn(COutPoint(tx.sha256, 0), b"")]
|
||||
tx2.vin = [CTxIn(COutPoint(tx.txid_int, 0), b"")]
|
||||
tx2.vout = [CTxOut(tx.vout[0].nValue - 1000, script_pubkey)]
|
||||
tx2.wit.vtxinwit.append(CTxInWitness())
|
||||
tx2.wit.vtxinwit[0].scriptWitness.stack = [witness_script]
|
||||
@ -1331,7 +1331,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
test_transaction_acceptance(self.nodes[0], self.test_node, tx2, with_witness=True, accepted=True)
|
||||
test_transaction_acceptance(self.nodes[1], self.std_node, tx2, with_witness=True, accepted=True)
|
||||
temp_utxo.pop() # last entry in temp_utxo was the output we just spent
|
||||
temp_utxo.append(UTXO(tx2.sha256, 0, tx2.vout[0].nValue))
|
||||
temp_utxo.append(UTXO(tx2.txid_int, 0, tx2.vout[0].nValue))
|
||||
|
||||
# Spend everything in temp_utxo into an segwit v1 output.
|
||||
tx3 = CTransaction()
|
||||
@ -1361,7 +1361,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
self.sync_blocks()
|
||||
|
||||
# Add utxo to our list
|
||||
self.utxo.append(UTXO(tx3.sha256, 0, tx3.vout[0].nValue))
|
||||
self.utxo.append(UTXO(tx3.txid_int, 0, tx3.vout[0].nValue))
|
||||
|
||||
@subtest
|
||||
def test_premature_coinbase_witness_spend(self):
|
||||
@ -1377,7 +1377,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
|
||||
|
||||
spend_tx = CTransaction()
|
||||
spend_tx.vin = [CTxIn(COutPoint(block.vtx[0].sha256, 0), b"")]
|
||||
spend_tx.vin = [CTxIn(COutPoint(block.vtx[0].txid_int, 0), b"")]
|
||||
spend_tx.vout = [CTxOut(block.vtx[0].vout[0].nValue, witness_script)]
|
||||
spend_tx.wit.vtxinwit.append(CTxInWitness())
|
||||
spend_tx.wit.vtxinwit[0].scriptWitness.stack = [witness_script]
|
||||
@ -1428,7 +1428,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
script_wsh = script_to_p2wsh_script(witness_script)
|
||||
|
||||
tx2 = CTransaction()
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), b""))
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.txid_int, 0), b""))
|
||||
tx2.vout.append(CTxOut(tx.vout[0].nValue - 1000, script_wsh))
|
||||
script = keyhash_to_p2pkh_script(pubkeyhash)
|
||||
tx2.wit.vtxinwit.append(CTxInWitness())
|
||||
@ -1449,7 +1449,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
script_sig = CScript([script_wsh])
|
||||
|
||||
tx3 = CTransaction()
|
||||
tx3.vin.append(CTxIn(COutPoint(tx2.sha256, 0), b""))
|
||||
tx3.vin.append(CTxIn(COutPoint(tx2.txid_int, 0), b""))
|
||||
tx3.vout.append(CTxOut(tx2.vout[0].nValue - 1000, script_p2sh))
|
||||
tx3.wit.vtxinwit.append(CTxInWitness())
|
||||
sign_p2pk_witness_input(witness_script, tx3, 0, SIGHASH_ALL, tx2.vout[0].nValue, key)
|
||||
@ -1466,7 +1466,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
# Send it to a P2PKH output, which we'll use in the next test.
|
||||
script_pubkey = keyhash_to_p2pkh_script(pubkeyhash)
|
||||
tx4 = CTransaction()
|
||||
tx4.vin.append(CTxIn(COutPoint(tx3.sha256, 0), script_sig))
|
||||
tx4.vin.append(CTxIn(COutPoint(tx3.txid_int, 0), script_sig))
|
||||
tx4.vout.append(CTxOut(tx3.vout[0].nValue - 1000, script_pubkey))
|
||||
tx4.wit.vtxinwit.append(CTxInWitness())
|
||||
sign_p2pk_witness_input(witness_script, tx4, 0, SIGHASH_ALL, tx3.vout[0].nValue, key)
|
||||
@ -1480,7 +1480,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
# Test 4: Uncompressed pubkeys should still be valid in non-segwit
|
||||
# transactions.
|
||||
tx5 = CTransaction()
|
||||
tx5.vin.append(CTxIn(COutPoint(tx4.sha256, 0), b""))
|
||||
tx5.vin.append(CTxIn(COutPoint(tx4.txid_int, 0), b""))
|
||||
tx5.vout.append(CTxOut(tx4.vout[0].nValue - 1000, CScript([OP_TRUE])))
|
||||
tx5.vin[0].scriptSig = CScript([pubkey])
|
||||
sign_input_legacy(tx5, 0, script_pubkey, key)
|
||||
@ -1489,7 +1489,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
block = self.build_next_block()
|
||||
self.update_witness_block_with_transactions(block, [tx5])
|
||||
test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
|
||||
self.utxo.append(UTXO(tx5.sha256, 0, tx5.vout[0].nValue))
|
||||
self.utxo.append(UTXO(tx5.txid_int, 0, tx5.vout[0].nValue))
|
||||
|
||||
@subtest
|
||||
def test_signature_version_1(self):
|
||||
@ -1511,7 +1511,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
self.utxo.pop(0)
|
||||
|
||||
# Test each hashtype
|
||||
prev_utxo = UTXO(tx.sha256, 0, tx.vout[0].nValue)
|
||||
prev_utxo = UTXO(tx.txid_int, 0, tx.vout[0].nValue)
|
||||
for sigflag in [0, SIGHASH_ANYONECANPAY]:
|
||||
for hashtype in [SIGHASH_ALL, SIGHASH_NONE, SIGHASH_SINGLE]:
|
||||
hashtype |= sigflag
|
||||
@ -1541,7 +1541,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
self.update_witness_block_with_transactions(block, [tx])
|
||||
test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
|
||||
|
||||
prev_utxo = UTXO(tx.sha256, 0, tx.vout[0].nValue)
|
||||
prev_utxo = UTXO(tx.txid_int, 0, tx.vout[0].nValue)
|
||||
|
||||
# Test combinations of signature hashes.
|
||||
# Split the utxo into a lot of outputs.
|
||||
@ -1559,7 +1559,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx.wit.vtxinwit.append(CTxInWitness())
|
||||
sign_p2pk_witness_input(witness_script, tx, 0, SIGHASH_ALL, prev_utxo.nValue, key)
|
||||
for i in range(NUM_SIGHASH_TESTS):
|
||||
temp_utxos.append(UTXO(tx.sha256, i, split_value))
|
||||
temp_utxos.append(UTXO(tx.txid_int, i, split_value))
|
||||
|
||||
block = self.build_next_block()
|
||||
self.update_witness_block_with_transactions(block, [tx])
|
||||
@ -1596,7 +1596,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
if (hashtype == SIGHASH_SINGLE and i >= num_outputs):
|
||||
used_sighash_single_out_of_bounds = True
|
||||
for i in range(num_outputs):
|
||||
temp_utxos.append(UTXO(tx.sha256, i, split_value))
|
||||
temp_utxos.append(UTXO(tx.txid_int, i, split_value))
|
||||
temp_utxos = temp_utxos[num_inputs:]
|
||||
|
||||
block.vtx.append(tx)
|
||||
@ -1623,7 +1623,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx.wit.vtxinwit.append(CTxInWitness())
|
||||
sign_p2pk_witness_input(witness_script, tx, 0, SIGHASH_ALL, temp_utxos[0].nValue, key)
|
||||
tx2 = CTransaction()
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), b""))
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.txid_int, 0), b""))
|
||||
tx2.vout.append(CTxOut(tx.vout[0].nValue, CScript([OP_TRUE])))
|
||||
|
||||
script = keyhash_to_p2pkh_script(pubkeyhash)
|
||||
@ -1669,7 +1669,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
|
||||
|
||||
for i in range(len(tx.vout)):
|
||||
self.utxo.append(UTXO(tx.sha256, i, tx.vout[i].nValue))
|
||||
self.utxo.append(UTXO(tx.txid_int, i, tx.vout[i].nValue))
|
||||
|
||||
@subtest
|
||||
def test_non_standard_witness_blinding(self):
|
||||
@ -1695,7 +1695,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
# rejected for having a witness shouldn't be added
|
||||
# to the rejection cache.
|
||||
tx2 = CTransaction()
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), CScript([p2sh_program])))
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.txid_int, 0), CScript([p2sh_program])))
|
||||
tx2.vout.append(CTxOut(tx.vout[0].nValue - 1000, script_pubkey))
|
||||
tx2.wit.vtxinwit.append(CTxInWitness())
|
||||
tx2.wit.vtxinwit[0].scriptWitness.stack = [b'a' * 400]
|
||||
@ -1708,7 +1708,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
|
||||
# Now create a new anyone-can-spend utxo for the next test.
|
||||
tx3 = CTransaction()
|
||||
tx3.vin.append(CTxIn(COutPoint(tx2.sha256, 0), CScript([p2sh_program])))
|
||||
tx3.vin.append(CTxIn(COutPoint(tx2.txid_int, 0), CScript([p2sh_program])))
|
||||
tx3.vout.append(CTxOut(tx2.vout[0].nValue - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
|
||||
test_transaction_acceptance(self.nodes[0], self.test_node, tx2, False, True)
|
||||
test_transaction_acceptance(self.nodes[0], self.test_node, tx3, False, True)
|
||||
@ -1717,7 +1717,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
|
||||
# Update our utxo list; we spent the first entry.
|
||||
self.utxo.pop(0)
|
||||
self.utxo.append(UTXO(tx3.sha256, 0, tx3.vout[0].nValue))
|
||||
self.utxo.append(UTXO(tx3.txid_int, 0, tx3.vout[0].nValue))
|
||||
|
||||
@subtest
|
||||
def test_non_standard_witness(self):
|
||||
@ -1743,7 +1743,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
p2wsh_scripts.append(p2wsh)
|
||||
tx.vout.append(CTxOut(outputvalue, p2wsh))
|
||||
tx.vout.append(CTxOut(outputvalue, script_to_p2sh_script(p2wsh)))
|
||||
txid = tx.sha256
|
||||
txid = tx.txid_int
|
||||
test_transaction_acceptance(self.nodes[0], self.test_node, tx, with_witness=False, accepted=True)
|
||||
|
||||
self.generate(self.nodes[0], 1)
|
||||
@ -1861,7 +1861,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
# too many sigops.
|
||||
total_value = 0
|
||||
for i in range(outputs - 1):
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.sha256, i), b""))
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.txid_int, i), b""))
|
||||
tx2.wit.vtxinwit.append(CTxInWitness())
|
||||
tx2.wit.vtxinwit[-1].scriptWitness.stack = [witness_script]
|
||||
total_value += tx.vout[i].nValue
|
||||
@ -1899,7 +1899,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
# output of tx
|
||||
block_5 = self.build_next_block()
|
||||
tx2.vout.pop()
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.sha256, outputs - 1), b""))
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.txid_int, outputs - 1), b""))
|
||||
tx2.wit.vtxinwit.append(CTxInWitness())
|
||||
tx2.wit.vtxinwit[-1].scriptWitness.stack = [witness_script_justright]
|
||||
self.update_witness_block_with_transactions(block_5, [tx2])
|
||||
@ -1909,7 +1909,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
|
||||
# Cleanup and prep for next test
|
||||
self.utxo.pop(0)
|
||||
self.utxo.append(UTXO(tx2.sha256, 0, tx2.vout[0].nValue))
|
||||
self.utxo.append(UTXO(tx2.txid_int, 0, tx2.vout[0].nValue))
|
||||
|
||||
@subtest
|
||||
def test_superfluous_witness(self):
|
||||
@ -1969,7 +1969,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
|
||||
# Create a Segwit transaction
|
||||
tx2 = CTransaction()
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), b""))
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.txid_int, 0), b""))
|
||||
tx2.vout.append(CTxOut(tx.vout[0].nValue - 1000, script_pubkey))
|
||||
tx2.wit.vtxinwit.append(CTxInWitness())
|
||||
tx2.wit.vtxinwit[0].scriptWitness.stack = [witness_script]
|
||||
@ -1986,7 +1986,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
self.tx_node.announce_tx_and_wait_for_getdata(tx2, use_wtxid=False)
|
||||
with p2p_lock:
|
||||
lgd = self.tx_node.lastgetdata[:]
|
||||
assert_equal(lgd, [CInv(MSG_TX|MSG_WITNESS_FLAG, tx2.sha256)])
|
||||
assert_equal(lgd, [CInv(MSG_TX|MSG_WITNESS_FLAG, tx2.txid_int)])
|
||||
|
||||
# Send tx2 through; it's an orphan so won't be accepted
|
||||
with p2p_lock:
|
||||
@ -1997,10 +1997,10 @@ class SegWitTest(BitcoinTestFramework):
|
||||
self.tx_node.peer_disconnect()
|
||||
|
||||
# Expect a request for parent (tx) by txid despite use of WTX peer
|
||||
self.wtx_node.wait_for_getdata([tx.sha256], timeout=60)
|
||||
self.wtx_node.wait_for_getdata([tx.txid_int], timeout=60)
|
||||
with p2p_lock:
|
||||
lgd = self.wtx_node.lastgetdata[:]
|
||||
assert_equal(lgd, [CInv(MSG_WITNESS_TX, tx.sha256)])
|
||||
assert_equal(lgd, [CInv(MSG_WITNESS_TX, tx.txid_int)])
|
||||
|
||||
# Send tx through
|
||||
test_transaction_acceptance(self.nodes[0], self.wtx_node, tx, with_witness=False, accepted=True)
|
||||
|
||||
@ -187,7 +187,7 @@ def create_tx_with_script(prevtx, n, script_sig=b"", *, amount, output_script=No
|
||||
output_script = CScript()
|
||||
tx = CTransaction()
|
||||
assert n < len(prevtx.vout)
|
||||
tx.vin.append(CTxIn(COutPoint(prevtx.sha256, n), script_sig, SEQUENCE_FINAL))
|
||||
tx.vin.append(CTxIn(COutPoint(prevtx.txid_int, n), script_sig, SEQUENCE_FINAL))
|
||||
tx.vout.append(CTxOut(amount, output_script))
|
||||
return tx
|
||||
|
||||
|
||||
@ -672,7 +672,7 @@ class CTransaction:
|
||||
return hash256(self.serialize_without_witness())[::-1].hex()
|
||||
|
||||
@property
|
||||
def sha256(self):
|
||||
def txid_int(self):
|
||||
"""Return txid (transaction hash without witness) as integer."""
|
||||
return uint256_from_str(hash256(self.serialize_without_witness()))
|
||||
|
||||
@ -804,7 +804,7 @@ class CBlock(CBlockHeader):
|
||||
def calc_merkle_root(self):
|
||||
hashes = []
|
||||
for tx in self.vtx:
|
||||
hashes.append(ser_uint256(tx.sha256))
|
||||
hashes.append(ser_uint256(tx.txid_int))
|
||||
return self.get_merkle_root(hashes)
|
||||
|
||||
def calc_witness_merkle_root(self):
|
||||
@ -996,7 +996,7 @@ class HeaderAndShortIDs:
|
||||
[k0, k1] = self.get_siphash_keys()
|
||||
for i in range(len(block.vtx)):
|
||||
if i not in prefill_list:
|
||||
tx_hash = block.vtx[i].sha256
|
||||
tx_hash = block.vtx[i].txid_int
|
||||
if use_witness:
|
||||
tx_hash = block.vtx[i].wtxid_int
|
||||
self.shortids.append(calculate_shortid(k0, k1, tx_hash))
|
||||
|
||||
@ -911,7 +911,7 @@ class P2PDataStore(P2PInterface):
|
||||
|
||||
with p2p_lock:
|
||||
for tx in txs:
|
||||
self.tx_store[tx.sha256] = tx
|
||||
self.tx_store[tx.txid_int] = tx
|
||||
|
||||
reject_reason = [reject_reason] if reject_reason else []
|
||||
with node.assert_debug_log(expected_msgs=reject_reason):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user