Publish Zenith beta version #80
3 changed files with 77 additions and 41 deletions
|
@ -31,16 +31,35 @@ share
|
|||
[persistLowerCase|
|
||||
ZcashWallet
|
||||
seedPhrase Phrase
|
||||
spendingKey BS.ByteString
|
||||
tPrivateKey BS.ByteString
|
||||
birthdayHeight Int
|
||||
name T.Text
|
||||
network ZcashNet
|
||||
deriving Show
|
||||
ZcashAccount
|
||||
walletId ZcashWalletId
|
||||
index Int
|
||||
orchSpendKey BS.ByteString
|
||||
sapSpendKey BS.ByteString
|
||||
tPrivateKey BS.ByteString
|
||||
deriving Show
|
||||
WalletAddress
|
||||
accId ZcashAccountId
|
||||
index Int
|
||||
orchRec BS.ByteString Maybe
|
||||
sapRec BS.ByteString Maybe
|
||||
tRec BS.ByteString Maybe
|
||||
encoded T.Text
|
||||
deriving Show
|
||||
|]
|
||||
|
||||
getWallets :: ZcashNet -> IO [Entity ZcashWallet]
|
||||
getWallets n =
|
||||
runSqlite "zenith.db" $ do
|
||||
getWallets :: T.Text -> ZcashNet -> IO [Entity ZcashWallet]
|
||||
getWallets dbFp n =
|
||||
runSqlite dbFp $ do
|
||||
s <- selectList [ZcashWalletNetwork ==. n] []
|
||||
liftIO $ return s
|
||||
|
||||
getAccounts :: T.Text -> ZcashWalletId -> IO [Entity ZcashAccount]
|
||||
getAccounts dbFp w =
|
||||
runSqlite dbFp $ do
|
||||
s <- selectList [ZcashAccountWalletId ==. w] []
|
||||
liftIO $ return s
|
||||
|
|
88
test/Spec.hs
88
test/Spec.hs
|
@ -1,51 +1,67 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
import Control.Monad.IO.Class (liftIO)
|
||||
import Control.Monad (when)
|
||||
import Database.Persist
|
||||
import Database.Persist.Sqlite
|
||||
import System.Directory
|
||||
import Test.Hspec
|
||||
import ZcashHaskell.Types (ZcashNet(..))
|
||||
import Zenith.DB
|
||||
import Zenith.DB
|
||||
( EntityField(ZcashWalletId, ZcashWalletName)
|
||||
, ZcashWallet(zcashWalletName)
|
||||
)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
checkDbFile <- doesFileExist "test.db"
|
||||
when checkDbFile $ removeFile "test.db"
|
||||
hspec $ do
|
||||
describe "Database tests" $ do
|
||||
it "Create table" $ do
|
||||
s <- runSqlite "test.db" $ do runMigration migrateAll
|
||||
s `shouldBe` ()
|
||||
it "insert wallet record" $ do
|
||||
s <-
|
||||
runSqlite "test.db" $ do
|
||||
insert $
|
||||
ZcashWallet
|
||||
"one two three four five six seven eight nine ten eleven twelve"
|
||||
"123456789"
|
||||
"987654321"
|
||||
2000000
|
||||
"Main Wallet"
|
||||
MainNet
|
||||
fromSqlKey s `shouldBe` 1
|
||||
it "read wallet record" $ do
|
||||
s <-
|
||||
runSqlite "test.db" $ do
|
||||
selectList [ZcashWalletBirthdayHeight >. 0] []
|
||||
length s `shouldBe` 1
|
||||
it "modify wallet record" $ do
|
||||
s <-
|
||||
runSqlite "test.db" $ do
|
||||
let recId = toSqlKey 1 :: ZcashWalletId
|
||||
update recId [ZcashWalletName =. "New Wallet"]
|
||||
get recId
|
||||
"New Wallet" `shouldBe` maybe "None" zcashWalletName s
|
||||
it "delete wallet record" $ do
|
||||
s <-
|
||||
runSqlite "test.db" $ do
|
||||
let recId = toSqlKey 1 :: ZcashWalletId
|
||||
delete recId
|
||||
get recId
|
||||
"None" `shouldBe` maybe "None" zcashWalletName s
|
||||
describe "Wallet Table" $ do
|
||||
it "insert wallet record" $ do
|
||||
s <-
|
||||
runSqlite "test.db" $ do
|
||||
insert $
|
||||
ZcashWallet
|
||||
"one two three four five six seven eight nine ten eleven twelve"
|
||||
2000000
|
||||
"Main Wallet"
|
||||
MainNet
|
||||
fromSqlKey s `shouldBe` 1
|
||||
it "read wallet record" $ do
|
||||
s <-
|
||||
runSqlite "test.db" $ do
|
||||
selectList [ZcashWalletBirthdayHeight >. 0] []
|
||||
length s `shouldBe` 1
|
||||
it "modify wallet record" $ do
|
||||
s <-
|
||||
runSqlite "test.db" $ do
|
||||
let recId = toSqlKey 1 :: ZcashWalletId
|
||||
update recId [ZcashWalletName =. "New Wallet"]
|
||||
get recId
|
||||
"New Wallet" `shouldBe` maybe "None" zcashWalletName s
|
||||
it "delete wallet record" $ do
|
||||
s <-
|
||||
runSqlite "test.db" $ do
|
||||
let recId = toSqlKey 1 :: ZcashWalletId
|
||||
delete recId
|
||||
get recId
|
||||
"None" `shouldBe` maybe "None" zcashWalletName s
|
||||
describe "Account table" $ do
|
||||
it "insert account" $ do
|
||||
s <-
|
||||
runSqlite "test.db" $ do
|
||||
insert $
|
||||
ZcashWallet
|
||||
"one two three four five six seven eight nine ten eleven twelve"
|
||||
2000000
|
||||
"Main Wallet"
|
||||
MainNet
|
||||
t <-
|
||||
runSqlite "test.db" $ do
|
||||
insert $ ZcashAccount s 0 "132465798" "987654321" "739182462"
|
||||
fromSqlKey t `shouldBe` 1
|
||||
it "read accounts for wallet" $ do
|
||||
wList <- getWallets "test.db" MainNet
|
||||
acc <- getAccounts "test.db" $ entityKey (head wList)
|
||||
length acc `shouldBe` 1
|
||||
|
|
|
@ -104,6 +104,7 @@ test-suite zenith-tests
|
|||
, persistent
|
||||
, persistent-sqlite
|
||||
, hspec
|
||||
, directory
|
||||
, zcash-haskell
|
||||
, zenith
|
||||
pkgconfig-depends: rustzcash_wrapper
|
||||
|
|
Loading…
Reference in a new issue