From c91d5731d008489683febf6aab2b98d582f8c825 Mon Sep 17 00:00:00 2001 From: "Mark S. Lewis" Date: Mon, 15 May 2023 09:17:42 +0100 Subject: [PATCH] Fix ts-scenario TypeScript transpile failure (#675) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ts-scenario tests failed with Node 16 and 18 only, with the following error: TSError: тип Unable to compile TypeScript: error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2020', 'esnext'. The fix is to explicitly specify the location of the tsconfig.json file (containing the required TypeScript compiler configuration) for ts-node using the TS_NODE_PROJECT environment variable. Also disable runtime type checking in ts-node using the SWC transpiler to provide a performance improvement. Signed-off-by: Mark S. Lewis --- .eslintignore | 2 +- docs/tutorials/query-peers.md | 2 +- docs/tutorials/transaction-commit-events.md | 2 +- fabric-network/.eslintignore | 10 -------- package.json | 11 ++++----- scripts/npm_scripts/checkLicense.sh | 1 + scripts/utility/fabric_images.sh | 10 +++++--- test/ts-scenario/.gitignore | 1 + .../handlers/sample-query-handler.ts | 0 .../sample-transaction-event-handler.ts | 0 test/ts-scenario/{ => src}/steps/base_api.ts | 2 +- .../{ => src}/steps/channel_operations.ts | 0 test/ts-scenario/{ => src}/steps/cli.ts | 0 test/ts-scenario/{ => src}/steps/constants.ts | 23 ++++++++++++------- test/ts-scenario/{ => src}/steps/debug.ts | 0 .../ts-scenario/{ => src}/steps/deprecated.ts | 4 ++-- test/ts-scenario/{ => src}/steps/docker.ts | 12 +++++----- .../{ => src}/steps/event-listeners.ts | 0 .../{ => src}/steps/lib/chaincode.ts | 0 .../{ => src}/steps/lib/channel.ts | 0 .../{ => src}/steps/lib/contract.ts | 0 .../{ => src}/steps/lib/deprecatedSDK.ts | 2 +- .../{ => src}/steps/lib/gateway.ts | 6 ++--- .../{ => src}/steps/lib/listeners.ts | 0 .../{ => src}/steps/lib/transactions.ts | 0 .../{ => src}/steps/lib/utility/adminUtils.ts | 6 ++--- .../{ => src}/steps/lib/utility/baseUtils.ts | 0 .../steps/lib/utility/clientUtils.ts | 0 .../steps/lib/utility/commandRunner.ts | 0 .../utility/commonConnectionProfileHelper.ts | 0 .../{ => src}/steps/lib/utility/stateStore.ts | 0 test/ts-scenario/{ => src}/steps/lifecycle.ts | 4 ++-- .../{ => src}/steps/network-model.ts | 2 +- test/ts-scenario/{ => src}/support/hooks.ts | 0 test/ts-scenario/tsconfig.json | 9 ++++---- 35 files changed, 54 insertions(+), 55 deletions(-) delete mode 100644 fabric-network/.eslintignore create mode 100644 test/ts-scenario/.gitignore rename test/ts-scenario/{config => src}/handlers/sample-query-handler.ts (100%) rename test/ts-scenario/{config => src}/handlers/sample-transaction-event-handler.ts (100%) rename test/ts-scenario/{ => src}/steps/base_api.ts (98%) rename test/ts-scenario/{ => src}/steps/channel_operations.ts (100%) rename test/ts-scenario/{ => src}/steps/cli.ts (100%) rename test/ts-scenario/{ => src}/steps/constants.ts (84%) rename test/ts-scenario/{ => src}/steps/debug.ts (100%) rename test/ts-scenario/{ => src}/steps/deprecated.ts (93%) rename test/ts-scenario/{ => src}/steps/docker.ts (89%) rename test/ts-scenario/{ => src}/steps/event-listeners.ts (100%) rename test/ts-scenario/{ => src}/steps/lib/chaincode.ts (100%) rename test/ts-scenario/{ => src}/steps/lib/channel.ts (100%) rename test/ts-scenario/{ => src}/steps/lib/contract.ts (100%) rename test/ts-scenario/{ => src}/steps/lib/deprecatedSDK.ts (99%) rename test/ts-scenario/{ => src}/steps/lib/gateway.ts (98%) rename test/ts-scenario/{ => src}/steps/lib/listeners.ts (100%) rename test/ts-scenario/{ => src}/steps/lib/transactions.ts (100%) rename test/ts-scenario/{ => src}/steps/lib/utility/adminUtils.ts (97%) rename test/ts-scenario/{ => src}/steps/lib/utility/baseUtils.ts (100%) rename test/ts-scenario/{ => src}/steps/lib/utility/clientUtils.ts (100%) rename test/ts-scenario/{ => src}/steps/lib/utility/commandRunner.ts (100%) rename test/ts-scenario/{ => src}/steps/lib/utility/commonConnectionProfileHelper.ts (100%) rename test/ts-scenario/{ => src}/steps/lib/utility/stateStore.ts (100%) rename test/ts-scenario/{ => src}/steps/lifecycle.ts (94%) rename test/ts-scenario/{ => src}/steps/network-model.ts (98%) rename test/ts-scenario/{ => src}/support/hooks.ts (100%) diff --git a/.eslintignore b/.eslintignore index 6d1173894f..ef41e4810d 100644 --- a/.eslintignore +++ b/.eslintignore @@ -7,4 +7,4 @@ docs/** fabric-network/lib/** fabric-protos/** -test/typescript/** \ No newline at end of file +test/ts-scenario/lib/** diff --git a/docs/tutorials/query-peers.md b/docs/tutorials/query-peers.md index d3b32a13fb..4748321709 100644 --- a/docs/tutorials/query-peers.md +++ b/docs/tutorials/query-peers.md @@ -140,4 +140,4 @@ The following sample code is in TypeScript to show the object types involved. } ``` -For a complete sample plug-in query handler implementation, see [sample-query-handler.ts](https://github.com/hyperledger/fabric-sdk-node/blob/main/test/ts-scenario/config/handlers/sample-query-handler.ts). +For a complete sample plug-in query handler implementation, see [sample-query-handler.ts](https://github.com/hyperledger/fabric-sdk-node/blob/main/test/ts-scenario/src/handlers/sample-query-handler.ts). diff --git a/docs/tutorials/transaction-commit-events.md b/docs/tutorials/transaction-commit-events.md index 07fd85f4a0..7cd20a3133 100644 --- a/docs/tutorials/transaction-commit-events.md +++ b/docs/tutorials/transaction-commit-events.md @@ -121,4 +121,4 @@ listener to monitor commit events from endorsing peers by calling [Network.addCommitListener](module-fabric-network.Network.html#addCommitListener). For a complete sample plug-in event handler implementation, see -[sample-transaction-event-handler.ts](https://github.com/hyperledger/fabric-sdk-node/blob/main/test/ts-scenario/config/handlers/sample-transaction-event-handler.ts). +[sample-transaction-event-handler.ts](https://github.com/hyperledger/fabric-sdk-node/blob/main/test/ts-scenario/src/handlers/sample-transaction-event-handler.ts). diff --git a/fabric-network/.eslintignore b/fabric-network/.eslintignore deleted file mode 100644 index 12a13c416b..0000000000 --- a/fabric-network/.eslintignore +++ /dev/null @@ -1,10 +0,0 @@ -# -# Copyright 2018 IBM All Rights Reserved. -# -# SPDX-License-Identifier: Apache-2.0 -# -coverage -lib -node_modules -config -.nyc_output diff --git a/package.json b/package.json index 2852a7fdff..63978ffab1 100644 --- a/package.json +++ b/package.json @@ -31,13 +31,11 @@ "unitTest": "ts-mocha --reporter list", "dockerReady": "npm run dockerClean && (cd test/fixtures/docker-compose && docker-compose -f docker-compose-tls-level-db.yaml -p node up -d && sleep 15 && docker ps -a)", "tapeIntegration": "./scripts/npm_scripts/runTape.sh", - "cucumberScenario": "npm run setupCucumbers && export HFC_LOGGING='{\"debug\":\"test/temp/debugc.log\"}' && npm run test:cucumber && npm run dockerClean && nyc --check-coverage --statements 54 --branches 32 --functions 46 --lines 54 npm run test:ts-cucumber", - "cucumberScenarioNoHSM": "npm run setupCucumbers && export HFC_LOGGING='{\"debug\":\"test/temp/debugc.log\"}' && npm run test:cucumber && npm run dockerClean && nyc --check-coverage --statements 54 --branches 32 --functions 46 --lines 54 npm run test:ts-cucumberNoHSM", + "cucumberScenario": "npm run setupCucumbers && export HFC_LOGGING='{\"debug\":\"test/temp/debugc.log\"}' && npm run dockerClean && nyc --check-coverage --statements 54 --branches 32 --functions 46 --lines 54 npm run test:ts-cucumber", + "cucumberScenarioNoHSM": "npm run setupCucumbers && export HFC_LOGGING='{\"debug\":\"test/temp/debugc.log\"}' && npm run dockerClean && nyc --check-coverage --statements 54 --branches 32 --functions 46 --lines 54 npm run test:ts-cucumberNoHSM", "setupCucumbers": "node -e 'require(\"./scripts/npm_scripts/testFunctions.js\").createCucumberLogFile()'", - "test:cucumber": "cucumber-js -f @cucumber/pretty-formatter ./test/scenario/features/*.feature", - "test:ts-cucumber": "cucumber-js -f @cucumber/pretty-formatter ./test/ts-scenario/features/*.feature --require './test/ts-scenario/steps/**/*.ts' --require './test/ts-scenario/support/**/*.ts' --require-module ts-node/register", - "test:ts-cucumberNoHSM": "cucumber-js -f @cucumber/pretty-formatter ./test/ts-scenario/features/*.feature --require './test/ts-scenario/steps/**/*.ts' --require './test/ts-scenario/support/**/*.ts' --require-module ts-node/register --tags 'not @gateway_hsm'", - "test:ts-cucumber-tagged": "npm run test:ts-cucumber -- --tags @events", + "test:ts-cucumber": "tsc --project test/ts-scenario/tsconfig.json && cucumber-js -f @cucumber/pretty-formatter ./test/ts-scenario/features/*.feature --require './test/ts-scenario/lib/**/*.js'", + "test:ts-cucumberNoHSM": "npm run test:ts-cucumber -- --tags 'not @gateway_hsm'", "testHeadless": "run-s cleanUp compile lint unitTest:all", "tapeAndCucumber": "run-s tapeIntegration dockerClean cucumberScenario" }, @@ -79,7 +77,6 @@ "tape-promise": "^4.0.0", "ts-mocha": "^9.0.2", "ts-mock-imports": "^1.3.4", - "ts-node": "^10.5.0", "typescript": "~4.4.4", "winston": "^2.4.5" }, diff --git a/scripts/npm_scripts/checkLicense.sh b/scripts/npm_scripts/checkLicense.sh index c2aa44e0d6..833332312f 100755 --- a/scripts/npm_scripts/checkLicense.sh +++ b/scripts/npm_scripts/checkLicense.sh @@ -18,6 +18,7 @@ CHECK=$(find . -type f \ -not -path './fabric-protos/types/index.d.ts' \ -not -path './fabric-network/lib/*' \ -not -path './.idea/*' \ + -not -path './test/ts-scenario/lib/*' \ -not -name '.*' \ -not -name '*.txt' \ -not -name '*.rst' \ diff --git a/scripts/utility/fabric_images.sh b/scripts/utility/fabric_images.sh index 0cc012177e..9348514e61 100755 --- a/scripts/utility/fabric_images.sh +++ b/scripts/utility/fabric_images.sh @@ -10,13 +10,17 @@ FABRIC_VERSION=${FABRIC_VERSION:-2.2} COUCHDB_VERSION=${COUCHDB_VERSION:-3.2} CA_VERSION=${CA_VERSION:-1.5} +pull() { + docker pull -q "$1" || docker pull -q --platform amd64 "$1" +} + for image in peer orderer ccenv baseos nodeenv javaenv tools; do - docker pull -q "hyperledger/fabric-${image}:${FABRIC_VERSION}" + pull "hyperledger/fabric-${image}:${FABRIC_VERSION}" docker tag "hyperledger/fabric-${image}:${FABRIC_VERSION}" "hyperledger/fabric-${image}" done -docker pull -q "couchdb:${COUCHDB_VERSION}" +pull "couchdb:${COUCHDB_VERSION}" docker tag "couchdb:${COUCHDB_VERSION}" couchdb -docker pull -q "hyperledger/fabric-ca:${CA_VERSION}" +pull "hyperledger/fabric-ca:${CA_VERSION}" docker tag "hyperledger/fabric-ca:${CA_VERSION}" hyperledger/fabric-ca diff --git a/test/ts-scenario/.gitignore b/test/ts-scenario/.gitignore new file mode 100644 index 0000000000..fdf7ed5d6c --- /dev/null +++ b/test/ts-scenario/.gitignore @@ -0,0 +1 @@ +lib/** diff --git a/test/ts-scenario/config/handlers/sample-query-handler.ts b/test/ts-scenario/src/handlers/sample-query-handler.ts similarity index 100% rename from test/ts-scenario/config/handlers/sample-query-handler.ts rename to test/ts-scenario/src/handlers/sample-query-handler.ts diff --git a/test/ts-scenario/config/handlers/sample-transaction-event-handler.ts b/test/ts-scenario/src/handlers/sample-transaction-event-handler.ts similarity index 100% rename from test/ts-scenario/config/handlers/sample-transaction-event-handler.ts rename to test/ts-scenario/src/handlers/sample-transaction-event-handler.ts diff --git a/test/ts-scenario/steps/base_api.ts b/test/ts-scenario/src/steps/base_api.ts similarity index 98% rename from test/ts-scenario/steps/base_api.ts rename to test/ts-scenario/src/steps/base_api.ts index 6ddff031a1..a7860fbc17 100644 --- a/test/ts-scenario/steps/base_api.ts +++ b/test/ts-scenario/src/steps/base_api.ts @@ -14,7 +14,7 @@ Given(/^I have created a client named (.+?) based on information in profile (.+? async (clientName: string, ccpName: string, userOrg: string) => { // Get a CCP Helper - const profilePath: string = path.join(__dirname, '../config', ccpName); + const profilePath: string = path.join(Constants.CONFIG_PATH, ccpName); BaseUtils.logMsg(`loading profile ${profilePath}`); const ccp: CommonConnectionProfileHelper = new CommonConnectionProfileHelper(profilePath, true); diff --git a/test/ts-scenario/steps/channel_operations.ts b/test/ts-scenario/src/steps/channel_operations.ts similarity index 100% rename from test/ts-scenario/steps/channel_operations.ts rename to test/ts-scenario/src/steps/channel_operations.ts diff --git a/test/ts-scenario/steps/cli.ts b/test/ts-scenario/src/steps/cli.ts similarity index 100% rename from test/ts-scenario/steps/cli.ts rename to test/ts-scenario/src/steps/cli.ts diff --git a/test/ts-scenario/steps/constants.ts b/test/ts-scenario/src/steps/constants.ts similarity index 84% rename from test/ts-scenario/steps/constants.ts rename to test/ts-scenario/src/steps/constants.ts index b1fc5d4c57..f675b429c7 100644 --- a/test/ts-scenario/steps/constants.ts +++ b/test/ts-scenario/src/steps/constants.ts @@ -2,6 +2,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as path from 'path'; + // State store items (just in case you don't want to look at the code) // - Users Map @@ -19,14 +21,19 @@ export const INSTALL_TIMEOUT = 120000; export const INSTANTIATE_TIMEOUT = 300000; // Paths -export const LIB_TO_CONFIG = '../../config'; -export const LIB_TO_CHAINCODE = '../../../ts-fixtures/chaincode'; -export const LIB_TO_POLICIES = '../../config/policies.json'; -export const LIB_TO_TEMP = '../../../temp'; -export const STEPS_TO_POLICIES = '../config/policies.json'; -export const UTIL_TO_CONFIG = '../../../config'; - -export const GO_PATH = '../../../ts-fixtures/chaincode/goLang/'; + +const TEST_PATH = path.resolve(__dirname, '..', '..', '..'); +const FIXTURES_PATH = path.join(TEST_PATH, 'ts-fixtures'); +const SCENARIO_PATH = path.join(TEST_PATH, 'ts-scenario'); + +export const CHAINCODE_PATH = path.join(FIXTURES_PATH, 'chaincode'); +export const CONFIG_PATH = path.join(SCENARIO_PATH, 'config'); +export const TEMP_PATH = path.join(TEST_PATH, 'temp'); +export const DOCKER_COMPOSE_PATH = path.join(FIXTURES_PATH, 'docker-compose'); + +export const POLICIES = path.join(CONFIG_PATH, 'policies.json'); + +export const GO_PATH = path.join(FIXTURES_PATH, 'chaincode', 'goLang/'); export const GO_PRE_PEND = 'github.com'; // Features run diff --git a/test/ts-scenario/steps/debug.ts b/test/ts-scenario/src/steps/debug.ts similarity index 100% rename from test/ts-scenario/steps/debug.ts rename to test/ts-scenario/src/steps/debug.ts diff --git a/test/ts-scenario/steps/deprecated.ts b/test/ts-scenario/src/steps/deprecated.ts similarity index 93% rename from test/ts-scenario/steps/deprecated.ts rename to test/ts-scenario/src/steps/deprecated.ts index e9b27a8cea..373e967d4d 100644 --- a/test/ts-scenario/steps/deprecated.ts +++ b/test/ts-scenario/src/steps/deprecated.ts @@ -24,13 +24,13 @@ Given(/^I use the deprecated sdk to (.+?) a (.+?) smart contract named (.+?) at const tls: boolean = (fabricState.type.localeCompare('tls') === 0); // Create and persist the new gateway - const profilePath: string = path.join(__dirname, '../config', ccpName); + const profilePath: string = path.join(Constants.CONFIG_PATH, ccpName); const ccp: CommonConnectionProfileHelper = new CommonConnectionProfileHelper(profilePath, true); const isUpgrade: boolean = (deployType.localeCompare('upgrade') === 0); // eslint-disable-next-line max-len // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-var-requires,@typescript-eslint/no-explicit-any - const policy: EndorsementPolicy = require(path.join(__dirname, Constants.STEPS_TO_POLICIES))[policyType]; + const policy: EndorsementPolicy = require(Constants.POLICIES)[policyType]; for (const orgName of Object.keys(ccp.getOrganizations())) { const isInstalled: boolean = await AdminUtils.isOrgChaincodeInstalled(orgName, ccp, ccName, ccVersion); if (isInstalled) { diff --git a/test/ts-scenario/steps/docker.ts b/test/ts-scenario/src/steps/docker.ts similarity index 89% rename from test/ts-scenario/steps/docker.ts rename to test/ts-scenario/src/steps/docker.ts index 0d79498329..5d158dd9fb 100644 --- a/test/ts-scenario/steps/docker.ts +++ b/test/ts-scenario/src/steps/docker.ts @@ -12,8 +12,8 @@ import * as path from 'path'; const commandRunner: CommandRunner = CommandRunner.getInstance(); const stateStore: StateStore = StateStore.getInstance(); -const nonTlsNetwork = '../../ts-fixtures/docker-compose/docker-compose.yaml'; -const tlsNetwork = '../../ts-fixtures/docker-compose/docker-compose-tls.yaml'; +const nonTlsNetwork = path.join(Constants.DOCKER_COMPOSE_PATH, 'docker-compose.yaml'); +const tlsNetwork = path.join(Constants.DOCKER_COMPOSE_PATH, '/docker-compose-tls.yaml'); Given(/^I deploy a (.+?) Fabric network at (.+?) version/, {timeout: Constants.STEP_LONG}, async (type: string, version: string) => { @@ -35,9 +35,9 @@ Given(/^I deploy a (.+?) Fabric network at (.+?) version/, {timeout: Constants.S if (!fabricState || !fabricState.deployed) { BaseUtils.logMsg(` **** deploying a new fabric network of type ${type} version ${version}`); if (type.localeCompare('non-tls') === 0) { - await commandRunner.runShellCommand(true, 'docker-compose -f ' + path.join(__dirname, nonTlsNetwork) + ' -p node up -d'); + await commandRunner.runShellCommand(true, 'docker-compose -f ' + nonTlsNetwork + ' -p node up -d'); } else { - await commandRunner.runShellCommand(true, 'docker-compose -f ' + path.join(__dirname, tlsNetwork) + ' -p node up -d'); + await commandRunner.runShellCommand(true, 'docker-compose -f ' + tlsNetwork + ' -p node up -d'); } stateStore.set(Constants.FABRIC_STATE, {deployed: true, type, version}); await BaseUtils.sleep(Constants.INC_SHORT); @@ -54,9 +54,9 @@ Given(/^I deploy a (.+?) Fabric network at (.+?) version/, {timeout: Constants.S await BaseUtils.sleep(Constants.INC_MED); if (type.localeCompare('non-tls') === 0) { - await commandRunner.runShellCommand(true, 'docker-compose -f ' + path.join(__dirname, nonTlsNetwork) + ' -p node up -d'); + await commandRunner.runShellCommand(true, 'docker-compose -f ' + nonTlsNetwork + ' -p node up -d'); } else { - await commandRunner.runShellCommand(true, 'docker-compose -f ' + path.join(__dirname, tlsNetwork) + ' -p node up -d'); + await commandRunner.runShellCommand(true, 'docker-compose -f ' + tlsNetwork + ' -p node up -d'); } stateStore.set(Constants.FABRIC_STATE, {deployed: true, type, version}); await BaseUtils.sleep(Constants.INC_SHORT); diff --git a/test/ts-scenario/steps/event-listeners.ts b/test/ts-scenario/src/steps/event-listeners.ts similarity index 100% rename from test/ts-scenario/steps/event-listeners.ts rename to test/ts-scenario/src/steps/event-listeners.ts diff --git a/test/ts-scenario/steps/lib/chaincode.ts b/test/ts-scenario/src/steps/lib/chaincode.ts similarity index 100% rename from test/ts-scenario/steps/lib/chaincode.ts rename to test/ts-scenario/src/steps/lib/chaincode.ts diff --git a/test/ts-scenario/steps/lib/channel.ts b/test/ts-scenario/src/steps/lib/channel.ts similarity index 100% rename from test/ts-scenario/steps/lib/channel.ts rename to test/ts-scenario/src/steps/lib/channel.ts diff --git a/test/ts-scenario/steps/lib/contract.ts b/test/ts-scenario/src/steps/lib/contract.ts similarity index 100% rename from test/ts-scenario/steps/lib/contract.ts rename to test/ts-scenario/src/steps/lib/contract.ts diff --git a/test/ts-scenario/steps/lib/deprecatedSDK.ts b/test/ts-scenario/src/steps/lib/deprecatedSDK.ts similarity index 99% rename from test/ts-scenario/steps/lib/deprecatedSDK.ts rename to test/ts-scenario/src/steps/lib/deprecatedSDK.ts index 6d48a15cc0..ec33aa8f6f 100644 --- a/test/ts-scenario/steps/lib/deprecatedSDK.ts +++ b/test/ts-scenario/src/steps/lib/deprecatedSDK.ts @@ -79,7 +79,7 @@ export async function sdk_chaincode_install_for_org(ccType: 'golang' | 'car' | ' await AdminUtils.getSubmitter(client, true /* get peer org admin */, orgName, ccp); // chaincode and metadata paths - const chaincodePath: string = path.join(__dirname, Constants.LIB_TO_CHAINCODE, ccType, ccName); + const chaincodePath: string = path.join(Constants.CHAINCODE_PATH, ccType, ccName); const metadataPath: string = path.join(chaincodePath, 'metadata'); // send proposal to endorser diff --git a/test/ts-scenario/steps/lib/gateway.ts b/test/ts-scenario/src/steps/lib/gateway.ts similarity index 98% rename from test/ts-scenario/steps/lib/gateway.ts rename to test/ts-scenario/src/steps/lib/gateway.ts index bb4f2c1774..47763637d4 100644 --- a/test/ts-scenario/steps/lib/gateway.ts +++ b/test/ts-scenario/src/steps/lib/gateway.ts @@ -11,8 +11,8 @@ import FabricCAClient = require('fabric-ca-client'); import {Contract, DefaultEventHandlerStrategies, DefaultQueryHandlerStrategies, Gateway, GatewayOptions, HsmOptions, HsmX509Provider, Identity, IdentityProvider, Network, QueryHandlerFactory, Transaction, TransientMap, TxEventHandlerFactory, Wallet, Wallets, HsmX509Identity, X509Identity} from 'fabric-network'; import * as fs from 'fs'; import * as path from 'path'; -import {createQueryHandler as sampleQueryStrategy} from '../../config/handlers/sample-query-handler'; -import {createTransactionEventHandler as sampleTxnEventStrategy} from '../../config/handlers/sample-transaction-event-handler'; +import {createQueryHandler as sampleQueryStrategy} from '../../handlers/sample-query-handler'; +import {createTransactionEventHandler as sampleTxnEventStrategy} from '../../handlers/sample-transaction-event-handler'; import * as Constants from '../constants'; import * as AdminUtils from './utility/adminUtils'; import * as BaseUtils from './utility/baseUtils'; @@ -97,7 +97,7 @@ export async function createGateway(ccp: CommonConnectionProfileHelper, tls: boo break; case Constants.FILE_WALLET: { - const tempDir: string = path.join(__dirname, Constants.LIB_TO_TEMP, Constants.FILE_WALLET); + const tempDir: string = path.join(Constants.TEMP_PATH, Constants.FILE_WALLET); if (fs.existsSync(tempDir)) { BaseUtils.recursiveDirDelete(tempDir); } diff --git a/test/ts-scenario/steps/lib/listeners.ts b/test/ts-scenario/src/steps/lib/listeners.ts similarity index 100% rename from test/ts-scenario/steps/lib/listeners.ts rename to test/ts-scenario/src/steps/lib/listeners.ts diff --git a/test/ts-scenario/steps/lib/transactions.ts b/test/ts-scenario/src/steps/lib/transactions.ts similarity index 100% rename from test/ts-scenario/steps/lib/transactions.ts rename to test/ts-scenario/src/steps/lib/transactions.ts diff --git a/test/ts-scenario/steps/lib/utility/adminUtils.ts b/test/ts-scenario/src/steps/lib/utility/adminUtils.ts similarity index 97% rename from test/ts-scenario/steps/lib/utility/adminUtils.ts rename to test/ts-scenario/src/steps/lib/utility/adminUtils.ts index 088a8b26df..10635342fd 100644 --- a/test/ts-scenario/steps/lib/utility/adminUtils.ts +++ b/test/ts-scenario/src/steps/lib/utility/adminUtils.ts @@ -205,7 +205,7 @@ export async function assignOrgAdmin(client: Client, orgName: string, ccp: Commo export async function isOrgChaincodeInstalled(orgName: string, ccp: CommonConnectionProfileHelper, chaincodeName: string, chaincodeVersion: string): Promise { BaseUtils.logMsg(`Checking if smart contract ${chaincodeName} at version ${chaincodeVersion} has been installed`); - const clientPath: string = path.join(__dirname, Constants.UTIL_TO_CONFIG, orgName + '.json'); + const clientPath: string = path.join(Constants.CONFIG_PATH, orgName + '.json'); const orgClient: Client = Client.loadFromConfig(clientPath); // Augment it with full CCP @@ -239,7 +239,7 @@ export async function isOrgChaincodeInstalled(orgName: string, ccp: CommonConnec export async function isChaincodeInstantiatedOnChannel(orgName: string, ccp: CommonConnectionProfileHelper, channelName: string, chaincodeName: string, chaincodeVersion: string): Promise { BaseUtils.logMsg(`Checking if smart contract ${chaincodeName} has been instantiated on channel ${channelName}`); - const clientPath: string = path.join(__dirname, Constants.UTIL_TO_CONFIG, orgName + '.json'); + const clientPath: string = path.join(Constants.CONFIG_PATH, orgName + '.json'); const orgClient: Client = Client.loadFromConfig(clientPath); // Augment it with full CCP @@ -280,7 +280,7 @@ export function isChannelCreated(channelName: string): boolean { * @param channelName the name of the channel to check */ export async function isOrgChannelJoined(orgName: string, ccp: CommonConnectionProfileHelper, channelName: string): Promise { - const clientPath: string = path.join(__dirname, Constants.UTIL_TO_CONFIG, orgName + '.json'); + const clientPath: string = path.join(Constants.CONFIG_PATH, orgName + '.json'); const orgClient: Client = Client.loadFromConfig(clientPath); // Augment it with full CCP diff --git a/test/ts-scenario/steps/lib/utility/baseUtils.ts b/test/ts-scenario/src/steps/lib/utility/baseUtils.ts similarity index 100% rename from test/ts-scenario/steps/lib/utility/baseUtils.ts rename to test/ts-scenario/src/steps/lib/utility/baseUtils.ts diff --git a/test/ts-scenario/steps/lib/utility/clientUtils.ts b/test/ts-scenario/src/steps/lib/utility/clientUtils.ts similarity index 100% rename from test/ts-scenario/steps/lib/utility/clientUtils.ts rename to test/ts-scenario/src/steps/lib/utility/clientUtils.ts diff --git a/test/ts-scenario/steps/lib/utility/commandRunner.ts b/test/ts-scenario/src/steps/lib/utility/commandRunner.ts similarity index 100% rename from test/ts-scenario/steps/lib/utility/commandRunner.ts rename to test/ts-scenario/src/steps/lib/utility/commandRunner.ts diff --git a/test/ts-scenario/steps/lib/utility/commonConnectionProfileHelper.ts b/test/ts-scenario/src/steps/lib/utility/commonConnectionProfileHelper.ts similarity index 100% rename from test/ts-scenario/steps/lib/utility/commonConnectionProfileHelper.ts rename to test/ts-scenario/src/steps/lib/utility/commonConnectionProfileHelper.ts diff --git a/test/ts-scenario/steps/lib/utility/stateStore.ts b/test/ts-scenario/src/steps/lib/utility/stateStore.ts similarity index 100% rename from test/ts-scenario/steps/lib/utility/stateStore.ts rename to test/ts-scenario/src/steps/lib/utility/stateStore.ts diff --git a/test/ts-scenario/steps/lifecycle.ts b/test/ts-scenario/src/steps/lifecycle.ts similarity index 94% rename from test/ts-scenario/steps/lifecycle.ts rename to test/ts-scenario/src/steps/lifecycle.ts index 8987319466..881a21a873 100644 --- a/test/ts-scenario/steps/lifecycle.ts +++ b/test/ts-scenario/src/steps/lifecycle.ts @@ -12,8 +12,8 @@ import * as path from 'path'; const stateStore: StateStore = StateStore.getInstance(); -const lifecycleCcp: CommonConnectionProfileHelper = new CommonConnectionProfileHelper(path.join(__dirname, '../config', 'ccp-lifecycle.json'), true); -const lifecycleCcpTls: CommonConnectionProfileHelper = new CommonConnectionProfileHelper(path.join(__dirname, '../config', 'ccp-lifecycle-tls.json'), true); +const lifecycleCcp: CommonConnectionProfileHelper = new CommonConnectionProfileHelper(path.join(Constants.CONFIG_PATH, 'ccp-lifecycle.json'), true); +const lifecycleCcpTls: CommonConnectionProfileHelper = new CommonConnectionProfileHelper(path.join(Constants.CONFIG_PATH, 'ccp-lifecycle-tls.json'), true); Then(/^I can (submit|query) invalid function (.+?) on contract named (.+?) as organization (.+?) on channel (.+?) with args (.+?) I receive an error with status (.+?) and message containing (.+?)$/, {timeout: Constants.STEP_LONG}, async (submit: string, contractFunction: string, contractName: string, orgName: string, channelName: string, contractAgs: string, status: string, message: string) => { diff --git a/test/ts-scenario/steps/network-model.ts b/test/ts-scenario/src/steps/network-model.ts similarity index 98% rename from test/ts-scenario/steps/network-model.ts rename to test/ts-scenario/src/steps/network-model.ts index d313c7a04a..72ba686615 100644 --- a/test/ts-scenario/steps/network-model.ts +++ b/test/ts-scenario/src/steps/network-model.ts @@ -35,7 +35,7 @@ Given(/^I have a (.+?) backed gateway named (.+?) with discovery set to (.+?) fo try { // Create and persist the new gateway BaseUtils.logMsg(`Creating new Gateway named ${gatewayName}`); - const profilePath: string = path.join(__dirname, '../config', ccpName); + const profilePath: string = path.join(Constants.CONFIG_PATH, ccpName); const ccp: CommonConnectionProfileHelper = new CommonConnectionProfileHelper(profilePath, true); return await Gateway.createGateway(ccp, tls, userName, orgName || Constants.DEFAULT_ORG, gatewayName, useDiscovery.toLowerCase() === 'true', walletType); } catch (err) { diff --git a/test/ts-scenario/support/hooks.ts b/test/ts-scenario/src/support/hooks.ts similarity index 100% rename from test/ts-scenario/support/hooks.ts rename to test/ts-scenario/src/support/hooks.ts diff --git a/test/ts-scenario/tsconfig.json b/test/ts-scenario/tsconfig.json index d6da1b0377..249824fd4f 100644 --- a/test/ts-scenario/tsconfig.json +++ b/test/ts-scenario/tsconfig.json @@ -4,9 +4,8 @@ "compilerOptions": { "sourceMap": true, "strict": true, - "experimentalDecorators": true - }, - "exclude": [ - "node_modules" - ], + "experimentalDecorators": true, + "outDir": "lib", + "rootDir": "src" + } }