Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: rewrite integration testing #120

Merged
merged 5 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Integration testing
run: |
docker-compose up --exit-code-from rust_clightning_rpc --quiet-pull
- name: Upload lightning log
uses: actions/upload-artifact@v2
if: failure()
with:
path: |
sandbox/node_one.log
sandbox/node_two.log
name: ${{ github.run_number }}
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v22
- run: nix develop --command bash -c 'make check'
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"plugin_macros",
"conf",
"testing",
"tests",
]
resolver = "2"

37 changes: 0 additions & 37 deletions Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fmt:
$(CC) fmt --all

check:
$(CC) test --all
$(CC) test -- --show-output

example:
$(CC) build --example foo_plugin
Expand Down
26 changes: 13 additions & 13 deletions conf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ mod tests {
fn flush_conf_one() {
let path = get_conf_path();
let mut conf = CLNConf::new(path.to_string(), false);
conf.add_conf("plugin", "/some/path");
conf.add_conf("network", "bitcoin");
conf.add_conf("plugin", "/some/path").unwrap();
conf.add_conf("network", "bitcoin").unwrap();
let result = conf.flush();
assert!(result.is_ok());

Expand All @@ -282,9 +282,9 @@ mod tests {
fn flush_conf_two() {
let path = get_conf_path();
let mut conf = CLNConf::new(path.to_string(), false);
conf.add_conf("plugin", "/some/path");
conf.add_conf("plugin", "foo");
conf.add_conf("network", "bitcoin");
conf.add_conf("plugin", "/some/path").unwrap();
conf.add_conf("plugin", "foo").unwrap();
conf.add_conf("network", "bitcoin").unwrap();
let result = conf.flush();
assert!(result.is_ok());

Expand All @@ -303,10 +303,10 @@ mod tests {
fn flush_conf_three() {
let path = get_conf_path();
let mut conf = CLNConf::new(path.to_string(), false);
conf.add_conf("network", "bitcoin");
conf.add_conf("plugin", "/some/path");
conf.add_conf("plugin", "/some/other/path");
conf.rm_conf("plugin", None);
conf.add_conf("network", "bitcoin").unwrap();
conf.add_conf("plugin", "/some/path").unwrap();
conf.add_conf("plugin", "/some/other/path").unwrap();
conf.rm_conf("plugin", None).unwrap();
let result = conf.flush();
assert!(result.is_ok());

Expand All @@ -325,10 +325,10 @@ mod tests {
fn flush_conf_four() {
let path = get_conf_path();
let mut conf = CLNConf::new(path.to_string(), false);
conf.add_conf("network", "bitcoin");
conf.add_conf("plugin", "/some/path");
conf.add_conf("plugin", "/some/other/path");
conf.rm_conf("plugin", Some("/some/other/path"));
conf.add_conf("network", "bitcoin").unwrap();
conf.add_conf("plugin", "/some/path").unwrap();
conf.add_conf("plugin", "/some/other/path").unwrap();
conf.rm_conf("plugin", Some("/some/other/path")).unwrap();
let result = conf.flush();
assert!(result.is_ok());

Expand Down
5 changes: 0 additions & 5 deletions docker-compose.yaml

This file was deleted.

129 changes: 129 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
description = "A simple core lightning plugin that simplifies the Splice operation";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
};

outputs = { self, nixpkgs, flake-utils, rust-overlay, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ rust-overlay.overlay ];
};

clightning = pkgs.clightning.overrideAttrs (oldAttrs: {
version = "master-abfe";
src = pkgs.fetchgit {
url = "https://github.com/ElementsProject/lightning";
rev = "abfe55e2147ad6ff8d0a155cd49c90a6a659a164";
sha256 = "sha256-UDkrlss4ufd70zYWf6IESiJQ/yo9J7BSdVH5UKrIBbQ=";
fetchSubmodules = true;
};
configureFlags = [ "--disable-rust" "--disable-valgrind" ];
});
in {
packages = {
default = pkgs.gnumake;
};
formatter = pkgs.nixpkgs-fmt;

devShell = pkgs.mkShell {
buildInputs = with pkgs; [
# build dependencies
libcap
gcc
pkg-config
git

gnumake

rustc
cargo

# integration test dependencies
clightning
bitcoind
];

shellHook = ''
export HOST_CC=gcc
export PWD="$(pwd)"
'';
};
}
);
}
3 changes: 0 additions & 3 deletions plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,5 @@ serde_json = "1.0"
clightningrpc-common = { version = "0.3.0-beta.4" }
log = { version = "0.4.17", optional = true }

[dev-dependencies]
rstest = "0.10.0"

[features]
log = ["dep:log"]
12 changes: 6 additions & 6 deletions plugin/examples/foo_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ impl RPCCommand<PluginState> for HelloRPC {
}

#[derive(Clone)]
struct OnChannelOpened {}
struct OnShutdown {}

impl RPCCommand<PluginState> for OnChannelOpened {
fn call_void<'c>(&self, _plugin: &mut Plugin<PluginState>, _request: &'c Value) {
_plugin.log(LogLevel::Debug, "A new channel was opened!");
impl RPCCommand<PluginState> for OnShutdown {
fn call_void<'c>(&self, _: &mut Plugin<PluginState>, _: &'c Value) {
std::process::exit(0);
}
}

Expand All @@ -46,11 +46,11 @@ fn main() {
.add_opt(
"foo",
"flag",
None,
Some("false".to_owned()),
"An example of command line option",
false,
)
.register_notification("channel_opened", OnChannelOpened {})
.register_notification("shutdown", OnShutdown {})
.on_init(|plugin: &mut Plugin<_>| -> serde_json::Value {
plugin.log(LogLevel::Debug, "Custom init method called");
json!({})
Expand Down
18 changes: 8 additions & 10 deletions plugin/src/commands/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@
use std::collections::HashMap;
use std::sync::Arc;

use crate::commands::{
types::{RPCHookInfo, RPCMethodInfo},
RPCCommand,
};
use serde_json::Value;

use clightningrpc_common::json_utils::{add_bool, add_vec, init_payload};

use crate::commands::types::{InitConf, RPCHookInfo, RPCMethodInfo};
use crate::commands::RPCCommand;
use crate::errors::PluginError;
use crate::plugin::Plugin;
use crate::types::RpcOption;
use clightningrpc_common::json_utils::{add_bool, add_vec, init_payload};
use serde_json::Value;

use super::types::InitConf;

#[derive(Clone)]
/// Type to define the manifest method and its attributes, used during plugin initialization
#[derive(Clone)]
pub struct ManifestRPC {}

impl<T: Clone> RPCCommand<T> for ManifestRPC {
fn call<'c>(&self, plugin: &mut Plugin<T>, _request: Value) -> Result<Value, PluginError> {
fn call<'c>(&self, plugin: &mut Plugin<T>, _: Value) -> Result<Value, PluginError> {
let mut response = init_payload();
add_vec::<RpcOption>(
&mut response,
Expand Down Expand Up @@ -53,7 +51,7 @@
#[derive(Clone)]
/// Type to define the init method and its attributes, used in plugin
pub struct InitRPC<T: 'static + Clone> {
pub(crate) on_init: Option<Arc<dyn Fn(&mut Plugin<T>) -> Value>>,

Check warning on line 54 in plugin/src/commands/builtin.rs

View workflow job for this annotation

GitHub Actions / clippy

very complex type used. Consider factoring parts into `type` definitions

warning: very complex type used. Consider factoring parts into `type` definitions --> plugin/src/commands/builtin.rs:54:25 | 54 | pub(crate) on_init: Option<Arc<dyn Fn(&mut Plugin<T>) -> Value>>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity = note: `#[warn(clippy::type_complexity)]` on by default
}

impl<T: Clone> InitRPC<T> {
Expand Down
Loading
Loading