|
| 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() |
0 commit comments