qa: pass scriptsig directly to txins constructor in fee estimation test

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
This commit is contained in:
Antoine Poinsot 2021-09-21 12:31:18 +02:00
parent 1fc03155e5
commit eae52dd6ab
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304

View File

@ -63,19 +63,15 @@ def small_txpuzzle_randfee(
while total_in <= (amount + fee) and len(conflist) > 0: while total_in <= (amount + fee) and len(conflist) > 0:
t = conflist.pop(0) t = conflist.pop(0)
total_in += t["amount"] total_in += t["amount"]
tx.vin.append(CTxIn(COutPoint(int(t["txid"], 16), t["vout"]), b"")) tx.vin.append(CTxIn(COutPoint(int(t["txid"], 16), t["vout"]), REDEEM_SCRIPT))
while total_in <= (amount + fee) and len(unconflist) > 0: while total_in <= (amount + fee) and len(unconflist) > 0:
t = unconflist.pop(0) t = unconflist.pop(0)
total_in += t["amount"] total_in += t["amount"]
tx.vin.append(CTxIn(COutPoint(int(t["txid"], 16), t["vout"]), b"")) tx.vin.append(CTxIn(COutPoint(int(t["txid"], 16), t["vout"]), REDEEM_SCRIPT))
if total_in <= amount + fee: if total_in <= amount + fee:
raise RuntimeError(f"Insufficient funds: need {amount + fee}, have {total_in}") raise RuntimeError(f"Insufficient funds: need {amount + fee}, have {total_in}")
tx.vout.append(CTxOut(int((total_in - amount - fee) * COIN), P2SH)) tx.vout.append(CTxOut(int((total_in - amount - fee) * COIN), P2SH))
tx.vout.append(CTxOut(int(amount * COIN), P2SH)) tx.vout.append(CTxOut(int(amount * COIN), P2SH))
# These transactions don't need to be signed, but we still have to insert
# the ScriptSig that will satisfy the ScriptPubKey.
for inp in tx.vin:
inp.scriptSig = REDEEM_SCRIPT
txid = from_node.sendrawtransaction(hexstring=tx.serialize().hex(), maxfeerate=0) txid = from_node.sendrawtransaction(hexstring=tx.serialize().hex(), maxfeerate=0)
unconflist.append({"txid": txid, "vout": 0, "amount": total_in - amount - fee}) unconflist.append({"txid": txid, "vout": 0, "amount": total_in - amount - fee})
unconflist.append({"txid": txid, "vout": 1, "amount": amount}) unconflist.append({"txid": txid, "vout": 1, "amount": amount})
@ -218,7 +214,7 @@ class EstimateFeeTest(BitcoinTestFramework):
change = Decimal("100") - splitted_amount * utxo_count - fee change = Decimal("100") - splitted_amount * utxo_count - fee
tx = CTransaction() tx = CTransaction()
tx.vin = [ tx.vin = [
CTxIn(COutPoint(int(cb["txid"], 16), cb["vout"]), b"") CTxIn(COutPoint(int(cb["txid"], 16), cb["vout"]))
for cb in node.listunspent()[:2] for cb in node.listunspent()[:2]
] ]
tx.vout = [CTxOut(int(splitted_amount * COIN), P2SH) for _ in range(utxo_count)] tx.vout = [CTxOut(int(splitted_amount * COIN), P2SH) for _ in range(utxo_count)]