Skip to content

Implement importmulti method and test #263

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
Jun 28, 2025

Conversation

GideonBature
Copy link
Contributor

The JSON-RPC method importmulti does return a type. We want to test this to catch any changes in behavior in future Core versions.

This PR adds a client function that errors if the return value is anything other than the type it returns, along with an integration test that calls this function.

Ref: #116

Comment on lines 250 to 254
/// Args for the `importmulti` method
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct ImportMultiRequest {
Copy link
Collaborator

Choose a reason for hiding this comment

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

A question for @tcharding what is the reason for these argument structs being in client and not in types?

Copy link
Member

Choose a reason for hiding this comment

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

Because they are used with the client and if one writes their own client (which I hope folk will) and just depend on types we don't want a bunch of 'random' stuff in there. On the other hand wsince we have the client-sync feature we could expose them and then writers of a client could still depend on our client to grab them? I'd be open to that. (By expose I mean put them in lib.rs or someplace so they are not hidden by the feature.)

pub warnings: Option<Vec<String>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
/// The error.
pub error: Option<JsonRpcError>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand the use of #[serde(default, skip_serializing_if..., this is the result of the RPC call and therefore deserialized from json.

If we want fields that are None in the result types to be omitted from the serialization this should be done crate wide and not have different functionality for different RPC calls. I believe core always omits them?

@tcharding thoughts?

Copy link
Member

@tcharding tcharding Jun 24, 2025

Choose a reason for hiding this comment

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

My understanding is, and it may be wrong, that this is a no-op because serde already omits None when serializing options. I'm guessing you got this from an LLM @GideonBature? I've seen LLMs add this when using them.

I don't think we should use this attribute unless there is some explicit reason to, and if so, like you say @jamillambert it would then have to be done crate wide. And we definitely don't want to do that unless there is a very good reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

my bad, was not supposed to be for result, only for args.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is, and it may be wrong, that this is a no-op because serde already omits None when serializing options. I'm guessing you got this from an LLM @GideonBature? I've seen LLMs add this when using them.

I don't think we should use this attribute unless there is some explicit reason to, and if so, like you say @jamillambert it would then have to be done crate wide. And we definitely don't want to do that unless there is a very good reason.

yes... you are right.

@GideonBature GideonBature force-pushed the importmulti branch 3 times, most recently from afcf58d to b05f196 Compare June 24, 2025 10:08
@GideonBature
Copy link
Contributor Author

GideonBature commented Jun 24, 2025

Effected suggestions.

Also, introduced another type for v18 upwards, which has the warnings field. The v17 doesn't have the warnings field, had to confirm that with the code in core and found out that every thing remains same except that v17 doesn't return the warnings fields in it's response. Also, updated the test accordingly.

Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

Everything looks good except I'd like to see the test improved upon please. Its great that you are testing so thoroughly its just a bit unclear by reading the test exactly what it is testing.

Since we are primarily interested in proving the shape of the returned type perhaps structure the test, and include code comments, around this idea.

E.g, Do some set up and comment what is expected then assert that we get what is expected.

Also please comment if things are version specific, ATM it looks like descriptors are supported all the way back to v17 but the docs don't support that, or is it just undocumented?

Thanks

Comment on lines +258 to +260
#[serde(rename = "scriptPubKey", skip_serializing_if = "Option::is_none")]
pub script_pub_key: Option<ImportMultiScriptPubKey>,
Copy link
Member

Choose a reason for hiding this comment

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

This arg is required by v17 and v29 so shouldn't be Option, right?

Copy link
Contributor Author

@GideonBature GideonBature Jun 27, 2025

Choose a reason for hiding this comment

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

yes, it is required by v17 - v29. Why I made it Option is because for v18 - v29 either scriptPubkey or descriptor is required but not both.

Copy link
Member

Choose a reason for hiding this comment

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

ooo, I missed that. Thanks

Copy link
Member

Choose a reason for hiding this comment

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

Needs rename to script_pubkey.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will open a patch PR for the renaming.

@GideonBature
Copy link
Contributor Author

Everything looks good except I'd like to see the test improved upon please. Its great that you are testing so thoroughly its just a bit unclear by reading the test exactly what it is testing.

Since we are primarily interested in proving the shape of the returned type perhaps structure the test, and include code comments, around this idea.

E.g, Do some set up and comment what is expected then assert that we get what is expected.

Also please comment if things are version specific, ATM it looks like descriptors are supported all the way back to v17 but the docs don't support that, or is it just undocumented?

Thanks

Yes, descriptors is not mentioned in v17, yet the test still passes, prolly will exclude the test using descriptors for v17.

@GideonBature GideonBature force-pushed the importmulti branch 6 times, most recently from 5b1f2ad to cc79a67 Compare June 27, 2025 12:29
@GideonBature GideonBature marked this pull request as draft June 27, 2025 12:37
@GideonBature
Copy link
Contributor Author

GideonBature commented Jun 27, 2025

Implemented the changes suggested and also added more cases to the test...

@GideonBature GideonBature marked this pull request as ready for review June 27, 2025 18:40
Remove redundant code from types and args

Add comment and field checks to test

Add appropriate type for v17 and v18

Make test more explicit and robust

Resolve Bip125Replaceable import issue

Resolve assert checks for v17
Format code changes

Format code

Format code
Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK ec24420

@tcharding tcharding merged commit 2aede02 into rust-bitcoin:master Jun 28, 2025
29 checks passed
@tcharding
Copy link
Member

Good effort man, that test is nice.

@GideonBature
Copy link
Contributor Author

Thank you. :).

tcharding added a commit that referenced this pull request Jun 29, 2025
303d8e4 Rename script_pub_key to script_pubkey (GideonBature)

Pull request description:

  This is a follow up PR, that implements the suggestion given in this [comment](#263 (comment)) for PR #263 to rename `script_pub_key` to `script_pubkey` for readability purpose.

ACKs for top commit:
  tcharding:
    ACK 303d8e4

Tree-SHA512: b6f5f0def9947f8dcfbe2464ffdff295a084dfe634d5e081276ca79b84c31a7569a45db5ba6c8386372ab35ae33cf6154439832fa809b31ee0ba4d7c1aad2568
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants