14
14
* limitations under the License.
15
15
*/
16
16
17
- import { assert , expect } from 'chai' ;
17
+ import { expect } from 'chai' ;
18
18
import { 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' ;
22
21
import { Account } from '../../src/model/account/Account' ;
23
22
import { NetworkType } from '../../src/model/blockchain/NetworkType' ;
24
23
import { PlainMessage } from '../../src/model/message/PlainMessage' ;
25
24
import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic' ;
26
25
import { Deadline } from '../../src/model/transaction/Deadline' ;
27
- import { Transaction } from '../../src/model/transaction/Transaction' ;
28
26
import { TransactionInfo } from '../../src/model/transaction/TransactionInfo' ;
29
27
import { 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" ;
30
31
31
32
describe ( 'BlockHttp' , ( ) => {
33
+ let helper = new IntegrationTestHelper ( ) ;
32
34
let account : Account ;
33
35
let account2 : Account ;
34
- let blockHttp : BlockHttp ;
35
- let receiptHttp : ReceiptHttp ;
36
- let transactionHttp : TransactionHttp ;
36
+ let blockRepository : BlockRepository ;
37
+ let receiptRepository : ReceiptRepository ;
37
38
let blockReceiptHash = '' ;
38
39
let blockTransactionHash = '' ;
39
- let config ;
40
40
let chainHeight ;
41
41
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 ( ) ;
57
52
} ) ;
58
53
} ) ;
59
54
55
+ before ( ( ) => {
56
+ return helper . listener . open ( ) ;
57
+ } ) ;
58
+
59
+ after ( ( ) => {
60
+ helper . listener . close ( ) ;
61
+ } ) ;
62
+
60
63
/**
61
64
* =========================
62
65
* Setup Test Data
63
66
* =========================
64
67
*/
65
68
66
69
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
+
75
71
76
72
it ( 'Announce TransferTransaction' , ( done ) => {
77
73
const transferTransaction = TransferTransaction . create (
78
74
Deadline . create ( ) ,
79
75
account2 . address ,
80
76
[ NetworkCurrencyMosaic . createAbsolute ( 1 ) ] ,
81
77
PlainMessage . create ( 'test-message' ) ,
82
- NetworkType . MIJIN_TEST ,
78
+ networkType ,
79
+ helper . maxFee
83
80
) ;
84
81
const signedTransaction = transferTransaction . signWith ( account , generationHash ) ;
85
-
86
- listener . confirmed ( account . address ) . subscribe ( ( transaction : Transaction ) => {
82
+ helper . announce ( signedTransaction ) . then ( transaction => {
87
83
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 ;
94
85
} ) ;
95
- transactionHttp . announce ( signedTransaction ) ;
96
86
} ) ;
97
87
} ) ;
98
88
99
89
describe ( 'getBlockByHeight' , ( ) => {
100
90
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
+ } ) ;
111
101
} ) ;
112
102
} ) ;
113
103
@@ -116,39 +106,39 @@ describe('BlockHttp', () => {
116
106
let firstId : string ;
117
107
118
108
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
+ } ) ;
126
116
} ) ;
127
117
128
118
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
+ } ) ;
135
125
} ) ;
136
126
} ) ;
137
127
138
128
describe ( 'getBlocksByHeightWithLimit' , ( ) => {
139
129
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
+ } ) ;
145
135
} ) ;
146
136
} ) ;
147
137
describe ( 'getMerkleReceipts' , ( ) => {
148
138
it ( 'should return Merkle Receipts' , ( done ) => {
149
- receiptHttp . getBlockReceipts ( chainHeight ) . pipe (
139
+ receiptRepository . getBlockReceipts ( chainHeight ) . pipe (
150
140
mergeMap ( ( _ ) => {
151
- return receiptHttp . getMerkleReceipts ( chainHeight , _ . transactionStatements [ 0 ] . generateHash ( ) ) ;
141
+ return receiptRepository . getMerkleReceipts ( chainHeight , _ . transactionStatements [ 0 ] . generateHash ( ) ) ;
152
142
} ) )
153
143
. subscribe ( ( merkleReceipts ) => {
154
144
expect ( merkleReceipts . merklePath ) . not . to . be . null ;
@@ -158,30 +148,30 @@ describe('BlockHttp', () => {
158
148
} ) ;
159
149
describe ( 'getMerkleTransaction' , ( ) => {
160
150
it ( 'should return Merkle Transaction' , ( done ) => {
161
- blockHttp . getBlockTransactions ( chainHeight ) . pipe (
151
+ blockRepository . getBlockTransactions ( chainHeight ) . pipe (
162
152
mergeMap ( ( _ ) => {
163
153
const hash = ( _ [ 0 ] . transactionInfo as TransactionInfo ) . hash ;
164
154
if ( hash ) {
165
- return blockHttp . getMerkleTransaction ( chainHeight , hash ) ;
155
+ return blockRepository . getMerkleTransaction ( chainHeight , hash ) ;
166
156
}
167
157
// If reaching this line, something is not right
168
158
throw new Error ( 'Tansacation hash is undefined' ) ;
169
159
} ) )
170
160
. subscribe ( ( merkleTransactionss ) => {
171
- expect ( merkleTransactionss . merklePath ) . not . to . be . null ;
172
- done ( ) ;
173
- } ) ;
161
+ expect ( merkleTransactionss . merklePath ) . not . to . be . null ;
162
+ done ( ) ;
163
+ } ) ;
174
164
} ) ;
175
165
} ) ;
176
166
177
167
describe ( 'getBlockReceipts' , ( ) => {
178
168
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
+ } ) ;
185
175
} ) ;
186
176
} ) ;
187
177
} ) ;
0 commit comments