mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 05:11:09 +00:00
substrate-test-runtime migrated to "pure" frame runtime (#13737)
* substrate-test-runtime migrated to pure-frame based * test block builder: helpers added * simple renaming * basic_authorship test adjusted * block_building storage_proof test adjusted * babe: tests: should_panic expected added * babe: tests adjusted ConsensusLog::NextEpochData is now added by pallet_babe as pallet_babe::SameAuthoritiesForever trigger is used in runtime config. * beefy: tests adjusted test-substrate-runtime is now using frame::executive to finalize the block. during finalization the digests stored during block execution are checked against header digests: https://github.com/paritytech/substrate/blob/91bb2d29ca905599098a5b35eaf24867c4fbd60a/frame/executive/src/lib.rs#L585-L591 It makes impossible to directly manipulate header's digets, w/o depositing logs into system pallet storage `Digest<T: Config>`. Instead of this dedicated extrinsic allowing to store logs items (MmrRoot / AuthoritiesChange) is used. * grandpa: tests adjusted test-substrate-runtime is now using frame::executive to finalize the block. during finalization the digest logs stored during block execution are checked against header digest logs: https://github.com/paritytech/substrate/blob/91bb2d29ca905599098a5b35eaf24867c4fbd60a/frame/executive/src/lib.rs#L585-L591 It makes impossible to directly manipulate header's digets, w/o depositing logs into system pallet storage `Digest<T: Config>`. Instead of this dedicated extrinsic allowing to store logs items (ScheduledChange / ForcedChange and DigestItem::Other) is used. * network:bitswap: test adjusted The size of unchecked extrinsic was increased. The pattern used in test will be placed at the end of scale-encoded buffer. * runtime apis versions adjusted * storage keys used in runtime adjusted * wasm vs native tests removed * rpc tests: adjusted Transfer transaction processing was slightly improved, test was adjusted. * tests: sizes adjusted Runtime extrinsic size was increased. Size of data read during block execution was also increased due to usage of new pallets in runtime. Sizes were adjusted in tests. * cargo.lock update cargo update -p substrate-test-runtime -p substrate-test-runtime-client * warnings fixed * builders cleanup: includes / std * extrinsic validation cleanup * txpool: benches performance fixed * fmt * spelling * Apply suggestions from code review Co-authored-by: Davide Galassi <davxy@datawok.net> * Apply code review suggestions * Apply code review suggestions * get rid of 1063 const * renaming: UncheckedExtrinsic -> Extrinsic * test-utils-runtime: further step to pure-frame * basic-authorship: tests OK * CheckSubstrateCall added + tests fixes * test::Transfer call removed * priority / propagate / no sudo+root-testing * fixing warnings + format * cleanup: build2/nonce + format * final tests fixes all tests are passing * logs/comments removal * should_not_accept_old_signatures test removed * make txpool benches work again * Cargo.lock reset * format * sudo hack removed * txpool benches fix+cleanup * .gitignore reverted * rebase fixing + unsigned cleanup * Cargo.toml/Cargo.lock cleanup * force-debug feature removed * mmr tests fixed * make cargo-clippy happy * network sync test uses unsigned extrinsic * cleanup * ".git/.scripts/commands/fmt/fmt.sh" * push_storage_change signed call remove * GenesisConfig cleanup * fix * fix * GenesisConfig simplified * storage_keys_works: reworked * storage_keys_works: expected keys in vec * storage keys list moved to substrate-test-runtime * substrate-test: some sanity tests + GenesisConfigBuilder rework * Apply suggestions from code review Co-authored-by: Bastian Köcher <git@kchr.de> * Apply suggestions from code review * Review suggestions * fix * fix * beefy: generate_blocks_and_sync block_num sync with actaul value * Apply suggestions from code review Co-authored-by: Davide Galassi <davxy@datawok.net> * Update test-utils/runtime/src/genesismap.rs Co-authored-by: Davide Galassi <davxy@datawok.net> * cargo update -p sc-rpc -p sc-transaction-pool * Review suggestions * fix * doc added * slot_duration adjusted for Babe::slot_duration * small doc fixes * array_bytes::hex used instead of hex * tiny -> medium name fix * Apply suggestions from code review Co-authored-by: Sebastian Kunert <skunert49@gmail.com> * TransferData::try_from_unchecked_extrinsic -> try_from * Update Cargo.lock --------- Co-authored-by: parity-processbot <> Co-authored-by: Davide Galassi <davxy@datawok.net> Co-authored-by: Bastian Köcher <git@kchr.de> Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
This commit is contained in:
committed by
GitHub
parent
3a90728de0
commit
6a295e7c28
@@ -17,75 +17,119 @@
|
||||
|
||||
//! Tool for creating the genesis block.
|
||||
|
||||
use super::{system, wasm_binary_unwrap, AccountId, AuthorityId, Runtime};
|
||||
use codec::{Encode, Joiner, KeyedVec};
|
||||
use frame_support::traits::GenesisBuild;
|
||||
use super::{
|
||||
currency, substrate_test_pallet, wasm_binary_unwrap, AccountId, AuthorityId, Balance,
|
||||
GenesisConfig,
|
||||
};
|
||||
use codec::Encode;
|
||||
use sc_service::construct_genesis_block;
|
||||
use sp_core::{
|
||||
map,
|
||||
sr25519,
|
||||
storage::{well_known_keys, StateVersion, Storage},
|
||||
Pair,
|
||||
};
|
||||
use sp_keyring::{AccountKeyring, Sr25519Keyring};
|
||||
use sp_runtime::{
|
||||
traits::{Block as BlockT, Hash as HashT, Header as HeaderT},
|
||||
BuildStorage,
|
||||
};
|
||||
use sp_io::hashing::{blake2_256, twox_128};
|
||||
use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
/// Configuration of a general Substrate test genesis block.
|
||||
pub struct GenesisConfig {
|
||||
/// Builder for generating storage from substrate-test-runtime genesis config. Default storage can
|
||||
/// be extended with additional key-value pairs.
|
||||
pub struct GenesisStorageBuilder {
|
||||
authorities: Vec<AuthorityId>,
|
||||
balances: Vec<(AccountId, u64)>,
|
||||
heap_pages_override: Option<u64>,
|
||||
/// Additional storage key pairs that will be added to the genesis map.
|
||||
extra_storage: Storage,
|
||||
wasm_code: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl GenesisConfig {
|
||||
impl Default for GenesisStorageBuilder {
|
||||
/// Creates a builder with default settings for `substrate_test_runtime`.
|
||||
fn default() -> Self {
|
||||
Self::new(
|
||||
vec![
|
||||
sr25519::Public::from(Sr25519Keyring::Alice).into(),
|
||||
sr25519::Public::from(Sr25519Keyring::Bob).into(),
|
||||
sr25519::Public::from(Sr25519Keyring::Charlie).into(),
|
||||
],
|
||||
(0..16_usize)
|
||||
.into_iter()
|
||||
.map(|i| AccountKeyring::numeric(i).public())
|
||||
.chain(vec![
|
||||
AccountKeyring::Alice.into(),
|
||||
AccountKeyring::Bob.into(),
|
||||
AccountKeyring::Charlie.into(),
|
||||
])
|
||||
.collect(),
|
||||
1000 * currency::DOLLARS,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl GenesisStorageBuilder {
|
||||
/// Creates a storage builder for genesis config. `substrage test runtime` `GenesisConfig` is
|
||||
/// initialized with provided `authorities`, `endowed_accounts` with given balance. Key-pairs
|
||||
/// from `extra_storage` will be injected into built storage. `HEAP_PAGES` key and value will
|
||||
/// also be placed into storage.
|
||||
pub fn new(
|
||||
authorities: Vec<AuthorityId>,
|
||||
endowed_accounts: Vec<AccountId>,
|
||||
balance: u64,
|
||||
heap_pages_override: Option<u64>,
|
||||
extra_storage: Storage,
|
||||
balance: Balance,
|
||||
) -> Self {
|
||||
GenesisConfig {
|
||||
GenesisStorageBuilder {
|
||||
authorities,
|
||||
balances: endowed_accounts.into_iter().map(|a| (a, balance)).collect(),
|
||||
heap_pages_override,
|
||||
extra_storage,
|
||||
heap_pages_override: None,
|
||||
extra_storage: Default::default(),
|
||||
wasm_code: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn genesis_map(&self) -> Storage {
|
||||
let wasm_runtime = wasm_binary_unwrap().to_vec();
|
||||
let mut map: BTreeMap<Vec<u8>, Vec<u8>> = self
|
||||
.balances
|
||||
.iter()
|
||||
.map(|&(ref account, balance)| {
|
||||
(account.to_keyed_vec(b"balance:"), vec![].and(&balance))
|
||||
})
|
||||
.map(|(k, v)| (blake2_256(&k[..])[..].to_vec(), v.to_vec()))
|
||||
.chain(
|
||||
vec![
|
||||
(well_known_keys::CODE.into(), wasm_runtime),
|
||||
(
|
||||
well_known_keys::HEAP_PAGES.into(),
|
||||
vec![].and(&(self.heap_pages_override.unwrap_or(16_u64))),
|
||||
),
|
||||
]
|
||||
.into_iter(),
|
||||
)
|
||||
.collect();
|
||||
map.insert(twox_128(&b"sys:auth"[..])[..].to_vec(), self.authorities.encode());
|
||||
// Add the extra storage entries.
|
||||
map.extend(self.extra_storage.top.clone().into_iter());
|
||||
/// Override default wasm code to be placed into GenesisConfig.
|
||||
pub fn with_wasm_code(mut self, wasm_code: &Option<Vec<u8>>) -> Self {
|
||||
self.wasm_code = wasm_code.clone();
|
||||
self
|
||||
}
|
||||
|
||||
// Assimilate the system genesis config.
|
||||
let mut storage =
|
||||
Storage { top: map, children_default: self.extra_storage.children_default.clone() };
|
||||
<system::GenesisConfig as GenesisBuild<Runtime>>::assimilate_storage(
|
||||
&system::GenesisConfig { authorities: self.authorities.clone() },
|
||||
&mut storage,
|
||||
)
|
||||
.expect("Adding `system::GensisConfig` to the genesis");
|
||||
pub fn with_heap_pages(mut self, heap_pages_override: Option<u64>) -> Self {
|
||||
self.heap_pages_override = heap_pages_override;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_extra_storage(mut self, storage: Storage) -> Self {
|
||||
self.extra_storage = storage;
|
||||
self
|
||||
}
|
||||
|
||||
/// Builds the `GenesisConfig` and returns its storage.
|
||||
pub fn build_storage(&mut self) -> Storage {
|
||||
let genesis_config = GenesisConfig {
|
||||
system: frame_system::GenesisConfig {
|
||||
code: self.wasm_code.clone().unwrap_or(wasm_binary_unwrap().to_vec()),
|
||||
},
|
||||
babe: pallet_babe::GenesisConfig {
|
||||
authorities: self.authorities.clone().into_iter().map(|x| (x, 1)).collect(),
|
||||
epoch_config: Some(crate::TEST_RUNTIME_BABE_EPOCH_CONFIGURATION),
|
||||
},
|
||||
substrate_test: substrate_test_pallet::GenesisConfig {
|
||||
authorities: self.authorities.clone(),
|
||||
},
|
||||
balances: pallet_balances::GenesisConfig { balances: self.balances.clone() },
|
||||
};
|
||||
|
||||
let mut storage = genesis_config
|
||||
.build_storage()
|
||||
.expect("Build storage from substrate-test-runtime GenesisConfig");
|
||||
|
||||
storage.top.insert(
|
||||
well_known_keys::HEAP_PAGES.into(),
|
||||
self.heap_pages_override.unwrap_or(16_u64).encode(),
|
||||
);
|
||||
|
||||
storage.top.extend(self.extra_storage.top.clone());
|
||||
storage.children_default.extend(self.extra_storage.children_default.clone());
|
||||
|
||||
storage
|
||||
}
|
||||
@@ -108,12 +152,6 @@ pub fn insert_genesis_block(storage: &mut Storage) -> sp_core::hash::H256 {
|
||||
);
|
||||
let block: crate::Block = construct_genesis_block(state_root, StateVersion::V1);
|
||||
let genesis_hash = block.header.hash();
|
||||
storage.top.extend(additional_storage_with_genesis(&block));
|
||||
|
||||
genesis_hash
|
||||
}
|
||||
|
||||
pub fn additional_storage_with_genesis(genesis_block: &crate::Block) -> BTreeMap<Vec<u8>, Vec<u8>> {
|
||||
map![
|
||||
twox_128(&b"latest"[..]).to_vec() => genesis_block.hash().as_fixed_bytes().to_vec()
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user