Tryorama

repository·main·Indexed 42 days ago

https://github.com/holochain/tryorama

A tool for running multiple Holochain conductors locally, enabling developers to simulate a network of nodes and test complex multi-node behaviors using standard JavaScript test runners. It provides a hierarchical structure of Scenarios, Players, and Conductors to manage the lifecycle of hApps and verify application behavior.

Tokens
22.9K
Snippets
126
Records
182
Agent score
52%

What's inside Tryorama

  1. Understand Tryorama Scenarios, Players, and Conductors

    main

    Tryorama is organized into three hierarchical layers:

    1. Scenarios: High-level abstractions that provide functions to interact with the Holochain Conductor API across multiple nodes.
    2. Players: A constituent of a Scenario. A Player consists of a Conductor, an Agent, and installed hApps. You access installed hApps via cells, which can be retrieved by their role ID or destructured based on the installation sequence.
    3. Conductors: The layer below the Scenario. A Conductor manages the lifecycle (startup/shutdown) and provides full access to the Admin and App APIs available in the JavaScript client.
  2. Use the Scenario class to test Holochain hApps

    main

    The Scenario class is the primary abstraction for writing tests against Holochain hApps. It manages a local conductor environment, allowing you to orchestrate multiple conductors (players), install apps, and simulate network interactions.

    To use it, you instantiate a Scenario and then use its methods to add conductors, install apps, and manage the lifecycle of the test environment. Always ensure you call cleanUp() or shutDown() to prevent leaking processes.

    ```typescript
    import { Scenario } from '@holochain/tryorama';
    
    // Example conceptual usage
    const scenario = new Scenario({ /* options */ });
    // ... add conductors, install apps, run tests ...
    await scenario.cleanUp();
    ```埋
  3. Optimize transport timeouts for testing

    main
    When writing tests that frequently start and stop conductors, you may experience delays waiting for connections to establish or fail. To speed up your test suite, reduce the transportTimeoutS property in your NetworkConfig. This reduces the time Holochain spends waiting for connections to conductors that are no longer running.
  4. Install @holochain/tryorama

    main

    Install Tryorama via npm to run multiple Holochain conductors locally for testing. This allows you to simulate a network of nodes and use your preferred test runner and assertion library to verify Holochain application behavior.

    npm install @holochain/tryorama
  5. Use the Tryorama public API

    main

    Tryorama provides tools for managing Holochain Conductors. The library exports its core functionality through several modules:

    • conductor: Core conductor management logic.
    • conductor-helpers: Helper functions for interacting with conductors.
    • scenario: Tools for defining and running test scenarios.
    • types: TypeScript type definitions used throughout the library.
    • util: General utility functions.
  6. How CallableCell and Zome calls work

    main

    A CallableCell is an extension of a standard Holochain cell (ClonedCell or ProvisionedCell) that includes a specialized callZome method.

    When you use getCallableCell, the returned object wraps the standard AppWebsocket.callZome method. It automatically injects the correct cell_id from the cell into the request payload, ensuring that the call is routed to the correct location on the conductor. This abstraction allows developers to treat cells as objects with methods rather than raw data structures requiring manual ID management.

    // Internal mechanism used by getCallableCell
    const callZome = async <T>(request: CellZomeCallRequest, timeout?: number) => {
      const callZomeResponse = await appWs.callZome({
        ...request,
        cell_id: cell.cell_id,
        payload: request.payload ?? null,
      }, timeout);
      return callZomeResponse;
    };
  7. Configure Tryorama logging levels

    main

    You can control the verbosity of Tryorama logs using the TRYORAMA_LOG_LEVEL environment variable.

    Supported levels:

    • debug
    • verbose
    • info (default)

    To run a test with a specific log level, prepend the command with the environment variable.

    TRYORAMA_LOG_LEVEL=debug node test.js