mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-24 03:05:44 +00:00
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:
@@ -59,7 +59,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
|||||||
impl_name: create_runtime_str!("substrate-node"),
|
impl_name: create_runtime_str!("substrate-node"),
|
||||||
authoring_version: 10,
|
authoring_version: 10,
|
||||||
spec_version: 38,
|
spec_version: 38,
|
||||||
impl_version: 38,
|
impl_version: 39,
|
||||||
apis: RUNTIME_API_VERSIONS,
|
apis: RUNTIME_API_VERSIONS,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
BIN
Binary file not shown.
@@ -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
|
/// NOTE: LOW-LEVEL: This will not attempt to maintain total issuance. It is expected that
|
||||||
/// the caller will do this.
|
/// the caller will do this.
|
||||||
fn set_free_balance(who: &T::AccountId, balance: T::Balance) -> UpdateBalanceOutcome {
|
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::total_balance(who).is_zero());
|
||||||
|
// assert!(Self::free_balance(who) > Self::existential_deposit());
|
||||||
if balance < Self::existential_deposit() {
|
if balance < Self::existential_deposit() {
|
||||||
<FreeBalance<T, I>>::insert(who, balance);
|
<FreeBalance<T, I>>::insert(who, balance);
|
||||||
Self::on_free_too_low(who);
|
Self::on_free_too_low(who);
|
||||||
@@ -657,6 +658,19 @@ where
|
|||||||
UpdateBalanceOutcome
|
UpdateBalanceOutcome
|
||||||
) {
|
) {
|
||||||
let original = Self::free_balance(who);
|
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 {
|
let imbalance = if original <= balance {
|
||||||
SignedImbalance::Positive(PositiveImbalance(balance - original))
|
SignedImbalance::Positive(PositiveImbalance(balance - original))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -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]
|
#[test]
|
||||||
fn account_removal_on_free_too_low() {
|
fn account_removal_on_free_too_low() {
|
||||||
with_externalities(
|
with_externalities(
|
||||||
|
|||||||
Reference in New Issue
Block a user