mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-09 11:47:23 +00:00
Move justification code to primitives crate (#640)
* Move justification module to header-chain primitives crate * Get justification module compiling in new location * Get justification module tests compiling * Use justification code from `header-chain` crate Mostly compiles, having issues with std/test feature flags across crates. * Move some code around * Move justification tests to integration testing crate * Add `test-utils` crate * Remove tests and test-helper module from justification code * Use `test-utils` in Substrate bridge pallet tests * Remove `sp-keyring` related code from `pallet-substrate-bridge` * Remove `helpers` module from `pallet-substrate-bridge` * Add some documentation * Add more documentation * Fix typo Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com> Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
This commit is contained in:
committed by
Bastian Köcher
parent
0280400e30
commit
c6df9924e4
@@ -16,11 +16,11 @@
|
||||
|
||||
//! Mock Runtime for Substrate Pallet Testing.
|
||||
//!
|
||||
//! Includes some useful testing utilities in the `helpers` module.
|
||||
//! Includes some useful testing types and functions.
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
use crate::Config;
|
||||
use crate::{BridgedBlockHash, BridgedBlockNumber, BridgedHeader, Config};
|
||||
use bp_runtime::Chain;
|
||||
use frame_support::{impl_outer_origin, parameter_types, weights::Weight};
|
||||
use sp_runtime::{
|
||||
@@ -30,6 +30,9 @@ use sp_runtime::{
|
||||
};
|
||||
|
||||
pub type AccountId = u64;
|
||||
pub type TestHeader = BridgedHeader<TestRuntime>;
|
||||
pub type TestNumber = BridgedBlockNumber<TestRuntime>;
|
||||
pub type TestHash = BridgedBlockHash<TestRuntime>;
|
||||
|
||||
#[derive(Clone, Eq, PartialEq, Debug)]
|
||||
pub struct TestRuntime;
|
||||
@@ -88,66 +91,16 @@ pub fn run_test<T>(test: impl FnOnce() -> T) -> T {
|
||||
sp_io::TestExternalities::new(Default::default()).execute_with(test)
|
||||
}
|
||||
|
||||
pub mod helpers {
|
||||
use super::*;
|
||||
use crate::storage::ImportedHeader;
|
||||
use crate::{BridgedBlockHash, BridgedBlockNumber, BridgedHeader};
|
||||
use finality_grandpa::voter_set::VoterSet;
|
||||
use sp_finality_grandpa::{AuthorityId, AuthorityList};
|
||||
use sp_keyring::Ed25519Keyring;
|
||||
pub fn test_header(num: TestNumber) -> TestHeader {
|
||||
// We wrap the call to avoid explicit type annotations in our tests
|
||||
bp_test_utils::test_header(num)
|
||||
}
|
||||
|
||||
pub type TestHeader = BridgedHeader<TestRuntime>;
|
||||
pub type TestNumber = BridgedBlockNumber<TestRuntime>;
|
||||
pub type TestHash = BridgedBlockHash<TestRuntime>;
|
||||
pub type HeaderId = (TestHash, TestNumber);
|
||||
|
||||
pub fn test_header(num: TestNumber) -> TestHeader {
|
||||
let mut header = TestHeader::new_from_number(num);
|
||||
header.parent_hash = if num == 0 {
|
||||
Default::default()
|
||||
} else {
|
||||
test_header(num - 1).hash()
|
||||
};
|
||||
|
||||
header
|
||||
}
|
||||
|
||||
pub fn unfinalized_header(num: u64) -> ImportedHeader<TestHeader> {
|
||||
ImportedHeader {
|
||||
header: test_header(num),
|
||||
requires_justification: false,
|
||||
is_finalized: false,
|
||||
signal_hash: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn header_id(index: u8) -> HeaderId {
|
||||
(test_header(index.into()).hash(), index as _)
|
||||
}
|
||||
|
||||
pub fn extract_keyring(id: &AuthorityId) -> Ed25519Keyring {
|
||||
let mut raw_public = [0; 32];
|
||||
raw_public.copy_from_slice(id.as_ref());
|
||||
Ed25519Keyring::from_raw_public(raw_public).unwrap()
|
||||
}
|
||||
|
||||
pub fn voter_set() -> VoterSet<AuthorityId> {
|
||||
VoterSet::new(authority_list()).unwrap()
|
||||
}
|
||||
|
||||
pub fn authority_list() -> AuthorityList {
|
||||
vec![(alice(), 1), (bob(), 1), (charlie(), 1)]
|
||||
}
|
||||
|
||||
pub fn alice() -> AuthorityId {
|
||||
Ed25519Keyring::Alice.public().into()
|
||||
}
|
||||
|
||||
pub fn bob() -> AuthorityId {
|
||||
Ed25519Keyring::Bob.public().into()
|
||||
}
|
||||
|
||||
pub fn charlie() -> AuthorityId {
|
||||
Ed25519Keyring::Charlie.public().into()
|
||||
pub fn unfinalized_header(num: u64) -> crate::storage::ImportedHeader<TestHeader> {
|
||||
crate::storage::ImportedHeader {
|
||||
header: test_header(num),
|
||||
requires_justification: false,
|
||||
is_finalized: false,
|
||||
signal_hash: None,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user