Skip to content

Commit

Permalink
rpc: fix test with the new API
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Mar 10, 2023
1 parent f612b56 commit bdb3b0e
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 23 deletions.
6 changes: 3 additions & 3 deletions common/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ impl From<RpcError> for Error {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::Json(ref e) => write!(f, "JSON decode error: {}", e),
Error::Io(ref e) => write!(f, "IO error response: {}", e),
Error::Rpc(ref r) => write!(f, "RPC error response: {:?}", r),
Error::Json(ref e) => write!(f, "JSON decode error: {e}"),
Error::Io(ref e) => write!(f, "IO error response: {e}"),
Error::Rpc(ref r) => write!(f, "RPC error response: {r:?}"),
Error::NoErrorOrResult => write!(f, "Malformed RPC response"),
Error::NonceMismatch => write!(f, "Nonce of response did not match nonce of request"),
Error::VersionMismatch => write!(f, "`jsonrpc` field set to non-\"2.0\""),
Expand Down
8 changes: 4 additions & 4 deletions conf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ mod tests {
.duration_since(UNIX_EPOCH)
.unwrap()
.subsec_nanos();
format!("{dir}/conf-{}", nanos)
format!("{dir}/conf-{nanos}")
}

fn build_file(content: &str) -> Result<String, std::io::Error> {
Expand Down Expand Up @@ -193,7 +193,7 @@ mod tests {
let result = conf.parse();
assert!(result.is_ok());
assert_eq!(conf.fields.keys().len(), 2);
println!("{:?}", conf);
println!("{conf:?}");
assert!(conf.fields.contains_key("plugin"));
assert!(conf.fields.contains_key("network"));

Expand All @@ -214,7 +214,7 @@ mod tests {
let result = conf.parse();
assert!(result.is_ok());
assert_eq!(conf.fields.get("plugin").unwrap().len(), 2);
println!("{:?}", conf);
println!("{conf:?}");
assert!(conf.fields.contains_key("plugin"));
assert!(conf.fields.contains_key("network"));

Expand Down Expand Up @@ -248,7 +248,7 @@ mod tests {
format!("# this is just a commit\nplugin=foo\nnetwork=bitcoin\ninclude {subpath}")
.as_str(),
);
assert!(path.is_ok(), "{}", format!("{:?}", path));
assert!(path.is_ok(), "{}", format!("{path:?}"));
let path = path.unwrap();
let mut conf = CLNConf::new(path.to_string(), false);
let result = conf.parse();
Expand Down
8 changes: 3 additions & 5 deletions conf/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ impl Parser {
.collect();
let mut words = vec![];
for line in lines {
if line.starts_with("#") {
if line.starts_with('#') {
words.push(format!("comment {line}"));
continue;
}
if line.starts_with("include") {
words.push(line);
continue;
}
let mut split: Vec<String> = line.split("=").map(|it| it.to_owned()).collect();
let mut split: Vec<String> = line.split('=').map(|it| it.to_owned()).collect();
let key = split.first().unwrap().to_owned();
split.remove(0);
let val = if split.is_empty() {
Expand Down Expand Up @@ -91,9 +91,7 @@ impl Parser {
if key.starts_with("include") {
let value = key.strip_prefix("include ").unwrap().trim();
let mut subconf = CLNConf::new(value.to_owned(), false);
if let Err(err) = subconf.parse() {
return Err(err);
}
subconf.parse()?;
conf.add_subconf(subconf)?;
} else {
let value = stream.advance().to_owned();
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl<'a, T: 'a + Clone> Plugin<T> {
if let Err(json_res) = notification.call(self, params) {
self.log(
LogLevel::Debug,
format!("Notification end with and error: {}", json_res).as_str(),
format!("Notification end with and error: {json_res}").as_str(),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/tests/plugin_integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::path::Path;
pub fn lightningd() -> Client {
// FIXME(vincenzopalazzo): Using the env to take the path of the RPC file.
let sock = Path::new("/workdir/lightning_dir_one/regtest/lightning-rpc");
Client::new(&sock)
Client::new(sock)
}

#[rstest]
Expand Down
2 changes: 1 addition & 1 deletion plugin_macros/tests/plugin_integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::path::Path;
pub fn lightningd() -> Client {
// FIXME(vincenzopalazzo): Using the env to take the path of the RPC file.
let sock = Path::new("/workdir/lightning_dir_one/regtest/lightning-rpc");
Client::new(&sock)
Client::new(sock)
}

#[rstest]
Expand Down
22 changes: 14 additions & 8 deletions rpc/tests/rpc_utility_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ fn wait_for(millisecond: u64) {
pub fn lightningd() -> LightningRPC {
// FIXME(vincenzopalazzo): Using the env to take the path of the RPC file.
let sock = Path::new("/workdir/lightning_dir_two/regtest/lightning-rpc");
let client = LightningRPC::new(&sock);
client

LightningRPC::new(sock)
}

#[fixture]
pub fn lightningd_second() -> LightningRPC {
// FIXME(vincenzopalazzo): Using the env to take the path of the RPC file.
let sock = Path::new("/workdir/lightning_dir_one/regtest/lightning-rpc");
let client = LightningRPC::new(&sock);
client

LightningRPC::new(sock)
}

#[rstest]
Expand All @@ -54,7 +54,7 @@ fn connect_test_one(lightningd: LightningRPC, lightningd_second: LightningRPC) {
let host = match addr {
NetworkAddress::Ipv4 { address, port } => {
host.push_str(&address.to_string());
host.push_str(":");
host.push(':');
host.push_str(&port.to_string());
host
}
Expand All @@ -73,7 +73,7 @@ fn fundchannel_test_one(lightningd: LightningRPC, lightningd_second: LightningRP
let host = match addr {
NetworkAddress::Ipv4 { address, port } => {
host.push_str(&address.to_string());
host.push_str(":");
host.push(':');
host.push_str(&port.to_string());
host
}
Expand All @@ -97,7 +97,7 @@ fn listinvoice_by_payment_hash_test_one(lightningd: LightningRPC) {
fn generate_amountless_invoice_test_one(lightningd: LightningRPC) {
let label = format!("{}", Uuid::new_v4());
let invoice = lightningd
.invoice(None, label.as_str(), "generate an any invoice", None)
.invoice(None, label.as_str(), "generate an any invoice", None, None)
.unwrap();
let decode = lightningd.decodepay(&invoice.bolt11, None).unwrap();
assert_eq!(decode.amount_msat, None);
Expand All @@ -107,7 +107,13 @@ fn generate_amountless_invoice_test_one(lightningd: LightningRPC) {
fn generate_invoice_with_amount_test_one(lightningd: LightningRPC) {
let label = format!("{}", Uuid::new_v4());
let invoice = lightningd
.invoice(Some(1), label.as_str(), "generate an any invoice", None)
.invoice(
Some(1),
label.as_str(),
"generate an any invoice",
None,
None,
)
.unwrap();
let decode = lightningd.decodepay(&invoice.bolt11, None).unwrap();
assert_eq!(decode.amount_msat, Some(MSat(1)));
Expand Down

0 comments on commit bdb3b0e

Please sign in to comment.