MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_setconfig_changed

Function test_setconfig_changed

tests/test_misc.py:4753–4799  ·  view source on GitHub ↗

Test that we correctly fail (not crash) if config file changed

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

4751
4752
4753def test_setconfig_changed(node_factory, bitcoind):
4754 """Test that we correctly fail (not crash) if config file changed"""
4755 l1 = node_factory.get_node(start=False)
4756
4757 netconfigfile = os.path.join(l1.daemon.opts.get("lightning-dir"), TEST_NETWORK, 'config')
4758 with open(netconfigfile, 'w') as file:
4759 file.write("min-capacity-sat=100")
4760 l1.start()
4761
4762 assert l1.rpc.listconfigs(config="min-capacity-sat")['configs']['min-capacity-sat']['value_int'] == 100
4763
4764 # Change it underneath
4765 with open(netconfigfile, 'w') as file:
4766 file.write("#some comment\nmin-capacity-sat=100")
4767
4768 # This will fail.
4769 with pytest.raises(RpcError, match=f'Configfile {netconfigfile} line 1 changed from min-capacity-sat=100 to #some comment!'):
4770 l1.rpc.check("setconfig", config="min-capacity-sat", val=9999)
4771 with pytest.raises(RpcError, match=f'Configfile {netconfigfile} line 1 changed from min-capacity-sat=100 to #some comment!'):
4772 l1.rpc.setconfig(config="min-capacity-sat", val=9999)
4773
4774 # Restore it.
4775 with open(netconfigfile, 'w') as file:
4776 file.write("min-capacity-sat=100")
4777
4778 # Succeeds
4779 l1.rpc.setconfig(config="min-capacity-sat", val=9999)
4780
4781 # Now mess with config.setconfig...
4782 setconfigfile = netconfigfile + ".setconfig"
4783 with open(setconfigfile, 'w') as file:
4784 pass
4785
4786 # Now this will fail (truncated)
4787 with pytest.raises(RpcError, match=f'Configfile {setconfigfile} no longer has 2 lines'):
4788 l1.rpc.check("setconfig", config="min-capacity-sat", val=9999)
4789 with pytest.raises(RpcError, match=f'Configfile {setconfigfile} no longer has 2 lines'):
4790 l1.rpc.setconfig(config="min-capacity-sat", val=9999)
4791
4792 # This will fail (changed)
4793 with open(setconfigfile, 'w') as file:
4794 file.write("# Created and update by setconfig, but you can edit this manually when node is stopped.\nmin-capacity-sat=999")
4795
4796 with pytest.raises(RpcError, match=f'Configfile {setconfigfile} line 2 changed from min-capacity-sat=9999 to min-capacity-sat=999!'):
4797 l1.rpc.check("setconfig", config="min-capacity-sat", val=9999)
4798 with pytest.raises(RpcError, match=f'Configfile {setconfigfile} line 2 changed from min-capacity-sat=9999 to min-capacity-sat=999!'):
4799 l1.rpc.setconfig(config="min-capacity-sat", val=9999)
4800
4801
4802def test_setconfig_dynamic_multi_option(node_factory, bitcoind):

Callers

nothing calls this directly

Calls 7

joinMethod · 0.80
listconfigsMethod · 0.80
get_nodeMethod · 0.45
getMethod · 0.45
writeMethod · 0.45
startMethod · 0.45
checkMethod · 0.45

Tested by

no test coverage detected