Skip to content

Commit ea928bf

Browse files
committed
pytest: use modern listconfigs.
Use the configs object, as the others are about to be deprecated. Signed-off-by: Rusty Russell <[email protected]>
1 parent 9cb2b2f commit ea928bf

File tree

5 files changed

+56
-53
lines changed

5 files changed

+56
-53
lines changed

contrib/pyln-testing/pyln/testing/utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,11 +1348,18 @@ def passes_filters(hmsg, filters):
13481348

13491349
def config(self, config_name):
13501350
try:
1351-
opt = self.rpc.listconfigs(config_name)
1352-
return opt[config_name]
1351+
config = self.rpc.listconfigs(config_name)
13531352
except RpcError:
13541353
return None
13551354

1355+
config = config['configs'][config_name]
1356+
for valfield in ('set',
1357+
'value_str', 'value_bool', 'value_int',
1358+
'values_str', 'values_bool', 'values_int'):
1359+
if valfield in config:
1360+
return config[valfield]
1361+
raise ValueError("Unknown value in config {}".format(config))
1362+
13561363
def dev_pay(self, bolt11, amount_msat=None, label=None, riskfactor=None,
13571364
maxfeepercent=None, retry_for=None,
13581365
maxdelay=None, exemptfee=None, use_shadow=True, exclude=[]):

tests/test_cln_rs.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,7 @@ def test_plugin_start(node_factory):
4343
plugins = l1.rpc.plugin('list')['plugins']
4444
assert len([p for p in plugins if 'cln-plugin-startup' in p['name'] and p['active']]) == 1
4545

46-
cfg = l1.rpc.listconfigs()
47-
p = cfg['plugins'][0]
48-
p['path'] = None # The path is host-specific, so blank it.
49-
expected = {
50-
'name': 'cln-plugin-startup',
51-
'options': {
52-
'test-option': 31337
53-
},
54-
'path': None
55-
}
56-
assert expected == p
46+
assert str(bin_path) in l1.rpc.listconfigs()['configs']['plugin']['values_str']
5747

5848
# Now check that the `testmethod was registered ok
5949
l1.rpc.help("testmethod") == {

tests/test_misc.py

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -726,36 +726,33 @@ def test_listconfigs(node_factory, bitcoind, chainparams):
726726
# Make extremely long entry, check it works
727727
for deprecated in (True, False):
728728
l1 = node_factory.get_node(options={'log-prefix': 'lightning1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
729-
'allow-deprecated-apis': deprecated})
730-
731-
configs = l1.rpc.listconfigs()
732-
# See utils.py
733-
assert configs['allow-deprecated-apis'] == deprecated
734-
assert configs['network'] == chainparams['name']
735-
assert configs['ignore-fee-limits'] is False
736-
assert configs['log-prefix'] == 'lightning1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
729+
'allow-deprecated-apis': deprecated,
730+
'wumbo': None})
731+
732+
configs = l1.rpc.listconfigs()['configs']
733+
# See utils.py for these values
734+
for name, valfield, val in (('allow-deprecated-apis', 'value_bool', deprecated),
735+
('network', 'value_str', chainparams['name']),
736+
('ignore-fee-limits', 'value_bool', False),
737+
('log-prefix', 'value_str', 'lightning1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')):
738+
c = configs[name]
739+
assert c['source'] == 'cmdline'
740+
assert c[valfield] == val
737741

738742
# These are aliases, but we don't print the (unofficial!) wumbo.
739743
assert 'wumbo' not in configs
740-
assert configs['large-channels'] is False
741-
742-
# Test one at a time.
743-
for c in configs.keys():
744-
if c.startswith('#') or c.startswith('plugins') or c == 'important-plugins' or c == 'configs':
745-
continue
746-
oneconfig = l1.rpc.listconfigs(config=c)
747-
assert(oneconfig[c] == configs[c])
744+
assert configs['large-channels']['set'] is True
745+
assert configs['large-channels']['source'] == 'cmdline'
748746

749747
# Test modern ones!
750-
for c in configs['configs'].keys():
748+
for c in configs.keys():
751749
oneconfig = l1.rpc.listconfigs(config=c)['configs']
752-
assert(oneconfig[c] == configs['configs'][c])
750+
assert oneconfig[c] == configs[c]
753751

754752

755753
def test_listconfigs_plugins(node_factory, bitcoind, chainparams):
756-
l1 = node_factory.get_node()
754+
l1 = node_factory.get_node(options={'allow-deprecated-apis': True})
757755

