Skip to content

Commit

Permalink
Test deposit REST module
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino committed Sep 9, 2024
1 parent 6283116 commit 33aec0f
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/customer-deposit-wallet/customer-deposit-wallet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ test-suite unit
other-modules:
Cardano.Wallet.Deposit.HTTP.JSON.JSONSpec
Cardano.Wallet.Deposit.HTTP.OpenAPISpec
Cardano.Wallet.Deposit.RESTSpec
Paths_customer_deposit_wallet
Spec

Expand Down
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"

0 comments on commit 33aec0f

Please sign in to comment.