zcashd/qa/rpc-tests/wallet_deprecation.py

75 lines
2.4 KiB
Python
Raw Normal View History

Allow deprecated wallet features to be preemptively disabled. This adds an `-allowdeprecated` CLI parameter whose value is a flag indicating a deprecated feature that should be explicitly enabled. Multiple instances of this argument may be provided. In the case that this parameter is not provided, all currently deprecated RPC methods that are not slated for removal in the next release remain available. A user may disable all deprecated features entirely by providing the string "none" as the argument to this parameter, or enable all deprecated features, including those slated for removal, by providing the string "all" as the argument to this parameter. In the case that "all" or "none" is specified, multiple invocations of `-allowdeprecated` are not permitted. To explicitly enable only a specific set of deprecated features, use `-allowdeprecated=<flag1> -allowdeprecated=<flagN> ...` when starting zcashd. The following flags are recognized: - "all" - enables all deprecated features. - "none" - disables all deprecated features. - "legacy_privacy" - enables the use of the deprecated "legacy" privacy policy for z_sendmany. This causes the default behavior to conform to the `FullPrivacy` directive in all cases instead of just for transactions involving unified addresses. - "getnewaddress" - enables the `getnewaddress` RPC method. - "z_getnewaddress" - enables the `z_getnewaddress` RPC method. - "zcrawreceive" - enables the `zcrawreceive` RPC method. - "zcrawjoinsplit" - enables the `zcrawjoinsplit` RPC method. - "zcrawkeygen" - enables the `zcrawkeygen` RPC method. - "addrtype" - when this option is set, the deprecated `type` attribute is returned in addition to `pool` or `address_type` (which contain the same information) in the results of RPC methods that return address metadata.
2022-04-21 15:47:56 -07:00
#!/usr/bin/env python3
# Copyright (c) 2022 The Zcash developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://www.opensource.org/licenses/mit-license.php .
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
start_nodes,
stop_nodes,
wait_bitcoinds,
)
from test_framework.authproxy import JSONRPCException
# Test wallet address behaviour across network upgrades
class WalletDeprecationTest(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 1
def setup_network(self):
self.setup_network_internal([])
def setup_network_internal(self, allowed_deprecated = []):
dep_args = ["-allowdeprecated=" + v for v in allowed_deprecated]
self.nodes = start_nodes(
self.num_nodes, self.options.tmpdir,
extra_args=[dep_args] * self.num_nodes)
def run_test(self):
# z_getnewaddress is deprecated, but enabled by default so it should succeed
self.nodes[0].z_getnewaddress()
# zcrawkeygen is deprecated, and not enabled by default so it should fail
errorString = ''
try:
self.nodes[0].zcrawkeygen()
except JSONRPCException as e:
errorString = e.error['message']
assert "DEPRECATED" in errorString
Allow deprecated wallet features to be preemptively disabled. This adds an `-allowdeprecated` CLI parameter whose value is a flag indicating a deprecated feature that should be explicitly enabled. Multiple instances of this argument may be provided. In the case that this parameter is not provided, all currently deprecated RPC methods that are not slated for removal in the next release remain available. A user may disable all deprecated features entirely by providing the string "none" as the argument to this parameter, or enable all deprecated features, including those slated for removal, by providing the string "all" as the argument to this parameter. In the case that "all" or "none" is specified, multiple invocations of `-allowdeprecated` are not permitted. To explicitly enable only a specific set of deprecated features, use `-allowdeprecated=<flag1> -allowdeprecated=<flagN> ...` when starting zcashd. The following flags are recognized: - "all" - enables all deprecated features. - "none" - disables all deprecated features. - "legacy_privacy" - enables the use of the deprecated "legacy" privacy policy for z_sendmany. This causes the default behavior to conform to the `FullPrivacy` directive in all cases instead of just for transactions involving unified addresses. - "getnewaddress" - enables the `getnewaddress` RPC method. - "z_getnewaddress" - enables the `z_getnewaddress` RPC method. - "zcrawreceive" - enables the `zcrawreceive` RPC method. - "zcrawjoinsplit" - enables the `zcrawjoinsplit` RPC method. - "zcrawkeygen" - enables the `zcrawkeygen` RPC method. - "addrtype" - when this option is set, the deprecated `type` attribute is returned in addition to `pool` or `address_type` (which contain the same information) in the results of RPC methods that return address metadata.
2022-04-21 15:47:56 -07:00
# restart with a specific selection of deprecated methods enabled
stop_nodes(self.nodes)
wait_bitcoinds()
self.setup_network_internal(["getnewaddress","zcrawkeygen"])
# z_getnewaddress is enabled by default, so it should succeed
self.nodes[0].z_getnewaddress()
Allow deprecated wallet features to be preemptively disabled. This adds an `-allowdeprecated` CLI parameter whose value is a flag indicating a deprecated feature that should be explicitly enabled. Multiple instances of this argument may be provided. In the case that this parameter is not provided, all currently deprecated RPC methods that are not slated for removal in the next release remain available. A user may disable all deprecated features entirely by providing the string "none" as the argument to this parameter, or enable all deprecated features, including those slated for removal, by providing the string "all" as the argument to this parameter. In the case that "all" or "none" is specified, multiple invocations of `-allowdeprecated` are not permitted. To explicitly enable only a specific set of deprecated features, use `-allowdeprecated=<flag1> -allowdeprecated=<flagN> ...` when starting zcashd. The following flags are recognized: - "all" - enables all deprecated features. - "none" - disables all deprecated features. - "legacy_privacy" - enables the use of the deprecated "legacy" privacy policy for z_sendmany. This causes the default behavior to conform to the `FullPrivacy` directive in all cases instead of just for transactions involving unified addresses. - "getnewaddress" - enables the `getnewaddress` RPC method. - "z_getnewaddress" - enables the `z_getnewaddress` RPC method. - "zcrawreceive" - enables the `zcrawreceive` RPC method. - "zcrawjoinsplit" - enables the `zcrawjoinsplit` RPC method. - "zcrawkeygen" - enables the `zcrawkeygen` RPC method. - "addrtype" - when this option is set, the deprecated `type` attribute is returned in addition to `pool` or `address_type` (which contain the same information) in the results of RPC methods that return address metadata.
2022-04-21 15:47:56 -07:00
# getnewaddress and zcrawkeygen are enabled so they should succeed.
self.nodes[0].getnewaddress()
self.nodes[0].zcrawkeygen()
# restart with no deprecated methods enabled
stop_nodes(self.nodes)
wait_bitcoinds()
self.setup_network_internal(["none"])
errorString = ''
try:
self.nodes[0].z_getnewaddress()
except JSONRPCException as e:
errorString = e.error['message']
assert "DEPRECATED" in errorString
errorString = ''
try:
self.nodes[0].zcrawkeygen()
except JSONRPCException as e:
errorString = e.error['message']
assert "DEPRECATED" in errorString
if __name__ == '__main__':
WalletDeprecationTest().main()