Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

fabric-contract-api

Package Overview
Dependencies
Maintainers
1
Versions
221
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fabric-contract-api - npm Package Compare versions

Comparing version 1.4.0-snapshot.43 to 1.4.0-snapshot.44

10

lib/contract.js

@@ -27,3 +27,2 @@ /*

constructor(name) {
this.__isContract = true;
if (name && name.trim() !== '') {

@@ -37,11 +36,2 @@ this.name = name.trim();

/**
* 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

@@ -48,0 +38,0 @@ * Override this method to implement your own processing. Examples of what you may wish to code

27

lib/jsontransactionserializer.js

@@ -51,19 +51,28 @@ /*

}
let value;
let jsonForValidation;
// check that schema to see exactly how we should de-marshall this
if (schema.type && (schema.type === 'string' || schema.type === 'number')) {
// ok so this is a basic primitive type, and for strings and numbers the wireprotocol is different
value = data.toString();
jsonForValidation = JSON.stringify(value);
} else {
const json = JSON.parse(data.toString());
if (json.type) {
if (json.type === 'Buffer') {
value = Buffer.from(json.data);
const json = JSON.parse(data.toString());
if (json.type) {
if (json.type === 'Buffer') {
value = Buffer.from(json.data);
} else {
throw new Error(`Type of ${json.type} is not understood, can't recreate data`);
}
} else {
throw new Error(`Type of ${json.type} is not understood, can't recreate data`);
value = json;
}
} else {
value = json;
// as JSON then this si the same
jsonForValidation = value;
}
return {value};
return {value, jsonForValidation};
}
};
{
"name": "fabric-contract-api",
"version": "1.4.0-snapshot.43",
"version": "1.4.0-snapshot.44",
"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",

@@ -128,29 +128,4 @@ /*

});
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', () => {

@@ -157,0 +132,0 @@

@@ -60,2 +60,9 @@ /*

const dataForValidation = [
'HelloWorld',
42,
{text:'hello', value: {i:'root -1'}},
Buffer.from('hello')
];
const buffer = [];

@@ -98,6 +105,25 @@

for (let i = 0; i < data.length; i++) {
expect(sc0.fromBuffer(buffer[i])).to.deep.equal({value: data[i]});
expect(sc0.fromBuffer(buffer[i])).to.deep.equal({value: data[i], jsonForValidation: dataForValidation[i]});
}
});
it('should handle specific String case', () => {
const sc0 = new JSONSerializer();
const v = sc0.fromBuffer(Buffer.from('HelloWorld'), {type:'string'});
v.should.deep.equal({value:'HelloWorld', jsonForValidation:JSON.stringify('HelloWorld')});
});
it('should handle specific Number case', () => {
const sc0 = new JSONSerializer();
const v = sc0.fromBuffer(Buffer.from('102345679'), {type:'number'});
v.should.deep.equal({value:'102345679', jsonForValidation:JSON.stringify('102345679')});
});
it('should handle specific Number case', () => {
const sc0 = new JSONSerializer();
const v = sc0.fromBuffer(Buffer.from(JSON.stringify({'wibble':'wobble'})), {type:'whatever'});
v.should.deep.equal({value:{'wibble':'wobble'}, jsonForValidation:{'wibble':'wobble'}});
});
it ('should handle errors of unkown type', () => {

@@ -104,0 +130,0 @@ const sc0 = new JSONSerializer();

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc