From e3473f4f03f37c677c02571b1b1b0d42e7e1c3bb Mon Sep 17 00:00:00 2001 From: Dave Kelsey Date: Thu, 14 Mar 2019 16:47:53 +0000 Subject: [PATCH] [Master] expose clientIdentity in getNativeAPI (#4617) Signed-off-by: Dave Kelsey --- .../composer-runtime-hlfv1/lib/nodecontext.js | 3 ++- .../test/nodecontext.js | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/composer-runtime-hlfv1/lib/nodecontext.js b/packages/composer-runtime-hlfv1/lib/nodecontext.js index e0138fe8ec..3b70bbe992 100644 --- a/packages/composer-runtime-hlfv1/lib/nodecontext.js +++ b/packages/composer-runtime-hlfv1/lib/nodecontext.js @@ -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'); @@ -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; } diff --git a/packages/composer-runtime-hlfv1/test/nodecontext.js b/packages/composer-runtime-hlfv1/test/nodecontext.js index dec8e748a5..301257ab4d 100644 --- a/packages/composer-runtime-hlfv1/test/nodecontext.js +++ b/packages/composer-runtime-hlfv1/test/nodecontext.js @@ -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'); @@ -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); @@ -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); }); }); });