Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.

Commit 8bb520d

Browse files
authored
Merge pull request #245 from renuzit/wrap-vars-in-before
Wrap mocha test vars in before()
2 parents 4157261 + 5cb8c32 commit 8bb520d

File tree

3 files changed

+66
-36
lines changed

3 files changed

+66
-36
lines changed

test/block/block.js

Lines changed: 27 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/block/blockheader.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,34 @@ var dataRawId = '000000000b99b16390660d79fcc138d2ad0c89a0d044c4201a02bdf1f61ffa1
1616
var data = require('../data/blk86756-testnet');
1717

1818
describe('BlockHeader', function() {
19-
20-
var version = data.version;
21-
var prevblockidbuf = new Buffer(data.prevblockidhex, 'hex');
22-
var merklerootbuf = new Buffer(data.merkleroothex, 'hex');
23-
var time = data.time;
24-
var bits = data.bits;
25-
var nonce = data.nonce;
26-
var bh = new BlockHeader({
27-
version: version,
28-
prevHash: prevblockidbuf,
29-
merkleRoot: merklerootbuf,
30-
time: time,
31-
bits: bits,
32-
nonce: nonce
19+
var version;
20+
var prevblockidbuf;
21+
var merklerootbuf;
22+
var time;
23+
var bits;
24+
var nonce;
25+
var bh;
26+
var bhhex;
27+
var bhbuf;
28+
29+
before(function () {
30+
version = data.version;
31+
prevblockidbuf = new Buffer(data.prevblockidhex, 'hex');
32+
merklerootbuf = new Buffer(data.merkleroothex, 'hex');
33+
time = data.time;
34+
bits = data.bits;
35+
nonce = data.nonce;
36+
bh = new BlockHeader({
37+
version: version,
38+
prevHash: prevblockidbuf,
39+
merkleRoot: merklerootbuf,
40+
time: time,
41+
bits: bits,
42+
nonce: nonce
43+
});
44+
bhhex = data.blockheaderhex;
45+
bhbuf = new Buffer(bhhex, 'hex');
3346
});
34-
var bhhex = data.blockheaderhex;
35-
var bhbuf = new Buffer(bhhex, 'hex');
3647

3748
it('should make a new blockheader', function() {
3849
BlockHeader(bhbuf).toBuffer().toString('hex').should.equal(bhhex);

test/block/merkleblock.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@ var transactionVector = require('../data/tx_creation');
1212

1313

1414
describe('MerkleBlock', function() {
15-
var blockhex = data.HEX[0];
16-
var blockbuf = new Buffer(blockhex,'hex');
17-
var blockJSON = JSON.stringify(data.JSON[0]);
18-
var blockObject = JSON.parse(JSON.stringify(data.JSON[0]));
15+
var blockhex;
16+
var blockbuf;
17+
var blockJSON;
18+
var blockObject;
19+
20+
before(function() {
21+
blockhex = data.HEX[0];
22+
blockbuf = new Buffer(blockhex,'hex');
23+
blockJSON = JSON.stringify(data.JSON[0]);
24+
blockObject = JSON.parse(JSON.stringify(data.JSON[0]));
25+
});
1926

2027
describe('#constructor', function() {
2128
it('should make a new merkleblock from buffer', function() {
@@ -155,7 +162,7 @@ describe('MerkleBlock', function() {
155162
describe('#filterdTxsHash', function() {
156163

157164
it('should validate good merkleblocks', function() {
158-
var hashOfFilteredTx = '6f64fd5aa9dd01f74c03656d376625cf80328d83d9afebe60cc68b8f0e245bd9'
165+
var hashOfFilteredTx = '6f64fd5aa9dd01f74c03656d376625cf80328d83d9afebe60cc68b8f0e245bd9'
159166
var b = MerkleBlock(data.JSON[3]);
160167
b.filterdTxsHash()[0].should.equal(hashOfFilteredTx);
161168
});
@@ -227,4 +234,3 @@ describe('MerkleBlock', function() {
227234
});
228235

229236
});
230-

0 commit comments

Comments
 (0)