@@ -18,7 +18,7 @@ import { deepEqual } from 'assert';
18
18
import { expect } from 'chai' ;
19
19
import { Observable , of as observableOf } from 'rxjs' ;
20
20
import { deepEqual as deepEqualParam , instance , mock , verify , when } from 'ts-mockito' ;
21
- import { UnresolvedAddress } from '../../src' ;
21
+ import { MultisigAccountGraphInfo , UnresolvedAddress } from '../../src' ;
22
22
import { Listener , ListenerChannelName } from '../../src/infrastructure/Listener' ;
23
23
import { MultisigRepository } from '../../src/infrastructure/MultisigRepository' ;
24
24
import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository' ;
@@ -43,7 +43,29 @@ describe('Listener', () => {
43
43
'26b64cb10f005e5988a36744ca19e20d835ccc7c105aaa5f3b212da593180930' ,
44
44
NetworkType . PRIVATE_TEST ,
45
45
) ;
46
+ const account1 = Address . createFromPublicKey (
47
+ '68B3FBB18729C1FDE225C57F8CE080FA828F0067E451A3FD81FA628842B0B763' ,
48
+ NetworkType . PRIVATE_TEST ,
49
+ ) ;
50
+ const account2 = Address . createFromPublicKey (
51
+ 'DAB1C38C3E1642494FCCB33138B95E81867B5FB59FC4277A1D53761C8B9F6D14' ,
52
+ NetworkType . PRIVATE_TEST ,
53
+ ) ;
54
+
55
+ const account3 = Address . createFromPublicKey (
56
+ '1674016C27FE2C2EB5DFA73996FA54A183B38AED0AA64F756A3918BAF08E061B' ,
57
+ NetworkType . PRIVATE_TEST ,
58
+ ) ;
59
+
60
+ const multisig1 = Address . createFromPublicKey (
61
+ 'B694186EE4AB0558CA4AFCFDD43B42114AE71094F5A1FC4A913FE9971CACD21D' ,
62
+ NetworkType . PRIVATE_TEST ,
63
+ ) ;
46
64
65
+ const multisig2 = Address . createFromPublicKey (
66
+ 'CF893FFCC47C33E7F68AB1DB56365C156B0736824A0C1E273F9E00B8DF8F01EB' ,
67
+ NetworkType . PRIVATE_TEST ,
68
+ ) ;
47
69
let namespaceRepoMock : NamespaceRepository ;
48
70
let namespaceRepo : NamespaceRepository ;
49
71
let multisigRepoMock : MultisigRepository ;
@@ -57,6 +79,14 @@ describe('Listener', () => {
57
79
multisigRepo = instance ( multisigRepoMock ) ;
58
80
} ) ;
59
81
82
+ function givenMultisig2AccountGraphInfo ( ) : MultisigAccountGraphInfo {
83
+ const map = new Map < number , MultisigAccountInfo [ ] > ( ) ;
84
+ map . set ( 0 , [ new MultisigAccountInfo ( 1 , multisig2 , 2 , 1 , [ multisig1 , account1 ] , [ ] ) ] ) . set ( 1 , [
85
+ new MultisigAccountInfo ( 1 , multisig1 , 1 , 1 , [ account2 , account3 ] , [ multisig2 ] ) ,
86
+ ] ) ;
87
+
88
+ return new MultisigAccountGraphInfo ( map ) ;
89
+ }
60
90
it ( 'should createComplete a WebSocket instance given url parameter' , ( ) => {
61
91
const listener = new Listener ( 'http://localhost:3000/ws' , namespaceRepo , epochAdjustment ) ;
62
92
expect ( 'http://localhost:3000/ws' ) . to . be . equal ( listener . url ) ;
@@ -215,7 +245,6 @@ describe('Listener', () => {
215
245
216
246
[ ListenerChannelName . confirmedAdded , ListenerChannelName . partialAdded , ListenerChannelName . unconfirmedAdded ] . forEach ( ( name ) => {
217
247
const subscribedAddress = account . address ;
218
- const multisigAccount = Account . generateNewAccount ( NetworkType . PRIVATE_TEST ) ;
219
248
class WebSocketMock {
220
249
constructor ( public readonly url : string ) { }
221
250
send ( payload : string ) : void {
@@ -259,14 +288,15 @@ describe('Listener', () => {
259
288
describe ( `${ name } transaction subscription` , ( ) => {
260
289
it ( 'subscribe multsig' , ( ) => {
261
290
const alias = new NamespaceId ( 'test' ) ;
262
- const multisigInfo = new MultisigAccountInfo ( 1 , subscribedAddress , 1 , 1 , [ ] , [ multisigAccount . address ] ) ;
263
- when ( multisigRepoMock . getMultisigAccountInfo ( deepEqualParam ( subscribedAddress ) ) ) . thenReturn ( observableOf ( multisigInfo ) ) ;
264
- when ( namespaceRepoMock . getAccountsNames ( deepEqualParam ( [ subscribedAddress ] ) ) ) . thenReturn (
265
- observableOf ( [ new AccountNames ( subscribedAddress , [ new NamespaceName ( alias , 'test' ) ] ) ] ) ,
291
+ when ( multisigRepoMock . getMultisigAccountGraphInfo ( deepEqualParam ( account2 ) ) ) . thenReturn (
292
+ observableOf ( givenMultisig2AccountGraphInfo ( ) ) ,
293
+ ) ;
294
+ when ( namespaceRepoMock . getAccountsNames ( deepEqualParam ( [ account2 ] ) ) ) . thenReturn (
295
+ observableOf ( [ new AccountNames ( account2 , [ new NamespaceName ( alias , 'test' ) ] ) ] ) ,
266
296
) ;
267
297
const transferTransaction = TransferTransaction . create (
268
298
Deadline . create ( epochAdjustment ) ,
269
- multisigAccount . address ,
299
+ multisig2 ,
270
300
[ ] ,
271
301
PlainMessage . create ( 'test-message' ) ,
272
302
NetworkType . PRIVATE_TEST ,
@@ -277,7 +307,7 @@ describe('Listener', () => {
277
307
278
308
const listener = new Listener ( 'http://localhost:3000' , namespaceRepo , WebSocketMultisigMock , multisigRepo ) ;
279
309
listener . open ( ) ;
280
- subscriptionMethod ( listener , subscribedAddress , hash , true ) . subscribe ( ) ;
310
+ subscriptionMethod ( listener , account2 , hash , true ) . subscribe ( ) ;
281
311
282
312
listener . handleMessage (
283
313
{
@@ -377,8 +407,6 @@ describe('Listener', () => {
377
407
} ) ;
378
408
379
409
it ( 'Using invalid no hash' , ( ) => {
380
- const subscribedAddress = account . address ;
381
-
382
410
const alias = new NamespaceId ( 'test' ) ;
383
411
const transferTransaction = TransferTransaction . create (
384
412
Deadline . create ( epochAdjustment ) ,
@@ -511,7 +539,6 @@ describe('Listener', () => {
511
539
512
540
[ ListenerChannelName . unconfirmedRemoved , ListenerChannelName . partialRemoved ] . forEach ( ( name ) => {
513
541
const subscribedAddress = account . address ;
514
- const multisigAccount = Account . generateNewAccount ( NetworkType . PRIVATE_TEST ) ;
515
542
class WebSocketMock {
516
543
constructor ( public readonly url : string ) { }
517
544
send ( payload : string ) : void {
@@ -539,20 +566,20 @@ describe('Listener', () => {
539
566
540
567
describe ( `${ name } transaction subscription` , ( ) => {
541
568
it ( 'subscribe multsig' , ( ) => {
542
- const multisigInfo = new MultisigAccountInfo ( 1 , subscribedAddress , 1 , 1 , [ ] , [ multisigAccount . address ] ) ;
543
- when ( multisigRepoMock . getMultisigAccountInfo ( deepEqualParam ( subscribedAddress ) ) ) . thenReturn ( observableOf ( multisigInfo ) ) ;
569
+ when ( multisigRepoMock . getMultisigAccountGraphInfo ( deepEqualParam ( account2 ) ) ) . thenReturn (
570
+ observableOf ( givenMultisig2AccountGraphInfo ( ) ) ,
571
+ ) ;
544
572
const hash = 'abc' ;
545
573
const message = {
546
- topic : `${ name . toString ( ) } /${ subscribedAddress . plain ( ) } ` ,
574
+ topic : `${ name . toString ( ) } /${ account2 . plain ( ) } ` ,
547
575
data : { meta : { height : '1' , hash : hash } } ,
548
576
} ;
549
577
550
578
const listener = new Listener ( 'http://localhost:3000' , namespaceRepo , WebSocketMultisigMock , multisigRepo ) ;
551
579
listener . open ( ) ;
552
- subscriptionMethod ( listener , subscribedAddress , hash , true ) . subscribe ( ) ;
580
+ subscriptionMethod ( listener , account2 , hash , true ) . subscribe ( ) ;
553
581
554
582
listener . handleMessage ( message , null ) ;
555
-
556
583
expect ( multisigIndex ) . to . be . equal ( 2 ) ;
557
584
} ) ;
558
585
} ) ;
0 commit comments