Skip to content

Commit 364bae5

Browse files
MarcoFalkejl2012
authored andcommitted
qa: Pad scriptPubKeys to get minimum sized txs
1 parent 7485488 commit 364bae5

File tree

7 files changed

+48
-45
lines changed

7 files changed

+48
-45
lines changed

test/functional/feature_bip68_sequence.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_disable_flag(self):
8080
tx2.nVersion = 2
8181
sequence_value = sequence_value & 0x7fffffff
8282
tx2.vin = [CTxIn(COutPoint(tx1_id, 0), nSequence=sequence_value)]
83-
tx2.vout = [CTxOut(int(value-self.relayfee*COIN), CScript([b'a']))]
83+
tx2.vout = [CTxOut(int(value - self.relayfee * COIN), CScript([b'a' * 35]))]
8484
tx2.rehash()
8585

8686
assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, ToHex(tx2))
@@ -222,7 +222,7 @@ def test_nonzero_locks(orig_tx, node, relayfee, use_height_lock):
222222
tx = CTransaction()
223223
tx.nVersion = 2
224224
tx.vin = [CTxIn(COutPoint(orig_tx.sha256, 0), nSequence=sequence_value)]
225-
tx.vout = [CTxOut(int(orig_tx.vout[0].nValue - relayfee*COIN), CScript([b'a']))]
225+
tx.vout = [CTxOut(int(orig_tx.vout[0].nValue - relayfee * COIN), CScript([b'a' * 35]))]
226226
tx.rehash()
227227

228228
if (orig_tx.hash in node.getrawmempool()):
@@ -350,7 +350,7 @@ def test_bip68_not_consensus(self):
350350
tx3 = CTransaction()
351351
tx3.nVersion = 2
352352
tx3.vin = [CTxIn(COutPoint(tx2.sha256, 0), nSequence=sequence_value)]
353-
tx3.vout = [CTxOut(int(tx2.vout[0].nValue - self.relayfee*COIN), CScript([b'a']))]
353+
tx3.vout = [CTxOut(int(tx2.vout[0].nValue - self.relayfee * COIN), CScript([b'a' * 35]))]
354354
tx3.rehash()
355355

356356
assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, ToHex(tx3))

test/functional/feature_block.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
OP_ELSE,
3333
OP_ENDIF,
3434
OP_EQUAL,
35+
OP_DROP,
3536
OP_FALSE,
3637
OP_HASH160,
3738
OP_IF,
@@ -1215,7 +1216,7 @@ def add_transactions_to_block(self, block, tx_list):
12151216
block.vtx.extend(tx_list)
12161217

12171218
# this is a little handier to use than the version in blocktools.py
1218-
def create_tx(self, spend_tx, n, value, script=CScript([OP_TRUE])):
1219+
def create_tx(self, spend_tx, n, value, script=CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])):
12191220
return create_transaction(spend_tx, n, b"", value, script)
12201221

12211222
# sign a transaction, using the key we know about

test/functional/feature_rbf.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def test_simple_doublespend(self):
123123

124124
tx1a = CTransaction()
125125
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)]
126-
tx1a.vout = [CTxOut(1*COIN, CScript([b'a']))]
126+
tx1a.vout = [CTxOut(1 * COIN, CScript([b'a' * 35]))]
127127
tx1a_hex = txToHex(tx1a)
128128
tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, True)
129129

@@ -132,7 +132,7 @@ def test_simple_doublespend(self):
132132
# Should fail because we haven't changed the fee
133133
tx1b = CTransaction()
134134
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
135-
tx1b.vout = [CTxOut(1*COIN, CScript([b'b']))]
135+
tx1b.vout = [CTxOut(1 * COIN, CScript([b'b' * 35]))]
136136
tx1b_hex = txToHex(tx1b)
137137

