-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate Haskell code for
UpdateNonce
- Loading branch information
1 parent
7a8846b
commit 9302544
Showing
7 changed files
with
93 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,7 @@ open import Data.Nat using (ℕ) | |
OCertCounters : Type | ||
OCertCounters = KeyHashˢ ⇀ ℕ | ||
|
||
Slot = ℕ | ||
Epoch = ℕ | ||
|
||
\end{code} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module Spec.Foreign.HSConsensus where | ||
|
||
open import Spec.Foreign.HSConsensus.TickNonce public | ||
|
||
open import Spec.Foreign.HSConsensus.UpdateNonce public |
27 changes: 27 additions & 0 deletions
27
docs/agda-spec/src/Spec/Foreign/HSConsensus/UpdateNonce.agda
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,27 @@ | ||
module Spec.Foreign.HSConsensus.UpdateNonce where | ||
|
||
open import Spec.Foreign.ExternalFunctions | ||
|
||
open import Foreign.Haskell.Coerce | ||
|
||
open import Spec.Foreign.HSConsensus.BaseTypes | ||
open import Spec.UpdateNonce DummyCrypto DummyNonces DummyEpochStructure | ||
|
||
instance | ||
|
||
HsTy-UpdateNonceEnv = autoHsType UpdateNonceEnv ⊣ withConstructor "MkUpdateNonceEnv" | ||
• fieldPrefix "ue" | ||
Conv-UpdateNonceEnv = autoConvert UpdateNonceEnv | ||
|
||
HsTy-UpdateNonceState = autoHsType UpdateNonceState ⊣ withConstructor "MkUpdateNonceState" | ||
• fieldPrefix "us" | ||
Conv-UpdateNonceState = autoConvert UpdateNonceState | ||
|
||
module _ (ext : ExternalFunctions) where | ||
open ExternalStructures ext hiding (Slot) | ||
open import Spec.UpdateNonce.Properties HSCrypto HSNonces HSEpochStructure | ||
|
||
updn-step : HsType (UpdateNonceEnv → UpdateNonceState → Slot → ComputationResult String UpdateNonceState) | ||
updn-step = to (coerce ⦃ TrustMe ⦄ $ compute Computational-UPDN) | ||
|
||
{-# COMPILE GHC updn-step as updnStep #-} |
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,8 @@ | ||
module Spec.Foreign.Util where | ||
|
||
open import Ledger.Prelude | ||
|
||
postulate | ||
error : {A : Set} → String → A | ||
{-# FOREIGN GHC import Data.Text #-} | ||
{-# COMPILE GHC error = \ _ s -> error (unpack s) #-} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{-# LANGUAGE StandaloneDeriving #-} | ||
{-# OPTIONS -Wno-orphans #-} | ||
module UpdateNonceSpec (spec) where | ||
|
||
import Data.Text | ||
|
||
import Test.Hspec ( Spec, describe, it ) | ||
import Test.HUnit ( (@?=) ) | ||
|
||
import Lib | ||
|
||
initEnv :: UpdateNonceEnv | ||
initEnv = MkUpdateNonceEnv { ueΗ = 2 } | ||
|
||
initState :: UpdateNonceState | ||
initState = MkUpdateNonceState { usΗv = 3, usΗc = 4 } | ||
|
||
slotBeforeWindow :: Slot | ||
slotBeforeWindow = 1 | ||
|
||
testUpdateNonceStepWithSlotBeforeWindow :: ComputationResult Text UpdateNonceState | ||
testUpdateNonceStepWithSlotBeforeWindow = updnStep dummyExternalFunctions initEnv initState slotBeforeWindow | ||
|
||
{- window = 20 | ||
______________ | ||
/ \ | ||
s | ||
+---+---+---+---+---+---+---+---+---+---+---+---+ | ||
0 1 2 ... 99 100 119 ... 199 200 | ||
\___________________/ \___________________/ | ||
epoch 0 epoch 1 | ||
-} | ||
|
||
slotAfterWindow :: Slot | ||
slotAfterWindow = 99 | ||
|
||
testUpdateNonceStepWithSlotAfterWindow :: ComputationResult Text UpdateNonceState | ||
testUpdateNonceStepWithSlotAfterWindow = updnStep dummyExternalFunctions initEnv initState slotAfterWindow | ||
|
||
spec :: Spec | ||
spec = do | ||
describe "updnStep" $ do | ||
it "updnStep results in the expected state with slot before window" $ | ||
testUpdateNonceStepWithSlotBeforeWindow @?= Success (MkUpdateNonceState { usΗv = 3 + 2, usΗc = 3 + 2 }) | ||
it "updnStep results in the expected state with slot after window" $ | ||
testUpdateNonceStepWithSlotAfterWindow @?= Success (MkUpdateNonceState { usΗv = 3 + 2, usΗc = 4 }) |