-
Notifications
You must be signed in to change notification settings - Fork 707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Balances: Allow Configurable Number of Genesis Accounts with Specified Balances for Benchmarking #6267
base: master
Are you sure you want to change the base?
Conversation
Balances of |
Hello @michalkucharczyk @ggwpez please review 🤝 |
{ | ||
let (num_accounts, balance, ref derivation) = self.dev_accounts; | ||
// Check if `derivation` is `Some` and generate key pair | ||
if let Some(derivation_string) = &derivation { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use some default (//Sender/{}
) here, if None
is given in genesis config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be placed in a helper function
/// Generate dev account from derivation string.
#[cfg(feature = "runtime-benchmarks")]
pub fn derive_dev_account(
num_accounts: u32,
balance: T::Balance,
derivation: &String,
) {
// Ensure that the number of accounts is not zero
assert!(num_accounts > 0, "num_accounts must be greater than zero");
assert!(
balance >= <T as Config<I>>::ExistentialDeposit::get(),
"the balance of any account should always be at least the existential deposit.",
);
for index in 0..num_accounts {
// Replace "{}" in the derivation string with the index.
let derivation_string = derivation.replace("{}", &index.to_string());
// Attempt to create the key pair from the derivation string with error handling.
let pair: SrPair = Pair::from_string(&derivation_string, None)
.expect(&format!("Failed to parse derivation string: {}", derivation_string));
// Convert the public key to AccountId.
let who = T::AccountId::decode(&mut &pair.public().encode()[..])
.expect(&format!("Failed to decode public key from pair: {}", pair.public()));
frame_system::Pallet::<T>::inc_providers(&who);
// Insert the account into the store and ensure it succeeds.
assert!(T::AccountStore::insert(
&who,
AccountData { free: balance, ..Default::default() }
)
.is_ok());
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be useful to generate one dev account with a balance in the pallets that require balances by default?
impl<T: Config<I>, I: 'static> Default for GenesisConfig<T, I> {
fn default() -> Self {
Self {
balances: Default::default(),
#[cfg(feature = "runtime-benchmarks")]
dev_accounts: (One::one(), <T as Config<I>>::ExistentialDeposit::get(), None),
}
}
}
Derived Dev Accounts
Resolves #6040