difftreelog
feat add scheduler tx to helpers
in: master
1 file changed
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth10import {encodeAddress, decodeAddress, keccakAsHex, evmToAddress, addressToEvm} from '@polkadot/util-crypto';10import {encodeAddress, decodeAddress, keccakAsHex, evmToAddress, addressToEvm} from '@polkadot/util-crypto';11import {IKeyringPair} from '@polkadot/types/types';11import {IKeyringPair} from '@polkadot/types/types';12import {IApiListeners, IBlock, IEvent, IChainProperties, ICollectionCreationOptions, ICollectionLimits, ICollectionPermissions, ICrossAccountId, ICrossAccountIdLower, ILogger, INestingPermissions, IProperty, IStakingInfo, ISchedulerOptions, ISubstrateBalance, IToken, ITokenPropertyPermission, ITransactionResult, IUniqueHelperLog, TApiAllowedListeners, TEthereumAccount, TSigner, TSubstrateAccount, IForeignAssetMetadata, TNetworks, MoonbeamAssetInfo, DemocracyStandardAccountVote, AcalaAssetMetadata} from './types';12import {IApiListeners, IBlock, IEvent, IChainProperties, ICollectionCreationOptions, ICollectionLimits, ICollectionPermissions, ICrossAccountId, ICrossAccountIdLower, ILogger, INestingPermissions, IProperty, IStakingInfo, ISchedulerOptions, ISubstrateBalance, IToken, ITokenPropertyPermission, ITransactionResult, IUniqueHelperLog, TApiAllowedListeners, TEthereumAccount, TSigner, TSubstrateAccount, IForeignAssetMetadata, TNetworks, MoonbeamAssetInfo, DemocracyStandardAccountVote, AcalaAssetMetadata} from './types';13import {RuntimeDispatchInfo} from '@polkadot/types/interfaces';131414export class CrossAccountId implements ICrossAccountId {15export class CrossAccountId implements ICrossAccountId {15 Substrate?: TSubstrateAccount;16 Substrate?: TSubstrateAccount;532 });533 });533 }534 }535536 async getPaymentInfo(signer: TSigner, tx: any, len: number | null) {537 const signingInfo = await this.api!.derive.tx.signingInfo(signer.address);538539 // We need to sign the tx because540 // unsigned transactions does not have an inclusion fee541 tx.sign(signer, {542 blockHash: this.api!.genesisHash,543 genesisHash: this.api!.genesisHash,544 runtimeVersion: this.api!.runtimeVersion,545 nonce: signingInfo.nonce,546 });547548 if (len === null) {549 return (await this.callRpc('api.rpc.payment.queryInfo', [tx.toHex()])) as RuntimeDispatchInfo;550 } else {551 return (await this.api!.call.transactionPaymentApi.queryInfo(tx, len)) as RuntimeDispatchInfo;552 }553 }534554535 constructApiCall(apiCall: string, params: any[]) {555 constructApiCall(apiCall: string, params: any[]) {536 if(!apiCall.startsWith('api.')) throw Error(`Invalid api call: ${apiCall}`);556 if(!apiCall.startsWith('api.')) throw Error(`Invalid api call: ${apiCall}`);1353 return this.getCollectionObject(this.helper.util.extractCollectionIdFromCreationResult(creationResult));1373 return this.getCollectionObject(this.helper.util.extractCollectionIdFromCreationResult(creationResult));1354 }1374 }13751376 async mintDefaultCollection(signer: TSigner, mode: 'NFT' | 'RFT'): Promise<UniqueCollectionBase> {1377 const defaultCreateCollectionParams: ICollectionCreationOptions = {1378 description: 'description',1379 name: 'name',1380 tokenPrefix: 'prfx',1381 };13821383 return this.mintCollection(signer, defaultCreateCollectionParams, mode);1384 }135513851356 getCollectionObject(_collectionId: number): any {1386 getCollectionObject(_collectionId: number): any {1357 return null;1387 return null;1537 return await super.mintCollection(signer, collectionOptions, 'NFT') as UniqueNFTCollection;1567 return await super.mintCollection(signer, collectionOptions, 'NFT') as UniqueNFTCollection;1538 }1568 }15691570 async mintDefaultCollection(signer: IKeyringPair): Promise<UniqueNFTCollection> {1571 return await super.mintDefaultCollection(signer, 'NFT') as UniqueNFTCollection;1572 }153915731540 /**1574 /**1541 * Mint new token1575 * Mint new token1723 return await super.mintCollection(signer, collectionOptions, 'RFT') as UniqueRFTCollection;1757 return await super.mintCollection(signer, collectionOptions, 'RFT') as UniqueRFTCollection;1724 }1758 }17591760 async mintDefaultCollection(signer: IKeyringPair): Promise<UniqueRFTCollection> {1761 return await super.mintDefaultCollection(signer, 'RFT') as UniqueRFTCollection;1762 }172517631726 /**1764 /**1727 * Mint new token1765 * Mint new token2398}2436}239924372400class SchedulerGroup extends HelperGroup<UniqueHelper> {2438class SchedulerGroup extends HelperGroup<UniqueHelper> {2439 scheduledIdSlider = 0;24402441 async waitNoScheduledTasks() {2442 const api = this.helper.api!;2443 2444 // eslint-disable-next-line no-async-promise-executor2445 const promise = new Promise<void>(async resolve => {2446 const unsubscribe = await api.rpc.chain.subscribeNewHeads(async () => {2447 const areThereScheduledTasks = await api.query.scheduler.lookup.entries();24482449 if(areThereScheduledTasks.length == 0) {2450 unsubscribe();2451 resolve();2452 }2453 }); 2454 });24552456 return promise;2457 }24582401 constructor(helper: UniqueHelper) {2459 async makeScheduledIds(num: number): Promise<string[]> {2402 super(helper);2460 await this.waitNoScheduledTasks();24612462 function makeId(slider: number) {2463 const scheduledIdSize = 32;2464 const hexId = slider.toString(16);2465 const prefixSize = scheduledIdSize - hexId.length;24662467 const scheduledId = '0x' + '0'.repeat(prefixSize) + hexId;24682469 return scheduledId; 2470 }24712472 const ids = [];2473 for (let i = 0; i < num; i++) {2474 ids.push(makeId(this.scheduledIdSlider));2475 this.scheduledIdSlider += 1;2476 }24772478 return ids;2403 }2479 }24802481 async makeScheduledId(): Promise<string> {2482 return (await this.makeScheduledIds(1))[0];2483 }240424842405 async cancelScheduled(signer: TSigner, scheduledId: string) {2485 async cancelScheduled(signer: TSigner, scheduledId: string) {2406 return this.helper.executeExtrinsic(2486 return this.helper.executeExtrinsic(