difftreelog
fix after review
in: master
1 file changed
tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth70 * @returns array of newly created accounts70 * @returns array of newly created accounts71 * @example const [acc1, acc2, acc3] = await createAccounts([0n, 10n, 20n], donor); 71 * @example const [acc1, acc2, acc3] = await createAccounts([0n, 10n, 20n], donor); 72 */72 */73 creteAccounts = async (balances: bigint[], donor: TSigner): Promise<TSigner[]> => {73 creteAccounts = async (balances: bigint[], donor: IKeyringPair): Promise<IKeyringPair[]> => {74 let nonce = await this.helper.chain.getNonce(donor.address);74 let nonce = await this.helper.chain.getNonce(donor.address);75 const tokenNominal = this.helper.balance.getOneTokenNominal();75 const tokenNominal = this.helper.balance.getOneTokenNominal();76 const transactions = [];76 const transactions = [];101 };101 };102102103 let accountsCreated = false;103 let accountsCreated = false;104 // waiting up to 1 minute with .25 sec retry104 // checkBalances retry up to 5 blocks105 for (let index = 0; index < 240; index++) {105 for (let index = 0; index < 5; index++) {106 console.log(await this.helper.chain.getLatestBlockNumber());106 accountsCreated = await checkBalances();107 accountsCreated = await checkBalances();107 if(accountsCreated) break;108 if(accountsCreated) break;108 await new Promise(resolve => setTimeout(resolve, 250));109 await this.waitNewBlocks(1);109 }110 }110111111 if (!accountsCreated) throw Error('Accounts generation failed');112 if (!accountsCreated) throw Error('Accounts generation failed');114 return accounts;115 return accounts;115 };116 };117118 /**119 * Wait for specified bnumber of blocks120 * @param blocksCount number of blocks to wait121 * @returns 122 */123 async waitNewBlocks(blocksCount = 1): Promise<void> {124 const promise = new Promise<void>(async (resolve) => {125 const unsubscribe = await this.helper.api!.rpc.chain.subscribeNewHeads(() => {126 if (blocksCount > 0) {127 blocksCount--;128 } else {129 unsubscribe();130 resolve();131 }132 });133 });134 return promise;135 }116}136}