Skip to content

Commit

Permalink
Unit test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sevanspowell committed May 25, 2022
1 parent b4d19ac commit b49eba9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
18 changes: 16 additions & 2 deletions test/Test/Cardano/Catalyst/Registration.hs
Expand Up @@ -9,6 +9,8 @@ import qualified Cardano.Crypto.DSIGN.Class as Crypto
import qualified Data.Aeson as Aeson
import qualified Data.ByteString.Base16 as Base16
import qualified Data.HashMap.Strict as HM
import qualified Data.List.NonEmpty as NE
import qualified Data.Vector as Vector
import Data.List (sort)
import qualified Data.Text.Encoding as T
import Hedgehog (property, tripping, (===))
Expand Down Expand Up @@ -76,15 +78,27 @@ prop_vote_serialized_format = H.property $ do

let
sig = ("0x" <>) . T.decodeUtf8 . Base16.encode . Crypto.rawSerialiseSigDSIGN . voteSignature $ vote
votePub = ("0x" <>) . T.decodeUtf8 . Api.serialiseToRawBytesHex . voteRegistrationPublicKey $ vote
votePubJSON = Aeson.String . ("0x" <>) . T.decodeUtf8 . Api.serialiseToRawBytesHex
delegations =
case voteRegistrationDelegations vote of
LegacyDelegation votePub -> votePubJSON votePub
Delegations weights ->
Aeson.Array
$ Vector.fromList $ NE.toList
$ fmap (\(votePub, weight) ->
Aeson.Array
$ Vector.fromList
$ [votePubJSON votePub, Aeson.Number $ fromIntegral weight]
)
$ weights
verKey = ("0x" <>) . T.decodeUtf8 . Api.serialiseToRawBytesHex . voteRegistrationVerificationKey $ vote
rewardsAddr = ("0x" <>) . T.decodeUtf8 . Api.serialiseToRawBytesHex . voteRegistrationRewardsAddress $ vote
slotNo = fromIntegral . voteRegistrationSlot $ vote

expectedJSON = Aeson.Object $ HM.fromList
[ ( "61285", Aeson.Object $ HM.fromList [ ("1", Aeson.String sig) ] )
, ( "61284", Aeson.Object $ HM.fromList
[ ("1", Aeson.String votePub)
[ ("1", delegations)
, ("2", Aeson.String verKey)
, ("3", Aeson.String rewardsAddr)
, ("4", Aeson.Number slotNo)
Expand Down
1 change: 1 addition & 0 deletions voting-tools.cabal
Expand Up @@ -136,6 +136,7 @@ test-suite unit-tests
, tasty-hedgehog
, base16-bytestring
, unordered-containers
, vector
, voting-tools
, cardano-crypto-class

Expand Down

0 comments on commit b49eba9

Please sign in to comment.