Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_fundrawtransaction.py
Show First 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# | # | ||||
inputs = [] | inputs = [] | ||||
outputs = {self.nodes[0].getnewaddress(): 1.0} | outputs = {self.nodes[0].getnewaddress(): 1.0} | ||||
rawTx = self.nodes[2].createrawtransaction(inputs, outputs) | rawTx = self.nodes[2].createrawtransaction(inputs, outputs) | ||||
dec_tx = self.nodes[2].decoderawtransaction(rawTx) | dec_tx = self.nodes[2].decoderawtransaction(rawTx) | ||||
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 that we have enough inputs | # test that we have enough inputs | ||||
assert len(dec_tx['vin']) > 0 | |||||
# | # | ||||
# simple test with two coins # | # simple test with two coins # | ||||
# | # | ||||
inputs = [] | inputs = [] | ||||
outputs = {self.nodes[0].getnewaddress(): 2.2} | outputs = {self.nodes[0].getnewaddress(): 2.2} | ||||
rawTx = self.nodes[2].createrawtransaction(inputs, outputs) | rawTx = self.nodes[2].createrawtransaction(inputs, outputs) | ||||
dec_tx = self.nodes[2].decoderawtransaction(rawTx) | dec_tx = self.nodes[2].decoderawtransaction(rawTx) | ||||
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 enough inputs | # test if we have enough inputs | ||||
assert len(dec_tx['vin']) > 0 | |||||
# | # | ||||
# simple test with two coins # | # simple test with two coins # | ||||
# | # | ||||
inputs = [] | inputs = [] | ||||
outputs = {self.nodes[0].getnewaddress(): 2.6} | outputs = {self.nodes[0].getnewaddress(): 2.6} | ||||
rawTx = self.nodes[2].createrawtransaction(inputs, outputs) | rawTx = self.nodes[2].createrawtransaction(inputs, outputs) | ||||
dec_tx = self.nodes[2].decoderawtransaction(rawTx) | dec_tx = self.nodes[2].decoderawtransaction(rawTx) | ||||
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) | assert len(dec_tx['vin']) > 0 | ||||
assert_equal(dec_tx['vin'][0]['scriptSig']['hex'], '') | assert_equal(dec_tx['vin'][0]['scriptSig']['hex'], '') | ||||
# | # | ||||
# simple test with two outputs # | # simple test with two outputs # | ||||
# | # | ||||
inputs = [] | inputs = [] | ||||
outputs = { | outputs = { | ||||
self.nodes[0].getnewaddress(): 2.6, self.nodes[1].getnewaddress(): 2.5} | self.nodes[0].getnewaddress(): 2.6, self.nodes[1].getnewaddress(): 2.5} | ||||
rawTx = self.nodes[2].createrawtransaction(inputs, outputs) | rawTx = self.nodes[2].createrawtransaction(inputs, outputs) | ||||
dec_tx = self.nodes[2].decoderawtransaction(rawTx) | dec_tx = self.nodes[2].decoderawtransaction(rawTx) | ||||
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']) | ||||
totalOut = 0 | totalOut = 0 | ||||
for out in dec_tx['vout']: | for out in dec_tx['vout']: | ||||
totalOut += out['value'] | totalOut += out['value'] | ||||
assert(len(dec_tx['vin']) > 0) | assert len(dec_tx['vin']) > 0 | ||||
assert_equal(dec_tx['vin'][0]['scriptSig']['hex'], '') | assert_equal(dec_tx['vin'][0]['scriptSig']['hex'], '') | ||||
# | # | ||||
# test a fundrawtransaction with a VIN greater than the required amount # | # test a fundrawtransaction with a VIN greater than the required amount # | ||||
# | # | ||||
utx = get_unspent(self.nodes[2].listunspent(), 5) | utx = get_unspent(self.nodes[2].listunspent(), 5) | ||||
inputs = [{'txid': utx['txid'], 'vout': utx['vout']}] | inputs = [{'txid': utx['txid'], 'vout': utx['vout']}] | ||||
▲ Show 20 Lines • Show All 201 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
fundedTx = self.nodes[0].fundrawtransaction(rawTx) | fundedTx = self.nodes[0].fundrawtransaction(rawTx) | ||||
# create same transaction over sendtoaddress | # create same transaction over sendtoaddress | ||||
txId = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1.1) | txId = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1.1) | ||||
signedFee = self.nodes[0].getrawmempool(True)[txId]['fee'] | signedFee = self.nodes[0].getrawmempool(True)[txId]['fee'] | ||||
# compare fee | # compare fee | ||||
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee) | feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee) | ||||
assert(feeDelta >= 0 and feeDelta <= feeTolerance) | assert feeDelta >= 0 and feeDelta <= feeTolerance | ||||
# | # | ||||
# | # | ||||
# compare fee of a standard pubkeyhash transaction with multiple | # compare fee of a standard pubkeyhash transaction with multiple | ||||
# outputs | # outputs | ||||
inputs = [] | inputs = [] | ||||
outputs = {self.nodes[1].getnewaddress(): 1.1, self.nodes[1].getnewaddress(): 1.2, self.nodes[1].getnewaddress(): 0.1, self.nodes[ | outputs = {self.nodes[1].getnewaddress(): 1.1, self.nodes[1].getnewaddress(): 1.2, self.nodes[1].getnewaddress(): 0.1, self.nodes[ | ||||
1].getnewaddress(): 1.3, self.nodes[1].getnewaddress(): 0.2, self.nodes[1].getnewaddress(): 0.3} | 1].getnewaddress(): 1.3, self.nodes[1].getnewaddress(): 0.2, self.nodes[1].getnewaddress(): 0.3} | ||||
rawTx = self.nodes[0].createrawtransaction(inputs, outputs) | rawTx = self.nodes[0].createrawtransaction(inputs, outputs) | ||||
fundedTx = self.nodes[0].fundrawtransaction(rawTx) | fundedTx = self.nodes[0].fundrawtransaction(rawTx) | ||||
# create same transaction over sendtoaddress | # create same transaction over sendtoaddress | ||||
txId = self.nodes[0].sendmany("", outputs) | txId = self.nodes[0].sendmany("", outputs) | ||||
signedFee = self.nodes[0].getrawmempool(True)[txId]['fee'] | signedFee = self.nodes[0].getrawmempool(True)[txId]['fee'] | ||||
# compare fee | # compare fee | ||||
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee) | feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee) | ||||
assert(feeDelta >= 0 and feeDelta <= feeTolerance) | assert feeDelta >= 0 and feeDelta <= feeTolerance | ||||
# | # | ||||
# | # | ||||
# compare fee of a 2of2 multisig p2sh transaction | # compare fee of a 2of2 multisig p2sh transaction | ||||
# create 2of2 addr | # create 2of2 addr | ||||
addr1 = self.nodes[1].getnewaddress() | addr1 = self.nodes[1].getnewaddress() | ||||
addr2 = self.nodes[1].getnewaddress() | addr2 = self.nodes[1].getnewaddress() | ||||
Show All 10 Lines | def run_test(self): | ||||
fundedTx = self.nodes[0].fundrawtransaction(rawTx) | fundedTx = self.nodes[0].fundrawtransaction(rawTx) | ||||
# create same transaction over sendtoaddress | # create same transaction over sendtoaddress | ||||
txId = self.nodes[0].sendtoaddress(mSigObj, 1.1) | txId = self.nodes[0].sendtoaddress(mSigObj, 1.1) | ||||
signedFee = self.nodes[0].getrawmempool(True)[txId]['fee'] | signedFee = self.nodes[0].getrawmempool(True)[txId]['fee'] | ||||
# compare fee | # compare fee | ||||
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee) | feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee) | ||||
assert(feeDelta >= 0 and feeDelta <= feeTolerance) | assert feeDelta >= 0 and feeDelta <= feeTolerance | ||||
# | # | ||||
# | # | ||||
# compare fee of a standard pubkeyhash transaction | # compare fee of a standard pubkeyhash transaction | ||||
# create 4of5 addr | # create 4of5 addr | ||||
addr1 = self.nodes[1].getnewaddress() | addr1 = self.nodes[1].getnewaddress() | ||||
addr2 = self.nodes[1].getnewaddress() | addr2 = self.nodes[1].getnewaddress() | ||||
Show All 16 Lines | def run_test(self): | ||||
fundedTx = self.nodes[0].fundrawtransaction(rawTx) | fundedTx = self.nodes[0].fundrawtransaction(rawTx) | ||||
# create same transaction over sendtoaddress | # create same transaction over sendtoaddress | ||||
txId = self.nodes[0].sendtoaddress(mSigObj, 1.1) | txId = self.nodes[0].sendtoaddress(mSigObj, 1.1) | ||||
signedFee = self.nodes[0].getrawmempool(True)[txId]['fee'] | signedFee = self.nodes[0].getrawmempool(True)[txId]['fee'] | ||||
# compare fee | # compare fee | ||||
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee) | feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee) | ||||
assert(feeDelta >= 0 and feeDelta <= feeTolerance) | assert feeDelta >= 0 and feeDelta <= feeTolerance | ||||
# | # | ||||
# | # | ||||
# spend a 2of2 multisig transaction over fundraw | # spend a 2of2 multisig transaction over fundraw | ||||
# create 2of2 addr | # create 2of2 addr | ||||
addr1 = self.nodes[2].getnewaddress() | addr1 = self.nodes[2].getnewaddress() | ||||
addr2 = self.nodes[2].getnewaddress() | addr2 = self.nodes[2].getnewaddress() | ||||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
fundedTx = self.nodes[1].fundrawtransaction(rawTx) | fundedTx = self.nodes[1].fundrawtransaction(rawTx) | ||||
# create same transaction over sendtoaddress | # create same transaction over sendtoaddress | ||||
txId = self.nodes[1].sendmany("", outputs) | txId = self.nodes[1].sendmany("", outputs) | ||||
signedFee = self.nodes[1].getrawmempool(True)[txId]['fee'] | signedFee = self.nodes[1].getrawmempool(True)[txId]['fee'] | ||||
# compare fee | # compare fee | ||||
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee) | feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee) | ||||
assert(feeDelta >= 0 and feeDelta <= feeTolerance * 19) # ~19 inputs | # ~19 inputs | ||||
assert feeDelta >= 0 and feeDelta <= feeTolerance * 19 | |||||
# | # | ||||
# multiple (~19) inputs tx test | sign/send # | # multiple (~19) inputs tx test | sign/send # | ||||
# | # | ||||
# again, empty node1, send some small coins from node0 to node1 | # again, empty node1, send some small coins from node0 to node1 | ||||
self.nodes[1].sendtoaddress( | self.nodes[1].sendtoaddress( | ||||
self.nodes[0].getnewaddress(), self.nodes[1].getbalance(), "", "", True) | self.nodes[0].getnewaddress(), self.nodes[1].getbalance(), "", "", True) | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
rawTx = self.nodes[3].createrawtransaction(inputs, outputs) | rawTx = self.nodes[3].createrawtransaction(inputs, outputs) | ||||
result = self.nodes[3].fundrawtransaction( | result = self.nodes[3].fundrawtransaction( | ||||
rawTx, {'includeWatching': True}) | rawTx, {'includeWatching': True}) | ||||
res_dec = self.nodes[0].decoderawtransaction(result["hex"]) | res_dec = self.nodes[0].decoderawtransaction(result["hex"]) | ||||
assert_equal(len(res_dec["vin"]), 1) | assert_equal(len(res_dec["vin"]), 1) | ||||
assert_equal(res_dec["vin"][0]["txid"], watchonly_txid) | assert_equal(res_dec["vin"][0]["txid"], watchonly_txid) | ||||
assert("fee" in result.keys()) | assert "fee" in result.keys() | ||||
assert_greater_than(result["changepos"], -1) | assert_greater_than(result["changepos"], -1) | ||||
# | # | ||||
# test fundrawtransaction using the entirety of watched funds # | # test fundrawtransaction using the entirety of watched funds # | ||||
# | # | ||||
inputs = [] | inputs = [] | ||||
outputs = {self.nodes[2].getnewaddress(): watchonly_amount} | outputs = {self.nodes[2].getnewaddress(): watchonly_amount} | ||||
rawTx = self.nodes[3].createrawtransaction(inputs, outputs) | rawTx = self.nodes[3].createrawtransaction(inputs, outputs) | ||||
# Backward compatibility test (2nd param is includeWatching) | # Backward compatibility test (2nd param is includeWatching) | ||||
result = self.nodes[3].fundrawtransaction(rawTx, True) | result = self.nodes[3].fundrawtransaction(rawTx, True) | ||||
res_dec = self.nodes[0].decoderawtransaction(result["hex"]) | res_dec = self.nodes[0].decoderawtransaction(result["hex"]) | ||||
assert_equal(len(res_dec["vin"]), 2) | assert_equal(len(res_dec["vin"]), 2) | ||||
assert(res_dec["vin"][0]["txid"] == watchonly_txid or res_dec[ | assert res_dec["vin"][0]["txid"] == watchonly_txid or res_dec[ | ||||
"vin"][1]["txid"] == watchonly_txid) | "vin"][1]["txid"] == watchonly_txid | ||||
assert_greater_than(result["fee"], 0) | assert_greater_than(result["fee"], 0) | ||||
assert_greater_than(result["changepos"], -1) | assert_greater_than(result["changepos"], -1) | ||||
assert_equal(result["fee"] + res_dec["vout"][ | assert_equal(result["fee"] + res_dec["vout"][ | ||||
result["changepos"]]["value"], watchonly_amount / 10) | result["changepos"]]["value"], watchonly_amount / 10) | ||||
signedtx = self.nodes[3].signrawtransactionwithwallet(result["hex"]) | signedtx = self.nodes[3].signrawtransactionwithwallet(result["hex"]) | ||||
assert(not signedtx["complete"]) | assert not signedtx["complete"] | ||||
signedtx = self.nodes[0].signrawtransactionwithwallet(signedtx["hex"]) | signedtx = self.nodes[0].signrawtransactionwithwallet(signedtx["hex"]) | ||||
assert(signedtx["complete"]) | assert signedtx["complete"] | ||||
self.nodes[0].sendrawtransaction(signedtx["hex"]) | self.nodes[0].sendrawtransaction(signedtx["hex"]) | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
self.sync_all() | self.sync_all() | ||||
# | # | ||||
# Test feeRate option # | # Test feeRate option # | ||||
# | # | ||||
Show All 26 Lines | def run_test(self): | ||||
# | # | ||||
result3 = self.nodes[3].fundrawtransaction(rawTx) | result3 = self.nodes[3].fundrawtransaction(rawTx) | ||||
res_dec = self.nodes[0].decoderawtransaction(result3["hex"]) | res_dec = self.nodes[0].decoderawtransaction(result3["hex"]) | ||||
changeaddress = "" | changeaddress = "" | ||||
for out in res_dec['vout']: | for out in res_dec['vout']: | ||||
if out['value'] > 1.0: | if out['value'] > 1.0: | ||||
changeaddress += out['scriptPubKey']['addresses'][0] | changeaddress += out['scriptPubKey']['addresses'][0] | ||||
assert(changeaddress != "") | assert changeaddress != "" | ||||
nextaddr = self.nodes[3].getnewaddress() | nextaddr = self.nodes[3].getnewaddress() | ||||
# Now the change address key should be removed from the keypool | # Now the change address key should be removed from the keypool | ||||
assert(changeaddress != nextaddr) | assert changeaddress != nextaddr | ||||
# | # | ||||
# Test subtractFeeFromOutputs option # | # Test subtractFeeFromOutputs option # | ||||
# | # | ||||
# Make sure there is exactly one input so coin selection can't skew the | # Make sure there is exactly one input so coin selection can't skew the | ||||
# result | # result | ||||
assert_equal(len(self.nodes[3].listunspent(1)), 1) | assert_equal(len(self.nodes[3].listunspent(1)), 1) | ||||
▲ Show 20 Lines • Show All 75 Lines • Show Last 20 Lines |