|
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();
|
@@ -212,9 +211,9 @@ impl OfferBuilder {
|
212 | 211 | }
|
213 | 212 |
|
214 | 213 | /// Builds an [`Offer`] from the builder's settings.
|
215 |
| - pub fn build(self) -> Result<Offer, ()> { |
| 214 | + pub fn build(self) -> Result<Offer, SemanticError> { |
216 | 215 | if self.offer.quantity_min() > self.offer.quantity_max() {
|
217 |
| - return Err(()); |
| 216 | + return Err(SemanticError::InvalidQuantity); |
218 | 217 | }
|
219 | 218 |
|
220 | 219 | let mut bytes = Vec::new();
|
@@ -533,6 +532,7 @@ mod tests {
|
533 | 532 | use core::num::NonZeroU64;
|
534 | 533 | use core::time::Duration;
|
535 | 534 | use ln::features::OfferFeatures;
|
| 535 | + use offers::parse::SemanticError; |
536 | 536 | use onion_message::{BlindedHop, BlindedPath};
|
537 | 537 | use util::ser::Writeable;
|
538 | 538 |
|
@@ -886,11 +886,10 @@ mod tests {
|
886 | 886 | assert_eq!(tlv_stream.quantity_min, None);
|
887 | 887 | assert_eq!(tlv_stream.quantity_max, Some(9));
|
888 | 888 |
|
889 |
| - assert!(OfferBuilder::new("foo".into(), pubkey(42)) |
890 |
| - .quantity_range(ten..five) |
891 |
| - .build() |
892 |
| - .is_err() |
893 |
| - ); |
| 889 | + match OfferBuilder::new("foo".into(), pubkey(42)).quantity_range(ten..five).build() { |
| 890 | + Ok(_) => panic!("expected error"), |
| 891 | + Err(e) => assert_eq!(e, SemanticError::InvalidQuantity), |
| 892 | + } |
894 | 893 | }
|
895 | 894 | }
|
896 | 895 |
|
|
0 commit comments