/
RewardsSpec.hs
119 lines (108 loc) · 3.61 KB
/
RewardsSpec.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Cardano.Wallet.Jormungandr.RewardsSpec
( spec
) where
import Prelude
import Cardano.Wallet.Jormungandr.Rewards
( Ratio (..)
, RewardFormula (..)
, RewardLimit (..)
, RewardParams (..)
, TaxParameters (..)
, rewardsAt
)
import Cardano.Wallet.Primitive.Types
( EpochNo (..) )
import Data.Quantity
( Quantity (..) )
import Test.Hspec
( Spec, describe, it, shouldBe )
import Test.QuickCheck
( Arbitrary (..), choose, property, (===) )
spec :: Spec
spec = describe "rewardsAt" $ do
it "try-out ITN parameters" $ property $ \epochNo ->
let
drawingLimit =
( RewardLimitByAbsoluteStake (Ratio 4109589 10000000000)
, Quantity 10548000000000000
)
treasuryTax = TaxParameters
{ taxFixed = 0
, taxRatio = Ratio 1 10
, taxLimit = Nothing
}
rewardFormula = LinearFormula $ RewardParams
{ rFixed = 3835616440000
, rEpochRate = 1
, rEpochStart = 1
, rRatio = Ratio 0 1
}
in
rewardsAt drawingLimit treasuryTax epochNo rewardFormula
=== Quantity 3452054796000
describe "Halving, C = 10000, ratio = 1/1, estart=10, rate=1" $ do
let rewardFormula = HalvingFormula $ RewardParams
{ rFixed = 10000
, rEpochRate = 1
, rEpochStart = 10
, rRatio = Ratio 1 1
}
mapM_ (testReward noDrawingLimit noTreasuryTax rewardFormula) $ mconcat
[ [ (e, 0) | e <- [0..9] ]
, [ (10, 10000) ]
, [ (11, 10000) ]
, [ (12, 10000) ]
, [ (13, 10000) ]
, [ (14, 10000) ]
]
describe "Linear, C = 10000, ratio = 1000/1, estart=10, rate=2" $ do
let rewardFormula = LinearFormula $ RewardParams
{ rFixed = 10000
, rEpochRate = 2
, rEpochStart = 10
, rRatio = Ratio 1000 1
}
mapM_ (testReward noDrawingLimit noTreasuryTax rewardFormula) $ mconcat
[ [ (e, 0) | e <- [0..9] ]
, [ (10, 10000) ]
, [ (11, 10000) ]
, [ (12, 9000) ]
, [ (13, 9000) ]
, [ (14, 8000) ]
]
describe "Halving, C = 10000, ratio = 1/2, estart=10, rate=2" $ do
let rewardFormula = HalvingFormula $ RewardParams
{ rFixed = 10000
, rEpochRate = 2
, rEpochStart = 10
, rRatio = Ratio 1 2
}
mapM_ (testReward noDrawingLimit noTreasuryTax rewardFormula) $ mconcat
[ [ (e, 0) | e <- [0..9] ]
, [ (10, 10000) ]
, [ (11, 10000) ]
, [ (12, 5000) ]
, [ (13, 5000) ]
, [ (14, 2500) ]
]
where
testReward drawingLimit treasuryTax rewardFormula (epochNo, reward) =
it title $
rewardsAt drawingLimit treasuryTax epochNo rewardFormula
`shouldBe` Quantity reward
where
title = "epoch #" <> show (unEpochNo epochNo) <> " --> " <> show reward
noDrawingLimit =
( RewardLimitNone
, Quantity 0
)
noTreasuryTax = TaxParameters
{ taxFixed = 0
, taxRatio = Ratio 0 1
, taxLimit = Nothing
}
instance Arbitrary EpochNo where
arbitrary = EpochNo . fromIntegral @Int <$> choose (0, 1000)