From: Jeffrey Czyz Date: Mon, 13 Jun 2022 22:25:10 +0000 (-0500) Subject: Replace Arc with reference in some tests X-Git-Tag: v0.0.109~15^2~1 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=cb66dcd3b40a0e5b0f224a0ac44d88bec26a8f53;p=rust-lightning Replace Arc with reference in some tests --- diff --git a/fuzz/src/process_network_graph.rs b/fuzz/src/process_network_graph.rs index ae38d678a..8b6462e81 100644 --- a/fuzz/src/process_network_graph.rs +++ b/fuzz/src/process_network_graph.rs @@ -9,8 +9,8 @@ use std::sync::Arc; /// Actual fuzz test, method signature and name are fixed fn do_test(data: &[u8], out: Out) { let block_hash = bitcoin::BlockHash::default(); - let logger: Arc = Arc::new(test_logger::TestLogger::new("".to_owned(), out)); - let network_graph = lightning::routing::gossip::NetworkGraph::new(block_hash, logger); + let logger = test_logger::TestLogger::new("".to_owned(), out); + let network_graph = lightning::routing::gossip::NetworkGraph::new(block_hash, &logger); let rapid_sync = RapidGossipSync::new(&network_graph); let _ = rapid_sync.update_network_graph(data); } diff --git a/fuzz/src/router.rs b/fuzz/src/router.rs index 21fb2dc15..f3af5bdc1 100644 --- a/fuzz/src/router.rs +++ b/fuzz/src/router.rs @@ -159,10 +159,10 @@ pub fn do_test(data: &[u8], out: Out) { } } - let logger: Arc = Arc::new(test_logger::TestLogger::new("".to_owned(), out)); + let logger = test_logger::TestLogger::new("".to_owned(), out); let our_pubkey = get_pubkey!(); - let net_graph = NetworkGraph::new(genesis_block(Network::Bitcoin).header.block_hash(), Arc::clone(&logger)); + let net_graph = NetworkGraph::new(genesis_block(Network::Bitcoin).header.block_hash(), &logger); let mut node_pks = HashSet::new(); let mut scid = 42; @@ -269,7 +269,7 @@ pub fn do_test(data: &[u8], out: Out) { }; let _ = find_route(&our_pubkey, &route_params, &net_graph.read_only(), first_hops.map(|c| c.iter().collect::>()).as_ref().map(|a| a.as_slice()), - Arc::clone(&logger), &scorer, &random_seed_bytes); + &logger, &scorer, &random_seed_bytes); } }, } diff --git a/lightning/src/routing/gossip.rs b/lightning/src/routing/gossip.rs index f404e77b2..bd2b9d06e 100644 --- a/lightning/src/routing/gossip.rs +++ b/lightning/src/routing/gossip.rs @@ -1632,7 +1632,6 @@ mod tests { UnsignedChannelAnnouncement, ChannelAnnouncement, UnsignedChannelUpdate, ChannelUpdate, ReplyChannelRange, QueryChannelRange, QueryShortChannelIds, MAX_VALUE_MSAT}; use util::test_utils; - use util::logger::Logger; use util::ser::{ReadableArgs, Writeable}; use util::events::{Event, EventHandler, MessageSendEvent, MessageSendEventsProvider}; use util::scid_utils::scid_from_parts; @@ -1829,7 +1828,7 @@ mod tests { #[test] fn handling_channel_announcements() { let secp_ctx = Secp256k1::new(); - let logger: Arc = Arc::new(test_utils::TestLogger::new()); + let logger = test_utils::TestLogger::new(); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); @@ -1839,8 +1838,8 @@ mod tests { // Test if the UTXO lookups were not supported let genesis_hash = genesis_block(Network::Testnet).header.block_hash(); - let network_graph = NetworkGraph::new(genesis_hash, Arc::clone(&logger)); - let mut gossip_sync = P2PGossipSync::new(&network_graph, None, Arc::clone(&logger)); + let network_graph = NetworkGraph::new(genesis_hash, &logger); + let mut gossip_sync = P2PGossipSync::new(&network_graph, None, &logger); match gossip_sync.handle_channel_announcement(&valid_announcement) { Ok(res) => assert!(res), _ => panic!() @@ -1861,10 +1860,10 @@ mod tests { }; // Test if an associated transaction were not on-chain (or not confirmed). - let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet)); + let chain_source = test_utils::TestChainSource::new(Network::Testnet); *chain_source.utxo_ret.lock().unwrap() = Err(chain::AccessError::UnknownTx); - let network_graph = NetworkGraph::new(genesis_hash, Arc::clone(&logger)); - gossip_sync = P2PGossipSync::new(&network_graph, Some(chain_source.clone()), Arc::clone(&logger)); + let network_graph = NetworkGraph::new(genesis_hash, &logger); + gossip_sync = P2PGossipSync::new(&network_graph, Some(&chain_source), &logger); let valid_announcement = get_signed_channel_announcement(|unsigned_announcement| { unsigned_announcement.short_channel_id += 1; @@ -1945,11 +1944,11 @@ mod tests { #[test] fn handling_channel_update() { let secp_ctx = Secp256k1::new(); - let logger: Arc = Arc::new(test_utils::TestLogger::new()); - let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet)); + let logger = test_utils::TestLogger::new(); + let chain_source = test_utils::TestChainSource::new(Network::Testnet); let genesis_hash = genesis_block(Network::Testnet).header.block_hash(); - let network_graph = NetworkGraph::new(genesis_hash, Arc::clone(&logger)); - let gossip_sync = P2PGossipSync::new(&network_graph, Some(chain_source.clone()), Arc::clone(&logger)); + let network_graph = NetworkGraph::new(genesis_hash, &logger); + let gossip_sync = P2PGossipSync::new(&network_graph, Some(&chain_source), &logger); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); @@ -2151,10 +2150,10 @@ mod tests { fn test_channel_timeouts() { // Test the removal of channels with `remove_stale_channels`. let logger = test_utils::TestLogger::new(); - let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet)); + let chain_source = test_utils::TestChainSource::new(Network::Testnet); let genesis_hash = genesis_block(Network::Testnet).header.block_hash(); let network_graph = NetworkGraph::new(genesis_hash, &logger); - let gossip_sync = P2PGossipSync::new(&network_graph, Some(chain_source.clone()), &logger); + let gossip_sync = P2PGossipSync::new(&network_graph, Some(&chain_source), &logger); let secp_ctx = Secp256k1::new(); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap();