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

Chain service error #989

Merged
merged 9 commits into from
May 27, 2024
13 changes: 11 additions & 2 deletions libs/sdk-core/src/input_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,15 +1075,24 @@ pub(crate) mod tests {
}
"#.replace('\n', "");

let response_body = match return_lnurl_error {
let response_body = match &return_lnurl_error {
None => expected_lnurl_withdraw_data,
Some(err_reason) => {
["{\"status\": \"ERROR\", \"reason\": \"", &err_reason, "\"}"].join("")
}
};

let status = match &return_lnurl_error {
None => 200,
Some(_) => 400,
};

Copy link
Contributor

@erdemyerebasmaz erdemyerebasmaz May 27, 2024

Choose a reason for hiding this comment

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

I think we can match once and return the result as tuple here:

let (response_body, status) = match &return_lnurl_error {
    None => (expected_lnurl_withdraw_data, 200),
    Some(err_reason) => (
        ["{\"status\": \"ERROR\", \"reason\": \"", &err_reason, "\"}"].join(""),
        400,
    ),
};

or we can use response_body to set status to avoid matching twice:

let status = if return_lnurl_error.is_none() {
    200
} else {
    400
};

Copy link
Contributor

Choose a reason for hiding this comment

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

@roeierez cargo clippy has this warning:

error: this expression creates a reference which is immediately dereferenced by the compiler
    --> sdk-core/src/input_parser.rs:1081:60
     |
1081 |                 ["{\"status\": \"ERROR\", \"reason\": \"", &err_reason, "\"}"].join(""),
     |                                                            ^^^^^^^^^^^ help: change this to: `err_reason`
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
     = note: `-D clippy::needless-borrow` implied by `-D warnings`
     = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]`

let mut server = MOCK_HTTP_SERVER.lock().unwrap();
server.mock("GET", path).with_body(response_body).create()
server
.mock("GET", path)
.with_body(response_body)
.with_status(status)
.create()
}

#[tokio::test]
Expand Down
Loading