Skip to content

Commit c8a2ac4

Browse files
committed
[invoice] Add the BOLT 11 failure unit tests that we already pass
1 parent 0cff1f7 commit c8a2ac4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lightning-invoice/tests/ser_de.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use secp256k1::Secp256k1;
1111
use secp256k1::key::SecretKey;
1212
use secp256k1::recovery::{RecoverableSignature, RecoveryId};
1313
use std::time::{Duration, UNIX_EPOCH};
14+
use std::str::FromStr;
1415

1516
// TODO: add more of the examples from BOLT11 and generate ones causing SemanticErrors
1617

@@ -149,3 +150,20 @@ fn deserialize() {
149150
}
150151
}
151152
}
153+
154+
#[test]
155+
fn test_bolt_invaoid_invoices() {
156+
// Tests the BOLT 11 invalid invoice test vectors
157+
assert_eq!(Invoice::from_str(
158+
"lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrnt"
159+
), Err(ParseOrSemanticError::ParseError(ParseError::Bech32Error(bech32::Error::InvalidChecksum))));
160+
assert_eq!(Invoice::from_str(
161+
"pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrny"
162+
), Err(ParseOrSemanticError::ParseError(ParseError::Bech32Error(bech32::Error::MissingSeparator))));
163+
assert_eq!(Invoice::from_str(
164+
"LNBC2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrny"
165+
), Err(ParseOrSemanticError::ParseError(ParseError::Bech32Error(bech32::Error::MixedCase))));
166+
assert_eq!(Invoice::from_str(
167+
"lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6na6hlh"
168+
), Err(ParseOrSemanticError::ParseError(ParseError::TooShortDataPart)));
169+
}

0 commit comments

Comments
 (0)