10
10
from test_framework .script import CScript , OP_DROP
11
11
from test_framework .test_framework import BitcoinTestFramework
12
12
from test_framework .util import assert_equal , assert_raises_rpc_error , satoshi_round
13
+ from test_framework .script_util import DUMMY_P2WPKH_SCRIPT
13
14
14
15
MAX_REPLACEMENT_LIMIT = 100
15
16
16
17
def txToHex (tx ):
17
18
return tx .serialize ().hex ()
18
19
19
- def make_utxo (node , amount , confirmed = True , scriptPubKey = CScript ([ 1 ]) ):
20
+ def make_utxo (node , amount , confirmed = True , scriptPubKey = DUMMY_P2WPKH_SCRIPT ):
20
21
"""Create a txout with a given amount and scriptPubKey
21
22
22
23
Mines coins as needed.
@@ -65,7 +66,6 @@ def make_utxo(node, amount, confirmed=True, scriptPubKey=CScript([1])):
65
66
class ReplaceByFeeTest (BitcoinTestFramework ):
66
67
def set_test_params (self ):
67
68
self .num_nodes = 1
68
- # TODO remove output type argument and fix resulting "tx-size-small" errors
69
69
self .extra_args = [
70
70
[
71
71
"-acceptnonstdtxn=1" ,
@@ -74,7 +74,6 @@ def set_test_params(self):
74
74
"-limitancestorsize=101" ,
75
75
"-limitdescendantcount=200" ,
76
76
"-limitdescendantsize=101" ,
77
- "-addresstype=p2sh-segwit" ,
78
77
],
79
78
]
80
79
@@ -133,7 +132,7 @@ def test_simple_doublespend(self):
133
132
134
133
tx1a = CTransaction ()
135
134
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 )]
137
136
tx1a_hex = txToHex (tx1a )
138
137
tx1a_txid = self .nodes [0 ].sendrawtransaction (tx1a_hex , 0 )
139
138
@@ -142,7 +141,7 @@ def test_simple_doublespend(self):
142
141
# Should fail because we haven't changed the fee
143
142
tx1b = CTransaction ()
144
143
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' )]
146
145
tx1b_hex = txToHex (tx1b )
147
146
148
147
# This will raise an exception due to insufficient fee
@@ -151,7 +150,7 @@ def test_simple_doublespend(self):
151
150
# Extra 0.1 BTC fee
152
151
tx1b = CTransaction ()
153
152
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 )]
155
154
tx1b_hex = txToHex (tx1b )
156
155
# Works when enabled
157
156
tx1b_txid = self .nodes [0 ].sendrawtransaction (tx1b_hex , 0 )
@@ -186,7 +185,7 @@ def test_doublespend_chain(self):
186
185
# child fees - 40 BTC - so this attempt is rejected.
187
186
dbl_tx = CTransaction ()
188
187
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 )]
190
189
dbl_tx_hex = txToHex (dbl_tx )
191
190
192
191
# This will raise an exception due to insufficient fee
@@ -195,7 +194,7 @@ def test_doublespend_chain(self):
195
194
# Accepted with sufficient fee
196
195
dbl_tx = CTransaction ()
197
196
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 )]
199
198
dbl_tx_hex = txToHex (dbl_tx )
200
199
self .nodes [0 ].sendrawtransaction (dbl_tx_hex , 0 )
201
200
@@ -248,15 +247,15 @@ def branch(prevout, initial_value, max_txs, tree_width=5, fee=0.0001*COIN, _tota
248
247
# Attempt double-spend, will fail because too little fee paid
249
248
dbl_tx = CTransaction ()
250
249
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 )]
252
251
dbl_tx_hex = txToHex (dbl_tx )
253
252
# This will raise an exception due to insufficient fee
254
253
assert_raises_rpc_error (- 26 , "insufficient fee" , self .nodes [0 ].sendrawtransaction , dbl_tx_hex , 0 )
255
254
256
255
# 1 BTC fee is enough
257
256
dbl_tx = CTransaction ()
258
257
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 )]
260
259
dbl_tx_hex = txToHex (dbl_tx )
261
260
self .nodes [0 ].sendrawtransaction (dbl_tx_hex , 0 )
262
261
@@ -276,7 +275,7 @@ def branch(prevout, initial_value, max_txs, tree_width=5, fee=0.0001*COIN, _tota
276
275
277
276
dbl_tx = CTransaction ()
278
277
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 )]
280
279
dbl_tx_hex = txToHex (dbl_tx )
281
280
# This will raise an exception
282
281
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):
291
290
292
291
tx1a = CTransaction ()
293
292
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 )]
295
294
tx1a_hex = txToHex (tx1a )
296
295
self .nodes [0 ].sendrawtransaction (tx1a_hex , 0 )
297
296
@@ -312,7 +311,7 @@ def test_spends_of_conflicting_outputs(self):
312
311
313
312
tx1a = CTransaction ()
314
313
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 )]
316
315
tx1a_hex = txToHex (tx1a )
317
316
tx1a_txid = self .nodes [0 ].sendrawtransaction (tx1a_hex , 0 )
318
317
@@ -331,7 +330,7 @@ def test_spends_of_conflicting_outputs(self):
331
330
# Spend tx1a's output to test the indirect case.
332
331
tx1b = CTransaction ()
333
332
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 )]
335
334
tx1b_hex = txToHex (tx1b )
336
335
tx1b_txid = self .nodes [0 ].sendrawtransaction (tx1b_hex , 0 )
337
336
tx1b_txid = int (tx1b_txid , 16 )
@@ -352,7 +351,7 @@ def test_new_unconfirmed_inputs(self):
352
351
353
352
tx1 = CTransaction ()
354
353
tx1 .vin = [CTxIn (confirmed_utxo )]
355
- tx1 .vout = [CTxOut (1 * COIN , CScript ([ b'a' * 35 ]) )]
354
+ tx1 .vout = [CTxOut (1 * COIN , DUMMY_P2WPKH_SCRIPT )]
356
355
tx1_hex = txToHex (tx1 )
357
356
self .nodes [0 ].sendrawtransaction (tx1_hex , 0 )
358
357
@@ -391,7 +390,7 @@ def test_too_many_replacements(self):
391
390
for i in range (MAX_REPLACEMENT_LIMIT + 1 ):
392
391
tx_i = CTransaction ()
393
392
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 )]
395
394
tx_i_hex = txToHex (tx_i )
396
395
self .nodes [0 ].sendrawtransaction (tx_i_hex , 0 )
397
396
@@ -424,7 +423,7 @@ def test_opt_in(self):
424
423
# Create a non-opting in transaction
425
424
tx1a = CTransaction ()
426
425
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 )]
428
427
tx1a_hex = txToHex (tx1a )
429
428
tx1a_txid = self .nodes [0 ].sendrawtransaction (tx1a_hex , 0 )
430
429
@@ -434,7 +433,7 @@ def test_opt_in(self):
434
433
# Shouldn't be able to double-spend
435
434
tx1b = CTransaction ()
436
435
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 )]
438
437
tx1b_hex = txToHex (tx1b )
439
438
440
439
# This will raise an exception
@@ -445,14 +444,14 @@ def test_opt_in(self):
445
444
# Create a different non-opting in transaction
446
445
tx2a = CTransaction ()
447
446
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 )]
449
448
tx2a_hex = txToHex (tx2a )
450
449
tx2a_txid = self .nodes [0 ].sendrawtransaction (tx2a_hex , 0 )
451
450
452
451
# Still shouldn't be able to double-spend
453
452
tx2b = CTransaction ()
454
453
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 )]
456
455
tx2b_hex = txToHex (tx2b )
457
456
458
457
# This will raise an exception
@@ -478,12 +477,12 @@ def test_opt_in(self):
478
477
479
478
tx3b = CTransaction ()
480
479
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 )]
482
481
tx3b_hex = txToHex (tx3b )
483
482
484
483
tx3c = CTransaction ()
485
484
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 )]
487
486
tx3c_hex = txToHex (tx3c )
488
487
489
488
self .nodes [0 ].sendrawtransaction (tx3b_hex , 0 )
@@ -500,7 +499,7 @@ def test_prioritised_transactions(self):
500
499
501
500
tx1a = CTransaction ()
502
501
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 )]
504
503
tx1a_hex = txToHex (tx1a )
505
504
tx1a_txid = self .nodes [0 ].sendrawtransaction (tx1a_hex , 0 )
506
505
@@ -526,14 +525,14 @@ def test_prioritised_transactions(self):
526
525
527
526
tx2a = CTransaction ()
528
527
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 )]
530
529
tx2a_hex = txToHex (tx2a )
531
530
self .nodes [0 ].sendrawtransaction (tx2a_hex , 0 )
532
531
533
532
# Lower fee, but we'll prioritise it
534
533
tx2b = CTransaction ()
535
534
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 )]
537
536
tx2b .rehash ()
538
537
tx2b_hex = txToHex (tx2b )
539
538
0 commit comments