138138
# This will raise an exception due to insufficient fee
@@ -143,7 +143,7 @@ def test_simple_doublespend(self):
143143
# Extra 0.1 BTC fee
144144
tx1b = CTransaction()
145145
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
146-
tx1b.vout = [CTxOut(int(0.9*COIN), CScript([b'b']))]
146+
tx1b.vout = [CTxOut(int(0.9 * COIN), CScript([b'b' * 35]))]
147147
tx1b_hex = txToHex(tx1b)
148148
# Replacement still disabled even with "enough fee"
149149
assert_raises_rpc_error(-26, "txn-mempool-conflict", self.nodes[1].sendrawtransaction, tx1b_hex, True)
@@ -175,7 +175,7 @@ def test_doublespend_chain(self):
175175
remaining_value -= 1*COIN
176176
tx = CTransaction()
177177
tx.vin = [CTxIn(prevout, nSequence=0)]
178-
tx.vout = [CTxOut(remaining_value, CScript([1]))]
178+
tx.vout = [CTxOut(remaining_value, CScript([1, OP_DROP] * 15 + [1]))]
179179
tx_hex = txToHex(tx)
180180
txid = self.nodes[0].sendrawtransaction(tx_hex, True)
181181
chain_txids.append(txid)
@@ -185,7 +185,7 @@ def test_doublespend_chain(self):
185185
# child fees - 40 BTC - so this attempt is rejected.
186186
dbl_tx = CTransaction()
187187
dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)]
188-
dbl_tx.vout = [CTxOut(initial_nValue - 30*COIN, CScript([1]))]
188+
dbl_tx.vout = [CTxOut(initial_nValue - 30 * COIN, CScript([1] * 35))]
189189
dbl_tx_hex = txToHex(dbl_tx)
190190

191191
# This will raise an exception due to insufficient fee
@@ -194,7 +194,7 @@ def test_doublespend_chain(self):
194194
# Accepted with sufficient fee
195195
dbl_tx = CTransaction()
196196
dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)]
197-
dbl_tx.vout = [CTxOut(1*COIN, CScript([1]))]
197+
dbl_tx.vout = [CTxOut(1 * COIN, CScript([1] * 35))]
198198
dbl_tx_hex = txToHex(dbl_tx)
199199
self.nodes[0].sendrawtransaction(dbl_tx_hex, True)
200200

@@ -247,15 +247,15 @@ def branch(prevout, initial_value, max_txs, tree_width=5, fee=0.0001*COIN, _tota
247247
# Attempt double-spend, will fail because too little fee paid
248248
dbl_tx = CTransaction()
249249
dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)]
250-
dbl_tx.vout = [CTxOut(initial_nValue - fee*n, CScript([1]))]
250+
dbl_tx.vout = [CTxOut(initial_nValue - fee * n, CScript([1] * 35))]
251251
dbl_tx_hex = txToHex(dbl_tx)
252252
# This will raise an exception due to insufficient fee
253253
assert_raises_rpc_error(-26, "insufficient fee", self.nodes[0].sendrawtransaction, dbl_tx_hex, True)
254254

255255
# 1 BTC fee is enough
256256
dbl_tx = CTransaction()
257257
dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)]
258-
dbl_tx.vout = [CTxOut(initial_nValue - fee*n - 1*COIN, CScript([1]))]
258+
dbl_tx.vout = [CTxOut(initial_nValue - fee * n - 1 * COIN, CScript([1] * 35))]
259259
dbl_tx_hex = txToHex(dbl_tx)
260260
self.nodes[0].sendrawtransaction(dbl_tx_hex, True)
261261

@@ -275,7 +275,7 @@ def branch(prevout, initial_value, max_txs, tree_width=5, fee=0.0001*COIN, _tota
275275

276276
dbl_tx = CTransaction()
277277
dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)]
278-
dbl_tx.vout = [CTxOut(initial_nValue - 2*fee*n, CScript([1]))]
278+
dbl_tx.vout = [CTxOut(initial_nValue - 2 * fee * n, CScript([1] * 35))]
279279
dbl_tx_hex = txToHex(dbl_tx)
280280
# This will raise an exception
281281
assert_raises_rpc_error(-26, "too many potential replacements", self.nodes[0].sendrawtransaction, dbl_tx_hex, True)
@@ -290,7 +290,7 @@ def test_replacement_feeperkb(self):
290290

291291
tx1a = CTransaction()
292292
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)]
293-
tx1a.vout = [CTxOut(1*COIN, CScript([b'a']))]
293+
tx1a.vout = [CTxOut(1 * COIN, CScript([b'a' * 35]))]
294294
tx1a_hex = txToHex(tx1a)
295295
self.nodes[0].sendrawtransaction(tx1a_hex, True)
296296

@@ -311,7 +311,7 @@ def test_spends_of_conflicting_outputs(self):
311311

312312
tx1a = CTransaction()
313313
tx1a.vin = [CTxIn(utxo1, nSequence=0)]
314-
tx1a.vout = [CTxOut(int(1.1*COIN), CScript([b'a']))]
314+
tx1a.vout = [CTxOut(int(1.1 * COIN), CScript([b'a' * 35]))]
315315
tx1a_hex = txToHex(tx1a)
316316
tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, True)
317317

