-
Notifications
You must be signed in to change notification settings - Fork 46
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
Introduce a replaceable RestClient #1175
base: savage-wasm-sdk-common
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! I gave it a first pass and looks good. Will give it a second look later.
b713f01
to
d869fc2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good!
I like the way the responses can be set in the mock client. I very much like that we're not calling mempool.space in the tests anymore.
Some nits.
libs/sdk-common/src/input_parser.rs
Outdated
} | ||
|
||
pub async fn parse_with_rest_client( | ||
rest_client: Arc<dyn RestClient>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs for the reqwest client say
You do not have to wrap the Client in an [Rc] or Arc to reuse it, because it already uses an Arc internally.
So nit: I think functions can use a borrowed rest client rather than an Arc. That saves clones on passing it to the next function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this what you had in mind? 0f4633d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really. I had in mind
pub async fn validate_lnurl_withdraw(rest_client: &dyn RestClient)
...
let mock_rest_client = MockRestClient::new();
validate_lnurl_withdraw(&mock_rest_client, withdraw_req, invoice);
But coding it up it would require generics, to support cloning the rest client. It would get quite some feet in the earth. So let's stick with the arcs.
libs/sdk-common/src/input_parser.rs
Outdated
@@ -469,6 +472,9 @@ fn ln_address_decode(ln_address: &str) -> Result<(String, String, String)> { | |||
// It is safe to downcase the domains since they are case-insensitive. | |||
// https://www.rfc-editor.org/rfc/rfc3986#section-3.2.2 | |||
let domain = split[1].to_lowercase(); | |||
if !domain.contains('.') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What caused you to add this here in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The MockRestClient was picking up a request to get LNURL info for 03864ef025fde8fb587d989186ce6a4a186895ee44a926bfc370e2c366597a3zzz@sdfsffs
(in the node_id parsing trst). I think TLDs need a dot right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically it could be localhost
, or other domains in the local network. So this failed before because the network call failed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this failed before because the network call failed?
Yes. Ok, it maybe makes sense to remove this then and add a mock response for this case
This PR: