git.delta.rocks / unique-network / refs/commits / c52e8a647b65

difftreelog

fix flaky tests: account generation with nonce

Max Andreev2022-08-25parent: #9e1cf3e.patch.diff
in: master
ignore errors
wait for balances

1 file changed

modifiedtests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth
6import {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';
910
1011
11export 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 }
8687
87 await Promise.all(transactions);88 await Promise.all(transactions).catch(e => {});
89
90 //#region TODO remove this region, when nonce problem will be solved
91 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 };
102
103 let accountsCreated = false;
104 // waiting up to 1 minute with .25 sec retry
105 for (let index = 0; index < 240; index++) {
106 accountsCreated = await checkBalances();
107 if(accountsCreated) break;
108 await new Promise(resolve => setTimeout(resolve, 250));
109 }
110
111 if (!accountsCreated) throw Error('Accounts generation failed');
112 //#endregion
113
88 return accounts;114 return accounts;
89 };115 };