Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ton-assembly",
"version": "0.2.4",
"version": "0.3.0",
"description": "TON assembler and disassembler",
"keywords": [
"ton",
Expand Down
4 changes: 2 additions & 2 deletions src/coverage/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ export const buildFuncLineInfo = (traces: TraceInfo[], funcCode: string): Line[]
for (const trace of traces) {
const perLineSteps: Map<number, Step[]> = new Map()
for (const step of trace.steps) {
if (step.funcLoc === undefined) continue
const line = step.funcLoc.line
if (step.sourceMapEntries.length === 0) continue
const line = step.sourceMapEntries[0]?.loc.line ?? 0

perLineSteps.set(line, [...(perLineSteps.get(line) ?? []), step])
}
Expand Down
8 changes: 4 additions & 4 deletions src/coverage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {Cell} from "@ton/core"
import type { Mapping} from "../runtime";
import {compileCellWithMapping, decompileCell} from "../runtime"
import {print, parse} from "../text"
import {createMappingInfo, createTraceInfoPerTransaction, loadFuncMapping} from "../trace"
import {createMappingInfo, createTraceInfoPerTransaction} from "../trace"
import {buildFuncLineInfo, buildLineInfo, generateCoverageSummary} from "./data"
import {readFileSync} from "node:fs"

Expand All @@ -22,13 +22,13 @@ export function collectFuncCoverage(
cell: Cell,
logs: string,
funcSources: string,
funcMappingPath: string,
_funcMappingPath: string,
) {
const [_, mapping] = recompileCell(cell, true)
const info = createMappingInfo(mapping)

const funcMapping = loadFuncMapping(readFileSync(funcMappingPath, "utf8"))
const traceInfos = createTraceInfoPerTransaction(logs, info, funcMapping)
// const funcMapping = loadFuncMapping(readFileSync(funcMappingPath, "utf8"))
const traceInfos = createTraceInfoPerTransaction(logs, info, undefined)
const func = readFileSync(funcSources, "utf8")
const combinedLines = buildFuncLineInfo(traceInfos, func)
const combinedSummary = generateCoverageSummary(combinedLines)
Expand Down
124 changes: 62 additions & 62 deletions src/coverage/test/__snapshots__/asm-coverage.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
exports[`asm coverage dictionary 1`] = `
"Coverage Summary:
Lines: 4/8 (50.00%)
Total Gas: 296
Total Hits: 4
Total Gas: 301
Total Hits: 5

Instruction Stats:
DICTIGETJMPZ | 226 gas | 1 hits | 226 avg gas | 76.35%
DICTPUSHCONST | 34 gas | 1 hits | 34 avg gas | 11.49%
PUSHINT_4 | 18 gas | 1 hits | 18 avg gas | 6.08%
INC | 18 gas | 1 hits | 18 avg gas | 6.08%
DICTIGETJMPZ | 226 gas | 1 hits | 226 avg gas | 75.08%
DICTPUSHCONST | 34 gas | 1 hits | 34 avg gas | 11.30%
INC | 23 gas | 2 hits | 11.5 avg gas | 7.64%
PUSHINT_4 | 18 gas | 1 hits | 18 avg gas | 5.98%

Annotated Code:
1 ✓ | DICTPUSHCONST 19 [ | gas:34 | hits:1
2 | 0 => { | |
3 ✓ | PUSHINT_4 10 | gas:18 | hits:1
4 ✓ | INC | gas:18 | hits:1
4 ✓ | INC | gas:23 | hits:2
5 | } | |
6 | 2 => { | |
7 ✗ | PUSHINT_4 5 | |
Expand All @@ -31,14 +31,14 @@ Annotated Code:
exports[`asm coverage dictionary 2 1`] = `
"Coverage Summary:
Lines: 4/8 (50.00%)
Total Gas: 296
Total Hits: 4
Total Gas: 301
Total Hits: 5

Instruction Stats:
DICTIGETJMPZ | 226 gas | 1 hits | 226 avg gas | 76.35%
DICTPUSHCONST | 34 gas | 1 hits | 34 avg gas | 11.49%
PUSHINT_4 | 18 gas | 1 hits | 18 avg gas | 6.08%
INC | 18 gas | 1 hits | 18 avg gas | 6.08%
DICTIGETJMPZ | 226 gas | 1 hits | 226 avg gas | 75.08%
DICTPUSHCONST | 34 gas | 1 hits | 34 avg gas | 11.30%
INC | 23 gas | 2 hits | 11.5 avg gas | 7.64%
PUSHINT_4 | 18 gas | 1 hits | 18 avg gas | 5.98%

Annotated Code:
1 ✓ | DICTPUSHCONST 19 [ | gas:34 | hits:1
Expand All @@ -48,7 +48,7 @@ Annotated Code:
5 | } | |
6 | 2 => { | |
7 ✓ | PUSHINT_4 5 | gas:18 | hits:1
8 ✓ | INC | gas:18 | hits:1
8 ✓ | INC | gas:23 | hits:2
9 | } | |
10 ✗ | ] | |
11 ✓ | DICTIGETJMPZ | gas:226 | hits:1
Expand Down Expand Up @@ -80,15 +80,15 @@ Annotated Code:
exports[`asm coverage nested try with rethrow 1`] = `
"Coverage Summary:
Lines: 9/9 (100.00%)
Total Gas: 334
Total Hits: 9
Total Gas: 344
Total Hits: 11

Instruction Stats:
PUSHCONT | 104 gas | 4 hits | 26 avg gas | 31.14%
THROW | 84 gas | 1 hits | 84 avg gas | 25.15%
THROWANY | 76 gas | 1 hits | 76 avg gas | 22.75%
TRY | 52 gas | 2 hits | 26 avg gas | 15.57%
PUSHINT_4 | 18 gas | 1 hits | 18 avg gas | 5.39%
PUSHCONT | 104 gas | 4 hits | 26 avg gas | 30.23%
THROW | 84 gas | 1 hits | 84 avg gas | 24.42%
THROWANY | 76 gas | 1 hits | 76 avg gas | 22.09%
TRY | 52 gas | 2 hits | 26 avg gas | 15.12%
PUSHINT_4 | 28 gas | 3 hits | 9.33 avg gas | 8.14%

Annotated Code:
1 ✓ | PUSHCONT { | gas:26 | hits:1
Expand All @@ -101,7 +101,7 @@ Annotated Code:
8 ✓ | TRY | gas:26 | hits:1
9 | } | |
10 ✓ | PUSHCONT { | gas:26 | hits:1
11 ✓ | PUSHINT_4 2 | gas:18 | hits:1
11 ✓ | PUSHINT_4 2 | gas:28 | hits:3
12 | } | |
13 ✓ | TRY | gas:26 | hits:1
14 | | |"
Expand All @@ -110,13 +110,13 @@ Annotated Code:
exports[`asm coverage simple if 1`] = `
"Coverage Summary:
Lines: 4/7 (57.14%)
Total Gas: 80
Total Hits: 4
Total Gas: 85
Total Hits: 5

Instruction Stats:
PUSHINT_4 | 36 gas | 2 hits | 18 avg gas | 45.00%
PUSHCONT | 26 gas | 1 hits | 26 avg gas | 32.50%
IF | 18 gas | 1 hits | 18 avg gas | 22.50%
PUSHINT_4 | 36 gas | 2 hits | 18 avg gas | 42.35%
PUSHCONT | 26 gas | 1 hits | 26 avg gas | 30.59%
IF | 23 gas | 2 hits | 11.5 avg gas | 27.06%

Annotated Code:
1 ✓ | PUSHINT_4 0 | gas:18 | hits:1
Expand All @@ -126,27 +126,27 @@ Annotated Code:
5 ✗ | INC | |
6 ✗ | INC | |
7 | } | |
8 ✓ | IF | gas:18 | hits:1
8 ✓ | IF | gas:23 | hits:2
9 | | |"
`;

exports[`asm coverage simple if-else 1`] = `
"Coverage Summary:
Lines: 6/7 (85.71%)
Total Gas: 124
Total Hits: 6
Total Gas: 134
Total Hits: 8

Instruction Stats:
PUSHCONT | 52 gas | 2 hits | 26 avg gas | 41.94%
PUSHINT_4 | 36 gas | 2 hits | 18 avg gas | 29.03%
INC | 18 gas | 1 hits | 18 avg gas | 14.52%
IFELSE | 18 gas | 1 hits | 18 avg gas | 14.52%
PUSHCONT | 52 gas | 2 hits | 26 avg gas | 38.81%
PUSHINT_4 | 36 gas | 2 hits | 18 avg gas | 26.87%
INC | 28 gas | 3 hits | 9.33 avg gas | 20.90%
IFELSE | 18 gas | 1 hits | 18 avg gas | 13.43%

Annotated Code:
1 ✓ | PUSHINT_4 0 | gas:18 | hits:1
2 ✓ | PUSHINT_4 -1 | gas:18 | hits:1
3 ✓ | PUSHCONT { | gas:26 | hits:1
4 ✓ | INC | gas:18 | hits:1
4 ✓ | INC | gas:28 | hits:3
5 | } | |
6 ✓ | PUSHCONT { | gas:26 | hits:1
7 ✗ | DEC | |
Expand All @@ -158,23 +158,23 @@ Annotated Code:
exports[`asm coverage try with throw 1`] = `
"Coverage Summary:
Lines: 6/6 (100.00%)
Total Gas: 198
Total Hits: 6
Total Gas: 208
Total Hits: 8

Instruction Stats:
THROW | 84 gas | 1 hits | 84 avg gas | 42.42%
PUSHCONT | 52 gas | 2 hits | 26 avg gas | 26.26%
TRY | 26 gas | 1 hits | 26 avg gas | 13.13%
PUSHINT_4 | 18 gas | 1 hits | 18 avg gas | 9.09%
SUB | 18 gas | 1 hits | 18 avg gas | 9.09%
THROW | 84 gas | 1 hits | 84 avg gas | 40.38%
PUSHCONT | 52 gas | 2 hits | 26 avg gas | 25.00%
SUB | 28 gas | 3 hits | 9.33 avg gas | 13.46%
TRY | 26 gas | 1 hits | 26 avg gas | 12.50%
PUSHINT_4 | 18 gas | 1 hits | 18 avg gas | 8.65%

Annotated Code:
1 ✓ | PUSHINT_4 10 | gas:18 | hits:1
2 ✓ | PUSHCONT { | gas:26 | hits:1
3 ✓ | THROW 10 | gas:84 | hits:1
4 | } | |
5 ✓ | PUSHCONT { | gas:26 | hits:1
6 ✓ | SUB | gas:18 | hits:1
6 ✓ | SUB | gas:28 | hits:3
7 | } | |
8 ✓ | TRY | gas:26 | hits:1
9 | | |"
Expand All @@ -183,19 +183,19 @@ Annotated Code:
exports[`asm coverage try without throw 1`] = `
"Coverage Summary:
Lines: 5/6 (83.33%)
Total Gas: 114
Total Hits: 5
Total Gas: 124
Total Hits: 7

Instruction Stats:
PUSHCONT | 52 gas | 2 hits | 26 avg gas | 45.61%
TRY | 26 gas | 1 hits | 26 avg gas | 22.81%
PUSHINT_4 | 18 gas | 1 hits | 18 avg gas | 15.79%
INC | 18 gas | 1 hits | 18 avg gas | 15.79%
PUSHCONT | 52 gas | 2 hits | 26 avg gas | 41.94%
INC | 28 gas | 3 hits | 9.33 avg gas | 22.58%
TRY | 26 gas | 1 hits | 26 avg gas | 20.97%
PUSHINT_4 | 18 gas | 1 hits | 18 avg gas | 14.52%

Annotated Code:
1 ✓ | PUSHINT_4 10 | gas:18 | hits:1
2 ✓ | PUSHCONT { | gas:26 | hits:1
3 ✓ | INC | gas:18 | hits:1
3 ✓ | INC | gas:28 | hits:3
4 | } | |
5 ✓ | PUSHCONT { | gas:26 | hits:1
6 ✗ | DEC | |
Expand All @@ -207,30 +207,30 @@ Annotated Code:
exports[`asm coverage while loop with break 1`] = `
"Coverage Summary:
Lines: 10/10 (100.00%)
Total Gas: 1002
Total Hits: 45
Total Gas: 1067
Total Hits: 58

Instruction Stats:
DUP | 252 gas | 14 hits | 18 avg gas | 25.15%
GTINT | 182 gas | 7 hits | 26 avg gas | 18.16%
LESSINT | 182 gas | 7 hits | 26 avg gas | 18.16%
IFRETALT | 182 gas | 7 hits | 26 avg gas | 18.16%
DEC | 108 gas | 6 hits | 18 avg gas | 10.78%
PUSHCONT | 52 gas | 2 hits | 26 avg gas | 5.19%
WHILEBRK | 26 gas | 1 hits | 26 avg gas | 2.59%
PUSHINT_4 | 18 gas | 1 hits | 18 avg gas | 1.80%
DUP | 252 gas | 14 hits | 18 avg gas | 23.62%
GTINT | 217 gas | 14 hits | 15.5 avg gas | 20.34%
LESSINT | 182 gas | 7 hits | 26 avg gas | 17.06%
IFRETALT | 182 gas | 7 hits | 26 avg gas | 17.06%
DEC | 138 gas | 12 hits | 11.5 avg gas | 12.93%
PUSHCONT | 52 gas | 2 hits | 26 avg gas | 4.87%
WHILEBRK | 26 gas | 1 hits | 26 avg gas | 2.44%
PUSHINT_4 | 18 gas | 1 hits | 18 avg gas | 1.69%

Annotated Code:
1 ✓ | PUSHINT_4 10 | gas:18 | hits:1
2 ✓ | PUSHCONT { | gas:26 | hits:1
3 ✓ | DUP | gas:126 | hits:7
4 ✓ | GTINT 0 | gas:182 | hits:7
4 ✓ | GTINT 0 | gas:217 | hits:14
5 | } | |
6 ✓ | PUSHCONT { | gas:26 | hits:1
7 ✓ | DUP | gas:126 | hits:7
8 ✓ | LESSINT 5 | gas:182 | hits:7
9 ✓ | IFRETALT | gas:182 | hits:7
10 ✓ | DEC | gas:108 | hits:6
10 ✓ | DEC | gas:138 | hits:12
11 | } | |
12 ✓ | WHILEBRK | gas:26 | hits:1
13 | | |"
Expand Down
Loading
Loading