difftreelog
fix flaky tests: account generation with nonce
in: master
ignore errors wait for balances
1 file changed
tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth6import {ApiPromise, WsProvider} from '@polkadot/api';6import {ApiPromise, WsProvider} from '@polkadot/api';7import * as defs from '../../interfaces/definitions';7import * as defs from '../../interfaces/definitions';8import { TSigner } from './types';8import {TSigner} from './types';9import {IKeyringPair} from '@polkadot/types/types';910101111export class DevUniqueHelper extends UniqueHelper {12export class DevUniqueHelper extends UniqueHelper {73 let nonce = await this.helper.chain.getNonce(donor.address);74 let nonce = await this.helper.chain.getNonce(donor.address);74 const tokenNominal = this.helper.balance.getOneTokenNominal();75 const tokenNominal = this.helper.balance.getOneTokenNominal();75 const transactions = [];76 const transactions = [];76 const accounts = [];77 const accounts: IKeyringPair[] = [];77 for (const balance of balances) {78 for (const balance of balances) {78 const recepient = this.helper.util.fromSeed(mnemonicGenerate());79 const recepient = this.helper.util.fromSeed(mnemonicGenerate());79 accounts.push(recepient);80 accounts.push(recepient);84 }85 }85 }86 }868787 await Promise.all(transactions);88 await Promise.all(transactions).catch(e => {});89 90 //#region TODO remove this region, when nonce problem will be solved91 const checkBalances = async () => {92 let isSuccess = true;93 for (let i = 0; i < balances.length; i++) {94 const balance = await this.helper.balance.getSubstrate(accounts[i].address);95 if (balance !== balances[i] * tokenNominal) {96 isSuccess = false;97 break;98 }99 }100 return isSuccess;101 };102103 let accountsCreated = false;104 // waiting up to 1 minute with .25 sec retry105 for (let index = 0; index < 240; index++) {106 accountsCreated = await checkBalances();107 if(accountsCreated) break;108 await new Promise(resolve => setTimeout(resolve, 250));109 }110111 if (!accountsCreated) throw Error('Accounts generation failed');112 //#endregion11388 return accounts;114 return accounts;89 };115 };