1 // This file is auto-generated by gen_target.sh based on msg_target_template.txt
2 // To modify it, modify msg_target_template.txt and run gen_target.sh instead.
4 use bitcoin::hash_types::BlockHash;
6 use lightning::chain::channelmonitor;
7 use lightning::util::test_channel_signer::TestChannelSigner;
8 use lightning::util::ser::{ReadableArgs, Writer, Writeable};
9 use lightning::util::test_utils::OnlyReadsKeysInterface;
11 use crate::utils::test_logger;
15 struct VecWriter(Vec<u8>);
16 impl Writer for VecWriter {
17 fn write_all(&mut self, buf: &[u8]) -> Result<(), ::std::io::Error> {
18 self.0.extend_from_slice(buf);
24 pub fn do_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
25 if let Ok((latest_block_hash, monitor)) = <(BlockHash, channelmonitor::ChannelMonitor<TestChannelSigner>)>::read(&mut Cursor::new(data), (&OnlyReadsKeysInterface {}, &OnlyReadsKeysInterface {})) {
26 let mut w = VecWriter(Vec::new());
27 monitor.write(&mut w).unwrap();
28 let deserialized_copy = <(BlockHash, channelmonitor::ChannelMonitor<TestChannelSigner>)>::read(&mut Cursor::new(&w.0), (&OnlyReadsKeysInterface {}, &OnlyReadsKeysInterface {})).unwrap();
29 assert!(latest_block_hash == deserialized_copy.0);
30 assert!(monitor == deserialized_copy.1);
34 pub fn chanmon_deser_test<Out: test_logger::Output>(data: &[u8], out: Out) {
39 pub extern "C" fn chanmon_deser_run(data: *const u8, datalen: usize) {
40 do_test(unsafe { std::slice::from_raw_parts(data, datalen) }, test_logger::DevNull{});