/
invoice_deser.rs
31 lines (27 loc) · 1.05 KB
/
invoice_deser.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// This file is Copyright its original authors, visible in version control
// history.
//
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
// You may not use this file except in accordance with one or both of these
// licenses.
use crate::utils::test_logger;
use lightning::offers::invoice::Bolt12Invoice;
use lightning::util::ser::Writeable;
use std::convert::TryFrom;
#[inline]
pub fn do_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
if let Ok(invoice) = Bolt12Invoice::try_from(data.to_vec()) {
let mut bytes = Vec::with_capacity(data.len());
invoice.write(&mut bytes).unwrap();
assert_eq!(data, bytes);
}
}
pub fn invoice_deser_test<Out: test_logger::Output>(data: &[u8], out: Out) {
do_test(data, out);
}
#[no_mangle]
pub extern "C" fn invoice_deser_run(data: *const u8, datalen: usize) {
do_test(unsafe { std::slice::from_raw_parts(data, datalen) }, test_logger::DevNull {});
}