Skip to content

Commit 9576b4b

Browse files
Fix typo in nodesdk docs and add line breaks
Change HLC -> HFC in the Running Unit Tests section Also put line breaks at 80 characters to aid in readability of the markdown source. Change-Id: I29623eae09b3eac7d0a843907a5543e4a2b8218e Signed-off-by: Julian Carrivick <[email protected]>
1 parent 457635a commit 9576b4b

File tree

1 file changed

+102
-31
lines changed

1 file changed

+102
-31
lines changed

docs/Setup/NodeSDK-setup.md

+102-31
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
## Hyperledger Fabric Client (HFC) SDK for Node.js
22

3-
The Hyperledger Fabric Client (HFC) SDK provides a powerful and easy to use API to interact with a Hyperledger Fabric blockchain.
3+
The Hyperledger Fabric Client (HFC) SDK provides a powerful and easy to use API
4+
to interact with a Hyperledger Fabric blockchain.
45

5-
This document assumes that you already have set up a Node.js development environment. If not, go [here](https://nodejs.org/en/download/package-manager/) to download and install Node.js for your OS. You'll also want the latest version of `npm` installed. For that, execute `sudo npm install npm -g` to get the latest version.
6+
This document assumes that you already have set up a Node.js development
7+
environment. If not, go [here](https://nodejs.org/en/download/package-manager/)
8+
to download and install Node.js for your OS. You'll also want the latest version
9+
of `npm` installed. For that, execute `sudo npm install npm -g` to get the
10+
latest version.
611

712
### Installing the hfc module
813

9-
We publish the `hfc` node module to `npm`. To install `hfc` from npm simply execute the following command:
14+
We publish the `hfc` node module to `npm`. To install `hfc` from npm simply
15+
execute the following command:
1016

1117
```
1218
npm install -g hfc
@@ -16,24 +22,41 @@ npm install -g hfc
1622

1723
The sections in this document are as follows:
1824

19-
* The [Getting Started](#getting-started) section is intended to help you quickly get a feel for HFC, how to use it, and some of its common capabilities. This is demonstrated by example.
25+
* The [Getting Started](#getting-started) section is intended to help you
26+
quickly get a feel for HFC, how to use it, and some of its common capabilities.
27+
This is demonstrated by example.
2028

21-
* The [Getting Set Up](#getting-set-up) section shows you how to set up up your environment and how to [run the unit tests](#running-unit-tests). Looking at the implementation of the unit tests will also help you learn more about the APIs by example, including asset management and confidentiality.
29+
* The [Getting Set Up](#getting-set-up) section shows you how to set up up your
30+
environment and how to [run the unit tests](#running-unit-tests). Looking at the
31+
implementation of the unit tests will also help you learn more about the APIs by
32+
example, including asset management and confidentiality.
2233

2334
## Getting Started
24-
This purpose of this section is to help you quickly get a feel for HFC and how you may use it. It is not intended to demonstrate all of its power, but to demonstrate common use cases by example.
35+
This purpose of this section is to help you quickly get a feel for HFC and how
36+
you may use it. It is not intended to demonstrate all of its power, but to
37+
demonstrate common use cases by example.
2538

2639
### Some basic terminology
27-
First, there is some basic terminology you should understand. In order to transact on a hyperledger blockchain, you must first have an identity which has been both **registered** and **enrolled**.
40+
First, there is some basic terminology you should understand. In order to
41+
transact on a hyperledger blockchain, you must first have an identity which has
42+
been both **registered** and **enrolled**.
2843

29-
Think of **registration** as *issuing a user invitation* to join a blockchain. It consists of adding a new user name (also called an *enrollment ID*) to the membership service configuration. This can be done programatically with the `Member.register` method, or by adding the enrollment ID directly to the [membersrvc.yaml](https://github.com/hyperledger/fabric/blob/master/membersrvc/membersrvc.yaml) configuration file.
44+
Think of **registration** as *issuing a user invitation* to join a blockchain.
45+
It consists of adding a new user name (also called an *enrollment ID*) to the
46+
membership service configuration. This can be done programatically with the
47+
`Member.register` method, or by adding the enrollment ID directly to the
48+
[membersrvc.yaml](https://github.com/hyperledger/fabric/blob/master/membersrvc/membersrvc.yaml)
49+
configuration file.
3050

31-
Think of **enrollment** as *accepting a user invitation* to join a blockchain. This is always done by the entity that will transact on the blockchain. This can be done programatically via the `Member.enroll` method.
51+
Think of **enrollment** as *accepting a user invitation* to join a blockchain.
52+
This is always done by the entity that will transact on the blockchain. This can
53+
be done programatically via the `Member.enroll` method.
3254

3355
### Learn by example
3456
The best way to quickly learn HFC is by example.
3557

36-
The following example demonstrates a typical web app. The web app authenticates a user and then transacts on a blockchain on behalf of that user.
58+
The following example demonstrates a typical web app. The web app authenticates
59+
a user and then transacts on a blockchain on behalf of that user.
3760

3861
```
3962
/**
@@ -136,13 +159,22 @@ function handleUserRequest(userName, chaincodeID, fcn, args) {
136159

137160
## Getting Set Up
138161

139-
First, you'll want to have a running peer node and CA. You can follow the instructions for setting up a network [here](https://github.com/hyperledger/fabric/blob/master/docs/Setup/ca-setup.md#Operating-the-CA), and start a single peer node and CA.
162+
First, you'll want to have a running peer node and CA. You can follow the
163+
instructions for setting up a network
164+
[here](https://github.com/hyperledger/fabric/blob/master/docs/Setup/ca-setup.md#Operating-the-CA),
165+
and start a single peer node and CA.
140166

141167
### Chaincode Deployment Directory Structure
142168

143-
To have the chaincode deployment succeed in network mode, you must properly set up the chaincode project outside of your Hyperledger Fabric source tree. The following instructions will demonstrate how to properly set up the directory structure to deploy *chaincode_example02* in network mode.
169+
To have the chaincode deployment succeed in network mode, you must properly set
170+
up the chaincode project outside of your Hyperledger Fabric source tree. The
171+
following instructions will demonstrate how to properly set up the directory
172+
structure to deploy *chaincode_example02* in network mode.
144173

145-
The chaincode project must be placed under the `$GOPATH/src` directory. For example, the [chaincode_example02](https://github.com/hyperledger/fabric/blob/master/examples/chaincode/go/chaincode_example02/chaincode_example02.go) project should be placed under `$GOPATH/src/` as shown below.
174+
The chaincode project must be placed under the `$GOPATH/src` directory. For
175+
example, the
176+
[chaincode_example02](https://github.com/hyperledger/fabric/blob/master/examples/chaincode/go/chaincode_example02/chaincode_example02.go)
177+
project should be placed under `$GOPATH/src/` as shown below.
146178

147179
```
148180
mkdir -p $GOPATH/src/github.com/chaincode_example02/
@@ -159,20 +191,29 @@ govendor init
159191
govendor fetch github.com/hyperledger/fabric
160192
```
161193

162-
Now, execute `go build` to verify that all of the chaincode dependencies are present.
194+
Now, execute `go build` to verify that all of the chaincode dependencies are
195+
present.
163196

164197
```
165198
go build
166199
```
167200

168-
Next, we will switch over to the node sdk directory in the fabric repo to run the node sdk tests, to make sure you have everything properly set up. Verify that the [chain-tests.js](https://github.com/hyperledger/fabric/blob/master/sdk/node/test/unit/chain-tests.js) unit test file points to the correct chaincode project path. The default directory is set to `github.com/chaincode_example02/` as shown below. If you placed the sample chaincode elsewhere, then you will need to change that.
201+
Next, we will switch over to the node sdk directory in the fabric repo to run
202+
the node sdk tests, to make sure you have everything properly set up. Verify
203+
that the
204+
[chain-tests.js](https://github.com/hyperledger/fabric/blob/master/sdk/node/test/unit/chain-tests.js)
205+
unit test file points to the correct chaincode project path. The default
206+
directory is set to `github.com/chaincode_example02/` as shown below. If you
207+
placed the sample chaincode elsewhere, then you will need to change that.
169208

170209
```
171210
// Path to the local directory containing the chaincode project under $GOPATH
172211
var testChaincodePath = "github.com/chaincode_example02/";
173212
```
174213

175-
**Note:** You will need to run `npm install` the first time you run the sdk tests, in order to install all of the dependencies. Set the `DEPLOY_MODE` environment variable to `net` and run the chain-tests as follows:
214+
**Note:** You will need to run `npm install` the first time you run the sdk
215+
tests, in order to install all of the dependencies. Set the `DEPLOY_MODE`
216+
environment variable to `net` and run the chain-tests as follows:
176217

177218
```
178219
cd $GOPATH/src/github.com/hyperledger/fabric/sdk/node
@@ -183,7 +224,8 @@ node test/unit/chain-tests.js | node_modules/.bin/tap-spec
183224

184225
### Enabling TLS
185226

186-
If you wish to configure TLS with the Membership Services server, the following steps are required:
227+
If you wish to configure TLS with the Membership Services server, the following
228+
steps are required:
187229

188230
- Modify `$GOPATH/src/github.com/hyperledger/fabric/membersrvc/membersrvc.yaml` as follows:
189231

@@ -196,7 +238,8 @@ server:
196238
file: "/var/hyperledger/production/.membersrvc/tlsca.priv"
197239
```
198240

199-
To specify to the Membership Services (TLS) Certificate Authority (TLSCA) what X.509 v3 Certificate (with a corresponding Private Key) to use:
241+
To specify to the Membership Services (TLS) Certificate Authority (TLSCA) what
242+
X.509 v3 Certificate (with a corresponding Private Key) to use:
200243

201244
- Modify `$GOPATH/src/github.com/hyperledger/fabric/peer/core.yaml` as follows:
202245

@@ -209,39 +252,63 @@ peer:
209252
file: "/var/hyperledger/production/.membersrvc/tlsca.cert"
210253
```
211254

212-
To configure the peer to connect to the Membership Services server over TLS (otherwise, the connection will fail).
255+
To configure the peer to connect to the Membership Services server over TLS
256+
(otherwise, the connection will fail).
213257

214-
- Bootstrap your Membership Services and the peer. This is needed in order to have the file *tlsca.cert* generated by the member services.
258+
- Bootstrap your Membership Services and the peer. This is needed in order to
259+
have the file *tlsca.cert* generated by the member services.
215260

216-
- Copy `/var/hyperledger/production/.membersrvc/tlsca.cert` to `$GOPATH/src/github.com/hyperledger/fabric/sdk/node`.
261+
- Copy `/var/hyperledger/production/.membersrvc/tlsca.cert` to
262+
`$GOPATH/src/github.com/hyperledger/fabric/sdk/node`.
217263

218-
*Note:* If you cleanup the folder `/var/hyperledger/production` then don't forget to copy again the *tlsca.cert* file as described above.
264+
*Note:* If you cleanup the folder `/var/hyperledger/production` then don't
265+
forget to copy again the *tlsca.cert* file as described above.
219266

220267
## Running Unit Tests
221-
HLC includes a set of unit tests implemented with the [tape framework](https://github.com/substack/tape). The [unit test script](https://github.com/hyperledger/fabric/blob/master/sdk/node/bin/run-unit-tests.sh) builds and runs both the membership service server and the peer node for you, therefore you do not have to start those manually.
268+
HFC includes a set of unit tests implemented with the
269+
[tape framework](https://github.com/substack/tape). The
270+
[unit test script](https://github.com/hyperledger/fabric/blob/master/sdk/node/bin/run-unit-tests.sh)
271+
builds and runs both the membership service server and the peer node for you,
272+
therefore you do not have to start those manually.
222273

223274
### Running the SDK unit tests
224-
HFC includes a set of unit tests implemented with the [tape framework](https://github.com/substack/tape). To run the unit tests, execute the following commands:
275+
HFC includes a set of unit tests implemented with the
276+
[tape framework](https://github.com/substack/tape). To run the unit tests,
277+
execute the following commands:
225278

226279
cd $GOPATH/src/github.com/hyperledger/fabric
227280
make node-sdk-unit-tests
228281

229-
The following are brief descriptions of each of the unit tests that are being run.
282+
The following are brief descriptions of each of the unit tests that are being
283+
run.
230284

231285
#### registrar
232-
The [registrar.js](https://github.com/hyperledger/fabric/blob/master/sdk/node/test/unit/registrar.js) test case exercises registering users with Membership Services. It also tests registering a designated registrar user which can then register additional users.
286+
The [registrar.js](https://github.com/hyperledger/fabric/blob/master/sdk/node/test/unit/registrar.js)
287+
test case exercises registering users with Membership Services. It also tests
288+
registering a designated registrar user which can then register additional users.
233289

234290
#### chain-tests
235-
The [chain-tests.js](https://github.com/hyperledger/fabric/blob/master/sdk/node/test/unit/chain-tests.js) test case exercises the [chaincode_example02.go](https://github.com/hyperledger/fabric/tree/master/examples/chaincode/go/chaincode_example02) chaincode when it has been deployed in both development mode and network mode.
291+
The [chain-tests.js](https://github.com/hyperledger/fabric/blob/master/sdk/node/test/unit/chain-tests.js)
292+
test case exercises the [chaincode_example02.go](https://github.com/hyperledger/fabric/tree/master/examples/chaincode/go/chaincode_example02)
293+
chaincode when it has been deployed in both development mode and network mode.
236294

237295
#### asset-mgmt
238-
The [asset-mgmt.js](https://github.com/hyperledger/fabric/blob/master/sdk/node/test/unit/asset-mgmt.js) test case exercises the [asset_management.go](https://github.com/hyperledger/fabric/tree/master/examples/chaincode/go/asset_management) chaincode when it has been deployed in both development mode and network mode.
296+
The [asset-mgmt.js](https://github.com/hyperledger/fabric/blob/master/sdk/node/test/unit/asset-mgmt.js)
297+
test case exercises the [asset_management.go](https://github.com/hyperledger/fabric/tree/master/examples/chaincode/go/asset_management)
298+
chaincode when it has been deployed in both development mode and network mode.
239299

240300
#### asset-mgmt-with-roles
241-
The [asset-mgmt-with-roles.js](https://github.com/hyperledger/fabric/blob/master/sdk/node/test/unit/asset-mgmt-with-roles.js) test case exercises the [asset_management_with_roles.go](https://github.com/hyperledger/fabric/tree/master/examples/chaincode/go/asset_management_with_roles) chaincode when it has been deployed in both development mode and network mode.
301+
The [asset-mgmt-with-roles.js](https://github.com/hyperledger/fabric/blob/master/sdk/node/test/unit/asset-mgmt-with-roles.js)
302+
test case exercises the [asset_management_with_roles.go](https://github.com/hyperledger/fabric/tree/master/examples/chaincode/go/asset_management_with_roles)
303+
chaincode when it has been deployed in both development mode and network mode.
242304

243305
#### Troublingshooting
244-
If you see errors stating that the client has already been registered/enrolled, keep in mind that you can perform the enrollment process only once, as the enrollmentSecret is a one-time-use password. You will see these errors if you have performed a user registration/enrollment and subsequently deleted the cryptographic tokens stored on the client side. The next time you try to enroll, errors similar to the ones below will be seen.
306+
If you see errors stating that the client has already been registered/enrolled,
307+
keep in mind that you can perform the enrollment process only once, as the
308+
enrollmentSecret is a one-time-use password. You will see these errors if you
309+
have performed a user registration/enrollment and subsequently deleted the
310+
cryptographic tokens stored on the client side. The next time you try to enroll,
311+
errors similar to the ones below will be seen.
245312

246313
```
247314
Error: identity or token do not match
@@ -250,4 +317,8 @@ If you see errors stating that the client has already been registered/enrolled,
250317
Error: user is already registered
251318
```
252319

253-
To address this, remove any stored cryptographic material from the CA server by following the instructions [here](https://github.com/hyperledger/fabric/blob/master/docs/Setup/Chaincode-setup.md#removing-temporary-files-when-security-is-enabled). You will also need to remove any of the cryptographic tokens stored on the client side by deleting the KeyValStore directory. That directory is configurable and is set to `/tmp/keyValStore` within the unit tests.
320+
To address this, remove any stored cryptographic material from the CA server by
321+
following the instructions [here](https://github.com/hyperledger/fabric/blob/master/docs/Setup/Chaincode-setup.md#removing-temporary-files-when-security-is-enabled).
322+
You will also need to remove any of the cryptographic tokens stored on the
323+
client side by deleting the KeyValStore directory. That directory is
324+
configurable and is set to `/tmp/keyValStore` within the unit tests.

0 commit comments

Comments
 (0)