diff --git a/src/test/e2e/__snapshots__/func.spec.ts.snap b/src/test/e2e/__snapshots__/func.spec.ts.snap index 1358809..1003581 100644 --- a/src/test/e2e/__snapshots__/func.spec.ts.snap +++ b/src/test/e2e/__snapshots__/func.spec.ts.snap @@ -1,5 +1,21 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +exports[`disassemble > should decompile GETGLOB and GETGLOBVAR correctly 1`] = ` +""Asm.fif" include +PROGRAM{ + DECLPROC recv_internal + recv_internal PROC:<{ + ONE + ONE + ADD + GETGLOBVAR + DROP + 2 GETGLOB + DROP + }> +}END>c" +`; + exports[`disassemble > should decompile and compile back PUSHREF with bytes 1`] = ` ""Asm.fif" include PROGRAM{ diff --git a/src/test/e2e/func.spec.ts b/src/test/e2e/func.spec.ts index 489a76a..0a104df 100644 --- a/src/test/e2e/func.spec.ts +++ b/src/test/e2e/func.spec.ts @@ -3,31 +3,55 @@ import {Cell} from "@ton/core" import {disassembleRoot} from "../../decompiler/disasm" import {AssemblyWriter} from "../../printer/assembly-writer" import {debugSymbols} from "../../utils/known-methods" -import {compileFunc} from "@ton-community/func-js" +import {compileFunc, ErrorResult, SuccessResult} from "@ton-community/func-js" import {fail} from "node:assert" import {compileFiftBackAndCompare} from "./utils" describe("disassemble", () => { it("should decompile and compile back PUSHREF with bytes", async () => { + await compileAndCheck(` + int cell_hash(cell c) asm "HASHCU"; + + cell __gen_cell_cell_37e90db9d1f7725dc0128ee6bad2035fb50479e09a488a29257bed01a23050a0() asm """ + B{b5ee9c7241010101000d00001600000000537563636573738a3a2a2a} B>boc PUSHREF + """; + + () recv_internal() { + cell c = __gen_cell_cell_37e90db9d1f7725dc0128ee6bad2035fb50479e09a488a29257bed01a23050a0(); + throw(cell_hash(c)); + } + `) + }) + + it("should decompile GETGLOB and GETGLOBVAR correctly", async () => { + await compileAndCheck(` + forall X -> (X, ()) ~impure_touch(X x) impure asm "NOP"; + + global int first; + global int second; + + (int) test() impure inline asm "ONE ONE ADD GETGLOBVAR"; + + () recv_internal() { + ~impure_touch(test()); + ~impure_touch(second); + } + `) + }) + + async function compileAndCheck(content: string) { const funcRes = await compileFunc({ sources: [ { filename: "main.fc", - content: ` - int cell_hash(cell c) asm "HASHCU"; - - cell __gen_cell_cell_37e90db9d1f7725dc0128ee6bad2035fb50479e09a488a29257bed01a23050a0() asm """ - B{b5ee9c7241010101000d00001600000000537563636573738a3a2a2a} B>boc PUSHREF - """; - - () recv_internal() { - cell c = __gen_cell_cell_37e90db9d1f7725dc0128ee6bad2035fb50479e09a488a29257bed01a23050a0(); - throw(cell_hash(c)); - }`, + content: content, }, ], }) + await check(funcRes) + } + async function check(funcRes: SuccessResult | ErrorResult) { if (funcRes.status === "error") { fail(`cannot compile FunC: ${funcRes.message}`) return @@ -48,5 +72,5 @@ describe("disassemble", () => { expect(decompiled).toMatchSnapshot() await compileFiftBackAndCompare(decompiled, buffer) - }) + } })