Skip to content

Commit

Permalink
generator quality
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornkihlberg committed Mar 27, 2023
1 parent 4c8a527 commit b7acb2b
Showing 1 changed file with 22 additions and 14 deletions.
Expand Up @@ -56,31 +56,39 @@ base16EncodedTextGen n = fromString <$> Gen.vectorOf n (Gen.elements $ ['0' .. '

cip25MetadataCompletenessTests :: Gen.Property
cip25MetadataCompletenessTests = Gen.checkCoverage $
Gen.forAll cip25MetadataJSONRelationGen \(md@(CIP25Metadata policyIds), json) ->
Gen.cover 1.0 (null policyIds) "no policies" do
Gen.forAll cip25MetadataJSONRelationGen \(md@(CIP25Metadata policies), json) ->
Gen.cover 1.0 (Maybe.isJust $ find null policies) "some policy with no token" $
Gen.cover 60.0 (Maybe.isJust $ find (not . null) policies) "some policy with some token" $
Gen.cover 60.0 (not $ null policies) "some policies" $
Gen.cover 1.0 (null policies) "no policies" do
let document = Aeson.encode json
Aeson.encode md `shouldBe` document
-- fmap show (Aeson.decode @CIP25Metadata document) `shouldBe` Just (show md)
where
cip25MetadataJSONRelationGen :: Gen (CIP25Metadata, Aeson.Value)
cip25MetadataJSONRelationGen = do
let emptyGen = pure []
nonemptyGen = do
n <- Gen.chooseInt (1, 8)
Gen.vectorOf n do
(policyId, policyIdJSON) <- policyIdJSONKeyRelationGen
(tokenMetadata, tokenMetadataJSON) <- tokenMetadataJSONRelationGen
pure ((policyId, tokenMetadata), (policyIdJSON, tokenMetadataJSON))
(Map.fromList -> metadata, Aeson.Object . Aeson.KeyMap.fromList -> json) <-
fmap unzip $ Gen.frequency [(1, pure []), (9, do
n <- Gen.chooseInt (1, 10)
Gen.vectorOf n do
(policyId, policyIdJSON) <- policyIdJSONKeyRelationGen
(tokenMetadata, tokenMetadataJSON) <- tokenMetadataJSONRelationGen
pure ((policyId, tokenMetadata), (policyIdJSON, tokenMetadataJSON)))]
unzip <$> Gen.frequency [(1, emptyGen), (9, nonemptyGen)]
pure (CIP25Metadata metadata, Aeson.Object [("721", json)])

tokenMetadataJSONRelationGen :: Gen (Map TokenName CIP25MetadataDetails, Aeson.Value)
tokenMetadataJSONRelationGen = do
(Map.fromList *** Aeson.Object . Aeson.KeyMap.fromList) . unzip <$> do
n <- Gen.chooseInt (1, 10)
Gen.vectorOf n do
(tokenName, tokenNameJSON) <- tokenNameJSONKeyRelationGen
(metadataDetails, metadataDetailsJSON) <- cip25MetadataDetailsJSONRelationGen
pure ((tokenName, metadataDetails), (tokenNameJSON, metadataDetailsJSON))
let emptyGen = pure []
nonEmptyGen = do
n <- Gen.chooseInt (1, 8)
Gen.vectorOf n do
(tokenName, tokenNameJSON) <- tokenNameJSONKeyRelationGen
(metadataDetails, metadataDetailsJSON) <- cip25MetadataDetailsJSONRelationGen
pure ((tokenName, metadataDetails), (tokenNameJSON, metadataDetailsJSON))
(Map.fromList *** Aeson.Object . Aeson.KeyMap.fromList) .
unzip <$> Gen.frequency [(1, emptyGen),(9, nonEmptyGen)]

policyIdJSONKeyRelationGen :: Gen (PolicyId, Aeson.Key)
policyIdJSONKeyRelationGen =
Expand Down

0 comments on commit b7acb2b

Please sign in to comment.