Skip to content

Commit

Permalink
policy id parsing for cip-25 v1 is correct
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornkihlberg committed Mar 24, 2023
1 parent 1e4d87d commit 09731a2
Showing 1 changed file with 20 additions and 1 deletion.
Expand Up @@ -8,8 +8,12 @@ import Language.Marlowe.Runtime.Transaction.Api (CIP25Metadata(..), CIP25Metadat

import qualified Data.Aeson as Aeson
import qualified Data.ByteString.Lazy.Char8 as BL
import qualified Data.Maybe as Maybe
import Test.Hspec (Spec, it, shouldBe)
import qualified Test.Hspec as Hspec
import Test.Hspec.QuickCheck (prop)
import Test.QuickCheck (Gen)
import qualified Test.QuickCheck as Gen

{-
DOING Ensure CIP-25 version 2 is supported
Expand All @@ -23,11 +27,26 @@ TODO CIP25Metadata -> Metadata procedure
TODO Reorganizes strings into lists of strings such that they are each no longer than 64 characters long
-}

version1Gen :: Gen (Maybe Int)
version1Gen = Gen.elements [Nothing, Just 1]

spec :: Spec
spec = do
Hspec.fdescribe "CIP-25 Metadata" do
Hspec.describe "version 1" do
it "Parses PolicyId as UTF-8 string" Hspec.pending
prop "Parses PolicyId as UTF-8 string" do
version1 <- version1Gen
let input :: BL.ByteString
input = Aeson.encode $
Aeson.Object [("721", Aeson.Object $
if Maybe.isJust version1
then [("53756e", Aeson.Object []), ("version", Aeson.Number 1)]
else [("53756e", Aeson.Object [])])]
actual :: Either String CIP25Metadata
actual = Aeson.eitherDecode' input
expected :: Either String CIP25Metadata
expected = Right $ CIP25Metadata $ CIP25MetadataLabel [("53756e", [])] version1
pure $ actual `shouldBe` expected
it "Serializes PolicyId as UTF-8 string" Hspec.pending
it "Parses TokenName as UTF-8 string" Hspec.pending
it "Serializes TokenName as UTF-8 string" Hspec.pending
Expand Down

0 comments on commit 09731a2

Please sign in to comment.