@@ -45,7 +45,6 @@ import Test.QuickCheck
45
45
, chooseInt
46
46
, chooseInteger
47
47
, liftArbitrary
48
- , suchThat
49
48
, vector
50
49
)
51
50
@@ -62,6 +61,9 @@ genKeyPair =
62
61
let (skey, _) = withDRG (drgNewTest seed) generateSecretKey
63
62
in KeyPair skey $ toPublic skey
64
63
64
+ genIntegerGreaterThan :: Integer -> Gen Integer
65
+ genIntegerGreaterThan a = arbitrary @ (Positive Integer ) <&> \ (Positive b) -> a + b
66
+
65
67
genTxInfoTemplate :: Gen TxInfo
66
68
genTxInfoTemplate = do
67
69
txInfoFeeAda <- arbitrary @ Integer
@@ -82,15 +84,29 @@ genTxInfoTemplate = do
82
84
, txInfoId
83
85
}
84
86
85
- genValidBidTerms :: CurrencySymbol -> AuctionTerms -> KeyPair -> KeyPair -> Gen BidTerms
86
- genValidBidTerms auctionCs auctionTerms sellerKeys bidderKeys = do
87
+ genValidBidTerms
88
+ :: CurrencySymbol
89
+ -> AuctionTerms
90
+ -> KeyPair
91
+ -> KeyPair
92
+ -> Maybe Integer
93
+ -> Gen BidTerms
94
+ genValidBidTerms auctionCs auctionTerms sellerKeys bidderKeys mOldBidPrice = do
87
95
let (bi'BidderVk, bi'BidderPkh) = hashVerificationKey $ vkey bidderKeys
88
96
let bt'Bidder = BidderInfo {.. }
89
- bt'BidPrice <- arbitrary @ Integer `suchThat` ( \ x -> x > at'StartingBid auctionTerms)
97
+ bt'BidPrice <- genBidPrice
90
98
let bt'SellerSignature = sellerSignature bi'BidderVk
91
99
let bt'BidderSignature = bidderSignature bt'BidPrice bi'BidderPkh
92
100
pure BidTerms {.. }
93
101
where
102
+ genBidPrice :: Gen Integer
103
+ genBidPrice =
104
+ case mOldBidPrice of
105
+ Just oldBidPrice ->
106
+ genIntegerGreaterThan $ oldBidPrice + at'MinBidIncrement auctionTerms
107
+ Nothing ->
108
+ genIntegerGreaterThan $ at'StartingBid auctionTerms
109
+
94
110
sellerSignature :: BuiltinByteString -> BuiltinByteString
95
111
sellerSignature bidderVkey =
96
112
signUsingKeyPair sellerKeys $
@@ -110,7 +126,7 @@ genValidBidState
110
126
genValidBidState auctionCs auctionTerms sellerKeys bidderKeys =
111
127
StandingBidState
112
128
<$> liftArbitrary
113
- (genValidBidTerms auctionCs auctionTerms sellerKeys bidderKeys)
129
+ (genValidBidTerms auctionCs auctionTerms sellerKeys bidderKeys Nothing )
114
130
115
131
genValidNewBidState
116
132
:: StandingBidState
@@ -120,15 +136,14 @@ genValidNewBidState
120
136
-> KeyPair
121
137
-> Gen StandingBidState
122
138
genValidNewBidState oldBidState auctionCs auctionTerms sellerKeys bidderKeys =
123
- case oldBidState of
124
- StandingBidState Nothing ->
125
- genValidBidState auctionCs auctionTerms sellerKeys bidderKeys
126
- StandingBidState (Just oldBidTerms) -> do
127
- newBidPrice <- arbitrary @ Integer `suchThat` (\ x -> x >= at'MinBidIncrement auctionTerms)
128
- pure . StandingBidState . Just $
129
- oldBidTerms
130
- { bt'BidPrice = newBidPrice
131
- }
139
+ StandingBidState . Just
140
+ <$> genValidBidTerms auctionCs auctionTerms sellerKeys bidderKeys oldBidPrice
141
+ where
142
+ oldBidPrice :: Maybe Integer
143
+ oldBidPrice =
144
+ case oldBidState of
145
+ StandingBidState Nothing -> Nothing
146
+ StandingBidState (Just oldBidTerms) -> Just $ bt'BidPrice oldBidTerms
132
147
133
148
genValidAuctionTerms :: PublicKey -> Gen AuctionTerms
134
149
genValidAuctionTerms vkey = do
@@ -145,10 +160,10 @@ genValidAuctionTerms vkey = do
145
160
let at'Cleanup = at'PurchaseDeadline + penaltyPeriod
146
161
147
162
let minAuctionFeePerDelegate = 2_000_000
148
- at'AuctionFeePerDelegate <- arbitrary @ Integer `suchThat` ( \ x -> x > minAuctionFeePerDelegate)
163
+ at'AuctionFeePerDelegate <- genIntegerGreaterThan minAuctionFeePerDelegate
149
164
150
165
let minStartingBid = at'AuctionFeePerDelegate * fromIntegral (length at'Delegates)
151
- at'StartingBid <- arbitrary @ Integer `suchThat` ( \ x -> x > minStartingBid)
166
+ at'StartingBid <- genIntegerGreaterThan minStartingBid
152
167
153
168
Positive at'MinBidIncrement <- arbitrary @ (Positive Integer )
154
169
NonNegative at'MinDepositAmount <- arbitrary @ (NonNegative Integer )
0 commit comments