add GetData unit data, and more integration tests

This commit is contained in:
Manuel Araoz 2015-02-03 12:26:09 -03:00
parent 61754b267b
commit 17e890996e
3 changed files with 24 additions and 13 deletions

View File

@ -27,8 +27,8 @@ var blockHash = {
'testnet': '0000000058cc069d964711cd25083c0a709f4df2b34c8ff9302ce71fe5b45786' 'testnet': '0000000058cc069d964711cd25083c0a709f4df2b34c8ff9302ce71fe5b45786'
}; };
var stopBlock = { var stopBlock = {
'livenet': '000000000000000006181d9d183e2191a5e704d6ed3513f29b0970198fb34d2e', 'livenet': '00000000000000000b539ef570128acb953af3dbcfc19dd8e6066949672311a1',
'testnet': '000000003d594c41db49d5a8b850344943438620acf79ce8aa88177f5b35e337' 'testnet': '00000000d0bc4271bcefaa7eb25000e345910ba16b91eb375cd944b68624de9f'
}; };
var txHash = { var txHash = {
'livenet': '22231e8219a0617a0ded618b5dc713fdf9b0db8ebd5bb3322d3011a703119d3b', 'livenet': '22231e8219a0617a0ded618b5dc713fdf9b0db8ebd5bb3322d3011a703119d3b',
@ -143,16 +143,16 @@ describe('Integration with ' + network.name + ' bitcoind', function() {
peer.sendMessage(message); peer.sendMessage(message);
}); });
}); });
var fakeHash = 'e2dfb8afe1575bfacae1a0b4afc49af7ddda69285857267bae0e22be15f74a3a';
it('can handle request tx data not found', function(cb) { it('can handle request tx data not found', function(cb) {
connect(function(peer) { connect(function(peer) {
var hash = 'e2dfb8afe1575bfacae1a0b4afc49af7ddda69285857267bae0e22be15f74a3a'; var expected = Messages.NotFound.forTransaction(fakeHash);
var expected = Messages.NotFound.forTransaction(hash);
peer.once('notfound', function(message) { peer.once('notfound', function(message) {
(message instanceof Messages.NotFound).should.equal(true); (message instanceof Messages.NotFound).should.equal(true);
message.should.deep.equal(expected); message.should.deep.equal(expected);
cb(); cb();
}); });
var message = Messages.GetData.forTransaction(hash); var message = Messages.GetData.forTransaction(fakeHash);
peer.sendMessage(message); peer.sendMessage(message);
}); });
}); });
@ -162,20 +162,18 @@ describe('Integration with ' + network.name + ' bitcoind', function() {
connect(function(peer) { connect(function(peer) {
peer.once('headers', function(message) { peer.once('headers', function(message) {
(message instanceof Messages.Headers).should.equal(true); (message instanceof Messages.Headers).should.equal(true);
message.headers.length.should.equal(2); message.headers.length.should.equal(3);
cb(); cb();
}); });
var message = new Messages.GetHeaders(from, stop); var message = new Messages.GetHeaders(from, stop);
peer.sendMessage(message); peer.sendMessage(message);
}); });
}); });
it.skip('can get blocks', function(cb) { it('can get blocks', function(cb) {
connect(function(peer) { connect(function(peer) {
peer.on('inv', function(message) { peer.once('inv', function(message) {
(message instanceof Messages.Inventory).should.equal(true); (message instanceof Messages.Inventory).should.equal(true);
console.log('inv' + message.inventory.length);
if (message.inventory.length === 2) { if (message.inventory.length === 2) {
console.log(message);
message.inventory[0].type.should.equal(Messages.Inventory.TYPE.BLOCK); message.inventory[0].type.should.equal(Messages.Inventory.TYPE.BLOCK);
cb(); cb();
} }
@ -184,4 +182,17 @@ describe('Integration with ' + network.name + ' bitcoind', function() {
peer.sendMessage(message); peer.sendMessage(message);
}); });
}); });
it('can send inv and respond with info', function(cb) {
connect(function(peer) {
var randomHash = Random.getRandomBuffer(32);// needs to be random for repeatability
var expected = Messages.GetData.forBlock(randomHash);
peer.once('getdata', function(message) {
(message instanceof Messages.GetData).should.equal(true);
message.should.deep.equal(expected);
cb();
});
var message = Messages.Inventory.forBlock(randomHash);
peer.sendMessage(message);
});
});
}); });

View File

@ -20,8 +20,8 @@
"payload": "" "payload": ""
}, },
"GETDATA": { "GETDATA": {
"message": "", "message": "f9beb4d967657464617461000000000025000000253fc50c01020000003c2a5e4dcb5a44daf5ebff14a89d26a99b8aa1c1d757694b03d7e6ca7eeda6ca",
"payload": "" "payload": "01020000003c2a5e4dcb5a44daf5ebff14a89d26a99b8aa1c1d757694b03d7e6ca7eeda6ca"
}, },
"GETADDR": { "GETADDR": {
"message": "", "message": "",

View File

@ -31,7 +31,7 @@ describe('Messages', function() {
NotFound: 'notfound' NotFound: 'notfound'
}; };
// TODO: add data for these // TODO: add data for these
var noPayload = ['Alert', 'Reject', 'GetBlocks', 'GetHeaders', 'GetData']; var noPayload = ['Alert', 'Reject', 'GetBlocks', 'GetHeaders'];
var names = Object.keys(commands); var names = Object.keys(commands);
describe('named', function() { describe('named', function() {
names.forEach(function(name) { names.forEach(function(name) {