Skip to content

Commit

Permalink
add descriptors and load_on_startup args for create_wallet
Browse files Browse the repository at this point in the history
Since Bitcoin Core v23 by default a descriptor wallet is created.
In the integration tests, we don't want to have a descriptor wallet
at the moment as we are using dumprivkey, which isn't avalaible in
descriptor wallets.
  • Loading branch information
0xB10C committed Sep 1, 2023
1 parent 06f0543 commit ab16de2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 10 deletions.
16 changes: 15 additions & 1 deletion client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,17 +284,31 @@ pub trait RpcApi: Sized {
blank: Option<bool>,
passphrase: Option<&str>,
avoid_reuse: Option<bool>,
descriptors: Option<bool>,
load_on_startup: Option<bool>,
) -> Result<json::LoadWalletResult> {
let mut args = [
wallet.into(),
opt_into_json(disable_private_keys)?,
opt_into_json(blank)?,
opt_into_json(passphrase)?,
opt_into_json(avoid_reuse)?,
opt_into_json(descriptors)?,
opt_into_json(load_on_startup)?,
];
self.call(
"createwallet",
handle_defaults(&mut args, &[false.into(), false.into(), into_json("")?, false.into()]),
handle_defaults(
&mut args,
&[
false.into(),
false.into(),
into_json("")?,
false.into(),
false.into(),
false.into(),
],
),
)
}

Expand Down
50 changes: 41 additions & 9 deletions integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,13 @@ fn main() {
unsafe { VERSION = cl.version().unwrap() };
println!("Version: {}", version());

cl.create_wallet("testwallet", None, None, None, None).unwrap();
if version() >= 230000 {
// This is explicilty not a descriptor wallet. The tests try to export
// private keys, which isn't possible with descriptor wallets.
cl.create_wallet("testwallet", None, None, None, None, Some(false), None).unwrap();
} else {
cl.create_wallet("testwallet", None, None, None, None, None, None).unwrap();
}

test_get_mining_info(&cl);
test_get_blockchain_info(&cl);
Expand Down Expand Up @@ -1066,14 +1072,16 @@ fn test_rescan_blockchain(cl: &Client) {
}

fn test_create_wallet(cl: &Client) {
let wallet_names = vec!["alice", "bob", "carol", "denise", "emily"];
let wallet_names = vec!["alice", "bob", "carol", "denise", "emily", "frank"];

struct WalletParams<'a> {
name: &'a str,
disable_private_keys: Option<bool>,
blank: Option<bool>,
passphrase: Option<&'a str>,
avoid_reuse: Option<bool>,
descriptors: Option<bool>,
load_on_startup: Option<bool>,
}

let mut wallet_params = vec![
Expand All @@ -1083,20 +1091,26 @@ fn test_create_wallet(cl: &Client) {
blank: None,
passphrase: None,
avoid_reuse: None,
descriptors: None,
load_on_startup: None,
},
WalletParams {
name: wallet_names[1],
disable_private_keys: Some(true),
blank: None,
passphrase: None,
avoid_reuse: None,
descriptors: None,
load_on_startup: None,
},
WalletParams {
name: wallet_names[2],
disable_private_keys: None,
blank: Some(true),
passphrase: None,
avoid_reuse: None,
descriptors: None,
load_on_startup: None,
},
];

Expand All @@ -1107,13 +1121,29 @@ fn test_create_wallet(cl: &Client) {
blank: None,
passphrase: Some("pass"),
avoid_reuse: None,
descriptors: None,
load_on_startup: None,
});
wallet_params.push(WalletParams {
name: wallet_names[4],
disable_private_keys: None,
blank: None,
passphrase: None,
avoid_reuse: Some(true),
descriptors: None,
load_on_startup: None,
});
}

if version() >= 220000 {
wallet_params.push(WalletParams {
name: wallet_names[5],
disable_private_keys: None,
blank: None,
passphrase: None,
avoid_reuse: Some(true),
descriptors: Some(false),
load_on_startup: Some(true),
});
}

Expand All @@ -1125,6 +1155,8 @@ fn test_create_wallet(cl: &Client) {
wallet_param.blank,
wallet_param.passphrase,
wallet_param.avoid_reuse,
wallet_param.descriptors,
wallet_param.load_on_startup,
)
.unwrap();

Expand All @@ -1144,8 +1176,10 @@ fn test_create_wallet(cl: &Client) {

let has_private_keys = !wallet_param.disable_private_keys.unwrap_or(false);
assert_eq!(wallet_info.private_keys_enabled, has_private_keys);
let has_hd_seed = has_private_keys && !wallet_param.blank.unwrap_or(false);

let has_hd_seed = has_private_keys && !wallet_param.blank.unwrap_or(if version() >= 230000 { true } else { false });
assert_eq!(wallet_info.hd_seed_id.is_some(), has_hd_seed);

let has_avoid_reuse = wallet_param.avoid_reuse.unwrap_or(false);
assert_eq!(wallet_info.avoid_reuse.unwrap_or(false), has_avoid_reuse);
assert_eq!(
Expand Down Expand Up @@ -1282,11 +1316,9 @@ fn test_getblocktemplate(cl: &Client) {
}

fn test_unloadwallet(cl: &Client) {
cl.create_wallet("testunloadwallet", None, None, None, None).unwrap();
cl.create_wallet("testunloadwallet", None, None, None, None, None, None).unwrap();

let res = new_wallet_client("testunloadwallet")
.unload_wallet(None)
.unwrap();
let res = new_wallet_client("testunloadwallet").unload_wallet(None).unwrap();

if version() >= 210000 {
assert!(res.is_some());
Expand All @@ -1300,7 +1332,7 @@ fn test_loadwallet(_: &Client) {
let wallet_client = new_wallet_client(wallet_name);

assert!(wallet_client.load_wallet(wallet_name).is_err());
wallet_client.create_wallet(wallet_name, None, None, None, None).unwrap();
wallet_client.create_wallet(wallet_name, None, None, None, None, None, None).unwrap();
assert!(wallet_client.load_wallet(wallet_name).is_err());
wallet_client.unload_wallet(None).unwrap();

Expand All @@ -1315,7 +1347,7 @@ fn test_backupwallet(_: &Client) {

assert!(wallet_client.backup_wallet(None).is_err());
assert!(wallet_client.backup_wallet(Some(&backup_path)).is_err());
wallet_client.create_wallet("testbackupwallet", None, None, None, None).unwrap();
wallet_client.create_wallet("testbackupwallet", None, None, None, None, None, None).unwrap();
assert!(wallet_client.backup_wallet(None).is_err());
assert!(wallet_client.backup_wallet(Some(&backup_path)).is_ok());
}
Expand Down

0 comments on commit ab16de2

Please sign in to comment.