Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 'slotRatio' case where the numerator is further than the denominator #234

Merged
merged 1 commit into from
May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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