Factorize repeated logEvents function (#1409)

This commit is contained in:
Amaury Martiny
2019-09-20 17:16:12 +02:00
committed by GitHub
parent bc8782a885
commit 06d0c1fdfb
6 changed files with 33 additions and 88 deletions
@@ -5,30 +5,9 @@
import Keyring from '@polkadot/keyring';
import testingPairs from '@polkadot/keyring/testingPairs';
import WsProvider from '@polkadot/rpc-provider/ws';
import { EventRecord } from '@polkadot/types/interfaces';
import { SubmittableResult } from '../../../src';
import ApiPromise from '../../../src/promise';
import { describeE2E, calculateAccountDeposit } from '../../util';
// log all events for the transfers, calling done() when finalized
const logEvents = (done: () => {}): (r: SubmittableResult) => void =>
({ events, status }: SubmittableResult): void => {
console.log('Transaction status:', status.type);
if (status.isFinalized) {
console.log('Completed at block hash', status.value.toHex());
console.log('Events:');
events.forEach(({ phase, event: { data, method, section } }: EventRecord): void => {
console.log('\t', phase.toString(), `: ${section}.${method}`, data.toString());
});
if (events.length) {
done();
}
}
};
import { describeE2E, calculateAccountDeposit, logEvents } from '../../util';
describeE2E({
except: ['remote-polkadot-alexander', 'remote-substrate-1.0']
@@ -4,32 +4,12 @@
import testingPairs from '@polkadot/keyring/testingPairs';
import WsProvider from '@polkadot/rpc-provider/ws';
import { EventRecord, Header, Index } from '@polkadot/types/interfaces';
import { Header, Index } from '@polkadot/types/interfaces';
import { createType } from '@polkadot/types';
import { SubmittableResult } from '../../../src';
import ApiPromise from '../../../src/promise';
import { Signer } from '../../../src/types';
import { describeE2E, SingleAccountSigner } from '../../util';
// log all events for the transfer, calling done() when finalized
const logEvents = (done: () => {}): (r: SubmittableResult) => void =>
({ events, status }: SubmittableResult): void => {
console.log('Transaction status:', status.type);
if (status.isFinalized) {
console.log('Completed at block hash', status.value.toHex());
console.log('Events:');
events.forEach(({ phase, event: { data, method, section } }: EventRecord): void => {
console.log('\t', phase.toString(), `: ${section}.${method}`, data.toString());
});
if (events.length) {
done();
}
}
};
import { describeE2E, logEvents, SingleAccountSigner } from '../../util';
describeE2E({
except: [
@@ -4,31 +4,10 @@
import testingPairs from '@polkadot/keyring/testingPairs';
import WsProvider from '@polkadot/rpc-provider/ws';
import { EventRecord } from '@polkadot/types/interfaces';
import { SubmittableResult } from '../../../src';
import ApiPromise from '../../../src/promise';
import { Signer } from '../../../src/types';
import { describeE2E, SingleAccountSigner } from '../../util';
// log all events for the transfer, calling done() when finalized
const logEvents = (done: () => {}): (r: SubmittableResult) => void =>
({ events, status }: SubmittableResult): void => {
console.log('Transaction status:', status.type);
if (status.isFinalized) {
console.log('Completed at block hash', status.value.toHex());
console.log('Events:');
events.forEach(({ phase, event: { data, method, section } }: EventRecord): void => {
console.log('\t', phase.toString(), `: ${section}.${method}`, data.toString());
});
if (events.length) {
done();
}
}
};
import { describeE2E, logEvents, SingleAccountSigner } from '../../util';
describeE2E({
except: ['remote-polkadot-alexander', 'remote-substrate-1.0']
+2 -22
View File
@@ -7,31 +7,11 @@ import testingPairs from '@polkadot/keyring/testingPairs';
import WsProvider from '@polkadot/rpc-provider/ws';
import { randomAsHex } from '@polkadot/util-crypto';
import { u8aToHex } from '@polkadot/util';
import { EventRecord, Index } from '@polkadot/types/interfaces';
import { Index } from '@polkadot/types/interfaces';
import { SubmittableResult } from '../../../src';
import ApiPromise from '../../../src/promise';
import randomAsHex2097152 from '../../mock-data/randomAsHex_2097152';
import { calculateAccountDeposit, describeE2E } from '../../util';
// log all events for the transfers, calling done() when finalized
const logEvents = (done: () => {}): (r: SubmittableResult) => void =>
({ events, status }: SubmittableResult): void => {
console.log('Transaction status:', status.type);
if (status.isFinalized) {
console.log('Completed at block hash', status.value.toHex());
console.log('Events:');
events.forEach(({ phase, event: { data, method, section } }: EventRecord): void => {
console.log('\t', phase.toString(), `: ${section}.${method}`, data.toString());
});
if (events.length) {
done();
}
}
};
import { calculateAccountDeposit, describeE2E, logEvents } from '../../util';
describeE2E({
except: ['remote-polkadot-alexander', 'remote-substrate-1.0']
+1
View File
@@ -4,4 +4,5 @@
export * from './calculateAccountDeposit';
export * from './describeE2E';
export * from './logEvents';
export * from './SingleAccountSigner';
+26
View File
@@ -0,0 +1,26 @@
// Copyright 2017-2019 @polkadot/api authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { EventRecord } from '@polkadot/types/interfaces';
import { SubmittableResult } from '../../src';
// log all events for the transfers, calling done() when finalized
export const logEvents = (done: () => {}): (r: SubmittableResult) => void =>
({ events, status }: SubmittableResult): void => {
console.log('Transaction status:', status.type);
if (status.isFinalized) {
console.log('Completed at block hash', status.value.toHex());
console.log('Events:');
events.forEach(({ phase, event: { data, method, section } }: EventRecord): void => {
console.log('\t', phase.toString(), `: ${section}.${method}`, data.toString());
});
if (events.length) {
done();
}
}
};