diff --git a/build/tasks/test.js b/build/tasks/test.js index f246d61d18..fa386909e0 100644 --- a/build/tasks/test.js +++ b/build/tasks/test.js @@ -130,7 +130,7 @@ gulp.task('compile', shell.task([ // - Cannot use gulp-istabul because it throws "unexpected identifier" for async/await functions // Main test to run all tests -gulp.task('test', shell.task('npx nyc gulp run-test')); +gulp.task('test', shell.task('npx nyc gulp run-test-all')); // Test to run all unit tests gulp.task('test-headless', shell.task('npx gulp run-test-headless')); @@ -170,7 +170,7 @@ gulp.task('mocha-fabric-client', gulp.task('mocha-fabric-network', () => { return gulp.src(['./fabric-network/test/**/*.js'], {read: false}) - .pipe(mocha({reporter: 'list', exit: true})); + .pipe(mocha({reporter: 'list', exit: true, timeout: 10000})); } ); @@ -287,7 +287,7 @@ gulp.task('run-tape-e2e', ['docker-ready'], 'test/integration/nodechaincode/e2e.js', 'test/integration/e2e.js', 'test/integration/network-e2e/e2e.js', - // 'test/integration/network-e2e/e2e-hsm.js', + 'test/integration/network-e2e/e2e-hsm.js', 'test/integration/signTransactionOffline.js', 'test/integration/query.js', 'test/integration/client.js', @@ -332,9 +332,6 @@ function shouldRunTests(tests) { tests.push('!test/unit/pkcs11.js'); tests.push('!test/integration/network-e2e/e2e-hsm.js'); // check to see if they want to test PKCS11 - } else if (typeof process.env.PKCS11_TESTS === 'string' && process.env.PKCS11_TESTS.toLowerCase() === 'true') { - tests.push('!test/integration/network-e2e/e2e.js'); - // check to see if they do not want to test PKCS11 } else if (typeof process.env.PKCS11_TESTS === 'string' && process.env.PKCS11_TESTS.toLowerCase() === 'false') { tests.push('!test/unit/pkcs11.js'); tests.push('!test/integration/network-e2e/e2e-hsm.js'); diff --git a/fabric-client/lib/Channel.js b/fabric-client/lib/Channel.js index db1ae1e069..8886b6f8c8 100644 --- a/fabric-client/lib/Channel.js +++ b/fabric-client/lib/Channel.js @@ -45,6 +45,8 @@ function logAndThrow(methodName, errorMessage) { throw new Error(errorMessage); } +let channel_count = 1; + /** * Channels provide data isolation for a set of participating organizations. *

@@ -116,7 +118,8 @@ const Channel = class { this._commit_handler = null; this._prover_handler = null; - logger.debug('Constructed Channel instance: name - %s, network mode: %s', this._name, !this._devMode); + this._number = channel_count++; + logger.debug('Constructed Channel instance:%s name - %s, network mode: %s', this._number, this._name, !this._devMode); } /** @@ -179,14 +182,16 @@ const Channel = class { * @return {Promise} A Promise that will resolve when the action is complete */ async initialize(request) { - const method = 'initialize'; - logger.debug('%s - start', method); + const method = 'initialize' + this._number; + logger.debug('%s - start channel:%s', method, this._name); let endorsement_handler_path = null; let commit_handler_path = null; let prover_handler_path = null; if (request) { + logger.debug('%s - request.asLocalhost:%s', method, request.asLocalhost); + logger.debug('%s - ConfigSetting-discovery-as-localhost:%s', method, sdk_utils.getConfigSetting('discovery-as-localhost')); if (request.configUpdate) { logger.debug('%s - have a configupdate', method); this.loadConfigUpdate(request.configUpdate); @@ -1489,7 +1494,10 @@ const Channel = class { // endpoints may be running in containers on the local system if (this._as_localhost) { + logger.debug('%s - mapping to localhost %s', method, t_hostname); t_hostname = 'localhost'; + } else { + logger.debug('%s - not mapping to localhost %s', method, t_hostname); } // If we connect to the discovery peer over TLS, any peers returned by @@ -2859,7 +2867,9 @@ const Channel = class { const method = 'sendTransactionProposal'; logger.debug('%s - start', method); + const errorMsg = client_utils.checkProposalRequest(request, true); + if (errorMsg) { logAndThrow(method, errorMsg); } diff --git a/fabric-client/lib/Remote.js b/fabric-client/lib/Remote.js index 034e25d4c7..b02479aad1 100644 --- a/fabric-client/lib/Remote.js +++ b/fabric-client/lib/Remote.js @@ -152,7 +152,7 @@ class Remote { client.waitForReady(timeout, (err) => { if (err) { if (err.message) { - err.message = err.message + ' URL:' + self.getUrl(); + err.message = err.message + ' URL:' + self.getUrl() + ' timeout:' + this._grpc_wait_for_ready_timeout; } err.connectFailed = true; logger.error(err); diff --git a/fabric-client/lib/impl/DiscoveryEndorsementHandler.js b/fabric-client/lib/impl/DiscoveryEndorsementHandler.js index 5c0c3ae566..6d338d6f0c 100644 --- a/fabric-client/lib/impl/DiscoveryEndorsementHandler.js +++ b/fabric-client/lib/impl/DiscoveryEndorsementHandler.js @@ -126,6 +126,7 @@ class DiscoveryEndorsementHandler extends EndorsementHandler { async _endorse(endorsement_plan, request, proposal, timeout) { const method = '_endorse'; + logger.debug('%s - start', method); // see if we have an endorsement plan for the requested chaincodes/collection call if (endorsement_plan) { @@ -136,12 +137,12 @@ class DiscoveryEndorsementHandler extends EndorsementHandler { results.failed_endorsements = []; results.success = false; - const required = this._create_map(request.required, 'endpoint'); - const preferred = this._create_map(request.preferred, 'endpoint'); - const ignored = this._create_map(request.ignored, 'endpoint'); - const required_orgs = this._create_map(request.requiredOrgs, 'mspid'); - const preferred_orgs = this._create_map(request.preferredOrgs, 'mspid'); - const ignored_orgs = this._create_map(request.ignoredOrgs, 'mspid'); + const required = this._create_map(request.required, 'required'); + const preferred = this._create_map(request.preferred, 'preferred'); + const ignored = this._create_map(request.ignored, 'ignored'); + const required_orgs = this._create_map(request.requiredOrgs, 'requiredOrgs'); + const preferred_orgs = this._create_map(request.preferredOrgs, 'preferredOrgs'); + const ignored_orgs = this._create_map(request.ignoredOrgs, 'ignoredOrgs'); let preferred_height_gap = null; try { preferred_height_gap = Long.fromValue(request.preferredHeightGap); @@ -182,7 +183,13 @@ class DiscoveryEndorsementHandler extends EndorsementHandler { if (!results.success) { const error = new Error('Endorsement has failed'); + logger.error('%s - endorsement failed::%s', method, error.stack); error.endorsements = results.failed_endorsements; + for (const endorsement of results.endorsements) { + if (endorsement instanceof Error) { + logger.error('%s - %s', method, endorsement.stack); + } + } throw error; } @@ -345,8 +352,11 @@ class DiscoveryEndorsementHandler extends EndorsementHandler { for (const group_name in endorsement_plan.groups) { const group = endorsement_plan.groups[group_name]; + logger.debug('%s starting - group: %s - size: %s', method, group_name, group.peers.length); // remove ignored and non-required const clean_list = this._removePeers(ignored, ignored_orgs, required, required_orgs, group.peers); + logger.debug('%s removed - group: %s - size: %s', method, group_name, clean_list.length); + // get the highest ledger height if needed let highest = null; if (preferred_height_gap) { @@ -354,10 +364,13 @@ class DiscoveryEndorsementHandler extends EndorsementHandler { } // sort based on ledger height or randomly const sorted_list = this._sortPeerList(sort, clean_list); + logger.debug('%s sorted - group: %s - size: %s', method, group_name, sorted_list.length); // pop the priority peers off the sorted list const split_lists = this._splitList(preferred, preferred_orgs, highest, preferred_height_gap, sorted_list); // put the priorities on top const reordered_list = split_lists.priority.concat(split_lists.non_priority); + logger.debug('%s reordered - group: %s - size: %s', method, group_name, reordered_list.length); + // set the rebuilt peer list into the group group.peers = reordered_list; } @@ -365,10 +378,13 @@ class DiscoveryEndorsementHandler extends EndorsementHandler { logger.debug('%s - updated endorsement_plan:%j', method, endorsement_plan); } - _create_map(array) { + _create_map(items, type) { + const method = '_create_map'; + logger.debug('%s - start for %s', method, type); const map = new Map(); - if (array && Array.isArray(array)) { - array.forEach((item) => { + if (items && Array.isArray(items)) { + items.forEach((item) => { + logger.debug('%s - adding %s', method, item); map.set(item, item); }); } @@ -381,35 +397,42 @@ class DiscoveryEndorsementHandler extends EndorsementHandler { */ _removePeers(ignored_peers, ignored_orgs, required_peers, required_orgs, peers) { const method = '_removePeers'; - logger.debug('%s - start', method); + logger.debug('%s - start size:%s', method, peers.length); const keep_list = []; for (const peer of peers) { let found = ignored_peers.has(peer.name); if (!found) { found = ignored_orgs.has(peer.mspid); if (!found) { + logger.debug('%s - not found in ignored list - peer:%s', method, peer.name); // if the user has requested required peers/orgs // then all peers that stay on the list must be // one of those peers or in one of those orgs - if (required_peers.size || required_orgs.size) { + if (required_peers.size > 0 || required_orgs.size > 0) { found = required_peers.has(peer.name); if (!found) { + logger.debug('%s - not found in required peers - peer:%s', method, peer.name); found = required_orgs.has(peer.mspid); } // if we did not find it on a either list then // this peer will not be added to the keep list if (!found) { + logger.debug('%s - removing peer:%s', method, peer.name); continue; // do not add this peer to the keep list } } // looks like this peer is not on the ignored list and // is on the required list (if being used); + logger.debug('%s - keeping peer:%s', method, peer.name); keep_list.push(peer); } + } else { + logger.debug('%s - found in ignored list - peer:%s', method, peer.name); } } + logger.debug('%s - end size:%s', method, keep_list.length); return keep_list; } @@ -429,8 +452,8 @@ class DiscoveryEndorsementHandler extends EndorsementHandler { } _sortPeerList(sort, peers) { - const method = '_sortList'; - logger.debug('%s - start - %s', method, sort); + const method = '_sortPeerList'; + logger.debug('%s - start - sort:%s - size:%s', method, sort, peers.length); let sorted = null; if (!sort || sort === BLOCK_HEIGHT || sort === DEFAULT) { @@ -474,7 +497,7 @@ class DiscoveryEndorsementHandler extends EndorsementHandler { _splitList(preferred_peers, preferred_orgs, preferred_height_gap, highest, sorted_list) { const method = '_splitList'; - logger.debug('%s - start', method); + logger.debug('%s - start size:%s', method, sorted_list.length); const list = {}; list.priority = []; list.non_priority = []; @@ -508,6 +531,7 @@ class DiscoveryEndorsementHandler extends EndorsementHandler { } } + logger.debug('%s - end - priority:%s - non_priority:%s', method, list.priority.length, list.non_priority.length); return list; } diff --git a/test/typescript/integration/network-e2e/invoke.ts b/test/typescript/integration/network-e2e/invoke.ts index 7a8fea96ab..a4f290d908 100644 --- a/test/typescript/integration/network-e2e/invoke.ts +++ b/test/typescript/integration/network-e2e/invoke.ts @@ -124,6 +124,10 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using try { const contract = await createContract(t, gateway, { clientTlsIdentity: 'tlsId', + discovery: { + asLocalhost: true, + enabled: true, + }, identity: 'User1@org1.example.com', wallet: inMemoryWallet, }); @@ -424,6 +428,10 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using try { const contract = await createContract(t, gateway, { clientTlsIdentity: 'tlsId', + discovery: { + asLocalhost: true, + enabled: true, + }, eventHandlerOptions: { strategy: DefaultEventHandlerStrategies.NETWORK_SCOPE_ALLFORTX, }, @@ -552,6 +560,10 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using try { const contract = await createContract(t, gateway, { clientTlsIdentity: 'tlsId', + discovery: { + asLocalhost: true, + enabled: true, + }, eventHandlerOptions: { strategy: DefaultEventHandlerStrategies.NETWORK_SCOPE_ANYFORTX, },