1616
1717import { assert , expect } from 'chai' ;
1818import { AccountRepository } from '../../src/infrastructure/AccountRepository' ;
19- import { Listener } from '../../src/infrastructure/Listener' ;
2019import { MultisigRepository } from '../../src/infrastructure/MultisigRepository' ;
2120import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository' ;
22- import { RestrictionAccountRepository } from '../../src/infrastructure/RestrictionAccountRespository' ;
23- import { TransactionRepository } from '../../src/infrastructure/TransactionRepository' ;
2421import { Account } from '../../src/model/account/Account' ;
2522import { Address } from '../../src/model/account/Address' ;
2623import { PublicAccount } from '../../src/model/account/PublicAccount' ;
@@ -37,9 +34,9 @@ import { NamespaceRegistrationTransaction } from '../../src/model/transaction/Na
3734import { TransferTransaction } from '../../src/model/transaction/TransferTransaction' ;
3835import { UInt64 } from '../../src/model/UInt64' ;
3936import { RepositoryFactory } from "../../src/infrastructure/RepositoryFactory" ;
40- import { RepositoryFactoryHttp } from "../../src/infrastructure/RepositoryFactoryHttp " ;
37+ import { Config } from "./Config " ;
4138
42- describe ( 'AccountRepository ' , ( ) => {
39+ describe ( 'AccountHttp ' , ( ) => {
4340 let account : Account ;
4441 let account2 : Account ;
4542 let account3 : Account ;
@@ -54,47 +51,45 @@ describe('AccountRepository', () => {
5451 let accountRepository : AccountRepository ;
5552 let multisigRepository : MultisigRepository ;
5653 let namespaceRepository : NamespaceRepository ;
57- let restrictionRepository : RestrictionAccountRepository ;
58- let transactionRepository : TransactionRepository ;
5954 let namespaceId : NamespaceId ;
6055 let generationHash : string ;
61- let networkType : NetworkType = NetworkType . MIJIN_TEST ;
62- let config ;
56+ let networkType : NetworkType ;
57+ let config : Config ;
58+ let maxFee = UInt64 . fromUint ( 1000000 ) ;
6359
6460 before ( ( done ) => {
65- const path = require ( 'path' ) ;
66- require ( 'fs' ) . readFile ( path . resolve ( __dirname , '../conf/network.conf' ) , ( err , data ) => {
67- if ( err ) {
68- throw err ;
69- }
70- const json = JSON . parse ( data ) ;
71- config = json ;
72- account = Account . createFromPrivateKey ( json . testAccount . privateKey , networkType ) ;
73- account2 = Account . createFromPrivateKey ( json . testAccount2 . privateKey , networkType ) ;
74- account3 = Account . createFromPrivateKey ( json . testAccount3 . privateKey , networkType ) ;
75- multisigAccount = Account . createFromPrivateKey ( json . multisigAccount . privateKey , networkType ) ;
76- cosignAccount1 = Account . createFromPrivateKey ( json . cosignatoryAccount . privateKey , networkType ) ;
77- cosignAccount2 = Account . createFromPrivateKey ( json . cosignatory2Account . privateKey , networkType ) ;
78- cosignAccount3 = Account . createFromPrivateKey ( json . cosignatory3Account . privateKey , networkType ) ;
79- accountAddress = Address . createFromRawAddress ( json . testAccount . address ) ;
80- accountPublicKey = json . testAccount . publicKey ;
81- publicAccount = PublicAccount . createFromPublicKey ( json . testAccount . publicKey , networkType ) ;
82- generationHash = json . generationHash ;
8361
84- repositoryFactory = new RepositoryFactoryHttp ( json . apiUrl ) ;
62+ config = new Config ( ( ) => {
63+ account = config . account ;
64+ account2 = config . account2 ;
65+ account3 = config . account3 ;
66+ multisigAccount = config . multisigAccount ;
67+ cosignAccount1 = config . cosignAccount1 ;
68+ cosignAccount2 = config . cosignAccount2 ;
69+ cosignAccount3 = config . cosignAccount3 ;
70+ accountAddress = config . account . address ;
71+ accountPublicKey = config . account . publicKey ;
72+ publicAccount = config . account . publicAccount ;
73+ generationHash = config . generationHash ;
74+ networkType = config . networkType ;
75+ repositoryFactory = config . repositoryFactory ;
8576 accountRepository = repositoryFactory . createAccountRepository ( ) ;
86- transactionRepository = repositoryFactory . createTransactionRepository ( ) ;
87- restrictionRepository = repositoryFactory . createRestrictionAccountRepository ( ) ;
8877 multisigRepository = repositoryFactory . createMultisigRepository ( ) ;
8978 namespaceRepository = repositoryFactory . createNamespaceRepository ( ) ;
90-
91- repositoryFactory . getGenerationHash ( ) . subscribe ( generationHash => {
92- this . generationHash = generationHash ;
93- done ( ) ;
94- } ) ;
95-
79+ done ( ) ;
9680 } ) ;
9781 } ) ;
82+ before ( ( ) => {
83+ return config . listener . open ( ) ;
84+ } ) ;
85+
86+ after ( ( ) => {
87+ config . listener . close ( ) ;
88+ } ) ;
89+ afterEach ( ( done ) => {
90+ // cold down
91+ setTimeout ( done , 200 ) ;
92+ } ) ;
9893
9994 /**
10095 * =========================
@@ -103,109 +98,54 @@ describe('AccountRepository', () => {
10398 */
10499
105100 describe ( 'Make sure test account is not virgin' , ( ) => {
106- let listener : Listener ;
107- before ( ( ) => {
108- listener = new Listener ( config . apiUrl ) ;
109- return listener . open ( ) ;
110- } ) ;
111- after ( ( ) => {
112- return listener . close ( ) ;
113- } ) ;
114-
115101 it ( 'Announce TransferTransaction' , ( done ) => {
116102 const transferTransaction = TransferTransaction . create (
117103 Deadline . create ( ) ,
118104 account2 . address ,
119105 [ NetworkCurrencyMosaic . createAbsolute ( 1 ) ] ,
120106 PlainMessage . create ( 'test-message' ) ,
121107 networkType ,
108+ maxFee
122109 ) ;
123- const signedTransaction = transferTransaction . signWith ( account , generationHash ) ;
124110
125- listener . confirmed ( account . address ) . subscribe ( ( ) => {
126- done ( ) ;
127- } ) ;
128- listener . status ( account . address ) . subscribe ( ( error ) => {
129- console . log ( 'Error:' , error ) ;
130- assert ( false ) ;
131- done ( ) ;
132- } ) ;
133- transactionRepository . announce ( signedTransaction ) ;
111+ const signedTransaction = transferTransaction . signWith ( account , generationHash ) ;
112+ config . announceTransaction ( signedTransaction , done ) ;
134113 } ) ;
135114 } ) ;
136115
137116 describe ( 'Setup test NamespaceId' , ( ) => {
138- let listener : Listener ;
139- before ( ( ) => {
140- listener = new Listener ( config . apiUrl ) ;
141- return listener . open ( ) ;
142- } ) ;
143- after ( ( ) => {
144- return listener . close ( ) ;
145- } ) ;
146117 it ( 'Announce NamespaceRegistrationTransaction' , ( done ) => {
147118 const namespaceName = 'root-test-namespace-' + Math . floor ( Math . random ( ) * 10000 ) ;
148119 const registerNamespaceTransaction = NamespaceRegistrationTransaction . createRootNamespace (
149120 Deadline . create ( ) ,
150121 namespaceName ,
151122 UInt64 . fromUint ( 9 ) ,
152123 networkType ,
124+ maxFee
153125 ) ;
154126 namespaceId = new NamespaceId ( namespaceName ) ;
155127 const signedTransaction = registerNamespaceTransaction . signWith ( account , generationHash ) ;
156- listener . confirmed ( account . address ) . subscribe ( ( ) => {
157- done ( ) ;
158- } ) ;
159- listener . status ( account . address ) . subscribe ( ( error ) => {
160- console . log ( 'Error:' , error ) ;
161- assert ( false ) ;
162- done ( ) ;
163- } ) ;
164- transactionRepository . announce ( signedTransaction ) ;
128+ config . announceTransaction ( signedTransaction , done ) ;
165129 } ) ;
166130 } ) ;
167131
168132 describe ( 'Setup test AddressAlias' , ( ) => {
169- let listener : Listener ;
170- before ( ( ) => {
171- listener = new Listener ( config . apiUrl ) ;
172- return listener . open ( ) ;
173- } ) ;
174- after ( ( ) => {
175- return listener . close ( ) ;
176- } ) ;
177133
178134 it ( 'Announce addressAliasTransaction' , ( done ) => {
179135 const addressAliasTransaction = AddressAliasTransaction . create (
180136 Deadline . create ( ) ,
181137 AliasAction . Link ,
182138 namespaceId ,
183139 account . address ,
184- networkType ,
140+ networkType , maxFee ,
185141 ) ;
186142 const signedTransaction = addressAliasTransaction . signWith ( account , generationHash ) ;
187-
188- listener . confirmed ( account . address ) . subscribe ( ( ) => {
189- done ( ) ;
190- } ) ;
191- listener . status ( account . address ) . subscribe ( ( error ) => {
192- console . log ( 'Error:' , error ) ;
193- assert ( false ) ;
194- done ( ) ;
195- } ) ;
196- transactionRepository . announce ( signedTransaction ) ;
143+ config . announceTransaction ( signedTransaction , done ) ;
197144 } ) ;
198145 } ) ;
199146
200147 describe ( 'Setup test multisig account' , ( ) => {
201- let listener : Listener ;
202- before ( ( ) => {
203- listener = new Listener ( config . apiUrl ) ;
204- return listener . open ( ) ;
205- } ) ;
206- after ( ( ) => {
207- return listener . close ( ) ;
208- } ) ;
148+
209149 it ( 'Announce MultisigAccountModificationTransaction' , ( done ) => {
210150 const modifyMultisigAccountTransaction = MultisigAccountModificationTransaction . create (
211151 Deadline . create ( ) ,
@@ -217,24 +157,18 @@ describe('AccountRepository', () => {
217157 cosignAccount3 . publicAccount ,
218158 ] ,
219159 [ ] ,
220- networkType ,
160+ networkType , maxFee ,
221161 ) ;
222162
223163 const aggregateTransaction = AggregateTransaction . createComplete ( Deadline . create ( ) ,
224164 [ modifyMultisigAccountTransaction . toAggregate ( multisigAccount . publicAccount ) ] ,
225165 networkType ,
226- [ ] ) ;
166+ [ ] ,
167+ maxFee ) ;
227168 const signedTransaction = aggregateTransaction
228169 . signTransactionWithCosignatories ( multisigAccount , [ cosignAccount1 , cosignAccount2 , cosignAccount3 ] , generationHash ) ;
229170
230- listener . confirmed ( multisigAccount . address ) . subscribe ( ( ) => {
231- done ( ) ;
232- } ) ;
233- listener . status ( multisigAccount . address ) . subscribe ( ( error ) => {
234- console . log ( 'Error:' , error ) ;
235- done ( ) ;
236- } ) ;
237- transactionRepository . announce ( signedTransaction ) ;
171+ config . announceTransaction ( signedTransaction , done ) ;
238172 } ) ;
239173 } ) ;
240174
@@ -266,22 +200,18 @@ describe('AccountRepository', () => {
266200
267201 describe ( 'getMultisigAccountGraphInfo' , ( ) => {
268202 it ( 'should call getMultisigAccountGraphInfo successfully' , ( done ) => {
269- setTimeout ( ( ) => {
270- multisigRepository . getMultisigAccountGraphInfo ( multisigAccount . publicAccount . address ) . subscribe ( ( multisigAccountGraphInfo ) => {
271- expect ( multisigAccountGraphInfo . multisigAccounts . get ( 0 ) ! [ 0 ] . account . publicKey ) . to . be . equal ( multisigAccount . publicKey ) ;
272- done ( ) ;
273- } ) ;
274- } , 1000 ) ;
203+ multisigRepository . getMultisigAccountGraphInfo ( multisigAccount . publicAccount . address ) . subscribe ( ( multisigAccountGraphInfo ) => {
204+ expect ( multisigAccountGraphInfo . multisigAccounts . get ( 0 ) ! [ 0 ] . account . publicKey ) . to . be . equal ( multisigAccount . publicKey ) ;
205+ done ( ) ;
206+ } ) ;
275207 } ) ;
276208 } ) ;
277209 describe ( 'getMultisigAccountInfo' , ( ) => {
278210 it ( 'should call getMultisigAccountInfo successfully' , ( done ) => {
279- setTimeout ( ( ) => {
280- multisigRepository . getMultisigAccountInfo ( multisigAccount . publicAccount . address ) . subscribe ( ( multisigAccountInfo ) => {
281- expect ( multisigAccountInfo . account . publicKey ) . to . be . equal ( multisigAccount . publicKey ) ;
282- done ( ) ;
283- } ) ;
284- } , 1000 ) ;
211+ multisigRepository . getMultisigAccountInfo ( multisigAccount . publicAccount . address ) . subscribe ( ( multisigAccountInfo ) => {
212+ expect ( multisigAccountInfo . account . publicKey ) . to . be . equal ( multisigAccount . publicKey ) ;
213+ done ( ) ;
214+ } ) ;
285215 } ) ;
286216 } ) ;
287217
@@ -338,46 +268,21 @@ describe('AccountRepository', () => {
338268 * =========================
339269 */
340270 describe ( 'Remove test AddressAlias' , ( ) => {
341- let listener : Listener ;
342- before ( ( ) => {
343- listener = new Listener ( config . apiUrl ) ;
344- return listener . open ( ) ;
345- } ) ;
346- after ( ( ) => {
347- return listener . close ( ) ;
348- } ) ;
349-
350271 it ( 'Announce addressAliasTransaction' , ( done ) => {
351272 const addressAliasTransaction = AddressAliasTransaction . create (
352273 Deadline . create ( ) ,
353274 AliasAction . Unlink ,
354275 namespaceId ,
355276 account . address ,
356277 networkType ,
278+ maxFee
357279 ) ;
358280 const signedTransaction = addressAliasTransaction . signWith ( account , generationHash ) ;
359-
360- listener . confirmed ( account . address ) . subscribe ( ( ) => {
361- done ( ) ;
362- } ) ;
363- listener . status ( account . address ) . subscribe ( ( error ) => {
364- console . log ( 'Error:' , error ) ;
365- assert ( false ) ;
366- done ( ) ;
367- } ) ;
368- transactionRepository . announce ( signedTransaction ) ;
281+ config . announceTransaction ( signedTransaction , done ) ;
369282 } ) ;
370283 } ) ;
371284
372285 describe ( 'Restore test multisig Accounts' , ( ) => {
373- let listener : Listener ;
374- before ( ( ) => {
375- listener = new Listener ( config . apiUrl ) ;
376- return listener . open ( ) ;
377- } ) ;
378- after ( ( ) => {
379- return listener . close ( ) ;
380- } ) ;
381286 it ( 'Announce MultisigAccountModificationTransaction' , ( done ) => {
382287 const removeCosigner1 = MultisigAccountModificationTransaction . create (
383288 Deadline . create ( ) ,
@@ -387,6 +292,7 @@ describe('AccountRepository', () => {
387292 [ cosignAccount1 . publicAccount ,
388293 ] ,
389294 networkType ,
295+ maxFee
390296 ) ;
391297 const removeCosigner2 = MultisigAccountModificationTransaction . create (
392298 Deadline . create ( ) ,
@@ -397,6 +303,7 @@ describe('AccountRepository', () => {
397303 cosignAccount2 . publicAccount ,
398304 ] ,
399305 networkType ,
306+ maxFee
400307 ) ;
401308
402309 const removeCosigner3 = MultisigAccountModificationTransaction . create (
@@ -408,25 +315,18 @@ describe('AccountRepository', () => {
408315 cosignAccount3 . publicAccount ,
409316 ] ,
410317 networkType ,
318+ maxFee
411319 ) ;
412320
413321 const aggregateTransaction = AggregateTransaction . createComplete ( Deadline . create ( ) ,
414322 [ removeCosigner1 . toAggregate ( multisigAccount . publicAccount ) ,
415323 removeCosigner2 . toAggregate ( multisigAccount . publicAccount ) ,
416324 removeCosigner3 . toAggregate ( multisigAccount . publicAccount ) ] ,
417325 networkType ,
418- [ ] ) ;
326+ [ ] , maxFee ) ;
419327 const signedTransaction = aggregateTransaction
420328 . signTransactionWithCosignatories ( cosignAccount1 , [ cosignAccount2 , cosignAccount3 ] , generationHash ) ;
421-
422- listener . confirmed ( cosignAccount1 . address ) . subscribe ( ( ) => {
423- done ( ) ;
424- } ) ;
425- listener . status ( cosignAccount1 . address ) . subscribe ( ( error ) => {
426- console . log ( 'Error:' , error ) ;
427- done ( ) ;
428- } ) ;
429- transactionRepository . announce ( signedTransaction ) ;
329+ config . announceTransaction ( signedTransaction , done ) ;
430330 } ) ;
431331 } ) ;
432332} ) ;
0 commit comments