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.49 to 1.4.0-snapshot.50

16

lib/jsontransactionserializer.js

@@ -24,3 +24,3 @@ /*

*/
toBuffer(result) {
toBuffer(result, schema = {}) {

@@ -30,4 +30,14 @@ // relay on the default algorithms, including for Buffers. Just retunring the buffer

if (result) {
const payload = JSON.stringify(result);
return Buffer.from(payload);
// 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
// double check the type of the result passed in
if (schema.type !== typeof result) {
throw new Error(`Returned value is ${typeof result} does not match schema type of ${schema.type}`);
}
return Buffer.from(result.toString());
} else {
const payload = JSON.stringify(result);
return Buffer.from(payload);
}
} else {

@@ -34,0 +44,0 @@ return;

2

package.json
{
"name": "fabric-contract-api",
"version": "1.4.0-snapshot.49",
"version": "1.4.0-snapshot.50",
"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",

@@ -77,3 +77,3 @@ /*

it ('should return undefined if nothing passed in ', () => {
it ('should return undefined if nothing passed in (no schema) ', () => {
const sc0 = new JSONSerializer();

@@ -83,6 +83,4 @@ expect(sc0.toBuffer()).to.be.equal(undefined);

it ('should return stringifed result', () => {
it ('should return stringifed result (no schema)', () => {
const sc0 = new JSONSerializer();
for (let i = 0; i < data.length; i++) {

@@ -92,2 +90,19 @@ expect(sc0.toBuffer(data[i])).to.deep.equal(buffer[i]);

});
it ('should return string from a string in result if schema given', () => {
const sc0 = new JSONSerializer();
expect(sc0.toBuffer('hello world', {type:'string'})).to.deep.equal(Buffer.from('hello world'));
});
it ('should return number from a number in result if schema given', () => {
const sc0 = new JSONSerializer();
expect(sc0.toBuffer(42, {type:'number'})).to.deep.equal(Buffer.from('42'));
});
it ('should throw an error if the type of data passed does not match schema given', () => {
const sc0 = new JSONSerializer();
(() => {
sc0.toBuffer(42, {type:'string'});
}).should.throw(/Returned value is .* does not match schema type of .*/);
});
});

@@ -94,0 +109,0 @@

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