From 4eca0f15101eb75c8fe577b0a23d470353196be5 Mon Sep 17 00:00:00 2001 From: Guillermo Rodriguez Date: Mon, 11 Dec 2023 23:58:09 -0300 Subject: [PATCH] Improve build output and export everything --- package.json | 13 +++++-------- scripts/create-dist-packages.mjs | 2 +- scripts/docker-stop.mjs | 2 +- src/controllerUtils.ts | 2 +- {tests => src/tests}/hyperion-sequence.spec.ts | 10 +++++----- {tests => src/tests}/utils.ts | 9 +++++---- tsconfig.json | 3 ++- yarn.lock | 9 +++++++++ 8 files changed, 29 insertions(+), 21 deletions(-) rename {tests => src/tests}/hyperion-sequence.spec.ts (86%) rename {tests => src/tests}/utils.ts (89%) diff --git a/package.json b/package.json index fa5d054..0a677c4 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,18 @@ { - "name": "leap-mock", + "name": "@guilledk/leap-mock", "repository": "guilledk/leap-mock", "version": "0.1.0", "description": "AntelopeIO/leap mocker for advanced indexer testing", - "main": "./build/src/main.js", + "main": "./build/main.js", + "type": "module", "exports": { - ".": { - "import": "./build/src/main.js" - } + ".": "./**/*.js" }, - "type": "module", "scripts": { "bootstrap": "sh -c 'yarn && cd node_modules/@eosrio/hyperion-sequential-reader && npm i && npx tsc'", "build": "npm run bootstrap && tsc && node scripts/create-dist-packages.mjs", "start": "node build/src/main.js", - "test": "mocha build/tests/**/*.spec.js --timeout 120000", "docker-build": "npm run build && node scripts/docker-build.mjs", @@ -31,7 +28,6 @@ "@types/ws": "^8.5.8", "async": "^3.2.4", "axios": "^1.6.2", - "chai": "^4.3.10", "commander": "^11.1.0", "express": "^4.18.2", "winston": "^3.11.0", @@ -43,6 +39,7 @@ "@types/chai": "^4.3.11", "@types/mocha": "^10.0.6", "@types/node": "^20.10.4", + "chai": "^4.3.10", "mocha": "^10.2.0", "nodemon": "^2.0.22", "ts-node": "^10.9.2", diff --git a/scripts/create-dist-packages.mjs b/scripts/create-dist-packages.mjs index 59da5db..4c87800 100644 --- a/scripts/create-dist-packages.mjs +++ b/scripts/create-dist-packages.mjs @@ -4,6 +4,6 @@ import path from 'path'; const currentDir = path.dirname(fileURLToPath(import.meta.url)); const src = path.join(currentDir, '../src/shipAbi.json'); -const dest = path.join(currentDir, '../build/src/shipAbi.json'); +const dest = path.join(currentDir, '../build/shipAbi.json'); copyFileSync(src, dest); diff --git a/scripts/docker-stop.mjs b/scripts/docker-stop.mjs index 83ba05b..924b78f 100644 --- a/scripts/docker-stop.mjs +++ b/scripts/docker-stop.mjs @@ -1,7 +1,7 @@ import {spawn} from "child_process"; // Spawn the process -const process = spawn('docker', ['kill', '--signal=SIGINT', 'leap-mock']); +const process = spawn('docker', ['kill', 'leap-mock']); // Handle standard output process.stdout.on('data', (data) => { diff --git a/src/controllerUtils.ts b/src/controllerUtils.ts index f5ceab6..f61b237 100644 --- a/src/controllerUtils.ts +++ b/src/controllerUtils.ts @@ -4,7 +4,7 @@ import controllerRouter from "./controllerRoutes.js"; import * as http from "http"; import process from "process"; import ControllerHTTPClient from "./controllerHTTPClient.js"; -import {generateTestChainDescriptor} from "../tests/utils.js"; +import {generateTestChainDescriptor} from "./tests/utils.js"; import logger from "./logging.js"; process.on('unhandledRejection', error => { diff --git a/tests/hyperion-sequence.spec.ts b/src/tests/hyperion-sequence.spec.ts similarity index 86% rename from tests/hyperion-sequence.spec.ts rename to src/tests/hyperion-sequence.spec.ts index 7407bae..a6bc0e5 100644 --- a/tests/hyperion-sequence.spec.ts +++ b/src/tests/hyperion-sequence.spec.ts @@ -1,6 +1,6 @@ -import {ControllerContext} from "../src/controllerUtils.js"; -import {ControllerConfig} from "../src/controller.js"; -import {getRandomPort} from "../src/utils.js"; +import {ControllerContext} from "../controllerUtils.js"; +import {ControllerConfig} from "../controller.js"; +import {getRandomPort} from "../utils.js"; import {expectSequence} from "./utils.js"; @@ -38,7 +38,7 @@ describe('Hyperion In Order Sequence', async function () { context.registerTestChain(testForkDoubleName, { jumps: [[5, 3], [6, 6]]}); it(testForkDoubleName, async function () { - const chainInfo = context.getTestChain(testForkName); + const chainInfo = context.getTestChain(testForkDoubleName); return await expectSequence( chainInfo, [ @@ -59,7 +59,7 @@ describe('Hyperion In Order Sequence', async function () { context.registerTestChain(testReconMultiName, { pauses: [[3, 2], [10, 2]]}); it(testReconMultiName, async function () { - const chainInfo = context.getTestChain(testReconName); + const chainInfo = context.getTestChain(testReconMultiName); return await expectSequence(chainInfo, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]); }); }); diff --git a/tests/utils.ts b/src/tests/utils.ts similarity index 89% rename from tests/utils.ts rename to src/tests/utils.ts index 6de5fa8..89b77b3 100644 --- a/tests/utils.ts +++ b/src/tests/utils.ts @@ -1,7 +1,8 @@ -import {ChainDescriptor, NewChainInfo} from "../src/controller.js"; +import {ChainDescriptor, NewChainInfo} from "../controller.js"; import {HyperionSequentialReader} from "@eosrio/hyperion-sequential-reader"; -import {sleep, randomHash} from "../src/utils.js"; +import {sleep, randomHash} from "../utils.js"; import {assert} from "chai"; +import logging from "../logging.js"; export function generateTestChainDescriptor( chainId?: string, @@ -39,13 +40,13 @@ export async function expectSequence( blockConcurrency: 1, outputQueueLimit: 10, startBlock: 1, - logLevel: 'debug' + logLevel: logging.level }); reader.onDisconnect = async () => { if (!isExpectedSequence || reachedEnd) return; - reader.log('warning', `reader disconnected, restarting in 3 seconds...`); + logging.info(`reader disconnected, restarting in 3 seconds...`); await sleep(3 * 1000); reader.restart(); }; diff --git a/tsconfig.json b/tsconfig.json index b852120..057923b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "baseUrl": "src", "module": "esnext", "outDir": "build", + "rootDir": "./src", "target": "esnext", "moduleResolution": "node", "declaration": true, @@ -27,5 +28,5 @@ }, "compileOnSave": false, "exclude": ["node_modules", "dist", "build"], - "include": ["src", "tests"] + "include": ["src/**/*.ts"] } diff --git a/yarn.lock b/yarn.lock index b5fe6b7..0c5a0e0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -23,6 +23,15 @@ enabled "2.0.x" kuler "^2.0.0" +"@eosrio/hyperion-sequential-reader@https://github.com/eosrio/hyperion-sequential-reader.git#hist_buf_size": + version "1.2.5" + resolved "https://github.com/eosrio/hyperion-sequential-reader.git#87839c6cfa5b2a5df017c36bb65e7edd17ae80ba" + dependencies: + "@greymass/eosio" "0.6.11" + async "^3.2.4" + node-fetch "^3.3.0" + ws "^8.13.0" + "@esbuild/android-arm64@0.18.20": version "0.18.20" resolved "https://registry.yarnpkg.com/@esbuild/android-arm64/-/android-arm64-0.18.20.tgz#984b4f9c8d0377443cc2dfcef266d02244593622"