difftreelog
Merge pull request #742 from UniqueNetwork/tests/vesting
in: master
3 files changed
tests/src/app-promotion.test.tsdiffbeforeafterboth--- a/tests/src/app-promotion.test.ts
+++ b/tests/src/app-promotion.test.ts
@@ -56,7 +56,8 @@
// Staker balance is: miscFrozen: 100, feeFrozen: 100, reserved: 0n...
// ...so he can not transfer 900
- expect (await helper.balance.getSubstrateFull(staker.address)).to.contain({miscFrozen: 100n * nominal, feeFrozen: 100n * nominal, reserved: 0n});
+ expect(await helper.balance.getSubstrateFull(staker.address)).to.contain({miscFrozen: 100n * nominal, feeFrozen: 100n * nominal, reserved: 0n});
+ expect(await helper.balance.getLocked(staker.address)).to.deep.eq([{id: 'appstake', amount: 100n * nominal, reasons: 'All'}]);
await expect(helper.balance.transferToSubstrate(staker, recepient.address, 900n * nominal)).to.be.rejectedWith('balances.LiquidityRestrictions');
expect(await helper.staking.getTotalStaked({Substrate: staker.address})).to.be.equal(100n * nominal);
@@ -530,7 +531,7 @@
});
});
- describe('rewards', () => {
+ describe('payoutStakers', () => {
itSub('can not be called by non admin', async ({helper}) => {
const nonAdmin = accounts.pop()!;
await expect(helper.admin.payoutStakers(nonAdmin, 100)).to.be.rejectedWith('appPromotion.NoPermission');
@@ -569,8 +570,14 @@
expect(payoutToStaker + 300n * nominal).to.equal(calculateIncome(300n * nominal));
const totalStakedPerBlock = await helper.staking.getTotalStakedPerBlock({Substrate: staker.address});
- expect(totalStakedPerBlock[0].amount).to.equal(calculateIncome(100n * nominal));
- expect(totalStakedPerBlock[1].amount).to.equal(calculateIncome(200n * nominal));
+ const income1 = calculateIncome(100n * nominal);
+ const income2 = calculateIncome(200n * nominal);
+ expect(totalStakedPerBlock[0].amount).to.equal(income1);
+ expect(totalStakedPerBlock[1].amount).to.equal(income2);
+
+ const stakerBalance = await helper.balance.getSubstrateFull(staker.address);
+ expect(stakerBalance).to.contain({miscFrozen: income1 + income2, feeFrozen: income1 + income2, reserved: 0n});
+ expect(stakerBalance.free / nominal).to.eq(999n);
});
itSub('shoud be paid for more than one period if payments was missed', async ({helper}) => {
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -2200,6 +2200,15 @@
}
/**
+ * Get latest relay block
+ * @returns {number} relay block
+ */
+ async getRelayBlockNumber(): Promise<bigint> {
+ const blockNumber = (await this.helper.callRpc('api.query.parachainSystem.validationData')).toJSON().relayParentNumber;
+ return BigInt(blockNumber);
+ }
+
+ /**
* Get account nonce
* @param address substrate address
* @example getNonce("5GrwvaEF5zXb26Fz...");
@@ -2257,6 +2266,11 @@
const accountInfo = (await this.helper.callRpc('api.query.system.account', [address])).data;
return {free: accountInfo.free.toBigInt(), miscFrozen: accountInfo.miscFrozen.toBigInt(), feeFrozen: accountInfo.feeFrozen.toBigInt(), reserved: accountInfo.reserved.toBigInt()};
}
+
+ async getLocked(address: TSubstrateAccount): Promise<[{id: string, amount: bigint, reason: string}]> {
+ const locks = (await this.helper.callRpc('api.query.balances.locks', [address])).toHuman();
+ return locks.map((lock: any) => {return {id: lock.id, amount: BigInt(lock.amount.replace(/,/g, '')), reasons: lock.reasons};});
+ }
}
class EthereumBalanceGroup<T extends ChainHelperBase> extends HelperGroup<T> {
@@ -2341,6 +2355,15 @@
}
/**
+ * Get locked balances
+ * @param address substrate address
+ * @returns locked balances with reason via api.query.balances.locks
+ */
+ getLocked(address: TSubstrateAccount) {
+ return this.subBalanceGroup.getLocked(address);
+ }
+
+ /**
* Get ethereum address balance
* @param address ethereum address
* @example getEthereum("0x9F0583DbB855d...")
@@ -2380,6 +2403,52 @@
isSuccess = isSuccess && BigInt(amount) === transfer.amount;
return isSuccess;
}
+
+ /**
+ * Transfer tokens with the unlock period
+ * @param signer signers Keyring
+ * @param address Substrate address of recipient
+ * @param schedule Schedule params
+ * @example vestedTransfer(signer, recepient.address, 20000, 100, 10, 50 * nominal); // total amount of vested tokens will be 100 * 50 = 5000
+ */
+ async vestedTransfer(signer: TSigner, address: TSubstrateAccount, schedule: {start: bigint, period: bigint, periodCount: bigint, perPeriod: bigint}): Promise<void> {
+ const result = await this.helper.executeExtrinsic(signer, 'api.tx.vesting.vestedTransfer', [address, schedule]);
+ const event = result.result.events
+ .find(e => e.event.section === 'vesting' &&
+ e.event.method === 'VestingScheduleAdded' &&
+ e.event.data[0].toHuman() === signer.address);
+ if (!event) throw Error('Cannot find transfer in events');
+ }
+
+ /**
+ * Get schedule for recepient of vested transfer
+ * @param address Substrate address of recipient
+ * @returns
+ */
+ async getVestingSchedules(address: TSubstrateAccount): Promise<{start: bigint, period: bigint, periodCount: bigint, perPeriod: bigint}[]> {
+ const schedule = (await this.helper.callRpc('api.query.vesting.vestingSchedules', [address])).toJSON();
+ return schedule.map((schedule: any) => {
+ return {
+ start: BigInt(schedule.start),
+ period: BigInt(schedule.period),
+ periodCount: BigInt(schedule.periodCount),
+ perPeriod: BigInt(schedule.perPeriod),
+ };
+ });
+ }
+
+ /**
+ * Claim vested tokens
+ * @param signer signers Keyring
+ */
+ async claim(signer: TSigner) {
+ const result = await this.helper.executeExtrinsic(signer, 'api.tx.vesting.claim', []);
+ const event = result.result.events
+ .find(e => e.event.section === 'vesting' &&
+ e.event.method === 'Claimed' &&
+ e.event.data[0].toHuman() === signer.address);
+ if (!event) throw Error('Cannot find claim in events');
+ }
}
class AddressGroup extends HelperGroup<ChainHelperBase> {
tests/src/vesting.test.tsdiffbeforeafterbothno changes