From 7079d71009aa44e1e4ed5ca122f6e0a7a88dd398 Mon Sep 17 00:00:00 2001 From: Max Andreev Date: Thu, 25 Aug 2022 09:34:06 +0000 Subject: [PATCH] fix after review --- --- a/tests/src/util/playgrounds/unique.dev.ts +++ b/tests/src/util/playgrounds/unique.dev.ts @@ -70,7 +70,7 @@ * @returns array of newly created accounts * @example const [acc1, acc2, acc3] = await createAccounts([0n, 10n, 20n], donor); */ - creteAccounts = async (balances: bigint[], donor: TSigner): Promise => { + creteAccounts = async (balances: bigint[], donor: IKeyringPair): Promise => { let nonce = await this.helper.chain.getNonce(donor.address); const tokenNominal = this.helper.balance.getOneTokenNominal(); const transactions = []; @@ -101,11 +101,12 @@ }; let accountsCreated = false; - // waiting up to 1 minute with .25 sec retry - for (let index = 0; index < 240; index++) { + // checkBalances retry up to 5 blocks + for (let index = 0; index < 5; index++) { + console.log(await this.helper.chain.getLatestBlockNumber()); accountsCreated = await checkBalances(); if(accountsCreated) break; - await new Promise(resolve => setTimeout(resolve, 250)); + await this.waitNewBlocks(1); } if (!accountsCreated) throw Error('Accounts generation failed'); @@ -113,4 +114,23 @@ return accounts; }; + + /** + * Wait for specified bnumber of blocks + * @param blocksCount number of blocks to wait + * @returns + */ + async waitNewBlocks(blocksCount = 1): Promise { + const promise = new Promise(async (resolve) => { + const unsubscribe = await this.helper.api!.rpc.chain.subscribeNewHeads(() => { + if (blocksCount > 0) { + blocksCount--; + } else { + unsubscribe(); + resolve(); + } + }); + }); + return promise; + } } \ No newline at end of file -- gitstuff