Fix tests on block and transaction services

This commit is contained in:
eordano 2015-03-20 12:36:39 -03:00
parent 51c7af57d0
commit a2a6f03c50
4 changed files with 24 additions and 11 deletions

View File

@ -126,7 +126,7 @@ BlockService.blockRPCtoBitcore = function(blockData, transactions) {
* @return {Promise} a promise that will always be rejected * @return {Promise} a promise that will always be rejected
*/ */
var blockNotFound = function(err) { var blockNotFound = function(err) {
console.log(err); console.log(err, err.stack);
return Promise.reject(new BitcoreNode.errors.Blocks.NotFound()); return Promise.reject(new BitcoreNode.errors.Blocks.NotFound());
}; };

View File

@ -150,7 +150,9 @@ TransactionService.prototype._confirmInput = function(ops, block, transaction) {
return; return;
} }
return self._getAddressForInput(input).then(function(address) { return Promise.try(function() {
return self._getAddressForInput(input)
}).then(function(address) {
if (address) { if (address) {
ops.push({ ops.push({
type: 'put', type: 'put',

View File

@ -42,7 +42,7 @@ describe('BlockService', function() {
size: 215, size: 215,
height: 2, height: 2,
version: 1, version: 1,
merkleRoot: '9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5', merkleroot: '9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5',
tx: [ '9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5' ], tx: [ '9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5' ],
time: 1231469744, time: 1231469744,
nonce: 1639830024, nonce: 1639830024,

View File

@ -71,7 +71,12 @@ describe('TransactionService', function() {
it('confirms correctly the first transaction on genesis block', function(callback) { it('confirms correctly the first transaction on genesis block', function(callback) {
var ops = []; var ops = [];
service._confirmTransaction(ops, genesisBlock, genesisTx).then(function() { service._confirmTransaction(ops, genesisBlock, genesisTx).then(function() {
ops.should.deep.equal([ ops.map(function(k) {
if (bitcore.util.js.isValidJSON(k.value)) {
k.value = JSON.parse(k.value);
}
return k;
}).should.deep.equal([
{ type: 'put', { type: 'put',
key: 'btx-4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b', key: 'btx-4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b',
value: '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f' }, value: '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f' },
@ -84,7 +89,8 @@ describe('TransactionService', function() {
key: 'txa-1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa-4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b-0', key: 'txa-1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa-4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b-0',
value: value:
{ satoshis: 5000000000, { satoshis: 5000000000,
script: '65 0x04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f OP_CHECKSIG' } } script: '65 0x04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f OP_CHECKSIG',
heightConfirmed: 0} }
]); ]);
callback(); callback();
}); });
@ -102,7 +108,12 @@ describe('TransactionService', function() {
} }
}); });
service._confirmTransaction(ops, block170, block170.transactions[1]).then(function() { service._confirmTransaction(ops, block170, block170.transactions[1]).then(function() {
ops.should.deep.equal([ ops.map(function(k) {
if (bitcore.util.js.isValidJSON(k.value)) {
k.value = JSON.parse(k.value);
}
return k;
}).should.deep.equal([
{ type: 'put', { type: 'put',
key: 'btx-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', key: 'btx-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16',
value: '00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee' }, value: '00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee' },
@ -115,7 +126,8 @@ describe('TransactionService', function() {
key: 'txa-1Q2TWHE3GMdB6BZKafqwxXtWAWgFt5Jvm3-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16-0', key: 'txa-1Q2TWHE3GMdB6BZKafqwxXtWAWgFt5Jvm3-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16-0',
value: value:
{ satoshis: 1000000000, { satoshis: 1000000000,
script: '65 0x04ae1a62fe09c5f51b13905f07f06b99a2f7159b2225f374cd378d71302fa28414e7aab37397f554a7df5f142c21c1b7303b8a0626f1baded5c72a704f7e6cd84c OP_CHECKSIG' } }, script: '65 0x04ae1a62fe09c5f51b13905f07f06b99a2f7159b2225f374cd378d71302fa28414e7aab37397f554a7df5f142c21c1b7303b8a0626f1baded5c72a704f7e6cd84c OP_CHECKSIG',
heightConfirmed: 170 } },
{ type: 'put', { type: 'put',
key: 'txo-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16-1', key: 'txo-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16-1',
value: value:
@ -125,7 +137,8 @@ describe('TransactionService', function() {
key: 'txa-12cbQLTFMXRnSzktFkuoG3eHoMeFtpTu3S-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16-1', key: 'txa-12cbQLTFMXRnSzktFkuoG3eHoMeFtpTu3S-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16-1',
value: value:
{ satoshis: 4000000000, { satoshis: 4000000000,
script: '65 0x0411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3 OP_CHECKSIG' } }, script: '65 0x0411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3 OP_CHECKSIG',
heightConfirmed: 170 } },
{ type: 'put', { type: 'put',
key: 'txo-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16-0', key: 'txo-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16-0',
value: value:
@ -133,7 +146,6 @@ describe('TransactionService', function() {
outputIndex: 0, outputIndex: 0,
sequenceNumber: 4294967295, sequenceNumber: 4294967295,
script: '71 0x304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901', script: '71 0x304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901',
output: undefined,
heightConfirmed: 170 } }, heightConfirmed: 170 } },
{ type: 'put', { type: 'put',
key: 'txas-12cbQLTFMXRnSzktFkuoG3eHoMeFtpTu3S-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16-0', key: 'txas-12cbQLTFMXRnSzktFkuoG3eHoMeFtpTu3S-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16-0',
@ -144,8 +156,7 @@ describe('TransactionService', function() {
spendInput: { prevTxId: '0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9', spendInput: { prevTxId: '0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9',
outputIndex: 0, outputIndex: 0,
sequenceNumber: 4294967295, sequenceNumber: 4294967295,
script: '71 0x304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901', script: '71 0x304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901' }}}]);
output: undefined }}}]);
callback(); callback();
}); });
}); });