Rebuild, add a couple of tests and fix theoretical issue (#2056)

* Rebuild, add a couple of tests and fix theoretical issue

* Update lib.rs
This commit is contained in:
Gav Wood
2019-03-21 13:56:31 +01:00
committed by GitHub
parent b31bcdfcc3
commit df65a92c91
4 changed files with 46 additions and 2 deletions
+1 -1
View File
@@ -59,7 +59,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_name: create_runtime_str!("substrate-node"),
authoring_version: 10,
spec_version: 38,
impl_version: 38,
impl_version: 39,
apis: RUNTIME_API_VERSIONS,
};
+15 -1
View File
@@ -283,8 +283,9 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
/// NOTE: LOW-LEVEL: This will not attempt to maintain total issuance. It is expected that
/// the caller will do this.
fn set_free_balance(who: &T::AccountId, balance: T::Balance) -> UpdateBalanceOutcome {
// Commented out for no - but consider it instructive.
// Commented out for now - but consider it instructive.
// assert!(!Self::total_balance(who).is_zero());
// assert!(Self::free_balance(who) > Self::existential_deposit());
if balance < Self::existential_deposit() {
<FreeBalance<T, I>>::insert(who, balance);
Self::on_free_too_low(who);
@@ -657,6 +658,19 @@ where
UpdateBalanceOutcome
) {
let original = Self::free_balance(who);
if balance < Self::existential_deposit() && original.is_zero() {
// If we're attempting to set an existing account to less than ED, then
// bypass the entire operation. It's a no-op if you follow it through, but
// since this is an instance where we might account for a negative imbalance
// (in the dust cleaner of set_free_balance) before we account for its actual
// equal and opposite cause (returned as an Imbalance), then in the
// instance that there's no other accounts on the system at all, we might
// underflow the issuance and our arithmetic will be off.
return (
SignedImbalance::Positive(Self::PositiveImbalance::zero()),
UpdateBalanceOutcome::AccountKilled,
)
}
let imbalance = if original <= balance {
SignedImbalance::Positive(PositiveImbalance(balance - original))
} else {
+30
View File
@@ -440,6 +440,36 @@ fn transferring_too_high_value_should_not_panic() {
});
}
#[test]
fn account_create_on_free_too_low_with_other() {
with_externalities(
&mut ExtBuilder::default().existential_deposit(100).build(),
|| {
let _ = Balances::deposit_creating(&1, 100);
assert_eq!(<TotalIssuance<Runtime>>::get(), 100);
// No-op.
let _ = Balances::deposit_creating(&2, 50);
assert_eq!(Balances::free_balance(&2), 0);
assert_eq!(<TotalIssuance<Runtime>>::get(), 100);
}
)
}
#[test]
fn account_create_on_free_too_low() {
with_externalities(
&mut ExtBuilder::default().existential_deposit(100).build(),
|| {
// No-op.
let _ = Balances::deposit_creating(&2, 50);
assert_eq!(Balances::free_balance(&2), 0);
assert_eq!(<TotalIssuance<Runtime>>::get(), 0);
}
)
}
#[test]
fn account_removal_on_free_too_low() {
with_externalities(