| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 202 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
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:
If many parameters/temporary variables are present:
| 1 | /* jshint -W101, -W098 */  | 
            ||
| 66 | describe('data api', function() { | 
            ||
| 67 |     it('test address', function(cb) { | 
            ||
| 68 |         client.address("3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief", function(err, address) { | 
            ||
| 69 | assert.ifError(err);  | 
            ||
| 70 | assert.ok(address['address']);  | 
            ||
| 71 | assert.equal(address['address'], '3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief');  | 
            ||
| 72 | |||
| 73 | // trim off deprecated fields  | 
            ||
| 74 | delete address.category;  | 
            ||
| 75 | delete address.tag;  | 
            ||
| 76 | delete address.first_seen;  | 
            ||
| 77 | delete address.last_seen;  | 
            ||
| 78 | delete address.total_transactions_in;  | 
            ||
| 79 | delete address.total_transactions_out;  | 
            ||
| 80 | delete address.unconfirmed_utxos;  | 
            ||
| 81 | // trim off new fields  | 
            ||
| 82 | delete address.first_tx;  | 
            ||
| 83 | delete address.last_tx;  | 
            ||
| 84 | |||
| 85 | assert.deepEqual(  | 
            ||
| 86 | address,  | 
            ||
| 87 |                 require('./test_data/address.3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief') | 
            ||
| 88 | );  | 
            ||
| 89 | |||
| 90 | cb();  | 
            ||
| 91 | });  | 
            ||
| 92 | });  | 
            ||
| 93 |     it('test addressTransactions', function(cb) { | 
            ||
| 94 |         client.addressTransactions("3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief", {limit: 20}, function(err, address_txs) { | 
            ||
| 95 | assert.ifError(err);  | 
            ||
| 96 | |||
| 97 | assert.ok(address_txs['data']);  | 
            ||
| 98 | assert.ok(address_txs['total']);  | 
            ||
| 99 | |||
| 100 |             var expected = require('./test_data/addressTxs.3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief'); | 
            ||
| 101 |             var expectedTxMap = {}; | 
            ||
| 102 |             expected.data.forEach(function(tx) { | 
            ||
| 103 | cleanTx(tx);  | 
            ||
| 104 | expectedTxMap[tx.hash] = tx;  | 
            ||
| 105 | });  | 
            ||
| 106 | |||
| 107 |             address_txs.data.forEach(function(tx) { | 
            ||
| 108 | cleanTx(tx);  | 
            ||
| 109 | assert.deepEqual(tx, expectedTxMap[tx.hash]);  | 
            ||
| 110 | });  | 
            ||
| 111 | |||
| 112 | cb();  | 
            ||
| 113 | });  | 
            ||
| 114 | });  | 
            ||
| 115 |     it('test addressUnconfirmedTransactions', function(cb) { | 
            ||
| 116 |         client.addressUnconfirmedTransactions("1dice8EMZmqKvrGE4Qc9bUFf9PX3xaYDp", {limit: 23}, function(err, address_txs) { | 
            ||
| 117 | assert.ifError(err);  | 
            ||
| 118 |             assert.ok('data' in address_txs); | 
            ||
| 119 |             assert.ok('total' in address_txs); | 
            ||
| 120 | assert.ok(address_txs['total'] >= address_txs['data'].length);  | 
            ||
| 121 | |||
| 122 | cb();  | 
            ||
| 123 | });  | 
            ||
| 124 | });  | 
            ||
| 125 |     it('test addressUnspentOutputs', function(cb) { | 
            ||
| 126 |         client.addressUnspentOutputs("16dwJmR4mX5RguGrocMfN9Q9FR2kZcLw2z", {limit: 23}, function(err, address_utxo) { | 
            ||
| 127 | assert.ifError(err);  | 
            ||
| 128 |             assert.ok('data' in address_utxo); | 
            ||
| 129 |             assert.ok('total' in address_utxo); | 
            ||
| 130 | assert.ok(address_utxo['total'] >= address_utxo['data'].length);  | 
            ||
| 131 | |||
| 132 | cb();  | 
            ||
| 133 | });  | 
            ||
| 134 | });  | 
            ||
| 135 |     it('test batchAddressUnspentOutputs', function(cb) { | 
            ||
| 136 | this.skip();  | 
            ||
| 137 | |||
| 138 |         client.batchAddressUnspentOutputs(["16dwJmR4mX5RguGrocMfN9Q9FR2kZcLw2z", "16fVUD4yCuabS153FJGtmLL8tgydsrf6vu"], {limit: 23}, function(err, address_utxo) { | 
            ||
| 139 | assert.ifError(err);  | 
            ||
| 140 |             assert.ok('data' in address_utxo); | 
            ||
| 141 |             assert.ok('total' in address_utxo); | 
            ||
| 142 | assert.ok(address_utxo['total'] >= address_utxo['data'].length);  | 
            ||
| 143 | cb();  | 
            ||
| 144 | });  | 
            ||
| 145 | });  | 
            ||
| 146 |     it('test verifyAddress', function(cb) { | 
            ||
| 147 | this.skip(); // @TODO: client side  | 
            ||
| 148 | |||
| 149 |         client.verifyAddress("16dwJmR4mX5RguGrocMfN9Q9FR2kZcLw2z", "HPMOHRgPSMKdXrU6AqQs/i9S7alOakkHsJiqLGmInt05Cxj6b/WhS7kJxbIQxKmDW08YKzoFnbVZIoTI2qofEzk=", function(err, result) { | 
            ||
| 150 | assert.ifError(err);  | 
            ||
| 151 | assert.ok(result);  | 
            ||
| 152 | |||
| 153 | cb();  | 
            ||
| 154 | });  | 
            ||
| 155 | });  | 
            ||
| 156 |     it('test block by hash', function(cb) { | 
            ||
| 157 |         client.block("000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf", function(err, block) { | 
            ||
| 158 | assert.ifError(err);  | 
            ||
| 159 | assert.ok(block['hash']);  | 
            ||
| 160 | assert.equal(block['hash'], '000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf');  | 
            ||
| 161 | |||
| 162 |             var expected = require('./test_data/block.000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf'); | 
            ||
| 163 | |||
| 164 | cleanBlock(block);  | 
            ||
| 165 | cleanBlock(expected);  | 
            ||
| 166 | |||
| 167 | assert.deepEqual(block, expected);  | 
            ||
| 168 | |||
| 169 | cb();  | 
            ||
| 170 | });  | 
            ||
| 171 | });  | 
            ||
| 172 |     it('test block by height', function(cb) { | 
            ||
| 173 |         client.block(200000, function(err, block) { | 
            ||
| 174 | assert.ifError(err);  | 
            ||
| 175 | assert.ok(block['hash']);  | 
            ||
| 176 | assert.equal(block['hash'], '000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf');  | 
            ||
| 177 | |||
| 178 | cb();  | 
            ||
| 179 | });  | 
            ||
| 180 | });  | 
            ||
| 181 |     it('test blockTransactions', function(cb) { | 
            ||
| 182 |         client.blockTransactions("000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf", {limit: 23}, function(err, block_txs) { | 
            ||
| 183 | assert.ifError(err);  | 
            ||
| 184 | assert.ok(block_txs['data']);  | 
            ||
| 185 | assert.ok(block_txs['total']);  | 
            ||
| 186 | assert.ok(block_txs['data'].length === 23);  | 
            ||
| 187 | |||
| 188 | cb();  | 
            ||
| 189 | });  | 
            ||
| 190 | });  | 
            ||
| 191 |     it('test allBlocks', function(cb) { | 
            ||
| 192 | this.skip(); // @TODO  | 
            ||
| 193 | |||
| 194 |         client.allBlocks({page: 2, limit: 23, sort_dir: 'asc'}, function(err, blocks) { | 
            ||
| 195 | assert.ifError(err);  | 
            ||
| 196 | assert.ok(blocks['data']);  | 
            ||
| 197 | assert.ok(blocks['total']);  | 
            ||
| 198 | assert.ok(blocks['data'].length === 23);  | 
            ||
| 199 | assert.equal(blocks['data'][0]['hash'], '000000000cd339982e556dfffa9de94744a4135c53eeef15b7bcc9bdeb9c2182');  | 
            ||
| 200 | assert.equal(blocks['data'][1]['hash'], '00000000fc051fbbce89a487e811a5d4319d209785ea4f4b27fc83770d1e415f');  | 
            ||
| 201 | |||
| 202 | cb();  | 
            ||
| 203 | });  | 
            ||
| 204 | });  | 
            ||
| 205 |     it('test blockLatest', function(cb) { | 
            ||
| 206 |         client.blockLatest(function(err, block) { | 
            ||
| 207 | assert.ifError(err);  | 
            ||
| 208 | assert.ok(block['hash']);  | 
            ||
| 209 | |||
| 210 | cb();  | 
            ||
| 211 | });  | 
            ||
| 212 | });  | 
            ||
| 213 |     it('test coinbase transaction', function(cb) { | 
            ||
| 214 |         client.transaction("0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098", function(err, tx) { | 
            ||
| 215 | assert.ifError(err);  | 
            ||
| 216 | assert.equal(tx['hash'], "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098");  | 
            ||
| 217 | assert.equal(tx['enough_fee'], null);  | 
            ||
| 218 | |||
| 219 | cb();  | 
            ||
| 220 | });  | 
            ||
| 221 | });  | 
            ||
| 222 |     it('test tx 95740451ac22f63c42c0d1b17392a0bf02983176d6de8dd05d6f06944d93e615', function(cb) { | 
            ||
| 223 |         client.transaction("95740451ac22f63c42c0d1b17392a0bf02983176d6de8dd05d6f06944d93e615", function(err, tx) { | 
            ||
| 224 | assert.ifError(err);  | 
            ||
| 225 | assert.equal(tx['hash'], "95740451ac22f63c42c0d1b17392a0bf02983176d6de8dd05d6f06944d93e615");  | 
            ||
| 226 | |||
| 227 |             var expected = require('./test_data/tx.95740451ac22f63c42c0d1b17392a0bf02983176d6de8dd05d6f06944d93e615'); | 
            ||
| 228 | cleanTx(expected);  | 
            ||
| 229 | cleanTx(tx);  | 
            ||
| 230 | |||
| 231 | assert.deepEqual(tx, expected);  | 
            ||
| 232 | |||
| 233 | cb();  | 
            ||
| 234 | });  | 
            ||
| 235 | });  | 
            ||
| 236 |     it('test batch transactions', function(cb) { | 
            ||
| 237 | client.transactions([  | 
            ||
| 238 | "c791b82ed9af681b73eadb7a05b67294c1c3003e52d01e03775bfb79d4ac58d1",  | 
            ||
| 239 | "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098",  | 
            ||
| 240 | "4bbe6feeb50e47e2de5ef6a9d7378363823611dd07d4a5ea1799da9ae6a21665",  | 
            ||
| 241 | "6c0d3156621051a86b8af3f23dfe211e8a17a01bffe3c2b24cbee65139873c6a",  | 
            ||
| 242 | "356210d6b8143e23d0cf4d0dae0ac686015a13fe3b2b46b1cc43a71a36c73355",  | 
            ||
| 243 | "a40d1eee0cec3d963d8df2870bd642bd3fd07163e864aeb90fa5efe9ea91c998",  | 
            ||
| 244 | "1c7e3c9823baa9bb70b09ed666e8a6b3120b07f84429ed41f05d5504bd58f188",  | 
            ||
| 245 | "1f0a168f0fceb6e48208b23ffb1ad528acfc11c30ab302d447743f2a0fc5fe80",  | 
            ||
| 246 | "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" // not found  | 
            ||
| 247 |         ], function(err, txs) { | 
            ||
| 248 | assert.ifError(err);  | 
            ||
| 249 | |||
| 250 | assert.equal(Object.keys(txs['data']).length, 8);  | 
            ||
| 251 | |||
| 252 | var tx1 = txs['data']["c791b82ed9af681b73eadb7a05b67294c1c3003e52d01e03775bfb79d4ac58d1"];  | 
            ||
| 253 | assert.equal(tx1['hash'], "c791b82ed9af681b73eadb7a05b67294c1c3003e52d01e03775bfb79d4ac58d1");  | 
            ||
| 254 | assert.ok(tx1['confirmations']);  | 
            ||
| 255 | |||
| 256 | var tx2 = txs['data']["0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"];  | 
            ||
| 257 | assert.equal(tx2['hash'], "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098");  | 
            ||
| 258 | |||
| 259 | var tx8 = txs['data']["1f0a168f0fceb6e48208b23ffb1ad528acfc11c30ab302d447743f2a0fc5fe80"];  | 
            ||
| 260 | assert.equal(tx8['hash'], "1f0a168f0fceb6e48208b23ffb1ad528acfc11c30ab302d447743f2a0fc5fe80");  | 
            ||
| 261 | |||
| 262 | assert.ok(!txs['data']['ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff']);  | 
            ||
| 263 | |||
| 264 | cb();  | 
            ||
| 265 | });  | 
            ||
| 266 | });  | 
            ||
| 267 | });  | 
            ||
| 268 | |||
| 269 |