commit 86c66400e8ebc0b5413e077a726008a59a16aa90
parent 7db453176af2081e20de3aaca61886af22852d96
Author: Jared Tobin <jared@jtobin.io>
Date: Mon, 20 Apr 2026 15:55:23 +0800
test: add property tests
Add 4 property tests:
- ChannelFlags encode/decode roundtrip
- ShortChannelId scidFromBytes/scidToBytes roundtrip
- Hostname validates length bounds (1-255)
- SCID list encode/decode roundtrip
Diffstat:
| M | test/Main.hs | | | 58 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 58 insertions(+), 0 deletions(-)
diff --git a/test/Main.hs b/test/Main.hs
@@ -615,6 +615,14 @@ property_tests = testGroup "Properties" [
propAnnouncementSignaturesRoundtrip
, testProperty "GossipTimestampFilter roundtrip"
propGossipTimestampFilterRoundtrip
+ , testProperty "ChannelFlags encode/decode roundtrip"
+ propChannelFlagsRoundtrip
+ , testProperty "ShortChannelId bytes roundtrip"
+ propScidBytesRoundtrip
+ , testProperty "Hostname validates length bounds"
+ propHostnameValidation
+ , testProperty "SCID list encode/decode roundtrip"
+ propScidListRoundtrip
]
-- Property: ChannelAnnouncement roundtrip
@@ -686,3 +694,53 @@ propGossipTimestampFilterRoundtrip firstTs tsRange = property $ do
case decodeGossipTimestampFilter encoded of
Right (decoded, _) -> decoded == msg
Left _ -> False
+
+-- Property: ChannelFlags encode/decode roundtrip
+propChannelFlagsRoundtrip :: Property
+propChannelFlagsRoundtrip =
+ forAll genChannelFlags $ \cf ->
+ decodeChannelFlags (encodeChannelFlags cf) == cf
+ where
+ genChannelFlags :: Gen ChannelFlags
+ genChannelFlags = ChannelFlags
+ <$> elements [NodeOne, NodeTwo]
+ <*> elements [Enabled, Disabled]
+
+-- Property: ShortChannelId bytes roundtrip
+propScidBytesRoundtrip :: Property
+propScidBytesRoundtrip =
+ forAll (choose (0, 0xFFFFFF)) $ \bh ->
+ forAll (choose (0, 0xFFFFFF)) $ \ti ->
+ forAll arbitrary $ \oi ->
+ case shortChannelId bh ti oi of
+ Nothing -> False
+ Just scid ->
+ scidFromBytes (scidToBytes scid)
+ == Just scid
+
+-- Property: Hostname validates length bounds
+propHostnameValidation :: NonNegative Int -> Property
+propHostnameValidation (NonNegative n) = property $
+ let len = n `mod` 300
+ bs = BS.replicate len 0x61
+ in case hostname bs of
+ Just _ -> len >= 1 && len <= 255
+ Nothing -> len == 0 || len > 255
+
+-- Property: SCID list encode/decode roundtrip
+propScidListRoundtrip :: Property
+propScidListRoundtrip =
+ forAll (listOf genScid) $ \scids ->
+ case decodeShortChannelIdList
+ (encodeShortChannelIdList scids) of
+ Right decoded -> decoded == scids
+ Left _ -> False
+ where
+ genScid :: Gen ShortChannelId
+ genScid = do
+ bh <- choose (0, 0xFFFFFF)
+ ti <- choose (0, 0xFFFFFF)
+ oi <- arbitrary
+ case shortChannelId bh ti oi of
+ Just s -> pure s
+ Nothing -> pure testShortChannelId