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

Commit 906b255

Browse files
committed
add tests for new method filteredTxsHash, all test passed
1 parent 070814b commit 906b255

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

test/block/merkleblock.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,36 @@ describe('MerkleBlock', function() {
152152

153153
});
154154

155+
describe('#filterdTxsHash', function() {
156+
157+
it('should validate good merkleblocks', function() {
158+
var hashOfFilteredTx = '6f64fd5aa9dd01f74c03656d376625cf80328d83d9afebe60cc68b8f0e245bd9'
159+
var b = MerkleBlock(data.JSON[3]);
160+
b.filterdTxsHash()[0].should.equal(hashOfFilteredTx);
161+
});
162+
163+
it('should fail with merkleblocks with too many hashes', function() {
164+
var b = MerkleBlock(data.JSON[0]);
165+
// Add too many hashes
166+
var i = 0;
167+
while(i <= b.numTransactions) {
168+
b.hashes.push('bad' + i++);
169+
}
170+
(function() {
171+
b.filterdTxsHash();
172+
}).should.throw('This MerkleBlock contain an invalid Merkle Tree');
173+
});
174+
175+
it('should fail with merkleblocks with too few bit flags', function() {
176+
var b = MerkleBlock(JSON.parse(blockJSON));
177+
b.flags.pop();
178+
(function() {
179+
b.filterdTxsHash();
180+
}).should.throw('This MerkleBlock contain an invalid Merkle Tree');
181+
});
182+
183+
});
184+
155185
describe('#hasTransaction', function() {
156186

157187
it('should find transactions via hash string', function() {

test/data/merkleblocks.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,34 @@ module.exports = {
453453
nonce : 322045839,
454454
bits : 419587686,
455455
}
456+
},
457+
{ // Mainnet FilteredBlock 399775 with filter: 6f64fd5aa9dd01f74c03656d376625cf80328d83d9afebe60cc68b8f0e245bd9
458+
"header": {
459+
"hash": "0000000000000000011b04bc9f4f3856e299b53a335eb1c42be906237c860bb8",
460+
"version": 4,
461+
"prevHash": "0000000000000000015373947aa93c7cb16a308fb0a59644d4123072ad24ce5b",
462+
"merkleRoot": "ac1841eb3b7d380ee114270e3b1c7df349f1e27e2f0f7891138199bc07e006f8",
463+
"time": 1456274787,
464+
"bits": 403093919,
465+
"nonce": 736568686
466+
},
467+
"numTransactions": 3309,
468+
"hashes": [
469+
"adaf1e41a5349a7e2b27e6f2b5fc1186d576d21b47531a410a654439f49bd5a9",
470+
"0f64562b6d361757bfdc5926d28cafb7c45e4822b4ad5a14e65530d0c9d44cd2",
471+
"c34dec8d5954d8c151c3a594a5a6d1f3a1ec8a1a6c470b27aea879b7757328fb",
472+
"c044e5d998fe29cdbe88f87c97c3547f142f5b491cb909d9b0a8e9d3ab7fc984",
473+
"51ecd2d2b02b0ca1a3b439eae3adf87ab37dd87f7be0c5b3437cd22350079101",
474+
"684ebe37c6eaae2879249ff20b3769d5f2f7ad853a5363a4baee68c0c85777a5",
475+
"e561fbeb0faff42f95f2dc8d57d432d4d1a9f84483597a0602e1edc3390f1e33",
476+
"02c070afc743c885a6c8d94d15d6e9c3b991c636b4284258dd37686c8792fe44",
477+
"6f64fd5aa9dd01f74c03656d376625cf80328d83d9afebe60cc68b8f0e245bd9",
478+
"a296fef97b3da0825bac00c794ea234913421b7c1cbb8571978d8d5ba3b16de2",
479+
"691c6855c5da434a06cb39a7e47d9337da0e39112ad975cc70cecc882233920a",
480+
"6a9e7f8e6d1d8c326a774ff691bdf424252cee710f8e5d9da2c094e999c15efc",
481+
"0723ffc695fef989e86784fa2b47097d55f6aac244631536d8d901f5cd9bf170"
482+
],
483+
"flags": [171,86,23,0]
456484
}
457485
]
458486
};

0 commit comments

Comments
 (0)