git.delta.rocks / unique-network / refs/commits / 238065067ad7

difftreelog

Add more tests

Max Andreev2023-01-31parent: #e5f3450.patch.diff
in: master

1 file changed

modifiedtests/src/sub/appPromotion/appPromotion.test.tsdiffbeforeafterboth
91 expect(await helper.staking.getTotalStaked({Substrate: staker.address})).to.equal(100n * nominal);91 expect(await helper.staking.getTotalStaked({Substrate: staker.address})).to.equal(100n * nominal);
92 });92 });
93
94 itSub('should allow to stake() if balance is locked with different id', async ({helper}) => {
95 const staker = accounts.pop()!;
96
97 // staker has tokens locked with vesting id:
98 await helper.balance.vestedTransfer(donor, staker.address, {start: 0n, period: 1n, periodCount: 1n, perPeriod: 200n * nominal});
99 expect(await helper.balance.getSubstrateFull(staker.address))
100 .to.deep.contain({free: 1200n * nominal, miscFrozen: 200n * nominal, feeFrozen: 200n * nominal, reserved: 0n});
101
102 // Locked balance can be staked. staker can stake 1200 tokens (minus fee):
103 await helper.staking.stake(staker, 1000n * nominal);
104 await helper.staking.stake(staker, 199n * nominal);
105 // check balances
106 expect(await helper.balance.getLocked(staker.address)).to.deep.eq([{id: 'ormlvest', amount: 200n * nominal, reasons: 'All'}, {id: 'appstake', amount: 1199n * nominal, reasons: 'All'}]);
107 expect(await helper.balance.getSubstrateFull(staker.address)).to.deep.contain({reserved: 0n, miscFrozen: 1199n * nominal, feeFrozen: 1199n * nominal});
108 expect(await helper.balance.getSubstrate(staker.address) / nominal).to.eq(1199n);
109 expect(await helper.staking.getTotalStaked({Substrate: staker.address})).to.eq(1199n * nominal);
110
111 // staker can unstake
112 await helper.staking.unstake(staker);
113 expect(await helper.staking.getPendingUnstake({Substrate: staker.address})).to.eq(1199n * nominal);
114 const [pendingUnstake] = await helper.staking.getPendingUnstakePerBlock({Substrate: staker.address});
115 await helper.wait.forParachainBlockNumber(pendingUnstake.block);
116
117 // check balances
118 expect(await helper.balance.getLocked(staker.address)).to.deep.eq([{id: 'ormlvest', amount: 200n * nominal, reasons: 'All'}]);
119 expect(await helper.balance.getSubstrateFull(staker.address)).to.deep.contain({reserved: 0n, miscFrozen: 200n * nominal, feeFrozen: 200n * nominal});
120 expect(await helper.balance.getSubstrate(staker.address) / nominal).to.eq(1199n);
121 expect(await helper.staking.getTotalStaked({Substrate: staker.address})).to.eq(0n);
122
123 // staker can transfer balances now
124 await helper.balance.transferToSubstrate(staker, donor.address, 900n * nominal);
125 });
93126
94 itSub('should reject transaction if stake amount is more than total free balance minus frozen', async ({helper}) => {127 itSub('should not allow to stake(), if stake amount is more than total free balance minus locked by staking', async ({helper}) => {
95 const staker = accounts.pop()!;128 const staker = accounts.pop()!;
96129
97 // Can't stake full balance because Alice needs to pay some fee130 // Can't stake full balance because Alice needs to pay some fee
115 });148 });
116149
117 describe('unstake extrinsic', () => {150 describe('unstake extrinsic', () => {
118 itSub('should change balance state from "frozen" to "reserved", add it to "pendingUnstake" map, and subtract it from totalStaked', async ({helper}) => {151 itSub('should move tokens to "pendingUnstake" map and subtract it from totalStaked', async ({helper}) => {
119 const [staker, recepient] = [accounts.pop()!, accounts.pop()!];152 const [staker, recepient] = [accounts.pop()!, accounts.pop()!];
120 const totalStakedBefore = await helper.staking.getTotalStaked();153 const totalStakedBefore = await helper.staking.getTotalStaked();
121 await helper.staking.stake(staker, 900n * nominal);154 await helper.staking.stake(staker, 900n * nominal);
122 await helper.staking.unstake(staker);155 await helper.staking.unstake(staker);
123156
124 // Right after unstake balance is reserved157 // Right after unstake tokens are still locked
125 // Staker can not transfer158 expect(await helper.balance.getLocked(staker.address)).to.deep.eq([{id: 'appstake', amount: 900n * nominal, reasons: 'All'}]);
126 expect(await helper.balance.getSubstrateFull(staker.address)).to.deep.contain({reserved: 0n, miscFrozen: 900n * nominal, feeFrozen: 900n * nominal});159 expect(await helper.balance.getSubstrateFull(staker.address)).to.deep.contain({reserved: 0n, miscFrozen: 900n * nominal, feeFrozen: 900n * nominal});
160 // Staker can not transfer
127 await expect(helper.balance.transferToSubstrate(staker, recepient.address, 100n * nominal)).to.be.rejectedWith('balances.LiquidityRestrictions');161 await expect(helper.balance.transferToSubstrate(staker, recepient.address, 100n * nominal)).to.be.rejectedWith('balances.LiquidityRestrictions');
128 expect(await helper.staking.getPendingUnstake({Substrate: staker.address})).to.be.equal(900n * nominal);162 expect(await helper.staking.getPendingUnstake({Substrate: staker.address})).to.be.equal(900n * nominal);
129 expect(await helper.staking.getTotalStaked({Substrate: staker.address})).to.be.equal(0n);163 expect(await helper.staking.getTotalStaked({Substrate: staker.address})).to.be.equal(0n);
210 expect(unstakingPerBlock[1].amount).to.equal(120n * nominal);244 expect(unstakingPerBlock[1].amount).to.equal(120n * nominal);
211 });245 });
212246
213 itSub('should be possible for different accounts in one block', async ({helper}) => {247 itSub('should be possible for 3 accounts in one block', async ({helper}) => {
214 const stakers = [accounts.pop()!, accounts.pop()!, accounts.pop()!];248 const stakers = [accounts.pop()!, accounts.pop()!, accounts.pop()!];
215249
216 await Promise.all(stakers.map(staker => helper.staking.stake(staker, 100n * nominal)));250 await Promise.all(stakers.map(staker => helper.staking.stake(staker, 100n * nominal)));
222 }));256 }));
223 });257 });
258
259 itSub('should not be possible for more than 3 accounts in one block', async ({helper}) => {
260 if (!await helper.arrange.isDevNode()) {
261 const stakers = await helper.arrange.createAccounts([200n,200n,200n,200n,200n,200n,200n,200n,200n,200n], donor);
262
263 await Promise.all(stakers.map(staker => helper.staking.stake(staker, 100n * nominal)));
264 const unstakingResults = await Promise.allSettled(stakers.map(staker => helper.staking.unstake(staker)));
265
266 const successfulUnstakes = unstakingResults.filter(result => result.status === 'fulfilled');
267 expect(successfulUnstakes).to.have.length(3);
268 }
269 });
224 });270 });
225271
226 describe('collection sponsoring', () => {272 describe('collection sponsoring', () => {
599 expect(stakerFullBalance).to.contain({reserved: 0n, feeFrozen: frozenBalanceShouldBe, miscFrozen: frozenBalanceShouldBe});645 expect(stakerFullBalance).to.contain({reserved: 0n, feeFrozen: frozenBalanceShouldBe, miscFrozen: frozenBalanceShouldBe});
600 });646 });
601647
602 itSub('should not be credited for unstaked (reserved) balance', async ({helper}) => {648 itSub('should not be credited for pending-unstaked tokens', async ({helper}) => {
603 // staker unstakes before rewards has been payed649 // staker unstakes before rewards been payed
604 const staker = accounts.pop()!;650 const staker = accounts.pop()!;
605 await helper.staking.stake(staker, 100n * nominal);651 await helper.staking.stake(staker, 100n * nominal);
606 const [stake] = await helper.staking.getTotalStakedPerBlock({Substrate: staker.address});652 const [stake] = await helper.staking.getTotalStakedPerBlock({Substrate: staker.address});