@@ -8,6 +8,7 @@ var Encoding = require('../../../lib/services/address/encoding');
8
8
var Readable = require ( 'stream' ) . Readable ;
9
9
var EventEmitter = require ( 'events' ) . EventEmitter ;
10
10
var bcoin = require ( 'bcoin' ) ;
11
+ var lodash = require ( 'lodash' ) ;
11
12
12
13
describe ( 'Address Service' , function ( ) {
13
14
@@ -54,7 +55,7 @@ describe('Address Service', function() {
54
55
55
56
describe ( '#getAddressHistory' , function ( ) {
56
57
57
- it ( 'should get the address history' , function ( done ) {
58
+ it ( 'should get the address history (null case) ' , function ( done ) {
58
59
59
60
sandbox . stub ( addressService , '_getAddressTxidHistory' ) . callsArgWith ( 2 , null , null ) ;
60
61
sandbox . stub ( addressService , '_getAddressTxHistory' ) . callsArgWith ( 1 , null , [ ] ) ;
@@ -74,6 +75,104 @@ describe('Address Service', function() {
74
75
} ) ;
75
76
} ) ;
76
77
78
+ it ( 'should get the sorted address history' , function ( done ) {
79
+
80
+ var old_getAddressTxidHistory = addressService . _getAddressTxidHistory ;
81
+ addressService . _getAddressTxidHistory = function ( addr , options , cb ) {
82
+ options . txIdList = [
83
+ {
84
+ txid : "d" ,
85
+ height : 10 ,
86
+ } ,
87
+ {
88
+ txid : "c" ,
89
+ height : 10 ,
90
+ } ,
91
+ {
92
+ txid : "a" ,
93
+ height : 101 ,
94
+ } ,
95
+ {
96
+ txid : "b" ,
97
+ height : 100 ,
98
+ } ,
99
+ ] ;
100
+ return cb ( ) ;
101
+ } ;
102
+
103
+
104
+ var old_getAddressTxHistory = addressService . _getAddressTxHistory ;
105
+ addressService . _getAddressTxHistory = function ( options , cb ) {
106
+ return cb ( null , options . txIdList ) ;
107
+ } ;
108
+
109
+ addressService . getAddressHistory ( [ 'a' , 'b' , 'c' ] , { from : 12 , to : 14 } , function ( err , res ) {
110
+
111
+ if ( err ) {
112
+ return done ( err ) ;
113
+ }
114
+
115
+ expect ( res . totalCount ) . equal ( 4 ) ;
116
+ expect ( lodash . map ( res . items , 'txid' ) ) . to . be . deep . equal ( [ 'a' , 'b' , 'c' , 'd' ] ) ;
117
+
118
+ addressService . _getAddressTxidHistory = old_getAddressTxHistory ;
119
+ addressService . _getAddressTxHistory = old_getAddressTxHistory ;
120
+ done ( ) ;
121
+ } ) ;
122
+ } ) ;
123
+
124
+ it ( 'should remove duplicated items in history' , function ( done ) {
125
+
126
+ var old_getAddressTxidHistory = addressService . _getAddressTxidHistory ;
127
+ addressService . _getAddressTxidHistory = function ( addr , options , cb ) {
128
+ options . txIdList = [
129
+ {
130
+ txid : "b" ,
131
+ height : 10 ,
132
+ } ,
133
+ {
134
+ txid : "b" ,
135
+ height : 10 ,
136
+ } ,
137
+ {
138
+ txid : "d" ,
139
+ height : 101 ,
140
+ } ,
141
+ {
142
+ txid : "c" ,
143
+ height : 100 ,
144
+ } ,
145
+ {
146
+ txid : "d" ,
147
+ height : 101 ,
148
+ } ,
149
+ ] ;
150
+ return cb ( ) ;
151
+ } ;
152
+
153
+
154
+ var old_getAddressTxHistory = addressService . _getAddressTxHistory ;
155
+ addressService . _getAddressTxHistory = function ( options , cb ) {
156
+ return cb ( null , options . txIdList ) ;
157
+ } ;
158
+
159
+ addressService . getAddressHistory ( [ 'a' , 'b' , 'c' ] , { from : 12 , to : 14 } , function ( err , res ) {
160
+
161
+ if ( err ) {
162
+ return done ( err ) ;
163
+ }
164
+
165
+ expect ( res . totalCount ) . equal ( 3 ) ;
166
+ expect ( lodash . map ( res . items , 'txid' ) ) . to . be . deep . equal ( [ 'd' , 'c' , 'b' ] ) ;
167
+
168
+ addressService . _getAddressTxidHistory = old_getAddressTxHistory ;
169
+ addressService . _getAddressTxHistory = old_getAddressTxHistory ;
170
+ done ( ) ;
171
+ } ) ;
172
+ } ) ;
173
+
174
+
175
+
77
176
} ) ;
78
177
79
178
describe ( '#_getAddressTxidHistory' , function ( ) {
0 commit comments