Skip to content

Commit

Permalink
Update e2e test to use multi-org setup
Browse files Browse the repository at this point in the history
FAB-2617
the end-to-end test has been running against either the default
"testchainid" or even for a newly created chain it uses a
network of orderers and peers that all share the same MSP
config (in fabric/msp/sampleconfig).

this tasks is to create a target network using at least two
organizations in order to test more realistic user scenarios.

This is part I. Goes as far as create chain, join chain from
two separate orgs, install chaincode from two orgs, instantiate
chaincode, and invoke transaction (which has a policy error
at the moment)

Change-Id: I24a0745b35ac0f405a4e912f32de8440aca71988
Signed-off-by: Jim Zhang <jzhang@us.ibm.com>
  • Loading branch information
jimthematrix committed Mar 3, 2017
1 parent ffd5775 commit b95036b
Show file tree
Hide file tree
Showing 16 changed files with 935 additions and 31 deletions.
4 changes: 3 additions & 1 deletion fabric-client/lib/Chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -1985,7 +1985,9 @@ var Chain = class {
responses.push(result.value());
} else {
logger.debug('Chain-sendPeersProposal - Promise is rejected: '+result.reason());
responses.push(result.reason());
// the reason() would simply return the error object that's difficult to print in logs
// wrap it in an object for better visibility
responses.push({error: result.reason().toString()});
}
});
return responses;
Expand Down
9 changes: 5 additions & 4 deletions fabric-client/lib/Peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var api = require('./api.js');
var utils = require('./utils.js');
var Remote = require('./Remote');
var grpc = require('grpc');
var util = require('util');

var _serviceProto = grpc.load(__dirname + '/protos/peer/peer.proto').protos;

