Test the `rpc_command` hook chain
(node_factory)
| 1806 | |
| 1807 | |
| 1808 | def test_rpc_command_hook(node_factory): |
| 1809 | """Test the `rpc_command` hook chain""" |
| 1810 | plugin = [ |
| 1811 | os.path.join(os.getcwd(), "tests/plugins/rpc_command_1.py"), |
| 1812 | os.path.join(os.getcwd(), "tests/plugins/rpc_command_2.py") |
| 1813 | ] |
| 1814 | l1 = node_factory.get_node(options={"plugin": plugin}) |
| 1815 | |
| 1816 | # rpc_command_2 plugin restricts using "sendpay" |
| 1817 | with pytest.raises(RpcError, match=r"rpc_command_2 cannot do this"): |
| 1818 | l1.rpc.call("sendpay") |
| 1819 | |
| 1820 | # Both plugins will replace calls made for the "invoice" command |
| 1821 | # The first will win, for the second a warning should be logged |
| 1822 | invoice = l1.rpc.invoice(10**6, "test_side", "test_input") |
| 1823 | decoded = l1.rpc.decode(invoice["bolt11"]) |
| 1824 | assert decoded["description"] == "rpc_command_1 modified this description" |
| 1825 | l1.daemon.wait_for_log("rpc_command hook 'invoice' already modified, ignoring.") |
| 1826 | |
| 1827 | # Disable schema checking here! |
| 1828 | schemas = l1.rpc.jsonschemas |
| 1829 | l1.rpc.jsonschemas = {} |
| 1830 | # rpc_command_1 plugin sends a custom response to "listfunds" |
| 1831 | funds = l1.rpc.listfunds() |
| 1832 | assert funds[0] == "Custom rpc_command_1 result" |
| 1833 | |
| 1834 | # Test command redirection to a plugin |
| 1835 | l1.rpc.call('help', ['developer']) |
| 1836 | |
| 1837 | # Check the 'already modified' warning is not logged on just 'continue' |
| 1838 | assert not l1.daemon.is_in_log("rpc_command hook 'listfunds' already modified, ignoring.") |
| 1839 | |
| 1840 | # Tests removing a chained hook in random order. |
| 1841 | # Note: This will get flaky by design if theres a problem. |
| 1842 | if bool(random.getrandbits(1)): |
| 1843 | l1.rpc.plugin_stop('rpc_command_2.py') |
| 1844 | l1.rpc.plugin_stop('rpc_command_1.py') |
| 1845 | else: |
| 1846 | l1.rpc.plugin_stop('rpc_command_1.py') |
| 1847 | l1.rpc.plugin_stop('rpc_command_2.py') |
| 1848 | |
| 1849 | l1.rpc.jsonschemas = schemas |
| 1850 | |
| 1851 | |
| 1852 | def test_libplugin(node_factory): |
nothing calls this directly
no test coverage detected