@@ -20,18 +20,25 @@ import { TransactionRepository } from '../../src/infrastructure/TransactionRepos
2020import { Account } from '../../src/model/account/Account' ;
2121import { NetworkType } from '../../src/model/blockchain/NetworkType' ;
2222import { PlainMessage } from '../../src/model/message/PlainMessage' ;
23- import { Mosaic , UInt64 } from '../../src/model/model' ;
23+ import {
24+ Address ,
25+ CosignatureTransaction ,
26+ LockFundsTransaction ,
27+ Mosaic ,
28+ SignedTransaction ,
29+ UInt64
30+ } from '../../src/model/model' ;
2431import { MosaicId } from '../../src/model/mosaic/MosaicId' ;
2532import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic' ;
2633import { NamespaceId } from '../../src/model/namespace/NamespaceId' ;
2734import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction' ;
2835import { Deadline } from '../../src/model/transaction/Deadline' ;
2936import { MultisigAccountModificationTransaction } from '../../src/model/transaction/MultisigAccountModificationTransaction' ;
3037import { TransferTransaction } from '../../src/model/transaction/TransferTransaction' ;
31- import { TransactionUtils } from './TransactionUtils' ;
3238import { IntegrationTestHelper } from "./IntegrationTestHelper" ;
3339import { NamespaceRepository } from "../../src/infrastructure/NamespaceRepository" ;
3440import { filter } from "rxjs/operators" ;
41+ import { ChronoUnit } from "js-joda" ;
3542
3643describe ( 'Listener' , ( ) => {
3744
@@ -75,6 +82,42 @@ describe('Listener', () => {
7582 // cold down
7683 setTimeout ( done , 200 ) ;
7784 } ) ;
85+
86+
87+ let createSignedAggregatedBondTransaction = ( aggregatedTo : Account ,
88+ signer : Account ,
89+ recipient : Address ) : SignedTransaction => {
90+ const transferTransaction = TransferTransaction . create (
91+ Deadline . create ( ) ,
92+ recipient ,
93+ [ ] ,
94+ PlainMessage . create ( 'test-message' ) ,
95+ networkType , helper . maxFee
96+ ) ;
97+
98+ const aggregateTransaction = AggregateTransaction . createBonded (
99+ Deadline . create ( 2 , ChronoUnit . MINUTES ) ,
100+ [ transferTransaction . toAggregate ( aggregatedTo . publicAccount ) ] ,
101+ networkType ,
102+ [ ] , helper . maxFee
103+ ) ;
104+ return signer . sign ( aggregateTransaction , generationHash ) ;
105+ } ;
106+
107+ let createHashLockTransactionAndAnnounce = ( signedAggregatedTransaction : SignedTransaction ,
108+ signer : Account ,
109+ mosaicId : MosaicId ) => {
110+ const lockFundsTransaction = LockFundsTransaction . create (
111+ Deadline . create ( ) ,
112+ new Mosaic ( mosaicId , UInt64 . fromUint ( 10 * Math . pow ( 10 , NetworkCurrencyMosaic . DIVISIBILITY ) ) ) ,
113+ UInt64 . fromUint ( 1000 ) ,
114+ signedAggregatedTransaction ,
115+ networkType , helper . maxFee
116+ ) ;
117+ const signedLockFundsTransaction = signer . sign ( lockFundsTransaction , generationHash ) ;
118+ transactionRepository . announce ( signedLockFundsTransaction ) ;
119+ } ;
120+
78121 describe ( 'Confirmed' , ( ) => {
79122
80123 it ( 'confirmedTransactionsGiven address signer' , ( ) => {
@@ -150,8 +193,6 @@ describe('Listener', () => {
150193 } ) ;
151194
152195 describe ( 'TransferTransaction' , ( ) => {
153-
154-
155196 it ( 'standalone' , ( ) => {
156197 const transferTransaction = TransferTransaction . create (
157198 Deadline . create ( ) ,
@@ -200,18 +241,16 @@ describe('Listener', () => {
200241 done ( ) ;
201242 } ) ;
202243 helper . listener . confirmed ( account . address ) . subscribe ( ( ) => {
203- TransactionUtils . announceAggregateBoundedTransaction ( signedAggregatedTx , transactionRepository ) ;
244+ transactionRepository . announceAggregateBonded ( signedAggregatedTx )
204245 } ) ;
205246 helper . listener . status ( account . address ) . subscribe ( ( error ) => {
206247 console . log ( 'Error:' , error ) ;
207248 assert ( false ) ;
208249 done ( ) ;
209250 } ) ;
210- const signedAggregatedTx = TransactionUtils . createSignedAggregatedBondTransaction ( multisigAccount , account ,
211- account2 . address , generationHash ) ;
251+ const signedAggregatedTx = createSignedAggregatedBondTransaction ( multisigAccount , account , account2 . address ) ;
212252
213- TransactionUtils . createHashLockTransactionAndAnnounce ( signedAggregatedTx , account , networkCurrencyMosaicId ,
214- transactionRepository , generationHash ) ;
253+ createHashLockTransactionAndAnnounce ( signedAggregatedTx , account , networkCurrencyMosaicId ) ;
215254 } ) ;
216255 } ) ;
217256 describe ( 'Aggregate Bonded Transactions' , ( ) => {
@@ -223,26 +262,28 @@ describe('Listener', () => {
223262 helper . listener . aggregateBondedAdded ( cosignAccount1 . address ) . subscribe ( ( ) => {
224263 accountRepository . getAccountPartialTransactions ( cosignAccount1 . publicAccount . address ) . subscribe ( ( transactions ) => {
225264 const transactionToCosign = transactions [ 0 ] ;
226- TransactionUtils . cosignTransaction ( transactionToCosign , cosignAccount2 , transactionRepository ) ;
265+ const cosignatureTransaction = CosignatureTransaction . create ( transactionToCosign ) ;
266+ const cosignatureSignedTransaction = cosignAccount2 . signCosignatureTransaction ( cosignatureTransaction ) ;
267+ transactionRepository . announceAggregateBondedCosignature ( cosignatureSignedTransaction ) ;
268+
227269 } ) ;
228270 } ) ;
229271 helper . listener . status ( cosignAccount1 . address ) . subscribe ( ( error ) => {
230272 console . log ( 'Error:' , error ) ;
231273 assert ( false ) ;
232274 done ( ) ;
233275 } ) ;
234- TransactionUtils . announceAggregateBoundedTransaction ( signedAggregatedTx , transactionRepository ) ;
276+ transactionRepository . announceAggregateBonded ( signedAggregatedTx )
235277 } ) ;
236278 helper . listener . status ( cosignAccount1 . address ) . subscribe ( ( error ) => {
237279 console . log ( 'Error:' , error ) ;
238280 assert ( false ) ;
239281 done ( ) ;
240282 } ) ;
241283 const signedAggregatedTx =
242- TransactionUtils . createSignedAggregatedBondTransaction ( multisigAccount , cosignAccount1 , account2 . address , generationHash ) ;
284+ createSignedAggregatedBondTransaction ( multisigAccount , cosignAccount1 , account2 . address ) ;
243285
244- TransactionUtils . createHashLockTransactionAndAnnounce ( signedAggregatedTx , cosignAccount1 ,
245- networkCurrencyMosaicId , transactionRepository , generationHash ) ;
286+ createHashLockTransactionAndAnnounce ( signedAggregatedTx , cosignAccount1 , networkCurrencyMosaicId ) ;
246287 } ) ;
247288 } ) ;
248289
@@ -255,22 +296,23 @@ describe('Listener', () => {
255296 helper . listener . aggregateBondedAdded ( cosignAccount1 . address ) . subscribe ( ( ) => {
256297 accountRepository . getAccountPartialTransactions ( cosignAccount1 . publicAccount . address ) . subscribe ( ( transactions ) => {
257298 const transactionToCosign = transactions [ 0 ] ;
258- TransactionUtils . cosignTransaction ( transactionToCosign , cosignAccount2 , transactionRepository ) ;
299+ const cosignatureTransaction = CosignatureTransaction . create ( transactionToCosign ) ;
300+ const cosignatureSignedTransaction = cosignAccount2 . signCosignatureTransaction ( cosignatureTransaction ) ;
301+ transactionRepository . announceAggregateBondedCosignature ( cosignatureSignedTransaction ) ;
259302 } ) ;
260303 } ) ;
261304 helper . listener . confirmed ( cosignAccount1 . address ) . subscribe ( ( ) => {
262- TransactionUtils . announceAggregateBoundedTransaction ( signedAggregatedTx , transactionRepository ) ;
305+ transactionRepository . announceAggregateBonded ( signedAggregatedTx )
263306 } ) ;
264307 helper . listener . status ( cosignAccount1 . address ) . subscribe ( ( error ) => {
265308 console . log ( 'Error:' , error ) ;
266309 assert ( false ) ;
267310 done ( ) ;
268311 } ) ;
269312 const signedAggregatedTx =
270- TransactionUtils . createSignedAggregatedBondTransaction ( multisigAccount , cosignAccount1 , account2 . address , generationHash ) ;
313+ createSignedAggregatedBondTransaction ( multisigAccount , cosignAccount1 , account2 . address ) ;
271314
272- TransactionUtils . createHashLockTransactionAndAnnounce ( signedAggregatedTx , cosignAccount1 ,
273- networkCurrencyMosaicId , transactionRepository , generationHash ) ;
315+ createHashLockTransactionAndAnnounce ( signedAggregatedTx , cosignAccount1 , networkCurrencyMosaicId ) ;
274316 } ) ;
275317 } ) ;
276318
@@ -317,13 +359,21 @@ describe('Listener', () => {
317359
318360 describe ( 'Transactions Status' , ( ) => {
319361
320- it ( 'transactionStatusGiven' , ( done ) => {
321- helper . listener . status ( account . address ) . subscribe ( ( error ) => {
362+ it ( 'transactionStatusGiven' , ( ) => {
363+ const mosaics = [ NetworkCurrencyMosaic . createRelative ( 1000000000000 ) ] ;
364+ const transferTransaction = TransferTransaction . create (
365+ Deadline . create ( ) ,
366+ account2 . address ,
367+ mosaics ,
368+ PlainMessage . create ( 'test-message' ) ,
369+ networkType , helper . maxFee
370+ ) ;
371+
372+ return helper . announce ( transferTransaction . signWith ( account , generationHash ) ) . then ( ( ) => {
373+ throw new Error ( "Transaction should have failed!!" ) ;
374+ } , error => {
322375 expect ( error . status ) . to . be . equal ( 'Failure_Core_Insufficient_Balance' ) ;
323- done ( ) ;
324376 } ) ;
325- const mosaics = [ NetworkCurrencyMosaic . createRelative ( 1000000000000 ) ] ;
326- TransactionUtils . createAndAnnounce ( account , account2 . address , transactionRepository , mosaics , generationHash ) ;
327377 } ) ;
328378 } ) ;
329379
@@ -333,7 +383,15 @@ describe('Listener', () => {
333383 helper . listener . newBlock ( ) . subscribe ( ( ) => {
334384 done ( ) ;
335385 } ) ;
336- TransactionUtils . createAndAnnounce ( account , account . address , transactionRepository , undefined , generationHash ) ;
386+ const transferTransaction = TransferTransaction . create (
387+ Deadline . create ( ) ,
388+ account2 . address ,
389+ [ ] ,
390+ PlainMessage . create ( 'test-message' ) ,
391+ networkType , helper . maxFee
392+ ) ;
393+
394+ helper . announce ( transferTransaction . signWith ( account , generationHash ) ) ;
337395 } ) ;
338396 } ) ;
339397} ) ;
0 commit comments