relay_substrate_client/
test_chain.rs1#![cfg(any(feature = "test-helpers", test))]
23
24use crate::{
25 Chain, ChainWithBalances, ChainWithMessages, ChainWithRewards, ChainWithTransactions,
26 Error as SubstrateError, SignParam, UnsignedTransaction,
27};
28use bp_messages::{ChainWithMessages as ChainWithMessagesBase, MessageNonce};
29use bp_runtime::ChainId;
30use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
31use frame_support::{sp_runtime::StateVersion, weights::Weight};
32use scale_info::TypeInfo;
33use std::time::Duration;
34
35#[derive(Clone, Debug, PartialEq, Eq)]
37pub struct TestChain;
38
39impl bp_runtime::Chain for TestChain {
40 const ID: ChainId = *b"test";
41
42 type BlockNumber = u32;
43 type Hash = sp_core::H256;
44 type Hasher = sp_runtime::traits::BlakeTwo256;
45 type Header = sp_runtime::generic::Header<u32, sp_runtime::traits::BlakeTwo256>;
46
47 type AccountId = u32;
48 type Balance = u32;
49 type Nonce = u32;
50 type Signature = sp_runtime::testing::TestSignature;
51
52 const STATE_VERSION: StateVersion = StateVersion::V1;
53
54 fn max_extrinsic_size() -> u32 {
55 100000
56 }
57
58 fn max_extrinsic_weight() -> Weight {
59 unreachable!()
60 }
61}
62
63impl Chain for TestChain {
64 const NAME: &'static str = "Test";
65 const BEST_FINALIZED_HEADER_ID_METHOD: &'static str = "TestMethod";
66 const FREE_HEADERS_INTERVAL_METHOD: &'static str = "TestMethod";
67 const AVERAGE_BLOCK_INTERVAL: Duration = Duration::from_millis(0);
68
69 type SignedBlock = sp_runtime::generic::SignedBlock<
70 sp_runtime::generic::Block<Self::Header, sp_runtime::OpaqueExtrinsic>,
71 >;
72 type Call = TestRuntimeCall;
73}
74
75impl ChainWithBalances for TestChain {
76 fn account_info_storage_key(_account_id: &u32) -> sp_core::storage::StorageKey {
77 unreachable!()
78 }
79}
80
81#[derive(
83 Clone,
84 Copy,
85 Debug,
86 Decode,
87 DecodeWithMemTracking,
88 Encode,
89 Eq,
90 MaxEncodedLen,
91 PartialEq,
92 TypeInfo,
93)]
94pub enum ChainReward {
95 Reward1,
97}
98
99impl ChainWithRewards for TestChain {
100 const WITH_CHAIN_RELAYERS_PALLET_NAME: Option<&'static str> = None;
101 type RewardBalance = u128;
102 type Reward = ChainReward;
103
104 fn account_reward_storage_key(
105 _account_id: &Self::AccountId,
106 _reward: impl Into<Self::Reward>,
107 ) -> sp_core::storage::StorageKey {
108 unreachable!()
109 }
110}
111
112impl ChainWithMessagesBase for TestChain {
113 const WITH_CHAIN_MESSAGES_PALLET_NAME: &'static str = "Test";
114 const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = 0;
115 const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce = 0;
116}
117
118impl ChainWithMessages for TestChain {
119 const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = "TestMessagesDetailsMethod";
120 const FROM_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = "TestFromMessagesDetailsMethod";
121}
122
123impl ChainWithTransactions for TestChain {
124 type AccountKeyPair = sp_core::sr25519::Pair;
125 type SignedTransaction = bp_polkadot_core::UncheckedExtrinsic<
126 TestRuntimeCall,
127 bp_polkadot_core::SuffixedCommonTransactionExtension<(
128 bp_runtime::extensions::BridgeRejectObsoleteHeadersAndMessages,
129 bp_runtime::extensions::RefundBridgedParachainMessagesSchema,
130 )>,
131 >;
132
133 fn sign_transaction(
134 _param: SignParam<Self>,
135 _unsigned: UnsignedTransaction<Self>,
136 ) -> Result<Self::SignedTransaction, SubstrateError> {
137 unreachable!()
138 }
139}
140
141#[derive(Decode, Encode, Clone, Debug, PartialEq)]
143pub enum TestRuntimeCall {
144 #[codec(index = 0)]
146 Dummy,
147}
148
149#[derive(Clone, Debug, PartialEq, Eq)]
151pub struct TestParachainBase;
152
153impl bp_runtime::Chain for TestParachainBase {
154 const ID: ChainId = *b"tstp";
155
156 type BlockNumber = u32;
157 type Hash = sp_core::H256;
158 type Hasher = sp_runtime::traits::BlakeTwo256;
159 type Header = sp_runtime::generic::Header<u32, sp_runtime::traits::BlakeTwo256>;
160
161 type AccountId = u32;
162 type Balance = u32;
163 type Nonce = u32;
164 type Signature = sp_runtime::testing::TestSignature;
165
166 const STATE_VERSION: StateVersion = StateVersion::V1;
167
168 fn max_extrinsic_size() -> u32 {
169 unreachable!()
170 }
171
172 fn max_extrinsic_weight() -> Weight {
173 unreachable!()
174 }
175}
176
177impl bp_runtime::Parachain for TestParachainBase {
178 const PARACHAIN_ID: u32 = 1000;
179 const MAX_HEADER_SIZE: u32 = 1_024;
180}
181
182#[derive(Clone, Debug, PartialEq, Eq)]
184pub struct TestParachain;
185
186impl bp_runtime::UnderlyingChainProvider for TestParachain {
187 type Chain = TestParachainBase;
188}
189
190impl Chain for TestParachain {
191 const NAME: &'static str = "TestParachain";
192 const BEST_FINALIZED_HEADER_ID_METHOD: &'static str = "TestParachainMethod";
193 const FREE_HEADERS_INTERVAL_METHOD: &'static str = "TestParachainMethod";
194 const AVERAGE_BLOCK_INTERVAL: Duration = Duration::from_millis(0);
195
196 type SignedBlock = sp_runtime::generic::SignedBlock<
197 sp_runtime::generic::Block<Self::Header, sp_runtime::OpaqueExtrinsic>,
198 >;
199 type Call = TestRuntimeCall;
200}