ton-assembly
Version:
TON assembler and disassembler
164 lines (160 loc) • 5.91 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
const node_child_process_1 = require("node:child_process");
const node_fs_1 = require("node:fs");
const path = __importStar(require("node:path"));
const core_1 = require("@ton/core");
// disable tests on windows
const testExceptWindows = process.platform === "win32" && Boolean(process.env["CI"]) ? test.skip : test;
const CLI_PATH = path.join(__dirname, "..", "..", "..", "dist", "cli", "fift-compiler.js");
describe("Fift assembly compiler CLI", () => {
const testDir = path.join(__dirname, "temp");
const testInputFile = path.join(testDir, "test.fif");
const testOutputFile = path.join(testDir, "test.boc");
beforeEach(() => {
try {
(0, node_fs_1.rmSync)(testDir, { recursive: true, force: true });
}
catch {
// ignore
}
(0, node_child_process_1.execSync)(`mkdir -p "${testDir}"`);
});
afterEach(() => {
try {
(0, node_fs_1.rmSync)(testDir, { recursive: true, force: true });
}
catch {
// ignore
}
});
testExceptWindows("should compile simple Fift assembly file to BOC", () => {
const fiftCode = `"Asm.fif" include
PROGRAM{
DECLGLOBVAR $test_var
0 DECLMETHOD recv_internal()
recv_internal() PROC:<{
42 PUSHINT
$test_var SETGLOB
}>
}END>c`;
(0, node_fs_1.writeFileSync)(testInputFile, fiftCode);
const result = (0, node_child_process_1.execSync)(`node "${CLI_PATH}" "${testInputFile}" -o "${testOutputFile}"`, {
encoding: "utf8",
});
expect(result).toBe("");
// Verify BOC file was created and is valid
const bocBuffer = (0, node_fs_1.readFileSync)(testOutputFile);
expect(bocBuffer.length).toBeGreaterThan(0);
const cell = core_1.Cell.fromBoc(bocBuffer)[0];
expect(cell).toBeDefined();
});
testExceptWindows("should output to stdout in hex format", () => {
const fiftCode = `"Asm.fif" include
PROGRAM{
0 DECLMETHOD recv_internal()
recv_internal() PROC:<{
1 PUSHINT
DROP
}>
}END>c`;
(0, node_fs_1.writeFileSync)(testInputFile, fiftCode);
const result = (0, node_child_process_1.execSync)(`node "${CLI_PATH}" "${testInputFile}" -f hex`, {
encoding: "utf8",
});
expect(result.trim()).toMatchSnapshot();
});
testExceptWindows("should output to stdout in base64 format", () => {
const fiftCode = `"Asm.fif" include
PROGRAM{
0 DECLMETHOD recv_internal()
recv_internal() PROC:<{
1 PUSHINT
DROP
}>
}END>c`;
(0, node_fs_1.writeFileSync)(testInputFile, fiftCode);
const result = (0, node_child_process_1.execSync)(`node "${CLI_PATH}" "${testInputFile}" -f base64`, {
encoding: "utf8",
});
expect(result.trim()).toMatchSnapshot();
});
testExceptWindows("should compile from string input", () => {
const fiftCode = `"Asm.fif" include
PROGRAM{
0 DECLMETHOD recv_internal()
recv_internal() PROC:<{
1 PUSHINT
DROP
}>
}END>c`;
const result = (0, node_child_process_1.execSync)(`node "${CLI_PATH}" -s '${fiftCode}' -f hex`, {
encoding: "utf8",
});
expect(result.trim()).toMatchSnapshot();
});
testExceptWindows("should handle parse errors gracefully", () => {
const invalidFiftCode = `invalid syntax here`;
(0, node_fs_1.writeFileSync)(testInputFile, invalidFiftCode);
expect(() => {
(0, node_child_process_1.execSync)(`node "${CLI_PATH}" "${testInputFile}"`, {
encoding: "utf8",
stdio: "pipe",
});
}).toThrow();
});
testExceptWindows("should require input file or string", () => {
expect(() => {
(0, node_child_process_1.execSync)(`node "${CLI_PATH}"`, {
encoding: "utf8",
stdio: "pipe",
});
}).toThrow();
});
testExceptWindows("should show help", () => {
const result = (0, node_child_process_1.execSync)(`node "${CLI_PATH}" --help`, {
encoding: "utf8",
});
expect(result).toMatchSnapshot();
});
testExceptWindows("should show version", () => {
const result = (0, node_child_process_1.execSync)(`node "${CLI_PATH}" --version`, {
encoding: "utf8",
});
expect(result).toContain("0.0.1");
});
});
//# sourceMappingURL=fift-compiler.spec.js.map