@@ -14,6 +14,7 @@ module Test.Cardano.Db.Mock.Validate (
14
14
assertTxInCount ,
15
15
assertUnspentTx ,
16
16
assertRewardCount ,
17
+ assertInstantRewardCount ,
17
18
assertBlockNoBackoff ,
18
19
assertBlockNoBackoffTimes ,
19
20
assertEqQuery ,
@@ -79,7 +80,7 @@ import Database.Esqueleto.Legacy (
79
80
(==.) ,
80
81
(^.) ,
81
82
)
82
- import Database.Persist.Sql (Entity , SqlBackend , entityVal )
83
+ import Database.Persist.Sql (Entity , SqlBackend )
83
84
import Database.PostgreSQL.Simple (SqlError (.. ))
84
85
import Ouroboros.Consensus.Cardano.Block
85
86
import Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock )
@@ -112,6 +113,10 @@ assertRewardCount :: DBSyncEnv -> Word64 -> IO ()
112
113
assertRewardCount env n =
113
114
assertEqBackoff env queryRewardCount n defaultDelays " Unexpected rewards count"
114
115
116
+ assertInstantRewardCount :: DBSyncEnv -> Word64 -> IO ()
117
+ assertInstantRewardCount env n =
118
+ assertEqBackoff env queryInstantRewardCount n defaultDelays " Unexpected instant rewards count"
119
+
115
120
assertBlockNoBackoff :: DBSyncEnv -> Int -> IO ()
116
121
assertBlockNoBackoff = assertBlockNoBackoffTimes defaultDelays
117
122
@@ -242,7 +247,7 @@ assertRewardCounts env st filterAddr mEpoch expected = do
242
247
expectedMap :: Map ByteString (Word64 , Word64 , Word64 , Word64 , Word64 )
243
248
expectedMap = Map. fromList $ fmap (first mkDBStakeAddress) expected
244
249
245
- groupByAddress :: [(Reward , ByteString )] -> Map ByteString (Word64 , Word64 , Word64 , Word64 , Word64 )
250
+ groupByAddress :: [(RewardSource , ByteString )] -> Map ByteString (Word64 , Word64 , Word64 , Word64 , Word64 )
246
251
groupByAddress rewards =
247
252
let res = foldr updateMap Map. empty rewards
248
253
in if filterAddr
@@ -255,39 +260,46 @@ assertRewardCounts env st filterAddr mEpoch expected = do
255
260
Right cred -> Ledger. serialiseRewardAcnt $ Ledger. RewardAcnt Testnet cred
256
261
257
262
updateAddrCounters ::
258
- Reward ->
263
+ RewardSource ->
259
264
Maybe (Word64 , Word64 , Word64 , Word64 , Word64 ) ->
260
265
(Word64 , Word64 , Word64 , Word64 , Word64 )
261
- updateAddrCounters reward Nothing = updateCounters reward (0 , 0 , 0 , 0 , 0 )
262
- updateAddrCounters reward (Just cs) = updateCounters reward cs
266
+ updateAddrCounters rs Nothing = updateCounters rs (0 , 0 , 0 , 0 , 0 )
267
+ updateAddrCounters rs (Just cs) = updateCounters rs cs
263
268
264
269
updateCounters ::
265
- Reward ->
270
+ RewardSource ->
266
271
(Word64 , Word64 , Word64 , Word64 , Word64 ) ->
267
272
(Word64 , Word64 , Word64 , Word64 , Word64 )
268
- updateCounters reward (a, b, c, d, e) = case rewardType reward of
273
+ updateCounters rs (a, b, c, d, e) = case rs of
269
274
RwdLeader -> (a + 1 , b, c, d, e)
270
275
RwdMember -> (a, b + 1 , c, d, e)
271
276
RwdReserves -> (a, b, c + 1 , d, e)
272
277
RwdTreasury -> (a, b, c, d + 1 , e)
273
278
RwdDepositRefund -> (a, b, c, d, e + 1 )
274
279
275
280
updateMap ::
276
- (Reward , ByteString ) ->
281
+ (RewardSource , ByteString ) ->
277
282
Map ByteString (Word64 , Word64 , Word64 , Word64 , Word64 ) ->
278
283
Map ByteString (Word64 , Word64 , Word64 , Word64 , Word64 )
279
- updateMap (rew , addr) = Map. alter (Just . updateAddrCounters rew ) addr
284
+ updateMap (rs , addr) = Map. alter (Just . updateAddrCounters rs ) addr
280
285
281
286
filterEpoch rw = case mEpoch of
282
287
Nothing -> val True
283
288
Just e -> rw ^. RewardSpendableEpoch ==. val e
289
+ filterEpoch' rw = case mEpoch of
290
+ Nothing -> val True
291
+ Just e -> rw ^. InstantRewardSpendableEpoch ==. val e
284
292
285
293
q = do
286
- res <- select . from $ \ (reward `InnerJoin ` stake_addr) -> do
294
+ res1 <- select . from $ \ (reward `InnerJoin ` stake_addr) -> do
287
295
on (reward ^. RewardAddrId ==. stake_addr ^. StakeAddressId )
288
296
where_ (filterEpoch reward)
289
- pure (reward, stake_addr ^. StakeAddressHashRaw )
290
- pure $ fmap (bimap entityVal unValue) res
297
+ pure (reward ^. RewardType , stake_addr ^. StakeAddressHashRaw )
298
+ res2 <- select . from $ \ (ireward `InnerJoin ` stake_addr) -> do
299
+ on (ireward ^. InstantRewardAddrId ==. stake_addr ^. StakeAddressId )
300
+ where_ (filterEpoch' ireward)
301
+ pure (ireward ^. InstantRewardType , stake_addr ^. StakeAddressHashRaw )
302
+ pure $ fmap (bimap unValue unValue) (res1 <> res2)
291
303
292
304
assertEpochStake :: DBSyncEnv -> Word64 -> IO ()
293
305
assertEpochStake env expected =
0 commit comments