From 531f4ca918de7ceaf1b6fb03c6846f184562d59c Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Wed, 3 Mar 2021 10:57:50 +1000 Subject: [PATCH] TokenMetadata: Add more validation test cases --- .../Cardano/Wallet/TokenMetadata/golden2.json | 12 +++++++ .../Cardano/Wallet/TokenMetadata/golden4.json | 30 ++++++++++++++-- .../unit/Cardano/Wallet/TokenMetadataSpec.hs | 35 ++++++++++++------- 3 files changed, 61 insertions(+), 16 deletions(-) diff --git a/lib/core/test/data/Cardano/Wallet/TokenMetadata/golden2.json b/lib/core/test/data/Cardano/Wallet/TokenMetadata/golden2.json index d64cb2eebcb..a508461ea09 100644 --- a/lib/core/test/data/Cardano/Wallet/TokenMetadata/golden2.json +++ b/lib/core/test/data/Cardano/Wallet/TokenMetadata/golden2.json @@ -83,6 +83,18 @@ "description": { "value": "description2" }, "ticker": { "value": "ticker2" }, "custom": { "value": "meta" } + }, + { + "subject": "unit with ticker", + "name": { "value": "Token3" }, + "description": { "value": "description3" }, + "unit": { + "value": { + "name": "BigToken3", + "decimals": 3, + "ticker": "tck3" + } + } } ] } diff --git a/lib/core/test/data/Cardano/Wallet/TokenMetadata/golden4.json b/lib/core/test/data/Cardano/Wallet/TokenMetadata/golden4.json index 35a4ef76154..c40636ab1bf 100644 --- a/lib/core/test/data/Cardano/Wallet/TokenMetadata/golden4.json +++ b/lib/core/test/data/Cardano/Wallet/TokenMetadata/golden4.json @@ -15,7 +15,7 @@ { "subject": "malformed unit - wrong type", "name": { - "value": "token9" + "value": "Token9" }, "description": { "value": "description9" @@ -27,7 +27,7 @@ { "subject": "malformed unit - name too long", "name": { - "value": "token10" + "value": "Token10" }, "description": { "value": "description10" @@ -42,7 +42,7 @@ { "subject": "malformed url - wrong scheme", "name": { - "value": "token11" + "value": "Token11" }, "description": { "value": "description11" @@ -50,6 +50,30 @@ "url": { "value": "javascript:window.alert('hello')" } + }, + { + "subject": "malformed ticker - too short", + "name": { + "value": "Token12" + }, + "description": { + "value": "description12" + }, + "ticker": { + "value": "x" + } + }, + { + "subject": "malformed ticker - too long", + "name": { + "value": "Token13" + }, + "description": { + "value": "description13" + }, + "ticker": { + "value": "ticker13" + } } ] } diff --git a/lib/core/test/unit/Cardano/Wallet/TokenMetadataSpec.hs b/lib/core/test/unit/Cardano/Wallet/TokenMetadataSpec.hs index 8ef4f58c155..fa437035501 100644 --- a/lib/core/test/unit/Cardano/Wallet/TokenMetadataSpec.hs +++ b/lib/core/test/unit/Cardano/Wallet/TokenMetadataSpec.hs @@ -39,7 +39,7 @@ import Data.Aeson import Data.Either ( isRight ) import Data.Maybe - ( isJust, isNothing ) + ( isNothing ) import Network.URI ( parseURI ) import System.FilePath @@ -55,44 +55,53 @@ spec :: Spec spec = do describe "JSON decoding" $ do describe "BatchResponse" $ do - it "golden1.json" $ do + it "golden1.json - Simple valid WKP" $ do decodeGoldenBatch golden1File `shouldReturn` golden1Properties - it "golden2.json" $ do + it "golden2.json - Valid WKP" $ do rs <- decodeGoldenBatch (dir "golden2.json") - length rs `shouldBe` 4 + length rs `shouldBe` 5 - it "golden3.json" $ do + it "golden3.json - Required WKP are invalid" $ do rs <- decodeGoldenBatch (dir "golden3.json") - rs `shouldNotBe` [] + length rs `shouldBe` 5 - it "golden4.json" $ do + it "golden4.json - Non-required WKP are invalid" $ do rs <- decodeGoldenBatch (dir "golden4.json") - rs `shouldNotBe` [] + length rs `shouldBe` 6 describe "metadataFromProperties" $ do - it "golden1.json" $ do + it "golden1.json - Simple valid WKP" $ do map metadataFromProperties golden1Properties `shouldBe` (Just <$> [golden1Metadata0,golden1Metadata1,golden1Metadata2]) - it "golden2.json" $ do + it "golden2.json - Valid WKP" $ do rs <- decodeGoldenBatch (dir "golden2.json") map metadataFromProperties rs `shouldBe` [ Just golden1Metadata0 , Just (AssetMetadata "Token1" "description1" (Just "tck1") Nothing Nothing Nothing) , Nothing , Just (AssetMetadata "Token2" "description2" Nothing Nothing Nothing Nothing) + , Just (AssetMetadata "Token3" "description3" Nothing Nothing Nothing (Just (AssetUnit "BigToken3" 3 (Just "tck3")))) ] - it "golden3.json" $ do + it "golden3.json - Required WKP are invalid" $ do rs <- decodeGoldenBatch (dir "golden3.json") rs `shouldNotBe` [] map metadataFromProperties rs `shouldSatisfy` all isNothing - it "golden4.json" $ do + it "golden4.json - Non-required WKP are invalid" $ do rs <- decodeGoldenBatch (dir "golden4.json") rs `shouldNotBe` [] - map metadataFromProperties rs `shouldSatisfy` all isJust + map metadataFromProperties rs `shouldBe` + map Just + [ AssetMetadata "Token7" "description7" Nothing Nothing Nothing Nothing + , AssetMetadata "Token9" "description9" Nothing Nothing Nothing Nothing + , AssetMetadata "Token10" "description10" Nothing Nothing Nothing Nothing + , AssetMetadata "Token11" "description11" Nothing Nothing Nothing Nothing + , AssetMetadata "Token12" "description12" Nothing Nothing Nothing Nothing + , AssetMetadata "Token13" "description13" Nothing Nothing Nothing Nothing + ] traceSpec $ describe "Using mock server" $ do it "testing empty req" $ \tr ->