]> Git — Sourcephile - majurity.git/blob - hjugement-protocol/tests/HUnit/FFC.hs
cli: admin: directly use election_hash
[majurity.git] / hjugement-protocol / tests / HUnit / FFC.hs
1 {-# LANGUAGE OverloadedStrings #-}
2 module HUnit.FFC where
3
4 import GHC.Natural (minusNaturalMaybe)
5 import Data.Maybe (fromJust)
6 import Test.Tasty.HUnit
7 import Voting.Protocol
8 import Utils
9 import qualified Data.Text as Text
10
11 hunit :: Reifies v Version => Proxy v -> TestTree
12 hunit _v = testGroup "FFC"
13 [ testGroup "inverse"
14 [ hunitInv weakFFC
15 , hunitInv beleniosFFC
16 ]
17 , testGroup "hash"
18 [ testGroup "WeakParams" $
19 reify weakFFC $ \(Proxy::Proxy c) ->
20 [ testCase "[groupGen]" $
21 hash "start" [groupGen :: G FFC c] @?=
22 fromNatural 62
23 , testCase "[groupGen, groupGen]" $
24 hash "start" [groupGen :: G FFC c, groupGen] @?=
25 fromNatural 31
26 ]
27 , testGroup "BeleniosParams" $
28 reify beleniosFFC $ \(Proxy::Proxy c) ->
29 [ testCase "[groupGen]" $
30 hash "start" [groupGen :: G FFC c] @?=
31 fromNatural 75778590284190557660612328423573274641033882642784670156837892421285248292707
32 , testCase "[groupGen, groupGen]" $
33 hash "start" [groupGen :: G FFC c, groupGen] @?=
34 fromNatural 28798937720387703653439047952832768487958170248947132321730024269734141660223
35 ]
36 ]
37 ]
38
39 hunitInv ::
40 forall crypto.
41 ReifyCrypto crypto => Key crypto =>
42 crypto -> TestTree
43 hunitInv crypto =
44 testGroup (Text.unpack $ cryptoName crypto)
45 [ testCase "groupGen" $
46 reifyCrypto crypto $ \(_c::Proxy c) ->
47 inverse (groupGen :: G crypto c) @?=
48 groupGen ^ E (fromJust $ groupOrder (Proxy @c) `minusNaturalMaybe` one)
49 ]