[C#] Add a simple test of BOLT12 offer parsing
[ldk-java] / c_sharp / test / src / tests.cs
index c095be5991492fc2d2a6619dffb5ede41cbead72..cd7249a2d37ef1252a0bdd32c194e429e5ceb683 100644 (file)
@@ -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();