From 3399026e39cf6677b74c4b55800a192ff3163501 Mon Sep 17 00:00:00 2001 From: Tadeuchi Date: Wed, 20 Dec 2023 09:29:12 +0100 Subject: [PATCH] interactions loader - previous sk instead of offset --- src/__tests__/unit/gateway-interactions.loader.test.ts | 10 +++++----- src/core/modules/impl/WarpGatewayInteractionsLoader.ts | 8 +++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/__tests__/unit/gateway-interactions.loader.test.ts b/src/__tests__/unit/gateway-interactions.loader.test.ts index 42954a54..5f1ea8ff 100644 --- a/src/__tests__/unit/gateway-interactions.loader.test.ts +++ b/src/__tests__/unit/gateway-interactions.loader.test.ts @@ -80,7 +80,7 @@ const sorter = new LexicographicalInteractionsSorter(Arweave.init({})); const contractId = 'SJ3l7474UHh3Dw6dWVT1bzsJ-8JvOewtGoDdOecWIZo'; const fromBlockHeight = sorter.generateLastSortKey(600000); const toBlockHeight = sorter.generateLastSortKey(655393); -const baseUrl = `http://baseUrl/gateway/v2/interactions-sort-key?contractId=SJ3l7474UHh3Dw6dWVT1bzsJ-8JvOewtGoDdOecWIZo&from=000000600000%2C9999999999999%2Czzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz&to=000000655393%2C9999999999999%2Czzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz`; +const baseUrl = `http://baseUrl/gateway/v3/interactions-sort-key?contractId=SJ3l7474UHh3Dw6dWVT1bzsJ-8JvOewtGoDdOecWIZo&from=000000600000%2C9999999999999%2Czzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz&to=000000655393%2C9999999999999%2Czzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz`; const fetchMock = jest .spyOn(global, 'fetch') .mockImplementation( @@ -97,7 +97,7 @@ describe('WarpGatewayInteractionsLoader -> load', () => { it('should be called with correct params', async () => { const loader = getLoader(); await loader.load(contractId, fromBlockHeight, toBlockHeight); - expect(fetchMock).toBeCalledWith(`${baseUrl}&page=1&fromSdk=true`); + expect(fetchMock).toBeCalledWith(`${baseUrl}&fromSdk=true`); }); it('should be called accordingly to the amount of pages', async () => { const fetchMock = jest.spyOn(global, 'fetch').mockImplementation( @@ -110,7 +110,7 @@ describe('WarpGatewayInteractionsLoader -> load', () => { ); const loader = getLoader(); await loader.load(contractId, fromBlockHeight, toBlockHeight); - expect(fetchMock).toBeCalledWith(`${baseUrl}&page=1&fromSdk=true`); + expect(fetchMock).toBeCalledWith(`${baseUrl}&fromSdk=true`); /*expect(fetchMock).toBeCalledWith(`${baseUrl}&page=2&fromSdk=true`); expect(fetchMock).toBeCalledWith(`${baseUrl}&page=3&fromSdk=true`); expect(fetchMock).toBeCalledWith(`${baseUrl}&page=4&fromSdk=true`); @@ -120,12 +120,12 @@ describe('WarpGatewayInteractionsLoader -> load', () => { it('should be called with confirmationStatus set to "confirmed"', async () => { const loader = getLoader({ confirmed: true }); await loader.load(contractId, fromBlockHeight, toBlockHeight); - expect(fetchMock).toBeCalledWith(`${baseUrl}&page=1&fromSdk=true&confirmationStatus=confirmed`); + expect(fetchMock).toBeCalledWith(`${baseUrl}&fromSdk=true&confirmationStatus=confirmed`); }); it('should be called with confirmationStatus set to "not_corrupted"', async () => { const loader = getLoader({ notCorrupted: true }); await loader.load(contractId, fromBlockHeight, toBlockHeight); - expect(fetchMock).toBeCalledWith(`${baseUrl}&page=1&fromSdk=true&confirmationStatus=not_corrupted`); + expect(fetchMock).toBeCalledWith(`${baseUrl}&fromSdk=true&confirmationStatus=not_corrupted`); }); it('should throw an error in case of timeout', async () => { jest.spyOn(global, 'fetch').mockImplementation(() => Promise.reject({ status: 504, ok: false })); diff --git a/src/core/modules/impl/WarpGatewayInteractionsLoader.ts b/src/core/modules/impl/WarpGatewayInteractionsLoader.ts index f2b752db..2b3b4cfe 100644 --- a/src/core/modules/impl/WarpGatewayInteractionsLoader.ts +++ b/src/core/modules/impl/WarpGatewayInteractionsLoader.ts @@ -70,6 +70,7 @@ export class WarpGatewayInteractionsLoader implements InteractionsLoader { signal?: AbortSignal ): Promise { this.logger.debug('Loading interactions: for ', { contractId, fromSortKey, toSortKey }); + const originalFromSortKey = fromSortKey; const interactions: GQLNodeInterface[] = []; let page = 0; @@ -88,8 +89,9 @@ export class WarpGatewayInteractionsLoader implements InteractionsLoader { throw new AbortError(`Abort signal in ${WarpGatewayInteractionsLoader.name}`); } - const url = `${baseUrl}/gateway/v2/interactions-sort-key`; + const url = `${baseUrl}/gateway/v3/interactions-sort-key`; + page++; const response = await getJsonResponse( fetch( `${url}?${new URLSearchParams({ @@ -97,7 +99,6 @@ export class WarpGatewayInteractionsLoader implements InteractionsLoader { ...(this._warp.whoAmI ? { client: this._warp.whoAmI } : ''), ...(fromSortKey ? { from: fromSortKey } : ''), ...(toSortKey ? { to: toSortKey } : ''), - page: (++page).toString(), fromSdk: 'true', ...(this.confirmationStatus && this.confirmationStatus.confirmed ? { confirmationStatus: 'confirmed' } @@ -114,12 +115,13 @@ export class WarpGatewayInteractionsLoader implements InteractionsLoader { interactions.push(...response.interactions); limit = response.paging.limit; items = response.paging.items; + fromSortKey = interactions[interactions.length - 1]?.sortKey; this.logger.debug(`Loaded interactions length: ${interactions.length}, from: ${fromSortKey}, to: ${toSortKey}`); } while (items == limit && page < pagesPerBatch); // note: items < limit means that we're on the last page this.logger.debug('All loaded interactions:', { - from: fromSortKey, + from: originalFromSortKey, to: toSortKey, loaded: interactions.length, time: benchmarkTotalTime.elapsed()