difftreelog
Add vesting e2e test and helpers
in: master
2 files changed
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -2146,6 +2146,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...");
@@ -2326,6 +2335,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: {startRelayBlock: bigint, periodBlocks: bigint, periodCount: bigint, perPeriod: bigint}): Promise<void> {
+ const result = await this.helper.executeExtrinsic(signer, 'api.tx.vesting.vestedTransfer', [address, {start: schedule.startRelayBlock, period: schedule.periodBlocks, periodCount: schedule.periodCount, perPeriod: schedule.perPeriod}]);
+ 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<{startRelayBlock: bigint, periodBlocks: bigint, periodCount: bigint, perPeriod: bigint}[]> {
+ const schedule = (await this.helper.callRpc('api.query.vesting.vestingSchedules', [address])).toJSON();
+ return schedule.map((schedule: any) => {
+ return {
+ startRelayBlock: BigInt(schedule.start),
+ periodBlocks: 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