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

Commit

Permalink
[Master] expose clientIdentity in getNativeAPI (#4617)
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Kelsey <[email protected]>
  • Loading branch information
Dave Kelsey authored and nklincoln committed Mar 14, 2019
1 parent ac291c6 commit e3473f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/composer-runtime-hlfv1/lib/nodecontext.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const NodeDataService = require('./nodedataservice');
const NodeIdentityService = require('./nodeidentityservice');
const NodeEventService = require('./nodeeventservice');
const NodeHTTPService = require('./nodehttpservice');
//const NodeScriptCompiler = require('./nodescriptcompiler');
const ClientIdentity = require('fabric-shim').ClientIdentity;

const Logger = require('composer-common').Logger;
const LOG = Logger.getLog('NodeContext');
Expand Down Expand Up @@ -109,6 +109,7 @@ class NodeContext extends Context {
getNativeAPI() {
const method = 'getNativeAPI';
LOG.entry(method);
this.stub._clientIdentityClass = ClientIdentity;
LOG.exit(method, this.stub);
return this.stub;
}
Expand Down
19 changes: 17 additions & 2 deletions packages/composer-runtime-hlfv1/test/nodecontext.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const NodeEventService = require('../lib/nodeeventservice');
const NodeHTTPService = require('../lib/nodehttpservice');
const NodeIdentityService = require('../lib/nodeidentityservice');
const ChaincodeStub = require('fabric-shim/lib/stub');
const ClientIdentity = require('fabric-shim').ClientIdentity;

require('chai').should();
const sinon = require('sinon');
Expand Down Expand Up @@ -51,7 +52,18 @@ XVMHPa0iyC497vdNURA=\

beforeEach(() => {
mockStub = sinon.createStubInstance(ChaincodeStub);
mockStub.getCreator.returns(cert);
mockStub.getCreator.returns({
getMspid: () => {
return 'mspid';
},
getIdBytes: () => {
return {
toBuffer: () => {
return cert;
}
};
}
});
mockStub.getTxID.returns('12345abcdefg');
mockNodeContainer = sinon.createStubInstance(NodeContainer);
mockEngine = sinon.createStubInstance(Engine);
Expand Down Expand Up @@ -115,7 +127,10 @@ XVMHPa0iyC497vdNURA=\

describe('#getNativeAPI', () => {
it('should return the native api', () => {
context.getNativeAPI().should.equal(mockStub);
const api = context.getNativeAPI();
api.should.equal(mockStub);
const clientIdentity = new api._clientIdentityClass(api);
clientIdentity.should.be.instanceOf(ClientIdentity);
});
});
});

0 comments on commit e3473f4

Please sign in to comment.