mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-15 16:38:23 +01:00
test: remove bare CTransaction .rehash()/.calc_sha256() calls
Since the previous commit, CTransaction object calls to the methods `.rehash()` and `.calc_sha256()` are effectively no-ops if the returned value is not used, so we can just remove them.
This commit is contained in:
@@ -313,7 +313,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx = CTransaction()
|
||||
tx.vin.append(CTxIn(COutPoint(txid, 0), b""))
|
||||
tx.vout.append(CTxOut(49 * 100000000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
|
||||
tx.calc_sha256()
|
||||
|
||||
# Check that serializing it with or without witness is the same
|
||||
# This is a sanity check of our testing framework.
|
||||
@@ -471,7 +470,6 @@ 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])))
|
||||
tx.rehash()
|
||||
txid = tx.sha256
|
||||
|
||||
# Add it to a block
|
||||
@@ -489,14 +487,12 @@ class SegWitTest(BitcoinTestFramework):
|
||||
p2wsh_tx.vout = [CTxOut(value, CScript([OP_TRUE]))]
|
||||
p2wsh_tx.wit.vtxinwit.append(CTxInWitness())
|
||||
p2wsh_tx.wit.vtxinwit[0].scriptWitness.stack = [CScript([OP_TRUE])]
|
||||
p2wsh_tx.rehash()
|
||||
|
||||
p2sh_p2wsh_tx = CTransaction()
|
||||
p2sh_p2wsh_tx.vin = [CTxIn(COutPoint(txid, 1), CScript([script_pubkey]))]
|
||||
p2sh_p2wsh_tx.vout = [CTxOut(value, CScript([OP_TRUE]))]
|
||||
p2sh_p2wsh_tx.wit.vtxinwit.append(CTxInWitness())
|
||||
p2sh_p2wsh_tx.wit.vtxinwit[0].scriptWitness.stack = [CScript([OP_TRUE])]
|
||||
p2sh_p2wsh_tx.rehash()
|
||||
|
||||
for tx in [p2wsh_tx, p2sh_p2wsh_tx]:
|
||||
|
||||
@@ -527,7 +523,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx.vout.append(CTxOut(self.utxo[0].nValue - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
|
||||
tx.wit.vtxinwit.append(CTxInWitness())
|
||||
tx.wit.vtxinwit[0].scriptWitness.stack = [b'a']
|
||||
tx.rehash()
|
||||
|
||||
tx_hash = tx.sha256
|
||||
tx_value = tx.vout[0].nValue
|
||||
@@ -573,7 +568,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
p2sh_tx = CTransaction()
|
||||
p2sh_tx.vin = [CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")]
|
||||
p2sh_tx.vout = [CTxOut(self.utxo[0].nValue - 1000, p2sh_script_pubkey)]
|
||||
p2sh_tx.rehash()
|
||||
|
||||
# Mine it on test_node to create the confirmed output.
|
||||
test_transaction_acceptance(self.nodes[0], self.test_node, p2sh_tx, with_witness=True, accepted=True)
|
||||
@@ -586,7 +580,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
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
|
||||
tx.rehash()
|
||||
|
||||
# This is always accepted, since the mempool policy is to consider segwit as always active
|
||||
# and thus allow segwit outputs
|
||||
@@ -601,7 +594,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx2.vout = [CTxOut(7000, script_pubkey)]
|
||||
tx2.wit.vtxinwit.append(CTxInWitness())
|
||||
tx2.wit.vtxinwit[0].scriptWitness.stack = [witness_script]
|
||||
tx2.rehash()
|
||||
|
||||
test_transaction_acceptance(self.nodes[1], self.std_node, tx2, with_witness=True, accepted=True)
|
||||
|
||||
@@ -614,7 +606,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
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]
|
||||
tx3.rehash()
|
||||
if not self.segwit_active:
|
||||
# Just check mempool acceptance, but don't add the transaction to the mempool, since witness is disallowed
|
||||
# in blocks and the tx is impossible to mine right now.
|
||||
@@ -636,7 +627,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx3_out = tx3.vout[0]
|
||||
tx3 = tx
|
||||
tx3.vout = [tx3_out]
|
||||
tx3.rehash()
|
||||
testres3_replaced = self.nodes[0].testmempoolaccept([tx3.serialize_with_witness().hex()])
|
||||
testres3_replaced[0]["fees"].pop("effective-feerate")
|
||||
testres3_replaced[0]["fees"].pop("effective-includes")
|
||||
@@ -683,7 +673,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx = CTransaction()
|
||||
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
|
||||
tx.vout.append(CTxOut(self.utxo[0].nValue - 1000, script_pubkey))
|
||||
tx.rehash()
|
||||
|
||||
# Verify mempool acceptance and block validity
|
||||
test_transaction_acceptance(self.nodes[0], self.test_node, tx, with_witness=False, accepted=True)
|
||||
@@ -696,7 +685,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
spend_tx = CTransaction()
|
||||
spend_tx.vin.append(CTxIn(COutPoint(tx.sha256, 0), script_sig))
|
||||
spend_tx.vout.append(CTxOut(tx.vout[0].nValue - 1000, CScript([OP_TRUE])))
|
||||
spend_tx.rehash()
|
||||
|
||||
# This transaction should not be accepted into the mempool pre- or
|
||||
# post-segwit. Mempool acceptance will use SCRIPT_VERIFY_WITNESS which
|
||||
@@ -709,7 +697,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
|
||||
# Try to put the witness script in the scriptSig, should also fail.
|
||||
spend_tx.vin[0].scriptSig = CScript([p2wsh_pubkey, b'a'])
|
||||
spend_tx.rehash()
|
||||
with self.nodes[0].assert_debug_log(
|
||||
expected_msgs=[spend_tx.hash, 'was not accepted: mandatory-script-verify-flag-failed (Script evaluated without error but finished with a false/empty top stack element)']):
|
||||
test_transaction_acceptance(self.nodes[0], self.test_node, spend_tx, with_witness=False, accepted=False)
|
||||
@@ -717,7 +704,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
# Now put the witness script in the witness, should succeed after
|
||||
# segwit activates.
|
||||
spend_tx.vin[0].scriptSig = script_sig
|
||||
spend_tx.rehash()
|
||||
spend_tx.wit.vtxinwit.append(CTxInWitness())
|
||||
spend_tx.wit.vtxinwit[0].scriptWitness.stack = [b'a', witness_script]
|
||||
|
||||
@@ -772,7 +758,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
witness_script = CScript([OP_TRUE])
|
||||
script_pubkey = script_to_p2wsh_script(witness_script)
|
||||
tx.vout.append(CTxOut(self.utxo[0].nValue - 1000, script_pubkey))
|
||||
tx.rehash()
|
||||
|
||||
# tx2 will spend tx1, and send back to a regular anyone-can-spend address
|
||||
tx2 = CTransaction()
|
||||
@@ -780,7 +765,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx2.vout.append(CTxOut(tx.vout[0].nValue - 1000, witness_script))
|
||||
tx2.wit.vtxinwit.append(CTxInWitness())
|
||||
tx2.wit.vtxinwit[0].scriptWitness.stack = [witness_script]
|
||||
tx2.rehash()
|
||||
|
||||
block_3 = self.build_next_block()
|
||||
self.update_witness_block_with_transactions(block_3, [tx, tx2], nonce=1)
|
||||
@@ -788,7 +772,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
# even though it has extra data after the incorrect commitment.
|
||||
# This block should fail.
|
||||
block_3.vtx[0].vout.append(CTxOut(0, CScript([OP_RETURN, WITNESS_COMMITMENT_HEADER + ser_uint256(2), 10])))
|
||||
block_3.vtx[0].rehash()
|
||||
block_3.hashMerkleRoot = block_3.calc_merkle_root()
|
||||
block_3.solve()
|
||||
|
||||
@@ -801,7 +784,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
add_witness_commitment(block_3, nonce=0)
|
||||
block_3.vtx[0].vout[0].nValue -= 1
|
||||
block_3.vtx[0].vout[-1].nValue += 1
|
||||
block_3.vtx[0].rehash()
|
||||
block_3.hashMerkleRoot = block_3.calc_merkle_root()
|
||||
assert len(block_3.vtx[0].vout) == 4 # 3 OP_returns
|
||||
block_3.solve()
|
||||
@@ -813,7 +795,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx3 = CTransaction()
|
||||
tx3.vin.append(CTxIn(COutPoint(tx2.sha256, 0), b""))
|
||||
tx3.vout.append(CTxOut(tx.vout[0].nValue - 1000, witness_script))
|
||||
tx3.rehash()
|
||||
block_4.vtx.append(tx3)
|
||||
block_4.hashMerkleRoot = block_4.calc_merkle_root()
|
||||
block_4.solve()
|
||||
@@ -893,7 +874,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
parent_tx.vout.append(CTxOut(child_value, script_pubkey))
|
||||
parent_tx.vout[0].nValue -= 50000
|
||||
assert parent_tx.vout[0].nValue > 0
|
||||
parent_tx.rehash()
|
||||
|
||||
child_tx = CTransaction()
|
||||
for i in range(NUM_OUTPUTS):
|
||||
@@ -902,7 +882,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
for _ in range(NUM_OUTPUTS):
|
||||
child_tx.wit.vtxinwit.append(CTxInWitness())
|
||||
child_tx.wit.vtxinwit[-1].scriptWitness.stack = [b'a' * 195] * (2 * NUM_DROPS) + [witness_script]
|
||||
child_tx.rehash()
|
||||
self.update_witness_block_with_transactions(block, [parent_tx, child_tx])
|
||||
|
||||
additional_bytes = MAX_BLOCK_WEIGHT - block.get_weight()
|
||||
@@ -990,7 +969,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx.vout.append(CTxOut(1000, CScript([OP_TRUE]))) # non-witness output
|
||||
tx.wit.vtxinwit.append(CTxInWitness())
|
||||
tx.wit.vtxinwit[0].scriptWitness.stack = [CScript([])]
|
||||
tx.rehash()
|
||||
self.update_witness_block_with_transactions(block, [tx])
|
||||
|
||||
# Extra witness data should not be allowed.
|
||||
@@ -1000,7 +978,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
# Try extra signature data. Ok if we're not spending a witness output.
|
||||
block.vtx[1].wit.vtxinwit = []
|
||||
block.vtx[1].vin[0].scriptSig = CScript([OP_0])
|
||||
block.vtx[1].rehash()
|
||||
add_witness_commitment(block)
|
||||
block.solve()
|
||||
|
||||
@@ -1028,7 +1005,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx2.vin[1].scriptSig = CScript([OP_TRUE])
|
||||
tx2.wit.vtxinwit[0].scriptWitness.stack.pop(0)
|
||||
tx2.wit.vtxinwit[1].scriptWitness.stack = []
|
||||
tx2.rehash()
|
||||
add_witness_commitment(block)
|
||||
block.solve()
|
||||
|
||||
@@ -1039,7 +1015,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
# Now get rid of the extra scriptsig on the witness input, and verify
|
||||
# success (even with extra scriptsig data in the non-witness input)
|
||||
tx2.vin[0].scriptSig = b""
|
||||
tx2.rehash()
|
||||
add_witness_commitment(block)
|
||||
block.solve()
|
||||
|
||||
@@ -1061,7 +1036,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx = CTransaction()
|
||||
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
|
||||
tx.vout.append(CTxOut(self.utxo[0].nValue - 1000, script_pubkey))
|
||||
tx.rehash()
|
||||
|
||||
tx2 = CTransaction()
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), b""))
|
||||
@@ -1069,7 +1043,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx2.wit.vtxinwit.append(CTxInWitness())
|
||||
# First try a 521-byte stack element
|
||||
tx2.wit.vtxinwit[0].scriptWitness.stack = [b'a' * (MAX_SCRIPT_ELEMENT_SIZE + 1), witness_script]
|
||||
tx2.rehash()
|
||||
|
||||
self.update_witness_block_with_transactions(block, [tx, tx2])
|
||||
test_witness_block(self.nodes[0], self.test_node, block, accepted=False,
|
||||
@@ -1102,14 +1075,12 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx = CTransaction()
|
||||
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
|
||||
tx.vout.append(CTxOut(self.utxo[0].nValue - 1000, long_script_pubkey))
|
||||
tx.rehash()
|
||||
|
||||
tx2 = CTransaction()
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.sha256, 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]
|
||||
tx2.rehash()
|
||||
|
||||
self.update_witness_block_with_transactions(block, [tx, tx2])
|
||||
|
||||
@@ -1122,10 +1093,8 @@ class SegWitTest(BitcoinTestFramework):
|
||||
script_pubkey = script_to_p2wsh_script(witness_script)
|
||||
|
||||
tx.vout[0] = CTxOut(tx.vout[0].nValue, script_pubkey)
|
||||
tx.rehash()
|
||||
tx2.vin[0].prevout.hash = tx.sha256
|
||||
tx2.wit.vtxinwit[0].scriptWitness.stack = [b'a'] * 43 + [witness_script]
|
||||
tx2.rehash()
|
||||
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)
|
||||
@@ -1234,7 +1203,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx.vout.append(CTxOut(self.utxo[0].nValue - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
|
||||
tx.wit.vtxinwit.append(CTxInWitness())
|
||||
tx.wit.vtxinwit[0].scriptWitness.stack = [b'a']
|
||||
tx.rehash()
|
||||
|
||||
tx_hash = tx.sha256
|
||||
|
||||
@@ -1252,7 +1220,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx2 = CTransaction()
|
||||
tx2.vin.append(CTxIn(COutPoint(tx_hash, 0), b""))
|
||||
tx2.vout.append(CTxOut(tx.vout[0].nValue - 1000, script_pubkey))
|
||||
tx2.rehash()
|
||||
|
||||
tx3 = CTransaction()
|
||||
tx3.vin.append(CTxIn(COutPoint(tx2.sha256, 0), b""))
|
||||
@@ -1263,7 +1230,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
witness_script2 = CScript([b'a' * 400000])
|
||||
tx3.vout.append(CTxOut(tx2.vout[0].nValue - 1000, script_to_p2sh_script(p2sh_script)))
|
||||
tx3.wit.vtxinwit[0].scriptWitness.stack = [witness_script2]
|
||||
tx3.rehash()
|
||||
|
||||
# Node will not be blinded to the transaction, requesting it any number of times
|
||||
# if it is being announced via txid relay.
|
||||
@@ -1277,7 +1243,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
# Remove witness stuffing, instead add extra witness push on stack
|
||||
tx3.vout[0] = CTxOut(tx2.vout[0].nValue - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE]))
|
||||
tx3.wit.vtxinwit[0].scriptWitness.stack = [CScript([CScriptNum(1)]), witness_script]
|
||||
tx3.rehash()
|
||||
|
||||
test_transaction_acceptance(self.nodes[0], self.test_node, tx2, with_witness=True, accepted=True)
|
||||
test_transaction_acceptance(self.nodes[0], self.test_node, tx3, with_witness=True, accepted=False)
|
||||
@@ -1324,7 +1289,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
split_value = (self.utxo[0].nValue - 4000) // NUM_SEGWIT_VERSIONS
|
||||
for _ in range(NUM_SEGWIT_VERSIONS):
|
||||
tx.vout.append(CTxOut(split_value, CScript([OP_TRUE])))
|
||||
tx.rehash()
|
||||
block = self.build_next_block()
|
||||
self.update_witness_block_with_transactions(block, [tx])
|
||||
test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
|
||||
@@ -1347,7 +1311,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
script_pubkey = CScript([CScriptOp(version), witness_hash])
|
||||
tx.vin = [CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")]
|
||||
tx.vout = [CTxOut(self.utxo[0].nValue - 1000, script_pubkey)]
|
||||
tx.rehash()
|
||||
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)
|
||||
@@ -1364,7 +1327,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx2.vout = [CTxOut(tx.vout[0].nValue - 1000, script_pubkey)]
|
||||
tx2.wit.vtxinwit.append(CTxInWitness())
|
||||
tx2.wit.vtxinwit[0].scriptWitness.stack = [witness_script]
|
||||
tx2.rehash()
|
||||
# Gets accepted to both policy-enforcing nodes and others.
|
||||
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)
|
||||
@@ -1380,7 +1342,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
total_value += i.nValue
|
||||
tx3.wit.vtxinwit[-1].scriptWitness.stack = [witness_script]
|
||||
tx3.vout.append(CTxOut(total_value - 1000, script_pubkey))
|
||||
tx3.rehash()
|
||||
|
||||
# First we test this transaction against std_node
|
||||
# making sure the txid is added to the reject filter
|
||||
@@ -1420,7 +1381,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
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]
|
||||
spend_tx.rehash()
|
||||
|
||||
# Now test a premature spend.
|
||||
self.generate(self.nodes[0], 98)
|
||||
@@ -1456,7 +1416,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx = CTransaction()
|
||||
tx.vin.append(CTxIn(COutPoint(utxo.sha256, utxo.n), b""))
|
||||
tx.vout.append(CTxOut(utxo.nValue - 1000, script_pkh))
|
||||
tx.rehash()
|
||||
|
||||
# Confirm it in a block.
|
||||
block = self.build_next_block()
|
||||
@@ -1542,7 +1501,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx = CTransaction()
|
||||
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
|
||||
tx.vout.append(CTxOut(self.utxo[0].nValue - 1000, script_pubkey))
|
||||
tx.rehash()
|
||||
|
||||
test_transaction_acceptance(self.nodes[0], self.test_node, tx, with_witness=True, accepted=True)
|
||||
# Mine this transaction in preparation for following tests.
|
||||
@@ -1637,7 +1595,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
sign_p2pk_witness_input(witness_script, tx, i, hashtype, temp_utxos[i].nValue, key)
|
||||
if (hashtype == SIGHASH_SINGLE and i >= num_outputs):
|
||||
used_sighash_single_out_of_bounds = True
|
||||
tx.rehash()
|
||||
for i in range(num_outputs):
|
||||
temp_utxos.append(UTXO(tx.sha256, i, split_value))
|
||||
temp_utxos = temp_utxos[num_inputs:]
|
||||
@@ -1676,7 +1633,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
|
||||
# Check that we can't have a scriptSig
|
||||
tx2.vin[0].scriptSig = CScript([signature, pubkey])
|
||||
tx2.rehash()
|
||||
block = self.build_next_block()
|
||||
self.update_witness_block_with_transactions(block, [tx, tx2])
|
||||
test_witness_block(self.nodes[0], self.test_node, block, accepted=False,
|
||||
@@ -1687,7 +1643,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx2.wit.vtxinwit.append(CTxInWitness())
|
||||
tx2.wit.vtxinwit[0].scriptWitness.stack = [signature, pubkey]
|
||||
tx2.vin[0].scriptSig = b""
|
||||
tx2.rehash()
|
||||
|
||||
self.update_witness_block_with_transactions(block, [tx2])
|
||||
test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
|
||||
@@ -1731,7 +1686,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx = CTransaction()
|
||||
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
|
||||
tx.vout.append(CTxOut(self.utxo[0].nValue - 1000, script_pubkey))
|
||||
tx.rehash()
|
||||
test_transaction_acceptance(self.nodes[0], self.test_node, tx, False, True)
|
||||
self.generate(self.nodes[0], 1)
|
||||
|
||||
@@ -1745,7 +1699,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
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]
|
||||
tx2.rehash()
|
||||
# This will be rejected due to a policy check:
|
||||
# No witness is allowed, since it is not a witness program but a p2sh program
|
||||
test_transaction_acceptance(self.nodes[1], self.std_node, tx2, True, False, 'bad-witness-nonstandard')
|
||||
@@ -1757,7 +1710,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx3 = CTransaction()
|
||||
tx3.vin.append(CTxIn(COutPoint(tx2.sha256, 0), CScript([p2sh_program])))
|
||||
tx3.vout.append(CTxOut(tx2.vout[0].nValue - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
|
||||
tx3.rehash()
|
||||
test_transaction_acceptance(self.nodes[0], self.test_node, tx2, False, True)
|
||||
test_transaction_acceptance(self.nodes[0], self.test_node, tx3, False, True)
|
||||
|
||||
@@ -1791,7 +1743,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
p2wsh_scripts.append(p2wsh)
|
||||
tx.vout.append(CTxOut(outputvalue, p2wsh))
|
||||
tx.vout.append(CTxOut(outputvalue, script_to_p2sh_script(p2wsh)))
|
||||
tx.rehash()
|
||||
txid = tx.sha256
|
||||
test_transaction_acceptance(self.nodes[0], self.test_node, tx, with_witness=False, accepted=True)
|
||||
|
||||
@@ -1805,13 +1756,11 @@ class SegWitTest(BitcoinTestFramework):
|
||||
p2wsh_tx.vin.append(CTxIn(COutPoint(txid, i * 2)))
|
||||
p2wsh_tx.vout.append(CTxOut(outputvalue - 5000, CScript([OP_0, hash160(b"")])))
|
||||
p2wsh_tx.wit.vtxinwit.append(CTxInWitness())
|
||||
p2wsh_tx.rehash()
|
||||
p2wsh_txs.append(p2wsh_tx)
|
||||
p2sh_tx = CTransaction()
|
||||
p2sh_tx.vin.append(CTxIn(COutPoint(txid, i * 2 + 1), CScript([p2wsh_scripts[i]])))
|
||||
p2sh_tx.vout.append(CTxOut(outputvalue - 5000, CScript([OP_0, hash160(b"")])))
|
||||
p2sh_tx.wit.vtxinwit.append(CTxInWitness())
|
||||
p2sh_tx.rehash()
|
||||
p2sh_txs.append(p2sh_tx)
|
||||
|
||||
# Testing native P2WSH
|
||||
@@ -1902,7 +1851,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx.vout.append(CTxOut(split_value, script_pubkey))
|
||||
tx.vout[-2].scriptPubKey = script_pubkey_toomany
|
||||
tx.vout[-1].scriptPubKey = script_pubkey_justright
|
||||
tx.rehash()
|
||||
|
||||
block_1 = self.build_next_block()
|
||||
self.update_witness_block_with_transactions(block_1, [tx])
|
||||
@@ -1919,7 +1867,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
total_value += tx.vout[i].nValue
|
||||
tx2.wit.vtxinwit[-1].scriptWitness.stack = [witness_script_toomany]
|
||||
tx2.vout.append(CTxOut(total_value, CScript([OP_TRUE])))
|
||||
tx2.rehash()
|
||||
|
||||
block_2 = self.build_next_block()
|
||||
self.update_witness_block_with_transactions(block_2, [tx2])
|
||||
@@ -1933,7 +1880,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx2.vin.pop()
|
||||
tx2.wit.vtxinwit.pop()
|
||||
tx2.vout[0].nValue -= tx.vout[-2].nValue
|
||||
tx2.rehash()
|
||||
block_3 = self.build_next_block()
|
||||
self.update_witness_block_with_transactions(block_3, [tx2])
|
||||
test_witness_block(self.nodes[0], self.test_node, block_3, accepted=False, reason='bad-blk-sigops')
|
||||
@@ -1941,7 +1887,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
# If we drop the last checksig in this output, the tx should succeed.
|
||||
block_4 = self.build_next_block()
|
||||
tx2.vout[-1].scriptPubKey = CScript([OP_CHECKSIG] * (checksig_count - 1))
|
||||
tx2.rehash()
|
||||
self.update_witness_block_with_transactions(block_4, [tx2])
|
||||
test_witness_block(self.nodes[0], self.test_node, block_4, accepted=True)
|
||||
|
||||
@@ -1957,7 +1902,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx2.vin.append(CTxIn(COutPoint(tx.sha256, outputs - 1), b""))
|
||||
tx2.wit.vtxinwit.append(CTxInWitness())
|
||||
tx2.wit.vtxinwit[-1].scriptWitness.stack = [witness_script_justright]
|
||||
tx2.rehash()
|
||||
self.update_witness_block_with_transactions(block_5, [tx2])
|
||||
test_witness_block(self.nodes[0], self.test_node, block_5, accepted=True)
|
||||
|
||||
@@ -2022,7 +1966,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx = CTransaction()
|
||||
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
|
||||
tx.vout.append(CTxOut(self.utxo[0].nValue - 1000, script_pubkey))
|
||||
tx.rehash()
|
||||
|
||||
# Create a Segwit transaction
|
||||
tx2 = CTransaction()
|
||||
@@ -2030,7 +1973,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx2.vout.append(CTxOut(tx.vout[0].nValue - 1000, script_pubkey))
|
||||
tx2.wit.vtxinwit.append(CTxInWitness())
|
||||
tx2.wit.vtxinwit[0].scriptWitness.stack = [witness_script]
|
||||
tx2.rehash()
|
||||
|
||||
# Announce Segwit transaction with wtxid
|
||||
# and wait for getdata
|
||||
|
||||
Reference in New Issue
Block a user