Skip to content

Commit

Permalink
TokenMetadata: Add more validation test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed Mar 3, 2021
1 parent 99c5c96 commit d7344e8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 16 deletions.
12 changes: 12 additions & 0 deletions lib/core/test/data/Cardano/Wallet/TokenMetadata/golden2.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
]
}
30 changes: 27 additions & 3 deletions lib/core/test/data/Cardano/Wallet/TokenMetadata/golden4.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{
"subject": "malformed unit - wrong type",
"name": {
"value": "token9"
"value": "Token9"
},
"description": {
"value": "description9"
Expand All @@ -27,7 +27,7 @@
{
"subject": "malformed unit - name too long",
"name": {
"value": "token10"
"value": "Token10"
},
"description": {
"value": "description10"
Expand All @@ -42,14 +42,38 @@
{
"subject": "malformed url - wrong scheme",
"name": {
"value": "token11"
"value": "Token11"
},
"description": {
"value": "description11"
},
"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"
}
}
]
}
35 changes: 22 additions & 13 deletions lib/core/test/unit/Cardano/Wallet/TokenMetadataSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import Data.Aeson
import Data.Either
( isRight )
import Data.Maybe
( isJust, isNothing )
( isNothing )
import Network.URI
( parseURI )
import System.FilePath
Expand All @@ -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 ->
Expand Down

0 comments on commit d7344e8

Please sign in to comment.