--- a/tests/src/util/playgrounds/unique.dev.ts +++ b/tests/src/util/playgrounds/unique.dev.ts @@ -5,7 +5,8 @@ import {UniqueHelper} from './unique'; import {ApiPromise, WsProvider} from '@polkadot/api'; import * as defs from '../../interfaces/definitions'; -import { TSigner } from './types'; +import {TSigner} from './types'; +import {IKeyringPair} from '@polkadot/types/types'; export class DevUniqueHelper extends UniqueHelper { @@ -73,7 +74,7 @@ let nonce = await this.helper.chain.getNonce(donor.address); const tokenNominal = this.helper.balance.getOneTokenNominal(); const transactions = []; - const accounts = []; + const accounts: IKeyringPair[] = []; for (const balance of balances) { const recepient = this.helper.util.fromSeed(mnemonicGenerate()); accounts.push(recepient); @@ -84,7 +85,32 @@ } } - await Promise.all(transactions); + await Promise.all(transactions).catch(e => {}); + + //#region TODO remove this region, when nonce problem will be solved + const checkBalances = async () => { + let isSuccess = true; + for (let i = 0; i < balances.length; i++) { + const balance = await this.helper.balance.getSubstrate(accounts[i].address); + if (balance !== balances[i] * tokenNominal) { + isSuccess = false; + break; + } + } + return isSuccess; + }; + + let accountsCreated = false; + // waiting up to 1 minute with .25 sec retry + for (let index = 0; index < 240; index++) { + accountsCreated = await checkBalances(); + if(accountsCreated) break; + await new Promise(resolve => setTimeout(resolve, 250)); + } + + if (!accountsCreated) throw Error('Accounts generation failed'); + //#endregion + return accounts; }; } \ No newline at end of file