1414 * limitations under the License.
1515 */
1616
17- import { assert , expect } from 'chai' ;
17+ import { expect } from 'chai' ;
1818import { mergeMap } from 'rxjs/operators' ;
19- import { BlockHttp } from '../../src/infrastructure/BlockHttp' ;
20- import { Listener , ReceiptHttp , TransactionHttp } from '../../src/infrastructure/infrastructure' ;
21- import { QueryParams } from '../../src/infrastructure/QueryParams' ;
19+ import { BlockHttp } from '../../src/infrastructure/BlockHttp' ;
20+ import { QueryParams } from '../../src/infrastructure/QueryParams' ;
2221import { Account } from '../../src/model/account/Account' ;
2322import { NetworkType } from '../../src/model/blockchain/NetworkType' ;
2423import { PlainMessage } from '../../src/model/message/PlainMessage' ;
2524import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic' ;
2625import { Deadline } from '../../src/model/transaction/Deadline' ;
27- import { Transaction } from '../../src/model/transaction/Transaction' ;
2826import { TransactionInfo } from '../../src/model/transaction/TransactionInfo' ;
2927import { TransferTransaction } from '../../src/model/transaction/TransferTransaction' ;
28+ import { IntegrationTestHelper } from "./IntegrationTestHelper" ;
29+ import { BlockRepository } from "../../src/infrastructure/BlockRepository" ;
30+ import { ReceiptRepository } from "../../src/infrastructure/ReceiptRepository" ;
3031
3132describe ( 'BlockHttp' , ( ) => {
33+ let helper = new IntegrationTestHelper ( ) ;
3234 let account : Account ;
3335 let account2 : Account ;
34- let blockHttp : BlockHttp ;
35- let receiptHttp : ReceiptHttp ;
36- let transactionHttp : TransactionHttp ;
36+ let blockRepository : BlockRepository ;
37+ let receiptRepository : ReceiptRepository ;
3738 let blockReceiptHash = '' ;
3839 let blockTransactionHash = '' ;
39- let config ;
4040 let chainHeight ;
4141 let generationHash : string ;
42- before ( ( done ) => {
43- const path = require ( 'path' ) ;
44- require ( 'fs' ) . readFile ( path . resolve ( __dirname , '../conf/network.conf' ) , ( err , data ) => {
45- if ( err ) {
46- throw err ;
47- }
48- const json = JSON . parse ( data ) ;
49- config = json ;
50- account = Account . createFromPrivateKey ( json . testAccount . privateKey , NetworkType . MIJIN_TEST ) ;
51- account2 = Account . createFromPrivateKey ( json . testAccount2 . privateKey , NetworkType . MIJIN_TEST ) ;
52- blockHttp = new BlockHttp ( json . apiUrl ) ;
53- transactionHttp = new TransactionHttp ( json . apiUrl ) ;
54- receiptHttp = new ReceiptHttp ( json . apiUrl ) ;
55- generationHash = json . generationHash ;
56- done ( ) ;
42+ let networkType : NetworkType ;
43+
44+ before ( ( ) => {
45+ return helper . start ( ) . then ( ( ) => {
46+ account = helper . account ;
47+ account2 = helper . account2 ;
48+ generationHash = helper . generationHash ;
49+ networkType = helper . networkType ;
50+ blockRepository = helper . repositoryFactory . createBlockRepository ( ) ;
51+ receiptRepository = helper . repositoryFactory . createReceiptRepository ( ) ;
5752 } ) ;
5853 } ) ;
5954
55+ before ( ( ) => {
56+ return helper . listener . open ( ) ;
57+ } ) ;
58+
59+ after ( ( ) => {
60+ helper . listener . close ( ) ;
61+ } ) ;
62+
6063 /**
6164 * =========================
6265 * Setup Test Data
6366 * =========================
6467 */
6568
6669 describe ( 'Setup Test Data' , ( ) => {
67- let listener : Listener ;
68- before ( ( ) => {
69- listener = new Listener ( config . apiUrl ) ;
70- return listener . open ( ) ;
71- } ) ;
72- after ( ( ) => {
73- return listener . close ( ) ;
74- } ) ;
70+
7571
7672 it ( 'Announce TransferTransaction' , ( done ) => {
7773 const transferTransaction = TransferTransaction . create (
7874 Deadline . create ( ) ,
7975 account2 . address ,
8076 [ NetworkCurrencyMosaic . createAbsolute ( 1 ) ] ,
8177 PlainMessage . create ( 'test-message' ) ,
82- NetworkType . MIJIN_TEST ,
78+ networkType ,
79+ helper . maxFee
8380 ) ;
8481 const signedTransaction = transferTransaction . signWith ( account , generationHash ) ;
85-
86- listener . confirmed ( account . address ) . subscribe ( ( transaction : Transaction ) => {
82+ helper . announce ( signedTransaction ) . then ( transaction => {
8783 chainHeight = transaction . transactionInfo ! . height . toString ( ) ;
88- done ( ) ;
89- } ) ;
90- listener . status ( account . address ) . subscribe ( ( error ) => {
91- console . log ( 'Error:' , error ) ;
92- assert ( false ) ;
93- done ( ) ;
84+ return transaction ;
9485 } ) ;
95- transactionHttp . announce ( signedTransaction ) ;
9686 } ) ;
9787 } ) ;
9888
9989 describe ( 'getBlockByHeight' , ( ) => {
10090 it ( 'should return block info given height' , ( done ) => {
101- blockHttp . getBlockByHeight ( '1' )
102- . subscribe ( ( blockInfo ) => {
103- blockReceiptHash = blockInfo . blockReceiptsHash ;
104- blockTransactionHash = blockInfo . blockTransactionsHash ;
105- expect ( blockInfo . height . lower ) . to . be . equal ( 1 ) ;
106- expect ( blockInfo . height . higher ) . to . be . equal ( 0 ) ;
107- expect ( blockInfo . timestamp . lower ) . to . be . equal ( 0 ) ;
108- expect ( blockInfo . timestamp . higher ) . to . be . equal ( 0 ) ;
109- done ( ) ;
110- } ) ;
91+ blockRepository . getBlockByHeight ( '1' )
92+ . subscribe ( ( blockInfo ) => {
93+ blockReceiptHash = blockInfo . blockReceiptsHash ;
94+ blockTransactionHash = blockInfo . blockTransactionsHash ;
95+ expect ( blockInfo . height . lower ) . to . be . equal ( 1 ) ;
96+ expect ( blockInfo . height . higher ) . to . be . equal ( 0 ) ;
97+ expect ( blockInfo . timestamp . lower ) . to . be . equal ( 0 ) ;
98+ expect ( blockInfo . timestamp . higher ) . to . be . equal ( 0 ) ;
99+ done ( ) ;
100+ } ) ;
111101 } ) ;
112102 } ) ;
113103
@@ -116,39 +106,39 @@ describe('BlockHttp', () => {
116106 let firstId : string ;
117107
118108 it ( 'should return block transactions data given height' , ( done ) => {
119- blockHttp . getBlockTransactions ( '1' )
120- . subscribe ( ( transactions ) => {
121- nextId = transactions [ 0 ] . transactionInfo ! . id ;
122- firstId = transactions [ 1 ] . transactionInfo ! . id ;
123- expect ( transactions . length ) . to . be . greaterThan ( 0 ) ;
124- done ( ) ;
125- } ) ;
109+ blockRepository . getBlockTransactions ( '1' )
110+ . subscribe ( ( transactions ) => {
111+ nextId = transactions [ 0 ] . transactionInfo ! . id ;
112+ firstId = transactions [ 1 ] . transactionInfo ! . id ;
113+ expect ( transactions . length ) . to . be . greaterThan ( 0 ) ;
114+ done ( ) ;
115+ } ) ;
126116 } ) ;
127117
128118 it ( 'should return block transactions data given height with paginated transactionId' , ( done ) => {
129- blockHttp . getBlockTransactions ( '1' , new QueryParams ( 10 , nextId ) )
130- . subscribe ( ( transactions ) => {
131- expect ( transactions [ 0 ] . transactionInfo ! . id ) . to . be . equal ( firstId ) ;
132- expect ( transactions . length ) . to . be . greaterThan ( 0 ) ;
133- done ( ) ;
134- } ) ;
119+ blockRepository . getBlockTransactions ( '1' , new QueryParams ( 10 , nextId ) )
120+ . subscribe ( ( transactions ) => {
121+ expect ( transactions [ 0 ] . transactionInfo ! . id ) . to . be . equal ( firstId ) ;
122+ expect ( transactions . length ) . to . be . greaterThan ( 0 ) ;
123+ done ( ) ;
124+ } ) ;
135125 } ) ;
136126 } ) ;
137127
138128 describe ( 'getBlocksByHeightWithLimit' , ( ) => {
139129 it ( 'should return block info given height and limit' , ( done ) => {
140- blockHttp . getBlocksByHeightWithLimit ( chainHeight , 50 )
141- . subscribe ( ( blocksInfo ) => {
142- expect ( blocksInfo . length ) . to . be . greaterThan ( 0 ) ;
143- done ( ) ;
144- } ) ;
130+ blockRepository . getBlocksByHeightWithLimit ( chainHeight , 50 )
131+ . subscribe ( ( blocksInfo ) => {
132+ expect ( blocksInfo . length ) . to . be . greaterThan ( 0 ) ;
133+ done ( ) ;
134+ } ) ;
145135 } ) ;
146136 } ) ;
147137 describe ( 'getMerkleReceipts' , ( ) => {
148138 it ( 'should return Merkle Receipts' , ( done ) => {
149- receiptHttp . getBlockReceipts ( chainHeight ) . pipe (
139+ receiptRepository . getBlockReceipts ( chainHeight ) . pipe (
150140 mergeMap ( ( _ ) => {
151- return receiptHttp . getMerkleReceipts ( chainHeight , _ . transactionStatements [ 0 ] . generateHash ( ) ) ;
141+ return receiptRepository . getMerkleReceipts ( chainHeight , _ . transactionStatements [ 0 ] . generateHash ( ) ) ;
152142 } ) )
153143 . subscribe ( ( merkleReceipts ) => {
154144 expect ( merkleReceipts . merklePath ) . not . to . be . null ;
@@ -158,30 +148,30 @@ describe('BlockHttp', () => {
158148 } ) ;
159149 describe ( 'getMerkleTransaction' , ( ) => {
160150 it ( 'should return Merkle Transaction' , ( done ) => {
161- blockHttp . getBlockTransactions ( chainHeight ) . pipe (
151+ blockRepository . getBlockTransactions ( chainHeight ) . pipe (
162152 mergeMap ( ( _ ) => {
163153 const hash = ( _ [ 0 ] . transactionInfo as TransactionInfo ) . hash ;
164154 if ( hash ) {
165- return blockHttp . getMerkleTransaction ( chainHeight , hash ) ;
155+ return blockRepository . getMerkleTransaction ( chainHeight , hash ) ;
166156 }
167157 // If reaching this line, something is not right
168158 throw new Error ( 'Tansacation hash is undefined' ) ;
169159 } ) )
170160 . subscribe ( ( merkleTransactionss ) => {
171- expect ( merkleTransactionss . merklePath ) . not . to . be . null ;
172- done ( ) ;
173- } ) ;
161+ expect ( merkleTransactionss . merklePath ) . not . to . be . null ;
162+ done ( ) ;
163+ } ) ;
174164 } ) ;
175165 } ) ;
176166
177167 describe ( 'getBlockReceipts' , ( ) => {
178168 it ( 'should return block receipts' , ( done ) => {
179- receiptHttp . getBlockReceipts ( chainHeight )
180- . subscribe ( ( statement ) => {
181- expect ( statement . transactionStatements ) . not . to . be . null ;
182- expect ( statement . transactionStatements . length ) . to . be . greaterThan ( 0 ) ;
183- done ( ) ;
184- } ) ;
169+ receiptRepository . getBlockReceipts ( chainHeight )
170+ . subscribe ( ( statement ) => {
171+ expect ( statement . transactionStatements ) . not . to . be . null ;
172+ expect ( statement . transactionStatements . length ) . to . be . greaterThan ( 0 ) ;
173+ done ( ) ;
174+ } ) ;
185175 } ) ;
186176 } ) ;
187177} ) ;
0 commit comments