pytest: use modern listconfigs.

Use the configs object, as the others are about to be deprecated.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2023-06-02 12:06:04 +09:30
parent 9cb2b2f13a
commit ea928bfca1
5 changed files with 55 additions and 52 deletions

View file

@ -1348,11 +1348,18 @@ class LightningNode(object):
def config(self, config_name):
try:
opt = self.rpc.listconfigs(config_name)
return opt[config_name]
config = self.rpc.listconfigs(config_name)
except RpcError:
return None
config = config['configs'][config_name]
for valfield in ('set',
'value_str', 'value_bool', 'value_int',
'values_str', 'values_bool', 'values_int'):
if valfield in config:
return config[valfield]
raise ValueError("Unknown value in config {}".format(config))
def dev_pay(self, bolt11, amount_msat=None, label=None, riskfactor=None,
maxfeepercent=None, retry_for=None,
maxdelay=None, exemptfee=None, use_shadow=True, exclude=[]):

View file

@ -43,17 +43,7 @@ def test_plugin_start(node_factory):
plugins = l1.rpc.plugin('list')['plugins']
assert len([p for p in plugins if 'cln-plugin-startup' in p['name'] and p['active']]) == 1
cfg = l1.rpc.listconfigs()
p = cfg['plugins'][0]
p['path'] = None # The path is host-specific, so blank it.
expected = {
'name': 'cln-plugin-startup',
'options': {
'test-option': 31337
},
'path': None
}
assert expected == p
assert str(bin_path) in l1.rpc.listconfigs()['configs']['plugin']['values_str']
# Now check that the `testmethod was registered ok
l1.rpc.help("testmethod") == {

View file

@ -726,36 +726,33 @@ def test_listconfigs(node_factory, bitcoind, chainparams):
# Make extremely long entry, check it works
for deprecated in (True, False):
l1 = node_factory.get_node(options={'log-prefix': 'lightning1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'allow-deprecated-apis': deprecated})
'allow-deprecated-apis': deprecated,
'wumbo': None})
configs = l1.rpc.listconfigs()
# See utils.py
assert configs['allow-deprecated-apis'] == deprecated
assert configs['network'] == chainparams['name']
assert configs['ignore-fee-limits'] is False
assert configs['log-prefix'] == 'lightning1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
configs = l1.rpc.listconfigs()['configs']
# See utils.py for these values
for name, valfield, val in (('allow-deprecated-apis', 'value_bool', deprecated),
('network', 'value_str', chainparams['name']),
('ignore-fee-limits', 'value_bool', False),
('log-prefix', 'value_str', 'lightning1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')):
c = configs[name]
assert c['source'] == 'cmdline'
assert c[valfield] == val
# These are aliases, but we don't print the (unofficial!) wumbo.
assert 'wumbo' not in configs
assert configs['large-channels'] is False
# Test one at a time.
for c in configs.keys():
if c.startswith('#') or c.startswith('plugins') or c == 'important-plugins' or c == 'configs':
continue
oneconfig = l1.rpc.listconfigs(config=c)
assert(oneconfig[c] == configs[c])
assert configs['large-channels']['set'] is True
assert configs['large-channels']['source'] == 'cmdline'
# Test modern ones!
for c in configs['configs'].keys():
for c in configs.keys():
oneconfig = l1.rpc.listconfigs(config=c)['configs']
assert(oneconfig[c] == configs['configs'][c])
assert oneconfig[c] == configs[c]
def test_listconfigs_plugins(node_factory, bitcoind, chainparams):
l1 = node_factory.get_node()
l1 = node_factory.get_node(options={'allow-deprecated-apis': True})
# assert that we have pay plugin and that plugins have a name and path
configs = l1.rpc.listconfigs()
assert configs['important-plugins']
assert len([p for p in configs['important-plugins'] if p['name'] == "pay"]) == 1
@ -1701,8 +1698,19 @@ def test_logging(node_factory):
.format(l2.daemon.lightning_dir),
'-H',
'listconfigs']).decode('utf-8').splitlines()
# Arrays get split awkwardly by -H!
assert 'log-file=logfile1' in lines
assert 'log-file=logfile2' in lines
assert 'logfile2' in lines
# Flat mode is better!
lines = subprocess.check_output(['cli/lightning-cli',
'--network={}'.format(TEST_NETWORK),
'--lightning-dir={}'
.format(l2.daemon.lightning_dir),
'-F',
'listconfigs']).decode('utf-8').splitlines()
assert 'configs.log-file.values_str[0]=logfile1' in lines
assert 'configs.log-file.values_str[1]=logfile2' in lines
@unittest.skipIf(VALGRIND,
@ -1738,8 +1746,8 @@ def test_configfile_before_chdir(node_factory):
# Update executable to point to right place
l1.daemon.executable = os.path.join(olddir, l1.daemon.executable)
l1.start()
assert l1.rpc.listconfigs()['always-use-proxy']
assert l1.rpc.listconfigs()['proxy'] == '127.0.0.1:100'
assert l1.rpc.listconfigs()['configs']['always-use-proxy'] == {'source': os.path.abspath(config) + ":1", 'value_bool': True}
assert l1.rpc.listconfigs()['configs']['proxy'] == {'source': os.path.abspath(config) + ":2", 'value_str': '127.0.0.1:100'}
os.chdir(olddir)
@ -2159,7 +2167,7 @@ def test_relative_config_dir(node_factory):
os.chdir('/'.join(root_dir))
l1.daemon.executable = os.path.join(initial_dir, l1.daemon.executable)
l1.start()
assert os.path.isabs(l1.rpc.listconfigs()["lightning-dir"])
assert os.path.isabs(l1.rpc.listconfigs()['configs']["lightning-dir"]['value_str'])
l1.stop()
os.chdir(initial_dir)
@ -2236,7 +2244,7 @@ def test_include(node_factory):
l1.daemon.opts['conf'] = os.path.join(subdir, "conf1")
l1.start()
assert l1.rpc.listconfigs('alias')['alias'] == 'conf2'
assert l1.rpc.listconfigs('alias')['configs']['alias'] == {'source': os.path.join(subdir, "conf2") + ":1", 'value_str': 'conf2'}
def test_config_in_subdir(node_factory, chainparams):
@ -2248,7 +2256,7 @@ def test_config_in_subdir(node_factory, chainparams):
f.write('alias=test_config_in_subdir')
l1.start()
assert l1.rpc.listconfigs('alias')['alias'] == 'test_config_in_subdir'
assert l1.rpc.listconfigs('alias')['configs']['alias'] == {'source': os.path.join(subdir, "config") + ":1", 'value_str': 'test_config_in_subdir'}
l1.stop()
@ -2928,7 +2936,7 @@ def test_notimestamp_logging(node_factory):
l1.start()
assert l1.daemon.logs[0].startswith("DEBUG")
assert l1.rpc.listconfigs()['log-timestamps'] is False
assert l1.rpc.listconfigs()['configs']['log-timestamps']['value_bool'] is False
def test_getlog(node_factory):
@ -2954,7 +2962,7 @@ def test_log_filter(node_factory):
def test_force_feerates(node_factory):
l1 = node_factory.get_node(options={'force-feerates': 1111})
assert l1.rpc.listconfigs()['force-feerates'] == '1111'
assert l1.rpc.listconfigs()['configs']['force-feerates']['value_str'] == '1111'
# Note that estimates are still valid here, despite "force-feerates"
estimates = [{"blockcount": 2,
@ -2984,7 +2992,7 @@ def test_force_feerates(node_factory):
l1.daemon.opts['force-feerates'] = '1111/2222'
l1.start()
assert l1.rpc.listconfigs()['force-feerates'] == '1111/2222'
assert l1.rpc.listconfigs()['configs']['force-feerates']['value_str'] == '1111/2222'
assert l1.rpc.feerates('perkw')['perkw'] == {
"opening": 1111,
"mutual_close": 2222,
@ -2999,7 +3007,7 @@ def test_force_feerates(node_factory):
l1.daemon.opts['force-feerates'] = '1111/2222/3333/4444/5555/6666'
l1.start()
assert l1.rpc.listconfigs()['force-feerates'] == '1111/2222/3333/4444/5555/6666'
assert l1.rpc.listconfigs()['configs']['force-feerates']['value_str'] == '1111/2222/3333/4444/5555/6666'
assert l1.rpc.feerates('perkw')['perkw'] == {
"opening": 1111,
"mutual_close": 2222,

View file

@ -2025,7 +2025,7 @@ def test_openchannel_no_confirmed_inputs_opener(node_factory, bitcoind):
l2_opts = l1_opts.copy()
l1_opts['require-confirmed-inputs'] = True
l1, l2 = node_factory.get_nodes(2, opts=[l1_opts, l2_opts])
assert l1.rpc.listconfigs()['require-confirmed-inputs']
assert l1.rpc.listconfigs()['configs']['require-confirmed-inputs']['value_bool'] is True
amount = 500000
l1.fundwallet(20000000)
@ -2066,7 +2066,7 @@ def test_openchannel_no_unconfirmed_inputs_accepter(node_factory, bitcoind):
l2_opts = l1_opts.copy()
l2_opts['require-confirmed-inputs'] = True
l1, l2 = node_factory.get_nodes(2, opts=[l1_opts, l2_opts])
assert l2.rpc.listconfigs()['require-confirmed-inputs']
assert l2.rpc.listconfigs()['configs']['require-confirmed-inputs']['value_bool'] is True
amount = 500000
l1.fundwallet(20000000)
@ -2117,7 +2117,7 @@ def test_openchannel_no_unconfirmed_inputs_accepter(node_factory, bitcoind):
l2.stop()
del l2.daemon.opts['require-confirmed-inputs']
l2.start()
assert not l2.rpc.listconfigs()['require-confirmed-inputs']
assert l2.rpc.listconfigs()['configs']['require-confirmed-inputs']['value_bool'] is False
# Turn the mock back on so we pretend everything l1 sends is unconf
l2.daemon.rpcproxy.mock_rpc('gettxout', _no_utxo_response)

View file

@ -363,7 +363,7 @@ def test_plugin_disable(node_factory):
n = node_factory.get_node(options={'disable-plugin':
['something-else.py', 'helloworld.py']})
assert n.rpc.listconfigs()['disable-plugin'] == ['something-else.py', 'helloworld.py']
assert n.rpc.listconfigs()['configs']['disable-plugin'] == {'values_str': ['something-else.py', 'helloworld.py'], 'sources': ['cmdline', 'cmdline']}
def test_plugin_hook(node_factory, executor):
@ -1572,7 +1572,7 @@ def test_libplugin(node_factory):
with pytest.raises(RpcError, match=r"Deprecated command.*testrpc-deprecated"):
l1.rpc.help('testrpc-deprecated')
assert 'somearg-deprecated' not in str(l1.rpc.listconfigs())
assert 'somearg-deprecated' not in str(l1.rpc.listconfigs()['configs'])
l1.stop()
l1.daemon.opts["somearg-deprecated"] = "test_opt"
@ -2440,12 +2440,10 @@ def test_dynamic_args(node_factory):
l1.rpc.plugin_start(plugin_path, greeting='Test arg parsing')
assert l1.rpc.call("hello") == "Test arg parsing world"
plugin = only_one([p for p in l1.rpc.listconfigs()['plugins'] if p['path'] == plugin_path])
assert plugin['options']['greeting'] == 'Test arg parsing'
assert l1.rpc.listconfigs('greeting')['configs']['greeting']['value_str'] == 'Test arg parsing'
l1.rpc.plugin_stop(plugin_path)
assert [p for p in l1.rpc.listconfigs()['plugins'] if p['path'] == plugin_path] == []
assert 'greeting' not in l1.rpc.listconfigs()['configs']
def test_pyln_request_notify(node_factory):
@ -2532,7 +2530,7 @@ def test_custom_notification_topics(node_factory):
# The plugin just dist what previously was a fatal mistake (emit
# an unknown notification), make sure we didn't kill it.
assert 'custom_notifications.py' in [p['name'] for p in l1.rpc.listconfigs()['plugins']]
assert str(plugin) in [p['name'] for p in l1.rpc.plugin_list()['plugins']]
def test_restart_on_update(node_factory):