difftreelog
Add vesting e2e test and helpers
in: master
2 files changed
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth2145 return (await this.helper.callRpc('api.rpc.chain.getBlock', [blockHash])).toHuman().block;2145 return (await this.helper.callRpc('api.rpc.chain.getBlock', [blockHash])).toHuman().block;2146 }2146 }21472148 /**2149 * Get latest relay block2150 * @returns {number} relay block2151 */2152 async getRelayBlockNumber(): Promise<bigint> {2153 const blockNumber = (await this.helper.callRpc('api.query.parachainSystem.validationData')).toJSON().relayParentNumber;2154 return BigInt(blockNumber);2155 }214721562148 /**2157 /**2149 * Get account nonce2158 * Get account nonce2327 return isSuccess;2336 return isSuccess;2328 }2337 }23382339 /**2340 * Transfer tokens with the unlock period2341 * @param signer signers Keyring2342 * @param address Substrate address of recipient2343 * @param schedule Schedule params2344 * @example vestedTransfer(signer, recepient.address, 20000, 100, 10, 50 * nominal); // total amount of vested tokens will be 100 * 50 = 50002345 */2346 async vestedTransfer(signer: TSigner, address: TSubstrateAccount, schedule: {startRelayBlock: bigint, periodBlocks: bigint, periodCount: bigint, perPeriod: bigint}): Promise<void> {2347 const result = await this.helper.executeExtrinsic(signer, 'api.tx.vesting.vestedTransfer', [address, {start: schedule.startRelayBlock, period: schedule.periodBlocks, periodCount: schedule.periodCount, perPeriod: schedule.perPeriod}]);2348 const event = result.result.events2349 .find(e => e.event.section === 'vesting' &&2350 e.event.method === 'VestingScheduleAdded' &&2351 e.event.data[0].toHuman() === signer.address);2352 if (!event) throw Error('Cannot find transfer in events');2353 }23542355 /**2356 * Get schedule for recepient of vested transfer2357 * @param address Substrate address of recipient2358 * @returns 2359 */2360 async getVestingSchedules(address: TSubstrateAccount): Promise<{startRelayBlock: bigint, periodBlocks: bigint, periodCount: bigint, perPeriod: bigint}[]> {2361 const schedule = (await this.helper.callRpc('api.query.vesting.vestingSchedules', [address])).toJSON();2362 return schedule.map((schedule: any) => {2363 return {2364 startRelayBlock: BigInt(schedule.start),2365 periodBlocks: BigInt(schedule.period),2366 periodCount: BigInt(schedule.periodCount),2367 perPeriod: BigInt(schedule.perPeriod),2368 };2369 });2370 }23712372 /**2373 * Claim vested tokens2374 * @param signer signers Keyring2375 */2376 async claim(signer: TSigner) {2377 const result = await this.helper.executeExtrinsic(signer, 'api.tx.vesting.claim', []);2378 const event = result.result.events2379 .find(e => e.event.section === 'vesting' &&2380 e.event.method === 'Claimed' &&2381 e.event.data[0].toHuman() === signer.address);2382 if (!event) throw Error('Cannot find claim in events');2383 }2329}2384}233023852331class AddressGroup extends HelperGroup<ChainHelperBase> {2386class AddressGroup extends HelperGroup<ChainHelperBase> {tests/src/vesting.test.tsdiffbeforeafterbothno changes