Scenario

scalus.testing.Scenario
See theScenario companion trait
object Scenario

Attributes

Companion
trait
Graph
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
Scenario.type

Members list

Type members

Classlikes

case class Branches[A](branches: LogicStreamT[Future, Scenario[A]]) extends Scenario[A]

Non-deterministic branching — each branch is an independent Scenario.

Non-deterministic branching — each branch is an independent Scenario.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Scenario[A]
class Object
trait Matchable
class Any
Show all
case class Done[A](state: ScenarioState, value: A) extends Scenario[A]

Terminal: holds final state and value.

Terminal: holds final state and value.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Scenario[A]
class Object
trait Matchable
class Any
Show all
case class FromStream[A](stream: LogicStreamT[Future, (ScenarioState, A)]) extends Scenario[A]

Already-evaluated stream (from fsplit/msplit tails).

Already-evaluated stream (from fsplit/msplit tails).

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Scenario[A]
class Object
trait Matchable
class Any
Show all
case class Leaf[A](state: ScenarioState, run: ScenarioState => Scenario[A]) extends Scenario[A]

State-dependent continuation.

State-dependent continuation.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Scenario[A]
class Object
trait Matchable
class Any
Show all
case class ScenarioError[A](state: ScenarioState, error: Throwable) extends Scenario[A]

Error with state for rollback in flatMapTry.

Error with state for rollback in flatMapTry.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Scenario[A]
class Object
trait Matchable
class Any
Show all
case class WaitFuture[A](future: Future[Scenario[A]]) extends Scenario[A]

Async suspension — wait for Future, then continue.

Async suspension — wait for Future, then continue.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Scenario[A]
class Object
trait Matchable
class Any
Show all
object genToScenarioConversion extends CpsMonadConversion[Gen, Scenario]

Enables implicit conversion from ScalaCheck Gen to Scenario.

Enables implicit conversion from ScalaCheck Gen to Scenario.

Allows writing:

 async[Scenario] {
   val x = Gen.choose(1, 10).await // implicitly converted via sample
   ...
 }

Attributes

Supertypes
trait CpsMonadConversion[Gen, Scenario]
class Object
trait Matchable
class Any
Self type
object scenarioLogicMonad extends CpsConcurrentLogicMonad[Scenario, Future], CpsConcurrentLogicMonadInstanceContext[Scenario, Future]

Attributes

Supertypes
trait CpsConcurrentLogicMonadInstanceContext[Scenario, Future]
trait CpsConcurrentLogicMonad[Scenario, Future]
trait CpsLogicMonad[Scenario]
trait CpsTryMonad[Scenario]
trait CpsTrySupport[Scenario]
trait CpsThrowMonad[Scenario]
trait CpsThrowSupport[Scenario]
trait CpsMonad[Scenario]
class Object
trait Matchable
class Any
Show all
Self type

Inherited and Abstract types

type MirroredElemLabels <: Tuple

The names of the product elements

The names of the product elements

Attributes

Inherited from:
Mirror
type MirroredLabel <: String

The name of the type

The name of the type

Attributes

Inherited from:
Mirror

Value members

Concrete methods

Get the current action log (in chronological order).

Get the current action log (in chronological order).

Attributes

inline def check(inline condition: Boolean, inline message: String = ...): Scenario[Unit]

Check a condition, failing the scenario with CheckFailure if false.

Check a condition, failing the scenario with CheckFailure if false.

This is an inline macro that captures the predicate expression, optional message, and source location at compile time.

Usage:

async[Scenario] {
   Scenario.check(balance >= 0).await
   Scenario.check(owner != null, "owner must be set").await
}

Attributes

def choices[A](xs: A*): Scenario[A]

Create non-deterministic choices from the given values.

Create non-deterministic choices from the given values.

Attributes

Get the current emulator state (read-only snapshot).

Get the current emulator state (read-only snapshot).

Attributes

def error[A](e: Throwable): Scenario[A]

Raise an error in the current branch.

Raise an error in the current branch.

Attributes

