Skip to content

Commit

Permalink
Merge bitcoin#8216: [qa] assert 'changePosition out of bounds'
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
laanwj authored and codablock committed Dec 28, 2017
1 parent c2dabf8 commit e2bcf8a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 77 deletions.
7 changes: 4 additions & 3 deletions qa/pull-tester/rpc-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@

#Tests
testScripts = [
# longest test should go first, to favor running tests in parallel
'p2p-fullblocktest.py', # NOTE: needs dash_hash to pass
'walletbackup.py',
'bip68-112-113-p2p.py',
'wallet.py',
Expand Down Expand Up @@ -139,7 +141,6 @@
'timestampindex.py',
'spentindex.py',
'decodescript.py',
'p2p-fullblocktest.py', # NOTE: needs dash_hash to pass
'blockchain.py',
'disablewallet.py',
'sendheaders.py', # NOTE: needs dash_hash to pass
Expand Down Expand Up @@ -206,7 +207,7 @@ def runtests():
if coverage:
flags.append(coverage.flag)

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

Expand Down Expand Up @@ -270,7 +271,7 @@ def get_next(self):
log_stdout,
log_stderr))
if not self.jobs:
raise IndexError('%s from empty list' % __name__)
raise IndexError('pop from empty list')
while True:
# Return first proc that finishes
time.sleep(.5)
Expand Down
99 changes: 25 additions & 74 deletions qa/rpc-tests/fundrawtransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *

# Create one-input, one-output, no-fee transaction:

def get_unspent(listunspent, amount):
for utx in listunspent:
if utx['amount'] == amount:
return utx
raise AssertionError('Could not find unspent with amount={}'.format(amount))


class RawTransactionsTest(BitcoinTestFramework):

def __init__(self):
Expand Down Expand Up @@ -71,7 +78,7 @@ def run_test(self):
rawtxfund = self.nodes[2].fundrawtransaction(rawtx)
fee = rawtxfund['fee']
dec_tx = self.nodes[2].decoderawtransaction(rawtxfund['hex'])
assert(len(dec_tx['vin']) > 0) #test if we have enought inputs
assert(len(dec_tx['vin']) > 0) #test that we have enough inputs

##############################
# simple test with two coins #
Expand Down Expand Up @@ -123,14 +130,7 @@ def run_test(self):
#########################################################################
# test a fundrawtransaction with a VIN greater than the required amount #
#########################################################################
utx = False
listunspent = self.nodes[2].listunspent()
for aUtx in listunspent:
if aUtx['amount'] == 50:
utx = aUtx
break

assert(utx!=False)
utx = get_unspent(self.nodes[2].listunspent(), 50)

inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']}]
outputs = { self.nodes[0].getnewaddress() : 10 }
Expand All @@ -151,14 +151,7 @@ def run_test(self):
#####################################################################
# test a fundrawtransaction with which will not get a change output #
#####################################################################
utx = False
listunspent = self.nodes[2].listunspent()
for aUtx in listunspent:
if aUtx['amount'] == 50:
utx = aUtx
break

assert(utx!=False)
utx = get_unspent(self.nodes[2].listunspent(), 50)

inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']}]
outputs = { self.nodes[0].getnewaddress() : Decimal(50) - fee - feeTolerance }
Expand All @@ -180,14 +173,7 @@ def run_test(self):
####################################################
# test a fundrawtransaction with an invalid option #
####################################################
utx = False
listunspent = self.nodes[2].listunspent()
for aUtx in listunspent:
if aUtx['amount'] == 50:
utx = aUtx
break

assert_equal(utx!=False, True)
utx = get_unspent(self.nodes[2].listunspent(), 50)

inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']} ]
outputs = { self.nodes[0].getnewaddress() : Decimal(40) }
Expand All @@ -205,14 +191,7 @@ def run_test(self):
############################################################
# test a fundrawtransaction with an invalid change address #
############################################################
utx = False
listunspent = self.nodes[2].listunspent()
for aUtx in listunspent:
if aUtx['amount'] == 50:
utx = aUtx
break

assert_equal(utx!=False, True)
utx = get_unspent(self.nodes[2].listunspent(), 50)

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



############################################################
# test a fundrawtransaction with a provided change address #
############################################################
utx = False
listunspent = self.nodes[2].listunspent()
for aUtx in listunspent:
if aUtx['amount'] == 50:
utx = aUtx
break

assert_equal(utx!=False, True)
utx = get_unspent(self.nodes[2].listunspent(), 50)

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

change = self.nodes[2].getnewaddress()
try:
rawtxfund = self.nodes[2].fundrawtransaction(rawtx, {'changeAddress': change, 'changePosition': 2})
except JSONRPCException as e:
assert('changePosition out of bounds' == e.error['message'])
else:
assert(False)
rawtxfund = self.nodes[2].fundrawtransaction(rawtx, {'changeAddress': change, 'changePosition': 0})
dec_tx = self.nodes[2].decoderawtransaction(rawtxfund['hex'])
out = dec_tx['vout'][0];
assert_equal(change, out['scriptPubKey']['addresses'][0])



#########################################################################
# test a fundrawtransaction with a VIN smaller than the required amount #
#########################################################################
utx = False
listunspent = self.nodes[2].listunspent()
for aUtx in listunspent:
if aUtx['amount'] == 10:
utx = aUtx
break

assert(utx!=False)
utx = get_unspent(self.nodes[2].listunspent(), 10)

inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']}]
outputs = { self.nodes[0].getnewaddress() : 10 }
Expand Down Expand Up @@ -299,17 +268,8 @@ def run_test(self):
###########################################
# test a fundrawtransaction with two VINs #
###########################################
utx = False
utx2 = False
listunspent = self.nodes[2].listunspent()
for aUtx in listunspent:
if aUtx['amount'] == 10:
utx = aUtx
if aUtx['amount'] == 50:
utx2 = aUtx


assert(utx!=False)
utx = get_unspent(self.nodes[2].listunspent(), 10)
utx2 = get_unspent(self.nodes[2].listunspent(), 50)

inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']},{'txid' : utx2['txid'], 'vout' : utx2['vout']} ]
outputs = { self.nodes[0].getnewaddress() : 60 }
Expand Down Expand Up @@ -341,17 +301,8 @@ def run_test(self):
#########################################################
# test a fundrawtransaction with two VINs and two vOUTs #
#########################################################
utx = False
utx2 = False
listunspent = self.nodes[2].listunspent()
for aUtx in listunspent:
if aUtx['amount'] == 10:
utx = aUtx
if aUtx['amount'] == 50:
utx2 = aUtx


assert(utx!=False)
utx = get_unspent(self.nodes[2].listunspent(), 10)
utx2 = get_unspent(self.nodes[2].listunspent(), 50)

inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']},{'txid' : utx2['txid'], 'vout' : utx2['vout']} ]
outputs = { self.nodes[0].getnewaddress() : 60, self.nodes[0].getnewaddress() : 10 }
Expand Down

0 comments on commit e2bcf8a

Please sign in to comment.