Skip to content

Commit 0d41d70

Browse files
committed
Merge #8216: [qa] assert 'changePosition out of bounds'
fa58f94 [qa] pull-tester: Start longest test first (MarcoFalke) fa3b379 [qa] pull-tester: Fix assertion and check for run_parallel (MarcoFalke) fa32465 [qa] fundrawtransaction: Create get_unspent() (MarcoFalke) fa8ce3b [qa] assert 'changePosition out of bounds' (MarcoFalke)
2 parents bf9c70b + fa58f94 commit 0d41d70

File tree

2 files changed

+29
-77
lines changed

2 files changed

+29
-77
lines changed

qa/pull-tester/rpc-tests.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101

102102
#Tests
103103
testScripts = [
104+
# longest test should go first, to favor running tests in parallel
105+
'p2p-fullblocktest.py',
104106
'walletbackup.py',
105107
'bip68-112-113-p2p.py',
106108
'wallet.py',
@@ -125,7 +127,6 @@
125127
'nodehandling.py',
126128
'reindex.py',
127129
'decodescript.py',
128-
'p2p-fullblocktest.py',
129130
'blockchain.py',
130131
'disablewallet.py',
131132
'sendheaders.py',
@@ -191,7 +192,7 @@ def runtests():
191192
if coverage:
192193
flags.append(coverage.flag)
193194

194-
if len(test_list) > 1:
195+
if len(test_list) > 1 and run_parallel > 1:
195196
# Populate cache
196197
subprocess.check_output([RPC_TESTS_DIR + 'create_cache.py'] + flags)
197198

@@ -251,7 +252,7 @@ def get_next(self):
251252
stdout=subprocess.PIPE,
252253
stderr=subprocess.PIPE)))
253254
if not self.jobs:
254-
raise IndexError('%s from empty list' % __name__)
255+
raise IndexError('pop from empty list')
255256
while True:
256257
# Return first proc that finishes
257258
time.sleep(.5)

qa/rpc-tests/fundrawtransaction.py

Lines changed: 25 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
from test_framework.test_framework import BitcoinTestFramework
77
from test_framework.util import *
88

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+
1017
class RawTransactionsTest(BitcoinTestFramework):
1118

1219
def __init__(self):
@@ -71,7 +78,7 @@ def run_test(self):
7178
rawtxfund = self.nodes[2].fundrawtransaction(rawtx)
7279
fee = rawtxfund['fee']
7380
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
7582

7683
##############################
7784
# simple test with two coins #
@@ -123,14 +130,7 @@ def run_test(self):
123130
#########################################################################
124131
# test a fundrawtransaction with a VIN greater than the required amount #
125132
#########################################################################
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)
134134

135135
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']}]
136136
outputs = { self.nodes[0].getnewaddress() : 1.0 }
@@ -151,14 +151,7 @@ def run_test(self):
151151
#####################################################################
152152
# test a fundrawtransaction with which will not get a change output #
153153
#####################################################################
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)
162155

163156
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']}]
164157
outputs = { self.nodes[0].getnewaddress() : Decimal(5.0) - fee - feeTolerance }
@@ -180,14 +173,7 @@ def run_test(self):
180173
####################################################
181174
# test a fundrawtransaction with an invalid option #
182175
####################################################
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)
191177

192178
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']} ]
193179
outputs = { self.nodes[0].getnewaddress() : Decimal(4.0) }
@@ -205,14 +191,7 @@ def run_test(self):
205191
############################################################
206192
# test a fundrawtransaction with an invalid change address #
207193
############################################################
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)
216195

217196
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']} ]
218197
outputs = { self.nodes[0].getnewaddress() : Decimal(4.0) }
@@ -227,18 +206,10 @@ def run_test(self):
227206
assert("changeAddress must be a valid bitcoin address" in e.error['message'])
228207

229208

230-
231209
############################################################
232210
# test a fundrawtransaction with a provided change address #
233211
############################################################
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)
242213

243214
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']} ]
244215
outputs = { self.nodes[0].getnewaddress() : Decimal(4.0) }
@@ -247,24 +218,22 @@ def run_test(self):
247218
assert_equal(utx['txid'], dec_tx['vin'][0]['txid'])
248219

249220
change = self.nodes[2].getnewaddress()
221+
try:
222+
rawtxfund = self.nodes[2].fundrawtransaction(rawtx, {'changeAddress': change, 'changePosition': 2})
223+
except JSONRPCException as e:
224+
assert('changePosition out of bounds' == e.error['message'])
225+
else:
226+
assert(False)
250227
rawtxfund = self.nodes[2].fundrawtransaction(rawtx, {'changeAddress': change, 'changePosition': 0})
251228
dec_tx = self.nodes[2].decoderawtransaction(rawtxfund['hex'])
252229
out = dec_tx['vout'][0];
253230
assert_equal(change, out['scriptPubKey']['addresses'][0])
254231

255232

256-
257233
#########################################################################
258234
# test a fundrawtransaction with a VIN smaller than the required amount #
259235
#########################################################################
260-
utx = False
261-
listunspent = self.nodes[2].listunspent()
262-
for aUtx in listunspent:
263-
if aUtx['amount'] == 1.0:
264-
utx = aUtx
265-
break
266-
267-
assert(utx!=False)
236+
utx = get_unspent(self.nodes[2].listunspent(), 1)
268237

269238
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']}]
270239
outputs = { self.nodes[0].getnewaddress() : 1.0 }
@@ -299,17 +268,8 @@ def run_test(self):
299268
###########################################
300269
# test a fundrawtransaction with two VINs #
301270
###########################################
302-
utx = False
303-
utx2 = False
304-
listunspent = self.nodes[2].listunspent()
305-
for aUtx in listunspent:
306-
if aUtx['amount'] == 1.0:
307-
utx = aUtx
308-
if aUtx['amount'] == 5.0:
309-
utx2 = aUtx
310-
311-
312-
assert(utx!=False)
271+
utx = get_unspent(self.nodes[2].listunspent(), 1)
272+
utx2 = get_unspent(self.nodes[2].listunspent(), 5)
313273

314274
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']},{'txid' : utx2['txid'], 'vout' : utx2['vout']} ]
315275
outputs = { self.nodes[0].getnewaddress() : 6.0 }
@@ -341,17 +301,8 @@ def run_test(self):
341301
#########################################################
342302
# test a fundrawtransaction with two VINs and two vOUTs #
343303
#########################################################
344-
utx = False
345-
utx2 = False
346-
listunspent = self.nodes[2].listunspent()
347-
for aUtx in listunspent:
348-
if aUtx['amount'] == 1.0:
349-
utx = aUtx
350-
if aUtx['amount'] == 5.0:
351-
utx2 = aUtx
352-
353-
354-
assert(utx!=False)
304+
utx = get_unspent(self.nodes[2].listunspent(), 1)
305+
utx2 = get_unspent(self.nodes[2].listunspent(), 5)
355306

356307
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']},{'txid' : utx2['txid'], 'vout' : utx2['vout']} ]
357308
outputs = { self.nodes[0].getnewaddress() : 6.0, self.nodes[0].getnewaddress() : 1.0 }

0 commit comments

Comments
 (0)