Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_listreceivedby.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 listreceivedbyaddress RPC.""" | """Test the listreceivedbyaddress RPC.""" | ||||
from decimal import Decimal | from decimal import Decimal | ||||
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_raises_rpc_error, | assert_raises_rpc_error, | ||||
) | ) | ||||
from test_framework.wallet_util import ( | |||||
labels_value, | |||||
test_address, | |||||
) | |||||
class ReceivedByTest(BitcoinTestFramework): | class ReceivedByTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
def skip_test_if_missing_module(self): | def skip_test_if_missing_module(self): | ||||
self.skip_if_no_wallet() | self.skip_if_no_wallet() | ||||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
assert_raises_rpc_error(-4, "Address not found in wallet", | assert_raises_rpc_error(-4, "Address not found in wallet", | ||||
self.nodes[0].getreceivedbyaddress, addr) | self.nodes[0].getreceivedbyaddress, addr) | ||||
self.log.info("listreceivedbylabel + getreceivedbylabel Test") | self.log.info("listreceivedbylabel + getreceivedbylabel Test") | ||||
# set pre-state | # set pre-state | ||||
label = '' | label = '' | ||||
address = self.nodes[1].getnewaddress() | address = self.nodes[1].getnewaddress() | ||||
assert_equal(self.nodes[1].getaddressinfo(address)['label'], label) | test_address( | ||||
self.nodes[1], | |||||
address, | |||||
label=label, | |||||
labels=labels_value( | |||||
name=label)) | |||||
received_by_label_json = [ | received_by_label_json = [ | ||||
r for r in self.nodes[1].listreceivedbylabel() if r["label"] == label][0] | r for r in self.nodes[1].listreceivedbylabel() if r["label"] == label][0] | ||||
balance_by_label = self.nodes[1].getreceivedbylabel(label) | balance_by_label = self.nodes[1].getreceivedbylabel(label) | ||||
txid = self.nodes[0].sendtoaddress(addr, 0.1) | txid = self.nodes[0].sendtoaddress(addr, 0.1) | ||||
self.sync_all() | self.sync_all() | ||||
# listreceivedbylabel should return received_by_label_json because of 0 | # listreceivedbylabel should return received_by_label_json because of 0 | ||||
Show All 37 Lines |