partner_chains_mock_data_sources/lib.rs
1//! # Partner Chains Mocked Data Sources
2//!
3//! This crate provides mocked implementations of all data source interfaces used
4//! by the Partner Chain toolkit's components, that can be wired into a Substrate
5//! node to avoid having access to a real data source like the Db-Sync data sources
6//! provided by `partner_chain_db_sync_data_sources` crate.
7//!
8//! # Usage
9//!
10//! *Important*: The mock data sources completely replace any interaction of the Partner
11//! Chain with its Cardano main chain, making them suitable only for local
12//! development and early exploration. They should not be used in production
13//! of public testnets.
14//!
15//! The mock data sources defined in this crate are meant to make it possible to run
16//! a Partner Chain node with as little additional work as possible. Because of that,
17//! most of them return either empty or constant data. The important exception is the
18//! [AuthoritySelectionDataSourceMock] which can be fully configured with epoch data.
19//! See each data source's documentation to see if and how it can be configured.
20//!
21//!
22//! The mock data sources should be created as part of the node code, like so:
23//! ```rust
24//! use partner_chains_mock_data_sources::*;
25//! use std::error::Error;
26//! use std::sync::Arc;
27//!
28//! pub fn create_mock_data_sources()
29//! -> std::result::Result<(), Box<dyn Error + Send + Sync + 'static>> {
30//! /// The block data source is reused by other data sources
31//! let block = Arc::new(BlockDataSourceMock::new_from_env()?);
32//!
33//! let mc_hash = Arc::new(McHashDataSourceMock::new(block.clone()));
34//! let sidechain_rpc = Arc::new(SidechainRpcDataSourceMock::new(block));
35//! let authority_selection = Arc::new(AuthoritySelectionDataSourceMock::new_from_env()?);
36//! let native_token = Arc::new(NativeTokenDataSourceMock::new());
37//! let block_participation = Arc::new(StakeDistributionDataSourceMock::new());
38//! let governed_map = Arc::new(GovernedMapDataSourceMock::default());
39//!
40//! Ok(())
41//! }
42//! ```
43//!
44//! After that they can be passed as dependencies to other Partner Chains toolkit components.
45
46#![deny(missing_docs)]
47
48#[cfg(feature = "block-source")]
49mod block;
50#[cfg(feature = "block-source")]
51pub use block::BlockDataSourceMock;
52
53#[cfg(feature = "candidate-source")]
54mod candidate;
55#[cfg(feature = "candidate-source")]
56pub use candidate::{
57 AuthoritySelectionDataSourceMock, MockEpochCandidates, MockRegistrationsConfig,
58};
59
60#[cfg(feature = "governed-map")]
61mod governed_map;
62#[cfg(feature = "governed-map")]
63pub use governed_map::GovernedMapDataSourceMock;
64
65#[cfg(feature = "mc-hash")]
66mod mc_hash;
67#[cfg(feature = "mc-hash")]
68pub use mc_hash::McHashDataSourceMock;
69
70#[cfg(feature = "native-token")]
71mod native_token;
72#[cfg(feature = "native-token")]
73pub use native_token::NativeTokenDataSourceMock;
74
75#[cfg(feature = "sidechain-rpc")]
76mod sidechain_rpc;
77#[cfg(feature = "sidechain-rpc")]
78pub use sidechain_rpc::SidechainRpcDataSourceMock;
79
80#[cfg(feature = "block-participation")]
81mod stake_distribution;
82#[cfg(feature = "block-participation")]
83pub use stake_distribution::StakeDistributionDataSourceMock;
84
85type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;