Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_labels.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2016-2017 The Bitcoin Core developers | # Copyright (c) 2016-2017 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 label RPCs. | """Test label RPCs. | ||||
RPCs tested are: | RPCs tested are: | ||||
- getaddressesbylabel | - getaddressesbylabel | ||||
- listaddressgroupings | - listaddressgroupings | ||||
- setlabel | - setlabel | ||||
""" | """ | ||||
from collections import defaultdict | from collections import defaultdict | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import assert_equal, assert_raises_rpc_error | from test_framework.util import assert_equal, assert_raises_rpc_error | ||||
from test_framework.wallet_util import ( | |||||
labels_value, | |||||
test_address, | |||||
) | |||||
class WalletLabelsTest(BitcoinTestFramework): | class WalletLabelsTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
def skip_test_if_missing_module(self): | def skip_test_if_missing_module(self): | ||||
▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | def add_address(self, address): | ||||
self.addresses.append(address) | self.addresses.append(address) | ||||
def add_receive_address(self, address): | def add_receive_address(self, address): | ||||
self.add_address(address) | self.add_address(address) | ||||
def verify(self, node): | def verify(self, node): | ||||
if self.receive_address is not None: | if self.receive_address is not None: | ||||
assert self.receive_address in self.addresses | assert self.receive_address in self.addresses | ||||
for address in self.addresses: | for address in self.addresses: | ||||
assert_equal( | test_address( | ||||
node.getaddressinfo(address)['labels'][0], | node, | ||||
{"name": self.name, | address, | ||||
"purpose": self.purpose[address]}) | label=self.name, | ||||
assert_equal(node.getaddressinfo(address)['label'], self.name) | labels=labels_value( | ||||
name=self.name, purpose=self.purpose[address]) | |||||
) | |||||
assert self.name in node.listlabels() | |||||
assert_equal( | assert_equal( | ||||
node.getaddressesbylabel(self.name), | node.getaddressesbylabel(self.name), | ||||
{address: {"purpose": self.purpose[address]} for address in self.addresses}) | {address: {"purpose": self.purpose[address]} for address in self.addresses}) | ||||
def change_label(node, address, old_label, new_label): | def change_label(node, address, old_label, new_label): | ||||
assert_equal(address in old_label.addresses, True) | assert_equal(address in old_label.addresses, True) | ||||
node.setlabel(address, new_label.name) | node.setlabel(address, new_label.name) | ||||
Show All 10 Lines |