Skip to content

Commit 4e3ddfd

Browse files
committed
fix(test): Enable any client type in config test
As pointed out in the issue bitcoindevkit#255, whenever Esplora was compiled out, the config test will fail because Esplora was used as the client. This fix addresses the above issue by adding other client types in the test.
1 parent 15b6f5b commit 4e3ddfd

1 file changed

Lines changed: 37 additions & 15 deletions

File tree

src/config.rs

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -166,20 +166,49 @@ impl TryFrom<&WalletConfigInner> for WalletOpts {
166166
mod tests {
167167
use super::*;
168168
use std::convert::TryInto;
169+
const EXT_DESCRIPTOR: &str = "wpkh([07234a14/84'/1'/0']tpubDCSgT6PaVLQH9h2TAxKryhvkEurUBcYRJc9dhTcMDyahhWiMWfEWvQQX89yaw7w7XU8bcVujoALfxq59VkFATri3Cxm5mkp9kfHfRFDckEh/0/*)#429nsxmg";
170+
const INT_DESCRIPTOR: &str = "wpkh([07234a14/84'/1'/0']tpubDCSgT6PaVLQH9h2TAxKryhvkEurUBcYRJc9dhTcMDyahhWiMWfEWvQQX89yaw7w7XU8bcVujoALfxq59VkFATri3Cxm5mkp9kfHfRFDckEh/1/*)#y7qjdnts";
169171

170172
#[test]
171173
fn test_wallet_config_inner_to_opts_conversion() {
174+
#[cfg(any(
175+
feature = "electrum",
176+
feature = "esplora",
177+
feature = "rpc",
178+
feature = "cbf"
179+
))]
180+
let client_type = {
181+
if cfg!(feature = "esplora") {
182+
Some("esplora".to_string())
183+
} else if cfg!(feature = "rpc") {
184+
Some("rpc".to_string())
185+
} else if cfg!(feature = "electrum") {
186+
Some("electrum".to_string())
187+
} else if cfg!(feature = "cbf") {
188+
Some("cbf".to_string())
189+
} else {
190+
None
191+
}
192+
};
193+
172194
let wallet_config = WalletConfigInner {
173195
wallet: "test_wallet".to_string(),
174196
network: "testnet4".to_string(),
175-
ext_descriptor: "wpkh([07234a14/84'/1'/0']tpubDCSgT6PaVLQH9h2TAxKryhvkEurUBcYRJc9dhTcMDyahhWiMWfEWvQQX89yaw7w7XU8bcVujoALfxq59VkFATri3Cxm5mkp9kfHfRFDckEh/0/*)#429nsxmg".to_string(),
176-
int_descriptor: Some("wpkh([07234a14/84'/1'/0']tpubDCSgT6PaVLQH9h2TAxKryhvkEurUBcYRJc9dhTcMDyahhWiMWfEWvQQX89yaw7w7XU8bcVujoALfxq59VkFATri3Cxm5mkp9kfHfRFDckEh/1/*)#y7qjdnts".to_string()),
197+
ext_descriptor: EXT_DESCRIPTOR.to_string(),
198+
int_descriptor: Some(INT_DESCRIPTOR.to_string()),
177199
#[cfg(any(feature = "sqlite", feature = "redb"))]
178200
database_type: "sqlite".to_string(),
179-
#[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc", feature = "cbf"))]
180-
client_type: Some("esplora".to_string()),
201+
202+
#[cfg(any(
203+
feature = "electrum",
204+
feature = "esplora",
205+
feature = "rpc",
206+
feature = "cbf"
207+
))]
208+
client_type,
209+
181210
#[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))]
182-
server_url: Some(" https://blockstream.info/testnet4/api".to_string()),
211+
server_url: Some("https://example.com/testnet/api".to_string()),
183212
#[cfg(feature = "electrum")]
184213
batch_size: None,
185214
#[cfg(feature = "esplora")]
@@ -197,22 +226,15 @@ mod tests {
197226
.expect("Conversion should succeed");
198227

199228
assert_eq!(opts.wallet, Some("test_wallet".to_string()));
200-
assert_eq!(
201-
opts.ext_descriptor,
202-
"wpkh([07234a14/84'/1'/0']tpubDCSgT6PaVLQH9h2TAxKryhvkEurUBcYRJc9dhTcMDyahhWiMWfEWvQQX89yaw7w7XU8bcVujoALfxq59VkFATri3Cxm5mkp9kfHfRFDckEh/0/*)#429nsxmg"
203-
);
204229

205-
#[cfg(any(
206-
feature = "electrum",
207-
feature = "esplora",
208-
feature = "rpc",
209-
feature = "cbf"
210-
))]
230+
#[cfg(feature = "esplora")]
211231
assert_eq!(opts.client_type, ClientType::Esplora);
212232

213233
#[cfg(feature = "sqlite")]
214234
assert_eq!(opts.database_type, DatabaseType::Sqlite);
215235

236+
assert_eq!(opts.ext_descriptor, EXT_DESCRIPTOR);
237+
216238
#[cfg(feature = "electrum")]
217239
assert_eq!(opts.batch_size, 10);
218240

0 commit comments

Comments
 (0)