interactions loader - previous sk instead of offset
This commit is contained in:
@@ -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 }));
|
||||
|
||||
@@ -70,6 +70,7 @@ export class WarpGatewayInteractionsLoader implements InteractionsLoader {
|
||||
signal?: AbortSignal
|
||||
): Promise<GQLNodeInterface[]> {
|
||||
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<InteractionsResult>(
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user