Skip to content

Commit

Permalink
CompatibilitySpec: Add Value-TokenBundle roundtrip test
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed Jan 11, 2021
1 parent 21a2ee9 commit 7287f37
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/shelley/test/unit/Cardano/Wallet/Shelley/CompatibilitySpec.hs
Expand Up @@ -45,20 +45,26 @@ import Cardano.Wallet.Primitive.Types
( DecentralizationLevel (..), SlotId (..) )
import Cardano.Wallet.Primitive.Types.Address
( Address (..) )
import Cardano.Wallet.Primitive.Types.Coin
( Coin (..) )
import Cardano.Wallet.Primitive.Types.Hash
( Hash (..) )
import Cardano.Wallet.Primitive.Types.RewardAccount
( RewardAccount (..) )
import Cardano.Wallet.Primitive.Types.TokenBundle.Gen
( genTokenBundleSmallRange, shrinkTokenBundleSmallRange )
import Cardano.Wallet.Shelley.Compatibility
( CardanoBlock
, StandardCrypto
, decentralizationLevelFromPParams
, fromCardanoValue
, fromTip
, inspectAddress
, interval0
, interval1
, invertUnitInterval
, toCardanoHash
, toCardanoValue
, toPoint
)
import Cardano.Wallet.Unsafe
Expand Down Expand Up @@ -115,6 +121,7 @@ import qualified Cardano.Ledger.Shelley as SL
import qualified Cardano.Wallet.Primitive.AddressDerivation.Byron as Byron
import qualified Cardano.Wallet.Primitive.AddressDerivation.Shelley as Shelley
import qualified Cardano.Wallet.Primitive.Types as W
import qualified Cardano.Wallet.Primitive.Types.TokenBundle as TokenBundle
import qualified Codec.Binary.Bech32 as Bech32
import qualified Data.ByteString as BS
import qualified Data.Text.Encoding as T
Expand Down Expand Up @@ -199,6 +206,14 @@ spec = do
& toText
it title $ output `shouldBe` expectedOutput

describe "Cardano.Api.Value-TokenBundle conversion" $ do
it "roundtrips" $ checkCoverage $ property $ \tb ->
cover 20 (TokenBundle.getCoin tb /= Coin 0) "has ada" $
cover 2 (TokenBundle.getCoin tb == Coin 0) "has no ada" $
cover 10 (length (snd $ TokenBundle.toFlatList tb) > 3)
"has some assets" $
fromCardanoValue (toCardanoValue tb) === tb

describe "Utilities" $ do

describe "UnitInterval" $ do
Expand Down Expand Up @@ -368,6 +383,10 @@ genMnemonic = do
instance Show XPrv where
show _ = "<xprv>"

instance Arbitrary TokenBundle.TokenBundle where
arbitrary = genTokenBundleSmallRange
shrink = shrinkTokenBundleSmallRange

--
-- Helpers
--
Expand Down

0 comments on commit 7287f37

Please sign in to comment.