Skip to content

Commit

Permalink
[FAB-3886] Reduce steps to run gulp test
Browse files Browse the repository at this point in the history
Eliminate the need to run these preparation steps:
- gulp ca
- rm -rf /tmp/hfc-test-kvs*
- delete chaincode docker images

All the above are automated in gulp tasks and are pre-req to
gulp test

Change-Id: I5097f2cffc3b04e36bc9c98474037f4eaf964238
Signed-off-by: Jim Zhang <[email protected]>
  • Loading branch information
jimthematrix committed May 12, 2017
1 parent a705a81 commit 6e1d2a5
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 227 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Clone the project and launch the following commands to install the dependencies

In the project root folder:
* `npm install` to install dependencies
* `gulp ca` to copy common dependent modules from the `fabric-client` folder to the `fabric-ca-client` folder and the installed fabric-ca-client package under `node_modules`
* 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
* `npm test` or `gulp test-headless` to run the headless tests that do not require any additional set up
Expand All @@ -50,11 +49,7 @@ You can build the docker images in your native host (Mac, Ubuntu, Windows, etc.)
* run `docker-compose up --force-recreate` to launch the network
* Now you are ready to run the tests:
* Clear out your previous key value stores that may have cached user enrollment certificates (`rm -rf /tmp/hfc-*`, `rm -rf ~/.hfc-key-store`)
* run 'gulp test' to execute the entire test suite (535+ test cases), or you can run them individually
* Test user management by member services with the following tests that exercise the fabric-ca-client package with a KeyValueStore implementations for a file-based KeyValueStore as well as a CouchDB KeyValueStore. To successfully run this test, you must first set up a CouchDB database instance on your local machine. Please see the instructions below.
* `test/integration/fabric-ca-services-tests.js`
* `test/integration/couchdb-fabricca-tests.js`
* `test/integration/cloudant-fabricca-tests.js`
* run `gulp test` to execute the entire test suite (800+ test cases), or you can run them individually
* Test happy path from end to end, run `node test/integration/e2e.js`
* Test end to end one step at a time, make sure to follow this sequence:
* `node test/integration/e2e/create-channel.js`
Expand All @@ -63,7 +58,11 @@ You can build the docker images in your native host (Mac, Ubuntu, Windows, etc.)
* `node test/integration/e2e/instantiate-chaincode.js`
* `node test/integration/e2e/invoke-transaction.js`
* `node test/integration/e2e/query.js`
* To re-run `node test/integration/e2e.js` or `fabric-ca-services-tests.js` stop the network (ctrl-c), clean up the docker instances (`docker rm $(docker ps -aq)`) and restart the network with docker-compose as described above.
* Test user management by member services with the following tests that exercise the fabric-ca-client package with a KeyValueStore implementations for a file-based KeyValueStore as well as a CouchDB KeyValueStore. To successfully run this test, you must first set up a CouchDB database instance on your local machine. Please see the instructions below.
* `test/integration/fabric-ca-services-tests.js`
* `test/integration/couchdb-fabricca-tests.js`
* `test/integration/cloudant-fabricca-tests.js`
* To re-run `node test/integration/e2e.js` or `fabric-ca-services-tests.js` stop the network (ctrl-c), clean up the docker instances (`docker rm $(docker ps -aq)`) and restart the network with `docker-compose up` as described above.

### Contributor Check-list
The following check-list is for code contributors to make sure their changesets are compliant to the coding standards and avoid time wasted in rejected changesets:
Expand Down
28 changes: 26 additions & 2 deletions build/tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ var tape = require('gulp-tape');
var tapColorize = require('tap-colorize');
var istanbul = require('gulp-istanbul');

var fs = require('fs-extra');
var shell = require('gulp-shell');
var testConstants = require('../../test/unit/constants.js');

