@@ -12,4 +12,187 @@ describe('Etherscan API', () => {
12
12
expect ( etherscan2 . network ) . toBe ( 'ROPSTEN' )
13
13
expect ( etherscan2 . host ) . toBe ( 'http://api-ropsten.etherscan.io' )
14
14
} )
15
+
16
+ describe ( 'Methods' , ( ) => {
17
+ const e = new EtherscanAPI ( )
18
+
19
+ test ( 'getAccountBalance' , ( ) => {
20
+ return e
21
+ . getAccountBalance ( '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae' )
22
+ . then ( data => {
23
+ expect ( data ) . toBe ( '670456215208885498951364' )
24
+ } )
25
+ } )
26
+
27
+ test ( 'getAccountBalance ether' , ( ) => {
28
+ return e
29
+ . getAccountBalance (
30
+ '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae' ,
31
+ 'ether'
32
+ )
33
+ . then ( data => {
34
+ expect ( data ) . toBe ( '670456.215208885498951364' )
35
+ } )
36
+ } )
37
+
38
+ test ( 'getAccountBalances' , ( ) => {
39
+ return e
40
+ . getAccountBalances ( [
41
+ '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a' ,
42
+ '0x63a9975ba31b0b9626b34300f7f627147df1f526' ,
43
+ '0x198ef1ec325a96cc354c7266a038be8b5c558f67'
44
+ ] )
45
+ . then ( data => {
46
+ expect ( data ) . toEqual ( [
47
+ {
48
+ account : '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a' ,
49
+ balance : '40807168564070000000000'
50
+ } ,
51
+ {
52
+ account : '0x63a9975ba31b0b9626b34300f7f627147df1f526' ,
53
+ balance : '332567136222827062478'
54
+ } ,
55
+ {
56
+ account : '0x198ef1ec325a96cc354c7266a038be8b5c558f67' ,
57
+ balance : '0'
58
+ }
59
+ ] )
60
+ } )
61
+ } )
62
+
63
+ test ( 'getAccountBalances eth' , ( ) => {
64
+ return e
65
+ . getAccountBalances (
66
+ [
67
+ '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a' ,
68
+ '0x63a9975ba31b0b9626b34300f7f627147df1f526' ,
69
+ '0x198ef1ec325a96cc354c7266a038be8b5c558f67'
70
+ ] ,
71
+ 'eth'
72
+ )
73
+ . then ( data => {
74
+ expect ( data ) . toEqual ( [
75
+ {
76
+ account : '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a' ,
77
+ balance : '40807.16856407'
78
+ } ,
79
+ {
80
+ account : '0x63a9975ba31b0b9626b34300f7f627147df1f526' ,
81
+ balance : '332.567136222827062478'
82
+ } ,
83
+ {
84
+ account : '0x198ef1ec325a96cc354c7266a038be8b5c558f67' ,
85
+ balance : '0'
86
+ }
87
+ ] )
88
+ } )
89
+ } )
90
+
91
+ test ( 'getTransactions' , ( ) => {
92
+ return e
93
+ . getTransactions (
94
+ '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a' ,
95
+ 0 ,
96
+ 9999999 ,
97
+ 3 ,
98
+ 3 ,
99
+ 'asc'
100
+ )
101
+ . then ( data => {
102
+ expect ( data . length ) . toBe ( 3 )
103
+ expect ( Object . keys ( data [ 0 ] ) ) . toEqual ( [
104
+ 'blockNumber' ,
105
+ 'timeStamp' ,
106
+ 'hash' ,
107
+ 'nonce' ,
108
+ 'blockHash' ,
109
+ 'transactionIndex' ,
110
+ 'from' ,
111
+ 'to' ,
112
+ 'value' ,
113
+ 'gas' ,
114
+ 'gasPrice' ,
115
+ 'isError' ,
116
+ 'txreceipt_status' ,
117
+ 'input' ,
118
+ 'contractAddress' ,
119
+ 'cumulativeGasUsed' ,
120
+ 'gasUsed' ,
121
+ 'confirmations'
122
+ ] )
123
+ } )
124
+ } )
125
+
126
+ test ( 'getInternalTransactions' , ( ) => {
127
+ return e
128
+ . getInternalTransactions (
129
+ '0x2c1ba59d6f58433fb1eaee7d20b26ed83bda51a3' ,
130
+ 0 ,
131
+ 2702578 ,
132
+ 3 ,
133
+ 3 ,
134
+ 'asc'
135
+ )
136
+ . then ( data => {
137
+ expect ( data . length ) . toBe ( 3 )
138
+ expect ( Object . keys ( data [ 0 ] ) ) . toEqual ( [
139
+ 'blockNumber' ,
140
+ 'timeStamp' ,
141
+ 'hash' ,
142
+ 'from' ,
143
+ 'to' ,
144
+ 'value' ,
145
+ 'contractAddress' ,
146
+ 'input' ,
147
+ 'type' ,
148
+ 'gas' ,
149
+ 'gasUsed' ,
150
+ 'traceId' ,
151
+ 'isError' ,
152
+ 'errCode'
153
+ ] )
154
+ } )
155
+ } )
156
+
157
+ test ( 'getInternalTransactionsByHash' , ( ) => {
158
+ return e
159
+ . getInternalTransactionsByHash (
160
+ '0x40eb908387324f2b575b4879cd9d7188f69c8fc9d87c901b9e2daaea4b442170'
161
+ )
162
+ . then ( data => {
163
+ expect ( Object . keys ( data [ 0 ] ) ) . toEqual ( [
164
+ 'blockNumber' ,
165
+ 'timeStamp' ,
166
+ 'from' ,
167
+ 'to' ,
168
+ 'value' ,
169
+ 'contractAddress' ,
170
+ 'input' ,
171
+ 'type' ,
172
+ 'gas' ,
173
+ 'gasUsed' ,
174
+ 'isError' ,
175
+ 'errCode'
176
+ ] )
177
+ } )
178
+ } )
179
+
180
+ test ( 'getMinedBlocks' , ( ) => {
181
+ return e
182
+ . getMinedBlocks (
183
+ '0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b' ,
184
+ 'blocks' ,
185
+ 10 ,
186
+ 1
187
+ )
188
+ . then ( data => {
189
+ expect ( data . length ) . toBe ( 10 )
190
+ expect ( Object . keys ( data [ 0 ] ) ) . toEqual ( [
191
+ 'blockNumber' ,
192
+ 'timeStamp' ,
193
+ 'blockReward'
194
+ ] )
195
+ } )
196
+ } )
197
+ } )
15
198
} )
0 commit comments