@@ -330,7 +330,7 @@ def test_spends_of_conflicting_outputs(self):
330330
# Spend tx1a's output to test the indirect case.
331331
tx1b = CTransaction()
332332
tx1b.vin = [CTxIn(COutPoint(tx1a_txid, 0), nSequence=0)]
333-
tx1b.vout = [CTxOut(1*COIN, CScript([b'a']))]
333+
tx1b.vout = [CTxOut(1 * COIN, CScript([b'a' * 35]))]
334334
tx1b_hex = txToHex(tx1b)
335335
tx1b_txid = self.nodes[0].sendrawtransaction(tx1b_hex, True)
336336
tx1b_txid = int(tx1b_txid, 16)
@@ -351,7 +351,7 @@ def test_new_unconfirmed_inputs(self):
351351

352352
tx1 = CTransaction()
353353
tx1.vin = [CTxIn(confirmed_utxo)]
354-
tx1.vout = [CTxOut(1*COIN, CScript([b'a']))]
354+
tx1.vout = [CTxOut(1 * COIN, CScript([b'a' * 35]))]
355355
tx1_hex = txToHex(tx1)
356356
self.nodes[0].sendrawtransaction(tx1_hex, True)
357357

@@ -390,7 +390,7 @@ def test_too_many_replacements(self):
390390
for i in range(MAX_REPLACEMENT_LIMIT+1):
391391
tx_i = CTransaction()
392392
tx_i.vin = [CTxIn(COutPoint(txid, i), nSequence=0)]
393-
tx_i.vout = [CTxOut(split_value-fee, CScript([b'a']))]
393+
tx_i.vout = [CTxOut(split_value - fee, CScript([b'a' * 35]))]
394394
tx_i_hex = txToHex(tx_i)
395395
self.nodes[0].sendrawtransaction(tx_i_hex, True)
396396

@@ -423,14 +423,14 @@ def test_opt_in(self):
423423
# Create a non-opting in transaction
424424
tx1a = CTransaction()
425425
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0xffffffff)]
426-
tx1a.vout = [CTxOut(1*COIN, CScript([b'a']))]
426+
tx1a.vout = [CTxOut(1 * COIN, CScript([b'a' * 35]))]
427427
tx1a_hex = txToHex(tx1a)
428428
tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, True)
429429

430430
# Shouldn't be able to double-spend
431431
tx1b = CTransaction()
432432
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
433-
tx1b.vout = [CTxOut(int(0.9*COIN), CScript([b'b']))]
433+
tx1b.vout = [CTxOut(int(0.9 * COIN), CScript([b'b' * 35]))]
434434
tx1b_hex = txToHex(tx1b)
435435

436436
# This will raise an exception
@@ -441,14 +441,14 @@ def test_opt_in(self):
441441
# Create a different non-opting in transaction
442442
tx2a = CTransaction()
443443
tx2a.vin = [CTxIn(tx1_outpoint, nSequence=0xfffffffe)]
444-
tx2a.vout = [CTxOut(1*COIN, CScript([b'a']))]
444+
tx2a.vout = [CTxOut(1 * COIN, CScript([b'a' * 35]))]
445445
tx2a_hex = txToHex(tx2a)
446446
tx2a_txid = self.nodes[0].sendrawtransaction(tx2a_hex, True)
447447

448448
# Still shouldn't be able to double-spend
449449
tx2b = CTransaction()
450450
tx2b.vin = [CTxIn(tx1_outpoint, nSequence=0)]
451-
tx2b.vout = [CTxOut(int(0.9*COIN), CScript([b'b']))]
451+
tx2b.vout = [CTxOut(int(0.9 * COIN), CScript([b'b' * 35]))]
452452
tx2b_hex = txToHex(tx2b)
453453

454454
# This will raise an exception
@@ -471,12 +471,12 @@ def test_opt_in(self):
471471

472472
tx3b = CTransaction()
473473
tx3b.vin = [CTxIn(COutPoint(tx1a_txid, 0), nSequence=0)]
474-
tx3b.vout = [CTxOut(int(0.5*COIN), CScript([b'e']))]
474+
tx3b.vout = [CTxOut(int(0.5 * COIN), CScript([b'e' * 35]))]
475475
tx3b_hex = txToHex(tx3b)
476476

