Skip to content

Commit

Permalink
pytest: Test the rust bindings from cln-rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
cdecker committed Feb 11, 2022
1 parent faa3835 commit 787350e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions cln-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cln-rpc/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 18 additions & 0 deletions cln-rpc/examples/getinfo.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
23 changes: 23 additions & 0 deletions tests/test_cln_rs.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 787350e

Please sign in to comment.