@@ -18,16 +18,10 @@ jest.useFakeTimers();
1818const ADDRESS_MOCK = '0x123' ;
1919const ONE_DAY_MS = 1000 * 60 * 60 * 24 ;
2020const NOW_MOCK = 789000 + ONE_DAY_MS ;
21- const CURSOR_MOCK = 'abcdef' ;
22- const CACHED_TIMESTAMP_MOCK = 456 ;
23- const INITIAL_TIMESTAMP_MOCK = 789 ;
2421
2522const REQUEST_MOCK : RemoteTransactionSourceRequest = {
2623 address : ADDRESS_MOCK ,
27- cache : { } ,
2824 includeTokenTransfers : true ,
29- queryEntireHistory : true ,
30- updateCache : jest . fn ( ) ,
3125 updateTransactions : true ,
3226} ;
3327
@@ -140,60 +134,10 @@ describe('AccountsApiRemoteTransactionSource', () => {
140134 expect ( getAccountTransactionsMock ) . toHaveBeenCalledWith ( {
141135 address : ADDRESS_MOCK ,
142136 chainIds : SUPPORTED_CHAIN_IDS ,
143- cursor : undefined ,
144- sortDirection : 'ASC' ,
137+ sortDirection : 'DESC' ,
145138 } ) ;
146139 } ) ;
147140
148- it ( 'queries accounts API with start timestamp if queryEntireHistory is false' , async ( ) => {
149- await new AccountsApiRemoteTransactionSource ( ) . fetchTransactions ( {
150- ...REQUEST_MOCK ,
151- queryEntireHistory : false ,
152- } ) ;
153-
154- expect ( getAccountTransactionsMock ) . toHaveBeenCalledTimes ( 1 ) ;
155- expect ( getAccountTransactionsMock ) . toHaveBeenCalledWith (
156- expect . objectContaining ( {
157- startTimestamp : INITIAL_TIMESTAMP_MOCK ,
158- } ) ,
159- ) ;
160- } ) ;
161-
162- it ( 'queries accounts API with cursor from cache' , async ( ) => {
163- await new AccountsApiRemoteTransactionSource ( ) . fetchTransactions ( {
164- ...REQUEST_MOCK ,
165- cache : {
166- [ `accounts-api#${ SUPPORTED_CHAIN_IDS . join ( ',' ) } #${ ADDRESS_MOCK } ` ] :
167- CURSOR_MOCK ,
168- } ,
169- } ) ;
170-
171- expect ( getAccountTransactionsMock ) . toHaveBeenCalledTimes ( 1 ) ;
172- expect ( getAccountTransactionsMock ) . toHaveBeenCalledWith (
173- expect . objectContaining ( {
174- cursor : CURSOR_MOCK ,
175- } ) ,
176- ) ;
177- } ) ;
178-
179- it ( 'queries accounts API with timestamp from cache' , async ( ) => {
180- await new AccountsApiRemoteTransactionSource ( ) . fetchTransactions ( {
181- ...REQUEST_MOCK ,
182- queryEntireHistory : false ,
183- cache : {
184- [ `accounts-api#timestamp#${ SUPPORTED_CHAIN_IDS . join ( ',' ) } #${ ADDRESS_MOCK } ` ] :
185- CACHED_TIMESTAMP_MOCK ,
186- } ,
187- } ) ;
188-
189- expect ( getAccountTransactionsMock ) . toHaveBeenCalledTimes ( 1 ) ;
190- expect ( getAccountTransactionsMock ) . toHaveBeenCalledWith (
191- expect . objectContaining ( {
192- startTimestamp : CACHED_TIMESTAMP_MOCK ,
193- } ) ,
194- ) ;
195- } ) ;
196-
197141 it ( 'returns normalized standard transaction' , async ( ) => {
198142 getAccountTransactionsMock . mockResolvedValue ( {
199143 data : [ RESPONSE_STANDARD_MOCK ] ,
@@ -222,117 +166,6 @@ describe('AccountsApiRemoteTransactionSource', () => {
222166 expect ( transactions ) . toStrictEqual ( [ TRANSACTION_TOKEN_TRANSFER_MOCK ] ) ;
223167 } ) ;
224168
225- it ( 'queries multiple times if response has next page' , async ( ) => {
226- getAccountTransactionsMock
227- . mockResolvedValueOnce ( {
228- data : [ RESPONSE_STANDARD_MOCK ] ,
229- pageInfo : { hasNextPage : true , count : 1 , cursor : CURSOR_MOCK } ,
230- } )
231- . mockResolvedValueOnce ( {
232- data : [ RESPONSE_STANDARD_MOCK ] ,
233- pageInfo : { hasNextPage : true , count : 1 , cursor : CURSOR_MOCK } ,
234- } ) ;
235-
236- await new AccountsApiRemoteTransactionSource ( ) . fetchTransactions (
237- REQUEST_MOCK ,
238- ) ;
239-
240- expect ( getAccountTransactionsMock ) . toHaveBeenCalledTimes ( 3 ) ;
241- expect ( getAccountTransactionsMock ) . toHaveBeenNthCalledWith (
242- 1 ,
243- expect . objectContaining ( { cursor : undefined } ) ,
244- ) ;
245- expect ( getAccountTransactionsMock ) . toHaveBeenNthCalledWith (
246- 2 ,
247- expect . objectContaining ( { cursor : CURSOR_MOCK } ) ,
248- ) ;
249- expect ( getAccountTransactionsMock ) . toHaveBeenNthCalledWith (
250- 3 ,
251- expect . objectContaining ( { cursor : CURSOR_MOCK } ) ,
252- ) ;
253- } ) ;
254-
255- it ( 'updates cache if response has cursor' , async ( ) => {
256- getAccountTransactionsMock
257- . mockResolvedValueOnce ( {
258- data : [ RESPONSE_STANDARD_MOCK ] ,
259- pageInfo : { hasNextPage : true , count : 1 , cursor : CURSOR_MOCK } ,
260- } )
261- . mockResolvedValueOnce ( {
262- data : [ RESPONSE_STANDARD_MOCK ] ,
263- pageInfo : { hasNextPage : true , count : 1 , cursor : CURSOR_MOCK } ,
264- } ) ;
265-
266- const cacheMock = { } ;
267-
268- const updateCacheMock = jest
269- . fn ( )
270- . mockImplementation ( ( fn ) => fn ( cacheMock ) ) ;
271-
272- await new AccountsApiRemoteTransactionSource ( ) . fetchTransactions ( {
273- ...REQUEST_MOCK ,
274- updateCache : updateCacheMock ,
275- } ) ;
276-
277- expect ( updateCacheMock ) . toHaveBeenCalledTimes ( 2 ) ;
278- expect ( cacheMock ) . toStrictEqual ( {
279- [ `accounts-api#${ SUPPORTED_CHAIN_IDS . join ( ',' ) } #${ ADDRESS_MOCK } ` ] :
280- CURSOR_MOCK ,
281- } ) ;
282- } ) ;
283-
284- it ( 'removes timestamp cache entry if response has cursor' , async ( ) => {
285- getAccountTransactionsMock . mockResolvedValueOnce ( {
286- data : [ RESPONSE_STANDARD_MOCK ] ,
287- pageInfo : { hasNextPage : false , count : 1 , cursor : CURSOR_MOCK } ,
288- } ) ;
289-
290- const cacheMock = {
291- [ `accounts-api#timestamp#${ SUPPORTED_CHAIN_IDS . join ( ',' ) } #${ ADDRESS_MOCK } ` ] :
292- CACHED_TIMESTAMP_MOCK ,
293- } ;
294-
295- const updateCacheMock = jest
296- . fn ( )
297- . mockImplementation ( ( fn ) => fn ( cacheMock ) ) ;
298-
299- await new AccountsApiRemoteTransactionSource ( ) . fetchTransactions ( {
300- ...REQUEST_MOCK ,
301- updateCache : updateCacheMock ,
302- } ) ;
303-
304- expect ( updateCacheMock ) . toHaveBeenCalledTimes ( 1 ) ;
305- expect ( cacheMock ) . toStrictEqual ( {
306- [ `accounts-api#${ SUPPORTED_CHAIN_IDS . join ( ',' ) } #${ ADDRESS_MOCK } ` ] :
307- CURSOR_MOCK ,
308- } ) ;
309- } ) ;
310-
311- it ( 'updates cache with timestamp if response does not have cursor' , async ( ) => {
312- getAccountTransactionsMock . mockResolvedValueOnce ( {
313- data : [ ] ,
314- pageInfo : { hasNextPage : false , count : 0 , cursor : undefined } ,
315- } ) ;
316-
317- const cacheMock = { } ;
318-
319- const updateCacheMock = jest
320- . fn ( )
321- . mockImplementation ( ( fn ) => fn ( cacheMock ) ) ;
322-
323- await new AccountsApiRemoteTransactionSource ( ) . fetchTransactions ( {
324- ...REQUEST_MOCK ,
325- queryEntireHistory : false ,
326- updateCache : updateCacheMock ,
327- } ) ;
328-
329- expect ( updateCacheMock ) . toHaveBeenCalledTimes ( 1 ) ;
330- expect ( cacheMock ) . toStrictEqual ( {
331- [ `accounts-api#timestamp#${ SUPPORTED_CHAIN_IDS . join ( ',' ) } #${ ADDRESS_MOCK } ` ] :
332- INITIAL_TIMESTAMP_MOCK ,
333- } ) ;
334- } ) ;
335-
336169 it ( 'ignores outgoing transactions if updateTransactions is false' , async ( ) => {
337170 getAccountTransactionsMock . mockResolvedValue ( {
338171 data : [ { ...RESPONSE_STANDARD_MOCK , to : '0x456' } ] ,
0 commit comments