Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jormungandr.NetworkSpec: Add more error path tests #525

Merged
merged 2 commits into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/jormungandr/src/Cardano/Wallet/Jormungandr/Network.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ module Cardano.Wallet.Jormungandr.Network
, JormungandrLayer (..)
, mkJormungandrLayer

-- * Exception
-- * Exceptions
, ErrUnexpectedNetworkFailure (..)

-- * Errors
, ErrGetInitialFeePolicy (..)
, ErrGetDescendants (..)

-- * Re-export
, BaseUrl (..)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import Cardano.Wallet.Jormungandr.Api
import Cardano.Wallet.Jormungandr.Compatibility
( Jormungandr, Network (..), block0 )
import Cardano.Wallet.Jormungandr.Network
( BaseUrl (..), ErrUnexpectedNetworkFailure (..), Scheme (..) )
( BaseUrl (..)
, ErrGetDescendants (..)
, ErrUnexpectedNetworkFailure (..)
, Scheme (..)
)
import Cardano.Wallet.Jormungandr.Primitive.Types
( Tx (..) )
import Cardano.Wallet.Network
Expand Down Expand Up @@ -60,6 +64,8 @@ import Data.Functor
( ($>) )
import Data.Proxy
( Proxy (..) )
import Network.HTTP.Client
( defaultManagerSettings, newManager )
import Servant.Links
( safeLink )
import System.Directory
Expand Down Expand Up @@ -164,6 +170,26 @@ spec = do
show link == show (safeLink api (Proxy @GetTipId))
bracket (startNode wrongUrl wait) killNode test

describe "White-box error path tests" $
beforeAll startNode' $ afterAll killNode $ do

it "can't fetch a block that doesn't exist" $ \_ -> do
mgr <- newManager defaultManagerSettings
let jml = Jormungandr.mkJormungandrLayer mgr url
let nonexistent = Hash "kitten"
res <- runExceptT (Jormungandr.getBlock jml nonexistent)
res `shouldBe` Left (ErrGetBlockNotFound nonexistent)

it "can't fetch a blocks from a parent that doesn't exist" $ \_ -> do
mgr <- newManager defaultManagerSettings
let jml = Jormungandr.mkJormungandrLayer mgr url
let nonexistent = Hash "cat"
res <- runExceptT (Jormungandr.getDescendantIds jml nonexistent 42)
res `shouldSatisfy` \case
Left (ErrGetDescendantsParentNotFound _) -> True
Left (ErrGetDescendantsNetworkUnreachable _) -> False
Right _ -> False


-- NOTE: 'Right ()' just means that the format wasn't obviously wrong.
-- The tx may still be rejected.
Expand Down