Refactor the balances module (#4649)

* Initially scoping out of the problem

* Remove need for exiry in balance locks.

* Remove expiry from locks.

* Remove supefluous balance test

* Amalgamate pieces of balance module

* Split out vesting

* Fix tests

* Fixes for vesting.

* Docs.

* Weight docs.

* Refactor things in terms of set_balances.

* Switch out ED to be free + reserved.

* Remove on_free_balance_zero and some docs.

* Build fixes

* Update frame/vesting/src/lib.rs

Co-Authored-By: Xiliang Chen <xlchen1291@gmail.com>

* Update frame/vesting/src/lib.rs

Co-Authored-By: Xiliang Chen <xlchen1291@gmail.com>

* Migration

* Remove superfluous code.

* Test fixes

* Fix some tests

* Fix repatriate reserve

* Fixes

* Add test for migration

* Final cleanups

* Fix

* Indentation.

* Undo unneeded referencing

* Bump runtime version

* Fixes

Co-authored-by: Xiliang Chen <xlchen1291@gmail.com>
This commit is contained in:
Gavin Wood
2020-02-01 13:20:16 +00:00
committed by GitHub
parent b6e8fba179
commit d52d8692f9
46 changed files with 1748 additions and 1171 deletions
+1 -2
View File
@@ -26,7 +26,7 @@
use sp_std::prelude::*;
use sp_runtime::{
RuntimeDebug, DispatchResult, print,
traits::{Zero, One, StaticLookup, Bounded, Saturating},
traits::{Zero, One, StaticLookup, Saturating},
};
use frame_support::{
decl_storage, decl_event, ensure, decl_module, decl_error,
@@ -894,7 +894,6 @@ impl<T: Trait> Module<T> {
MODULE_ID,
&who,
locked_balance,
T::BlockNumber::max_value(),
WithdrawReasons::all(),
);
+2 -5
View File
@@ -58,19 +58,16 @@ impl frame_system::Trait for Test {
parameter_types! {
pub const ExistentialDeposit: u64 = 0;
pub const TransferFee: u64 = 0;
pub const CreationFee: u64 = 0;
}
impl pallet_balances::Trait for Test {
type Balance = u64;
type OnNewAccount = ();
type OnFreeBalanceZero = ();
type OnReapAccount = System;
type Event = Event;
type TransferPayment = ();
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee;
type CreationFee = CreationFee;
}
@@ -222,7 +219,6 @@ impl ExtBuilder {
(5, 50 * self.balance_factor),
(6, 60 * self.balance_factor)
],
vesting: vec![],
}),
elections: Some(elections::GenesisConfig::<Test>{
members: vec![],
@@ -270,7 +266,8 @@ pub(crate) fn create_candidate(i: u64, index: u32) {
}
pub(crate) fn balances(who: &u64) -> (u64, u64) {
(Balances::free_balance(who), Balances::reserved_balance(who))
let a = Balances::account(who);
(a.free, a.reserved)
}
pub(crate) fn locks(who: &u64) -> Vec<u64> {
+3 -3
View File
@@ -1179,14 +1179,14 @@ fn election_present_when_presenter_is_poor_should_not_work() {
// -3
assert_ok!(Elections::submit_candidacy(Origin::signed(1), 0));
assert_eq!(Balances::free_balance(&1), 12);
assert_eq!(Balances::free_balance(1), 12);
// -2 -5
assert_ok!(Elections::set_approvals(Origin::signed(1), vec![true], 0, 0, 15));
assert_ok!(Elections::end_block(System::block_number()));
System::set_block_number(6);
assert_eq!(Balances::free_balance(&1), 5);
assert_eq!(Balances::reserved_balance(&1), 5);
assert_eq!(Balances::free_balance(1), 5);
assert_eq!(Balances::reserved_balance(1), 5);
if p > 5 {
assert_noop!(Elections::present_winner(
Origin::signed(1), 1, 10, 0),