From b8977e1ceb1498ad2de5cc8007bfdef6ef7393f5 Mon Sep 17 00:00:00 2001 From: i582 <51853996+i582@users.noreply.github.com> Date: Mon, 17 Feb 2025 03:32:26 +0400 Subject: [PATCH 1/3] feat: add test for `GETGLOB` and `GETGLOBVAR` Fixes #22 --- src/test/e2e/__snapshots__/func.spec.ts.snap | 16 +++++++ src/test/e2e/func.spec.ts | 50 +++++++++++++++----- 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/src/test/e2e/__snapshots__/func.spec.ts.snap b/src/test/e2e/__snapshots__/func.spec.ts.snap index 1358809..a88aa4a 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 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) - }) + } }) From f6f551203eb80cfea449ea15fdbf9a1e2586167c Mon Sep 17 00:00:00 2001 From: i582 <51853996+i582@users.noreply.github.com> Date: Mon, 17 Feb 2025 03:39:24 +0400 Subject: [PATCH 2/3] fix --- src/test/e2e/__snapshots__/func.spec.ts.snap | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/test/e2e/__snapshots__/func.spec.ts.snap b/src/test/e2e/__snapshots__/func.spec.ts.snap index a88aa4a..c3b348e 100644 --- a/src/test/e2e/__snapshots__/func.spec.ts.snap +++ b/src/test/e2e/__snapshots__/func.spec.ts.snap @@ -16,6 +16,22 @@ PROGRAM{ }END>c" `; +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{ From 04cc1719b5e4ccba2ba601a0bfd949cb7c5b5129 Mon Sep 17 00:00:00 2001 From: i582 <51853996+i582@users.noreply.github.com> Date: Mon, 17 Feb 2025 03:40:38 +0400 Subject: [PATCH 3/3] fix --- src/test/e2e/__snapshots__/func.spec.ts.snap | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/test/e2e/__snapshots__/func.spec.ts.snap b/src/test/e2e/__snapshots__/func.spec.ts.snap index c3b348e..1003581 100644 --- a/src/test/e2e/__snapshots__/func.spec.ts.snap +++ b/src/test/e2e/__snapshots__/func.spec.ts.snap @@ -1,21 +1,5 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`disassemble > should decompile GETGLOB 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 GETGLOB and GETGLOBVAR correctly 1`] = ` ""Asm.fif" include PROGRAM{