Expand Down Expand Up @@ -187,15 +188,15 @@ var Peer = class extends Remote {
return new Promise(function(resolve, reject) {
self._endorserClient.processProposal(proposal, function(err, proposalResponse) {
if (err) {
logger.error('GRPC client got an error response from the peer. %s', err.stack ? err.stack : err);
logger.error('GRPC client got an error response from the peer "%s". %s', self._url, err.stack ? err.stack : err);
reject(new Error(err));
} else {
if (proposalResponse) {
logger.info('Received proposal response received: status - %s', proposalResponse.response.status);
logger.debug('Received proposal response from peer "%s": status - %s', self._url, proposalResponse.response.status);
resolve(proposalResponse);
} else {
logger.error('GRPC client failed to get a proper response from the peer.');
reject(new Error('GRPC client failed to get a proper response from the peer.'));
logger.error('GRPC client failed to get a proper response from the peer "%s".', self._url);
reject(new Error(util.format('GRPC client failed to get a proper response from the peer "%s".', self._url)));
}
}
});
Expand Down
22 changes: 13 additions & 9 deletions test/fixtures/channel/configtx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Organizations:
- &OrdererOrg
# DefaultOrg defines the organization which is used in the sampleconfig
# of the fabric.git development environment
Name: OrdererOrg
Name: OrdererMSP

# ID to load the MSP definition as
ID: OrdererMSP
Expand All @@ -45,7 +45,7 @@ Organizations:
# FIXME: this path needs to be fixed to point to the actual location of #
# the project 'fabric-sdk-node' in the file system #
#########################################################################
MSPDir: /fabric-sdk-node/test/fixtures/configtx/crypto/orderer/localMspConfig
MSPDir: /fabric-sdk-node/test/fixtures/channel/crypto-config/ordererOrganizations/ordererOrg1/msp

# BCCSP (Blockchain crypto provider): Select which crypto implementation or
# library to use
Expand All @@ -62,17 +62,17 @@ Organizations:
- &Org0
# DefaultOrg defines the organization which is used in the sampleconfig
# of the fabric.git development environment
Name: Org0MSP
Name: Org1MSP

# ID to load the MSP definition as
ID: Org0MSP
ID: Org1MSP

# MSPDir is the filesystem path which contains the MSP configuration
#########################################################################
# FIXME: this path needs to be fixed to point to the actual location of #
# the project 'fabric-sdk-node' in the file system #
#########################################################################
MSPDir: /fabric-sdk-node/test/fixtures/configtx/crypto/peer/peer0/localMspConfig
MSPDir: /fabric-sdk-node/test/fixtures/channel/crypto-config/peerOrganizations/peerOrg1/msp/

# BCCSP (Blockchain crypto provider): Select which crypto implementation or
# library to use
Expand All @@ -92,21 +92,23 @@ Organizations:
# encoded in the genesis block in the Application section context
- Host: localhost
Port: 7051
- Host: localhost
Port: 7056

- &Org1
# DefaultOrg defines the organization which is used in the sampleconfig
# of the fabric.git development environment
Name: Org1MSP
Name: Org2MSP

# ID to load the MSP definition as
ID: Org1MSP
ID: Org2MSP

# MSPDir is the filesystem path which contains the MSP configuration
#########################################################################
# FIXME: this path needs to be fixed to point to the actual location of #
# the project 'fabric-sdk-node' in the file system #
#########################################################################
MSPDir: /fabric-sdk-node/test/fixtures/configtx/crypto/peer/peer2/localMspConfig
MSPDir: /fabric-sdk-node/test/fixtures/channel/crypto-config/peerOrganizations/peerOrg2/msp/

# BCCSP (Blockchain crypto provider): Select which crypto implementation or
# library to use
Expand All @@ -125,7 +127,9 @@ Organizations:
# for cross org gossip communication. Note, this value is only
# encoded in the genesis block in the Application section context
- Host: localhost
Port: 7056
Port: 8051
- Host: localhost
Port: 8056

################################################################################
#
Expand Down
25 changes: 21 additions & 4 deletions test/fixtures/channel/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ networks:
bridge:

services:
ca:
ca0:
image: hyperledger/fabric-ca
environment:
- FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
Expand All @@ -12,7 +12,18 @@ services:
command: sh -c 'fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/peerOrg1-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/d8a5b3cac1b821f6e4b487ceaf1fd239cdcfc310894150908b90f05e9179556a_sk -b admin:adminpw' -d
volumes:
- ./crypto-config/peerOrganizations/peerOrg1/ca/:/etc/hyperledger/fabric-ca-server-config
container_name: ca
container_name: ca_peerOrg1

ca1:
image: hyperledger/fabric-ca
environment:
- FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
ports:
- "8054:7054"
command: sh -c 'fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/peerOrg2-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/96bdb57f4efbdcf201a269899eb47e2a73fbb728ae14d47d0d5afb75ddea71de_sk -b admin:adminpw' -d
volumes:
- ./crypto-config/peerOrganizations/peerOrg2/ca/:/etc/hyperledger/fabric-ca-server-config
container_name: ca_peerOrg2

orderer:
container_name: orderer
Expand Down Expand Up @@ -80,6 +91,9 @@ services:
- CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/configtx/crypto-config/peerOrganizations/peerOrg1/peers/peerOrg1Peer2/
working_dir: /opt/gopath/src/github.com/hyperledger/fabric
command: peer node start --peer-defaultchain=false
ports:
- 7056:7051
- 7058:7053
links:
- orderer
volumes:
Expand Down Expand Up @@ -109,8 +123,8 @@ services:
working_dir: /opt/gopath/src/github.com/hyperledger/fabric
command: peer node start --peer-defaultchain=false
ports:
- 7056:7051
- 7058:7053
- 8051:7051
- 8053:7053
links:
- orderer:orderer
volumes:
Expand Down Expand Up @@ -140,6 +154,9 @@ services:
- CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/configtx/crypto-config/peerOrganizations/peerOrg2/peers/peerOrg2Peer2/
working_dir: /opt/gopath/src/github.com/hyperledger/fabric
command: peer node start --peer-defaultchain=false
ports:
- 8056:7051
- 8058:7053
links:
- orderer:orderer
volumes:
Expand Down
Binary file modified test/fixtures/channel/mychannel.tx
Binary file not shown.
Binary file modified test/fixtures/channel/twoorgs.orderer.block
Binary file not shown.
4 changes: 4 additions & 0 deletions test/integration/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require('./e2e/create-channel.js');
require('./e2e/join-channel.js');
require('./e2e/install-chaincode.js');
require('./e2e/instantiate-chaincode.js');
31 changes: 31 additions & 0 deletions test/integration/e2e/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"test-network": {
"orderer": "grpc://localhost:7050",
"org1": {
"name": "peerOrg1",
"mspid": "Org1MSP",
"ca": "http://localhost:7054",
"peer1": {
"requests": "grpc://localhost:7051",
"events": "grpc://localhost:7053"
},
"peer2": {
"requests": "grpc://localhost:7056",
"events": "grpc://localhost:7058"
}
},
"org2": {
"name": "peerOrg2",
"mspid": "Org2MSP",
"ca": "http://localhost:8054",
"peer1": {
"requests": "grpc://localhost:8051",
"events": "grpc://localhost:8053"
},
"peer2": {
"requests": "grpc://localhost:8056",
"events": "grpc://localhost:8058"
}
}
}
}
119 changes: 119 additions & 0 deletions test/integration/e2e/create-channel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/**
* Copyright 2016 IBM All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

var tape = require('tape');
var _test = require('tape-promise');
var test = _test(tape);

var hfc = require('fabric-client');
var util = require('util');
var fs = require('fs');
var path = require('path');

var testUtil = require('../../unit/util.js');
var utils = require('fabric-client/lib/utils.js');
var Orderer = require('fabric-client/lib/Orderer.js');

var the_user = null;

var logger = utils.getLogger('create-channel');

hfc.addConfigFile(path.join(__dirname, './config.json'));
var ORGS = hfc.getConfigSetting('test-network');

//
//Attempt to send a request to the orderer with the sendCreateChain method
//
test('\n\n***** End-to-end flow: create channel *****\n\n', function(t) {
//
// Create and configure the test chain
//
var client = new hfc();
var chain = client.newChain('mychannel');
chain.addOrderer(new Orderer(ORGS.orderer));

// Acting as a client in org1 when creating the channel
var org = ORGS.org1.name;

hfc.newDefaultKeyValueStore({
path: testUtil.storePathForOrg(org)
})
.then((store) => {
client.setStateStore(store);
return testUtil.getSubmitter(client, t, 'org1');
})
.then((admin) => {
t.pass('Successfully enrolled user \'admin\'');
the_user = admin;

//FIXME: temporary fix until mspid is configured into Chain
the_user.mspImpl._id = ORGS.org1.mspid;

// readin the envelope to send to the orderer
return readFile('./test/fixtures/channel/mychannel.tx');
}, (err) => {
t.fail('Failed to enroll user \'admin\'. ' + err);
t.end();
})
.then((data) => {
t.pass('Successfully read file');
var request = {
envelope : data
};
// send to orderer
return chain.createChannel(request);
}, (err) => {
t.fail('Failed to read file for channel template: ' + err);
t.end();
})
.then((response) => {
logger.debug(' response ::%j',response);

if (response && response.status === 'SUCCESS') {
t.pass('Successfully created the channel.');
return sleep(5000);
} else {
t.fail('Failed to create the channel. ');
t.end();
}
}, (err) => {
t.fail('Failed to initialize the channel: ' + err.stack ? err.stack : err);
t.end();
})
.then((nothing) => {
t.pass('Successfully waited to make sure new channel was created.');
t.end();
}, (err) => {
t.fail('Failed to sleep due to error: ' + err.stack ? err.stack : err);
t.end();
});
});

function readFile(path) {
return new Promise(function(resolve, reject) {
fs.readFile(path, function(err, data) {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
Loading

0 comments on commit b95036b

Please sign in to comment.