Completed
Pull Request — master (#99)
by
unknown
03:07
created

describe(ꞌbtccom.convertꞌ)   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 333

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
cc 1
c 3
b 0
f 1
nc 1
dl 0
loc 333
rs 8.2857
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
var assert = require('assert');
2
var BtccomConverter = require("../lib/btccom.convert");
3
var RestClient = require('../lib/rest_client');
4
var network = {
5
    messagePrefix: '\u0018Bitcoin Signed Message:\n',
6
    bech32: 'bc',
7
    bip32: { public: 76067358, private: 76066276 },
8
    pubKeyHash: 0,
9
    scriptHash: 5,
10
    wif: 128 }
11
var useNewCashAddr = true;
12
13
var converter = new BtccomConverter(network, useNewCashAddr);
14
15
describe("btccom.convert", function() {
16
    describe("convertBlock", function() {
17
        it("works", function(cb) {
18
            var input = {
19
                "data": {
20
                    "height": 200000,
21
                    "version": 2,
22
                    "mrkl_root": "a08f8101f50fd9c9b3e5252aff4c1c1bd668f878fffaf3d0dbddeb029c307e88",
23
                    "timestamp": 1348310759,
24
                    "bits": 436591499,
25
                    "nonce": 4158183488,
26
                    "hash": "000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf",
27
                    "prev_block_hash": "00000000000003a20def7a05a77361b9657ff954b2f2080e135ea6f5970da215",
28
                    "next_block_hash": "00000000000002e3269b8a00caf315115297c626f954770e8398470d7f387e1c",
29
                    "size": 247533,
30
                    "pool_difficulty": 5097877,
31
                    "difficulty": 2864140.5078109736,
32
                    "tx_count": 388,
33
                    "reward_block": 5000000000,
34
                    "reward_fees": 63517500,
35
                    "created_at": 1492101215,
36
                    "confirmations": 310251,
37
                    "is_orphan": false,
38
                    "curr_max_timestamp": 1348310759,
39
                    "is_sw_block": false,
40
                    "stripped_size": 247533,
41
                    "weight": 990132,
42
                    "extras": {
43
                        "pool_name": "unknown",
44
                        "pool_link": ""
45
                    }
46
                },
47
                "err_no": 0,
48
                "err_msg": null
49
            };
50
51
            var output = converter.convertBlock(input);
52
            [
53
                ["height", "height"],
54
                ["is_orphan", "is_orphan"],
55
                ["merkleroot", "mrkl_root"],
56
                ["hash", "hash"],
57
                ["prev_block", "prev_block_hash"],
58
                ["next_block", "next_block_hash"],
59
                ["transactions", "tx_count"],
60
            ].map(function(keyAssoc) {
61
                var blocktrailKey = keyAssoc[0];
62
                var btccomKey = keyAssoc[1];
63
                assert.ok(blocktrailKey in output);
64
                assert.ok(input.data[btccomKey] == output[blocktrailKey])
65
            });
66
67
            cb();
68
        })
69
    })
70
    describe("convertBlockTx", function() {
71
        it("works", function(cb) {
72
            var input = {
73
                "data": {
74
                    "total_count": 388,
75
                    "page": 1,
76
                    "pagesize": 50,
77
                    "list": [
78
                        {
79
                            "confirmations": 310251,
80
                            "block_height": 200000,
81
                            "block_time": 1348310759,
82
                            "created_at": 1492101215,
83
                            "fee": 63517500,
84
                            "hash": "dbaf14e1c476e76ea05a8b71921a46d6b06f0a950f17c5f9f1a03b8fae467f10",
85
                            "inputs_count": 1,
86
                            "inputs_value": 0,
87
                            "is_coinbase": true,
88
                            "is_double_spend": false,
89
                            "is_sw_tx": false,
90
                            "weight": 768,
91
                            "vsize": 192,
92
                            "witness_hash": "dbaf14e1c476e76ea05a8b71921a46d6b06f0a950f17c5f9f1a03b8fae467f10",
93
                            "lock_time": 0,
94
                            "outputs_count": 1,
95
                            "outputs_value": 5063517500,
96
                            "size": 192,
97
                            "sigops": 4,
98
                            "version": 1,
99
                            "inputs": [
100
                                {
101
                                    "prev_addresses": [],
102
                                    "prev_position": -1,
103
                                    "prev_tx_hash": "0000000000000000000000000000000000000000000000000000000000000000",
104
                                    "prev_type": "NONSTANDARD",
105
                                    "prev_value": 0,
106
                                    "sequence": 4294967295,
107
                                    "script_asm": "",
108
                                    "script_hex": "03400d0302ef02062f503253482f522cfabe6d6dd90d39663d10f8fd25ec88338295d4c6ce1c90d4aeb368d8bdbadcc1da3b635801000000000000000474073e03",
109
                                    "witness": []
110
                                }
111
                            ],
112
                            "outputs": [
113
                                {
114
                                    "addresses": [
115
                                        "1MdYC22Gmjp2ejVPCxyYjFyWbQCYTGhGq8"
116
                                    ],
117
                                    "value": 5063517500,
118
                                    "type": "P2PKH_PUBKEY",
119
                                    "script_asm": "04b0bd634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e6537a576782eba668a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3c1e0908ef7b OP_CHECKSIG",
120
                                    "script_hex": "4104b0bd634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e6537a576782eba668a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3c1e0908ef7bac",
121
                                    "spent_by_tx": "5c76eb4dfb0941856a229833ef05b2f5c669dadc98ed2a34ea11974cacba9dc7",
122
                                    "spent_by_tx_position": 0
123
                                }
124
                            ]
125
                        },
126
                        {
127
                            "confirmations": 310251,
128
                            "block_height": 200000,
129
                            "block_time": 1348310759,
130
                            "created_at": 1492101215,
131
                            "fee": 0,
132
                            "hash": "ee475443f1fbfff84ffba43ba092a70d291df233bd1428f3d09f7bd1a6054a1f",
133
                            "inputs_count": 1,
134
                            "inputs_value": 10212000000,
135
                            "is_coinbase": false,
136
                            "is_double_spend": false,
137
                            "is_sw_tx": false,
138
                            "weight": 904,
139
                            "vsize": 226,
140
                            "witness_hash": "ee475443f1fbfff84ffba43ba092a70d291df233bd1428f3d09f7bd1a6054a1f",
141
                            "lock_time": 0,
142
                            "outputs_count": 2,
143
                            "outputs_value": 10212000000,
144
                            "size": 226,
145
                            "sigops": 8,
146
                            "version": 1,
147
                            "inputs": [
148
                                {
149
                                    "prev_addresses": [
150
                                        "1CfD77hupeUvFwBPxZ2fA8iyWmVwQY22oh"
151
                                    ],
152
                                    "prev_position": 1,
153
                                    "prev_tx_hash": "6e046b9c7683b5887bbde42ec358542ffe9c250306edb2d0cf386394aa96ee10",
154
                                    "prev_type": "P2PKH",
155
                                    "prev_value": 10212000000,
156
                                    "sequence": 4294967295,
157
                                    "script_asm": "3045022100e5e4749d539a163039769f52e1ebc8e6f62e39387d61e1a305bd722116cded6c022014924b745dd02194fe6b5cb8ac88ee8e9a2aede89e680dcea6169ea696e24d52[ALL] 02b4b754609b46b5d09644c2161f1767b72b93847ce8154d795f95d31031a08aa2",
158
                                    "script_hex": "483045022100e5e4749d539a163039769f52e1ebc8e6f62e39387d61e1a305bd722116cded6c022014924b745dd02194fe6b5cb8ac88ee8e9a2aede89e680dcea6169ea696e24d52012102b4b754609b46b5d09644c2161f1767b72b93847ce8154d795f95d31031a08aa2",
159
                                    "witness": []
160
                                }
161
                            ],
162
                            "outputs": [
163
                                {
164
                                    "addresses": [
165
                                        "1FhNPRh1TxVidoKkWFEpdmK5RXw9vG1KUb"
166
                                    ],
167
                                    "value": 5586000000,
168
                                    "type": "P2PKH",
169
                                    "script_asm": "OP_DUP OP_HASH160 a134408afa258a50ed7a1d9817f26b63cc9002cc OP_EQUALVERIFY OP_CHECKSIG",
170
                                    "script_hex": "76a914a134408afa258a50ed7a1d9817f26b63cc9002cc88ac",
171
                                    "spent_by_tx": "12c7db0b0f4baae58ee1be0fd925fbbf7588ea3339f38557978015ba120ca086",
172
                                    "spent_by_tx_position": 0
173
                                },
174
                                {
175
                                    "addresses": [
176
                                        "1QE7Tazy1uHD1utCb1fCW6aLF3RZ1sNwd2"
177
                                    ],
178
                                    "value": 4626000000,
179
                                    "type": "P2PKH",
180
                                    "script_asm": "OP_DUP OP_HASH160 fec5b1145596b35f59f8be1daf169f3759421433 OP_EQUALVERIFY OP_CHECKSIG",
181
                                    "script_hex": "76a914fec5b1145596b35f59f8be1daf169f375942143388ac",
182
                                    "spent_by_tx": "6cf0a98e6290c343c8eed9373ec63329a5147a491974d3a146bdbf466978b306",
183
                                    "spent_by_tx_position": 0
184
                                }
185
                            ]
186
                        },
187
                        {
188
                            "confirmations": 310251,
189
                            "block_height": 200000,
190
                            "block_time": 1348310759,
191
                            "created_at": 1492101215,
192
                            "fee": 0,
193
                            "hash": "e03a9a4b5c557f6ee3400a29ff1475d1df73e9cddb48c2391abdc391d8c1504a",
194
                            "inputs_count": 1,
195
                            "inputs_value": 9500000000,
196
                            "is_coinbase": false,
197
                            "is_double_spend": false,
198
                            "is_sw_tx": false,
199
                            "weight": 900,
200
                            "vsize": 225,
201
                            "witness_hash": "e03a9a4b5c557f6ee3400a29ff1475d1df73e9cddb48c2391abdc391d8c1504a",
202
                            "lock_time": 0,
203
                            "outputs_count": 2,
204
                            "outputs_value": 9500000000,
205
                            "size": 225,
206
                            "sigops": 8,
207
                            "version": 1,
208
                            "inputs": [
209
                                {
210
                                    "prev_addresses": [
211
                                        "1DC8mbgdVFNZn7ie6wUVGegKHsqvKkN7Qn"
212
                                    ],
213
                                    "prev_position": 0,
214
                                    "prev_tx_hash": "0530375a5bf4ea9a82494fcb5ef4a61076c2af807982076fa810851f4bc31c09",
215
                                    "prev_type": "P2PKH",
216
                                    "prev_value": 9500000000,
217
                                    "sequence": 4294967295,
218
                                    "script_asm": "304402202b5869e0b4e711784daecd511f9dadf28e37113ef5054a6898d0367034afb067022014dfd2f58da949550ddc4ebb1135527cdbc48b25c6eb6388cc88231fd7ea04a9[ALL] 02fec863d4d0baf5e01a9bd9c59b790bbf683c5b7b6624d7aa7ab9405c5fdb9786",
219
                                    "script_hex": "47304402202b5869e0b4e711784daecd511f9dadf28e37113ef5054a6898d0367034afb067022014dfd2f58da949550ddc4ebb1135527cdbc48b25c6eb6388cc88231fd7ea04a9012102fec863d4d0baf5e01a9bd9c59b790bbf683c5b7b6624d7aa7ab9405c5fdb9786",
220
                                    "witness": []
221
                                }
222
                            ],
223
                            "outputs": [
224
                                {
225
                                    "addresses": [
226
                                        "1HtF7xbaDwJu1j5sKpetG91xr4AZHYmJTL"
227
                                    ],
228
                                    "value": 9400000000,
229
                                    "type": "P2PKH",
230
                                    "script_asm": "OP_DUP OP_HASH160 b933036b1f143e6ee5f9038c4205f6bbe41e49cc OP_EQUALVERIFY OP_CHECKSIG",
231
                                    "script_hex": "76a914b933036b1f143e6ee5f9038c4205f6bbe41e49cc88ac",
232
                                    "spent_by_tx": "360c0ee799aa6e00032f87d62751d5a20cd9e6c6245f6420971647c45aca59e9",
233
                                    "spent_by_tx_position": 0
234
                                },
235
                                {
236
                                    "addresses": [
237
                                        "1AQHgGfYswNkput7vzGzCUUzH4wQQkWKXr"
238
                                    ],
239
                                    "value": 100000000,
240
                                    "type": "P2PKH",
241
                                    "script_asm": "OP_DUP OP_HASH160 67209ed8971b9bdf4147cd25e5f09c77f43c0dac OP_EQUALVERIFY OP_CHECKSIG",
242
                                    "script_hex": "76a91467209ed8971b9bdf4147cd25e5f09c77f43c0dac88ac",
243
                                    "spent_by_tx": "4f67254491474ae03d8e023fae4bf249e1f81b07efb6ea763a13c9bc7b4210b3",
244
                                    "spent_by_tx_position": 1
245
                                }
246
                            ]
247
                        },
248
                        {
249
                            "confirmations": 310251,
250
                            "block_height": 200000,
251
                            "block_time": 1348310759,
252
                            "created_at": 1492101215,
253
                            "fee": 0,
254
                            "hash": "ffa0267c8f2af736858894d6f3e5081a05e2ec16dc98f78a80f376ce35077491",
255
                            "inputs_count": 1,
256
                            "inputs_value": 37325663465,
257
                            "is_coinbase": false,
258
                            "is_double_spend": false,
259
                            "is_sw_tx": false,
260
                            "weight": 1032,
261
                            "vsize": 258,
262
                            "witness_hash": "ffa0267c8f2af736858894d6f3e5081a05e2ec16dc98f78a80f376ce35077491",
263
                            "lock_time": 0,
264
                            "outputs_count": 2,
265
                            "outputs_value": 37325663465,
266
                            "size": 258,
267
                            "sigops": 8,
268
                            "version": 1,
269
                            "inputs": [
270
                                {
271
                                    "prev_addresses": [
272
                                        "1AGt1P3fhCF9MUue3dheegBZgGVHeLAtLr"
273
                                    ],
274
                                    "prev_position": 1,
275
                                    "prev_tx_hash": "1fa6ecf02e5de2001e4aec6d3e90b5ef6d81aead39e7f04f303e6c8415547bba",
276
                                    "prev_type": "P2PKH",
277
                                    "prev_value": 37325663465,
278
                                    "sequence": 4294967295,
279
                                    "script_asm": "3045022001b572518fe610121b777286b424d89ba73fe503ff440458f01361a29348248b022100fa1afae0ccf3007d208605662685dd57e6940066ae6be81aa8b2af319060fceb[ALL] 04f28840b52c60c0fa041b9f4b2fa3dd00bccd71c0ab03f4db3c4295a23b117535fdd6d34787f95870d51ec245c800d851dd8509de42c47a0dc7a09300053110b8",
280
                                    "script_hex": "483045022001b572518fe610121b777286b424d89ba73fe503ff440458f01361a29348248b022100fa1afae0ccf3007d208605662685dd57e6940066ae6be81aa8b2af319060fceb014104f28840b52c60c0fa041b9f4b2fa3dd00bccd71c0ab03f4db3c4295a23b117535fdd6d34787f95870d51ec245c800d851dd8509de42c47a0dc7a09300053110b8",
281
                                    "witness": []
282
                                }
283
                            ],
284
                            "outputs": [
285
                                {
286
                                    "addresses": [
287
                                        "1D5Em12TqtZtX3LJHYiGjarKCVss4nMmGP"
288
                                    ],
289
                                    "value": 17749527722,
290
                                    "type": "P2PKH",
291
                                    "script_asm": "OP_DUP OP_HASH160 846ea88b63aa1dbf265a33127f518974402870bd OP_EQUALVERIFY OP_CHECKSIG",
292
                                    "script_hex": "76a914846ea88b63aa1dbf265a33127f518974402870bd88ac",
293
                                    "spent_by_tx": "0e6641d59cbcbbb2df61f1f80b044642dd68916096de00f9d9e4f0106e148d2c",
294
                                    "spent_by_tx_position": 1
295
                                },
296
                                {
297
                                    "addresses": [
298
                                        "13b9rHKTNBMdKWmoiKM8o7Gx5zkvJwZG6x"
299
                                    ],
300
                                    "value": 19576135743,
301
                                    "type": "P2PKH",
302
                                    "script_asm": "OP_DUP OP_HASH160 1c65c81774aa85e123b0e5c51bc7cda6805f154e OP_EQUALVERIFY OP_CHECKSIG",
303
                                    "script_hex": "76a9141c65c81774aa85e123b0e5c51bc7cda6805f154e88ac",
304
                                    "spent_by_tx": "93ee77570a26841bc55a76a0739024b6521183a7d2fee3a0320570c41d01b76f",
305
                                    "spent_by_tx_position": 0
306
                                }
307
                            ]
308
                        },
309
                        {
310
                            "confirmations": 310251,
311
                            "block_height": 200000,
312
                            "block_time": 1348310759,
313
                            "created_at": 1492101215,
314
                            "fee": 50000,
315
                            "hash": "2674c8a46b75e5a5e3287a34d7999a1e5e6f052be36f63f3cb483ec148c9b86c",
316
                            "inputs_count": 1,
317
                            "inputs_value": 946622517855,
318
                            "is_coinbase": false,
319
                            "is_double_spend": false,
320
                            "is_sw_tx": false,
321
                            "weight": 908,
322
                            "vsize": 227,
323
                            "witness_hash": "2674c8a46b75e5a5e3287a34d7999a1e5e6f052be36f63f3cb483ec148c9b86c",
324
                            "lock_time": 0,
325
                            "outputs_count": 2,
326
                            "outputs_value": 946622467855,
327
                            "size": 227,
328
                            "sigops": 8,
329
                            "version": 1,
330
                            "inputs": [
331
                                {
332
                                    "prev_addresses": [
333
                                        "14DeXEwWrpo7urTz76LgQpxXtF8SAQMTbe"
334
                                    ],
335
                                    "prev_position": 0,
336
                                    "prev_tx_hash": "a8d4bb8395b6a59ff0355a145b3c0a63d42966af02c373e4c86e4d2779f514e2",
337
                                    "prev_type": "P2PKH",
338
                                    "prev_value": 946622517855,
339
                                    "sequence": 4294967295,
340
                                    "script_asm": "3046022100d9331c464433c16e59947d6d36df23cd6d29160e97e2707c27bd7641d291a3380221008b1927354afb5a1bd0412fdbde7a3141cba991342ac17505bf13452dac4a533a[ALL] 0319a9a55c1e4dfd168adae85af834ec0db91ae1c164c7286316155a9135afcee8",
341
                                    "script_hex": "493046022100d9331c464433c16e59947d6d36df23cd6d29160e97e2707c27bd7641d291a3380221008b1927354afb5a1bd0412fdbde7a3141cba991342ac17505bf13452dac4a533a01210319a9a55c1e4dfd168adae85af834ec0db91ae1c164c7286316155a9135afcee8",
342
                                    "witness": []
343
                                }
344
                            ],
345
                            "outputs": [
346
                                {
347
                                    "addresses": [
348
                                        "1Fg7BsVkTk1gWnWTpgyb26Zo6NGNsx2gcQ"
349
                                    ],
350
                                    "value": 945815591855,
351
                                    "type": "P2PKH",
352
                                    "script_asm": "OP_DUP OP_HASH160 a0f7260313ab5798391cb610bc4fe0a6be883d59 OP_EQUALVERIFY OP_CHECKSIG",
353
                                    "script_hex": "76a914a0f7260313ab5798391cb610bc4fe0a6be883d5988ac",
354
                                    "spent_by_tx": "981db136c4efaa9f91db680bf16aa2e38a0bc13e70f56d5f10b1b86903973f51",
355
                                    "spent_by_tx_position": 0
356
                                },
357
                                {
358
                                    "addresses": [
359
                                        "1Q22kYfL81iaAZZLj4epvUQ3yLv57Mgd56"
360
                                    ],
361
                                    "value": 806876000,
362
                                    "type": "P2PKH",
363
                                    "script_asm": "OP_DUP OP_HASH160 fc7cc53ddff31d4c6b18ea7331b80f2b76d7a45d OP_EQUALVERIFY OP_CHECKSIG",
364
                                    "script_hex": "76a914fc7cc53ddff31d4c6b18ea7331b80f2b76d7a45d88ac",
365
                                    "spent_by_tx": "a68c971e3666c36717fe2ec80e6ebbefd5045601476d5c845b90c26c4fa2a71d",
366
                                    "spent_by_tx_position": 9
367
                                }
368
                            ]
369
                        }
370
                    ]
371
                },
372
                "err_no": 0,
373
                "err_msg": null
374
            };
375
376
            var output = converter.convertBlockTx(input);
377
            assert.ok("current_page" in output);
378
            assert.ok("per_page" in output);
379
            assert.ok("total" in output);
380
381
            [
382
                ["size", "size"],
383
                ["hash", "hash"],
384
                ["confirmations", "confirmations"],
385
                ["is_coinbase", "is_coinbase"],
386
                ["total_fee", "fee"],
387
                ["size", "size"],
388
                ["is_double_spend", "is_double_spend"]
389
390
            ].map(function(keyAssoc) {
391
                var blocktrailKey = keyAssoc[0];
392
                var btccomKey = keyAssoc[1];
393
                var blockTx = output.data[0];
394
                console.log(blocktrailKey)
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
395
                assert.ok(blocktrailKey in blockTx);
396
                console.log(input.data.list[0][btccomKey],blockTx[blocktrailKey])
397
                assert.ok(input.data.list[0][btccomKey] == blockTx[blocktrailKey])
398
            });
399
400
            cb();
401
        })
402
    });
403
404
    describe("convertTx", function() {
405
        it("works", function(cb) {
406
            var input = {
407
                "err_no": 0,
408
                "data": {
409
                    "confirmations": 310251,
410
                    "block_height": 200000,
411
                    "block_time": 1348310759,
412
                    "created_at": 1492101215,
413
                    "fee": 63517500,
414
                    "hash": "dbaf14e1c476e76ea05a8b71921a46d6b06f0a950f17c5f9f1a03b8fae467f10",
415
                    "inputs_count": 1,
416
                    "inputs_value": 0,
417
                    "is_coinbase": true,
418
                    "is_double_spend": false,
419
                    "is_sw_tx": false,
420
                    "weight": 768,
421
                    "vsize": 192,
422
                    "witness_hash": "dbaf14e1c476e76ea05a8b71921a46d6b06f0a950f17c5f9f1a03b8fae467f10",
423
                    "lock_time": 0,
424
                    "outputs_count": 1,
425
                    "outputs_value": 5063517500,
426
                    "size": 192,
427
                    "sigops": 4,
428
                    "version": 1,
429
                    "inputs": [
430
                        {
431
                            "prev_addresses": [],
432
                            "prev_position": -1,
433
                            "prev_tx_hash": "0000000000000000000000000000000000000000000000000000000000000000",
434
                            "prev_type": "NONSTANDARD",
435
                            "prev_value": 0,
436
                            "sequence": 4294967295,
437
                            "script_asm": "",
438
                            "script_hex": "03400d0302ef02062f503253482f522cfabe6d6dd90d39663d10f8fd25ec88338295d4c6ce1c90d4aeb368d8bdbadcc1da3b635801000000000000000474073e03",
439
                            "witness": []
440
                        }
441
                    ],
442
                    "outputs": [
443
                        {
444
                            "addresses": [
445
                                "1MdYC22Gmjp2ejVPCxyYjFyWbQCYTGhGq8"
446
                            ],
447
                            "value": 5063517500,
448
                            "type": "P2PKH_PUBKEY",
449
                            "script_asm": "04b0bd634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e6537a576782eba668a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3c1e0908ef7b OP_CHECKSIG",
450
                            "script_hex": "4104b0bd634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e6537a576782eba668a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3c1e0908ef7bac",
451
                            "spent_by_tx": "5c76eb4dfb0941856a229833ef05b2f5c669dadc98ed2a34ea11974cacba9dc7",
452
                            "spent_by_tx_position": 0
453
                        }
454
                    ]
455
                }
456
            };
457
458
            var output = converter.convertTx(input);
459
            assert.ok("hash" in output);
460
461
            [
462
                ["size", "size"],
463
                ["hash", "hash"],
464
                ["confirmations", "confirmations"],
465
                ["is_coinbase", "is_coinbase"],
466
                ["block_height", "block_height"],
467
                ["total_fee", "fee"],
468
                ["size", "size"],
469
                ["is_double_spend", "is_double_spend"]
470
471
            ].map(function(keyAssoc) {
472
                var blocktrailKey = keyAssoc[0];
473
                var btccomKey = keyAssoc[1]
474
                var blockTx = output;
475
                console.log(blocktrailKey)
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
476
                assert.ok(blocktrailKey in blockTx);
477
                assert.ok(input.data[btccomKey] == blockTx[blocktrailKey])
478
            });
479
            cb();
480
        })
481
482
    });
483
484
    describe("convertAddress", function() {
485
        it("works", function(cb) {
486
            var input = {
487
                "err_no": 0,
488
                "data": {
489
                    "address": "3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief",
490
                    "received": 190000,
491
                    "sent": 100000,
492
                    "balance": 90000,
493
                    "tx_count": 3,
494
                    "unconfirmed_tx_count": 0,
495
                    "unconfirmed_received": 0,
496
                    "unconfirmed_sent": 0,
497
                    "unspent_tx_count": 1,
498
                    "first_tx": "2613f3f7ccf6ca8beb68f72469905048120d7fc353bb02e81b1b4f570c5ce490",
499
                    "last_tx": "bd430d52f35166a7dd6251c73a48559ad8b5f41b6c5bc4a6c4c1a3e3702f4287"
500
                }
501
            };
502
503
            var output = converter.convertAddress(input);
504
            [
505
                ["address", "address"],
506
                ["balance", "balance"],
507
                ["received", "received"],
508
                ["sent", "sent"],
509
                ["transactions", "tx_count"],
510
                ["unconfirmed_received", "unconfirmed_received"],
511
                ["unconfirmed_sent", "unconfirmed_sent"],
512
                ["unconfirmed_transactions", "unconfirmed_tx_count"],
513
                ["unconfirmed_utxos", "unspent_tx_count"],
514
                ["first_tx", "first_tx"],
515
                ["last_tx", "last_tx"]
516
517
            ].map(function(keyAssoc) {
518
                var blocktrailKey = keyAssoc[0];
519
                var btccomKey = keyAssoc[1];
520
521
                var blockTx = output.data[0];
522
                console.log(blocktrailKey)
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
523
                assert.ok(blocktrailKey in blockTx);
524
                assert.ok(input.data.list[0][btccomKey] == blockTx[blocktrailKey])
525
            });
526
            cb();
527
        })
528
    });
529
530
    describe("convertAddressTx", function() {
531
        it("works", function(cb) {
532
            var input = {
533
                "data": {
534
                    "total_count": 3,
535
                    "page": 1,
536
                    "pagesize": 50,
537
                    "list": [
538
                        {
539
                            "confirmations": 28118,
540
                            "block_height": 482133,
541
                            "block_time": 1503801123,
542
                            "created_at": 1503563229,
543
                            "fee": 13409,
544
                            "hash": "bd430d52f35166a7dd6251c73a48559ad8b5f41b6c5bc4a6c4c1a3e3702f4287",
545
                            "inputs_count": 1,
546
                            "inputs_value": 100000,
547
                            "is_coinbase": false,
548
                            "is_double_spend": false,
549
                            "is_sw_tx": true,
550
                            "weight": 578,
551
                            "vsize": 145,
552
                            "witness_hash": "8d558281ffc88ca7c294e15ce0b778b9c85490dd1ff3121305c4f51b86a758f1",
553
                            "lock_time": 0,
554
                            "outputs_count": 1,
555
                            "outputs_value": 86591,
556
                            "size": 227,
557
                            "sigops": 1,
558
                            "version": 1,
559
                            "inputs": [
560
                                {
561
                                    "prev_addresses": [
562
                                        "3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief"
563
                                    ],
564
                                    "prev_position": 1,
565
                                    "prev_tx_hash": "4de2b03b46c8c1ab5e582ea3ab4f1b055c91798ffd8e9cbe05010c99bc914947",
566
                                    "prev_type": "P2SH",
567
                                    "prev_value": 100000,
568
                                    "sequence": 4294967295,
569
                                    "script_asm": "00145d6f02f47dc6c57093df246e3742cfe1e22ab410",
570
                                    "script_hex": "1600145d6f02f47dc6c57093df246e3742cfe1e22ab410",
571
                                    "witness": [
572
                                        "3045022100a1707fff61f5add9ca4cf7cdb39aa0b3fd9f672274715749c9356d4eda57becd02201aea20e0ba29adc67fba8fdcf727297b841017cb8b0ff58ea5c5160037975f0201",
573
                                        "03534da516a0ab32f30246620fdfbfaf1921228c1e222c6bd2fcddbcfd9024a1b6"
574
                                    ]
575
                                }
576
                            ],
577
                            "outputs": [
578
                                {
579
                                    "addresses": [
580
                                        "916ff972855bf7589caf8c46a31f7f33b07d0100d953fde95a8354ac36e98165"
581
                                    ],
582
                                    "value": 86591,
583
                                    "type": "P2WSH_V0",
584
                                    "script_asm": "0 916ff972855bf7589caf8c46a31f7f33b07d0100d953fde95a8354ac36e98165",
585
                                    "script_hex": "0020916ff972855bf7589caf8c46a31f7f33b07d0100d953fde95a8354ac36e98165",
586
                                    "spent_by_tx": "cab75da6d7fe1531c881d4efdb4826410a2604aa9e6442ab12a08363f34fb408",
587
                                    "spent_by_tx_position": 0
588
                                }
589
                            ],
590
                            "balance_diff": -100000
591
                        },
592
                        {
593
                            "confirmations": 28162,
594
                            "block_height": 482089,
595
                            "block_time": 1503765455,
596
                            "created_at": 1503560516,
597
                            "fee": 83409,
598
                            "hash": "4de2b03b46c8c1ab5e582ea3ab4f1b055c91798ffd8e9cbe05010c99bc914947",
599
                            "inputs_count": 1,
600
                            "inputs_value": 316400,
601
                            "is_coinbase": false,
602
                            "is_double_spend": false,
603
                            "is_sw_tx": false,
604
                            "weight": 1484,
605
                            "vsize": 371,
606
                            "witness_hash": "4de2b03b46c8c1ab5e582ea3ab4f1b055c91798ffd8e9cbe05010c99bc914947",
607
                            "lock_time": 0,
608
                            "outputs_count": 2,
609
                            "outputs_value": 232991,
610
                            "size": 371,
611
                            "sigops": 12,
612
                            "version": 1,
613
                            "inputs": [
614
                                {
615
                                    "prev_addresses": [
616
                                        "3Fzr53M54N8nWwTPt7btU4pcXQ3kNUUtrx"
617
                                    ],
618
                                    "prev_position": 0,
619
                                    "prev_tx_hash": "d37f2a922c3e03d5c8e3bbb5e8f704d4eb221e4c9e1e3165201e58ddea54b440",
620
                                    "prev_type": "P2SH",
621
                                    "prev_value": 316400,
622
                                    "sequence": 4294967295,
623
                                    "script_asm": "0 3045022100dc0eb9ebb44e21a2334b1a9936ff2d3e6f85b6a8b0bae2462640ad574d5653570220591365f8795c68b788d3949e9d6a984dae2f79d49bf3b0b184edf9f676732524[ALL] 3045022100aac67f935a52fd961b404dd4d273600924f74498062e237fec3ef50416440e3d02204fcf8deaee86c5a95c8c8c235bb252a5d4d304b9bd3e01d9c7098fae3c9172cf[ALL] 522102ef6587d4850890bd42e7779365ed2baeec17824b84a285894ec090edf0b604e4210322f35f79c76036a68746d8e3804b9097a6575ae6d7fc9dfb99c06280b656dfc12103f73d0f5d4f8919a74d4b0cc72fc0ef5ee9eaf759d3731319294491883d97881b53ae",
624
                                    "script_hex": "00483045022100dc0eb9ebb44e21a2334b1a9936ff2d3e6f85b6a8b0bae2462640ad574d5653570220591365f8795c68b788d3949e9d6a984dae2f79d49bf3b0b184edf9f67673252401483045022100aac67f935a52fd961b404dd4d273600924f74498062e237fec3ef50416440e3d02204fcf8deaee86c5a95c8c8c235bb252a5d4d304b9bd3e01d9c7098fae3c9172cf014c69522102ef6587d4850890bd42e7779365ed2baeec17824b84a285894ec090edf0b604e4210322f35f79c76036a68746d8e3804b9097a6575ae6d7fc9dfb99c06280b656dfc12103f73d0f5d4f8919a74d4b0cc72fc0ef5ee9eaf759d3731319294491883d97881b53ae",
625
                                    "witness": []
626
                                }
627
                            ],
628
                            "outputs": [
629
                                {
630
                                    "addresses": [
631
                                        "32bH64DNFHV3y74Qyx3FSAKykUauUB94as"
632
                                    ],
633
                                    "value": 132991,
634
                                    "type": "P2SH",
635
                                    "script_asm": "OP_HASH160 09e249cd56381853743834cf7c367093f4f84970 OP_EQUAL",
636
                                    "script_hex": "a91409e249cd56381853743834cf7c367093f4f8497087",
637
                                    "spent_by_tx": "2562317b87aeddd42fff89ecd0802f4c7cfb0cc404c37534b33a10fa4391878e",
638
                                    "spent_by_tx_position": 2
639
                                },
640
                                {
641
                                    "addresses": [
642
                                        "3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief"
643
                                    ],
644
                                    "value": 100000,
645
                                    "type": "P2SH",
646
                                    "script_asm": "OP_HASH160 8c299479cf35311569d8c1450a85de22d206ab49 OP_EQUAL",
647
                                    "script_hex": "a9148c299479cf35311569d8c1450a85de22d206ab4987",
648
                                    "spent_by_tx": "bd430d52f35166a7dd6251c73a48559ad8b5f41b6c5bc4a6c4c1a3e3702f4287",
649
                                    "spent_by_tx_position": 0
650
                                }
651
                            ],
652
                            "balance_diff": 100000
653
                        },
654
                        {
655
                            "confirmations": 28319,
656
                            "block_height": 481932,
657
                            "block_time": 1503632682,
658
                            "created_at": 1503562862,
659
                            "fee": 159820,
660
                            "hash": "2613f3f7ccf6ca8beb68f72469905048120d7fc353bb02e81b1b4f570c5ce490",
661
                            "inputs_count": 1,
662
                            "inputs_value": 9223832,
663
                            "is_coinbase": false,
664
                            "is_double_spend": false,
665
                            "is_sw_tx": false,
666
                            "weight": 1468,
667
                            "vsize": 367,
668
                            "witness_hash": "2613f3f7ccf6ca8beb68f72469905048120d7fc353bb02e81b1b4f570c5ce490",
669
                            "lock_time": 0,
670
                            "outputs_count": 2,
671
                            "outputs_value": 9064012,
672
                            "size": 367,
673
                            "sigops": 12,
674
                            "version": 1,
675
                            "inputs": [
676
                                {
677
                                    "prev_addresses": [
678
                                        "36398e4nx2uXBw83wFusq2u6CwrAYMRUd6"
679
                                    ],
680
                                    "prev_position": 0,
681
                                    "prev_tx_hash": "317f62e894f112bd7042e3352f4e5fc546dfa1a55e7d86da13de3feb800f1991",
682
                                    "prev_type": "P2SH",
683
                                    "prev_value": 9223832,
684
                                    "sequence": 4294967295,
685
                                    "script_asm": "0 304402206578aea3eecb83bb9727257e3b1a798d2cc6bf177e2f0e55b81dccb99c52d58602201af4ba5938dc290a1d3b380d120b468258a01abb035b3f8d451564927d668fae[ALL] 304402204910eec198eb9476c7e1d352b3fe3e4a3307422a442f7972d6a0eb838346bf4102205f18db326d81ca8dc4cadbc817551bab3fad369b245e8d7e30d8aa00a642ea82[ALL] 522102a75a0a36bbd4bc4ef4b015d1ecf477558fd13024e5de28eb4ce1db8bd9b1c92c2102d34d25fffe77d7142e2b2b4937bf970a3fc2c01e8200bd05172c6ce7b85ed1282103b04a7f2da2f3b16fcf9b7472a053cf89251b64636f6b2c55bf9e34026a4c756553ae",
686
                                    "script_hex": "0047304402206578aea3eecb83bb9727257e3b1a798d2cc6bf177e2f0e55b81dccb99c52d58602201af4ba5938dc290a1d3b380d120b468258a01abb035b3f8d451564927d668fae0147304402204910eec198eb9476c7e1d352b3fe3e4a3307422a442f7972d6a0eb838346bf4102205f18db326d81ca8dc4cadbc817551bab3fad369b245e8d7e30d8aa00a642ea82014c69522102a75a0a36bbd4bc4ef4b015d1ecf477558fd13024e5de28eb4ce1db8bd9b1c92c2102d34d25fffe77d7142e2b2b4937bf970a3fc2c01e8200bd05172c6ce7b85ed1282103b04a7f2da2f3b16fcf9b7472a053cf89251b64636f6b2c55bf9e34026a4c756553ae",
687
                                    "witness": []
688
                                }
689
                            ],
690
                            "outputs": [
691
                                {
692
                                    "addresses": [
693
                                        "3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief"
694
                                    ],
695
                                    "value": 90000,
696
                                    "type": "P2SH",
697
                                    "script_asm": "OP_HASH160 8c299479cf35311569d8c1450a85de22d206ab49 OP_EQUAL",
698
                                    "script_hex": "a9148c299479cf35311569d8c1450a85de22d206ab4987",
699
                                    "spent_by_tx": null,
700
                                    "spent_by_tx_position": -1
701
                                },
702
                                {
703
                                    "addresses": [
704
                                        "3Qfkqzpd6EjGSzDXQXNcYCJE78BH7poKoD"
705
                                    ],
706
                                    "value": 8974012,
707
                                    "type": "P2SH",
708
                                    "script_asm": "OP_HASH160 fc0de3e893c40ae834ee970d5178eba47c37b642 OP_EQUAL",
709
                                    "script_hex": "a914fc0de3e893c40ae834ee970d5178eba47c37b64287",
710
                                    "spent_by_tx": "7b7462ade8518268c2cf89d2b5750a8058f18e40d224ee55ab38ebeb1d696e26",
711
                                    "spent_by_tx_position": 0
712
                                }
713
                            ],
714
                            "balance_diff": 90000
715
                        }
716
                    ]
717
                },
718
                "err_no": 0,
719
                "err_msg": null
720
            };
721
722
            var output = converter.convertAddressTx(input);
723
            assert.ok("total" in output);
724
            cb();
725
726
        })
727
728
    });
729
    
730
    
731
    describe ("convertAddressUnspentOutputs", function() {
732
        it("works", function(cb) {
733
            var input = {
734
                "data": {
735
                    "total_count": 1200,
736
                    "page": 1,
737
                    "pagesize": 50,
738
                    "list": [
739
                        {
740
                            "tx_hash": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
741
                            "tx_output_n": 0,
742
                            "tx_output_n2": 0,
743
                            "value": 5000000000,
744
                            "confirmations": 510251
745
                        },
746
                        {
747
                            "tx_hash": "3387418aaddb4927209c5032f515aa442a6587d6e54677f08a03b8fa7789e688",
748
                            "tx_output_n": 1,
749
                            "tx_output_n2": 0,
750
                            "value": 1000000,
751
                            "confirmations": 386528
752
                        },
753
                        {
754
                            "tx_hash": "8f6b63012753005236b1b76e4884e4dee7415e05ab96604d353001662cde6b53",
755
                            "tx_output_n": 1,
756
                            "tx_output_n2": 0,
757
                            "value": 222222,
758
                            "confirmations": 382308
759
                        },
760
                        {
761
                            "tx_hash": "60ff2dfdf67917040139903a0141f7525a7d152365b371b35fd1cf83f1d7f704",
762
                            "tx_output_n": 1,
763
                            "tx_output_n2": 0,
764
                            "value": 333333,
765
                            "confirmations": 382308
766
                        },
767
                        {
768
                            "tx_hash": "1b703ca32b2da08cf896081a96c48f6433641e2c7d805fd170a31b0cbfb900df",
769
                            "tx_output_n": 1,
770
                            "tx_output_n2": 0,
771
                            "value": 500000,
772
                            "confirmations": 381697
773
                        },
774
                        {
775
                            "tx_hash": "495167f5b9d55519717cb171208a98ffd347410169f258b598b1b65447d8e078",
776
                            "tx_output_n": 1,
777
                            "tx_output_n2": 0,
778
                            "value": 500000,
779
                            "confirmations": 381697
780
                        },
781
                        {
782
                            "tx_hash": "2c484eaaf9bdaa42caee501523c631b1ceaef89838ea93bd5d199ac275469d22",
783
                            "tx_output_n": 1,
784
                            "tx_output_n2": 0,
785
                            "value": 1000000,
786
                            "confirmations": 378843
787
                        },
788
                        {
789
                            "tx_hash": "02a206264aecaf9f45f725533496b1b80bdd5a239194d8dd8100eed5415b6a14",
790
                            "tx_output_n": 1,
791
                            "tx_output_n2": 0,
792
                            "value": 6660000,
793
                            "confirmations": 375256
794
                        },
795
                        {
796
                            "tx_hash": "fd3c66b9c981a3ccc40ae0f631f45286e7b31cf6d9afa1acaf8be1261f133690",
797
                            "tx_output_n": 0,
798
                            "tx_output_n2": 0,
799
                            "value": 100000,
800
                            "confirmations": 375016
801
                        }
802
                    ]
803
                },
804
                "err_no": 0,
805
                "err_msg": null
806
            };
807
808
            var output = converter.convertAddressUnspentOutputs(input,"1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa");
809
810
            [
811
                ["hash", "tx_hash"],
812
                ["time", "time"],
813
                ["confirmations", "confirmations"],
814
                ["value", "value"],
815
                ["index", "tx_output_n"],
816
817
            ].map(function(keyAssoc) {
818
                var blocktrailKey = keyAssoc[0];
819
                var btccomKey = keyAssoc[1];
820
821
                var blockTx = output.data[0];
822
                console.log(blocktrailKey)
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
823
                assert.ok(blocktrailKey in blockTx);
824
                console.log(input.data.list[0][btccomKey], blockTx[blocktrailKey])
825
                assert.ok(input.data.list[0][btccomKey] == blockTx[blocktrailKey])
826
            });
827
828
            assert.ok("total" in output);
829
            cb();
830
831
        })
832
    })
833
834
})
835
836
837
838
839