-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
lib/customer-deposit-wallet/test/unit/Cardano/Wallet/Deposit/RESTSpec.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
module Cardano.Wallet.Deposit.RESTSpec | ||
( spec | ||
) | ||
where | ||
|
||
import Prelude | ||
|
||
import Cardano.Crypto.Wallet | ||
( XPub | ||
, generate | ||
, toXPub | ||
) | ||
import Cardano.Wallet.Deposit.IO | ||
( WalletBootEnv (WalletBootEnv) | ||
) | ||
import Cardano.Wallet.Deposit.IO.Resource | ||
( withResource | ||
) | ||
import Cardano.Wallet.Deposit.REST | ||
( WalletResourceM | ||
, availableBalance | ||
, initXPubWallet | ||
, loadWallet | ||
, runWalletResourceM | ||
) | ||
import Control.Concurrent | ||
( threadDelay | ||
) | ||
import Control.Monad.IO.Class | ||
( MonadIO (..) | ||
) | ||
import System.IO.Temp | ||
( withSystemTempDirectory | ||
) | ||
import Test.Hspec | ||
( Spec | ||
, describe | ||
, it | ||
, shouldBe | ||
) | ||
|
||
import qualified Cardano.Wallet.Deposit.Read as Read | ||
import qualified Data.ByteString.Char8 as B8 | ||
|
||
fakeBootEnv :: WalletBootEnv IO | ||
fakeBootEnv = WalletBootEnv undefined undefined undefined | ||
|
||
xpub :: XPub | ||
xpub = | ||
toXPub | ||
$ generate (B8.pack "random seed for a testing xpub lala") B8.empty | ||
|
||
waitAndGetBalance :: WalletResourceM Read.Value | ||
waitAndGetBalance = do | ||
liftIO $ threadDelay 100000 | ||
availableBalance | ||
|
||
spec :: Spec | ||
spec = do | ||
describe "REST Deposit interface" $ do | ||
it "can initialize a wallet" | ||
$ withSystemTempDirectory "deposit-rest" | ||
$ \dir -> do | ||
r <- | ||
withResource | ||
$ runWalletResourceM | ||
$ do | ||
initXPubWallet fakeBootEnv dir xpub 0 | ||
waitAndGetBalance | ||
case r of | ||
Left e -> fail $ show e | ||
Right cs -> cs `shouldBe` mempty | ||
it "can load an existing wallet" | ||
$ withSystemTempDirectory "deposit-rest" | ||
$ \dir -> do | ||
r <- | ||
withResource | ||
$ runWalletResourceM | ||
$ do | ||
initXPubWallet fakeBootEnv dir xpub 0 | ||
waitAndGetBalance | ||
case r of | ||
Left e -> fail $ show e | ||
Right _ -> do | ||
r' <- | ||
withResource | ||
$ runWalletResourceM | ||
$ do | ||
loadWallet fakeBootEnv dir | ||
waitAndGetBalance | ||
case r' of | ||
Left e -> fail $ show e | ||
Right cs -> cs `shouldBe` mempty | ||
it "cannot re-initialize a wallet" | ||
$ withSystemTempDirectory "deposit-rest" | ||
$ \dir -> do | ||
r <- | ||
withResource | ||
$ runWalletResourceM | ||
$ initXPubWallet fakeBootEnv dir xpub 0 | ||
case r of | ||
Left e -> fail $ show e | ||
Right _ -> do | ||
r' <- | ||
withResource | ||
$ runWalletResourceM | ||
$ do | ||
initXPubWallet fakeBootEnv dir xpub 0 | ||
waitAndGetBalance | ||
case r' of | ||
Left _ -> return () | ||
Right _ -> fail "Should have failed" |