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

Function test_libplugin

tests/test_plugin.py:1852–1971  ·  view source on GitHub ↗

Sanity checks for plugins made with libplugin

(node_factory)

Source from the content-addressed store, hash-verified

1850
1851
1852def test_libplugin(node_factory):
1853 """Sanity checks for plugins made with libplugin"""
1854 plugin = os.path.join(os.getcwd(), "tests/plugins/test_libplugin")
1855 l1 = node_factory.get_node(options={"plugin": plugin,
1856 'allow-deprecated-apis': False,
1857 'log-level': 'io'},
1858 broken_log='plugin-test_libplugin: Datastore gave nonstring result')
1859
1860 # Test startup
1861 assert l1.daemon.is_in_log("test_libplugin initialised!")
1862 assert l1.daemon.is_in_log("String name from datastore:.*token has no index 0")
1863 assert l1.daemon.is_in_log("Hex name from datastore:.*token has no index 0")
1864
1865 # This will look on datastore for default, won't find it.
1866 assert l1.rpc.call("helloworld") == {"hello": "NOT FOUND"}
1867 l1.daemon.wait_for_log("get_ds_bin_done: NOT FOUND")
1868
1869 # Check dynamic!
1870 assert l1.rpc.listconfigs('dynamicopt')['configs']['dynamicopt']['value_int'] == 7
1871
1872 with pytest.raises(RpcError) as err:
1873 l1.rpc.setconfig('dynamicopt', 4)
1874 assert err.value.error['message'] == 'I don\'t like \\"even\\" numbers (valid JSON? Try {})!'
1875
1876 with pytest.raises(RpcError) as err:
1877 l1.rpc.check(command_to_check='setconfig', config='dynamicopt', val=4)
1878 assert err.value.error['message'] == 'I don\'t like \\"even\\" numbers (valid JSON? Try {})!'
1879
1880 l1.rpc.check(command_to_check='setconfig', config='dynamicopt', val=9)
1881
1882 # Unchanged!
1883 assert l1.rpc.listconfigs('dynamicopt')['configs']['dynamicopt']['value_int'] == 7
1884
1885 l1.rpc.setconfig('dynamicopt', 9)
1886 conf = l1.rpc.listconfigs('dynamicopt')['configs']['dynamicopt']
1887 assert conf['value_int'] == 9
1888 assert conf['plugin'] == plugin
1889 assert conf['dynamic'] is True
1890
1891 # Test dynamic startup
1892 l1.rpc.plugin_stop(plugin)
1893 # Non-string datastore value:
1894 l1.rpc.datastore(["test_libplugin", "name"], hex="00010203")
1895 l1.rpc.plugin_start(plugin)
1896 l1.rpc.check("helloworld")
1897
1898 myname = os.path.splitext(os.path.basename(sys.argv[0]))[0]
1899
1900 # getmanifest assumes everyone handles string-based JSON ids:
1901 l1.daemon.wait_for_log(r'test_libplugin: "[-A-Za-z0-9:#]*/cln:getmanifest#[0-9]*"\[OUT\]')
1902
1903 l1.daemon.wait_for_log("String name from datastore:.*object does not have member string")
1904 l1.daemon.wait_for_log("Hex name from datastore: 00010203")
1905
1906 # Test commands
1907 assert l1.rpc.call("helloworld") == {"hello": "NOT FOUND"}
1908 l1.daemon.wait_for_log(r'listpeers gave 3 tokens: {"peers":\[\]}')
1909 l1.daemon.wait_for_log("get_ds_bin_done: 00010203")

Callers

nothing calls this directly

Calls 15

only_oneFunction · 0.90
joinMethod · 0.80
is_in_logMethod · 0.80
wait_for_logMethod · 0.80
listconfigsMethod · 0.80
plugin_stopMethod · 0.80
plugin_startMethod · 0.80
is_in_stderrMethod · 0.80
anyClass · 0.50
get_nodeMethod · 0.45
callMethod · 0.45
checkMethod · 0.45

Tested by

no test coverage detected