mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-19 04:41:37 +03:00
676a8ee6a6
This changes Pass to decode the Ed.Point directly in the type, instead of having the packed Atom representation or raw ByteStrings. Added conversion quickchecks and also decoded data off the Ethereum contracts.
59 lines
1.6 KiB
Haskell
59 lines
1.6 KiB
Haskell
module NounConversionTests (tests) where
|
|
|
|
import Arvo.Event
|
|
import Noun.Conversions
|
|
import UrbitPrelude
|
|
|
|
import Crypto.Random.Types
|
|
import Test.QuickCheck hiding ((.&.))
|
|
import Test.QuickCheck.Gen
|
|
import Test.QuickCheck.Random
|
|
import Test.Tasty
|
|
import Test.Tasty.QuickCheck
|
|
import Test.Tasty.TH
|
|
|
|
import qualified Crypto.ECC.Edwards25519 as Ed
|
|
import qualified Crypto.Error as Ed
|
|
import qualified Data.ByteArray as BA
|
|
|
|
-- String Representations of Atoms ---------------------------------------------
|
|
|
|
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)
|
|
|
|
-- Cryptographic Point Representations -----------------------------------------
|
|
|
|
instance Crypto.Random.Types.MonadRandom Gen where
|
|
getRandomBytes size = BA.pack <$> vector size
|
|
|
|
instance Arbitrary Ed.Point where
|
|
arbitrary = Ed.toPoint <$> Ed.scalarGenerate
|
|
|
|
instance Arbitrary Ed.Scalar where
|
|
arbitrary = Ed.scalarGenerate
|
|
|
|
passRoundTrip :: Ed.Point -> Ed.Point -> Bool
|
|
passRoundTrip crypt sign =
|
|
Just val == (fromNoun $ toNoun val)
|
|
where val = (Pass2 crypt sign)
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
tests :: TestTree
|
|
tests =
|
|
testGroup "Noun"
|
|
[ testProperty "0v0 printing/parsing round trip" $ vRoundTrip
|
|
, testProperty "0w0 printing/parsing round trip" $ wRoundTrip
|
|
, testProperty "Pass round trip" $ passRoundTrip
|
|
]
|