From 85b56f6a586955f7b79a0b45c2dd055be3fd3f39 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Wed, 14 Sep 2022 15:53:43 +0000 Subject: [PATCH] Merge pull request #591 from UniqueNetwork/fix/app-promotion Fix/app promotion --- --- 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", --- 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())?; - >::try_mutate(|staked| { - staked - .checked_add(&*income_acc.borrow()) - .ok_or(ArithmeticError::Overflow.into()) - }) + )?; + + Self::add_lock_balance(last_id, *income_acc.borrow())?; + >::try_mutate(|staked| -> DispatchResult { + *staked = staked + .checked_add(&*income_acc.borrow()) + .ok_or(ArithmeticError::Overflow)?; + Ok(()) })?; Self::deposit_event(Event::StakingRecalculation( --- a/tests/src/app-promotion.test.ts +++ b/tests/src/app-promotion.test.ts @@ -661,6 +661,26 @@ }); }); + it('should increase total staked', async() => { + await usingPlaygrounds(async (helper) => { + const staker = accounts.pop()!; + const totalStakedBefore = await helper.staking.getTotalStaked(); + await helper.staking.stake(staker, 100n * nominal); + + // Wait for rewards and pay + const stakedInBlock = (await helper.staking.getTotalStakedPerBlock({Substrate: staker.address}))[0][0]; + await helper.wait.forRelayBlockNumber(rewardAvailableInBlock(stakedInBlock)); + await helper.signTransaction(palletAdmin, helper.api!.tx.appPromotion.payoutStakers(100)); + + const totalStakedAfter = await helper.staking.getTotalStaked(); + 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 - calculateIncome(100n * nominal, 10n)); + }); + }); + it('should credit 0.05% for staking period', async () => { await usingPlaygrounds(async helper => { const staker = accounts.pop()!; -- gitstuff