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 (
|
2022-12-02 21:10:51 -08:00
|
|
|
assert_true,
|
2022-04-21 15:47:56 -07:00
|
|
|
start_nodes,
|
|
|
|
stop_nodes,
|
|
|
|
wait_bitcoinds,
|
|
|
|
)
|
|
|
|
from test_framework.authproxy import JSONRPCException
|
|
|
|
|
2023-02-10 15:51:56 -08:00
|
|
|
import os.path
|
|
|
|
|
2023-02-10 15:39:19 -08:00
|
|
|
# Pick a subset of the deprecated RPC methods to test with. This test assumes that
|
|
|
|
# the deprecation feature name is the same as the RPC method name, and that the RPC
|
|
|
|
# method works without any arguments.
|
2023-02-10 16:00:22 -08:00
|
|
|
TESTABLE_FEATURES = [
|
2023-02-10 15:39:19 -08:00
|
|
|
"z_gettotalbalance",
|
|
|
|
"getnewaddress",
|
|
|
|
"z_getnewaddress",
|
|
|
|
]
|
|
|
|
|
2022-04-21 15:47:56 -07:00
|
|
|
# Test wallet address behaviour across network upgrades
|
|
|
|
class WalletDeprecationTest(BitcoinTestFramework):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
self.num_nodes = 1
|
|
|
|
|
2023-02-10 15:51:56 -08:00
|
|
|
def setup_chain(self):
|
|
|
|
super().setup_chain()
|
|
|
|
# Save a copy of node 0's zcash.conf
|
|
|
|
with open(os.path.join(self.options.tmpdir, "node0", "zcash.conf"), 'r', encoding='utf8') as f:
|
|
|
|
self.conf_lines = f.readlines()
|
|
|
|
|
2022-04-21 15:47:56 -07:00
|
|
|
def setup_network(self):
|
2023-02-10 15:39:19 -08:00
|
|
|
self.setup_network_with_args([])
|
2022-04-21 15:47:56 -07:00
|
|
|
|
2023-02-10 15:39:19 -08:00
|
|
|
def setup_network_with_args(self, allowed_deprecated):
|
2022-04-21 15:47:56 -07:00
|
|
|
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)
|
|
|
|
|
2023-02-10 15:51:56 -08:00
|
|
|
def setup_network_with_config(self, allowed_deprecated):
|
|
|
|
conf_lines = self.conf_lines + ["allowdeprecated={}\n".format(v) for v in allowed_deprecated]
|
|
|
|
with open(os.path.join(self.options.tmpdir, "node0", "zcash.conf"), 'w', encoding='utf8') as f:
|
|
|
|
f.writelines(conf_lines)
|
|
|
|
|
|
|
|
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir)
|
|
|
|
|
2022-12-02 21:10:51 -08:00
|
|
|
def verify_enabled(self, function):
|
|
|
|
try:
|
|
|
|
getattr(self.nodes[0], function)()
|
|
|
|
except JSONRPCException as e:
|
|
|
|
raise AssertionError("'%s' not enabled (failed with '%s')" % (
|
|
|
|
function,
|
|
|
|
e.error['message'],
|
|
|
|
))
|
2022-04-21 15:47:56 -07:00
|
|
|
|
2022-12-02 21:10:51 -08:00
|
|
|
def verify_disabled(self, function):
|
2022-04-21 15:47:56 -07:00
|
|
|
errorString = ''
|
|
|
|
try:
|
2022-12-02 21:10:51 -08:00
|
|
|
getattr(self.nodes[0], function)()
|
2022-04-21 15:47:56 -07:00
|
|
|
except JSONRPCException as e:
|
|
|
|
errorString = e.error['message']
|
2022-12-02 21:10:51 -08:00
|
|
|
assert_true(
|
|
|
|
"DEPRECATED" in errorString,
|
|
|
|
"'%s' not disabled (%s)" % (
|
|
|
|
function,
|
|
|
|
"failed with '%s'" % errorString if len(errorString) > 0 else "succeeded",
|
|
|
|
))
|
|
|
|
|
2023-02-10 16:00:22 -08:00
|
|
|
def test_case(self, start_mode, features_to_allow, expected_state, default_enabled, default_disabled):
|
2023-02-10 15:39:19 -08:00
|
|
|
stop_nodes(self.nodes)
|
|
|
|
wait_bitcoinds()
|
|
|
|
start_mode(features_to_allow)
|
2022-12-02 21:10:51 -08:00
|
|
|
|
2023-02-10 16:00:22 -08:00
|
|
|
for function in default_enabled:
|
|
|
|
if function in TESTABLE_FEATURES:
|
|
|
|
expected_state(function)
|
|
|
|
for function in default_disabled:
|
|
|
|
if function in TESTABLE_FEATURES:
|
|
|
|
expected_state(function)
|
2023-02-10 15:39:19 -08:00
|
|
|
|
|
|
|
def run_test(self):
|
2023-02-10 16:00:22 -08:00
|
|
|
dep_info = self.nodes[0].getdeprecationinfo()
|
|
|
|
default_enabled = dep_info['deprecated_features']
|
|
|
|
default_disabled = dep_info['disabled_features']
|
|
|
|
|
2023-03-09 08:31:37 -08:00
|
|
|
for function in TESTABLE_FEATURES:
|
|
|
|
assert(function in default_enabled or function in default_disabled)
|
|
|
|
|
2022-12-02 21:10:51 -08:00
|
|
|
# RPC methods that are deprecated but enabled by default should succeed
|
2023-02-10 16:00:22 -08:00
|
|
|
for function in default_enabled:
|
|
|
|
if function in TESTABLE_FEATURES:
|
|
|
|
self.verify_enabled(function)
|
2022-12-02 21:10:51 -08:00
|
|
|
|
|
|
|
# RPC methods that are deprecated and not enabled by default should fail
|
2023-02-10 16:00:22 -08:00
|
|
|
for function in default_disabled:
|
|
|
|
if function in TESTABLE_FEATURES:
|
|
|
|
self.verify_disabled(function)
|
2022-04-21 15:47:56 -07:00
|
|
|
|
2023-02-10 15:51:56 -08:00
|
|
|
for start_mode in (self.setup_network_with_args, self.setup_network_with_config):
|
2023-02-10 15:39:19 -08:00
|
|
|
# restart with a specific selection of deprecated methods enabled
|
2023-02-10 16:00:22 -08:00
|
|
|
self.test_case(start_mode, default_disabled, self.verify_enabled, default_enabled, default_disabled)
|
2022-04-21 15:47:56 -07:00
|
|
|
|
2023-02-10 15:39:19 -08:00
|
|
|
# restart with no deprecated methods enabled
|
2023-02-10 16:00:22 -08:00
|
|
|
self.test_case(start_mode, ["none"], self.verify_disabled, default_enabled, default_disabled)
|
2022-04-21 15:47:56 -07:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
WalletDeprecationTest().main()
|