From 37f27d3b6a526a37a88ccbf7480f4bc6dc06153f Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Thu, 15 Feb 2024 10:58:12 -0600 Subject: [PATCH] fix(structure): use snake case for file and folder names --- .eslintrc | 13 +++--- jest.config.ts | 2 +- src/common/{ArIO.ts => ar-io.ts} | 4 +- ...rNSRemoteCache.ts => arns-remote-cache.ts} | 12 ++++-- src/common/caches/index.ts | 2 +- src/common/http.ts | 2 +- src/common/index.ts | 2 +- src/constants.ts | 2 + src/types.ts | 6 +++ src/utils/{httpClient.ts => http-client.ts} | 0 tests/ArIO.test.ts | 19 ++++++++- tests/ArNSRemoteCache.test.ts | 4 +- tests/fixtures/arns-service-responses.ts | 40 +++++++++++++++++++ 13 files changed, 88 insertions(+), 20 deletions(-) rename src/common/{ArIO.ts => ar-io.ts} (94%) rename src/common/caches/{ArNSRemoteCache.ts => arns-remote-cache.ts} (88%) rename src/utils/{httpClient.ts => http-client.ts} (100%) create mode 100644 tests/fixtures/arns-service-responses.ts diff --git a/.eslintrc b/.eslintrc index f8f9fbb0..c05fc2a9 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,11 +5,11 @@ "eslint:recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", - "plugin:prettier/recommended" + "plugin:prettier/recommended", ], "parser": "@typescript-eslint/parser", "parserOptions": { - "project": "./tsconfig.json" + "project": "./tsconfig.json", }, "rules": { "header/header": ["error", "resources/license.header.js"], @@ -19,8 +19,9 @@ { "allowNullableObject": true, "allowNullableBoolean": true, - "allowAny": true - } - ] - } + "allowAny": true, + }, + ], + "@typescript-eslint/no-unused-vars": "error", + }, } diff --git a/jest.config.ts b/jest.config.ts index 5222b745..af9dfd64 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -6,7 +6,7 @@ module.exports = { collectCoverage: true, collectCoverageFrom: ['src/**/*.ts', 'tests/**/*.ts'], testEnvironment: 'node', - testTimeout: 5000, + testTimeout: 60_000, extensionsToTreatAsEsm: ['.ts'], transform: { '^.+\\.(ts|js)$': ['ts-jest', { useESM: true }], diff --git a/src/common/ArIO.ts b/src/common/ar-io.ts similarity index 94% rename from src/common/ArIO.ts rename to src/common/ar-io.ts index db33fcfd..06982746 100644 --- a/src/common/ArIO.ts +++ b/src/common/ar-io.ts @@ -31,11 +31,11 @@ export class ArIO implements ContractCache { * Fetches the state of a contract. * @param {string} contractTxId - The Arweave transaction id of the contract. */ - async getContractState({ + async getContractState({ contractTxId, }: { contractTxId: string; - }): Promise { + }): Promise { return this.contractStateProvider.getContractState({ contractTxId }); } } diff --git a/src/common/caches/ArNSRemoteCache.ts b/src/common/caches/arns-remote-cache.ts similarity index 88% rename from src/common/caches/ArNSRemoteCache.ts rename to src/common/caches/arns-remote-cache.ts index 22e66a43..0ab3e487 100644 --- a/src/common/caches/ArNSRemoteCache.ts +++ b/src/common/caches/arns-remote-cache.ts @@ -14,7 +14,11 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -import { ContractCache, HTTPClient } from '../../types.js'; +import { + ContractCache, + EvaluatedContractState, + HTTPClient, +} from '../../types.js'; import { AxiosHTTPService } from '../http.js'; import { DefaultLogger } from '../logger.js'; @@ -39,14 +43,14 @@ export class ArNSRemoteCache implements ContractCache { }); } - async getContractState({ + async getContractState({ contractTxId, }: { contractTxId: string; - }): Promise { + }): Promise { this.logger.debug(`Fetching contract state`); - const state = await this.http.get({ + const { state } = await this.http.get>({ endpoint: `/contract/${contractTxId.toString()}`, }); diff --git a/src/common/caches/index.ts b/src/common/caches/index.ts index 1a043925..1f8d0053 100644 --- a/src/common/caches/index.ts +++ b/src/common/caches/index.ts @@ -14,4 +14,4 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -export * from './ArNSRemoteCache.js'; +export * from './arns-remote-cache.js'; diff --git a/src/common/http.ts b/src/common/http.ts index 1f0cf2e8..3ccb209d 100644 --- a/src/common/http.ts +++ b/src/common/http.ts @@ -19,7 +19,7 @@ import { Readable } from 'stream'; import { ReadableStream } from 'stream/web'; import { HTTPClient, Logger } from '../types.js'; -import { createAxiosInstance } from '../utils/httpClient.js'; +import { createAxiosInstance } from '../utils/http-client.js'; import { FailedRequestError } from './error.js'; export class AxiosHTTPService implements HTTPClient { diff --git a/src/common/index.ts b/src/common/index.ts index 34c6b2fa..8901ae5e 100644 --- a/src/common/index.ts +++ b/src/common/index.ts @@ -14,7 +14,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -export * from './ArIO.js'; +export * from './ar-io.js'; export * from './caches/index.js'; export * from './error.js'; export * from './logger.js'; diff --git a/src/constants.ts b/src/constants.ts index e0f29233..177e8b5b 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -16,3 +16,5 @@ */ export const ARWEAVE_TX_REGEX = new RegExp('^[a-zA-Z0-9_-]{43}$'); +export const ARNS_REGISTRY_TX = + process.env.ARNS_REGISTRY_TX ?? 'bLAgYxAdX2Ry-nt6aH2ixgvJXbpsEYm28NgJgyqfs-U'; diff --git a/src/types.ts b/src/types.ts index f70f4008..9281e572 100644 --- a/src/types.ts +++ b/src/types.ts @@ -16,6 +16,7 @@ */ import { Readable } from 'stream'; import { ReadableStream } from 'stream/web'; +import { EvalStateResult, EvaluationOptions } from 'warp-contracts/web'; export interface ContractCache { /** @@ -24,6 +25,11 @@ export interface ContractCache { getContractState({ contractTxId }: { contractTxId: string }): Promise; } +export type EvaluatedContractState = EvalStateResult & { + sortKey: string; + evaluationOptions: EvaluationOptions; +}; + /* eslint-disable @typescript-eslint/no-explicit-any */ export interface Logger { setLogLevel: (level: string) => void; diff --git a/src/utils/httpClient.ts b/src/utils/http-client.ts similarity index 100% rename from src/utils/httpClient.ts rename to src/utils/http-client.ts diff --git a/tests/ArIO.test.ts b/tests/ArIO.test.ts index aafbc1cd..3692bf18 100644 --- a/tests/ArIO.test.ts +++ b/tests/ArIO.test.ts @@ -1,5 +1,12 @@ -import { ArIO } from '../src/common/ArIO.js'; -import { ArNSRemoteCache } from '../src/common/caches/ArNSRemoteCache.js'; +import { ArIO } from '../src/common/ar-io.js'; +import { ArNSRemoteCache } from '../src/common/caches/arns-remote-cache.js'; +import { AxiosHTTPService } from '../src/common/http.js'; +import { ARNS_REGISTRY_TX } from '../src/constants.js'; +import { ArnsStateResponse } from './fixtures/arns-service-responses.js'; + +jest + .spyOn(AxiosHTTPService.prototype, 'get') + .mockResolvedValue(ArnsStateResponse); describe('ArIO Client', () => { const remoteCacheProvider = new ArNSRemoteCache({}); @@ -10,4 +17,12 @@ describe('ArIO Client', () => { it('should create an ArIO client', () => { expect(arioClient).toBeInstanceOf(ArIO); }); + + it('should get a contract state', async () => { + const state = await arioClient.getContractState>({ + contractTxId: ARNS_REGISTRY_TX, + }); + expect(state).toBeDefined(); + expect(state).toHaveProperty('gateways'); + }); }); diff --git a/tests/ArNSRemoteCache.test.ts b/tests/ArNSRemoteCache.test.ts index bb03abc5..c6f73900 100644 --- a/tests/ArNSRemoteCache.test.ts +++ b/tests/ArNSRemoteCache.test.ts @@ -1,5 +1,5 @@ -import { ArIO } from '../src/common/ArIO.js'; -import { ArNSRemoteCache } from '../src/common/caches/ArNSRemoteCache.js'; +import { ArIO } from '../src/common/ar-io.js'; +import { ArNSRemoteCache } from '../src/common/caches/arns-remote-cache.js'; describe('ArIO Client', () => { const remoteCacheProvider = new ArNSRemoteCache({}); diff --git a/tests/fixtures/arns-service-responses.ts b/tests/fixtures/arns-service-responses.ts new file mode 100644 index 00000000..4f6338e3 --- /dev/null +++ b/tests/fixtures/arns-service-responses.ts @@ -0,0 +1,40 @@ +export const ArnsStateResponse = { + contractTxId: 'bLAgYxAdX2Ry-nt6aH2ixgvJXbpsEYm28NgJgyqfs-U', + state: { + ticker: 'ARNS-TEST', + name: 'Arweave Name System Test', + version: '0.0.18', + owner: '', + evolve: null, + records: {}, + balances: {}, + vaults: {}, + reserved: {}, + fees: {}, + auctions: {}, + settings: {}, + gateways: {}, + observations: {}, + demandFactoring: { + periodZeroBlockHeight: 0, + currentPeriod: 0, + trailingPeriodPurchases: [0, 0, 0, 0, 0, 0, 0], + trailingPeriodRevenues: [0, 0, 0, 0, 0, 0, 0], + purchasesThisPeriod: 0, + demandFactor: 1, + revenueThisPeriod: 0, + consecutivePeriodsWithMinDemandFactor: 0, + }, + }, + sortKey: + '000001301946,0000000000000,d2efe5278648460ed160e1d8a28fb86ab686e36cf14a3321d0a2b10c6851ea99', + evaluationOptions: { + sourceType: 'arweave', + internalWrites: true, + useKVStorage: true, + remoteStateSyncEnabled: true, + waitForConfirmation: true, + maxInteractionEvaluationTimeSeconds: 0, + throwOnInternalWriteError: true, + }, +};