mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Do not allow zero Existential Deposit when using Balances (#4894)
* Add non-zero ed check on Balances genesis * Update ED from 0 to 1 * bump impl * bump spec * Found remove more ed = 0 * Fix some contract tests * Use ctx.overlay.set_balance for contracts * Fix staking test * Remove obsolete logic * Allow death of payout account in society * Update frame/balances/src/lib.rs Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * Dont create genesis balances if balance is zero in transaction payment pallet Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Gavin Wood <github@gavwood.com>
This commit is contained in:
@@ -394,6 +394,10 @@ decl_storage! {
|
||||
config(balances): Vec<(T::AccountId, T::Balance)>;
|
||||
// ^^ begin, length, amount liquid at genesis
|
||||
build(|config: &GenesisConfig<T, I>| {
|
||||
assert!(
|
||||
<T as Trait<I>>::ExistentialDeposit::get() > Zero::zero(),
|
||||
"The existential deposit should be greater than zero."
|
||||
);
|
||||
for (_, balance) in &config.balances {
|
||||
assert!(
|
||||
*balance >= <T as Trait<I>>::ExistentialDeposit::get(),
|
||||
|
||||
@@ -103,7 +103,7 @@ pub struct ExtBuilder {
|
||||
impl Default for ExtBuilder {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
existential_deposit: 0,
|
||||
existential_deposit: 1,
|
||||
creation_fee: 0,
|
||||
monied: false,
|
||||
}
|
||||
@@ -120,9 +120,6 @@ impl ExtBuilder {
|
||||
}
|
||||
pub fn monied(mut self, monied: bool) -> Self {
|
||||
self.monied = monied;
|
||||
if self.existential_deposit == 0 {
|
||||
self.existential_deposit = 1;
|
||||
}
|
||||
self
|
||||
}
|
||||
pub fn set_associated_consts(&self) {
|
||||
|
||||
@@ -1009,7 +1009,7 @@ mod tests {
|
||||
|
||||
let mut gas_meter = GasMeter::<Test>::with_limit(1000, 1);
|
||||
|
||||
let result = ctx.instantiate(0, &mut gas_meter, &code, vec![]);
|
||||
let result = ctx.instantiate(1, &mut gas_meter, &code, vec![]);
|
||||
assert_matches!(result, Ok(_));
|
||||
|
||||
let mut toks = gas_meter.tokens().iter();
|
||||
@@ -1302,8 +1302,10 @@ mod tests {
|
||||
let cfg = Config::preload();
|
||||
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
|
||||
|
||||
ctx.overlay.set_balance(&ALICE, 1);
|
||||
|
||||
let result = ctx.instantiate(
|
||||
0,
|
||||
1,
|
||||
&mut GasMeter::<Test>::with_limit(10000, 1),
|
||||
&input_data_ch,
|
||||
vec![1, 2, 3, 4],
|
||||
@@ -1348,6 +1350,7 @@ mod tests {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
let cfg = Config::preload();
|
||||
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
|
||||
ctx.overlay.set_balance(&BOB, 1);
|
||||
ctx.overlay.instantiate_contract(&BOB, recurse_ch).unwrap();
|
||||
|
||||
let result = ctx.call(
|
||||
@@ -1661,8 +1664,10 @@ mod tests {
|
||||
let cfg = Config::preload();
|
||||
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
|
||||
|
||||
ctx.overlay.set_balance(&ALICE, 1);
|
||||
|
||||
let result = ctx.instantiate(
|
||||
0,
|
||||
1,
|
||||
&mut GasMeter::<Test>::with_limit(10000, 1),
|
||||
&rent_allowance_ch,
|
||||
vec![],
|
||||
|
||||
@@ -235,7 +235,7 @@ pub struct ExtBuilder {
|
||||
impl Default for ExtBuilder {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
existential_deposit: 0,
|
||||
existential_deposit: 1,
|
||||
gas_price: 2,
|
||||
block_gas_limit: 100_000_000,
|
||||
transfer_fee: 0,
|
||||
|
||||
@@ -1229,7 +1229,7 @@ mod tests {
|
||||
type ModuleToIndex = ();
|
||||
}
|
||||
parameter_types! {
|
||||
pub const ExistentialDeposit: u64 = 0;
|
||||
pub const ExistentialDeposit: u64 = 1;
|
||||
pub const CreationFee: u64 = 0;
|
||||
}
|
||||
impl pallet_balances::Trait for Test {
|
||||
|
||||
@@ -57,7 +57,7 @@ impl frame_system::Trait for Test {
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const ExistentialDeposit: u64 = 0;
|
||||
pub const ExistentialDeposit: u64 = 1;
|
||||
pub const CreationFee: u64 = 0;
|
||||
}
|
||||
impl pallet_balances::Trait for Test {
|
||||
|
||||
@@ -689,7 +689,7 @@ mod tests {
|
||||
type ModuleToIndex = ();
|
||||
}
|
||||
parameter_types! {
|
||||
pub const ExistentialDeposit: u64 = 0;
|
||||
pub const ExistentialDeposit: u64 = 1;
|
||||
pub const CreationFee: u64 = 0;
|
||||
}
|
||||
impl pallet_balances::Trait for Test {
|
||||
|
||||
@@ -453,7 +453,7 @@ mod tests {
|
||||
type ModuleToIndex = ();
|
||||
}
|
||||
parameter_types! {
|
||||
pub const ExistentialDeposit: u64 = 0;
|
||||
pub const ExistentialDeposit: u64 = 1;
|
||||
pub const CreationFee: u64 = 0;
|
||||
}
|
||||
impl pallet_balances::Trait for Runtime {
|
||||
|
||||
@@ -926,7 +926,7 @@ mod tests {
|
||||
type ModuleToIndex = ();
|
||||
}
|
||||
parameter_types! {
|
||||
pub const ExistentialDeposit: u64 = 0;
|
||||
pub const ExistentialDeposit: u64 = 1;
|
||||
pub const CreationFee: u64 = 0;
|
||||
}
|
||||
impl pallet_balances::Trait for Test {
|
||||
|
||||
@@ -287,7 +287,7 @@ mod tests {
|
||||
type ModuleToIndex = ();
|
||||
}
|
||||
parameter_types! {
|
||||
pub const ExistentialDeposit: u64 = 0;
|
||||
pub const ExistentialDeposit: u64 = 1;
|
||||
pub const CreationFee: u64 = 0;
|
||||
}
|
||||
impl pallet_balances::Trait for Test {
|
||||
|
||||
@@ -46,7 +46,7 @@ parameter_types! {
|
||||
pub const MaximumBlockLength: u32 = 2 * 1024;
|
||||
pub const AvailableBlockRatio: Perbill = Perbill::one();
|
||||
|
||||
pub const ExistentialDeposit: u64 = 0;
|
||||
pub const ExistentialDeposit: u64 = 1;
|
||||
pub const CreationFee: u64 = 0;
|
||||
}
|
||||
ord_parameter_types! {
|
||||
|
||||
@@ -263,7 +263,7 @@ use frame_support::{decl_error, decl_module, decl_storage, decl_event, ensure, d
|
||||
use frame_support::weights::SimpleDispatchInfo;
|
||||
use frame_support::traits::{
|
||||
Currency, ReservableCurrency, Randomness, Get, ChangeMembers,
|
||||
ExistenceRequirement::{KeepAlive, AllowDeath},
|
||||
ExistenceRequirement::AllowDeath,
|
||||
};
|
||||
use frame_system::{self as system, ensure_signed, ensure_root};
|
||||
|
||||
@@ -788,7 +788,7 @@ decl_module! {
|
||||
let mut payouts = <Payouts<T, I>>::get(&who);
|
||||
if let Some((when, amount)) = payouts.first() {
|
||||
if when <= &<system::Module<T>>::block_number() {
|
||||
T::Currency::transfer(&Self::payouts(), &who, *amount, KeepAlive)?;
|
||||
T::Currency::transfer(&Self::payouts(), &who, *amount, AllowDeath)?;
|
||||
payouts.remove(0);
|
||||
if payouts.is_empty() {
|
||||
<Payouts<T, I>>::remove(&who);
|
||||
|
||||
@@ -50,7 +50,7 @@ parameter_types! {
|
||||
pub const MaximumBlockLength: u32 = 2 * 1024;
|
||||
pub const AvailableBlockRatio: Perbill = Perbill::one();
|
||||
|
||||
pub const ExistentialDeposit: u64 = 0;
|
||||
pub const ExistentialDeposit: u64 = 1;
|
||||
pub const CreationFee: u64 = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -233,7 +233,7 @@ pub struct ExtBuilder {
|
||||
impl Default for ExtBuilder {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
existential_deposit: 0,
|
||||
existential_deposit: 1,
|
||||
validator_pool: false,
|
||||
nominate: true,
|
||||
validator_count: 2,
|
||||
@@ -290,7 +290,7 @@ impl ExtBuilder {
|
||||
pub fn build(self) -> sp_io::TestExternalities {
|
||||
self.set_associated_consts();
|
||||
let mut storage = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
let balance_factor = if self.existential_deposit > 0 {
|
||||
let balance_factor = if self.existential_deposit > 1 {
|
||||
256
|
||||
} else {
|
||||
1
|
||||
|
||||
@@ -2066,7 +2066,8 @@ fn slash_in_old_span_does_not_deselect() {
|
||||
),
|
||||
reporters: vec![],
|
||||
}],
|
||||
&[Perbill::from_percent(100)],
|
||||
// NOTE: A 100% slash here would clean up the account, causing de-registration.
|
||||
&[Perbill::from_percent(95)],
|
||||
1,
|
||||
);
|
||||
|
||||
@@ -2272,7 +2273,7 @@ fn only_slash_for_max_in_era() {
|
||||
|
||||
#[test]
|
||||
fn garbage_collection_after_slashing() {
|
||||
ExtBuilder::default().existential_deposit(1).build().execute_with(|| {
|
||||
ExtBuilder::default().existential_deposit(2).build().execute_with(|| {
|
||||
assert_eq!(Balances::free_balance(11), 256_000);
|
||||
|
||||
on_offence_now(
|
||||
|
||||
@@ -306,7 +306,7 @@ mod tests {
|
||||
|
||||
parameter_types! {
|
||||
pub const CreationFee: u64 = 0;
|
||||
pub const ExistentialDeposit: u64 = 0;
|
||||
pub const ExistentialDeposit: u64 = 1;
|
||||
}
|
||||
|
||||
impl pallet_balances::Trait for Runtime {
|
||||
@@ -394,14 +394,18 @@ mod tests {
|
||||
self.set_constants();
|
||||
let mut t = frame_system::GenesisConfig::default().build_storage::<Runtime>().unwrap();
|
||||
pallet_balances::GenesisConfig::<Runtime> {
|
||||
balances: vec![
|
||||
(1, 10 * self.balance_factor),
|
||||
(2, 20 * self.balance_factor),
|
||||
(3, 30 * self.balance_factor),
|
||||
(4, 40 * self.balance_factor),
|
||||
(5, 50 * self.balance_factor),
|
||||
(6, 60 * self.balance_factor)
|
||||
],
|
||||
balances: if self.balance_factor > 0 {
|
||||
vec![
|
||||
(1, 10 * self.balance_factor),
|
||||
(2, 20 * self.balance_factor),
|
||||
(3, 30 * self.balance_factor),
|
||||
(4, 40 * self.balance_factor),
|
||||
(5, 50 * self.balance_factor),
|
||||
(6, 60 * self.balance_factor)
|
||||
]
|
||||
} else {
|
||||
vec![]
|
||||
},
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
t.into()
|
||||
}
|
||||
|
||||
@@ -702,7 +702,7 @@ mod tests {
|
||||
type ModuleToIndex = ();
|
||||
}
|
||||
parameter_types! {
|
||||
pub const ExistentialDeposit: u64 = 0;
|
||||
pub const ExistentialDeposit: u64 = 1;
|
||||
pub const CreationFee: u64 = 0;
|
||||
}
|
||||
impl pallet_balances::Trait for Test {
|
||||
|
||||
Reference in New Issue
Block a user