mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-19 05:45:05 +01:00
test: Avoid CScript() as default function argument
This does not cause any issues, because CScript in the tests are const. However, this change allows to enable the "function-call-in-default-argument (B008)" lint rule.
This commit is contained in:
parent
fadf621825
commit
fa46a1b74b
@ -192,7 +192,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):
|
||||
@ -242,7 +242,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=1)
|
||||
|
||||
def getDisabledOpcodeTemplate(opcode):
|
||||
|
@ -1326,8 +1326,10 @@ 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])):
|
||||
return create_tx_with_script(spend_tx, n, amount=value, script_pub_key=script)
|
||||
def create_tx(self, spend_tx, n, value, output_script=None):
|
||||
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, output_script=output_script)
|
||||
|
||||
# sign a transaction, using the key we know about
|
||||
# this signs input 0 in tx, which is assumed to be spending output 0 in spend_tx
|
||||
@ -1338,13 +1340,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
|
||||
@ -1361,7 +1367,7 @@ class FullBlockTest(BitcoinTestFramework):
|
||||
else:
|
||||
coinbase.vout[0].nValue += spend.vout[0].nValue - 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])
|
||||
|
@ -154,16 +154,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, script_pub_key=CScript()):
|
||||
def create_tx_with_script(prevtx, n, script_sig=b"", *, amount, 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))
|
||||
tx.calc_sha256()
|
||||
return tx
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user