git.delta.rocks / unique-network / refs/commits / 385c9660b4ca

difftreelog

tests(util): minor refactor of transaction options

Fahrrader2022-09-20parent: #1b4500f.patch.diff
in: master

2 files changed

modifiedtests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth
132 accounts.push(recipient);132 accounts.push(recipient);
133 if (balance !== 0n) {133 if (balance !== 0n) {
134 const tx = this.helper.constructApiCall('api.tx.balances.transfer', [{Id: recipient.address}, balance * tokenNominal]);134 const tx = this.helper.constructApiCall('api.tx.balances.transfer', [{Id: recipient.address}, balance * tokenNominal]);
135 transactions.push(this.helper.signTransaction(donor, tx, 'account generation', {nonce}));135 transactions.push(this.helper.signTransaction(donor, tx, {nonce}, 'account generation'));
136 nonce++;136 nonce++;
137 }137 }
138 }138 }
183 accounts.push(recepient);183 accounts.push(recepient);
184 if (withBalance !== 0n) {184 if (withBalance !== 0n) {
185 const tx = this.helper.constructApiCall('api.tx.balances.transfer', [{Id: recepient.address}, withBalance * tokenNominal]);185 const tx = this.helper.constructApiCall('api.tx.balances.transfer', [{Id: recepient.address}, withBalance * tokenNominal]);
186 transactions.push(this.helper.signTransaction(donor, tx, 'account generation', {nonce}));186 transactions.push(this.helper.signTransaction(donor, tx, {nonce}, 'account generation'));
187 nonce++;187 nonce++;
188 }188 }
189 }189 }
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
6/* eslint-disable no-prototype-builtins */6/* eslint-disable no-prototype-builtins */
77
8import {ApiPromise, WsProvider, Keyring} from '@polkadot/api';8import {ApiPromise, WsProvider, Keyring} from '@polkadot/api';
9import {ApiInterfaceEvents} from '@polkadot/api/types';9import {ApiInterfaceEvents, SignerOptions} from '@polkadot/api/types';
10import {encodeAddress, decodeAddress, keccakAsHex, evmToAddress, addressToEvm} from '@polkadot/util-crypto';10import {encodeAddress, decodeAddress, keccakAsHex, evmToAddress, addressToEvm} from '@polkadot/util-crypto';
11import {IKeyringPair} from '@polkadot/types/types';11import {IKeyringPair} from '@polkadot/types/types';
12import {IApiListeners, IBlock, IEvent, IChainProperties, ICollectionCreationOptions, ICollectionLimits, ICollectionPermissions, ICrossAccountId, ICrossAccountIdLower, ILogger, INestingPermissions, IProperty, IStakingInfo, ISubstrateBalance, IToken, ITokenPropertyPermission, ITransactionResult, IUniqueHelperLog, TApiAllowedListeners, TEthereumAccount, TSigner, TSubstrateAccount, TUniqueNetworks} from './types';12import {IApiListeners, IBlock, IEvent, IChainProperties, ICollectionCreationOptions, ICollectionLimits, ICollectionPermissions, ICrossAccountId, ICrossAccountIdLower, ILogger, INestingPermissions, IProperty, IStakingInfo, ISubstrateBalance, IToken, ITokenPropertyPermission, ITransactionResult, IUniqueHelperLog, TApiAllowedListeners, TEthereumAccount, TSigner, TSubstrateAccount, TUniqueNetworks} from './types';
205 let obj: any = {};205 let obj: any = {};
206 let index = 0;206 let index = 0;
207207
208 if (data.entries)208 if (data.entries) {
209 for(const [key, value] of data.entries()) {209 for(const [key, value] of data.entries()) {
210 obj[key] = this.extractData(value, subTypes[index]);210 obj[key] = this.extractData(value, subTypes[index]);
211 index++;211 index++;
212 }212 }
213 else obj = data.toJSON();213 } else obj = data.toJSON();
214214
215 return obj;215 return obj;
216 }216 }
365 return this.transactionStatus.FAIL;365 return this.transactionStatus.FAIL;
366 }366 }
367367
368 signTransaction(sender: TSigner, transaction: any, label = 'transaction', options: any = null) {368 signTransaction(sender: TSigner, transaction: any, options: Partial<SignerOptions> | null = null, label = 'transaction') {
369 const sign = (callback: any) => {369 const sign = (callback: any) => {
370 if(options !== null) return transaction.signAndSend(sender, options, callback);370 if(options !== null) return transaction.signAndSend(sender, options, callback);
371 return transaction.signAndSend(sender, callback);371 return transaction.signAndSend(sender, callback);
421 return call(...params);421 return call(...params);
422 }422 }
423423
424 async executeExtrinsic(sender: TSigner, extrinsic: string, params: any[], expectSuccess=true/*, failureMessage='expected success'*/) {424 async executeExtrinsic(sender: TSigner, extrinsic: string, params: any[], expectSuccess=true, options: Partial<SignerOptions>|null = null/*, failureMessage='expected success'*/) {
425 if(this.api === null) throw Error('API not initialized');425 if(this.api === null) throw Error('API not initialized');
426 if(!extrinsic.startsWith('api.tx.')) throw Error(`${extrinsic} is not transaction`);426 if(!extrinsic.startsWith('api.tx.')) throw Error(`${extrinsic} is not transaction`);
427427
428 const startTime = (new Date()).getTime();428 const startTime = (new Date()).getTime();
429 let result: ITransactionResult;429 let result: ITransactionResult;
430 let events: IEvent[] = [];430 let events: IEvent[] = [];
431 try {431 try {
432 result = await this.signTransaction(sender, this.constructApiCall(extrinsic, params), extrinsic) as ITransactionResult;432 result = await this.signTransaction(sender, this.constructApiCall(extrinsic, params), options, extrinsic) as ITransactionResult;
433 events = this.eventHelper.extractEvents(result);433 events = this.eventHelper.extractEvents(result);
434 }434 }
435 catch(e) {435 catch(e) {