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 block_participation = Arc::new(StakeDistributionDataSourceMock::new());
37//!    let governed_map        = Arc::new(GovernedMapDataSourceMock::default());
38//!
39//!    Ok(())
40//! }
41//! ```
42//!
43//! After that they can be passed as dependencies to other Partner Chains toolkit components.
44
45#![deny(missing_docs)]
46
47#[cfg(feature = "block-source")]
48mod block;
49#[cfg(feature = "block-source")]
50pub use block::BlockDataSourceMock;
51
52#[cfg(feature = "candidate-source")]
53mod candidate;
54#[cfg(feature = "candidate-source")]
55pub use candidate::{
56	AuthoritySelectionDataSourceMock, MockEpochCandidates, MockRegistrationsConfig,
57};
58
59#[cfg(feature = "governed-map")]
60mod governed_map;
61#[cfg(feature = "governed-map")]
62pub use governed_map::GovernedMapDataSourceMock;
63
64#[cfg(feature = "mc-hash")]
65mod mc_hash;
66#[cfg(feature = "mc-hash")]
67pub use mc_hash::McHashDataSourceMock;
68
69#[cfg(feature = "sidechain-rpc")]
70mod sidechain_rpc;
71#[cfg(feature = "sidechain-rpc")]
72pub use sidechain_rpc::SidechainRpcDataSourceMock;
73
74#[cfg(feature = "block-participation")]
75mod stake_distribution;
76#[cfg(feature = "block-participation")]
77pub use stake_distribution::StakeDistributionDataSourceMock;
78
79#[cfg(feature = "bridge")]
80mod bridge;
81#[cfg(feature = "bridge")]
82pub use bridge::TokenBridgeDataSourceMock;
83
84type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;