fabric-contract-api
Advanced tools
Comparing version 1.3.0-snapshot.13 to 1.4.0-beta
@@ -38,6 +38,6 @@ /* | ||
constructor(){ | ||
} | ||
constructor() { | ||
} | ||
/** | ||
/** | ||
* This sets the chaincode stub object with api to use for worldstate access. | ||
@@ -48,7 +48,7 @@ * MUST NOT BE CALLED FROM SMART CONTRACT CODE | ||
*/ | ||
setChaincodeStub(stub){ | ||
this.stub = stub; | ||
} | ||
setChaincodeStub(stub) { | ||
this.stub = stub; | ||
} | ||
/** | ||
/** | ||
* This sets the ClientIdentity object to use for information on the transaction invoking identity | ||
@@ -59,7 +59,7 @@ * MUST NOT BE CALLED FROM SMART CONTRACT CODE | ||
*/ | ||
setClientIdentity(clientIdentity){ | ||
this.clientIdentity = clientIdentity; | ||
} | ||
setClientIdentity(clientIdentity) { | ||
this.clientIdentity = clientIdentity; | ||
} | ||
} | ||
module.exports = Context; |
@@ -21,3 +21,3 @@ /* | ||
/** | ||
/** | ||
* Constructor - supplying a namespace is recommended but is not mandatory. | ||
@@ -27,11 +27,11 @@ * | ||
*/ | ||
constructor(namespace){ | ||
if (namespace && namespace.trim() !== '' ){ | ||
this.namespace = namespace.trim(); | ||
} else { | ||
this.namespace = ''; | ||
} | ||
} | ||
constructor(namespace) { | ||
if (namespace && namespace.trim() !== '') { | ||
this.namespace = namespace.trim(); | ||
} else { | ||
this.namespace = ''; | ||
} | ||
} | ||
/** | ||
/** | ||
* 'beforeTransaction' will be called before any of the transaction functions within your contract | ||
@@ -45,7 +45,7 @@ * Override this method to implement your own processing. Examples of what you may wish to code | ||
*/ | ||
async beforeTransaction(ctx){ // eslint-disable-line | ||
// default implementation is do nothing | ||
} | ||
async beforeTransaction(ctx) { | ||
// default implementation is do nothing | ||
} | ||
/** | ||
/** | ||
* 'afterTransaction' will be called before any of the transaction functions within your contract | ||
@@ -60,10 +60,9 @@ * Override this method to implement your own processing. Examples of what you may wish to code | ||
*/ | ||
async afterTransaction(ctx,result){ // eslint-disable-line no-unused-vars | ||
// default implementation is do nothing | ||
} | ||
async afterTransaction(ctx, result) { | ||
// default implementation is do nothing | ||
} | ||
/** | ||
/** | ||
* 'unknownTransaction' will be called if the required transaction function requested does not exist | ||
* Override this method to implement your own processing. | ||
* * | ||
* If an error is thrown, the whole transaction will be rejected | ||
@@ -73,8 +72,8 @@ * | ||
*/ | ||
async unknownTransaction(ctx) { | ||
const { fcn } = ctx.stub.getFunctionAndParameters(); | ||
throw new Error(`You've asked to invoke a function that does not exist: ${fcn}`); | ||
} | ||
async unknownTransaction(ctx) { | ||
const {fcn} = ctx.stub.getFunctionAndParameters(); | ||
throw new Error(`You've asked to invoke a function that does not exist: ${fcn}`); | ||
} | ||
/** | ||
/** | ||
* 'createContext' is called before any after, before, unknown or user defined transaction function. This permits contracts | ||
@@ -89,12 +88,12 @@ * to use their own subclass of context to add additinal processing. | ||
*/ | ||
createContext(){ | ||
return new Context(); | ||
} | ||
createContext() { | ||
return new Context(); | ||
} | ||
/** | ||
/** | ||
* @return {String} returns the namepsace | ||
*/ | ||
getNamespace(){ | ||
return this.namespace; | ||
} | ||
getNamespace() { | ||
return this.namespace; | ||
} | ||
@@ -101,0 +100,0 @@ } |
{ | ||
"name": "fabric-contract-api", | ||
"version": "1.3.0-snapshot.13", | ||
"version": "1.4.0-beta", | ||
"tag":"beta", | ||
"description": "A node.js implementation of Hyperledger Fabric chaincode shim, to allow endorsing peers and user-provided chaincodes to communicate with each other", | ||
@@ -5,0 +6,0 @@ "main": "index.js", |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* | ||
@@ -8,3 +9,3 @@ Copyright 2018 IBM All Rights Reserved. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/// <reference path="../../../fabric-shim/types/index.d.ts" /> | ||
const fabric_contract_api_1 = require("fabric-contract-api"); | ||
@@ -11,0 +12,0 @@ class ScenarioContext extends fabric_contract_api_1.Context { |
@@ -7,3 +7,3 @@ /* | ||
*/ | ||
/// <reference path="../../../fabric-shim/types/index.d.ts" /> | ||
import { Contract, Context } from 'fabric-contract-api'; | ||
@@ -10,0 +10,0 @@ import { ChaincodeStub, ClientIdentity } from 'fabric-shim'; |
@@ -14,3 +14,4 @@ /* | ||
*/ | ||
/*global describe it beforeEach afterEach */ | ||
/* global describe it beforeEach afterEach */ | ||
'use strict'; | ||
@@ -29,33 +30,33 @@ | ||
const Context = require(path.join(pathToRoot,'fabric-contract-api/lib/context')); | ||
const Context = require(path.join(pathToRoot, 'fabric-contract-api/lib/context')); | ||
describe('contract.js',()=>{ | ||
describe('contract.js', () => { | ||
let sandbox; | ||
let sandbox; | ||
beforeEach('Sandbox creation',() => { | ||
sandbox = sinon.createSandbox(); | ||
}); | ||
beforeEach('Sandbox creation', () => { | ||
sandbox = sinon.createSandbox(); | ||
}); | ||
afterEach('Sandbox restoration',() => { | ||
sandbox.restore(); | ||
}); | ||
afterEach('Sandbox restoration', () => { | ||
sandbox.restore(); | ||
}); | ||
describe('#constructor',()=>{ | ||
describe('#constructor', () => { | ||
it('should create plain object ok',()=>{ | ||
let sc0 = new Context(); | ||
sc0.should.be.an.instanceOf(Context); | ||
}); | ||
it ('should create plain object ok', () => { | ||
const sc0 = new Context(); | ||
sc0.should.be.an.instanceOf(Context); | ||
}); | ||
it('should have set* methods',()=>{ | ||
let sc0 = new Context(); | ||
sc0.setChaincodeStub('a stub'); | ||
sc0.stub.should.equal('a stub'); | ||
sc0.setClientIdentity('a client identity'); | ||
sc0.clientIdentity.should.equal('a client identity'); | ||
}); | ||
it ('should have set* methods', () => { | ||
const sc0 = new Context(); | ||
sc0.setChaincodeStub('a stub'); | ||
sc0.stub.should.equal('a stub'); | ||
sc0.setClientIdentity('a client identity'); | ||
sc0.clientIdentity.should.equal('a client identity'); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -14,3 +14,3 @@ /* | ||
*/ | ||
/*global describe it beforeEach afterEach */ | ||
/* global describe it beforeEach afterEach */ | ||
'use strict'; | ||
@@ -28,4 +28,4 @@ | ||
const pathToRoot = '../../..'; | ||
const Contract = require(path.join(pathToRoot,'fabric-contract-api/lib/contract')); | ||
const Context = require(path.join(pathToRoot,'fabric-contract-api/lib/context')); | ||
const Contract = require(path.join(pathToRoot, 'fabric-contract-api/lib/contract')); | ||
const Context = require(path.join(pathToRoot, 'fabric-contract-api/lib/context')); | ||
@@ -43,23 +43,23 @@ | ||
/** */ | ||
constructor() { | ||
super('alpha.beta.delta'); | ||
/** */ | ||
constructor() { | ||
super('alpha.beta.delta'); | ||
} | ||
} | ||
async unknownTransaction(ctx){ | ||
unknownStub(ctx); | ||
} | ||
async unknownTransaction(ctx) { | ||
unknownStub(ctx); | ||
} | ||
async beforeTransaction(ctx){ | ||
beforeStub(ctx); | ||
} | ||
async beforeTransaction(ctx) { | ||
beforeStub(ctx); | ||
} | ||
async afterTransaction(ctx,result){ | ||
afterStub(ctx,result); | ||
} | ||
async afterTransaction(ctx, result) { | ||
afterStub(ctx, result); | ||
} | ||
createContext(){ | ||
createContextStub(); | ||
} | ||
createContext() { | ||
createContextStub(); | ||
} | ||
} | ||
@@ -69,100 +69,100 @@ | ||
describe('contract.js',()=>{ | ||
describe('contract.js', () => { | ||
let sandbox; | ||
let sandbox; | ||
beforeEach('Sandbox creation',() => { | ||
sandbox = sinon.createSandbox(); | ||
}); | ||
beforeEach('Sandbox creation', () => { | ||
sandbox = sinon.createSandbox(); | ||
}); | ||
afterEach('Sandbox restoration',() => { | ||
sandbox.restore(); | ||
}); | ||
afterEach('Sandbox restoration', () => { | ||
sandbox.restore(); | ||
}); | ||
describe('#constructor',()=>{ | ||
describe('#constructor', () => { | ||
it('should create with default namespace',()=>{ | ||
let sc0 = new Contract(); | ||
expect(sc0.getNamespace()).to.equal(''); | ||
it ('should create with default namespace', () => { | ||
const sc0 = new Contract(); | ||
expect(sc0.getNamespace()).to.equal(''); | ||
// should also create default when the supplied name is empty space | ||
let sc1 = new Contract(''); | ||
expect(sc1.getNamespace()).to.equal(''); | ||
// should also create default when the supplied name is empty space | ||
const sc1 = new Contract(''); | ||
expect(sc1.getNamespace()).to.equal(''); | ||
let sc2 = new Contract(' '); | ||
expect(sc2.getNamespace()).to.equal(''); | ||
}); | ||
const sc2 = new Contract(' '); | ||
expect(sc2.getNamespace()).to.equal(''); | ||
}); | ||
it('should have default unknownTx fn',()=>{ | ||
let sc0 = new Contract(); | ||
const ctx = { | ||
stub : { | ||
getFunctionAndParameters: 'fn' | ||
} | ||
}; | ||
it ('should have default unknownTx fn', () => { | ||
const sc0 = new Contract(); | ||
const ctx = { | ||
stub : { | ||
getFunctionAndParameters: 'fn' | ||
} | ||
}; | ||
ctx.stub.getFunctionAndParameters = sandbox.stub().returns({fcn:'wibble'}); | ||
ctx.stub.getFunctionAndParameters = sandbox.stub().returns({fcn:'wibble'}); | ||
return sc0.unknownTransaction(ctx).should.eventually.be.rejectedWith(/^You've asked to invoke a function that does not exist: wibble$/); | ||
}); | ||
return sc0.unknownTransaction(ctx).should.eventually.be.rejectedWith(/^You've asked to invoke a function that does not exist: wibble$/); | ||
}); | ||
it('should create with the name specified',()=>{ | ||
let sc1 = new Contract('brain.size.planet.smart'); | ||
expect(sc1.namespace).to.equal('brain.size.planet.smart'); | ||
expect(sc1.getNamespace()).to.equal('brain.size.planet.smart'); | ||
it ('should create with the name specified', () => { | ||
const sc1 = new Contract('brain.size.planet.smart'); | ||
expect(sc1.namespace).to.equal('brain.size.planet.smart'); | ||
expect(sc1.getNamespace()).to.equal('brain.size.planet.smart'); | ||
let sc2 = new Contract(' somewhat.padded.out '); | ||
expect(sc2.namespace).to.equal('somewhat.padded.out'); | ||
expect(sc2.getNamespace()).to.equal('somewhat.padded.out'); | ||
}); | ||
const sc2 = new Contract(' somewhat.padded.out '); | ||
expect(sc2.namespace).to.equal('somewhat.padded.out'); | ||
expect(sc2.getNamespace()).to.equal('somewhat.padded.out'); | ||
}); | ||
it('should call the default before/after functions',()=>{ | ||
let sc0 = new Contract(); | ||
it ('should call the default before/after functions', () => { | ||
const sc0 = new Contract(); | ||
return Promise.all([ | ||
sc0.beforeTransaction().should.be.fulfilled, | ||
sc0.afterTransaction().should.be.fulfilled]); | ||
}); | ||
return Promise.all([ | ||
sc0.beforeTransaction().should.be.fulfilled, | ||
sc0.afterTransaction().should.be.fulfilled]); | ||
}); | ||
it('should call the default createContext functions',()=>{ | ||
let sc0 = new Contract(); | ||
sc0.createContext().should.be.an.instanceOf(Context); | ||
}); | ||
}); | ||
it ('should call the default createContext functions', () => { | ||
const sc0 = new Contract(); | ||
sc0.createContext().should.be.an.instanceOf(Context); | ||
}); | ||
}); | ||
describe('subclass specific functioning',()=>{ | ||
describe('subclass specific functioning', () => { | ||
beforeEach('setup the stubs',()=>{ | ||
beforeStub = sandbox.stub().resolves(); | ||
afterStub = sandbox.stub().resolves(); | ||
unknownStub = sandbox.stub().resolves(); | ||
createContextStub = sandbox.stub().returns(); | ||
}); | ||
beforeEach('setup the stubs', () => { | ||
beforeStub = sandbox.stub().resolves(); | ||
afterStub = sandbox.stub().resolves(); | ||
unknownStub = sandbox.stub().resolves(); | ||
createContextStub = sandbox.stub().returns(); | ||
}); | ||
it('should set the correct namespace',()=>{ | ||
let sc = new SCAlpha(); | ||
sc.getNamespace().should.equal('alpha.beta.delta'); | ||
}); | ||
it ('should set the correct namespace', () => { | ||
const sc = new SCAlpha(); | ||
sc.getNamespace().should.equal('alpha.beta.delta'); | ||
}); | ||
it('should call the correct subclassed fns',()=>{ | ||
let sc = new SCAlpha(); | ||
let ctx = 'a really simple context'; | ||
sc.beforeTransaction(ctx); | ||
sinon.assert.calledOnce(beforeStub); | ||
sinon.assert.calledWith(beforeStub,ctx); | ||
it ('should call the correct subclassed fns', () => { | ||
const sc = new SCAlpha(); | ||
const ctx = 'a really simple context'; | ||
sc.beforeTransaction(ctx); | ||
sinon.assert.calledOnce(beforeStub); | ||
sinon.assert.calledWith(beforeStub, ctx); | ||
sc.afterTransaction(ctx,'result'); | ||
sinon.assert.calledOnce(afterStub); | ||
sinon.assert.calledWith(afterStub,ctx,'result'); | ||
sc.afterTransaction(ctx, 'result'); | ||
sinon.assert.calledOnce(afterStub); | ||
sinon.assert.calledWith(afterStub, ctx, 'result'); | ||
sc.unknownTransaction(ctx); | ||
sinon.assert.calledOnce(unknownStub); | ||
sinon.assert.calledWith(unknownStub,ctx); | ||
sc.unknownTransaction(ctx); | ||
sinon.assert.calledOnce(unknownStub); | ||
sinon.assert.calledWith(unknownStub, ctx); | ||
sc.createContext(); | ||
sinon.assert.calledOnce(createContextStub); | ||
sc.createContext(); | ||
sinon.assert.calledOnce(createContextStub); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -169,0 +169,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
23560
501
137