Skip to content

Commit 8f250ab

Browse files
committed
TEST: Replace hard-coded hex tx with classes
1 parent b3edacb commit 8f250ab

File tree

1 file changed

+13
-10
lines changed
  • test/functional/test_framework

1 file changed

+13
-10
lines changed

test/functional/test_framework/util.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from . import coverage
2121
from .authproxy import AuthServiceProxy, JSONRPCException
22+
from io import BytesIO
2223

2324
logger = logging.getLogger("TestFramework.utils")
2425

@@ -515,31 +516,33 @@ def gen_return_txouts():
515516
for i in range(512):
516517
script_pubkey = script_pubkey + "01"
517518
# concatenate 128 txouts of above script_pubkey which we'll insert before the txout for change
518-
txouts = "81"
519+
txouts = []
520+
from .messages import CTxOut
521+
txout = CTxOut()
522+
txout.nValue = 0
523+
txout.scriptPubKey = hex_str_to_bytes(script_pubkey)
519524
for k in range(128):
520-
# add txout value
521-
txouts = txouts + "0000000000000000"
522-
# add length of script_pubkey
523-
txouts = txouts + "fd0402"
524-
# add script_pubkey
525-
txouts = txouts + script_pubkey
525+
txouts.append(txout)
526526
return txouts
527527

528528
# Create a spend of each passed-in utxo, splicing in "txouts" to each raw
529529
# transaction to make it large. See gen_return_txouts() above.
530530
def create_lots_of_big_transactions(node, txouts, utxos, num, fee):
531531
addr = node.getnewaddress()
532532
txids = []
533+
from .messages import CTransaction
533534
for _ in range(num):
534535
t = utxos.pop()
535536
inputs = [{"txid": t["txid"], "vout": t["vout"]}]
536537
outputs = {}
537538
change = t['amount'] - fee
538539
outputs[addr] = satoshi_round(change)
539540
rawtx = node.createrawtransaction(inputs, outputs)
540-
newtx = rawtx[0:92]
541-
newtx = newtx + txouts
542-
newtx = newtx + rawtx[94:]
541+
tx = CTransaction()
542+
tx.deserialize(BytesIO(hex_str_to_bytes(rawtx)))
543+
for txout in txouts:
544+
tx.vout.append(txout)
545+
newtx = tx.serialize().hex()
543546
signresult = node.signrawtransactionwithwallet(newtx, None, "NONE")
544547
txid = node.sendrawtransaction(signresult["hex"], 0)
545548
txids.append(txid)

0 commit comments

Comments
 (0)