Skip to content

Commit

Permalink
[FABN-1393] Pass baseDir/gopath from client to node-sdk
Browse files Browse the repository at this point in the history
Signed-off-by: bharadwajambati1 <[email protected]>
Change-Id: Iad9f15823b12b50787aa3d7ef8dd292043ffb321
  • Loading branch information
bharadwajambati95 committed Nov 20, 2019
1 parent cce8f1c commit 2815f6d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
4 changes: 3 additions & 1 deletion fabric-client/lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,7 @@ const Client = class extends BaseClient {
* @property {string} metadataPath - Optional. The path to the top-level
* directory containing metadata descriptors.
* @property {string} chaincodeId - Required. Name of the chaincode
* @property {string} goPath - Optional. The path to be used with the golang chaincode.
* @property {string} chaincodeVersion - Required. Version string of the
* chaincode, such as 'v1'
* @property {byte[]} chaincodePackage - Optional. Byte array of the archive
Expand Down Expand Up @@ -1195,7 +1196,8 @@ const Client = class extends BaseClient {
version: request.chaincodeVersion,
path: request.chaincodePath,
type: request.chaincodeType,
metadataPath: request.metadataPath
metadataPath: request.metadataPath,
goPath: request.goPath
});
cdsBytes = await cdsPkg.toBuffer();
logger.debug(`installChaincode - built chaincode package (${cdsBytes.length} bytes)`);
Expand Down
5 changes: 3 additions & 2 deletions fabric-client/lib/Package.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,13 @@ class Package {
* @param {string} options.path The directory containing the smart contract.
* @param {string} options.type The type of the smart contract, one of 'golang', 'car', 'node' or 'java'.
* @param {string} [options.metadataPath] The directory containing the metadata descriptors.
* @param {string} options.goPath The path to be used with the golang chaincode.
* @returns {Package} The smart contract package.
*/
static async fromDirectory({name, version, path, type, metadataPath}) {
static async fromDirectory({name, version, path, type, metadataPath, goPath}) {
logger.debug('Package.fromDirectory - entry - %s, %s, %s, %s', name, version, path, type);
Package._validateNameAndVersion(name, version);
const codePackage = await Packager.package(path, type, false, metadataPath);
const codePackage = await Packager.package(path, type, false, metadataPath, goPath);
logger.debug('Package.fromDirectory - code package is %s bytes', codePackage.length);
const fixedPath = path.split('\\').join('/'); // for windows style paths
const chaincodeSpec = {
Expand Down
37 changes: 24 additions & 13 deletions fabric-client/test/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1663,10 +1663,11 @@ describe('Client', () => {
version: '0.0.1',
path: 'mycc',
type: undefined,
metadataPath: undefined
metadataPath: undefined,
goPath: undefined
}).resolves(smartContractPackage);
getTargetPeersStub.withArgs(['peer']).returns(['peer']);
const request = {chaincodeId: 'mycc', chaincodeVersion: '0.0.1', chaincodePath: 'mycc', targets: ['peer']};
const request = {chaincodeId: 'mycc', chaincodeVersion: '0.0.1', chaincodePath: 'mycc', targets: ['peer'], goPath: undefined};
const response = await client.installChaincode(request);
sinon.assert.calledWith(getTargetPeersStub, ['peer']);
sinon.assert.calledOnce(fromDirectoryStub);
Expand All @@ -1690,14 +1691,16 @@ describe('Client', () => {
version: '0.0.1',
path: 'mycc',
type: 'java',
metadataPath: undefined
metadataPath: undefined,
goPath: undefined
}).resolves(smartContractPackage);
getTargetPeersStub.withArgs(['peer']).returns(['peer']);
const request = {
chaincodeId: 'mycc',
chaincodeVersion: '0.0.1',
chaincodePath: 'mycc',
chaincodeType: 'java',
goPath: undefined,
targets: ['peer']
};
const response = await client.installChaincode(request);
Expand All @@ -1723,7 +1726,8 @@ describe('Client', () => {
version: '0.0.1',
path: 'mycc',
type: 'java',
metadataPath: 'mycc/META-INF'
metadataPath: 'mycc/META-INF',
goPath: undefined
}).resolves(smartContractPackage);
getTargetPeersStub.withArgs(['peer']).returns(['peer']);
const request = {
Expand All @@ -1732,7 +1736,8 @@ describe('Client', () => {
chaincodePath: 'mycc',
chaincodeType: 'java',
metadataPath: 'mycc/META-INF',
targets: ['peer']
targets: ['peer'],
goPath: undefined
};
const response = await client.installChaincode(request);
sinon.assert.calledWith(getTargetPeersStub, ['peer']);
Expand All @@ -1755,7 +1760,7 @@ describe('Client', () => {
client.setDevMode(true);
const fromDirectoryStub = sinon.stub(Package, 'fromDirectory').rejects(new Error('such error'));
getTargetPeersStub.withArgs(['peer']).returns(['peer']);
const request = {chaincodeId: 'mycc', chaincodeVersion: '0.0.1', chaincodePath: 'mycc', targets: ['peer']};
const request = {chaincodeId: 'mycc', chaincodeVersion: '0.0.1', chaincodePath: 'mycc', targets: ['peer'], goPath: undefined};
const response = await client.installChaincode(request);
sinon.assert.calledWith(getTargetPeersStub, ['peer']);
sinon.assert.notCalled(fromDirectoryStub);
Expand All @@ -1776,7 +1781,7 @@ describe('Client', () => {
it('should install using a chaincode package', async () => {
const fromDirectoryStub = sinon.stub(Package, 'fromDirectory').rejects(new Error('such error'));
getTargetPeersStub.withArgs(['peer']).returns(['peer']);
const request = {chaincodePackage: smartContractPackageBytes, targets: ['peer']};
const request = {chaincodePackage: smartContractPackageBytes, targets: ['peer'], goPath: undefined};
const response = await client.installChaincode(request);
sinon.assert.calledWith(getTargetPeersStub, ['peer']);
sinon.assert.notCalled(fromDirectoryStub);
Expand All @@ -1800,7 +1805,8 @@ describe('Client', () => {
version: '0.0.1',
path: 'mycc',
type: undefined,
metadataPath: undefined
metadataPath: undefined,
goPath: undefined
}).resolves(smartContractPackage);
getTargetPeersStub.returns(['peer']);
const request = {
Expand All @@ -1809,7 +1815,8 @@ describe('Client', () => {
chaincodePath: 'mycc',
targets: [],
channelNames: [],
txId: {isAdmin: isAdminStub, getNonce: getNonceStub, getTransactionID: getTransactionIDStub}
txId: {isAdmin: isAdminStub, getNonce: getNonceStub, getTransactionID: getTransactionIDStub,
goPath: undefined}
};
const response = await client.installChaincode(request);
sinon.assert.calledWith(getTargetPeersStub, []);
Expand All @@ -1833,7 +1840,8 @@ describe('Client', () => {
version: '0.0.1',
path: 'mycc',
type: undefined,
metadataPath: undefined
metadataPath: undefined,
goPath: undefined
}).resolves(smartContractPackage);
getTargetPeersStub.returns(['peer']);
const request = {
Expand All @@ -1842,7 +1850,8 @@ describe('Client', () => {
chaincodePath: 'mycc',
targets: [],
channelNames: [],
txId: {isAdmin: isAdminStub, getNonce: getNonceStub, getTransactionID: getTransactionIDStub}
txId: {isAdmin: isAdminStub, getNonce: getNonceStub, getTransactionID: getTransactionIDStub},
goPath: undefined
};
const response = await client.installChaincode(request);
sinon.assert.calledWith(getTargetPeersStub, []);
Expand All @@ -1866,15 +1875,17 @@ describe('Client', () => {
version: '0.0.1',
path: 'mycc',
type: undefined,
metadataPath: undefined
metadataPath: undefined,
goPath: undefined
}).resolves(smartContractPackage);
getTargetPeersStub.returns();
getPeersForOrgOnChannelStub.withArgs(['mychannel']).returns(['peer']);
const request = {
chaincodeId: 'mycc',
chaincodeVersion: '0.0.1',
chaincodePath: 'mycc',
channelNames: ['mychannel']
channelNames: ['mychannel'],
goPath: undefined
};
const response = await client.installChaincode(request);
sinon.assert.calledWith(getTargetPeersStub, undefined);
Expand Down

0 comments on commit 2815f6d

Please sign in to comment.