mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-11 20:32:35 -03:00
[qa] fundrawtransaction: Create get_unspent()
This commit is contained in:
parent
fa8ce3b670
commit
fa324653ab
1 changed files with 19 additions and 74 deletions
|
@ -6,7 +6,14 @@
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import *
|
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):
|
class RawTransactionsTest(BitcoinTestFramework):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -71,7 +78,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
rawtxfund = self.nodes[2].fundrawtransaction(rawtx)
|
rawtxfund = self.nodes[2].fundrawtransaction(rawtx)
|
||||||
fee = rawtxfund['fee']
|
fee = rawtxfund['fee']
|
||||||
dec_tx = self.nodes[2].decoderawtransaction(rawtxfund['hex'])
|
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 #
|
# simple test with two coins #
|
||||||
|
@ -123,14 +130,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
#########################################################################
|
#########################################################################
|
||||||
# test a fundrawtransaction with a VIN greater than the required amount #
|
# test a fundrawtransaction with a VIN greater than the required amount #
|
||||||
#########################################################################
|
#########################################################################
|
||||||
utx = False
|
utx = get_unspent(self.nodes[2].listunspent(), 5)
|
||||||
listunspent = self.nodes[2].listunspent()
|
|
||||||
for aUtx in listunspent:
|
|
||||||
if aUtx['amount'] == 5.0:
|
|
||||||
utx = aUtx
|
|
||||||
break
|
|
||||||
|
|
||||||
assert(utx!=False)
|
|
||||||
|
|
||||||
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']}]
|
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']}]
|
||||||
outputs = { self.nodes[0].getnewaddress() : 1.0 }
|
outputs = { self.nodes[0].getnewaddress() : 1.0 }
|
||||||
|
@ -151,14 +151,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
#####################################################################
|
#####################################################################
|
||||||
# test a fundrawtransaction with which will not get a change output #
|
# test a fundrawtransaction with which will not get a change output #
|
||||||
#####################################################################
|
#####################################################################
|
||||||
utx = False
|
utx = get_unspent(self.nodes[2].listunspent(), 5)
|
||||||
listunspent = self.nodes[2].listunspent()
|
|
||||||
for aUtx in listunspent:
|
|
||||||
if aUtx['amount'] == 5.0:
|
|
||||||
utx = aUtx
|
|
||||||
break
|
|
||||||
|
|
||||||
assert(utx!=False)
|
|
||||||
|
|
||||||
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']}]
|
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']}]
|
||||||
outputs = { self.nodes[0].getnewaddress() : Decimal(5.0) - fee - feeTolerance }
|
outputs = { self.nodes[0].getnewaddress() : Decimal(5.0) - fee - feeTolerance }
|
||||||
|
@ -180,14 +173,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
####################################################
|
####################################################
|
||||||
# test a fundrawtransaction with an invalid option #
|
# test a fundrawtransaction with an invalid option #
|
||||||
####################################################
|
####################################################
|
||||||
utx = False
|
utx = get_unspent(self.nodes[2].listunspent(), 5)
|
||||||
listunspent = self.nodes[2].listunspent()
|
|
||||||
for aUtx in listunspent:
|
|
||||||
if aUtx['amount'] == 5.0:
|
|
||||||
utx = aUtx
|
|
||||||
break
|
|
||||||
|
|
||||||
assert_equal(utx!=False, True)
|
|
||||||
|
|
||||||
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']} ]
|
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']} ]
|
||||||
outputs = { self.nodes[0].getnewaddress() : Decimal(4.0) }
|
outputs = { self.nodes[0].getnewaddress() : Decimal(4.0) }
|
||||||
|
@ -205,14 +191,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
############################################################
|
############################################################
|
||||||
# test a fundrawtransaction with an invalid change address #
|
# test a fundrawtransaction with an invalid change address #
|
||||||
############################################################
|
############################################################
|
||||||
utx = False
|
utx = get_unspent(self.nodes[2].listunspent(), 5)
|
||||||
listunspent = self.nodes[2].listunspent()
|
|
||||||
for aUtx in listunspent:
|
|
||||||
if aUtx['amount'] == 5.0:
|
|
||||||
utx = aUtx
|
|
||||||
break
|
|
||||||
|
|
||||||
assert_equal(utx!=False, True)
|
|
||||||
|
|
||||||
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']} ]
|
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']} ]
|
||||||
outputs = { self.nodes[0].getnewaddress() : Decimal(4.0) }
|
outputs = { self.nodes[0].getnewaddress() : Decimal(4.0) }
|
||||||
|
@ -227,18 +206,10 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
assert("changeAddress must be a valid bitcoin address" in e.error['message'])
|
assert("changeAddress must be a valid bitcoin address" in e.error['message'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# test a fundrawtransaction with a provided change address #
|
# test a fundrawtransaction with a provided change address #
|
||||||
############################################################
|
############################################################
|
||||||
utx = False
|
utx = get_unspent(self.nodes[2].listunspent(), 5)
|
||||||
listunspent = self.nodes[2].listunspent()
|
|
||||||
for aUtx in listunspent:
|
|
||||||
if aUtx['amount'] == 5.0:
|
|
||||||
utx = aUtx
|
|
||||||
break
|
|
||||||
|
|
||||||
assert_equal(utx!=False, True)
|
|
||||||
|
|
||||||
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']} ]
|
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']} ]
|
||||||
outputs = { self.nodes[0].getnewaddress() : Decimal(4.0) }
|
outputs = { self.nodes[0].getnewaddress() : Decimal(4.0) }
|
||||||
|
@ -259,18 +230,10 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
assert_equal(change, out['scriptPubKey']['addresses'][0])
|
assert_equal(change, out['scriptPubKey']['addresses'][0])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#########################################################################
|
#########################################################################
|
||||||
# test a fundrawtransaction with a VIN smaller than the required amount #
|
# test a fundrawtransaction with a VIN smaller than the required amount #
|
||||||
#########################################################################
|
#########################################################################
|
||||||
utx = False
|
utx = get_unspent(self.nodes[2].listunspent(), 1)
|
||||||
listunspent = self.nodes[2].listunspent()
|
|
||||||
for aUtx in listunspent:
|
|
||||||
if aUtx['amount'] == 1.0:
|
|
||||||
utx = aUtx
|
|
||||||
break
|
|
||||||
|
|
||||||
assert(utx!=False)
|
|
||||||
|
|
||||||
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']}]
|
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']}]
|
||||||
outputs = { self.nodes[0].getnewaddress() : 1.0 }
|
outputs = { self.nodes[0].getnewaddress() : 1.0 }
|
||||||
|
@ -305,17 +268,8 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
###########################################
|
###########################################
|
||||||
# test a fundrawtransaction with two VINs #
|
# test a fundrawtransaction with two VINs #
|
||||||
###########################################
|
###########################################
|
||||||
utx = False
|
utx = get_unspent(self.nodes[2].listunspent(), 1)
|
||||||
utx2 = False
|
utx2 = get_unspent(self.nodes[2].listunspent(), 5)
|
||||||
listunspent = self.nodes[2].listunspent()
|
|
||||||
for aUtx in listunspent:
|
|
||||||
if aUtx['amount'] == 1.0:
|
|
||||||
utx = aUtx
|
|
||||||
if aUtx['amount'] == 5.0:
|
|
||||||
utx2 = aUtx
|
|
||||||
|
|
||||||
|
|
||||||
assert(utx!=False)
|
|
||||||
|
|
||||||
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']},{'txid' : utx2['txid'], 'vout' : utx2['vout']} ]
|
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']},{'txid' : utx2['txid'], 'vout' : utx2['vout']} ]
|
||||||
outputs = { self.nodes[0].getnewaddress() : 6.0 }
|
outputs = { self.nodes[0].getnewaddress() : 6.0 }
|
||||||
|
@ -347,17 +301,8 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
#########################################################
|
#########################################################
|
||||||
# test a fundrawtransaction with two VINs and two vOUTs #
|
# test a fundrawtransaction with two VINs and two vOUTs #
|
||||||
#########################################################
|
#########################################################
|
||||||
utx = False
|
utx = get_unspent(self.nodes[2].listunspent(), 1)
|
||||||
utx2 = False
|
utx2 = get_unspent(self.nodes[2].listunspent(), 5)
|
||||||
listunspent = self.nodes[2].listunspent()
|
|
||||||
for aUtx in listunspent:
|
|
||||||
if aUtx['amount'] == 1.0:
|
|
||||||
utx = aUtx
|
|
||||||
if aUtx['amount'] == 5.0:
|
|
||||||
utx2 = aUtx
|
|
||||||
|
|
||||||
|
|
||||||
assert(utx!=False)
|
|
||||||
|
|
||||||
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']},{'txid' : utx2['txid'], 'vout' : utx2['vout']} ]
|
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']},{'txid' : utx2['txid'], 'vout' : utx2['vout']} ]
|
||||||
outputs = { self.nodes[0].getnewaddress() : 6.0, self.nodes[0].getnewaddress() : 1.0 }
|
outputs = { self.nodes[0].getnewaddress() : 6.0, self.nodes[0].getnewaddress() : 1.0 }
|
||||||
|
|
Loading…
Reference in a new issue