git.delta.rocks / unique-network / refs/commits / 85b56f6a5869

difftreelog

Merge pull request #591 from UniqueNetwork/fix/app-promotion

Yaroslav Bolyukin2022-09-14parents: #dd0a161 #7d1c4da.patch.diff
in: master
Fix/app promotion

3 files changed

modifiedCargo.lockdiffbeforeafterboth
64756475
6476[[package]]6476[[package]]
6477name = "pallet-unique"6477name = "pallet-unique"
6478version = "0.1.4"6478version = "0.2.0"
6479dependencies = [6479dependencies = [
6480 "ethereum",6480 "ethereum",
6481 "evm-coder",6481 "evm-coder",
modifiedpallets/app-promotion/src/lib.rsdiffbeforeafterboth
589 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(|_| {598
599 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 = staked
602 .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 })?;
606606
607 Self::deposit_event(Event::StakingRecalculation(607 Self::deposit_event(Event::StakingRecalculation(
608 last_id.clone(),608 last_id.clone(),
modifiedtests/src/app-promotion.test.tsdiffbeforeafterboth
661 });661 });
662 });662 });
663
664 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);
669
670 // Wait for rewards and pay
671 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));
674
675 const totalStakedAfter = await helper.staking.getTotalStaked();
676 expect(totalStakedAfter >= totalStakedBefore + calculateIncome(100n * nominal, 10n)).to.be.true;
677
678 // staker can unstake
679 await helper.staking.unstake(staker);
680 expect(await helper.staking.getTotalStaked()).to.be.equal(totalStakedAfter - calculateIncome(100n * nominal, 10n));
681 });
682 });
663683
664 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 => {