bitcore-node-zcash/test/integration/addrCache.js

166 lines
5.2 KiB
JavaScript
Raw Normal View History

2014-05-28 04:17:47 -07:00
#!/usr/bin/env node
'use strict';
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var assert = require('assert'),
fs = require('fs'),
Address = require('../../app/models/Address'),
TransactionDb = require('../../lib/TransactionDb').default(),
addrValid = JSON.parse(fs.readFileSync('test/integration/addr.json')),
utxoValid = JSON.parse(fs.readFileSync('test/integration/utxo.json'));
var should = require('chai');
var txDb;
describe('Address cache ', function() {
this.timeout(5000);
before(function(c) {
txDb = TransactionDb;
txDb.deleteCacheForAddress('muAt5RRqDarPFCe6qDXGZc54xJjXYUyepG',function(){
txDb.deleteCacheForAddress('mt2AzeCorSf7yFckj19HFiXJgh9aNyc4h3',function(){
txDb.deleteCacheForAddress('2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk',c);
});
2014-05-28 04:17:47 -07:00
});
});
it('cache case 1 w/o cache', function(done) {
var a = new Address('muAt5RRqDarPFCe6qDXGZc54xJjXYUyepG', txDb);
a.update(function(err) {
if (err) done(err);
a.balance.should.equal(0, 'balance');
a.totalReceived.should.equal(19175, 'totalReceived');
a.txApperances.should.equal(2, 'txApperances');
return done();
});
});
it('cache case 1 w cache', function(done) {
var a = new Address('muAt5RRqDarPFCe6qDXGZc54xJjXYUyepG', txDb);
a.update(function(err) {
if (err) done(err);
a.balance.should.equal(0, 'balance');
a.totalReceived.should.equal(19175, 'totalReceived');
a.txApperances.should.equal(2, 'txApperances');
return done();
});
});
it('cache case 2 w/o cache', function(done) {
2014-05-28 04:17:47 -07:00
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');
return done();
});
});
it('cache case 2 w cache', function(done) {
2014-05-28 04:17:47 -07:00
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');
return done();
});
});
it('cache case 2 unspent wo cache', function(done) {
txDb.deleteCacheForAddress('2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk',function() {
var a = new Address('2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk', txDb);
a.update(function(err) {
if (err) done(err);
a.unspent.length.should.equal(1);
2014-06-08 16:10:33 -07:00
a.unspent[0].scriptPubKey.should.equal('a914a1d5be9f72224b5e83d00d7f5b9b674d456c573f87');
a.unspent[0].confirmations.should.be.above(15000);
a.unspent[0].confirmationsFromCache.should.equal(false);
2014-06-08 16:10:33 -07:00
a.update(function(err) {
a.balance.should.equal(0.23, 'balance');
a.totalReceived.should.equal(0.23, 'totalReceived');
a.txApperances.should.equal(1, 'txApperances');
return done();
});
}, {onlyUnspent:1});
});
});
it('cache case 2 unspent w cache', function(done) {
2014-06-08 16:10:33 -07:00
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(true);
a.unspent[0].confirmations.should.equal(6);
2014-06-08 16:10:33 -07:00
a.unspent[0].scriptPubKey.should.equal('a914a1d5be9f72224b5e83d00d7f5b9b674d456c573f87');
a.update(function(err) {
a.balance.should.equal(0.23, 'balance');
a.totalReceived.should.equal(0.23, 'totalReceived');
a.txApperances.should.equal(1, 'txApperances');
return done();
});
}, {onlyUnspent:1});
});
it('cache case 3 w/o cache', function(done) {
2014-05-28 04:17:47 -07:00
var a = new Address('mt2AzeCorSf7yFckj19HFiXJgh9aNyc4h3', txDb);
a.update(function(err) {
if (err) done(err);
a.balance.should.equal(0, 'balance');
a.totalReceived.should.equal(1376000, 'totalReceived');
a.txApperances.should.equal(8003, 'txApperances');
return done();
});
},1);
it('cache case 4 w cache', function(done) {
2014-05-28 04:17:47 -07:00
var a = new Address('mt2AzeCorSf7yFckj19HFiXJgh9aNyc4h3', txDb);
a.update(function(err) {
if (err) done(err);
a.balance.should.equal(0, 'balance');
a.totalReceived.should.equal(1376000, 'totalReceived');
a.txApperances.should.equal(8003, 'txApperances');
return done();
},{txLimit:0});
2014-05-28 04:17:47 -07:00
});
it('cache case 4 w ignore cache', function(done) {
2014-05-30 10:10:32 -07:00
var a = new Address('mt2AzeCorSf7yFckj19HFiXJgh9aNyc4h3', txDb);
a.update(function(err) {
if (err) done(err);
a.balance.should.equal(0, 'balance');
a.totalReceived.should.equal(1376000, 'totalReceived');
a.txApperances.should.equal(8003, 'txApperances');
return done();
},{txLimit:0, ignoreCache:1});
});
it('cache case 5 unspent w cache', function(done) {
var a = new Address('2NBuTjjZrURxLaMyPUu2sJwNrtpt7GtPX2p', txDb);
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);
return done();
}, {onlyUnspent:1});
});
2014-05-28 04:17:47 -07:00
});