genesis check for balances and ED (#4151)

* genesis check for balances

* fix test.

* Update paint/balances/src/lib.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Kian Paimani
2019-11-20 14:36:55 +01:00
committed by GitHub
parent 303843f483
commit e29b261240
5 changed files with 22 additions and 3 deletions
+1 -1
View File
@@ -78,7 +78,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
spec_version: 194,
impl_version: 194,
impl_version: 195,
apis: RUNTIME_API_VERSIONS,
};
+8
View File
@@ -372,6 +372,14 @@ decl_storage! {
config(balances): Vec<(T::AccountId, T::Balance)>;
config(vesting): Vec<(T::AccountId, T::BlockNumber, T::BlockNumber, T::Balance)>;
// ^^ begin, length, amount liquid at genesis
build(|config: &GenesisConfig<T, I>| {
for (_, balance) in &config.balances {
assert!(
*balance >= <T as Trait<I>>::ExistentialDeposit::get(),
"the balance of any account should always be more than existential deposit.",
)
}
});
}
}
+1 -1
View File
@@ -32,7 +32,7 @@ impl_outer_origin!{
}
thread_local! {
static EXISTENTIAL_DEPOSIT: RefCell<u64> = RefCell::new(0);
pub(crate) static EXISTENTIAL_DEPOSIT: RefCell<u64> = RefCell::new(0);
static TRANSFER_FEE: RefCell<u64> = RefCell::new(0);
static CREATION_FEE: RefCell<u64> = RefCell::new(0);
}
+11
View File
@@ -760,3 +760,14 @@ fn transfer_keep_alive_works() {
assert_eq!(Balances::total_balance(&2), 0);
});
}
#[test]
#[should_panic="the balance of any account should always be more than existential deposit."]
fn cannot_set_genesis_value_below_ed() {
mock::EXISTENTIAL_DEPOSIT.with(|v| *v.borrow_mut() = 11);
let mut t = system::GenesisConfig::default().build_storage::<Runtime>().unwrap();
let _ = GenesisConfig::<Runtime> {
balances: vec![(1, 10)],
vesting: vec![],
}.assimilate_storage(&mut t).unwrap();
}
+1 -1
View File
@@ -709,7 +709,7 @@ mod tests {
#[test]
fn block_hooks_weight_is_stored() {
new_test_ext(0).execute_with(|| {
new_test_ext(1).execute_with(|| {
Executive::initialize_block(&Header::new_from_number(1));
// NOTE: might need updates over time if system and balance introduce new weights. For