Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet.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. | ||||
"""Test the wallet.""" | """Test the wallet.""" | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import * | from test_framework.util import * | ||||
from test_framework.mininode import * | from test_framework.mininode import * | ||||
class WalletTest(BitcoinTestFramework): | class WalletTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 4 | self.num_nodes = 4 | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.extra_args = [ | self.extra_args = [ | ||||
['-usehd={:d}'.format(i % 2 == 0), "-deprecatedrpc=signrawtransaction"] for i in range(4)] | ['-usehd={:d}'.format(i % 2 == 0)] for i in range(4)] | ||||
def setup_network(self): | def setup_network(self): | ||||
self.add_nodes(4, self.extra_args) | self.add_nodes(4, self.extra_args) | ||||
self.start_node(0) | self.start_node(0) | ||||
self.start_node(1) | self.start_node(1) | ||||
self.start_node(2) | self.start_node(2) | ||||
connect_nodes_bi(self.nodes, 0, 1) | connect_nodes_bi(self.nodes, 0, 1) | ||||
connect_nodes_bi(self.nodes, 1, 2) | connect_nodes_bi(self.nodes, 1, 2) | ||||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# create both transactions | # create both transactions | ||||
txns_to_send = [] | txns_to_send = [] | ||||
for utxo in node0utxos: | for utxo in node0utxos: | ||||
inputs = [] | inputs = [] | ||||
outputs = {} | outputs = {} | ||||
inputs.append({"txid": utxo["txid"], "vout": utxo["vout"]}) | inputs.append({"txid": utxo["txid"], "vout": utxo["vout"]}) | ||||
outputs[self.nodes[2].getnewaddress("from1")] = utxo["amount"] - 3 | outputs[self.nodes[2].getnewaddress("from1")] = utxo["amount"] - 3 | ||||
raw_tx = self.nodes[0].createrawtransaction(inputs, outputs) | raw_tx = self.nodes[0].createrawtransaction(inputs, outputs) | ||||
txns_to_send.append(self.nodes[0].signrawtransaction(raw_tx)) | txns_to_send.append( | ||||
self.nodes[0].signrawtransactionwithwallet(raw_tx)) | |||||
# Have node 1 (miner) send the transactions | # Have node 1 (miner) send the transactions | ||||
self.nodes[1].sendrawtransaction(txns_to_send[0]["hex"], True) | self.nodes[1].sendrawtransaction(txns_to_send[0]["hex"], True) | ||||
self.nodes[1].sendrawtransaction(txns_to_send[1]["hex"], True) | self.nodes[1].sendrawtransaction(txns_to_send[1]["hex"], True) | ||||
# Have node1 mine a block to confirm transactions: | # Have node1 mine a block to confirm transactions: | ||||
self.nodes[1].generate(1) | self.nodes[1].generate(1) | ||||
self.sync_all([self.nodes[0:3]]) | self.sync_all([self.nodes[0:3]]) | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
usp = self.nodes[1].listunspent() | usp = self.nodes[1].listunspent() | ||||
inputs = [{"txid": usp[0]['txid'], "vout":usp[0]['vout']}] | inputs = [{"txid": usp[0]['txid'], "vout":usp[0]['vout']}] | ||||
outputs = {self.nodes[1].getnewaddress(): 49.998, | outputs = {self.nodes[1].getnewaddress(): 49.998, | ||||
self.nodes[0].getnewaddress(): 11.11} | self.nodes[0].getnewaddress(): 11.11} | ||||
rawTx = self.nodes[1].createrawtransaction(inputs, outputs).replace( | rawTx = self.nodes[1].createrawtransaction(inputs, outputs).replace( | ||||
"c0833842", "00000000") # replace 11.11 with 0.0 (int32) | "c0833842", "00000000") # replace 11.11 with 0.0 (int32) | ||||
decRawTx = self.nodes[1].decoderawtransaction(rawTx) | decRawTx = self.nodes[1].decoderawtransaction(rawTx) | ||||
signedRawTx = self.nodes[1].signrawtransaction(rawTx) | signedRawTx = self.nodes[1].signrawtransactionwithwallet(rawTx) | ||||
decRawTx = self.nodes[1].decoderawtransaction(signedRawTx['hex']) | decRawTx = self.nodes[1].decoderawtransaction(signedRawTx['hex']) | ||||
zeroValueTxid = decRawTx['txid'] | zeroValueTxid = decRawTx['txid'] | ||||
sendResp = self.nodes[1].sendrawtransaction(signedRawTx['hex']) | sendResp = self.nodes[1].sendrawtransaction(signedRawTx['hex']) | ||||
self.sync_all() | self.sync_all() | ||||
self.nodes[1].generate(1) # mine a block | self.nodes[1].generate(1) # mine a block | ||||
self.sync_all() | self.sync_all() | ||||
▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# disabled until issue is fixed: https://github.com/bitcoin/bitcoin/issues/7463 | # disabled until issue is fixed: https://github.com/bitcoin/bitcoin/issues/7463 | ||||
# '-salvagewallet', | # '-salvagewallet', | ||||
] | ] | ||||
chainlimit = 6 | chainlimit = 6 | ||||
for m in maintenance: | for m in maintenance: | ||||
self.log.info("check " + m) | self.log.info("check " + m) | ||||
self.stop_nodes() | self.stop_nodes() | ||||
# set lower ancestor limit for later | # set lower ancestor limit for later | ||||
self.start_node(0, [m, "-limitancestorcount=" + | self.start_node(0, [m, "-limitancestorcount=" + str(chainlimit)]) | ||||
str(chainlimit), "-deprecatedrpc=signrawtransaction"]) | self.start_node(1, [m, "-limitancestorcount=" + str(chainlimit)]) | ||||
self.start_node(1, [m, "-limitancestorcount=" + | self.start_node(2, [m, "-limitancestorcount=" + str(chainlimit)]) | ||||
str(chainlimit), "-deprecatedrpc=signrawtransaction"]) | |||||
self.start_node(2, [m, "-limitancestorcount=" + | |||||
str(chainlimit), "-deprecatedrpc=signrawtransaction"]) | |||||
while m == '-reindex' and [block_count] * 3 != [self.nodes[i].getblockcount() for i in range(3)]: | while m == '-reindex' and [block_count] * 3 != [self.nodes[i].getblockcount() for i in range(3)]: | ||||
# reindex will leave rpc warm up "early"; Wait for it to finish | # reindex will leave rpc warm up "early"; Wait for it to finish | ||||
time.sleep(0.1) | time.sleep(0.1) | ||||
assert_equal(balance_nodes, [ | assert_equal(balance_nodes, [ | ||||
self.nodes[i].getbalance() for i in range(3)]) | self.nodes[i].getbalance() for i in range(3)]) | ||||
# Exercise listsinceblock with the last two blocks | # Exercise listsinceblock with the last two blocks | ||||
coinbase_tx_1 = self.nodes[0].listsinceblock(blocks[0]) | coinbase_tx_1 = self.nodes[0].listsinceblock(blocks[0]) | ||||
Show All 10 Lines | def run_test(self): | ||||
), self.nodes[0].getnewaddress()] | ), self.nodes[0].getnewaddress()] | ||||
singletxid = self.nodes[0].sendtoaddress( | singletxid = self.nodes[0].sendtoaddress( | ||||
chain_addrs[0], self.nodes[0].getbalance(), "", "", True) | chain_addrs[0], self.nodes[0].getbalance(), "", "", True) | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
node0_balance = self.nodes[0].getbalance() | node0_balance = self.nodes[0].getbalance() | ||||
# Split into two chains | # Split into two chains | ||||
rawtx = self.nodes[0].createrawtransaction([{"txid": singletxid, "vout": 0}], { | rawtx = self.nodes[0].createrawtransaction([{"txid": singletxid, "vout": 0}], { | ||||
chain_addrs[0]: node0_balance / 2 - Decimal('0.01'), chain_addrs[1]: node0_balance / 2 - Decimal('0.01')}) | chain_addrs[0]: node0_balance / 2 - Decimal('0.01'), chain_addrs[1]: node0_balance / 2 - Decimal('0.01')}) | ||||
signedtx = self.nodes[0].signrawtransaction(rawtx) | signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx) | ||||
singletxid = self.nodes[0].sendrawtransaction(signedtx["hex"]) | singletxid = self.nodes[0].sendrawtransaction(signedtx["hex"]) | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
# Make a long chain of unconfirmed payments without hitting mempool limit | # Make a long chain of unconfirmed payments without hitting mempool limit | ||||
# Each tx we make leaves only one output of change on a chain 1 longer | # Each tx we make leaves only one output of change on a chain 1 longer | ||||
# Since the amount to send is always much less than the outputs, we only ever need one output | # Since the amount to send is always much less than the outputs, we only ever need one output | ||||
# So we should be able to generate exactly chainlimit txs for each original output | # So we should be able to generate exactly chainlimit txs for each original output | ||||
sending_addr = self.nodes[1].getnewaddress() | sending_addr = self.nodes[1].getnewaddress() | ||||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |