@@ -75,6 +75,33 @@ describe('Bitcoin Service', function() {
7575 bitcoind . _loadConfiguration ( { datadir : './test' } ) ;
7676 } ) . should . throw ( 'Txindex option' ) ;
7777 } ) ;
78+ describe ( 'reindex' , function ( ) {
79+ var log = require ( '../../lib/' ) . log ;
80+ var stub ;
81+ beforeEach ( function ( ) {
82+ stub = sinon . stub ( log , 'warn' ) ;
83+ } ) ;
84+ after ( function ( ) {
85+ stub . restore ( ) ;
86+ } ) ;
87+ it ( 'should warn the user if reindex is set to 1 in the bitcoin.conf file' , function ( ) {
88+ var readFileSync = function ( ) {
89+ return "txindex=1\nreindex=1" ;
90+ } ;
91+ var testbitcoin = proxyquire ( '../../lib/services/bitcoind' , {
92+ fs : {
93+ readFileSync : readFileSync ,
94+ existsSync : sinon . stub ( ) . returns ( true )
95+ } ,
96+ mkdirp : {
97+ sync : sinon . stub ( )
98+ } ,
99+ } ) ;
100+ var bitcoind = new testbitcoin ( baseConfig ) ;
101+ bitcoind . _loadConfiguration ( ) ;
102+ stub . callCount . should . equal ( 1 ) ;
103+ } ) ;
104+ } ) ;
78105 } ) ;
79106 describe ( '#_registerEventHandlers' , function ( ) {
80107 it ( 'will emit tx with transactions from bindings' , function ( done ) {
@@ -252,6 +279,48 @@ describe('Bitcoin Service', function() {
252279 done ( ) ;
253280 } ) ;
254281 } ) ;
282+ describe ( 'reindex' , function ( ) {
283+ var log = require ( '../../lib/' ) . log ;
284+ var info ;
285+ beforeEach ( function ( ) {
286+ info = sinon . stub ( log , 'info' ) ;
287+ } ) ;
288+ afterEach ( function ( ) {
289+ info . restore ( ) ;
290+ } ) ;
291+ it ( 'will wait for a reindex to complete before calling the callback.' , function ( done ) {
292+ var start = sinon . stub ( ) . callsArgWith ( 1 , null ) ;
293+ var onBlocksReady = sinon . stub ( ) . callsArg ( 0 ) ;
294+ var percentage = 98 ;
295+ var TestBitcoin = proxyquire ( '../../lib/services/bitcoind' , {
296+ fs : {
297+ readFileSync : readFileSync
298+ } ,
299+ bindings : function ( name ) {
300+ return {
301+ start : start ,
302+ onBlocksReady : onBlocksReady ,
303+ syncPercentage : function ( ) {
304+ return percentage ;
305+ }
306+ } ;
307+ }
308+ } ) ;
309+ var bitcoind = new TestBitcoin ( baseConfig ) ;
310+ bitcoind . _reindex = true ;
311+ bitcoind . _reindexWait = 1 ;
312+ bitcoind . _onReady = sinon . stub ( ) . callsArg ( 1 ) ;
313+ bitcoind . _loadConfiguration = sinon . stub ( ) ;
314+ bitcoind . start ( function ( ) {
315+ info . callCount . should . be . within ( 2 , 3 ) ;
316+ bitcoind . _reindex . should . be . false ;
317+ done ( ) ;
318+ } ) ;
319+ setTimeout ( function ( ) {
320+ percentage = 100 ;
321+ } , 2 ) ;
322+ } ) ;
323+ } ) ;
255324 } ) ;
256325 describe ( '#stop' , function ( ) {
257326 it ( 'will call bindings stop' , function ( ) {
0 commit comments