mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 21:37:56 +00:00
Uniformize tests (#220)
* Initial commit Forked at:56753b7717Parent branch: origin/master * Copy runtime module from rococo Forked at:56753b7717Parent branch: origin/master * Also copy dependencies pallets and primitives Forked at:56753b7717Parent branch: origin/master * WIP Forked at:56753b7717Parent branch: origin/master * WIP Forked at:56753b7717Parent branch: origin/master * test-service * Move integration test * CLEANUP Forked at:56753b7717Parent branch: origin/master * Not sure what went wrong... * WIP Forked at:56753b7717Parent branch: origin/master * WIP Forked at:56753b7717Parent branch: origin/master * CLEANUP Forked at:56753b7717Parent branch: origin/master * fmt * CLEANUP Forked at:56753b7717Parent branch: origin/master * CLEANUP Forked at:56753b7717Parent branch: origin/master * Remove pallet contracts (not used) * Remove pallet parachain-info and token-dealer (not used) * Sort dependencies alphabetically * CLEANUP Forked at:56753b7717Parent branch: origin/master * CumulusTestNode for testing * Speed up block generation * Fix improper shutdown * rustfmt * runtime: replace const by storage * Fix for previous commit * Remove some generics * Move generate_genesis_state to cumulus-primitives * fmt * Remove message_example * fixup! Remove message_example * WIP Forked at:56753b7717Parent branch: origin/master * Half the solution to previous commit :( * Revert "Fix for previous commit" This reverts commit 60010bab6797487093ac8c790b3a536f7ca0895b. * Revert "runtime: replace const by storage" This reverts commit c64b3a46f0325a98922015e0cbf3570e2e431774. Not working for some reason... * Use helper Forked at:56753b7717Parent branch: origin/master * WIP Forked at:56753b7717Parent branch: origin/master * Remove test-primitives * Revert "Half the solution to previous commit :(" This reverts commit 9a8f89f9f06252198e6405057043c6b313f1aea4. * Revert "Revert "Half the solution to previous commit :("" This reverts commit 6a93f0f09d74ccdc3738dd78a777c483427c03ce. * Test with some extra extrinsics * WIP Forked at:56753b7717Parent branch: origin/master * CLEANUP Forked at:56753b7717Parent branch: origin/master * WIP Forked at:56753b7717Parent branch: origin/master * WIP Forked at:56753b7717Parent branch: origin/master * WIP Forked at:56753b7717Parent branch: origin/master * WIP Forked at:56753b7717Parent branch: origin/master * WIP Forked at:56753b7717Parent branch: origin/master * WIP Forked at:56753b7717Parent branch: origin/master * WIP Forked at:56753b7717Parent branch: origin/master * CLEANUP Forked at:56753b7717Parent branch: origin/master * Remove message broker
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Cumulus.
|
||||
|
||||
// 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.
|
||||
|
||||
// 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::Client;
|
||||
use cumulus_primitives::{
|
||||
inherents::VALIDATION_FUNCTION_PARAMS_IDENTIFIER,
|
||||
validation_function_params::ValidationFunctionParams,
|
||||
};
|
||||
use runtime::GetLastTimestamp;
|
||||
use sc_block_builder::BlockBuilderApi;
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
use sp_blockchain::HeaderBackend;
|
||||
use sp_core::ExecutionContext;
|
||||
use sp_runtime::generic::BlockId;
|
||||
|
||||
/// Generate the inherents to a block so you don't have to.
|
||||
pub fn generate_block_inherents(client: &Client) -> Vec<runtime::UncheckedExtrinsic> {
|
||||
let mut inherent_data = sp_consensus::InherentData::new();
|
||||
let block_id = BlockId::Hash(client.info().best_hash);
|
||||
let last_timestamp = client
|
||||
.runtime_api()
|
||||
.get_last_timestamp(&block_id)
|
||||
.expect("Get last timestamp");
|
||||
let timestamp = last_timestamp + runtime::MinimumPeriod::get();
|
||||
|
||||
inherent_data
|
||||
.put_data(sp_timestamp::INHERENT_IDENTIFIER, ×tamp)
|
||||
.expect("Put timestamp failed");
|
||||
inherent_data
|
||||
.put_data(
|
||||
VALIDATION_FUNCTION_PARAMS_IDENTIFIER,
|
||||
&ValidationFunctionParams::default(),
|
||||
)
|
||||
.expect("Put validation function params failed");
|
||||
|
||||
client
|
||||
.runtime_api()
|
||||
.inherent_extrinsics_with_context(
|
||||
&BlockId::number(0),
|
||||
ExecutionContext::BlockConstruction,
|
||||
inherent_data,
|
||||
)
|
||||
.expect("Get inherents failed")
|
||||
}
|
||||
@@ -16,15 +16,25 @@
|
||||
|
||||
//! A Cumulus test client.
|
||||
|
||||
mod block_builder;
|
||||
|
||||
pub use block_builder::*;
|
||||
|
||||
use codec::Encode;
|
||||
pub use runtime;
|
||||
use runtime::{
|
||||
genesismap::{additional_storage_with_genesis, GenesisConfig},
|
||||
Block,
|
||||
Balance, Block, BlockHashCount, Call, GenesisConfig, Runtime, Signature, SignedExtra,
|
||||
SignedPayload, UncheckedExtrinsic, VERSION,
|
||||
};
|
||||
use sc_service::client;
|
||||
use sp_core::{sr25519, storage::Storage, ChangesTrieConfiguration};
|
||||
use sp_keyring::{AccountKeyring, Sr25519Keyring};
|
||||
use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT};
|
||||
use sp_blockchain::HeaderBackend;
|
||||
use sp_core::{map, storage::Storage, twox_128, ChangesTrieConfiguration};
|
||||
use sp_runtime::{
|
||||
generic::Era,
|
||||
traits::{Block as BlockT, Hash as HashT, Header as HeaderT},
|
||||
BuildStorage, SaturatedConversion,
|
||||
};
|
||||
use std::collections::BTreeMap;
|
||||
pub use test_client::*;
|
||||
|
||||
mod local_executor {
|
||||
@@ -63,14 +73,12 @@ pub struct GenesisParameters {
|
||||
|
||||
impl test_client::GenesisInit for GenesisParameters {
|
||||
fn genesis_storage(&self) -> Storage {
|
||||
use codec::Encode;
|
||||
|
||||
let changes_trie_config: Option<ChangesTrieConfiguration> = if self.support_changes_trie {
|
||||
Some(sp_test_primitives::changes_trie_config())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let mut storage = genesis_config(changes_trie_config).genesis_map();
|
||||
let mut storage = genesis_config(changes_trie_config).build_storage().unwrap();
|
||||
|
||||
let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
|
||||
let state_root =
|
||||
@@ -128,20 +136,68 @@ impl DefaultTestClientBuilderExt for TestClientBuilder {
|
||||
}
|
||||
|
||||
fn genesis_config(changes_trie_config: Option<ChangesTrieConfiguration>) -> GenesisConfig {
|
||||
GenesisConfig::new(
|
||||
changes_trie_config,
|
||||
vec![
|
||||
sr25519::Public::from(Sr25519Keyring::Alice).into(),
|
||||
sr25519::Public::from(Sr25519Keyring::Bob).into(),
|
||||
sr25519::Public::from(Sr25519Keyring::Charlie).into(),
|
||||
],
|
||||
vec![
|
||||
AccountKeyring::Alice.into(),
|
||||
AccountKeyring::Bob.into(),
|
||||
AccountKeyring::Charlie.into(),
|
||||
],
|
||||
1000,
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
cumulus_test_service::local_testnet_genesis(changes_trie_config)
|
||||
}
|
||||
|
||||
fn additional_storage_with_genesis(genesis_block: &Block) -> BTreeMap<Vec<u8>, Vec<u8>> {
|
||||
map![
|
||||
twox_128(&b"latest"[..]).to_vec() => genesis_block.hash().as_fixed_bytes().to_vec()
|
||||
]
|
||||
}
|
||||
|
||||
/// Generate an extrinsic from the provided function call, origin and [`Client`].
|
||||
pub fn generate_extrinsic(
|
||||
client: &Client,
|
||||
origin: sp_keyring::AccountKeyring,
|
||||
function: Call,
|
||||
) -> 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 = 0;
|
||||
let period = BlockHashCount::get()
|
||||
.checked_next_power_of_two()
|
||||
.map(|c| c / 2)
|
||||
.unwrap_or(2) as u64;
|
||||
let tip = 0;
|
||||
let extra: SignedExtra = (
|
||||
frame_system::CheckSpecVersion::<Runtime>::new(),
|
||||
frame_system::CheckGenesis::<Runtime>::new(),
|
||||
frame_system::CheckEra::<Runtime>::from(Era::mortal(period, current_block)),
|
||||
frame_system::CheckNonce::<Runtime>::from(nonce),
|
||||
frame_system::CheckWeight::<Runtime>::new(),
|
||||
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
|
||||
);
|
||||
let raw_payload = SignedPayload::from_raw(
|
||||
function.clone(),
|
||||
extra.clone(),
|
||||
(
|
||||
VERSION.spec_version,
|
||||
genesis_block,
|
||||
current_block_hash,
|
||||
(),
|
||||
(),
|
||||
(),
|
||||
),
|
||||
);
|
||||
let signature = raw_payload.using_encoded(|e| origin.sign(e));
|
||||
|
||||
UncheckedExtrinsic::new_signed(
|
||||
function.clone(),
|
||||
origin.public().into(),
|
||||
Signature::Sr25519(signature.clone()),
|
||||
extra.clone(),
|
||||
)
|
||||
}
|
||||
|
||||
/// Transfer some token from one account to another using a provided test [`Client`].
|
||||
pub fn transfer(
|
||||
client: &Client,
|
||||
origin: sp_keyring::AccountKeyring,
|
||||
dest: sp_keyring::AccountKeyring,
|
||||
value: Balance,
|
||||
) -> UncheckedExtrinsic {
|
||||
let function = Call::Balances(pallet_balances::Call::transfer(dest.public().into(), value));
|
||||
|
||||
generate_extrinsic(client, origin, function)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user