Skip to content

Commit

Permalink
Fix IPV6 parser
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusbfs committed Feb 5, 2025
1 parent 5f963f1 commit 5c2d73f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Internal/QueryM/Ogmios/Types.purs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ parseIpv6String str = do
padded = String.replaceAll (Pattern " ") (Replacement "0") $ fold $
partsFixed
<#> StringUtils.padStart 4
decodeCbor <<< wrap =<< hexToByteArray padded
decodeCbor <<< wrap =<< hexToByteArray ("50" <> padded)

decodeRelay :: Aeson -> Either JsonDecodeError Relay
decodeRelay aeson = do
Expand Down
19 changes: 11 additions & 8 deletions test/Types/Ipv6.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,28 @@ import Prelude
import Cardano.AsCbor (decodeCbor)
import Ctl.Internal.QueryM.Ogmios.Types (parseIpv6String)
import Data.ByteArray (hexToByteArrayUnsafe)
import Data.Maybe (Maybe(Nothing))
import Data.Newtype (wrap)
import Effect.Aff (Aff)
import Mote (group, test)
import Mote.TestPlanM (TestPlanM)
import Test.Spec.Assertions (shouldEqual)
import Test.Spec.Assertions (shouldEqual, shouldNotEqual)

suite :: TestPlanM (Aff Unit) Unit
suite = do
group "Ipv6 type (parsing)" do
testIpv6 "2345:425:2CA1:0000:0000:567:5673:23b5"
"234504252CA1000000000567567323b5"
"50234504252CA1000000000567567323b5"
testIpv6 "2345:0425:2CA1:0:0:0567:5673:23b5"
"234504252CA1000000000567567323b5"
testIpv6 "2345:0425:2CA1::0567:5673:23b5" "234504252CA1000000000567567323b5"
testIpv6 "2345:0425:2CA1::5673:23b5" "234504252CA1000000000000567323b5"
testIpv6 "2345:0425:2CA1::23b5" "234504252CA1000000000000000023b5"
"50234504252CA1000000000567567323b5"
testIpv6 "2345:0425:2CA1::0567:5673:23b5"
"50234504252CA1000000000567567323b5"
testIpv6 "2345:0425:2CA1::5673:23b5" "50234504252CA1000000000000567323b5"
testIpv6 "2345:0425:2CA1::23b5" "50234504252CA1000000000000000023b5"

testIpv6 :: String -> String -> TestPlanM (Aff Unit) Unit
testIpv6 str expected =
test str do
parseIpv6String str `shouldEqual`
(decodeCbor (wrap $ hexToByteArrayUnsafe expected))
let ipv6 = parseIpv6String str
ipv6 `shouldNotEqual` Nothing
ipv6 `shouldEqual` (decodeCbor (wrap $ hexToByteArrayUnsafe expected))

0 comments on commit 5c2d73f

Please sign in to comment.