Skip to content

Commit

Permalink
[FAB-8232] apply ES6 syntax to Channel,ChannelEventHub
Browse files Browse the repository at this point in the history
- auto fix some eslint warning
- trim redundant regular expression in t.doesNotThrow
- use arrow function to avoid manually assign self=this
- use strict equals
- update jsdoc: setPeerAddr is deprecated along with EventHub, let docs align
- use for(const element of array), if index is only used to get element
- merge sleep definitaion to e2eutils and testUtils

Change-Id: I36eb871b38f7286ac5addebce35af4c397fb099e
Signed-off-by: davidliu <david-khala@hotmail.com>
  • Loading branch information
davidkhala committed Jul 24, 2018
1 parent 25fa4b0 commit e16ae90
Show file tree
Hide file tree
Showing 28 changed files with 3,059 additions and 2,957 deletions.
346 changes: 173 additions & 173 deletions fabric-client/lib/BlockDecoder.js

Large diffs are not rendered by default.

1,190 changes: 538 additions & 652 deletions fabric-client/lib/Channel.js

Large diffs are not rendered by default.

622 changes: 304 additions & 318 deletions fabric-client/lib/ChannelEventHub.js

Large diffs are not rendered by default.

339 changes: 330 additions & 9 deletions package-lock.json

Large diffs are not rendered by default.

1,040 changes: 520 additions & 520 deletions test/integration/channel-event-hub.js

Large diffs are not rendered by default.

213 changes: 105 additions & 108 deletions test/integration/e2e/e2eUtils.js

Large diffs are not rendered by default.

45 changes: 18 additions & 27 deletions test/integration/e2e/instantiate-chaincode.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,31 @@
// in a happy-path scenario
'use strict';

var utils = require('fabric-client/lib/utils.js');
var logger = utils.getLogger('E2E instantiate-chaincode');
const utils = require('fabric-client/lib/utils.js');
const logger = utils.getLogger('E2E instantiate-chaincode');

var tape = require('tape');
var _test = require('tape-promise').default;
var test = _test(tape);
const tape = require('tape');
const _test = require('tape-promise').default;
const test = _test(tape);

var e2eUtils = require('./e2eUtils.js');
var testUtil = require('../../unit/util.js');
const e2eUtils = require('./e2eUtils.js');
const testUtil = require('../../unit/util.js');

