use crate::ln::features::{InvoiceRequestFeatures, OfferFeatures};
use crate::ln::inbound_payment::ExpandedKey;
use crate::ln::msgs::{DecodeError, MAX_VALUE_MSAT};
- use crate::offers::invoice_request::{ExperimentalInvoiceRequestTlvStreamRef, INVOICE_REQUEST_TYPES, InvoiceRequestTlvStreamRef};
+ use crate::offers::invoice_request::{EXPERIMENTAL_INVOICE_REQUEST_TYPES, ExperimentalInvoiceRequestTlvStreamRef, INVOICE_REQUEST_TYPES, InvoiceRequestTlvStreamRef};
use crate::offers::nonce::Nonce;
use crate::offers::offer::{ExperimentalOfferTlvStreamRef, OfferTlvStreamRef};
use crate::offers::parse::{Bolt12ParseError, Bolt12SemanticError};
}
}
+ #[test]
+ fn parses_refund_with_experimental_tlv_records() {
+ const UNKNOWN_ODD_TYPE: u64 = EXPERIMENTAL_INVOICE_REQUEST_TYPES.start + 1;
+ assert!(UNKNOWN_ODD_TYPE % 2 == 1);
+
+ let refund = RefundBuilder::new(vec![1; 32], payer_pubkey(), 1000).unwrap()
+ .build().unwrap();
+
+ let mut encoded_refund = Vec::new();
+ refund.write(&mut encoded_refund).unwrap();
+ BigSize(UNKNOWN_ODD_TYPE).write(&mut encoded_refund).unwrap();
+ BigSize(32).write(&mut encoded_refund).unwrap();
+ [42u8; 32].write(&mut encoded_refund).unwrap();
+
+ match Refund::try_from(encoded_refund.clone()) {
+ Ok(refund) => assert_eq!(refund.bytes, encoded_refund),
+ Err(e) => panic!("error parsing refund: {:?}", e),
+ }
+
+ const UNKNOWN_EVEN_TYPE: u64 = EXPERIMENTAL_INVOICE_REQUEST_TYPES.start;
+ assert!(UNKNOWN_EVEN_TYPE % 2 == 0);
+
+ let refund = RefundBuilder::new(vec![1; 32], payer_pubkey(), 1000).unwrap()
+ .build().unwrap();
+
+ let mut encoded_refund = Vec::new();
+ refund.write(&mut encoded_refund).unwrap();
+ BigSize(UNKNOWN_EVEN_TYPE).write(&mut encoded_refund).unwrap();
+ BigSize(32).write(&mut encoded_refund).unwrap();
+ [42u8; 32].write(&mut encoded_refund).unwrap();
+
+ match Refund::try_from(encoded_refund) {
+ Ok(_) => panic!("expected error"),
+ Err(e) => assert_eq!(e, Bolt12ParseError::Decode(DecodeError::UnknownRequiredFeature)),
+ }
+ }
+
#[test]
fn fails_parsing_refund_with_out_of_range_tlv_records() {
let secp_ctx = Secp256k1::new();
Ok(_) => panic!("expected error"),
Err(e) => assert_eq!(e, Bolt12ParseError::Decode(DecodeError::InvalidValue)),
}
+
+ let mut encoded_refund = Vec::new();
+ refund.write(&mut encoded_refund).unwrap();
+ BigSize(EXPERIMENTAL_INVOICE_REQUEST_TYPES.end).write(&mut encoded_refund).unwrap();
+ BigSize(32).write(&mut encoded_refund).unwrap();
+ [42u8; 32].write(&mut encoded_refund).unwrap();
+
+ match Refund::try_from(encoded_refund) {
+ Ok(_) => panic!("expected error"),
+ Err(e) => assert_eq!(e, Bolt12ParseError::Decode(DecodeError::InvalidValue)),
+ }
}
}