fabric-shim
Advanced tools
Comparing version 1.3.0-snapshot.18 to 1.3.0-snapshot.19
@@ -99,5 +99,3 @@ /* | ||
let splitFcn = fcn.split('.'); | ||
let fn = splitFcn.pop(); | ||
let ns = splitFcn.join('.'); | ||
let {namespace:ns,function:fn} = this._splitFunctionName(fcn); | ||
@@ -115,3 +113,2 @@ if (!this.contracts[ns]){ | ||
if (functionExists) { | ||
// before tx fn | ||
@@ -136,2 +133,27 @@ await contractInstance.beforeTransaction(ctx); | ||
/** | ||
* Parse the fcn name to be namespace and function. These are separated by a : | ||
* Anything after the : is treated as the function name | ||
* No : implies that the whole string is a function name | ||
* | ||
* @param {String} fcn the combined function and name string | ||
* @return {Object} split into namespace and string | ||
*/ | ||
_splitFunctionName(fcn){ | ||
// Did consider using a split(':') call to do this; however I chose regular expression for | ||
// the reason that it provides definitive description. | ||
// Split will just split - you would then need to write the code to handle edge cases | ||
// for no input, for multiple :, for multiple : without intervening characters | ||
// https://regex101.com/ is very useful for understanding | ||
const regex = /([^:]*)(?::|^)(.*)/g; | ||
let result = {namespace:'',function:''}; | ||
let m = regex.exec(fcn); | ||
result.namespace = m[1]; | ||
result.function = m[2]; | ||
return result; | ||
} | ||
/** | ||
* get information on the contracts | ||
@@ -138,0 +160,0 @@ */ |
{ | ||
"name": "fabric-shim", | ||
"version": "1.3.0-snapshot.18", | ||
"version": "1.3.0-snapshot.19", | ||
"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 +5,0 @@ "main": "index.js", |
@@ -203,3 +203,3 @@ /* | ||
stubInterface.getFunctionAndParameters.returns({ | ||
fcn:'alpha.alpha', | ||
fcn:'alpha:alpha', | ||
params: [ 'arg1','arg2' ] | ||
@@ -262,3 +262,3 @@ } ); | ||
stubInterface.getFunctionAndParameters.returns({ | ||
fcn:'beta.beta', | ||
fcn:'beta:beta', | ||
params: [ 'arg1','arg2' ] | ||
@@ -319,3 +319,3 @@ } ); | ||
stubInterface.getFunctionAndParameters.returns({ | ||
fcn:'beta.beta', | ||
fcn:'beta:beta', | ||
params: [ 'arg1','arg2' ] | ||
@@ -376,3 +376,3 @@ } ); | ||
stubInterface.getFunctionAndParameters.returns({ | ||
fcn:'wibble.alpha', | ||
fcn:'wibble:alpha', | ||
params: [ 'arg1','arg2' ] | ||
@@ -400,3 +400,3 @@ } ); | ||
stubInterface.getFunctionAndParameters.returns({ | ||
fcn:'alpha.wibble', | ||
fcn:'alpha:wibble', | ||
params: [ 'arg1','arg2' ] | ||
@@ -464,3 +464,3 @@ } ); | ||
stubInterface.getFunctionAndParameters.returns({ | ||
fcn:'org.hyperledger.fabric.getMetaData', | ||
fcn:'org.hyperledger.fabric:getMetaData', | ||
params: [ 'arg1','arg2' ] | ||
@@ -504,2 +504,35 @@ } ); | ||
describe('#_splitFunctionName',()=>{ | ||
let cc; | ||
beforeEach(()=>{ | ||
// actual contract instance is not important for this test | ||
cc = new ChaincodeFromContract([SCBeta]); | ||
}); | ||
it('should handle the usual case of ns:fn',()=>{ | ||
let result= cc._splitFunctionName('namespace:function'); | ||
result.should.deep.equal({namespace:'namespace',function:'function'}); | ||
}); | ||
it('should handle the case of no namespace explicit',()=>{ | ||
let result = cc._splitFunctionName(':function'); | ||
result.should.deep.equal({namespace:'',function:'function'}); | ||
}); | ||
it('should handle the case of no namespace implict',()=>{ | ||
let result = cc._splitFunctionName('function'); | ||
result.should.deep.equal({namespace:'',function:'function'}); | ||
}); | ||
it('should handle the case of no input',()=>{ | ||
let result = cc._splitFunctionName(''); | ||
result.should.deep.equal({namespace:'',function:''}); | ||
}); | ||
it('should handle the case of multiple :',()=>{ | ||
let result = cc._splitFunctionName('namespace:function:with:colons:'); | ||
result.should.deep.equal({namespace:'namespace',function:'function:with:colons:'}); | ||
}); | ||
}); | ||
}); |
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
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
352285
6920