diff --git a/README.md b/README.md index a52985f8ad..d976addc07 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,7 @@ Clone the project and launch the following commands to install the dependencies In the project root folder: * `npm install` to install dependencies -* optionally, `gulp watch` to set up watch that updates fabric-ca-client's shared dependencies from fabric-client/lib and updates installed fabric-client and fabric-ca-client modules in node_modules. This command does not return, so you should keep it running in a separate command window as you work on the code and test in another command window. Note that you do NOT need to run this unless you plan to make changes in the fabric-client and fabric-ca-client packages -* optionally, `gulp doc` to generate API docs if you want to review the doc content +* optionally, `gulp docs` to generate API docs if you want to review the doc content * `npm test` or `gulp test-headless` to run the headless tests that do not require any additional set up The following tests require setting up a local blockchain network as the target. You need to build the necessary Docker images required to run the network. Follow the steps below to set it up. @@ -85,14 +84,15 @@ The unit test assumes slot '0' and user PIN `98765432`. If your configuration is * PKCS11_SLOT ### Hyperledger Fabric Client objects and reference documentation -For a high-level design specificiation for Fabric SDKs of all languages, visit [this google doc](https://docs.google.com/document/d/1R5RtIBMW9fZpli37E5Li5_Q9ve3BnQ4q3gWmGZj6Sv4/edit?usp=sharing) (Work-In-Progress). +The SDK has support for Java based Chaincode. To turn these tests off, set the environment variable "JAVA_TESTS" to false. +### Hyperledger Fabric Client objects fabric-client and fabric-ca-client are written in CommonJS modules and take advantage of ECMAScript 2015 class syntax. -* The main top-level class is **Channel**. It is the client's view of a fabric [channel](https://docs.google.com/document/d/1eRNxxQ0P8yp4Wh__Vi6ddaN_vhN2RQHP-IruHNUwyhc/). The SDK allows you to interact with multiple channels. A channel object can be configured with a different ordering service or share a common ordering service, depending on how the target blockchain network is set up. A channel object has a _KeyValueStore_ to store private keys and certificates for authenticated users. Through the channel object the application can perform +* The main top-level class is **Client**. The client's view of a fabric [channel] is the class **Channel**. +The SDK allows you to interact with multiple channels. A channel object can be configured with a different ordering service or share a common ordering service, depending on how the target blockchain network is set up. A client object has a _KeyValueStore_ to store private keys and certificates for authenticated users. Through the client object the application can perform * The **KeyValueStore** is a very simple interface which SDK uses to store and retrieve all persistent data. This data includes private keys, so it is very important to keep this storage secure. The default implementation is a simple file-based version found in the _FileKeyValueStore_ class. The SDK also provides an implementation based on CouchDB which can be configured to use a local CouchDB database or a remote deployment including a Cloudant database. * The **User** class represents an end user who transacts on the channel. The user object must have a valid enrollment configured in order to properly sign transaction requests. The enrollment materials can either be obtained from enrolling with fabric-ca or an external Certificate Authority. -* The **ChannelEventHub** class encapsulates the interaction with the network peers' event streams. * The **FabricCAClientImpl** class provides security and identity related features such as user registration and enrollment, transaction certificate issuance. The Hyperledger Fabric has a built-in implementation that issues _ECerts_ (enrollment certificates) and _TCerts_ (transaction certificates). ECerts are for enrollment identity and TCerts are for transactions. ### Pluggability diff --git a/build/tasks/test.js b/build/tasks/test.js index bd329d0ec5..bc7ee71c46 100644 --- a/build/tasks/test.js +++ b/build/tasks/test.js @@ -16,7 +16,6 @@ const tapColorize = require('tap-colorize'); const fs = require('fs-extra'); const path = require('path'); -const os = require('os'); const util = require('util'); const shell = require('gulp-shell'); const testConstants = require('../../test/unit/constants.js'); @@ -200,7 +199,7 @@ gulp.task('run-tape-unit', // too many listeners to the "unhandledRejection" event process.setMaxListeners(0); - return gulp.src(shouldRunPKCS11Tests([ + return gulp.src(shouldRunTests([ 'test/unit/**/*.js', '!test/unit/constants.js', '!test/unit/util.js', @@ -218,9 +217,9 @@ gulp.task('run-logger-unit', // too many listeners to the "unhandledRejection" event process.setMaxListeners(0); - return gulp.src(shouldRunPKCS11Tests([ + return gulp.src([ 'test/unit/logger.js' - ])) + ]) .pipe(tape({ reporter: tapColorize() })); @@ -239,7 +238,7 @@ gulp.task('run-tape-e2e', ['docker-ready'], // of the tests will re-use the same key value store that has // saved the user certificates so they can interact with the // network - return gulp.src(shouldRunPKCS11Tests([ + return gulp.src(shouldRunTests([ 'test/unit/config.js', // needs to be first 'test/integration/fabric-ca-affiliation-service-tests.js', 'test/integration/fabric-ca-identity-service-tests.js', @@ -286,20 +285,32 @@ gulp.task('run-tape-e2e', ['docker-ready'], }); // Filter out tests that should not be run on specific operating systems since only the x64 CI jobs are configured with SoftHSM -// - disable the pkcs11.js test for s390 or other jobs -// - may be enabled manually with an environment variable -function shouldRunPKCS11Tests(tests) { - if (typeof process.env.PKCS11_TESTS === 'string' && process.env.PKCS11_TESTS.toLowerCase() === 'false' && os.arch().match(/(x64|x86)/) !== null) { +// - disable the pkcs11 (HSM) tests for s390 (non x86) +// - may be enabled manually with an environment variable, (actually left enabled, but disable the non HSM version of the e2e test) +// - disable javachaincode except for x86 environment +// - may enable the java testing with environment variable +function shouldRunTests(tests) { + // for now always disable the pkcs11 testing on s390 + if (arch.indexOf('s390') === 0) { tests.push('!test/unit/pkcs11.js'); tests.push('!test/integration/network-e2e/e2e-hsm.js'); - } else if (os.arch().match(/(x64|x86)/) === null) { + // check to see if they want to test PKCS11 + } else if (typeof process.env.PKCS11_TESTS === 'string' && process.env.PKCS11_TESTS.toLowerCase() === 'true') { + tests.push('!test/integration/network-e2e/e2e.js'); + // check to see if they do not want to test PKCS11 + } else if (typeof process.env.PKCS11_TESTS === 'string' && process.env.PKCS11_TESTS.toLowerCase() === 'false') { tests.push('!test/unit/pkcs11.js'); - tests.push('!test/integration/javachaincode/e2e.js'); tests.push('!test/integration/network-e2e/e2e-hsm.js'); + // default is to run the PKCS11 tests so we need to disable the non HSM version } else { - // If running HSM tests tests.push('!test/integration/network-e2e/e2e.js'); } + // keep the java tests + if (typeof process.env.JAVA_TESTS === 'string' && process.env.JAVA_TESTS.toLowerCase() === 'true') { + // disable when z390 or when JAVA tests is off + } else if ((arch.indexOf('s390') === 0) || (typeof process.env.JAVA_TESTS === 'string' && process.env.JAVA_TESTS.toLowerCase() === 'false')) { + tests.push('!test/integration/javachaincode/e2e.js'); + } return tests; } diff --git a/test/unit/logger.js b/test/unit/logger.js index 1cc9613160..911e7bbca5 100644 --- a/test/unit/logger.js +++ b/test/unit/logger.js @@ -21,6 +21,8 @@ const fs = require('fs-extra'); const util = require('util'); const path = require('path'); +let backup_env = null; + // Logger tests ///////// function testLogger(t, ignoreLevels) { let output = ''; @@ -50,6 +52,14 @@ function testLogger(t, ignoreLevels) { } } +test('\n\n ** Logging utility tests - save settings **\n\n', (t) => { + if (process.env.HFC_LOGGING) { + backup_env = process.env.HFC_LOGGING; + } + + t.end(); +}); + test('\n\n ** Logging utility tests - built-in logger **\n\n', (t) => { if (process.env.HFC_LOGGING) { delete process.env.HFC_LOGGING; @@ -249,3 +259,18 @@ test('\n\n ** Logging utility tests - test setting an invalid external logger ** } } }); + +test('\n\n ** Logging utility tests - clean up **\n\n', (t) => { + if (backup_env) { + process.env.HFC_LOGGING = backup_env; + } + + // remove the args we added + process.argv.pop(); + // internal call. clearing the cached config. + global.hfc.config = undefined; + // internal call. clearing the cached logger. + global.hfc.logger = undefined; + + t.end(); +});