diff --git a/examples/simple-asset-transfer/fabric/connector.js b/examples/simple-asset-transfer/fabric/connector.js index f5df7b98ec..b995ea7550 100644 --- a/examples/simple-asset-transfer/fabric/connector.js +++ b/examples/simple-asset-transfer/fabric/connector.js @@ -2,7 +2,6 @@ const rp = require(`request-promise-native`); const { Connector } = require(`@hyperledger-labs/blockchain-integration-framework`); class MyFabricConnector extends Connector.FABRIC { - static snakeToCamel(str) { return str.replace(/(_\w)/g, m => m[1].toUpperCase()); } @@ -14,15 +13,18 @@ class MyFabricConnector extends Connector.FABRIC { const isArray = Array.isArray(value); acc[newKey] = isArray ? value.map(item => MyFabricConnector.objectKeysSnakeToCamel(item)) : value; return acc; - }, {}) + }, {}); } static omitDeep(obj, omitKey) { - return Object.keys(obj).reduce((acc, key) => { - if (key === omitKey) return acc; - acc[key] = obj[key]; - return acc; - }, { ...obj[omitKey] }) + return Object.keys(obj).reduce( + (acc, key) => { + if (key === omitKey) return acc; + acc[key] = obj[key]; + return acc; + }, + { ...obj[omitKey] } + ); } static renameKeysByMap(obj, map) { @@ -32,13 +34,17 @@ class MyFabricConnector extends Connector.FABRIC { const isArray = Array.isArray(value); acc[newKey] = isArray ? value.map(item => MyFabricConnector.renameKeysByMap(item, map)) : value; return acc; - }, {}) + }, {}); } static standardizeAssetOutput(asset) { const camelAsset = MyFabricConnector.objectKeysSnakeToCamel(asset); const deepOmitedAsset = MyFabricConnector.omitDeep(camelAsset, 'properties'); - return MyFabricConnector.renameKeysByMap(deepOmitedAsset, { dltId: 'dltID', originDltId: 'originDLTId', receiverPk: 'receiverPK' }); + return MyFabricConnector.renameKeysByMap(deepOmitedAsset, { + dltId: 'dltID', + originDltId: 'originDLTId', + receiverPk: 'receiverPK', + }); } /** diff --git a/examples/simple-asset-transfer/quorum/connector.js b/examples/simple-asset-transfer/quorum/connector.js index 53c739a3a8..6a3dedab7e 100644 --- a/examples/simple-asset-transfer/quorum/connector.js +++ b/examples/simple-asset-transfer/quorum/connector.js @@ -10,7 +10,7 @@ class MyQuorumConnector extends Connector.QUORUM { return { asset_id: asset.assetId, dltId: asset.dltID, - origin: asset.origin.map(item => ({ + origin: asset.origin.map(() => ({ origin_dlt_id: `DLT100`, origin_asset_id: `Asset_DLT100_1`, })), diff --git a/examples/simple-asset-transfer/tests/connector-quorum.js b/examples/simple-asset-transfer/tests/connector-quorum.js index 4005814cbe..fb1d7bdf96 100644 --- a/examples/simple-asset-transfer/tests/connector-quorum.js +++ b/examples/simple-asset-transfer/tests/connector-quorum.js @@ -13,10 +13,10 @@ const { Multisig } = require(`@hyperledger-labs/blockchain-integration-framework chai.use(cp); -describe(`ConnectorQuorumExample Constructor`, function () { - it(`empty instance should throw`, function () { +describe(`ConnectorQuorumExample Constructor`, function() { + it(`empty instance should throw`, function() { chai - .expect(function () { + .expect(function() { new ConnectorQuorumEx(); }) .to.throw(ReferenceError); @@ -33,68 +33,68 @@ describe(`ConnectorQuorumExample Constructor`, function () { .to.throw(ReferenceError); }); - it(`Invalid url should throw`, function () { + it(`Invalid url should throw`, function() { const options = { url: `http://:6000`, }; chai - .expect(function () { + .expect(function() { new ConnectorQuorumEx(options); }) .to.throw(TypeError); }); - it(`Invalid port should throw`, function () { + it(`Invalid port should throw`, function() { const options = { url: `http://127.0.0.1:23`, }; chai - .expect(function () { + .expect(function() { new ConnectorQuorumEx(options); }) .to.throw(RangeError); }); - it(`Non provided Quorum-specific param should throw`, function () { + it(`Non provided Quorum-specific param should throw`, function() { const options = { url: `http://127.0.0.1:4000`, }; chai - .expect(function () { + .expect(function() { new ConnectorQuorumEx(options); }) .to.throw(ReferenceError); }); - it(`Invalid password should throw`, function () { + it(`Invalid password should throw`, function() { const options = { url: `http://127.0.0.1:4000`, username: `smith`, password: 45, }; chai - .expect(function () { + .expect(function() { new ConnectorQuorumEx(options); }) .to.throw(TypeError, `invalid password provided: 45`); }); }); -describe(`ConnectorQuorumExample getAccessToken`, function () { +describe(`ConnectorQuorumExample getAccessToken`, function() { const options = config.blockchains.quorum; const connector1 = new ConnectorQuorumEx(options); - before(function () { + before(function() { if (!process.env.BLOCKCHAIN) { this.skip(); } }); - it(`getAccessToken with correct credentials`, function (done) { + it(`getAccessToken with correct credentials`, function(done) { chai.expect(connector1.getAccessToken()).to.eventually.be.fulfilled.notify(done); }); - it(`getAccessToken with wrong credentials`, function (done) { + it(`getAccessToken with wrong credentials`, function(done) { connector1.options.password = `fakePassword`; chai .expect(connector1.getAccessToken()) @@ -102,7 +102,7 @@ describe(`ConnectorQuorumExample getAccessToken`, function () { .notify(done); }); - it(`Wrong param added on the fly should throw`, function (done) { + it(`Wrong param added on the fly should throw`, function(done) { connector1.options.url = 45; chai .expect(connector1.getAccessToken()) @@ -111,17 +111,17 @@ describe(`ConnectorQuorumExample getAccessToken`, function () { }); }); -describe(`ConnectorQuorumExample addForeignValidator`, function () { +describe(`ConnectorQuorumExample addForeignValidator`, function() { const options = config.blockchains.quorum; const connector2 = new ConnectorQuorumEx(options); - before(function () { + before(function() { if (!process.env.BLOCKCHAIN) { this.skip(); } }); - it(`Add correct foreign validator`, function (done) { + it(`Add correct foreign validator`, function(done) { this.timeout(5000); let privkey; @@ -136,7 +136,7 @@ describe(`ConnectorQuorumExample addForeignValidator`, function () { .notify(done); }); - it(`Add foreign validator with empty input`, function (done) { + it(`Add foreign validator with empty input`, function(done) { this.timeout(5000); chai .expect(connector2.addForeignValidator()) @@ -165,7 +165,7 @@ describe(`ConnectorQuorumExample addForeignValidator`, function () { // .notify(done); // }); - it(`Wrong param added on the fly should throw`, function (done) { + it(`Wrong param added on the fly should throw`, function(done) { connector2.options.url = 45; chai .expect(connector2.addForeignValidator()) @@ -174,11 +174,11 @@ describe(`ConnectorQuorumExample addForeignValidator`, function () { }); }); -describe(`ConnectorQuorumExample verifySignature`, function () { +describe(`ConnectorQuorumExample verifySignature`, function() { const options = config.blockchains.quorum; const connector3 = new ConnectorQuorumEx(options); - before(function () { + before(function() { this.timeout(5000); if (!process.env.BLOCKCHAIN) { this.skip(); @@ -188,10 +188,10 @@ describe(`ConnectorQuorumExample verifySignature`, function () { // already exist. const pubkey = '0234fae14b0993085d798b964761abd5036376133a79d1b6545b58a1d28fe14a2e'; const name = `foreignValidator1`; - return connector3.addForeignValidator(pubkey, name).catch(() => { }); + return connector3.addForeignValidator(pubkey, name).catch(() => {}); }); - it(`Verify a correct signature`, function (done) { + it(`Verify a correct signature`, function(done) { this.timeout(5000); // const pubkey = `036aaf98c8c07ccef29f43528b8682407b1ddb9e9ca4c427c751a3ea151cfabd90`; const signature = `0xc81acfc729bc5527a0a9187ba88a7b495100d018cb2814877a9bdbf058daf25f59cf38cbd6ea7237967c8c31799af3afc3614216f565af451a80c395399ca8031b`; @@ -202,7 +202,7 @@ describe(`ConnectorQuorumExample verifySignature`, function () { .notify(done); }); - it(`Verify a wrong signature`, function (done) { + it(`Verify a wrong signature`, function(done) { this.timeout(5000); // const pubkey = `036aaf98c8c07ccef29f43528b8682407b1ddb9e9ca4c427c751a3ea151cfabd90`; const signature = `0xc81acfc729bc5527a0a9187ba88a7b495100d018cb2814877a9bdbf058daf25f59cf38cbd6ea7237967c8c31799af3afc3614216f565af451a80c395399ca8031b`; @@ -213,7 +213,7 @@ describe(`ConnectorQuorumExample verifySignature`, function () { .notify(done); }); - it(`Wrong param added on the fly should throw`, function (done) { + it(`Wrong param added on the fly should throw`, function(done) { // const pubkey = `036aaf98c8c07ccef29f43528b8682407b1ddb9e9ca4c427c751a3ea151cfabd90`; const signature = `0xc81acfc729bc5527a0a9187ba88a7b495100d018cb2814877a9bdbf058daf25f59cf38cbd6ea7237967c8c31799af3afc3614216f565af451a80c395399ca8031b`; const message = `Hello world!`; @@ -225,11 +225,11 @@ describe(`ConnectorQuorumExample verifySignature`, function () { }); }); -describe(`ConnectorQuorumExample verifyMultisig`, function () { +describe(`ConnectorQuorumExample verifyMultisig`, function() { const options = config.blockchains.quorum; const connector4 = new ConnectorQuorumEx(options); - before(function () { + before(function() { this.timeout(5000); if (!process.env.BLOCKCHAIN) { this.skip(); @@ -240,7 +240,7 @@ describe(`ConnectorQuorumExample verifyMultisig`, function () { return connector4.addForeignValidator(pubkey, name).catch(() => 0); }); - it(`empty multisig object should throw`, function (done) { + it(`empty multisig object should throw`, function(done) { const multisig1 = new Multisig(); chai .expect(connector4.verifyMultisig(multisig1)) @@ -248,7 +248,7 @@ describe(`ConnectorQuorumExample verifyMultisig`, function () { .notify(done); }); - it(`one correct signature, one wrong signature`, function (done) { + it(`one correct signature, one wrong signature`, function(done) { this.timeout(5000); const multisig2 = new Multisig(`Hello world!`); const pubkey = `036aaf98c8c07ccef29f43528b8682407b1ddb9e9ca4c427c751a3ea151cfabd90`; @@ -263,7 +263,7 @@ describe(`ConnectorQuorumExample verifyMultisig`, function () { .notify(done); }); - it(`Wrong param added on the fly should throw`, function (done) { + it(`Wrong param added on the fly should throw`, function(done) { const multisig3 = new Multisig(`Hello world!`); const pubkey = `036aaf98c8c07ccef29f43528b8682407b1ddb9e9ca4c427c751a3ea151cfabd90`; const signature = `0xc81acfc729bc5527a0a9187ba88a7b495100d018cb2814877a9bdbf058daf25f59cf38cbd6ea7237967c8c31799af3afc3614216f565af451a80c395399ca8031b`; @@ -276,17 +276,17 @@ describe(`ConnectorQuorumExample verifyMultisig`, function () { }); }); -describe(`ConnectorQuorumExample CreateAsset`, function () { +describe(`ConnectorQuorumExample CreateAsset`, function() { const options = config.blockchains.quorum; const connector4 = new ConnectorQuorumEx(options); - before(function () { + before(function() { if (!process.env.BLOCKCHAIN) { this.skip(); } }); - it(`Creating a correctly formed asset`, function (done) { + it(`Creating a correctly formed asset`, function(done) { this.timeout(5000); const asset1 = { assetId: `Asset_DLT_1_${Date.now()}`, @@ -304,7 +304,7 @@ describe(`ConnectorQuorumExample CreateAsset`, function () { chai.expect(connector4.createAsset(asset1)).to.eventually.fulfilled.notify(done); }); - it(`Creating a malformed asset`, function (done) { + it(`Creating a malformed asset`, function(done) { this.timeout(5000); const asset2 = {}; chai @@ -313,7 +313,7 @@ describe(`ConnectorQuorumExample CreateAsset`, function () { .notify(done); }); - it(`Wrong param added on the fly should throw`, function (done) { + it(`Wrong param added on the fly should throw`, function(done) { const asset3 = { assetId: `Asset_DLT_1_${Date.now()}`, origin: [ @@ -335,7 +335,7 @@ describe(`ConnectorQuorumExample CreateAsset`, function () { }); }); -describe(`ConnectorQuorumExample LockAsset`, function () { +describe(`ConnectorQuorumExample LockAsset`, function() { const options = config.blockchains.quorum; const connector5 = new ConnectorQuorumEx(options); @@ -353,7 +353,7 @@ describe(`ConnectorQuorumExample LockAsset`, function () { }, }; - before(async function () { + before(async function() { if (!process.env.BLOCKCHAIN) { this.skip(); } else { @@ -362,14 +362,14 @@ describe(`ConnectorQuorumExample LockAsset`, function () { } }); - it(`Missing parametters should throw`, function (done) { + it(`Missing parametters should throw`, function(done) { chai .expect(connector5.lockAsset(asset4.assetId)) .be.rejectedWith(Error) .notify(done); }); - it(`Locking an existing asset with correct params`, function (done) { + it(`Locking an existing asset with correct params`, function(done) { this.timeout(5000); chai .expect( @@ -382,7 +382,7 @@ describe(`ConnectorQuorumExample LockAsset`, function () { .to.eventually.fulfilled.notify(done); }); - it(`Wrong param added on the fly should throw`, function (done) { + it(`Wrong param added on the fly should throw`, function(done) { connector5.options.url = 45; chai .expect( @@ -397,7 +397,7 @@ describe(`ConnectorQuorumExample LockAsset`, function () { }); }); -describe(`ConnectorQuorumExample SetProperty`, function () { +describe(`ConnectorQuorumExample SetProperty`, function() { const options = config.blockchains.quorum; const connector6 = new ConnectorQuorumEx(options); const asset5 = { @@ -414,7 +414,7 @@ describe(`ConnectorQuorumExample SetProperty`, function () { }, }; - before(async function () { + before(async function() { if (!process.env.BLOCKCHAIN) { this.skip(); } else { @@ -423,7 +423,7 @@ describe(`ConnectorQuorumExample SetProperty`, function () { } }); - it(`Missing parametters should throw`, function (done) { + it(`Missing parametters should throw`, function(done) { this.timeout(5000); chai .expect(connector6.setProperty(asset5.assetId)) @@ -431,14 +431,14 @@ describe(`ConnectorQuorumExample SetProperty`, function () { .notify(done); }); - it(`Setting an existing property`, function (done) { + it(`Setting an existing property`, function(done) { this.timeout(5000); chai .expect(connector6.setProperty(asset5.assetId, `property1`, `new_value_property_1`)) .to.eventually.fulfilled.notify(done); }); - it(`Setting an unknown property`, function (done) { + it(`Setting an unknown property`, function(done) { this.timeout(5000); chai .expect(connector6.setProperty(asset5.assetId, `property4`, `new_value_property_4`)) @@ -446,7 +446,7 @@ describe(`ConnectorQuorumExample SetProperty`, function () { .notify(done); }); - it(`Wrong param added on the fly should throw`, function (done) { + it(`Wrong param added on the fly should throw`, function(done) { connector6.url = 45; chai .expect(connector6.setProperty(asset5.assetId, `property4`, `new_value_property_4`)) @@ -455,7 +455,7 @@ describe(`ConnectorQuorumExample SetProperty`, function () { }); }); -describe(`ConnectorQuorumExample GetAsset`, function () { +describe(`ConnectorQuorumExample GetAsset`, function() { const options = config.blockchains.quorum; const connector7 = new ConnectorQuorumEx(options); const asset6 = { @@ -472,7 +472,7 @@ describe(`ConnectorQuorumExample GetAsset`, function () { }, }; - before(async function () { + before(async function() { if (!process.env.BLOCKCHAIN) { this.skip(); } else { @@ -481,12 +481,12 @@ describe(`ConnectorQuorumExample GetAsset`, function () { } }); - it(`get existing asset`, function (done) { + it(`get existing asset`, function(done) { this.timeout(5000); chai.expect(connector7.getAsset(asset6.assetId)).to.eventually.fulfilled.notify(done); }); - it(`get unknown asset`, function (done) { + it(`get unknown asset`, function(done) { this.timeout(5000); chai .expect(connector7.getAsset(`Asset_DLT_1`)) @@ -494,7 +494,7 @@ describe(`ConnectorQuorumExample GetAsset`, function () { .notify(done); }); - it(`Wrong param added on the fly should throw`, function (done) { + it(`Wrong param added on the fly should throw`, function(done) { connector7.options.password = undefined; chai .expect(connector7.getAsset(asset6.assetId)) @@ -503,17 +503,17 @@ describe(`ConnectorQuorumExample GetAsset`, function () { }); }); -describe(`ConnectorQuorumExample copyAsset`, function () { +describe(`ConnectorQuorumExample copyAsset`, function() { const options = config.blockchains.quorum; const connector4 = new ConnectorQuorumEx(options); - before(function () { + before(function() { if (!process.env.BLOCKCHAIN) { this.skip(); } }); - it(`Copy Asset with correct signature`, function (done) { + it(`Copy Asset with correct signature`, function(done) { this.skip(); // FixMe: Asset can be copied (created) only once. this.timeout(5000); const pubkey = '03fd076032614ba907cf03108bfb37840fd7bf4057228d32a7323077bf70144db8'; @@ -532,7 +532,7 @@ describe(`ConnectorQuorumExample copyAsset`, function () { .notify(done); }); - it(`Copy Asset with wrong signature`, function (done) { + it(`Copy Asset with wrong signature`, function(done) { this.timeout(5000); const pubkey = '03fd076032614ba907cf03108bfb37840fd7bf4057228d32a7323077bf70144db8'; const signature =