Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit e3473f4

Browse files
Dave Kelseynklincoln
Dave Kelsey
authored andcommitted
[Master] expose clientIdentity in getNativeAPI (#4617)
Signed-off-by: Dave Kelsey <d_kelsey@uk.ibm.com>
1 parent ac291c6 commit e3473f4

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

packages/composer-runtime-hlfv1/lib/nodecontext.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const NodeDataService = require('./nodedataservice');
1919
const NodeIdentityService = require('./nodeidentityservice');
2020
const NodeEventService = require('./nodeeventservice');
2121
const NodeHTTPService = require('./nodehttpservice');
22-
//const NodeScriptCompiler = require('./nodescriptcompiler');
22+
const ClientIdentity = require('fabric-shim').ClientIdentity;
2323

2424
const Logger = require('composer-common').Logger;
2525
const LOG = Logger.getLog('NodeContext');
@@ -109,6 +109,7 @@ class NodeContext extends Context {
109109
getNativeAPI() {
110110
const method = 'getNativeAPI';
111111
LOG.entry(method);
112+
this.stub._clientIdentityClass = ClientIdentity;
112113
LOG.exit(method, this.stub);
113114
return this.stub;
114115
}

packages/composer-runtime-hlfv1/test/nodecontext.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const NodeEventService = require('../lib/nodeeventservice');
2323
const NodeHTTPService = require('../lib/nodehttpservice');
2424
const NodeIdentityService = require('../lib/nodeidentityservice');
2525
const ChaincodeStub = require('fabric-shim/lib/stub');
26+
const ClientIdentity = require('fabric-shim').ClientIdentity;
2627

2728
require('chai').should();
2829
const sinon = require('sinon');
@@ -51,7 +52,18 @@ XVMHPa0iyC497vdNURA=\
5152

5253
beforeEach(() => {
5354
mockStub = sinon.createStubInstance(ChaincodeStub);
54-
mockStub.getCreator.returns(cert);
55+
mockStub.getCreator.returns({
56+
getMspid: () => {
57+
return 'mspid';
58+
},
59+
getIdBytes: () => {
60+
return {
61+
toBuffer: () => {
62+
return cert;
63+
}
64+
};
65+
}
66+
});
5567
mockStub.getTxID.returns('12345abcdefg');
5668
mockNodeContainer = sinon.createStubInstance(NodeContainer);
5769
mockEngine = sinon.createStubInstance(Engine);
@@ -115,7 +127,10 @@ XVMHPa0iyC497vdNURA=\
115127

116128
describe('#getNativeAPI', () => {
117129
it('should return the native api', () => {
118-
context.getNativeAPI().should.equal(mockStub);
130+
const api = context.getNativeAPI();
131+
api.should.equal(mockStub);
132+
const clientIdentity = new api._clientIdentityClass(api);
133+
clientIdentity.should.be.instanceOf(ClientIdentity);
119134
});
120135
});
121136
});

0 commit comments

Comments
 (0)