@@ -89,23 +89,24 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using
89
89
}
90
90
} ) ;
91
91
92
+ const transaction = contract . createTransaction ( 'move' ) ;
93
+ const transactionId = transaction . getTransactionID ( ) . getTransactionID ( ) ;
94
+
92
95
// Obtain an event hub that that will be used by the underlying implementation
93
96
org1EventHub = await getFirstEventHubForOrg ( gateway , 'Org1MSP' ) ;
94
97
const org2EventHub = await getFirstEventHubForOrg ( gateway , 'Org2MSP' ) ;
95
98
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 ;
99
100
100
101
// have to register for all transaction events (a new feature in 1.3) as
101
102
// there is no way to know what the initial transaction id is
102
103
org1EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
103
- if ( code === 'VALID' ) {
104
+ if ( code === 'VALID' && txId === transactionId ) {
104
105
eventFired ++ ;
105
106
}
106
107
} , ( ) => { } ) ;
107
108
108
- const response = await contract . submitTransaction ( 'move' , 'a' , 'b' , '100' ) ;
109
+ const response = await transaction . submit ( 'a' , 'b' , '100' ) ;
109
110
110
111
t . true ( org1EventHub . isconnected ( ) , 'org1 event hub correctly connected' ) ;
111
112
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
145
146
}
146
147
} ) ;
147
148
149
+ const transactions = new Array ( 3 ) . fill ( 'move' ) . map ( ( name ) => contract . createTransaction ( name ) ) ;
150
+ const transactionIds = transactions . map ( ( tx ) => tx . getTransactionID ( ) . getTransactionID ( ) ) ;
151
+
148
152
// Obtain an event hub that that will be used by the underlying implementation
149
153
org1EventHub = await getFirstEventHubForOrg ( gateway , 'Org1MSP' ) ;
150
154
const org2EventHub = await getFirstEventHubForOrg ( gateway , 'Org2MSP' ) ;
151
155
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 ;
155
157
156
158
// have to register for all transaction events (a new feature in 1.3) as
157
159
// there is no way to know what the initial transaction id is
158
160
org1EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
159
- if ( code === 'VALID' ) {
161
+ if ( code === 'VALID' && transactionIds . includes ( txId ) ) {
160
162
eventFired ++ ;
161
163
}
162
164
} , ( ) => { } ) ;
163
165
164
- let response = await contract . submitTransaction ( 'move' , 'a' , 'b' , '100' ) ;
166
+ let response = await transactions [ 0 ] . submit ( 'a' , 'b' , '100' ) ;
165
167
166
168
t . true ( org1EventHub . isconnected ( ) , 'org1 event hub correctly connected' ) ;
167
169
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
175
177
}
176
178
177
179
// second transaction for same connection
178
- response = await contract . submitTransaction ( 'move' , 'a' , 'b' , '50' ) ;
180
+ response = await transactions [ 1 ] . submit ( 'a' , 'b' , '50' ) ;
179
181
180
182
t . equal ( eventFired , 2 , 'single event for org1 correctly unblocked submitTransaction' ) ;
181
183
@@ -186,7 +188,7 @@ test('\n\n***** Network End-to-end flow: invoke multiple transactions to move mo
186
188
}
187
189
188
190
// third transaction for same connection
189
- response = await contract . submitTransaction ( 'move' , 'a' , 'b' , '25' ) ;
191
+ response = await transactions [ 2 ] . submit ( 'a' , 'b' , '25' ) ;
190
192
191
193
t . equal ( eventFired , 3 , 'single event for org1 correctly unblocked submitTransaction' ) ;
192
194
@@ -226,23 +228,24 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using
226
228
}
227
229
} ) ;
228
230
231
+ const transaction = contract . createTransaction ( 'move' ) ;
232
+ const transactionId = transaction . getTransactionID ( ) . getTransactionID ( ) ;
233
+
229
234
// Obtain an event hub that that will be used by the underlying implementation
230
235
org1EventHub = await getFirstEventHubForOrg ( gateway , 'Org1MSP' ) ;
231
236
const org2EventHub = await getFirstEventHubForOrg ( gateway , 'Org2MSP' ) ;
232
237
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 ;
236
239
237
240
// have to register for all transaction events (a new feature in 1.3) as
238
241
// there is no way to know what the initial transaction id is
239
242
org1EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
240
- if ( code === 'VALID' ) {
243
+ if ( code === 'VALID' && txId === transactionId ) {
241
244
eventFired ++ ;
242
245
}
243
246
} , ( ) => { } ) ;
244
247
245
- const response = await contract . submitTransaction ( 'move' , 'a' , 'b' , '100' ) ;
248
+ const response = await transaction . submit ( 'a' , 'b' , '100' ) ;
246
249
247
250
t . false ( org2EventHub . isconnected ( ) , 'org2 event hub correctly not connected' ) ;
248
251
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
281
284
}
282
285
} ) ;
283
286
287
+ const transaction = contract . createTransaction ( 'move' ) ;
288
+ const transactionId = transaction . getTransactionID ( ) . getTransactionID ( ) ;
289
+
284
290
// Obtain an event hub that that will be used by the underlying implementation
285
291
org1EventHub = await getFirstEventHubForOrg ( gateway , 'Org1MSP' ) ;
286
292
const org2EventHub = await getFirstEventHubForOrg ( gateway , 'Org2MSP' ) ;
287
293
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 ;
291
295
292
296
// have to register for all transaction events (a new feature in 1.3) as
293
297
// there is no way to know what the initial transaction id is
294
298
org1EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
295
- if ( code === 'VALID' ) {
299
+ if ( code === 'VALID' && txId === transactionId ) {
296
300
eventFired ++ ;
297
301
}
298
302
} , ( ) => { } ) ;
299
303
300
- const response = await contract . submitTransaction ( 'move' , 'a' , 'b' , '100' ) ;
304
+ const response = await transaction . submit ( 'a' , 'b' , '100' ) ;
301
305
302
306
t . false ( org2EventHub . isconnected ( ) , 'org2 event hub correctly not connected' ) ;
303
307
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
338
342
}
339
343
} ) ;
340
344
345
+ const transaction = contract . createTransaction ( 'move' ) ;
346
+ const transactionId = transaction . getTransactionID ( ) . getTransactionID ( ) ;
347
+
341
348
// Obtain the event hubs that that will be used by the underlying implementation
342
349
org1EventHub = await getFirstEventHubForOrg ( gateway , 'Org1MSP' ) ;
343
350
org2EventHub = await getFirstEventHubForOrg ( gateway , 'Org2MSP' ) ;
344
351
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 ;
349
354
org1EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
350
- if ( code === 'VALID' ) {
355
+ if ( code === 'VALID' && txId === transactionId ) {
351
356
org1EventFired ++ ;
352
357
}
353
358
} , ( ) => { } ) ;
354
359
355
360
org2EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
356
- if ( code === 'VALID' ) {
361
+ if ( code === 'VALID' && txId === transactionId ) {
357
362
org2EventFired ++ ;
358
363
}
359
364
} , ( ) => { } ) ;
360
365
361
- const response = await contract . submitTransaction ( 'move' , 'a' , 'b' , '100' ) ;
366
+ const response = await transaction . submit ( 'a' , 'b' , '100' ) ;
362
367
363
368
const unblockCorrectly = ( org1EventFired === 1 ) && ( org2EventFired === 1 ) ;
364
369
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
402
407
}
403
408
} ) ;
404
409
410
+ const transaction = contract . createTransaction ( 'move' ) ;
411
+ const transactionId = transaction . getTransactionID ( ) . getTransactionID ( ) ;
412
+
405
413
// Obtain the event hubs that that will be used by the underlying implementation
406
414
org1EventHub = await getFirstEventHubForOrg ( gateway , 'Org1MSP' ) ;
407
415
org2EventHub = await getFirstEventHubForOrg ( gateway , 'Org2MSP' ) ;
408
416
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 ;
413
419
org1EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
414
- if ( code === 'VALID' ) {
420
+ if ( code === 'VALID' && txId === transactionId ) {
415
421
org1EventFired ++ ;
416
422
}
417
423
} , ( ) => { } ) ;
418
424
419
425
org2EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
420
- if ( code === 'VALID' ) {
426
+ if ( code === 'VALID' && txId === transactionId ) {
421
427
org2EventFired ++ ;
422
428
}
423
429
} , ( ) => { } ) ;
424
430
425
- const response = await contract . submitTransaction ( 'move' , 'a' , 'b' , '100' ) ;
431
+ const response = await transaction . submit ( 'a' , 'b' , '100' ) ;
426
432
427
433
const unblockCorrectly = ( org1EventFired === 1 ) && ( org2EventFired === 1 ) ;
428
434
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
466
472
}
467
473
} ) ;
468
474
475
+ const transaction = contract . createTransaction ( 'move' ) ;
476
+ const transactionId = transaction . getTransactionID ( ) . getTransactionID ( ) ;
477
+
469
478
// Obtain the event hubs that that will be used by the underlying implementation
470
479
org1EventHub = await getFirstEventHubForOrg ( gateway , 'Org1MSP' ) ;
471
480
org2EventHub = await getFirstEventHubForOrg ( gateway , 'Org2MSP' ) ;
472
481
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 ;
478
484
org1EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
479
- if ( code === 'VALID' ) {
485
+ if ( code === 'VALID' && txId === transactionId ) {
480
486
org1EventFired ++ ;
481
487
}
482
488
} , ( ) => { } ) ;
483
489
484
490
org2EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
485
- if ( code === 'VALID' ) {
491
+ if ( code === 'VALID' && txId === transactionId ) {
486
492
org2EventFired ++ ;
487
493
}
488
494
} , ( ) => { } ) ;
489
495
490
- const response = await contract . submitTransaction ( 'move' , 'a' , 'b' , '100' ) ;
496
+ const response = await transaction . submit ( 'a' , 'b' , '100' ) ;
491
497
492
498
const unblockCorrectly = ( org1EventFired === 1 && org2EventFired === 0 ) ||
493
499
( org1EventFired === 0 && org2EventFired === 1 )
@@ -536,28 +542,28 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using
536
542
}
537
543
} ) ;
538
544
545
+ const transaction = contract . createTransaction ( 'move' ) ;
546
+ const transactionId = transaction . getTransactionID ( ) . getTransactionID ( ) ;
547
+
539
548
// Obtain the event hubs that that will be used by the underlying implementation
540
549
org1EventHub = await getFirstEventHubForOrg ( gateway , 'Org1MSP' ) ;
541
550
org2EventHub = await getFirstEventHubForOrg ( gateway , 'Org2MSP' ) ;
542
551
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 ;
548
554
org1EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
549
- if ( code === 'VALID' ) {
555
+ if ( code === 'VALID' && txId === transactionId ) {
550
556
org1EventFired ++ ;
551
557
}
552
558
} , ( ) => { } ) ;
553
559
554
560
org2EventHub . registerTxEvent ( 'all' , ( txId , code ) => {
555
- if ( code === 'VALID' ) {
561
+ if ( code === 'VALID' && txId === transactionId ) {
556
562
org2EventFired ++ ;
557
563
}
558
564
} , ( ) => { } ) ;
559
565
560
- const response = await contract . submitTransaction ( 'move' , 'a' , 'b' , '100' ) ;
566
+ const response = await transaction . submit ( 'a' , 'b' , '100' ) ;
561
567
562
568
const unblockCorrectly = ( org1EventFired === 1 && org2EventFired === 0 ) ||
563
569
( org1EventFired === 0 && org2EventFired === 1 )
0 commit comments