Add tests for Orchard spending key
This commit is contained in:
parent
53716685a8
commit
3822e9f2ff
3 changed files with 19 additions and 4 deletions
|
@ -625,7 +625,7 @@ pub extern "C" fn rust_wrapper_derive_orchard_spending_key(
|
|||
let sk = SpendingKey::from_zip32_seed(&s, coin_type, zip32::AccountId::try_from(acc_id).unwrap());
|
||||
match sk {
|
||||
Ok(key) => {
|
||||
marshall_to_haskell_var(&key.to_bytes(), out, out_len, RW);
|
||||
marshall_to_haskell_var(&key.to_bytes().to_vec(), out, out_len, RW);
|
||||
},
|
||||
Err(_e) => {
|
||||
marshall_to_haskell_var(&vec![0], out, out_len, RW);
|
||||
|
|
|
@ -34,10 +34,18 @@ import ZcashHaskell.Types
|
|||
import ZcashHaskell.Utils (encodeBech32m, f4Jumble)
|
||||
|
||||
-- | Derives an Orchard spending key for the given seed and account ID
|
||||
genOrchardSpendingKey :: Seed -> CoinType -> AccountId -> BS.ByteString
|
||||
genOrchardSpendingKey :: Seed -> CoinType -> AccountId -> Maybe BS.ByteString
|
||||
genOrchardSpendingKey s coinType accountId =
|
||||
withPureBorshVarBuffer $
|
||||
rustWrapperGenOrchardSpendKey s (getValue coinType) (fromIntegral accountId)
|
||||
if BS.length k /= 32
|
||||
then Nothing
|
||||
else Just k
|
||||
where
|
||||
k =
|
||||
withPureBorshVarBuffer $
|
||||
rustWrapperGenOrchardSpendKey
|
||||
s
|
||||
(getValue coinType)
|
||||
(fromIntegral accountId)
|
||||
|
||||
-- | Checks if given bytestring is a valid encoded unified address
|
||||
isValidUnifiedAddress :: BS.ByteString -> Maybe UnifiedAddress
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
import C.Zcash (rustWrapperUADecode)
|
||||
import Control.Monad.IO.Class (liftIO)
|
||||
import Data.Aeson
|
||||
import Data.Bool (Bool(True))
|
||||
import qualified Data.ByteString as BS
|
||||
|
@ -45,6 +46,7 @@ import ZcashHaskell.Sapling
|
|||
import ZcashHaskell.Transparent (encodeTransparent)
|
||||
import ZcashHaskell.Types
|
||||
( BlockResponse(..)
|
||||
, CoinType(..)
|
||||
, DecodedNote(..)
|
||||
, OrchardAction(..)
|
||||
, RawData(..)
|
||||
|
@ -453,6 +455,11 @@ main = do
|
|||
p <- generateWalletSeedPhrase
|
||||
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
|
||||
it "Encode transparent" $ do
|
||||
let ua =
|
||||
|
|
Loading…
Reference in a new issue