477477
tx3c = CTransaction()
478478
tx3c.vin = [CTxIn(COutPoint(tx2a_txid, 0), nSequence=0)]
479-
tx3c.vout = [CTxOut(int(0.5*COIN), CScript([b'f']))]
479+
tx3c.vout = [CTxOut(int(0.5 * COIN), CScript([b'f' * 35]))]
480480
tx3c_hex = txToHex(tx3c)
481481

482482
self.nodes[0].sendrawtransaction(tx3b_hex, True)
@@ -493,7 +493,7 @@ def test_prioritised_transactions(self):
493493

494494
tx1a = CTransaction()
495495
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)]
496-
tx1a.vout = [CTxOut(1*COIN, CScript([b'a']))]
496+
tx1a.vout = [CTxOut(1 * COIN, CScript([b'a' * 35]))]
497497
tx1a_hex = txToHex(tx1a)
498498
tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, True)
499499

@@ -519,14 +519,14 @@ def test_prioritised_transactions(self):
519519

520520
tx2a = CTransaction()
521521
tx2a.vin = [CTxIn(tx1_outpoint, nSequence=0)]
522-
tx2a.vout = [CTxOut(1*COIN, CScript([b'a']))]
522+
tx2a.vout = [CTxOut(1 * COIN, CScript([b'a' * 35]))]
523523
tx2a_hex = txToHex(tx2a)
524524
self.nodes[0].sendrawtransaction(tx2a_hex, True)
525525

526526
# Lower fee, but we'll prioritise it
527527
tx2b = CTransaction()
528528
tx2b.vin = [CTxIn(tx1_outpoint, nSequence=0)]
529-
tx2b.vout = [CTxOut(int(1.01*COIN), CScript([b'a']))]
529+
tx2b.vout = [CTxOut(int(1.01 * COIN), CScript([b'a' * 35]))]
530530
tx2b.rehash()
531531
tx2b_hex = txToHex(tx2b)
532532

test/functional/feature_segwit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from test_framework.util import *
1717
from test_framework.mininode import sha256, CTransaction, CTxIn, COutPoint, CTxOut, COIN, ToHex, FromHex
1818
from test_framework.address import script_to_p2sh, key_to_p2pkh
19-
from test_framework.script import CScript, OP_HASH160, OP_CHECKSIG, OP_0, hash160, OP_EQUAL, OP_DUP, OP_EQUALVERIFY, OP_1, OP_2, OP_CHECKMULTISIG, OP_TRUE
19+
from test_framework.script import CScript, OP_HASH160, OP_CHECKSIG, OP_0, hash160, OP_EQUAL, OP_DUP, OP_EQUALVERIFY, OP_1, OP_2, OP_CHECKMULTISIG, OP_TRUE, OP_DROP
2020
from io import BytesIO
2121

2222
NODE_0 = 0
@@ -212,7 +212,7 @@ def run_test(self):
212212
# Now create tx2, which will spend from txid1.
213213
tx = CTransaction()
214214
tx.vin.append(CTxIn(COutPoint(int(txid1, 16), 0), b''))
215-
tx.vout.append(CTxOut(int(49.99*COIN), CScript([OP_TRUE])))
215+
tx.vout.append(CTxOut(int(49.99 * COIN), CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
216216
tx2_hex = self.nodes[0].signrawtransactionwithwallet(ToHex(tx))['hex']
217217
txid2 = self.nodes[0].sendrawtransaction(tx2_hex)
218218
tx = FromHex(CTransaction(), tx2_hex)
@@ -221,7 +221,7 @@ def run_test(self):
221221
# Now create tx3, which will spend from txid2
222222
tx = CTransaction()
223223
tx.vin.append(CTxIn(COutPoint(int(txid2, 16), 0), b""))
224-
tx.vout.append(CTxOut(int(49.95*COIN), CScript([OP_TRUE]))) # Huge fee
224+
tx.vout.append(CTxOut(int(49.95 * COIN), CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE]))) # Huge fee
225225
tx.calc_sha256()
226226
txid3 = self.nodes[0].sendrawtransaction(ToHex(tx))
227227
assert(tx.wit.is_null())

test/functional/p2p_compactblocks.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
from test_framework.test_framework import BitcoinTestFramework
1313
from test_framework.util import *
1414
from test_framework.blocktools import create_block, create_coinbase, add_witness_commitment
15-
from test_framework.script import CScript, OP_TRUE
15+
from test_framework.script import CScript, OP_TRUE, OP_DROP
16+
1617

