Skip to content

Commit 51ede15

Browse files
committed
integration_test: Improve NodeExt constructors
Add a `Wallet` enum and improve the constructors.
1 parent a9fef2b commit 51ede15

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

integration_test/src/lib.rs

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,37 @@ const NBLOCKS: usize = 101;
1515
#[allow(dead_code)] // Not all tests use this function.
1616
pub fn init_logger() { let _ = env_logger::try_init(); }
1717

18+
/// Controls the loaded wallet.
19+
pub enum Wallet {
20+
/// Load the default wallet.
21+
Default,
22+
/// Load a wallet with custom name.
23+
Load(String),
24+
/// Do not load a wallet.
25+
None,
26+
}
27+
1828
pub trait NodeExt {
1929
/// Returns a handle to a `bitcoind` instance after leading wallet if present.
20-
fn new(conf: node::Conf, wallet: Option<String>) -> Node;
30+
fn _new(wallet: Wallet, txindex: bool) -> Node;
2131

2232
/// Returns a handle to a `bitcoind` instance with "default" wallet loaded.
23-
fn new_with_default_wallet() -> Node {
24-
let conf = node::Conf::default();
25-
Self::new(conf, None)
26-
}
33+
fn new_with_default_wallet() -> Node { Self::_new(Wallet::Default, false) }
2734

2835
/// Returns a handle to a `bitcoind` instance with "default" wallet loaded and `-txindex` enabled.
29-
fn new_with_default_wallet_txindex() -> Node {
30-
let mut conf = node::Conf::default();
31-
conf.args.push("-txindex");
32-
Self::new(conf, None)
33-
}
36+
fn new_with_default_wallet_txindex() -> Node { Self::_new(Wallet::Default, true) }
3437

3538
/// Returns a handle to a `bitcoind` instance with `wallet` loaded.
36-
fn new_with_wallet(wallet: String) -> Node {
37-
let conf = node::Conf::default();
38-
Self::new(conf, Some(wallet))
39-
}
39+
fn new_with_wallet(wallet: String) -> Node { Self::_new(Wallet::Load(wallet), false) }
40+
41+
/// Returns a handle to a `bitcoind` instance with `wallet` loaded and `-txindex` enabled.
42+
fn new_with_wallet_txindex(wallet: String) -> Node { Self::_new(Wallet::Load(wallet), true) }
4043

4144
/// Returns a handle to a `bitcoind` instance without any wallet loaded.
42-
fn new_no_wallet() -> Node {
43-
let mut conf = node::Conf::default();
44-
conf.wallet = None;
45-
Self::new(conf, None)
46-
}
45+
fn new_no_wallet() -> Node { Self::_new(Wallet::None, false) }
4746

4847
/// Returns a handle to a `bitcoind` instance without any wallet loaded and `-txindex` enabled.
49-
fn new_no_wallet_txindex() -> Node {
50-
let mut conf = node::Conf::default();
51-
conf.args.push("-txindex");
52-
Self::new(conf, None)
53-
}
48+
fn new_no_wallet_txindex() -> Node { Self::_new(Wallet::None, true) }
5449

5550
/// Generates [`NBLOCKS`] to an address controlled by the loaded wallet.
5651
fn fund_wallet(&self);
@@ -76,11 +71,18 @@ pub trait NodeExt {
7671
}
7772

7873
impl NodeExt for Node {
79-
fn new(mut conf: node::Conf, wallet: Option<String>) -> Node {
74+
fn _new(wallet: Wallet, txindex: bool) -> Node {
8075
let exe = node::exe_path().expect("failed to get bitcoind executable");
8176

82-
if let Some(wallet) = wallet {
83-
conf.wallet = Some(wallet);
77+
let mut conf = node::Conf::default();
78+
match wallet {
79+
Wallet::Default => {}, // conf.wallet = Some("default")
80+
Wallet::Load(w) => conf.wallet = Some(w),
81+
Wallet::None => conf.wallet = None,
82+
}
83+
84+
if txindex {
85+
conf.args.push("-txindex");
8486
}
8587

8688
Node::with_conf(exe, &conf).expect("failed to create node")

0 commit comments

Comments
 (0)