mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 02:07:56 +00:00
Adds support for checking the timestamp inherent while validating a block (#494)
* Adds support for checking the timestamp inherent while validating a block This adds support for checking the timestamp inherent while validating a block. This will use the relay chain slot number * relay chain slot duration to calculate a timestamp. This timestamp is used to check the timestamp in the timestamp inherent. * Update polkadot-parachains/rococo-runtime/src/lib.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> * Update polkadot-parachains/statemine-runtime/src/lib.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> * Update primitives/timestamp/src/lib.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Fix warnings Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
This commit is contained in:
+41
-6
@@ -1,36 +1,43 @@
|
||||
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
// This file is part of Cumulus.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// Cumulus 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.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// Cumulus 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 Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! A Polkadot test client.
|
||||
//! A Cumulus test client.
|
||||
|
||||
mod block_builder;
|
||||
use codec::Encode;
|
||||
use codec::{Encode, Decode};
|
||||
use runtime::{
|
||||
Balance, Block, BlockHashCount, Call, GenesisConfig, Runtime, Signature, SignedExtra,
|
||||
SignedPayload, UncheckedExtrinsic, VERSION,
|
||||
};
|
||||
use sc_executor::{sp_wasm_interface::HostFunctions, WasmExecutionMethod, WasmExecutor};
|
||||
use sc_executor_common::runtime_blob::RuntimeBlob;
|
||||
use sc_service::client;
|
||||
use sp_blockchain::HeaderBackend;
|
||||
use sp_core::storage::Storage;
|
||||
use sp_io::TestExternalities;
|
||||
use sp_runtime::{generic::Era, BuildStorage, SaturatedConversion};
|
||||
|
||||
pub use block_builder::*;
|
||||
pub use cumulus_test_runtime as runtime;
|
||||
pub use polkadot_parachain::primitives::{BlockData, HeadData, ValidationParams, ValidationResult};
|
||||
pub use sc_executor::error::Result as ExecutorResult;
|
||||
pub use substrate_test_client::*;
|
||||
|
||||
pub type ParachainBlockData = cumulus_primitives_core::ParachainBlockData<Block>;
|
||||
|
||||
mod local_executor {
|
||||
use substrate_test_client::sc_executor::native_executor_instance;
|
||||
native_executor_instance!(
|
||||
@@ -159,3 +166,31 @@ pub fn transfer(
|
||||
|
||||
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 executor = WasmExecutor::new(
|
||||
WasmExecutionMethod::Interpreted,
|
||||
Some(1024),
|
||||
sp_io::SubstrateHostFunctions::host_functions(),
|
||||
1,
|
||||
None,
|
||||
);
|
||||
|
||||
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`."))
|
||||
.map_err(|err| err.into())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user