git.delta.rocks / unique-network / refs/commits / 7d1c4da161ca

difftreelog

fix totalstaked calc bug

PraetorP2022-09-14parent: #0384755.patch.diff
in: master

3 files changed

modifiedCargo.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",
modifiedpallets/app-promotion/src/lib.rsdiffbeforeafterboth
--- a/pallets/app-promotion/src/lib.rs
+++ b/pallets/app-promotion/src/lib.rs
@@ -594,14 +594,14 @@
 								last_id,
 								*income_acc.borrow(),
 								ExistenceRequirement::KeepAlive,
-							)
-							.and_then(|_| {
-								Self::add_lock_balance(last_id, *income_acc.borrow())?;
-								<TotalStaked<T>>::try_mutate(|staked| {
-									staked
-										.checked_add(&*income_acc.borrow())
-										.ok_or(ArithmeticError::Overflow.into())
-								})
+							)?;
+
+							Self::add_lock_balance(last_id, *income_acc.borrow())?;
+							<TotalStaked<T>>::try_mutate(|staked| -> DispatchResult {
+								*staked = staked
+									.checked_add(&*income_acc.borrow())
+									.ok_or(ArithmeticError::Overflow)?;
+								Ok(())
 							})?;
 
 							Self::deposit_event(Event::StakingRecalculation(
modifiedtests/src/app-promotion.test.tsdiffbeforeafterboth
661 });661 });
662 });662 });
663663
664 it.only('should increase total staked', async() => {664 it('should increase total staked', async() => {
665 await usingPlaygrounds(async (helper) => {665 await usingPlaygrounds(async (helper) => {
666 const staker = accounts.pop()!;666 const staker = accounts.pop()!;
667 const totalStakedBefore = await helper.staking.getTotalStaked();667 const totalStakedBefore = await helper.staking.getTotalStaked();
673 await helper.signTransaction(palletAdmin, helper.api!.tx.appPromotion.payoutStakers(100));673 await helper.signTransaction(palletAdmin, helper.api!.tx.appPromotion.payoutStakers(100));
674674
675 const totalStakedAfter = await helper.staking.getTotalStaked();675 const totalStakedAfter = await helper.staking.getTotalStaked();
676 const stakersStakedBalance = totalStakedBefore + calculateIncome(100n * nominal, 10n);
677 expect(totalStakedAfter >= stakersStakedBalance).to.be.true;676 expect(totalStakedAfter >= totalStakedBefore + calculateIncome(100n * nominal, 10n)).to.be.true;
678677
679 // staker can unstake678 // staker can unstake
680 await helper.staking.unstake(staker);679 await helper.staking.unstake(staker);
681 expect(await helper.staking.getTotalStaked()).to.be.equal(totalStakedAfter - stakersStakedBalance);680 expect(await helper.staking.getTotalStaked()).to.be.equal(totalStakedAfter - calculateIncome(100n * nominal, 10n));
682 });681 });
683 });682 });
684683