Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_balance.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2018-2019 The Bitcoin Core developers | # Copyright (c) 2018-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 balance RPC methods.""" | """Test the wallet balance RPC methods.""" | ||||
from decimal import Decimal | from decimal import Decimal | ||||
import struct | import struct | ||||
from test_framework.address import ADDRESS_BCHREG_UNSPENDABLE as ADDRESS_WATCHONLY | from test_framework.address import ADDRESS_BCHREG_UNSPENDABLE as ADDRESS_WATCHONLY | ||||
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_raises_rpc_error, | assert_raises_rpc_error, | ||||
connect_nodes, | connect_nodes, | ||||
sync_blocks, | |||||
) | ) | ||||
def create_transactions(node, address, amt, fees): | def create_transactions(node, address, amt, fees): | ||||
# Create and sign raw transactions from node to address for amt. | # Create and sign raw transactions from node to address for amt. | ||||
# Creates a transaction for each fee and returns an array | # Creates a transaction for each fee and returns an array | ||||
# of the raw transactions. | # of the raw transactions. | ||||
utxos = [u for u in node.listunspent(0) if u['spendable']] | utxos = [u for u in node.listunspent(0) if u['spendable']] | ||||
▲ Show 20 Lines • Show All 276 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
assert_equal(self.nodes[0].getbalance(minconf=0), 0) | assert_equal(self.nodes[0].getbalance(minconf=0), 0) | ||||
self.nodes[0].generatetoaddress(1, ADDRESS_WATCHONLY) | self.nodes[0].generatetoaddress(1, ADDRESS_WATCHONLY) | ||||
# wallet txs not in the mempool are untrusted | # wallet txs not in the mempool are untrusted | ||||
assert_equal(self.nodes[0].getbalance(minconf=0), 0) | assert_equal(self.nodes[0].getbalance(minconf=0), 0) | ||||
# Now confirm tx_orig | # Now confirm tx_orig | ||||
self.restart_node(1, ['-persistmempool=0']) | self.restart_node(1, ['-persistmempool=0']) | ||||
connect_nodes(self.nodes[0], self.nodes[1]) | connect_nodes(self.nodes[0], self.nodes[1]) | ||||
sync_blocks(self.nodes) | self.sync_blocks() | ||||
self.nodes[1].sendrawtransaction(tx_orig) | self.nodes[1].sendrawtransaction(tx_orig) | ||||
self.nodes[1].generatetoaddress(1, ADDRESS_WATCHONLY) | self.nodes[1].generatetoaddress(1, ADDRESS_WATCHONLY) | ||||
self.sync_all() | self.sync_all() | ||||
# The reorg recovered our fee of 1 coin | # The reorg recovered our fee of 1 coin | ||||
assert_equal(self.nodes[0].getbalance(minconf=0), total_amount + 1) | assert_equal(self.nodes[0].getbalance(minconf=0), total_amount + 1) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
WalletTest().main() | WalletTest().main() |