-
Notifications
You must be signed in to change notification settings - Fork 754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Staking] Noop refactor to prep pallet for currency fungible migration #5399
Changes from all commits
02d3a70
fa1064f
babc205
2f0cd28
4af4aee
1995e06
f3a3081
6a03abb
040c630
3d3ceac
61eb7b7
b8a0e4b
2926255
9e38e8e
34e1d48
31c6467
851c5f3
fe893a8
087692b
67bd3fa
994c6c5
940e5e0
0c296ab
61bac35
12607ec
9660a41
0cfd8e4
165261f
f62354b
a156423
a8b78a7
17144b0
c1fc3dc
679f290
49c2045
5af34d5
00841b6
d6258bc
b2d2245
748ec96
e7c4e6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -322,24 +322,24 @@ fn automatic_unbonding_pools() { | |
assert_eq!(<Runtime as pallet_nomination_pools::Config>::MaxUnbonding::get(), 1); | ||
|
||
// init state of pool members. | ||
let init_free_balance_2 = Balances::free_balance(2); | ||
let init_free_balance_3 = Balances::free_balance(3); | ||
let init_stakeable_balance_2 = pallet_staking::asset::stakeable_balance::<Runtime>(&2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe worth a |
||
let init_stakeable_balance_3 = pallet_staking::asset::stakeable_balance::<Runtime>(&3); | ||
|
||
let pool_bonded_account = Pools::generate_bonded_account(1); | ||
|
||
// creates a pool with 5 bonded, owned by 1. | ||
assert_ok!(Pools::create(RuntimeOrigin::signed(1), 5, 1, 1, 1)); | ||
assert_eq!(locked_amount_for(pool_bonded_account), 5); | ||
assert_eq!(staked_amount_for(pool_bonded_account), 5); | ||
|
||
let init_tvl = TotalValueLocked::<Runtime>::get(); | ||
|
||
// 2 joins the pool. | ||
assert_ok!(Pools::join(RuntimeOrigin::signed(2), 10, 1)); | ||
assert_eq!(locked_amount_for(pool_bonded_account), 15); | ||
assert_eq!(staked_amount_for(pool_bonded_account), 15); | ||
|
||
// 3 joins the pool. | ||
assert_ok!(Pools::join(RuntimeOrigin::signed(3), 10, 1)); | ||
assert_eq!(locked_amount_for(pool_bonded_account), 25); | ||
assert_eq!(staked_amount_for(pool_bonded_account), 25); | ||
|
||
assert_eq!(TotalValueLocked::<Runtime>::get(), 25); | ||
|
||
|
@@ -350,7 +350,7 @@ fn automatic_unbonding_pools() { | |
assert_ok!(Pools::unbond(RuntimeOrigin::signed(2), 2, 10)); | ||
|
||
// amount is still locked in the pool, needs to wait for unbonding period. | ||
assert_eq!(locked_amount_for(pool_bonded_account), 25); | ||
assert_eq!(staked_amount_for(pool_bonded_account), 25); | ||
|
||
// max chunks in the ledger are now filled up (`MaxUnlockingChunks == 1`). | ||
assert_eq!(unlocking_chunks_of(pool_bonded_account), 1); | ||
|
@@ -372,8 +372,8 @@ fn automatic_unbonding_pools() { | |
assert_eq!(current_era(), 3); | ||
System::reset_events(); | ||
|
||
let locked_before_withdraw_pool = locked_amount_for(pool_bonded_account); | ||
assert_eq!(Balances::free_balance(pool_bonded_account), 26); | ||
let staked_before_withdraw_pool = staked_amount_for(pool_bonded_account); | ||
assert_eq!(pallet_staking::asset::stakeable_balance::<Runtime>(&pool_bonded_account), 26); | ||
|
||
// now unbonding 3 will work, although the pool's ledger still has the unlocking chunks | ||
// filled up. | ||
|
@@ -391,20 +391,21 @@ fn automatic_unbonding_pools() { | |
); | ||
|
||
// balance of the pool remains the same, it hasn't withdraw explicitly from the pool yet. | ||
assert_eq!(Balances::free_balance(pool_bonded_account), 26); | ||
assert_eq!(pallet_staking::asset::stakeable_balance::<Runtime>(&pool_bonded_account), 26); | ||
// but the locked amount in the pool's account decreases due to the auto-withdraw: | ||
assert_eq!(locked_before_withdraw_pool - 10, locked_amount_for(pool_bonded_account)); | ||
assert_eq!(staked_before_withdraw_pool - 10, staked_amount_for(pool_bonded_account)); | ||
|
||
// TVL correctly updated. | ||
assert_eq!(TotalValueLocked::<Runtime>::get(), 25 - 10); | ||
|
||
// however, note that the withdrawing from the pool still works for 2, the funds are taken | ||
// from the pool's free balance. | ||
assert_eq!(Balances::free_balance(pool_bonded_account), 26); | ||
// from the pool's non staked balance. | ||
assert_eq!(pallet_staking::asset::stakeable_balance::<Runtime>(&pool_bonded_account), 26); | ||
assert_eq!(pallet_staking::asset::staked::<Runtime>(&pool_bonded_account), 15); | ||
assert_ok!(Pools::withdraw_unbonded(RuntimeOrigin::signed(2), 2, 10)); | ||
assert_eq!(Balances::free_balance(pool_bonded_account), 16); | ||
assert_eq!(pallet_staking::asset::stakeable_balance::<Runtime>(&pool_bonded_account), 16); | ||
|
||
assert_eq!(Balances::free_balance(2), 20); | ||
assert_eq!(pallet_staking::asset::stakeable_balance::<Runtime>(&2), 20); | ||
assert_eq!(TotalValueLocked::<Runtime>::get(), 15); | ||
|
||
// 3 cannot withdraw yet. | ||
|
@@ -423,9 +424,15 @@ fn automatic_unbonding_pools() { | |
assert_ok!(Pools::withdraw_unbonded(RuntimeOrigin::signed(3), 3, 10)); | ||
|
||
// final conditions are the expected. | ||
assert_eq!(Balances::free_balance(pool_bonded_account), 6); // 5 init bonded + ED | ||
assert_eq!(Balances::free_balance(2), init_free_balance_2); | ||
assert_eq!(Balances::free_balance(3), init_free_balance_3); | ||
assert_eq!(pallet_staking::asset::stakeable_balance::<Runtime>(&pool_bonded_account), 6); // 5 init bonded + ED | ||
assert_eq!( | ||
pallet_staking::asset::stakeable_balance::<Runtime>(&2), | ||
init_stakeable_balance_2 | ||
); | ||
assert_eq!( | ||
pallet_staking::asset::stakeable_balance::<Runtime>(&3), | ||
init_stakeable_balance_3 | ||
); | ||
|
||
assert_eq!(TotalValueLocked::<Runtime>::get(), init_tvl); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -137,15 +137,16 @@ fn deregister_works() { | |||||
ExtBuilder::default().build_and_execute(|| { | ||||||
ErasToCheckPerBlock::<T>::put(1); | ||||||
|
||||||
assert_eq!(<T as Config>::Currency::reserved_balance(&1), 0); | ||||||
// reserved balance prior to registering for fast unstake. | ||||||
let pre_reserved = <T as Config>::Currency::reserved_balance(&1); | ||||||
|
||||||
// Controller account registers for fast unstake. | ||||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1))); | ||||||
assert_eq!(<T as Config>::Currency::reserved_balance(&1), Deposit::get()); | ||||||
assert_eq!(<T as Config>::Currency::reserved_balance(&1) - pre_reserved, Deposit::get()); | ||||||
|
||||||
// Controller then changes mind and deregisters. | ||||||
assert_ok!(FastUnstake::deregister(RuntimeOrigin::signed(1))); | ||||||
assert_eq!(<T as Config>::Currency::reserved_balance(&1), 0); | ||||||
assert_eq!(<T as Config>::Currency::reserved_balance(&1) - pre_reserved, 0); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
// Ensure stash no longer exists in the queue. | ||||||
assert_eq!(Queue::<T>::get(1), None); | ||||||
|
@@ -243,15 +244,19 @@ mod on_idle { | |||||
CurrentEra::<T>::put(BondingDuration::get()); | ||||||
|
||||||
// given | ||||||
assert_eq!(<T as Config>::Currency::reserved_balance(&1), 0); | ||||||
// reserved balance prior to registering for fast unstake. | ||||||
let pre_reserved = <T as Config>::Currency::reserved_balance(&1); | ||||||
|
||||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(1))); | ||||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(3))); | ||||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(5))); | ||||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(7))); | ||||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(9))); | ||||||
|
||||||
assert_eq!(<T as Config>::Currency::reserved_balance(&1), Deposit::get()); | ||||||
assert_eq!( | ||||||
<T as Config>::Currency::reserved_balance(&1) - pre_reserved, | ||||||
Deposit::get() | ||||||
); | ||||||
|
||||||
assert_eq!(Queue::<T>::count(), 5); | ||||||
assert_eq!(Head::<T>::get(), None); | ||||||
|
@@ -279,6 +284,9 @@ mod on_idle { | |||||
// when | ||||||
next_block(true); | ||||||
|
||||||
// pre_reserve may change due to unstaked amount. | ||||||
let pre_reserved = <T as Config>::Currency::reserved_balance(&1); | ||||||
|
||||||
// then | ||||||
assert_eq!( | ||||||
Head::<T>::get(), | ||||||
|
@@ -289,7 +297,7 @@ mod on_idle { | |||||
); | ||||||
assert_eq!(Queue::<T>::count(), 3); | ||||||
|
||||||
assert_eq!(<T as Config>::Currency::reserved_balance(&1), 0); | ||||||
assert_eq!(<T as Config>::Currency::reserved_balance(&1) - pre_reserved, 0); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
assert_eq!( | ||||||
fast_unstake_events_since_last_call(), | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ use sp_runtime::{ | |
traits::{Bounded, StaticLookup, Zero}, | ||
Perbill, | ||
}; | ||
use sp_staking::EraIndex; | ||
use sp_staking::{EraIndex, StakingUnchecked}; | ||
// `frame_benchmarking::benchmarks!` macro needs this | ||
use pallet_nomination_pools::Call; | ||
|
||
|
@@ -131,6 +131,8 @@ fn migrate_to_transfer_stake<T: Config>(pool_id: PoolId) { | |
) | ||
.expect("member should have enough balance to transfer"); | ||
}); | ||
|
||
pallet_staking::Pallet::<T>::migrate_to_direct_staker(&pool_acc); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not no-op, but it seems to be a fix. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is actually no-op as well. Previously, |
||
} | ||
|
||
fn vote_to_balance<T: pallet_nomination_pools::Config>( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed this since it does not actually migrate to direct staker anymore but only kills agent.