This repository has been archived by the owner on Aug 18, 2020. It is now read-only.
/
WalletSpecs.hs
70 lines (57 loc) · 2.58 KB
/
WalletSpecs.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TupleSections #-}
module WalletSpecs (walletSpecs) where
import Universum
import Cardano.Wallet.Client.Http
import Control.Lens
import Test.Hspec
import Util
walletSpecs :: WalletRef -> WalletClient IO -> Spec
walletSpecs _ wc = do
describe "Wallets" $ do
it "Creating a wallet makes it available." $ do
newWallet <- randomWallet CreateWallet
Wallet{..} <- createWalletCheck wc newWallet
eresp <- getWallet wc walId
void $ eresp `shouldPrism` _Right
it "Updating a wallet persists the update" $ do
newWallet <- randomWallet CreateWallet
wallet <- createWalletCheck wc newWallet
let newName = "Foobar Bazquux"
newAssurance = NormalAssurance
eupdatedWallet <- updateWallet wc (walId wallet) WalletUpdate
{ uwalName = newName
, uwalAssuranceLevel = newAssurance
}
Wallet{..} <- wrData <$> eupdatedWallet `shouldPrism` _Right
walName `shouldBe` newName
walAssuranceLevel `shouldBe` newAssurance
it "CreateWallet with the same mnemonics rises WalletAlreadyExists error" $
testWalletAlreadyExists CreateWallet
it "RestoreWallet with the same mnemonics throws WalletAlreadyExists" $
testWalletAlreadyExists RestoreWallet
it "Can accept Unicode characters" $ do
newWallet <- randomWallet CreateWallet
wallet <- createWalletCheck wc newWallet
eresp <- updateWallet wc (walId wallet) WalletUpdate
{ uwalName = "patate漢patate字patat"
, uwalAssuranceLevel = NormalAssurance
}
eresp `shouldPrism_` _Right
where
testWalletAlreadyExists action = do
newWallet1 <- randomWallet action
preWallet2 <- randomWallet action
let newWallet2 =
preWallet2
{ newwalBackupPhrase = newwalBackupPhrase newWallet1
}
-- First wallet creation/restoration should succeed
result <- postWallet wc newWallet1
wallet <- fmap wrData (result `shouldPrism` _Right)
-- Second wallet creation/restoration should rise WalletAlreadyExists
eresp <- postWallet wc newWallet2
clientError <- eresp `shouldPrism` _Left
clientError
`shouldBe`
ClientWalletError (WalletAlreadyExists (walId wallet))