Skip to content

Commit

Permalink
refactor: split prepare.ts and tact.config.json (#1335)
Browse files Browse the repository at this point in the history
  • Loading branch information
verytactical authored Jan 14, 2025
1 parent c7ae423 commit d4209dd
Show file tree
Hide file tree
Showing 12 changed files with 503 additions and 466 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,13 @@ The implementation that we have right now is being refactored to produce FunC AS
One can find the end-to-end codegen test spec files in the [src/test/e2e-emulated](./src/test/e2e-emulated/) folder. The test contracts are located in [src/test/e2e-emulated/contracts](./src/test/e2e-emulated/contracts) subfolder. Many of those spec files test various language features in relative isolation.
An important spec file that tests argument passing semantics for functions and assignment semantics for variables is here: [src/test/e2e-emulated/semantics.spec.ts](./src/test/e2e-emulated/semantics.spec.ts).

Note: If you add an end-to-end test contract, you also need to include it into [tact.config.json](./tact.config.json) and run `yarn gen` to compile it and create TypeScript wrappers.
Note: If you add an end-to-end test contract, you also need to include it into [tact.config.json](src/test/tact.config.json) and run `yarn gen` to compile it and create TypeScript wrappers.

`yarn gen` also re-compiles test contracts, so it's important to run it when code generation is changed.

Some other codegen tests are as follows:

- [src/test/benchmarks](./src/test/benchmarks): check gas consumption;
- [src/test/exit-codes](./src/test/exit-codes): test that certain actions produce the expected exit codes;
- [src/test/codegen](./src/test/codegen/): test that these contracts compile just fine without running any dynamic tests: bug fixes for FunC code generation often add tests into this folder.

Expand Down
19 changes: 10 additions & 9 deletions scripts/prepare.ts → examples/contracts.build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import fs from "fs";
import { run } from "../src/node";
import path from "path";
import { glob } from "glob";
import { verify } from "../src/verify";
import { verify } from "./verify";
import { Logger } from "../src/context/logger";
import { __DANGER__disableVersionNumber } from "../src/pipeline/version";

const configPath = path.join(__dirname, "tact.config.json");
const packagesPath = path.resolve(__dirname, "output", "*.pkg");

// Read cases
void (async () => {
const main = async () => {
// Disable version number in packages
__DANGER__disableVersionNumber();

Expand All @@ -16,18 +19,14 @@ void (async () => {
try {
// Compile projects
const compileResult = await run({
configPath: path.join(__dirname, "..", "tact.config.json"),
configPath,
});
if (!compileResult.ok) {
throw new Error("Tact projects compilation failed");
}

// Verify projects
for (const pkgPath of glob.sync(
path.normalize(
path.resolve(__dirname, "..", "examples", "output", "*.pkg"),
),
)) {
for (const pkgPath of glob.sync(path.normalize(packagesPath))) {
const res = await verify({
pkg: fs.readFileSync(pkgPath, "utf-8"),
});
Expand All @@ -39,4 +38,6 @@ void (async () => {
logger.error(error as Error);
process.exit(1);
}
})();
};

void main();
83 changes: 83 additions & 0 deletions examples/tact.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"$schema": "../src/config/configSchema.json",
"projects": [
{
"name": "echo",
"path": "./echo.tact",
"output": "./output"
},
{
"name": "inheritance",
"path": "./inheritance.tact",
"output": "./output"
},
{
"name": "large",
"path": "./large.tact",
"output": "./output"
},
{
"name": "native",
"path": "./native.tact",
"output": "./output"
},
{
"name": "maps",
"path": "./maps.tact",
"output": "./output"
},
{
"name": "payouts",
"path": "./payouts.tact",
"output": "./output"
},
{
"name": "external",
"path": "./external.tact",
"output": "./output",
"options": {
"external": true
}
},
{
"name": "wallet",
"path": "./wallet.tact",
"output": "./output"
},
{
"name": "wallet-opt",
"path": "./wallet-opt.tact",
"output": "./output",
"options": {
"experimental": {
"inline": true
}
}
},
{
"name": "treasure",
"path": "./treasure.tact",
"output": "./output"
},
{
"name": "multisig",
"path": "./multisig.tact",
"output": "./output"
},
{
"name": "multisig-3",
"path": "./multisig-3.tact",
"output": "./output"
},
{
"name": "increment",
"path": "./increment.tact",
"output": "./output"
},
{
"name": "rugpull",
"path": "./rugpull.tact",
"output": "./output"
}
]
}
10 changes: 5 additions & 5 deletions src/verify.ts → examples/verify.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import normalize from "path-normalize";
import { Cell } from "@ton/core";
import { Config, Options } from "./config/parseConfig";
import { ILogger, Logger } from "./context/logger";
import { PackageFileFormat, run } from "./";
import { fileFormat } from "./packaging/fileFormat";
import { getCompilerVersion } from "./pipeline/version";
import { Config, Options } from "../src/config/parseConfig";
import { ILogger, Logger } from "../src/context/logger";
import { PackageFileFormat, run } from "../src";
import { fileFormat } from "../src/packaging/fileFormat";
import { getCompilerVersion } from "../src/pipeline/version";

export type VerifyResult =
| {
Expand Down
1 change: 1 addition & 0 deletions knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"project": ["src/**/*.ts", "bin/tact.js", "bin/unboc.js"],
"ignore": [
"src/ast/ast.ts",
"src/config/parseConfig.ts",
"src/prettyPrinter.ts",
"src/error/display-to-json.ts",
"src/grammar/src-info.ts",
Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
"gen:grammar:new": "pgen src/grammar/next/grammar.gg -o src/grammar/next/grammar.ts",
"gen:grammar": "yarn gen:grammar:old && yarn gen:grammar:new",
"gen:pack": "ts-node ./scripts/pack.ts",
"gen:compiler": "ts-node ./scripts/prepare.ts",
"gen": "yarn gen:grammar && yarn gen:pack && yarn gen:compiler",
"gen:contracts:examples": "ts-node examples/contracts.build.ts",
"gen:contracts:test": "ts-node src/test/contracts.build.ts",
"gen": "yarn gen:grammar && yarn gen:pack && yarn gen:contracts:examples && yarn gen:contracts:test",
"clean": "rm -fr dist",
"cleanall": "rm -fr dist node_modules",
"build": "tsc && node --no-warnings=ExperimentalWarning -r ts-node/register ./scripts/copy-files",
Expand All @@ -24,7 +25,8 @@
"release": "yarn clean && yarn build && yarn coverage && yarn release-it --npm.yarn1",
"type": "tsc --noEmit",
"lint": "yarn eslint .",
"lint:schema": "ajv validate -s src/config/configSchema.json -d tact.config.json",
"lint:one-schema": "ajv validate -s src/config/configSchema.json -d",
"lint:schema": "yarn lint:one-schema src/test/tact.config.json && yarn lint:one-schema examples/tact.config.json",
"fmt": "yarn prettier -l -w .",
"fmt:check": "yarn prettier --check .",
"spell": "yarn cspell --no-progress \"**\"",
Expand All @@ -41,7 +43,8 @@
"bin/**/*",
"stdlib/**/*",
"!**/test",
"!/docs"
"!/docs",
"!**/*.build.ts"
],
"main": "./dist/index.js",
"bin": {
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ export { VirtualFileSystem } from "./vfs/VirtualFileSystem";
export { createVirtualFileSystem } from "./vfs/createVirtualFileSystem";

export * from "./browser";
export * from "./verify";
export * from "./context/logger";
export * from "./error/errors";
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions src/test/contracts.build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { run } from "../node";
import path from "path";
import { Logger } from "../context/logger";
import { __DANGER__disableVersionNumber } from "../pipeline/version";

const configPath = path.join(__dirname, "tact.config.json");

const main = async () => {
// Disable version number in packages
__DANGER__disableVersionNumber();

const logger = new Logger();

try {
const compileResult = await run({
configPath,
});
if (!compileResult.ok) {
throw new Error("Tact projects compilation failed");
}
} catch (error) {
logger.error(error as Error);
process.exit(1);
}
};

void main();
Loading

0 comments on commit d4209dd

Please sign in to comment.