From 72c1a24d0876278a4c69e803261bbf3d0d00e793 Mon Sep 17 00:00:00 2001 From: "Mark S. Lewis" Date: Sun, 3 Sep 2023 18:12:43 +0100 Subject: [PATCH] Fixes required by changes to typing in dependencies Signed-off-by: Mark S. Lewis --- fabric-common/package.json | 4 +- fabric-common/types/index.d.ts | 2 +- fabric-common/types/tsconfig.json | 8 +- fabric-network/package.json | 4 +- fabric-network/src/checkpointer.ts | 2 +- fabric-network/src/events.ts | 2 +- .../src/impl/event/blockeventsource.ts | 2 +- .../src/impl/event/commitlistenersession.ts | 2 +- .../src/impl/event/orderedblockqueue.ts | 2 +- fabric-network/src/impl/filecheckpointer.ts | 4 +- .../test/impl/event/commitlistener.spec.ts | 2 +- .../test/impl/event/contractlistener.spec.ts | 2 +- .../test/impl/event/listeners.spec.ts | 2 +- .../test/impl/event/orderedblockqueue.spec.ts | 2 +- .../test/impl/event/stubcheckpointer.ts | 2 +- .../event/transactioneventhandler.spec.ts | 2 +- .../test/impl/filecheckpointer.spec.ts | 2 +- fabric-network/tsconfig.json | 7 +- package.json | 1 + .../src/steps/channel_operations.ts | 79 ------------------- test/ts-scenario/src/steps/lib/listeners.ts | 8 +- .../src/steps/lib/utility/clientUtils.ts | 2 +- .../utility/commonConnectionProfileHelper.ts | 25 +++--- test/ts-scenario/tsconfig.json | 6 +- 24 files changed, 50 insertions(+), 124 deletions(-) delete mode 100644 test/ts-scenario/src/steps/channel_operations.ts diff --git a/fabric-common/package.json b/fabric-common/package.json index bf4c5fd5fe..cd3264532e 100644 --- a/fabric-common/package.json +++ b/fabric-common/package.json @@ -29,6 +29,7 @@ "fabric-protos": "file:../fabric-protos", "js-sha3": "^0.8.0", "jsrsasign": "^10.5.25", + "long": "^5.2.3", "nconf": "^0.12.0", "promise-settle": "^0.3.0", "sjcl": "^1.0.8", @@ -61,6 +62,5 @@ "type": "Apache-2.0", "url": "https://github.com/hyperledger/fabric/blob/main/LICENSE" } - ], - "devDependencies": {} + ] } diff --git a/fabric-common/types/index.d.ts b/fabric-common/types/index.d.ts index 60ba07eab6..02774b72af 100644 --- a/fabric-common/types/index.d.ts +++ b/fabric-common/types/index.d.ts @@ -5,7 +5,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -import * as Long from 'long'; +import Long from 'long'; import * as fabproto6 from 'fabric-protos'; import winston = require('winston'); diff --git a/fabric-common/types/tsconfig.json b/fabric-common/types/tsconfig.json index a101181b97..86b6a11d64 100644 --- a/fabric-common/types/tsconfig.json +++ b/fabric-common/types/tsconfig.json @@ -2,14 +2,14 @@ "$schema": "https://json.schemastore.org/tsconfig", "extends": "@tsconfig/node10/tsconfig.json", "compilerOptions": { - "removeComments": false, "preserveConstEnums": true, "sourceMap": true, "declaration": true, - "noImplicitAny": true, + "declarationMap": true, + "strict": true, + "noUnusedLocals": true, "noImplicitReturns": true, - "noImplicitThis": true, - "suppressImplicitAnyIndexErrors": true, + "forceConsistentCasingInFileNames": true, "baseUrl": ".", "paths": { "*": [ diff --git a/fabric-network/package.json b/fabric-network/package.json index 0f7aa1a81d..faffe232e9 100644 --- a/fabric-network/package.json +++ b/fabric-network/package.json @@ -26,6 +26,7 @@ "dependencies": { "fabric-common": "file:../fabric-common", "fabric-protos": "file:../fabric-protos", + "long": "^5.2.3", "nano": "^9.0.5" }, "nyc": { @@ -54,6 +55,5 @@ "type": "Apache-2.0", "url": "https://github.com/hyperledger/fabric/blob/master/LICENSE" } - ], - "devDependencies": {} + ] } diff --git a/fabric-network/src/checkpointer.ts b/fabric-network/src/checkpointer.ts index c17699b5eb..6757c59096 100644 --- a/fabric-network/src/checkpointer.ts +++ b/fabric-network/src/checkpointer.ts @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import * as Long from 'long'; +import Long from 'long'; export interface Checkpointer { addTransactionId(transactionId: string): Promise; diff --git a/fabric-network/src/events.ts b/fabric-network/src/events.ts index 511c89c9c8..c7259b9a68 100644 --- a/fabric-network/src/events.ts +++ b/fabric-network/src/events.ts @@ -7,7 +7,7 @@ import {BlockType, Endorser} from 'fabric-common'; import * as fabproto6 from 'fabric-protos'; import {Checkpointer} from './checkpointer'; -import * as Long from 'long'; +import Long from 'long'; export type EventType = BlockType; diff --git a/fabric-network/src/impl/event/blockeventsource.ts b/fabric-network/src/impl/event/blockeventsource.ts index 0d45c21b4b..b802030392 100644 --- a/fabric-network/src/impl/event/blockeventsource.ts +++ b/fabric-network/src/impl/event/blockeventsource.ts @@ -15,7 +15,7 @@ import {newFullBlockEvent} from './fullblockeventfactory'; import {OrderedBlockQueue} from './orderedblockqueue'; import {newPrivateBlockEvent} from './privateblockeventfactory'; import {notNullish} from '../gatewayutils'; -import * as Long from 'long'; +import Long from 'long'; const logger = Logger.getLogger('BlockEventSource'); diff --git a/fabric-network/src/impl/event/commitlistenersession.ts b/fabric-network/src/impl/event/commitlistenersession.ts index ccf2cae52e..f010f83bb8 100644 --- a/fabric-network/src/impl/event/commitlistenersession.ts +++ b/fabric-network/src/impl/event/commitlistenersession.ts @@ -72,7 +72,7 @@ export class CommitListenerSession implements ListenerSession { return startErrors; } - private async startEventService(eventService: EventService): Promise { + private async startEventService(eventService: EventService): Promise { try { await this.eventServiceManager.startEventService(eventService); } catch (error) { diff --git a/fabric-network/src/impl/event/orderedblockqueue.ts b/fabric-network/src/impl/event/orderedblockqueue.ts index c767312f21..3183eec9ec 100644 --- a/fabric-network/src/impl/event/orderedblockqueue.ts +++ b/fabric-network/src/impl/event/orderedblockqueue.ts @@ -5,7 +5,7 @@ */ import {BlockEvent} from '../../events'; -import * as Long from 'long'; +import Long from 'long'; export class OrderedBlockQueue { private readonly queue = new Map(); diff --git a/fabric-network/src/impl/filecheckpointer.ts b/fabric-network/src/impl/filecheckpointer.ts index cc1b9e49bc..69eb823ff4 100644 --- a/fabric-network/src/impl/filecheckpointer.ts +++ b/fabric-network/src/impl/filecheckpointer.ts @@ -5,7 +5,7 @@ */ import {Checkpointer} from '../checkpointer'; -import * as Long from 'long'; +import Long from 'long'; import * as fs from 'fs'; const encoding = 'utf8'; @@ -58,7 +58,7 @@ export class FileCheckpointer implements Checkpointer { } } - private async readFile(): Promise { + private async readFile(): Promise { try { return await fs.promises.readFile(this.path); } catch (err) { diff --git a/fabric-network/test/impl/event/commitlistener.spec.ts b/fabric-network/test/impl/event/commitlistener.spec.ts index 44952b470b..097ea0f2b9 100644 --- a/fabric-network/test/impl/event/commitlistener.spec.ts +++ b/fabric-network/test/impl/event/commitlistener.spec.ts @@ -16,7 +16,7 @@ import { Client, Eventer } from 'fabric-common'; -import * as Long from 'long'; +import Long from 'long'; import {NetworkImpl} from '../../../src/network'; import {EventServiceManager} from '../../../src/impl/event/eventservicemanager'; diff --git a/fabric-network/test/impl/event/contractlistener.spec.ts b/fabric-network/test/impl/event/contractlistener.spec.ts index 8d41a5af29..7e148c388c 100644 --- a/fabric-network/test/impl/event/contractlistener.spec.ts +++ b/fabric-network/test/impl/event/contractlistener.spec.ts @@ -12,7 +12,7 @@ import * as sinon from 'sinon'; import {expect} from 'chai'; -import * as Long from 'long'; +import Long from 'long'; import {Channel, Client, Endorser, Eventer, EventInfo, IdentityContext} from 'fabric-common'; import * as fabproto6 from 'fabric-protos'; diff --git a/fabric-network/test/impl/event/listeners.spec.ts b/fabric-network/test/impl/event/listeners.spec.ts index cfd12728ce..ffb39b7e19 100644 --- a/fabric-network/test/impl/event/listeners.spec.ts +++ b/fabric-network/test/impl/event/listeners.spec.ts @@ -7,7 +7,7 @@ import * as Listeners from '../../../src/impl/event/listeners'; import {StubCheckpointer} from './stubcheckpointer'; import {BlockEvent, BlockListener, TransactionEvent, ContractEvent} from '../../../src/events'; -import * as Long from 'long'; +import Long from 'long'; import * as chai from 'chai'; import * as sinon from 'sinon'; diff --git a/fabric-network/test/impl/event/orderedblockqueue.spec.ts b/fabric-network/test/impl/event/orderedblockqueue.spec.ts index df8dea7bf9..b01a85722e 100644 --- a/fabric-network/test/impl/event/orderedblockqueue.spec.ts +++ b/fabric-network/test/impl/event/orderedblockqueue.spec.ts @@ -6,7 +6,7 @@ import {BlockEvent} from '../../../src/events'; import {OrderedBlockQueue} from '../../../src/impl/event/orderedblockqueue'; -import * as Long from 'long'; +import Long from 'long'; import * as chai from 'chai'; const expect = chai.expect; diff --git a/fabric-network/test/impl/event/stubcheckpointer.ts b/fabric-network/test/impl/event/stubcheckpointer.ts index dc10c3c901..56704e95a4 100644 --- a/fabric-network/test/impl/event/stubcheckpointer.ts +++ b/fabric-network/test/impl/event/stubcheckpointer.ts @@ -5,7 +5,7 @@ */ import {Checkpointer} from '../../../src/checkpointer'; -import * as Long from 'long'; +import Long from 'long'; export class StubCheckpointer implements Checkpointer { private blockNumber: Long; diff --git a/fabric-network/test/impl/event/transactioneventhandler.spec.ts b/fabric-network/test/impl/event/transactioneventhandler.spec.ts index 4a0124e579..6507209b03 100644 --- a/fabric-network/test/impl/event/transactioneventhandler.spec.ts +++ b/fabric-network/test/impl/event/transactioneventhandler.spec.ts @@ -19,7 +19,7 @@ import { EventInfo, IdentityContext } from 'fabric-common'; -import * as Long from 'long'; +import Long from 'long'; import {Gateway, ConnectedGatewayOptions} from '../../../src/gateway'; import {Network, NetworkImpl} from '../../../src/network'; diff --git a/fabric-network/test/impl/filecheckpointer.spec.ts b/fabric-network/test/impl/filecheckpointer.spec.ts index e494745cf0..19740c2c9f 100644 --- a/fabric-network/test/impl/filecheckpointer.spec.ts +++ b/fabric-network/test/impl/filecheckpointer.spec.ts @@ -7,7 +7,7 @@ import {Checkpointer} from '../../src/checkpointer'; import {DefaultCheckpointers} from '../../src/defaultcheckpointers'; import * as testUtils from '../testutils'; -import * as Long from 'long'; +import Long from 'long'; import * as path from 'path'; import * as fs from 'fs'; import * as chai from 'chai'; diff --git a/fabric-network/tsconfig.json b/fabric-network/tsconfig.json index bb4ed5b538..ab0e6606b4 100644 --- a/fabric-network/tsconfig.json +++ b/fabric-network/tsconfig.json @@ -3,9 +3,14 @@ "extends": "@tsconfig/node10/tsconfig.json", "compilerOptions": { "declaration": true, + "declarationMap": true, "outDir": "./lib", "rootDir": "./src", - "sourceMap": true + "sourceMap": true, + "strict": true, + "noUnusedLocals": true, + "noImplicitReturns": true, + "forceConsistentCasingInFileNames": true }, "include": [ "src/" diff --git a/package.json b/package.json index 0ce9fe57fc..4ee0de9899 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "ink-docstrap": "^1.3.2", "jsdoc": "^3.6.6", "jsrsasign": "^10.5.25", + "long": "^5.2.3", "mocha": "^9.2.2", "npm-run-all": "^4.1.5", "nyc": "^15.0.0", diff --git a/test/ts-scenario/src/steps/channel_operations.ts b/test/ts-scenario/src/steps/channel_operations.ts deleted file mode 100644 index b21c86ca6a..0000000000 --- a/test/ts-scenario/src/steps/channel_operations.ts +++ /dev/null @@ -1,79 +0,0 @@ -/** - * SPDX-License-Identifier: Apache-2.0 - */ - -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/restrict-template-expressions */ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ - -import * as BaseUtils from './lib/utility/baseUtils'; -import * as util from 'util'; - -/** - * Validate two passed items against a match requirement: - * - includes: each 'expected' object property must exist and be the same key value as 'actual' - * - matches: 'expected' and 'actual' must be identical - * - mirrors: 'expected' and 'actual' structures must match - * @param expected expected item to compare against an actual item - * @param actual actual item - * @param {string} compareType the match type being run (include | match | mirror) - */ -function validateObjectKeyMatch(expected: any, actual: any, compareType: 'includes' | 'matches' | 'mirrors'): any { - // walk down the expected and keep in line with the response - if (typeof expected === 'object') { - if (Array.isArray(expected) && (compareType.localeCompare('includes') === 0)) { - // Have an array that may be an object or a value - - for (let index = 0; index < expected.length; index++) { - const expectedItem: any = expected[index]; - let detected = false; - for (let iterate = 0; iterate < actual.length; iterate++) { - const actualItem: any = actual[iterate]; - const wasFound: boolean = validateObjectKeyMatch(expectedItem, actualItem, compareType); - if (wasFound) { - detected = true; - break; - } - } - if (!detected) { - BaseUtils.logAndThrow(`--> Missing item ${expectedItem} from ${actual}`); - } - } - } else { - for (const key of Object.keys(expected as Record)) { - if (Object.prototype.hasOwnProperty.call(actual, key)) { - // recursive call to scan property - BaseUtils.logMsg(`->Recursively checking response key ${key}`); - // eslint-disable-next-line @typescript-eslint/no-unused-vars - return validateObjectKeyMatch(expected[key], actual[key], compareType); - } else { - BaseUtils.logAndThrow(`-->Missing key in response expected field ${key} to be present in ${util.inspect(actual)}`); - } - } - } - } else { - // not an Object so "expected" is a value that should (conditionally) match - switch (compareType) { - case 'matches': - if (expected !== actual) { - BaseUtils.logAndThrow(`-->Mismatched items expected ${util.inspect(expected)} but found ${util.inspect(actual)}`); - } else { - BaseUtils.logMsg(`-->Confirmed match of expected key value ${util.inspect(actual)}`); - } - break; - case 'includes': - if (expected !== actual) { - return false; - } else { - BaseUtils.logMsg(`-->Confirmed existence of required 'include' key with value ${util.inspect(actual)}`); - return true; - } - case 'mirrors': - BaseUtils.logMsg('-->Confirmed existence of required \'mirror\' key name and presence of a value'); - break; - default: - throw new Error(`Unconditioned switch type ${util.inspect(compareType)} passed to validate match`); - } - } -} diff --git a/test/ts-scenario/src/steps/lib/listeners.ts b/test/ts-scenario/src/steps/lib/listeners.ts index 7f250a2a7a..19506fcdfe 100644 --- a/test/ts-scenario/src/steps/lib/listeners.ts +++ b/test/ts-scenario/src/steps/lib/listeners.ts @@ -12,7 +12,7 @@ import * as Constants from '../constants'; import * as GatewayHelper from './gateway'; import * as BaseUtils from './utility/baseUtils'; import {StateStore} from './utility/stateStore'; -import * as Long from 'long'; +import Long from 'long'; import * as fs from 'fs'; import * as path from 'path'; import * as os from 'os'; @@ -263,10 +263,8 @@ export function checkContractListenerPayloads(listenerName: string, checkData: s const contractEvents: ContractEvent[] = listenerObject.payloads; const found = contractEvents.some((contractEvent) => { - if (contractEvent.payload) { - // Check a contract event payload is what we expect - return contractEvent.payload.toString() === checkData; - } + // Check a contract event payload is what we expect + return contractEvent.payload?.toString() === checkData; }); if (found) { diff --git a/test/ts-scenario/src/steps/lib/utility/clientUtils.ts b/test/ts-scenario/src/steps/lib/utility/clientUtils.ts index 4e97ed6cd2..c03b83b206 100644 --- a/test/ts-scenario/src/steps/lib/utility/clientUtils.ts +++ b/test/ts-scenario/src/steps/lib/utility/clientUtils.ts @@ -15,7 +15,7 @@ import { StartRequestOptions, SendEventOptions, BuildProposalRequest, SendProposalRequest, EventRegistrationOptions, EventListener } from 'fabric-common'; import * as fs from 'fs'; -import * as Long from 'long'; +import Long from 'long'; import * as Constants from '../../constants'; import * as BaseUtils from './baseUtils'; import {CommonConnectionProfileHelper} from './commonConnectionProfileHelper'; diff --git a/test/ts-scenario/src/steps/lib/utility/commonConnectionProfileHelper.ts b/test/ts-scenario/src/steps/lib/utility/commonConnectionProfileHelper.ts index 324d5ba6b9..1bf6c894c5 100644 --- a/test/ts-scenario/src/steps/lib/utility/commonConnectionProfileHelper.ts +++ b/test/ts-scenario/src/steps/lib/utility/commonConnectionProfileHelper.ts @@ -193,10 +193,10 @@ export class CommonConnectionProfileHelper { /** * Retrieve all the peers named in the profile - * @return {Object[]} the peers named in the profile + * @return {Record} the peers named in the profile */ - public getPeers(): any[] { - return this.profile.peers; + public getPeers(): Record { + return this.profile.peers ?? {}; } /** @@ -205,7 +205,7 @@ export class CommonConnectionProfileHelper { * @return {Object} the peer object */ public getPeer(peerName: string): Endpoint { - return this.profile.peers[peerName]; + return this.getPeers()[peerName]; } /** @@ -229,16 +229,13 @@ export class CommonConnectionProfileHelper { /** * check if the CCP is for a TLS network */ - public isTls(): boolean | undefined { - const peers: any = this.getPeers(); - if (peers) { - for (const key of Object.keys(peers as Record)) { - const peer: any = peers[key]; - // eslint-disable-next-line @typescript-eslint/no-unsafe-call - return (peer.url).includes('grpcs'); - } - } else { - throw new Error('No peers listed in the CCP'); + public isTls(): boolean { + const peers = this.getPeers(); + for (const peer of Object.values(peers)) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-call + return peer.url.includes('grpcs'); } + + throw new Error('No peers listed in the CCP'); } } diff --git a/test/ts-scenario/tsconfig.json b/test/ts-scenario/tsconfig.json index 249824fd4f..d4fed45f88 100644 --- a/test/ts-scenario/tsconfig.json +++ b/test/ts-scenario/tsconfig.json @@ -2,9 +2,13 @@ "$schema": "https://json.schemastore.org/tsconfig", "extends": "@tsconfig/node10/tsconfig.json", "compilerOptions": { + "declaration": true, + "declarationMap": true, "sourceMap": true, "strict": true, - "experimentalDecorators": true, + "noUnusedLocals": true, + "noImplicitReturns": true, + "forceConsistentCasingInFileNames": true, "outDir": "lib", "rootDir": "src" }