@@ -11,6 +11,8 @@ use bitcoincore_rpc::{
11
11
bitcoincore_rpc_json:: { GetBlockTemplateModes , GetBlockTemplateRules } ,
12
12
RpcApi ,
13
13
} ;
14
+ use electrsd:: bitcoind:: anyhow:: Context ;
15
+
14
16
pub use electrsd;
15
17
pub use electrsd:: bitcoind;
16
18
pub use electrsd:: bitcoind:: anyhow;
@@ -26,35 +28,52 @@ pub struct TestEnv {
26
28
pub electrsd : electrsd:: ElectrsD ,
27
29
}
28
30
31
+ /// Configuration parameters.
32
+ #[ derive( Debug ) ]
33
+ pub struct Config < ' a > {
34
+ /// [`bitcoind::Conf`]
35
+ pub bitcoind : bitcoind:: Conf < ' a > ,
36
+ /// [`electrsd::Conf`]
37
+ pub electrsd : electrsd:: Conf < ' a > ,
38
+ }
39
+
40
+ impl < ' a > Default for Config < ' a > {
41
+ /// Use the default configuration plus set `http_enabled = true` for [`electrsd::Conf`]
42
+ /// which is required for testing `bdk_esplora`.
43
+ fn default ( ) -> Self {
44
+ Self {
45
+ bitcoind : bitcoind:: Conf :: default ( ) ,
46
+ electrsd : {
47
+ let mut conf = electrsd:: Conf :: default ( ) ;
48
+ conf. http_enabled = true ;
49
+ conf
50
+ } ,
51
+ }
52
+ }
53
+ }
54
+
29
55
impl TestEnv {
30
- /// Construct a new [`TestEnv`] instance with default configurations .
56
+ /// Construct a new [`TestEnv`] instance with the default configuration used by BDK .
31
57
pub fn new ( ) -> anyhow:: Result < Self > {
32
- let bitcoind = match std:: env:: var_os ( "BITCOIND_EXE" ) {
33
- Some ( bitcoind_path) => electrsd:: bitcoind:: BitcoinD :: new ( bitcoind_path) ,
34
- None => {
35
- let bitcoind_exe = electrsd:: bitcoind:: downloaded_exe_path ( )
36
- . expect (
58
+ TestEnv :: new_with_config ( Config :: default ( ) )
59
+ }
60
+
61
+ /// Construct a new [`TestEnv`] instance with the provided [`Config`].
62
+ pub fn new_with_config ( config : Config ) -> anyhow:: Result < Self > {
63
+ let bitcoind_exe = match std:: env:: var ( "BITCOIND_EXE" ) {
64
+ Ok ( path) => path,
65
+ Err ( _) => bitcoind:: downloaded_exe_path ( ) . context (
37
66
"you need to provide an env var BITCOIND_EXE or specify a bitcoind version feature" ,
38
- ) ;
39
- electrsd:: bitcoind:: BitcoinD :: with_conf (
40
- bitcoind_exe,
41
- & electrsd:: bitcoind:: Conf :: default ( ) ,
42
- )
43
- }
44
- } ?;
67
+ ) ?,
68
+ } ;
69
+ let bitcoind = bitcoind:: BitcoinD :: with_conf ( bitcoind_exe, & config. bitcoind ) ?;
45
70
46
- let mut electrsd_conf = electrsd:: Conf :: default ( ) ;
47
- electrsd_conf. http_enabled = true ;
48
- let electrsd = match std:: env:: var_os ( "ELECTRS_EXE" ) {
49
- Some ( env_electrs_exe) => {
50
- electrsd:: ElectrsD :: with_conf ( env_electrs_exe, & bitcoind, & electrsd_conf)
51
- }
52
- None => {
53
- let electrs_exe = electrsd:: downloaded_exe_path ( )
54
- . expect ( "electrs version feature must be enabled" ) ;
55
- electrsd:: ElectrsD :: with_conf ( electrs_exe, & bitcoind, & electrsd_conf)
56
- }
57
- } ?;
71
+ let electrs_exe = match std:: env:: var ( "ELECTRS_EXE" ) {
72
+ Ok ( path) => path,
73
+ Err ( _) => electrsd:: downloaded_exe_path ( )
74
+ . context ( "electrs version feature must be enabled" ) ?,
75
+ } ;
76
+ let electrsd = electrsd:: ElectrsD :: with_conf ( electrs_exe, & bitcoind, & config. electrsd ) ?;
58
77
59
78
Ok ( Self { bitcoind, electrsd } )
60
79
}
0 commit comments