difftreelog
fix totalstaked calc bug
in: master
3 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6475,7 +6475,7 @@
[[package]]
name = "pallet-unique"
-version = "0.1.4"
+version = "0.2.0"
dependencies = [
"ethereum",
"evm-coder",
pallets/app-promotion/src/lib.rsdiffbeforeafterboth589 let flush_stake = || -> DispatchResult {589 let flush_stake = || -> DispatchResult {590 if let Some(last_id) = &*last_id.borrow() {590 if let Some(last_id) = &*last_id.borrow() {591 if !income_acc.borrow().is_zero() {591 if !income_acc.borrow().is_zero() {592 <T::Currency as Currency<T::AccountId>>::transfer(592 <T::Currency as Currency<T::AccountId>>::transfer(593 &T::TreasuryAccountId::get(),593 &T::TreasuryAccountId::get(),594 last_id,594 last_id,595 *income_acc.borrow(),595 *income_acc.borrow(),596 ExistenceRequirement::KeepAlive,596 ExistenceRequirement::KeepAlive,597 )597 )?;598 .and_then(|_| {598599 Self::add_lock_balance(last_id, *income_acc.borrow())?;599 Self::add_lock_balance(last_id, *income_acc.borrow())?;600 <TotalStaked<T>>::try_mutate(|staked| {600 <TotalStaked<T>>::try_mutate(|staked| -> DispatchResult {601 staked601 *staked = staked602 .checked_add(&*income_acc.borrow())602 .checked_add(&*income_acc.borrow())603 .ok_or(ArithmeticError::Overflow.into())603 .ok_or(ArithmeticError::Overflow)?;604 Ok(())604 })605 })?;605 })?;606606607 Self::deposit_event(Event::StakingRecalculation(607 Self::deposit_event(Event::StakingRecalculation(608 last_id.clone(),608 last_id.clone(),tests/src/app-promotion.test.tsdiffbeforeafterboth--- a/tests/src/app-promotion.test.ts
+++ b/tests/src/app-promotion.test.ts
@@ -661,7 +661,7 @@
});
});
- it.only('should increase total staked', async() => {
+ it('should increase total staked', async() => {
await usingPlaygrounds(async (helper) => {
const staker = accounts.pop()!;
const totalStakedBefore = await helper.staking.getTotalStaked();
@@ -673,12 +673,11 @@
await helper.signTransaction(palletAdmin, helper.api!.tx.appPromotion.payoutStakers(100));
const totalStakedAfter = await helper.staking.getTotalStaked();
- const stakersStakedBalance = totalStakedBefore + calculateIncome(100n * nominal, 10n);
- expect(totalStakedAfter >= stakersStakedBalance).to.be.true;
+ expect(totalStakedAfter >= totalStakedBefore + calculateIncome(100n * nominal, 10n)).to.be.true;
// staker can unstake
await helper.staking.unstake(staker);
- expect(await helper.staking.getTotalStaked()).to.be.equal(totalStakedAfter - stakersStakedBalance);
+ expect(await helper.staking.getTotalStaked()).to.be.equal(totalStakedAfter - calculateIncome(100n * nominal, 10n));
});
});