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:
MarcoFalke
2024-07-31 10:13:10 +02:00
parent fadf621825
commit fa46a1b74b
3 changed files with 18 additions and 10 deletions

View File

@@ -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])