Skip to content

Commit

Permalink
feat(test): Use driver's single contract functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
byakuren-hijiri committed Jul 25, 2024
1 parent d9a5db5 commit 06177e4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 40 deletions.
16 changes: 4 additions & 12 deletions test/builtinDetectors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
import fs from "fs";
import path from "path";
import { exec } from "child_process";
import { describe, it } from "@jest/globals";

import {
generateConfig,
TAP,
processTactFiles,
CONTRACTS_DIR,
} from "./testUtil";
import { TAP, processTactFiles, CONTRACTS_DIR } from "./testUtil";
import fs from "fs";
import path from "path";

processTactFiles(CONTRACTS_DIR, (file) => {
const contractName = file.replace(".tact", "");
const actualSuffix = "actual.out";
describe(`Testing built-in detectors for ${contractName}`, () => {
it(`should generate the expected warnings for ${contractName}`, async () => {
const configPath = await generateConfig(contractName);

// Run the driver and save results to the file.
const outputFilePath = path.join(
CONTRACTS_DIR,
`${contractName}.${actualSuffix}`,
);
const runCommand = `node dist/src/main.js ${configPath}`;
const runCommand = `node dist/src/main.js ${path.join(CONTRACTS_DIR, file)}`;
await new Promise((resolve, reject) => {
exec(runCommand, (error, stdout, stderr) => {
const out = stdout.trim() + stderr.trim();
Expand Down
12 changes: 3 additions & 9 deletions test/tactIR.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import { run } from "../src/driver";
import { describe, it } from "@jest/globals";

import {
generateConfig,
TAP,
processTactFiles,
CONTRACTS_DIR,
} from "./testUtil";
import { TAP, processTactFiles, CONTRACTS_DIR } from "./testUtil";
import path from "path";

processTactFiles(CONTRACTS_DIR, (file) => {
const contractName = file.replace(".tact", "");
describe(`Testing CFG dump for ${contractName}`, () => {
it(`should produce the correct CFG JSON output for ${contractName}`, async () => {
const configPath = await generateConfig(contractName);
await run(configPath, {
await run(path.join(CONTRACTS_DIR, file), {
dumpCfg: "json",
dumpCfgStdlib: false,
dumpCfgOutput: CONTRACTS_DIR,
Expand Down
19 changes: 0 additions & 19 deletions test/testUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,6 @@ import { expect } from "@jest/globals";

export const CONTRACTS_DIR = path.resolve(__dirname, "contracts");

/**
* Generates a Tact configuration file for the given contract.
*/
export async function generateConfig(contractName: string): Promise<string> {
const config = {
projects: [
{
name: `${contractName}`,
path: `./${contractName}.tact`,
output: `./output`,
options: {},
},
],
};
const configPath = path.join(CONTRACTS_DIR, `${contractName}.config.json`);
await fs.promises.writeFile(configPath, JSON.stringify(config), "utf8");
return configPath;
}

/**
* Provides a minimal TAP-like API.
*/
Expand Down

0 comments on commit 06177e4

Please sign in to comment.