]> Git — Sourcephile - majurity.git/blob - hjugement-protocol/tests/HUnit/Credential.hs
protocol: bump versions
[majurity.git] / hjugement-protocol / tests / HUnit / Credential.hs
1 {-# LANGUAGE OverloadedStrings #-}
2 module HUnit.Credential where
3
4 import Test.Tasty.HUnit
5 import qualified Control.Monad.Trans.State.Strict as S
6 import qualified System.Random as Random
7
8 import Voting.Protocol
9 import Utils
10
11 hunit :: TestTree
12 hunit = testGroup "Credential"
13 [ testGroup "randomCredential"
14 [ testCase "0" $
15 S.evalState randomCredential (Random.mkStdGen 0) @?=
16 Credential "xLcs7ev6Jy6FHHE"
17 ]
18 , testGroup "randomUUID"
19 [ testCase "0" $
20 S.evalState randomUUID (Random.mkStdGen 0) @?=
21 UUID "xLcs7ev6Jy6FHH"
22 ]
23 , testGroup "readCredential" $
24 let (==>) inp exp =
25 testCase (show inp) $ readCredential inp @?= exp in
26 [ "" ==> Left ErrorToken_Length
27 , "xLcs7ev6Jy6FH_E" ==> Left (ErrorToken_BadChar '_')
28 , "xLcs7ev6Jy6FHIE" ==> Left (ErrorToken_BadChar 'I')
29 , "xLcs7ev6Jy6FH0E" ==> Left (ErrorToken_BadChar '0')
30 , "xLcs7ev6Jy6FHOE" ==> Left (ErrorToken_BadChar 'O')
31 , "xLcs7ev6Jy6FHlE" ==> Left (ErrorToken_BadChar 'l')
32 , "xLcs7ev6Jy6FH6" ==> Left ErrorToken_Length
33 , "xLcs7ev6Jy6FHHy1" ==> Left ErrorToken_Length
34 , "xLcs7ev6Jy6FHHF" ==> Left ErrorToken_Checksum
35 , "xLcs7ev6Jy6FHHE" ==> Right (Credential "xLcs7ev6Jy6FHHE")
36 ]
37 , testGroup "credentialSecretKey" $
38 [ testSecretKey beleniosFFC
39 (UUID "xLcs7ev6Jy6FHH")
40 (Credential "xLcs7ev6Jy6FHHE")
41 24202898752499029126606335829564687069186982035759723128887013101942425902424
42 ]
43 ]
44
45 testSecretKey :: FFC -> UUID -> Credential -> Natural -> TestTree
46 testSecretKey ffc uuid cred exp =
47 reify ffc $ \(Proxy::Proxy c) ->
48 testCase (show (uuid,cred)) $
49 credentialSecretKey @c uuid cred @?= E exp