@@ -5,76 +5,78 @@ const assert = chai.assert
5
5
6
6
const fs = require ( 'fs' )
7
7
8
- const config = require ( './config' )
8
+ const { servers } = require ( './config' )
9
9
10
10
describe ( 'ElectrumClient' , async ( ) => {
11
11
let txData
12
12
13
13
before ( async ( ) => {
14
- txData = JSON . parse ( await fs . readFileSync ( './test/tx.json' , 'utf8' ) )
14
+ txData = JSON . parse ( fs . readFileSync ( './test/tx.json' , 'utf8' ) )
15
15
} )
16
16
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
21
22
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
+ )
29
30
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
+ } )
40
41
41
- after ( async ( ) => {
42
- await client . close ( )
43
- } )
42
+ after ( async ( ) => {
43
+ await client . close ( )
44
+ } )
44
45
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 )
48
49
49
- assert . equal ( result , expectedResult , 'unexpected result' )
50
+ assert . equal ( result , expectedResult , 'unexpected result' )
51
+ } )
50
52
} )
51
- } )
52
- } )
53
- } )
54
53
55
- context ( 'when not connected' , async ( ) => {
56
- before ( async ( ) => {
57
- const server = config . servers . tcp
54
+ describe ( 'when not connected' , async ( ) => {
55
+ let client
58
56
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
+ } )
66
65
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
+ } )
78
80
} )
79
81
} )
80
82
// TODO: Add tests
0 commit comments