Skip to content
Open
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
26 changes: 17 additions & 9 deletions src/asm/coverage/test/asm-coverage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { collectAsmCoverage } from "@/asm/coverage/index";
import { generateTextReport } from "@/asm/coverage/text";
import { generateHtml } from "@/asm/coverage/html";
import { mkdirSync, writeFileSync, existsSync } from "node:fs";
import { step } from "@/test/allure/allure";

describe("asm coverage", () => {
const test =
Expand All @@ -19,16 +20,23 @@ describe("asm coverage", () => {
const [_, logs] = await executeInstructions(res.instructions, id);
const { lines, summary } = collectAsmCoverage(cell, logs);

const report = generateTextReport(lines, summary);
expect(report).toMatchSnapshot();

const report = await step("Generating text report", () => {
return generateTextReport(lines, summary);
});
await step("Report should match snapshot", () => {
expect(report).toMatchSnapshot();
});
const outDirname = `${__dirname}/output`;
if (!existsSync(outDirname)) {
mkdirSync(outDirname);
}

const htmlReport = generateHtml(lines);
writeFileSync(`${__dirname}/output/${name}.html`, htmlReport);
const htmlReport = await step("Generating HTML report", () => {
return generateHtml(lines);
});
await step("Write html report", () => {
writeFileSync(`${__dirname}/output/${name}.html`, htmlReport);
});
};

it(
Expand All @@ -55,9 +63,9 @@ describe("asm coverage", () => {
`
DROP
PUSHINT -1 // cond

IFRET

PUSHINT 1
PUSHINT 2
ADD
Expand Down Expand Up @@ -89,14 +97,14 @@ describe("asm coverage", () => {
"while loop with break",
`
PUSHINT 10 // a = 10

PUSHCONT { DUP GTINT 0 } // a > 0
PUSHCONT {
// if (a < 5) { break }
DUP
LESSINT 5
IFRETALT

// a -= 1;
DEC
}
Expand Down
11 changes: 6 additions & 5 deletions src/asm/helpers/measure-gas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
CALLDICT_LONG,
} from "@/asm/runtime";
import { measureGas } from "@/asm/helpers/measure-gas";
import { parameter, step } from "@/test/allure/allure";

interface TestCase {
readonly name: string;
Expand Down Expand Up @@ -48,11 +49,11 @@ const TESTS: TestCase[] = [
];

describe("tests", () => {
// TODO: rewrite with just `it()`
for (const { name, instructions, expectedGas } of TESTS) {
it(`Test ${name}`, async () => {
const gasUsed = await measureGas(instructions);
it.each(TESTS)("Test $name", async ({ instructions, expectedGas }) => {
const gasUsed = await measureGas(instructions);
await parameter("Gas used", gasUsed.toString());
await step("Used gas should be same", () => {
expect(gasUsed).toEqual(expectedGas);
});
}
});
});
13 changes: 8 additions & 5 deletions src/asm/logs/test/parse.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { parse } from "@/asm/logs/parse";
import { step } from "@/test/allure/allure";

describe("logs-parse", () => {
it("should parse NaN", () => {
it("should parse NaN", async () => {
const res = parse(`
stack: [ 0 ]
stack: [ 0 ]
code cell hash: C4252597808DE321E4DBEDFCF683B8D9A53BB1E5A77FDD44091B1163114468FA offset: 0
execute PUSHINT 200
gas remaining: 9999977
stack: [ 0 200 ]
stack: [ 0 200 ]
code cell hash: C4252597808DE321E4DBEDFCF683B8D9A53BB1E5A77FDD44091B1163114468FA offset: 32
execute FITS 1
gas remaining: 9999943
stack: [ 0 NaN ]
stack: [ 0 NaN ]
execute implicit RET
gas remaining: 9999938
`);

expect(res).toMatchSnapshot();
await step("Parse result should match snapshot", () => {
expect(res).toMatchSnapshot();
});
});
});
73 changes: 50 additions & 23 deletions src/asm/runtime/test/signatures.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { signatureOf, signatureString } from "@/asm/runtime/stack-signatures";
import { step } from "@/test/allure/allure";

describe("instructions signatures", () => {
it("should find correct signatures", async () => {
{
const signature = await signatureOf("ADD");
expect(signature).toBeDefined();
await step("Signature should be defined", () => {
expect(signature).toBeDefined();
});
if (signature) {
expect(signatureString(signature)).toEqual(
"x:Int y:Int -> result:Int",
Expand All @@ -13,54 +16,78 @@ describe("instructions signatures", () => {
}
{
const signature = await signatureOf("PUSHINT_LONG");
expect(signature).toBeDefined();
await step("Signature should be defined", () => {
expect(signature).toBeDefined();
});
if (signature) {
expect(signatureString(signature)).toEqual("∅ -> x:Int");
await step("Signature should match expected", () => {
expect(signatureString(signature)).toEqual("∅ -> x:Int");
});
}
}
{
const signature = await signatureOf("STDICT");
expect(signature).toBeDefined();
await step("Signature should be defined", () => {
expect(signature).toBeDefined();
});
if (signature) {
expect(signatureString(signature)).toEqual(
"D:Cell|Null b:Builder -> b2:Builder",
);
await step("Signature should match expected", () => {
expect(signatureString(signature)).toEqual(
"D:Cell|Null b:Builder -> b2:Builder",
);
});
}
}
{
const signature = await signatureOf("TUPLE");
expect(signature).toBeDefined();
await step("Signature should be defined", () => {
expect(signature).toBeDefined();
});
if (signature) {
expect(signatureString(signature)).toEqual(
"x_1...x_n -> t:Tuple",
);
await step("Signature should match expected", () => {
expect(signatureString(signature)).toEqual(
"x_1...x_n -> t:Tuple",
);
});
}
}
{
const signature = await signatureOf("UNTUPLE");
expect(signature).toBeDefined();
await step("Signature should be defined", () => {
expect(signature).toBeDefined();
});
if (signature) {
expect(signatureString(signature)).toEqual(
"t:Tuple -> x_1...x_n",
);
await step("Signature should match expected", () => {
expect(signatureString(signature)).toEqual(
"t:Tuple -> x_1...x_n",
);
});
}
}
{
const signature = await signatureOf("STDICT");
expect(signature).toBeDefined();
await step("Signature should be defined", () => {
expect(signature).toBeDefined();
});
if (signature) {
expect(signatureString(signature)).toEqual(
"D:Cell|Null b:Builder -> b2:Builder",
);
await step("Signature should match expected", () => {
expect(signatureString(signature)).toEqual(
"D:Cell|Null b:Builder -> b2:Builder",
);
});
}
}
{
const signature = await signatureOf("STUXQ");
expect(signature).toBeDefined();
await step("Signature should be defined", () => {
expect(signature).toBeDefined();
});
if (signature) {
expect(signatureString(signature)).toEqual(
"x:Int b:Builder l:Int -> (b2:Builder 0)|(x:Int b:Builder -1)|(x:Int b:Builder 1) status:Int",
);
await step("Signature should match expected", () => {
expect(signatureString(signature)).toEqual(
"x:Int b:Builder l:Int -> (b2:Builder 0)|(x:Int b:Builder -1)|(x:Int b:Builder 1) status:Int",
);
});
}
}
});
Expand Down
7 changes: 5 additions & 2 deletions src/asm/runtime/test/tests-boc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as path from "node:path";
import * as fs from "node:fs";
import { Cell } from "@ton/core";
import { DefaultExoticCell, hex } from "@/asm/runtime/util";
import { step } from "@/test/allure/allure";

const readBoc = (filename: string): Cell | undefined => {
const filePath = path.join(__dirname, "testdata", filename);
Expand All @@ -23,12 +24,14 @@ const readHex = (filename: string): Cell => {

const test =
(instructions: i.Instr[], expectedBoc: Cell | undefined): (() => void) =>
() => {
async () => {
if (expectedBoc === undefined) {
throw new Error("expectedBoc is undefined");
}
const compiled = i.compileCell(instructions);
expect(compiled.toString()).toEqual(expectedBoc.toString());
await step("Compiled cell should be expected", () => {
expect(compiled.toString()).toEqual(expectedBoc.toString());
});
};

describe("tests", () => {
Expand Down
17 changes: 10 additions & 7 deletions src/asm/runtime/test/tests-run.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import * as u from "@/asm/runtime/util";
import { execute } from "@/asm/helpers/helpers";
import { code, dictMap } from "@/asm/runtime/util";
import { print } from "@/asm/text/printer";
import { step } from "@/test/allure/allure";

const emptyData = () => beginCell().endCell();

Expand Down Expand Up @@ -70,13 +71,15 @@ const test = (
const openContract = blockchain.openContract(contract);

// Deploy
await openContract.send(
treasury.getSender(),
{
value: toNano("10"),
},
new Cell(),
);
await step("Send contract", async () => {
await openContract.send(
treasury.getSender(),
{
value: toNano("10"),
},
new Cell(),
);
});

const data = await openContract.getAny(methodId);
compareResult(data);
Expand Down
17 changes: 10 additions & 7 deletions src/asm/runtime/test/tests-runvm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type { SandboxContract, TreasuryContract } from "@ton/sandbox";
import { Blockchain } from "@ton/sandbox";
import { call, measureGas2, when } from "@/asm/helpers";
import { dictMap } from "@/asm/runtime/util";
import { step } from "@/test/allure/allure";

describe("runvm-helper", () => {
it(`should correctly execute instructions inside runvm`, async () => {
Expand Down Expand Up @@ -76,13 +77,15 @@ describe("runvm-helper", () => {
const openContract = blockchain.openContract(contract);

// Deploy
await openContract.send(
treasure.getSender(),
{
value: toNano("10"),
},
new Cell(),
);
await step("Send contract", async () => {
await openContract.send(
treasure.getSender(),
{
value: toNano("10"),
},
new Cell(),
);
});
});
});

Expand Down
Loading