Skip to content

Commit

Permalink
fix 'slotRatio' case where the numerator is further than the denominator
Browse files Browse the repository at this point in the history
  • Loading branch information
KtorZ committed May 7, 2019
1 parent 1a59d86 commit 377a19e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/core/src/Cardano/Wallet/Primitive/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ slotRatio (SlotId ep0 sl0) (SlotId ep1 sl1) =
n0 = flat ep0 sl0
n1 = flat ep1 sl1
tolerance = 5
in if distance n0 n1 < tolerance then
in if distance n0 n1 < tolerance || n0 >= n1 then
maxBound
else
Quantity $ toEnum $ fromIntegral $ (100 * n0) `div` n1
Expand Down
6 changes: 6 additions & 0 deletions lib/core/test/unit/Cardano/Wallet/Primitive/TypesSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ import Cardano.Wallet.Primitive.Types
, isValidCoin
, restrictedBy
, restrictedTo
, slotRatio
, walletNameMaxLength
, walletNameMinLength
)
import Control.DeepSeq
( deepseq )
import Control.Monad
( replicateM )
import Crypto.Hash
Expand Down Expand Up @@ -138,6 +141,9 @@ spec = do
\ <~ 19999800000 @ DdzFFzCq...UfLEFu1q\n"
=== pretty @_ @Text block

describe "slotRatio" $ do
it "works for any two slots" $ property $ \sl0 sl1 ->
slotRatio sl0 sl1 `deepseq` ()

describe "Negative cases for types decoding" $ do
it "fail fromText @Address \"0000\"" $ do
Expand Down

0 comments on commit 377a19e

Please sign in to comment.