@@ -5,76 +5,78 @@ const assert = chai.assert
55
66const fs = require ( 'fs' )
77
8- const config = require ( './config' )
8+ const { servers } = require ( './config' )
99
1010describe ( 'ElectrumClient' , async ( ) => {
1111 let txData
1212
1313 before ( async ( ) => {
14- txData = JSON . parse ( await fs . readFileSync ( './test/tx.json' , 'utf8' ) )
14+ txData = JSON . parse ( fs . readFileSync ( './test/tx.json' , 'utf8' ) )
1515 } )
1616
17- context ( 'when connected' , async ( ) => {
18- config . serversArray . forEach ( ( server ) => {
19- describe ( `for ${ server . protocol } protocol` , async ( ) => {
20- let client
17+ describe ( 'for all protocols' , async ( ) => {
18+ servers . forEach ( ( server ) => {
19+ describe ( `${ server . protocol } ://${ server . host } :${ server . port } ` , async ( ) => {
20+ describe ( 'when connected' , async ( ) => {
21+ let client
2122
22- before ( async ( ) => {
23- client = new ElectrumClient (
24- server . host ,
25- server . port ,
26- server . protocol ,
27- server . options
28- )
23+ before ( async ( ) => {
24+ client = new ElectrumClient (
25+ server . host ,
26+ server . port ,
27+ server . protocol ,
28+ server . options ,
29+ )
2930
30- await client
31- . connect ( 'test_client' + server . protocol , '1.4.2' )
32- . catch ( ( err ) => {
33- console . error (
34- `failed to connect with config [${ JSON . stringify (
35- server
36- ) } ]: [${ err } ]`
37- )
38- } )
39- } )
31+ await client
32+ . connect ( 'test_client' + server . protocol , '1.4.2' )
33+ . catch ( ( err ) => {
34+ console . error (
35+ `failed to connect with config [${ JSON . stringify (
36+ server ,
37+ ) } ]: [${ err } ]`,
38+ )
39+ } )
40+ } )
4041
41- after ( async ( ) => {
42- await client . close ( )
43- } )
42+ after ( async ( ) => {
43+ await client . close ( )
44+ } )
4445
45- it ( 'request returns result' , async ( ) => {
46- const expectedResult = txData . hex
47- const result = await client . blockchain_transaction_get ( txData . hash )
46+ it ( 'request returns result' , async ( ) => {
47+ const expectedResult = txData . hex
48+ const result = await client . blockchain_transaction_get ( txData . hash )
4849
49- assert . equal ( result , expectedResult , 'unexpected result' )
50+ assert . equal ( result , expectedResult , 'unexpected result' )
51+ } )
5052 } )
51- } )
52- } )
53- } )
5453
55- context ( 'when not connected' , async ( ) => {
56- before ( async ( ) => {
57- const server = config . servers . tcp
54+ describe ( 'when not connected' , async ( ) => {
55+ let client
5856
59- client = new ElectrumClient (
60- server . host ,
61- server . port ,
62- server . protocol ,
63- server . options
64- )
65- } )
57+ before ( async ( ) => {
58+ client = new ElectrumClient (
59+ server . host ,
60+ server . port ,
61+ server . protocol ,
62+ server . options ,
63+ )
64+ } )
6665
67- it ( 'request throws error' , async ( ) => {
68- await client . blockchain_transaction_get ( txData . hash ) . then (
69- ( value ) => {
70- // onFulfilled
71- assert . fail ( 'not failed as expected' )
72- } ,
73- ( reason ) => {
74- // onRejected
75- assert . include ( reason . toString ( ) , `connection not established` )
76- }
77- )
66+ it ( 'request throws error' , async ( ) => {
67+ await client . blockchain_transaction_get ( txData . hash ) . then (
68+ ( value ) => {
69+ // onFulfilled
70+ assert . fail ( 'not failed as expected' )
71+ } ,
72+ ( reason ) => {
73+ // onRejected
74+ assert . include ( reason . toString ( ) , `connection not established` )
75+ } ,
76+ )
77+ } )
78+ } )
79+ } )
7880 } )
7981 } )
8082 // TODO: Add tests
0 commit comments