refactor: minor redstone interactions loader and tests refactor
This commit is contained in:
@@ -5,7 +5,6 @@ the SmartWeave [Protocol](./docs/SMARTWEAVE_PROTOCOL.md).
|
||||
It has been built with performance (e.g. caching at multiple layers, Arweave calls optimization)
|
||||
and modularity (e.g. ability to use different types of caches, imported from external libraries) in mind.
|
||||
|
||||
#### Warning: SDK is currently in alpha version.
|
||||
We're already using the new SDK on production, both in our webapp and nodes.
|
||||
However, if you'd like to use it in production as well, please contact us on [discord](https://discord.com/invite/PVxBZKFr46) to ensure a smooth transition and get help with testing.
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable */
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import Arweave from 'arweave';
|
||||
@@ -5,9 +6,9 @@ import {
|
||||
LoggerFactory,
|
||||
RedstoneGatewayInteractionsLoader,
|
||||
ArweaveGatewayInteractionsLoader,
|
||||
DefaultEvaluationOptions
|
||||
DefaultEvaluationOptions,
|
||||
GQLEdgeInterface
|
||||
} from '@smartweave';
|
||||
import { GQLEdgeInterface } from '../../legacy/gqlResult';
|
||||
|
||||
/*
|
||||
TODO: two test cases have been removed from the list - gateway-interaction test is failing due to the different
|
||||
@@ -35,26 +36,9 @@ const testCases: string[] = JSON.parse(
|
||||
);
|
||||
|
||||
/**
|
||||
* These regression tests should verify whether ArweaveGatewayInteractionsLoader and RedstoneGatewayInteractionsLoader
|
||||
* return same results for given variables
|
||||
* These regression tests should verify whether {@link ArweaveGatewayInteractionsLoader}
|
||||
* and {@link RedstoneGatewayInteractionsLoader} return same results for given variables.
|
||||
*/
|
||||
|
||||
describe.each(testCases)('testing for contract %#', (contractTxId) => {
|
||||
it('returns same amount of interactions for RedstoneGatewayInteractionsLoader and ArweaveGatewayInteractionsLoader', async () => {
|
||||
const redstoneInteractionsLoader = new RedstoneGatewayInteractionsLoader(gatewayUrl);
|
||||
const arweaveInteractionsLoader = new ArweaveGatewayInteractionsLoader(arweave);
|
||||
const responseRedstoneInteractionsLoader = await redstoneInteractionsLoader.load(contractTxId, 0, 8301901);
|
||||
const responseArweaveInteractionsLoader = await arweaveInteractionsLoader.load(
|
||||
contractTxId,
|
||||
0,
|
||||
8301901,
|
||||
new DefaultEvaluationOptions()
|
||||
);
|
||||
|
||||
expect(responseRedstoneInteractionsLoader.length).toEqual(responseArweaveInteractionsLoader.length);
|
||||
}, 600000);
|
||||
});
|
||||
|
||||
describe.each([750000, 775000, 800000, 825000, 850000])('testing for block height %#', (toBlockHeight) => {
|
||||
it('returns same amount of interactions for the same block height', async () => {
|
||||
const redstoneInteractionsLoader = new RedstoneGatewayInteractionsLoader(gatewayUrl);
|
||||
@@ -91,6 +75,8 @@ describe.each(testCases)('testing contractId %#', (contractTxId) => {
|
||||
new DefaultEvaluationOptions()
|
||||
);
|
||||
|
||||
expect(responseRedstoneInteractionsLoader.length).toEqual(responseArweaveInteractionsLoader.length);
|
||||
|
||||
let arr = [];
|
||||
responseRedstoneInteractionsLoader.forEach((resRedstone) => {
|
||||
arr.push(
|
||||
|
||||
@@ -33,11 +33,22 @@ type ConfirmationStatus =
|
||||
};
|
||||
|
||||
/**
|
||||
* The aim of this implementation of the {@link InteractionsLoader} is to make use of Redstone Gateway endpoint
|
||||
* and retrieve contracts' interactions. Optionally - it is possible to pass skipOrphans flag in the constructor
|
||||
* and therefore receive only these transactions which are confirmed. To learn more about Redstone Gateway please visit
|
||||
* {@link https://github.com/redstone-finance/redstone-sw-gateway}.
|
||||
* Please note that currently caching is switched off for RedstoneGatewayInteractionsLoader due to the issue mentioned in the
|
||||
* The aim of this implementation of the {@link InteractionsLoader} is to make use of
|
||||
* Redstone Gateway ({@link https://github.com/redstone-finance/redstone-sw-gateway})
|
||||
* endpoint and retrieve contracts' interactions.
|
||||
*
|
||||
* Optionally - it is possible to pass:
|
||||
* 1. {@link ConfirmationStatus.confirmed} flag - to receive only confirmed interactions - ie. interactions with
|
||||
* enough confirmations, whose existence is confirmed by at least 3 Arweave peers.
|
||||
* 2. {@link ConfirmationStatus.notCorrupted} flag - to receive both already confirmed and not yet confirmed (ie. latest)
|
||||
* interactions.
|
||||
*
|
||||
* Passing no flag is the "backwards compatible" mode (ie. it will behave like the original Arweave GQL gateway endpoint).
|
||||
* Note that this may result in returning corrupted and/or forked interactions
|
||||
* - read more {@link https://github.com/redstone-finance/redstone-sw-gateway#corrupted-transactions}.
|
||||
*
|
||||
* Please note that currently caching (ie. {@link CacheableContractInteractionsLoader} is switched off
|
||||
* for RedstoneGatewayInteractionsLoader due to the issue mentioned in the
|
||||
* following comment {@link https://github.com/redstone-finance/redstone-smartcontracts/pull/62#issuecomment-995249264}
|
||||
*/
|
||||
export class RedstoneGatewayInteractionsLoader implements InteractionsLoader {
|
||||
@@ -68,14 +79,7 @@ export class RedstoneGatewayInteractionsLoader implements InteractionsLoader {
|
||||
})}`
|
||||
)
|
||||
.then((res) => {
|
||||
if (res.ok) {
|
||||
return res.json();
|
||||
} else {
|
||||
return Promise.reject(res);
|
||||
}
|
||||
})
|
||||
.then((data) => {
|
||||
return data;
|
||||
return res.ok ? res.json() : Promise.reject(res);
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error.body?.message) {
|
||||
@@ -83,11 +87,11 @@ export class RedstoneGatewayInteractionsLoader implements InteractionsLoader {
|
||||
}
|
||||
throw new Error(`Unable to retrieve transactions. Redstone gateway responded with status ${error.status}.`);
|
||||
});
|
||||
this.logger.debug(`Loading interactions: page ${page}, time: `, benchmarkRequestTime.elapsed());
|
||||
|
||||
totalPages = response.paging.pages;
|
||||
|
||||
this.logger.debug(`Loading interactions: page ${page} of ${totalPages} loaded`);
|
||||
this.logger.debug(
|
||||
`Loading interactions: page ${page} of ${totalPages} loaded in ${benchmarkRequestTime.elapsed()}`
|
||||
);
|
||||
|
||||
response.interactions.forEach((interaction) =>
|
||||
interactions.push({
|
||||
@@ -99,7 +103,7 @@ export class RedstoneGatewayInteractionsLoader implements InteractionsLoader {
|
||||
this.logger.debug(`Loaded interactions length: ${interactions.length}`);
|
||||
} while (page < totalPages);
|
||||
|
||||
this.logger.debug(`Loading interactions for ${contractId}:`, benchmarkTotalTime.elapsed());
|
||||
this.logger.debug(`Loading interactions for ${contractId}: ${benchmarkTotalTime.elapsed()}`);
|
||||
|
||||
this.logger.debug('All loaded interactions:', {
|
||||
from: fromBlockHeight,
|
||||
|
||||
Reference in New Issue
Block a user