1010from test_framework .script import CScript , OP_DROP
1111from test_framework .test_framework import BitcoinTestFramework
1212from test_framework .util import assert_equal , assert_raises_rpc_error , satoshi_round
13+ from test_framework .script_util import DUMMY_P2WPKH_SCRIPT
1314
1415MAX_REPLACEMENT_LIMIT = 100
1516
1617def txToHex (tx ):
1718 return tx .serialize ().hex ()
1819
19- def make_utxo (node , amount , confirmed = True , scriptPubKey = CScript ([ 1 ]) ):
20+ def make_utxo (node , amount , confirmed = True , scriptPubKey = DUMMY_P2WPKH_SCRIPT ):
2021 """Create a txout with a given amount and scriptPubKey
2122
2223 Mines coins as needed.
@@ -65,7 +66,6 @@ def make_utxo(node, amount, confirmed=True, scriptPubKey=CScript([1])):
6566class ReplaceByFeeTest (BitcoinTestFramework ):
6667 def set_test_params (self ):
6768 self .num_nodes = 1
68- # TODO remove output type argument and fix resulting "tx-size-small" errors
6969 self .extra_args = [
7070 [
7171 "-acceptnonstdtxn=1" ,
@@ -74,7 +74,6 @@ def set_test_params(self):
7474 "-limitancestorsize=101" ,
7575 "-limitdescendantcount=200" ,
7676 "-limitdescendantsize=101" ,
77- "-addresstype=p2sh-segwit" ,
7877 ],
7978 ]
8079
@@ -133,7 +132,7 @@ def test_simple_doublespend(self):
133132
134133 tx1a = CTransaction ()
135134 tx1a .vin = [CTxIn (tx0_outpoint , nSequence = 0 )]
136- tx1a .vout = [CTxOut (1 * COIN , CScript ([ b'a' * 35 ]) )]
135+ tx1a .vout = [CTxOut (1 * COIN , DUMMY_P2WPKH_SCRIPT )]
137136 tx1a_hex = txToHex (tx1a )
138137 tx1a_txid = self .nodes [0 ].sendrawtransaction (tx1a_hex , 0 )
139138
@@ -142,7 +141,7 @@ def test_simple_doublespend(self):
142141 # Should fail because we haven't changed the fee
143142 tx1b = CTransaction ()
144143 tx1b .vin = [CTxIn (tx0_outpoint , nSequence = 0 )]
145- tx1b .vout = [CTxOut (1 * COIN , CScript ([ b'b' * 35 ]) )]
144+ tx1b .vout = [CTxOut (1 * COIN , DUMMY_P2WPKH_SCRIPT + b'a' )]
146145 tx1b_hex = txToHex (tx1b )
147146
148147 # This will raise an exception due to insufficient fee
@@ -151,7 +150,7 @@ def test_simple_doublespend(self):
151150 # Extra 0.1 BTC fee
152151 tx1b = CTransaction ()
153152 tx1b .vin = [CTxIn (tx0_outpoint , nSequence = 0 )]
154- tx1b .vout = [CTxOut (int (0.9 * COIN ), CScript ([ b'b' * 35 ]) )]
153+ tx1b .vout = [CTxOut (int (0.9 * COIN ), DUMMY_P2WPKH_SCRIPT )]
155154 tx1b_hex = txToHex (tx1b )
156155 # Works when enabled
157156 tx1b_txid = self .nodes [0 ].sendrawtransaction (tx1b_hex , 0 )
@@ -186,7 +185,7 @@ def test_doublespend_chain(self):
186185 # child fees - 40 BTC - so this attempt is rejected.
187186 dbl_tx = CTransaction ()
188187 dbl_tx .vin = [CTxIn (tx0_outpoint , nSequence = 0 )]
189- dbl_tx .vout = [CTxOut (initial_nValue - 30 * COIN , CScript ([ 1 ] * 35 ) )]
188+ dbl_tx .vout = [CTxOut (initial_nValue - 30 * COIN , DUMMY_P2WPKH_SCRIPT )]
190189 dbl_tx_hex = txToHex (dbl_tx )
191190
192191 # This will raise an exception due to insufficient fee
@@ -195,7 +194,7 @@ def test_doublespend_chain(self):
195194 # Accepted with sufficient fee
196195 dbl_tx = CTransaction ()
197196 dbl_tx .vin = [CTxIn (tx0_outpoint , nSequence = 0 )]
198- dbl_tx .vout = [CTxOut (1 * COIN , CScript ([ 1 ] * 35 ) )]
197+ dbl_tx .vout = [CTxOut (1 * COIN , DUMMY_P2WPKH_SCRIPT )]
199198 dbl_tx_hex = txToHex (dbl_tx )
200199 self .nodes [0 ].sendrawtransaction (dbl_tx_hex , 0 )
201200
@@ -248,15 +247,15 @@ def branch(prevout, initial_value, max_txs, tree_width=5, fee=0.0001*COIN, _tota
248247 # Attempt double-spend, will fail because too little fee paid
249248 dbl_tx = CTransaction ()
250249 dbl_tx .vin = [CTxIn (tx0_outpoint , nSequence = 0 )]
251- dbl_tx .vout = [CTxOut (initial_nValue - fee * n , CScript ([ 1 ] * 35 ) )]
250+ dbl_tx .vout = [CTxOut (initial_nValue - fee * n , DUMMY_P2WPKH_SCRIPT )]
252251 dbl_tx_hex = txToHex (dbl_tx )
253252 # This will raise an exception due to insufficient fee
254253 assert_raises_rpc_error (- 26 , "insufficient fee" , self .nodes [0 ].sendrawtransaction , dbl_tx_hex , 0 )
255254
256255 # 1 BTC fee is enough
257256 dbl_tx = CTransaction ()
258257 dbl_tx .vin = [CTxIn (tx0_outpoint , nSequence = 0 )]
259- dbl_tx .vout = [CTxOut (initial_nValue - fee * n - 1 * COIN , CScript ([ 1 ] * 35 ) )]
258+ dbl_tx .vout = [CTxOut (initial_nValue - fee * n - 1 * COIN , DUMMY_P2WPKH_SCRIPT )]
260259 dbl_tx_hex = txToHex (dbl_tx )
261260 self .nodes [0 ].sendrawtransaction (dbl_tx_hex , 0 )
262261
@@ -276,7 +275,7 @@ def branch(prevout, initial_value, max_txs, tree_width=5, fee=0.0001*COIN, _tota
276275
277276 dbl_tx = CTransaction ()
278277 dbl_tx .vin = [CTxIn (tx0_outpoint , nSequence = 0 )]
279- dbl_tx .vout = [CTxOut (initial_nValue - 2 * fee * n , CScript ([ 1 ] * 35 ) )]
278+ dbl_tx .vout = [CTxOut (initial_nValue - 2 * fee * n , DUMMY_P2WPKH_SCRIPT )]
280279 dbl_tx_hex = txToHex (dbl_tx )
281280 # This will raise an exception
282281 assert_raises_rpc_error (- 26 , "too many potential replacements" , self .nodes [0 ].sendrawtransaction , dbl_tx_hex , 0 )
@@ -291,7 +290,7 @@ def test_replacement_feeperkb(self):
291290
292291 tx1a = CTransaction ()
293292 tx1a .vin = [CTxIn (tx0_outpoint , nSequence = 0 )]
294- tx1a .vout = [CTxOut (1 * COIN , CScript ([ b'a' * 35 ]) )]
293+ tx1a .vout = [CTxOut (1 * COIN , DUMMY_P2WPKH_SCRIPT )]
295294 tx1a_hex = txToHex (tx1a )
296295 self .nodes [0 ].sendrawtransaction (tx1a_hex , 0 )
297296
@@ -312,7 +311,7 @@ def test_spends_of_conflicting_outputs(self):
312311
313312 tx1a = CTransaction ()
314313 tx1a .vin = [CTxIn (utxo1 , nSequence = 0 )]
315- tx1a .vout = [CTxOut (int (1.1 * COIN ), CScript ([ b'a' * 35 ]) )]
314+ tx1a .vout = [CTxOut (int (1.1 * COIN ), DUMMY_P2WPKH_SCRIPT )]
316315 tx1a_hex = txToHex (tx1a )
317316 tx1a_txid = self .nodes [0 ].sendrawtransaction (tx1a_hex , 0 )
318317
@@ -331,7 +330,7 @@ def test_spends_of_conflicting_outputs(self):
331330 # Spend tx1a's output to test the indirect case.
332331 tx1b = CTransaction ()
333332 tx1b .vin = [CTxIn (COutPoint (tx1a_txid , 0 ), nSequence = 0 )]
334- tx1b .vout = [CTxOut (1 * COIN , CScript ([ b'a' * 35 ]) )]
333+ tx1b .vout = [CTxOut (1 * COIN , DUMMY_P2WPKH_SCRIPT )]
335334 tx1b_hex = txToHex (tx1b )
336335 tx1b_txid = self .nodes [0 ].sendrawtransaction (tx1b_hex , 0 )
337336 tx1b_txid = int (tx1b_txid , 16 )
@@ -352,7 +351,7 @@ def test_new_unconfirmed_inputs(self):
352351
353352 tx1 = CTransaction ()
354353 tx1 .vin = [CTxIn (confirmed_utxo )]
355- tx1 .vout = [CTxOut (1 * COIN , CScript ([ b'a' * 35 ]) )]
354+ tx1 .vout = [CTxOut (1 * COIN , DUMMY_P2WPKH_SCRIPT )]
356355 tx1_hex = txToHex (tx1 )
357356 self .nodes [0 ].sendrawtransaction (tx1_hex , 0 )
358357
@@ -391,7 +390,7 @@ def test_too_many_replacements(self):
391390 for i in range (MAX_REPLACEMENT_LIMIT + 1 ):
392391 tx_i = CTransaction ()
393392 tx_i .vin = [CTxIn (COutPoint (txid , i ), nSequence = 0 )]
394- tx_i .vout = [CTxOut (split_value - fee , CScript ([ b'a' * 35 ]) )]
393+ tx_i .vout = [CTxOut (split_value - fee , DUMMY_P2WPKH_SCRIPT )]
395394 tx_i_hex = txToHex (tx_i )
396395 self .nodes [0 ].sendrawtransaction (tx_i_hex , 0 )
397396
@@ -424,7 +423,7 @@ def test_opt_in(self):
424423 # Create a non-opting in transaction
425424 tx1a = CTransaction ()
426425 tx1a .vin = [CTxIn (tx0_outpoint , nSequence = 0xffffffff )]
427- tx1a .vout = [CTxOut (1 * COIN , CScript ([ b'a' * 35 ]) )]
426+ tx1a .vout = [CTxOut (1 * COIN , DUMMY_P2WPKH_SCRIPT )]
428427 tx1a_hex = txToHex (tx1a )
429428 tx1a_txid = self .nodes [0 ].sendrawtransaction (tx1a_hex , 0 )
430429
@@ -434,7 +433,7 @@ def test_opt_in(self):
434433 # Shouldn't be able to double-spend
435434 tx1b = CTransaction ()
436435 tx1b .vin = [CTxIn (tx0_outpoint , nSequence = 0 )]
437- tx1b .vout = [CTxOut (int (0.9 * COIN ), CScript ([ b'b' * 35 ]) )]
436+ tx1b .vout = [CTxOut (int (0.9 * COIN ), DUMMY_P2WPKH_SCRIPT )]
438437 tx1b_hex = txToHex (tx1b )
439438
440439 # This will raise an exception
@@ -445,14 +444,14 @@ def test_opt_in(self):
445444 # Create a different non-opting in transaction
446445 tx2a = CTransaction ()
447446 tx2a .vin = [CTxIn (tx1_outpoint , nSequence = 0xfffffffe )]
448- tx2a .vout = [CTxOut (1 * COIN , CScript ([ b'a' * 35 ]) )]
447+ tx2a .vout = [CTxOut (1 * COIN , DUMMY_P2WPKH_SCRIPT )]
449448 tx2a_hex = txToHex (tx2a )
450449 tx2a_txid = self .nodes [0 ].sendrawtransaction (tx2a_hex , 0 )
451450
452451 # Still shouldn't be able to double-spend
453452 tx2b = CTransaction ()
454453 tx2b .vin = [CTxIn (tx1_outpoint , nSequence = 0 )]
455- tx2b .vout = [CTxOut (int (0.9 * COIN ), CScript ([ b'b' * 35 ]) )]
454+ tx2b .vout = [CTxOut (int (0.9 * COIN ), DUMMY_P2WPKH_SCRIPT )]
456455 tx2b_hex = txToHex (tx2b )
457456
458457 # This will raise an exception
@@ -478,12 +477,12 @@ def test_opt_in(self):
478477
479478 tx3b = CTransaction ()
480479 tx3b .vin = [CTxIn (COutPoint (tx1a_txid , 0 ), nSequence = 0 )]
481- tx3b .vout = [CTxOut (int (0.5 * COIN ), CScript ([ b'e' * 35 ]) )]
480+ tx3b .vout = [CTxOut (int (0.5 * COIN ), DUMMY_P2WPKH_SCRIPT )]
482481 tx3b_hex = txToHex (tx3b )
483482
484483 tx3c = CTransaction ()
485484 tx3c .vin = [CTxIn (COutPoint (tx2a_txid , 0 ), nSequence = 0 )]
486- tx3c .vout = [CTxOut (int (0.5 * COIN ), CScript ([ b'f' * 35 ]) )]
485+ tx3c .vout = [CTxOut (int (0.5 * COIN ), DUMMY_P2WPKH_SCRIPT )]
487486 tx3c_hex = txToHex (tx3c )
488487
489488 self .nodes [0 ].sendrawtransaction (tx3b_hex , 0 )
@@ -500,7 +499,7 @@ def test_prioritised_transactions(self):
500499
501500 tx1a = CTransaction ()
502501 tx1a .vin = [CTxIn (tx0_outpoint , nSequence = 0 )]
503- tx1a .vout = [CTxOut (1 * COIN , CScript ([ b'a' * 35 ]) )]
502+ tx1a .vout = [CTxOut (1 * COIN , DUMMY_P2WPKH_SCRIPT )]
504503 tx1a_hex = txToHex (tx1a )
505504 tx1a_txid = self .nodes [0 ].sendrawtransaction (tx1a_hex , 0 )
506505
@@ -526,14 +525,14 @@ def test_prioritised_transactions(self):
526525
527526 tx2a = CTransaction ()
528527 tx2a .vin = [CTxIn (tx1_outpoint , nSequence = 0 )]
529- tx2a .vout = [CTxOut (1 * COIN , CScript ([ b'a' * 35 ]) )]
528+ tx2a .vout = [CTxOut (1 * COIN , DUMMY_P2WPKH_SCRIPT )]
530529 tx2a_hex = txToHex (tx2a )
531530 self .nodes [0 ].sendrawtransaction (tx2a_hex , 0 )
532531
533532 # Lower fee, but we'll prioritise it
534533 tx2b = CTransaction ()
535534 tx2b .vin = [CTxIn (tx1_outpoint , nSequence = 0 )]
536- tx2b .vout = [CTxOut (int (1.01 * COIN ), CScript ([ b'a' * 35 ]) )]
535+ tx2b .vout = [CTxOut (int (1.01 * COIN ), DUMMY_P2WPKH_SCRIPT )]
537536 tx2b .rehash ()
538537 tx2b_hex = txToHex (tx2b )
539538
0 commit comments