758-
# assert that we have pay plugin and that plugins have a name and path
759756
configs = l1.rpc.listconfigs()
760757
assert configs['important-plugins']
761758
assert len([p for p in configs['important-plugins'] if p['name'] == "pay"]) == 1
@@ -1701,8 +1698,19 @@ def check_new_log():
17011698
.format(l2.daemon.lightning_dir),
17021699
'-H',
17031700
'listconfigs']).decode('utf-8').splitlines()
1701+
# Arrays get split awkwardly by -H!
17041702
assert 'log-file=logfile1' in lines
1705-
assert 'log-file=logfile2' in lines
1703+
assert 'logfile2' in lines
1704+
1705+
# Flat mode is better!
1706+
lines = subprocess.check_output(['cli/lightning-cli',
1707+
'--network={}'.format(TEST_NETWORK),
1708+
'--lightning-dir={}'
1709+
.format(l2.daemon.lightning_dir),
1710+
'-F',
1711+
'listconfigs']).decode('utf-8').splitlines()
1712+
assert 'configs.log-file.values_str[0]=logfile1' in lines
1713+
assert 'configs.log-file.values_str[1]=logfile2' in lines
17061714

17071715

17081716
@unittest.skipIf(VALGRIND,
@@ -1738,8 +1746,8 @@ def test_configfile_before_chdir(node_factory):
17381746
# Update executable to point to right place
17391747
l1.daemon.executable = os.path.join(olddir, l1.daemon.executable)
17401748
l1.start()
1741-
assert l1.rpc.listconfigs()['always-use-proxy']
1742-
assert l1.rpc.listconfigs()['proxy'] == '127.0.0.1:100'
1749+
assert l1.rpc.listconfigs()['configs']['always-use-proxy'] == {'source': os.path.abspath(config) + ":1", 'value_bool': True}
1750+
assert l1.rpc.listconfigs()['configs']['proxy'] == {'source': os.path.abspath(config) + ":2", 'value_str': '127.0.0.1:100'}
17431751
os.chdir(olddir)
17441752

17451753

@@ -2159,7 +2167,7 @@ def test_relative_config_dir(node_factory):
21592167
os.chdir('/'.join(root_dir))
21602168
l1.daemon.executable = os.path.join(initial_dir, l1.daemon.executable)
21612169
l1.start()
2162-
assert os.path.isabs(l1.rpc.listconfigs()["lightning-dir"])
2170+
assert os.path.isabs(l1.rpc.listconfigs()['configs']["lightning-dir"]['value_str'])
21632171
l1.stop()
21642172
os.chdir(initial_dir)
21652173

@@ -2236,7 +2244,7 @@ def test_include(node_factory):
22362244
l1.daemon.opts['conf'] = os.path.join(subdir, "conf1")
22372245
l1.start()
22382246

2239-
assert l1.rpc.listconfigs('alias')['alias'] == 'conf2'
2247+
assert l1.rpc.listconfigs('alias')['configs']['alias'] == {'source': os.path.join(subdir, "conf2") + ":1", 'value_str': 'conf2'}
22402248

22412249

22422250
def test_config_in_subdir(node_factory, chainparams):
@@ -2248,7 +2256,7 @@ def test_config_in_subdir(node_factory, chainparams):
22482256
f.write('alias=test_config_in_subdir')
22492257
l1.start()
22502258

2251-
assert l1.rpc.listconfigs('alias')['alias'] == 'test_config_in_subdir'
2259+
assert l1.rpc.listconfigs('alias')['configs']['alias'] == {'source': os.path.join(subdir, "config") + ":1", 'value_str': 'test_config_in_subdir'}
22522260

22532261
l1.stop()
22542262

@@ -2928,7 +2936,7 @@ def test_notimestamp_logging(node_factory):
29282936
l1.start()
29292937
assert l1.daemon.logs[0].startswith("DEBUG")
29302938

2931-
assert l1.rpc.listconfigs()['log-timestamps'] is False
2939+
assert l1.rpc.listconfigs()['configs']['log-timestamps']['value_bool'] is False
29322940

29332941

29342942
def test_getlog(node_factory):
@@ -2954,7 +2962,7 @@ def test_log_filter(node_factory):
29542962

29552963
def test_force_feerates(node_factory):
29562964
l1 = node_factory.get_node(options={'force-feerates': 1111})
2957-
assert l1.rpc.listconfigs()['force-feerates'] == '1111'
2965+
assert l1.rpc.listconfigs()['configs']['force-feerates']['value_str'] == '1111'
29582966

29592967
# Note that estimates are still valid here, despite "force-feerates"
29602968
estimates = [{"blockcount": 2,
@@ -2984,7 +2992,7 @@ def test_force_feerates(node_factory):
29842992
l1.daemon.opts['force-feerates'] = '1111/2222'
29852993
l1.start()
29862994

2987-
assert l1.rpc.listconfigs()['force-feerates'] == '1111/2222'
2995+
assert l1.rpc.listconfigs()['configs']['force-feerates']['value_str'] == '1111/2222'
29882996
assert l1.rpc.feerates('perkw')['perkw'] == {
29892997
"opening": 1111,
29902998
"mutual_close": 2222,
@@ -2999,7 +3007,7 @@ def test_force_feerates(node_factory):
29993007
l1.daemon.opts['force-feerates'] = '1111/2222/3333/4444/5555/6666'
30003008
l1.start()
30013009

3002-
assert l1.rpc.listconfigs()['force-feerates'] == '1111/2222/3333/4444/5555/6666'
3010+
assert l1.rpc.listconfigs()['configs']['force-feerates']['value_str'] == '1111/2222/3333/4444/5555/6666'
30033011
assert l1.rpc.feerates('perkw')['perkw'] == {
30043012
"opening": 1111,
30053013
"mutual_close": 2222,

tests/test_opening.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,7 +2025,7 @@ def test_openchannel_no_confirmed_inputs_opener(node_factory, bitcoind):
20252025
l2_opts = l1_opts.copy()
20262026
l1_opts['require-confirmed-inputs'] = True
20272027
l1, l2 = node_factory.get_nodes(2, opts=[l1_opts, l2_opts])
2028-
assert l1.rpc.listconfigs()['require-confirmed-inputs']
2028+
assert l1.rpc.listconfigs()['configs']['require-confirmed-inputs']['value_bool'] is True
20292029

20302030
amount = 500000
20312031
l1.fundwallet(20000000)
@@ -2066,7 +2066,7 @@ def test_openchannel_no_unconfirmed_inputs_accepter(node_factory, bitcoind):
20662066
l2_opts = l1_opts.copy()
20672067
l2_opts['require-confirmed-inputs'] = True
20682068
l1, l2 = node_factory.get_nodes(2, opts=[l1_opts, l2_opts])
2069-
assert l2.rpc.listconfigs()['require-confirmed-inputs']
2069+
assert l2.rpc.listconfigs()['configs']['require-confirmed-inputs']['value_bool'] is True
20702070

20712071
amount = 500000
20722072
l1.fundwallet(20000000)
@@ -2117,7 +2117,7 @@ def _no_utxo_response(r):
21172117
l2.stop()
21182118
del l2.daemon.opts['require-confirmed-inputs']
21192119
l2.start()
2120-
assert not l2.rpc.listconfigs()['require-confirmed-inputs']
2120+
assert l2.rpc.listconfigs()['configs']['require-confirmed-inputs']['value_bool'] is False
21212121

21222122
# Turn the mock back on so we pretend everything l1 sends is unconf
21232123
l2.daemon.rpcproxy.mock_rpc('gettxout', _no_utxo_response)

tests/test_plugin.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ def test_plugin_disable(node_factory):
363363
n = node_factory.get_node(options={'disable-plugin':
364364
['something-else.py', 'helloworld.py']})
365365

366-
assert n.rpc.listconfigs()['disable-plugin'] == ['something-else.py', 'helloworld.py']
366+
assert n.rpc.listconfigs()['configs']['disable-plugin'] == {'values_str': ['something-else.py', 'helloworld.py'], 'sources': ['cmdline', 'cmdline']}
367367

368368

369369
def test_plugin_hook(node_factory, executor):
@@ -1572,7 +1572,7 @@ def test_libplugin(node_factory):
15721572
with pytest.raises(RpcError, match=r"Deprecated command.*testrpc-deprecated"):
15731573
l1.rpc.help('testrpc-deprecated')
15741574

1575-
assert 'somearg-deprecated' not in str(l1.rpc.listconfigs())
1575+
assert 'somearg-deprecated' not in str(l1.rpc.listconfigs()['configs'])
15761576

15771577
l1.stop()
15781578
l1.daemon.opts["somearg-deprecated"] = "test_opt"
@@ -2440,12 +2440,10 @@ def test_dynamic_args(node_factory):
24402440
l1.rpc.plugin_start(plugin_path, greeting='Test arg parsing')
24412441

24422442
assert l1.rpc.call("hello") == "Test arg parsing world"
2443-
plugin = only_one([p for p in l1.rpc.listconfigs()['plugins'] if p['path'] == plugin_path])
2444-
assert plugin['options']['greeting'] == 'Test arg parsing'
2443+
assert l1.rpc.listconfigs('greeting')['configs']['greeting']['value_str'] == 'Test arg parsing'
24452444

24462445
l1.rpc.plugin_stop(plugin_path)
2447-
2448-
assert [p for p in l1.rpc.listconfigs()['plugins'] if p['path'] == plugin_path] == []
2446+
assert 'greeting' not in l1.rpc.listconfigs()['configs']
24492447

24502448

24512449
def test_pyln_request_notify(node_factory):
@@ -2532,7 +2530,7 @@ def test_custom_notification_topics(node_factory):
25322530

25332531
# The plugin just dist what previously was a fatal mistake (emit
25342532
# an unknown notification), make sure we didn't kill it.
2535-
assert 'custom_notifications.py' in [p['name'] for p in l1.rpc.listconfigs()['plugins']]
2533+
assert str(plugin) in [p['name'] for p in l1.rpc.plugin_list()['plugins']]
25362534

25372535

25382536
def test_restart_on_update(node_factory):

0 commit comments

Comments
 (0)