feat: Rebrand Polkadot/Substrate references to PezkuwiChain
This commit systematically rebrands various references from Parity Technologies' Polkadot/Substrate ecosystem to PezkuwiChain within the kurdistan-sdk. Key changes include: - Updated external repository URLs (zombienet-sdk, parity-db, parity-scale-codec, wasm-instrument) to point to pezkuwichain forks. - Modified internal documentation and code comments to reflect PezkuwiChain naming and structure. - Replaced direct references to with or specific paths within the for XCM, Pezkuwi, and other modules. - Cleaned up deprecated issue and PR references in various and files, particularly in and modules. - Adjusted image and logo URLs in documentation to point to PezkuwiChain assets. - Removed or rephrased comments related to external Polkadot/Substrate PRs and issues. This is a significant step towards fully customizing the SDK for the PezkuwiChain ecosystem.
This commit is contained in:
@@ -0,0 +1,287 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// This file is part of Pezcumulus.
|
||||
|
||||
// Pezcumulus is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Pezcumulus is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Pezcumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::Client;
|
||||
use codec::Encode;
|
||||
use cumulus_primitives_core::{PersistedValidationData, TeyrchainBlockData};
|
||||
use cumulus_primitives_teyrchain_inherent::{TeyrchainInherentData, INHERENT_IDENTIFIER};
|
||||
use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
|
||||
use cumulus_test_runtime::{Block, GetLastTimestamp, Hash, Header};
|
||||
use pezkuwi_primitives::{BlockNumber as PBlockNumber, Hash as PHash};
|
||||
use pezsc_block_builder::BlockBuilderBuilder;
|
||||
use pezsp_api::{ProofRecorder, ProofRecorderIgnoredNodes, ProvideRuntimeApi};
|
||||
use pezsp_consensus_aura::{AuraApi, Slot};
|
||||
use pezsp_runtime::{traits::Header as HeaderT, Digest, DigestItem};
|
||||
|
||||
/// A struct containing a block builder and support data required to build test scenarios.
|
||||
pub struct BlockBuilderAndSupportData<'a> {
|
||||
pub block_builder: pezsc_block_builder::BlockBuilder<'a, Block, Client>,
|
||||
pub persisted_validation_data: PersistedValidationData<PHash, PBlockNumber>,
|
||||
}
|
||||
|
||||
/// An extension for the Pezcumulus test client to init a block builder.
|
||||
pub trait InitBlockBuilder {
|
||||
/// Init a specific block builder that works for the test runtime.
|
||||
///
|
||||
/// This will automatically create and push the inherents for you to make the block
|
||||
/// valid for the test runtime.
|
||||
///
|
||||
/// You can use the relay chain state sproof builder to arrange required relay chain state or
|
||||
/// just use a default one. The relay chain slot in the storage proof
|
||||
/// will be adjusted to align with the teyrchain slot to pass validation.
|
||||
///
|
||||
/// Returns the block builder and validation data for further usage.
|
||||
fn init_block_builder(
|
||||
&self,
|
||||
validation_data: Option<PersistedValidationData<PHash, PBlockNumber>>,
|
||||
relay_sproof_builder: RelayStateSproofBuilder,
|
||||
) -> BlockBuilderAndSupportData<'_>;
|
||||
|
||||
/// Init a specific block builder at a specific block that works for the test runtime.
|
||||
///
|
||||
/// Same as [`InitBlockBuilder::init_block_builder`] besides that it takes a
|
||||
/// [`type@Hash`] to say which should be the parent block of the block that is being build.
|
||||
fn init_block_builder_at(
|
||||
&self,
|
||||
at: Hash,
|
||||
validation_data: Option<PersistedValidationData<PHash, PBlockNumber>>,
|
||||
relay_sproof_builder: RelayStateSproofBuilder,
|
||||
) -> BlockBuilderAndSupportData<'_>;
|
||||
|
||||
/// Init a specific block builder using the given pre-digests.
|
||||
///
|
||||
/// Same as [`InitBlockBuilder::init_block_builder`] besides that it takes vector of
|
||||
/// [`DigestItem`]'s that are passed as pre-digest to the block builder.
|
||||
fn init_block_builder_with_pre_digests(
|
||||
&self,
|
||||
validation_data: Option<PersistedValidationData<PHash, PBlockNumber>>,
|
||||
relay_sproof_builder: RelayStateSproofBuilder,
|
||||
pre_digests: Vec<DigestItem>,
|
||||
) -> BlockBuilderAndSupportData<'_>;
|
||||
/// Init a specific block builder at a specific block that works for the test runtime.
|
||||
///
|
||||
/// Same as [`InitBlockBuilder::init_block_builder_with_timestamp`] besides that it takes
|
||||
/// `ignored_nodes` that instruct the proof recorder to not record these nodes.
|
||||
fn init_block_builder_with_ignored_nodes(
|
||||
&self,
|
||||
at: Hash,
|
||||
validation_data: Option<PersistedValidationData<PHash, PBlockNumber>>,
|
||||
relay_sproof_builder: RelayStateSproofBuilder,
|
||||
timestamp: u64,
|
||||
ignored_nodes: ProofRecorderIgnoredNodes<Block>,
|
||||
) -> BlockBuilderAndSupportData<'_>;
|
||||
|
||||
/// Init a specific block builder that works for the test runtime.
|
||||
///
|
||||
/// Same as [`InitBlockBuilder::init_block_builder`] besides that it takes a
|
||||
/// [`type@Hash`] to say which should be the parent block of the block that is being build and
|
||||
/// it will use the given `timestamp` as input for the timestamp inherent.
|
||||
fn init_block_builder_with_timestamp(
|
||||
&self,
|
||||
at: Hash,
|
||||
validation_data: Option<PersistedValidationData<PHash, PBlockNumber>>,
|
||||
relay_sproof_builder: RelayStateSproofBuilder,
|
||||
timestamp: u64,
|
||||
) -> BlockBuilderAndSupportData<'_>;
|
||||
}
|
||||
|
||||
fn init_block_builder(
|
||||
client: &Client,
|
||||
at: Hash,
|
||||
validation_data: Option<PersistedValidationData<PHash, PBlockNumber>>,
|
||||
mut relay_sproof_builder: RelayStateSproofBuilder,
|
||||
timestamp: Option<u64>,
|
||||
extra_pre_digests: Option<Vec<DigestItem>>,
|
||||
ignored_nodes: Option<ProofRecorderIgnoredNodes<Block>>,
|
||||
) -> BlockBuilderAndSupportData<'_> {
|
||||
let timestamp = timestamp.unwrap_or_else(|| {
|
||||
let last_timestamp =
|
||||
client.runtime_api().get_last_timestamp(at).expect("Get last timestamp");
|
||||
|
||||
if last_timestamp == 0 {
|
||||
if relay_sproof_builder.current_slot != 0u64 {
|
||||
*relay_sproof_builder.current_slot * 6_000
|
||||
} else {
|
||||
std::time::SystemTime::now()
|
||||
.duration_since(std::time::SystemTime::UNIX_EPOCH)
|
||||
.expect("Time is always after UNIX_EPOCH; qed")
|
||||
.as_millis() as u64
|
||||
}
|
||||
} else {
|
||||
last_timestamp + client.runtime_api().slot_duration(at).unwrap().as_millis()
|
||||
}
|
||||
});
|
||||
|
||||
let slot: Slot =
|
||||
(timestamp / client.runtime_api().slot_duration(at).unwrap().as_millis()).into();
|
||||
|
||||
if relay_sproof_builder.current_slot == 0u64 {
|
||||
relay_sproof_builder.current_slot = (timestamp / 6_000).into();
|
||||
}
|
||||
|
||||
let pre_digests = Digest {
|
||||
logs: extra_pre_digests
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.chain(std::iter::once(DigestItem::PreRuntime(
|
||||
pezsp_consensus_aura::AURA_ENGINE_ID,
|
||||
slot.encode(),
|
||||
)))
|
||||
.collect::<Vec<_>>(),
|
||||
};
|
||||
|
||||
let mut block_builder = BlockBuilderBuilder::new(client)
|
||||
.on_parent_block(at)
|
||||
.fetch_parent_block_number(client)
|
||||
.unwrap()
|
||||
.with_proof_recorder(Some(ProofRecorder::<Block>::with_ignored_nodes(
|
||||
ignored_nodes.unwrap_or_default(),
|
||||
)))
|
||||
.with_inherent_digests(pre_digests)
|
||||
.build()
|
||||
.expect("Creates new block builder for test runtime");
|
||||
|
||||
let mut inherent_data = pezsp_inherents::InherentData::new();
|
||||
|
||||
inherent_data
|
||||
.put_data(pezsp_timestamp::INHERENT_IDENTIFIER, ×tamp)
|
||||
.expect("Put timestamp failed");
|
||||
|
||||
let (relay_parent_storage_root, relay_chain_state) =
|
||||
relay_sproof_builder.into_state_root_and_proof();
|
||||
|
||||
let mut validation_data = validation_data.unwrap_or_default();
|
||||
validation_data.relay_parent_storage_root = relay_parent_storage_root;
|
||||
|
||||
inherent_data
|
||||
.put_data(
|
||||
INHERENT_IDENTIFIER,
|
||||
&TeyrchainInherentData {
|
||||
validation_data: validation_data.clone(),
|
||||
relay_chain_state,
|
||||
downward_messages: Default::default(),
|
||||
horizontal_messages: Default::default(),
|
||||
relay_parent_descendants: Default::default(),
|
||||
collator_peer_id: None,
|
||||
},
|
||||
)
|
||||
.expect("Put validation function params failed");
|
||||
|
||||
let inherents = block_builder.create_inherents(inherent_data).expect("Creates inherents");
|
||||
|
||||
inherents
|
||||
.into_iter()
|
||||
.for_each(|ext| block_builder.push(ext).expect("Pushes inherent"));
|
||||
|
||||
BlockBuilderAndSupportData { block_builder, persisted_validation_data: validation_data }
|
||||
}
|
||||
|
||||
impl InitBlockBuilder for Client {
|
||||
fn init_block_builder(
|
||||
&self,
|
||||
validation_data: Option<PersistedValidationData<PHash, PBlockNumber>>,
|
||||
relay_sproof_builder: RelayStateSproofBuilder,
|
||||
) -> BlockBuilderAndSupportData<'_> {
|
||||
let chain_info = self.chain_info();
|
||||
self.init_block_builder_at(chain_info.best_hash, validation_data, relay_sproof_builder)
|
||||
}
|
||||
|
||||
fn init_block_builder_with_pre_digests(
|
||||
&self,
|
||||
validation_data: Option<PersistedValidationData<PHash, PBlockNumber>>,
|
||||
relay_sproof_builder: RelayStateSproofBuilder,
|
||||
pre_digests: Vec<DigestItem>,
|
||||
) -> BlockBuilderAndSupportData<'_> {
|
||||
let chain_info = self.chain_info();
|
||||
init_block_builder(
|
||||
self,
|
||||
chain_info.best_hash,
|
||||
validation_data,
|
||||
relay_sproof_builder,
|
||||
None,
|
||||
Some(pre_digests),
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
fn init_block_builder_at(
|
||||
&self,
|
||||
at: Hash,
|
||||
validation_data: Option<PersistedValidationData<PHash, PBlockNumber>>,
|
||||
relay_sproof_builder: RelayStateSproofBuilder,
|
||||
) -> BlockBuilderAndSupportData<'_> {
|
||||
init_block_builder(self, at, validation_data, relay_sproof_builder, None, None, None)
|
||||
}
|
||||
|
||||
fn init_block_builder_with_ignored_nodes(
|
||||
&self,
|
||||
at: Hash,
|
||||
validation_data: Option<PersistedValidationData<PHash, PBlockNumber>>,
|
||||
relay_sproof_builder: RelayStateSproofBuilder,
|
||||
timestamp: u64,
|
||||
ignored_nodes: ProofRecorderIgnoredNodes<Block>,
|
||||
) -> BlockBuilderAndSupportData<'_> {
|
||||
init_block_builder(
|
||||
self,
|
||||
at,
|
||||
validation_data,
|
||||
relay_sproof_builder,
|
||||
Some(timestamp),
|
||||
None,
|
||||
Some(ignored_nodes),
|
||||
)
|
||||
}
|
||||
|
||||
fn init_block_builder_with_timestamp(
|
||||
&self,
|
||||
at: Hash,
|
||||
validation_data: Option<PersistedValidationData<PHash, PBlockNumber>>,
|
||||
relay_sproof_builder: RelayStateSproofBuilder,
|
||||
timestamp: u64,
|
||||
) -> BlockBuilderAndSupportData<'_> {
|
||||
init_block_builder(
|
||||
self,
|
||||
at,
|
||||
validation_data,
|
||||
relay_sproof_builder,
|
||||
Some(timestamp),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Extension trait for the [`BlockBuilder`](pezsc_block_builder::BlockBuilder) to build directly a
|
||||
/// [`TeyrchainBlockData`].
|
||||
pub trait BuildTeyrchainBlockData {
|
||||
/// Directly build the [`TeyrchainBlockData`] from the block that comes out of the block
|
||||
/// builder.
|
||||
fn build_teyrchain_block(self, parent_state_root: Hash) -> TeyrchainBlockData<Block>;
|
||||
}
|
||||
|
||||
impl<'a> BuildTeyrchainBlockData for pezsc_block_builder::BlockBuilder<'a, Block, Client> {
|
||||
fn build_teyrchain_block(self, parent_state_root: Hash) -> TeyrchainBlockData<Block> {
|
||||
let built_block = self.build().expect("Builds the block");
|
||||
|
||||
let storage_proof = built_block
|
||||
.proof
|
||||
.expect("We enabled proof recording before.")
|
||||
.into_compact_proof::<<Header as HeaderT>::Hashing>(parent_state_root)
|
||||
.expect("Creates the compact proof");
|
||||
|
||||
TeyrchainBlockData::new(vec![built_block.block], storage_proof)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// This file is part of Pezcumulus.
|
||||
|
||||
// Pezcumulus is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Pezcumulus is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Pezcumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! A Pezcumulus test client.
|
||||
|
||||
mod block_builder;
|
||||
pub use block_builder::*;
|
||||
use codec::{Decode, Encode};
|
||||
pub use cumulus_test_runtime as runtime;
|
||||
use cumulus_test_runtime::AuraId;
|
||||
pub use pezkuwi_teyrchain_primitives::primitives::{
|
||||
BlockData, HeadData, ValidationParams, ValidationResult,
|
||||
};
|
||||
use runtime::{
|
||||
Balance, Block, BlockHashCount, Runtime, RuntimeCall, Signature, SignedPayload, TxExtension,
|
||||
UncheckedExtrinsic, VERSION,
|
||||
};
|
||||
use pezsc_consensus_aura::{
|
||||
find_pre_digest,
|
||||
standalone::{seal, slot_author},
|
||||
};
|
||||
pub use pezsc_executor::error::Result as ExecutorResult;
|
||||
use pezsc_executor::HeapAllocStrategy;
|
||||
use pezsc_executor_common::runtime_blob::RuntimeBlob;
|
||||
use pezsp_api::ProvideRuntimeApi;
|
||||
use pezsp_application_crypto::AppCrypto;
|
||||
use pezsp_blockchain::HeaderBackend;
|
||||
use pezsp_consensus_aura::AuraApi;
|
||||
use pezsp_core::Pair;
|
||||
use pezsp_io::TestExternalities;
|
||||
use pezsp_keystore::testing::MemoryKeystore;
|
||||
use pezsp_runtime::{generic::Era, traits::Header, BuildStorage, MultiAddress, SaturatedConversion};
|
||||
use std::sync::Arc;
|
||||
pub use bizinikiwi_test_client::*;
|
||||
|
||||
pub type TeyrchainBlockData = cumulus_primitives_core::TeyrchainBlockData<Block>;
|
||||
|
||||
/// Test client database backend.
|
||||
pub type Backend = bizinikiwi_test_client::Backend<Block>;
|
||||
|
||||
/// Test client executor.
|
||||
pub type Executor = client::LocalCallExecutor<
|
||||
Block,
|
||||
Backend,
|
||||
WasmExecutor<(
|
||||
pezsp_io::BizinikiwiHostFunctions,
|
||||
cumulus_primitives_proof_size_hostfunction::storage_proof_size::HostFunctions,
|
||||
)>,
|
||||
>;
|
||||
|
||||
/// Test client builder for Pezcumulus
|
||||
pub type TestClientBuilder =
|
||||
bizinikiwi_test_client::TestClientBuilder<Block, Executor, Backend, GenesisParameters>;
|
||||
|
||||
/// LongestChain type for the test runtime/client.
|
||||
pub type LongestChain = pezsc_consensus::LongestChain<Backend, Block>;
|
||||
|
||||
/// Test client type with `LocalExecutor` and generic Backend.
|
||||
pub type Client = client::Client<Backend, Executor, Block, runtime::RuntimeApi>;
|
||||
|
||||
/// Parameters of test-client builder with test-runtime.
|
||||
#[derive(Default)]
|
||||
pub struct GenesisParameters {
|
||||
pub endowed_accounts: Vec<cumulus_test_runtime::AccountId>,
|
||||
pub wasm: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl bizinikiwi_test_client::GenesisInit for GenesisParameters {
|
||||
fn genesis_storage(&self) -> Storage {
|
||||
cumulus_test_service::chain_spec::get_chain_spec_with_extra_endowed(
|
||||
None,
|
||||
self.endowed_accounts.clone(),
|
||||
self.wasm.as_deref().unwrap_or_else(|| {
|
||||
cumulus_test_runtime::WASM_BINARY.expect("WASM binary not compiled!")
|
||||
}),
|
||||
)
|
||||
.build_storage()
|
||||
.expect("Builds test runtime genesis storage")
|
||||
}
|
||||
}
|
||||
|
||||
/// A `test-runtime` extensions to [`TestClientBuilder`].
|
||||
pub trait TestClientBuilderExt: Sized {
|
||||
/// Build the test client.
|
||||
fn build(self) -> Client {
|
||||
self.build_with_longest_chain().0
|
||||
}
|
||||
|
||||
/// Build the test client and longest chain selector.
|
||||
fn build_with_longest_chain(self) -> (Client, LongestChain);
|
||||
}
|
||||
|
||||
impl TestClientBuilderExt for TestClientBuilder {
|
||||
fn build_with_longest_chain(self) -> (Client, LongestChain) {
|
||||
self.build_with_native_executor(None)
|
||||
}
|
||||
}
|
||||
|
||||
/// A `TestClientBuilder` with default backend and executor.
|
||||
pub trait DefaultTestClientBuilderExt: Sized {
|
||||
/// Create new `TestClientBuilder`
|
||||
fn new() -> Self;
|
||||
}
|
||||
|
||||
impl DefaultTestClientBuilderExt for TestClientBuilder {
|
||||
fn new() -> Self {
|
||||
Self::with_default_backend()
|
||||
}
|
||||
}
|
||||
|
||||
/// Create an unsigned extrinsic from a runtime call.
|
||||
pub fn generate_unsigned(function: impl Into<RuntimeCall>) -> UncheckedExtrinsic {
|
||||
UncheckedExtrinsic::new_bare(function.into())
|
||||
}
|
||||
|
||||
/// Create a signed extrinsic from a runtime call and sign
|
||||
/// with the given key pair.
|
||||
pub fn generate_extrinsic_with_pair(
|
||||
client: &Client,
|
||||
origin: pezsp_core::sr25519::Pair,
|
||||
function: impl Into<RuntimeCall>,
|
||||
nonce: Option<u32>,
|
||||
) -> UncheckedExtrinsic {
|
||||
let current_block_hash = client.info().best_hash;
|
||||
let current_block = client.info().best_number.saturated_into();
|
||||
let genesis_block = client.hash(0).unwrap().unwrap();
|
||||
let nonce = nonce.unwrap_or_default();
|
||||
let period =
|
||||
BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2) as u64;
|
||||
let tip = 0;
|
||||
let tx_ext: TxExtension = (
|
||||
pezframe_system::AuthorizeCall::<Runtime>::new(),
|
||||
pezframe_system::CheckNonZeroSender::<Runtime>::new(),
|
||||
pezframe_system::CheckSpecVersion::<Runtime>::new(),
|
||||
pezframe_system::CheckGenesis::<Runtime>::new(),
|
||||
pezframe_system::CheckEra::<Runtime>::from(Era::mortal(period, current_block)),
|
||||
pezframe_system::CheckNonce::<Runtime>::from(nonce),
|
||||
pezframe_system::CheckWeight::<Runtime>::new(),
|
||||
pezpallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
|
||||
)
|
||||
.into();
|
||||
|
||||
let function = function.into();
|
||||
|
||||
let raw_payload = SignedPayload::from_raw(
|
||||
function.clone(),
|
||||
tx_ext.clone(),
|
||||
((), (), VERSION.spec_version, genesis_block, current_block_hash, (), (), ()),
|
||||
);
|
||||
let signature = raw_payload.using_encoded(|e| origin.sign(e));
|
||||
|
||||
UncheckedExtrinsic::new_signed(
|
||||
function,
|
||||
MultiAddress::Id(origin.public().into()),
|
||||
Signature::Sr25519(signature),
|
||||
tx_ext,
|
||||
)
|
||||
}
|
||||
|
||||
/// Generate an extrinsic from the provided function call, origin and [`Client`].
|
||||
pub fn generate_extrinsic(
|
||||
client: &Client,
|
||||
origin: pezsp_keyring::Sr25519Keyring,
|
||||
function: impl Into<RuntimeCall>,
|
||||
) -> UncheckedExtrinsic {
|
||||
generate_extrinsic_with_pair(client, origin.into(), function, None)
|
||||
}
|
||||
|
||||
/// Transfer some token from one account to another using a provided test [`Client`].
|
||||
pub fn transfer(
|
||||
client: &Client,
|
||||
origin: pezsp_keyring::Sr25519Keyring,
|
||||
dest: pezsp_keyring::Sr25519Keyring,
|
||||
value: Balance,
|
||||
) -> UncheckedExtrinsic {
|
||||
let function = RuntimeCall::Balances(pezpallet_balances::Call::transfer_allow_death {
|
||||
dest: MultiAddress::Id(dest.public().into()),
|
||||
value,
|
||||
});
|
||||
|
||||
generate_extrinsic(client, origin, function)
|
||||
}
|
||||
|
||||
/// Call `validate_block` in the given `wasm_blob`.
|
||||
pub fn validate_block(
|
||||
validation_params: ValidationParams,
|
||||
wasm_blob: &[u8],
|
||||
) -> ExecutorResult<ValidationResult> {
|
||||
let mut ext = TestExternalities::default();
|
||||
let mut ext_ext = ext.ext();
|
||||
|
||||
let heap_pages = HeapAllocStrategy::Static { extra_pages: 2048 };
|
||||
let executor = WasmExecutor::<(
|
||||
pezsp_io::BizinikiwiHostFunctions,
|
||||
cumulus_primitives_proof_size_hostfunction::storage_proof_size::HostFunctions,
|
||||
)>::builder()
|
||||
.with_execution_method(WasmExecutionMethod::default())
|
||||
.with_max_runtime_instances(1)
|
||||
.with_runtime_cache_size(2)
|
||||
.with_onchain_heap_alloc_strategy(heap_pages)
|
||||
.with_offchain_heap_alloc_strategy(heap_pages)
|
||||
.build();
|
||||
|
||||
executor
|
||||
.uncached_call(
|
||||
RuntimeBlob::uncompress_if_needed(wasm_blob).expect("RuntimeBlob uncompress & parse"),
|
||||
&mut ext_ext,
|
||||
false,
|
||||
"validate_block",
|
||||
&validation_params.encode(),
|
||||
)
|
||||
.map(|v| ValidationResult::decode(&mut &v[..]).expect("Decode `ValidationResult`."))
|
||||
}
|
||||
|
||||
fn get_keystore() -> pezsp_keystore::KeystorePtr {
|
||||
let keystore = MemoryKeystore::new();
|
||||
pezsp_keyring::Sr25519Keyring::iter().for_each(|key| {
|
||||
keystore
|
||||
.sr25519_generate_new(
|
||||
pezsp_consensus_aura::sr25519::AuthorityPair::ID,
|
||||
Some(&key.to_seed()),
|
||||
)
|
||||
.expect("Key should be created");
|
||||
});
|
||||
Arc::new(keystore)
|
||||
}
|
||||
|
||||
/// Seals the given block with an AURA seal.
|
||||
///
|
||||
/// Assumes that the authorities of the test runtime are present in the keyring.
|
||||
pub fn seal_block(mut block: Block, client: &Client) -> Block {
|
||||
let teyrchain_slot =
|
||||
find_pre_digest::<Block, <AuraId as AppCrypto>::Signature>(&block.header).unwrap();
|
||||
let parent_hash = block.header.parent_hash;
|
||||
let authorities = client.runtime_api().authorities(parent_hash).unwrap();
|
||||
let expected_author = slot_author::<<AuraId as AppCrypto>::Pair>(teyrchain_slot, &authorities)
|
||||
.expect("Should be able to find author");
|
||||
|
||||
let keystore = get_keystore();
|
||||
let seal_digest = seal::<_, pezsp_consensus_aura::sr25519::AuthorityPair>(
|
||||
&block.header.hash(),
|
||||
expected_author,
|
||||
&keystore,
|
||||
)
|
||||
.expect("Should be able to create seal");
|
||||
block.header.digest_mut().push(seal_digest);
|
||||
|
||||
block
|
||||
}
|
||||
Reference in New Issue
Block a user