diff --git a/test/functional/data/invalid_txs.py b/test/functional/data/invalid_txs.py index f5dd4e341e..c677f86e88 100644 --- a/test/functional/data/invalid_txs.py +++ b/test/functional/data/invalid_txs.py @@ -196,7 +196,7 @@ class SpendTooMuch(BadTxTemplate): def get_tx(self): return create_tx_with_script( - self.spend_tx, 0, script_pub_key=basic_p2sh, amount=(self.spend_avail + 1)) + self.spend_tx, 0, output_script=basic_p2sh, amount=(self.spend_avail + 1)) class CreateNegative(BadTxTemplate): @@ -246,7 +246,7 @@ class TooManySigops(BadTxTemplate): lotsa_checksigs = CScript([OP_CHECKSIG] * (MAX_BLOCK_SIGOPS)) return create_tx_with_script( self.spend_tx, 0, - script_pub_key=lotsa_checksigs, + output_script=lotsa_checksigs, amount=self.spend_avail) def getDisabledOpcodeTemplate(opcode): diff --git a/test/functional/feature_block.py b/test/functional/feature_block.py index 219952cbe0..1a2abc7d34 100755 --- a/test/functional/feature_block.py +++ b/test/functional/feature_block.py @@ -1351,9 +1351,11 @@ class FullBlockTest(BitcoinTestFramework): block.vtx.extend(tx_list) # this is a little handier to use than the version in blocktools.py - def create_tx(self, spend_tx, n, value, script=CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])): + def create_tx(self, spend_tx, n, value, output_script=None): fee = spend_tx.vout[n].nValue.getAmount() - value - return create_tx_with_script(spend_tx, n, amount=value, fee=fee, script_pub_key=script) + if output_script is None: + output_script = CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE]) + return create_tx_with_script(spend_tx, n, amount=value, fee=fee, output_script=output_script) # update the fee output amount and also move it to the end def update_fee(self, tx, prev_tx, prev_n): @@ -1377,13 +1379,17 @@ class FullBlockTest(BitcoinTestFramework): return sign_input_legacy(tx, 0, spend_tx.vout[0].scriptPubKey, self.coinbase_key) - def create_and_sign_transaction(self, spend_tx, value, script=CScript([OP_TRUE])): - tx = self.create_tx(spend_tx, 0, value, script) + def create_and_sign_transaction(self, spend_tx, value, output_script=None): + if output_script is None: + output_script = CScript([OP_TRUE]) + tx = self.create_tx(spend_tx, 0, value, output_script=output_script) self.sign_tx(tx, spend_tx) tx.rehash() return tx - def next_block(self, number, spend=None, additional_coinbase_value=0, script=CScript([OP_TRUE]), *, version=4): + def next_block(self, number, spend=None, additional_coinbase_value=0, *, script=None, version=4): + if script is None: + script = CScript([OP_TRUE]) if self.tip is None: base_block_hash = self.genesis_hash block_time = int(time.time()) + 1 @@ -1400,7 +1406,7 @@ class FullBlockTest(BitcoinTestFramework): else: coinbase.vout[0].nValue.setToAmount(coinbase.vout[0].nValue.getAmount() + spend.vout[0].nValue.getAmount() - 1) # all but one satoshi to fees coinbase.rehash() - tx = self.create_tx(spend, 0, 1, script) # spend 1 satoshi + tx = self.create_tx(spend, 0, 1, output_script=script) # spend 1 satoshi self.sign_tx(tx, spend) tx.rehash() block = create_block(base_block_hash, coinbase, block_time, version=version, txlist=[tx]) diff --git a/test/functional/feature_taproot.py b/test/functional/feature_taproot.py index 31e300b859..85c10fbae3 100755 --- a/test/functional/feature_taproot.py +++ b/test/functional/feature_taproot.py @@ -244,7 +244,7 @@ def default_sigmsg(ctx): codeseppos = get(ctx, "codeseppos") leaf_ver = get(ctx, "leafversion") script = get(ctx, "script_taproot") - return TaprootSignatureMsg(tx, utxos, hashtype, genesis_hash, idx, scriptpath=True, script=script, leaf_ver=leaf_ver, codeseparator_pos=codeseppos, annex=annex) + return TaprootSignatureMsg(tx, utxos, hashtype, genesis_hash, idx, scriptpath=True, leaf_script=script, leaf_ver=leaf_ver, codeseparator_pos=codeseppos, annex=annex) else: return TaprootSignatureMsg(tx, utxos, hashtype, genesis_hash, idx, scriptpath=False, annex=annex) elif mode == "witv0": diff --git a/test/functional/p2p_invalid_block.py b/test/functional/p2p_invalid_block.py index 287b82b283..41a4f14f5c 100755 --- a/test/functional/p2p_invalid_block.py +++ b/test/functional/p2p_invalid_block.py @@ -71,8 +71,8 @@ class InvalidBlockRequestTest(BitcoinTestFramework): # ELEMENTS: scriptpubkeys can't be empty or else we interpret them as fee outputs, # so we modify the Core test to move the OP_TRUEs from scriptSig to scriptPubKey - tx1 = create_tx_with_script(block1.vtx[0], 0, script_pub_key=bytes([OP_TRUE]), amount=50 * COIN) - tx2 = create_tx_with_script(tx1, 0, script_pub_key=bytes([OP_TRUE]), amount=50 * COIN) + tx1 = create_tx_with_script(block1.vtx[0], 0, output_script=bytes([OP_TRUE]), amount=50 * COIN) + tx2 = create_tx_with_script(tx1, 0, output_script=bytes([OP_TRUE]), amount=50 * COIN) block2 = create_block(tip, create_coinbase(height), block_time, txlist=[tx1, tx2]) block_time += 1 block2.solve() diff --git a/test/functional/test_framework/blocktools.py b/test/functional/test_framework/blocktools.py index 3c909a5f8b..392e9ca74e 100755 --- a/test/functional/test_framework/blocktools.py +++ b/test/functional/test_framework/blocktools.py @@ -173,16 +173,18 @@ def create_coinbase(height, pubkey=None, *, script_pubkey=None, extra_output_scr coinbase.calc_sha256() return coinbase -def create_tx_with_script(prevtx, n, script_sig=b"", *, amount, fee=0, script_pub_key=CScript()): +def create_tx_with_script(prevtx, n, script_sig=b"", *, amount, fee=0, output_script=None): """Return one-input, one-output transaction object spending the prevtx's n-th output with the given amount. Can optionally pass scriptPubKey and scriptSig, default is anyone-can-spend output. """ + if output_script is None: + output_script = CScript() tx = CTransaction() assert n < len(prevtx.vout) tx.vin.append(CTxIn(COutPoint(prevtx.sha256, n), script_sig, SEQUENCE_FINAL)) - tx.vout.append(CTxOut(amount, script_pub_key)) + tx.vout.append(CTxOut(amount, output_script)) if fee > 0: tx.vout.append(CTxOut(fee)) tx.calc_sha256() diff --git a/test/functional/test_framework/script.py b/test/functional/test_framework/script.py index f80475829d..b571b750db 100644 --- a/test/functional/test_framework/script.py +++ b/test/functional/test_framework/script.py @@ -967,7 +967,7 @@ def BIP341_sha_sequences(txTo): def BIP341_sha_outputs(txTo): return sha256(b"".join(o.serialize() for o in txTo.vout)) -def TaprootSignatureMsg(txTo, spent_utxos, hash_type, genesis_hash, input_index = 0, scriptpath = False, script = CScript(), codeseparator_pos = -1, annex = None, leaf_ver = LEAF_VERSION_TAPSCRIPT): +def TaprootSignatureMsg(txTo, spent_utxos, hash_type, genesis_hash, input_index = 0, scriptpath = False, leaf_script=None, codeseparator_pos = -1, annex = None, leaf_ver = LEAF_VERSION_TAPSCRIPT): assert (len(txTo.vin) == len(spent_utxos)) assert (input_index < len(txTo.vin)) out_type = SIGHASH_ALL if hash_type == 0 else hash_type & 3 @@ -993,7 +993,7 @@ def TaprootSignatureMsg(txTo, spent_utxos, hash_type, genesis_hash, input_index spend_type = 0 if annex is not None: spend_type |= 1 - if (scriptpath): + if scriptpath: spend_type |= 2 ss += bytes([spend_type]) @@ -1023,7 +1023,7 @@ def TaprootSignatureMsg(txTo, spent_utxos, hash_type, genesis_hash, input_index ss += bytes(0 for _ in range(32)) ss += bytes(0 for _ in range(32)) if (scriptpath): - ss += TaggedHash("TapLeaf/elements", bytes([leaf_ver]) + ser_string(script)) + ss += TaggedHash("TapLeaf/elements", bytes([leaf_ver]) + ser_string(leaf_script)) ss += bytes([0]) ss += codeseparator_pos.to_bytes(4, "little", signed=True) # ELEMENTS -35 since we encode nAsset (33) + nValue (9) + nNonce (1) rather than nValue (8)