Skip to content

Commit

Permalink
Do not generate transaction outputs with zero ada quantities.
Browse files Browse the repository at this point in the history
In real life, we'll always see transaction outputs with non-zero ada
quantities.

The coin selection algorithm also expects this.
  • Loading branch information
jonathanknowles committed Jan 15, 2021
1 parent 996234f commit bd08932
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/core/src/Cardano/Wallet/Primitive/Types/Tx/Gen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ import Prelude

import Cardano.Wallet.Primitive.Types.Address.Gen
( genAddressSmallRange, shrinkAddressSmallRange )
import Cardano.Wallet.Primitive.Types.Coin
( Coin (..) )
import Cardano.Wallet.Primitive.Types.Hash
( Hash (..) )
import Cardano.Wallet.Primitive.Types.TokenBundle
( TokenBundle )
import Cardano.Wallet.Primitive.Types.TokenBundle.Gen
( genTokenBundleSmallRange, shrinkTokenBundleSmallRange )
import Cardano.Wallet.Primitive.Types.Tx
Expand All @@ -32,10 +36,11 @@ import Data.Text.Class
import Data.Word
( Word32 )
import Test.QuickCheck
( Gen, arbitrary, elements )
( Gen, arbitrary, elements, suchThat )
import Test.QuickCheck.Extra
( shrinkInterleaved )

import qualified Cardano.Wallet.Primitive.Types.TokenBundle as TokenBundle
import qualified Data.ByteString.Char8 as B8
import qualified Data.Text as T

Expand Down Expand Up @@ -104,12 +109,15 @@ genTxInLargeRange = TxIn
genTxOutSmallRange :: Gen TxOut
genTxOutSmallRange = TxOut
<$> genAddressSmallRange
<*> genTokenBundleSmallRange
<*> genTokenBundleSmallRange `suchThat` tokenBundleHasNonZeroCoin

shrinkTxOutSmallRange :: TxOut -> [TxOut]
shrinkTxOutSmallRange (TxOut a b) = uncurry TxOut <$> shrinkInterleaved
(a, shrinkAddressSmallRange)
(b, shrinkTokenBundleSmallRange)
(b, filter tokenBundleHasNonZeroCoin . shrinkTokenBundleSmallRange)

tokenBundleHasNonZeroCoin :: TokenBundle -> Bool
tokenBundleHasNonZeroCoin b = TokenBundle.getCoin b /= Coin 0

--------------------------------------------------------------------------------
-- Internal utilities
Expand Down

0 comments on commit bd08932

Please sign in to comment.