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
12sp_api::decl_runtime_apis! {
13    /// Api for querying onchain state in the test
14    pub trait OnchainStateApi<AccountId, Balance>
15    where
16        AccountId: Encode + Decode,
17        Balance: Encode + Decode
18    {
19        /// Api to get the free balance of the given account
20        fn free_balance(account_id: AccountId) -> Balance;
21
22        /// Returns the last open channel for a given domain.
23        fn get_open_channel_for_chain(dst_chain_id: ChainId) -> Option<ChannelId>;
24
25        /// Verify the mmr proof statelessly and extract the state root.
26        fn verify_proof_and_extract_leaf(proof: ConsensusChainMmrLeafProof<NumberFor<Block>, Block::Hash, H256>) -> Option<MmrLeaf<NumberFor<Block>, Block::Hash>>;
27
28        /// Return the domain balance in the consensus chain bookkeeping
29        fn domain_balance(domain_id: DomainId) -> Balance;
30
31        /// Returns the domain stake summary
32        fn domain_stake_summary(domain_id: DomainId) -> Option<StakingSummary<OperatorId, Balance>>;
33    }
34}