Skip to content

Commit

Permalink
[FAB-7504] Fix Client.getPeersForOrgOnChannela fcn
Browse files Browse the repository at this point in the history
There was an error in the logic to obtain all
the peers for an org that have joined a
channel. This fixes the logic and adds
corresponding unit test cases.

This fixes the issue and updates the tests
to cover this case.

Change-Id: Id10d34a6000b8946f99e2b75313e0d4506adca05
Signed-off-by: Gari Singh <gari.r.singh@gmail.com>
  • Loading branch information
mastersingh24 committed Jan 6, 2018
1 parent ea8d0c3 commit ef0c3f7
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fabric-client/lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1786,7 +1786,7 @@ var Client = class extends BaseClient {
if(channel_peer.isInRole(Constants.NetworkConfig.ENDORSING_PEER_ROLE)
|| channel_peer.isInRole(Constants.NetworkConfig.CHAINCODE_QUERY_ROLE)) {
for(let k in org_peers) {
let org_peer = org_peers[i];
let org_peer = org_peers[k];
logger.debug('%s - looking at org peer:%s',method,org_peer.getName());
if(org_peer.getName() === channel_peer.getName()) {
found_peers[org_peer.getName()] = org_peer;//to avoid Duplicate Peers
Expand Down
137 changes: 137 additions & 0 deletions test/fixtures/network2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
---
#
# The network connection profile provides client applications the information about the target
# blockchain network that are necessary for the applications to interact with it. These are all
# knowledge that must be acquired from out-of-band sources. This file provides such a source.
#
name: "global-trade-network"

x-type: "hlfv1"

#
# Describe what the target network is/does.
#
description: "The network to be in if you want to stay in the global trade business"

#
# Schema version of the content. Used by the SDK to apply the corresponding parsing rules.
#
version: "1.0"

channels:
# name of the channel
mychannel3:
orderers:
- orderer.example.com

# Required. list of peers from participating orgs
peers:
peer0.org1.example.com:
endorsingPeer: true
chaincodeQuery: true
ledgerQuery: true
eventSource: true

peer1.org1.example.com:
endorsingPeer: true
chaincodeQuery: true
ledgerQuery: true
eventSource: false

peer0.org2.example.com:
endorsingPeer: true
chaincodeQuery: false
ledgerQuery: true
eventSource: false

chaincodes:
# the format follows the "cannonical name" of chaincodes by fabric code
- example02:v1
- marbles:1.0

organizations:
Org1:
mspid: Org1MSP

peers:
- peer0.org1.example.com
- peer1.org1.example.com
- peer2.org1.example.com

certificateAuthorities:
- ca-org1

adminPrivateKey:
path: test/fixtures/channel/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/keystore/9022d671ceedbb24af3ea69b5a8136cc64203df6b9920e26f48123fcfcb1d2e9_sk
signedCert:
path: test/fixtures/channel/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/signcerts/Admin@org1.example.com-cert.pem

Org2:
mspid: Org2MSP
peers:
- peer0.org2.example.com
certificateAuthorities:
- ca-org2
adminPrivateKey:
path: test/fixtures/channel/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/keystore/5a983ddcbefe52a7f9b8ee5b85a590c3e3a43c4ccd70c7795bec504e7f74848d_sk
signedCert:
path: test/fixtures/channel/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/signcerts/Admin@org2.example.com-cert.pem

orderers:
orderer.example.com:
url: grpcs://localhost:7050

# these are standard properties defined by the gRPC library
# they will be passed in as-is to gRPC client constructor
grpcOptions:
ssl-target-name-override: orderer.example.com
grpc-max-send-message-length: 15

tlsCACerts:
path: test/fixtures/channel/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tlscacerts/example.com-cert.pem

peers:
peer0.org1.example.com:
# this URL is used to send endorsement and query requests
url: grpc://localhost:7051

peer1.org1.example.com:
# this URL is used to send endorsement and query requests
url: grpc://localhost:8051

peer2.org1.example.com:
# this URL is used to send endorsement and query requests
url: grpc://localhost:9051

peer0.org2.example.com:
url: grpc://localhost:10051

certificateAuthorities:
ca-org1:
url: https://localhost:7054
# the properties specified under this object are passed to the 'http' client verbatim when
# making the request to the Fabric-CA server
httpOptions:
verify: false
tlsCACerts:
path: test/fixtures/channel/crypto-config/peerOrganizations/org1.example.com/ca/org1.example.com-cert.pem

# Fabric-CA supports dynamic user enrollment via REST APIs. A "root" user, a.k.a registrar, is
# needed to enroll and invoke new users.
registrar:
- enrollId: admin
enrollSecret: adminpw
# [Optional] The optional name of the CA.
caName: ca-org1

ca-org2:
url: https://localhost:8054
httpOptions:
verify: false
tlsCACerts:
path: test/fixtures/channel/crypto-config/peerOrganizations/org2.example.com/ca/org2.example.com-cert.pem
registrar:
- enrollId: admin
enrollSecret: adminpw
# [Optional] The optional name of the CA.
caName: ca-org2
9 changes: 9 additions & 0 deletions test/unit/network-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,22 @@ test('\n\n ** configuration testing **\n\n', function (t) {
t.equals('grpcs://localhost:8051', peers[0].getUrl(), ' Check to see if we got the right peer for org2 that is endorsing and on the channel');
client.loadFromConfig('test/fixtures/org1.yaml');
peers = client.getPeersForOrgOnChannel(['mychannel2']);
t.equals(1, peers.length, 'Check to see that we got 1 peer')
t.equals('grpcs://localhost:7051', peers[0].getUrl(), ' Check to see if we got the right peer for org1 that is endorsing and on the channel');
peers = client.getPeersForOrgOnChannel([]);
t.equals(0, peers.length, ' Check to see that we got no peers');
peers = client.getPeersForOrgOnChannel();
t.equals(1, peers.length, ' Check to see that we got 1 peer');
t.equals('grpcs://localhost:7051', peers[0].getUrl(), ' Check to see if we got the right peer for org1 that is endorsing and on the channel');

var client2 = Client.loadFromConfig('test/fixtures/network2.yaml')
client2.loadFromConfig('test/fixtures/org1.yaml')
t.equals(client2.getPeersForOrg().length, 3, ' Check to see that we got 3 peers for Org1')
t.equals(client2.getPeersForOrgOnChannel(['mychannel3']).length, 2, ' Check to see that we got 2 peers for Org2 on "mychannel3"')
client2.loadFromConfig('test/fixtures/org2.yaml')
t.equals(client2.getPeersForOrg().length, 1, ' Check to see that we got 1 peer for Org2')
t.equals(client2.getPeersForOrgOnChannel(['mychannel3']).length, 1, ' Check to see that we got 1 peers for Org2 on "mychannel3"')

let opts = {somesetting : 4};
client._network_config.addTimeout(opts,1);
t.equals(opts['somesetting'], 4, 'check that existing settings are still there');
Expand Down

0 comments on commit ef0c3f7

Please sign in to comment.