referrerpolicy=no-referrer-when-downgrade

polkadot_node_subsystem_test_helpers/
mock.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
16
17use std::sync::Arc;
18
19use polkadot_node_subsystem::{ActivatedLeaf, BlockInfo};
20use sc_client_api::UnpinHandle;
21use sc_keystore::LocalKeystore;
22use sc_utils::mpsc::tracing_unbounded;
23use sp_application_crypto::AppCrypto;
24use sp_keyring::Sr25519Keyring;
25use sp_keystore::{Keystore, KeystorePtr};
26
27use polkadot_primitives::{AuthorityDiscoveryId, Block, BlockNumber, Hash, ValidatorId};
28
29/// Get mock keystore with `Ferdie` key.
30pub fn make_ferdie_keystore() -> KeystorePtr {
31	let keystore: KeystorePtr = Arc::new(LocalKeystore::in_memory());
32	Keystore::sr25519_generate_new(
33		&*keystore,
34		ValidatorId::ID,
35		Some(&Sr25519Keyring::Ferdie.to_seed()),
36	)
37	.expect("Insert key into keystore");
38	Keystore::sr25519_generate_new(
39		&*keystore,
40		AuthorityDiscoveryId::ID,
41		Some(&Sr25519Keyring::Ferdie.to_seed()),
42	)
43	.expect("Insert key into keystore");
44	keystore
45}
46
47/// Create a meaningless unpin handle for a block.
48pub fn dummy_unpin_handle(block: Hash) -> UnpinHandle<Block> {
49	let (dummy_sink, _) = tracing_unbounded("Expect Chaos", 69);
50	UnpinHandle::new(block, dummy_sink)
51}
52
53/// Create a new leaf with the given hash and number.
54pub fn new_leaf(hash: Hash, number: BlockNumber) -> ActivatedLeaf {
55	ActivatedLeaf { hash, number, unpin_handle: dummy_unpin_handle(hash) }
56}
57
58/// Create a new leaf with the given hash and number.
59pub fn new_block_import_info(hash: Hash, number: BlockNumber) -> BlockInfo {
60	BlockInfo { hash, parent_hash: Hash::default(), number, unpin_handle: dummy_unpin_handle(hash) }
61}