Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add test for GETGLOB and GETGLOBVAR #42

Merged
merged 3 commits into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
}
})