-use bitcoin_hashes::sha256d::Hash as Sha256dHash;
use bitcoin::blockdata::script::{Script, Builder};
use bitcoin::blockdata::block::Block;
use bitcoin::blockdata::transaction::Transaction;
+use bitcoin::hash_types::{Txid, BlockHash};
use lightning::chain::chaininterface::{ChainError,ChainWatchInterface};
use lightning::ln::channelmanager::ChannelDetails;
use lightning::util::logger::Logger;
use lightning::util::ser::Readable;
-use secp256k1::key::PublicKey;
+use bitcoin::secp256k1::key::PublicKey;
use utils::test_logger;
}
impl ChainWatchInterface for DummyChainWatcher {
- fn install_watch_tx(&self, _txid: &Sha256dHash, _script_pub_key: &Script) { }
- fn install_watch_outpoint(&self, _outpoint: (Sha256dHash, u32), _out_script: &Script) { }
+ fn install_watch_tx(&self, _txid: &Txid, _script_pub_key: &Script) { }
+ fn install_watch_outpoint(&self, _outpoint: (Txid, u32), _out_script: &Script) { }
fn watch_all_txn(&self) { }
fn filter_block<'a>(&self, _block: &'a Block) -> (Vec<&'a Transaction>, Vec<u32>) {
(Vec::new(), Vec::new())
}
fn reentered(&self) -> usize { 0 }
- fn get_chain_utxo(&self, _genesis_hash: Sha256dHash, _unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError> {
+ fn get_chain_utxo(&self, _genesis_hash: BlockHash, _unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError> {
match self.input.get_slice(2) {
Some(&[0, _]) => Err(ChainError::NotSupported),
Some(&[1, _]) => Err(ChainError::NotWatched),
}
#[inline]
-pub fn do_test(data: &[u8]) {
+pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
let input = Arc::new(InputData {
data: data.to_vec(),
read_pos: AtomicUsize::new(0),
macro_rules! decode_msg {
($MsgType: path, $len: expr) => {{
let mut reader = ::std::io::Cursor::new(get_slice!($len));
- match <($MsgType)>::read(&mut reader) {
+ match <$MsgType>::read(&mut reader) {
Ok(msg) => msg,
Err(e) => match e {
msgs::DecodeError::UnknownVersion => return,
msgs::DecodeError::UnknownRequiredFeature => return,
msgs::DecodeError::InvalidValue => return,
- msgs::DecodeError::ExtraAddressesPerType => return,
msgs::DecodeError::BadLengthDescriptor => return,
msgs::DecodeError::ShortRead => panic!("We picked the length..."),
msgs::DecodeError::Io(e) => panic!(format!("{}", e)),
}
}
- let logger: Arc<dyn Logger> = Arc::new(test_logger::TestLogger::new("".to_owned()));
+ let logger: Arc<dyn Logger> = Arc::new(test_logger::TestLogger::new("".to_owned(), out));
let chain_monitor = Arc::new(DummyChainWatcher {
input: Arc::clone(&input),
});
}
}
-#[no_mangle]
-pub extern "C" fn router_run(data: *const u8, datalen: usize) {
- do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+pub fn router_test<Out: test_logger::Output>(data: &[u8], out: Out) {
+ do_test(data, out);
}
-#[cfg(test)]
-mod tests {
- #[test]
- fn duplicate_crash() {
- super::do_test(&::hex::decode("00").unwrap());
- }
+#[no_mangle]
+pub extern "C" fn router_run(data: *const u8, datalen: usize) {
+ do_test(unsafe { std::slice::from_raw_parts(data, datalen) }, test_logger::DevNull {});
}