@@ -60,6 +60,36 @@ def run_test(self):
60
60
self .nodes [0 ].generate (121 )
61
61
self .sync_all ()
62
62
63
+ self .test_change_position ()
64
+ self .test_simple ()
65
+ self .test_simple_two_coins ()
66
+ self .test_simple_two_outputs ()
67
+ self .test_change ()
68
+ self .test_no_change ()
69
+ self .test_invalid_option ()
70
+ self .test_invalid_change_address ()
71
+ self .test_valid_change_address ()
72
+ self .test_change_type ()
73
+ self .test_coin_selection ()
74
+ self .test_two_vin ()
75
+ self .test_two_vin_two_vout ()
76
+ self .test_invalid_input ()
77
+ self .test_fee_p2pkh ()
78
+ self .test_fee_p2pkh_multi_out ()
79
+ self .test_fee_p2sh ()
80
+ self .test_fee_4of5 ()
81
+ self .test_spend_2of2 ()
82
+ self .test_locked_wallet ()
83
+ self .test_many_inputs_fee ()
84
+ self .test_many_inputs_send ()
85
+ self .test_op_return ()
86
+ self .test_watchonly ()
87
+ self .test_all_watched_funds ()
88
+ self .test_option_feerate ()
89
+ self .test_address_reuse ()
90
+ self .test_option_subtract_fee_from_outputs ()
91
+
92
+ def test_change_position (self ):
63
93
# ensure that setting changePosition in fundraw with an exact match is handled properly
64
94
rawmatch = self .nodes [2 ].createrawtransaction ([], {self .nodes [2 ].getnewaddress ():50 })
65
95
rawmatch = self .nodes [2 ].fundrawtransaction (rawmatch , {"changePosition" :1 , "subtractFeeFromOutputs" :[0 ]})
@@ -84,6 +114,7 @@ def run_test(self):
84
114
self .nodes [0 ].generate (1 )
85
115
self .sync_all ()
86
116
117
+ def test_simple (self ):
87
118
###############
88
119
# simple test #
89
120
###############
@@ -92,10 +123,10 @@ def run_test(self):
92
123
rawtx = self .nodes [2 ].createrawtransaction (inputs , outputs )
93
124
dec_tx = self .nodes [2 ].decoderawtransaction (rawtx )
94
125
rawtxfund = self .nodes [2 ].fundrawtransaction (rawtx )
95
- fee = rawtxfund ['fee' ]
96
126
dec_tx = self .nodes [2 ].decoderawtransaction (rawtxfund ['hex' ])
97
127
assert len (dec_tx ['vin' ]) > 0 #test that we have enough inputs
98
128
129
+ def test_simple_two_coins (self ):
99
130
##############################
100
131
# simple test with two coins #
101
132
##############################
@@ -105,25 +136,11 @@ def run_test(self):
105
136
dec_tx = self .nodes [2 ].decoderawtransaction (rawtx )
106
137
107
138
rawtxfund = self .nodes [2 ].fundrawtransaction (rawtx )
108
- fee = rawtxfund ['fee' ]
109
139
dec_tx = self .nodes [2 ].decoderawtransaction (rawtxfund ['hex' ])
110
140
assert len (dec_tx ['vin' ]) > 0 #test if we have enough inputs
111
-
112
- ##############################
113
- # simple test with two coins #
114
- ##############################
115
- inputs = [ ]
116
- outputs = { self .nodes [0 ].getnewaddress () : 2.6 }
117
- rawtx = self .nodes [2 ].createrawtransaction (inputs , outputs )
118
- dec_tx = self .nodes [2 ].decoderawtransaction (rawtx )
119
-
120
- rawtxfund = self .nodes [2 ].fundrawtransaction (rawtx )
121
- fee = rawtxfund ['fee' ]
122
- dec_tx = self .nodes [2 ].decoderawtransaction (rawtxfund ['hex' ])
123
- assert len (dec_tx ['vin' ]) > 0
124
141
assert_equal (dec_tx ['vin' ][0 ]['scriptSig' ]['hex' ], '' )
125
142
126
-
143
+ def test_simple_two_outputs ( self ):
127
144
################################
128
145
# simple test with two outputs #
129
146
################################
@@ -133,7 +150,6 @@ def run_test(self):
133
150
dec_tx = self .nodes [2 ].decoderawtransaction (rawtx )
134
151
135
152
rawtxfund = self .nodes [2 ].fundrawtransaction (rawtx )
136
- fee = rawtxfund ['fee' ]
137
153
dec_tx = self .nodes [2 ].decoderawtransaction (rawtxfund ['hex' ])
138
154
totalOut = 0
139
155
for out in dec_tx ['vout' ]:
@@ -142,7 +158,7 @@ def run_test(self):
142
158
assert len (dec_tx ['vin' ]) > 0
143
159
assert_equal (dec_tx ['vin' ][0 ]['scriptSig' ]['hex' ], '' )
144
160
145
-
161
+ def test_change ( self ):
146
162
#########################################################################
147
163
# test a fundrawtransaction with a VIN greater than the required amount #
148
164
#########################################################################
@@ -164,7 +180,7 @@ def run_test(self):
164
180
165
181
assert_equal (fee + totalOut , utx ['amount' ]) #compare vin total and totalout+fee
166
182
167
-
183
+ def test_no_change ( self ):
168
184
#####################################################################
169
185
# test a fundrawtransaction with which will not get a change output #
170
186
#####################################################################
@@ -186,7 +202,7 @@ def run_test(self):
186
202
assert_equal (rawtxfund ['changepos' ], - 1 )
187
203
assert_equal (fee + totalOut , utx ['amount' ]) #compare vin total and totalout+fee
188
204
189
-
205
+ def test_invalid_option ( self ):
190
206
####################################################
191
207
# test a fundrawtransaction with an invalid option #
192
208
####################################################
@@ -203,6 +219,7 @@ def run_test(self):
203
219
# reserveChangeKey was deprecated and is now removed
204
220
assert_raises_rpc_error (- 3 , "Unexpected key reserveChangeKey" , lambda : self .nodes [2 ].fundrawtransaction (hexstring = rawtx , options = {'reserveChangeKey' : True }))
205
221
222
+ def test_invalid_change_address (self ):
206
223
############################################################
207
224
# test a fundrawtransaction with an invalid change address #
208
225
############################################################
@@ -216,6 +233,7 @@ def run_test(self):
216
233
217
234
assert_raises_rpc_error (- 5 , "changeAddress must be a valid bitcoin address" , self .nodes [2 ].fundrawtransaction , rawtx , {'changeAddress' :'foobar' })
218
235
236
+ def test_valid_change_address (self ):
219
237
############################################################
220
238
# test a fundrawtransaction with a provided change address #
221
239
############################################################
@@ -234,6 +252,7 @@ def run_test(self):
234
252
out = dec_tx ['vout' ][0 ]
235
253
assert_equal (change , out ['scriptPubKey' ]['addresses' ][0 ])
236
254
255
+ def test_change_type (self ):
237
256
#########################################################
238
257
# test a fundrawtransaction with a provided change type #
239
258
#########################################################
@@ -248,6 +267,7 @@ def run_test(self):
248
267
dec_tx = self .nodes [2 ].decoderawtransaction (rawtx ['hex' ])
249
268
assert_equal ('witness_v0_keyhash' , dec_tx ['vout' ][rawtx ['changepos' ]]['scriptPubKey' ]['type' ])
250
269
270
+ def test_coin_selection (self ):
251
271
#########################################################################
252
272
# test a fundrawtransaction with a VIN smaller than the required amount #
253
273
#########################################################################
@@ -265,7 +285,6 @@ def run_test(self):
265
285
assert_equal ("00" , dec_tx ['vin' ][0 ]['scriptSig' ]['hex' ])
266
286
267
287
rawtxfund = self .nodes [2 ].fundrawtransaction (rawtx )
268
- fee = rawtxfund ['fee' ]
269
288
dec_tx = self .nodes [2 ].decoderawtransaction (rawtxfund ['hex' ])
270
289
totalOut = 0
271
290
matchingOuts = 0
@@ -282,7 +301,7 @@ def run_test(self):
282
301
assert_equal (matchingOuts , 1 )
283
302
assert_equal (len (dec_tx ['vout' ]), 2 )
284
303
285
-
304
+ def test_two_vin ( self ):
286
305
###########################################
287
306
# test a fundrawtransaction with two VINs #
288
307
###########################################
@@ -296,7 +315,6 @@ def run_test(self):
296
315
assert_equal (utx ['txid' ], dec_tx ['vin' ][0 ]['txid' ])
297
316
298
317
rawtxfund = self .nodes [2 ].fundrawtransaction (rawtx )
299
- fee = rawtxfund ['fee' ]
300
318
dec_tx = self .nodes [2 ].decoderawtransaction (rawtxfund ['hex' ])
301
319
totalOut = 0
302
320
matchingOuts = 0
@@ -316,6 +334,7 @@ def run_test(self):
316
334
317
335
assert_equal (matchingIns , 2 ) #we now must see two vins identical to vins given as params
318
336
337
+ def test_two_vin_two_vout (self ):
319
338
#########################################################
320
339
# test a fundrawtransaction with two VINs and two vOUTs #
321
340
#########################################################
@@ -329,7 +348,6 @@ def run_test(self):
329
348
assert_equal (utx ['txid' ], dec_tx ['vin' ][0 ]['txid' ])
330
349
331
350
rawtxfund = self .nodes [2 ].fundrawtransaction (rawtx )
332
- fee = rawtxfund ['fee' ]
333
351
dec_tx = self .nodes [2 ].decoderawtransaction (rawtxfund ['hex' ])
334
352
totalOut = 0
335
353
matchingOuts = 0
@@ -341,16 +359,16 @@ def run_test(self):
341
359
assert_equal (matchingOuts , 2 )
342
360
assert_equal (len (dec_tx ['vout' ]), 3 )
343
361
362
+ def test_invalid_input (self ):
344
363
##############################################
345
364
# test a fundrawtransaction with invalid vin #
346
365
##############################################
347
366
inputs = [ {'txid' : "1c7f966dab21119bac53213a2bc7532bff1fa844c124fd750a7d0b1332440bd1" , 'vout' : 0 } ] #invalid vin!
348
367
outputs = { self .nodes [0 ].getnewaddress () : 1.0 }
349
368
rawtx = self .nodes [2 ].createrawtransaction (inputs , outputs )
350
- dec_tx = self .nodes [2 ].decoderawtransaction (rawtx )
351
-
352
369
assert_raises_rpc_error (- 4 , "Insufficient funds" , self .nodes [2 ].fundrawtransaction , rawtx )
353
370
371
+ def test_fee_p2pkh (self ):
354
372
############################################################
355
373
#compare fee of a standard pubkeyhash transaction
356
374
inputs = []
@@ -367,6 +385,7 @@ def run_test(self):
367
385
assert feeDelta >= 0 and feeDelta <= self .fee_tolerance
368
386
############################################################
369
387
388
+ def test_fee_p2pkh_multi_out (self ):
370
389
############################################################
371
390
#compare fee of a standard pubkeyhash transaction with multiple outputs
372
391
inputs = []
@@ -382,7 +401,7 @@ def run_test(self):
382
401
assert feeDelta >= 0 and feeDelta <= self .fee_tolerance
383
402
############################################################
384
403
385
-
404
+ def test_fee_p2sh ( self ):
386
405
############################################################
387
406
#compare fee of a 2of2 multisig p2sh transaction
388
407
@@ -409,7 +428,7 @@ def run_test(self):
409
428
assert feeDelta >= 0 and feeDelta <= self .fee_tolerance
410
429
############################################################
411
430
412
-
431
+ def test_fee_4of5 ( self ):
413
432
############################################################
414
433
#compare fee of a standard pubkeyhash transaction
415
434
@@ -442,7 +461,7 @@ def run_test(self):
442
461
assert feeDelta >= 0 and feeDelta <= self .fee_tolerance
443
462
############################################################
444
463
445
-
464
+ def test_spend_2of2 ( self ):
446
465
############################################################
447
466
# spend a 2of2 multisig transaction over fundraw
448
467
@@ -457,7 +476,7 @@ def run_test(self):
457
476
458
477
459
478
# send 1.2 BTC to msig addr
460
- txId = self .nodes [0 ].sendtoaddress (mSigObj , 1.2 )
479
+ self .nodes [0 ].sendtoaddress (mSigObj , 1.2 )
461
480
self .sync_all ()
462
481
self .nodes [1 ].generate (1 )
463
482
self .sync_all ()
@@ -469,14 +488,15 @@ def run_test(self):
469
488
fundedTx = self .nodes [2 ].fundrawtransaction (rawtx )
470
489
471
490
signedTx = self .nodes [2 ].signrawtransactionwithwallet (fundedTx ['hex' ])
472
- txId = self .nodes [2 ].sendrawtransaction (signedTx ['hex' ])
491
+ self .nodes [2 ].sendrawtransaction (signedTx ['hex' ])
473
492
self .sync_all ()
474
493
self .nodes [1 ].generate (1 )
475
494
self .sync_all ()
476
495
477
496
# make sure funds are received at node1
478
497
assert_equal (oldBalance + Decimal ('1.10000000' ), self .nodes [1 ].getbalance ())
479
498
499
+ def test_locked_wallet (self ):
480
500
############################################################
481
501
# locked wallet test
482
502
self .nodes [1 ].encryptwallet ("test" )
@@ -524,14 +544,14 @@ def run_test(self):
524
544
#now we need to unlock
525
545
self .nodes [1 ].walletpassphrase ("test" , 600 )
526
546
signedTx = self .nodes [1 ].signrawtransactionwithwallet (fundedTx ['hex' ])
527
- txId = self .nodes [1 ].sendrawtransaction (signedTx ['hex' ])
547
+ self .nodes [1 ].sendrawtransaction (signedTx ['hex' ])
528
548
self .nodes [1 ].generate (1 )
529
549
self .sync_all ()
530
550
531
551
# make sure funds are received at node1
532
552
assert_equal (oldBalance + Decimal ('51.10000000' ), self .nodes [0 ].getbalance ())
533
553
534
-
554
+ def test_many_inputs_fee ( self ):
535
555
###############################################
536
556
# multiple (~19) inputs tx test | Compare fee #
537
557
###############################################
@@ -561,7 +581,7 @@ def run_test(self):
561
581
feeDelta = Decimal (fundedTx ['fee' ]) - Decimal (signedFee )
562
582
assert feeDelta >= 0 and feeDelta <= self .fee_tolerance * 19 #~19 inputs
563
583
564
-
584
+ def test_many_inputs_send ( self ):
565
585
#############################################
566
586
# multiple (~19) inputs tx test | sign/send #
567
587
#############################################
@@ -585,12 +605,13 @@ def run_test(self):
585
605
rawtx = self .nodes [1 ].createrawtransaction (inputs , outputs )
586
606
fundedTx = self .nodes [1 ].fundrawtransaction (rawtx )
587
607
fundedAndSignedTx = self .nodes [1 ].signrawtransactionwithwallet (fundedTx ['hex' ])
588
- txId = self .nodes [1 ].sendrawtransaction (fundedAndSignedTx ['hex' ])
608
+ self .nodes [1 ].sendrawtransaction (fundedAndSignedTx ['hex' ])
589
609
self .sync_all ()
590
610
self .nodes [0 ].generate (1 )
591
611
self .sync_all ()
592
612
assert_equal (oldBalance + Decimal ('50.19000000' ), self .nodes [0 ].getbalance ()) #0.19+block reward
593
613
614
+ def test_op_return (self ):
594
615
#####################################################
595
616
# test fundrawtransaction with OP_RETURN and no vin #
596
617
#####################################################
@@ -607,7 +628,7 @@ def run_test(self):
607
628
assert_greater_than (len (dec_tx ['vin' ]), 0 ) # at least one vin
608
629
assert_equal (len (dec_tx ['vout' ]), 2 ) # one change output added
609
630
610
-
631
+ def test_watchonly ( self ):
611
632
##################################################
612
633
# test a fundrawtransaction using only watchonly #
613
634
##################################################
@@ -624,6 +645,7 @@ def run_test(self):
624
645
assert "fee" in result .keys ()
625
646
assert_greater_than (result ["changepos" ], - 1 )
626
647
648
+ def test_all_watched_funds (self ):
627
649
###############################################################
628
650
# test fundrawtransaction using the entirety of watched funds #
629
651
###############################################################
@@ -650,6 +672,7 @@ def run_test(self):
650
672
self .nodes [0 ].generate (1 )
651
673
self .sync_all ()
652
674
675
+ def test_option_feerate (self ):
653
676
#######################
654
677
# Test feeRate option #
655
678
#######################
@@ -668,6 +691,7 @@ def run_test(self):
668
691
assert_fee_amount (result2 ['fee' ], count_bytes (result2 ['hex' ]), 2 * result_fee_rate )
669
692
assert_fee_amount (result3 ['fee' ], count_bytes (result3 ['hex' ]), 10 * result_fee_rate )
670
693
694
+ def test_address_reuse (self ):
671
695
################################
672
696
# Test no address reuse occurs #
673
697
################################
@@ -684,6 +708,7 @@ def run_test(self):
684
708
# Now the change address key should be removed from the keypool
685
709
assert changeaddress != nextaddr
686
710
711
+ def test_option_subtract_fee_from_outputs (self ):
687
712
######################################
688
713
# Test subtractFeeFromOutputs option #
689
714
######################################
0 commit comments