1718
# TestP2PConn: A peer we use to send messages to bitcoind, and store responses.
1819
class TestP2PConn(P2PInterface):
@@ -423,7 +424,7 @@ def build_block_with_transactions(self, node, utxo, num_transactions):
423424
for i in range(num_transactions):
424425
tx = CTransaction()
425426
tx.vin.append(CTxIn(COutPoint(utxo[0], utxo[1]), b''))
426-
tx.vout.append(CTxOut(utxo[2] - 1000, CScript([OP_TRUE])))
427+
tx.vout.append(CTxOut(utxo[2] - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
427428
tx.rehash()
428429
utxo = [tx.sha256, 0, tx.vout[0].nValue]
429430
block.vtx.append(tx)

test/functional/p2p_invalid_tx.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def run_test(self):
7070
# Transaction will be rejected with code 16 (REJECT_INVALID)
7171
# and we get disconnected immediately
7272
self.log.info('Test a transaction that is rejected')
73-
tx1 = create_transaction(block1.vtx[0], 0, b'\x64', 50 * COIN - 12000)
73+
tx1 = create_transaction(block1.vtx[0], 0, b'\x64' * 35, 50 * COIN - 12000)
7474
node.p2p.send_txs_and_test([tx1], node, success=False, expect_disconnect=True)
7575

7676
# Make two p2p connections to provide the node with orphans
@@ -81,32 +81,33 @@ def run_test(self):
8181
self.log.info('Test orphan transaction handling ... ')
8282
# Create a root transaction that we withold until all dependend transactions
8383
# are sent out and in the orphan cache
84+
SCRIPT_PUB_KEY_OP_TRUE = b'\x51\x75' * 15 + b'\x51'
8485
tx_withhold = CTransaction()
8586
tx_withhold.vin.append(CTxIn(outpoint=COutPoint(block1.vtx[0].sha256, 0)))
86-
tx_withhold.vout.append(CTxOut(nValue=50 * COIN - 12000, scriptPubKey=b'\x51'))
87+
tx_withhold.vout.append(CTxOut(nValue=50 * COIN - 12000, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))
8788
tx_withhold.calc_sha256()
8889

8990
# Our first orphan tx with some outputs to create further orphan txs
9091
tx_orphan_1 = CTransaction()
9192
tx_orphan_1.vin.append(CTxIn(outpoint=COutPoint(tx_withhold.sha256, 0)))
92-
tx_orphan_1.vout = [CTxOut(nValue=10 * COIN, scriptPubKey=b'\x51')] * 3
93+
tx_orphan_1.vout = [CTxOut(nValue=10 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE)] * 3
9394
tx_orphan_1.calc_sha256()
9495

9596
# A valid transaction with low fee
9697
tx_orphan_2_no_fee = CTransaction()
9798
tx_orphan_2_no_fee.vin.append(CTxIn(outpoint=COutPoint(tx_orphan_1.sha256, 0)))
98-
tx_orphan_2_no_fee.vout.append(CTxOut(nValue=10 * COIN, scriptPubKey=b'\x51'))
99+
tx_orphan_2_no_fee.vout.append(CTxOut(nValue=10 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))
99100

100101
# A valid transaction with sufficient fee
101102
tx_orphan_2_valid = CTransaction()
102103
tx_orphan_2_valid.vin.append(CTxIn(outpoint=COutPoint(tx_orphan_1.sha256, 1)))
103-
tx_orphan_2_valid.vout.append(CTxOut(nValue=10 * COIN - 12000, scriptPubKey=b'\x51'))
104+
tx_orphan_2_valid.vout.append(CTxOut(nValue=10 * COIN - 12000, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))
104105
tx_orphan_2_valid.calc_sha256()
105106

106107
# An invalid transaction with negative fee
107108
tx_orphan_2_invalid = CTransaction()
108109
tx_orphan_2_invalid.vin.append(CTxIn(outpoint=COutPoint(tx_orphan_1.sha256, 2)))
109-
tx_orphan_2_invalid.vout.append(CTxOut(nValue=11 * COIN, scriptPubKey=b'\x51'))
110+
tx_orphan_2_invalid.vout.append(CTxOut(nValue=11 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))
110111

111112
self.log.info('Send the orphans ... ')
112113
# Send valid orphan txs from p2ps[0]

0 commit comments

Comments
 (0)