-
Notifications
You must be signed in to change notification settings - Fork 33
Follow up to v21 TODO #293
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,19 @@ | |
//! Tests for methods found under the `== Wallet ==` section of the API docs. | ||
|
||
#![allow(non_snake_case)] // Test names intentionally use double underscore. | ||
#![allow(unused_imports)] // Some imports are only used in specific versions. | ||
|
||
#[cfg(feature = "TODO")] | ||
use bitcoin::address::{Address, NetworkChecked}; | ||
use bitcoin::{Amount, FeeRate, PrivateKey, PublicKey}; | ||
use bitcoin::address::{Address, KnownHrp, NetworkChecked}; | ||
use bitcoin::{secp256k1, Amount, CompressedPublicKey, FeeRate, PrivateKey, PublicKey}; | ||
use integration_test::{Node, NodeExt as _, Wallet}; | ||
use node::{mtype, AddressType, ImportMultiRequest, ImportMultiScriptPubKey, ImportMultiTimestamp}; | ||
|
||
#[cfg(not(feature = "v20_and_below"))] | ||
use node::ImportDescriptorsRequest; | ||
|
||
use node::vtype::*; // All the version specific types. | ||
use std::fs; | ||
use std::time::{SystemTime, UNIX_EPOCH}; | ||
|
||
#[test] | ||
fn wallet__abandon_transaction() { | ||
|
@@ -326,21 +331,47 @@ fn wallet__import_address() { | |
#[test] | ||
#[cfg(not(feature = "v20_and_below"))] | ||
fn wallet__import_descriptors() { | ||
use node::{serde_json, ImportDescriptorsRequest}; | ||
|
||
let node = Node::with_wallet(Wallet::None, &[]); | ||
let wallet_name = "desc_wallet"; | ||
node.client.create_wallet_with_descriptors(wallet_name).expect("create descriptor wallet"); | ||
|
||
let address = node.client.new_address().expect("failed to get new address"); | ||
let descriptor = format!("addr({})", address); | ||
#[cfg(feature = "v22_and_below")] | ||
node.client.create_descriptor_wallet(wallet_name).expect("create descriptor wallet"); | ||
|
||
let request = ImportDescriptorsRequest { | ||
descriptor, | ||
timestamp: serde_json::Value::String("now".to_string()), | ||
}; | ||
// v23 onwards uses descriptor wallets by default. | ||
#[cfg(not(feature = "v22_and_below"))] | ||
node.client.create_wallet(wallet_name).expect("create wallet"); | ||
|
||
node.fund_wallet(); | ||
|
||
// 1. Get the current time | ||
let start_time = SystemTime::now() | ||
.duration_since(UNIX_EPOCH) | ||
.expect("failed to get current time") | ||
.as_secs(); | ||
|
||
// 2. Use a known private key, derive the address from it and send some coins to it. | ||
let privkey = | ||
PrivateKey::from_wif("cVt4o7BGAig1UXywgGSmARhxMdzP5qvQsxKkSsc1XEkw3tDTQFpy").unwrap(); | ||
let secp = secp256k1::Secp256k1::new(); | ||
let pubkey = privkey.public_key(&secp); | ||
let address = Address::p2wpkh(&CompressedPublicKey(pubkey.inner), KnownHrp::Regtest); | ||
let amount = Amount::from_sat(10_000); | ||
let _txid = node.client.send_to_address(&address, amount).expect("sendtoaddress"); | ||
|
||
// 3. Get the descriptor from the private key. | ||
let raw_descriptor = format!("wpkh({})", privkey.to_wif()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For my education, why does the descriptor use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because one bit was copied from another test 😊. I have changed it now so both are native SegWit. |
||
let info = node.client.get_descriptor_info(&raw_descriptor).expect("get_descriptor_info"); | ||
let descriptor = format!("{}#{}", raw_descriptor, info.checksum); | ||
Comment on lines
+363
to
+364
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clever! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This took me a bit to figure out. It kept complaining that that the descriptor had no private key when it looked like it should. |
||
|
||
// 4. Mine 100 blocks | ||
let mining_address = node.client.new_address().expect("failed to get mining address"); | ||
let _blocks = node.client.generate_to_address(100, &mining_address).expect("generatetoaddress"); | ||
|
||
let _: ImportDescriptors = node.client.import_descriptors(&[request]).expect("importdescriptors"); | ||
// 5. Scan for the descriptor using the time from (1) | ||
let request = ImportDescriptorsRequest::new(descriptor, start_time); | ||
let result: ImportDescriptors = node.client.import_descriptors(&[request]).expect("importdescriptors"); | ||
assert_eq!(result.0.len(), 1, "should have exactly one import result"); | ||
assert!(result.0[0].success); | ||
} | ||
|
||
#[test] | ||
|
@@ -515,7 +546,7 @@ fn wallet__list_descriptors() { | |
let wallet_name = "desc_wallet"; | ||
|
||
#[cfg(feature = "v22_and_below")] | ||
node.client.create_wallet_with_descriptors(wallet_name).expect("create descriptor wallet"); | ||
node.client.create_descriptor_wallet(wallet_name).expect("create descriptor wallet"); | ||
|
||
// v23 onwards uses descriptor wallets by default. | ||
#[cfg(not(feature = "v22_and_below"))] | ||
|
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.
This is waaay better, nice one man.