From 26f8aeb27b4020998086a71c08a9c24b1ed853cc Mon Sep 17 00:00:00 2001 From: vanishmax Date: Tue, 26 Mar 2024 12:23:45 +0100 Subject: [PATCH 01/21] feat: support JSON Schema for Tact configuration --- grammar/configSchema.json | 60 +++++++++++++++++++++++++++++++++++++++ tact.config.json | 3 +- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 grammar/configSchema.json diff --git a/grammar/configSchema.json b/grammar/configSchema.json new file mode 100644 index 000000000..c6c41ab0a --- /dev/null +++ b/grammar/configSchema.json @@ -0,0 +1,60 @@ +{ + "$schema": "https://json-schema.org/schema#", + "id": "https://raw.githubusercontent.com/vanishmax/tact/main/grammar/configSchema.json", + "title": "Tact configuration schema", + "description": "JSON Schema for Tact configuration file", + "type": "object", + "required": ["projects"], + "properties": { + "projects": { + "type": "array", + "description": "The list of all projects with compiler parameters", + "items": { + "type": "object", + "required": ["name", "path", "output"], + "properties": { + "name": { + "type": "string", + "description": "The name of a project. All generated files are prefixed with this name" + }, + "path": { + "type": "string", + "description": "The path to the root Tact file" + }, + "output": { + "type": "string", + "description": "The path to a directory where all generated files will be placed" + }, + "options": { + "type": "object", + "description": "Additional project properties", + "properties": { + "debug": { + "type": "boolean", + "description": "Enables debug output of a contract. It is useful for debugging purposes. Enabling this contract would report that it was compiled in debug mode using the supported_interfaces method" + }, + "masterchain": { + "type": "boolean", + "description": "Enables masterchain support in the contract" + }, + "external": { + "type": "boolean", + "description": "Allows the contract to call external functions" + }, + "experimental": { + "type": "object", + "description": "Experimental project properties. Might be removed in the future", + "properties": { + "inline": { + "type": "boolean", + "description": "Enables inlining of all functions in contracts. Could reduce gas usage at the cost of a bigger contract" + } + } + } + } + } + } + } + } + } +} diff --git a/tact.config.json b/tact.config.json index 36238f424..48441cdab 100644 --- a/tact.config.json +++ b/tact.config.json @@ -1,4 +1,5 @@ { + "$schema": "https://raw.githubusercontent.com/vanishmax/tact/main/grammar/configSchema.json", "projects": [ { "name": "echo", @@ -269,4 +270,4 @@ } } ] -} \ No newline at end of file +} From 73889f613ba16cef8b66ae3de777385f63e99d87 Mon Sep 17 00:00:00 2001 From: vanishmax Date: Tue, 26 Mar 2024 13:06:16 +0100 Subject: [PATCH 02/21] feat: add tests for config schema --- grammar/configSchema.json | 4 ++-- package.json | 1 + src/test/schema.spec.ts | 31 +++++++++++++++++++++++++++++++ src/test/test-tact.config.json | 21 +++++++++++---------- tact.config.json | 2 +- yarn.lock | 20 ++++++++++++++++++++ 6 files changed, 66 insertions(+), 13 deletions(-) create mode 100644 src/test/schema.spec.ts diff --git a/grammar/configSchema.json b/grammar/configSchema.json index c6c41ab0a..f07bc7b4f 100644 --- a/grammar/configSchema.json +++ b/grammar/configSchema.json @@ -1,6 +1,6 @@ { - "$schema": "https://json-schema.org/schema#", - "id": "https://raw.githubusercontent.com/vanishmax/tact/main/grammar/configSchema.json", + "$schema": "http://json-schema.org/schema#", + "$id": "https://raw.githubusercontent.com/vanishmax/tact/main/grammar/configSchema.json", "title": "Tact configuration schema", "description": "JSON Schema for Tact configuration file", "type": "object", diff --git a/package.json b/package.json index 0418f66c1..64004f26d 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "@types/qs": "^6.9.7", "@typescript-eslint/eslint-plugin": "^7.0.2", "@typescript-eslint/parser": "^7.0.2", + "ajv": "^8.12.0", "cross-env": "^7.0.3", "eslint": "^8.56.0", "glob": "^8.1.0", diff --git a/src/test/schema.spec.ts b/src/test/schema.spec.ts new file mode 100644 index 000000000..db086a976 --- /dev/null +++ b/src/test/schema.spec.ts @@ -0,0 +1,31 @@ +import fs from 'fs'; +import path from 'path'; +import Ajv from 'ajv'; +import { __DANGER_resetNodeId } from '../grammar/ast'; + +describe('configuration schema', () => { + const ajv = new Ajv(); + const schema = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '..', 'grammar', 'configSchema.json'), 'utf8')); + + beforeEach(() => { + __DANGER_resetNodeId(); + }); + + it('should validate Tact config', () => { + const tactConfig = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '..', 'tact.config.json'), 'utf8')); + + const validate = ajv.compile(schema); + validate(tactConfig); + + expect(validate.errors).toBeNull(); + }); + + it('should validate test config', () => { + const testConfig = JSON.parse(fs.readFileSync(path.join(__dirname, 'test-tact.config.json'), 'utf8')); + + const validate = ajv.compile(schema); + validate(testConfig); + + expect(validate.errors).toBeNull(); + }); +}); diff --git a/src/test/test-tact.config.json b/src/test/test-tact.config.json index cbabf7f06..2e37ede59 100644 --- a/src/test/test-tact.config.json +++ b/src/test/test-tact.config.json @@ -1,12 +1,13 @@ { - "projects": [ - { - "name": "implicit-init-2", - "path": "./features/implicit-init-2.tact", - "output": "./features/output", - "options": { - "debug": true - } + "$schema": "https://raw.githubusercontent.com/vanishmax/tact/main/grammar/configSchema.json", + "projects": [ + { + "name": "implicit-init-2", + "path": "./features/implicit-init-2.tact", + "output": "./features/output", + "options": { + "debug": true } - ] - } \ No newline at end of file + } + ] +} diff --git a/tact.config.json b/tact.config.json index 48441cdab..423b9fcc5 100644 --- a/tact.config.json +++ b/tact.config.json @@ -1,5 +1,5 @@ { - "$schema": "https://raw.githubusercontent.com/vanishmax/tact/main/grammar/configSchema.json", + "$schema": "http://raw.githubusercontent.com/vanishmax/tact/main/grammar/configSchema.json", "projects": [ { "name": "echo", diff --git a/yarn.lock b/yarn.lock index 8733907a6..30026c858 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1323,6 +1323,16 @@ ajv@^6.12.4: json-schema-traverse "^0.4.1" uri-js "^4.2.2" +ajv@^8.12.0: + version "8.12.0" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.12.0.tgz#d1a0527323e22f53562c567c00991577dfbe19d1" + integrity sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA== + dependencies: + fast-deep-equal "^3.1.1" + json-schema-traverse "^1.0.0" + require-from-string "^2.0.2" + uri-js "^4.2.2" + ansi-align@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/ansi-align/-/ansi-align-3.0.1.tgz#0cdf12e111ace773a86e9a1fad1225c43cb19a59" @@ -4139,6 +4149,11 @@ json-schema-traverse@^0.4.1: resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660" integrity sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg== +json-schema-traverse@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz#ae7bcb3656ab77a73ba5c49bf654f38e6b6860e2" + integrity sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug== + json-stable-stringify-without-jsonify@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651" @@ -5095,6 +5110,11 @@ require-directory@^2.1.1: resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42" integrity sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q== +require-from-string@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-2.0.2.tgz#89a7fdd938261267318eafe14f9c32e598c36909" + integrity sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw== + resolve-alpn@^1.2.0: version "1.2.1" resolved "https://registry.yarnpkg.com/resolve-alpn/-/resolve-alpn-1.2.1.tgz#b7adbdac3546aaaec20b45e7d8265927072726f9" From f6580347a3b6524c735da4c95d57b66a208c77a2 Mon Sep 17 00:00:00 2001 From: vanishmax Date: Tue, 26 Mar 2024 13:08:37 +0100 Subject: [PATCH 03/21] feat: finish setting up the config JSON schema --- grammar/configSchema.json | 2 +- src/test/test-tact.config.json | 2 +- tact.config.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/grammar/configSchema.json b/grammar/configSchema.json index f07bc7b4f..f027204a0 100644 --- a/grammar/configSchema.json +++ b/grammar/configSchema.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/schema#", - "$id": "https://raw.githubusercontent.com/vanishmax/tact/main/grammar/configSchema.json", + "$id": "http://raw.githubusercontent.com/tact-lang/tact/main/grammar/configSchema.json", "title": "Tact configuration schema", "description": "JSON Schema for Tact configuration file", "type": "object", diff --git a/src/test/test-tact.config.json b/src/test/test-tact.config.json index 2e37ede59..f275e1c3d 100644 --- a/src/test/test-tact.config.json +++ b/src/test/test-tact.config.json @@ -1,5 +1,5 @@ { - "$schema": "https://raw.githubusercontent.com/vanishmax/tact/main/grammar/configSchema.json", + "$schema": "http://raw.githubusercontent.com/tact-lang/tact/main/grammar/configSchema.json", "projects": [ { "name": "implicit-init-2", diff --git a/tact.config.json b/tact.config.json index 423b9fcc5..d1d49aca2 100644 --- a/tact.config.json +++ b/tact.config.json @@ -1,5 +1,5 @@ { - "$schema": "http://raw.githubusercontent.com/vanishmax/tact/main/grammar/configSchema.json", + "$schema": "http://raw.githubusercontent.com/tact-lang/tact/main/grammar/configSchema.json", "projects": [ { "name": "echo", From a1f4e0f41de258d8a6e614707ed5e09e35d81900 Mon Sep 17 00:00:00 2001 From: vanishmax Date: Tue, 26 Mar 2024 18:53:07 +0100 Subject: [PATCH 04/21] fix: CI errors --- src/config/parseConfig.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/config/parseConfig.ts b/src/config/parseConfig.ts index f0ae1f7e0..31ea905b9 100644 --- a/src/config/parseConfig.ts +++ b/src/config/parseConfig.ts @@ -17,6 +17,7 @@ const projectSchema = z.object({ }).strict(); const configSchema = z.object({ + $schema: z.string().optional(), projects: z.array(projectSchema) }).strict(); @@ -31,4 +32,4 @@ export function parseConfig(src: string) { export function verifyConfig(config: Config) { return configSchema.parse(config); -} \ No newline at end of file +} From c11da7fb90a89970ccf3aa47c21d188e4831fd21 Mon Sep 17 00:00:00 2001 From: Max Korsunov Date: Wed, 27 Mar 2024 09:51:35 +0100 Subject: [PATCH 05/21] fix: update schema descriptions Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com> --- grammar/configSchema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grammar/configSchema.json b/grammar/configSchema.json index f027204a0..e3b9c7f41 100644 --- a/grammar/configSchema.json +++ b/grammar/configSchema.json @@ -8,7 +8,7 @@ "properties": { "projects": { "type": "array", - "description": "The list of all projects with compiler parameters", + "description": "List of Tact projects with respective compilation options. Each .tact file represents its own Tact project.", "items": { "type": "object", "required": ["name", "path", "output"], From 6328c8b5aa72387ceb982abccb083beb2d003af5 Mon Sep 17 00:00:00 2001 From: Max Korsunov Date: Wed, 27 Mar 2024 09:51:47 +0100 Subject: [PATCH 06/21] fix: update schema descriptions Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com> --- grammar/configSchema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grammar/configSchema.json b/grammar/configSchema.json index e3b9c7f41..1fc02d55b 100644 --- a/grammar/configSchema.json +++ b/grammar/configSchema.json @@ -2,7 +2,7 @@ "$schema": "http://json-schema.org/schema#", "$id": "http://raw.githubusercontent.com/tact-lang/tact/main/grammar/configSchema.json", "title": "Tact configuration schema", - "description": "JSON Schema for Tact configuration file", + "description": "JSON Schema for tact.config.json", "type": "object", "required": ["projects"], "properties": { From 70ba3d8acbfda4fd319be77724039860d203ab43 Mon Sep 17 00:00:00 2001 From: Max Korsunov Date: Wed, 27 Mar 2024 09:51:53 +0100 Subject: [PATCH 07/21] fix: update schema descriptions Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com> --- grammar/configSchema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grammar/configSchema.json b/grammar/configSchema.json index 1fc02d55b..d9683ac39 100644 --- a/grammar/configSchema.json +++ b/grammar/configSchema.json @@ -15,7 +15,7 @@ "properties": { "name": { "type": "string", - "description": "The name of a project. All generated files are prefixed with this name" + "description": "Name of the project. All generated files are prefixed with it." }, "path": { "type": "string", From c2c6055e3ae04b5d3f6041b947b2a7b9190c9340 Mon Sep 17 00:00:00 2001 From: Max Korsunov Date: Wed, 27 Mar 2024 09:52:04 +0100 Subject: [PATCH 08/21] fix: update schema descriptions Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com> --- grammar/configSchema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grammar/configSchema.json b/grammar/configSchema.json index d9683ac39..5fd950e38 100644 --- a/grammar/configSchema.json +++ b/grammar/configSchema.json @@ -19,7 +19,7 @@ }, "path": { "type": "string", - "description": "The path to the root Tact file" + "description": "Path to the project's Tact file. You can only specify one Tact file per project." }, "output": { "type": "string", From 109ec17167565781b42456f79590f1343e6190ba Mon Sep 17 00:00:00 2001 From: Max Korsunov Date: Wed, 27 Mar 2024 09:52:19 +0100 Subject: [PATCH 09/21] fix: update schema descriptions Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com> --- grammar/configSchema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grammar/configSchema.json b/grammar/configSchema.json index 5fd950e38..5c364c1e8 100644 --- a/grammar/configSchema.json +++ b/grammar/configSchema.json @@ -23,7 +23,7 @@ }, "output": { "type": "string", - "description": "The path to a directory where all generated files will be placed" + "description": "Path to the directory where all generated files will be placed." }, "options": { "type": "object", From 5998c7dc4751ddbc00daddad17094a6f81596f90 Mon Sep 17 00:00:00 2001 From: Max Korsunov Date: Wed, 27 Mar 2024 09:52:27 +0100 Subject: [PATCH 10/21] fix: update schema descriptions Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com> --- grammar/configSchema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grammar/configSchema.json b/grammar/configSchema.json index 5c364c1e8..4447a8efc 100644 --- a/grammar/configSchema.json +++ b/grammar/configSchema.json @@ -31,7 +31,7 @@ "properties": { "debug": { "type": "boolean", - "description": "Enables debug output of a contract. It is useful for debugging purposes. Enabling this contract would report that it was compiled in debug mode using the supported_interfaces method" + "description": "False by default. If set to true, enables debug output of a contract and allows usage of `dump()` function, which is useful for debugging purposes. With this option enabled, the contract will report that it was compiled in debug mode using the supported_interfaces method.\n\nRead more on debugging Tact code: https://docs.tact-lang.org/book/debug." }, "masterchain": { "type": "boolean", From a4976512c2d2614774cdfd69c33a2c730b14e2e0 Mon Sep 17 00:00:00 2001 From: Max Korsunov Date: Wed, 27 Mar 2024 09:52:40 +0100 Subject: [PATCH 11/21] fix: update schema descriptions Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com> --- grammar/configSchema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grammar/configSchema.json b/grammar/configSchema.json index 4447a8efc..eb44e2d48 100644 --- a/grammar/configSchema.json +++ b/grammar/configSchema.json @@ -27,7 +27,7 @@ }, "options": { "type": "object", - "description": "Additional project properties", + "description": "Compilation options for the project.", "properties": { "debug": { "type": "boolean", From 80537ec5a5a7886983b0dd1830d49d71fe8adaa2 Mon Sep 17 00:00:00 2001 From: Max Korsunov Date: Wed, 27 Mar 2024 09:52:48 +0100 Subject: [PATCH 12/21] fix: update schema descriptions Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com> --- grammar/configSchema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grammar/configSchema.json b/grammar/configSchema.json index eb44e2d48..c543315a8 100644 --- a/grammar/configSchema.json +++ b/grammar/configSchema.json @@ -35,7 +35,7 @@ }, "masterchain": { "type": "boolean", - "description": "Enables masterchain support in the contract" + "description": "False by default. If set to true, enables masterchain support.\n\nRead more about masterchain: https://docs.tact-lang.org/book/masterchain." }, "external": { "type": "boolean", From 8c40a2953bb10e6cea4b774635106e4352402524 Mon Sep 17 00:00:00 2001 From: Max Korsunov Date: Wed, 27 Mar 2024 09:52:54 +0100 Subject: [PATCH 13/21] fix: update schema descriptions Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com> --- grammar/configSchema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grammar/configSchema.json b/grammar/configSchema.json index c543315a8..552dce564 100644 --- a/grammar/configSchema.json +++ b/grammar/configSchema.json @@ -39,7 +39,7 @@ }, "external": { "type": "boolean", - "description": "Allows the contract to call external functions" + "description": "False by default. If set to true, enables support of external message receivers.\n\nRead more about external message receivers: https://docs.tact-lang.org/book/external." }, "experimental": { "type": "object", From 7efb443f6b4d56d27ff44fb4413df19e3b74fe6f Mon Sep 17 00:00:00 2001 From: Max Korsunov Date: Wed, 27 Mar 2024 09:53:05 +0100 Subject: [PATCH 14/21] fix: update schema descriptions Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com> --- grammar/configSchema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grammar/configSchema.json b/grammar/configSchema.json index 552dce564..de5160251 100644 --- a/grammar/configSchema.json +++ b/grammar/configSchema.json @@ -43,7 +43,7 @@ }, "experimental": { "type": "object", - "description": "Experimental project properties. Might be removed in the future", + "description": "Experimental options that might be removed in the future. Use with caution!", "properties": { "inline": { "type": "boolean", From 3091b3489899e018a31f37f874fa15b41b197d78 Mon Sep 17 00:00:00 2001 From: Max Korsunov Date: Wed, 27 Mar 2024 09:53:13 +0100 Subject: [PATCH 15/21] fix: update schema descriptions Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com> --- grammar/configSchema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grammar/configSchema.json b/grammar/configSchema.json index de5160251..5b6f35226 100644 --- a/grammar/configSchema.json +++ b/grammar/configSchema.json @@ -47,7 +47,7 @@ "properties": { "inline": { "type": "boolean", - "description": "Enables inlining of all functions in contracts. Could reduce gas usage at the cost of a bigger contract" + "description": "False by default. If set to true, enables inlining of all functions in contracts. This can reduce gas usage at the cost of bigger contracts." } } } From 8da0191223d69e643f322597743a24b5daafd44c Mon Sep 17 00:00:00 2001 From: vanishmax Date: Wed, 27 Mar 2024 16:40:56 +0100 Subject: [PATCH 16/21] refactor: separate tests into two categories: regular and formatters --- .github/workflows/tact.yml | 7 ++++--- package.json | 3 ++- src/grammar/{grammar.spec.ts => grammar.format-spec.ts} | 0 src/test/{schema.spec.ts => schema.format-spec.ts} | 0 4 files changed, 6 insertions(+), 4 deletions(-) rename src/grammar/{grammar.spec.ts => grammar.format-spec.ts} (100%) rename src/test/{schema.spec.ts => schema.format-spec.ts} (100%) diff --git a/.github/workflows/tact.yml b/.github/workflows/tact.yml index 916e1d61d..9b78115a8 100644 --- a/.github/workflows/tact.yml +++ b/.github/workflows/tact.yml @@ -14,7 +14,7 @@ jobs: matrix: node-version: [18.x] os: [ubuntu-latest, windows-latest, macos-latest] - + runs-on: ${{ matrix.os }} steps: @@ -36,10 +36,11 @@ jobs: yarn gen yarn build yarn coverage - + - name: Check there are no errors reported by ESLint run: | yarn lint + yarn test:format - name: Compare Tact version from CLI flag `--version` against package.json if: runner.os != 'Windows' @@ -61,7 +62,7 @@ jobs: yarn build yarn test yarn tact --version - + - name: Test compatibility with Blueprint run: | yarn create ton -- test-project --type tact-counter --contractName Counter diff --git a/package.json b/package.json index 64004f26d..4def2f0e7 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "gen": "yarn gen:grammar && yarn gen:pack && yarn gen:compiler", "clean": "rm -fr dist", "build": "tsc && cp ./src/grammar/grammar.ohm* ./dist/grammar/ && cp ./src/func/funcfiftlib.* ./dist/func", - "test": "jest", + "test": "jest --testMatch=\"**/*.spec.ts\"", + "test:format": "jest --testMatch=\"**/*.format-spec.ts\"", "coverage": "cross-env COVERAGE=true jest", "release": "yarn clean && yarn build && yarn coverage && yarn release-it --npm.yarn1", "lint": "yarn eslint ." diff --git a/src/grammar/grammar.spec.ts b/src/grammar/grammar.format-spec.ts similarity index 100% rename from src/grammar/grammar.spec.ts rename to src/grammar/grammar.format-spec.ts diff --git a/src/test/schema.spec.ts b/src/test/schema.format-spec.ts similarity index 100% rename from src/test/schema.spec.ts rename to src/test/schema.format-spec.ts From 069184c313e512c67a98d3c4e0a961694d7967f0 Mon Sep 17 00:00:00 2001 From: vanishmax Date: Wed, 27 Mar 2024 21:11:03 +0100 Subject: [PATCH 17/21] Revert "refactor: separate tests into two categories: regular and formatters" This reverts commit 8da0191223d69e643f322597743a24b5daafd44c. --- .github/workflows/tact.yml | 7 +++---- package.json | 3 +-- src/grammar/{grammar.format-spec.ts => grammar.spec.ts} | 0 src/test/{schema.format-spec.ts => schema.spec.ts} | 0 4 files changed, 4 insertions(+), 6 deletions(-) rename src/grammar/{grammar.format-spec.ts => grammar.spec.ts} (100%) rename src/test/{schema.format-spec.ts => schema.spec.ts} (100%) diff --git a/.github/workflows/tact.yml b/.github/workflows/tact.yml index 9b78115a8..916e1d61d 100644 --- a/.github/workflows/tact.yml +++ b/.github/workflows/tact.yml @@ -14,7 +14,7 @@ jobs: matrix: node-version: [18.x] os: [ubuntu-latest, windows-latest, macos-latest] - + runs-on: ${{ matrix.os }} steps: @@ -36,11 +36,10 @@ jobs: yarn gen yarn build yarn coverage - + - name: Check there are no errors reported by ESLint run: | yarn lint - yarn test:format - name: Compare Tact version from CLI flag `--version` against package.json if: runner.os != 'Windows' @@ -62,7 +61,7 @@ jobs: yarn build yarn test yarn tact --version - + - name: Test compatibility with Blueprint run: | yarn create ton -- test-project --type tact-counter --contractName Counter diff --git a/package.json b/package.json index 4def2f0e7..64004f26d 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,7 @@ "gen": "yarn gen:grammar && yarn gen:pack && yarn gen:compiler", "clean": "rm -fr dist", "build": "tsc && cp ./src/grammar/grammar.ohm* ./dist/grammar/ && cp ./src/func/funcfiftlib.* ./dist/func", - "test": "jest --testMatch=\"**/*.spec.ts\"", - "test:format": "jest --testMatch=\"**/*.format-spec.ts\"", + "test": "jest", "coverage": "cross-env COVERAGE=true jest", "release": "yarn clean && yarn build && yarn coverage && yarn release-it --npm.yarn1", "lint": "yarn eslint ." diff --git a/src/grammar/grammar.format-spec.ts b/src/grammar/grammar.spec.ts similarity index 100% rename from src/grammar/grammar.format-spec.ts rename to src/grammar/grammar.spec.ts diff --git a/src/test/schema.format-spec.ts b/src/test/schema.spec.ts similarity index 100% rename from src/test/schema.format-spec.ts rename to src/test/schema.spec.ts From b6561e9e0ded084a2201933c7c9f235cb832cb38 Mon Sep 17 00:00:00 2001 From: vanishmax Date: Wed, 27 Mar 2024 21:18:05 +0100 Subject: [PATCH 18/21] fix: use ajv CLI to lint the schema --- .github/workflows/tact.yml | 1 + package.json | 5 +++-- src/test/schema.spec.ts | 31 ----------------------------- yarn.lock | 40 ++++++++++++++++++++++++++++++++++---- 4 files changed, 40 insertions(+), 37 deletions(-) delete mode 100644 src/test/schema.spec.ts diff --git a/.github/workflows/tact.yml b/.github/workflows/tact.yml index 916e1d61d..26dd81791 100644 --- a/.github/workflows/tact.yml +++ b/.github/workflows/tact.yml @@ -40,6 +40,7 @@ jobs: - name: Check there are no errors reported by ESLint run: | yarn lint + yarn lint:schema - name: Compare Tact version from CLI flag `--version` against package.json if: runner.os != 'Windows' diff --git a/package.json b/package.json index 64004f26d..84bbd51a7 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "test": "jest", "coverage": "cross-env COVERAGE=true jest", "release": "yarn clean && yarn build && yarn coverage && yarn release-it --npm.yarn1", - "lint": "yarn eslint ." + "lint": "yarn eslint .", + "lint:schema": "ajv validate -s grammar/configSchema.json -d tact.config.json" }, "files": [ "dist/**/*", @@ -59,7 +60,7 @@ "@types/qs": "^6.9.7", "@typescript-eslint/eslint-plugin": "^7.0.2", "@typescript-eslint/parser": "^7.0.2", - "ajv": "^8.12.0", + "ajv-cli": "^5.0.0", "cross-env": "^7.0.3", "eslint": "^8.56.0", "glob": "^8.1.0", diff --git a/src/test/schema.spec.ts b/src/test/schema.spec.ts deleted file mode 100644 index db086a976..000000000 --- a/src/test/schema.spec.ts +++ /dev/null @@ -1,31 +0,0 @@ -import fs from 'fs'; -import path from 'path'; -import Ajv from 'ajv'; -import { __DANGER_resetNodeId } from '../grammar/ast'; - -describe('configuration schema', () => { - const ajv = new Ajv(); - const schema = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '..', 'grammar', 'configSchema.json'), 'utf8')); - - beforeEach(() => { - __DANGER_resetNodeId(); - }); - - it('should validate Tact config', () => { - const tactConfig = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '..', 'tact.config.json'), 'utf8')); - - const validate = ajv.compile(schema); - validate(tactConfig); - - expect(validate.errors).toBeNull(); - }); - - it('should validate test config', () => { - const testConfig = JSON.parse(fs.readFileSync(path.join(__dirname, 'test-tact.config.json'), 'utf8')); - - const validate = ajv.compile(schema); - validate(testConfig); - - expect(validate.errors).toBeNull(); - }); -}); diff --git a/yarn.lock b/yarn.lock index 30026c858..c423b79f5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1313,6 +1313,19 @@ agent-base@^7.0.2, agent-base@^7.1.0: dependencies: debug "^4.3.4" +ajv-cli@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/ajv-cli/-/ajv-cli-5.0.0.tgz#78956ed2934e6dde4c9e696b587be1c2998862e8" + integrity sha512-LY4m6dUv44HTyhV+u2z5uX4EhPYTM38Iv1jdgDJJJCyOOuqB8KtZEGjPZ2T+sh5ZIJrXUfgErYx/j3gLd3+PlQ== + dependencies: + ajv "^8.0.0" + fast-json-patch "^2.0.0" + glob "^7.1.0" + js-yaml "^3.14.0" + json-schema-migrate "^2.0.0" + json5 "^2.1.3" + minimist "^1.2.0" + ajv@^6.12.4: version "6.12.6" resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4" @@ -1323,7 +1336,7 @@ ajv@^6.12.4: json-schema-traverse "^0.4.1" uri-js "^4.2.2" -ajv@^8.12.0: +ajv@^8.0.0: version "8.12.0" resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.12.0.tgz#d1a0527323e22f53562c567c00991577dfbe19d1" integrity sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA== @@ -2465,6 +2478,11 @@ external-editor@^3.0.3: iconv-lite "^0.4.24" tmp "^0.0.33" +fast-deep-equal@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49" + integrity sha512-bCK/2Z4zLidyB4ReuIsvALH6w31YfAQDmXMqMx6FyfHqvBxtjC0eRumeSu4Bs3XtXwpyIywtSTrVT99BxY1f9w== + fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3: version "3.1.3" resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525" @@ -2492,6 +2510,13 @@ fast-glob@^3.2.9: merge2 "^1.3.0" micromatch "^4.0.4" +fast-json-patch@^2.0.0: + version "2.2.1" + resolved "https://registry.yarnpkg.com/fast-json-patch/-/fast-json-patch-2.2.1.tgz#18150d36c9ab65c7209e7d4eb113f4f8eaabe6d9" + integrity sha512-4j5uBaTnsYAV5ebkidvxiLUYOwjQ+JSFljeqfTxCrH9bDmlCQaOJFS84oDJ2rAXZq2yskmk3ORfoP9DCwqFNig== + dependencies: + fast-deep-equal "^2.0.1" + fast-json-stable-stringify@2.x, fast-json-stable-stringify@^2.0.0, fast-json-stable-stringify@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633" @@ -2703,7 +2728,7 @@ glob-parent@^6.0.2: dependencies: is-glob "^4.0.3" -glob@^7.0.0, glob@^7.1.3, glob@^7.1.4: +glob@^7.0.0, glob@^7.1.0, glob@^7.1.3, glob@^7.1.4: version "7.2.3" resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.3.tgz#b8df0fb802bbfa8e89bd1d938b4e16578ed44f2b" integrity sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q== @@ -4109,7 +4134,7 @@ js-tokens@^4.0.0: resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== -js-yaml@^3.13.1: +js-yaml@^3.13.1, js-yaml@^3.14.0: version "3.14.1" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.14.1.tgz#dae812fdb3825fa306609a8717383c50c36a0537" integrity sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g== @@ -4144,6 +4169,13 @@ json-parse-even-better-errors@^2.3.0: resolved "https://registry.yarnpkg.com/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz#7c47805a94319928e05777405dc12e1f7a4ee02d" integrity sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w== +json-schema-migrate@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/json-schema-migrate/-/json-schema-migrate-2.0.0.tgz#335ef5218cd32fcc96c1ddce66c71ba586224496" + integrity sha512-r38SVTtojDRp4eD6WsCqiE0eNDt4v1WalBXb9cyZYw9ai5cGtBwzRNWjHzJl38w6TxFkXAIA7h+fyX3tnrAFhQ== + dependencies: + ajv "^8.0.0" + json-schema-traverse@^0.4.1: version "0.4.1" resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660" @@ -4159,7 +4191,7 @@ json-stable-stringify-without-jsonify@^1.0.1: resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651" integrity sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw== -json5@^2.2.3: +json5@^2.1.3, json5@^2.2.3: version "2.2.3" resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283" integrity sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg== From 9a409d516a10271984bf1e23cb204f5df37604d1 Mon Sep 17 00:00:00 2001 From: vanishmax Date: Wed, 27 Mar 2024 21:21:19 +0100 Subject: [PATCH 19/21] feat: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96296a660..4fba00d13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Update the `dump` function to handle addresses: PR [#175](https://github.com/tact-lang/tact/pull/175) - The implicit empty `init` function is now present by default in the contract if not declared: PR [#167](https://github.com/tact-lang/tact/pull/167) +- Add JSON Schema for `tact.config.json`: PR [#194](https://github.com/tact-lang/tact/pull/194) ### Fixed From eac5032dece9afb40c899fbfdad1b116fef95974 Mon Sep 17 00:00:00 2001 From: Novus Nota <68142933+novusnota@users.noreply.github.com> Date: Wed, 27 Mar 2024 21:25:49 +0100 Subject: [PATCH 20/21] ci: JSON Schema adherence check for tact.config.json --- .github/workflows/tact.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tact.yml b/.github/workflows/tact.yml index 26dd81791..0a8b247c1 100644 --- a/.github/workflows/tact.yml +++ b/.github/workflows/tact.yml @@ -40,6 +40,9 @@ jobs: - name: Check there are no errors reported by ESLint run: | yarn lint + + - name: Check that tact.config.json adheres to the JSON schema + run: | yarn lint:schema - name: Compare Tact version from CLI flag `--version` against package.json From 9f15e6c74a5bcc284229b3e4e601b7fc09a58478 Mon Sep 17 00:00:00 2001 From: vanishmax Date: Wed, 27 Mar 2024 21:42:23 +0100 Subject: [PATCH 21/21] fix: changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a814750f..8349fee5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,11 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - `log2` and `log` math functions in `@stdlib/math`: PR [#166](https://github.com/tact-lang/tact/pull/166) - Reserve mode constants in `@stdlib/reserve`, namely `ReserveExact`, `ReserveAllExcept`, `ReserveAtMost`, `ReserveAddOriginalBalance`, `ReserveInvertSign`, `ReserveBounceIfActionFail`: PR [#173](https://github.com/tact-lang/tact/pull/173) +- JSON Schema for `tact.config.json`: PR [#194](https://github.com/tact-lang/tact/pull/194) ### Changed - Update the `dump` function to handle addresses: PR [#175](https://github.com/tact-lang/tact/pull/175) - The implicit empty `init` function is now present by default in the contract if not declared: PR [#167](https://github.com/tact-lang/tact/pull/167) -- Add JSON Schema for `tact.config.json`: PR [#194](https://github.com/tact-lang/tact/pull/194) - `@stdlib/stoppable` now imports `@stdlib/ownable` so the programmer does not have to do it separately: PR [#193](https://github.com/tact-lang/tact/pull/193) ### Fixed