@@ -3856,44 +3856,21 @@ mod tests {
3856
3856
}
3857
3857
}
3858
3858
3859
- use std:: fs:: File ;
3860
- use util:: ser:: Readable ;
3861
- /// Tries to open a network graph file, or panics with a URL to fetch it.
3862
- pub ( super ) fn get_route_file ( ) -> Result < std:: fs:: File , std:: io:: Error > {
3863
- let res = File :: open ( "net_graph-2021-05-27.bin" ) // By default we're run in RL/lightning
3864
- . or_else ( |_| File :: open ( "lightning/net_graph-2021-05-27.bin" ) ) // We may be run manually in RL/
3865
- . or_else ( |_| { // Fall back to guessing based on the binary location
3866
- // path is likely something like .../rust-lightning/target/debug/deps/lightning-...
3867
- let mut path = std:: env:: current_exe ( ) . unwrap ( ) ;
3868
- path. pop ( ) ; // lightning-...
3869
- path. pop ( ) ; // deps
3870
- path. pop ( ) ; // debug
3871
- path. pop ( ) ; // target
3872
- path. push ( "lightning" ) ;
3873
- path. push ( "net_graph-2021-05-27.bin" ) ;
3874
- eprintln ! ( "{}" , path. to_str( ) . unwrap( ) ) ;
3875
- File :: open ( path)
3876
- } ) ;
3877
- #[ cfg( require_route_graph_test) ]
3878
- return Ok ( res. expect ( "Didn't have route graph and was configured to require it" ) ) ;
3879
- #[ cfg( not( require_route_graph_test) ) ]
3880
- return res;
3881
- }
3882
-
3883
3859
pub ( super ) fn random_init_seed ( ) -> u64 {
3884
3860
// Because the default HashMap in std pulls OS randomness, we can use it as a (bad) RNG.
3885
3861
use core:: hash:: { BuildHasher , Hasher } ;
3886
3862
let seed = std:: collections:: hash_map:: RandomState :: new ( ) . build_hasher ( ) . finish ( ) ;
3887
3863
println ! ( "Using seed of {}" , seed) ;
3888
3864
seed
3889
3865
}
3866
+ use util:: ser:: Readable ;
3890
3867
3891
3868
#[ test]
3892
3869
fn generate_routes ( ) {
3893
- let mut d = match get_route_file ( ) {
3870
+ let mut d = match super :: test_utils :: get_route_file ( ) {
3894
3871
Ok ( f) => f,
3895
- Err ( _ ) => {
3896
- eprintln ! ( "Please fetch https://bitcoin.ninja/ldk-net_graph-45d86ead641d-2021-05-27.bin and place it at lightning/net_graph-2021-05-27.bin" ) ;
3872
+ Err ( e ) => {
3873
+ eprintln ! ( "{}" , e ) ;
3897
3874
return ;
3898
3875
} ,
3899
3876
} ;
@@ -3917,10 +3894,10 @@ mod tests {
3917
3894
3918
3895
#[ test]
3919
3896
fn generate_routes_mpp ( ) {
3920
- let mut d = match get_route_file ( ) {
3897
+ let mut d = match super :: test_utils :: get_route_file ( ) {
3921
3898
Ok ( f) => f,
3922
- Err ( _ ) => {
3923
- eprintln ! ( "Please fetch https://bitcoin.ninja/ldk-net_graph-45d86ead641d-2021-05-27.bin and place it at lightning/net_graph-2021-05-27.bin" ) ;
3899
+ Err ( e ) => {
3900
+ eprintln ! ( "{}" , e ) ;
3924
3901
return ;
3925
3902
} ,
3926
3903
} ;
@@ -3943,12 +3920,38 @@ mod tests {
3943
3920
}
3944
3921
}
3945
3922
3923
+ #[ cfg( test) ]
3924
+ pub ( crate ) mod test_utils {
3925
+ use std:: fs:: File ;
3926
+ /// Tries to open a network graph file, or panics with a URL to fetch it.
3927
+ pub ( crate ) fn get_route_file ( ) -> Result < std:: fs:: File , & ' static str > {
3928
+ let res = File :: open ( "net_graph-2021-05-27.bin" ) // By default we're run in RL/lightning
3929
+ . or_else ( |_| File :: open ( "lightning/net_graph-2021-05-27.bin" ) ) // We may be run manually in RL/
3930
+ . or_else ( |_| { // Fall back to guessing based on the binary location
3931
+ // path is likely something like .../rust-lightning/target/debug/deps/lightning-...
3932
+ let mut path = std:: env:: current_exe ( ) . unwrap ( ) ;
3933
+ path. pop ( ) ; // lightning-...
3934
+ path. pop ( ) ; // deps
3935
+ path. pop ( ) ; // debug
3936
+ path. pop ( ) ; // target
3937
+ path. push ( "lightning" ) ;
3938
+ path. push ( "net_graph-2021-05-27.bin" ) ;
3939
+ eprintln ! ( "{}" , path. to_str( ) . unwrap( ) ) ;
3940
+ File :: open ( path)
3941
+ } )
3942
+ . map_err ( |_| "Please fetch https://bitcoin.ninja/ldk-net_graph-45d86ead641d-2021-05-27.bin and place it at lightning/net_graph-2021-05-27.bin" ) ;
3943
+ #[ cfg( require_route_graph_test) ]
3944
+ return Ok ( res. unwrap ( ) ) ;
3945
+ #[ cfg( not( require_route_graph_test) ) ]
3946
+ return res;
3947
+ }
3948
+ }
3949
+
3946
3950
#[ cfg( all( test, feature = "unstable" ) ) ]
3947
3951
mod benches {
3948
3952
use super :: * ;
3949
3953
use util:: logger:: { Logger , Record } ;
3950
3954
3951
- use prelude:: * ;
3952
3955
use test:: Bencher ;
3953
3956
3954
3957
struct DummyLogger { }
@@ -3958,8 +3961,7 @@ mod benches {
3958
3961
3959
3962
#[ bench]
3960
3963
fn generate_routes ( bench : & mut Bencher ) {
3961
- let mut d = tests:: get_route_file ( )
3962
- . expect ( "Please fetch https://bitcoin.ninja/ldk-net_graph-45d86ead641d-2021-05-27.bin and place it at lightning/net_graph-2021-05-27.bin" ) ;
3964
+ let mut d = test_utils:: get_route_file ( ) . unwrap ( ) ;
3963
3965
let graph = NetworkGraph :: read ( & mut d) . unwrap ( ) ;
3964
3966
3965
3967
// First, get 100 (source, destination) pairs for which route-getting actually succeeds...
@@ -3990,8 +3992,7 @@ mod benches {
3990
3992
3991
3993
#[ bench]
3992
3994
fn generate_mpp_routes ( bench : & mut Bencher ) {
3993
- let mut d = tests:: get_route_file ( )
3994
- . expect ( "Please fetch https://bitcoin.ninja/ldk-net_graph-45d86ead641d-2021-05-27.bin and place it at lightning/net_graph-2021-05-27.bin" ) ;
3995
+ let mut d = test_utils:: get_route_file ( ) . unwrap ( ) ;
3995
3996
let graph = NetworkGraph :: read ( & mut d) . unwrap ( ) ;
3996
3997
3997
3998
// First, get 100 (source, destination) pairs for which route-getting actually succeeds...
0 commit comments