Skip to content

Commit cc204b8

Browse files
committed
qa: use a single p2sh script in fee estimation test
Using 2 different scripts is unnecessary complication Signed-off-by: Antoine Poinsot <[email protected]>
1 parent 19dd91a commit cc204b8

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

test/functional/feature_fee_estimation.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from test_framework.script import (
1818
CScript,
1919
OP_1,
20-
OP_2,
2120
OP_DROP,
2221
OP_TRUE,
2322
)
@@ -36,13 +35,9 @@
3635
# Construct 2 trivial P2SH's and the ScriptSigs that spend them
3736
# So we can create many transactions without needing to spend
3837
# time signing.
39-
REDEEM_SCRIPT_1 = CScript([OP_1, OP_DROP])
40-
REDEEM_SCRIPT_2 = CScript([OP_2, OP_DROP])
41-
P2SH_1 = script_to_p2sh_script(REDEEM_SCRIPT_1)
42-
P2SH_2 = script_to_p2sh_script(REDEEM_SCRIPT_2)
43-
44-
# Associated ScriptSig's to spend satisfy P2SH_1 and P2SH_2
45-
SCRIPT_SIG = [CScript([OP_TRUE, REDEEM_SCRIPT_1]), CScript([OP_TRUE, REDEEM_SCRIPT_2])]
38+
SCRIPT = CScript([OP_1, OP_DROP])
39+
P2SH = script_to_p2sh_script(SCRIPT)
40+
REDEEM_SCRIPT = CScript([OP_TRUE, SCRIPT])
4641

4742

4843
def small_txpuzzle_randfee(from_node, conflist, unconflist, amount, min_fee, fee_increment):
@@ -73,12 +68,12 @@ def small_txpuzzle_randfee(from_node, conflist, unconflist, amount, min_fee, fee
7368
tx.vin.append(CTxIn(COutPoint(int(t["txid"], 16), t["vout"]), b""))
7469
if total_in <= amount + fee:
7570
raise RuntimeError(f"Insufficient funds: need {amount + fee}, have {total_in}")
76-
tx.vout.append(CTxOut(int((total_in - amount - fee) * COIN), P2SH_1))
77-
tx.vout.append(CTxOut(int(amount * COIN), P2SH_2))
71+
tx.vout.append(CTxOut(int((total_in - amount - fee) * COIN), P2SH))
72+
tx.vout.append(CTxOut(int(amount * COIN), P2SH))
7873
# These transactions don't need to be signed, but we still have to insert
7974
# the ScriptSig that will satisfy the ScriptPubKey.
8075
for inp in tx.vin:
81-
inp.scriptSig = SCRIPT_SIG[inp.prevout.n]
76+
inp.scriptSig = REDEEM_SCRIPT
8277
txid = from_node.sendrawtransaction(hexstring=tx.serialize().hex(), maxfeerate=0)
8378
unconflist.append({"txid": txid, "vout": 0, "amount": total_in - amount - fee})
8479
unconflist.append({"txid": txid, "vout": 1, "amount": amount})
@@ -100,15 +95,15 @@ def split_inputs(from_node, txins, txouts, initial_split=False):
10095

10196
half_change = satoshi_round(prevtxout["amount"] / 2)
10297
rem_change = prevtxout["amount"] - half_change - Decimal("0.00001000")
103-
tx.vout.append(CTxOut(int(half_change * COIN), P2SH_1))
104-
tx.vout.append(CTxOut(int(rem_change * COIN), P2SH_2))
98+
tx.vout.append(CTxOut(int(half_change * COIN), P2SH))
99+
tx.vout.append(CTxOut(int(rem_change * COIN), P2SH))
105100

106101
# If this is the initial split we actually need to sign the transaction
107102
# Otherwise we just need to insert the proper ScriptSig
108103
if (initial_split):
109104
completetx = from_node.signrawtransactionwithwallet(tx.serialize().hex())["hex"]
110105
else:
111-
tx.vin[0].scriptSig = SCRIPT_SIG[prevtxout["vout"]]
106+
tx.vin[0].scriptSig = REDEEM_SCRIPT
112107
completetx = tx.serialize().hex()
113108
txid = from_node.sendrawtransaction(hexstring=completetx, maxfeerate=0)
114109
txouts.append({"txid": txid, "vout": 0, "amount": half_change})
@@ -163,8 +158,8 @@ def send_tx(node, utxo, feerate):
163158
fee = tx_size * feerate
164159

165160
tx = CTransaction()
166-
tx.vin = [CTxIn(COutPoint(int(utxo["txid"], 16), utxo["vout"]), SCRIPT_SIG[utxo["vout"]])]
167-
tx.vout = [CTxOut(int(utxo["amount"] * COIN) - fee, P2SH_1)]
161+
tx.vin = [CTxIn(COutPoint(int(utxo["txid"], 16), utxo["vout"]), REDEEM_SCRIPT)]
162+
tx.vout = [CTxOut(int(utxo["amount"] * COIN) - fee, P2SH)]
168163
txid = node.sendrawtransaction(tx.serialize().hex())
169164

170165
return txid

0 commit comments

Comments
 (0)