Skip to content

Drop unnecessary Result in RpcClient::new #3353

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

Merged
merged 2 commits into from
Oct 11, 2024

Conversation

tnull
Copy link
Contributor

@tnull tnull commented Oct 9, 2024

.. as it's infallible. Just a trivial change that spares the user a dangerous looking unwrap.

TheBlueMatt
TheBlueMatt previously approved these changes Oct 9, 2024
@TheBlueMatt
Copy link
Collaborator

Needs corresponding test updates.

@tnull
Copy link
Contributor Author

tnull commented Oct 9, 2024

Needs corresponding test updates.

Ah, sorry, duh. Now force pushed the following changes:

> git diff-tree -U2 3c8f728b3 4cdb12f91
diff --git a/lightning-block-sync/src/rpc.rs b/lightning-block-sync/src/rpc.rs
index f0d4051a3..3df50a226 100644
--- a/lightning-block-sync/src/rpc.rs
+++ b/lightning-block-sync/src/rpc.rs
@@ -205,5 +205,5 @@ mod tests {
        async fn call_method_returning_unknown_response() {
                let server = HttpServer::responding_with_not_found();
-               let client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
+               let client = RpcClient::new(CREDENTIALS, server.endpoint());

                match client.call_method::<u64>("getblockcount", &[]).await {
@@ -217,5 +217,5 @@ mod tests {
                let response = serde_json::json!("foo");
                let server = HttpServer::responding_with_ok(MessageBody::Content(response));
-               let client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
+               let client = RpcClient::new(CREDENTIALS, server.endpoint());

                match client.call_method::<u64>("getblockcount", &[]).await {
@@ -234,5 +234,5 @@ mod tests {
                });
                let server = HttpServer::responding_with_server_error(response);
-               let client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
+               let client = RpcClient::new(CREDENTIALS, server.endpoint());

                let invalid_block_hash = serde_json::json!("foo");
@@ -252,5 +252,5 @@ mod tests {
                let response = serde_json::json!({});
                let server = HttpServer::responding_with_ok(MessageBody::Content(response));
-               let client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
+               let client = RpcClient::new(CREDENTIALS, server.endpoint());

                match client.call_method::<u64>("getblockcount", &[]).await {
@@ -267,5 +267,5 @@ mod tests {
                let response = serde_json::json!({ "result": "foo" });
                let server = HttpServer::responding_with_ok(MessageBody::Content(response));
-               let client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
+               let client = RpcClient::new(CREDENTIALS, server.endpoint());

                match client.call_method::<u64>("getblockcount", &[]).await {
@@ -282,5 +282,5 @@ mod tests {
                let response = serde_json::json!({ "result": 654470 });
                let server = HttpServer::responding_with_ok(MessageBody::Content(response));
-               let client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
+               let client = RpcClient::new(CREDENTIALS, server.endpoint());

                match client.call_method::<u64>("getblockcount", &[]).await {
@@ -294,5 +294,5 @@ mod tests {
                let response = serde_json::json!({ "result": null });
                let server = HttpServer::responding_with_ok(MessageBody::Content(response));
-               let client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
+               let client = RpcClient::new(CREDENTIALS, server.endpoint());
                let outpoint = OutPoint::new(bitcoin::Txid::from_byte_array([0; 32]), 0);
                let unspent_output = client.is_output_unspent(outpoint).await.unwrap();
@@ -304,5 +304,5 @@ mod tests {
                let response = serde_json::json!({ "result": {"bestblock": 1, "confirmations": 42}});
                let server = HttpServer::responding_with_ok(MessageBody::Content(response));
-               let client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
+               let client = RpcClient::new(CREDENTIALS, server.endpoint());
                let outpoint = OutPoint::new(bitcoin::Txid::from_byte_array([0; 32]), 0);
                let unspent_output = client.is_output_unspent(outpoint).await.unwrap();

Copy link

codecov bot commented Oct 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.60%. Comparing base (a952d2d) to head (88cbb4f).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3353      +/-   ##
==========================================
- Coverage   89.61%   89.60%   -0.01%     
==========================================
  Files         127      127              
  Lines      103531   103531              
  Branches   103531   103531              
==========================================
- Hits        92782    92774       -8     
- Misses       8052     8055       +3     
- Partials     2697     2702       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@jkczyz jkczyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you do the same for RestClient?

@tnull
Copy link
Contributor Author

tnull commented Oct 9, 2024

Could you do the same for RestClient?

Sure, added another commit.

Copy link
Contributor

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I was looking in doing the same thing yesterday!

@TheBlueMatt
Copy link
Collaborator

Why did no one merge this?

@TheBlueMatt TheBlueMatt merged commit cb4584a into lightningdevkit:main Oct 11, 2024
20 of 21 checks passed
@vincenzopalazzo
Copy link
Contributor

Why did no one merge this?

Usually, the problem is the opposite 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants