diff --git a/.depcheckrc b/.depcheckrc new file mode 100644 index 0000000..80c1581 --- /dev/null +++ b/.depcheckrc @@ -0,0 +1 @@ +ignores: ['ts-node'] diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bceb529..eb59986 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -41,7 +41,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@master with: - node-version: 18.x + node-version: 20.x - name: Use npm latest run: npm install -g npm@latest - name: Cache Node.js modules @@ -64,7 +64,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@master with: - node-version: 18.x + node-version: 20.x - name: Use npm latest run: npm install -g npm@latest - name: Cache Node.js modules @@ -86,7 +86,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@master with: - node-version: 18.x + node-version: 20.x - name: Use npm latest run: npm install -g npm@latest - name: Cache Node.js modules @@ -100,7 +100,7 @@ jobs: - name: Install Packages run: npm ci - name: Setup dependencies - run: docker-compose up -d + run: docker compose -f ./docker-compose-test.yaml up -d - name: Sleep uses: kibertoad/wait-action@1.0.1 with: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8fb50a7..70b2ec1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -30,7 +30,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@master with: - node-version: 18.x + node-version: 20.x - name: Use npm latest run: npm install -g npm@latest - name: Cache Node.js modules @@ -52,7 +52,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@master with: - node-version: 18.x + node-version: 20.x - name: Use npm latest run: npm install -g npm@latest - name: Cache Node.js modules @@ -86,7 +86,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@master with: - node-version: 18.x + node-version: 20.x - name: Use npm latest run: npm install -g npm@latest - name: Cache Node.js modules @@ -100,7 +100,7 @@ jobs: - name: Install Packages run: npm ci - name: Setup dependencies - run: docker-compose up -d + run: docker compose -f ./docker-compose-test.yaml up -d - name: Sleep uses: kibertoad/wait-action@1.0.1 with: diff --git a/README.md b/README.md index beb2216..45fbec0 100644 --- a/README.md +++ b/README.md @@ -18,26 +18,19 @@ To start the basic application npm run local ``` -To run the tests - -```shell -npm run test -npm run test:unit -``` - To install npm CLI tool. It will be linked to local binaries so can be executed as `process-management` ```shell npm i -g ``` -# using CLI +## using CLI ```sh process-management help ``` -## Options +### Options `dscp-process-management` takes the following arguments to configure the `Polkadot.js` API connection: @@ -198,3 +191,23 @@ $ process-management list --active } ] ``` + +## Running tests + +Unit tests can be run without docker using: + +```shell +npm run test:unit +``` + +To run the integration test suite first bring up the test dependency services using docker + +```shell +docker compose -f ./docker-compose-test.yaml up -d +``` + +And then to run the tests + +```shell +npm run test +``` diff --git a/docker-compose-test.yaml b/docker-compose-test.yaml new file mode 100644 index 0000000..2073091 --- /dev/null +++ b/docker-compose-test.yaml @@ -0,0 +1,15 @@ +version: '3' +services: + dscp-node: + image: digicatapult/dscp-node:latest + command: --base-path /data/ + --dev + --manual-seal + --unsafe-ws-external + --unsafe-rpc-external + --rpc-cors all + ports: + - 30333:30333 + - 9944:9944 + - 9933:9933 + restart: on-failure diff --git a/package-lock.json b/package-lock.json index eb6a9ff..681d259 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,17 @@ { "name": "@digicatapult/dscp-process-management", - "version": "2.0.17", + "version": "2.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@digicatapult/dscp-process-management", - "version": "2.0.17", + "version": "2.1.0", "license": "Apache-2.0", "dependencies": { "@polkadot/api": "^10.11.1", "chalk": "^5.3.0", "commander": "^11.1.0", - "ts-node": "^10.9.2", "typescript": "^5.3.3", "zod": "^3.22.4" }, @@ -35,11 +34,12 @@ "mocha": "^10.2.0", "nodemon": "^3.0.2", "prettier": "^3.1.1", - "ts-mocha": "^10.0.0" + "ts-mocha": "^10.0.0", + "ts-node": "^10.9.2" }, "engines": { - "node": ">=18.x.x", - "npm": ">=9.x.x" + "node": ">=20.x.x", + "npm": ">=10.x.x" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -364,6 +364,7 @@ "version": "0.8.1", "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, "dependencies": { "@jridgewell/trace-mapping": "0.3.9" }, @@ -375,6 +376,7 @@ "version": "0.3.9", "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, "dependencies": { "@jridgewell/resolve-uri": "^3.0.3", "@jridgewell/sourcemap-codec": "^1.4.10" @@ -520,6 +522,7 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz", "integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==", + "dev": true, "engines": { "node": ">=6.0.0" } @@ -536,7 +539,8 @@ "node_modules/@jridgewell/sourcemap-codec": { "version": "1.4.15", "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz", - "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==" + "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==", + "dev": true }, "node_modules/@jridgewell/trace-mapping": { "version": "0.3.20", @@ -1136,22 +1140,26 @@ "node_modules/@tsconfig/node10": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", - "integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==" + "integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==", + "dev": true }, "node_modules/@tsconfig/node12": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", - "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==" + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", + "dev": true }, "node_modules/@tsconfig/node14": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", - "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==" + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", + "dev": true }, "node_modules/@tsconfig/node16": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.3.tgz", - "integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==" + "integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==", + "dev": true }, "node_modules/@types/bn.js": { "version": "5.1.5", @@ -1495,6 +1503,7 @@ "version": "8.9.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.9.0.tgz", "integrity": "sha512-jaVNAFBHNLXspO543WnNNPZFRtavh3skAkITqD0/2aeMkKZTN+254PyhwxFYrk3vQ1xfY+2wbesJMs/JC8/PwQ==", + "dev": true, "bin": { "acorn": "bin/acorn" }, @@ -1515,6 +1524,7 @@ "version": "8.2.0", "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", + "dev": true, "engines": { "node": ">=0.4.0" } @@ -1584,7 +1594,8 @@ "node_modules/arg": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", - "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==" + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true }, "node_modules/argparse": { "version": "1.0.10", @@ -1905,7 +1916,8 @@ "node_modules/create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", - "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==" + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true }, "node_modules/cross-spawn": { "version": "7.0.3", @@ -3311,7 +3323,8 @@ "node_modules/make-error": { "version": "1.3.6", "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", - "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==" + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true }, "node_modules/merge-stream": { "version": "2.0.0", @@ -4616,6 +4629,7 @@ "version": "10.9.2", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", + "dev": true, "dependencies": { "@cspotcode/source-map-support": "^0.8.0", "@tsconfig/node10": "^1.0.7", @@ -4658,6 +4672,7 @@ "version": "4.0.2", "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true, "engines": { "node": ">=0.3.1" } @@ -4770,7 +4785,8 @@ "node_modules/v8-compile-cache-lib": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", - "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==" + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", + "dev": true }, "node_modules/web-streams-polyfill": { "version": "3.2.1", @@ -4914,6 +4930,7 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true, "engines": { "node": ">=6" } @@ -5191,6 +5208,7 @@ "version": "0.8.1", "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, "requires": { "@jridgewell/trace-mapping": "0.3.9" }, @@ -5199,6 +5217,7 @@ "version": "0.3.9", "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, "requires": { "@jridgewell/resolve-uri": "^3.0.3", "@jridgewell/sourcemap-codec": "^1.4.10" @@ -5307,7 +5326,8 @@ "@jridgewell/resolve-uri": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz", - "integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==" + "integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==", + "dev": true }, "@jridgewell/set-array": { "version": "1.1.2", @@ -5318,7 +5338,8 @@ "@jridgewell/sourcemap-codec": { "version": "1.4.15", "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz", - "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==" + "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==", + "dev": true }, "@jridgewell/trace-mapping": { "version": "0.3.20", @@ -5766,22 +5787,26 @@ "@tsconfig/node10": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", - "integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==" + "integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==", + "dev": true }, "@tsconfig/node12": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", - "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==" + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", + "dev": true }, "@tsconfig/node14": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", - "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==" + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", + "dev": true }, "@tsconfig/node16": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.3.tgz", - "integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==" + "integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==", + "dev": true }, "@types/bn.js": { "version": "5.1.5", @@ -6035,7 +6060,8 @@ "acorn": { "version": "8.9.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.9.0.tgz", - "integrity": "sha512-jaVNAFBHNLXspO543WnNNPZFRtavh3skAkITqD0/2aeMkKZTN+254PyhwxFYrk3vQ1xfY+2wbesJMs/JC8/PwQ==" + "integrity": "sha512-jaVNAFBHNLXspO543WnNNPZFRtavh3skAkITqD0/2aeMkKZTN+254PyhwxFYrk3vQ1xfY+2wbesJMs/JC8/PwQ==", + "dev": true }, "acorn-jsx": { "version": "5.3.2", @@ -6047,7 +6073,8 @@ "acorn-walk": { "version": "8.2.0", "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", - "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==" + "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", + "dev": true }, "ajv": { "version": "6.12.6", @@ -6095,7 +6122,8 @@ "arg": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", - "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==" + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true }, "argparse": { "version": "1.0.10", @@ -6338,7 +6366,8 @@ "create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", - "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==" + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true }, "cross-spawn": { "version": "7.0.3", @@ -7352,7 +7381,8 @@ "make-error": { "version": "1.3.6", "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", - "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==" + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true }, "merge-stream": { "version": "2.0.0", @@ -8231,6 +8261,7 @@ "version": "10.9.2", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", + "dev": true, "requires": { "@cspotcode/source-map-support": "^0.8.0", "@tsconfig/node10": "^1.0.7", @@ -8250,7 +8281,8 @@ "diff": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", - "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==" + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true } } }, @@ -8339,7 +8371,8 @@ "v8-compile-cache-lib": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", - "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==" + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", + "dev": true }, "web-streams-polyfill": { "version": "3.2.1", @@ -8438,7 +8471,8 @@ "yn": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", - "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==" + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true }, "yocto-queue": { "version": "0.1.0", diff --git a/package.json b/package.json index 49ffd92..04f3133 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@digicatapult/dscp-process-management", - "version": "2.0.17", + "version": "2.1.0", "description": "DSCP Process Management Flow", "main": "./lib/index.js", "bin": { @@ -8,9 +8,9 @@ }, "type": "module", "scripts": { - "start": "ts-node --esm src/index.ts", + "start": "node --loader ts-node/esm src/index.ts", "local": "npm i -g && process-management", - "dev": "nodemon --watch 'src/**/*.ts' --exec ts-node --esm src/index.ts", + "dev": "nodemon --watch 'src/**/*.ts' --exec node --loader ts-node/esm src/index.ts", "lint": "eslint . --ext .ts", "build": "tsc --build", "depcheck": "depcheck", @@ -26,8 +26,8 @@ "/build" ], "engines": { - "node": ">=18.x.x", - "npm": ">=9.x.x" + "node": ">=20.x.x", + "npm": ">=10.x.x" }, "author": "Digital Catapult", "license": "Apache-2.0", @@ -51,13 +51,13 @@ "mocha": "^10.2.0", "nodemon": "^3.0.2", "prettier": "^3.1.1", - "ts-mocha": "^10.0.0" + "ts-mocha": "^10.0.0", + "ts-node": "^10.9.2" }, "dependencies": { "@polkadot/api": "^10.11.1", "chalk": "^5.3.0", "commander": "^11.1.0", - "ts-node": "^10.9.2", "typescript": "^5.3.3", "zod": "^3.22.4" } diff --git a/src/lib/process/api.ts b/src/lib/process/api.ts index 414deba..2e6de7c 100644 --- a/src/lib/process/api.ts +++ b/src/lib/process/api.ts @@ -21,36 +21,37 @@ export const createProcessTransaction = async ( options: Polkadot.Options ): Promise => { const sudo = polkadot.keyring.addFromUri(options.USER_URI) + const supportsManualSeal = !!polkadot.api.rpc.engine.createBlock if (!isProgramValid(program)) throw new ProgramError('invalid program') - return new Promise((resolve, reject) => { - let unsub: Function - polkadot.api.tx.sudo - .sudo(polkadot.api.tx.processValidation.createProcess(processId, program)) - .signAndSend(sudo, (result: any) => { - if (result.status.isInBlock) { - const { event } = result.events.find( - ({ event: { method } }: { event: { method: string } }) => method === 'ProcessCreated' - ) + return new Promise(async (resolve, reject) => { + try { + const unsub = await polkadot.api.tx.sudo + .sudo(polkadot.api.tx.processValidation.createProcess(processId, program)) + .signAndSend(sudo, (result: any) => { + if (result.status.isFinalized) { + const { event } = result.events.find( + ({ event: { method } }: { event: { method: string } }) => method === 'ProcessCreated' + ) - const data = event.data - const newProcess: Process.Payload = { - name: data[0].toHuman(), - version: data[1].toNumber(), - status: 'Enabled', - program, + const data = event.data + const newProcess: Process.Payload = { + name: data[0].toHuman(), + version: data[1].toNumber(), + status: 'Enabled', + program, + } + unsub() + resolve(newProcess) } - unsub() - resolve(newProcess) - } - }) - .then((res: Function) => { - unsub = res - }) - .catch((err: Error) => { - reject(err) - }) + }) + if (supportsManualSeal) { + await polkadot.api.rpc.engine.createBlock(true, true) + } + } catch (err) { + reject(err) + } }) } @@ -61,34 +62,35 @@ export const disableProcessTransaction = async ( options: Polkadot.Options ): Promise => { const sudo = polkadot.keyring.addFromUri(options.USER_URI) + const supportsManualSeal = !!polkadot.api.rpc.engine.createBlock - return new Promise((resolve, reject) => { - let unsub: Function - polkadot.api.tx.sudo - .sudo(polkadot.api.tx.processValidation.disableProcess(processId, version)) - .signAndSend(sudo, (result: any) => { - if (result.status.isInBlock) { - const { event } = result.events.find( - ({ event: { method } }: { event: { method: string } }) => method === 'ProcessDisabled' - ) + return new Promise(async (resolve, reject) => { + try { + const unsub = await polkadot.api.tx.sudo + .sudo(polkadot.api.tx.processValidation.disableProcess(processId, version)) + .signAndSend(sudo, (result: any) => { + if (result.status.isFinalized) { + const { event } = result.events.find( + ({ event: { method } }: { event: { method: string } }) => method === 'ProcessDisabled' + ) - const data = event.data - const disabledProcess: Process.Payload = { - name: data[0].toHuman(), - version: data[1].toNumber(), - status: 'Disabled', - } + const data = event.data + const disabledProcess: Process.Payload = { + name: data[0].toHuman(), + version: data[1].toNumber(), + status: 'Disabled', + } - unsub() - resolve(disabledProcess) - } - }) - .then((res: Function) => { - unsub = res - }) - .catch((err: Error) => { - reject(err) - }) + unsub() + resolve(disabledProcess) + } + }) + if (supportsManualSeal) { + await polkadot.api.rpc.engine.createBlock(true, true) + } + } catch (err) { + reject(err) + } }) } diff --git a/src/lib/types/process.d.ts b/src/lib/types/process.d.ts index 974a2b4..5f1973e 100644 --- a/src/lib/types/process.d.ts +++ b/src/lib/types/process.d.ts @@ -21,6 +21,7 @@ declare namespace Process { export type CLIOptions = { print?: boolean + manualSeal?: boolean dryRun?: boolean active?: boolean disabled?: boolean diff --git a/tests/integration/command-functions.test.ts b/tests/integration/command-functions.test.ts index 02963b3..bbdb68a 100644 --- a/tests/integration/command-functions.test.ts +++ b/tests/integration/command-functions.test.ts @@ -20,7 +20,7 @@ import { getAll } from '../../src/lib/process/api.js' /* fixtures */ import processesExample from '../fixtures/processes.js' -const polkadotOptions = { API_HOST: 'localhost', API_PORT: 9944, USER_URI: '//Alice' } +const polkadotOptions = { API_HOST: 'localhost', API_PORT: 9944, USER_URI: '//Alice', MANUAL_SEAL: true } describe('Process creation and deletion, listing', () => { describe('Happy path', () => {