Add tests for matching Sapling address and VK

This commit is contained in:
Rene Vergara 2023-06-14 10:55:20 -05:00
parent 0acff0d965
commit 0dd9680158
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2
3 changed files with 29 additions and 10 deletions

View file

@ -23,7 +23,7 @@ import Foreign.Rust.Serialisation.Raw
import Foreign.Rust.Serialisation.Raw.Base16
import qualified Generics.SOP as SOP
import qualified GHC.Generics as GHC
import HaskellZcash.Types
import ZcashHaskell.Types
{# fun unsafe rust_wrapper_f4jumble as rustWrapperF4Jumble
@ -65,6 +65,13 @@ import HaskellZcash.Types
-> `Bool'
#}
{# fun pure unsafe rust_wrapper_svk_check_address as rustWrapperSaplingCheck
{ toBorshVar* `BS.ByteString'&
, toBorshVar* `BS.ByteString'&
}
-> `Bool'
#}
{# fun unsafe rust_wrapper_ufvk_decode as rustWrapperUfvkDecode
{ toBorshVar* `BS.ByteString'&
, getVarBuffer `Buffer UnifiedFullViewingKey'&

View file

@ -4,16 +4,20 @@ import C.Zcash (rustWrapperIsUA)
import qualified Data.ByteString as BS
import qualified Data.Text.Encoding as E
import Data.Word
import HaskellZcash.Orchard
import HaskellZcash.Sapling (isValidSaplingViewingKey, isValidShieldedAddress)
import HaskellZcash.Types
import Test.Hspec
import ZcashHaskell.Orchard
import ZcashHaskell.Sapling
( isValidSaplingViewingKey
, isValidShieldedAddress
, matchSaplingAddress
)
import ZcashHaskell.Types
( OrchardAction(..)
, OrchardDecodedAction(..)
, RawData(..)
, UnifiedFullViewingKey(..)
)
import HaskellZcash.Utils
import Test.Hspec
import ZcashHaskell.Utils
main :: IO ()
main = do
@ -243,10 +247,18 @@ main = do
"zxviews1qdjagrrpqqqqpq8es75mlu6rref0qyrstchf8dxzeygtsejwfqu8ckhwl2qj5m8am7lmupxk3vkvdjm8pawjpmesjfapvsqw96pa46c2z0kk7letrxf7mkltwz54fwpxc7kc79mm5kce3rwn5ssl009zwsra2spppwgrx25s9k5hq65f69l4jz2tjmqgy0pl49qmtaj3nudk6wglwe2hpa327hydlchtyq9av6wjd6hu68e04ahwk9a9n2kt0kj3nj99nue65awtu5cwwcpjs"
let sa =
"zs1g2ne5w2r8kvalwzngsk3kfzppx3qcx5560pnfmw9rj5xfd3zfg9dkm7hyxnfyhc423fev5wuue4"
let sa' =
"zs17faa6l5ma55s55exq9rnr32tu0wl8nmqg7xp3e6tz0m5ajn2a6yxlc09t03mqdmvyphavvf3sl8"
let rawKey = decodeBech32 vk
let rawSa = decodeBech32 sa
let rawSa' = decodeBech32 sa'
it "is mainnet" $ do hrp rawKey `shouldBe` "zxviews"
it "is valid Sapling raw key" $ do
isValidSaplingViewingKey (bytes rawKey) `shouldBe` True
it "matches the right Sapling address" $ do
matchSaplingAddress (bytes rawKey) (bytes rawSa) `shouldBe` True
it "doesn't match the wrong Sapling address" $ do
matchSaplingAddress (bytes rawKey) (bytes rawSa') `shouldBe` False
describe "Decode invalid Sapling VK" $ do
let vk =
"zxviews1qdjagrrpqqqqpq8es75mlu6rref0qyrstchf8dxzeygtsejwfqu8ckhwl2qj5m8am7lmupxk3vkvdjm8pawjpmesjfapvsqw96pa46c2z0kk7letrxf7mkltwz54fwpxc7kc79mm5kce3rwn5ssl009zwsra2spppwgrx25s9k5hq65f69l4jz2tjmqgy0pl49qmtaj3nudk6wglwe2hpa327hydlchtyq9av6wjd6hu68e04ahwk9a9n2kt0kj3nj99nue65awtu5cwwfake"

View file

@ -27,10 +27,10 @@ source-repository head
library
exposed-modules:
C.Zcash
HaskellZcash.Orchard
HaskellZcash.Sapling
HaskellZcash.Types
HaskellZcash.Utils
ZcashHaskell.Orchard
ZcashHaskell.Sapling
ZcashHaskell.Types
ZcashHaskell.Utils
other-modules:
Paths_zcash_haskell
hs-source-dirs: