1515 */
1616
1717import { deepEqual } from 'assert' ;
18- import { expect } from 'chai' ;
18+ import { assert , expect } from 'chai' ;
1919import { AccountHttp } from '../../src/infrastructure/AccountHttp' ;
20+ import { Listener , TransactionHttp } from '../../src/infrastructure/infrastructure' ;
2021import { QueryParams } from '../../src/infrastructure/QueryParams' ;
22+ import { Account } from '../../src/model/account/Account' ;
2123import { Address } from '../../src/model/account/Address' ;
24+ import { PropertyModificationType } from '../../src/model/account/PropertyModificationType' ;
25+ import { PropertyType } from '../../src/model/account/PropertyType' ;
2226import { PublicAccount } from '../../src/model/account/PublicAccount' ;
2327import { NetworkType } from '../../src/model/blockchain/NetworkType' ;
28+ import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic' ;
29+ import { AccountPropertyModification } from '../../src/model/transaction/AccountPropertyModification' ;
30+ import { AccountPropertyTransaction } from '../../src/model/transaction/AccountPropertyTransaction' ;
31+ import { Deadline } from '../../src/model/transaction/Deadline' ;
32+ import { ModifyMultisigAccountTransaction } from '../../src/model/transaction/ModifyMultisigAccountTransaction' ;
33+ import { MultisigCosignatoryModification } from '../../src/model/transaction/MultisigCosignatoryModification' ;
34+ import { MultisigCosignatoryModificationType } from '../../src/model/transaction/MultisigCosignatoryModificationType' ;
35+ import { PlainMessage } from '../../src/model/transaction/PlainMessage' ;
36+ import { TransferTransaction } from '../../src/model/transaction/TransferTransaction' ;
2437
2538describe ( 'AccountHttp' , ( ) => {
39+ let account : Account ;
40+ let account2 : Account ;
41+ let account3 : Account ;
42+ let multisigAccount : Account ;
43+ let cosignAccount1 : Account ;
44+ let cosignAccount2 : Account ;
45+ let cosignAccount3 : Account ;
2646 let accountAddress : Address ;
2747 let accountPublicKey : string ;
2848 let publicAccount : PublicAccount ;
2949 let multisigPublicAccount : PublicAccount ;
3050 let accountHttp : AccountHttp ;
51+ let transactionHttp : TransactionHttp ;
52+ let config ;
3153
3254 before ( ( done ) => {
3355 const path = require ( 'path' ) ;
@@ -36,16 +58,55 @@ describe('AccountHttp', () => {
3658 throw err ;
3759 }
3860 const json = JSON . parse ( data ) ;
39-
61+ config = json ;
62+ account = Account . createFromPrivateKey ( json . testAccount . privateKey , NetworkType . MIJIN_TEST ) ;
63+ account2 = Account . createFromPrivateKey ( json . testAccount2 . privateKey , NetworkType . MIJIN_TEST ) ;
64+ account3 = Account . createFromPrivateKey ( json . testAccount3 . privateKey , NetworkType . MIJIN_TEST ) ;
65+ multisigAccount = Account . createFromPrivateKey ( json . multisigAccount . privateKey , NetworkType . MIJIN_TEST ) ;
66+ cosignAccount1 = Account . createFromPrivateKey ( json . cosignatoryAccount . privateKey , NetworkType . MIJIN_TEST ) ;
67+ cosignAccount2 = Account . createFromPrivateKey ( json . cosignatory2Account . privateKey , NetworkType . MIJIN_TEST ) ;
68+ cosignAccount3 = Account . createFromPrivateKey ( json . cosignatory3Account . privateKey , NetworkType . MIJIN_TEST ) ;
4069 accountAddress = Address . createFromRawAddress ( json . testAccount . address ) ;
4170 accountPublicKey = json . testAccount . publicKey ;
4271 publicAccount = PublicAccount . createFromPublicKey ( json . testAccount . publicKey , NetworkType . MIJIN_TEST ) ;
4372 multisigPublicAccount = PublicAccount . createFromPublicKey ( json . multisigAccount . publicKey , NetworkType . MIJIN_TEST ) ;
4473
4574 accountHttp = new AccountHttp ( json . apiUrl ) ;
75+ transactionHttp = new TransactionHttp ( json . apiUrl ) ;
4676 done ( ) ;
4777 } ) ;
4878 } ) ;
79+ describe ( 'TransferTransaction' , ( ) => {
80+ let listener : Listener ;
81+ before ( ( ) => {
82+ listener = new Listener ( config . apiUrl ) ;
83+ return listener . open ( ) ;
84+ } ) ;
85+ after ( ( ) => {
86+ return listener . close ( ) ;
87+ } ) ;
88+
89+ it ( 'standalone' , ( done ) => {
90+ const transferTransaction = TransferTransaction . create (
91+ Deadline . create ( ) ,
92+ account2 . address ,
93+ [ NetworkCurrencyMosaic . createAbsolute ( 1 ) ] ,
94+ PlainMessage . create ( 'test-message' ) ,
95+ NetworkType . MIJIN_TEST ,
96+ ) ;
97+ const signedTransaction = transferTransaction . signWith ( account ) ;
98+
99+ listener . confirmed ( account . address ) . subscribe ( ( transaction ) => {
100+ done ( ) ;
101+ } ) ;
102+ listener . status ( account . address ) . subscribe ( ( error ) => {
103+ console . log ( 'Error:' , error ) ;
104+ assert ( false ) ;
105+ done ( ) ;
106+ } ) ;
107+ transactionHttp . announce ( signedTransaction ) ;
108+ } ) ;
109+ } ) ;
49110
50111 describe ( 'getAccountInfo' , ( ) => {
51112 it ( 'should return account data given a NEM Address' , ( done ) => {
@@ -67,41 +128,148 @@ describe('AccountHttp', () => {
67128 } ) ;
68129 } ) ;
69130
70- describe ( 'getMultisigAccountInfo' , ( ) => {
71- it ( 'should call getMultisigAccountInfo successfully' , ( done ) => {
72- accountHttp . getMultisigAccountInfo ( multisigPublicAccount . address ) . subscribe ( ( multisigAccountInfo ) => {
73- expect ( multisigAccountInfo . account . publicKey ) . to . be . equal ( multisigPublicAccount . publicKey ) ;
131+ describe ( 'AccountPropertyTransaction - Address' , ( ) => {
132+ let listener : Listener ;
133+ before ( ( ) => {
134+ listener = new Listener ( config . apiUrl ) ;
135+ return listener . open ( ) ;
136+ } ) ;
137+ after ( ( ) => {
138+ return listener . close ( ) ;
139+ } ) ;
140+
141+ it ( 'add properties' , ( done ) => {
142+ const addressPropertyFilter = AccountPropertyModification . createForAddress (
143+ PropertyModificationType . Add ,
144+ account3 . address ,
145+ ) ;
146+ const addressModification = AccountPropertyTransaction . createAddressPropertyModificationTransaction (
147+ Deadline . create ( ) ,
148+ PropertyType . BlockAddress ,
149+ [ addressPropertyFilter ] ,
150+ NetworkType . MIJIN_TEST ,
151+ ) ;
152+ const signedTransaction = addressModification . signWith ( account ) ;
153+
154+ listener . confirmed ( account . address ) . subscribe ( ( transaction ) => {
74155 done ( ) ;
75156 } ) ;
157+ listener . status ( account . address ) . subscribe ( ( error ) => {
158+ console . log ( 'Error:' , error ) ;
159+ assert ( false ) ;
160+ done ( ) ;
161+ } ) ;
162+ transactionHttp . announce ( signedTransaction ) ;
76163 } ) ;
77164 } ) ;
78165
79166 describe ( 'getAccountProperty' , ( ) => {
80167 it ( 'should call getAccountProperty successfully' , ( done ) => {
81- accountHttp . getAccountProperty ( accountAddress ) . subscribe ( ( accountProperty ) => {
82- deepEqual ( accountProperty . accountProperties . address , accountAddress ) ;
83- done ( ) ;
84- } ) ;
168+ setTimeout ( ( ) => {
169+ accountHttp . getAccountProperty ( accountAddress ) . subscribe ( ( accountProperty ) => {
170+ deepEqual ( accountProperty . accountProperties . address , accountAddress ) ;
171+ done ( ) ;
172+ } ) ;
173+ } , 1000 ) ;
85174 } ) ;
86175 } ) ;
87176
88177 describe ( 'getAccountProperties' , ( ) => {
89178 it ( 'should call getAccountProperties successfully' , ( done ) => {
90- accountHttp . getAccountProperties ( [ accountAddress ] ) . subscribe ( ( accountProperties ) => {
91- deepEqual ( accountProperties [ 0 ] ! . accountProperties . address , accountAddress ) ;
179+ setTimeout ( ( ) => {
180+ accountHttp . getAccountProperties ( [ accountAddress ] ) . subscribe ( ( accountProperties ) => {
181+ deepEqual ( accountProperties [ 0 ] ! . accountProperties . address , accountAddress ) ;
182+ done ( ) ;
183+ } ) ;
184+ } ) ;
185+ } ) ;
186+ } ) ;
187+ describe ( 'AccountPropertyTransaction - Address' , ( ) => {
188+ let listener : Listener ;
189+ before ( ( ) => {
190+ listener = new Listener ( config . apiUrl ) ;
191+ return listener . open ( ) ;
192+ } ) ;
193+ after ( ( ) => {
194+ return listener . close ( ) ;
195+ } ) ;
196+
197+ it ( 'remove properties' , ( done ) => {
198+ const addressPropertyFilter = AccountPropertyModification . createForAddress (
199+ PropertyModificationType . Remove ,
200+ account3 . address ,
201+ ) ;
202+ const addressModification = AccountPropertyTransaction . createAddressPropertyModificationTransaction (
203+ Deadline . create ( ) ,
204+ PropertyType . BlockAddress ,
205+ [ addressPropertyFilter ] ,
206+ NetworkType . MIJIN_TEST ,
207+ ) ;
208+ const signedTransaction = addressModification . signWith ( account ) ;
209+
210+ listener . confirmed ( account . address ) . subscribe ( ( transaction ) => {
211+ done ( ) ;
212+ } ) ;
213+ listener . status ( account . address ) . subscribe ( ( error ) => {
214+ console . log ( 'Error:' , error ) ;
215+ assert ( false ) ;
216+ done ( ) ;
217+ } ) ;
218+ transactionHttp . announce ( signedTransaction ) ;
219+ } ) ;
220+ } ) ;
221+ describe ( 'ModifyMultisigAccountTransaction' , ( ) => {
222+ let listener : Listener ;
223+ before ( ( ) => {
224+ listener = new Listener ( config . apiUrl ) ;
225+ return listener . open ( ) ;
226+ } ) ;
227+ after ( ( ) => {
228+ return listener . close ( ) ;
229+ } ) ;
230+ it ( 'ModifyMultisigAccountTransaction' , ( done ) => {
231+ const modifyMultisigAccountTransaction = ModifyMultisigAccountTransaction . create (
232+ Deadline . create ( ) ,
233+ 2 ,
234+ 1 ,
235+ [ new MultisigCosignatoryModification ( MultisigCosignatoryModificationType . Add , cosignAccount1 . publicAccount ) ,
236+ new MultisigCosignatoryModification ( MultisigCosignatoryModificationType . Add , cosignAccount2 . publicAccount ) ,
237+ new MultisigCosignatoryModification ( MultisigCosignatoryModificationType . Add , cosignAccount3 . publicAccount ) ,
238+ ] ,
239+ NetworkType . MIJIN_TEST ,
240+ ) ;
241+ const signedTransaction = multisigAccount . sign ( modifyMultisigAccountTransaction ) ;
242+ listener . confirmed ( multisigAccount . address ) . subscribe ( ( transaction ) => {
243+ done ( ) ;
244+ } ) ;
245+ listener . status ( multisigAccount . address ) . subscribe ( ( error ) => {
246+ console . log ( 'Error:' , error ) ;
92247 done ( ) ;
93248 } ) ;
249+ transactionHttp . announce ( signedTransaction ) ;
94250 } ) ;
95251 } ) ;
96252 describe ( 'getMultisigAccountGraphInfo' , ( ) => {
97253 it ( 'should call getMultisigAccountGraphInfo successfully' , ( done ) => {
98- accountHttp . getMultisigAccountGraphInfo ( multisigPublicAccount . address ) . subscribe ( ( multisigAccountGraphInfo ) => {
99- expect ( multisigAccountGraphInfo . multisigAccounts . get ( 0 ) ! [ 0 ] . account . publicKey ) . to . be . equal ( multisigPublicAccount . publicKey ) ;
100- done ( ) ;
254+ setTimeout ( ( ) => {
255+ accountHttp . getMultisigAccountGraphInfo ( multisigPublicAccount . address ) . subscribe ( ( multisigAccountGraphInfo ) => {
256+ expect ( multisigAccountGraphInfo . multisigAccounts . get ( 0 ) ! [ 0 ] .
257+ account . publicKey ) . to . be . equal ( multisigPublicAccount . publicKey ) ;
258+ done ( ) ;
259+ } ) ;
260+ } ) ;
261+ } ) ;
262+ } ) ;
263+ describe ( 'getMultisigAccountInfo' , ( ) => {
264+ it ( 'should call getMultisigAccountInfo successfully' , ( done ) => {
265+ setTimeout ( ( ) => {
266+ accountHttp . getMultisigAccountInfo ( multisigPublicAccount . address ) . subscribe ( ( multisigAccountInfo ) => {
267+ expect ( multisigAccountInfo . account . publicKey ) . to . be . equal ( multisigPublicAccount . publicKey ) ;
268+ done ( ) ;
269+ } ) ;
101270 } ) ;
102271 } ) ;
103272 } ) ;
104-
105273 describe ( 'incomingTransactions' , ( ) => {
106274 it ( 'should call incomingTransactions successfully' , ( done ) => {
107275 accountHttp . incomingTransactions ( publicAccount ) . subscribe ( ( transactions ) => {
@@ -121,29 +289,15 @@ describe('AccountHttp', () => {
121289 done ( ) ;
122290 } ) ;
123291 } ) ;
124- // it('should call outgoingTransactions successfully pageSize 11', (done) => {
125- // accountHttp.outgoingTransactions(publicAccount, new QueryParams(22)).subscribe((transactions) => {
126- // expect(transactions.length).to.be.equal(2);
127- // nextId = transactions[10].transactionInfo!.id;
128- // lastId = transactions[11].transactionInfo!.id;
129- // done();
130- // });
131- // });
132-
133- // it('should call outgoingTransactions successfully pageSize 11 and next id', (done) => {
134- // accountHttp.outgoingTransactions(publicAccount, new QueryParams(11, nextId)).subscribe((transactions) => {
135- // expect(transactions.length).to.be.equal(2);
136- // expect(transactions[0].transactionInfo!.id).to.be.equal(lastId);
137- // done();
138- // });
139- // });
140292 } ) ;
141293
142294 describe ( 'aggregateBondedTransactions' , ( ) => {
143295 it ( 'should call aggregateBondedTransactions successfully' , ( done ) => {
144296 accountHttp . aggregateBondedTransactions ( publicAccount ) . subscribe ( ( transactions ) => {
145- expect ( transactions . length ) . to . be . equal ( 0 ) ;
146297 done ( ) ;
298+ } , ( error ) => {
299+ console . log ( 'Error:' , error ) ;
300+ assert ( false ) ;
147301 } ) ;
148302 } ) ;
149303 } ) ;
0 commit comments