Skip to content

Commit

Permalink
pytest: Add test for optional options in cln-plugin
Browse files Browse the repository at this point in the history
Changelog-Added: cln-plugin: Options are no longer required to have a default value
  • Loading branch information
cdecker committed Nov 3, 2022
1 parent f111d67 commit 2605e11
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions plugins/examples/cln-plugin-startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@ async fn main() -> Result<(), anyhow::Error> {
options::Value::Integer(42),
"a test-option with default 42",
))
.option(options::ConfigOption::new(
"opt-option",
options::Value::OptInteger,
"An optional option",
))
.rpcmethod("testmethod", "This is a test", testmethod)
.rpcmethod(
"testoptions",
"Retrieve options from this plugin",
testoptions,
)
.subscribe("connect", connect_handler)
.hook("peer_connected", peer_connected_handler)
.start(state)
Expand All @@ -26,6 +36,12 @@ async fn main() -> Result<(), anyhow::Error> {
}
}

async fn testoptions(p: Plugin<()>, _v: serde_json::Value) -> Result<serde_json::Value, Error> {
Ok(json!({
"opt-option": format!("{:?}", p.option("opt-option").unwrap())
}))
}

async fn testmethod(_p: Plugin<()>, _v: serde_json::Value) -> Result<serde_json::Value, Error> {
Ok(json!("Hello"))
}
Expand Down
14 changes: 14 additions & 0 deletions tests/test_cln_rs.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ def test_plugin_start(node_factory):
l1.daemon.wait_for_log(r'Got a connect notification')


def test_plugin_optional_opts(node_factory):
"""Start a minimal plugin and ensure it is well-behaved
"""
bin_path = Path.cwd() / "target" / "debug" / "examples" / "cln-plugin-startup"
l1 = node_factory.get_node(options={"plugin": str(bin_path), 'opt-option': 31337})
opts = l1.rpc.testoptions()
print(opts)

# Do not set any value, should be None now
l1 = node_factory.get_node(options={"plugin": str(bin_path)})
opts = l1.rpc.testoptions()
print(opts)


def test_grpc_connect(node_factory):
"""Attempts to connect to the grpc interface and call getinfo"""
# These only exist if we have rust!
Expand Down

0 comments on commit 2605e11

Please sign in to comment.