Skip to content

Commit

Permalink
pytest: Add a test for the cln-plugin logging integration
Browse files Browse the repository at this point in the history
  • Loading branch information
cdecker committed Jan 25, 2022
1 parent 2e8b8a5 commit b23527e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
10 changes: 6 additions & 4 deletions plugins/examples/cln-plugin-startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ use tokio;

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
env_logger::init();
let (plugin, input) = Builder::new((), tokio::io::stdin(), tokio::io::stdout()).build();

let plugin = Builder::new((), tokio::io::stdin(), tokio::io::stdout());
plugin.run().await;
Ok(())
tokio::spawn(async {
tokio::time::sleep(tokio::time::Duration::from_millis(1000)).await;
log::info!("Hello world");
});
plugin.run(input).await
}
17 changes: 14 additions & 3 deletions tests/test_cln_rs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,23 @@
reason='RUST is not enabled, skipping rust-dependent tests'
)

os.environ['RUST_LOG'] = "trace"


def test_rpc_client(node_factory):
l1 = node_factory.get_node()
bin_path = Path.cwd() / "target" / "debug" / "examples" / "cln-rpc-getinfo"
rpc_path = Path(l1.daemon.lightning_dir) / TEST_NETWORK / "lightning-rpc"
out = subprocess.check_output([bin_path, rpc_path], stderr=subprocess.STDOUT)
assert(b'0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518' in out)


def test_plugin_start(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)})

# The plugin should be in the list of active plugins
plugins = l1.rpc.plugin('list')['plugins']
assert len([p for p in plugins if 'cln-plugin-startup' in p['name'] and p['active']]) == 1

# Logging should also work through the log integration
l1.daemon.wait_for_log(r'Hello world')

0 comments on commit b23527e

Please sign in to comment.