mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 20:27:58 +00:00
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:
@@ -121,14 +121,12 @@ impl frame_system::Trait for Test {
|
||||
}
|
||||
impl pallet_balances::Trait for Test {
|
||||
type Balance = u64;
|
||||
type OnFreeBalanceZero = Contract;
|
||||
type OnReapAccount = System;
|
||||
type OnReapAccount = (System, Contract);
|
||||
type OnNewAccount = ();
|
||||
type Event = MetaEvent;
|
||||
type DustRemoval = ();
|
||||
type TransferPayment = ();
|
||||
type ExistentialDeposit = ExistentialDeposit;
|
||||
type TransferFee = TransferFee;
|
||||
type CreationFee = CreationFee;
|
||||
}
|
||||
parameter_types! {
|
||||
@@ -171,7 +169,6 @@ impl Trait for Test {
|
||||
type RentByteFee = RentByteFee;
|
||||
type RentDepositOffset = RentDepositOffset;
|
||||
type SurchargeReward = SurchargeReward;
|
||||
type TransferFee = TransferFee;
|
||||
type CreationFee = CreationFee;
|
||||
type TransactionBaseFee = TransactionBaseFee;
|
||||
type TransactionByteFee = TransactionByteFee;
|
||||
@@ -278,7 +275,6 @@ impl ExtBuilder {
|
||||
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
pallet_balances::GenesisConfig::<Test> {
|
||||
balances: vec![],
|
||||
vesting: vec![],
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
GenesisConfig::<Test> {
|
||||
current_schedule: Schedule {
|
||||
@@ -311,7 +307,7 @@ fn refunds_unused_gas() {
|
||||
assert_ok!(Contract::call(Origin::signed(ALICE), BOB, 0, 100_000, Vec::new()));
|
||||
|
||||
// 2 * 135 - gas price multiplied by the call base fee.
|
||||
assert_eq!(Balances::free_balance(&ALICE), 100_000_000 - (2 * 135));
|
||||
assert_eq!(Balances::free_balance(ALICE), 100_000_000 - (2 * 135));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1018,7 +1014,7 @@ fn removals(trigger_call: impl Fn() -> bool) {
|
||||
// Trigger rent must have no effect
|
||||
assert!(trigger_call());
|
||||
assert_eq!(ContractInfoOf::<Test>::get(BOB).unwrap().get_alive().unwrap().rent_allowance, 1_000);
|
||||
assert_eq!(Balances::free_balance(&BOB), 100);
|
||||
assert_eq!(Balances::free_balance(BOB), 100);
|
||||
|
||||
// Advance blocks
|
||||
initialize_block(10);
|
||||
@@ -1026,7 +1022,7 @@ fn removals(trigger_call: impl Fn() -> bool) {
|
||||
// Trigger rent through call
|
||||
assert!(trigger_call());
|
||||
assert!(ContractInfoOf::<Test>::get(BOB).unwrap().get_tombstone().is_some());
|
||||
assert_eq!(Balances::free_balance(&BOB), subsistence_threshold);
|
||||
assert_eq!(Balances::free_balance(BOB), subsistence_threshold);
|
||||
|
||||
// Advance blocks
|
||||
initialize_block(20);
|
||||
@@ -1034,7 +1030,7 @@ fn removals(trigger_call: impl Fn() -> bool) {
|
||||
// Trigger rent must have no effect
|
||||
assert!(trigger_call());
|
||||
assert!(ContractInfoOf::<Test>::get(BOB).unwrap().get_tombstone().is_some());
|
||||
assert_eq!(Balances::free_balance(&BOB), subsistence_threshold);
|
||||
assert_eq!(Balances::free_balance(BOB), subsistence_threshold);
|
||||
});
|
||||
|
||||
// Allowance exceeded
|
||||
@@ -1052,7 +1048,7 @@ fn removals(trigger_call: impl Fn() -> bool) {
|
||||
// Trigger rent must have no effect
|
||||
assert!(trigger_call());
|
||||
assert_eq!(ContractInfoOf::<Test>::get(BOB).unwrap().get_alive().unwrap().rent_allowance, 100);
|
||||
assert_eq!(Balances::free_balance(&BOB), 1_000);
|
||||
assert_eq!(Balances::free_balance(BOB), 1_000);
|
||||
|
||||
// Advance blocks
|
||||
initialize_block(10);
|
||||
@@ -1061,7 +1057,7 @@ fn removals(trigger_call: impl Fn() -> bool) {
|
||||
assert!(trigger_call());
|
||||
assert!(ContractInfoOf::<Test>::get(BOB).unwrap().get_tombstone().is_some());
|
||||
// Balance should be initial balance - initial rent_allowance
|
||||
assert_eq!(Balances::free_balance(&BOB), 900);
|
||||
assert_eq!(Balances::free_balance(BOB), 900);
|
||||
|
||||
// Advance blocks
|
||||
initialize_block(20);
|
||||
@@ -1069,7 +1065,7 @@ fn removals(trigger_call: impl Fn() -> bool) {
|
||||
// Trigger rent must have no effect
|
||||
assert!(trigger_call());
|
||||
assert!(ContractInfoOf::<Test>::get(BOB).unwrap().get_tombstone().is_some());
|
||||
assert_eq!(Balances::free_balance(&BOB), 900);
|
||||
assert_eq!(Balances::free_balance(BOB), 900);
|
||||
});
|
||||
|
||||
// Balance reached and inferior to subsistence threshold
|
||||
@@ -1087,12 +1083,12 @@ fn removals(trigger_call: impl Fn() -> bool) {
|
||||
// Trigger rent must have no effect
|
||||
assert!(trigger_call());
|
||||
assert_eq!(ContractInfoOf::<Test>::get(BOB).unwrap().get_alive().unwrap().rent_allowance, 1_000);
|
||||
assert_eq!(Balances::free_balance(&BOB), 50 + Balances::minimum_balance());
|
||||
assert_eq!(Balances::free_balance(BOB), 50 + Balances::minimum_balance());
|
||||
|
||||
// Transfer funds
|
||||
assert_ok!(Contract::call(Origin::signed(ALICE), BOB, 0, 100_000, call::transfer()));
|
||||
assert_eq!(ContractInfoOf::<Test>::get(BOB).unwrap().get_alive().unwrap().rent_allowance, 1_000);
|
||||
assert_eq!(Balances::free_balance(&BOB), Balances::minimum_balance());
|
||||
assert_eq!(Balances::free_balance(BOB), Balances::minimum_balance());
|
||||
|
||||
// Advance blocks
|
||||
initialize_block(10);
|
||||
@@ -1100,7 +1096,7 @@ fn removals(trigger_call: impl Fn() -> bool) {
|
||||
// Trigger rent through call
|
||||
assert!(trigger_call());
|
||||
assert!(ContractInfoOf::<Test>::get(BOB).is_none());
|
||||
assert_eq!(Balances::free_balance(&BOB), Balances::minimum_balance());
|
||||
assert_eq!(Balances::free_balance(BOB), Balances::minimum_balance());
|
||||
|
||||
// Advance blocks
|
||||
initialize_block(20);
|
||||
@@ -1108,7 +1104,7 @@ fn removals(trigger_call: impl Fn() -> bool) {
|
||||
// Trigger rent must have no effect
|
||||
assert!(trigger_call());
|
||||
assert!(ContractInfoOf::<Test>::get(BOB).is_none());
|
||||
assert_eq!(Balances::free_balance(&BOB), Balances::minimum_balance());
|
||||
assert_eq!(Balances::free_balance(BOB), Balances::minimum_balance());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user