Completed
Pull Request — master (#99)
by
unknown
01:16
created

api_client.test.js ➔ ... ➔ it(ꞌtest addressꞌ)   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
dl 0
loc 26
rs 8.8571
nop 1
1
/* jshint -W101, -W098 */
2
var blocktrail = require('../');
3
var assert = require('assert');
4
var crypto = require('crypto');
5
6
/**
7
 * @type APIClient
8
 */
9
var client = blocktrail.BlocktrailSDK({
10
    apiKey: process.env.BLOCKTRAIL_SDK_APIKEY || "EXAMPLE_BLOCKTRAIL_SDK_NODEJS_APIKEY",
11
    apiSecret: process.env.BLOCKTRAIL_SDK_APISECRET || "EXAMPLE_BLOCKTRAIL_SDK_NODEJS_APISECRET",
12
    btccom: typeof process.env.BLOCKTRAIL_SDK_BTCCOM !== "undefined" ? JSON.parse(process.env.BLOCKTRAIL_SDK_BTCCOM) : true
13
});
14
15
var cleanTx = function(tx) {
16
    [
17
        'block_hash', // @TODO
18
        'confirmations', 'estimated_change', 'estimated_change_address', 'estimated_value',
19
        'is_coinbase', 'time', 'version', 'weight', 'witness_hash', 'is_double_spend', 'is_sw_tx',
20
        'sigops', 'lock_time', 'contains_dust', 'double_spend_in', 'enough_fee', 'first_seen_at',
21
        'last_seen_at', 'high_priority', 'unconfirmed_inputs'
22
    ].forEach(function(prop) {
23
        delete tx[prop];
24
    });
25
26
    tx.inputs.forEach(function(txin) {
27
        cleanTxin(txin);
28
    });
29
30
    tx.outputs.forEach(function(txout) {
31
        cleanTxout(txout);
32
    });
33
};
34
35
var cleanTxin = function(txin) {
36
    delete txin.output_confirmed;
37
    delete txin.multisig;
38
    delete txin.multisig_addresses;
39
};
40
41
var cleanTxout = function(txout) {
42
    if (txout.type === 'witnessscripthash') {
43
        txout.type = 'unknown';
44
        txout.address = null;
45
    }
46
47
    if (!txout.spent_hash) {
48
        txout.spent_index = -1;
49
    }
50
51
    delete txout.multisig;
52
    delete txout.multisig_addresses;
53
};
54
55
var cleanBlock = function(block) {
56
    delete block.confirmations;
57
    delete block.is_sw_block;
58
    delete block.created_at;
59
    delete block.bits;
60
    delete block.reward_block;
61
    delete block.reward_fees;
62
    delete block.weight;
63
    delete block.value;
64
}
65
66
describe('SDK general', function() {
67
    it('test Coin Value', function(cb) {
68
        assert.equal(blocktrail.toSatoshi(0.00000001), 1);
69
        assert.equal(blocktrail.toBTC(100000000), 1.0);
70
71
        assert.equal(blocktrail.toSatoshi(1.23456789), 123456789);
72
        assert.equal(blocktrail.toBTC(123456789), 1.23456789);
73
74
        cb();
75
    });
76
    it('test auth failure', function(cb) {
77
        var client = blocktrail.BlocktrailSDK({
78
            apiKey: "TESTKEY-FAIL",
79
            apiSecret: "TESTSECRET-FAIL"
80
        });
81
82
        client.address("1dice8EMZmqKvrGE4Qc9bUFf9PX3xaYDp", function(err, address) {
0 ignored issues
show
Unused Code introduced by
The parameter address is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
83
            assert.ok(err);
84
85
            cb();
86
        });
87
    });
88
});
89
90
describe('data api', function() {
91
    it('test address', function(cb) {
92
        client.address("3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief", function(err, address) {
93
            assert.ifError(err);
94
            assert.ok(address['address']);
95
            assert.equal(address['address'], '3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief');
96
97
            // trim off deprecated fields
98
            delete address.category;
99
            delete address.tag;
100
            delete address.first_seen;
101
            delete address.last_seen;
102
            delete address.total_transactions_in;
103
            delete address.total_transactions_out;
104
            delete address.unconfirmed_utxos;
105
            // trim off new fields
106
            delete address.first_tx;
107
            delete address.last_tx;
108
109
            assert.deepEqual(
110
                address,
111
                require('./test_data/address.3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief')
112
            );
113
114
            cb();
115
        });
116
    });
117
    it('test addressTransactions', function(cb) {
118
        client.addressTransactions("3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief", {limit: 20}, function(err, address_txs) {
119
            assert.ifError(err);
120
121
            assert.ok(address_txs['data']);
122
            assert.ok(address_txs['total']);
123
124
            var expected = require('./test_data/addressTxs.3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief');
125
            var expectedTxMap = {};
126
            expected.data.forEach(function(tx) {
127
                cleanTx(tx);
128
                expectedTxMap[tx.hash] = tx;
129
            });
130
131
            address_txs.data.forEach(function(tx) {
132
                cleanTx(tx);
133
                assert.deepEqual(tx, expectedTxMap[tx.hash]);
134
            });
135
136
            cb();
137
        });
138
    });
139
    it('test addressUnconfirmedTransactions', function(cb) {
140
        client.addressUnconfirmedTransactions("1dice8EMZmqKvrGE4Qc9bUFf9PX3xaYDp", {limit: 23}, function(err, address_txs) {
141
            assert.ifError(err);
142
            assert.ok('data' in address_txs);
143
            assert.ok('total' in address_txs);
144
            assert.ok(address_txs['total'] >= address_txs['data'].length);
145
146
            cb();
147
        });
148
    });
149
    it('test addressUnspentOutputs', function(cb) {
150
        client.addressUnspentOutputs("16dwJmR4mX5RguGrocMfN9Q9FR2kZcLw2z", {limit: 23}, function(err, address_utxo) {
151
            assert.ifError(err);
152
            assert.ok('data' in address_utxo);
153
            assert.ok('total' in address_utxo);
154
            assert.ok(address_utxo['total'] >= address_utxo['data'].length);
155
156
            cb();
157
        });
158
    });
159
    it('test batchAddressUnspentOutputs', function(cb) {
160
        this.skip();
161
162
        client.batchAddressUnspentOutputs(["16dwJmR4mX5RguGrocMfN9Q9FR2kZcLw2z", "16fVUD4yCuabS153FJGtmLL8tgydsrf6vu"], {limit: 23}, function(err, address_utxo) {
163
            assert.ifError(err);
164
            assert.ok('data' in address_utxo);
165
            assert.ok('total' in address_utxo);
166
            assert.ok(address_utxo['total'] >= address_utxo['data'].length);
167
            cb();
168
        });
169
    });
170
    it('test verifyAddress', function(cb) {
171
        this.skip(); // @TODO: client side
172
173
        client.verifyAddress("16dwJmR4mX5RguGrocMfN9Q9FR2kZcLw2z", "HPMOHRgPSMKdXrU6AqQs/i9S7alOakkHsJiqLGmInt05Cxj6b/WhS7kJxbIQxKmDW08YKzoFnbVZIoTI2qofEzk=", function(err, result) {
174
            assert.ifError(err);
175
            assert.ok(result);
176
177
            cb();
178
        });
179
    });
180
    it('test block by hash', function(cb) {
181
        client.block("000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf", function(err, block) {
182
            assert.ifError(err);
183
            assert.ok(block['hash']);
184
            assert.equal(block['hash'], '000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf');
185
186
            var expected = require('./test_data/block.000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf');
187
188
            cleanBlock(block);
189
            cleanBlock(expected);
190
191
            assert.deepEqual(block, expected);
192
193
            cb();
194
        });
195
    });
196
    it('test block by height', function(cb) {
197
        client.block(200000, function(err, block) {
198
            assert.ifError(err);
199
            assert.ok(block['hash']);
200
            assert.equal(block['hash'], '000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf');
201
202
            cb();
203
        });
204
    });
205
    it('test blockTransactions', function(cb) {
206
        client.blockTransactions("000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf", {limit: 23}, function(err, block_txs) {
207
            assert.ifError(err);
208
            assert.ok(block_txs['data']);
209
            assert.ok(block_txs['total']);
210
            assert.ok(block_txs['data'].length === 23);
211
212
            cb();
213
        });
214
    });
215
    it('test allBlocks', function(cb) {
216
        this.skip(); // @TODO
217
218
        client.allBlocks({page: 2, limit: 23, sort_dir: 'asc'}, function(err, blocks) {
219
            assert.ifError(err);
220
            assert.ok(blocks['data']);
221
            assert.ok(blocks['total']);
222
            assert.ok(blocks['data'].length === 23);
223
            assert.equal(blocks['data'][0]['hash'], '000000000cd339982e556dfffa9de94744a4135c53eeef15b7bcc9bdeb9c2182');
224
            assert.equal(blocks['data'][1]['hash'], '00000000fc051fbbce89a487e811a5d4319d209785ea4f4b27fc83770d1e415f');
225
226
            cb();
227
        });
228
    });
229
    it('test blockLatest', function(cb) {
230
        client.blockLatest(function(err, block) {
231
            assert.ifError(err);
232
            assert.ok(block['hash']);
233
234
            cb();
235
        });
236
    });
237
    it('test coinbase transaction', function(cb) {
238
        client.transaction("0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098", function(err, tx) {
239
            assert.ifError(err);
240
            assert.equal(tx['hash'], "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098");
241
            assert.equal(tx['enough_fee'], null);
242
243
            cb();
244
        });
245
    });
246
    it('test tx 95740451ac22f63c42c0d1b17392a0bf02983176d6de8dd05d6f06944d93e615', function(cb) {
247
        client.transaction("95740451ac22f63c42c0d1b17392a0bf02983176d6de8dd05d6f06944d93e615", function(err, tx) {
248
            assert.ifError(err);
249
            assert.equal(tx['hash'], "95740451ac22f63c42c0d1b17392a0bf02983176d6de8dd05d6f06944d93e615");
250
251
            var expected = require('./test_data/tx.95740451ac22f63c42c0d1b17392a0bf02983176d6de8dd05d6f06944d93e615');
252
            cleanTx(expected);
253
            cleanTx(tx);
254
255
            assert.deepEqual(tx, expected);
256
257
            cb();
258
        });
259
    });
260
    it('test batch transactions', function(cb) {
261
        client.transactions([
262
            "c791b82ed9af681b73eadb7a05b67294c1c3003e52d01e03775bfb79d4ac58d1",
263
            "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098",
264
            "4bbe6feeb50e47e2de5ef6a9d7378363823611dd07d4a5ea1799da9ae6a21665",
265
            "6c0d3156621051a86b8af3f23dfe211e8a17a01bffe3c2b24cbee65139873c6a",
266
            "356210d6b8143e23d0cf4d0dae0ac686015a13fe3b2b46b1cc43a71a36c73355",
267
            "a40d1eee0cec3d963d8df2870bd642bd3fd07163e864aeb90fa5efe9ea91c998",
268
            "1c7e3c9823baa9bb70b09ed666e8a6b3120b07f84429ed41f05d5504bd58f188",
269
            "1f0a168f0fceb6e48208b23ffb1ad528acfc11c30ab302d447743f2a0fc5fe80",
270
            "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" // not found
271
        ], function(err, txs) {
272
            assert.ifError(err);
273
274
            assert.equal(Object.keys(txs['data']).length, 8);
275
276
            var tx1 = txs['data']["c791b82ed9af681b73eadb7a05b67294c1c3003e52d01e03775bfb79d4ac58d1"];
277
            assert.equal(tx1['hash'], "c791b82ed9af681b73eadb7a05b67294c1c3003e52d01e03775bfb79d4ac58d1");
278
            assert.ok(tx1['confirmations']);
279
280
            var tx2 = txs['data']["0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"];
281
            assert.equal(tx2['hash'], "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098");
282
283
            var tx8 = txs['data']["1f0a168f0fceb6e48208b23ffb1ad528acfc11c30ab302d447743f2a0fc5fe80"];
284
            assert.equal(tx8['hash'], "1f0a168f0fceb6e48208b23ffb1ad528acfc11c30ab302d447743f2a0fc5fe80");
285
286
            assert.ok(!txs['data']['ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff']);
287
288
            cb();
289
        });
290
    });
291
});
292
293
describe('webhooks api', function() {
294
    var createdWebhooks = [];
295
    var cleanup = function(done) {
296
        client.allWebhooks({page:1, limit:500}, function(err, response) {
0 ignored issues
show
Unused Code introduced by
The parameter response is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter err is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
297
            //delete each webhook
298
            //var allWebhooks = response.data;
299
            if (!createdWebhooks.length) {
300
                done();
301
            }
302
            createdWebhooks.forEach(function(identifier) {
303
                client.deleteWebhook(identifier, function(err, response) {
0 ignored issues
show
Unused Code introduced by
The parameter response is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter err is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
304
                    createdWebhooks.splice(identifier, 1);
305
                    if (createdWebhooks.length === 0) {
306
                        done();
307
                    }
308
                });
309
            });
310
        });
311
    };
312
    before(function(done) {
313
        // runs before all tests in this block..cleanup any existing data that could conflict with the tests
314
        cleanup(done);
315
    });
316
    after(function(done) {
317
        //cleanup after all tests
318
        cleanup(done);
319
    });
320
321
    //create a custom (yet "random") identifier such to avoid conflicts when running multiple tests simultaneously
322
    var myIdentifier = crypto.randomBytes(24).toString('hex');
323
324
    // test cases
325
    it('create new webhook with custom identifier', function(done) {
326
        client.setupWebhook("https://www.blocktrail.com/webhook-test", myIdentifier, function(err, webhook) {
327
            assert.ifError(err);
328
            assert.equal(webhook.url, "https://www.blocktrail.com/webhook-test");
329
            assert.equal(webhook.identifier, myIdentifier);
330
            createdWebhooks.push(webhook.identifier);
331
            done();
332
        });
333
    });
334
335
    it('create new webhook with random identifier', function(done) {
336
        client.setupWebhook("https://www.blocktrail.com/webhook-test", function(err, webhook) {
337
            assert.ifError(err);
338
            assert.equal(webhook.url, "https://www.blocktrail.com/webhook-test");
339
            assert.ok(webhook.identifier);
340
            createdWebhooks.push(webhook.identifier);
341
            done();
342
        });
343
    });
344
345
    it('get all user webhooks', function(done) {
346
        client.allWebhooks(null, function(err, response) {
347
            assert.ifError(err);
348
            assert.ok('data' in response, "'data' key not in response");
349
            assert.ok('total' in response, "'total' key not in response");
350
            assert.ok(parseInt(response['total']) >= 2, "'total' does not match expected value");
351
            assert.ok(response['data'].length >= 2, "Count of webhooks returned is not equal to 2");
352
353
            assert.ok('url' in response['data'][0], "'url' key not in first webhook of response");
354
            assert.ok('url' in response['data'][1], "'url' key not in second webhook of response");
355
            done();
356
        });
357
    });
358
359
    it('get a single webhook', function(done) {
360
        client.getWebhook(createdWebhooks[0], function(err, response) {
361
            assert.ifError(err);
362
            assert.ok('url' in response, "'url' key not in response");
363
            assert.ok('identifier' in response, "'identifier' key not in response");
364
            assert.equal(response['url'], "https://www.blocktrail.com/webhook-test", "'url' does not match expected value");
365
            assert.equal(response['identifier'], myIdentifier, "'identifier' does not match expected value");
366
            done();
367
        });
368
    });
369
370
    it('delete a webhook', function(done) {
371
        client.deleteWebhook(createdWebhooks[0], function(err, response) {
372
            assert.ifError(err);
373
            assert.ok(response);
374
            done();
375
        });
376
    });
377
378
    it('update a webhook', function(done) {
379
        var newIdentifier = crypto.randomBytes(24).toString('hex');
380
        var newUrl = "https://www.blocktrail.com/new-webhook-url";
381
        client.updateWebhook(createdWebhooks[1], {identifier: newIdentifier, url: newUrl}, function(err, response) {
382
            assert.ifError(err);
383
            assert.ok('url' in response, "'url' key not in response");
384
            assert.ok('identifier' in response, "'identifier' key not in response");
385
            assert.equal(response['url'], newUrl, "'url' does not match expected value");
386
            assert.equal(response['identifier'], newIdentifier, "'identifier' does not match expected value");
387
388
            createdWebhooks[1] = newIdentifier;
389
            done();
390
        });
391
    });
392
393
    it('subscribe to address-transaction events', function(done) {
394
        var address = "1dice8EMZmqKvrGE4Qc9bUFf9PX3xaYDp";
395
        client.subscribeAddressTransactions(createdWebhooks[1], address, 2, function(err, response) {
396
            assert.ifError(err);
397
            assert.ok('event_type' in response, "'event_type' key not in response");
398
            assert.ok('address' in response, "'address' key not in response");
399
            assert.ok('confirmations' in response, "'confirmations' key not in response");
400
            assert.equal(response['event_type'], "address-transactions", "'event_type' does not match expected value");
401
            assert.equal(response['address'], address, "'address' does not match expected value");
402
            assert.equal(response['confirmations'], 2, "'confirmations' does not match expected value");
403
            done();
404
        });
405
    });
406
407
    it('subscribe to transaction event', function(done) {
408
        var transaction = "a0a87b1577d606b349cfded85c842bdc53b99bcd49614229a71804b46b1c27cc";
409
        client.subscribeTransaction(createdWebhooks[1], transaction, 2, function(err, response) {
410
            assert.ifError(err);
411
            assert.ok('event_type' in response, "'event_type' key not in response");
412
            assert.ok('address' in response, "'address' key not in response");
413
            assert.ok('confirmations' in response, "'confirmations' key not in response");
414
            assert.equal(response['event_type'], "transaction", "'event_type' does not match expected value");
415
            assert.equal(response['transaction'], transaction, "'transaction' does not match expected value");
416
            assert.equal(response['confirmations'], 2, "'confirmations' does not match expected value");
417
            done();
418
        });
419
    });
420
421
    it('subscribe to new block events', function(done) {
422
        client.subscribeNewBlocks(createdWebhooks[1], function(err, response) {
423
            assert.ifError(err);
424
            assert.ok('event_type' in response, "'event_type' key not in response");
425
            assert.ok('address' in response, "'address' key not in response");
426
            assert.ok('confirmations' in response, "'confirmations' key not in response");
427
            assert.equal(response['event_type'], "block", "'event_type' does not match expected value");
428
            assert.equal(response['address'], null, "'address' does not match expected value");
429
            assert.equal(response['confirmations'], null, "'confirmations' does not match expected value");
430
            done();
431
        });
432
    });
433
434
    it('batch subscribe to address-transaction events', function(done) {
435
        var batchData = [
436
            {
437
                'event_type': 'address-transactions',
438
                'address': '18FA8Tn54Hu8fjn7kkfAygPoGEJLHMbHzo',
439
                'confirmations': 1
440
            },
441
            {
442
                'address': '1LUCKYwD6V9JHVXAFEEjyQSD4Dj5GLXmte',
443
                'confirmations': 1
444
            },
445
            {
446
                'address': '1qMBuZnrmGoAc2MWyTnSgoLuWReDHNYyF'
447
            }
448
        ];
449
        client.batchSubscribeAddressTransactions(createdWebhooks[1], batchData, function(err, response) {
450
            assert.ifError(err);
451
            assert.ok(response);
452
            done();
453
        });
454
    });
455
456
    it('get webhook event subscriptions', function(done) {
457
        client.getWebhookEvents(createdWebhooks[1], function(err, response) {
458
            assert.ifError(err);
459
            assert.ok('data' in response, "'data' key not in response");
460
            assert.ok('total' in response, "'total' key not in response");
461
            assert.equal(parseInt(response['total']), 6, "'total' does not match expected value");
462
            assert.equal(response['data'].length, 6, "Count of event subscriptions returned is not equal to 2");
463
464
            assert.ok('event_type' in response['data'][0], "'event_type' key not in first event subscription of response");
465
466
            done();
467
        });
468
    });
469
470
    it('unsubscribe from address-transaction events', function(done) {
471
        var address = "1dice8EMZmqKvrGE4Qc9bUFf9PX3xaYDp";
472
        client.unsubscribeAddressTransactions(createdWebhooks[1], address, function(err, response) {
473
            assert.ifError(err);
474
            assert.ok(response);
475
            done();
476
        });
477
    });
478
479
    it('unsubscribe from new transaction events', function(done) {
480
        var transaction = "a0a87b1577d606b349cfded85c842bdc53b99bcd49614229a71804b46b1c27cc";
481
        client.unsubscribeTransaction(createdWebhooks[1], transaction, function(err, response) {
482
            assert.ifError(err);
483
            assert.ok(response);
484
            done();
485
        });
486
    });
487
488
    it('unsubscribe from new block events', function(done) {
489
        client.unsubscribeNewBlocks(createdWebhooks[1], function(err, response) {
490
            assert.ifError(err);
491
            assert.ok(response);
492
            done();
493
        });
494
    });
495
});
496
497
describe('market api', function() {
498
    it('should have a price', function(done) {
499
        client.price(function(err, price) {
500
            assert.ifError(err);
501
            assert.ok(price);
502
            assert.ok(price['USD']);
503
            done();
504
        });
505
    });
506
});
507
508
describe('verify message', function() {
509
    var address = "1F26pNMrywyZJdr22jErtKcjF8R3Ttt55G";
510
    var message = address;
511
    var signature = "H85WKpqtNZDrajOnYDgUY+abh0KCAcOsAIOQwx2PftAbLEPRA7mzXA/CjXRxzz0MC225pR/hx02Vf2Ag2x33kU4=";
512
513
    it('should verify using bitcoinjs-lib', function(done) {
514
        client.verifyMessage(message, address, signature, function(err, result) {
515
            assert.ifError(err);
516
            assert.ok(result);
517
            done();
518
        });
519
    });
520
521
    it('should handle errors nicely', function(done) {
522
        signature = "rubensayshi";
523
        client.verifyMessage(message, address, signature, function(err, result) {
0 ignored issues
show
Unused Code introduced by
The parameter result is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
524
            assert.ok(err);
525
            done();
526
        });
527
    });
528
529
    it('should verify using API', function(done) {
530
        client.client.post("/verify_message", null, {message: message, address: address, signature: signature}, function(err, result) {
531
            assert.ifError(err);
532
            assert.ok(result);
533
            done();
534
        });
535
    });
536
});
537
538
describe('send raw', function() {
539
    /**
540
     * @type APIClient
541
     */
542
    var client = blocktrail.BlocktrailSDK({
543
        apiKey : process.env.BLOCKTRAIL_SDK_APIKEY || "EXAMPLE_BLOCKTRAIL_SDK_NODEJS_APIKEY",
544
        apiSecret : process.env.BLOCKTRAIL_SDK_APISECRET || "EXAMPLE_BLOCKTRAIL_SDK_NODEJS_APISECRET",
545
        testnet : true
546
    });
547
548
    var tx = "0100000001bee92b36d3092e492e858d1199e46b942b3bddcc4c98071f0d307acced6f7751000000006b48304502210087831790820bf8218dc8df38758660a6f1f54a54d5d45ab0c3384e5ace9253ad0220650bce47447094148d45ec5b9ce4e3008e00723f4de6edd677110b2ebf0ff3da012102d8aa27d34020a6eb06e424787dbbb60f2cf4250a5a1110ab9e15e68fe710abc5ffffffff0131244c00000000001976a914a8d7a8e6724cf3f8ffb92c376ecb0094c18cbaf588ac00000000";
549
550
    // note that -27 (already in blockchain) is only when it's unspent
551
    it("should report TX is already in blockchain", function(done) {
552
        client.sendRawTransaction(tx, function(err, result) {
553
            assert.ok(err);
554
            assert.ok(result.code === -27 || result.code === -25);
555
556
            done();
557
        });
558
    });
559
560
    it('should error decode failed', function(done) {
561
        client.sendRawTransaction(tx.substr(-2), function(err, result) {
562
            assert.ok(err);
563
            assert.equal(-22, result.code);
564
565
            done();
566
        });
567
    });
568
});
569
570