{-# LANGUAGE OverloadedRecordDot #-} {-# OPTIONS_GHC -Wno-ambiguous-fields #-} module Hydra.HeadLogic.SnapshotOwnerSpec (spec) where import Hydra.HeadLogic.Program (reject) import Hydra.HeadLogic.Rules.Coordinated qualified as Staging import Hydra.HeadLogic.Rules.Network.AckSn qualified as AckSn import Hydra.Prelude import Test.Hydra.HeadLogic.Interpreter (testInterpreterConfig) import Test.Hydra.HeadLogic.Validated (checkedSnapshot) import Test.Hydra.Prelude (Spec, describe, it, shouldBe, shouldSatisfy) import Cardano.Binary (decodeFull', serialize') import Codec.CBOR.Write (toStrictByteString) import Control.Monad (foldM) import Crem.Topology (Topology (Topology)) import Data.Aeson (eitherDecode, encode, object, (.=)) import Data.Map.Strict qualified as Map import Hydra.Agda.OffChainReference qualified as Agda import Hydra.HeadLogic.Error (LogicError (AssertionFailed, RequireFailed), RequirementFailure (InvalidMultisignature)) import Hydra.HeadLogic.Interpreter qualified as Interpreter import Hydra.HeadLogic.Outcome (Outcome (Continue, Error), StateChanged (DecommitFinalized, PartySignedSnapshot, SnapshotConfirmed, SnapshotRequestDecided, SnapshotRequested)) import Hydra.HeadLogic.Program qualified as Program import Hydra.HeadLogic.Snapshot.Cached qualified as Cached import Hydra.HeadLogic.Snapshot.Verification (verifyCandidate, verifySeenSnapshot) import Hydra.HeadLogic.State (CoordinatedHeadState (..), HeadState (Open), OpenState (..), SeenSnapshot (RequestedSnapshot, SeenSnapshot, cachedSnapshot, signatories), mkSeenSnapshot) import Hydra.HeadLogic.State.Coordinated qualified as Owner import Hydra.HeadLogic.State.Coordinated.Snapshots.Topology (SnapshotPhase, snapshotTopology) import Hydra.HeadLogic.Workflow qualified as Workflow import Hydra.Ledger.Simple (SimpleChainState (SimpleChainState), SimpleTx (..), simpleLedger) import Hydra.Network.Message (Message (AckSn), NetworkEvent (ReceivedMessage)) import Hydra.Node.HeadLogic qualified as Head import Hydra.Node.State (NodeState (..), initialChainTime) import Hydra.Tx.Accumulator qualified as Accumulator import Hydra.Tx.Crypto (MultiSignature, aggregateInOrder, getSignableRepresentation, sign) import Hydra.Tx.HeadId (HeadId (UnsafeHeadId)) import Hydra.Tx.HeadParameters (HeadParameters (parties)) import Hydra.Tx.Party (Party (vkey)) import Hydra.Tx.Snapshot (ConfirmedSnapshot (ConfirmedSnapshot), Snapshot (..)) import Hydra.Tx.Snapshot qualified as Snapshot import System.Mem.StableName (makeStableName) import Test.Hydra.HeadLogic.DecommitSequences qualified as Sequences import Test.Hydra.HeadLogic.Scenario qualified as Scenario import Test.Hydra.Ledger.Simple (utxoRef) import Test.Hydra.Tx.Fixture (alice, aliceSk, bob, bobSk, carol, carolSk) spec :: Spec spec :: Spec spec = String -> Spec -> Spec forall a. HasCallStack => String -> SpecWith a -> SpecWith a describe String "live snapshot ownership" (Spec -> Spec) -> Spec -> Spec forall a b. (a -> b) -> a -> b $ do String -> IO () -> SpecWith (Arg (IO ())) forall a. (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) it String "checks 960 decommit, acknowledgement and rollback schedules at all three parties" (IO () -> SpecWith (Arg (IO ()))) -> IO () -> SpecWith (Arg (IO ())) forall a b. (a -> b) -> a -> b $ do [Schedule] -> Int forall a. [a] -> Int forall (t :: * -> *) a. Foldable t => t a -> Int length [Schedule] Sequences.schedules Int -> Int -> IO () forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO () `shouldBe` Int 960 [Schedule] -> (Schedule -> IO ()) -> IO () forall (t :: * -> *) (m :: * -> *) a b. (Foldable t, Monad m) => t a -> (a -> m b) -> m () forM_ [Schedule] Sequences.schedules ((Schedule -> IO ()) -> IO ()) -> (Schedule -> IO ()) -> IO () forall a b. (a -> b) -> a -> b $ \Schedule schedule -> (Text -> IO ()) -> ([Step] -> IO ()) -> Either Text [Step] -> IO () forall a c b. (a -> c) -> (b -> c) -> Either a b -> c either (String -> IO () forall a. String -> IO a forall (m :: * -> *) a. MonadFail m => String -> m a fail (String -> IO ()) -> (Text -> String) -> Text -> IO () forall b c a. (b -> c) -> (a -> b) -> a -> c . Text -> String forall a. ToString a => a -> String toString) (IO () -> [Step] -> IO () forall a b. a -> b -> a const (IO () -> [Step] -> IO ()) -> IO () -> [Step] -> IO () forall a b. (a -> b) -> a -> b $ () -> IO () forall a. a -> IO a forall (f :: * -> *) a. Applicative f => a -> f a pure ()) (Either Text [Step] -> IO ()) -> Either Text [Step] -> IO () forall a b. (a -> b) -> a -> b $ Schedule -> Either Text [Step] Sequences.runSchedule Schedule schedule String -> IO () -> SpecWith (Arg (IO ())) forall a. (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) it String "admits the next follower candidate and refuses replacement while collecting" (IO () -> SpecWith (Arg (IO ()))) -> IO () -> SpecWith (Arg (IO ())) forall a b. (a -> b) -> a -> b $ do let command :: Command SimpleTx command = ValidatedSnapshot SimpleTx -> Seq SimpleTx -> Command SimpleTx forall tx. ValidatedSnapshot tx -> Seq tx -> Command tx Owner.acceptSnapshot (Snapshot SimpleTx -> ValidatedSnapshot SimpleTx checkedSnapshot Snapshot SimpleTx snapshot) Seq SimpleTx forall a. Monoid a => a mempty Program SimpleTx () -> Outcome SimpleTx run (Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx () forall (f :: * -> *) a. Functor f => f a -> f () void (Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx ()) -> Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx () forall a b. (a -> b) -> a -> b $ Runtime SimpleTx -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall tx. Runtime tx -> Command tx -> Program tx (Runtime tx) Staging.stage Runtime SimpleTx initial Command SimpleTx command) Outcome SimpleTx -> Outcome SimpleTx -> IO () forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO () `shouldBe` [StateChanged SimpleTx] -> [Effect SimpleTx] -> Outcome SimpleTx forall tx. [StateChanged tx] -> [Effect tx] -> Outcome tx Continue [Snapshot SimpleTx -> Seq SimpleTx -> Maybe (TxIdType SimpleTx) -> StateChanged SimpleTx forall tx. Snapshot tx -> Seq tx -> Maybe (TxIdType tx) -> StateChanged tx SnapshotRequested Snapshot SimpleTx snapshot Seq SimpleTx forall a. Monoid a => a mempty Maybe Integer Maybe (TxIdType SimpleTx) forall a. Maybe a Nothing] [] [Snapshot SimpleTx] -> (Snapshot SimpleTx -> IO ()) -> IO () forall (t :: * -> *) (m :: * -> *) a b. (Foldable t, Monad m) => t a -> (a -> m b) -> m () forM_ [Snapshot SimpleTx snapshot, Snapshot SimpleTx different, Snapshot SimpleTx snapshot{number = 2}] ((Snapshot SimpleTx -> IO ()) -> IO ()) -> (Snapshot SimpleTx -> IO ()) -> IO () forall a b. (a -> b) -> a -> b $ \Snapshot SimpleTx replacement -> Program SimpleTx () -> Outcome SimpleTx run (Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx () forall (f :: * -> *) a. Functor f => f a -> f () void (Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx ()) -> Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx () forall a b. (a -> b) -> a -> b $ Runtime SimpleTx -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall tx. Runtime tx -> Command tx -> Program tx (Runtime tx) Staging.stage Runtime SimpleTx collecting (Command SimpleTx -> Program SimpleTx (Runtime SimpleTx)) -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall a b. (a -> b) -> a -> b $ ValidatedSnapshot SimpleTx -> Seq SimpleTx -> Command SimpleTx forall tx. ValidatedSnapshot tx -> Seq tx -> Command tx Owner.acceptSnapshot (Snapshot SimpleTx -> ValidatedSnapshot SimpleTx checkedSnapshot Snapshot SimpleTx replacement) Seq SimpleTx forall a. Monoid a => a mempty) Outcome SimpleTx -> (Outcome SimpleTx -> Bool) -> IO () forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO () `shouldSatisfy` Outcome SimpleTx -> Bool refused String -> IO () -> SpecWith (Arg (IO ())) forall a. (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) it String "refuses a foreign Head, wrong version, skipped round or conflicting request marker" (IO () -> SpecWith (Arg (IO ()))) -> IO () -> SpecWith (Arg (IO ())) forall a b. (a -> b) -> a -> b $ do [Snapshot SimpleTx] -> (Snapshot SimpleTx -> IO ()) -> IO () forall (t :: * -> *) (m :: * -> *) a b. (Foldable t, Monad m) => t a -> (a -> m b) -> m () forM_ ([Snapshot SimpleTx snapshot{Snapshot.headId = UnsafeHeadId "other"}, Snapshot SimpleTx snapshot{Snapshot.version = 1}, Snapshot SimpleTx snapshot{number = 2}] :: [Snapshot SimpleTx]) ((Snapshot SimpleTx -> IO ()) -> IO ()) -> (Snapshot SimpleTx -> IO ()) -> IO () forall a b. (a -> b) -> a -> b $ \Snapshot SimpleTx invalid -> Program SimpleTx () -> Outcome SimpleTx run (Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx () forall (f :: * -> *) a. Functor f => f a -> f () void (Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx ()) -> Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx () forall a b. (a -> b) -> a -> b $ Runtime SimpleTx -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall tx. Runtime tx -> Command tx -> Program tx (Runtime tx) Staging.stage Runtime SimpleTx initial (Command SimpleTx -> Program SimpleTx (Runtime SimpleTx)) -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall a b. (a -> b) -> a -> b $ ValidatedSnapshot SimpleTx -> Seq SimpleTx -> Command SimpleTx forall tx. ValidatedSnapshot tx -> Seq tx -> Command tx Owner.acceptSnapshot (Snapshot SimpleTx -> ValidatedSnapshot SimpleTx checkedSnapshot Snapshot SimpleTx invalid) Seq SimpleTx forall a. Monoid a => a mempty) Outcome SimpleTx -> (Outcome SimpleTx -> Bool) -> IO () forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO () `shouldSatisfy` Outcome SimpleTx -> Bool refused let requested :: Runtime SimpleTx requested = UTxOType SimpleTx -> StateChanged SimpleTx -> Runtime SimpleTx -> Runtime SimpleTx forall tx. IsChainState tx => UTxOType tx -> StateChanged tx -> Runtime tx -> Runtime tx Owner.replayEvent Set SimpleTxOut UTxOType SimpleTx forall a. Monoid a => a mempty (SnapshotNumber -> StateChanged SimpleTx forall tx. SnapshotNumber -> StateChanged tx SnapshotRequestDecided SnapshotNumber 2) Runtime SimpleTx initial Program SimpleTx () -> Outcome SimpleTx run (Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx () forall (f :: * -> *) a. Functor f => f a -> f () void (Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx ()) -> Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx () forall a b. (a -> b) -> a -> b $ Runtime SimpleTx -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall tx. Runtime tx -> Command tx -> Program tx (Runtime tx) Staging.stage Runtime SimpleTx requested (Command SimpleTx -> Program SimpleTx (Runtime SimpleTx)) -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall a b. (a -> b) -> a -> b $ ValidatedSnapshot SimpleTx -> Seq SimpleTx -> Command SimpleTx forall tx. ValidatedSnapshot tx -> Seq tx -> Command tx Owner.acceptSnapshot (Snapshot SimpleTx -> ValidatedSnapshot SimpleTx checkedSnapshot Snapshot SimpleTx snapshot) Seq SimpleTx forall a. Monoid a => a mempty) Outcome SimpleTx -> (Outcome SimpleTx -> Bool) -> IO () forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO () `shouldSatisfy` Outcome SimpleTx -> Bool refused String -> IO () -> SpecWith (Arg (IO ())) forall a. (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) it String "binds signature recording to candidate content, version and number" (IO () -> SpecWith (Arg (IO ()))) -> IO () -> SpecWith (Arg (IO ())) forall a b. (a -> b) -> a -> b $ [Snapshot SimpleTx] -> (Snapshot SimpleTx -> IO ()) -> IO () forall (t :: * -> *) (m :: * -> *) a b. (Foldable t, Monad m) => t a -> (a -> m b) -> m () forM_ ([Snapshot SimpleTx different, Snapshot SimpleTx snapshot{Snapshot.version = 1}, Snapshot SimpleTx snapshot{number = 2}] :: [Snapshot SimpleTx]) ((Snapshot SimpleTx -> IO ()) -> IO ()) -> (Snapshot SimpleTx -> IO ()) -> IO () forall a b. (a -> b) -> a -> b $ \Snapshot SimpleTx other -> do let stale :: Candidate SimpleTx stale = Runtime SimpleTx -> Candidate SimpleTx owned (Runtime SimpleTx -> Candidate SimpleTx) -> Runtime SimpleTx -> Candidate SimpleTx forall a b. (a -> b) -> a -> b $ Snapshot SimpleTx -> Runtime SimpleTx owner Snapshot SimpleTx other program :: Program SimpleTx () program = do Runtime SimpleTx staged <- Runtime SimpleTx -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall tx. Runtime tx -> Command tx -> Program tx (Runtime tx) Staging.stage Runtime SimpleTx collecting (Command SimpleTx -> Program SimpleTx (Runtime SimpleTx)) -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall a b. (a -> b) -> a -> b $ Candidate SimpleTx -> Party -> Signature (Snapshot SimpleTx) -> Command SimpleTx forall tx. Candidate tx -> Party -> Signature (Snapshot tx) -> Command tx Owner.recordSignature (Runtime SimpleTx -> Candidate SimpleTx owned Runtime SimpleTx collecting) Party alice (Secret (SigningKey HydraKey) -> Snapshot SimpleTx -> Signature (Snapshot SimpleTx) forall a. SignableRepresentation a => Secret (SigningKey HydraKey) -> a -> Signature a sign Secret (SigningKey HydraKey) aliceSk Snapshot SimpleTx snapshot) Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx () forall (f :: * -> *) a. Functor f => f a -> f () void (Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx ()) -> Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx () forall a b. (a -> b) -> a -> b $ Runtime SimpleTx -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall tx. Runtime tx -> Command tx -> Program tx (Runtime tx) Staging.stage Runtime SimpleTx staged (Command SimpleTx -> Program SimpleTx (Runtime SimpleTx)) -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall a b. (a -> b) -> a -> b $ Candidate SimpleTx -> Party -> Signature (Snapshot SimpleTx) -> Command SimpleTx forall tx. Candidate tx -> Party -> Signature (Snapshot tx) -> Command tx Owner.recordSignature Candidate SimpleTx stale Party bob (Secret (SigningKey HydraKey) -> Snapshot SimpleTx -> Signature (Snapshot SimpleTx) forall a. SignableRepresentation a => Secret (SigningKey HydraKey) -> a -> Signature a sign Secret (SigningKey HydraKey) bobSk Snapshot SimpleTx other) Program SimpleTx () -> Outcome SimpleTx run Program SimpleTx () program Outcome SimpleTx -> (Outcome SimpleTx -> Bool) -> IO () forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO () `shouldSatisfy` Outcome SimpleTx -> Bool refused String -> IO () -> SpecWith (Arg (IO ())) forall a. (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) it String "refuses a replacement signature and discards the attempt's staged prefix" (IO () -> SpecWith (Arg (IO ()))) -> IO () -> SpecWith (Arg (IO ())) forall a b. (a -> b) -> a -> b $ do let program :: Program.Program SimpleTx () program :: Program SimpleTx () program = do Runtime SimpleTx staged <- Runtime SimpleTx -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall tx. Runtime tx -> Command tx -> Program tx (Runtime tx) Staging.stage Runtime SimpleTx collecting (Command SimpleTx -> Program SimpleTx (Runtime SimpleTx)) -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall a b. (a -> b) -> a -> b $ Candidate SimpleTx -> Party -> Signature (Snapshot SimpleTx) -> Command SimpleTx forall tx. Candidate tx -> Party -> Signature (Snapshot tx) -> Command tx Owner.recordSignature (Runtime SimpleTx -> Candidate SimpleTx owned Runtime SimpleTx collecting) Party alice (Secret (SigningKey HydraKey) -> Snapshot SimpleTx -> Signature (Snapshot SimpleTx) forall a. SignableRepresentation a => Secret (SigningKey HydraKey) -> a -> Signature a sign Secret (SigningKey HydraKey) aliceSk Snapshot SimpleTx snapshot) Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx () forall (f :: * -> *) a. Functor f => f a -> f () void (Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx ()) -> Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx () forall a b. (a -> b) -> a -> b $ Runtime SimpleTx -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall tx. Runtime tx -> Command tx -> Program tx (Runtime tx) Staging.stage Runtime SimpleTx staged (Command SimpleTx -> Program SimpleTx (Runtime SimpleTx)) -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall a b. (a -> b) -> a -> b $ Candidate SimpleTx -> Party -> Signature (Snapshot SimpleTx) -> Command SimpleTx forall tx. Candidate tx -> Party -> Signature (Snapshot tx) -> Command tx Owner.recordSignature (Runtime SimpleTx -> Candidate SimpleTx owned Runtime SimpleTx staged) Party alice (Secret (SigningKey HydraKey) -> Snapshot SimpleTx -> Signature (Snapshot SimpleTx) forall a. SignableRepresentation a => Secret (SigningKey HydraKey) -> a -> Signature a sign Secret (SigningKey HydraKey) aliceSk Snapshot SimpleTx different) Program SimpleTx () -> Outcome SimpleTx run Program SimpleTx () program Outcome SimpleTx -> (Outcome SimpleTx -> Bool) -> IO () forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO () `shouldSatisfy` Outcome SimpleTx -> Bool refused String -> IO () -> SpecWith (Arg (IO ())) forall a. (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) it String "refuses stale confirmation evidence even after staging a current signature" (IO () -> SpecWith (Arg (IO ()))) -> IO () -> SpecWith (Arg (IO ())) forall a b. (a -> b) -> a -> b $ do let program :: Program.Program SimpleTx () program :: Program SimpleTx () program = do VerifiedCandidate SimpleTx evidence <- Candidate SimpleTx -> MultiSignature (Snapshot SimpleTx) -> Program SimpleTx (Either (LogicError SimpleTx) (VerifiedCandidate SimpleTx)) forall tx. Candidate tx -> MultiSignature (Snapshot tx) -> Program tx (Either (LogicError tx) (VerifiedCandidate tx)) verifyCandidate (Runtime SimpleTx -> Candidate SimpleTx owned (Runtime SimpleTx -> Candidate SimpleTx) -> Runtime SimpleTx -> Candidate SimpleTx forall a b. (a -> b) -> a -> b $ Snapshot SimpleTx -> Runtime SimpleTx owner Snapshot SimpleTx different) (Snapshot SimpleTx -> MultiSignature (Snapshot SimpleTx) signatures Snapshot SimpleTx different) Program SimpleTx (Either (LogicError SimpleTx) (VerifiedCandidate SimpleTx)) -> (Either (LogicError SimpleTx) (VerifiedCandidate SimpleTx) -> Program SimpleTx (VerifiedCandidate SimpleTx)) -> Program SimpleTx (VerifiedCandidate SimpleTx) forall a b. Program SimpleTx a -> (a -> Program SimpleTx b) -> Program SimpleTx b forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b >>= (LogicError SimpleTx -> Program SimpleTx (VerifiedCandidate SimpleTx)) -> (VerifiedCandidate SimpleTx -> Program SimpleTx (VerifiedCandidate SimpleTx)) -> Either (LogicError SimpleTx) (VerifiedCandidate SimpleTx) -> Program SimpleTx (VerifiedCandidate SimpleTx) forall a c b. (a -> c) -> (b -> c) -> Either a b -> c either LogicError SimpleTx -> Program SimpleTx (VerifiedCandidate SimpleTx) forall tx a. LogicError tx -> Program tx a reject VerifiedCandidate SimpleTx -> Program SimpleTx (VerifiedCandidate SimpleTx) forall a. a -> Program SimpleTx a forall (f :: * -> *) a. Applicative f => a -> f a pure Runtime SimpleTx staged <- Runtime SimpleTx -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall tx. Runtime tx -> Command tx -> Program tx (Runtime tx) Staging.stage Runtime SimpleTx collecting (Command SimpleTx -> Program SimpleTx (Runtime SimpleTx)) -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall a b. (a -> b) -> a -> b $ Candidate SimpleTx -> Party -> Signature (Snapshot SimpleTx) -> Command SimpleTx forall tx. Candidate tx -> Party -> Signature (Snapshot tx) -> Command tx Owner.recordSignature (Runtime SimpleTx -> Candidate SimpleTx owned Runtime SimpleTx collecting) Party alice (Secret (SigningKey HydraKey) -> Snapshot SimpleTx -> Signature (Snapshot SimpleTx) forall a. SignableRepresentation a => Secret (SigningKey HydraKey) -> a -> Signature a sign Secret (SigningKey HydraKey) aliceSk Snapshot SimpleTx snapshot) Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx () forall (f :: * -> *) a. Functor f => f a -> f () void (Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx ()) -> Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx () forall a b. (a -> b) -> a -> b $ Runtime SimpleTx -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall tx. Runtime tx -> Command tx -> Program tx (Runtime tx) Staging.stage Runtime SimpleTx staged (Command SimpleTx -> Program SimpleTx (Runtime SimpleTx)) -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall a b. (a -> b) -> a -> b $ VerifiedCandidate SimpleTx -> Command SimpleTx forall tx. VerifiedCandidate tx -> Command tx Owner.confirmSnapshot VerifiedCandidate SimpleTx evidence Program SimpleTx () -> Outcome SimpleTx run Program SimpleTx () program Outcome SimpleTx -> (Outcome SimpleTx -> Bool) -> IO () forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO () `shouldSatisfy` Outcome SimpleTx -> Bool refused String -> IO () -> SpecWith (Arg (IO ())) forall a. (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) it String "keeps a candidate handle valid when settlement precedes its final acknowledgement" (IO () -> SpecWith (Arg (IO ()))) -> IO () -> SpecWith (Arg (IO ())) forall a b. (a -> b) -> a -> b $ do let ownedCandidate :: Candidate SimpleTx ownedCandidate = Runtime SimpleTx -> Candidate SimpleTx owned Runtime SimpleTx collecting program :: Program.Program SimpleTx () program :: Program SimpleTx () program = do Runtime SimpleTx settled <- Runtime SimpleTx -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall tx. Runtime tx -> Command tx -> Program tx (Runtime tx) Staging.stage Runtime SimpleTx collecting (Command SimpleTx -> Program SimpleTx (Runtime SimpleTx)) -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall a b. (a -> b) -> a -> b $ ChainStateType SimpleTx -> SnapshotVersion -> UTxOType SimpleTx -> Command SimpleTx forall tx. ChainStateType tx -> SnapshotVersion -> UTxOType tx -> Command tx Owner.recordDecommitFinalization (ChainSlot -> SimpleChainState SimpleChainState ChainSlot 2) SnapshotVersion 1 Set SimpleTxOut UTxOType SimpleTx forall a. Monoid a => a mempty VerifiedCandidate SimpleTx evidence <- Candidate SimpleTx -> MultiSignature (Snapshot SimpleTx) -> Program SimpleTx (Either (LogicError SimpleTx) (VerifiedCandidate SimpleTx)) forall tx. Candidate tx -> MultiSignature (Snapshot tx) -> Program tx (Either (LogicError tx) (VerifiedCandidate tx)) verifyCandidate Candidate SimpleTx ownedCandidate (Snapshot SimpleTx -> MultiSignature (Snapshot SimpleTx) signatures Snapshot SimpleTx snapshot) Program SimpleTx (Either (LogicError SimpleTx) (VerifiedCandidate SimpleTx)) -> (Either (LogicError SimpleTx) (VerifiedCandidate SimpleTx) -> Program SimpleTx (VerifiedCandidate SimpleTx)) -> Program SimpleTx (VerifiedCandidate SimpleTx) forall a b. Program SimpleTx a -> (a -> Program SimpleTx b) -> Program SimpleTx b forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b >>= (LogicError SimpleTx -> Program SimpleTx (VerifiedCandidate SimpleTx)) -> (VerifiedCandidate SimpleTx -> Program SimpleTx (VerifiedCandidate SimpleTx)) -> Either (LogicError SimpleTx) (VerifiedCandidate SimpleTx) -> Program SimpleTx (VerifiedCandidate SimpleTx) forall a c b. (a -> c) -> (b -> c) -> Either a b -> c either LogicError SimpleTx -> Program SimpleTx (VerifiedCandidate SimpleTx) forall tx a. LogicError tx -> Program tx a reject VerifiedCandidate SimpleTx -> Program SimpleTx (VerifiedCandidate SimpleTx) forall a. a -> Program SimpleTx a forall (f :: * -> *) a. Applicative f => a -> f a pure Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx () forall (f :: * -> *) a. Functor f => f a -> f () void (Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx ()) -> Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx () forall a b. (a -> b) -> a -> b $ Runtime SimpleTx -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall tx. Runtime tx -> Command tx -> Program tx (Runtime tx) Staging.stage Runtime SimpleTx settled (Command SimpleTx -> Program SimpleTx (Runtime SimpleTx)) -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall a b. (a -> b) -> a -> b $ VerifiedCandidate SimpleTx -> Command SimpleTx forall tx. VerifiedCandidate tx -> Command tx Owner.confirmSnapshot VerifiedCandidate SimpleTx evidence Program SimpleTx () -> Outcome SimpleTx run Program SimpleTx () program Outcome SimpleTx -> (Outcome SimpleTx -> Bool) -> IO () forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO () `shouldSatisfy` \case Continue [DecommitFinalized{}, SnapshotConfirmed{}] [] -> Bool True Outcome SimpleTx _ -> Bool False String -> IO () -> SpecWith (Arg (IO ())) forall a. (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) it String "retires a confirmed candidate and exposes the next round's candidate" (IO () -> SpecWith (Arg (IO ()))) -> IO () -> SpecWith (Arg (IO ())) forall a b. (a -> b) -> a -> b $ do let nextSnapshot :: Snapshot SimpleTx nextSnapshot = Snapshot SimpleTx snapshot{number = 2} program :: Program.Program SimpleTx () program :: Program SimpleTx () program = do VerifiedCandidate SimpleTx firstEvidence <- Candidate SimpleTx -> MultiSignature (Snapshot SimpleTx) -> Program SimpleTx (Either (LogicError SimpleTx) (VerifiedCandidate SimpleTx)) forall tx. Candidate tx -> MultiSignature (Snapshot tx) -> Program tx (Either (LogicError tx) (VerifiedCandidate tx)) verifyCandidate (Runtime SimpleTx -> Candidate SimpleTx owned Runtime SimpleTx collecting) (Snapshot SimpleTx -> MultiSignature (Snapshot SimpleTx) signatures Snapshot SimpleTx snapshot) Program SimpleTx (Either (LogicError SimpleTx) (VerifiedCandidate SimpleTx)) -> (Either (LogicError SimpleTx) (VerifiedCandidate SimpleTx) -> Program SimpleTx (VerifiedCandidate SimpleTx)) -> Program SimpleTx (VerifiedCandidate SimpleTx) forall a b. Program SimpleTx a -> (a -> Program SimpleTx b) -> Program SimpleTx b forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b >>= (LogicError SimpleTx -> Program SimpleTx (VerifiedCandidate SimpleTx)) -> (VerifiedCandidate SimpleTx -> Program SimpleTx (VerifiedCandidate SimpleTx)) -> Either (LogicError SimpleTx) (VerifiedCandidate SimpleTx) -> Program SimpleTx (VerifiedCandidate SimpleTx) forall a c b. (a -> c) -> (b -> c) -> Either a b -> c either LogicError SimpleTx -> Program SimpleTx (VerifiedCandidate SimpleTx) forall tx a. LogicError tx -> Program tx a reject VerifiedCandidate SimpleTx -> Program SimpleTx (VerifiedCandidate SimpleTx) forall a. a -> Program SimpleTx a forall (f :: * -> *) a. Applicative f => a -> f a pure Runtime SimpleTx confirmed <- Runtime SimpleTx -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall tx. Runtime tx -> Command tx -> Program tx (Runtime tx) Staging.stage Runtime SimpleTx collecting (Command SimpleTx -> Program SimpleTx (Runtime SimpleTx)) -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall a b. (a -> b) -> a -> b $ VerifiedCandidate SimpleTx -> Command SimpleTx forall tx. VerifiedCandidate tx -> Command tx Owner.confirmSnapshot VerifiedCandidate SimpleTx firstEvidence Bool -> Program SimpleTx () -> Program SimpleTx () forall (f :: * -> *). Applicative f => Bool -> f () -> f () when (Maybe (Candidate SimpleTx) -> Bool forall a. Maybe a -> Bool isJust (Maybe (Candidate SimpleTx) -> Bool) -> Maybe (Candidate SimpleTx) -> Bool forall a b. (a -> b) -> a -> b $ Runtime SimpleTx -> Maybe (Candidate SimpleTx) forall tx. Runtime tx -> Maybe (Candidate tx) Owner.candidate Runtime SimpleTx confirmed) (Program SimpleTx () -> Program SimpleTx ()) -> Program SimpleTx () -> Program SimpleTx () forall a b. (a -> b) -> a -> b $ LogicError SimpleTx -> Program SimpleTx () forall tx a. LogicError tx -> Program tx a reject (LogicError SimpleTx -> Program SimpleTx ()) -> LogicError SimpleTx -> Program SimpleTx () forall a b. (a -> b) -> a -> b $ Text -> LogicError SimpleTx forall tx. Text -> LogicError tx AssertionFailed Text "confirmed owner still exposes a candidate" Runtime SimpleTx next <- Runtime SimpleTx -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall tx. Runtime tx -> Command tx -> Program tx (Runtime tx) Staging.stage Runtime SimpleTx confirmed (Command SimpleTx -> Program SimpleTx (Runtime SimpleTx)) -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall a b. (a -> b) -> a -> b $ ValidatedSnapshot SimpleTx -> Seq SimpleTx -> Command SimpleTx forall tx. ValidatedSnapshot tx -> Seq tx -> Command tx Owner.acceptSnapshot (Snapshot SimpleTx -> ValidatedSnapshot SimpleTx checkedSnapshot Snapshot SimpleTx nextSnapshot) Seq SimpleTx forall a. Monoid a => a mempty VerifiedCandidate SimpleTx nextEvidence <- Candidate SimpleTx -> MultiSignature (Snapshot SimpleTx) -> Program SimpleTx (Either (LogicError SimpleTx) (VerifiedCandidate SimpleTx)) forall tx. Candidate tx -> MultiSignature (Snapshot tx) -> Program tx (Either (LogicError tx) (VerifiedCandidate tx)) verifyCandidate (Runtime SimpleTx -> Candidate SimpleTx owned Runtime SimpleTx next) (Snapshot SimpleTx -> MultiSignature (Snapshot SimpleTx) signatures Snapshot SimpleTx nextSnapshot) Program SimpleTx (Either (LogicError SimpleTx) (VerifiedCandidate SimpleTx)) -> (Either (LogicError SimpleTx) (VerifiedCandidate SimpleTx) -> Program SimpleTx (VerifiedCandidate SimpleTx)) -> Program SimpleTx (VerifiedCandidate SimpleTx) forall a b. Program SimpleTx a -> (a -> Program SimpleTx b) -> Program SimpleTx b forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b >>= (LogicError SimpleTx -> Program SimpleTx (VerifiedCandidate SimpleTx)) -> (VerifiedCandidate SimpleTx -> Program SimpleTx (VerifiedCandidate SimpleTx)) -> Either (LogicError SimpleTx) (VerifiedCandidate SimpleTx) -> Program SimpleTx (VerifiedCandidate SimpleTx) forall a c b. (a -> c) -> (b -> c) -> Either a b -> c either LogicError SimpleTx -> Program SimpleTx (VerifiedCandidate SimpleTx) forall tx a. LogicError tx -> Program tx a reject VerifiedCandidate SimpleTx -> Program SimpleTx (VerifiedCandidate SimpleTx) forall a. a -> Program SimpleTx a forall (f :: * -> *) a. Applicative f => a -> f a pure Runtime SimpleTx finished <- Runtime SimpleTx -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall tx. Runtime tx -> Command tx -> Program tx (Runtime tx) Staging.stage Runtime SimpleTx next (Command SimpleTx -> Program SimpleTx (Runtime SimpleTx)) -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall a b. (a -> b) -> a -> b $ VerifiedCandidate SimpleTx -> Command SimpleTx forall tx. VerifiedCandidate tx -> Command tx Owner.confirmSnapshot VerifiedCandidate SimpleTx nextEvidence Bool -> Program SimpleTx () -> Program SimpleTx () forall (f :: * -> *). Applicative f => Bool -> f () -> f () when (Maybe (Candidate SimpleTx) -> Bool forall a. Maybe a -> Bool isJust (Maybe (Candidate SimpleTx) -> Bool) -> Maybe (Candidate SimpleTx) -> Bool forall a b. (a -> b) -> a -> b $ Runtime SimpleTx -> Maybe (Candidate SimpleTx) forall tx. Runtime tx -> Maybe (Candidate tx) Owner.candidate Runtime SimpleTx finished) (Program SimpleTx () -> Program SimpleTx ()) -> Program SimpleTx () -> Program SimpleTx () forall a b. (a -> b) -> a -> b $ LogicError SimpleTx -> Program SimpleTx () forall tx a. LogicError tx -> Program tx a reject (LogicError SimpleTx -> Program SimpleTx ()) -> LogicError SimpleTx -> Program SimpleTx () forall a b. (a -> b) -> a -> b $ Text -> LogicError SimpleTx forall tx. Text -> LogicError tx AssertionFailed Text "second confirmation retains a candidate" Program SimpleTx () -> Outcome SimpleTx run Program SimpleTx () program Outcome SimpleTx -> (Outcome SimpleTx -> Bool) -> IO () forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO () `shouldSatisfy` \case Continue [SnapshotConfirmed{}, SnapshotRequested{}, SnapshotConfirmed{}] [] -> Bool True Outcome SimpleTx _ -> Bool False String -> IO () -> SpecWith (Arg (IO ())) forall a. (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) it String "imports historical request markers without adding an edge to the live graph" (IO () -> SpecWith (Arg (IO ()))) -> IO () -> SpecWith (Arg (IO ())) forall a b. (a -> b) -> a -> b $ do let restored :: Runtime SimpleTx restored = UTxOType SimpleTx -> StateChanged SimpleTx -> Runtime SimpleTx -> Runtime SimpleTx forall tx. IsChainState tx => UTxOType tx -> StateChanged tx -> Runtime tx -> Runtime tx Owner.replayEvent Set SimpleTxOut UTxOType SimpleTx forall a. Monoid a => a mempty (SnapshotNumber -> StateChanged SimpleTx forall tx. SnapshotNumber -> StateChanged tx SnapshotRequestDecided SnapshotNumber 2) Runtime SimpleTx collecting (Runtime SimpleTx -> CoordinatedHeadState SimpleTx forall tx. Runtime tx -> CoordinatedHeadState tx Owner.currentState Runtime SimpleTx restored).seenSnapshot SeenSnapshot SimpleTx -> SeenSnapshot SimpleTx -> IO () forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO () `shouldBe` SnapshotNumber -> SnapshotNumber -> SeenSnapshot SimpleTx forall tx. SnapshotNumber -> SnapshotNumber -> SeenSnapshot tx RequestedSnapshot SnapshotNumber 1 SnapshotNumber 2 let imported :: Runtime SimpleTx imported = UTxOType SimpleTx -> StateChanged SimpleTx -> Runtime SimpleTx -> Runtime SimpleTx forall tx. IsChainState tx => UTxOType tx -> StateChanged tx -> Runtime tx -> Runtime tx Owner.replayEvent Set SimpleTxOut UTxOType SimpleTx forall a. Monoid a => a mempty (Snapshot SimpleTx -> Seq SimpleTx -> Maybe (TxIdType SimpleTx) -> StateChanged SimpleTx forall tx. Snapshot tx -> Seq tx -> Maybe (TxIdType tx) -> StateChanged tx SnapshotRequested Snapshot SimpleTx different Seq SimpleTx forall a. Monoid a => a mempty Maybe Integer Maybe (TxIdType SimpleTx) forall a. Maybe a Nothing) Runtime SimpleTx collecting (Runtime SimpleTx -> CoordinatedHeadState SimpleTx forall tx. Runtime tx -> CoordinatedHeadState tx Owner.currentState Runtime SimpleTx imported).seenSnapshot SeenSnapshot SimpleTx -> SeenSnapshot SimpleTx -> IO () forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO () `shouldBe` Snapshot SimpleTx -> Map Party (Signature (Snapshot SimpleTx)) -> SeenSnapshot SimpleTx forall tx. IsTx tx => Snapshot tx -> Map Party (Signature (Snapshot tx)) -> SeenSnapshot tx mkSeenSnapshot Snapshot SimpleTx different Map Party (Signature (Snapshot SimpleTx)) forall a. Monoid a => a mempty String -> IO () -> SpecWith (Arg (IO ())) forall a. (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) it String "does not confirm one snapshot using another snapshot's signatures" (IO () -> SpecWith (Arg (IO ()))) -> IO () -> SpecWith (Arg (IO ())) forall a b. (a -> b) -> a -> b $ do let before :: NodeState SimpleTx before = Snapshot SimpleTx -> NodeState SimpleTx withSignatures Snapshot SimpleTx different input :: Input SimpleTx input = TTL -> NetworkEvent (Message SimpleTx) -> Input SimpleTx forall tx. TTL -> NetworkEvent (Message tx) -> Input tx Head.NetworkInput TTL 0 (NetworkEvent (Message SimpleTx) -> Input SimpleTx) -> NetworkEvent (Message SimpleTx) -> Input SimpleTx forall a b. (a -> b) -> a -> b $ Party -> Message SimpleTx -> NetworkEvent (Message SimpleTx) forall msg. Party -> msg -> NetworkEvent msg ReceivedMessage Party carol (Message SimpleTx -> NetworkEvent (Message SimpleTx)) -> Message SimpleTx -> NetworkEvent (Message SimpleTx) forall a b. (a -> b) -> a -> b $ Signature (Snapshot SimpleTx) -> SnapshotNumber -> Message SimpleTx forall tx. Signature (Snapshot tx) -> SnapshotNumber -> Message tx AckSn (Secret (SigningKey HydraKey) -> Snapshot SimpleTx -> Signature (Snapshot SimpleTx) forall a. SignableRepresentation a => Secret (SigningKey HydraKey) -> a -> Signature a sign Secret (SigningKey HydraKey) carolSk Snapshot SimpleTx different) SnapshotNumber 1 outcome :: Outcome SimpleTx outcome = Environment -> Ledger SimpleTx -> UTCTime -> NodeState SimpleTx -> Input SimpleTx -> Outcome SimpleTx forall tx. IsChainState tx => Environment -> Ledger tx -> UTCTime -> NodeState tx -> Input tx -> Outcome tx Head.update (Int -> Environment Scenario.environment Int 0) Ledger SimpleTx simpleLedger UTCTime initialChainTime NodeState SimpleTx before Input SimpleTx input Outcome SimpleTx outcome Outcome SimpleTx -> (Outcome SimpleTx -> Bool) -> IO () forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO () `shouldSatisfy` Outcome SimpleTx -> Bool invalidSignatures NodeState SimpleTx -> Outcome SimpleTx -> NodeState SimpleTx forall tx. IsChainState tx => NodeState tx -> Outcome tx -> NodeState tx Head.aggregateState NodeState SimpleTx before Outcome SimpleTx outcome NodeState SimpleTx -> NodeState SimpleTx -> IO () forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO () `shouldBe` NodeState SimpleTx before String -> IO () -> SpecWith (Arg (IO ())) forall a. (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) it String "shares the cached snapshot through restoration, partial acknowledgements and aggregation" (IO () -> SpecWith (Arg (IO ()))) -> IO () -> SpecWith (Arg (IO ())) forall a b. (a -> b) -> a -> b $ do let before :: NodeState SimpleTx before = Snapshot SimpleTx -> NodeState SimpleTx node Snapshot SimpleTx snapshot cache :: NodeState SimpleTx -> CachedSnapshot SimpleTx cache NodeState SimpleTx st = case (NodeState SimpleTx -> OpenState SimpleTx Scenario.openState NodeState SimpleTx st).coordinatedHeadState.seenSnapshot of SeenSnapshot{CachedSnapshot SimpleTx $sel:cachedSnapshot:NoSeenSnapshot :: forall tx. SeenSnapshot tx -> CachedSnapshot tx cachedSnapshot :: CachedSnapshot SimpleTx cachedSnapshot} -> CachedSnapshot SimpleTx cachedSnapshot SeenSnapshot SimpleTx _ -> Text -> CachedSnapshot SimpleTx forall a t. (HasCallStack, IsText t) => t -> a error Text "expected a collecting snapshot" StableName (CachedSnapshot SimpleTx) cached <- CachedSnapshot SimpleTx -> IO (CachedSnapshot SimpleTx) forall a. a -> IO a forall (m :: * -> *) a. MonadEvaluate m => a -> m a evaluate (NodeState SimpleTx -> CachedSnapshot SimpleTx cache NodeState SimpleTx before) IO (CachedSnapshot SimpleTx) -> (CachedSnapshot SimpleTx -> IO (StableName (CachedSnapshot SimpleTx))) -> IO (StableName (CachedSnapshot SimpleTx)) forall a b. IO a -> (a -> IO b) -> IO b forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b >>= CachedSnapshot SimpleTx -> IO (StableName (CachedSnapshot SimpleTx)) forall a. a -> IO (StableName a) makeStableName StableName ByteString bytes <- ByteString -> IO ByteString forall a. a -> IO a forall (m :: * -> *) a. MonadEvaluate m => a -> m a evaluate (CachedSnapshot SimpleTx -> ByteString forall tx. CachedSnapshot tx -> ByteString Cached.signingBytes (CachedSnapshot SimpleTx -> ByteString) -> CachedSnapshot SimpleTx -> ByteString forall a b. (a -> b) -> a -> b $ NodeState SimpleTx -> CachedSnapshot SimpleTx cache NodeState SimpleTx before) IO ByteString -> (ByteString -> IO (StableName ByteString)) -> IO (StableName ByteString) forall a b. IO a -> (a -> IO b) -> IO b forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b >>= ByteString -> IO (StableName ByteString) forall a. a -> IO (StableName a) makeStableName let checkCache :: CachedSnapshot SimpleTx -> IO () checkCache CachedSnapshot SimpleTx retained = do StableName (CachedSnapshot SimpleTx) retainedName <- CachedSnapshot SimpleTx -> IO (CachedSnapshot SimpleTx) forall a. a -> IO a forall (m :: * -> *) a. MonadEvaluate m => a -> m a evaluate CachedSnapshot SimpleTx retained IO (CachedSnapshot SimpleTx) -> (CachedSnapshot SimpleTx -> IO (StableName (CachedSnapshot SimpleTx))) -> IO (StableName (CachedSnapshot SimpleTx)) forall a b. IO a -> (a -> IO b) -> IO b forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b >>= CachedSnapshot SimpleTx -> IO (StableName (CachedSnapshot SimpleTx)) forall a. a -> IO (StableName a) makeStableName (StableName (CachedSnapshot SimpleTx) retainedName StableName (CachedSnapshot SimpleTx) -> StableName (CachedSnapshot SimpleTx) -> Bool forall a. Eq a => a -> a -> Bool == StableName (CachedSnapshot SimpleTx) cached) Bool -> Bool -> IO () forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO () `shouldBe` Bool True StableName ByteString representation <- ByteString -> IO ByteString forall a. a -> IO a forall (m :: * -> *) a. MonadEvaluate m => a -> m a evaluate (CachedSnapshot SimpleTx -> ByteString forall tx. CachedSnapshot tx -> ByteString Cached.signingBytes CachedSnapshot SimpleTx retained) IO ByteString -> (ByteString -> IO (StableName ByteString)) -> IO (StableName ByteString) forall a b. IO a -> (a -> IO b) -> IO b forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b >>= ByteString -> IO (StableName ByteString) forall a. a -> IO (StableName a) makeStableName (StableName ByteString representation StableName ByteString -> StableName ByteString -> Bool forall a. Eq a => a -> a -> Bool == StableName ByteString bytes) Bool -> Bool -> IO () forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO () `shouldBe` Bool True NodeState SimpleTx after <- (NodeState SimpleTx -> (Party, Secret (SigningKey HydraKey)) -> IO (NodeState SimpleTx)) -> NodeState SimpleTx -> [(Party, Secret (SigningKey HydraKey))] -> IO (NodeState SimpleTx) forall (t :: * -> *) (m :: * -> *) b a. (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b foldM ( \NodeState SimpleTx st (Party party, Secret (SigningKey HydraKey) sk) -> do let runtime :: Runtime SimpleTx runtime = OpenState SimpleTx -> Runtime SimpleTx forall tx. IsChainState tx => OpenState tx -> Runtime tx Owner.start (OpenState SimpleTx -> Runtime SimpleTx) -> OpenState SimpleTx -> Runtime SimpleTx forall a b. (a -> b) -> a -> b $ NodeState SimpleTx -> OpenState SimpleTx Scenario.openState NodeState SimpleTx st ([StateChanged SimpleTx] events, Runtime SimpleTx staged) = Runtime SimpleTx -> Command SimpleTx -> ([StateChanged SimpleTx], Runtime SimpleTx) forall tx. Runtime tx -> Command tx -> ([StateChanged tx], Runtime tx) Owner.step Runtime SimpleTx runtime (Command SimpleTx -> ([StateChanged SimpleTx], Runtime SimpleTx)) -> Command SimpleTx -> ([StateChanged SimpleTx], Runtime SimpleTx) forall a b. (a -> b) -> a -> b $ Candidate SimpleTx -> Party -> Signature (Snapshot SimpleTx) -> Command SimpleTx forall tx. Candidate tx -> Party -> Signature (Snapshot tx) -> Command tx Owner.recordSignature (Runtime SimpleTx -> Candidate SimpleTx owned Runtime SimpleTx runtime) Party party (Secret (SigningKey HydraKey) -> Snapshot SimpleTx -> Signature (Snapshot SimpleTx) forall a. SignableRepresentation a => Secret (SigningKey HydraKey) -> a -> Signature a sign Secret (SigningKey HydraKey) sk Snapshot SimpleTx snapshot) [StateChanged SimpleTx] events [StateChanged SimpleTx] -> [StateChanged SimpleTx] -> IO () forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO () `shouldBe` [SnapshotNumber -> Party -> Signature (Snapshot SimpleTx) -> StateChanged SimpleTx forall tx. SnapshotNumber -> Party -> Signature (Snapshot tx) -> StateChanged tx PartySignedSnapshot SnapshotNumber 1 Party party (Secret (SigningKey HydraKey) -> Snapshot SimpleTx -> Signature (Snapshot SimpleTx) forall a. SignableRepresentation a => Secret (SigningKey HydraKey) -> a -> Signature a sign Secret (SigningKey HydraKey) sk Snapshot SimpleTx snapshot)] CachedSnapshot SimpleTx -> IO () checkCache (Runtime SimpleTx -> CoordinatedHeadState SimpleTx forall tx. Runtime tx -> CoordinatedHeadState tx Owner.currentState Runtime SimpleTx staged).seenSnapshot.cachedSnapshot let outcome :: Outcome SimpleTx outcome = Environment -> Ledger SimpleTx -> UTCTime -> NodeState SimpleTx -> Input SimpleTx -> Outcome SimpleTx forall tx. IsChainState tx => Environment -> Ledger tx -> UTCTime -> NodeState tx -> Input tx -> Outcome tx Head.update (Int -> Environment Scenario.environment Int 0) Ledger SimpleTx simpleLedger UTCTime initialChainTime NodeState SimpleTx st (Input SimpleTx -> Outcome SimpleTx) -> Input SimpleTx -> Outcome SimpleTx forall a b. (a -> b) -> a -> b $ TTL -> NetworkEvent (Message SimpleTx) -> Input SimpleTx forall tx. TTL -> NetworkEvent (Message tx) -> Input tx Head.NetworkInput TTL 0 (NetworkEvent (Message SimpleTx) -> Input SimpleTx) -> NetworkEvent (Message SimpleTx) -> Input SimpleTx forall a b. (a -> b) -> a -> b $ Party -> Message SimpleTx -> NetworkEvent (Message SimpleTx) forall msg. Party -> msg -> NetworkEvent msg ReceivedMessage Party party (Message SimpleTx -> NetworkEvent (Message SimpleTx)) -> Message SimpleTx -> NetworkEvent (Message SimpleTx) forall a b. (a -> b) -> a -> b $ Signature (Snapshot SimpleTx) -> SnapshotNumber -> Message SimpleTx forall tx. Signature (Snapshot tx) -> SnapshotNumber -> Message tx AckSn (Secret (SigningKey HydraKey) -> Snapshot SimpleTx -> Signature (Snapshot SimpleTx) forall a. SignableRepresentation a => Secret (SigningKey HydraKey) -> a -> Signature a sign Secret (SigningKey HydraKey) sk Snapshot SimpleTx snapshot) SnapshotNumber 1 Outcome SimpleTx outcome Outcome SimpleTx -> Outcome SimpleTx -> IO () forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO () `shouldBe` [StateChanged SimpleTx] -> [Effect SimpleTx] -> Outcome SimpleTx forall tx. [StateChanged tx] -> [Effect tx] -> Outcome tx Continue [SnapshotNumber -> Party -> Signature (Snapshot SimpleTx) -> StateChanged SimpleTx forall tx. SnapshotNumber -> Party -> Signature (Snapshot tx) -> StateChanged tx PartySignedSnapshot SnapshotNumber 1 Party party (Secret (SigningKey HydraKey) -> Snapshot SimpleTx -> Signature (Snapshot SimpleTx) forall a. SignableRepresentation a => Secret (SigningKey HydraKey) -> a -> Signature a sign Secret (SigningKey HydraKey) sk Snapshot SimpleTx snapshot)] [] let next :: NodeState SimpleTx next = NodeState SimpleTx -> Outcome SimpleTx -> NodeState SimpleTx forall tx. IsChainState tx => NodeState tx -> Outcome tx -> NodeState tx Head.aggregateState NodeState SimpleTx st Outcome SimpleTx outcome CachedSnapshot SimpleTx -> IO () checkCache (CachedSnapshot SimpleTx -> IO ()) -> CachedSnapshot SimpleTx -> IO () forall a b. (a -> b) -> a -> b $ NodeState SimpleTx -> CachedSnapshot SimpleTx cache NodeState SimpleTx next NodeState SimpleTx -> IO (NodeState SimpleTx) forall a. a -> IO a forall (f :: * -> *) a. Applicative f => a -> f a pure NodeState SimpleTx next ) NodeState SimpleTx before [(Party alice, Secret (SigningKey HydraKey) aliceSk), (Party bob, Secret (SigningKey HydraKey) bobSk)] let outcome :: Outcome SimpleTx outcome = Environment -> Ledger SimpleTx -> UTCTime -> NodeState SimpleTx -> Input SimpleTx -> Outcome SimpleTx forall tx. IsChainState tx => Environment -> Ledger tx -> UTCTime -> NodeState tx -> Input tx -> Outcome tx Head.update (Int -> Environment Scenario.environment Int 0) Ledger SimpleTx simpleLedger UTCTime initialChainTime NodeState SimpleTx after (Input SimpleTx -> Outcome SimpleTx) -> Input SimpleTx -> Outcome SimpleTx forall a b. (a -> b) -> a -> b $ TTL -> NetworkEvent (Message SimpleTx) -> Input SimpleTx forall tx. TTL -> NetworkEvent (Message tx) -> Input tx Head.NetworkInput TTL 0 (NetworkEvent (Message SimpleTx) -> Input SimpleTx) -> NetworkEvent (Message SimpleTx) -> Input SimpleTx forall a b. (a -> b) -> a -> b $ Party -> Message SimpleTx -> NetworkEvent (Message SimpleTx) forall msg. Party -> msg -> NetworkEvent msg ReceivedMessage Party carol (Message SimpleTx -> NetworkEvent (Message SimpleTx)) -> Message SimpleTx -> NetworkEvent (Message SimpleTx) forall a b. (a -> b) -> a -> b $ Signature (Snapshot SimpleTx) -> SnapshotNumber -> Message SimpleTx forall tx. Signature (Snapshot tx) -> SnapshotNumber -> Message tx AckSn (Secret (SigningKey HydraKey) -> Snapshot SimpleTx -> Signature (Snapshot SimpleTx) forall a. SignableRepresentation a => Secret (SigningKey HydraKey) -> a -> Signature a sign Secret (SigningKey HydraKey) carolSk Snapshot SimpleTx snapshot) SnapshotNumber 1 Outcome SimpleTx outcome Outcome SimpleTx -> (Outcome SimpleTx -> Bool) -> IO () forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO () `shouldSatisfy` \case Continue [PartySignedSnapshot{}, SnapshotConfirmed{}] [Effect SimpleTx] _ -> Bool True Outcome SimpleTx _ -> Bool False (NodeState SimpleTx -> OpenState SimpleTx Scenario.openState (NodeState SimpleTx -> OpenState SimpleTx) -> NodeState SimpleTx -> OpenState SimpleTx forall a b. (a -> b) -> a -> b $ NodeState SimpleTx -> Outcome SimpleTx -> NodeState SimpleTx forall tx. IsChainState tx => NodeState tx -> Outcome tx -> NodeState tx Head.aggregateState NodeState SimpleTx after Outcome SimpleTx outcome).coordinatedHeadState.confirmedSnapshot ConfirmedSnapshot SimpleTx -> ConfirmedSnapshot SimpleTx -> IO () forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO () `shouldBe` Snapshot SimpleTx -> MultiSignature (Snapshot SimpleTx) -> ConfirmedSnapshot SimpleTx forall tx. Snapshot tx -> MultiSignature (Snapshot tx) -> ConfirmedSnapshot tx ConfirmedSnapshot Snapshot SimpleTx snapshot (Snapshot SimpleTx -> MultiSignature (Snapshot SimpleTx) signatures Snapshot SimpleTx snapshot) String -> IO () -> SpecWith (Arg (IO ())) forall a. (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) it String "preserves JSON and CBOR layouts and reconstructs canonical signing bytes" (IO () -> SpecWith (Arg (IO ()))) -> IO () -> SpecWith (Arg (IO ())) forall a b. (a -> b) -> a -> b $ do let signatories :: Map Party (Signature (Snapshot SimpleTx)) signatories = Party -> Signature (Snapshot SimpleTx) -> Map Party (Signature (Snapshot SimpleTx)) forall k a. k -> a -> Map k a Map.singleton Party alice (Secret (SigningKey HydraKey) -> Snapshot SimpleTx -> Signature (Snapshot SimpleTx) forall a. SignableRepresentation a => Secret (SigningKey HydraKey) -> a -> Signature a sign Secret (SigningKey HydraKey) aliceSk Snapshot SimpleTx snapshot) seen :: SeenSnapshot SimpleTx seen = Snapshot SimpleTx -> Map Party (Signature (Snapshot SimpleTx)) -> SeenSnapshot SimpleTx forall tx. IsTx tx => Snapshot tx -> Map Party (Signature (Snapshot tx)) -> SeenSnapshot tx mkSeenSnapshot Snapshot SimpleTx snapshot Map Party (Signature (Snapshot SimpleTx)) signatories json :: Value json = [Pair] -> Value object [Key "tag" Key -> Text -> Pair forall v. ToJSON v => Key -> v -> Pair forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv .= (Text "SeenSnapshot" :: Text), Key "snapshot" Key -> Snapshot SimpleTx -> Pair forall v. ToJSON v => Key -> v -> Pair forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv .= Snapshot SimpleTx snapshot, Key "signatories" Key -> Map Party (Signature (Snapshot SimpleTx)) -> Pair forall v. ToJSON v => Key -> v -> Pair forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv .= Map Party (Signature (Snapshot SimpleTx)) signatories] cbor :: ByteString cbor = Encoding -> ByteString toStrictByteString (Encoding -> ByteString) -> Encoding -> ByteString forall a b. (a -> b) -> a -> b $ Text -> Encoding forall a. ToCBOR a => a -> Encoding toCBOR (Text "SeenSnapshot" :: Text) Encoding -> Encoding -> Encoding forall a. Semigroup a => a -> a -> a <> Snapshot SimpleTx -> Encoding forall a. ToCBOR a => a -> Encoding toCBOR Snapshot SimpleTx snapshot Encoding -> Encoding -> Encoding forall a. Semigroup a => a -> a -> a <> Map Party (Signature (Snapshot SimpleTx)) -> Encoding forall a. ToCBOR a => a -> Encoding toCBOR Map Party (Signature (Snapshot SimpleTx)) signatories SeenSnapshot SimpleTx -> Value forall a. ToJSON a => a -> Value toJSON SeenSnapshot SimpleTx seen Value -> Value -> IO () forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO () `shouldBe` Value json SeenSnapshot SimpleTx -> ByteString forall a. ToCBOR a => a -> ByteString serialize' SeenSnapshot SimpleTx seen ByteString -> ByteString -> IO () forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO () `shouldBe` ByteString cbor [Either String (SeenSnapshot SimpleTx)] -> (Either String (SeenSnapshot SimpleTx) -> IO ()) -> IO () forall (t :: * -> *) (m :: * -> *) a b. (Foldable t, Monad m) => t a -> (a -> m b) -> m () forM_ [ByteString -> Either String (SeenSnapshot SimpleTx) forall a. FromJSON a => ByteString -> Either String a eitherDecode (Value -> ByteString forall a. ToJSON a => a -> ByteString encode Value json), (DecoderError -> String) -> Either DecoderError (SeenSnapshot SimpleTx) -> Either String (SeenSnapshot SimpleTx) forall a b c. (a -> b) -> Either a c -> Either b c forall (p :: * -> * -> *) a b c. Bifunctor p => (a -> b) -> p a c -> p b c first DecoderError -> String forall b a. (Show a, IsString b) => a -> b show (Either DecoderError (SeenSnapshot SimpleTx) -> Either String (SeenSnapshot SimpleTx)) -> Either DecoderError (SeenSnapshot SimpleTx) -> Either String (SeenSnapshot SimpleTx) forall a b. (a -> b) -> a -> b $ ByteString -> Either DecoderError (SeenSnapshot SimpleTx) forall a. FromCBOR a => ByteString -> Either DecoderError a decodeFull' ByteString cbor] ((Either String (SeenSnapshot SimpleTx) -> IO ()) -> IO ()) -> (Either String (SeenSnapshot SimpleTx) -> IO ()) -> IO () forall a b. (a -> b) -> a -> b $ \case Right SeenSnapshot{CachedSnapshot SimpleTx $sel:cachedSnapshot:NoSeenSnapshot :: forall tx. SeenSnapshot tx -> CachedSnapshot tx cachedSnapshot :: CachedSnapshot SimpleTx cachedSnapshot, $sel:signatories:NoSeenSnapshot :: forall tx. SeenSnapshot tx -> Map Party (Signature (Snapshot tx)) signatories = Map Party (Signature (Snapshot SimpleTx)) retained} -> do CachedSnapshot SimpleTx -> Snapshot SimpleTx forall tx. CachedSnapshot tx -> Snapshot tx Cached.snapshot CachedSnapshot SimpleTx cachedSnapshot Snapshot SimpleTx -> Snapshot SimpleTx -> IO () forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO () `shouldBe` Snapshot SimpleTx snapshot CachedSnapshot SimpleTx -> ByteString forall tx. CachedSnapshot tx -> ByteString Cached.signingBytes CachedSnapshot SimpleTx cachedSnapshot ByteString -> ByteString -> IO () forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO () `shouldBe` Snapshot SimpleTx -> ByteString forall a. SignableRepresentation a => a -> ByteString getSignableRepresentation Snapshot SimpleTx snapshot Map Party (Signature (Snapshot SimpleTx)) retained Map Party (Signature (Snapshot SimpleTx)) -> Map Party (Signature (Snapshot SimpleTx)) -> IO () forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO () `shouldBe` Map Party (Signature (Snapshot SimpleTx)) signatories Either String (SeenSnapshot SimpleTx) other -> String -> IO () forall a. String -> IO a forall (m :: * -> *) a. MonadFail m => String -> m a fail (String -> IO ()) -> String -> IO () forall a b. (a -> b) -> a -> b $ String "failed to decode a collecting snapshot: " String -> String -> String forall a. Semigroup a => a -> a -> a <> Either String (SeenSnapshot SimpleTx) -> String forall b a. (Show a, IsString b) => a -> b show Either String (SeenSnapshot SimpleTx) other String -> IO () -> SpecWith (Arg (IO ())) forall a. (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) it String "does not demand signing bytes when persisting a snapshot to CBOR" (IO () -> SpecWith (Arg (IO ()))) -> IO () -> SpecWith (Arg (IO ())) forall a b. (a -> b) -> a -> b $ do let poisoned :: Snapshot SimpleTx poisoned = Snapshot SimpleTx snapshot{accumulator = error "CBOR forces signing bytes", appliedAccumulator = error "CBOR forces signing bytes"} ByteString -> Either DecoderError (SeenSnapshot SimpleTx) forall a. FromCBOR a => ByteString -> Either DecoderError a decodeFull' (SeenSnapshot SimpleTx -> ByteString forall a. ToCBOR a => a -> ByteString serialize' (SeenSnapshot SimpleTx -> ByteString) -> SeenSnapshot SimpleTx -> ByteString forall a b. (a -> b) -> a -> b $ Snapshot SimpleTx -> Map Party (Signature (Snapshot SimpleTx)) -> SeenSnapshot SimpleTx forall tx. IsTx tx => Snapshot tx -> Map Party (Signature (Snapshot tx)) -> SeenSnapshot tx mkSeenSnapshot Snapshot SimpleTx poisoned Map Party (Signature (Snapshot SimpleTx)) forall a. Monoid a => a mempty) Either DecoderError (SeenSnapshot SimpleTx) -> Either DecoderError (SeenSnapshot SimpleTx) -> IO () forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO () `shouldBe` SeenSnapshot SimpleTx -> Either DecoderError (SeenSnapshot SimpleTx) forall a b. b -> Either a b Right (Snapshot SimpleTx -> Map Party (Signature (Snapshot SimpleTx)) -> SeenSnapshot SimpleTx forall tx. IsTx tx => Snapshot tx -> Map Party (Signature (Snapshot tx)) -> SeenSnapshot tx mkSeenSnapshot Snapshot SimpleTx snapshot Map Party (Signature (Snapshot SimpleTx)) forall a. Monoid a => a mempty) String -> IO () -> SpecWith (Arg (IO ())) forall a. (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) it String "confirms the owned contents using their cached signing bytes" (IO () -> SpecWith (Arg (IO ()))) -> IO () -> SpecWith (Arg (IO ())) forall a b. (a -> b) -> a -> b $ do let before :: NodeState SimpleTx before = Snapshot SimpleTx -> NodeState SimpleTx withSignatures Snapshot SimpleTx snapshot outcome :: Outcome SimpleTx outcome = Environment -> Ledger SimpleTx -> UTCTime -> NodeState SimpleTx -> Input SimpleTx -> Outcome SimpleTx forall tx. IsChainState tx => Environment -> Ledger tx -> UTCTime -> NodeState tx -> Input tx -> Outcome tx Head.update (Int -> Environment Scenario.environment Int 0) Ledger SimpleTx simpleLedger UTCTime initialChainTime NodeState SimpleTx before (Input SimpleTx -> Outcome SimpleTx) -> Input SimpleTx -> Outcome SimpleTx forall a b. (a -> b) -> a -> b $ TTL -> NetworkEvent (Message SimpleTx) -> Input SimpleTx forall tx. TTL -> NetworkEvent (Message tx) -> Input tx Head.NetworkInput TTL 0 (NetworkEvent (Message SimpleTx) -> Input SimpleTx) -> NetworkEvent (Message SimpleTx) -> Input SimpleTx forall a b. (a -> b) -> a -> b $ Party -> Message SimpleTx -> NetworkEvent (Message SimpleTx) forall msg. Party -> msg -> NetworkEvent msg ReceivedMessage Party carol (Message SimpleTx -> NetworkEvent (Message SimpleTx)) -> Message SimpleTx -> NetworkEvent (Message SimpleTx) forall a b. (a -> b) -> a -> b $ Signature (Snapshot SimpleTx) -> SnapshotNumber -> Message SimpleTx forall tx. Signature (Snapshot tx) -> SnapshotNumber -> Message tx AckSn (Secret (SigningKey HydraKey) -> Snapshot SimpleTx -> Signature (Snapshot SimpleTx) forall a. SignableRepresentation a => Secret (SigningKey HydraKey) -> a -> Signature a sign Secret (SigningKey HydraKey) carolSk Snapshot SimpleTx snapshot) SnapshotNumber 1 Outcome SimpleTx outcome Outcome SimpleTx -> (Outcome SimpleTx -> Bool) -> IO () forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO () `shouldSatisfy` \case Continue [PartySignedSnapshot{}, SnapshotConfirmed{}] [Effect SimpleTx] _ -> Bool True Outcome SimpleTx _ -> Bool False (NodeState SimpleTx -> OpenState SimpleTx Scenario.openState (NodeState SimpleTx -> OpenState SimpleTx) -> NodeState SimpleTx -> OpenState SimpleTx forall a b. (a -> b) -> a -> b $ NodeState SimpleTx -> Outcome SimpleTx -> NodeState SimpleTx forall tx. IsChainState tx => NodeState tx -> Outcome tx -> NodeState tx Head.aggregateState NodeState SimpleTx before Outcome SimpleTx outcome).coordinatedHeadState.confirmedSnapshot ConfirmedSnapshot SimpleTx -> ConfirmedSnapshot SimpleTx -> IO () forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO () `shouldBe` Snapshot SimpleTx -> MultiSignature (Snapshot SimpleTx) -> ConfirmedSnapshot SimpleTx forall tx. Snapshot tx -> MultiSignature (Snapshot tx) -> ConfirmedSnapshot tx ConfirmedSnapshot Snapshot SimpleTx snapshot (Snapshot SimpleTx -> MultiSignature (Snapshot SimpleTx) signatures Snapshot SimpleTx snapshot) String -> IO () -> SpecWith (Arg (IO ())) forall a. (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) it String "does not select a chained request when this party is not the next leader" (IO () -> SpecWith (Arg (IO ()))) -> IO () -> SpecWith (Arg (IO ())) forall a b. (a -> b) -> a -> b $ do let before :: NodeState SimpleTx before = Snapshot SimpleTx -> NodeState SimpleTx withSignatures Snapshot SimpleTx snapshot program :: Program SimpleTx () program = Workflow SimpleTx AckTopology () -> Program SimpleTx () forall {vertex} tx (topology :: Topology vertex) result. Workflow tx topology result -> Program tx result Workflow.run (Workflow SimpleTx AckTopology () -> Program SimpleTx ()) -> Workflow SimpleTx AckTopology () -> Program SimpleTx () forall a b. (a -> b) -> a -> b $ Args SimpleTx -> Workflow SimpleTx AckTopology () forall tx. IsChainState tx => Args tx -> Workflow tx AckTopology () AckSn.workflow AckSn.Args { $sel:env:Args :: RuleEnvironment env = Environment -> RuleEnvironment Head.ruleEnvironment (Environment -> RuleEnvironment) -> Environment -> RuleEnvironment forall a b. (a -> b) -> a -> b $ Int -> Environment Scenario.environment Int 0 , $sel:chainPointTime:Args :: ChainPointTime chainPointTime = NodeState SimpleTx before.chainPointTime , $sel:pendingDeposits:Args :: PendingDeposits SimpleTx pendingDeposits = Text -> Map Integer (Deposit SimpleTx) forall a t. (HasCallStack, IsText t) => t -> a error Text "a follower must not inspect deposits to select a request" , $sel:openState:Args :: OpenState SimpleTx openState = NodeState SimpleTx -> OpenState SimpleTx Scenario.openState NodeState SimpleTx before , $sel:sender:Args :: Party sender = Party carol , $sel:signed:Args :: Signature (Snapshot SimpleTx) signed = Secret (SigningKey HydraKey) -> Snapshot SimpleTx -> Signature (Snapshot SimpleTx) forall a. SignableRepresentation a => Secret (SigningKey HydraKey) -> a -> Signature a sign Secret (SigningKey HydraKey) carolSk Snapshot SimpleTx snapshot , $sel:snapshotNumber:Args :: SnapshotNumber snapshotNumber = SnapshotNumber 1 } Program SimpleTx () -> Outcome SimpleTx run Program SimpleTx () program Outcome SimpleTx -> (Outcome SimpleTx -> Bool) -> IO () forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO () `shouldSatisfy` \case Continue [PartySignedSnapshot{}, SnapshotConfirmed{}] [] -> Bool True Outcome SimpleTx _ -> Bool False String -> IO () -> SpecWith (Arg (IO ())) forall a. (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) it String "chain adoption rejects another snapshot's signatures" (IO () -> SpecWith (Arg (IO ()))) -> IO () -> SpecWith (Arg (IO ())) forall a b. (a -> b) -> a -> b $ do let supplied :: SeenSnapshot SimpleTx supplied = Snapshot SimpleTx -> Map Party (Signature (Snapshot SimpleTx)) -> SeenSnapshot SimpleTx forall tx. IsTx tx => Snapshot tx -> Map Party (Signature (Snapshot tx)) -> SeenSnapshot tx mkSeenSnapshot Snapshot SimpleTx snapshot Map Party (Signature (Snapshot SimpleTx)) forall a. Monoid a => a mempty program :: Program.Program SimpleTx () program :: Program SimpleTx () program = [VerificationKey HydraKey] -> SeenSnapshot SimpleTx -> MultiSignature (Snapshot SimpleTx) -> Program SimpleTx (Either (LogicError SimpleTx) (VerifiedSnapshot SimpleTx)) forall tx. IsTx tx => [VerificationKey HydraKey] -> SeenSnapshot tx -> MultiSignature (Snapshot tx) -> Program tx (Either (LogicError tx) (VerifiedSnapshot tx)) verifySeenSnapshot (Party -> VerificationKey HydraKey vkey (Party -> VerificationKey HydraKey) -> [Party] -> [VerificationKey HydraKey] forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> [Party] Scenario.scenarioParties) SeenSnapshot SimpleTx supplied (Snapshot SimpleTx -> MultiSignature (Snapshot SimpleTx) signatures Snapshot SimpleTx different) Program SimpleTx (Either (LogicError SimpleTx) (VerifiedSnapshot SimpleTx)) -> (Either (LogicError SimpleTx) (VerifiedSnapshot SimpleTx) -> Program SimpleTx ()) -> Program SimpleTx () forall a b. Program SimpleTx a -> (a -> Program SimpleTx b) -> Program SimpleTx b forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b >>= (LogicError SimpleTx -> Program SimpleTx ()) -> (VerifiedSnapshot SimpleTx -> Program SimpleTx ()) -> Either (LogicError SimpleTx) (VerifiedSnapshot SimpleTx) -> Program SimpleTx () forall a c b. (a -> c) -> (b -> c) -> Either a b -> c either LogicError SimpleTx -> Program SimpleTx () forall tx a. LogicError tx -> Program tx a reject (Program SimpleTx () -> VerifiedSnapshot SimpleTx -> Program SimpleTx () forall a b. a -> b -> a const (Program SimpleTx () -> VerifiedSnapshot SimpleTx -> Program SimpleTx ()) -> Program SimpleTx () -> VerifiedSnapshot SimpleTx -> Program SimpleTx () forall a b. (a -> b) -> a -> b $ () -> Program SimpleTx () forall a. a -> Program SimpleTx a forall (f :: * -> *) a. Applicative f => a -> f a pure ()) Program SimpleTx () -> Outcome SimpleTx run Program SimpleTx () program Outcome SimpleTx -> (Outcome SimpleTx -> Bool) -> IO () forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO () `shouldSatisfy` Outcome SimpleTx -> Bool invalidSignatures String -> IO () -> SpecWith (Arg (IO ())) forall a. (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) it String "matches the Agda live graph including Crem's implicit self transitions" (IO () -> SpecWith (Arg (IO ()))) -> IO () -> SpecWith (Arg (IO ())) forall a b. (a -> b) -> a -> b $ do let Topology [(SnapshotPhase, [SnapshotPhase])] edges = Topology SnapshotPhase snapshotTopology [SnapshotPhase] -> (SnapshotPhase -> IO ()) -> IO () forall (t :: * -> *) (m :: * -> *) a b. (Foldable t, Monad m) => t a -> (a -> m b) -> m () forM_ ([SnapshotPhase forall a. Bounded a => a minBound .. SnapshotPhase forall a. Bounded a => a maxBound] :: [SnapshotPhase]) ((SnapshotPhase -> IO ()) -> IO ()) -> (SnapshotPhase -> IO ()) -> IO () forall a b. (a -> b) -> a -> b $ \SnapshotPhase from -> [SnapshotPhase] -> (SnapshotPhase -> IO ()) -> IO () forall (t :: * -> *) (m :: * -> *) a b. (Foldable t, Monad m) => t a -> (a -> m b) -> m () forM_ [SnapshotPhase forall a. Bounded a => a minBound .. SnapshotPhase forall a. Bounded a => a maxBound] ((SnapshotPhase -> IO ()) -> IO ()) -> (SnapshotPhase -> IO ()) -> IO () forall a b. (a -> b) -> a -> b $ \SnapshotPhase to -> (SnapshotPhase from SnapshotPhase -> SnapshotPhase -> Bool forall a. Eq a => a -> a -> Bool == SnapshotPhase to Bool -> Bool -> Bool || ((SnapshotPhase, [SnapshotPhase]) -> Bool) -> [(SnapshotPhase, [SnapshotPhase])] -> Bool forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool any (\(SnapshotPhase source, [SnapshotPhase] destinations) -> SnapshotPhase source SnapshotPhase -> SnapshotPhase -> Bool forall a. Eq a => a -> a -> Bool == SnapshotPhase from Bool -> Bool -> Bool && SnapshotPhase to SnapshotPhase -> [SnapshotPhase] -> Bool forall (f :: * -> *) a. (Foldable f, DisallowElem f, Eq a) => a -> f a -> Bool `elem` [SnapshotPhase] destinations) [(SnapshotPhase, [SnapshotPhase])] edges) Bool -> Bool -> IO () forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO () `shouldBe` Integer -> Integer -> Bool Agda.liveSnapshotEdgeRef (Int -> Integer forall a b. (Integral a, Num b) => a -> b fromIntegral (Int -> Integer) -> Int -> Integer forall a b. (a -> b) -> a -> b $ SnapshotPhase -> Int forall a. Enum a => a -> Int fromEnum SnapshotPhase from) (Int -> Integer forall a b. (Integral a, Num b) => a -> b fromIntegral (Int -> Integer) -> Int -> Integer forall a b. (a -> b) -> a -> b $ SnapshotPhase -> Int forall a. Enum a => a -> Int fromEnum SnapshotPhase to) String -> IO () -> SpecWith (Arg (IO ())) forall a. (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) it String "matches Agda on 96 ownership and party ordering combinations with real signatures" (IO () -> SpecWith (Arg (IO ()))) -> IO () -> SpecWith (Arg (IO ())) forall a b. (a -> b) -> a -> b $ [Bool] -> (Bool -> IO ()) -> IO () forall (t :: * -> *) (m :: * -> *) a b. (Foldable t, Monad m) => t a -> (a -> m b) -> m () forM_ [Bool False, Bool True] ((Bool -> IO ()) -> IO ()) -> (Bool -> IO ()) -> IO () forall a b. (a -> b) -> a -> b $ \Bool collects -> [Bool] -> (Bool -> IO ()) -> IO () forall (t :: * -> *) (m :: * -> *) a b. (Foldable t, Monad m) => t a -> (a -> m b) -> m () forM_ [Bool False, Bool True] ((Bool -> IO ()) -> IO ()) -> (Bool -> IO ()) -> IO () forall a b. (a -> b) -> a -> b $ \Bool foreignHead -> [SnapshotVersion] -> (SnapshotVersion -> IO ()) -> IO () forall (t :: * -> *) (m :: * -> *) a b. (Foldable t, Monad m) => t a -> (a -> m b) -> m () forM_ [SnapshotVersion 0, SnapshotVersion 1] ((SnapshotVersion -> IO ()) -> IO ()) -> (SnapshotVersion -> IO ()) -> IO () forall a b. (a -> b) -> a -> b $ \SnapshotVersion version -> [SnapshotNumber] -> (SnapshotNumber -> IO ()) -> IO () forall (t :: * -> *) (m :: * -> *) a b. (Foldable t, Monad m) => t a -> (a -> m b) -> m () forM_ [SnapshotNumber 1, SnapshotNumber 2] ((SnapshotNumber -> IO ()) -> IO ()) -> (SnapshotNumber -> IO ()) -> IO () forall a b. (a -> b) -> a -> b $ \SnapshotNumber number -> [Bool] -> (Bool -> IO ()) -> IO () forall (t :: * -> *) (m :: * -> *) a b. (Foldable t, Monad m) => t a -> (a -> m b) -> m () forM_ [Bool False, Bool True] ((Bool -> IO ()) -> IO ()) -> (Bool -> IO ()) -> IO () forall a b. (a -> b) -> a -> b $ \Bool otherContents -> [[Integer]] -> ([Integer] -> IO ()) -> IO () forall (t :: * -> *) (m :: * -> *) a b. (Foldable t, Monad m) => t a -> (a -> m b) -> m () forM_ [[Integer 0, Integer 1, Integer 2], [Integer 2, Integer 1, Integer 0], [Integer 0, Integer 1]] (([Integer] -> IO ()) -> IO ()) -> ([Integer] -> IO ()) -> IO () forall a b. (a -> b) -> a -> b $ \[Integer] members -> do let base :: Snapshot SimpleTx base = if Bool otherContents then Snapshot SimpleTx different else Snapshot SimpleTx snapshot supplied :: Snapshot SimpleTx supplied :: Snapshot SimpleTx supplied = Snapshot SimpleTx base{Snapshot.headId = if foreignHead then UnsafeHeadId "other" else snapshot.headId, Snapshot.version = version, number} signers :: [(Party, Secret (SigningKey HydraKey))] signers = [(Party alice, Secret (SigningKey HydraKey) aliceSk), (Party bob, Secret (SigningKey HydraKey) bobSk), (Party carol, Secret (SigningKey HydraKey) carolSk)] selected :: [(Party, Secret (SigningKey HydraKey))] selected = [(Party, Secret (SigningKey HydraKey)) entry | Integer i <- [Integer] members, (Integer j, (Party, Secret (SigningKey HydraKey)) entry) <- [Integer] -> [(Party, Secret (SigningKey HydraKey))] -> [(Integer, (Party, Secret (SigningKey HydraKey)))] forall a b. [a] -> [b] -> [(a, b)] zip [Integer 0 :: Integer ..] [(Party, Secret (SigningKey HydraKey))] signers, Integer i Integer -> Integer -> Bool forall a. Eq a => a -> a -> Bool == Integer j] open :: OpenState SimpleTx open = NodeState SimpleTx -> OpenState SimpleTx Scenario.openState (NodeState SimpleTx -> OpenState SimpleTx) -> NodeState SimpleTx -> OpenState SimpleTx forall a b. (a -> b) -> a -> b $ Snapshot SimpleTx -> NodeState SimpleTx node Snapshot SimpleTx supplied parameters :: HeadParameters parameters :: HeadParameters parameters = OpenState SimpleTx open.parameters{parties = fst <$> selected} issuer :: Runtime SimpleTx issuer = OpenState SimpleTx -> Runtime SimpleTx forall tx. IsChainState tx => OpenState tx -> Runtime tx Owner.start OpenState SimpleTx open{headId = supplied.headId, parameters} proof :: MultiSignature (Snapshot SimpleTx) proof = Map Party (Signature (Snapshot SimpleTx)) -> [Party] -> MultiSignature (Snapshot SimpleTx) forall k a. Ord k => Map k (Signature a) -> [k] -> MultiSignature a aggregateInOrder ([(Party, Signature (Snapshot SimpleTx))] -> Map Party (Signature (Snapshot SimpleTx)) forall k a. Ord k => [(k, a)] -> Map k a Map.fromList [(Party p, Secret (SigningKey HydraKey) -> Snapshot SimpleTx -> Signature (Snapshot SimpleTx) forall a. SignableRepresentation a => Secret (SigningKey HydraKey) -> a -> Signature a sign Secret (SigningKey HydraKey) sk Snapshot SimpleTx supplied) | (Party p, Secret (SigningKey HydraKey) sk) <- [(Party, Secret (SigningKey HydraKey))] selected]) ((Party, Secret (SigningKey HydraKey)) -> Party forall a b. (a, b) -> a fst ((Party, Secret (SigningKey HydraKey)) -> Party) -> [(Party, Secret (SigningKey HydraKey))] -> [Party] forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> [(Party, Secret (SigningKey HydraKey))] selected) program :: Program SimpleTx () program = do VerifiedCandidate SimpleTx verified <- Candidate SimpleTx -> MultiSignature (Snapshot SimpleTx) -> Program SimpleTx (Either (LogicError SimpleTx) (VerifiedCandidate SimpleTx)) forall tx. Candidate tx -> MultiSignature (Snapshot tx) -> Program tx (Either (LogicError tx) (VerifiedCandidate tx)) verifyCandidate (Runtime SimpleTx -> Candidate SimpleTx owned Runtime SimpleTx issuer) MultiSignature (Snapshot SimpleTx) proof Program SimpleTx (Either (LogicError SimpleTx) (VerifiedCandidate SimpleTx)) -> (Either (LogicError SimpleTx) (VerifiedCandidate SimpleTx) -> Program SimpleTx (VerifiedCandidate SimpleTx)) -> Program SimpleTx (VerifiedCandidate SimpleTx) forall a b. Program SimpleTx a -> (a -> Program SimpleTx b) -> Program SimpleTx b forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b >>= (LogicError SimpleTx -> Program SimpleTx (VerifiedCandidate SimpleTx)) -> (VerifiedCandidate SimpleTx -> Program SimpleTx (VerifiedCandidate SimpleTx)) -> Either (LogicError SimpleTx) (VerifiedCandidate SimpleTx) -> Program SimpleTx (VerifiedCandidate SimpleTx) forall a c b. (a -> c) -> (b -> c) -> Either a b -> c either LogicError SimpleTx -> Program SimpleTx (VerifiedCandidate SimpleTx) forall tx a. LogicError tx -> Program tx a reject VerifiedCandidate SimpleTx -> Program SimpleTx (VerifiedCandidate SimpleTx) forall a. a -> Program SimpleTx a forall (f :: * -> *) a. Applicative f => a -> f a pure Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx () forall (f :: * -> *) a. Functor f => f a -> f () void (Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx ()) -> Program SimpleTx (Runtime SimpleTx) -> Program SimpleTx () forall a b. (a -> b) -> a -> b $ Runtime SimpleTx -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall tx. Runtime tx -> Command tx -> Program tx (Runtime tx) Staging.stage (if Bool collects then Runtime SimpleTx collecting else Runtime SimpleTx initial) (Command SimpleTx -> Program SimpleTx (Runtime SimpleTx)) -> Command SimpleTx -> Program SimpleTx (Runtime SimpleTx) forall a b. (a -> b) -> a -> b $ VerifiedCandidate SimpleTx -> Command SimpleTx forall tx. VerifiedCandidate tx -> Command tx Owner.confirmSnapshot VerifiedCandidate SimpleTx verified accepted :: Bool accepted = case Program SimpleTx () -> Outcome SimpleTx run Program SimpleTx () program of Continue [SnapshotConfirmed{}] [] -> Bool True; Outcome SimpleTx _ -> Bool False suppliedIdentity :: [Integer] suppliedIdentity = [if Bool foreignHead then Integer 1 else Integer 0, SnapshotVersion -> Integer forall a b. (Integral a, Num b) => a -> b fromIntegral SnapshotVersion version, SnapshotNumber -> Integer forall a b. (Integral a, Num b) => a -> b fromIntegral SnapshotNumber number, if Bool otherContents then Integer 1 else Integer 0] Bool accepted Bool -> Bool -> IO () forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO () `shouldBe` Bool -> [Integer] -> [Integer] -> [Integer] -> [Integer] -> Bool Agda.candidateConfirmationRef Bool collects [Integer 0, Integer 0, Integer 1, Integer 0] [Integer] suppliedIdentity [Integer 0, Integer 1, Integer 2] [Integer] members run :: Program.Program SimpleTx () -> Outcome SimpleTx run :: Program SimpleTx () -> Outcome SimpleTx run = InterpreterConfig SimpleTx -> Program SimpleTx () -> Outcome SimpleTx forall tx. InterpreterConfig tx -> Program tx () -> Outcome tx Interpreter.runProgram (Ledger SimpleTx -> InterpreterConfig SimpleTx forall tx. IsTx tx => Ledger tx -> InterpreterConfig tx testInterpreterConfig Ledger SimpleTx simpleLedger) refused :: Outcome SimpleTx -> Bool refused :: Outcome SimpleTx -> Bool refused = \case Error AssertionFailed{} -> Bool True; Outcome SimpleTx _ -> Bool False invalidSignatures :: Outcome SimpleTx -> Bool invalidSignatures :: Outcome SimpleTx -> Bool invalidSignatures = \case Error (RequireFailed InvalidMultisignature{}) -> Bool True; Outcome SimpleTx _ -> Bool False initial :: Owner.Runtime SimpleTx initial :: Runtime SimpleTx initial = OpenState SimpleTx -> Runtime SimpleTx forall tx. IsChainState tx => OpenState tx -> Runtime tx Owner.start (OpenState SimpleTx -> Runtime SimpleTx) -> OpenState SimpleTx -> Runtime SimpleTx forall a b. (a -> b) -> a -> b $ NodeState SimpleTx -> OpenState SimpleTx Scenario.openState NodeState SimpleTx Scenario.initialNode collecting :: Owner.Runtime SimpleTx collecting :: Runtime SimpleTx collecting = Snapshot SimpleTx -> Runtime SimpleTx owner Snapshot SimpleTx snapshot owned :: Owner.Runtime SimpleTx -> Owner.Candidate SimpleTx owned :: Runtime SimpleTx -> Candidate SimpleTx owned = Candidate SimpleTx -> Maybe (Candidate SimpleTx) -> Candidate SimpleTx forall a. a -> Maybe a -> a fromMaybe (Text -> Candidate SimpleTx forall a t. (HasCallStack, IsText t) => t -> a error Text "fixture has no owned candidate") (Maybe (Candidate SimpleTx) -> Candidate SimpleTx) -> (Runtime SimpleTx -> Maybe (Candidate SimpleTx)) -> Runtime SimpleTx -> Candidate SimpleTx forall b c a. (b -> c) -> (a -> b) -> a -> c . Runtime SimpleTx -> Maybe (Candidate SimpleTx) forall tx. Runtime tx -> Maybe (Candidate tx) Owner.candidate owner :: Snapshot SimpleTx -> Owner.Runtime SimpleTx owner :: Snapshot SimpleTx -> Runtime SimpleTx owner Snapshot SimpleTx candidate = OpenState SimpleTx -> Runtime SimpleTx forall tx. IsChainState tx => OpenState tx -> Runtime tx Owner.start (OpenState SimpleTx -> Runtime SimpleTx) -> OpenState SimpleTx -> Runtime SimpleTx forall a b. (a -> b) -> a -> b $ NodeState SimpleTx -> OpenState SimpleTx Scenario.openState (NodeState SimpleTx -> OpenState SimpleTx) -> NodeState SimpleTx -> OpenState SimpleTx forall a b. (a -> b) -> a -> b $ Snapshot SimpleTx -> NodeState SimpleTx node Snapshot SimpleTx candidate node :: Snapshot SimpleTx -> NodeState SimpleTx node :: Snapshot SimpleTx -> NodeState SimpleTx node Snapshot SimpleTx candidate = let open :: OpenState SimpleTx open = NodeState SimpleTx -> OpenState SimpleTx Scenario.openState NodeState SimpleTx Scenario.initialNode coordinated :: CoordinatedHeadState SimpleTx coordinated = OpenState SimpleTx open.coordinatedHeadState{localUTxO = candidate.utxo, seenSnapshot = mkSeenSnapshot candidate mempty} in NodeState SimpleTx Scenario.initialNode{headState = Open open{coordinatedHeadState = coordinated}} snapshot, different :: Snapshot SimpleTx snapshot :: Snapshot SimpleTx snapshot = SimpleTx -> Snapshot SimpleTx snapshotFor (SimpleTx -> Snapshot SimpleTx) -> SimpleTx -> Snapshot SimpleTx forall a b. (a -> b) -> a -> b $ Integer -> UTxOType SimpleTx -> UTxOType SimpleTx -> SimpleTx SimpleTx Integer 1 (Integer -> UTxOType SimpleTx utxoRef Integer 1) (Integer -> UTxOType SimpleTx utxoRef Integer 2) different :: Snapshot SimpleTx different = SimpleTx -> Snapshot SimpleTx snapshotFor (SimpleTx -> Snapshot SimpleTx) -> SimpleTx -> Snapshot SimpleTx forall a b. (a -> b) -> a -> b $ Integer -> UTxOType SimpleTx -> UTxOType SimpleTx -> SimpleTx SimpleTx Integer 2 (Integer -> UTxOType SimpleTx utxoRef Integer 1) (Integer -> UTxOType SimpleTx utxoRef Integer 3) snapshotFor :: SimpleTx -> Snapshot SimpleTx snapshotFor :: SimpleTx -> Snapshot SimpleTx snapshotFor SimpleTx tx = Snapshot SimpleTx Scenario.initialSnapshot{number = 1, confirmed = [tx], utxo = tx.txOutputs, accumulator = Accumulator.buildFromUTxO @SimpleTx tx.txOutputs, appliedAccumulator = Accumulator.buildFromUTxO @SimpleTx tx.txOutputs} signatures :: Snapshot SimpleTx -> MultiSignature (Snapshot SimpleTx) signatures :: Snapshot SimpleTx -> MultiSignature (Snapshot SimpleTx) signatures Snapshot SimpleTx candidate = Map Party (Signature (Snapshot SimpleTx)) -> [Party] -> MultiSignature (Snapshot SimpleTx) forall k a. Ord k => Map k (Signature a) -> [k] -> MultiSignature a aggregateInOrder ([(Party, Signature (Snapshot SimpleTx))] -> Map Party (Signature (Snapshot SimpleTx)) forall k a. Ord k => [(k, a)] -> Map k a Map.fromList [(Party alice, Secret (SigningKey HydraKey) -> Snapshot SimpleTx -> Signature (Snapshot SimpleTx) forall a. SignableRepresentation a => Secret (SigningKey HydraKey) -> a -> Signature a sign Secret (SigningKey HydraKey) aliceSk Snapshot SimpleTx candidate), (Party bob, Secret (SigningKey HydraKey) -> Snapshot SimpleTx -> Signature (Snapshot SimpleTx) forall a. SignableRepresentation a => Secret (SigningKey HydraKey) -> a -> Signature a sign Secret (SigningKey HydraKey) bobSk Snapshot SimpleTx candidate), (Party carol, Secret (SigningKey HydraKey) -> Snapshot SimpleTx -> Signature (Snapshot SimpleTx) forall a. SignableRepresentation a => Secret (SigningKey HydraKey) -> a -> Signature a sign Secret (SigningKey HydraKey) carolSk Snapshot SimpleTx candidate)]) [Party] Scenario.scenarioParties withSignatures :: Snapshot SimpleTx -> NodeState SimpleTx withSignatures :: Snapshot SimpleTx -> NodeState SimpleTx withSignatures Snapshot SimpleTx signed = let open :: OpenState SimpleTx open = NodeState SimpleTx -> OpenState SimpleTx Scenario.openState (NodeState SimpleTx -> OpenState SimpleTx) -> NodeState SimpleTx -> OpenState SimpleTx forall a b. (a -> b) -> a -> b $ Snapshot SimpleTx -> NodeState SimpleTx node Snapshot SimpleTx snapshot seen :: SeenSnapshot SimpleTx seen = Snapshot SimpleTx -> Map Party (Signature (Snapshot SimpleTx)) -> SeenSnapshot SimpleTx forall tx. IsTx tx => Snapshot tx -> Map Party (Signature (Snapshot tx)) -> SeenSnapshot tx mkSeenSnapshot Snapshot SimpleTx snapshot ([(Party, Signature (Snapshot SimpleTx))] -> Map Party (Signature (Snapshot SimpleTx)) forall k a. Ord k => [(k, a)] -> Map k a Map.fromList [(Party alice, Secret (SigningKey HydraKey) -> Snapshot SimpleTx -> Signature (Snapshot SimpleTx) forall a. SignableRepresentation a => Secret (SigningKey HydraKey) -> a -> Signature a sign Secret (SigningKey HydraKey) aliceSk Snapshot SimpleTx signed), (Party bob, Secret (SigningKey HydraKey) -> Snapshot SimpleTx -> Signature (Snapshot SimpleTx) forall a. SignableRepresentation a => Secret (SigningKey HydraKey) -> a -> Signature a sign Secret (SigningKey HydraKey) bobSk Snapshot SimpleTx signed)]) in NodeState SimpleTx Scenario.initialNode{headState = Open open{coordinatedHeadState = open.coordinatedHeadState{seenSnapshot = seen}}}