1616
1717import { expect } from 'chai' ;
1818import { Listener } from '../../src/infrastructure/Listener' ;
19+ import { NamespaceHttp } from '../../src/infrastructure/NamespaceHttp' ;
1920import { TransactionHttp } from '../../src/infrastructure/TransactionHttp' ;
2021import { Account } from '../../src/model/account/Account' ;
2122import { Address } from '../../src/model/account/Address' ;
2223import { NetworkType } from '../../src/model/blockchain/NetworkType' ;
2324import { PlainMessage } from '../../src/model/message/PlainMessage' ;
25+ import { Mosaic } from '../../src/model/mosaic/Mosaic' ;
26+ import { MosaicId } from '../../src/model/mosaic/MosaicId' ;
2427import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic' ;
28+ import { NamespaceId } from '../../src/model/namespace/NamespaceId' ;
2529import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction' ;
2630import { Deadline } from '../../src/model/transaction/Deadline' ;
31+ import { LockFundsTransaction } from '../../src/model/transaction/LockFundsTransaction' ;
2732import { MultisigAccountModificationTransaction } from '../../src/model/transaction/MultisigAccountModificationTransaction' ;
33+ import { TransactionType } from '../../src/model/transaction/TransactionType' ;
2834import { TransferTransaction } from '../../src/model/transaction/TransferTransaction' ;
35+ import { UInt64 } from '../../src/model/UInt64' ;
2936import { TransactionService } from '../../src/service/TransactionService' ;
37+ import { TransactionUtils } from '../infrastructure/TransactionUtils' ;
3038
3139describe ( 'TransactionService' , ( ) => {
3240 let account : Account ;
@@ -35,9 +43,12 @@ describe('TransactionService', () => {
3543 let cosignAccount1 : Account ;
3644 let cosignAccount2 : Account ;
3745 let cosignAccount3 : Account ;
46+ let networkCurrencyMosaicId : MosaicId ;
3847 let url : string ;
3948 let generationHash : string ;
4049 let transactionHttp : TransactionHttp ;
50+ let transactionService : TransactionService ;
51+ let namespaceHttp : NamespaceHttp ;
4152 let config ;
4253
4354 before ( ( done ) => {
@@ -56,7 +67,9 @@ describe('TransactionService', () => {
5667 cosignAccount3 = Account . createFromPrivateKey ( json . cosignatory3Account . privateKey , NetworkType . MIJIN_TEST ) ;
5768 url = json . apiUrl ;
5869 generationHash = json . generationHash ;
59- transactionHttp = new TransactionHttp ( json . apiUrl ) ;
70+ transactionHttp = new TransactionHttp ( url ) ;
71+ namespaceHttp = new NamespaceHttp ( url ) ;
72+ transactionService = new TransactionService ( url ) ;
6073 done ( ) ;
6174 } ) ;
6275 } ) ;
@@ -66,6 +79,15 @@ describe('TransactionService', () => {
6679 * Setup test data
6780 * =========================
6881 */
82+ describe ( 'Get network currency mosaic id' , ( ) => {
83+ it ( 'get mosaicId' , ( done ) => {
84+ namespaceHttp . getLinkedMosaicId ( new NamespaceId ( 'cat.currency' ) ) . subscribe ( ( networkMosaicId ) => {
85+ networkCurrencyMosaicId = networkMosaicId ;
86+ done ( ) ;
87+ } ) ;
88+ } ) ;
89+ } ) ;
90+
6991 describe ( 'Setup test multisig account' , ( ) => {
7092 let listener : Listener ;
7193 before ( ( ) => {
@@ -123,7 +145,6 @@ describe('TransactionService', () => {
123145 return listener . close ( ) ;
124146 } ) ;
125147 it ( 'announce' , ( done ) => {
126- const transactionService = new TransactionService ( url ) ;
127148 const transferTransaction = TransferTransaction . create (
128149 Deadline . create ( ) ,
129150 account2 . address ,
@@ -143,6 +164,65 @@ describe('TransactionService', () => {
143164 } ) ;
144165 } ) ;
145166
167+ describe ( 'should announce aggregate bonded with hashlock' , ( ) => {
168+ let listener : Listener ;
169+ before ( ( ) => {
170+ listener = new Listener ( config . apiUrl ) ;
171+ return listener . open ( ) ;
172+ } ) ;
173+ after ( ( ) => {
174+ return listener . close ( ) ;
175+ } ) ;
176+ it ( 'announce' , ( done ) => {
177+ const signedAggregatedTransaction =
178+ TransactionUtils . createSignedAggregatedBondTransaction ( multisigAccount , account , account2 . address , generationHash ) ;
179+ const lockFundsTransaction = LockFundsTransaction . create (
180+ Deadline . create ( ) ,
181+ new Mosaic ( networkCurrencyMosaicId , UInt64 . fromUint ( 10 * Math . pow ( 10 , NetworkCurrencyMosaic . DIVISIBILITY ) ) ) ,
182+ UInt64 . fromUint ( 1000 ) ,
183+ signedAggregatedTransaction ,
184+ NetworkType . MIJIN_TEST ,
185+ ) ;
186+ const signedLockFundsTransaction = lockFundsTransaction . signWith ( account , generationHash ) ;
187+ transactionService
188+ . announceHashLockAggregateBonded ( signedLockFundsTransaction , signedAggregatedTransaction , listener ) . subscribe ( ( tx ) => {
189+ expect ( tx . signer ! . publicKey ) . to . be . equal ( account . publicKey ) ;
190+ expect ( tx . type ) . to . be . equal ( TransactionType . AGGREGATE_BONDED ) ;
191+ done ( ) ;
192+ } ) ;
193+ } ) ;
194+ } ) ;
195+
196+ describe ( 'should announce aggregate bonded transaction' , ( ) => {
197+ let listener : Listener ;
198+ before ( ( ) => {
199+ listener = new Listener ( config . apiUrl ) ;
200+ return listener . open ( ) ;
201+ } ) ;
202+ after ( ( ) => {
203+ return listener . close ( ) ;
204+ } ) ;
205+ it ( 'announce' , ( done ) => {
206+ const signedAggregatedTransaction =
207+ TransactionUtils . createSignedAggregatedBondTransaction ( multisigAccount , account , account2 . address , generationHash ) ;
208+ const lockFundsTransaction = LockFundsTransaction . create (
209+ Deadline . create ( ) ,
210+ new Mosaic ( networkCurrencyMosaicId , UInt64 . fromUint ( 10 * Math . pow ( 10 , NetworkCurrencyMosaic . DIVISIBILITY ) ) ) ,
211+ UInt64 . fromUint ( 1000 ) ,
212+ signedAggregatedTransaction ,
213+ NetworkType . MIJIN_TEST ,
214+ ) ;
215+ const signedLockFundsTransaction = lockFundsTransaction . signWith ( account , generationHash ) ;
216+ transactionService . announce ( signedLockFundsTransaction , listener ) . subscribe ( ( ) => {
217+ transactionService . announceAggregateBonded ( signedAggregatedTransaction , listener ) . subscribe ( ( tx ) => {
218+ expect ( tx . signer ! . publicKey ) . to . be . equal ( account . publicKey ) ;
219+ expect ( tx . type ) . to . be . equal ( TransactionType . AGGREGATE_BONDED ) ;
220+ done ( ) ;
221+ } ) ;
222+ } ) ;
223+ } ) ;
224+ } ) ;
225+
146226 /**
147227 * =========================
148228 * House Keeping
0 commit comments