Skip to content

Commit

Permalink
feat: add test for GETGLOB and GETGLOBVAR (#42)
Browse files Browse the repository at this point in the history
Fixes #22
  • Loading branch information
i582 authored Feb 16, 2025
1 parent 531996a commit 13f1206
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 13 deletions.
16 changes: 16 additions & 0 deletions src/test/e2e/__snapshots__/func.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -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{
Expand Down
50 changes: 37 additions & 13 deletions src/test/e2e/func.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -48,5 +72,5 @@ describe("disassemble", () => {
expect(decompiled).toMatchSnapshot()

await compileFiftBackAndCompare(decompiled, buffer)
})
}
})

0 comments on commit 13f1206

Please sign in to comment.