|
47 | 47 | //! .issuer("Foo Bar".to_string())
|
48 | 48 | //! .path(create_blinded_path())
|
49 | 49 | //! .path(create_another_blinded_path())
|
50 |
| -//! .build() |
51 |
| -//! .unwrap(); |
| 50 | +//! .build()?; |
52 | 51 | //!
|
53 | 52 | //! // Encode as a bech32 string for use in a QR code.
|
54 | 53 | //! let encoded_offer = offer.to_string();
|
@@ -211,9 +210,9 @@ impl OfferBuilder {
|
211 | 210 | }
|
212 | 211 |
|
213 | 212 | /// Builds an [`Offer`] from the builder's settings.
|
214 |
| - pub fn build(self) -> Result<Offer, ()> { |
| 213 | + pub fn build(self) -> Result<Offer, SemanticError> { |
215 | 214 | if self.offer.quantity_min() > self.offer.quantity_max() {
|
216 |
| - return Err(()); |
| 215 | + return Err(SemanticError::InvalidQuantity); |
217 | 216 | }
|
218 | 217 |
|
219 | 218 | let mut bytes = Vec::new();
|
@@ -531,6 +530,7 @@ mod tests {
|
531 | 530 | use core::num::NonZeroU64;
|
532 | 531 | use core::time::Duration;
|
533 | 532 | use ln::features::OfferFeatures;
|
| 533 | + use offers::parse::SemanticError; |
534 | 534 | use onion_message::{BlindedHop, BlindedPath};
|
535 | 535 | use util::ser::Writeable;
|
536 | 536 |
|
@@ -884,11 +884,10 @@ mod tests {
|
884 | 884 | assert_eq!(tlv_stream.quantity_min, None);
|
885 | 885 | assert_eq!(tlv_stream.quantity_max, Some(9));
|
886 | 886 |
|
887 |
| - assert!(OfferBuilder::new("foo".into(), pubkey(42)) |
888 |
| - .quantity_range(ten..five) |
889 |
| - .build() |
890 |
| - .is_err() |
891 |
| - ); |
| 887 | + match OfferBuilder::new("foo".into(), pubkey(42)).quantity_range(ten..five).build() { |
| 888 | + Ok(_) => panic!("expected error"), |
| 889 | + Err(e) => assert_eq!(e, SemanticError::InvalidQuantity), |
| 890 | + } |
892 | 891 | }
|
893 | 892 | }
|
894 | 893 |
|
|
0 commit comments