Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Postpone public key creation from account id in the test genesis stor…
…age builder
  • Loading branch information
davxy committed May 15, 2023
commit 98a38c4e9e8ea99981601bf37100409ac86a588b
4 changes: 2 additions & 2 deletions client/service/test/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fn construct_genesis_should_work_with_native() {
vec![AccountKeyring::One.into(), AccountKeyring::Two.into()],
1000 * DOLLARS,
)
.build_storage();
.build();
let genesis_hash = insert_genesis_block(&mut storage);

let backend = InMemoryBackend::from((storage, StateVersion::default()));
Expand Down Expand Up @@ -204,7 +204,7 @@ fn construct_genesis_should_work_with_wasm() {
vec![AccountKeyring::One.into(), AccountKeyring::Two.into()],
1000 * DOLLARS,
)
.build_storage();
.build();
let genesis_hash = insert_genesis_block(&mut storage);

let backend = InMemoryBackend::from((storage, StateVersion::default()));
Expand Down
2 changes: 1 addition & 1 deletion test-utils/runtime/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl GenesisInit for GenesisParameters {
.with_heap_pages(self.heap_pages_override)
.with_wasm_code(&self.wasm_code)
.with_extra_storage(self.extra_storage.clone())
.build_storage()
.build()
}
}

Expand Down
35 changes: 23 additions & 12 deletions test-utils/runtime/src/genesismap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
//! Tool for creating the genesis block.

use super::{
currency, substrate_test_pallet, wasm_binary_unwrap, AccountId, AuthorityId, Balance,
GenesisConfig,
currency, substrate_test_pallet, wasm_binary_unwrap, AccountId, Balance, GenesisConfig,
};
use codec::Encode;
use sc_service::construct_genesis_block;
Expand All @@ -34,14 +33,19 @@ use sp_runtime::{
BuildStorage,
};

/// Builder for generating storage from substrate-test-runtime genesis config. Default storage can
/// be extended with additional key-value pairs.
/// 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>,
/// 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)>,
/// Override default number of heap pages.
heap_pages_override: Option<u64>,
/// Additional storage key pairs that will be added to the genesis map.
extra_storage: Storage,
/// Optional wasm code override.
wasm_code: Option<Vec<u8>>,
}

Expand All @@ -50,9 +54,9 @@ impl Default for GenesisStorageBuilder {
fn default() -> Self {
Self::new(
vec![
sr25519::Public::from(Sr25519Keyring::Alice).into(),
sr25519::Public::from(Sr25519Keyring::Bob).into(),
sr25519::Public::from(Sr25519Keyring::Charlie).into(),
Sr25519Keyring::Alice.into(),
Sr25519Keyring::Bob.into(),
Sr25519Keyring::Charlie.into(),
],
(0..16_usize)
.into_iter()
Expand All @@ -74,7 +78,7 @@ impl GenesisStorageBuilder {
/// 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>,
authorities: Vec<AccountId>,
endowed_accounts: Vec<AccountId>,
balance: Balance,
) -> Self {
Expand Down Expand Up @@ -104,17 +108,24 @@ impl GenesisStorageBuilder {
}

/// 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).into())
.collect();

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(),
authorities: authorities_sr25519.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(),
authorities: authorities_sr25519.clone(),
},
balances: pallet_balances::GenesisConfig { balances: self.balances.clone() },
};
Expand Down
4 changes: 2 additions & 2 deletions test-utils/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1087,15 +1087,15 @@ mod tests {
vec![AccountKeyring::One.into(), AccountKeyring::Two.into()],
1000 * currency::DOLLARS,
)
.build_storage()
.build()
.into()
}

#[test]
fn validate_storage_keys() {
assert_eq!(
genesismap::GenesisStorageBuilder::default()
.build_storage()
.build()
.top
.keys()
.cloned()
Expand Down