pytest: Test the rust bindings from cln-rpc

This commit is contained in:
Christian Decker 2022-01-14 18:56:00 +01:00
parent faa3835177
commit 787350eaa9
5 changed files with 47 additions and 2 deletions

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -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
tests/test_cln_rs.py Normal file
View File

@ -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)