From 75d69f3a8e7953144f484d537233a85a83b545d9 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Thu, 23 Jan 2025 17:08:52 +0100 Subject: [PATCH] Add reconversion unit test We simply check that converting back-and-forth between hash types nothing is lost. --- src/uniffi_types.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/uniffi_types.rs b/src/uniffi_types.rs index 90d76dc18..0fe0f31b0 100644 --- a/src/uniffi_types.rs +++ b/src/uniffi_types.rs @@ -348,6 +348,7 @@ impl UniffiCustomTypeConverter for NodeAlias { /// Represents the description of an invoice which has to be either a directly included string or /// a hash of a description provided out of band. +#[derive(Debug, Clone, PartialEq, Eq)] pub enum Bolt11InvoiceDescription { /// Contains a full description. Direct { @@ -391,3 +392,17 @@ impl From for Bolt11InvoiceDescript } } } + +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn test_invoice_description_conversion() { + let hash = "09d08d4865e8af9266f6cc7c0ae23a1d6bf868207cf8f7c5979b9f6ed850dfb0".to_string(); + let description = Bolt11InvoiceDescription::Hash { hash }; + let converted_description = + lightning_invoice::Bolt11InvoiceDescription::try_from(&description).unwrap(); + let reconverted_description: Bolt11InvoiceDescription = converted_description.into(); + assert_eq!(description, reconverted_description); + } +}