1414 * limitations under the License.
1515 */
1616
17- import { expect } from 'chai' ;
17+ import { assert , expect } from 'chai' ;
1818import { BlockHttp } from '../../src/infrastructure/BlockHttp' ;
19+ import { Listener , TransactionHttp } from '../../src/infrastructure/infrastructure' ;
1920import { QueryParams } from '../../src/infrastructure/QueryParams' ;
21+ import { Account } from '../../src/model/account/Account' ;
22+ import { NetworkType } from '../../src/model/blockchain/NetworkType' ;
23+ import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic' ;
24+ import { Deadline } from '../../src/model/transaction/Deadline' ;
25+ import { PlainMessage } from '../../src/model/transaction/PlainMessage' ;
26+ import { Transaction } from '../../src/model/transaction/Transaction' ;
27+ import { TransferTransaction } from '../../src/model/transaction/TransferTransaction' ;
2028
2129describe ( 'BlockHttp' , ( ) => {
30+ let account : Account ;
31+ let account2 : Account ;
2232 let blockHttp : BlockHttp ;
33+ let transactionHttp : TransactionHttp ;
2334 let blockReceiptHash = '' ;
2435 let blockTransactionHash = '' ;
36+ let config ;
37+ let chainHeight ;
2538 before ( ( done ) => {
2639 const path = require ( 'path' ) ;
2740 require ( 'fs' ) . readFile ( path . resolve ( __dirname , '../conf/network.conf' ) , ( err , data ) => {
2841 if ( err ) {
2942 throw err ;
3043 }
3144 const json = JSON . parse ( data ) ;
45+ config = json ;
46+ account = Account . createFromPrivateKey ( json . testAccount . privateKey , NetworkType . MIJIN_TEST ) ;
47+ account2 = Account . createFromPrivateKey ( json . testAccount2 . privateKey , NetworkType . MIJIN_TEST ) ;
3248 blockHttp = new BlockHttp ( json . apiUrl ) ;
49+ transactionHttp = new TransactionHttp ( json . apiUrl ) ;
3350 done ( ) ;
3451 } ) ;
3552 } ) ;
53+
54+ describe ( 'Setup test data' , ( ) => {
55+ let listener : Listener ;
56+ before ( ( ) => {
57+ listener = new Listener ( config . apiUrl ) ;
58+ return listener . open ( ) ;
59+ } ) ;
60+ after ( ( ) => {
61+ return listener . close ( ) ;
62+ } ) ;
63+
64+ it ( 'standalone' , ( done ) => {
65+ const transferTransaction = TransferTransaction . create (
66+ Deadline . create ( ) ,
67+ account2 . address ,
68+ [ NetworkCurrencyMosaic . createAbsolute ( 1 ) ] ,
69+ PlainMessage . create ( 'test-message' ) ,
70+ NetworkType . MIJIN_TEST ,
71+ ) ;
72+ const signedTransaction = transferTransaction . signWith ( account ) ;
73+
74+ listener . confirmed ( account . address ) . subscribe ( ( transaction : Transaction ) => {
75+
76+ chainHeight = transaction . transactionInfo ! . height . lower ;
77+ console . log ( `Test chain height: ${ chainHeight } ` ) ;
78+ done ( ) ;
79+ } ) ;
80+ listener . status ( account . address ) . subscribe ( ( error ) => {
81+ console . log ( 'Error:' , error ) ;
82+ assert ( false ) ;
83+ done ( ) ;
84+ } ) ;
85+ transactionHttp . announce ( signedTransaction ) ;
86+ } ) ;
87+ } ) ;
88+
3689 describe ( 'getBlockByHeight' , ( ) => {
3790 it ( 'should return block info given height' , ( done ) => {
3891 blockHttp . getBlockByHeight ( 1 )
@@ -74,7 +127,7 @@ describe('BlockHttp', () => {
74127
75128 describe ( 'getBlocksByHeightWithLimit' , ( ) => {
76129 it ( 'should return block info given height and limit' , ( done ) => {
77- blockHttp . getBlocksByHeightWithLimit ( 1 , 50 )
130+ blockHttp . getBlocksByHeightWithLimit ( chainHeight , 50 )
78131 . subscribe ( ( blocksInfo ) => {
79132 expect ( blocksInfo . length ) . to . be . greaterThan ( 0 ) ;
80133 done ( ) ;
@@ -83,7 +136,7 @@ describe('BlockHttp', () => {
83136 } ) ;
84137 describe ( 'getMerkleReceipts' , ( ) => {
85138 it ( 'should return Merkle Receipts' , ( done ) => {
86- blockHttp . getMerkleReceipts ( 1 , blockReceiptHash )
139+ blockHttp . getMerkleReceipts ( chainHeight , blockReceiptHash )
87140 . subscribe ( ( merkleReceipts ) => {
88141 expect ( merkleReceipts . type ) . not . to . be . null ;
89142 expect ( merkleReceipts . payload ) . not . to . be . null ;
@@ -93,7 +146,7 @@ describe('BlockHttp', () => {
93146 } ) ;
94147 describe ( 'getMerkleTransaction' , ( ) => {
95148 it ( 'should return Merkle Transaction' , ( done ) => {
96- blockHttp . getMerkleTransaction ( 1 , blockTransactionHash )
149+ blockHttp . getMerkleTransaction ( chainHeight , blockTransactionHash )
97150 . subscribe ( ( merkleTransactionss ) => {
98151 expect ( merkleTransactionss . type ) . not . to . be . null ;
99152 expect ( merkleTransactionss . payload ) . not . to . be . null ;
@@ -102,14 +155,15 @@ describe('BlockHttp', () => {
102155 } ) ;
103156 } ) ;
104157
105- // describe('getBlockReceipts', () => {
106- // it('should return block receipts', (done) => {
107- // blockHttp.(1, '')
108- // .subscribe((merkleTransactionss) => {
109- // expect(merkleTransactionss.type).not.to.be.null;
110- // expect(merkleTransactionss.payload).not.to.be.null;
111- // done();
112- // });
113- // });
114- // });
158+ describe ( 'getBlockReceipts' , ( ) => {
159+ it ( 'should return block receipts' , ( done ) => {
160+ blockHttp . getBlockReceipts ( chainHeight )
161+ . subscribe ( ( statement ) => {
162+ console . log ( statement ) ;
163+ expect ( statement . transactionStatements ) . not . to . be . null ;
164+ expect ( statement . transactionStatements . length ) . to . be . greaterThan ( 0 ) ;
165+ done ( ) ;
166+ } ) ;
167+ } ) ;
168+ } ) ;
115169} ) ;
0 commit comments