|
|
@ -20,6 +20,7 @@
|
|
|
|
{-# LANGUAGE TypeSynonymInstances #-}
|
|
|
|
{-# LANGUAGE TypeSynonymInstances #-}
|
|
|
|
|
|
|
|
|
|
|
|
import C.Zcash (rustWrapperUADecode)
|
|
|
|
import C.Zcash (rustWrapperUADecode)
|
|
|
|
|
|
|
|
import Control.Exception (throwIO)
|
|
|
|
import Control.Monad.IO.Class (liftIO)
|
|
|
|
import Control.Monad.IO.Class (liftIO)
|
|
|
|
import Data.Aeson
|
|
|
|
import Data.Aeson
|
|
|
|
import Data.Bool (Bool(True))
|
|
|
|
import Data.Bool (Bool(True))
|
|
|
@ -61,6 +62,7 @@ import ZcashHaskell.Types
|
|
|
|
, Phrase(..)
|
|
|
|
, Phrase(..)
|
|
|
|
, RawData(..)
|
|
|
|
, RawData(..)
|
|
|
|
, RawTxResponse(..)
|
|
|
|
, RawTxResponse(..)
|
|
|
|
|
|
|
|
, Seed(..)
|
|
|
|
, ShieldedOutput(..)
|
|
|
|
, ShieldedOutput(..)
|
|
|
|
, UnifiedAddress(..)
|
|
|
|
, UnifiedAddress(..)
|
|
|
|
, UnifiedFullViewingKey(..)
|
|
|
|
, UnifiedFullViewingKey(..)
|
|
|
@ -466,12 +468,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\N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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\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"
|
|
|
|
describe "Wallet seed phrase" $ do
|
|
|
|
describe "Wallet seed phrase" $ do
|
|
|
|
prop "Generated phrases are valid" prop_PhraseLength
|
|
|
|
prop "Generated phrases are valid" $ again prop_PhraseLength
|
|
|
|
prop "Derived seeds are valid" prop_SeedLength
|
|
|
|
prop "Derived seeds are valid" $ again prop_SeedLength
|
|
|
|
prop "Orchard spending keys are valid" $
|
|
|
|
before getSeed $
|
|
|
|
forAll genOrcArgs $ \(c, i, _) -> prop_OrchardSpendingKey c i
|
|
|
|
describe "Optimized spending key tests" $ do
|
|
|
|
prop "Orchard receivers are valid" $
|
|
|
|
it "Sapling spending keys are valid" $ \s ->
|
|
|
|
forAll genOrcArgs $ \(c, i, j) -> prop_OrchardReceiver c i j
|
|
|
|
property $ prop_SaplingSpendingKey s
|
|
|
|
|
|
|
|
it "Sapling receivers are valid" $ \s ->
|
|
|
|
|
|
|
|
property $ prop_SaplingReceiver s
|
|
|
|
|
|
|
|
it "Orchard spending keys are valid" $ \s ->
|
|
|
|
|
|
|
|
property $ prop_OrchardSpendingKey s
|
|
|
|
|
|
|
|
it "Orchard receivers are valid" $ \s ->
|
|
|
|
|
|
|
|
property $ prop_OrchardReceiver s
|
|
|
|
describe "Address tests" $ do
|
|
|
|
describe "Address tests" $ do
|
|
|
|
it "Encode transparent" $ do
|
|
|
|
it "Encode transparent" $ do
|
|
|
|
let ua =
|
|
|
|
let ua =
|
|
|
@ -481,7 +489,7 @@ 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"
|
|
|
|
describe "Transparent Private and Publicc Key Generation" $ do
|
|
|
|
describe "Transparent Private and Public Key Generation" $ do
|
|
|
|
it "Obtain a transparent extended private key from HDSeed" $ do
|
|
|
|
it "Obtain a transparent extended private key from HDSeed" $ do
|
|
|
|
let hdseed =
|
|
|
|
let hdseed =
|
|
|
|
[ 206
|
|
|
|
[ 206
|
|
|
@ -577,55 +585,38 @@ main = do
|
|
|
|
xtpubk <- xtpubkIO
|
|
|
|
xtpubk <- xtpubkIO
|
|
|
|
---print $ show xtpubk
|
|
|
|
---print $ show xtpubk
|
|
|
|
xtpubk `shouldBe` testpbk
|
|
|
|
xtpubk `shouldBe` testpbk
|
|
|
|
describe "Sapling SpendingKey test" $ do
|
|
|
|
|
|
|
|
it "Generate Sapling spending key" $ do
|
|
|
|
|
|
|
|
p <- generateWalletSeedPhrase
|
|
|
|
|
|
|
|
let s = getWalletSeed p
|
|
|
|
|
|
|
|
genSaplingSpendingKey <$> s `shouldNotBe` Nothing
|
|
|
|
|
|
|
|
describe "Sapling Payment Address generation test" $ do
|
|
|
|
|
|
|
|
it "Call genSaplingPaymentAddress" $ do
|
|
|
|
|
|
|
|
p <- generateWalletSeedPhrase
|
|
|
|
|
|
|
|
let s = getWalletSeed p
|
|
|
|
|
|
|
|
genSaplingPaymentAddress (fromMaybe "" s) 0 `shouldNotBe` Nothing
|
|
|
|
|
|
|
|
prop "Sapling receivers are valid" $
|
|
|
|
|
|
|
|
forAll genSapArgs $ \i -> prop_SaplingReceiver i
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- | Properties
|
|
|
|
-- | Properties
|
|
|
|
prop_PhraseLength :: Int -> Property
|
|
|
|
prop_PhraseLength :: Property
|
|
|
|
prop_PhraseLength i =
|
|
|
|
prop_PhraseLength =
|
|
|
|
ioProperty $ do
|
|
|
|
ioProperty $ do
|
|
|
|
p <- generateWalletSeedPhrase
|
|
|
|
p <- generateWalletSeedPhrase
|
|
|
|
return $ BS.length p >= 95
|
|
|
|
return $ BS.length p >= 95
|
|
|
|
|
|
|
|
|
|
|
|
prop_SeedLength :: Int -> Property
|
|
|
|
prop_SeedLength :: Property
|
|
|
|
prop_SeedLength i =
|
|
|
|
prop_SeedLength =
|
|
|
|
ioProperty $ do
|
|
|
|
ioProperty $ do
|
|
|
|
p <- generateWalletSeedPhrase
|
|
|
|
p <- generateWalletSeedPhrase
|
|
|
|
let s = getWalletSeed p
|
|
|
|
let s = getWalletSeed p
|
|
|
|
return $ maybe 0 BS.length s === 64
|
|
|
|
return $ maybe 0 BS.length s === 64
|
|
|
|
|
|
|
|
|
|
|
|
prop_OrchardSpendingKey :: CoinType -> Int -> Property
|
|
|
|
prop_OrchardSpendingKey :: Seed -> CoinType -> NonNegative Int -> Property
|
|
|
|
prop_OrchardSpendingKey c i =
|
|
|
|
prop_OrchardSpendingKey s c (NonNegative i) =
|
|
|
|
ioProperty $ do
|
|
|
|
genOrchardSpendingKey s c i =/= Nothing
|
|
|
|
p <- generateWalletSeedPhrase
|
|
|
|
|
|
|
|
let s = getWalletSeed p
|
|
|
|
|
|
|
|
return $ genOrchardSpendingKey (fromMaybe "" s) c i =/= Nothing
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prop_OrchardReceiver :: CoinType -> Int -> Int -> Property
|
|
|
|
prop_OrchardReceiver ::
|
|
|
|
prop_OrchardReceiver c i j =
|
|
|
|
Seed -> CoinType -> NonNegative Int -> NonNegative Int -> Property
|
|
|
|
ioProperty $ do
|
|
|
|
prop_OrchardReceiver s c (NonNegative i) (NonNegative j) =
|
|
|
|
p <- generateWalletSeedPhrase
|
|
|
|
genOrchardReceiver j (fromMaybe "" $ genOrchardSpendingKey s c i) =/= Nothing
|
|
|
|
let s = getWalletSeed p
|
|
|
|
|
|
|
|
let sk = genOrchardSpendingKey (fromMaybe "" s) c i
|
|
|
|
|
|
|
|
return $ genOrchardReceiver j (fromMaybe "" sk) =/= Nothing
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prop_SaplingReceiver :: Int -> Property
|
|
|
|
prop_SaplingSpendingKey :: Seed -> NonNegative Int -> Property
|
|
|
|
prop_SaplingReceiver i =
|
|
|
|
prop_SaplingSpendingKey s (NonNegative i) =
|
|
|
|
ioProperty $ do
|
|
|
|
genSaplingSpendingKey s i =/= Nothing
|
|
|
|
p <- generateWalletSeedPhrase
|
|
|
|
|
|
|
|
let s = getWalletSeed p
|
|
|
|
prop_SaplingReceiver :: Seed -> NonNegative Int -> NonNegative Int -> Property
|
|
|
|
let sk = genSaplingSpendingKey (fromMaybe "" s)
|
|
|
|
prop_SaplingReceiver s (NonNegative i) (NonNegative j) =
|
|
|
|
return $ genSaplingPaymentAddress (fromMaybe "" sk) i =/= Nothing
|
|
|
|
genSaplingPaymentAddress (fromMaybe "" $ genSaplingSpendingKey s j) i =/=
|
|
|
|
|
|
|
|
Nothing
|
|
|
|
|
|
|
|
|
|
|
|
-- | Generators
|
|
|
|
-- | Generators
|
|
|
|
genOrcArgs :: Gen (CoinType, Int, Int)
|
|
|
|
genOrcArgs :: Gen (CoinType, Int, Int)
|
|
|
@ -637,4 +628,15 @@ genOrcArgs = do
|
|
|
|
|
|
|
|
|
|
|
|
genSapArgs :: Gen Int
|
|
|
|
genSapArgs :: Gen Int
|
|
|
|
genSapArgs = choose (1, 50)
|
|
|
|
genSapArgs = choose (1, 50)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getSeed :: IO Seed
|
|
|
|
|
|
|
|
getSeed = do
|
|
|
|
|
|
|
|
p <- generateWalletSeedPhrase
|
|
|
|
|
|
|
|
let s = getWalletSeed p
|
|
|
|
|
|
|
|
case s of
|
|
|
|
|
|
|
|
Nothing -> throwIO $ userError "Couldn't generate seed"
|
|
|
|
|
|
|
|
Just s' -> return s'
|
|
|
|
|
|
|
|
|
|
|
|
-- | Arbitrary instances
|
|
|
|
-- | Arbitrary instances
|
|
|
|
|
|
|
|
instance Arbitrary CoinType where
|
|
|
|
|
|
|
|
arbitrary = elements [MainNetCoin, TestNetCoin, RegTestNetCoin]
|
|
|
|