1 // This file is Copyright its original authors, visible in version control
4 // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5 // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7 // You may not use this file except in accordance with one or both of these
10 use bitcoin::bech32::{u5, FromBase32, ToBase32};
11 use crate::utils::test_logger;
12 use lightning_invoice::RawDataPart;
15 pub fn do_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
16 let bech32 = data.iter().map(|x| u5::try_from_u8(x % 32).unwrap()).collect::<Vec<_>>();
17 let invoice = match RawDataPart::from_base32(&bech32) {
18 Ok(invoice) => invoice,
22 // Our encoding is not worse than the input
23 assert!(invoice.to_base32().len() <= bech32.len());
25 // Our serialization is loss-less
27 RawDataPart::from_base32(&invoice.to_base32()).expect("faild parsing out own encoding"),
32 pub fn bolt11_deser_test<Out: test_logger::Output>(data: &[u8], out: Out) {
37 pub extern "C" fn bolt11_deser_run(data: *const u8, datalen: usize) {
38 do_test(unsafe { std::slice::from_raw_parts(data, datalen) }, test_logger::DevNull {});