Skip to content

Commit 2ddd5b5

Browse files
committed
[C#] Add a simple test of BOLT12 offer parsing
1 parent 621144a commit 2ddd5b5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

c_sharp/test/src/tests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,31 @@ static void NodeTest() {
326326
Assert(as_commit[0] is MessageSendEvent.MessageSendEvent_UpdateHTLCs, 33);
327327
}
328328

329+
static void Bolt12ParseTest() {
330+
// Parse a random BOLT12 offer from the BOLT12 test cases
331+
const string offerStr = "lno1pgx9getnwss8vetrw3hhyuckyypwa3eyt44h6txtxquqh7lz5djge4afgfjn7k4rgrkuag0jsd5xvxg";
332+
const string expectedPubkey = "02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619";
333+
const string expectedDescription = "Test vectors";
334+
335+
Result_OfferBolt12ParseErrorZ offer_res = Offer.from_str(offerStr);
336+
Assert(offer_res.is_ok(), 100);
337+
Offer offer = ((Result_OfferBolt12ParseErrorZ.Result_OfferBolt12ParseErrorZ_OK)offer_res).res;
338+
Assert(BitConverter.ToString(offer.signing_pubkey()).Replace("-", "").ToLower() == expectedPubkey, 101);
339+
Assert(offer.description().get_a() == expectedDescription, 102);
340+
Assert(offer.issuer() == null, 103);
341+
Assert(!offer.is_expired(), 104);
342+
Assert(!offer.expects_quantity(), 105);
343+
Assert(offer.supported_quantity() is Quantity.Quantity_One, 106);
344+
Assert(offer.amount() is Option_AmountZ.Option_AmountZ_None, 107);
345+
Assert(offer.supported_quantity() is Quantity.Quantity_One, 108);
346+
Assert(offer.to_str() == offerStr, 109);
347+
}
348+
329349
static void Main(string[] args) {
330350
SimpleConstructionTest();
331351
SimpleTraitTest();
332352
NodeTest();
353+
Bolt12ParseTest();
333354

334355
Console.WriteLine("\n\nTESTS PASSED\n\n");
335356
System.GC.Collect();

0 commit comments

Comments
 (0)