commit c8797c8adce7a5e0ea120590c8222539800b7dfd
parent 2a99b5c9df493f27989383f9b0fef80fb78b0569
Author: Jared Tobin <jared@jtobin.io>
Date: Sat, 10 Oct 2026 13:35:04 +0400
test: add TLV length and unknown even type tests
Diffstat:
1 file changed, 32 insertions(+), 0 deletions(-)
diff --git a/test/Main.hs b/test/Main.hs
@@ -65,6 +65,7 @@ main = defaultMain $ testGroup "ppad-bolt4" [
]
, testGroup "TLV" [
tlvTests
+ , tlvRejectionTests
]
, testGroup "ShortChannelId" [
sciTests
@@ -206,6 +207,37 @@ tlvTests = testGroup "encoding/decoding" [
decoded @?= Just []
]
+tlvRejectionTests :: TestTree
+tlvRejectionTests = testGroup "rejection" [
+ testCase "length of 2^64 - 1" $ do
+ let huge = BS.pack (0xff : replicate 8 0xff)
+ decodeTlv (BS.singleton 0x01 <> huge <> BS.pack [0xaa, 0xbb])
+ @?= Nothing
+ decodeTlvStream (BS.singleton 0x01 <> huge <> BS.pack [0x03, 0x00])
+ @?= Nothing
+ decodeHopPayload
+ (BS.singleton 0x02 <> huge <> BS.pack [0x04, 0x01, 0x07])
+ @?= Nothing
+ , testCase "hop payload: unknown even type" $
+ decodeHopPayload (BS.pack [0x02, 0x01, 0x05, 0x0e, 0x01, 0x07])
+ @?= Nothing
+ , testCase "hop payload: unknown odd type is kept" $
+ fmap hpUnknownTlvs
+ (decodeHopPayload (BS.pack [0x02, 0x01, 0x05, 0x0f, 0x01, 0x07]))
+ @?= Just [TlvRecord 15 (BS.singleton 0x07)]
+ , testCase "hop payload: types 16 and 18 are accepted" $
+ fmap hpUnknownTlvs
+ (decodeHopPayload (BS.pack [0x10, 0x01, 0x01, 0x12, 0x01, 0x02]))
+ @?= Just [ TlvRecord 16 (BS.singleton 0x01)
+ , TlvRecord 18 (BS.singleton 0x02) ]
+ , testCase "blinded hop data: unknown even type" $
+ decodeBlindedHopData (BS.pack [0x10, 0x01, 0x00]) @?= Nothing
+ , testCase "blinded hop data: unknown odd type is skipped" $
+ decodeBlindedHopData (BS.pack [0x06, 0x01, 0x2a, 0xfd, 0x02, 0x31,
+ 0x01, 0x00])
+ @?= Just emptyHopData { bhdPathId = Just (BS.singleton 0x2a) }
+ ]
+
-- ShortChannelId tests -----------------------------------------------------
sciTests :: TestTree