Skip to content

Commit

Permalink
fix ze boogs
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornkihlberg committed Mar 17, 2023
1 parent 3f11afd commit 17a69d5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Expand Up @@ -38,7 +38,7 @@ spec = do
version1 <- version1Gen
let input :: BL.ByteString
input = Aeson.encode $
Aeson.Object [("721", Aeson.Object $
Aeson.Object [("721", Aeson.Object
if Maybe.isJust version1
then [("53756e", Aeson.Object []), ("version", Aeson.Number 1)]
else [("53756e", Aeson.Object [])])]
Expand All @@ -47,7 +47,19 @@ spec = do
expected :: Either String CIP25Metadata
expected = Right $ CIP25Metadata $ CIP25MetadataLabel [("53756e", [])] version1
pure $ actual `shouldBe` expected
it "Serializes PolicyId as UTF-8 string" Hspec.pending
prop "Serializes PolicyId as UTF-8 string" do
version1 <- version1Gen
let input :: CIP25Metadata
input = CIP25Metadata $ CIP25MetadataLabel [("53756e", [])] version1
actual :: BL.ByteString
actual = Aeson.encode input
expected :: BL.ByteString
expected = Aeson.encode $
Aeson.Object [("721", Aeson.Object
if Maybe.isJust version1
then [("53756e", Aeson.Object []), ("version", Aeson.Number 1)]
else [("53756e", Aeson.Object [])])]
pure $ actual `shouldBe` expected
it "Parses TokenName as UTF-8 string" Hspec.pending
it "Serializes TokenName as UTF-8 string" Hspec.pending
it "Interprets lack of version as version 1" Hspec.pending
Expand All @@ -67,7 +79,18 @@ spec = do
expected :: Either String CIP25Metadata
expected = Right $ CIP25Metadata $ CIP25MetadataLabel [("53756e", [])] (Just 2)
actual `shouldBe` expected
it "Serializes PolicyId as raw byte string" Hspec.pending
it "Serializes PolicyId as raw byte string" do
let input :: CIP25Metadata
input = CIP25Metadata $ CIP25MetadataLabel [("53756e", [])] (Just 2)
actual :: BL.ByteString
actual = Aeson.encode input
expected :: BL.ByteString
expected = Aeson.encode $
Aeson.Object [("721", Aeson.Object
[ ("Sun", Aeson.Object [])
, ("version", Aeson.Number 2)
])]
actual `shouldBe` expected
it "Parses TokenName as raw byte string" Hspec.pending
it "Serializes TokenName as raw byte string" Hspec.pending
it "Interprets version 2 as version 2" Hspec.pending
Expand Down
Expand Up @@ -168,7 +168,7 @@ instance Aeson.ToJSON CIP25MetadataLabel where
CIP25MetadataLabel {version = Nothing, policyIds} -> toJSON policyIds
CIP25MetadataLabel {version = Just 1, policyIds = toJSON -> Aeson.Object policyIds} ->
Aeson.Object (policyIds <> [("version", Aeson.Number 1)])
CIP25MetadataLabel {version = Just 2, policyIds = toJSON -> Aeson.Object policyIds} ->
CIP25MetadataLabel {version = Just 2, policyIds = toJSON . Map.mapKeys (BS.unpack . coerce) -> Aeson.Object policyIds} ->
Aeson.Object (policyIds <> [("version", Aeson.Number 2)])
CIP25MetadataLabel {version = Just n} -> error $ "Unknown version " <> show n

Expand Down

0 comments on commit 17a69d5

Please sign in to comment.