MerkleBlock Tests

This commit is contained in:
William Wolf 2015-02-26 00:30:20 -08:00
parent b7473e7080
commit d6b89176f2
4 changed files with 18 additions and 4 deletions

View File

@ -316,7 +316,7 @@ function Inventory(inventory) {
}
util.inherits(Inventory, Message);
// https://en.bitcoin.it/wiki/Protocol_specification#Inventory_Vectors
// https://en.bitcoin.it/wiki/Protocol_specification#Inventory_Vectors
Inventory.TYPE = {};
Inventory.TYPE.ERROR = 0;
Inventory.TYPE.TX = 1;
@ -973,7 +973,7 @@ Buffers.prototype.skip = function(i) {
[Inventory, GetData, NotFound].forEach(function(clazz) {
clazz.forBlock = creatorForItem(clazz, Inventory.TYPE.BLOCK);
clazz.forFilteredBlock = creatorForItem(clazz, Inventory.TYPE.FILTERED_BLOCK);
clazz.forMerkleBlock = creatorForItem(clazz, Inventory.TYPE.FILTERED_BLOCK);
clazz.forFilteredBlock = clazz.forMerkleBlock =
creatorForItem(clazz, Inventory.TYPE.FILTERED_BLOCK);
clazz.forTransaction = creatorForItem(clazz, Inventory.TYPE.TX);
});

View File

@ -52,7 +52,7 @@
"url": "https://github.com/bitpay/bitcore-p2p.git"
},
"dependencies": {
"bitcore": "^0.10.2",
"bitcore": "^0.11.0",
"bloom-filter": "^0.1.1",
"bufferput": "^0.1.2",
"buffers": "^0.1.1",

View File

@ -77,5 +77,9 @@
"FILTERCLEAR": {
"message": "f9beb4d966696c7465726c6365617200000000005df6e0e2",
"payload": ""
},
"MERKLEBLOCK": {
"message": "f9beb4d96d65726b6c65626c6f636b00d7000000365913480100000082bb869cf3a793432a66e826e05a6fc37469f8efb7421dc880670100000000007f16c5962e8bd963659c793ce370d95f093bc7e367117b3c30c1f8fdd0d9728776381b4d4c86041b554b852907000000043612262624047ee87660be1a707519a443b1c1ce3d248cbfc6c15870f6c5daa2019f5b01d4195ecbc9398fbf3c3b1fa9bb3183301d7a1fb3bd174fcfa40a2b6541ed70551dd7e841883ab8f0b16bf04176b7d1480e4f0af9f3d4c3595768d06820d2a7bc994987302e5b1ac80fc425fe25f8b63169ea78e68fbaaefa59379bbf011d",
"payload": "0100000082bb869cf3a793432a66e826e05a6fc37469f8efb7421dc880670100000000007f16c5962e8bd963659c793ce370d95f093bc7e367117b3c30c1f8fdd0d9728776381b4d4c86041b554b852907000000043612262624047ee87660be1a707519a443b1c1ce3d248cbfc6c15870f6c5daa2019f5b01d4195ecbc9398fbf3c3b1fa9bb3183301d7a1fb3bd174fcfa40a2b6541ed70551dd7e841883ab8f0b16bf04176b7d1480e4f0af9f3d4c3595768d06820d2a7bc994987302e5b1ac80fc425fe25f8b63169ea78e68fbaaefa59379bbf011d"
}
}

View File

@ -27,6 +27,7 @@ describe('Messages', function() {
Alert: 'alert',
Reject: 'reject',
Block: 'block',
MerkleBlock: 'merkleblock',
FilterLoad: 'filterload',
FilterAdd: 'filteradd',
FilterClear: 'filterclear',
@ -111,10 +112,13 @@ describe('Messages', function() {
var hash = 'eb951630aba498b9a0d10f72b5ea9e39d5ff04b03dc2231e662f52057f948aa1';
[Messages.Inventory, Messages.GetData, Messages.NotFound].forEach(function(clazz) {
var b = clazz.forBlock(hash);
var mb = clazz.forMerkleBlock(hash);
(b instanceof clazz).should.equal(true);
var t = clazz.forTransaction(hash);
(t instanceof clazz).should.equal(true);
clazz.forBlock(BufferUtils.reverse(new Buffer(hash, 'hex'))).should.deep.equal(b);
clazz.forMerkleBlock(BufferUtils.reverse(new Buffer(hash, 'hex'))).should.deep.equal(mb);
clazz.forFilteredBlock(BufferUtils.reverse(new Buffer(hash, 'hex'))).should.deep.equal(mb);
clazz.forTransaction(BufferUtils.reverse(new Buffer(hash, 'hex'))).should.deep.equal(t);
});
});
@ -141,4 +145,10 @@ describe('Messages', function() {
msg.getPayload().toString('hex').should.equal(testPayload);
});
it('MerkleBlock#fromBuffer method works', function() {
var testPayload = Data.MERKLEBLOCK.payload;
var msg = new Messages.MerkleBlock().fromBuffer(new Buffer(testPayload, 'hex'));
msg.getPayload().toString('hex').should.equal(testPayload);
});
});