def eval[A](scenario: Scenario[A]): LogicStreamT[Future, (ScenarioState, A)]

Evaluate a Scenario tree to a LogicStreamT of (state, value) pairs.

Evaluate a Scenario tree to a LogicStreamT of (state, value) pairs.

Attributes

def explore(maxDepth: Int)(step: BlockchainReader => Scenario[Unit]): Scenario[Option[Violation]]

Explore contract interactions up to a maximum depth.

Explore contract interactions up to a maximum depth.

Convenience method that delegates to ScenarioExplorer.explore.

The step function receives a BlockchainReader and should perform one step of the contract interaction using normal Scenario operations (submit, sleep, etc.). Actions are automatically logged and included in Violation.path if a check fails.

Value parameters

maxDepth

maximum number of steps to explore

step

function that performs one interaction step; use Scenario.check for invariants, Scenario.choices/Scenario.fromCollection for branching

Attributes

Returns

Scenario returning None if all paths succeeded, Some(Violation) if a check failed

def fail[A]: Scenario[A]

Always-failing computation (prunes this branch).

Always-failing computation (prunes this branch).

Attributes

def fromCollection[A](xs: Iterable[A]): Scenario[A]

Create non-deterministic choices from a collection.

Create non-deterministic choices from a collection.

Attributes

def guard(cond: Boolean): Scenario[Unit]

Prune this branch if the condition is false.

Prune this branch if the condition is false.

Attributes

Get the current slot number.

Get the current slot number.

Attributes

Get a BlockchainProviderTF that operates within the Scenario monad.

Get a BlockchainProviderTF that operates within the Scenario monad.

Each call reads/updates the latest emulator state.

Attributes

def run[A](initial: ScenarioState)(s: Scenario[A]): LogicStreamT[Future, (ScenarioState, A)]

Evaluate and run a scenario, returning the raw LogicStreamT.

Evaluate and run a scenario, returning the raw LogicStreamT.

Attributes

def runAll[A](initial: ScenarioState, maxResults: Int = ...)(s: Scenario[A]): Future[IndexedSeq[(ScenarioState, A)]]

Run a scenario and collect all successful results (up to n, default 1000).

Run a scenario and collect all successful results (up to n, default 1000).

Attributes

def runFirst[A](initial: ScenarioState)(s: Scenario[A]): Future[Option[(ScenarioState, A)]]

Run a scenario and return the first successful result.

Run a scenario and return the first successful result.

Attributes

def sample[A](gen: Gen[A]): Scenario[A]

Sample a value from a ScalaCheck generator using the scenario's RNG.

Sample a value from a ScalaCheck generator using the scenario's RNG.

The RNG state is advanced deterministically, ensuring reproducible execution across branches. If the generator fails to produce a value, this branch is pruned (returns mzero).

Attributes

def sampleN[A](gen: Gen[A], n: Int = ...): Scenario[A]

Sample N values from a generator, creating N branches.

Sample N values from a generator, creating N branches.

Each branch receives a different sampled value and its own RNG state. Failed samples are filtered out.

Attributes

def sleep(slots: Long): Scenario[Unit]

Advance the slot by the given number of slots.

Advance the slot by the given number of slots.

Attributes

Get a read-only BlockchainReader snapshot from the current state.

Get a read-only BlockchainReader snapshot from the current state.

Attributes

Submit a transaction, updating the emulator state if successful.

Submit a transaction, updating the emulator state if successful.

On success, the transaction is logged to the action log.

Attributes

Deprecated methods

Get a read-only BlockchainProvider snapshot from the current state.

Get a read-only BlockchainProvider snapshot from the current state.

Attributes

Deprecated
[Since version 0.14.2] Use snapshotReader instead

Use snapshotReader instead. The submit method on this provider discards state changes which is misleading.

Givens

Givens

Enables implicit conversion from ScalaCheck Gen to Scenario.

Enables implicit conversion from ScalaCheck Gen to Scenario.

Allows writing:

 async[Scenario] {
   val x = Gen.choose(1, 10).await // implicitly converted via sample
   ...
 }

Attributes