gulp.task('pre-test', function() {
return gulp.src([
'node_modules/fabric-client/lib/**/*.js',
Expand All @@ -13,7 +17,25 @@ gulp.task('pre-test', function() {
.pipe(istanbul.hookRequire());
});

gulp.task('test', ['lint', 'pre-test'], function() {
gulp.task('clean-up', function() {
// some tests create temporary files or directories
// they are all created in the same temp folder
return fs.removeSync(testConstants.tempdir);
});

gulp.task('docker-clean', shell.task([
// stop and remove chaincode docker instances
'docker kill $(docker ps |grep "^dev-peer0.org[12].example.com-e" |awk "{print $1}")',
'docker rm $(docker ps -a|grep "^dev-peer0.org[12].example.com-e" |awk "{print $1}")',

// remove chaincode images so that they get rebuilt during test
'docker rmi $(docker images | grep "^dev-peer0.org[12].example.com-e" | awk "{print $3}")'
], {
verbose: true, // so we can see the docker command output
ignoreErrors: true // kill and rm may fail because the containers may have been cleaned up
}));

gulp.task('test', ['clean-up', 'lint', 'docker-clean', 'pre-test', 'ca'], function() {
// use individual tests to control the sequence they get executed
// first run the ca-tests that tests all the member registration
// and enrollment scenarios (good and bad calls). Then the rest
Expand All @@ -22,6 +44,7 @@ gulp.task('test', ['lint', 'pre-test'], function() {
// network
return gulp.src([
'test/unit/**/*.js',
'!test/unit/constants.js',
'!test/unit/util.js',
'!test/unit/pkcs11.js',
'test/integration/fabric-ca-services-tests.js',
Expand Down Expand Up @@ -53,14 +76,15 @@ gulp.task('test', ['lint', 'pre-test'], function() {
}));
});

gulp.task('test-headless', ['lint', 'pre-test'], function() {
gulp.task('test-headless', ['clean-up', 'lint', 'pre-test', 'ca'], function() {
// this is needed to avoid a problem in tape-promise with adding
// too many listeners
// to the "unhandledRejection" event
process.setMaxListeners(0);

return gulp.src([
'test/unit/**/*.js',
'!test/unit/constants.js',
'!test/unit/util.js',
'!test/unit/pkcs11.js'
])
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"gulp-eslint": "^3.0.1",
"gulp-istanbul": "^1.1.1",
"gulp-jsdoc3": "^0.3.0",
"gulp-shell": "^0.6.3",
"gulp-tape": "0.0.9",
"gulp-watch": "^4.3.11",
"gunzip-maybe": "^1.3.1",
Expand Down
5 changes: 0 additions & 5 deletions peer1.pem

This file was deleted.

2 changes: 1 addition & 1 deletion test/integration/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test('\n\n ** createUser happy path - file store **\n\n', function (t) {
var prvKey = path.join(__dirname, caImport.orgs[userOrg].cryptoContent.privateKey);
var sgnCert = path.join(__dirname, caImport.orgs[userOrg].cryptoContent.signedCert);

var keyStoreOpts = {path: caImport.orgs[userOrg].storePath};
var keyStoreOpts = {path: path.join(testUtil.getTempDir(), caImport.orgs[userOrg].storePath)};
var client = new Client();
var cryptoSuite = client.newCryptoSuite(keyStoreOpts);

Expand Down
2 changes: 1 addition & 1 deletion test/integration/fileKeyValueStore-fabricca-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ test('Use FabricCAServices with a File KeyValueStore', function(t) {

var keyValueStore = hfc.getConfigSetting('key-value-store');
logger.info('File Key Value Store = ' + keyValueStore);
var keyValStorePath = '/tmp/customKeyValStorePath';
var keyValStorePath = path.join(testUtil.getTempDir(), 'customKeyValStorePath');
logger.info('keyValStorePath: '+keyValStorePath);

var client = new Client();
Expand Down
5 changes: 3 additions & 2 deletions test/unit/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var _test = require('tape-promise');
var test = _test(tape);

var tar = require('tar-fs');
var path = require('path');
var gunzip = require('gunzip-maybe');
var fs = require('fs-extra');
var grpc = require('grpc');
Expand Down Expand Up @@ -392,8 +393,8 @@ test('\n\n** Packager tests **\n\n', function(t) {
return Packager.package(testutil.CHAINCODE_PATH,'',false);
}).then((data) => {
t.comment('Verify byte data begin');
var tmpFile = '/tmp/test-deploy-copy.tar.gz';
var destDir = '/tmp/test-deploy-copy-tar-gz';
var tmpFile = path.join(testutil.getTempDir(), 'test-deploy-copy.tar.gz');
var destDir = path.join(testutil.getTempDir(), 'test-deploy-copy-tar-gz');
fs.writeFileSync(tmpFile, data);
fs.removeSync(destDir);
var pipe = fs.createReadStream(tmpFile).pipe(gunzip()).pipe(tar.extract(destDir));
Expand Down
20 changes: 10 additions & 10 deletions test/unit/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ test('\n\n ** index.js **\n\n', function (t) {

var Client = hfc;
var client = new Client();
var chainKeyValStorePath = 'tmp/chainKeyValStorePath';
var chainKeyValStorePath = path.join(testutil.getTempDir(), 'chainKeyValStorePath');
var testKey = 'keyValFileStoreName';
var testValue = 'secretKeyValue';

Expand Down Expand Up @@ -633,7 +633,7 @@ test('\n\n ** createUser error path - missing required username **\n\n', functio
var msg = 'Client.createUser parameter \'opts username\' is required.';

var userOrg = 'org1';
var keyStoreOpts = {path: caImport.orgs[userOrg].storePath};
var keyStoreOpts = {path: path.join(testutil.getTempDir(), caImport.orgs[userOrg].storePath)};

var client = new Client();

Expand Down Expand Up @@ -665,7 +665,7 @@ test('\n\n ** createUser error path - missing required mspid **\n\n', function (
var msg = 'Client.createUser parameter \'opts mspid\' is required.';

var userOrg = 'org1';
var keyStoreOpts = {path: caImport.orgs[userOrg].storePath};
var keyStoreOpts = {path: path.join(testutil.getTempDir(), caImport.orgs[userOrg].storePath)};

var client = new Client();

Expand Down Expand Up @@ -697,7 +697,7 @@ test('\n\n ** createUser error path - missing required mspid **\n\n', function (
var msg = 'Client.createUser parameter \'opts mspid\' is required.';

var userOrg = 'org1';
var keyStoreOpts = {path: caImport.orgs[userOrg].storePath};
var keyStoreOpts = {path: path.join(testutil.getTempDir(), caImport.orgs[userOrg].storePath)};

var client = new Client();

Expand Down Expand Up @@ -729,7 +729,7 @@ test('\n\n ** createUser error path - missing required cryptoContent **\n\n', fu
var msg = 'Client.createUser parameter \'opts cryptoContent\' is required.';

var userOrg = 'org1';
var keyStoreOpts = {path: caImport.orgs[userOrg].storePath};
var keyStoreOpts = {path: path.join(testutil.getTempDir(), caImport.orgs[userOrg].storePath)};

var client = new Client();

Expand Down Expand Up @@ -761,7 +761,7 @@ test('\n\n ** createUser error path - missing required cryptoContent signedCertP
var msg = 'Client.createUser both parameters \'opts cryptoContent privateKeyPEM and signedCertPEM\' strings are required.';

var userOrg = 'org1';
var keyStoreOpts = {path: caImport.orgs[userOrg].storePath};
var keyStoreOpts = {path: path.join(testutil.getTempDir(), caImport.orgs[userOrg].storePath)};

var client = new Client();

Expand Down Expand Up @@ -793,7 +793,7 @@ test('\n\n ** createUser error path - missing required cryptoContent privateKeyP
var msg = 'Client.createUser both parameters \'opts cryptoContent privateKeyPEM and signedCertPEM\' strings are required.';

var userOrg = 'org1';
var keyStoreOpts = {path: caImport.orgs[userOrg].storePath};
var keyStoreOpts = {path: path.join(testutil.getTempDir(), caImport.orgs[userOrg].storePath)};

var client = new Client();

Expand Down Expand Up @@ -825,7 +825,7 @@ test('\n\n ** createUser error path - missing required cryptoContent signedCert
var msg = 'Client.createUser both parameters \'opts cryptoContent privateKey and signedCert\' files are required.';

var userOrg = 'org1';
var keyStoreOpts = {path: caImport.orgs[userOrg].storePath};
var keyStoreOpts = {path: path.join(testutil.getTempDir(), caImport.orgs[userOrg].storePath)};

var client = new Client();

Expand Down Expand Up @@ -857,7 +857,7 @@ test('\n\n ** createUser error path - missing required cryptoContent privateKeyP
var msg = 'Client.createUser both parameters \'opts cryptoContent privateKey and signedCert\' files are required.';

var userOrg = 'org1';
var keyStoreOpts = {path: caImport.orgs[userOrg].storePath};
var keyStoreOpts = {path: path.join(testutil.getTempDir(), caImport.orgs[userOrg].storePath)};

var client = new Client();

Expand Down Expand Up @@ -889,7 +889,7 @@ test('\n\n ** createUser error path - missing required keyStoreOpts **\n\n', fun
var msg = 'Failed to load key or certificate and save to local stores';

var userOrg = 'org1';
var keyStoreOpts = {path: caImport.orgs[userOrg].storePath};
var keyStoreOpts = {path: path.join(testutil.getTempDir(), caImport.orgs[userOrg].storePath)};

var client = new Client();

Expand Down
8 changes: 8 additions & 0 deletions test/unit/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var os = require('os');
var path = require('path');

var tempdir = path.join(os.tmpdir(), 'hfc');

module.exports = {
tempdir: tempdir
};
10 changes: 6 additions & 4 deletions test/unit/crypto-key-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ var f2 = KEYUTIL.getKey(TEST_KEY_PRIVATE_CERT_PEM);
var testPubKey = new ecdsaKey(f2);

test('\n\n** CryptoKeyStore tests **\n\n', function(t) {
var keystorePath = path.join(testutil.getTempDir(), 'crypto-key-store');

t.throws(
() => {
CKS();
Expand All @@ -81,14 +83,14 @@ test('\n\n** CryptoKeyStore tests **\n\n', function(t) {
);

var store;
CKS({path: '/tmp/hfc-cks'})
CKS({path: keystorePath})
.then((st) => {
store = st;
return store.putKey(testPrivKey);
}).then((keyPEM) => {
t.pass('Successfully saved private key in store');

t.equal(fs.existsSync(path.join('/tmp/hfc-cks', testPrivKey.getSKI() + '-priv')), true,
t.equal(fs.existsSync(path.join(keystorePath, testPrivKey.getSKI() + '-priv')), true,
'Check that the private key has been saved with the proper <SKI>-priv index');

return store.getKey(testPrivKey.getSKI());
Expand All @@ -98,7 +100,7 @@ test('\n\n** CryptoKeyStore tests **\n\n', function(t) {

return store.putKey(testPubKey);
}).then((keyPEM) => {
t.equal(fs.existsSync(path.join('/tmp/hfc-cks', testPrivKey.getSKI() + '-pub')), true,
t.equal(fs.existsSync(path.join(keystorePath, testPrivKey.getSKI() + '-pub')), true,
'Check that the public key has been saved with the proper <SKI>-pub index');

return store.getKey(testPubKey.getSKI());
Expand All @@ -107,7 +109,7 @@ test('\n\n** CryptoKeyStore tests **\n\n', function(t) {
t.equal(recoveredKey.isPrivate(), true, 'Test if the recovered key is a private key');

// delete the private key entry and test if getKey() would return the public key
fs.unlinkSync(path.join('/tmp/hfc-cks', testPrivKey.getSKI() + '-priv'));
fs.unlinkSync(path.join(keystorePath, testPrivKey.getSKI() + '-priv'));
return store.getKey(testPubKey.getSKI());
}).then((recoveredKey) => {
t.notEqual(recoveredKey, null, 'Successfully read public key from store using SKI');
Expand Down
2 changes: 1 addition & 1 deletion test/unit/cryptosuite-ecdsa-aes.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var BN = require('bn.js');
var Signature = require('elliptic/lib/elliptic/ec/signature.js');
var PKCS11 = require('fabric-client/lib/impl/bccsp_pkcs11.js');

var keyValStorePath = 'tmp/keyValStore1';
var keyValStorePath = path.join(testutil.getTempDir(), 'keyValStore1');

var TEST_MSG = 'this is a test message';
var TEST_LONG_MSG = 'The Hyperledger project is an open source collaborative effort created to advance cross-industry blockchain technologies. ' +
Expand Down
Loading

0 comments on commit 6e1d2a5

Please sign in to comment.