69 lines
2.3 KiB
Haskell
69 lines
2.3 KiB
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
import Control.Monad (when)
|
|
import Database.Persist
|
|
import Database.Persist.Sqlite
|
|
import System.Directory
|
|
import Test.Hspec
|
|
import ZcashHaskell.Types (ZcashNet(..))
|
|
import Zenith.Core (getAccounts)
|
|
import Zenith.DB
|
|
|
|
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` ()
|
|
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
|