2
2
module Test.Spec.CoinSelection.Generators (
3
3
genGroupedUtxo
4
4
, genPayee
5
+ , genPayeeWithNM
5
6
, genPayees
6
7
, genFiddlyPayees
7
8
, genUtxo
@@ -26,11 +27,12 @@ import Test.QuickCheck (Gen, arbitrary, choose, suchThat)
26
27
27
28
import qualified Pos.Chain.Txp as Core
28
29
import qualified Pos.Core as Core
30
+ import Pos.Core.NetworkMagic (NetworkMagic )
29
31
30
32
import Cardano.Wallet.Kernel.Util.Core (paymentAmount , utxoBalance )
31
33
32
34
-- type class instances
33
- import Test.Pos.Core.Arbitrary ()
35
+ import Test.Pos.Core.Arbitrary (genAddress )
34
36
35
37
{- ------------------------------------------------------------------------------
36
38
Useful types
@@ -92,6 +94,16 @@ arbitraryAddress opts = do
92
94
not (Core. isRedeemAddress a)
93
95
arbitrary `suchThat` (\ a -> fiddlyCondition a && redeemCondition a)
94
96
97
+ arbitraryAddressWithNM :: NetworkMagic
98
+ -> StakeGenOptions
99
+ -> Gen Core. Address
100
+ arbitraryAddressWithNM nm opts = do
101
+ let fiddlyCondition a = not (fiddlyAddresses opts) ||
102
+ (length (sformat F. build a) < 104 )
103
+ let redeemCondition a = allowRedeemAddresses opts ||
104
+ not (Core. isRedeemAddress a)
105
+ (genAddress nm) `suchThat` (\ a -> fiddlyCondition a && redeemCondition a)
106
+
95
107
96
108
-- | Finalise the generation of 'a' by transferring all the remaining \"slack\".
97
109
finalise :: Semigroup a
@@ -257,6 +269,14 @@ genTxOut opts = fromStakeOptions opts genOne paymentAmount
257
269
addr <- arbitraryAddress opts
258
270
return (Core. TxOut addr coins :| [] )
259
271
272
+ genTxOutWithNM :: NetworkMagic -> StakeGenOptions -> Gen (NonEmpty Core. TxOut )
273
+ genTxOutWithNM nm opts = fromStakeOptions opts genOne paymentAmount
274
+ where
275
+ genOne :: Maybe (NonEmpty Core. TxOut ) -> Core. Coin -> Gen (NonEmpty Core. TxOut )
276
+ genOne _ coins = do
277
+ addr <- arbitraryAddressWithNM nm opts
278
+ return (Core. TxOut addr coins :| [] )
279
+
260
280
utxoSmallestEntry :: Core. Utxo -> Core. Coin
261
281
utxoSmallestEntry utxo =
262
282
case sort (Map. toList utxo) of
@@ -320,6 +340,18 @@ genPayee _utxo payment = do
320
340
, allowRedeemAddresses = False
321
341
}
322
342
343
+ genPayeeWithNM :: NetworkMagic -> Core. Utxo -> Pay -> Gen (NonEmpty Core. TxOut )
344
+ genPayeeWithNM nm _utxo payment = do
345
+ let balance = toLovelaces payment
346
+ genTxOutWithNM nm StakeGenOptions {
347
+ stakeMaxValue = Nothing
348
+ , stakeGenerationTarget = AtLeast
349
+ , stakeNeeded = Core. mkCoin balance
350
+ , stakeMaxEntries = Just 1
351
+ , fiddlyAddresses = False
352
+ , allowRedeemAddresses = False
353
+ }
354
+
323
355
-- | Generates a single payee which has a redeem address inside.
324
356
genRedeemPayee :: Core. Utxo -> Pay -> Gen (NonEmpty Core. TxOut )
325
357
genRedeemPayee _utxo payment = do
0 commit comments