diff --git a/package.json b/package.json index 5ac7019..14e842c 100644 --- a/package.json +++ b/package.json @@ -70,8 +70,6 @@ "@typescript-eslint/parser": "^4.29.2", "arlocal": "1.1.13", "cheerio": "^1.0.0-rc.10", - "cli-table": "^0.3.11", - "colors": "^1.4.0", "cors": "^2.8.5", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", diff --git a/src/__tests__/regression/gateway-interactions.test.ts b/src/__tests__/regression/gateway-interactions.test.ts deleted file mode 100644 index 6ff470e..0000000 --- a/src/__tests__/regression/gateway-interactions.test.ts +++ /dev/null @@ -1,89 +0,0 @@ -/* eslint-disable */ -import fs from 'fs'; -import path from 'path'; -import Arweave from 'arweave'; -import { - LoggerFactory, - RedstoneGatewayInteractionsLoader, - ArweaveGatewayInteractionsLoader, - DefaultEvaluationOptions, - GQLEdgeInterface -} from '@smartweave'; - -/* -TODO: two test cases have been removed from the list - gateway-interaction test is failing due to the different -amount of interactions returned from Redstone gateway and Arweave GQL gateway -should be fixed in https://github.com/redstone-finance/redstone-sw-gateway/issues/17, following cases should be -then added to ../test-cases/gateway-interactions.json -"eWB7FHyPyCYnkcbK1aINbAQ9YYTDhKGkS7lDiNPZ5Mg", -"cpXtKvM0e6cqAgjv-BCfanWQmYGupECt1MxRk1N9Mjk" -*/ - -const arweave = Arweave.init({ - host: 'arweave.net', - port: 443, - protocol: 'https', - timeout: 600000, - logging: false -}); - -LoggerFactory.INST.logLevel('fatal'); - -const testCases: string[] = JSON.parse( - fs.readFileSync(path.join(__dirname, 'test-cases/gateway-interactions.json'), 'utf-8') -); - -/** - * These regression tests should verify whether {@link ArweaveGatewayInteractionsLoader} - * and {@link RedstoneGatewayInteractionsLoader} return same results for given variables. - */ -describe.each([750000, 775000, 800000, 825000, 850000])('testing for block height %d', (toBlockHeight) => { - it('returns same amount of interactions for the same block height', async () => { - console.log('toBlockHeight', toBlockHeight); - const redstoneInteractionsLoader = new RedstoneGatewayInteractionsLoader('https://gateway.redstone.finance/'); - const arweaveInteractionsLoader = new ArweaveGatewayInteractionsLoader(arweave); - const responseRedstoneInteractionsLoader: GQLEdgeInterface[] = await redstoneInteractionsLoader.load( - 'Daj-MNSnH55TDfxqC7v4eq0lKzVIwh98srUaWqyuZtY', - 0, - toBlockHeight - ); - const responseArweaveInteractionsLoader: GQLEdgeInterface[] = await arweaveInteractionsLoader.load( - 'Daj-MNSnH55TDfxqC7v4eq0lKzVIwh98srUaWqyuZtY', - 0, - toBlockHeight, - new DefaultEvaluationOptions() - ); - - expect(responseRedstoneInteractionsLoader.length).toEqual(responseArweaveInteractionsLoader.length); - }, 600000); -}); - -describe.each(testCases)('testing contractId %s', (contractTxId) => { - it('returns same interactions ids for RedstoneGatewayLoader and ArweaveGatewayInteractionsLoader', async () => { - const redstoneInteractionsLoader = new RedstoneGatewayInteractionsLoader('https://gateway.redstone.finance'); - const arweaveInteractionsLoader = new ArweaveGatewayInteractionsLoader(arweave); - const responseRedstoneInteractionsLoader: GQLEdgeInterface[] = await redstoneInteractionsLoader.load( - contractTxId, - 0, - 8301901 - ); - const responseArweaveInteractionsLoader: GQLEdgeInterface[] = await arweaveInteractionsLoader.load( - contractTxId, - 0, - 8301901, - new DefaultEvaluationOptions() - ); - - expect(responseRedstoneInteractionsLoader.length).toEqual(responseArweaveInteractionsLoader.length); - - let arr = []; - responseRedstoneInteractionsLoader.forEach((resRedstone) => { - arr.push( - responseArweaveInteractionsLoader.find((resArweave) => resArweave.node.id === resRedstone.node.id) !== undefined - ); - }); - const result = arr.every((a) => a === true); - - expect(result).toEqual(true); - }, 600000); -}); diff --git a/src/__tests__/regression/test-cases/gateway-interactions.json b/src/__tests__/regression/test-cases/gateway-interactions.json deleted file mode 100644 index f26bc5a..0000000 --- a/src/__tests__/regression/test-cases/gateway-interactions.json +++ /dev/null @@ -1,15 +0,0 @@ -[ - "Daj-MNSnH55TDfxqC7v4eq0lKzVIwh98srUaWqyuZtY", - "-8A6RexFkpfWwuyVO98wzSFZh0d6VJuI-buTJvlwOJQ", - "AVTqjPQGCCXim7Nl_gn3HMjE4k0Zi_eTFRJCNEVXZxw", - "6eTVr8IKPNYbMHVcpHFXr-XNaL5hT6zRJXimcP-owmo", - "mzvUgNc8YFk0w5K5H7c8pyT-FC5Y_ba0r7_8766Kx74", - "SJ3l7474UHh3Dw6dWVT1bzsJ-8JvOewtGoDdOecWIZo", - "ydjfv0hRQdD2c-MASv4L5Qahjap_LXJyD9tNyKWvf50", - "c25-RdheC6khcACLv23-XXg1W7YuA-VSZ_1_qnNFbhw", - "ZT-70ovBlkF6cRIqvyHy5lC2LcjudsmCz9z19M4_QC4", - "o-qJmQ4B0d6TnyA_awjhiBdiq0O4Vt_dNWU3pTnhTu8", - "BYRf00nIE4pGkJ8GyUY2PIJ1rBtxFPoWIu-0dd8iukg", - "5NgGX4OToJ4M5ohWP4yxaTz_2oPsnk7vmR0v3mqXi_A", - "4o-2xMPa45BXjGuII_LbOMQWfhE1F0qugdEUZvRlXRY" -] diff --git a/src/core/modules/impl/RedstoneGatewayInteractionsLoader.ts b/src/core/modules/impl/RedstoneGatewayInteractionsLoader.ts index 4d81f47..e632925 100644 --- a/src/core/modules/impl/RedstoneGatewayInteractionsLoader.ts +++ b/src/core/modules/impl/RedstoneGatewayInteractionsLoader.ts @@ -1,5 +1,4 @@ -import { Benchmark, InteractionsLoader, LoggerFactory, stripTrailingSlash } from '@smartweave'; -import { GQLEdgeInterface, GQLNodeInterface } from 'legacy/gqlResult'; +import { Benchmark, InteractionsLoader, LoggerFactory, stripTrailingSlash, GQLEdgeInterface, GQLNodeInterface } from '@smartweave'; import 'isomorphic-fetch'; interface Paging { total: string; diff --git a/tools/gateway-benchmark.ts b/tools/gateway-benchmark.ts deleted file mode 100644 index 698ce16..0000000 --- a/tools/gateway-benchmark.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* eslint-disable */ - -import Arweave from 'arweave'; -import { - ArweaveGatewayInteractionsLoader, - DefaultEvaluationOptions, - LoggerFactory, - RedstoneGatewayInteractionsLoader, - Benchmark -} from '@smartweave'; -import { TsLogFactory } from '../src/logging/node/TsLogFactory'; -import Table from 'cli-table'; -import colors from 'colors/safe'; - -/* -Script allows to benchmark loading interactions response time based on the given gateway -To run this script properly, one need to pass [gateway name][contract id][from][to] variables as script's arguments -e.g yarn ts-node -r tsconfig-paths/register tools/gateways-comparison-benchmark.ts arweave Daj-MNSnH55TDfxqC7v4eq0lKzVIwh98srUaWqyuZtY 0 70000 -*/ - -async function gatewayBenchmark() { - let table = new Table({ - head: ['gateway', 'contractId', 'fromBlockHeight', 'toBlockHeight', 'timeSpent'], - colWidths: [10, 50, 20, 20, 20] - }); - - const arweave = Arweave.init({ - host: 'arweave.net', - port: 443, - protocol: 'https', - logging: false - }); - - LoggerFactory.use(new TsLogFactory()); - LoggerFactory.INST.logLevel('debug'); - - const gateway = process.argv[2]; - const contractId = process.argv[3]; - const fromBlockHeight = process.argv[4]; - const toBlockHeight = process.argv[5]; - - const loader = - gateway == 'arweave' - ? new ArweaveGatewayInteractionsLoader(arweave) - : new RedstoneGatewayInteractionsLoader('https://d1o5nlqr4okus2.cloudfront.net'); - - const options = gateway == 'arweave' ? new DefaultEvaluationOptions() : null; - - const benchmark = Benchmark.measure(); - await loader.load(contractId, parseInt(fromBlockHeight), parseInt(toBlockHeight), options); - - const timeSpent = benchmark.elapsed(); - - table.push([gateway, contractId, fromBlockHeight, toBlockHeight, timeSpent.toString()].map((el) => colors.blue(el))); - - console.log(table.toString()); -} - -gatewayBenchmark().catch((e) => console.error(e)); diff --git a/tools/gateways-comparison-benchmark.ts b/tools/gateways-comparison-benchmark.ts deleted file mode 100644 index 68dc5b7..0000000 --- a/tools/gateways-comparison-benchmark.ts +++ /dev/null @@ -1,75 +0,0 @@ -/* eslint-disable */ - -import Arweave from 'arweave'; -import { - ArweaveGatewayInteractionsLoader, - DefaultEvaluationOptions, - LoggerFactory, - RedstoneGatewayInteractionsLoader, - Benchmark -} from '@smartweave'; -import { TsLogFactory } from '../src/logging/node/TsLogFactory'; -import Table from 'cli-table'; -import colors from 'colors/safe'; - -/* -Script allows to benchmark loading interactions response time for given contract for both Arweave and Redstone gateways -To run this script properly, one need to pass [contract id][from][to] variables as script's arugments -e.g yarn ts-node -r tsconfig-paths/register tools/gateways-comparison-benchmark.ts Daj-MNSnH55TDfxqC7v4eq0lKzVIwh98srUaWqyuZtY 0 70000 -*/ - -async function gatewayComparisonBenchmark() { - let table = new Table({ - head: ['contractId', 'fromBlockHeight', 'toBlockHeight', 'arweave', 'redstone'], - colWidths: [50, 20, 20, 15, 15] - }); - - LoggerFactory.use(new TsLogFactory()); - LoggerFactory.INST.logLevel('debug'); - - const contractId = process.argv[2]; - const fromBlockHeight = process.argv[3]; - const toBlockHeight = process.argv[4]; - - const timeSpentArweave = await loadFromAweaveGateway(contractId, fromBlockHeight, toBlockHeight); - - const timeSpentRedstone = await loadFromRedstoneGateway(contractId, fromBlockHeight, toBlockHeight); - - table.push( - [contractId, fromBlockHeight, toBlockHeight, timeSpentArweave.toString(), `${timeSpentRedstone.toString()}ms`].map( - (el) => colors.blue(el) - ) - ); - - console.log(table.toString()); -} - -async function loadFromRedstoneGateway(contractId: string, fromBlockHeight?: string, toBlockHeight?: string) { - const loader = new RedstoneGatewayInteractionsLoader('https://d1o5nlqr4okus2.cloudfront.net'); - - const benchmark = Benchmark.measure(); - for (let i = 0; i < 3; i++) { - await loader.load(contractId, parseInt(fromBlockHeight), parseInt(toBlockHeight)); - } - return Math.round(parseInt(benchmark.elapsed().toString().replace('ms', ''))) / 3; -} - -async function loadFromAweaveGateway(contractId: string, fromBlockHeight?: string, toBlockHeight?: string) { - const arweave = Arweave.init({ - host: 'arweave.net', - port: 443, - protocol: 'https', - logging: false - }); - - const loader = new ArweaveGatewayInteractionsLoader(arweave); - const benchmark = Benchmark.measure(); - await loader.load( - contractId, - fromBlockHeight ? parseInt(fromBlockHeight) : 0, - toBlockHeight ? parseInt(toBlockHeight) : 831900, - new DefaultEvaluationOptions() - ); - return benchmark.elapsed(); -} -gatewayComparisonBenchmark().catch((e) => console.error(e));