linera_sdk/test/
mock_stubs.rs1use linera_base::{
12 data_types::{Amount, Timestamp},
13 identifiers::{ApplicationId, ChainId},
14};
15use linera_views::context::MemoryContext;
16use serde::Serialize;
17
18const ERROR_MESSAGE: &str =
20 "The mock API is only available for unit tests running inside a WebAssembly virtual machine. \
21 Please check that the unit tests are executed with `linera project test` or with \
22 `cargo test --target wasm32-unknown-unknown`. \
23 Also ensure that the unit tests (or the module containing them) has a \
24 `#[cfg(target_arch = \"wasm32-unknown-unknown\")]` attribute so that they don't get compiled \
25 in for the integration tests";
26
27pub fn mock_chain_id(_chain_id: impl Into<Option<ChainId>>) {
29 unreachable!("{ERROR_MESSAGE}");
30}
31
32pub fn mock_application_id(_application_id: impl Into<Option<ApplicationId>>) {
34 unreachable!("{ERROR_MESSAGE}");
35}
36
37pub fn mock_application_parameters(_application_parameters: &impl Serialize) {
39 unreachable!("{ERROR_MESSAGE}");
40}
41
42pub fn mock_chain_balance(_chain_balance: impl Into<Option<Amount>>) {
44 unreachable!("{ERROR_MESSAGE}");
45}
46
47pub fn mock_system_timestamp(_system_timestamp: impl Into<Option<Timestamp>>) {
49 unreachable!("{ERROR_MESSAGE}");
50}
51
52pub fn log_messages() -> Vec<(log::Level, String)> {
54 unreachable!("{ERROR_MESSAGE}");
55}
56
57pub fn mock_application_state(_state: impl Into<Option<Vec<u8>>>) {
59 unreachable!("{ERROR_MESSAGE}");
60}
61
62pub fn mock_key_value_store() -> MemoryContext<()> {
64 unreachable!("{ERROR_MESSAGE}");
65}
66
67pub fn mock_try_query_application<E>(
69 _handler: impl FnMut(ApplicationId, Vec<u8>) -> Result<Vec<u8>, E> + 'static,
70) where
71 E: ToString + 'static,
72{
73 unreachable!("{ERROR_MESSAGE}");
74}