difftreelog
Add tests for trash-stakes rewards
in: master
1 file changed
tests/src/sub/appPromotion/appPromotion.test.tsdiffbeforeafterboth360 await helper.staking.stake(staker, 200n * nominal);360 await helper.staking.stake(staker, 200n * nominal);361361362 // cannot usntake 300.00000...1362 // cannot usntake 300.00000...1363 await expect(helper.staking.unstakePartial(staker, 300n * nominal + 1n)).to.be.rejectedWith('Arithmetic: Underflow');363 await expect(helper.staking.unstakePartial(staker, 300n * nominal + 1n)).to.be.rejectedWith('appPromotion.InsufficientStakedBalance');364 expect(await helper.staking.getStakesNumber({Substrate: staker.address})).eq(2);364 expect(await helper.staking.getStakesNumber({Substrate: staker.address})).eq(2);365365366 await helper.staking.unstakePartial(staker, 150n * nominal);366 await helper.staking.unstakePartial(staker, 150n * nominal);367 expect(await helper.staking.getStakesNumber({Substrate: staker.address})).eq(1);367 expect(await helper.staking.getStakesNumber({Substrate: staker.address})).eq(1);368 await expect(helper.staking.unstakePartial(staker, 150n * nominal + 1n)).to.be.rejectedWith('Arithmetic: Underflow');368 await expect(helper.staking.unstakePartial(staker, 150n * nominal + 1n)).to.be.rejectedWith('appPromotion.InsufficientStakedBalance');369 expect(await helper.staking.getStakesNumber({Substrate: staker.address})).eq(1);369 expect(await helper.staking.getStakesNumber({Substrate: staker.address})).eq(1);370370371 // nothing broken, can unstake full amount:371 // nothing broken, can unstake full amount:840 expect(stake.amount).to.equal(calculateIncome(100n * nominal, 2));840 expect(stake.amount).to.equal(calculateIncome(100n * nominal, 2));841 });841 });842842843 itSub.skip('can be paid 1000 rewards in a time', async ({helper}) => {843 itSub('can calculate reward for tiny stake', async ({helper}) => {844 // all other stakes should be unstaked845 const oneHundredStakers = await helper.arrange.createCrowd(100, 1050n, donor);844 const staker = accounts.pop()!;846845 await helper.staking.stake(staker, 100n * nominal);847 // stakers stakes 10 times each848 for (let i = 0; i < 10; i++) {849 await Promise.all(oneHundredStakers.map(staker => helper.staking.stake(staker, 100n * nominal)));846 await helper.staking.stake(staker, 100n * nominal);850 }847 await helper.staking.unstakePartial(staker, 100n * nominal - 1n);848849 const [stake] = await helper.staking.getTotalStakedPerBlock({Substrate: staker.address});851 await helper.wait.newBlocks(40);850 await helper.wait.forRelayBlockNumber(rewardAvailableInBlock(stake.block));851852 await helper.admin.payoutStakers(palletAdmin, 100);852 const payouts = await helper.admin.payoutStakers(palletAdmin, 100);853 const stakerPayout = payouts.find(p => p.staker === staker.address);854 expect(stakerPayout!.stake).to.eq(100n * nominal + 1n);853 });855 });854856855 itSub.skip('can handle 40.000 rewards', async ({helper}) => {857 itSub('can eventually pay all rewards', async ({helper}) => {856 const crowdStakes = async () => {858 const stakers = await helper.arrange.createAccounts(new Array(100).fill(200n), donor);857 // each account in the crowd stakes 2 times858 const crowd = await helper.arrange.createCrowd(500, 300n, donor);859 await Promise.all(crowd.map(account => helper.staking.stake(account, 100n * nominal)));859 await Promise.all(stakers.map(staker => helper.staking.stake(staker, 100n * nominal)));860861 let unstakingTxs = [];862 for (const staker of stakers) {863 if (unstakingTxs.length == 3) {864 await Promise.all(unstakingTxs);865 unstakingTxs = [];866 }860 await Promise.all(crowd.map(account => helper.staking.stake(account, 100n * nominal)));867 unstakingTxs.push(helper.staking.unstakePartial(staker, 100n * nominal - 1n));861 //868 }869862 };870 const [staker] = await helper.arrange.createAccounts([1000n], donor);863864 for (let i = 0; i < 40; i++) {871 await helper.staking.stake(staker, 100n * nominal);872 const [stake] = await helper.staking.getTotalStakedPerBlock({Substrate: staker.address});873 await helper.wait.forRelayBlockNumber(rewardAvailableInBlock(stake.block));874875 let payouts;876 do {865 await crowdStakes();877 payouts = await helper.admin.payoutStakers(palletAdmin, 20);866 }878 } while (payouts.length !== 0);867868 // TODO pay rewards for some period869 });879 });870 });880 });871});881});