test('\n\n***** End-to-end flow: instantiate chaincode *****\n\n', (t) => {
e2eUtils.instantiateChaincode('org1', testUtil.CHAINCODE_PATH, 'v0', 'golang', false, false, t)
.then((result) => {
if(result){
test('\n\n***** End-to-end flow: instantiate chaincode *****\n\n', async (t) => {
try {
const result = await e2eUtils.instantiateChaincode('org1', testUtil.CHAINCODE_PATH, 'v0', 'golang', false, false, t);
if (result) {
t.pass('Successfully instantiated chaincode on the channel');

return sleep(5000);
await testUtil.sleep(5000);
logger.debug('Successfully slept 5s to wait for chaincode instantiate to be completed and committed in all peers');
}
else {
t.fail('Failed to instantiate chaincode ');
t.end();
}
}, (err) => {
t.fail('Failed to instantiate chaincode on the channel. ' + err.stack ? err.stack : err);
t.end();
}).then(() => {
logger.debug('Successfully slept 5s to wait for chaincode instantiate to be completed and committed in all peers');
t.end();
}).catch((err) => {
t.fail('Test failed due to unexpected reasons. ' + err.stack ? err.stack : err);
t.end();
});
} catch (err) {
t.fail('Test failed due to reasons. ' + err.stack ? err.stack : err);
}
t.end();

});

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
6 changes: 1 addition & 5 deletions test/integration/e2e/invoke-transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test('\n\n***** End-to-end flow: invoke transaction to move money *****\n\n', as
let result = await e2eUtils.invokeChaincode('org2', 'v0', chaincodeId, t, false/*useStore*/, fcn, args, expectedResult);
if(result){
t.pass('Successfully invoke transaction chaincode on channel');
await sleep(5000);
await testUtils.sleep(5000);
}
else {
t.fail('Failed to invoke transaction chaincode ');
Expand All @@ -40,7 +40,3 @@ test('\n\n***** End-to-end flow: invoke transaction to move money *****\n\n', as
}
t.end();
});

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
26 changes: 13 additions & 13 deletions test/integration/eventutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

'use strict';

var utils = require('fabric-client/lib/utils.js');
var util = require('util');
const utils = require('fabric-client/lib/utils.js');
const util = require('util');

module.exports.registerTxEvent = function(eh, txid, timeout) {
return new Promise((resolve, reject) => {
var handle = setTimeout(() => {
const handle = setTimeout(() => {
eh.unregisterTxEvent(txid);
reject('timeout');
}, timeout);
Expand All @@ -30,8 +30,8 @@ module.exports.registerTxEvent = function(eh, txid, timeout) {

module.exports.registerCCEvent = function(eh, ccid, enregex, timeout, t, message) {
return new Promise((resolve, reject) => {
var regid = null;
var handle = setTimeout(() => {
let regid = null;
const handle = setTimeout(() => {
t.fail('Failed to receive '+ message);
reject();
if (regid) {
Expand All @@ -49,8 +49,8 @@ module.exports.registerCCEvent = function(eh, ccid, enregex, timeout, t, message
};

module.exports.createRequest = function(client, chaincode_id, targets, fcn, args) {
var tx_id = client.newTransactionID();
var request = {
const tx_id = client.newTransactionID();
const request = {
targets : targets,
chaincodeId: chaincode_id,
chaincodeVersion: '',
Expand All @@ -62,10 +62,10 @@ module.exports.createRequest = function(client, chaincode_id, targets, fcn, args
};

function checkProposal(results) {
var proposalResponses = results[0];
var all_good = true;
const proposalResponses = results[0];
let all_good = true;

for (var i in proposalResponses) {
for (const i in proposalResponses) {
let one_good = false;

if (proposalResponses &&
Expand All @@ -83,9 +83,9 @@ module.exports.checkProposal = checkProposal;

module.exports.sendTransaction = function(channel, results) {
if (checkProposal(results)) {
var proposalResponses = results[0];
var proposal = results[1];
var request = {
const proposalResponses = results[0];
const proposal = results[1];
const request = {
proposalResponses: proposalResponses,
proposal: proposal
};
Expand Down
10 changes: 3 additions & 7 deletions test/integration/network-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ test('\n\n***** use the connection profile file *****\n\n', async (t) => {
logger.debug(' response ::%j', result);
t.pass('Successfully created the channel.');
if (result.status && result.status === 'SUCCESS') {
await sleep(10000);
await testUtil.sleep(10000);
} else {
t.fail('Failed to create the channel. ');
throw new Error('Failed to create the channel. ');
Expand Down Expand Up @@ -248,7 +248,7 @@ test('\n\n***** use the connection profile file *****\n\n', async (t) => {
t.fail(' Failed to join channel on org1');
throw new Error('Failed to join channel on org1');
}
await sleep(10000);
await testUtil.sleep(10000);
t.pass('Successfully waited for peers to join the channel');

process.env.GOPATH = path.join(__dirname, '../fixtures');
Expand Down Expand Up @@ -328,7 +328,7 @@ test('\n\n***** use the connection profile file *****\n\n', async (t) => {
}
if (!(response instanceof Error) && response.status === 'SUCCESS') {
t.pass('Successfully sent transaction to instantiate the chaincode to the orderer.');
await sleep(10000);
await testUtil.sleep(10000);
} else {
t.fail('Failed to order the transaction to instantiate the chaincode. Error code: ' + response.status);
throw new Error('Failed to order the transaction to instantiate the chaincode. Error code: ' + response.status);
Expand Down Expand Up @@ -775,7 +775,3 @@ test('\n\n***** Enroll user and set user context using a bad caName *****\n\n',

t.end();
});

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
6 changes: 1 addition & 5 deletions test/integration/nodechaincode/instantiate-chaincode.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test('\n\n***** Node-Chaincode End-to-end flow: instantiate chaincode *****\n\n'
if(result){
t.pass('Successfully instantiated chaincode on the channel');

return sleep(5000);
return testUtil.sleep(5000);
}
else {
t.fail('Failed to instantiate chaincode ');
Expand All @@ -44,7 +44,3 @@ test('\n\n***** Node-Chaincode End-to-end flow: instantiate chaincode *****\n\n'
t.end();
});
});

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
6 changes: 1 addition & 5 deletions test/integration/nodechaincode/invoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test('\n\n***** Node-Chaincode End-to-end flow: invoke transaction to move money
let result = await e2eUtils.invokeChaincode('org2', 'v0', chaincodeId, t, false/*useStore*/, fcn, args, expectedResult);
if(result){
t.pass('Successfully invoke transaction chaincode on channel');
await sleep(5000);
await testUtils.sleep(5000);
}
else {
t.fail('Failed to invoke transaction chaincode ');
Expand All @@ -47,7 +47,3 @@ test('\n\n***** Node-Chaincode End-to-end flow: invoke transaction to move money
}
t.end();
});

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
Loading

0 comments on commit e16ae90

Please sign in to comment.