Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_fundrawtransaction.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2014-2016 The Bitcoin Core developers | # Copyright (c) 2014-2016 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
from decimal import Decimal | from decimal import Decimal | ||||
from test_framework.messages import CTransaction, FromHex | from test_framework.messages import CTransaction, FromHex | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
assert_fee_amount, | assert_fee_amount, | ||||
assert_greater_than, | assert_greater_than, | ||||
assert_greater_than_or_equal, | assert_greater_than_or_equal, | ||||
assert_raises_rpc_error, | assert_raises_rpc_error, | ||||
connect_nodes_bi, | connect_nodes_bi, | ||||
find_vout_for_address, | |||||
) | ) | ||||
def get_unspent(listunspent, amount): | def get_unspent(listunspent, amount): | ||||
for utx in listunspent: | for utx in listunspent: | ||||
if utx['amount'] == amount: | if utx['amount'] == amount: | ||||
return utx | return utx | ||||
raise AssertionError( | raise AssertionError( | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
watchonly_address = self.nodes[0].getnewaddress() | watchonly_address = self.nodes[0].getnewaddress() | ||||
watchonly_pubkey = self.nodes[ | watchonly_pubkey = self.nodes[ | ||||
0].getaddressinfo(watchonly_address)["pubkey"] | 0].getaddressinfo(watchonly_address)["pubkey"] | ||||
watchonly_amount = Decimal(200) | watchonly_amount = Decimal(200) | ||||
self.nodes[3].importpubkey(watchonly_pubkey, "", True) | self.nodes[3].importpubkey(watchonly_pubkey, "", True) | ||||
watchonly_txid = self.nodes[0].sendtoaddress( | watchonly_txid = self.nodes[0].sendtoaddress( | ||||
watchonly_address, watchonly_amount) | watchonly_address, watchonly_amount) | ||||
# Lock UTXO so nodes[0] doesn't accidentally spend it | |||||
watchonly_vout = find_vout_for_address( | |||||
self.nodes[0], watchonly_txid, watchonly_address) | |||||
self.nodes[0].lockunspent( | |||||
False, [{"txid": watchonly_txid, "vout": watchonly_vout}]) | |||||
self.nodes[0].sendtoaddress( | self.nodes[0].sendtoaddress( | ||||
self.nodes[3].getnewaddress(), watchonly_amount / 10) | self.nodes[3].getnewaddress(), watchonly_amount / 10) | ||||
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.5) | self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.5) | ||||
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.0) | self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.0) | ||||
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 5.0) | self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 5.0) | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
▲ Show 20 Lines • Show All 399 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# to be sure all txs are sent at a consistent desired feerate | # to be sure all txs are sent at a consistent desired feerate | ||||
for node in self.nodes: | for node in self.nodes: | ||||
node.settxfee(min_relay_tx_fee) | node.settxfee(min_relay_tx_fee) | ||||
connect_nodes_bi(self.nodes[0], self.nodes[1]) | connect_nodes_bi(self.nodes[0], self.nodes[1]) | ||||
connect_nodes_bi(self.nodes[1], self.nodes[2]) | connect_nodes_bi(self.nodes[1], self.nodes[2]) | ||||
connect_nodes_bi(self.nodes[0], self.nodes[2]) | connect_nodes_bi(self.nodes[0], self.nodes[2]) | ||||
connect_nodes_bi(self.nodes[0], self.nodes[3]) | connect_nodes_bi(self.nodes[0], self.nodes[3]) | ||||
# Again lock the watchonly UTXO or nodes[0] may spend it, because | |||||
# lockunspent is memory-only and thus lost on restart | |||||
self.nodes[0].lockunspent( | |||||
False, [{"txid": watchonly_txid, "vout": watchonly_vout}]) | |||||
self.sync_all() | self.sync_all() | ||||
# drain the keypool | # drain the keypool | ||||
self.nodes[1].getnewaddress() | self.nodes[1].getnewaddress() | ||||
self.nodes[1].getrawchangeaddress() | self.nodes[1].getrawchangeaddress() | ||||
inputs = [] | inputs = [] | ||||
outputs = {self.nodes[0].getnewaddress(): 1.1} | outputs = {self.nodes[0].getnewaddress(): 1.1} | ||||
rawTx = self.nodes[1].createrawtransaction(inputs, outputs) | rawTx = self.nodes[1].createrawtransaction(inputs, outputs) | ||||
▲ Show 20 Lines • Show All 282 Lines • Show Last 20 Lines |