-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3209: Light Mode: currentCardanoEra r=Unisay a=Unisay - [x] I have tested Epoch/Era translation in REPL manually. - [x] wrote unit test for the Epoch/Era translation. ### Comments Blockfrost API doesn't expose current Era so its implemented as a translation from current epoch number using a hardcoded table. ``` ┌───────┬───────┬─────────┐ │ Epoch │ Major │ Era │ ├───────┼───────┼─────────┤ │ ... │ 6 │ Alonzo │ │ 298 │ 6 │ Alonzo │ ├───────┼───────┼─────────┤ │ 297 │ 5 │ Alonzo │ │ ... │ 5 │ Alonzo │ │ 290 │ 5 │ Alonzo │ ├───────┼───────┼─────────┤ │ 289 │ 4 │ Mary │ │ ... │ 4 │ Mary │ │ 251 │ 4 │ Mary │ ├───────┼───────┼─────────┤ │ 250 │ 3 │ Allegra │ │ ... │ 3 │ Allegra │ │ 236 │ 3 │ Allegra │ ├───────┼───────┼─────────┤ │ 235 │ 2 │ Shelley │ │ ... │ 2 │ Shelley │ │ 202 │ 2 │ Shelley │ ├───────┼───────┼─────────┤ │ 201 │ 1 │ Byron │ │ ... │ 1 │ Byron │ └───────┴───────┴─────────┘ ``` When new era type is added its expected that compiler emits a warning about non-exhaustive pattern match, thus forcing developer to update translation table with the corresponding epoch number; ### Issue Number ADP-1504 Co-authored-by: Yuriy Lazaryev <[email protected]> Co-authored-by: IOHK <[email protected]>
- Loading branch information
Showing
5 changed files
with
134 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
lib/shelley/test/unit/Cardano/Wallet/Shelley/Network/BlockfrostSpec.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module Cardano.Wallet.Shelley.Network.BlockfrostSpec (spec) where | ||
|
||
import Prelude | ||
|
||
import Cardano.Api | ||
( AnyCardanoEra (..), CardanoEra (..), NetworkId (Mainnet) ) | ||
import Cardano.Wallet.Primitive.Types | ||
( EpochNo ) | ||
import Cardano.Wallet.Shelley.Network.Blockfrost | ||
( eraByEpoch ) | ||
import Data.Foldable | ||
( for_ ) | ||
import Test.Hspec | ||
( Spec, describe, it, shouldBe ) | ||
|
||
spec :: Spec | ||
spec = describe "Blockfrost Network" $ do | ||
it "determines era by epoch" $ do | ||
for_ epochEras $ \(epoch, era) -> | ||
eraByEpoch Mainnet epoch `shouldBe` Right era | ||
where | ||
epochEras :: [(EpochNo, AnyCardanoEra)] | ||
epochEras = | ||
[ (329, AnyCardanoEra AlonzoEra) | ||
, (298, AnyCardanoEra AlonzoEra) | ||
, (297, AnyCardanoEra AlonzoEra) | ||
, (295, AnyCardanoEra AlonzoEra) | ||
, (290, AnyCardanoEra AlonzoEra) | ||
, (289, AnyCardanoEra MaryEra) | ||
, (260, AnyCardanoEra MaryEra) | ||
, (251, AnyCardanoEra MaryEra) | ||
, (250, AnyCardanoEra AllegraEra) | ||
, (240, AnyCardanoEra AllegraEra) | ||
, (236, AnyCardanoEra AllegraEra) | ||
, (235, AnyCardanoEra ShelleyEra) | ||
, (220, AnyCardanoEra ShelleyEra) | ||
, (202, AnyCardanoEra ShelleyEra) | ||
, (201, AnyCardanoEra ByronEra) | ||
, (001, AnyCardanoEra ByronEra) | ||
, (000, AnyCardanoEra ByronEra) | ||
] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.