You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]>
Copy file name to clipboardexpand all lines: docs/Setup/NodeSDK-setup.md
+102-31
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,18 @@
1
1
## Hyperledger Fabric Client (HFC) SDK for Node.js
2
2
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.
4
5
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.
6
11
7
12
### Installing the hfc module
8
13
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:
10
16
11
17
```
12
18
npm install -g hfc
@@ -16,24 +22,41 @@ npm install -g hfc
16
22
17
23
The sections in this document are as follows:
18
24
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.
20
28
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.
22
33
23
34
## 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.
25
38
26
39
### 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**.
28
43
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
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.
32
54
33
55
### Learn by example
34
56
The best way to quickly learn HFC is by example.
35
57
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.
37
60
38
61
```
39
62
/**
@@ -136,13 +159,22 @@ function handleUserRequest(userName, chaincodeID, fcn, args) {
136
159
137
160
## Getting Set Up
138
161
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
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.
144
173
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
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.
163
196
164
197
```
165
198
go build
166
199
```
167
200
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
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.
169
208
170
209
```
171
210
// Path to the local directory containing the chaincode project under $GOPATH
172
211
var testChaincodePath = "github.com/chaincode_example02/";
173
212
```
174
213
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:
176
217
177
218
```
178
219
cd $GOPATH/src/github.com/hyperledger/fabric/sdk/node
*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.
219
266
220
267
## 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.
222
273
223
274
### 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:
225
278
226
279
cd $GOPATH/src/github.com/hyperledger/fabric
227
280
make node-sdk-unit-tests
228
281
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.
230
284
231
285
#### 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.
233
289
234
290
#### 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.
236
294
237
295
#### 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.
239
299
240
300
#### 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.
242
304
243
305
#### 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.
245
312
246
313
```
247
314
Error: identity or token do not match
@@ -250,4 +317,8 @@ If you see errors stating that the client has already been registered/enrolled,
250
317
Error: user is already registered
251
318
```
252
319
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