Test setconfig with multi-value dynamic plugin options (issue #8295).
(node_factory, bitcoind)
| 4800 | |
| 4801 | |
| 4802 | def test_setconfig_dynamic_multi_option(node_factory, bitcoind): |
| 4803 | """Test setconfig with multi-value dynamic plugin options (issue #8295).""" |
| 4804 | pluginpath = os.path.join(os.getcwd(), 'tests/plugins/dynamic_multi_option.py') |
| 4805 | l1 = node_factory.get_node(options={'plugin': pluginpath}) |
| 4806 | |
| 4807 | configfile = os.path.join(l1.daemon.opts.get("lightning-dir"), TEST_NETWORK, 'config') |
| 4808 | setconfigfile = configfile + ".setconfig" |
| 4809 | |
| 4810 | with pytest.raises(RpcError, match='is a multi option.*val must be an array'): |
| 4811 | l1.rpc.setconfig(config='test-multi-dynamic', val='single-value') |
| 4812 | |
| 4813 | with pytest.raises(RpcError, match='is not a multi option.*val must not be an array'): |
| 4814 | l1.rpc.setconfig(config='min-capacity-sat', val=['1000', '2000']) |
| 4815 | |
| 4816 | assert l1.rpc.call('dynamic-multi-report')['test-multi-dynamic'] is None |
| 4817 | |
| 4818 | # Transient before any permanent values exist |
| 4819 | ret = l1.rpc.setconfig(config='test-multi-dynamic', val=['transient1'], transient=True) |
| 4820 | assert 'transient' in ret['config']['sources'][0] |
| 4821 | assert l1.rpc.call('dynamic-multi-report')['test-multi-dynamic'] == ['transient1'] |
| 4822 | assert not os.path.exists(setconfigfile) |
| 4823 | |
| 4824 | # This used to crash with SIGABRT (issue #8295) |
| 4825 | ret = l1.rpc.setconfig(config='test-multi-dynamic', val=['value1', 'value2']) |
| 4826 | assert ret['config']['config'] == 'test-multi-dynamic' |
| 4827 | assert ret['config']['values_str'] == ['value1', 'value2'] |
| 4828 | assert ret['config']['dynamic'] is True |
| 4829 | assert l1.rpc.call('dynamic-multi-report')['test-multi-dynamic'] == ['value1', 'value2'] |
| 4830 | |
| 4831 | with open(setconfigfile, 'r') as f: |
| 4832 | lines = f.read().splitlines() |
| 4833 | assert "test-multi-dynamic=value1" in lines |
| 4834 | assert "test-multi-dynamic=value2" in lines |
| 4835 | |
| 4836 | # Replaces, doesn't append |
| 4837 | ret = l1.rpc.setconfig(config='test-multi-dynamic', val=['new1', 'new2']) |
| 4838 | assert ret['config']['values_str'] == ['new1', 'new2'] |
| 4839 | assert l1.rpc.call('dynamic-multi-report')['test-multi-dynamic'] == ['new1', 'new2'] |
| 4840 | |
| 4841 | # Empty strings and duplicates are preserved |
| 4842 | ret = l1.rpc.setconfig(config='test-multi-dynamic', val=['a', '', 'a']) |
| 4843 | assert ret['config']['values_str'] == ['a', '', 'a'] |
| 4844 | assert l1.rpc.call('dynamic-multi-report')['test-multi-dynamic'] == ['a', '', 'a'] |
| 4845 | |
| 4846 | # Transient overrides permanent |
| 4847 | ret = l1.rpc.setconfig(config='test-multi-dynamic', val=['transient_override'], transient=True) |
| 4848 | assert ret['config']['values_str'] == ['transient_override'] |
| 4849 | assert 'transient' in ret['config']['sources'][0] |
| 4850 | assert l1.rpc.call('dynamic-multi-report')['test-multi-dynamic'] == ['transient_override'] |
| 4851 | |
| 4852 | # Permanent clears transient |
| 4853 | ret = l1.rpc.setconfig(config='test-multi-dynamic', val=['back_to_perm']) |
| 4854 | assert ret['config']['values_str'] == ['back_to_perm'] |
| 4855 | assert 'transient' not in ret['config']['sources'][0] |
| 4856 | |
| 4857 | # Empty array clears all values |
| 4858 | ret = l1.rpc.setconfig(config='test-multi-dynamic', val=[]) |
| 4859 | assert ret['config']['values_str'] == [] |