add test for backwars compat
This commit is contained in:
parent
9df1674577
commit
3bfcb95e23
@ -408,7 +408,7 @@ TransactionDb.prototype.cacheScriptPubKey = function(txouts,cb) {
|
|||||||
|
|
||||||
TransactionDb.prototype._parseAddrData = function(k, data, ignoreCache) {
|
TransactionDb.prototype._parseAddrData = function(k, data, ignoreCache) {
|
||||||
var v = data.value.split(':');
|
var v = data.value.split(':');
|
||||||
//console.log('[TransactionDb.js.375]',data.key,data.value); //TODO
|
// console.log('[TransactionDb.js.375]',data.key,data.value);
|
||||||
var item = {
|
var item = {
|
||||||
key: data.key,
|
key: data.key,
|
||||||
ts: END_OF_WORLD_TS - parseInt(k[2]),
|
ts: END_OF_WORLD_TS - parseInt(k[2]),
|
||||||
@ -416,6 +416,7 @@ TransactionDb.prototype._parseAddrData = function(k, data, ignoreCache) {
|
|||||||
index: parseInt(k[4]),
|
index: parseInt(k[4]),
|
||||||
value_sat: parseInt(v[0]),
|
value_sat: parseInt(v[0]),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (ignoreCache)
|
if (ignoreCache)
|
||||||
return item;
|
return item;
|
||||||
|
|
||||||
@ -426,10 +427,10 @@ TransactionDb.prototype._parseAddrData = function(k, data, ignoreCache) {
|
|||||||
if (v[1]==='1'){
|
if (v[1]==='1'){
|
||||||
item.isConfirmed = 1;
|
item.isConfirmed = 1;
|
||||||
item.isConfirmedCached = 1;
|
item.isConfirmedCached = 1;
|
||||||
// console.log('[TransactionDb.js.356] CACHE HIT CONF:', item.key); //TODO
|
// console.log('[TransactionDb.js.356] CACHE HIT CONF:', item.key);
|
||||||
// Sent, confirmed
|
// Sent, confirmed
|
||||||
if (v[2] === '1'){
|
if (v[2] === '1'){
|
||||||
// console.log('[TransactionDb.js.356] CACHE HIT SPENT:', item.key); //TODO
|
// console.log('[TransactionDb.js.356] CACHE HIT SPENT:', item.key);
|
||||||
item.spentIsConfirmed = 1;
|
item.spentIsConfirmed = 1;
|
||||||
item.spentIsConfirmedCached = 1;
|
item.spentIsConfirmedCached = 1;
|
||||||
item.spentTxId = v[3];
|
item.spentTxId = v[3];
|
||||||
@ -437,11 +438,10 @@ TransactionDb.prototype._parseAddrData = function(k, data, ignoreCache) {
|
|||||||
item.spentTs = parseInt(v[5]);
|
item.spentTs = parseInt(v[5]);
|
||||||
}
|
}
|
||||||
// Scriptpubkey cached
|
// Scriptpubkey cached
|
||||||
// // TODO
|
|
||||||
else if (v[2]) {
|
else if (v[2]) {
|
||||||
item.scriptPubKey = v[2];
|
item.scriptPubKey = v[2];
|
||||||
item.scriptPubKeyCached = 1;
|
item.scriptPubKeyCached = 1;
|
||||||
// console.log('[TransactionDb.js.356] CACHE HIT SCRIPTPUBKEY:', item.key, v, item.scriptPubKey); //TODO
|
// console.log('[TransactionDb.js.356] CACHE HIT SCRIPTPUBKEY:', item.key, v, item.scriptPubKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
|
|||||||
@ -158,6 +158,40 @@ describe('Address cache ', function() {
|
|||||||
}, {onlyUnspent:1});
|
}, {onlyUnspent:1});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('cache fix broken cases', function(done) {
|
||||||
|
txDb._db.put('txa2-2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk-9998599199253-16c0287dbea7e323431caff7f7e490da6de66530717f86f8dae9549b3355301a-0', '23000000:1399232338:0:a914a1d5be9f72224b5e83d00d7f5b9b674d456c573f87', function(){
|
||||||
|
var a = new Address('2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk', txDb);
|
||||||
|
a.update(function(err) {
|
||||||
|
if (err) done(err);
|
||||||
|
a.balance.should.equal(0.23, 'balance');
|
||||||
|
a.totalReceived.should.equal(0.23, 'totalReceived');
|
||||||
|
a.txApperances.should.equal(1, 'txApperances');
|
||||||
|
a.transactions.length.should.equal(1);
|
||||||
|
a.transactions[0].should.equal('16c0287dbea7e323431caff7f7e490da6de66530717f86f8dae9549b3355301a');
|
||||||
|
return done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('cache fix broken cases 2)', function(done) {
|
||||||
|
txDb._db.put('txa2-2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk-9998599199253-16c0287dbea7e323431caff7f7e490da6de66530717f86f8dae9549b3355301a-0', '23000000:1399232338:0:a914a1d5be9f72224b5e83d00d7f5b9b674d456c573f87', function(){
|
||||||
|
var a = new Address('2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk', txDb);
|
||||||
|
a.update(function(err) {
|
||||||
|
if (err) done(err);
|
||||||
|
a.unspent.length.should.equal(1);
|
||||||
|
a.unspent[0].confirmationsFromCache.should.equal(false);
|
||||||
|
a.unspent[0].confirmations.should.above(6);
|
||||||
|
a.unspent[0].scriptPubKey.should.equal('a914a1d5be9f72224b5e83d00d7f5b9b674d456c573f87');
|
||||||
|
a.update(function(err) {
|
||||||
|
if (err) done(err);
|
||||||
|
a.unspent.length.should.equal(1);
|
||||||
|
a.unspent[0].confirmationsFromCache.should.equal(true);
|
||||||
|
a.unspent[0].confirmations.should.equal(6);
|
||||||
|
a.unspent[0].scriptPubKey.should.equal('a914a1d5be9f72224b5e83d00d7f5b9b674d456c573f87');
|
||||||
|
return done();
|
||||||
|
}, {onlyUnspent:1});
|
||||||
|
}, {onlyUnspent:1});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user