mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 11:27:58 +00:00
remove duplicate accounts in chain-spec. (#7725)
* remove duplicate accounts in chain-spec. * Fix build * Enforce in balances modules. * Apply suggestions from code review * Update frame/balances/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
@@ -218,7 +218,7 @@ pub fn testnet_genesis(
|
||||
endowed_accounts: Option<Vec<AccountId>>,
|
||||
enable_println: bool,
|
||||
) -> GenesisConfig {
|
||||
let endowed_accounts: Vec<AccountId> = endowed_accounts.unwrap_or_else(|| {
|
||||
let mut endowed_accounts: Vec<AccountId> = endowed_accounts.unwrap_or_else(|| {
|
||||
vec![
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
@@ -234,10 +234,16 @@ pub fn testnet_genesis(
|
||||
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
|
||||
]
|
||||
});
|
||||
initial_authorities.iter().for_each(|x|
|
||||
if !endowed_accounts.contains(&x.0) {
|
||||
endowed_accounts.push(x.0.clone())
|
||||
}
|
||||
);
|
||||
|
||||
let num_endowed_accounts = endowed_accounts.len();
|
||||
|
||||
const ENDOWMENT: Balance = 10_000_000 * DOLLARS;
|
||||
const STASH: Balance = 100 * DOLLARS;
|
||||
const STASH: Balance = ENDOWMENT / 1000;
|
||||
|
||||
GenesisConfig {
|
||||
frame_system: Some(SystemConfig {
|
||||
@@ -246,9 +252,8 @@ pub fn testnet_genesis(
|
||||
}),
|
||||
pallet_balances: Some(BalancesConfig {
|
||||
balances: endowed_accounts.iter().cloned()
|
||||
.map(|k| (k, ENDOWMENT))
|
||||
.chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH)))
|
||||
.collect(),
|
||||
.map(|x| (x, ENDOWMENT))
|
||||
.collect()
|
||||
}),
|
||||
pallet_indices: Some(IndicesConfig {
|
||||
indices: vec![],
|
||||
|
||||
@@ -412,6 +412,12 @@ decl_storage! {
|
||||
"the balance of any account should always be at least the existential deposit.",
|
||||
)
|
||||
}
|
||||
|
||||
// ensure no duplicates exist.
|
||||
let endowed_accounts = config.balances.iter().map(|(x, _)| x).cloned().collect::<std::collections::BTreeSet<_>>();
|
||||
|
||||
assert!(endowed_accounts.len() == config.balances.len(), "duplicate balances in genesis.");
|
||||
|
||||
for &(ref who, free) in config.balances.iter() {
|
||||
T::AccountStore::insert(who, AccountData { free, .. Default::default() });
|
||||
}
|
||||
|
||||
@@ -639,6 +639,15 @@ macro_rules! decl_tests {
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic = "duplicate balances in genesis."]
|
||||
fn cannot_set_genesis_value_twice() {
|
||||
let mut t = frame_system::GenesisConfig::default().build_storage::<$test>().unwrap();
|
||||
let _ = GenesisConfig::<$test> {
|
||||
balances: vec![(1, 10), (2, 20), (1, 15)],
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dust_moves_between_free_and_reserved() {
|
||||
<$ext_builder>::default()
|
||||
|
||||
Reference in New Issue
Block a user