fabric-contract-api
Advanced tools
Comparing version 1.4.0-snapshot.44 to 1.4.0-snapshot.45
@@ -27,6 +27,7 @@ /* | ||
constructor(name) { | ||
if (name && name.trim() !== '') { | ||
this.__isContract = true; | ||
if (typeof name === 'undefined' || name === null) { | ||
this.name = this.constructor.name; | ||
} else { | ||
this.name = name.trim(); | ||
} else { | ||
this.name = ''; | ||
} | ||
@@ -36,2 +37,11 @@ } | ||
/** | ||
* isContract provides functionality to check if a passed object is a contract type. Enables | ||
* checking if its a contract for when contract-api is "required" by different modules | ||
* @param {Object} obj | ||
*/ | ||
static _isContract(obj) { | ||
return obj instanceof Contract || Boolean(obj.__isContract); | ||
} | ||
/** | ||
* 'beforeTransaction' will be called before any of the transaction functions within your contract | ||
@@ -38,0 +48,0 @@ * Override this method to implement your own processing. Examples of what you may wish to code |
{ | ||
"name": "fabric-contract-api", | ||
"version": "1.4.0-snapshot.44", | ||
"version": "1.4.0-snapshot.45", | ||
"tag": "unstable", | ||
@@ -5,0 +5,0 @@ "description": "A node.js implementation of Hyperledger Fabric chaincode shim, to allow endorsing peers and user-provided chaincodes to communicate with each other", |
@@ -64,4 +64,12 @@ /* | ||
class SCBeta extends Contract { | ||
/** */ | ||
constructor() { | ||
super(); | ||
} | ||
} | ||
describe('contract.js', () => { | ||
@@ -83,3 +91,3 @@ | ||
const sc0 = new Contract(); | ||
expect(sc0.getName()).to.equal(''); | ||
expect(sc0.getName()).to.equal('Contract'); | ||
@@ -115,2 +123,6 @@ // should also create default when the supplied name is empty space | ||
expect(sc2.getName()).to.equal('somewhat.padded.out'); | ||
const sc3 = new SCBeta(); | ||
expect(sc3.name).to.equal('SCBeta'); | ||
expect(sc3.getName()).to.equal('SCBeta'); | ||
}); | ||
@@ -131,4 +143,29 @@ | ||
}); | ||
it ('should set the __isContract value', () => { | ||
const sc0 = new Contract(); | ||
expect(sc0.__isContract).to.deep.equal(true); | ||
}); | ||
}); | ||
describe('_isContract', () => { | ||
it ('should return true when class is a contract', () => { | ||
expect(Contract._isContract(new SCAlpha())).to.deep.equal(true); | ||
}); | ||
it ('should return true when class is not a contract', () => { | ||
class Something {} | ||
expect(Contract._isContract(new Something())).to.deep.equal(false); | ||
}); | ||
it ('should return true when class is not instanceOf contract but does have __isContract true', () => { | ||
class Something { | ||
constructor () { | ||
this.__isContract = true; | ||
} | ||
} | ||
expect(Contract._isContract(new Something())).to.deep.equal(true); | ||
}); | ||
}); | ||
describe('subclass specific functioning', () => { | ||
@@ -135,0 +172,0 @@ |
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
83142
2101