}
}
- use std::fs::File;
- use util::ser::Readable;
- /// Tries to open a network graph file, or panics with a URL to fetch it.
- pub(super) fn get_route_file() -> Result<std::fs::File, std::io::Error> {
- let res = File::open("net_graph-2021-05-27.bin") // By default we're run in RL/lightning
- .or_else(|_| File::open("lightning/net_graph-2021-05-27.bin")) // We may be run manually in RL/
- .or_else(|_| { // Fall back to guessing based on the binary location
- // path is likely something like .../rust-lightning/target/debug/deps/lightning-...
- let mut path = std::env::current_exe().unwrap();
- path.pop(); // lightning-...
- path.pop(); // deps
- path.pop(); // debug
- path.pop(); // target
- path.push("lightning");
- path.push("net_graph-2021-05-27.bin");
- eprintln!("{}", path.to_str().unwrap());
- File::open(path)
- });
- #[cfg(require_route_graph_test)]
- return Ok(res.expect("Didn't have route graph and was configured to require it"));
- #[cfg(not(require_route_graph_test))]
- return res;
- }
-
pub(super) fn random_init_seed() -> u64 {
// Because the default HashMap in std pulls OS randomness, we can use it as a (bad) RNG.
use core::hash::{BuildHasher, Hasher};
println!("Using seed of {}", seed);
seed
}
+ use util::ser::Readable;
#[test]
fn generate_routes() {
- let mut d = match get_route_file() {
+ let mut d = match super::test_utils::get_route_file() {
Ok(f) => f,
- Err(_) => {
- 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");
+ Err(e) => {
+ eprintln!("{}", e);
return;
},
};
#[test]
fn generate_routes_mpp() {
- let mut d = match get_route_file() {
+ let mut d = match super::test_utils::get_route_file() {
Ok(f) => f,
- Err(_) => {
- 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");
+ Err(e) => {
+ eprintln!("{}", e);
return;
},
};
}
}
+#[cfg(test)]
+pub(crate) mod test_utils {
+ use std::fs::File;
+ /// Tries to open a network graph file, or panics with a URL to fetch it.
+ pub(crate) fn get_route_file() -> Result<std::fs::File, &'static str> {
+ let res = File::open("net_graph-2021-05-27.bin") // By default we're run in RL/lightning
+ .or_else(|_| File::open("lightning/net_graph-2021-05-27.bin")) // We may be run manually in RL/
+ .or_else(|_| { // Fall back to guessing based on the binary location
+ // path is likely something like .../rust-lightning/target/debug/deps/lightning-...
+ let mut path = std::env::current_exe().unwrap();
+ path.pop(); // lightning-...
+ path.pop(); // deps
+ path.pop(); // debug
+ path.pop(); // target
+ path.push("lightning");
+ path.push("net_graph-2021-05-27.bin");
+ eprintln!("{}", path.to_str().unwrap());
+ File::open(path)
+ })
+ .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");
+ #[cfg(require_route_graph_test)]
+ return Ok(res.unwrap());
+ #[cfg(not(require_route_graph_test))]
+ return res;
+ }
+}
+
#[cfg(all(test, feature = "unstable"))]
mod benches {
use super::*;
use util::logger::{Logger, Record};
- use prelude::*;
use test::Bencher;
struct DummyLogger {}
#[bench]
fn generate_routes(bench: &mut Bencher) {
- let mut d = tests::get_route_file()
- .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");
+ let mut d = test_utils::get_route_file().unwrap();
let graph = NetworkGraph::read(&mut d).unwrap();
// First, get 100 (source, destination) pairs for which route-getting actually succeeds...
#[bench]
fn generate_mpp_routes(bench: &mut Bencher) {
- let mut d = tests::get_route_file()
- .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");
+ let mut d = test_utils::get_route_file().unwrap();
let graph = NetworkGraph::read(&mut d).unwrap();
// First, get 100 (source, destination) pairs for which route-getting actually succeeds...