Skip to content

Commit

Permalink
try to use genTx from cardano-api
Browse files Browse the repository at this point in the history
some fix to cabal-version
  • Loading branch information
paweljakubas committed Jul 26, 2021
1 parent f5f84c6 commit 7374e42
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/core/cardano-wallet-core.cabal
Expand Up @@ -276,6 +276,7 @@ test-suite unit
, foldl
, generic-arbitrary
, generic-lens
, hedgehog-quickcheck
, hspec >= 2.8.2
, hspec-core >= 2.8.2
, http-api-data
Expand Down
20 changes: 19 additions & 1 deletion lib/core/test/unit/Cardano/Wallet/Api/TypesSpec.hs
Expand Up @@ -396,6 +396,8 @@ import Test.QuickCheck.Arbitrary.Generic
( genericArbitrary, genericShrink )
import Test.QuickCheck.Extra
( reasonablySized )
import Test.QuickCheck.Hedgehog
( hedgehog )
import Test.Text.Roundtrip
( textRoundtrip )
import Test.Utils.Paths
Expand All @@ -409,6 +411,7 @@ import Text.Regex.PCRE
import Web.HttpApiData
( FromHttpApiData (..) )

import qualified Cardano.Api as Cardano
import qualified Cardano.Wallet.Api.Types as Api
import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Types as Aeson
Expand All @@ -421,6 +424,7 @@ import qualified Data.Map.Strict as Map
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Data.Yaml as Yaml
import qualified Gen.Cardano.Api.Typed as Cardano
import qualified Prelude
import qualified Test.Utils.Roundtrip as Utils

Expand Down Expand Up @@ -2021,14 +2025,28 @@ instance Arbitrary (PostTransactionFeeOldData t) where
<*> arbitrary
<*> arbitrary

genNodeTxBinary :: Gen ByteString
genNodeTxBinary = do
era <- elements
[ Cardano.CardanoEra Cardano.ByronEra
, Cardano.CardanoEra Cardano.ShelleyEra
, Cardano.CardanoEra Cardano.AllegraEra
, Cardano.CardanoEra Cardano.MaryEra
, Cardano.CardanoEra Cardano.AlonzoEra
]
tx <- hedgehog (Cardano.genTx era)
pure $ Cardano.serialiseToCBOR tx

{--
genSmallBlob :: Gen ByteString
genSmallBlob = BS.pack <$> Test.QuickCheck.scale (min 32) (listOf arbitrary)
--}

shrinkBlob :: ByteString -> [ByteString]
shrinkBlob bytes = BS.pack <$> shrink (BS.unpack bytes)

instance Arbitrary (ApiBytesT base ByteString) where
arbitrary = ApiBytesT <$> genSmallBlob
arbitrary = ApiBytesT <$> genNodeTxBinary
shrink (ApiBytesT bs) = ApiBytesT <$> shrinkBlob bs

instance Arbitrary (ApiBytesT base SerialisedTx) where
Expand Down
2 changes: 2 additions & 0 deletions lib/core/test/unit/Cardano/WalletSpec.hs
Expand Up @@ -1296,6 +1296,8 @@ dummyTransactionLayer = TransactionLayer

, mkUnsignedTransaction =
error "dummyTransactionLayer: mkUnsignedTransaction not implemented"
, mkSignedTransaction =
error "dummyTransactionLayer: mkSignedTransaction not implemented"
, initSelectionCriteria =
error "dummyTransactionLayer: initSelectionCriteria not implemented"
, calcMinimumCost =
Expand Down

0 comments on commit 7374e42

Please sign in to comment.