difftreelog
Merge pull request #591 from UniqueNetwork/fix/app-promotion
in: master
Fix/app promotion
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.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(
tests/src/app-promotion.test.tsdiffbeforeafterboth661 });661 });662 });662 });663664 it('should increase total staked', async() => {665 await usingPlaygrounds(async (helper) => {666 const staker = accounts.pop()!;667 const totalStakedBefore = await helper.staking.getTotalStaked();668 await helper.staking.stake(staker, 100n * nominal);669670 // Wait for rewards and pay671 const stakedInBlock = (await helper.staking.getTotalStakedPerBlock({Substrate: staker.address}))[0][0];672 await helper.wait.forRelayBlockNumber(rewardAvailableInBlock(stakedInBlock));673 await helper.signTransaction(palletAdmin, helper.api!.tx.appPromotion.payoutStakers(100));674675 const totalStakedAfter = await helper.staking.getTotalStaked();676 expect(totalStakedAfter >= totalStakedBefore + calculateIncome(100n * nominal, 10n)).to.be.true;677678 // staker can unstake679 await helper.staking.unstake(staker);680 expect(await helper.staking.getTotalStaked()).to.be.equal(totalStakedAfter - calculateIncome(100n * nominal, 10n));681 });682 });663683664 it('should credit 0.05% for staking period', async () => { 684 it('should credit 0.05% for staking period', async () => { 665 await usingPlaygrounds(async helper => {685 await usingPlaygrounds(async helper => {