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 pallet_domains::staking::StakingSummary;
5use parity_scale_codec::{Decode, Encode};
6use sp_core::H256;
7use sp_domains::{DomainId, OperatorId};
8use sp_messenger::messages::{ChainId, ChannelId};
9use sp_runtime::traits::NumberFor;
10use sp_subspace_mmr::{ConsensusChainMmrLeafProof, MmrLeaf};
11
12/// Domains Block pruning depth.
13pub const DOMAINS_BLOCK_PRUNING_DEPTH: u32 = 10;
14
15sp_api::decl_runtime_apis! {
16    /// Api for querying onchain state in the test
17    pub trait OnchainStateApi<AccountId, Balance>
18    where
19        AccountId: Encode + Decode,
20        Balance: Encode + Decode
21    {
22        /// Api to get the free balance of the given account
23        fn free_balance(account_id: AccountId) -> Balance;
24
25        /// Returns the last open channel for a given domain.
26        fn get_open_channel_for_chain(dst_chain_id: ChainId) -> Option<ChannelId>;
27
28        /// Verify the mmr proof statelessly and extract the state root.
29        fn verify_proof_and_extract_leaf(proof: ConsensusChainMmrLeafProof<NumberFor<Block>, Block::Hash, H256>) -> Option<MmrLeaf<NumberFor<Block>, Block::Hash>>;
30
31        /// Return the domain balance in the consensus chain bookkeeping
32        fn domain_balance(domain_id: DomainId) -> Balance;
33
34        /// Returns the domain stake summary
35        fn domain_stake_summary(domain_id: DomainId) -> Option<StakingSummary<OperatorId, Balance>>;
36    }
37}