linera_sdk/test/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) Zefchain Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//! Helper types for writing integration tests for WebAssembly applications.
//!
//! Integration tests are usually written in the `tests` directory in the root of the crate's
//! directory (i.e., beside the `src` directory). Linera application integration tests should be
//! executed targeting the host architecture, instead of targeting `wasm32-unknown-unknown` like
//! done for unit tests.

#![cfg(any(with_testing, with_wasm_runtime))]

#[cfg(with_integration_testing)]
mod block;
#[cfg(with_integration_testing)]
mod chain;
mod mock_stubs;
#[cfg(with_integration_testing)]
mod validator;

#[cfg(with_integration_testing)]
pub use {
    linera_chain::{
        data_types::{Medium, MessageAction},
        test::HttpServer,
        ChainError, ChainExecutionContext,
    },
    linera_core::worker::WorkerError,
    linera_execution::{system::Recipient, ExecutionError, QueryOutcome, WasmExecutionError},
};

#[cfg(with_testing)]
pub use self::mock_stubs::*;
#[cfg(with_integration_testing)]
pub use self::{
    block::BlockBuilder,
    chain::{ActiveChain, TryGraphQLMutationError, TryGraphQLQueryError, TryQueryError},
    validator::TestValidator,
};
use crate::{Contract, ContractRuntime, Service, ServiceRuntime};

/// Creates a [`ContractRuntime`] to use in tests.
pub fn test_contract_runtime<Application: Contract>() -> ContractRuntime<Application> {
    ContractRuntime::new()
}

/// Creates a [`ServiceRuntime`] to use in tests.
pub fn test_service_runtime<Application: Service>() -> ServiceRuntime<Application> {
    ServiceRuntime::new()
}