From cd0a02807e421c812f4c570a5b7745c277b5cb3c Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 24 May 2024 15:18:27 +0000 Subject: [PATCH] [C#] Add a simple test of BOLT12 offer parsing --- c_sharp/test/src/tests.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/c_sharp/test/src/tests.cs b/c_sharp/test/src/tests.cs index c095be59..cd7249a2 100644 --- a/c_sharp/test/src/tests.cs +++ b/c_sharp/test/src/tests.cs @@ -326,10 +326,29 @@ namespace tests { Assert(as_commit[0] is MessageSendEvent.MessageSendEvent_UpdateHTLCs, 33); } + static void Bolt12ParseTest() { + // Parse a random BOLT12 offer from the BOLT12 test cases + const string? offerStr = "lno1pgx9getnwss8vetrw3hhyuckyypwa3eyt44h6txtxquqh7lz5djge4afgfjn7k4rgrkuag0jsd5xvxg"; + const string expectedPubkey = "02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619"; + const string expectedDescription = "Test vectors"; + + Result_OfferBolt12ParseErrorZ offer_res = Offer.from_str(offerStr); + Assert(offer_res.is_ok(), 100); + Offer offer = ((Result_OfferBolt12ParseErrorZ.Result_OfferBolt12ParseErrorZ_OK)offer_res).res; + Assert(BitConverter.ToString(offer.signing_pubkey()).Replace("-", "").ToLower() == expectedPubkey, 101); + Assert(offer.description().get_a() == expectedDescription, 102); + Assert(offer.issuer() == null, 103); + Assert(!offer.is_expired(), 104); + Assert(offer.expects_quantity(), 105); + Assert(offer.amount() is Option_AmountZ.Option_AmountZ_None, 106); + Assert(offer.supported_quantity() is Quantity.Quantity_One, 107); + } + static void Main(string[] args) { SimpleConstructionTest(); SimpleTraitTest(); NodeTest(); + Bolt12ParseTest(); Console.WriteLine("\n\nTESTS PASSED\n\n"); System.GC.Collect(); -- 2.39.5