2019-09-24 01:45:33 +03:00
|
|
|
module NounConversionTests (tests) where
|
|
|
|
|
2019-09-25 00:01:39 +03:00
|
|
|
import Arvo.Event
|
2019-09-24 01:45:33 +03:00
|
|
|
import Noun.Conversions
|
|
|
|
import UrbitPrelude
|
|
|
|
|
2019-09-26 00:26:51 +03:00
|
|
|
import Data.Maybe
|
2019-09-25 00:01:39 +03:00
|
|
|
import Test.QuickCheck hiding ((.&.))
|
|
|
|
import Test.QuickCheck.Gen
|
|
|
|
import Test.QuickCheck.Random
|
2019-09-24 01:45:33 +03:00
|
|
|
import Test.Tasty
|
|
|
|
import Test.Tasty.QuickCheck
|
|
|
|
import Test.Tasty.TH
|
|
|
|
|
2019-09-26 00:26:51 +03:00
|
|
|
import qualified Crypto.Sign.Ed25519 as Ed
|
2019-09-25 00:01:39 +03:00
|
|
|
|
|
|
|
-- String Representations of Atoms ---------------------------------------------
|
|
|
|
|
2019-09-24 01:45:33 +03:00
|
|
|
instance Arbitrary UV where
|
|
|
|
arbitrary = UV <$> arbitrarySizedNatural
|
|
|
|
|
|
|
|
instance Arbitrary UW where
|
|
|
|
arbitrary = UW <$> arbitrarySizedNatural
|
|
|
|
|
|
|
|
vRoundTrip :: UV -> Bool
|
|
|
|
vRoundTrip uv = Just uv == (fromNoun $ toNoun $ uv)
|
|
|
|
|
|
|
|
wRoundTrip :: UW -> Bool
|
|
|
|
wRoundTrip uw = Just uw == (fromNoun $ toNoun uw)
|
|
|
|
|
2019-09-25 00:01:39 +03:00
|
|
|
-- Cryptographic Point Representations -----------------------------------------
|
|
|
|
|
2019-09-26 00:26:51 +03:00
|
|
|
data ThirtyTwoByteString = ThirtyTwoByteString ByteString
|
|
|
|
deriving (Show)
|
2019-09-25 00:01:39 +03:00
|
|
|
|
2019-09-26 00:26:51 +03:00
|
|
|
data KeyPair = KeyPair (Ed.PublicKey, Ed.SecretKey)
|
|
|
|
deriving (Show)
|
2019-09-25 00:01:39 +03:00
|
|
|
|
2019-09-26 00:26:51 +03:00
|
|
|
instance Arbitrary ThirtyTwoByteString where
|
|
|
|
arbitrary = (ThirtyTwoByteString . pack) <$> (vector 32)
|
2019-09-25 00:01:39 +03:00
|
|
|
|
2019-09-26 00:26:51 +03:00
|
|
|
instance Arbitrary KeyPair where
|
|
|
|
arbitrary =
|
|
|
|
(KeyPair . fromJust . Ed.createKeypairFromSeed_ . pack) <$> (vector 32)
|
|
|
|
|
|
|
|
|
|
|
|
passRoundTrip :: KeyPair -> KeyPair -> Bool
|
|
|
|
passRoundTrip (KeyPair (signPubkey, _)) (KeyPair (cryptPubkey, _)) =
|
|
|
|
(Just p) == (fromNoun $ toNoun p)
|
|
|
|
where
|
|
|
|
p = Pass signPubkey cryptPubkey
|
|
|
|
|
|
|
|
|
|
|
|
ringRoundTrip :: ThirtyTwoByteString -> ThirtyTwoByteString -> Bool
|
|
|
|
ringRoundTrip (ThirtyTwoByteString signSeed) (ThirtyTwoByteString cryptSeed) =
|
|
|
|
(Just r) == (fromNoun $ toNoun r)
|
|
|
|
where
|
|
|
|
r = Ring signSeed cryptSeed
|
2019-09-25 00:01:39 +03:00
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2019-09-24 01:45:33 +03:00
|
|
|
|
|
|
|
tests :: TestTree
|
|
|
|
tests =
|
|
|
|
testGroup "Noun"
|
|
|
|
[ testProperty "0v0 printing/parsing round trip" $ vRoundTrip
|
|
|
|
, testProperty "0w0 printing/parsing round trip" $ wRoundTrip
|
2019-09-25 00:01:39 +03:00
|
|
|
, testProperty "Pass round trip" $ passRoundTrip
|
2019-09-25 03:15:00 +03:00
|
|
|
, testProperty "Ring round trip" $ ringRoundTrip
|
2019-09-24 01:45:33 +03:00
|
|
|
]
|