difftreelog
fix unstake
in: master
2 files changed
pallets/app-promotion/src/lib.rsdiffbeforeafterboth--- a/pallets/app-promotion/src/lib.rs
+++ b/pallets/app-promotion/src/lib.rs
@@ -358,7 +358,7 @@
let block = <frame_system::Pallet<T>>::block_number() + T::PendingInterval::get();
let mut pendings = <PendingUnstake<T>>::get(block);
- ensure!(pendings.is_full(), Error::<T>::PendingForBlockOverflow);
+ ensure!(!pendings.is_full(), Error::<T>::PendingForBlockOverflow);
let mut total_stakes = 0u64;
@@ -370,7 +370,7 @@
.sum();
if total_staked.is_zero() {
- return Ok(None.into());
+ return Ok(None.into()); // TO-DO
}
pendings
@@ -387,7 +387,7 @@
TotalStaked::<T>::get()
.checked_sub(&total_staked)
.ok_or(ArithmeticError::Underflow)?,
- ); // when error we should recover initial stake state for the staker
+ );
StakesPerAccount::<T>::remove(&staker_id);
@@ -474,46 +474,46 @@
let next_recalc_block = current_recalc_block + T::RecalculationInterval::get();
let mut storage_iterator = Self::get_next_calculated_key()
- .map_or(Staked::<T>::iter().skip(0), |key| {
- Staked::<T>::iter_from(key).skip(1)
+ .map_or(Staked::<T>::iter(), |key| {
+ Staked::<T>::iter_from(key)
});
NextCalculatedRecord::<T>::set(None);
{
let mut stakers_number = stakers_number.unwrap_or(20);
- let mut current_id = admin_id;
+ let mut last_id = admin_id;
let mut income_acc = BalanceOf::<T>::default();
- while let Some(((id, staked_block), (amount, next_recalc_block_for_stake))) =
+ while let Some(((current_id, staked_block), (amount, next_recalc_block_for_stake))) =
storage_iterator.next()
{
- if current_id != id {
+ if last_id != current_id {
if income_acc != BalanceOf::<T>::default() {
<T::Currency as Currency<T::AccountId>>::transfer(
&T::TreasuryAccountId::get(),
- ¤t_id,
+ &last_id,
income_acc,
ExistenceRequirement::KeepAlive,
)
- .and_then(|_| Self::add_lock_balance(¤t_id, income_acc))?;
+ .and_then(|_| Self::add_lock_balance(&last_id, income_acc))?;
Self::deposit_event(Event::StakingRecalculation(
- current_id, amount, income_acc,
+ last_id, amount, income_acc,
));
}
if stakers_number == 0 {
- NextCalculatedRecord::<T>::set(Some((id, staked_block)));
+ NextCalculatedRecord::<T>::set(Some((current_id, staked_block)));
break;
}
stakers_number -= 1;
income_acc = BalanceOf::<T>::default();
- current_id = id;
+ last_id = current_id;
};
if current_recalc_block >= next_recalc_block_for_stake {
Self::recalculate_and_insert_stake(
- ¤t_id,
+ &last_id,
staked_block,
next_recalc_block,
amount,
tests/src/app-promotion.test.tsdiffbeforeafterboth51 if (!promotionStartBlock) {51 if (!promotionStartBlock) {52 promotionStartBlock = (await helper.api!.query.parachainSystem.lastRelayChainBlockNumber()).toNumber();52 promotionStartBlock = (await helper.api!.query.parachainSystem.lastRelayChainBlockNumber()).toNumber();53 }53 }54 await helper.signTransaction(alice, helper.api!.tx.sudo.sudo(helper.api!.tx.promotion.startAppPromotion(promotionStartBlock!)));55 accounts = await helper.arrange.createCrowd(100, 1000n, alice); // create accounts-pool to speed up tests54 accounts = await helper.arrange.createCrowd(100, 1000n, alice); // create accounts-pool to speed up tests56 });55 });57});56});585759after(async function () {58after(async function () {60 await usingPlaygrounds(async (helper) => {59 await usingPlaygrounds(async (helper) => {61 await helper.signTransaction(alice, helper.api!.tx.sudo.sudo(helper.api!.tx.promotion.stopAppPromotion()));62 });60 });63});61});6462241239242 it('should be possible for different accounts in one block', async () => {240 it('should be possible for different accounts in one block', async () => {243 await usingPlaygrounds(async (helper) => {241 await usingPlaygrounds(async (helper) => {244 const stakers = [accounts.pop()!, accounts.pop()!, accounts.pop()!, accounts.pop()!, accounts.pop()!];242 const stakers = [accounts.pop()!, accounts.pop()!, accounts.pop()!];245243246 await Promise.all(stakers.map(staker => helper.staking.stake(staker, 100n * nominal)));244 await Promise.all(stakers.map(staker => helper.staking.stake(staker, 100n * nominal)));247 await Promise.all(stakers.map(staker => helper.staking.unstake(staker)));245 await Promise.all(stakers.map(staker => helper.staking.unstake(staker)));