Skip to content

Commit 6876edc

Browse files
committed
Improve import_descriptors test
The current test of the RPC always returns true due to scanning for the timestamp `now`. Improve the test to be more thorough by creating a new address and then scanning for the descriptor at a later time.
1 parent 5f55e62 commit 6876edc

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

integration_test/tests/wallet.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,17 +314,37 @@ fn wallet__import_address() {
314314
#[cfg(not(feature = "v20_and_below"))]
315315
fn wallet__import_descriptors() {
316316
use node::{serde_json, ImportDescriptorsRequest};
317+
use std::time::{SystemTime, UNIX_EPOCH};
317318

318319
let node = Node::with_wallet(Wallet::None, &[]);
319320
let wallet_name = "desc_wallet";
320321
node.client.create_wallet_with_descriptors(wallet_name).expect("create descriptor wallet");
322+
node.fund_wallet();
323+
324+
// 1. Get the current time
325+
let start_time = SystemTime::now()
326+
.duration_since(UNIX_EPOCH)
327+
.expect("failed to get current time")
328+
.as_secs();
321329

330+
// 2. Get an address and send some coins to it
322331
let address = node.client.new_address().expect("failed to get new address");
323-
let descriptor = format!("addr({})", address);
332+
let amount = bitcoin::Amount::from_sat(10_000);
333+
let _txid = node.client.send_to_address(&address, amount).expect("sendtoaddress");
334+
335+
// 3. Get the descriptor for the address
336+
let descriptor = node.client.get_descriptor_info(&format!("addr({})", address))
337+
.expect("get_descriptor_info")
338+
.descriptor;
339+
340+
// 4. Mine 100 blocks
341+
let mining_address = node.client.new_address().expect("failed to get mining address");
342+
let _blocks = node.client.generate_to_address(100, &mining_address).expect("generatetoaddress");
324343

344+
// 5. Scan for the descriptor using the time from (1)
325345
let request = ImportDescriptorsRequest {
326346
desc: descriptor,
327-
timestamp: serde_json::Value::String("now".to_string()),
347+
timestamp: serde_json::Value::Number(serde_json::Number::from(start_time)),
328348
};
329349

330350
let _: ImportDescriptors = node.client.import_descriptors(&[request]).expect("importdescriptors");

0 commit comments

Comments
 (0)