Skip to content

Commit

Permalink
fix(structure): use snake case for file and folder names
Browse files Browse the repository at this point in the history
  • Loading branch information
atticusofsparta committed Feb 15, 2024
1 parent 844c1aa commit 37f27d3
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 20 deletions.
13 changes: 7 additions & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -19,8 +19,9 @@
{
"allowNullableObject": true,
"allowNullableBoolean": true,
"allowAny": true
}
]
}
"allowAny": true,
},
],
"@typescript-eslint/no-unused-vars": "error",
},
}
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }],
Expand Down
4 changes: 2 additions & 2 deletions src/common/ArIO.ts → src/common/ar-io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContractState>({
async getContractState<T>({
contractTxId,
}: {
contractTxId: string;
}): Promise<ContractState> {
}): Promise<T> {
return this.contractStateProvider.getContractState({ contractTxId });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { ContractCache, HTTPClient } from '../../types.js';
import {
ContractCache,
EvaluatedContractState,
HTTPClient,
} from '../../types.js';
import { AxiosHTTPService } from '../http.js';
import { DefaultLogger } from '../logger.js';

Expand All @@ -39,14 +43,14 @@ export class ArNSRemoteCache implements ContractCache {
});
}

async getContractState<ContractState>({
async getContractState<T>({
contractTxId,
}: {
contractTxId: string;
}): Promise<ContractState> {
}): Promise<T> {
this.logger.debug(`Fetching contract state`);

const state = await this.http.get<ContractState>({
const { state } = await this.http.get<EvaluatedContractState<T>>({
endpoint: `/contract/${contractTxId.toString()}`,
});

Expand Down
2 changes: 1 addition & 1 deletion src/common/caches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
export * from './ArNSRemoteCache.js';
export * from './arns-remote-cache.js';
2 changes: 1 addition & 1 deletion src/common/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
export * from './ArIO.js';
export * from './ar-io.js';
export * from './caches/index.js';
export * from './error.js';
export * from './logger.js';
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
import { Readable } from 'stream';
import { ReadableStream } from 'stream/web';
import { EvalStateResult, EvaluationOptions } from 'warp-contracts/web';

export interface ContractCache {
/**
Expand All @@ -24,6 +25,11 @@ export interface ContractCache {
getContractState<T>({ contractTxId }: { contractTxId: string }): Promise<T>;
}

export type EvaluatedContractState<T> = EvalStateResult<T> & {
sortKey: string;
evaluationOptions: EvaluationOptions;
};

/* eslint-disable @typescript-eslint/no-explicit-any */
export interface Logger {
setLogLevel: (level: string) => void;
Expand Down
File renamed without changes.
19 changes: 17 additions & 2 deletions tests/ArIO.test.ts
Original file line number Diff line number Diff line change
@@ -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({});
Expand All @@ -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<Record<string, any>>({
contractTxId: ARNS_REGISTRY_TX,
});
expect(state).toBeDefined();
expect(state).toHaveProperty('gateways');
});
});
4 changes: 2 additions & 2 deletions tests/ArNSRemoteCache.test.ts
Original file line number Diff line number Diff line change
@@ -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({});
Expand Down
40 changes: 40 additions & 0 deletions tests/fixtures/arns-service-responses.ts
Original file line number Diff line number Diff line change
@@ -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,
},
};

0 comments on commit 37f27d3

Please sign in to comment.