mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 05:51:02 +00:00
Postpone public key creation in the test GenesisStorageBuilder (#14142)
* Postpone public key creation from account id in the test genesis storage builder * Store raw sr25519 in substrate test pallet * Nitpick
This commit is contained in:
@@ -173,7 +173,7 @@ fn construct_genesis_should_work_with_native() {
|
|||||||
vec![AccountKeyring::One.into(), AccountKeyring::Two.into()],
|
vec![AccountKeyring::One.into(), AccountKeyring::Two.into()],
|
||||||
1000 * DOLLARS,
|
1000 * DOLLARS,
|
||||||
)
|
)
|
||||||
.build_storage();
|
.build();
|
||||||
let genesis_hash = insert_genesis_block(&mut storage);
|
let genesis_hash = insert_genesis_block(&mut storage);
|
||||||
|
|
||||||
let backend = InMemoryBackend::from((storage, StateVersion::default()));
|
let backend = InMemoryBackend::from((storage, StateVersion::default()));
|
||||||
@@ -204,7 +204,7 @@ fn construct_genesis_should_work_with_wasm() {
|
|||||||
vec![AccountKeyring::One.into(), AccountKeyring::Two.into()],
|
vec![AccountKeyring::One.into(), AccountKeyring::Two.into()],
|
||||||
1000 * DOLLARS,
|
1000 * DOLLARS,
|
||||||
)
|
)
|
||||||
.build_storage();
|
.build();
|
||||||
let genesis_hash = insert_genesis_block(&mut storage);
|
let genesis_hash = insert_genesis_block(&mut storage);
|
||||||
|
|
||||||
let backend = InMemoryBackend::from((storage, StateVersion::default()));
|
let backend = InMemoryBackend::from((storage, StateVersion::default()));
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ impl GenesisInit for GenesisParameters {
|
|||||||
.with_heap_pages(self.heap_pages_override)
|
.with_heap_pages(self.heap_pages_override)
|
||||||
.with_wasm_code(&self.wasm_code)
|
.with_wasm_code(&self.wasm_code)
|
||||||
.with_extra_storage(self.extra_storage.clone())
|
.with_extra_storage(self.extra_storage.clone())
|
||||||
.build_storage()
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,7 @@
|
|||||||
//! Tool for creating the genesis block.
|
//! Tool for creating the genesis block.
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
currency, substrate_test_pallet, wasm_binary_unwrap, AccountId, AuthorityId, Balance,
|
currency, substrate_test_pallet, wasm_binary_unwrap, AccountId, Balance, GenesisConfig,
|
||||||
GenesisConfig,
|
|
||||||
};
|
};
|
||||||
use codec::Encode;
|
use codec::Encode;
|
||||||
use sc_service::construct_genesis_block;
|
use sc_service::construct_genesis_block;
|
||||||
@@ -34,14 +33,19 @@ use sp_runtime::{
|
|||||||
BuildStorage,
|
BuildStorage,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Builder for generating storage from substrate-test-runtime genesis config. Default storage can
|
/// Builder for generating storage from substrate-test-runtime genesis config.
|
||||||
/// be extended with additional key-value pairs.
|
///
|
||||||
|
/// Default storage can be extended with additional key-value pairs.
|
||||||
pub struct GenesisStorageBuilder {
|
pub struct GenesisStorageBuilder {
|
||||||
authorities: Vec<AuthorityId>,
|
/// Authorities accounts used by any component requiring an authority set (e.g. babe).
|
||||||
|
authorities: Vec<AccountId>,
|
||||||
|
/// Accounts to be endowed with some funds.
|
||||||
balances: Vec<(AccountId, u64)>,
|
balances: Vec<(AccountId, u64)>,
|
||||||
|
/// Override default number of heap pages.
|
||||||
heap_pages_override: Option<u64>,
|
heap_pages_override: Option<u64>,
|
||||||
/// Additional storage key pairs that will be added to the genesis map.
|
/// Additional storage key pairs that will be added to the genesis map.
|
||||||
extra_storage: Storage,
|
extra_storage: Storage,
|
||||||
|
/// Optional wasm code override.
|
||||||
wasm_code: Option<Vec<u8>>,
|
wasm_code: Option<Vec<u8>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,9 +54,9 @@ impl Default for GenesisStorageBuilder {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new(
|
Self::new(
|
||||||
vec![
|
vec![
|
||||||
sr25519::Public::from(Sr25519Keyring::Alice).into(),
|
Sr25519Keyring::Alice.into(),
|
||||||
sr25519::Public::from(Sr25519Keyring::Bob).into(),
|
Sr25519Keyring::Bob.into(),
|
||||||
sr25519::Public::from(Sr25519Keyring::Charlie).into(),
|
Sr25519Keyring::Charlie.into(),
|
||||||
],
|
],
|
||||||
(0..16_usize)
|
(0..16_usize)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -74,7 +78,7 @@ impl GenesisStorageBuilder {
|
|||||||
/// from `extra_storage` will be injected into built storage. `HEAP_PAGES` key and value will
|
/// from `extra_storage` will be injected into built storage. `HEAP_PAGES` key and value will
|
||||||
/// also be placed into storage.
|
/// also be placed into storage.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
authorities: Vec<AuthorityId>,
|
authorities: Vec<AccountId>,
|
||||||
endowed_accounts: Vec<AccountId>,
|
endowed_accounts: Vec<AccountId>,
|
||||||
balance: Balance,
|
balance: Balance,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@@ -104,17 +108,28 @@ impl GenesisStorageBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Builds the `GenesisConfig` and returns its storage.
|
/// Builds the `GenesisConfig` and returns its storage.
|
||||||
pub fn build_storage(&mut self) -> Storage {
|
pub fn build(self) -> Storage {
|
||||||
|
let authorities_sr25519: Vec<_> = self
|
||||||
|
.authorities
|
||||||
|
.clone()
|
||||||
|
.into_iter()
|
||||||
|
.map(|id| sr25519::Public::from(id))
|
||||||
|
.collect();
|
||||||
|
|
||||||
let genesis_config = GenesisConfig {
|
let genesis_config = GenesisConfig {
|
||||||
system: frame_system::GenesisConfig {
|
system: frame_system::GenesisConfig {
|
||||||
code: self.wasm_code.clone().unwrap_or(wasm_binary_unwrap().to_vec()),
|
code: self.wasm_code.clone().unwrap_or(wasm_binary_unwrap().to_vec()),
|
||||||
},
|
},
|
||||||
babe: pallet_babe::GenesisConfig {
|
babe: pallet_babe::GenesisConfig {
|
||||||
authorities: self.authorities.clone().into_iter().map(|x| (x, 1)).collect(),
|
authorities: authorities_sr25519
|
||||||
|
.clone()
|
||||||
|
.into_iter()
|
||||||
|
.map(|x| (x.into(), 1))
|
||||||
|
.collect(),
|
||||||
epoch_config: Some(crate::TEST_RUNTIME_BABE_EPOCH_CONFIGURATION),
|
epoch_config: Some(crate::TEST_RUNTIME_BABE_EPOCH_CONFIGURATION),
|
||||||
},
|
},
|
||||||
substrate_test: substrate_test_pallet::GenesisConfig {
|
substrate_test: substrate_test_pallet::GenesisConfig {
|
||||||
authorities: self.authorities.clone(),
|
authorities: authorities_sr25519.clone(),
|
||||||
},
|
},
|
||||||
balances: pallet_balances::GenesisConfig { balances: self.balances.clone() },
|
balances: pallet_balances::GenesisConfig { balances: self.balances.clone() },
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -64,13 +64,11 @@ use sp_runtime::{
|
|||||||
use sp_version::NativeVersion;
|
use sp_version::NativeVersion;
|
||||||
use sp_version::RuntimeVersion;
|
use sp_version::RuntimeVersion;
|
||||||
|
|
||||||
// Ensure Babe and Aura use the same crypto to simplify things a bit.
|
pub use sp_consensus_babe::{AllowedSlots, BabeEpochConfiguration, Slot};
|
||||||
pub use sp_consensus_babe::{AllowedSlots, AuthorityId, BabeEpochConfiguration, Slot};
|
|
||||||
|
|
||||||
pub use pallet_balances::Call as BalancesCall;
|
pub use pallet_balances::Call as BalancesCall;
|
||||||
|
|
||||||
pub type AuraId = sp_consensus_aura::sr25519::AuthorityId;
|
pub type AuraId = sp_consensus_aura::sr25519::AuthorityId;
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub use extrinsic::{ExtrinsicBuilder, Transfer};
|
pub use extrinsic::{ExtrinsicBuilder, Transfer};
|
||||||
|
|
||||||
@@ -616,10 +614,7 @@ impl_runtime_apis! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn authorities() -> Vec<AuraId> {
|
fn authorities() -> Vec<AuraId> {
|
||||||
SubstrateTest::authorities().into_iter().map(|a| {
|
SubstrateTest::authorities().into_iter().map(|auth| AuraId::from(auth)).collect()
|
||||||
let authority: sr25519::Public = a.into();
|
|
||||||
AuraId::from(authority)
|
|
||||||
}).collect()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -630,10 +625,9 @@ impl_runtime_apis! {
|
|||||||
slot_duration: Babe::slot_duration(),
|
slot_duration: Babe::slot_duration(),
|
||||||
epoch_length: EpochDuration::get(),
|
epoch_length: EpochDuration::get(),
|
||||||
c: epoch_config.c,
|
c: epoch_config.c,
|
||||||
authorities: SubstrateTest::authorities()
|
authorities: Babe::authorities().to_vec(),
|
||||||
.into_iter().map(|x|(x, 1)).collect(),
|
randomness: Babe::randomness(),
|
||||||
randomness: Babe::randomness(),
|
allowed_slots: epoch_config.allowed_slots,
|
||||||
allowed_slots: epoch_config.allowed_slots,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1087,7 +1081,7 @@ mod tests {
|
|||||||
vec![AccountKeyring::One.into(), AccountKeyring::Two.into()],
|
vec![AccountKeyring::One.into(), AccountKeyring::Two.into()],
|
||||||
1000 * currency::DOLLARS,
|
1000 * currency::DOLLARS,
|
||||||
)
|
)
|
||||||
.build_storage()
|
.build()
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1095,7 +1089,7 @@ mod tests {
|
|||||||
fn validate_storage_keys() {
|
fn validate_storage_keys() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
genesismap::GenesisStorageBuilder::default()
|
genesismap::GenesisStorageBuilder::default()
|
||||||
.build_storage()
|
.build()
|
||||||
.top
|
.top
|
||||||
.keys()
|
.keys()
|
||||||
.cloned()
|
.cloned()
|
||||||
|
|||||||
@@ -21,8 +21,8 @@
|
|||||||
//! functioning runtime. Some calls are allowed to be submitted as unsigned extrinsics, however most
|
//! functioning runtime. Some calls are allowed to be submitted as unsigned extrinsics, however most
|
||||||
//! of them requires signing. Refer to `pallet::Call` for further details.
|
//! of them requires signing. Refer to `pallet::Call` for further details.
|
||||||
|
|
||||||
use crate::AuthorityId;
|
|
||||||
use frame_support::{pallet_prelude::*, storage};
|
use frame_support::{pallet_prelude::*, storage};
|
||||||
|
use sp_core::sr25519::Public;
|
||||||
use sp_runtime::transaction_validity::{
|
use sp_runtime::transaction_validity::{
|
||||||
InvalidTransaction, TransactionSource, TransactionValidity, ValidTransaction,
|
InvalidTransaction, TransactionSource, TransactionValidity, ValidTransaction,
|
||||||
};
|
};
|
||||||
@@ -49,12 +49,12 @@ pub mod pallet {
|
|||||||
|
|
||||||
#[pallet::storage]
|
#[pallet::storage]
|
||||||
#[pallet::getter(fn authorities)]
|
#[pallet::getter(fn authorities)]
|
||||||
pub type Authorities<T> = StorageValue<_, Vec<AuthorityId>, ValueQuery>;
|
pub type Authorities<T> = StorageValue<_, Vec<Public>, ValueQuery>;
|
||||||
|
|
||||||
#[pallet::genesis_config]
|
#[pallet::genesis_config]
|
||||||
#[cfg_attr(feature = "std", derive(Default))]
|
#[cfg_attr(feature = "std", derive(Default))]
|
||||||
pub struct GenesisConfig {
|
pub struct GenesisConfig {
|
||||||
pub authorities: Vec<AuthorityId>,
|
pub authorities: Vec<Public>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pallet::genesis_build]
|
#[pallet::genesis_build]
|
||||||
|
|||||||
Reference in New Issue
Block a user