Compare commits
No commits in common. "db5a694e7d15e1e423864aad8240f6ef61684cae" and "47e3cf71cbace77b592906f086174af176b09191" have entirely different histories.
db5a694e7d
...
47e3cf71cb
3 changed files with 12 additions and 51 deletions
|
@ -81,7 +81,6 @@ data CoinType
|
||||||
= MainNetCoin
|
= MainNetCoin
|
||||||
| TestNetCoin
|
| TestNetCoin
|
||||||
| RegTestNetCoin
|
| RegTestNetCoin
|
||||||
deriving (Eq, Prelude.Show, Ord)
|
|
||||||
|
|
||||||
getValue :: CoinType -> Word32
|
getValue :: CoinType -> Word32
|
||||||
getValue c =
|
getValue c =
|
||||||
|
|
60
test/Spec.hs
60
test/Spec.hs
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
-}
|
-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE TypeSynonymInstances #-}
|
|
||||||
|
|
||||||
import C.Zcash (rustWrapperUADecode)
|
import C.Zcash (rustWrapperUADecode)
|
||||||
import Control.Monad.IO.Class (liftIO)
|
import Control.Monad.IO.Class (liftIO)
|
||||||
|
@ -35,8 +34,6 @@ import qualified Data.Text.Lazy.IO as LTIO
|
||||||
import Data.Word
|
import Data.Word
|
||||||
import GHC.Float.RealFracMethods (properFractionDoubleInteger)
|
import GHC.Float.RealFracMethods (properFractionDoubleInteger)
|
||||||
import Test.Hspec
|
import Test.Hspec
|
||||||
import Test.Hspec.QuickCheck
|
|
||||||
import Test.QuickCheck
|
|
||||||
import ZcashHaskell.Keys (generateWalletSeedPhrase, getWalletSeed)
|
import ZcashHaskell.Keys (generateWalletSeedPhrase, getWalletSeed)
|
||||||
import ZcashHaskell.Orchard
|
import ZcashHaskell.Orchard
|
||||||
import ZcashHaskell.Sapling
|
import ZcashHaskell.Sapling
|
||||||
|
@ -52,7 +49,6 @@ import ZcashHaskell.Types
|
||||||
, CoinType(..)
|
, CoinType(..)
|
||||||
, DecodedNote(..)
|
, DecodedNote(..)
|
||||||
, OrchardAction(..)
|
, OrchardAction(..)
|
||||||
, Phrase(..)
|
|
||||||
, RawData(..)
|
, RawData(..)
|
||||||
, RawTxResponse(..)
|
, RawTxResponse(..)
|
||||||
, ShieldedOutput(..)
|
, ShieldedOutput(..)
|
||||||
|
@ -452,12 +448,18 @@ main = do
|
||||||
msg `shouldBe`
|
msg `shouldBe`
|
||||||
"Hello World!\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL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UL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL"
|
||||||
describe "Wallet seed phrase" $ do
|
describe "Wallet seed phrase" $ do
|
||||||
prop "Generated phrases are valid" prop_PhraseLength
|
it "Generate phrase" $ do
|
||||||
prop "Derived seeds are valid" prop_SeedLength
|
p <- generateWalletSeedPhrase
|
||||||
prop "Orchard spending keys are valid" $
|
BS.length p `shouldNotBe` 0
|
||||||
forAll genOrcArgs $ \(c, i, _) -> prop_OrchardSpendingKey c i
|
it "Derive seed" $ do
|
||||||
prop "Orchard receivers are valid" $
|
p <- generateWalletSeedPhrase
|
||||||
forAll genOrcArgs $ \(c, i, j) -> prop_OrchardReceiver c i j
|
let s = getWalletSeed p
|
||||||
|
maybe 0 BS.length s `shouldBe` 64
|
||||||
|
it "Generate Orchard spending key" $ do
|
||||||
|
p <- generateWalletSeedPhrase
|
||||||
|
let s = getWalletSeed p
|
||||||
|
genOrchardSpendingKey (fromMaybe "" s) MainNetCoin 1 `shouldNotBe`
|
||||||
|
Nothing
|
||||||
describe "Address tests" $ do
|
describe "Address tests" $ do
|
||||||
it "Encode transparent" $ do
|
it "Encode transparent" $ do
|
||||||
let ua =
|
let ua =
|
||||||
|
@ -467,41 +469,3 @@ main = do
|
||||||
Nothing -> "Bad UA"
|
Nothing -> "Bad UA"
|
||||||
Just u -> maybe "No transparent" encodeTransparent $ t_rec u
|
Just u -> maybe "No transparent" encodeTransparent $ t_rec u
|
||||||
msg `shouldBe` "t1LPWuQnjCRH7JAeEErSXKixcUteLJRJjKD"
|
msg `shouldBe` "t1LPWuQnjCRH7JAeEErSXKixcUteLJRJjKD"
|
||||||
|
|
||||||
-- | Properties
|
|
||||||
prop_PhraseLength :: Int -> Property
|
|
||||||
prop_PhraseLength i =
|
|
||||||
ioProperty $ do
|
|
||||||
p <- generateWalletSeedPhrase
|
|
||||||
return $ BS.length p >= 95
|
|
||||||
|
|
||||||
prop_SeedLength :: Int -> Property
|
|
||||||
prop_SeedLength i =
|
|
||||||
ioProperty $ do
|
|
||||||
p <- generateWalletSeedPhrase
|
|
||||||
let s = getWalletSeed p
|
|
||||||
return $ maybe 0 BS.length s === 64
|
|
||||||
|
|
||||||
prop_OrchardSpendingKey :: CoinType -> Int -> Property
|
|
||||||
prop_OrchardSpendingKey c i =
|
|
||||||
ioProperty $ do
|
|
||||||
p <- generateWalletSeedPhrase
|
|
||||||
let s = getWalletSeed p
|
|
||||||
return $ genOrchardSpendingKey (fromMaybe "" s) c i =/= Nothing
|
|
||||||
|
|
||||||
prop_OrchardReceiver :: CoinType -> Int -> Int -> Property
|
|
||||||
prop_OrchardReceiver c i j =
|
|
||||||
ioProperty $ do
|
|
||||||
p <- generateWalletSeedPhrase
|
|
||||||
let s = getWalletSeed p
|
|
||||||
let sk = genOrchardSpendingKey (fromMaybe "" s) c i
|
|
||||||
return $ genOrchardReceiver j (fromMaybe "" sk) =/= Nothing
|
|
||||||
|
|
||||||
-- | Generators
|
|
||||||
genOrcArgs :: Gen (CoinType, Int, Int)
|
|
||||||
genOrcArgs = do
|
|
||||||
i <- arbitrarySizedNatural
|
|
||||||
j <- arbitrarySizedNatural
|
|
||||||
c <- elements [MainNetCoin, TestNetCoin, RegTestNetCoin]
|
|
||||||
return (c, i, j)
|
|
||||||
-- | Arbitrary instances
|
|
||||||
|
|
|
@ -72,8 +72,6 @@ test-suite zcash-haskell-test
|
||||||
, haskoin-core
|
, haskoin-core
|
||||||
, hexstring
|
, hexstring
|
||||||
, hspec
|
, hspec
|
||||||
, QuickCheck
|
|
||||||
, quickcheck-transformer
|
|
||||||
, text
|
, text
|
||||||
, zcash-haskell
|
, zcash-haskell
|
||||||
pkgconfig-depends: rustzcash_wrapper
|
pkgconfig-depends: rustzcash_wrapper
|
||||||
|
|
Loading…
Reference in a new issue