-
Notifications
You must be signed in to change notification settings - Fork 33
Address all TODO
in v21
#289
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
Conversation
7704d52
to
86882e3
Compare
let json: GenerateBlock = node.client.generate_block(&mining_addr.to_string(), &transactions, false).expect("generateblock"); | ||
let model: Result<mtype::GenerateBlock, GenerateBlockError> = json.into_model(); | ||
model.unwrap(); | ||
} |
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.
nit: I rekon the feature guards could just guard the generate_block
call. The other two lines are identical.
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.
Done
types/src/v21/util.rs
Outdated
/// > | ||
/// > Arguments: | ||
/// > 1. index_name (string, optional) Filter results for an index with a specific name. | ||
/// > | ||
/// > Result: | ||
/// > { (json object) | ||
/// > "name" : { (json object) The name of the index | ||
/// > "synced" : true|false, (boolean) Whether the index is synced or not | ||
/// > "best_block_height" : n (numeric) The block height to which the index is synced | ||
/// > }, | ||
/// > ... |
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.
Would be better without all this. In general I rekon we should only add the docs up to 'required' args. Recently you did a few PRs that included option args but I didn't comment because they were brief docs and also they added some useful context. That isn't the case here IMO.
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.
I removed the optional args and result section from the docs of all the added RPCs in this PR.
types/src/v21/util.rs
Outdated
/// > } | ||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] | ||
#[serde(deny_unknown_fields)] | ||
pub struct GetIndexInfo(pub std::collections::BTreeMap<String, GetIndexInfoName>); |
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.
nit: I'd prefer to import BTreeMap
.
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.
Done
|
||
/// `name` field of `getindexinfo`. | ||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] | ||
#[serde(deny_unknown_fields)] |
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.
Cool, can you help me to remember we use this now in review because since I didn't code with this yet I'm likely to forget.
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.
Only got to reviewing half mate, I'll come back. Gotta do some kids stuff now.
86882e3
to
4909897
Compare
Add the RPC `generateblock` type to v21 and add reexports. Add model, into function, client macro and test. Update types table up to v29, v23 and later don't have docs for `Generating` and therefore no table entry.
Add the RPC `getindexinfo` type to v21 and add reexports. Add client macro and test. Update types table up to v29.
In preparation for adding v21 wallet RPCs move the module into a subdirectory and split out the into module. Move only, no code changes.
Add a new create wallet macro for v21 onwards to client that creates a descriptor wallet for tests that require one.
Add the RPC `importdescriptors` type to v21 and add reexports. Add client macro and test. Update types table up to v29.
Add the RPC `send` type to v21 and add reexports. Add model, client macro and test. Update types table up to v29.
Add the RPC `psbtbumpfee` type to v21 and add reexports. Add model, client macro and test. Update types table up to v29.
Add the RPC `upgradewallet` type to v21 and add reexports. Add client macro and test. Update types table up to v29.
4909897
to
a150076
Compare
let node = Node::with_wallet(Wallet::Default, &[]); | ||
let _: GetIndexInfo = node.client.get_index_info().expect("getindexinfo"); |
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.
IIUC this is going to return an empty map so doesn't really test the JSON shape. We have this same problem in many of our tests because I naively wrote a ton of them without thinking about the RPC method too much. @GideonBature has done a much better job at making sure there is something actually returned.
I created #291
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.
Test fixed in #293
@@ -9,6 +9,66 @@ | |||
//! | |||
//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. | |||
|
|||
/// Implements Bitcoin Core JSON-RPC API method `createwallet` with descriptors=true (descriptor wallet) |
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.
/// Implements Bitcoin Core JSON-RPC API method `createwallet` with descriptors=true (descriptor wallet) | |
/// Implements Bitcoin Core JSON-RPC API method `createwallet` with descriptors=true (descriptor wallet) | |
/// | |
/// This is a helper function only needed in v21 and v22 because from v23 onwards this is not needed | |
/// because descriptors=true is the default. |
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.
Done in #293
NB. I didn't use your exact wording of "only needed in v21 and v22 because from v23 onwards this is not needed"
} | ||
} | ||
}; | ||
} |
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.
I think this macro should be done like the v23 one i.e., include function create_wallet
as well as the with desrciptor function. Then in mod.rs of v23 and v24 only call this macro not the v17 one and from v23 onwards only call the v23 one.
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.
And I"d comment liberally about args to the RPC method changing and that we only include args we actually use in the integration tests - or some such thing.
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.
I've merged and left this suggested fix up to be done as a follow up because this PR is massive.
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.
Addedd #292
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.
It might just be that I am tired, but I don't understand what you mean.
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.
I added a commit to address this in the follow up PR #293
}; | ||
|
||
let _: ImportDescriptors = node.client.import_descriptors(&[request]).expect("importdescriptors"); | ||
} |
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.
From what I just read and assuming I understand the RPC method, this is going to just return 'success=true' because of use of "now". If we are going to do such a basic test (and that is perfectly ok) we don't need to have the timestamp
arg at all - just insert it in the client method that does the RPC call.
Another, more thorough test idea (although I'm not 100% its necessary) would be to
- get the current time
- get an address and send some coins to it
- get the descriptor
- mine 100 blocks
- scan for that descriptor using the time from (1)
Personally I'd just remove the "now" and comment that this just a basic test and likely good enough for now. There are other tests we can write that add more value and are better uses of your time.
The takeaway here is we (all of us) should try to understand exactly what we are testing and test as simply as possible to get that coverage.
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.
I went with the more thorough option of changing the test in #293
|
||
let json: Send = node.client.send(&outputs).expect("send"); | ||
let model: Result<mtype::Send, SendError> = json.into_model(); | ||
model.unwrap(); |
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.
Cool. This works (I debug printed the result of the last unwrap) but I'm baffled as to why it works. Can you explain if you know otherwise I don't suppose it matters? The docs say 'data' is required but I don't understand why it works without it and what 'data' even is?
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.
data
is not required, even though it doesn't say so in the docs. From what I read "It is for arbitrary hex-encoded data in a transaction, typically as an [OP_RETURN] output e.g. { "data": "deadbeef" }".
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.
ah, thanks.
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.
ACK a150076
A lot of work here man, well done. |
e396ad0 Improve import_descriptors test (Jamil Lambert, PhD) 746c5dc Add a constructor for ImportDescriptorsRequest (Jamil Lambert, PhD) 4f534f3 Rewrite create descriptor wallet client macro (Jamil Lambert, PhD) 62e01e5 Improve getindexinfo test (Jamil Lambert, PhD) Pull request description: There were a couple of points in the review of #289 that needed to be addressed. Improve the tests as suggested, and add a comment to the rustdocs. Redefine the `create_wallet` client macro so that for v21 and v22 where the default is a legacy wallet there is a separate function to create a descriptor wallet. Similarly for v23 and above where the default is a descriptor wallet there is a separate function to create a legacy wallet. Closes #292 ACKs for top commit: tcharding: ACK e396ad0 Tree-SHA512: e035315a926e9a789068a72b0e21f838f30d5c7feb2eba7245dbeea73f500b0c433a11b24620e5141550199a3173cabf3bb478b174d34194806f89b020b8eb05
Go through all the
TODO
in the v21 types table. Add all the missing RPCs including models when required and tests.Add a new macro
create_wallet_with_descriptors
that creates a descriptor wallet for use with v21 and v22 where the default is a legacy wallet. This is required for theimportdescriptors
test.Move the
wallet
module to a subdirectory since there are multiple new RPCs in v21.