Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_basic.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2014-2019 The Bitcoin Core developers | # Copyright (c) 2014-2019 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 decimal import Decimal | from decimal import Decimal | ||||
from test_framework.messages import FromHex, CTransaction | from test_framework.messages import FromHex, CTransaction | ||||
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_array_result, | assert_array_result, | ||||
assert_equal, | assert_equal, | ||||
assert_fee_amount, | assert_fee_amount, | ||||
assert_raises_rpc_error, | assert_raises_rpc_error, | ||||
connect_nodes, | connect_nodes, | ||||
count_bytes, | count_bytes, | ||||
wait_until, | |||||
) | ) | ||||
from test_framework.wallet_util import test_address | from test_framework.wallet_util import test_address | ||||
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 | ||||
▲ Show 20 Lines • Show All 466 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.start_node( | self.start_node( | ||||
0, self.extra_args[0] + [m, "-limitancestorcount=" + str(chainlimit)]) | 0, self.extra_args[0] + [m, "-limitancestorcount=" + str(chainlimit)]) | ||||
self.start_node( | self.start_node( | ||||
1, self.extra_args[1] + [m, "-limitancestorcount=" + str(chainlimit)]) | 1, self.extra_args[1] + [m, "-limitancestorcount=" + str(chainlimit)]) | ||||
self.start_node( | self.start_node( | ||||
2, self.extra_args[2] + [m, "-limitancestorcount=" + str(chainlimit)]) | 2, self.extra_args[2] + [m, "-limitancestorcount=" + str(chainlimit)]) | ||||
if m == '-reindex': | if m == '-reindex': | ||||
# reindex will leave rpc warm up "early"; Wait for it to finish | # reindex will leave rpc warm up "early"; Wait for it to finish | ||||
wait_until(lambda: [block_count] * 3 == | self.wait_until( | ||||
lambda: [block_count] * 3 == | |||||
[self.nodes[i].getblockcount() for i in range(3)]) | [self.nodes[i].getblockcount() for i in range(3)]) | ||||
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]) | ||||
assert_equal(coinbase_tx_1["lastblock"], blocks[1]) | assert_equal(coinbase_tx_1["lastblock"], blocks[1]) | ||||
assert_equal(len(coinbase_tx_1["transactions"]), 1) | assert_equal(len(coinbase_tx_1["transactions"]), 1) | ||||
assert_equal(coinbase_tx_1["transactions"][0]["blockhash"], blocks[1]) | assert_equal(coinbase_tx_1["transactions"][0]["blockhash"], blocks[1]) | ||||
assert_equal(len(self.nodes[0].listsinceblock( | assert_equal(len(self.nodes[0].listsinceblock( | ||||
blocks[1])["transactions"]), 0) | blocks[1])["transactions"]), 0) | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# Double chain limit but require combining inputs, so we pass | # Double chain limit but require combining inputs, so we pass | ||||
# SelectCoinsMinConf | # SelectCoinsMinConf | ||||
self.stop_node(0) | self.stop_node(0) | ||||
self.start_node(0, | self.start_node(0, | ||||
self.extra_args[0] + ["-walletrejectlongchains", | self.extra_args[0] + ["-walletrejectlongchains", | ||||
"-limitancestorcount=" + str(2 * chainlimit)]) | "-limitancestorcount=" + str(2 * chainlimit)]) | ||||
# wait until the wallet has submitted all transactions to the mempool | # wait until the wallet has submitted all transactions to the mempool | ||||
wait_until( | self.wait_until( | ||||
lambda: len( | lambda: len(self.nodes[0].getrawmempool()) == chainlimit * 2) | ||||
self.nodes[0].getrawmempool()) == chainlimit * | |||||
2) | |||||
node0_balance = self.nodes[0].getbalance() | node0_balance = self.nodes[0].getbalance() | ||||
# With walletrejectlongchains we will not create the tx and store it in | # With walletrejectlongchains we will not create the tx and store it in | ||||
# our wallet. | # our wallet. | ||||
assert_raises_rpc_error(-6, "Transaction has too long of a mempool chain", | assert_raises_rpc_error(-6, "Transaction has too long of a mempool chain", | ||||
self.nodes[0].sendtoaddress, sending_addr, node0_balance - Decimal('10000')) | self.nodes[0].sendtoaddress, sending_addr, node0_balance - Decimal('10000')) | ||||
# Verify nothing new in wallet | # Verify nothing new in wallet | ||||
▲ Show 20 Lines • Show All 88 Lines • Show Last 20 Lines |