X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Futil%2Ftest_utils.rs;h=4360c5701c40e93927eab81bcdc3a4963236a34e;hb=efcfb93ebe0ecf0889b0cb3393cbe4d3c1e13ab6;hp=b04f728b0f71edde16afa738fa2caa248c242bdb;hpb=8783a748bb952168623cb674f8ea3230d7c94b25;p=rust-lightning diff --git a/src/util/test_utils.rs b/src/util/test_utils.rs index b04f728b..4360c570 100644 --- a/src/util/test_utils.rs +++ b/src/util/test_utils.rs @@ -20,8 +20,8 @@ use secp256k1::{SecretKey, PublicKey}; use std::sync::{Arc,Mutex}; use std::{mem}; -struct VecWriter(Vec); -impl Writer for VecWriter { +pub struct TestVecWriter(pub Vec); +impl Writer for TestVecWriter { fn write_all(&mut self, buf: &[u8]) -> Result<(), ::std::io::Error> { self.0.extend_from_slice(buf); Ok(()) @@ -58,7 +58,7 @@ impl channelmonitor::ManyChannelMonitor for TestChannelMonitor { fn add_update_monitor(&self, funding_txo: OutPoint, monitor: channelmonitor::ChannelMonitor) -> Result<(), channelmonitor::ChannelMonitorUpdateErr> { // At every point where we get a monitor update, we should be able to send a useful monitor // to a watchtower and disk... - let mut w = VecWriter(Vec::new()); + let mut w = TestVecWriter(Vec::new()); monitor.write_for_disk(&mut w).unwrap(); assert!(<(Sha256dHash, channelmonitor::ChannelMonitor)>::read( &mut ::std::io::Cursor::new(&w.0), Arc::new(TestLogger::new())).unwrap().1 == monitor); @@ -215,6 +215,7 @@ impl Logger for TestLogger { pub struct TestKeysInterface { backing: keysinterface::KeysManager, pub override_session_priv: Mutex>, + pub override_channel_id_priv: Mutex>, } impl keysinterface::KeysInterface for TestKeysInterface { @@ -229,6 +230,13 @@ impl keysinterface::KeysInterface for TestKeysInterface { None => self.backing.get_session_key() } } + + fn get_channel_id(&self) -> [u8; 32] { + match *self.override_channel_id_priv.lock().unwrap() { + Some(key) => key.clone(), + None => self.backing.get_channel_id() + } + } } impl TestKeysInterface { @@ -236,6 +244,7 @@ impl TestKeysInterface { Self { backing: keysinterface::KeysManager::new(seed, network, logger), override_session_priv: Mutex::new(None), + override_channel_id_priv: Mutex::new(None), } } }