From a80819c9c2562fdf93a835cd30d42d955863c861 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 22 Aug 2021 19:35:15 +0000 Subject: [PATCH] [invoice] Add the BOLT 11 failure unit tests that we already pass --- lightning-invoice/tests/ser_de.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lightning-invoice/tests/ser_de.rs b/lightning-invoice/tests/ser_de.rs index 442166e74..2da843fd6 100644 --- a/lightning-invoice/tests/ser_de.rs +++ b/lightning-invoice/tests/ser_de.rs @@ -11,6 +11,7 @@ use secp256k1::Secp256k1; use secp256k1::key::SecretKey; use secp256k1::recovery::{RecoverableSignature, RecoveryId}; use std::time::{Duration, UNIX_EPOCH}; +use std::str::FromStr; // TODO: add more of the examples from BOLT11 and generate ones causing SemanticErrors @@ -149,3 +150,20 @@ fn deserialize() { } } } + +#[test] +fn test_bolt_invalid_invoices() { + // Tests the BOLT 11 invalid invoice test vectors + assert_eq!(Invoice::from_str( + "lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrnt" + ), Err(ParseOrSemanticError::ParseError(ParseError::Bech32Error(bech32::Error::InvalidChecksum)))); + assert_eq!(Invoice::from_str( + "pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrny" + ), Err(ParseOrSemanticError::ParseError(ParseError::Bech32Error(bech32::Error::MissingSeparator)))); + assert_eq!(Invoice::from_str( + "LNBC2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrny" + ), Err(ParseOrSemanticError::ParseError(ParseError::Bech32Error(bech32::Error::MixedCase)))); + assert_eq!(Invoice::from_str( + "lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6na6hlh" + ), Err(ParseOrSemanticError::ParseError(ParseError::TooShortDataPart))); +} -- 2.39.5