From 17a69d5fc4ca18189c957012f3be3f1e15c690e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Kihlberg?= Date: Fri, 17 Mar 2023 14:44:40 +0100 Subject: [PATCH] fix ze boogs --- .../Marlowe/Runtime/Transaction/ApiSpec.hs | 29 +++++++++++++++++-- .../Marlowe/Runtime/Transaction/Api.hs | 2 +- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/marlowe-runtime/test/Language/Marlowe/Runtime/Transaction/ApiSpec.hs b/marlowe-runtime/test/Language/Marlowe/Runtime/Transaction/ApiSpec.hs index cd8fa97b7d..fff62f71ec 100644 --- a/marlowe-runtime/test/Language/Marlowe/Runtime/Transaction/ApiSpec.hs +++ b/marlowe-runtime/test/Language/Marlowe/Runtime/Transaction/ApiSpec.hs @@ -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 [])])] @@ -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 @@ -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 diff --git a/marlowe-runtime/tx-api/Language/Marlowe/Runtime/Transaction/Api.hs b/marlowe-runtime/tx-api/Language/Marlowe/Runtime/Transaction/Api.hs index ce28d38eb6..0668d2d27c 100644 --- a/marlowe-runtime/tx-api/Language/Marlowe/Runtime/Transaction/Api.hs +++ b/marlowe-runtime/tx-api/Language/Marlowe/Runtime/Transaction/Api.hs @@ -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