Skip to content

Commit

Permalink
Fix ts-scenario TypeScript transpile failure (#675)
Browse files Browse the repository at this point in the history
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 <Mark.S.Lewis@outlook.com>
  • Loading branch information
bestbeforetoday authored May 15, 2023
1 parent ecbe99c commit c91d573
Show file tree
Hide file tree
Showing 35 changed files with 54 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
docs/**
fabric-network/lib/**
fabric-protos/**
test/typescript/**
test/ts-scenario/lib/**
2 changes: 1 addition & 1 deletion docs/tutorials/query-peers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
2 changes: 1 addition & 1 deletion docs/tutorials/transaction-commit-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
10 changes: 0 additions & 10 deletions fabric-network/.eslintignore

This file was deleted.

11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
},
Expand Down
1 change: 1 addition & 0 deletions scripts/npm_scripts/checkLicense.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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' \
Expand Down
10 changes: 7 additions & 3 deletions scripts/utility/fabric_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions test/ts-scenario/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib/**
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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<userName: string, user: User>

Expand All @@ -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
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {

Expand All @@ -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);
Expand All @@ -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);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
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
Expand Down Expand Up @@ -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<boolean> {
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
Expand Down Expand Up @@ -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<boolean> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
File renamed without changes.
9 changes: 4 additions & 5 deletions test/ts-scenario/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
"compilerOptions": {
"sourceMap": true,
"strict": true,
"experimentalDecorators": true
},
"exclude": [
"node_modules"
],
"experimentalDecorators": true,
"outDir": "lib",
"rootDir": "src"
}
}

0 comments on commit c91d573

Please sign in to comment.