Conditions | 1 |
Paths | 1 |
Total Lines | 195 |
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("3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief", {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 | client.batchAddressUnspentOutputs(["16dwJmR4mX5RguGrocMfN9Q9FR2kZcLw2z", "3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief"], {limit: 23}, function(err, address_utxo) { |
||
137 | console.log(address_utxo); |
||
|
|||
138 | assert.ifError(err); |
||
139 | assert.ok('data' in address_utxo); |
||
140 | assert.ok('total' in address_utxo); |
||
141 | assert.ok(address_utxo['total'] >= address_utxo['data'].length); |
||
142 | cb(); |
||
143 | }); |
||
144 | }); |
||
145 | it('test verifyAddress', function(cb) { |
||
146 | client.verifyAddress("16dwJmR4mX5RguGrocMfN9Q9FR2kZcLw2z", "HPMOHRgPSMKdXrU6AqQs/i9S7alOakkHsJiqLGmInt05Cxj6b/WhS7kJxbIQxKmDW08YKzoFnbVZIoTI2qofEzk=", function(err, result) { |
||
147 | assert.ifError(err); |
||
148 | assert.ok(result); |
||
149 | |||
150 | cb(); |
||
151 | }); |
||
152 | }); |
||
153 | it('test block by hash', function(cb) { |
||
154 | client.block("000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf", function(err, block) { |
||
155 | assert.ifError(err); |
||
156 | assert.ok(block['hash']); |
||
157 | assert.equal(block['hash'], '000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf'); |
||
158 | |||
159 | var expected = require('./test_data/block.000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf'); |
||
160 | |||
161 | cleanBlock(block); |
||
162 | cleanBlock(expected); |
||
163 | |||
164 | assert.deepEqual(block, expected); |
||
165 | |||
166 | cb(); |
||
167 | }); |
||
168 | }); |
||
169 | it('test block by height', function(cb) { |
||
170 | client.block(200000, function(err, block) { |
||
171 | assert.ifError(err); |
||
172 | assert.ok(block['hash']); |
||
173 | assert.equal(block['hash'], '000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf'); |
||
174 | |||
175 | cb(); |
||
176 | }); |
||
177 | }); |
||
178 | it('test blockTransactions', function(cb) { |
||
179 | client.blockTransactions("000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf", {limit: 23}, function(err, block_txs) { |
||
180 | assert.ifError(err); |
||
181 | assert.ok(block_txs['data']); |
||
182 | assert.ok(block_txs['total']); |
||
183 | assert.ok(block_txs['data'].length === 23); |
||
184 | |||
185 | cb(); |
||
186 | }); |
||
187 | }); |
||
188 | it('test allBlocks', function(cb) { |
||
189 | client.allBlocks({page: 2, limit: 23, sort_dir: 'asc'}, function(err, blocks) { |
||
190 | assert.ifError(err); |
||
191 | |||
192 | assert.ok(blocks['data']); |
||
193 | assert.ok(blocks['total']); |
||
194 | assert.ok(blocks['data'].length === 23); |
||
195 | |||
196 | cb(); |
||
197 | }); |
||
198 | }); |
||
199 | it('test blockLatest', function(cb) { |
||
200 | client.blockLatest(function(err, block) { |
||
201 | assert.ifError(err); |
||
202 | assert.ok(block['hash']); |
||
203 | |||
204 | cb(); |
||
205 | }); |
||
206 | }); |
||
207 | it('test coinbase transaction', function(cb) { |
||
208 | client.transaction("0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098", function(err, tx) { |
||
209 | assert.ifError(err); |
||
210 | assert.equal(tx['hash'], "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"); |
||
211 | assert.equal(tx['enough_fee'], null); |
||
212 | |||
213 | cb(); |
||
214 | }); |
||
215 | }); |
||
216 | it('test tx 95740451ac22f63c42c0d1b17392a0bf02983176d6de8dd05d6f06944d93e615', function(cb) { |
||
217 | client.transaction("95740451ac22f63c42c0d1b17392a0bf02983176d6de8dd05d6f06944d93e615", function(err, tx) { |
||
218 | assert.ifError(err); |
||
219 | assert.equal(tx['hash'], "95740451ac22f63c42c0d1b17392a0bf02983176d6de8dd05d6f06944d93e615"); |
||
220 | |||
221 | var expected = require('./test_data/tx.95740451ac22f63c42c0d1b17392a0bf02983176d6de8dd05d6f06944d93e615'); |
||
222 | cleanTx(expected); |
||
223 | cleanTx(tx); |
||
224 | |||
225 | assert.deepEqual(tx, expected); |
||
226 | |||
227 | cb(); |
||
228 | }); |
||
229 | }); |
||
230 | it('test batch transactions', function(cb) { |
||
231 | client.transactions([ |
||
232 | "c791b82ed9af681b73eadb7a05b67294c1c3003e52d01e03775bfb79d4ac58d1", |
||
233 | "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098", |
||
234 | "4bbe6feeb50e47e2de5ef6a9d7378363823611dd07d4a5ea1799da9ae6a21665", |
||
235 | "6c0d3156621051a86b8af3f23dfe211e8a17a01bffe3c2b24cbee65139873c6a", |
||
236 | "356210d6b8143e23d0cf4d0dae0ac686015a13fe3b2b46b1cc43a71a36c73355", |
||
237 | "a40d1eee0cec3d963d8df2870bd642bd3fd07163e864aeb90fa5efe9ea91c998", |
||
238 | "1c7e3c9823baa9bb70b09ed666e8a6b3120b07f84429ed41f05d5504bd58f188", |
||
239 | "1f0a168f0fceb6e48208b23ffb1ad528acfc11c30ab302d447743f2a0fc5fe80" |
||
240 | ], function(err, txs) { |
||
241 | assert.ifError(err); |
||
242 | |||
243 | assert.equal(Object.keys(txs['data']).length, 8); |
||
244 | |||
245 | var tx1 = txs['data']["c791b82ed9af681b73eadb7a05b67294c1c3003e52d01e03775bfb79d4ac58d1"]; |
||
246 | assert.equal(tx1['hash'], "c791b82ed9af681b73eadb7a05b67294c1c3003e52d01e03775bfb79d4ac58d1"); |
||
247 | assert.ok(tx1['confirmations']); |
||
248 | |||
249 | var tx2 = txs['data']["0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"]; |
||
250 | assert.equal(tx2['hash'], "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"); |
||
251 | |||
252 | var tx8 = txs['data']["1f0a168f0fceb6e48208b23ffb1ad528acfc11c30ab302d447743f2a0fc5fe80"]; |
||
253 | assert.equal(tx8['hash'], "1f0a168f0fceb6e48208b23ffb1ad528acfc11c30ab302d447743f2a0fc5fe80"); |
||
254 | |||
255 | assert.ok(!txs['data']['ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff']); |
||
256 | |||
257 | cb(); |
||
258 | }); |
||
259 | }); |
||
260 | }); |
||
261 | |||
262 |