{-# LANGUAGE OverloadedRecordDot #-}
{-# OPTIONS_GHC -Wno-ambiguous-fields #-}
module Hydra.HeadLogic.SnapshotProgramSpec (spec) where
import Data.Aeson (eitherDecode, encode)
import Data.List ((!!))
import Data.Map.Strict qualified as Map
import Data.Sequence qualified as Seq
import Hydra.Agda.OffChainReference (HsReqTxOutcome (..), HsReqTxTerminal (..), HsSnapshotChange (..), HsSnapshotEffect (..), HsSnapshotOutcome (..), HsSnapshotPhase (..), HsSnapshotRejection (..), HsSnapshotWait (..), ackSnOutcomeRef, reqSnOutcomeRef, reqTxKnownOutcomeRef)
import Hydra.Chain (PostChainTx (DecrementTx, IncrementTx))
import Hydra.HeadLogic.Interpreter qualified as Interpreter
import Hydra.HeadLogic.Program (foldProgram, instruction)
import Hydra.HeadLogic.Program qualified as Program
import Hydra.HeadLogic.Rules.Network.AckSn qualified as AckSn
import Hydra.HeadLogic.Rules.Network.ReqSn qualified as ReqSn
import Hydra.HeadLogic.Rules.Network.ReqTx qualified as ReqTx
import Hydra.HeadLogic.Snapshot.Cached qualified as Cached
import Hydra.HeadLogic.Trace qualified as Trace
import Hydra.HeadLogic.Workflow qualified as Workflow
import Hydra.Ledger (Ledger (..), ValidationError (..))
import Hydra.Ledger.Simple (SimpleTx, SimpleTxOut, simpleLedger)
import Hydra.Network.Message (Message (..))
import Hydra.Node (defaultTxTTL)
import Hydra.Node.Environment (Environment)
import Hydra.Node.HeadLogic (
CoordinatedHeadState (
allTxs,
confirmedSnapshot,
decommitTx,
localTxs,
localUTxO,
seenSnapshot
),
Effect (NetworkEffect, OnChainEffect),
HeadState (Open),
LogicError (RequireFailed),
OpenState (coordinatedHeadState),
Outcome (Continue, Error, Wait, effects),
RequirementFailure (
AckSnNumberInvalid,
InvalidMultisignature,
ReqSnNotLeader,
ReqSnNumberInvalid,
SnapshotAlreadySigned,
SnapshotDoesNotApply
),
SeenSnapshot (
LastSeenSnapshot,
NoSeenSnapshot,
RequestedSnapshot,
SeenSnapshot,
cachedSnapshot
),
StateChanged (
CommitApproved,
DecommitApproved,
PartySignedSnapshot,
SnapshotConfirmed,
SnapshotRequestDecided,
SnapshotRequested,
TransactionReceived
),
WaitReason (
WaitOnNotApplicableTx,
WaitOnSeenSnapshot,
WaitOnSnapshotNumber,
WaitOnSnapshotVersion,
WaitOnTxs
),
aggregateState,
mkSeenSnapshot,
ruleEnvironment,
)
import Hydra.Node.HeadLogic.Configuration qualified as Configuration
import Hydra.Node.State (Deposit (..), DepositStatus (..), NodeState (..), initialChainTime)
import Hydra.Prelude hiding (state, trace)
import Hydra.Tx (txId)
import Hydra.Tx.Crypto (VerificationError (InvalidSignatures), getVerificationKey, sign)
import Hydra.Tx.Snapshot (ConfirmedSnapshot (..), Snapshot (..), getSnapshot)
import Test.Hydra.HeadLogic.Debugger qualified as Debug
import Test.Hydra.HeadLogic.Explorer qualified as Explorer
import Test.Hydra.HeadLogic.Interpreter (testInterpreterConfig)
import Test.Hydra.HeadLogic.Registry qualified as Registry
import Test.Hydra.HeadLogic.Replay qualified as Replay
import Test.Hydra.HeadLogic.Scenario qualified as Scenario
import Test.Hydra.HeadLogic.Settlement qualified as Settlement
import Test.Hydra.Ledger.Simple (utxoRef)
import Test.Hydra.Node.Fixture (
alice,
aliceSk,
bob,
bobSk,
carol,
carolSk,
testHeadId,
)
import Test.Hydra.Prelude (
Spec,
describe,
failure,
it,
prop,
shouldBe,
shouldContain,
shouldSatisfy,
)
import Test.QuickCheck (chooseInt, counterexample, forAll, shuffle, vectorOf)
spec :: Spec
spec :: Spec
spec = do
Spec
reqSnSpec
String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"crem phases with program actions" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ AckRule -> Spec
specWith (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 ())
-> (Args SimpleTx -> Workflow SimpleTx AckTopology ()) -> AckRule
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Args SimpleTx -> Workflow SimpleTx AckTopology ()
forall tx. IsChainState tx => Args tx -> Workflow tx AckTopology ()
AckSn.workflow)
Spec
integrationSpec
reqSnSpec :: Spec
reqSnSpec :: Spec
reqSnSpec = do
String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"bounded ReqSn Agda agreement" (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
"compares independent ReqSn ordered outcomes with declared exclusions" (IO () -> SpecWith (Arg (IO ())))
-> IO () -> SpecWith (Arg (IO ()))
forall a b. (a -> b) -> a -> b
$ do
[SimpleId] -> (SimpleId -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [SimpleId
0 .. SimpleId
2] ((SimpleId -> IO ()) -> IO ()) -> (SimpleId -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \SimpleId
seen ->
[SimpleId] -> (SimpleId -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [SimpleId
0 .. SimpleId
seen] ((SimpleId -> IO ()) -> IO ()) -> (SimpleId -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \SimpleId
confirmed ->
[SimpleId] -> (SimpleId -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [SimpleId
0 .. SimpleId
4] ((SimpleId -> IO ()) -> IO ()) -> (SimpleId -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \SimpleId
sn ->
[Int] -> (Int -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Int
0 .. Int
2] ((Int -> IO ()) -> IO ()) -> (Int -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
sender ->
[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
sv ->
[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
missing ->
[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
applicable -> do
let predecessor :: Snapshot SimpleTx
predecessor = Snapshot SimpleTx
Scenario.initialSnapshot{number = fromIntegral confirmed}
c :: CoordinatedHeadState SimpleTx
c = OpenState SimpleTx
os.coordinatedHeadState{seenSnapshot = LastSeenSnapshot $ fromIntegral seen, confirmedSnapshot = ConfirmedSnapshot predecessor mempty}
ledger :: Ledger SimpleTx
ledger = if Bool
applicable then Ledger SimpleTx
simpleLedger else (ChainSlot
-> UTxOType SimpleTx
-> [SimpleTx]
-> Either (SimpleTx, ValidationError) (UTxOType SimpleTx))
-> Ledger SimpleTx
forall tx.
(ChainSlot
-> UTxOType tx
-> [tx]
-> Either (tx, ValidationError) (UTxOType tx))
-> Ledger tx
Ledger ((ChainSlot
-> UTxOType SimpleTx
-> [SimpleTx]
-> Either (SimpleTx, ValidationError) (UTxOType SimpleTx))
-> Ledger SimpleTx)
-> (ChainSlot
-> UTxOType SimpleTx
-> [SimpleTx]
-> Either (SimpleTx, ValidationError) (UTxOType SimpleTx))
-> Ledger SimpleTx
forall a b. (a -> b) -> a -> b
$ \ChainSlot
_ UTxOType SimpleTx
_ [SimpleTx]
_ -> (SimpleTx, ValidationError)
-> Either (SimpleTx, ValidationError) (Set SimpleTxOut)
forall a b. a -> Either a b
Left (SimpleTx
Scenario.transactionOne, Text -> ValidationError
ValidationError Text
"controlled failure")
outcome :: Outcome SimpleTx
outcome =
InterpreterConfig SimpleTx
-> Program SimpleTx () -> Outcome SimpleTx
forall tx. InterpreterConfig tx -> Program tx () -> Outcome tx
Interpreter.runProgram (Environment -> Ledger SimpleTx -> InterpreterConfig SimpleTx
forall tx.
IsTx tx =>
Environment -> Ledger tx -> InterpreterConfig tx
Configuration.interpreterConfig Environment
env Ledger SimpleTx
ledger) (Program SimpleTx () -> Outcome SimpleTx)
-> Program SimpleTx () -> Outcome SimpleTx
forall a b. (a -> b) -> a -> b
$
Workflow SimpleTx ReqSnTopology () -> Program SimpleTx ()
forall {vertex} tx (topology :: Topology vertex) result.
Workflow tx topology result -> Program tx result
Workflow.run (Workflow SimpleTx ReqSnTopology () -> Program SimpleTx ())
-> Workflow SimpleTx ReqSnTopology () -> Program SimpleTx ()
forall a b. (a -> b) -> a -> b
$
Args SimpleTx -> Workflow SimpleTx ReqSnTopology ()
forall tx.
IsChainState tx =>
Args tx -> Workflow tx ReqSnTopology ()
ReqSn.workflow
ReqSn.Args
{ $sel:env:Args :: RuleEnvironment
env = Environment -> RuleEnvironment
Configuration.ruleEnvironment Environment
env
, $sel:pendingDeposits:Args :: PendingDeposits SimpleTx
pendingDeposits = Map SimpleId (Deposit SimpleTx)
PendingDeposits SimpleTx
forall a. Monoid a => a
mempty
, $sel:chainPointTime:Args :: ChainPointTime
chainPointTime = NodeState SimpleTx
initial.chainPointTime
, $sel:openState:Args :: OpenState SimpleTx
openState = OpenState SimpleTx
os{coordinatedHeadState = c}
, $sel:ttl:Args :: TTL
ttl = TTL
1
, $sel:sender:Args :: Party
sender = [Party]
Scenario.scenarioParties [Party] -> Int -> Party
forall a. HasCallStack => [a] -> Int -> a
!! Int
sender
, $sel:snapshotVersion:Args :: SnapshotVersion
snapshotVersion = SnapshotVersion
sv
, $sel:snapshotNumber:Args :: SnapshotNumber
snapshotNumber = SimpleId -> SnapshotNumber
forall a b. (Integral a, Num b) => a -> b
fromIntegral SimpleId
sn
, $sel:transactionIds:Args :: [TxIdType SimpleTx]
transactionIds = [if Bool
missing then SimpleId
TxIdType SimpleTx
99 else SimpleId
TxIdType SimpleTx
1]
, $sel:decommitTx:Args :: Maybe SimpleTx
decommitTx = Maybe SimpleTx
forall a. Maybe a
Nothing
, $sel:depositTxId:Args :: Maybe (TxIdType SimpleTx)
depositTxId = Maybe SimpleId
Maybe (TxIdType SimpleTx)
forall a. Maybe a
Nothing
}
Outcome SimpleTx -> HsSnapshotOutcome
projectSnapshotOutcome Outcome SimpleTx
outcome HsSnapshotOutcome -> HsSnapshotOutcome -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` SimpleId
-> SimpleId
-> SimpleId
-> SimpleId
-> SimpleId
-> SimpleId
-> SimpleId
-> SimpleId
-> Bool
-> HsSnapshotOutcome
reqSnOutcomeRef SimpleId
seen SimpleId
confirmed SimpleId
0 (SnapshotVersion -> SimpleId
forall a b. (Integral a, Num b) => a -> b
fromIntegral SnapshotVersion
sv) SimpleId
sn SimpleId
2 (Int -> SimpleId
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
sender) (if Bool
missing then SimpleId
1 else SimpleId
0) Bool
applicable
type AckRule = AckSn.Args SimpleTx -> Program.Program SimpleTx ()
specWith :: AckRule -> Spec
specWith :: AckRule -> Spec
specWith AckRule
runAckSn = do
String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"AckSn program" (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
"preserves increment and decrement approval ordering at confirmation" (IO () -> SpecWith (Arg (IO ())))
-> IO () -> SpecWith (Arg (IO ()))
forall a b. (a -> b) -> a -> b
$ do
[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
decommitting -> do
let pending :: Map SimpleId (Deposit SimpleTx)
pending = if Bool
decommitting then Map SimpleId (Deposit SimpleTx)
forall a. Monoid a => a
mempty else SimpleId -> Deposit SimpleTx -> Map SimpleId (Deposit SimpleTx)
forall k a. k -> a -> Map k a
Map.singleton SimpleId
7 (DepositStatus -> Deposit SimpleTx
depositFixture DepositStatus
Active)
base :: OpenState SimpleTx
base = OpenState SimpleTx
os{coordinatedHeadState = os.coordinatedHeadState{decommitTx = if decommitting then Just Scenario.transactionOne else Nothing}}
ids :: [SimpleId]
ids = [SimpleId
1 | Bool -> Bool
not Bool
decommitting]
req :: Outcome SimpleTx
req =
InterpreterConfig SimpleTx
-> Program SimpleTx () -> Outcome SimpleTx
forall tx. InterpreterConfig tx -> Program tx () -> Outcome tx
Interpreter.runProgram (Environment -> Ledger SimpleTx -> InterpreterConfig SimpleTx
forall tx.
IsTx tx =>
Environment -> Ledger tx -> InterpreterConfig tx
Configuration.interpreterConfig Environment
env Ledger SimpleTx
simpleLedger) (Program SimpleTx () -> Outcome SimpleTx)
-> Program SimpleTx () -> Outcome SimpleTx
forall a b. (a -> b) -> a -> b
$
Workflow SimpleTx ReqSnTopology () -> Program SimpleTx ()
forall {vertex} tx (topology :: Topology vertex) result.
Workflow tx topology result -> Program tx result
Workflow.run (Workflow SimpleTx ReqSnTopology () -> Program SimpleTx ())
-> Workflow SimpleTx ReqSnTopology () -> Program SimpleTx ()
forall a b. (a -> b) -> a -> b
$
Args SimpleTx -> Workflow SimpleTx ReqSnTopology ()
forall tx.
IsChainState tx =>
Args tx -> Workflow tx ReqSnTopology ()
ReqSn.workflow
ReqSn.Args
{ $sel:env:Args :: RuleEnvironment
env = Environment -> RuleEnvironment
Configuration.ruleEnvironment Environment
env
, $sel:pendingDeposits:Args :: PendingDeposits SimpleTx
pendingDeposits = Map SimpleId (Deposit SimpleTx)
PendingDeposits SimpleTx
pending
, $sel:chainPointTime:Args :: ChainPointTime
chainPointTime = NodeState SimpleTx
initial.chainPointTime
, $sel:openState:Args :: OpenState SimpleTx
openState = OpenState SimpleTx
base
, $sel:ttl:Args :: TTL
ttl = TTL
1
, $sel:sender:Args :: Party
sender = Party
alice
, $sel:snapshotVersion:Args :: SnapshotVersion
snapshotVersion = SnapshotVersion
0
, $sel:snapshotNumber:Args :: SnapshotNumber
snapshotNumber = SnapshotNumber
1
, $sel:transactionIds:Args :: [TxIdType SimpleTx]
transactionIds = [SimpleId]
[TxIdType SimpleTx]
ids
, $sel:decommitTx:Args :: Maybe SimpleTx
decommitTx = if Bool
decommitting then SimpleTx -> Maybe SimpleTx
forall a. a -> Maybe a
Just SimpleTx
Scenario.transactionOne else Maybe SimpleTx
forall a. Maybe a
Nothing
, $sel:depositTxId:Args :: Maybe (TxIdType SimpleTx)
depositTxId = if Bool
decommitting then Maybe SimpleId
Maybe (TxIdType SimpleTx)
forall a. Maybe a
Nothing else SimpleId -> Maybe SimpleId
forall a. a -> Maybe a
Just SimpleId
7
}
afterRequest :: NodeState SimpleTx
afterRequest = NodeState SimpleTx -> Outcome SimpleTx -> NodeState SimpleTx
forall tx.
IsChainState tx =>
NodeState tx -> Outcome tx -> NodeState tx
aggregateState NodeState SimpleTx
initial{headState = Open base} Outcome SimpleTx
req
afterOpen :: OpenState SimpleTx
afterOpen = NodeState SimpleTx -> OpenState SimpleTx
Scenario.openState NodeState SimpleTx
afterRequest
case OpenState SimpleTx
afterOpen.coordinatedHeadState.seenSnapshot of
SeenSnapshot{$sel:cachedSnapshot:NoSeenSnapshot :: forall tx. SeenSnapshot tx -> CachedSnapshot tx
cachedSnapshot = (CachedSnapshot SimpleTx -> Snapshot SimpleTx
forall tx. CachedSnapshot tx -> Snapshot tx
Cached.snapshot -> Snapshot SimpleTx
snapshot)} -> do
let 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
snapshot), (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
snapshot)])
ready :: OpenState SimpleTx
ready = OpenState SimpleTx
afterOpen{coordinatedHeadState = afterOpen.coordinatedHeadState{seenSnapshot = seen}}
new :: Outcome SimpleTx
new =
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) (Program SimpleTx () -> Outcome SimpleTx)
-> Program SimpleTx () -> Outcome SimpleTx
forall a b. (a -> b) -> a -> b
$
AckRule
runAckSn
AckSn.Args
{ $sel:env:Args :: RuleEnvironment
env = Environment -> RuleEnvironment
Configuration.ruleEnvironment (Int -> Environment
Scenario.environment Int
1)
, $sel:chainPointTime:Args :: ChainPointTime
chainPointTime = NodeState SimpleTx
initial.chainPointTime
, $sel:pendingDeposits:Args :: PendingDeposits SimpleTx
pendingDeposits = Map SimpleId (Deposit SimpleTx)
PendingDeposits SimpleTx
pending
, $sel:openState:Args :: OpenState SimpleTx
openState = OpenState SimpleTx
ready
, $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
}
Outcome SimpleTx
new Outcome SimpleTx -> (Outcome SimpleTx -> Bool) -> IO ()
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO ()
`shouldSatisfy` \case
Continue (PartySignedSnapshot{} : SnapshotConfirmed{} : DecommitApproved{} : [StateChanged SimpleTx]
_) (OnChainEffect DecrementTx{} : [Effect SimpleTx]
_) -> Bool
decommitting
Continue (PartySignedSnapshot{} : SnapshotConfirmed{} : CommitApproved{} : [StateChanged SimpleTx]
_) (OnChainEffect IncrementTx{} : [Effect SimpleTx]
_) -> Bool -> Bool
not Bool
decommitting
Outcome SimpleTx
_ -> Bool
False
SeenSnapshot SimpleTx
_ -> String -> IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadThrow m) =>
String -> m a
failure String
"incremental request did not produce a snapshot"
String -> IO () -> SpecWith (Arg (IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"rejecting the last invalid signature discards its staged change" (IO () -> SpecWith (Arg (IO ())))
-> IO () -> SpecWith (Arg (IO ()))
forall a b. (a -> b) -> a -> b
$ do
let state :: NodeState SimpleTx
state = HsSnapshotPhase -> [Int] -> NodeState SimpleTx
ackState HsSnapshotPhase
CollectingSignatures [Int
0, Int
1]
program :: Program SimpleTx ()
program =
AckRule
runAckSn
AckSn.Args
{ $sel:env:Args :: RuleEnvironment
env = Environment -> RuleEnvironment
ruleEnvironment Environment
env
, $sel:chainPointTime:Args :: ChainPointTime
chainPointTime = NodeState SimpleTx
initial.chainPointTime
, $sel:pendingDeposits:Args :: PendingDeposits SimpleTx
pendingDeposits = Map SimpleId (Deposit SimpleTx)
PendingDeposits SimpleTx
forall a. Monoid a => a
mempty
, $sel:openState:Args :: OpenState SimpleTx
openState = NodeState SimpleTx -> OpenState SimpleTx
Scenario.openState NodeState SimpleTx
state
, $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)
aliceSk Snapshot SimpleTx
snapshotFixture
, $sel:snapshotNumber:Args :: SnapshotNumber
snapshotNumber = SnapshotNumber
1
}
(Outcome SimpleTx
outcome, [TraceStep]
trace) = InterpreterConfig SimpleTx
-> Program SimpleTx () -> (Outcome SimpleTx, [TraceStep])
forall tx.
InterpreterConfig tx -> Program tx () -> (Outcome tx, [TraceStep])
Interpreter.traceProgram (Ledger SimpleTx -> InterpreterConfig SimpleTx
forall tx. IsTx tx => Ledger tx -> InterpreterConfig tx
testInterpreterConfig Ledger SimpleTx
simpleLedger) Program SimpleTx ()
program
[TraceStep]
trace [TraceStep] -> [TraceStep] -> IO ()
forall a. (HasCallStack, Show a, Eq a) => [a] -> [a] -> IO ()
`shouldContain` [Text -> TraceStep
Trace.Changed Text
"party signed snapshot"]
(NonEmpty TraceStep -> TraceStep) -> [TraceStep] -> Maybe TraceStep
forall a b. (NonEmpty a -> b) -> [a] -> Maybe b
viaNonEmpty NonEmpty TraceStep -> TraceStep
forall (f :: * -> *) a. IsNonEmpty f a a "last" => f a -> a
last [TraceStep]
trace Maybe TraceStep -> Maybe TraceStep -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` TraceStep -> Maybe TraceStep
forall a. a -> Maybe a
Just TraceStep
Trace.Rejected
Outcome SimpleTx
outcome Outcome SimpleTx -> (Outcome SimpleTx -> Bool) -> IO ()
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO ()
`shouldSatisfy` \case Error (RequireFailed InvalidMultisignature{}) -> Bool
True; Outcome SimpleTx
_ -> Bool
False
NodeState SimpleTx -> Outcome SimpleTx -> NodeState SimpleTx
forall tx.
IsChainState tx =>
NodeState tx -> Outcome tx -> NodeState tx
aggregateState NodeState SimpleTx
state Outcome SimpleTx
outcome NodeState SimpleTx -> NodeState SimpleTx -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` NodeState SimpleTx
state
String -> IO () -> SpecWith (Arg (IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"uses the configured verifier in production and debugger recording" (IO () -> SpecWith (Arg (IO ())))
-> IO () -> SpecWith (Arg (IO ()))
forall a b. (a -> b) -> a -> b
$ do
let state :: NodeState SimpleTx
state = HsSnapshotPhase -> [Int] -> NodeState SimpleTx
ackState HsSnapshotPhase
CollectingSignatures [Int
0, Int
1]
program :: Program SimpleTx ()
program =
AckRule
runAckSn
AckSn.Args
{ $sel:env:Args :: RuleEnvironment
env = Environment -> RuleEnvironment
ruleEnvironment Environment
env
, $sel:chainPointTime:Args :: ChainPointTime
chainPointTime = NodeState SimpleTx
initial.chainPointTime
, $sel:pendingDeposits:Args :: PendingDeposits SimpleTx
pendingDeposits = Map SimpleId (Deposit SimpleTx)
PendingDeposits SimpleTx
forall a. Monoid a => a
mempty
, $sel:openState:Args :: OpenState SimpleTx
openState = NodeState SimpleTx -> OpenState SimpleTx
Scenario.openState NodeState SimpleTx
state
, $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
snapshotFixture
, $sel:snapshotNumber:Args :: SnapshotNumber
snapshotNumber = SnapshotNumber
1
}
config :: Interpreter.InterpreterConfig SimpleTx
config :: InterpreterConfig SimpleTx
config = (Ledger SimpleTx -> InterpreterConfig SimpleTx
forall tx. IsTx tx => Ledger tx -> InterpreterConfig tx
testInterpreterConfig Ledger SimpleTx
simpleLedger){Interpreter.snapshotVerifier = \[VerificationKey HydraKey]
_ MultiSignature (Snapshot SimpleTx)
_ ByteString
_ -> VerificationError -> Either VerificationError ()
forall a b. a -> Either a b
Left (VerificationError -> Either VerificationError ())
-> VerificationError -> Either VerificationError ()
forall a b. (a -> b) -> a -> b
$ NonEmpty (VerificationKey HydraKey) -> VerificationError
InvalidSignatures (Secret (SigningKey HydraKey) -> VerificationKey HydraKey
forall s k. HasVerificationKey s k => s -> VerificationKey k
getVerificationKey Secret (SigningKey HydraKey)
carolSk VerificationKey HydraKey
-> [VerificationKey HydraKey]
-> NonEmpty (VerificationKey HydraKey)
forall a. a -> [a] -> NonEmpty a
:| [])}
outcome :: Outcome SimpleTx
outcome = InterpreterConfig SimpleTx
-> Program SimpleTx () -> Outcome SimpleTx
forall tx. InterpreterConfig tx -> Program tx () -> Outcome tx
Interpreter.runProgram InterpreterConfig SimpleTx
config Program SimpleTx ()
program
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) Program SimpleTx ()
program Outcome SimpleTx -> (Outcome SimpleTx -> Bool) -> IO ()
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO ()
`shouldSatisfy` \case Continue{} -> Bool
True; Outcome SimpleTx
_ -> Bool
False
Outcome SimpleTx
outcome Outcome SimpleTx -> (Outcome SimpleTx -> Bool) -> IO ()
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO ()
`shouldSatisfy` \case
Error (RequireFailed (InvalidMultisignature Text
_ [VerificationKey HydraKey]
failedKeys)) -> [VerificationKey HydraKey]
failedKeys [VerificationKey HydraKey] -> [VerificationKey HydraKey] -> Bool
forall a. Eq a => a -> a -> Bool
== [Secret (SigningKey HydraKey) -> VerificationKey HydraKey
forall s k. HasVerificationKey s k => s -> VerificationKey k
getVerificationKey Secret (SigningKey HydraKey)
carolSk]
Outcome SimpleTx
_ -> Bool
False
NodeState SimpleTx -> Outcome SimpleTx -> NodeState SimpleTx
forall tx.
IsChainState tx =>
NodeState tx -> Outcome tx -> NodeState tx
aggregateState NodeState SimpleTx
state Outcome SimpleTx
outcome NodeState SimpleTx -> NodeState SimpleTx -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` NodeState SimpleTx
state
Prepared
recorded <- (Text -> IO Prepared)
-> (Prepared -> IO Prepared) -> Either Text Prepared -> IO Prepared
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (String -> IO Prepared
forall a. String -> IO a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> IO Prepared) -> (Text -> String) -> Text -> IO Prepared
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
forall a. ToString a => a -> String
toString) Prepared -> IO Prepared
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either Text Prepared -> IO Prepared)
-> Either Text Prepared -> IO Prepared
forall a b. (a -> b) -> a -> b
$ ReplyMode
-> InterpreterConfig SimpleTx
-> Program SimpleTx ()
-> Either Text Prepared
Debug.prepare ReplyMode
Debug.RecordReplies InterpreterConfig SimpleTx
config Program SimpleTx ()
program
InterpreterConfig SimpleTx
-> Program SimpleTx () -> Outcome SimpleTx
forall tx. InterpreterConfig tx -> Program tx () -> Outcome tx
Interpreter.runProgram InterpreterConfig SimpleTx
config Prepared
recorded.lowered Outcome SimpleTx -> Outcome SimpleTx -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Outcome SimpleTx
outcome
Prepared
replayed <- (Text -> IO Prepared)
-> (Prepared -> IO Prepared) -> Either Text Prepared -> IO Prepared
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (String -> IO Prepared
forall a. String -> IO a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> IO Prepared) -> (Text -> String) -> Text -> IO Prepared
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
forall a. ToString a => a -> String
toString) Prepared -> IO Prepared
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either Text Prepared -> IO Prepared)
-> Either Text Prepared -> IO Prepared
forall a b. (a -> b) -> a -> b
$ ReplyMode
-> InterpreterConfig SimpleTx
-> Program SimpleTx ()
-> Either Text Prepared
Debug.prepare ([QueryRecord] -> ReplyMode
Debug.RecordedReplies Prepared
recorded.queries) (Ledger SimpleTx -> InterpreterConfig SimpleTx
forall tx. IsTx tx => Ledger tx -> InterpreterConfig tx
testInterpreterConfig Ledger SimpleTx
simpleLedger) Program SimpleTx ()
program
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) Prepared
replayed.lowered Outcome SimpleTx -> Outcome SimpleTx -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Outcome SimpleTx
outcome
String -> IO () -> SpecWith (Arg (IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"records a partial acknowledgement once" (IO () -> SpecWith (Arg (IO ())))
-> IO () -> SpecWith (Arg (IO ()))
forall a b. (a -> b) -> a -> b
$ do
let signature :: Signature (Snapshot SimpleTx)
signature = 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
snapshotFixture
outcome :: Outcome SimpleTx
outcome =
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) (Program SimpleTx () -> Outcome SimpleTx)
-> Program SimpleTx () -> Outcome SimpleTx
forall a b. (a -> b) -> a -> b
$
AckRule
runAckSn
AckSn.Args
{ $sel:env:Args :: RuleEnvironment
env = Environment -> RuleEnvironment
ruleEnvironment Environment
env
, $sel:chainPointTime:Args :: ChainPointTime
chainPointTime = NodeState SimpleTx
initial.chainPointTime
, $sel:pendingDeposits:Args :: PendingDeposits SimpleTx
pendingDeposits = Map SimpleId (Deposit SimpleTx)
PendingDeposits SimpleTx
forall a. Monoid a => a
mempty
, $sel:openState:Args :: OpenState SimpleTx
openState = NodeState SimpleTx -> OpenState SimpleTx
Scenario.openState (NodeState SimpleTx -> OpenState SimpleTx)
-> NodeState SimpleTx -> OpenState SimpleTx
forall a b. (a -> b) -> a -> b
$ HsSnapshotPhase -> [Int] -> NodeState SimpleTx
ackState HsSnapshotPhase
CollectingSignatures []
, $sel:sender:Args :: Party
sender = Party
alice
, $sel:signed:Args :: Signature (Snapshot SimpleTx)
signed = Signature (Snapshot SimpleTx)
signature
, $sel:snapshotNumber:Args :: SnapshotNumber
snapshotNumber = SnapshotNumber
1
}
event :: StateChanged SimpleTx
event = SnapshotNumber
-> Party -> Signature (Snapshot SimpleTx) -> StateChanged SimpleTx
forall tx.
SnapshotNumber
-> Party -> Signature (Snapshot tx) -> StateChanged tx
PartySignedSnapshot SnapshotNumber
1 Party
alice Signature (Snapshot SimpleTx)
signature
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 [StateChanged SimpleTx
event] []
String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"bounded AckSn Agda agreement" (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
"compares independent AckSn outcomes including rejection after staging" (IO () -> SpecWith (Arg (IO ())))
-> IO () -> SpecWith (Arg (IO ()))
forall a b. (a -> b) -> a -> b
$ do
[HsSnapshotPhase] -> (HsSnapshotPhase -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [HsSnapshotPhase
forall a. Bounded a => a
minBound .. HsSnapshotPhase
forall a. Bounded a => a
maxBound] ((HsSnapshotPhase -> IO ()) -> IO ())
-> (HsSnapshotPhase -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \HsSnapshotPhase
phase ->
[[Int]] -> ([Int] -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ ([Int] -> [[Int]]
forall a. [a] -> [[a]]
subsequences [Int
0, Int
1, Int
2]) (([Int] -> IO ()) -> IO ()) -> ([Int] -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \[Int]
signers ->
[Int] -> (Int -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Int
0 .. Int
2] ((Int -> IO ()) -> IO ()) -> (Int -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
sender ->
[SnapshotNumber] -> (SnapshotNumber -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [SnapshotNumber
0 .. SnapshotNumber
3] ((SnapshotNumber -> IO ()) -> IO ())
-> (SnapshotNumber -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \SnapshotNumber
sn ->
[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
valid -> do
let state :: NodeState SimpleTx
state = HsSnapshotPhase -> [Int] -> NodeState SimpleTx
ackState HsSnapshotPhase
phase [Int]
signers
signature :: Signature (Snapshot SimpleTx)
signature = Secret (SigningKey HydraKey)
-> Snapshot SimpleTx -> Signature (Snapshot SimpleTx)
forall a.
SignableRepresentation a =>
Secret (SigningKey HydraKey) -> a -> Signature a
sign ([Secret (SigningKey HydraKey)
aliceSk, Secret (SigningKey HydraKey)
bobSk, Secret (SigningKey HydraKey)
carolSk] [Secret (SigningKey HydraKey)]
-> Int -> Secret (SigningKey HydraKey)
forall a. HasCallStack => [a] -> Int -> a
!! Int
sender) (if Bool
valid then Snapshot SimpleTx
snapshotFixture else Snapshot SimpleTx
Scenario.initialSnapshot)
outcome :: Outcome SimpleTx
outcome =
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) (Program SimpleTx () -> Outcome SimpleTx)
-> Program SimpleTx () -> Outcome SimpleTx
forall a b. (a -> b) -> a -> b
$
AckRule
runAckSn
AckSn.Args
{ $sel:env:Args :: RuleEnvironment
env = Environment -> RuleEnvironment
Configuration.ruleEnvironment (Int -> Environment
Scenario.environment Int
1)
, $sel:chainPointTime:Args :: ChainPointTime
chainPointTime = NodeState SimpleTx
initial.chainPointTime
, $sel:pendingDeposits:Args :: PendingDeposits SimpleTx
pendingDeposits = Map SimpleId (Deposit SimpleTx)
PendingDeposits SimpleTx
forall a. Monoid a => a
mempty
, $sel:openState:Args :: OpenState SimpleTx
openState = NodeState SimpleTx -> OpenState SimpleTx
Scenario.openState NodeState SimpleTx
state
, $sel:sender:Args :: Party
sender = [Party]
Scenario.scenarioParties [Party] -> Int -> Party
forall a. HasCallStack => [a] -> Int -> a
!! Int
sender
, $sel:signed:Args :: Signature (Snapshot SimpleTx)
signed = Signature (Snapshot SimpleTx)
signature
, $sel:snapshotNumber:Args :: SnapshotNumber
snapshotNumber = SnapshotNumber
sn
}
seen :: SimpleId
seen = if HsSnapshotPhase
phase HsSnapshotPhase -> HsSnapshotPhase -> Bool
forall a. Eq a => a -> a -> Bool
== HsSnapshotPhase
NeverSeen then SimpleId
0 else SimpleId
1
Outcome SimpleTx -> HsSnapshotOutcome
projectSnapshotOutcome Outcome SimpleTx
outcome HsSnapshotOutcome -> HsSnapshotOutcome -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` HsSnapshotPhase
-> SimpleId
-> SimpleId
-> [SimpleId]
-> SimpleId
-> SimpleId
-> Bool
-> Bool
-> SimpleId
-> HsSnapshotOutcome
ackSnOutcomeRef HsSnapshotPhase
phase SimpleId
seen (SnapshotNumber -> SimpleId
forall a b. (Integral a, Num b) => a -> b
fromIntegral SnapshotNumber
sn) (Int -> SimpleId
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> SimpleId) -> [Int] -> [SimpleId]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Int]
signers) (Int -> SimpleId
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
sender) SimpleId
2 Bool
valid Bool
True SimpleId
1
integrationSpec :: Spec
integrationSpec :: Spec
integrationSpec = do
String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"registry regressions and bounded recovery policies" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"preserves registry payloads and reconciles local UTxO at every scheduled prefix" (Property -> Spec) -> Property -> Spec
forall a b. (a -> b) -> a -> b
$
Gen [Int] -> ([Int] -> Property) -> Property
forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll (Int -> Gen Int -> Gen [Int]
forall a. Int -> Gen a -> Gen [a]
vectorOf Int
40 (Gen Int -> Gen [Int]) -> Gen Int -> Gen [Int]
forall a b. (a -> b) -> a -> b
$ (Int, Int) -> Gen Int
chooseInt (Int
0, Int
10000)) (([Int] -> Property) -> Property)
-> ([Int] -> Property) -> Property
forall a b. (a -> b) -> a -> b
$ \[Int]
choices ->
let worlds :: [World]
worlds = (World -> Int -> World) -> World -> [Int] -> [World]
forall b a. (b -> a -> b) -> b -> [a] -> [b]
scanl World -> Int -> World
scheduleChoice World
Scenario.initialWorld [Int]
choices
in String -> Bool -> Property
forall prop. Testable prop => String -> prop -> Property
counterexample ([Maybe Text] -> String
forall b a. (Show a, IsString b) => a -> b
show ([Maybe Text] -> String) -> [Maybe Text] -> String
forall a b. (a -> b) -> a -> b
$ (World -> Maybe Text) -> [World] -> [Maybe Text]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap World -> Maybe Text
Explorer.safetyFailure [World]
worlds) (Bool -> Property) -> Bool -> Property
forall a b. (a -> b) -> a -> b
$ (World -> Bool) -> [World] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Maybe Text -> Bool
forall a. Maybe a -> Bool
isNothing (Maybe Text -> Bool) -> (World -> Maybe Text) -> World -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. World -> Maybe Text
Explorer.safetyFailure) [World]
worlds
String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"confirms dependent transactions after fair delivery without retry exhaustion" (Property -> Spec) -> Property -> Spec
forall a b. (a -> b) -> a -> b
$
Gen [Delivery] -> ([Delivery] -> Property) -> Property
forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll ([Delivery] -> Gen [Delivery]
forall a. [a] -> Gen [a]
shuffle World
Scenario.initialWorld.pending) (([Delivery] -> Property) -> Property)
-> ([Delivery] -> Property) -> Property
forall a b. (a -> b) -> a -> b
$ \[Delivery]
deliveries ->
let final :: World
final = Int -> World -> World
drainWorld Int
100 World
Scenario.initialWorld{Scenario.pending = deliveries}
in String -> Bool -> Property
forall prop. Testable prop => String -> prop -> Property
counterexample (World -> String
forall b a. (Show a, IsString b) => a -> b
show World
final) (Bool -> Property) -> Bool -> Property
forall a b. (a -> b) -> a -> b
$
Maybe Text -> Bool
forall a. Maybe a -> Bool
isNothing (World -> Maybe Text
Explorer.invariantFailure World
final)
Bool -> Bool -> Bool
&& [Delivery] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null World
final.pending
Bool -> Bool -> Bool
&& [Delivery] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null World
final.retries
Bool -> Bool -> Bool
&& (NodeState SimpleTx -> Bool) -> [NodeState SimpleTx] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all ((UTxOType SimpleTx -> UTxOType SimpleTx -> Bool
forall a. Eq a => a -> a -> Bool
== SimpleId -> UTxOType SimpleTx
utxoRef SimpleId
3) (Set SimpleTxOut -> Bool)
-> (NodeState SimpleTx -> Set SimpleTxOut)
-> NodeState SimpleTx
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (.utxo) (Snapshot SimpleTx -> Set SimpleTxOut)
-> (NodeState SimpleTx -> Snapshot SimpleTx)
-> NodeState SimpleTx
-> Set SimpleTxOut
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConfirmedSnapshot SimpleTx -> Snapshot SimpleTx
forall tx. IsTx tx => ConfirmedSnapshot tx -> Snapshot tx
getSnapshot (ConfirmedSnapshot SimpleTx -> Snapshot SimpleTx)
-> (NodeState SimpleTx -> ConfirmedSnapshot SimpleTx)
-> NodeState SimpleTx
-> Snapshot SimpleTx
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (.confirmedSnapshot) (CoordinatedHeadState SimpleTx -> ConfirmedSnapshot SimpleTx)
-> (NodeState SimpleTx -> CoordinatedHeadState SimpleTx)
-> NodeState SimpleTx
-> ConfirmedSnapshot SimpleTx
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (.coordinatedHeadState) (OpenState SimpleTx -> CoordinatedHeadState SimpleTx)
-> (NodeState SimpleTx -> OpenState SimpleTx)
-> NodeState SimpleTx
-> CoordinatedHeadState SimpleTx
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NodeState SimpleTx -> OpenState SimpleTx
Scenario.openState) World
final.nodes
String -> IO () -> SpecWith (Arg (IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"preserves the validated payload and ignores every retry of an applied transaction" (IO () -> SpecWith (Arg (IO ())))
-> IO () -> SpecWith (Arg (IO ()))
forall a b. (a -> b) -> a -> b
$ do
World
world <- Either Text World -> IO World
forall a. Either Text a -> IO a
requireRight (Either Text World -> IO World) -> Either Text World -> IO World
forall a b. (a -> b) -> a -> b
$ ExecutionMode -> World -> [Action] -> Either Text World
Explorer.runPath ExecutionMode
Scenario.VerifySignatures World
Scenario.initialWorld [Action]
registryRegressionRoute
World -> Maybe Text
Explorer.invariantFailure World
world Maybe Text -> Maybe Text -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Maybe Text
forall a. Maybe a
Nothing
let node :: NodeState SimpleTx
node = World
world.nodes [NodeState SimpleTx] -> Int -> NodeState SimpleTx
forall a. HasCallStack => [a] -> Int -> a
!! Int
1
c :: CoordinatedHeadState SimpleTx
c = (NodeState SimpleTx -> OpenState SimpleTx
Scenario.openState NodeState SimpleTx
node).coordinatedHeadState
request :: Outcome SimpleTx
request =
InterpreterConfig SimpleTx
-> Program SimpleTx () -> Outcome SimpleTx
forall tx. InterpreterConfig tx -> Program tx () -> Outcome tx
Interpreter.runProgram (Environment -> Ledger SimpleTx -> InterpreterConfig SimpleTx
forall tx.
IsTx tx =>
Environment -> Ledger tx -> InterpreterConfig tx
Configuration.interpreterConfig (Int -> Environment
Scenario.environment Int
1) Ledger SimpleTx
simpleLedger) (Program SimpleTx () -> Outcome SimpleTx)
-> Program SimpleTx () -> Outcome SimpleTx
forall a b. (a -> b) -> a -> b
$
Workflow SimpleTx ReqSnTopology () -> Program SimpleTx ()
forall {vertex} tx (topology :: Topology vertex) result.
Workflow tx topology result -> Program tx result
Workflow.run (Workflow SimpleTx ReqSnTopology () -> Program SimpleTx ())
-> Workflow SimpleTx ReqSnTopology () -> Program SimpleTx ()
forall a b. (a -> b) -> a -> b
$
Args SimpleTx -> Workflow SimpleTx ReqSnTopology ()
forall tx.
IsChainState tx =>
Args tx -> Workflow tx ReqSnTopology ()
ReqSn.workflow
ReqSn.Args
{ $sel:env:Args :: RuleEnvironment
env = Environment -> RuleEnvironment
Configuration.ruleEnvironment (Int -> Environment
Scenario.environment Int
1)
, $sel:pendingDeposits:Args :: PendingDeposits SimpleTx
pendingDeposits = Map SimpleId (Deposit SimpleTx)
PendingDeposits SimpleTx
forall a. Monoid a => a
mempty
, $sel:chainPointTime:Args :: ChainPointTime
chainPointTime = NodeState SimpleTx
node.chainPointTime
, $sel:openState:Args :: OpenState SimpleTx
openState = NodeState SimpleTx -> OpenState SimpleTx
Scenario.openState NodeState SimpleTx
node
, $sel:ttl:Args :: TTL
ttl = TTL
2
, $sel:sender:Args :: Party
sender = Party
alice
, $sel:snapshotVersion:Args :: SnapshotVersion
snapshotVersion = SnapshotVersion
0
, $sel:snapshotNumber:Args :: SnapshotNumber
snapshotNumber = SnapshotNumber
1
, $sel:transactionIds:Args :: [TxIdType SimpleTx]
transactionIds = [SimpleId
TxIdType SimpleTx
1]
, $sel:decommitTx:Args :: Maybe SimpleTx
decommitTx = Maybe SimpleTx
forall a. Maybe a
Nothing
, $sel:depositTxId:Args :: Maybe (TxIdType SimpleTx)
depositTxId = Maybe SimpleId
Maybe (TxIdType SimpleTx)
forall a. Maybe a
Nothing
}
CoordinatedHeadState SimpleTx
c.localTxs Seq SimpleTx -> Seq SimpleTx -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` SimpleTx -> Seq SimpleTx
forall a. a -> Seq a
Seq.singleton SimpleTx
Scenario.transactionOne
CoordinatedHeadState SimpleTx
c.localUTxO Set SimpleTxOut -> Set SimpleTxOut -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` SimpleId -> UTxOType SimpleTx
utxoRef SimpleId
2
SimpleId -> Map SimpleId SimpleTx -> Maybe SimpleTx
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup SimpleId
1 CoordinatedHeadState SimpleTx
c.allTxs Maybe SimpleTx -> Maybe SimpleTx -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` SimpleTx -> Maybe SimpleTx
forall a. a -> Maybe a
Just SimpleTx
Scenario.transactionOne
Outcome SimpleTx
request Outcome SimpleTx -> (Outcome SimpleTx -> Bool) -> IO ()
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO ()
`shouldSatisfy` \case Continue{} -> Bool
True; Outcome SimpleTx
_ -> Bool
False
[TTL] -> (TTL -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [TTL
0 .. TTL
defaultTxTTL] ((TTL -> IO ()) -> IO ()) -> (TTL -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \TTL
ttl -> do
let program :: Program SimpleTx ()
program =
Workflow SimpleTx ReqTxTopology () -> Program SimpleTx ()
forall {vertex} tx (topology :: Topology vertex) result.
Workflow tx topology result -> Program tx result
Workflow.run (Workflow SimpleTx ReqTxTopology () -> Program SimpleTx ())
-> Workflow SimpleTx ReqTxTopology () -> Program SimpleTx ()
forall a b. (a -> b) -> a -> b
$
Args SimpleTx -> Workflow SimpleTx ReqTxTopology ()
forall tx.
IsChainState tx =>
Args tx -> Workflow tx ReqTxTopology ()
ReqTx.workflow
ReqTx.Args
{ $sel:env:Args :: RuleEnvironment
env = Environment -> RuleEnvironment
ruleEnvironment Environment
env
, $sel:chainPointTime:Args :: ChainPointTime
chainPointTime = NodeState SimpleTx
node.chainPointTime
, $sel:openState:Args :: OpenState SimpleTx
openState = NodeState SimpleTx -> OpenState SimpleTx
Scenario.openState NodeState SimpleTx
node
, $sel:ttl:Args :: TTL
ttl = TTL
ttl
, $sel:pendingDeposits:Args :: PendingDeposits SimpleTx
pendingDeposits = Map SimpleId (Deposit SimpleTx)
PendingDeposits SimpleTx
forall a. Monoid a => a
mempty
, $sel:transaction:Args :: SimpleTx
transaction = SimpleTx
Scenario.transactionOne
}
(Outcome SimpleTx
outcome, [TraceStep]
trace) = InterpreterConfig SimpleTx
-> Program SimpleTx () -> (Outcome SimpleTx, [TraceStep])
forall tx.
InterpreterConfig tx -> Program tx () -> (Outcome tx, [TraceStep])
Interpreter.traceProgram (Ledger SimpleTx -> InterpreterConfig SimpleTx
forall tx. IsTx tx => Ledger tx -> InterpreterConfig tx
testInterpreterConfig Ledger SimpleTx
simpleLedger) Program SimpleTx ()
program
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 [] []
[TraceStep]
trace [TraceStep] -> ([TraceStep] -> Bool) -> IO ()
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO ()
`shouldSatisfy` (TraceStep -> Bool) -> [TraceStep] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (\case Trace.LedgerApplied{} -> Bool
False; TraceStep
_ -> Bool
True)
Bool
-> Bool
-> SimpleId
-> Bool
-> SimpleId
-> SimpleId
-> SimpleId
-> HsReqTxOutcome
reqTxKnownOutcomeRef Bool
True Bool
False (TTL -> SimpleId
forall a. Integral a => a -> SimpleId
toInteger TTL
ttl) Bool
False SimpleId
2 SimpleId
1 SimpleId
1 HsReqTxOutcome -> HsReqTxOutcome -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` HsReqTxTerminal
-> [HsReqTxChange] -> [HsReqTxEffect] -> HsReqTxOutcome
HsReqTxOutcome HsReqTxTerminal
ReqTxFinished [] []
String -> IO () -> SpecWith (Arg (IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"characterizes an expired dependency leaving an honest head quiescent with pending work" (IO () -> SpecWith (Arg (IO ())))
-> IO () -> SpecWith (Arg (IO ()))
forall a b. (a -> b) -> a -> b
$ do
World
world <- Either Text World -> IO World
forall a. Either Text a -> IO a
requireRight (Either Text World -> IO World) -> Either Text World -> IO World
forall a b. (a -> b) -> a -> b
$ ExecutionMode -> World -> [Action] -> Either Text World
Explorer.runPath ExecutionMode
Scenario.VerifySignatures World
Scenario.initialWorld [Action]
expiredDependencyRoute
World
world.pending [Delivery] -> [Delivery] -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` []
World
world.retries [Delivery] -> [Delivery] -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` []
World
world.delayed [Delivery] -> [Delivery] -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` []
World -> Maybe Text
Explorer.invariantFailure World
world Maybe Text -> Maybe Text -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"quiescent scenario has unconfirmed transactions"
let states :: [CoordinatedHeadState SimpleTx]
states = (\NodeState SimpleTx
node -> (NodeState SimpleTx -> OpenState SimpleTx
Scenario.openState NodeState SimpleTx
node).coordinatedHeadState) (NodeState SimpleTx -> CoordinatedHeadState SimpleTx)
-> [NodeState SimpleTx] -> [CoordinatedHeadState SimpleTx]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> World
world.nodes
(CoordinatedHeadState SimpleTx -> SnapshotNumber)
-> [CoordinatedHeadState SimpleTx] -> [SnapshotNumber]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\CoordinatedHeadState SimpleTx
c -> (ConfirmedSnapshot SimpleTx -> Snapshot SimpleTx
forall tx. IsTx tx => ConfirmedSnapshot tx -> Snapshot tx
getSnapshot CoordinatedHeadState SimpleTx
c.confirmedSnapshot).number) [CoordinatedHeadState SimpleTx]
states [SnapshotNumber] -> [SnapshotNumber] -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` [SnapshotNumber
1, SnapshotNumber
1, SnapshotNumber
1]
(CoordinatedHeadState SimpleTx -> [SimpleTx])
-> [CoordinatedHeadState SimpleTx] -> [[SimpleTx]]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Seq SimpleTx -> [SimpleTx]
forall a. Seq a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (Seq SimpleTx -> [SimpleTx])
-> (CoordinatedHeadState SimpleTx -> Seq SimpleTx)
-> CoordinatedHeadState SimpleTx
-> [SimpleTx]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (.localTxs)) [CoordinatedHeadState SimpleTx]
states [[SimpleTx]] -> [[SimpleTx]] -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` [[SimpleTx
Scenario.transactionTwo], [], [SimpleTx
Scenario.transactionTwo]]
let bobNode :: NodeState SimpleTx
bobNode = World
world.nodes [NodeState SimpleTx] -> Int -> NodeState SimpleTx
forall a. HasCallStack => [a] -> Int -> a
!! Int
1
request :: Outcome SimpleTx
request =
InterpreterConfig SimpleTx
-> Program SimpleTx () -> Outcome SimpleTx
forall tx. InterpreterConfig tx -> Program tx () -> Outcome tx
Interpreter.runProgram (Environment -> Ledger SimpleTx -> InterpreterConfig SimpleTx
forall tx.
IsTx tx =>
Environment -> Ledger tx -> InterpreterConfig tx
Configuration.interpreterConfig (Int -> Environment
Scenario.environment Int
1) Ledger SimpleTx
simpleLedger) (Program SimpleTx () -> Outcome SimpleTx)
-> Program SimpleTx () -> Outcome SimpleTx
forall a b. (a -> b) -> a -> b
$
Workflow SimpleTx ReqSnTopology () -> Program SimpleTx ()
forall {vertex} tx (topology :: Topology vertex) result.
Workflow tx topology result -> Program tx result
Workflow.run (Workflow SimpleTx ReqSnTopology () -> Program SimpleTx ())
-> Workflow SimpleTx ReqSnTopology () -> Program SimpleTx ()
forall a b. (a -> b) -> a -> b
$
Args SimpleTx -> Workflow SimpleTx ReqSnTopology ()
forall tx.
IsChainState tx =>
Args tx -> Workflow tx ReqSnTopology ()
ReqSn.workflow
ReqSn.Args
{ $sel:env:Args :: RuleEnvironment
env = Environment -> RuleEnvironment
Configuration.ruleEnvironment (Int -> Environment
Scenario.environment Int
1)
, $sel:pendingDeposits:Args :: PendingDeposits SimpleTx
pendingDeposits = Map SimpleId (Deposit SimpleTx)
PendingDeposits SimpleTx
forall a. Monoid a => a
mempty
, $sel:chainPointTime:Args :: ChainPointTime
chainPointTime = NodeState SimpleTx
bobNode.chainPointTime
, $sel:openState:Args :: OpenState SimpleTx
openState = NodeState SimpleTx -> OpenState SimpleTx
Scenario.openState NodeState SimpleTx
bobNode
, $sel:ttl:Args :: TTL
ttl = TTL
2
, $sel:sender:Args :: Party
sender = Party
bob
, $sel:snapshotVersion:Args :: SnapshotVersion
snapshotVersion = SnapshotVersion
0
, $sel:snapshotNumber:Args :: SnapshotNumber
snapshotNumber = SnapshotNumber
2
, $sel:transactionIds:Args :: [TxIdType SimpleTx]
transactionIds = [SimpleId
TxIdType SimpleTx
2]
, $sel:decommitTx:Args :: Maybe SimpleTx
decommitTx = Maybe SimpleTx
forall a. Maybe a
Nothing
, $sel:depositTxId:Args :: Maybe (TxIdType SimpleTx)
depositTxId = Maybe SimpleId
Maybe (TxIdType SimpleTx)
forall a. Maybe a
Nothing
}
Outcome SimpleTx
request Outcome SimpleTx -> Outcome SimpleTx -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` WaitReason SimpleTx -> [StateChanged SimpleTx] -> Outcome SimpleTx
forall tx. WaitReason tx -> [StateChanged tx] -> Outcome tx
Wait ([TxIdType SimpleTx] -> WaitReason SimpleTx
forall tx. [TxIdType tx] -> WaitReason tx
WaitOnTxs [SimpleId
TxIdType SimpleTx
2]) []
let retryTx :: Outcome SimpleTx
retryTx =
InterpreterConfig SimpleTx
-> Program SimpleTx () -> Outcome SimpleTx
forall tx. InterpreterConfig tx -> Program tx () -> Outcome tx
Interpreter.runProgram (Environment -> Ledger SimpleTx -> InterpreterConfig SimpleTx
forall tx.
IsTx tx =>
Environment -> Ledger tx -> InterpreterConfig tx
Configuration.interpreterConfig (Int -> Environment
Scenario.environment Int
1) Ledger SimpleTx
simpleLedger) (Program SimpleTx () -> Outcome SimpleTx)
-> Program SimpleTx () -> Outcome SimpleTx
forall a b. (a -> b) -> a -> b
$
Workflow SimpleTx ReqTxTopology () -> Program SimpleTx ()
forall {vertex} tx (topology :: Topology vertex) result.
Workflow tx topology result -> Program tx result
Workflow.run (Workflow SimpleTx ReqTxTopology () -> Program SimpleTx ())
-> Workflow SimpleTx ReqTxTopology () -> Program SimpleTx ()
forall a b. (a -> b) -> a -> b
$
Args SimpleTx -> Workflow SimpleTx ReqTxTopology ()
forall tx.
IsChainState tx =>
Args tx -> Workflow tx ReqTxTopology ()
ReqTx.workflow
ReqTx.Args
{ $sel:env:Args :: RuleEnvironment
env = Environment -> RuleEnvironment
Configuration.ruleEnvironment (Int -> Environment
Scenario.environment Int
1)
, $sel:chainPointTime:Args :: ChainPointTime
chainPointTime = NodeState SimpleTx
bobNode.chainPointTime
, $sel:openState:Args :: OpenState SimpleTx
openState = NodeState SimpleTx -> OpenState SimpleTx
Scenario.openState NodeState SimpleTx
bobNode
, $sel:ttl:Args :: TTL
ttl = TTL
2
, $sel:pendingDeposits:Args :: PendingDeposits SimpleTx
pendingDeposits = Map SimpleId (Deposit SimpleTx)
PendingDeposits SimpleTx
forall a. Monoid a => a
mempty
, $sel:transaction:Args :: SimpleTx
transaction = SimpleTx
Scenario.transactionTwo
}
Outcome SimpleTx
retryTx Outcome SimpleTx -> (Outcome SimpleTx -> Bool) -> IO ()
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO ()
`shouldSatisfy` \case
Continue{[Effect SimpleTx]
$sel:effects:Continue :: forall tx. Outcome tx -> [Effect tx]
effects :: [Effect SimpleTx]
effects} -> Message SimpleTx -> Effect SimpleTx
forall tx. Message tx -> Effect tx
NetworkEffect (SnapshotVersion
-> SnapshotNumber
-> [TxIdType SimpleTx]
-> Maybe SimpleTx
-> Maybe (TxIdType SimpleTx)
-> Message SimpleTx
forall tx.
SnapshotVersion
-> SnapshotNumber
-> [TxIdType tx]
-> Maybe tx
-> Maybe (TxIdType tx)
-> Message tx
ReqSn SnapshotVersion
0 SnapshotNumber
2 [SimpleId
TxIdType SimpleTx
2] Maybe SimpleTx
forall a. Maybe a
Nothing Maybe SimpleId
Maybe (TxIdType SimpleTx)
forall a. Maybe a
Nothing) Effect SimpleTx -> [Effect SimpleTx] -> Bool
forall (f :: * -> *) a.
(Foldable f, DisallowElem f, Eq a) =>
a -> f a -> Bool
`elem` [Effect SimpleTx]
effects
Outcome SimpleTx
_ -> Bool
False
String -> IO () -> SpecWith (Arg (IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"characterizes invalid early signatures blocking later valid replacements" (IO () -> SpecWith (Arg (IO ())))
-> IO () -> SpecWith (Arg (IO ()))
forall a b. (a -> b) -> a -> b
$ do
let start :: NodeState SimpleTx
start = HsSnapshotPhase -> [Int] -> NodeState SimpleTx
ackState HsSnapshotPhase
CollectingSignatures []
applyAck :: NodeState SimpleTx
-> Party -> Signature (Snapshot SimpleTx) -> Outcome SimpleTx
applyAck NodeState SimpleTx
node Party
sender Signature (Snapshot SimpleTx)
signature =
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) (Program SimpleTx () -> Outcome SimpleTx)
-> Program SimpleTx () -> Outcome SimpleTx
forall a b. (a -> b) -> a -> b
$
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
Configuration.ruleEnvironment Environment
env
, $sel:chainPointTime:Args :: ChainPointTime
chainPointTime = NodeState SimpleTx
node.chainPointTime
, $sel:pendingDeposits:Args :: PendingDeposits SimpleTx
pendingDeposits = Map SimpleId (Deposit SimpleTx)
PendingDeposits SimpleTx
forall a. Monoid a => a
mempty
, $sel:openState:Args :: OpenState SimpleTx
openState = NodeState SimpleTx -> OpenState SimpleTx
Scenario.openState NodeState SimpleTx
node
, $sel:sender:Args :: Party
sender = Party
sender
, $sel:signed:Args :: Signature (Snapshot SimpleTx)
signed = Signature (Snapshot SimpleTx)
signature
, $sel:snapshotNumber:Args :: SnapshotNumber
snapshotNumber = SnapshotNumber
1
}
bad :: Signature (Snapshot SimpleTx)
bad = 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
Scenario.initialSnapshot
accepted :: Outcome SimpleTx
accepted = NodeState SimpleTx
-> Party -> Signature (Snapshot SimpleTx) -> Outcome SimpleTx
applyAck NodeState SimpleTx
start Party
alice Signature (Snapshot SimpleTx)
bad
poisoned :: NodeState SimpleTx
poisoned = NodeState SimpleTx -> Outcome SimpleTx -> NodeState SimpleTx
forall tx.
IsChainState tx =>
NodeState tx -> Outcome tx -> NodeState tx
aggregateState NodeState SimpleTx
start Outcome SimpleTx
accepted
afterBob :: NodeState SimpleTx
afterBob = NodeState SimpleTx -> Outcome SimpleTx -> NodeState SimpleTx
forall tx.
IsChainState tx =>
NodeState tx -> Outcome tx -> NodeState tx
aggregateState NodeState SimpleTx
poisoned (Outcome SimpleTx -> NodeState SimpleTx)
-> Outcome SimpleTx -> NodeState SimpleTx
forall a b. (a -> b) -> a -> b
$ NodeState SimpleTx
-> Party -> Signature (Snapshot SimpleTx) -> Outcome SimpleTx
applyAck NodeState SimpleTx
poisoned 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
snapshotFixture)
final :: Outcome SimpleTx
final = NodeState SimpleTx
-> Party -> Signature (Snapshot SimpleTx) -> Outcome SimpleTx
applyAck NodeState SimpleTx
afterBob 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
snapshotFixture)
corrected :: Outcome SimpleTx
corrected = NodeState SimpleTx
-> Party -> Signature (Snapshot SimpleTx) -> Outcome SimpleTx
applyAck NodeState SimpleTx
afterBob 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
snapshotFixture)
Outcome SimpleTx
accepted Outcome SimpleTx -> (Outcome SimpleTx -> Bool) -> IO ()
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO ()
`shouldSatisfy` \case Continue{} -> Bool
True; Outcome SimpleTx
_ -> Bool
False
Outcome SimpleTx
final Outcome SimpleTx -> (Outcome SimpleTx -> Bool) -> IO ()
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO ()
`shouldSatisfy` \case Error (RequireFailed InvalidMultisignature{}) -> Bool
True; Outcome SimpleTx
_ -> Bool
False
NodeState SimpleTx -> Outcome SimpleTx -> NodeState SimpleTx
forall tx.
IsChainState tx =>
NodeState tx -> Outcome tx -> NodeState tx
aggregateState NodeState SimpleTx
afterBob Outcome SimpleTx
final NodeState SimpleTx -> NodeState SimpleTx -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` NodeState SimpleTx
afterBob
Outcome SimpleTx
corrected Outcome SimpleTx -> (Outcome SimpleTx -> Bool) -> IO ()
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO ()
`shouldSatisfy` \case Error (RequireFailed SnapshotAlreadySigned{}) -> Bool
True; Outcome SimpleTx
_ -> Bool
False
String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"bounded explorer and replay debugger" (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
"preserves the validated Cardano transaction after an invalid duplicate" (IO () -> SpecWith (Arg (IO ())))
-> IO () -> SpecWith (Arg (IO ()))
forall a b. (a -> b) -> a -> b
$ do
Either Text ()
Registry.registryRegression Either Text () -> (Either Text () -> Bool) -> IO ()
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO ()
`shouldSatisfy` Either Text () -> Bool
forall a b. Either a b -> Bool
isRight
String -> IO () -> SpecWith (Arg (IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"detects omitted receipt and a dishonest ledger reply with independent state invariants" (IO () -> SpecWith (Arg (IO ())))
-> IO () -> SpecWith (Arg (IO ()))
forall a b. (a -> b) -> a -> b
$ do
let world :: World
world = World
Scenario.initialWorld
d :: Delivery
d = Int -> Int -> TTL -> Message SimpleTx -> Delivery
Scenario.Delivery Int
0 Int
1 TTL
2 (SimpleTx -> Message SimpleTx
forall tx. tx -> Message tx
ReqTx SimpleTx
Scenario.transactionOne)
withoutReceipt :: Program.Program tx a -> Program.Program tx a
withoutReceipt :: forall tx a. Program tx a -> Program tx a
withoutReceipt = (forall x. Instruction tx x -> Program tx x)
-> Program tx a -> Program tx a
forall (m :: * -> *) tx a.
Monad m =>
(forall x. Instruction tx x -> m x) -> Program tx a -> m a
foldProgram ((forall x. Instruction tx x -> Program tx x)
-> Program tx a -> Program tx a)
-> (forall x. Instruction tx x -> Program tx x)
-> Program tx a
-> Program tx a
forall a b. (a -> b) -> a -> b
$ \case
Program.Change TransactionReceived{} -> x -> Program tx x
forall a. a -> Program tx a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
Instruction tx x
op -> Instruction tx x -> Program tx x
forall tx a. Instruction tx a -> Program tx a
instruction Instruction tx x
op
missingReceipt :: Outcome SimpleTx
missingReceipt = case World -> Delivery -> Execution SimpleTx
Explorer.programFor World
world Delivery
d of
Interpreter.Execution InterpreterConfig SimpleTx
originalConfig Program SimpleTx ()
program -> InterpreterConfig SimpleTx
-> Program SimpleTx () -> Outcome SimpleTx
forall tx. InterpreterConfig tx -> Program tx () -> Outcome tx
Interpreter.runProgram InterpreterConfig SimpleTx
originalConfig (Program SimpleTx () -> Outcome SimpleTx)
-> Program SimpleTx () -> Outcome SimpleTx
forall a b. (a -> b) -> a -> b
$ Program SimpleTx () -> Program SimpleTx ()
forall tx a. Program tx a -> Program tx a
withoutReceipt Program SimpleTx ()
program
missingDependency :: Delivery
missingDependency = Int -> Int -> TTL -> Message SimpleTx -> Delivery
Scenario.Delivery Int
0 Int
1 TTL
2 (SimpleTx -> Message SimpleTx
forall tx. tx -> Message tx
ReqTx SimpleTx
Scenario.transactionTwo)
config :: InterpreterConfig SimpleTx
config = (Ledger SimpleTx -> InterpreterConfig SimpleTx
forall tx. IsTx tx => Ledger tx -> InterpreterConfig tx
testInterpreterConfig Ledger SimpleTx
simpleLedger){Interpreter.transactionApplication = \ChainSlot
_ UTxOType SimpleTx
_ SimpleTx
_ -> Set SimpleTxOut -> Either ValidationError (Set SimpleTxOut)
forall a b. b -> Either a b
Right (SimpleId -> UTxOType SimpleTx
utxoRef SimpleId
1 Set SimpleTxOut -> Set SimpleTxOut -> Set SimpleTxOut
forall a. Semigroup a => a -> a -> a
<> SimpleId -> UTxOType SimpleTx
utxoRef SimpleId
3)}
acceptedWithoutInput :: Outcome SimpleTx
acceptedWithoutInput =
InterpreterConfig SimpleTx
-> Program SimpleTx () -> Outcome SimpleTx
forall tx. InterpreterConfig tx -> Program tx () -> Outcome tx
Interpreter.runProgram InterpreterConfig SimpleTx
config (Program SimpleTx () -> Outcome SimpleTx)
-> Program SimpleTx () -> Outcome SimpleTx
forall a b. (a -> b) -> a -> b
$
Workflow SimpleTx ReqTxTopology () -> Program SimpleTx ()
forall {vertex} tx (topology :: Topology vertex) result.
Workflow tx topology result -> Program tx result
Workflow.run
( Args SimpleTx -> Workflow SimpleTx ReqTxTopology ()
forall tx.
IsChainState tx =>
Args tx -> Workflow tx ReqTxTopology ()
ReqTx.workflow
ReqTx.Args
{ $sel:env:Args :: RuleEnvironment
env = Environment -> RuleEnvironment
ruleEnvironment (Environment -> RuleEnvironment) -> Environment -> RuleEnvironment
forall a b. (a -> b) -> a -> b
$ Int -> Environment
Scenario.environment Int
1
, $sel:chainPointTime:Args :: ChainPointTime
chainPointTime = NodeState SimpleTx
Scenario.initialNode.chainPointTime
, $sel:openState:Args :: OpenState SimpleTx
openState = NodeState SimpleTx -> OpenState SimpleTx
Scenario.openState NodeState SimpleTx
Scenario.initialNode
, $sel:ttl:Args :: TTL
ttl = TTL
2
, $sel:pendingDeposits:Args :: PendingDeposits SimpleTx
pendingDeposits = Map SimpleId (Deposit SimpleTx)
PendingDeposits SimpleTx
forall a. Monoid a => a
mempty
, $sel:transaction:Args :: SimpleTx
transaction = SimpleTx
Scenario.transactionTwo
}
)
World -> Maybe Text
Explorer.safetyFailure (World -> Delivery -> Outcome SimpleTx -> World
Explorer.installOutcome World
world Delivery
d Outcome SimpleTx
missingReceipt)
Maybe Text -> Maybe Text -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"local pending transaction differs from the registry payload"
World -> Maybe Text
Explorer.safetyFailure (World -> Delivery -> Outcome SimpleTx -> World
Explorer.installOutcome World
world Delivery
missingDependency Outcome SimpleTx
acceptedWithoutInput)
Maybe Text -> Maybe Text -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"local UTxO does not reconcile with snapshot and pending transactions"
String -> IO () -> SpecWith (Arg (IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"finds asymmetric retry expiry within the default budget and replays its minimized schedule" (IO () -> SpecWith (Arg (IO ())))
-> IO () -> SpecWith (Arg (IO ()))
forall a b. (a -> b) -> a -> b
$ do
let settings :: Exploration
settings = Exploration
Scenario.defaultExploration{Scenario.family = Scenario.DelayedDependency, Scenario.searchOrder = Scenario.RetryWindows}
start :: World
start = ScenarioFamily -> World
Scenario.initialFor Exploration
settings.family
report :: SearchReport
report = Limits -> Exploration -> SearchReport
Explorer.explore Limits
Scenario.defaultLimits Exploration
settings
SearchReport
report.failure Maybe Text -> Maybe Text -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"quiescent scenario has unconfirmed transactions"
SearchReport
report.exploredStates Int -> (Int -> Bool) -> IO ()
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO ()
`shouldSatisfy` (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Limits
Scenario.defaultLimits.maxStates)
let route :: [Action]
route = ExecutionMode -> World -> [Action] -> [Action]
Explorer.minimize Exploration
settings.executionMode World
start SearchReport
report.path
(Scenario
scenario, [Step]
_) <- Either Text (Scenario, [Step]) -> IO (Scenario, [Step])
forall a. Either Text a -> IO a
requireRight (Either Text (Scenario, [Step]) -> IO (Scenario, [Step]))
-> Either Text (Scenario, [Step]) -> IO (Scenario, [Step])
forall a b. (a -> b) -> a -> b
$ Limits
-> Exploration
-> World
-> [Action]
-> Either Text (Scenario, [Step])
Replay.recordScenario Limits
Scenario.defaultLimits Exploration
settings World
start [Action]
route
(World
world, [Step]
_) <- Either Text (World, [Step]) -> IO (World, [Step])
forall a. Either Text a -> IO a
requireRight (Either Text (World, [Step]) -> IO (World, [Step]))
-> Either Text (World, [Step]) -> IO (World, [Step])
forall a b. (a -> b) -> a -> b
$ Scenario -> Either Text (World, [Step])
Replay.replayScenario Scenario
scenario
World -> Maybe Text
Explorer.safetyFailure World
world Maybe Text -> Maybe Text -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Maybe Text
forall a. Maybe a
Nothing
World -> Maybe Text
Explorer.progressFailure World
world Maybe Text -> Maybe Text -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` SearchReport
report.failure
Limits -> Exploration -> SearchReport
Explorer.explore (Int -> Int -> Limits
Scenario.Limits Int
1 Int
1) Exploration
settings SearchReport -> (SearchReport -> Bool) -> IO ()
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO ()
`shouldSatisfy` SearchReport -> Bool
Scenario.truncated
String -> IO () -> SpecWith (Arg (IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"preserves settlement and spent outputs across 24 rollback schedules and serialized replay" (IO () -> SpecWith (Arg (IO ())))
-> IO () -> SpecWith (Arg (IO ()))
forall a b. (a -> b) -> a -> b
$ do
[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
confirmed ->
[Int] -> (Int -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Int
2, Int
3] ((Int -> IO ()) -> IO ()) -> (Int -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
slot ->
[[Int]] -> ([Int] -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ ([Int] -> [[Int]]
forall a. [a] -> [[a]]
permutations [Int
0, Int
1, Int
2]) (([Int] -> IO ()) -> IO ()) -> ([Int] -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \[Int]
recipients ->
IO [SettlementStep] -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO [SettlementStep] -> IO ()) -> IO [SettlementStep] -> IO ()
forall a b. (a -> b) -> a -> b
$ Either Text [SettlementStep] -> IO [SettlementStep]
forall a. Either Text a -> IO a
requireRight (Either Text [SettlementStep] -> IO [SettlementStep])
-> Either Text [SettlementStep] -> IO [SettlementStep]
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> [Int] -> Either Text [SettlementStep]
Settlement.settlementSequence Bool
confirmed Int
slot [Int]
recipients
String -> IO () -> SpecWith (Arg (IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"finds and minimizes invalid confirmation, while the normal interpreter rejects that sequence" (IO () -> SpecWith (Arg (IO ())))
-> IO () -> SpecWith (Arg (IO ()))
forall a b. (a -> b) -> a -> b
$ do
let report :: SearchReport
report = Limits -> Exploration -> SearchReport
Explorer.explore (Int -> Int -> Limits
Scenario.Limits Int
24 Int
5000) Exploration
faultExploration
SearchReport
report.failure Maybe Text -> Maybe Text -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"confirmed snapshot has invalid signatures"
let route :: [Action]
route = ExecutionMode -> World -> [Action] -> [Action]
Explorer.minimize ExecutionMode
Scenario.BypassVerification World
Scenario.initialWorld SearchReport
report.path
World
normal <- Either Text World -> IO World
forall a. Either Text a -> IO a
requireRight (Either Text World -> IO World) -> Either Text World -> IO World
forall a b. (a -> b) -> a -> b
$ ExecutionMode -> World -> [Action] -> Either Text World
Explorer.runPath ExecutionMode
Scenario.VerifySignatures World
Scenario.initialWorld [Action]
route
World -> Maybe Text
Explorer.invariantFailure World
normal Maybe Text -> Maybe Text -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Maybe Text
forall a. Maybe a
Nothing
ExecutionMode -> World -> [Action] -> [Action]
Explorer.minimize ExecutionMode
Scenario.VerifySignatures World
Scenario.initialWorld [Action]
route [Action] -> [Action] -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` [Action]
route
[Outcome SimpleTx]
outcomes <- Either Text [Outcome SimpleTx] -> IO [Outcome SimpleTx]
forall a. Either Text a -> IO a
requireRight (Either Text [Outcome SimpleTx] -> IO [Outcome SimpleTx])
-> Either Text [Outcome SimpleTx] -> IO [Outcome SimpleTx]
forall a b. (a -> b) -> a -> b
$ ExecutionMode
-> World -> [Action] -> Either Text [Outcome SimpleTx]
Explorer.pathOutcomes ExecutionMode
Scenario.VerifySignatures World
Scenario.initialWorld [Action]
route
[Outcome SimpleTx]
outcomes [Outcome SimpleTx] -> ([Outcome SimpleTx] -> Bool) -> IO ()
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO ()
`shouldSatisfy` (Outcome SimpleTx -> Bool) -> [Outcome SimpleTx] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (\case Error (RequireFailed InvalidMultisignature{}) -> Bool
True; Outcome SimpleTx
_ -> Bool
False)
(Scenario
scenario, [Step]
views) <- Either Text (Scenario, [Step]) -> IO (Scenario, [Step])
forall a. Either Text a -> IO a
requireRight (Either Text (Scenario, [Step]) -> IO (Scenario, [Step]))
-> Either Text (Scenario, [Step]) -> IO (Scenario, [Step])
forall a b. (a -> b) -> a -> b
$ Limits
-> Exploration
-> World
-> [Action]
-> Either Text (Scenario, [Step])
Replay.recordScenario SearchReport
report.limits Exploration
faultExploration World
Scenario.initialWorld [Action]
route
(World
replayed, [Step]
replayViews) <- Either Text (World, [Step]) -> IO (World, [Step])
forall a. Either Text a -> IO a
requireRight (Either Text (World, [Step]) -> IO (World, [Step]))
-> Either Text (World, [Step]) -> IO (World, [Step])
forall a b. (a -> b) -> a -> b
$ Scenario -> Either Text (World, [Step])
Replay.replayScenario Scenario
scenario
World -> Maybe Text
Explorer.invariantFailure World
replayed Maybe Text -> Maybe Text -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` SearchReport
report.failure
[Step]
replayViews [Step] -> [Step] -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` [Step]
views
let ([Step]
_, [Step]
stopped) = Text -> [Step] -> ([Step], [Step])
Debug.breakAt Text
"TEST ONLY: bypass multisignature verification" [Step]
views
[Step]
stopped [Step] -> ([Step] -> Bool) -> IO ()
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO ()
`shouldSatisfy` (Bool -> Bool
not (Bool -> Bool) -> ([Step] -> Bool) -> [Step] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Step] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null)
[Step] -> Maybe (Step, [Step])
Debug.stepOnce [Step]
stopped Maybe (Step, [Step]) -> (Maybe (Step, [Step]) -> Bool) -> IO ()
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO ()
`shouldSatisfy` Maybe (Step, [Step]) -> Bool
forall a. Maybe a -> Bool
isJust
[Int] -> (Int -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Int
0 .. [Action] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Action]
route Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1] ((Int -> IO ()) -> IO ()) -> (Int -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
i ->
case ExecutionMode -> World -> [Action] -> Either Text World
Explorer.runPath ExecutionMode
Scenario.BypassVerification World
Scenario.initialWorld (Int -> [Action] -> [Action]
forall a. Int -> [a] -> [a]
take Int
i [Action]
route [Action] -> [Action] -> [Action]
forall a. Semigroup a => a -> a -> a
<> Int -> [Action] -> [Action]
forall a. Int -> [a] -> [a]
drop (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) [Action]
route) of
Left Text
_ -> () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
Right World
world -> World -> Maybe Text
Explorer.invariantFailure World
world Maybe Text -> Maybe Text -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Maybe Text
forall a. Maybe a
Nothing
String -> IO () -> SpecWith (Arg (IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"reports truncation and deterministic counts at the state limit" (IO () -> SpecWith (Arg (IO ())))
-> IO () -> SpecWith (Arg (IO ()))
forall a b. (a -> b) -> a -> b
$ do
let report :: SearchReport
report = Limits -> Exploration -> SearchReport
Explorer.explore (Int -> Int -> Limits
Scenario.Limits Int
24 Int
40) Exploration
Scenario.defaultExploration
SearchReport
report.truncated Bool -> Bool -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Bool
True
SearchReport
report.exploredStates Int -> Int -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Int
40
Limits -> Exploration -> SearchReport
Explorer.explore (Int -> Int -> Limits
Scenario.Limits Int
24 Int
40) Exploration
Scenario.defaultExploration SearchReport -> SearchReport -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` SearchReport
report
String -> IO () -> SpecWith (Arg (IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"round trips an explicit starting world" (IO () -> SpecWith (Arg (IO ())))
-> IO () -> SpecWith (Arg (IO ()))
forall a b. (a -> b) -> a -> b
$ do
World
start <- Either Text World -> IO World
forall a. Either Text a -> IO a
requireRight (Either Text World -> IO World) -> Either Text World -> IO World
forall a b. (a -> b) -> a -> b
$ ExecutionMode -> World -> [Action] -> Either Text World
Explorer.runPath ExecutionMode
Scenario.VerifySignatures World
Scenario.initialWorld [Delivery -> Action
Scenario.Deliver (Delivery -> Action) -> Delivery -> Action
forall a b. (a -> b) -> a -> b
$ Int -> Int -> TTL -> Message SimpleTx -> Delivery
Scenario.Delivery Int
0 Int
1 TTL
2 (SimpleTx -> Message SimpleTx
forall tx. tx -> Message tx
ReqTx SimpleTx
Scenario.transactionOne)]
(Scenario
scenario, [Step]
_) <- Either Text (Scenario, [Step]) -> IO (Scenario, [Step])
forall a. Either Text a -> IO a
requireRight (Either Text (Scenario, [Step]) -> IO (Scenario, [Step]))
-> Either Text (Scenario, [Step]) -> IO (Scenario, [Step])
forall a b. (a -> b) -> a -> b
$ Limits
-> Exploration
-> World
-> [Action]
-> Either Text (Scenario, [Step])
Replay.recordScenario Limits
Scenario.defaultLimits Exploration
Scenario.defaultExploration World
start []
Scenario
decoded <- (String -> IO Scenario)
-> (Scenario -> IO Scenario)
-> Either String Scenario
-> IO Scenario
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either String -> IO Scenario
forall (m :: * -> *) a.
(HasCallStack, MonadThrow m) =>
String -> m a
failure Scenario -> IO Scenario
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either String Scenario -> IO Scenario)
-> Either String Scenario -> IO Scenario
forall a b. (a -> b) -> a -> b
$ ByteString -> Either String Scenario
forall a. FromJSON a => ByteString -> Either String a
eitherDecode (ByteString -> Either String Scenario)
-> ByteString -> Either String Scenario
forall a b. (a -> b) -> a -> b
$ Scenario -> ByteString
forall a. ToJSON a => a -> ByteString
encode Scenario
scenario
Scenario
decoded Scenario -> Scenario -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Scenario
scenario
(World
world, [Step]
_) <- Either Text (World, [Step]) -> IO (World, [Step])
forall a. Either Text a -> IO a
requireRight (Either Text (World, [Step]) -> IO (World, [Step]))
-> Either Text (World, [Step]) -> IO (World, [Step])
forall a b. (a -> b) -> a -> b
$ Scenario -> Either Text (World, [Step])
Replay.replayScenario Scenario
decoded
World
world World -> World -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` World
start
String -> IO () -> SpecWith (Arg (IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"runs each declared family and search order deterministically within bounds" (IO () -> SpecWith (Arg (IO ())))
-> IO () -> SpecWith (Arg (IO ()))
forall a b. (a -> b) -> a -> b
$ do
[ScenarioFamily] -> (ScenarioFamily -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [ScenarioFamily
Scenario.DependentTransactions, ScenarioFamily
Scenario.DuplicateTransaction, ScenarioFamily
Scenario.DelayedDependency] ((ScenarioFamily -> IO ()) -> IO ())
-> (ScenarioFamily -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \ScenarioFamily
family ->
[SearchOrder] -> (SearchOrder -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [SearchOrder
Scenario.DeliveriesFirst, SearchOrder
Scenario.RetriesFirst, SearchOrder
Scenario.BreadthFirst, SearchOrder
Scenario.RetryWindows] ((SearchOrder -> IO ()) -> IO ())
-> (SearchOrder -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \SearchOrder
order -> do
let settings :: Exploration
settings = Exploration
Scenario.defaultExploration{Scenario.family = family, Scenario.searchOrder = order}
report :: SearchReport
report = Limits -> Exploration -> SearchReport
Explorer.explore (Int -> Int -> Limits
Scenario.Limits Int
24 Int
40) Exploration
settings
SearchReport
report.exploredStates Int -> (Int -> Bool) -> IO ()
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> IO ()
`shouldSatisfy` (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
40)
Limits -> Exploration -> SearchReport
Explorer.explore SearchReport
report.limits Exploration
settings SearchReport -> SearchReport -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` SearchReport
report
String -> IO () -> SpecWith (Arg (IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"rejects wrong query identity, arguments, missing and extra replies" (IO () -> SpecWith (Arg (IO ())))
-> IO () -> SpecWith (Arg (IO ()))
forall a b. (a -> b) -> a -> b
$ do
let program :: Program SimpleTx ()
program =
Workflow SimpleTx ReqTxTopology () -> Program SimpleTx ()
forall {vertex} tx (topology :: Topology vertex) result.
Workflow tx topology result -> Program tx result
Workflow.run (Workflow SimpleTx ReqTxTopology () -> Program SimpleTx ())
-> Workflow SimpleTx ReqTxTopology () -> Program SimpleTx ()
forall a b. (a -> b) -> a -> b
$
Args SimpleTx -> Workflow SimpleTx ReqTxTopology ()
forall tx.
IsChainState tx =>
Args tx -> Workflow tx ReqTxTopology ()
ReqTx.workflow
ReqTx.Args
{ $sel:env:Args :: RuleEnvironment
env = Environment -> RuleEnvironment
ruleEnvironment Environment
env
, $sel:chainPointTime:Args :: ChainPointTime
chainPointTime = NodeState SimpleTx
initial.chainPointTime
, $sel:openState:Args :: OpenState SimpleTx
openState = NodeState SimpleTx -> OpenState SimpleTx
Scenario.openState NodeState SimpleTx
Scenario.initialNode
, $sel:ttl:Args :: TTL
ttl = TTL
1
, $sel:pendingDeposits:Args :: PendingDeposits SimpleTx
pendingDeposits = Map SimpleId (Deposit SimpleTx)
PendingDeposits SimpleTx
forall a. Monoid a => a
mempty
, $sel:transaction:Args :: SimpleTx
transaction = SimpleTx
Scenario.transactionOne
}
config :: InterpreterConfig SimpleTx
config = Ledger SimpleTx -> InterpreterConfig SimpleTx
forall tx. IsTx tx => Ledger tx -> InterpreterConfig tx
testInterpreterConfig Ledger SimpleTx
simpleLedger
Prepared
prepared <- Either Text Prepared -> IO Prepared
forall a. Either Text a -> IO a
requireRight (Either Text Prepared -> IO Prepared)
-> Either Text Prepared -> IO Prepared
forall a b. (a -> b) -> a -> b
$ ReplyMode
-> InterpreterConfig SimpleTx
-> Program SimpleTx ()
-> Either Text Prepared
Debug.prepare ReplyMode
Debug.RecordReplies InterpreterConfig SimpleTx
config Program SimpleTx ()
program
let tape :: [QueryRecord]
tape = Prepared
prepared.queries
case [QueryRecord]
tape of
[] -> String -> IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadThrow m) =>
String -> m a
failure String
"expected a primitive query"
QueryRecord
q : [QueryRecord]
qs -> do
[[QueryRecord]] -> ([QueryRecord] -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [[], QueryRecord
q{Debug.primitive = "wrong query"} QueryRecord -> [QueryRecord] -> [QueryRecord]
forall a. a -> [a] -> [a]
: [QueryRecord]
qs, QueryRecord
q{Debug.arguments = toJSON ()} QueryRecord -> [QueryRecord] -> [QueryRecord]
forall a. a -> [a] -> [a]
: [QueryRecord]
qs, [QueryRecord]
tape [QueryRecord] -> [QueryRecord] -> [QueryRecord]
forall a. Semigroup a => a -> a -> a
<> [QueryRecord]
tape] (([QueryRecord] -> IO ()) -> IO ())
-> ([QueryRecord] -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \[QueryRecord]
wrong ->
Either Text Prepared -> Bool
forall a b. Either a b -> Bool
isLeft (ReplyMode
-> InterpreterConfig SimpleTx
-> Program SimpleTx ()
-> Either Text Prepared
Debug.prepare ([QueryRecord] -> ReplyMode
Debug.RecordedReplies [QueryRecord]
wrong) InterpreterConfig SimpleTx
config Program SimpleTx ()
program) Bool -> Bool -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Bool
True
let controlled :: [QueryRecord]
controlled = QueryRecord
q{Debug.reply = toJSON (Left (ValidationError "controlled") :: Either ValidationError (Set SimpleTxOut))} QueryRecord -> [QueryRecord] -> [QueryRecord]
forall a. a -> [a] -> [a]
: [QueryRecord]
qs
Prepared
changed <- Either Text Prepared -> IO Prepared
forall a. Either Text a -> IO a
requireRight (Either Text Prepared -> IO Prepared)
-> Either Text Prepared -> IO Prepared
forall a b. (a -> b) -> a -> b
$ ReplyMode
-> InterpreterConfig SimpleTx
-> Program SimpleTx ()
-> Either Text Prepared
Debug.prepare ([QueryRecord] -> ReplyMode
Debug.RecordedReplies [QueryRecord]
controlled) InterpreterConfig SimpleTx
config Program SimpleTx ()
program
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) Prepared
changed.lowered Outcome SimpleTx -> Outcome SimpleTx -> IO ()
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` WaitReason SimpleTx -> [StateChanged SimpleTx] -> Outcome SimpleTx
forall tx. WaitReason tx -> [StateChanged tx] -> Outcome tx
Wait (ValidationError -> WaitReason SimpleTx
forall tx. ValidationError -> WaitReason tx
WaitOnNotApplicableTx (ValidationError -> WaitReason SimpleTx)
-> ValidationError -> WaitReason SimpleTx
forall a b. (a -> b) -> a -> b
$ Text -> ValidationError
ValidationError Text
"controlled") [SimpleTx -> StateChanged SimpleTx
forall tx. tx -> StateChanged tx
TransactionReceived SimpleTx
Scenario.transactionOne]
initial :: NodeState SimpleTx
initial :: NodeState SimpleTx
initial = NodeState SimpleTx
Scenario.initialNode{headState = Open os}
os :: OpenState SimpleTx
os :: OpenState SimpleTx
os = OpenState SimpleTx
base{coordinatedHeadState = c{allTxs = Map.fromList [(txId tx, tx) | tx <- [Scenario.transactionOne, Scenario.transactionTwo]], localTxs = Seq.fromList [Scenario.transactionOne, Scenario.transactionTwo], localUTxO = utxoRef 3}}
where
base :: OpenState SimpleTx
base = NodeState SimpleTx -> OpenState SimpleTx
Scenario.openState NodeState SimpleTx
Scenario.initialNode
c :: CoordinatedHeadState SimpleTx
c = OpenState SimpleTx
base.coordinatedHeadState
env :: Environment
env :: Environment
env = Int -> Environment
Scenario.environment Int
0
snapshotFixture :: Snapshot SimpleTx
snapshotFixture :: Snapshot SimpleTx
snapshotFixture = case ( 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
aggregateState NodeState SimpleTx
initial (Outcome SimpleTx -> NodeState SimpleTx)
-> Outcome SimpleTx -> NodeState SimpleTx
forall a b. (a -> b) -> a -> b
$
InterpreterConfig SimpleTx
-> Program SimpleTx () -> Outcome SimpleTx
forall tx. InterpreterConfig tx -> Program tx () -> Outcome tx
Interpreter.runProgram
(Environment -> Ledger SimpleTx -> InterpreterConfig SimpleTx
forall tx.
IsTx tx =>
Environment -> Ledger tx -> InterpreterConfig tx
Configuration.interpreterConfig Environment
env Ledger SimpleTx
simpleLedger)
( Workflow SimpleTx ReqSnTopology () -> Program SimpleTx ()
forall {vertex} tx (topology :: Topology vertex) result.
Workflow tx topology result -> Program tx result
Workflow.run (Workflow SimpleTx ReqSnTopology () -> Program SimpleTx ())
-> Workflow SimpleTx ReqSnTopology () -> Program SimpleTx ()
forall a b. (a -> b) -> a -> b
$
Args SimpleTx -> Workflow SimpleTx ReqSnTopology ()
forall tx.
IsChainState tx =>
Args tx -> Workflow tx ReqSnTopology ()
ReqSn.workflow
ReqSn.Args
{ $sel:env:Args :: RuleEnvironment
env = Environment -> RuleEnvironment
Configuration.ruleEnvironment Environment
env
, $sel:pendingDeposits:Args :: PendingDeposits SimpleTx
pendingDeposits = Map SimpleId (Deposit SimpleTx)
PendingDeposits SimpleTx
forall a. Monoid a => a
mempty
, $sel:chainPointTime:Args :: ChainPointTime
chainPointTime = NodeState SimpleTx
initial.chainPointTime
, $sel:openState:Args :: OpenState SimpleTx
openState = OpenState SimpleTx
os
, $sel:ttl:Args :: TTL
ttl = TTL
1
, $sel:sender:Args :: Party
sender = Party
alice
, $sel:snapshotVersion:Args :: SnapshotVersion
snapshotVersion = SnapshotVersion
0
, $sel:snapshotNumber:Args :: SnapshotNumber
snapshotNumber = SnapshotNumber
1
, $sel:transactionIds:Args :: [TxIdType SimpleTx]
transactionIds = [SimpleId
TxIdType SimpleTx
1]
, $sel:decommitTx:Args :: Maybe SimpleTx
decommitTx = Maybe SimpleTx
forall a. Maybe a
Nothing
, $sel:depositTxId:Args :: Maybe (TxIdType SimpleTx)
depositTxId = Maybe SimpleId
Maybe (TxIdType SimpleTx)
forall a. Maybe a
Nothing
}
)
).coordinatedHeadState.seenSnapshot of
SeenSnapshot{CachedSnapshot SimpleTx
$sel:cachedSnapshot:NoSeenSnapshot :: forall tx. SeenSnapshot tx -> CachedSnapshot tx
cachedSnapshot :: CachedSnapshot SimpleTx
cachedSnapshot} -> CachedSnapshot SimpleTx -> Snapshot SimpleTx
forall tx. CachedSnapshot tx -> Snapshot tx
Cached.snapshot CachedSnapshot SimpleTx
cachedSnapshot
SeenSnapshot SimpleTx
_ -> Text -> Snapshot SimpleTx
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"snapshot fixture did not request"
ackState :: HsSnapshotPhase -> [Int] -> NodeState SimpleTx
ackState :: HsSnapshotPhase -> [Int] -> NodeState SimpleTx
ackState HsSnapshotPhase
phase [Int]
signers = NodeState SimpleTx
initial{headState = Open os{coordinatedHeadState = c{localTxs = Seq.singleton Scenario.transactionTwo, seenSnapshot = seen}}}
where
c :: CoordinatedHeadState SimpleTx
c = OpenState SimpleTx
os.coordinatedHeadState
seen :: SeenSnapshot SimpleTx
seen = case HsSnapshotPhase
phase of
HsSnapshotPhase
NeverSeen -> SeenSnapshot SimpleTx
forall tx. SeenSnapshot tx
NoSeenSnapshot
HsSnapshotPhase
RequestPending -> SnapshotNumber -> SnapshotNumber -> SeenSnapshot SimpleTx
forall tx. SnapshotNumber -> SnapshotNumber -> SeenSnapshot tx
RequestedSnapshot SnapshotNumber
1 SnapshotNumber
2
HsSnapshotPhase
CollectingSignatures -> 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
snapshotFixture ([(Party, Signature (Snapshot SimpleTx))]
-> Map Party (Signature (Snapshot SimpleTx))
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [([Party]
Scenario.scenarioParties [Party] -> Int -> Party
forall a. HasCallStack => [a] -> Int -> a
!! Int
i, Secret (SigningKey HydraKey)
-> Snapshot SimpleTx -> Signature (Snapshot SimpleTx)
forall a.
SignableRepresentation a =>
Secret (SigningKey HydraKey) -> a -> Signature a
sign ([Secret (SigningKey HydraKey)
aliceSk, Secret (SigningKey HydraKey)
bobSk, Secret (SigningKey HydraKey)
carolSk] [Secret (SigningKey HydraKey)]
-> Int -> Secret (SigningKey HydraKey)
forall a. HasCallStack => [a] -> Int -> a
!! Int
i) Snapshot SimpleTx
snapshotFixture) | Int
i <- [Int]
signers])
HsSnapshotPhase
LastConfirmed -> SnapshotNumber -> SeenSnapshot SimpleTx
forall tx. SnapshotNumber -> SeenSnapshot tx
LastSeenSnapshot SnapshotNumber
1
depositFixture :: DepositStatus -> Deposit SimpleTx
depositFixture :: DepositStatus -> Deposit SimpleTx
depositFixture = HeadId
-> UTxOType SimpleTx
-> UTCTime
-> UTCTime
-> DepositStatus
-> Deposit SimpleTx
forall tx.
HeadId
-> UTxOType tx -> UTCTime -> UTCTime -> DepositStatus -> Deposit tx
Deposit HeadId
testHeadId (SimpleId -> UTxOType SimpleTx
utxoRef SimpleId
100) UTCTime
initialChainTime (NominalDiffTime -> UTCTime -> UTCTime
addUTCTime NominalDiffTime
3600 UTCTime
initialChainTime)
projectSnapshotOutcome :: Outcome SimpleTx -> HsSnapshotOutcome
projectSnapshotOutcome :: Outcome SimpleTx -> HsSnapshotOutcome
projectSnapshotOutcome = \case
Continue [StateChanged SimpleTx]
events [Effect SimpleTx]
effects -> [HsSnapshotChange] -> [HsSnapshotEffect] -> HsSnapshotOutcome
SnapshotCompleted ((StateChanged SimpleTx -> HsSnapshotChange)
-> [StateChanged SimpleTx] -> [HsSnapshotChange]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap StateChanged SimpleTx -> HsSnapshotChange
projectChange [StateChanged SimpleTx]
events) ((Effect SimpleTx -> HsSnapshotEffect)
-> [Effect SimpleTx] -> [HsSnapshotEffect]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Effect SimpleTx -> HsSnapshotEffect
projectEffect [Effect SimpleTx]
effects)
Wait WaitReason SimpleTx
reason [StateChanged SimpleTx]
_ -> HsSnapshotWait -> HsSnapshotOutcome
SnapshotWaiting (HsSnapshotWait -> HsSnapshotOutcome)
-> HsSnapshotWait -> HsSnapshotOutcome
forall a b. (a -> b) -> a -> b
$ case WaitReason SimpleTx
reason of
WaitOnSnapshotNumber{} -> HsSnapshotWait
PreviousUnconfirmed
WaitOnSnapshotVersion{} -> HsSnapshotWait
VersionMismatch
WaitOnTxs{} -> HsSnapshotWait
MissingTransactions
WaitReason SimpleTx
WaitOnSeenSnapshot -> HsSnapshotWait
SnapshotNotSeen
WaitReason SimpleTx
_ -> Text -> HsSnapshotWait
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"wait outside bounded snapshot model"
Error (RequireFailed RequirementFailure SimpleTx
reason) -> HsSnapshotRejection -> HsSnapshotOutcome
SnapshotRejected (HsSnapshotRejection -> HsSnapshotOutcome)
-> HsSnapshotRejection -> HsSnapshotOutcome
forall a b. (a -> b) -> a -> b
$ case RequirementFailure SimpleTx
reason of
ReqSnNumberInvalid{} -> HsSnapshotRejection
InvalidNumber
AckSnNumberInvalid{} -> HsSnapshotRejection
InvalidNumber
ReqSnNotLeader{} -> HsSnapshotRejection
NotLeader
SnapshotDoesNotApply{} -> HsSnapshotRejection
TransactionDoesNotApply
SnapshotAlreadySigned{} -> HsSnapshotRejection
AlreadySigned
InvalidMultisignature{} -> HsSnapshotRejection
InvalidSignatureSet
RequirementFailure SimpleTx
_ -> Text -> HsSnapshotRejection
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"rejection outside bounded snapshot model"
Outcome SimpleTx
_ -> Text -> HsSnapshotOutcome
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"outcome outside bounded snapshot model"
where
projectChange :: StateChanged SimpleTx -> HsSnapshotChange
projectChange :: StateChanged SimpleTx -> HsSnapshotChange
projectChange = \case
PartySignedSnapshot{} -> HsSnapshotChange
RecordSignature
SnapshotConfirmed{} -> HsSnapshotChange
ConfirmSnapshot
SnapshotRequestDecided{} -> HsSnapshotChange
DecideNextSnapshot
SnapshotRequested{} -> HsSnapshotChange
RecordSnapshot
StateChanged SimpleTx
_ -> Text -> HsSnapshotChange
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"change outside bounded snapshot model"
projectEffect :: Effect SimpleTx -> HsSnapshotEffect
projectEffect :: Effect SimpleTx -> HsSnapshotEffect
projectEffect = \case
NetworkEffect AckSn{} -> HsSnapshotEffect
SendAcknowledgement
NetworkEffect ReqSn{} -> HsSnapshotEffect
SendSnapshotRequest
Effect SimpleTx
_ -> Text -> HsSnapshotEffect
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"effect outside bounded snapshot model"
requireRight :: Either Text a -> IO a
requireRight :: forall a. Either Text a -> IO a
requireRight = (Text -> IO a) -> (a -> IO a) -> Either Text a -> IO a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (String -> IO a
forall (m :: * -> *) a.
(HasCallStack, MonadThrow m) =>
String -> m a
failure (String -> IO a) -> (Text -> String) -> Text -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
forall a. ToString a => a -> String
toString) a -> IO a
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
registryRegressionRoute :: [Scenario.Action]
registryRegressionRoute :: [Action]
registryRegressionRoute = [Delivery -> Action
Scenario.Duplicate Delivery
d, Delivery -> Action
Scenario.Deliver Delivery
d, Delivery -> Action
Scenario.Deliver Delivery
d]
where
d :: Delivery
d = Int -> Int -> TTL -> Message SimpleTx -> Delivery
Scenario.Delivery Int
0 Int
1 TTL
2 (SimpleTx -> Message SimpleTx
forall tx. tx -> Message tx
ReqTx SimpleTx
Scenario.transactionOne)
expiredDependencyRoute :: [Scenario.Action]
expiredDependencyRoute :: [Action]
expiredDependencyRoute = [Action]
prefix [Action] -> [Action] -> [Action]
forall a. Semigroup a => a -> a -> a
<> Int -> World -> [Action]
drain Int
40 ((Text -> World) -> (World -> World) -> Either Text World -> World
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either Text -> World
forall a t. (HasCallStack, IsText t) => t -> a
error World -> World
forall a. a -> a
id (Either Text World -> World) -> Either Text World -> World
forall a b. (a -> b) -> a -> b
$ ExecutionMode -> World -> [Action] -> Either Text World
Explorer.runPath ExecutionMode
Scenario.VerifySignatures World
Scenario.initialWorld [Action]
prefix)
where
d :: Delivery
d = Int -> Int -> TTL -> Message SimpleTx -> Delivery
Scenario.Delivery Int
0 Int
1 TTL
2 (SimpleTx -> Message SimpleTx
forall tx. tx -> Message tx
ReqTx SimpleTx
Scenario.transactionTwo)
prefix :: [Action]
prefix = [Delivery -> Action
Scenario.Deliver Delivery
d{Scenario.recipientIndex = 0}, Delivery -> Action
Scenario.Deliver Delivery
d{Scenario.recipientIndex = 2}, Delivery -> Action
Scenario.Deliver Delivery
d, Delivery -> Action
Scenario.Retry Delivery
d{Scenario.remainingTTL = 1}, Delivery -> Action
Scenario.Retry Delivery
d{Scenario.remainingTTL = 0}]
drain :: Int -> Scenario.World -> [Scenario.Action]
drain :: Int -> World -> [Action]
drain Int
remaining World
world
| Int
remaining Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = []
| Bool
otherwise = case (Delivery -> Action) -> [Delivery] -> [Action]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Delivery -> Action
Scenario.Deliver World
world.pending [Action] -> [Action] -> [Action]
forall a. Semigroup a => a -> a -> a
<> (Delivery -> Action) -> [Delivery] -> [Action]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Delivery -> Action
Scenario.Retry World
world.retries of
[] -> []
Action
action : [Action]
_ -> Action
action Action -> [Action] -> [Action]
forall a. a -> [a] -> [a]
: Int -> World -> [Action]
drain (Int
remaining Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ((Text -> World) -> (World -> World) -> Either Text World -> World
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either Text -> World
forall a t. (HasCallStack, IsText t) => t -> a
error World -> World
forall a. a -> a
id (Either Text World -> World) -> Either Text World -> World
forall a b. (a -> b) -> a -> b
$ ExecutionMode -> World -> Action -> Either Text World
Explorer.advance ExecutionMode
Scenario.VerifySignatures World
world Action
action)
faultExploration :: Scenario.Exploration
faultExploration :: Exploration
faultExploration = Exploration
Scenario.defaultExploration{Scenario.executionMode = Scenario.BypassVerification, Scenario.disturbances = Scenario.AllowInvalidAcknowledgement}
scheduleChoice :: Scenario.World -> Int -> Scenario.World
scheduleChoice :: World -> Int -> World
scheduleChoice World
world Int
choice = case Disturbances -> World -> [Action]
Explorer.actions Disturbances
Scenario.ValidMessagesOnly World
world of
[] -> World
world
[Action]
enabled -> (Text -> World) -> (World -> World) -> Either Text World -> World
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either Text -> World
forall a t. (HasCallStack, IsText t) => t -> a
error World -> World
forall a. a -> a
id (Either Text World -> World) -> Either Text World -> World
forall a b. (a -> b) -> a -> b
$ ExecutionMode -> World -> Action -> Either Text World
Explorer.advance ExecutionMode
Scenario.VerifySignatures World
world ([Action]
enabled [Action] -> Int -> Action
forall a. HasCallStack => [a] -> Int -> a
!! (Int
choice Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` [Action] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Action]
enabled))
drainWorld :: Int -> Scenario.World -> Scenario.World
drainWorld :: Int -> World -> World
drainWorld Int
remaining World
world
| Int
remaining Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = World
world
| Bool
otherwise = case (Delivery -> Action) -> [Delivery] -> [Action]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Delivery -> Action
Scenario.Deliver World
world.pending [Action] -> [Action] -> [Action]
forall a. Semigroup a => a -> a -> a
<> (Delivery -> Action) -> [Delivery] -> [Action]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Delivery -> Action
Scenario.Retry World
world.retries of
[] -> World
world
Action
action : [Action]
_ -> Int -> World -> World
drainWorld (Int
remaining Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) (World -> World) -> World -> World
forall a b. (a -> b) -> a -> b
$ (Text -> World) -> (World -> World) -> Either Text World -> World
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either Text -> World
forall a t. (HasCallStack, IsText t) => t -> a
error World -> World
forall a. a -> a
id (Either Text World -> World) -> Either Text World -> World
forall a b. (a -> b) -> a -> b
$ ExecutionMode -> World -> Action -> Either Text World
Explorer.advance ExecutionMode
Scenario.VerifySignatures World
world Action
action