subspace_test_primitives/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2//! Test primitive crates that expose necessary extensions that are used in tests.
3
4use parity_scale_codec::{Decode, Encode};
5use sp_core::H256;
6use sp_domains::DomainId;
7use sp_messenger::messages::{ChainId, ChannelId};
8use sp_runtime::traits::NumberFor;
9use sp_subspace_mmr::{ConsensusChainMmrLeafProof, MmrLeaf};
10
11/// Domains Block pruning depth.
12pub const DOMAINS_BLOCK_PRUNING_DEPTH: u32 = 10;
13
14sp_api::decl_runtime_apis! {
15    /// Api for querying onchain state in the test
16    pub trait OnchainStateApi<AccountId, Balance>
17    where
18        AccountId: Encode + Decode,
19        Balance: Encode + Decode
20    {
21        /// Api to get the free balance of the given account
22        fn free_balance(account_id: AccountId) -> Balance;
23
24        /// Returns the last open channel for a given domain.
25        fn get_open_channel_for_chain(dst_chain_id: ChainId) -> Option<ChannelId>;
26
27        /// Verify the mmr proof statelessly and extract the state root.
28        fn verify_proof_and_extract_leaf(proof: ConsensusChainMmrLeafProof<NumberFor<Block>, Block::Hash, H256>) -> Option<MmrLeaf<NumberFor<Block>, Block::Hash>>;
29
30        /// Return the domain balance in the consensus chain bookkeeping
31        fn domain_balance(domain_id: DomainId) -> Balance;
32    }
33}