Skip to content

Commit 8bb405b

Browse files
committed
test: getaddressinfo labels purpose deprecation test
1 parent 60aba1f commit 8bb405b

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2020 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""
6+
Test deprecation of RPC getaddressinfo `labels` returning an array
7+
containing a JSON hash of `name` and purpose` key-value pairs. It now
8+
returns an array of label names.
9+
10+
"""
11+
from test_framework.test_framework import BitcoinTestFramework
12+
from test_framework.util import assert_equal
13+
14+
LABELS_TO_TEST = frozenset({"" , "New 𝅘𝅥𝅯 $<#>&!рыба Label"})
15+
16+
class GetAddressInfoLabelsPurposeDeprecationTest(BitcoinTestFramework):
17+
def set_test_params(self):
18+
self.num_nodes = 2
19+
self.setup_clean_chain = False
20+
# Start node[0] with -deprecatedrpc=labelspurpose and node[1] without.
21+
self.extra_args = [["-deprecatedrpc=labelspurpose"], []]
22+
23+
def skip_test_if_missing_module(self):
24+
self.skip_if_no_wallet()
25+
26+
def test_labels(self, node_num, label_name, expected_value):
27+
node = self.nodes[node_num]
28+
address = node.getnewaddress()
29+
if label_name != "":
30+
node.setlabel(address, label_name)
31+
self.log.info(" set label to {}".format(label_name))
32+
labels = node.getaddressinfo(address)["labels"]
33+
self.log.info(" labels = {}".format(labels))
34+
assert_equal(labels, expected_value)
35+
36+
def run_test(self):
37+
"""Test getaddressinfo labels with and without -deprecatedrpc flag."""
38+
self.log.info("Test getaddressinfo labels with -deprecatedrpc flag")
39+
for label in LABELS_TO_TEST:
40+
self.test_labels(node_num=0, label_name=label, expected_value=[{"name": label, "purpose": "receive"}])
41+
42+
self.log.info("Test getaddressinfo labels without -deprecatedrpc flag")
43+
for label in LABELS_TO_TEST:
44+
self.test_labels(node_num=1, label_name=label, expected_value=[label])
45+
46+
47+
if __name__ == '__main__':
48+
GetAddressInfoLabelsPurposeDeprecationTest().main()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@
212212
'p2p_permissions.py',
213213
'feature_blocksdir.py',
214214
'feature_config_args.py',
215+
'rpc_getaddressinfo_labels_purpose_deprecation.py',
215216
'rpc_help.py',
216217
'feature_help.py',
217218
'feature_shutdown.py',

0 commit comments

Comments
 (0)