Skip to content

Commit

Permalink
FAB-1824 CouchDBKeyValueStore setValue to return value
Browse files Browse the repository at this point in the history
To make CouchDBKeyValueStore setValue consistent with
FileKeyValueStore setValue, the return value is changed
from boolean to the value.

Additionally, fabric-ca default port is changed from 8888
to 7054 to sync up the fabric-sdk-node code with
change 4671.  Changed README.md references to COP with
fabric-ca.

Change-Id: I6c11cbca964331aaa5823f3144ac085bd98dd363
Signed-off-by: cdaughtr <[email protected]>
  • Loading branch information
cdaughtr committed Jan 24, 2017
1 parent 84f36d2 commit babccee
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 36 deletions.
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Clone the project and launch the following commands to install the dependencies

This project publishes two separate npm packages:
* `hfc` - main client for the Hyperledger Fabric. Applications can use this package to deploy chaincodes, submit transactions and make queries against a Hyperledger Fabric-based blockchain network.
* `hfc-cop` - client for the optional component in Hyperledger Fabric, [COP](https://github.com/hyperledger/fabric-cop). The COP component allows applications to enroll Peers and application users to establish trusted identities on the blockchain network. It also provides support for pseudonymous transaction submissions with Transaction Certificates. If the target blockchain network is configured with standard Certificate Authorities for trust anchors, then the application does not need to use this package.
* `hfc-cop` - client for the optional component in Hyperledger Fabric, [fabric-ca](https://github.com/hyperledger/fabric-ca). The fabric-ca component allows applications to enroll Peers and application users to establish trusted identities on the blockchain network. It also provides support for pseudonymous transaction submissions with Transaction Certificates. If the target blockchain network is configured with standard Certificate Authorities for trust anchors, then the application does not need to use this package.

In the project root folder:
* `npm install` to install dependencies
Expand All @@ -30,8 +30,8 @@ In the project root folder:
* `npm test` 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. Because v1.0 is still in active development, you still need the vagrant environment to build the necessary Docker images needed to run the network. Follow the steps below to set it up.
* You will need the COP server (new implementation of the member service) to run the tests. Because the COP project's build script does not yet produce a docker image, you'd need to run the COP server as a native process inside vagrant
* git clone both the *fabric* and *fabric-cop* repositories into the $GOPATH/src/github.com/hyperledger folder in your native host (MacOS, Windows or Ubuntu, etc).
* You will need the fabric-ca server (new implementation of the member service) to run the tests. Because the fabric-ca project's build script does not yet produce a docker image, you'd need to run the fabric-ca server as a native process inside vagrant
* git clone both the *fabric* and *fabric-ca* repositories into the $GOPATH/src/github.com/hyperledger folder in your native host (MacOS, Windows or Ubuntu, etc).

If you are using a Mac and would like to build the docker images and run them natively instead of using vagrant, do the following:
* If docker is installed and it’s not ‘Docker for Mac’, uninstall and follow Docker’s clean up instructions to uninstall completely.
Expand All @@ -43,22 +43,21 @@ If you are using a Mac and would like to build the docker images and run them na
* `cd fabric/devenv`
* Open the file `Vagrantfile` and insert the following statement below the existing `config.vm.network` statements:
* ` config.vm.network :forwarded_port, guest: 7056, host: 7056 # Openchain gRPC services`
* ` config.vm.network :forwarded_port, guest: 8888, host: 8888 # COP services`

* run `vagrant up` to launch the vagrant VM
* Once inside vagrant, follow these steps to start the COP server and the Peers network with orderer
* start COP (new membership service)
* cd `$GOPATH/src/github.com/hyperledger/fabric-cop
* run `make cop` to build the COP binary or follow the instructions in [fabric-cop README](https://github.com/hyperledger/fabric-cop)
* from the `fabric-cop` folder, launch the following command to start the COP server. The ec.pem and ec-key.pem certificates sets up the COP server as the trusted root that the Peer nodes have been statically configured as a temporary measure. In other words, the Peers will be able to trust any user certificates that have been signed by the COP server. This is important because the endorser code inside the Peer will need to validate the user certificate issued by COP before using it to verify the signature of the transaction proposal.
* `bin/cop server start -ca testdata/ec.pem -ca-key testdata/ec-key.pem -config testdata/testconfig.json`
* Once inside vagrant, follow these steps to start the fabric-ca server and the Peers network with orderer
* start fabric-ca (new membership service)
* cd `$GOPATH/src/github.com/hyperledger/fabric-ca
* run `make fabric-ca` to build the fabric-ca binary or follow the instructions in [fabric-ca README](https://github.com/hyperledger/fabric-ca)
* from the `fabric-ca` folder, launch the following command to start the fabric-ca server. The ec.pem and ec-key.pem certificates sets up the fabric-ca server as the trusted root that the Peer nodes have been statically configured as a temporary measure. In other words, the Peers will be able to trust any user certificates that have been signed by the fabric-ca server. This is important because the endorser code inside the Peer will need to validate the user certificate issued by fabric-ca before using it to verify the signature of the transaction proposal.
* `bin/fabric-ca server start -ca testdata/ec.pem -ca-key testdata/ec-key.pem -config testdata/testconfig.json`
* start the Peer network
* `cd $GOPATH/src/github.com/hyperledger/fabric`
* run `make docker` to build the docker images
* create a docker-compose.yml file in home directory (/home/vagrant), and copy [docker-compose.yml](https://raw.githubusercontent.com/hyperledger/fabric-sdk-node/master/test/fixtures/docker-compose.yml) file content into the file
* from /home/vagrant, run `docker-compose up --force-recreate` to launch the network
* Back in your native host (MacOS, or Windows, or Ubuntu, etc), run the following tests:
* Clear out your previous key value store if needed for fabric-sdk-node (`rm -fr /tmp/hfc-*`) and for fabric-cop (`rm $HOME/.cop/cop.db`)
* Clear out your previous key value store if needed for fabric-sdk-node (`rm -fr /tmp/hfc-*`) and for fabric-ca (`rm <...>/fabric-ca/testdata/fabric-ca.db`)
* Clear out your previous chaincode if needed by restarting the docker images (`docker-compose up --force-recreate`)
* Run `gulp test` to run the entire test bucket and generate coverage reports (both in console output and HTMLs)
* Test user management by member services with the `test/unit/ca-tests.js`. This test exercises the 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.
Expand Down Expand Up @@ -145,4 +144,4 @@ HFC defines the following abstract classes for application developers to supply

2. The cryptography suite used by the default implementation uses ECDSA for asymmetric keys cryptography, AES for encryption and SHA2/3 for secure hashes. A different suite can be plugged in with "CRYPTO_SUITE" environment variable specifying full require() path to the alternative implementation of the api.CrytoSuite abstract class.

3. If the user application uses an alternative membership service than the one provided by the component `fabric-cop`, the client code will likely need to use an alternative client to `hfc-cop` to interact with that membership service.
3. If the user application uses an alternative membership service than the one provided by the component `fabric-ca`, the client code will likely need to use an alternative client to `hfc-cop` to interact with that membership service.
12 changes: 1 addition & 11 deletions hfc/lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,7 @@ var Client = class {
.then(
function(result) {
logger.debug('saveUserToStateStore, store.setValue, result = ' + result);
// FileKeyValueStore returns value. CouchDBKeyValueStore returns boolean.
if (typeof(result) === 'boolean') {
if (result == true) {
resolve(self._userContext);
} else {
logger.debug('saveUserToStateStore, store.setValue, reject result');
reject(new Error('Failed to save user to state store.'));
}
} else {
resolve(self._userContext);
}
resolve(self._userContext);
},
function (reason) {
logger.debug('saveUserToStateStore, store.setValue, reject reason = ' + reason);
Expand Down
4 changes: 2 additions & 2 deletions hfc/lib/impl/CouchDBKeyValueStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ var CouchDBKeyValueStore = class extends api.KeyValueStore {
self._dbInsert({ _id: name, member: value })
.then( function (status) {
logger.debug('setValue add: ' + name + ', status: ' + status);
if (status == true) resolve(status);
if (status == true) resolve(value);
else reject(new Error('Couch database insert add failed.'));
});
}
Expand All @@ -177,7 +177,7 @@ var CouchDBKeyValueStore = class extends api.KeyValueStore {
self._dbInsert({ _id: name, _rev: body._rev, member: value })
.then( function (status) {
logger.debug('setValue update: ' + name + ', status: ' + status);
if (status == true) resolve(status);
if (status == true) resolve(value);
else reject(new Error('Couch database insert update failed.'));
});
}
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ services:
cop:
image: hyperledger/fabric-ca
ports:
- "8888:8888"
- "7054:7054"
command: sh -c 'fabric-ca server start -ca /.fabric-ca/ec.pem -ca-key /.fabric-ca/ec-key.pem -config /etc/hyperledger/fabric-ca/server-config.json -address "0.0.0.0"'
container_name: ca

orderer:
image: hyperledger/fabric-orderer
environment:
- ORDERER_GENERAL_LEDGERTYPE=ram
- ORDERER_GENERAL_LOGLEVEL=debug
- ORDERER_GENERAL_BATCHTIMEOUT=10s
- ORDERER_GENERAL_MAXMESSAGECOUNT=10
- ORDERER_GENERAL_MAXWINDOWSIZE=1000
Expand Down
2 changes: 1 addition & 1 deletion test/unit/chain-fabriccop-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ test('Attempt to use FabricCOPServices',function(t){
function(kvs) {
client.setStateStore(kvs);

var copService = new FabricCOPServices('http://localhost:8888');
var copService = new FabricCOPServices('http://localhost:7054');
copService.enroll({
enrollmentID: 'testUser',
enrollmentSecret: 'user1'
Expand Down
2 changes: 1 addition & 1 deletion test/unit/cloudant-fabriccop-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ test('Use FabricCOPServices wih a Cloudant CouchDB KeyValueStore', function(t) {
process.exit(1);
}
t.comment('Initialize the COP server connection and KeyValueStore');
return new FabricCOPServices('http://localhost:8888', kvs);
return new FabricCOPServices('http://localhost:7054', kvs);
},
function(err) {
console.log(err);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/couchdb-fabriccop-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ test('Use FabricCOPServices with a CouchDB KeyValueStore', function(t) {
process.exit(1);
}
t.comment('Initialize the COP server connection and KeyValueStore');
return new FabricCOPServices('http://localhost:8888', kvs);
return new FabricCOPServices('http://localhost:7054', kvs);
},
function(err) {
console.log(err);
Expand Down
6 changes: 3 additions & 3 deletions test/unit/fabriccopservices-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test('FabricCOPClient: Test enroll with missing parameters', function (t) {
var client = new FabricCOPClient({
protocol: 'http',
hostname: '127.0.0.1',
port: 8888
port: 7054
});

//
Expand All @@ -70,7 +70,7 @@ test('FabricCOPClient: Test enroll With Static CSR', function (t) {
var client = new FabricCOPClient({
protocol: 'http',
hostname: '127.0.0.1',
port: 8888
port: 7054
});

//
Expand Down Expand Up @@ -101,7 +101,7 @@ test('FabricCOPServices: Test enroll() With Dynamic CSR', function (t) {
// otherwise the client will not be able to decrypt the enrollment challenge
utils.setConfigSetting('crypto-keysize', 256);

var cop = new FabricCOPServices('http://localhost:8888');
var cop = new FabricCOPServices('http://localhost:7054');

var req = {
enrollmentID: 'admin',
Expand Down
6 changes: 3 additions & 3 deletions test/unit/headless-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2226,7 +2226,7 @@ test('FabricCOPClient: Test constructor', function (t) {
'Should not throw error if port is not set'
);

connectOpts.port = '8888';
connectOpts.port = '7054';

t.throws(
function () {
Expand All @@ -2236,7 +2236,7 @@ test('FabricCOPClient: Test constructor', function (t) {
'Throw error for invalid port'
);

connectOpts.port = 8888;
connectOpts.port = 7054;

t.doesNotThrow(
function () {
Expand Down Expand Up @@ -2279,7 +2279,7 @@ test('FabricCOPClient: Test _pemToDer static method',function(t){
test('FabricCOPServices: Test _parseURL() function', function (t) {

var goodHost = 'www.example.com';
var goodPort = 8888;
var goodPort = 7054;
var goodURL = 'http://' + goodHost + ':' + goodPort;
var goodURLSecure = 'https://' + goodHost + ':' + goodPort;

Expand Down
2 changes: 1 addition & 1 deletion test/unit/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function getSubmitter(username, password, client, t, loadFromConfig) {
} else {
if (!loadFromConfig) {
// need to enroll it with COP server
var cop = new copService('http://localhost:8888');
var cop = new copService('http://localhost:7054');

return cop.enroll({
enrollmentID: username,
Expand Down

0 comments on commit babccee

Please sign in to comment.