6
6
from test_framework .test_framework import BitcoinTestFramework
7
7
from test_framework .util import *
8
8
9
- # Create one-input, one-output, no-fee transaction:
9
+
10
+ def get_unspent (listunspent , amount ):
11
+ for utx in listunspent :
12
+ if utx ['amount' ] == amount :
13
+ return utx
14
+ raise AssertionError ('Could not find unspent with amount={}' .format (amount ))
15
+
16
+
10
17
class RawTransactionsTest (BitcoinTestFramework ):
11
18
12
19
def __init__ (self ):
@@ -71,7 +78,7 @@ def run_test(self):
71
78
rawtxfund = self .nodes [2 ].fundrawtransaction (rawtx )
72
79
fee = rawtxfund ['fee' ]
73
80
dec_tx = self .nodes [2 ].decoderawtransaction (rawtxfund ['hex' ])
74
- assert (len (dec_tx ['vin' ]) > 0 ) #test if we have enought inputs
81
+ assert (len (dec_tx ['vin' ]) > 0 ) #test that we have enough inputs
75
82
76
83
##############################
77
84
# simple test with two coins #
@@ -123,14 +130,7 @@ def run_test(self):
123
130
#########################################################################
124
131
# test a fundrawtransaction with a VIN greater than the required amount #
125
132
#########################################################################
126
- utx = False
127
- listunspent = self .nodes [2 ].listunspent ()
128
- for aUtx in listunspent :
129
- if aUtx ['amount' ] == 5.0 :
130
- utx = aUtx
131
- break
132
-
133
- assert (utx != False )
133
+ utx = get_unspent (self .nodes [2 ].listunspent (), 5 )
134
134
135
135
inputs = [ {'txid' : utx ['txid' ], 'vout' : utx ['vout' ]}]
136
136
outputs = { self .nodes [0 ].getnewaddress () : 1.0 }
@@ -151,14 +151,7 @@ def run_test(self):
151
151
#####################################################################
152
152
# test a fundrawtransaction with which will not get a change output #
153
153
#####################################################################
154
- utx = False
155
- listunspent = self .nodes [2 ].listunspent ()
156
- for aUtx in listunspent :
157
- if aUtx ['amount' ] == 5.0 :
158
- utx = aUtx
159
- break
160
-
161
- assert (utx != False )
154
+ utx = get_unspent (self .nodes [2 ].listunspent (), 5 )
162
155
163
156
inputs = [ {'txid' : utx ['txid' ], 'vout' : utx ['vout' ]}]
164
157
outputs = { self .nodes [0 ].getnewaddress () : Decimal (5.0 ) - fee - feeTolerance }
@@ -180,14 +173,7 @@ def run_test(self):
180
173
####################################################
181
174
# test a fundrawtransaction with an invalid option #
182
175
####################################################
183
- utx = False
184
- listunspent = self .nodes [2 ].listunspent ()
185
- for aUtx in listunspent :
186
- if aUtx ['amount' ] == 5.0 :
187
- utx = aUtx
188
- break
189
-
190
- assert_equal (utx != False , True )
176
+ utx = get_unspent (self .nodes [2 ].listunspent (), 5 )
191
177
192
178
inputs = [ {'txid' : utx ['txid' ], 'vout' : utx ['vout' ]} ]
193
179
outputs = { self .nodes [0 ].getnewaddress () : Decimal (4.0 ) }
@@ -205,14 +191,7 @@ def run_test(self):
205
191
############################################################
206
192
# test a fundrawtransaction with an invalid change address #
207
193
############################################################
208
- utx = False
209
- listunspent = self .nodes [2 ].listunspent ()
210
- for aUtx in listunspent :
211
- if aUtx ['amount' ] == 5.0 :
212
- utx = aUtx
213
- break
214
-
215
- assert_equal (utx != False , True )
194
+ utx = get_unspent (self .nodes [2 ].listunspent (), 5 )
216
195
217
196
inputs = [ {'txid' : utx ['txid' ], 'vout' : utx ['vout' ]} ]
218
197
outputs = { self .nodes [0 ].getnewaddress () : Decimal (4.0 ) }
@@ -227,18 +206,10 @@ def run_test(self):
227
206
assert ("changeAddress must be a valid bitcoin address" in e .error ['message' ])
228
207
229
208
230
-
231
209
############################################################
232
210
# test a fundrawtransaction with a provided change address #
233
211
############################################################
234
- utx = False
235
- listunspent = self .nodes [2 ].listunspent ()
236
- for aUtx in listunspent :
237
- if aUtx ['amount' ] == 5.0 :
238
- utx = aUtx
239
- break
240
-
241
- assert_equal (utx != False , True )
212
+ utx = get_unspent (self .nodes [2 ].listunspent (), 5 )
242
213
243
214
inputs = [ {'txid' : utx ['txid' ], 'vout' : utx ['vout' ]} ]
244
215
outputs = { self .nodes [0 ].getnewaddress () : Decimal (4.0 ) }
@@ -259,18 +230,10 @@ def run_test(self):
259
230
assert_equal (change , out ['scriptPubKey' ]['addresses' ][0 ])
260
231
261
232
262
-
263
233
#########################################################################
264
234
# test a fundrawtransaction with a VIN smaller than the required amount #
265
235
#########################################################################
266
- utx = False
267
- listunspent = self .nodes [2 ].listunspent ()
268
- for aUtx in listunspent :
269
- if aUtx ['amount' ] == 1.0 :
270
- utx = aUtx
271
- break
272
-
273
- assert (utx != False )
236
+ utx = get_unspent (self .nodes [2 ].listunspent (), 1 )
274
237
275
238
inputs = [ {'txid' : utx ['txid' ], 'vout' : utx ['vout' ]}]
276
239
outputs = { self .nodes [0 ].getnewaddress () : 1.0 }
@@ -305,17 +268,8 @@ def run_test(self):
305
268
###########################################
306
269
# test a fundrawtransaction with two VINs #
307
270
###########################################
308
- utx = False
309
- utx2 = False
310
- listunspent = self .nodes [2 ].listunspent ()
311
- for aUtx in listunspent :
312
- if aUtx ['amount' ] == 1.0 :
313
- utx = aUtx
314
- if aUtx ['amount' ] == 5.0 :
315
- utx2 = aUtx
316
-
317
-
318
- assert (utx != False )
271
+ utx = get_unspent (self .nodes [2 ].listunspent (), 1 )
272
+ utx2 = get_unspent (self .nodes [2 ].listunspent (), 5 )
319
273
320
274
inputs = [ {'txid' : utx ['txid' ], 'vout' : utx ['vout' ]},{'txid' : utx2 ['txid' ], 'vout' : utx2 ['vout' ]} ]
321
275
outputs = { self .nodes [0 ].getnewaddress () : 6.0 }
@@ -347,17 +301,8 @@ def run_test(self):
347
301
#########################################################
348
302
# test a fundrawtransaction with two VINs and two vOUTs #
349
303
#########################################################
350
- utx = False
351
- utx2 = False
352
- listunspent = self .nodes [2 ].listunspent ()
353
- for aUtx in listunspent :
354
- if aUtx ['amount' ] == 1.0 :
355
- utx = aUtx
356
- if aUtx ['amount' ] == 5.0 :
357
- utx2 = aUtx
358
-
359
-
360
- assert (utx != False )
304
+ utx = get_unspent (self .nodes [2 ].listunspent (), 1 )
305
+ utx2 = get_unspent (self .nodes [2 ].listunspent (), 5 )
361
306
362
307
inputs = [ {'txid' : utx ['txid' ], 'vout' : utx ['vout' ]},{'txid' : utx2 ['txid' ], 'vout' : utx2 ['vout' ]} ]
363
308
outputs = { self .nodes [0 ].getnewaddress () : 6.0 , self .nodes [0 ].getnewaddress () : 1.0 }
0 commit comments