diff --git a/Makefile b/Makefile index 618cc2d67..35c5b34ae 100644 --- a/Makefile +++ b/Makefile @@ -422,7 +422,7 @@ else endif endif -pytest: $(ALL_PROGRAMS) $(ALL_TEST_PROGRAMS) +pytest: $(ALL_PROGRAMS) $(DEFAULT_TARGETS) $(ALL_TEST_PROGRAMS) ifeq ($(PYTEST),) @echo "py.test is required to run the integration tests, please install using 'pip3 install -r requirements.txt', and rerun 'configure'." exit 1 diff --git a/cln-rpc/Cargo.toml b/cln-rpc/Cargo.toml index 4145d20a9..3c8f7f6e4 100644 --- a/cln-rpc/Cargo.toml +++ b/cln-rpc/Cargo.toml @@ -3,6 +3,10 @@ name = "cln-rpc" version = "0.1.0" edition = "2021" +[[example]] +name = "cln-rpc-getinfo" +path = "examples/getinfo.rs" + [dependencies] anyhow = "1.0.51" bytes = "1.1.0" diff --git a/cln-rpc/Makefile b/cln-rpc/Makefile index a1812982c..646d268d2 100644 --- a/cln-rpc/Makefile +++ b/cln-rpc/Makefile @@ -1,7 +1,7 @@ cln-rpc-wrongdir: $(MAKE) -C .. cln-rpc-all -CLN_RPC_EXAMPLES := +CLN_RPC_EXAMPLES := target/debug/examples/cln-rpc-getinfo CLN_RPC_GENALL = cln-rpc/src/model.rs CLN_RPC_SOURCES = $(shell find cln-rpc -name *.rs) ${CLN_RPC_GENALL} JSON_SCHEMA = doc/schemas/*.schema.json diff --git a/cln-rpc/examples/getinfo.rs b/cln-rpc/examples/getinfo.rs new file mode 100644 index 000000000..2ca02e76b --- /dev/null +++ b/cln-rpc/examples/getinfo.rs @@ -0,0 +1,18 @@ +use anyhow::Context; +use cln_rpc::{model::GetinfoRequest, ClnRpc, Request}; +use log::info; +use std::env::args; +use std::path::Path; +use tokio; + +#[tokio::main] +async fn main() -> Result<(), anyhow::Error> { + env_logger::init(); + let rpc_path = args().nth(1).context("missing argument: socket path")?; + let p = Path::new(&rpc_path); + + let mut rpc = ClnRpc::new(p).await?; + let response = rpc.call(Request::Getinfo(GetinfoRequest {})).await?; + info!("{}", serde_json::to_string_pretty(&response)?); + Ok(()) +} diff --git a/tests/test_cln_rs.py b/tests/test_cln_rs.py new file mode 100644 index 000000000..af01642a4 --- /dev/null +++ b/tests/test_cln_rs.py @@ -0,0 +1,23 @@ +from fixtures import * # noqa: F401,F403 +from pathlib import Path +from pyln.testing.utils import env, TEST_NETWORK +import subprocess +import os +import pytest + + +# Skip the entire module if we don't have Rust. +pytestmark = pytest.mark.skipif( + env('RUST') != '1', + 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)