Skip to content

Commit

Permalink
Merge pull request #163 from input-output-hk/piotr/testing
Browse files Browse the repository at this point in the history
Negative cases for types decoding
  • Loading branch information
piotr-iohk authored Apr 8, 2019
2 parents 1cd66fc + b55b2f9 commit 72b1df1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
5 changes: 0 additions & 5 deletions test/integration/Cardano/Wallet/Network/HttpBridgeSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -112,35 +112,30 @@ spec = do
describe "Submitting signed transactions"
$ beforeAll startBridge $ afterAll closeBridge $ do
it "empty tx fails" $ \(_, network) -> do

let signed = sign txEmpty []
(Left err) <- runExceptT $ postTx network signed
(show err) `shouldContain`
"Transaction failed verification: transaction has no inputs"

it "empty tx fails 2" $ \(_, network) -> do

let signed = sign txEmpty [pkWitness]
(Left err) <- runExceptT $ postTx network signed
(show err) `shouldContain`
"Transaction failed verification: transaction has no inputs"

it "old tx fails" $ \(_, network) -> do

let signed = sign txNonEmpty [pkWitness]
(Left err) <- runExceptT $ postTx network signed
(show err) `shouldContain`
"Failed to send to peers: Blockchain protocol error"

it "tx fails - more inputs than witnesses" $ \(_, network) -> do

let signed = sign txNonEmpty []
(Left err) <- runExceptT $ postTx network signed
(show err) `shouldContain`
"Transaction failed verification: transaction has more inputs than witnesses"

it "tx fails - more witnesses than inputs" $ \(_, network) -> do

let signed = sign txNonEmpty [pkWitness, pkWitness]
(Left err) <- runExceptT $ postTx network signed
(show err) `shouldContain`
Expand Down
25 changes: 24 additions & 1 deletion test/unit/Cardano/Wallet/Primitive/TypesSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import Data.Proxy
( Proxy (..) )
import Data.Set
( Set, (\\) )
import Data.Text.Class
( TextDecodingError (..), fromText )
import Test.Hspec
( Spec, describe, it )
import Test.QuickCheck
Expand Down Expand Up @@ -77,6 +79,28 @@ spec = do
textRoundtrip $ Proxy @WalletName
textRoundtrip $ Proxy @WalletId

describe "Negative cases for types decoding" $ do
it "fail fromText @Address \"0000\"" $ do
let err = "Unable to decode Address: expected Base58 encoding"
fromText @Address "0000" === Left (TextDecodingError err)
it "fail fromText @AddressPoolGap \"unusedused\"" $ do
let err = "Unable to decode address state: it's neither \"used\"\
\ nor \"unused\""
fromText @AddressState "unusedused" === Left (TextDecodingError err)
it "fail fromText @WalletName \"\"" $ do
let err = "name is too short: expected at least "
<> show walletNameMinLength <> " chars"
fromText @WalletName "" === Left (TextDecodingError err)
it "fail fromText @WalletName > walletNameMaxLength" $ do
let err = "name is too long: expected at most "
<> show walletNameMaxLength <> " chars"
let walName = T.pack (replicate (walletNameMaxLength + 1) 'x')
fromText @WalletName walName === Left (TextDecodingError err)
it "fail fromText @WalletId \"101\"" $ do
let err = "wallet id should be an hex-encoded string \
\of 40 characters"
fromText @WalletId "101" === Left (TextDecodingError err)

describe "Lemma 2.1 - Properties of UTxO operations" $ do
it "2.1.1) ins⊲ u ⊆ u"
(checkCoverage prop_2_1_1)
Expand Down Expand Up @@ -112,7 +136,6 @@ spec = do
(property $ SlotId { epochIndex = 1, slotNumber = 1 } < SlotId 1 2)
it "SlotId 1 2 < SlotId 2 2"
(property $ SlotId { epochIndex = 1, slotNumber = 2 } < SlotId 2 2)

{-------------------------------------------------------------------------------
Wallet Specification - Lemma 2.1 - Properties of UTxO operations
-------------------------------------------------------------------------------}
Expand Down

0 comments on commit 72b1df1

Please sign in to comment.