@@ -89,23 +89,24 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using
8989 }
9090 } ) ;
9191
92+ const transaction = contract . createTransaction ( 'move' ) ;
93+ const transactionId = transaction . getTransactionID ( ) . getTransactionID ( ) ;
94+
9295 // Obtain an event hub that that will be used by the underlying implementation
9396 org1EventHub = await getFirstEventHubForOrg ( gateway , 'Org1MSP' ) ;
9497 const org2EventHub = await getFirstEventHubForOrg ( gateway , 'Org2MSP' ) ;
9598
96- // Initialize eventFired to -1 since the event hub connection event will happen during
97- // the first call to submitTransaction() after the network is created
98- let eventFired = - 1 ;
99+ let eventFired = 0 ;
99100
100101 // have to register for all transaction events (a new feature in 1.3) as
101102 // there is no way to know what the initial transaction id is
102103 org1EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
103- if ( code === 'VALID' ) {
104+ if ( code === 'VALID' && txId === transactionId ) {
104105 eventFired ++ ;
105106 }
106107 } , ( ) => { } ) ;
107108
108- const response = await contract . submitTransaction ( 'move' , 'a' , 'b' , '100' ) ;
109+ const response = await transaction . submit ( 'a' , 'b' , '100' ) ;
109110
110111 t . true ( org1EventHub . isconnected ( ) , 'org1 event hub correctly connected' ) ;
111112 t . false ( org2EventHub . isconnected ( ) , 'org2 event hub correctly not connected' ) ;
@@ -145,23 +146,24 @@ test('\n\n***** Network End-to-end flow: invoke multiple transactions to move mo
145146 }
146147 } ) ;
147148
149+ const transactions = new Array ( 3 ) . fill ( 'move' ) . map ( ( name ) => contract . createTransaction ( name ) ) ;
150+ const transactionIds = transactions . map ( ( tx ) => tx . getTransactionID ( ) . getTransactionID ( ) ) ;
151+
148152 // Obtain an event hub that that will be used by the underlying implementation
149153 org1EventHub = await getFirstEventHubForOrg ( gateway , 'Org1MSP' ) ;
150154 const org2EventHub = await getFirstEventHubForOrg ( gateway , 'Org2MSP' ) ;
151155
152- // Initialize eventFired to -1 since the event hub connection event will happen during
153- // the first call to submitTransaction() after the network is created
154- let eventFired = - 1 ;
156+ let eventFired = 0 ;
155157
156158 // have to register for all transaction events (a new feature in 1.3) as
157159 // there is no way to know what the initial transaction id is
158160 org1EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
159- if ( code === 'VALID' ) {
161+ if ( code === 'VALID' && transactionIds . includes ( txId ) ) {
160162 eventFired ++ ;
161163 }
162164 } , ( ) => { } ) ;
163165
164- let response = await contract . submitTransaction ( 'move' , 'a' , 'b' , '100' ) ;
166+ let response = await transactions [ 0 ] . submit ( 'a' , 'b' , '100' ) ;
165167
166168 t . true ( org1EventHub . isconnected ( ) , 'org1 event hub correctly connected' ) ;
167169 t . false ( org2EventHub . isconnected ( ) , 'org2 event hub correctly not connected' ) ;
@@ -175,7 +177,7 @@ test('\n\n***** Network End-to-end flow: invoke multiple transactions to move mo
175177 }
176178
177179 // second transaction for same connection
178- response = await contract . submitTransaction ( 'move' , 'a' , 'b' , '50' ) ;
180+ response = await transactions [ 1 ] . submit ( 'a' , 'b' , '50' ) ;
179181
180182 t . equal ( eventFired , 2 , 'single event for org1 correctly unblocked submitTransaction' ) ;
181183
@@ -186,7 +188,7 @@ test('\n\n***** Network End-to-end flow: invoke multiple transactions to move mo
186188 }
187189
188190 // third transaction for same connection
189- response = await contract . submitTransaction ( 'move' , 'a' , 'b' , '25' ) ;
191+ response = await transactions [ 2 ] . submit ( 'a' , 'b' , '25' ) ;
190192
191193 t . equal ( eventFired , 3 , 'single event for org1 correctly unblocked submitTransaction' ) ;
192194
@@ -226,23 +228,24 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using
226228 }
227229 } ) ;
228230
231+ const transaction = contract . createTransaction ( 'move' ) ;
232+ const transactionId = transaction . getTransactionID ( ) . getTransactionID ( ) ;
233+
229234 // Obtain an event hub that that will be used by the underlying implementation
230235 org1EventHub = await getFirstEventHubForOrg ( gateway , 'Org1MSP' ) ;
231236 const org2EventHub = await getFirstEventHubForOrg ( gateway , 'Org2MSP' ) ;
232237
233- // Initialize eventFired to -1 since the event hub connection event will happen during
234- // the first call to submitTransaction() after the network is created
235- let eventFired = - 1 ;
238+ let eventFired = 0 ;
236239
237240 // have to register for all transaction events (a new feature in 1.3) as
238241 // there is no way to know what the initial transaction id is
239242 org1EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
240- if ( code === 'VALID' ) {
243+ if ( code === 'VALID' && txId === transactionId ) {
241244 eventFired ++ ;
242245 }
243246 } , ( ) => { } ) ;
244247
245- const response = await contract . submitTransaction ( 'move' , 'a' , 'b' , '100' ) ;
248+ const response = await transaction . submit ( 'a' , 'b' , '100' ) ;
246249
247250 t . false ( org2EventHub . isconnected ( ) , 'org2 event hub correctly not connected' ) ;
248251 t . equal ( eventFired , 1 , 'single event for org1 correctly unblocked submitTransaction' ) ;
@@ -281,23 +284,24 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using
281284 }
282285 } ) ;
283286
287+ const transaction = contract . createTransaction ( 'move' ) ;
288+ const transactionId = transaction . getTransactionID ( ) . getTransactionID ( ) ;
289+
284290 // Obtain an event hub that that will be used by the underlying implementation
285291 org1EventHub = await getFirstEventHubForOrg ( gateway , 'Org1MSP' ) ;
286292 const org2EventHub = await getFirstEventHubForOrg ( gateway , 'Org2MSP' ) ;
287293
288- // Initialize eventFired to -1 since the event hub connection event will happen during
289- // the first call to submitTransaction() after the network is created
290- let eventFired = - 1 ;
294+ let eventFired = 0 ;
291295
292296 // have to register for all transaction events (a new feature in 1.3) as
293297 // there is no way to know what the initial transaction id is
294298 org1EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
295- if ( code === 'VALID' ) {
299+ if ( code === 'VALID' && txId === transactionId ) {
296300 eventFired ++ ;
297301 }
298302 } , ( ) => { } ) ;
299303
300- const response = await contract . submitTransaction ( 'move' , 'a' , 'b' , '100' ) ;
304+ const response = await transaction . submit ( 'a' , 'b' , '100' ) ;
301305
302306 t . false ( org2EventHub . isconnected ( ) , 'org2 event hub correctly not connected' ) ;
303307 t . equal ( eventFired , 1 , 'single event for org1 correctly unblocked submitTransaction' ) ;
@@ -338,27 +342,28 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using
338342 }
339343 } ) ;
340344
345+ const transaction = contract . createTransaction ( 'move' ) ;
346+ const transactionId = transaction . getTransactionID ( ) . getTransactionID ( ) ;
347+
341348 // Obtain the event hubs that that will be used by the underlying implementation
342349 org1EventHub = await getFirstEventHubForOrg ( gateway , 'Org1MSP' ) ;
343350 org2EventHub = await getFirstEventHubForOrg ( gateway , 'Org2MSP' ) ;
344351
345- // Initialize eventFired to -1 since the event hub connection event will happen during
346- // the first call to submitTransaction() after the network is created
347- let org1EventFired = - 1 ;
348- let org2EventFired = - 1 ;
352+ let org1EventFired = 0 ;
353+ let org2EventFired = 0 ;
349354 org1EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
350- if ( code === 'VALID' ) {
355+ if ( code === 'VALID' && txId === transactionId ) {
351356 org1EventFired ++ ;
352357 }
353358 } , ( ) => { } ) ;
354359
355360 org2EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
356- if ( code === 'VALID' ) {
361+ if ( code === 'VALID' && txId === transactionId ) {
357362 org2EventFired ++ ;
358363 }
359364 } , ( ) => { } ) ;
360365
361- const response = await contract . submitTransaction ( 'move' , 'a' , 'b' , '100' ) ;
366+ const response = await transaction . submit ( 'a' , 'b' , '100' ) ;
362367
363368 const unblockCorrectly = ( org1EventFired === 1 ) && ( org2EventFired === 1 ) ;
364369 t . pass ( `org1 events: ${ org1EventFired } , org2 events: ${ org2EventFired } ` ) ;
@@ -402,27 +407,28 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using
402407 }
403408 } ) ;
404409
410+ const transaction = contract . createTransaction ( 'move' ) ;
411+ const transactionId = transaction . getTransactionID ( ) . getTransactionID ( ) ;
412+
405413 // Obtain the event hubs that that will be used by the underlying implementation
406414 org1EventHub = await getFirstEventHubForOrg ( gateway , 'Org1MSP' ) ;
407415 org2EventHub = await getFirstEventHubForOrg ( gateway , 'Org2MSP' ) ;
408416
409- // Initialize eventFired to -1 since the event hub connection event will happen during
410- // the first call to submitTransaction() after the network is created
411- let org1EventFired = - 1 ;
412- let org2EventFired = - 1 ;
417+ let org1EventFired = 0 ;
418+ let org2EventFired = 0 ;
413419 org1EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
414- if ( code === 'VALID' ) {
420+ if ( code === 'VALID' && txId === transactionId ) {
415421 org1EventFired ++ ;
416422 }
417423 } , ( ) => { } ) ;
418424
419425 org2EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
420- if ( code === 'VALID' ) {
426+ if ( code === 'VALID' && txId === transactionId ) {
421427 org2EventFired ++ ;
422428 }
423429 } , ( ) => { } ) ;
424430
425- const response = await contract . submitTransaction ( 'move' , 'a' , 'b' , '100' ) ;
431+ const response = await transaction . submit ( 'a' , 'b' , '100' ) ;
426432
427433 const unblockCorrectly = ( org1EventFired === 1 ) && ( org2EventFired === 1 ) ;
428434 t . pass ( `org1 events: ${ org1EventFired } , org2 events: ${ org2EventFired } ` ) ;
@@ -466,28 +472,28 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using
466472 }
467473 } ) ;
468474
475+ const transaction = contract . createTransaction ( 'move' ) ;
476+ const transactionId = transaction . getTransactionID ( ) . getTransactionID ( ) ;
477+
469478 // Obtain the event hubs that that will be used by the underlying implementation
470479 org1EventHub = await getFirstEventHubForOrg ( gateway , 'Org1MSP' ) ;
471480 org2EventHub = await getFirstEventHubForOrg ( gateway , 'Org2MSP' ) ;
472481
473- // Initialize eventFired to -1 since the event hub connection event will happen during
474- // the first call to submitTransaction() after the network is created
475- let org1EventFired = - 1 ;
476- let org2EventFired = - 1 ;
477-
482+ let org1EventFired = 0 ;
483+ let org2EventFired = 0 ;
478484 org1EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
479- if ( code === 'VALID' ) {
485+ if ( code === 'VALID' && txId === transactionId ) {
480486 org1EventFired ++ ;
481487 }
482488 } , ( ) => { } ) ;
483489
484490 org2EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
485- if ( code === 'VALID' ) {
491+ if ( code === 'VALID' && txId === transactionId ) {
486492 org2EventFired ++ ;
487493 }
488494 } , ( ) => { } ) ;
489495
490- const response = await contract . submitTransaction ( 'move' , 'a' , 'b' , '100' ) ;
496+ const response = await transaction . submit ( 'a' , 'b' , '100' ) ;
491497
492498 const unblockCorrectly = ( org1EventFired === 1 && org2EventFired === 0 ) ||
493499 ( org1EventFired === 0 && org2EventFired === 1 )
@@ -536,28 +542,28 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using
536542 }
537543 } ) ;
538544
545+ const transaction = contract . createTransaction ( 'move' ) ;
546+ const transactionId = transaction . getTransactionID ( ) . getTransactionID ( ) ;
547+
539548 // Obtain the event hubs that that will be used by the underlying implementation
540549 org1EventHub = await getFirstEventHubForOrg ( gateway , 'Org1MSP' ) ;
541550 org2EventHub = await getFirstEventHubForOrg ( gateway , 'Org2MSP' ) ;
542551
543- // Initialize eventFired to -1 since the event hub connection event will happen during
544- // the first call to submitTransaction() after the network is created
545- let org1EventFired = - 1 ;
546- let org2EventFired = - 1 ;
547-
552+ let org1EventFired = 0 ;
553+ let org2EventFired = 0 ;
548554 org1EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
549- if ( code === 'VALID' ) {
555+ if ( code === 'VALID' && txId === transactionId ) {
550556 org1EventFired ++ ;
551557 }
552558 } , ( ) => { } ) ;
553559
554560 org2EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
555- if ( code === 'VALID' ) {
561+ if ( code === 'VALID' && txId === transactionId ) {
556562 org2EventFired ++ ;
557563 }
558564 } , ( ) => { } ) ;
559565
560- const response = await contract . submitTransaction ( 'move' , 'a' , 'b' , '100' ) ;
566+ const response = await transaction . submit ( 'a' , 'b' , '100' ) ;
561567
562568 const unblockCorrectly = ( org1EventFired === 1 && org2EventFired === 0 ) ||
563569 ( org1EventFired === 0 && org2EventFired === 1 )
0 commit comments