difftreelog
Merge branch 'develop' into tests/eth-helpers
in: master
3 files changed
tests/src/app-promotion.test.tsdiffbeforeafterboth57 // Staker balance is: miscFrozen: 100, feeFrozen: 100, reserved: 0n...57 // Staker balance is: miscFrozen: 100, feeFrozen: 100, reserved: 0n...58 // ...so he can not transfer 90058 // ...so he can not transfer 90059 expect (await helper.balance.getSubstrateFull(staker.address)).to.contain({miscFrozen: 100n * nominal, feeFrozen: 100n * nominal, reserved: 0n});59 expect(await helper.balance.getSubstrateFull(staker.address)).to.contain({miscFrozen: 100n * nominal, feeFrozen: 100n * nominal, reserved: 0n});60 expect(await helper.balance.getLocked(staker.address)).to.deep.eq([{id: 'appstake', amount: 100n * nominal, reasons: 'All'}]);60 await expect(helper.balance.transferToSubstrate(staker, recepient.address, 900n * nominal)).to.be.rejectedWith('balances.LiquidityRestrictions');61 await expect(helper.balance.transferToSubstrate(staker, recepient.address, 900n * nominal)).to.be.rejectedWith('balances.LiquidityRestrictions');61 62 62 expect(await helper.staking.getTotalStaked({Substrate: staker.address})).to.be.equal(100n * nominal);63 expect(await helper.staking.getTotalStaked({Substrate: staker.address})).to.be.equal(100n * nominal);530 });531 });531 });532 });532 533 533 describe('rewards', () => {534 describe('payoutStakers', () => {534 itSub('can not be called by non admin', async ({helper}) => {535 itSub('can not be called by non admin', async ({helper}) => {535 const nonAdmin = accounts.pop()!;536 const nonAdmin = accounts.pop()!;536 await expect(helper.admin.payoutStakers(nonAdmin, 100)).to.be.rejectedWith('appPromotion.NoPermission');537 await expect(helper.admin.payoutStakers(nonAdmin, 100)).to.be.rejectedWith('appPromotion.NoPermission');569 expect(payoutToStaker + 300n * nominal).to.equal(calculateIncome(300n * nominal));570 expect(payoutToStaker + 300n * nominal).to.equal(calculateIncome(300n * nominal));570 571 571 const totalStakedPerBlock = await helper.staking.getTotalStakedPerBlock({Substrate: staker.address});572 const totalStakedPerBlock = await helper.staking.getTotalStakedPerBlock({Substrate: staker.address});573 const income1 = calculateIncome(100n * nominal);574 const income2 = calculateIncome(200n * nominal);572 expect(totalStakedPerBlock[0].amount).to.equal(calculateIncome(100n * nominal));575 expect(totalStakedPerBlock[0].amount).to.equal(income1);573 expect(totalStakedPerBlock[1].amount).to.equal(calculateIncome(200n * nominal));576 expect(totalStakedPerBlock[1].amount).to.equal(income2);577578 const stakerBalance = await helper.balance.getSubstrateFull(staker.address);579 expect(stakerBalance).to.contain({miscFrozen: income1 + income2, feeFrozen: income1 + income2, reserved: 0n});580 expect(stakerBalance.free / nominal).to.eq(999n);574 });581 });575 582 576 itSub('shoud be paid for more than one period if payments was missed', async ({helper}) => {583 itSub('shoud be paid for more than one period if payments was missed', async ({helper}) => {tests/src/util/playgrounds/unique.tsdiffbeforeafterboth2199 return (await this.helper.callRpc('api.rpc.chain.getBlock', [blockHash])).toHuman().block;2199 return (await this.helper.callRpc('api.rpc.chain.getBlock', [blockHash])).toHuman().block;2200 }2200 }22012202 /**2203 * Get latest relay block2204 * @returns {number} relay block2205 */2206 async getRelayBlockNumber(): Promise<bigint> {2207 const blockNumber = (await this.helper.callRpc('api.query.parachainSystem.validationData')).toJSON().relayParentNumber;2208 return BigInt(blockNumber);2209 }220122102202 /**2211 /**2203 * Get account nonce2212 * Get account nonce2258 return {free: accountInfo.free.toBigInt(), miscFrozen: accountInfo.miscFrozen.toBigInt(), feeFrozen: accountInfo.feeFrozen.toBigInt(), reserved: accountInfo.reserved.toBigInt()};2267 return {free: accountInfo.free.toBigInt(), miscFrozen: accountInfo.miscFrozen.toBigInt(), feeFrozen: accountInfo.feeFrozen.toBigInt(), reserved: accountInfo.reserved.toBigInt()};2259 }2268 }22692270 async getLocked(address: TSubstrateAccount): Promise<[{id: string, amount: bigint, reason: string}]> {2271 const locks = (await this.helper.callRpc('api.query.balances.locks', [address])).toHuman();2272 return locks.map((lock: any) => {return {id: lock.id, amount: BigInt(lock.amount.replace(/,/g, '')), reasons: lock.reasons};});2273 }2260}2274}226122752262class EthereumBalanceGroup<T extends ChainHelperBase> extends HelperGroup<T> {2276class EthereumBalanceGroup<T extends ChainHelperBase> extends HelperGroup<T> {2340 return this.subBalanceGroup.getSubstrateFull(address);2354 return this.subBalanceGroup.getSubstrateFull(address);2341 }2355 }23562357 /**2358 * Get locked balances2359 * @param address substrate address2360 * @returns locked balances with reason via api.query.balances.locks2361 */2362 getLocked(address: TSubstrateAccount) {2363 return this.subBalanceGroup.getLocked(address);2364 }234223652343 /**2366 /**2344 * Get ethereum address balance2367 * Get ethereum address balance2381 return isSuccess;2404 return isSuccess;2382 }2405 }24062407 /**2408 * Transfer tokens with the unlock period2409 * @param signer signers Keyring2410 * @param address Substrate address of recipient2411 * @param schedule Schedule params2412 * @example vestedTransfer(signer, recepient.address, 20000, 100, 10, 50 * nominal); // total amount of vested tokens will be 100 * 50 = 50002413 */2414 async vestedTransfer(signer: TSigner, address: TSubstrateAccount, schedule: {start: bigint, period: bigint, periodCount: bigint, perPeriod: bigint}): Promise<void> {2415 const result = await this.helper.executeExtrinsic(signer, 'api.tx.vesting.vestedTransfer', [address, schedule]);2416 const event = result.result.events2417 .find(e => e.event.section === 'vesting' &&2418 e.event.method === 'VestingScheduleAdded' &&2419 e.event.data[0].toHuman() === signer.address);2420 if (!event) throw Error('Cannot find transfer in events');2421 }24222423 /**2424 * Get schedule for recepient of vested transfer2425 * @param address Substrate address of recipient2426 * @returns 2427 */2428 async getVestingSchedules(address: TSubstrateAccount): Promise<{start: bigint, period: bigint, periodCount: bigint, perPeriod: bigint}[]> {2429 const schedule = (await this.helper.callRpc('api.query.vesting.vestingSchedules', [address])).toJSON();2430 return schedule.map((schedule: any) => {2431 return {2432 start: BigInt(schedule.start),2433 period: BigInt(schedule.period),2434 periodCount: BigInt(schedule.periodCount),2435 perPeriod: BigInt(schedule.perPeriod),2436 };2437 });2438 }24392440 /**2441 * Claim vested tokens2442 * @param signer signers Keyring2443 */2444 async claim(signer: TSigner) {2445 const result = await this.helper.executeExtrinsic(signer, 'api.tx.vesting.claim', []);2446 const event = result.result.events2447 .find(e => e.event.section === 'vesting' &&2448 e.event.method === 'Claimed' &&2449 e.event.data[0].toHuman() === signer.address);2450 if (!event) throw Error('Cannot find claim in events');2451 }2383}2452}238424532385class AddressGroup extends HelperGroup<ChainHelperBase> {2454class AddressGroup extends HelperGroup<ChainHelperBase> {tests/src/vesting.test.tsdiffbeforeafterbothno changes