@ton/sandbox 0.35.0 → 0.35.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/blockchain/SmartContract.d.ts +0 -5
- package/dist/blockchain/SmartContract.js +7 -21
- package/dist/debugger/DebugContext.d.ts +14 -0
- package/dist/debugger/DebugContext.js +27 -0
- package/dist/debugger/DebugInfoCache.d.ts +6 -3
- package/dist/debugger/DebugInfoCache.js +24 -5
- package/dist/debugger/index.d.ts +1 -0
- package/dist/debugger/index.js +5 -0
- package/dist/jest/BenchmarkReporter.js +2 -1
- package/dist/metric/index.d.ts +0 -1
- package/dist/metric/index.js +0 -1
- package/dist/utils/environment.d.ts +1 -0
- package/dist/utils/environment.js +8 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.35.1] - 2025-07-08
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Fixed sandbox not running in browser environment
|
|
13
|
+
|
|
8
14
|
## [0.35.0] - 2025-07-07
|
|
9
15
|
|
|
10
16
|
### Changed
|
|
@@ -3,7 +3,6 @@ import { Address, Cell, Message, OutAction, ShardAccount, Transaction, TupleItem
|
|
|
3
3
|
import { Blockchain } from './Blockchain';
|
|
4
4
|
import { ExtraCurrency } from '../utils/ec';
|
|
5
5
|
import { EmulationResult, RunCommonArgs, TickOrTock } from '../executor/Executor';
|
|
6
|
-
import { DebugInfo } from '../debugger/Debuggee';
|
|
7
6
|
export declare function createShardAccount(args: {
|
|
8
7
|
address?: Address;
|
|
9
8
|
code: Cell;
|
|
@@ -98,10 +97,6 @@ export declare class SmartContract {
|
|
|
98
97
|
}): SmartContract;
|
|
99
98
|
static empty(blockchain: Blockchain, address: Address): SmartContract;
|
|
100
99
|
protected createCommonArgs(params?: MessageParams): RunCommonArgs;
|
|
101
|
-
protected getDebugInfo(): {
|
|
102
|
-
uninitialized: boolean;
|
|
103
|
-
debugInfo: DebugInfo | undefined;
|
|
104
|
-
};
|
|
105
100
|
receiveMessage(message: Message, params?: MessageParams): Promise<SmartContractTransaction>;
|
|
106
101
|
runTickTock(which: TickOrTock, params?: MessageParams): Promise<SmartContractTransaction>;
|
|
107
102
|
protected runCommon(run: () => Promise<EmulationResult>): Promise<SmartContractTransaction>;
|
|
@@ -17,8 +17,7 @@ const core_1 = require("@ton/core");
|
|
|
17
17
|
const ec_1 = require("../utils/ec");
|
|
18
18
|
const selector_1 = require("../utils/selector");
|
|
19
19
|
const deepcopy_1 = require("../utils/deepcopy");
|
|
20
|
-
const
|
|
21
|
-
const debug_1 = require("../debugger/debug");
|
|
20
|
+
const debugger_1 = require("../debugger");
|
|
22
21
|
function createShardAccount(args) {
|
|
23
22
|
let wc = args.workchain ?? 0;
|
|
24
23
|
let address = args.address ?? (0, core_1.contractAddress)(wc, { code: args.code, data: args.data });
|
|
@@ -223,31 +222,17 @@ class SmartContract {
|
|
|
223
222
|
prevBlocksInfo: this.blockchain.prevBlocks,
|
|
224
223
|
};
|
|
225
224
|
}
|
|
226
|
-
getDebugInfo() {
|
|
227
|
-
const acc = this.account;
|
|
228
|
-
if (acc.account === undefined || acc.account === null) {
|
|
229
|
-
return { uninitialized: true, debugInfo: undefined };
|
|
230
|
-
}
|
|
231
|
-
if (acc.account.storage.state.type !== 'active') {
|
|
232
|
-
return { uninitialized: true, debugInfo: undefined };
|
|
233
|
-
}
|
|
234
|
-
const code = acc.account.storage.state.state.code;
|
|
235
|
-
if (code === undefined || code === null) {
|
|
236
|
-
return { uninitialized: true, debugInfo: undefined };
|
|
237
|
-
}
|
|
238
|
-
const debugInfo = DebugInfoCache_1.defaultDebugInfoCache.get(code.hash().toString('base64'));
|
|
239
|
-
return { uninitialized: false, debugInfo };
|
|
240
|
-
}
|
|
241
225
|
async receiveMessage(message, params) {
|
|
242
226
|
const args = {
|
|
243
227
|
...this.createCommonArgs(params),
|
|
244
228
|
message: (0, core_1.beginCell)().store((0, core_1.storeMessage)(message)).endCell(),
|
|
245
229
|
};
|
|
246
230
|
if (this.debug) {
|
|
247
|
-
const
|
|
231
|
+
const debugContext = (0, debugger_1.getDebugContext)();
|
|
232
|
+
const { uninitialized, debugInfo } = debugContext.getDebugInfo(this.account);
|
|
248
233
|
if (debugInfo !== undefined) {
|
|
249
234
|
const executor = await this.blockchain.getDebuggerExecutor();
|
|
250
|
-
return await this.runCommon(() =>
|
|
235
|
+
return await this.runCommon(() => debugContext.debugTransaction(executor, args, debugInfo));
|
|
251
236
|
}
|
|
252
237
|
else if (uninitialized) {
|
|
253
238
|
// eslint-disable-next-line no-console
|
|
@@ -330,10 +315,11 @@ class SmartContract {
|
|
|
330
315
|
};
|
|
331
316
|
let res;
|
|
332
317
|
if (this.debug) {
|
|
333
|
-
const
|
|
318
|
+
const debugContext = (0, debugger_1.getDebugContext)();
|
|
319
|
+
const { uninitialized, debugInfo } = debugContext.getDebugInfo(this.account);
|
|
334
320
|
if (debugInfo !== undefined) {
|
|
335
321
|
const executor = await this.blockchain.getDebuggerExecutor();
|
|
336
|
-
res = await
|
|
322
|
+
res = await debugContext.debugGetMethod(executor, args, debugInfo);
|
|
337
323
|
}
|
|
338
324
|
else {
|
|
339
325
|
if (uninitialized) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ShardAccount } from '@ton/core';
|
|
2
|
+
import type { EmulationResult, Executor, GetMethodArgs, GetMethodResult, RunTransactionArgs } from '../executor/Executor';
|
|
3
|
+
import type { DebugInfo } from './Debuggee';
|
|
4
|
+
declare class DebugContext {
|
|
5
|
+
constructor();
|
|
6
|
+
getDebugInfo: (account: ShardAccount) => {
|
|
7
|
+
uninitialized: boolean;
|
|
8
|
+
debugInfo: DebugInfo | undefined;
|
|
9
|
+
};
|
|
10
|
+
debugGetMethod: (executor: Executor, args: GetMethodArgs, debugInfo: DebugInfo) => Promise<GetMethodResult>;
|
|
11
|
+
debugTransaction: (executor: Executor, args: RunTransactionArgs, debugInfo: DebugInfo) => Promise<EmulationResult>;
|
|
12
|
+
}
|
|
13
|
+
export declare function getDebugContext(): DebugContext;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDebugContext = void 0;
|
|
4
|
+
const environment_1 = require("../utils/environment");
|
|
5
|
+
// only this class is allowed to use outside the 'debugger' directory for browser support
|
|
6
|
+
class DebugContext {
|
|
7
|
+
constructor() {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
9
|
+
const { debugGetMethod, debugTransaction } = require('./debug');
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
11
|
+
const { getDebugInfo } = require('./DebugInfoCache');
|
|
12
|
+
this.debugGetMethod = debugGetMethod;
|
|
13
|
+
this.debugTransaction = debugTransaction;
|
|
14
|
+
this.getDebugInfo = getDebugInfo;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
let debugContext = undefined;
|
|
18
|
+
function getDebugContext() {
|
|
19
|
+
if ((0, environment_1.isBrowser)()) {
|
|
20
|
+
throw new Error('Debug feature is not supported in browser environment');
|
|
21
|
+
}
|
|
22
|
+
if (!debugContext) {
|
|
23
|
+
debugContext = new DebugContext();
|
|
24
|
+
}
|
|
25
|
+
return debugContext;
|
|
26
|
+
}
|
|
27
|
+
exports.getDebugContext = getDebugContext;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { Cell } from '@ton/core';
|
|
1
|
+
import { Cell, type ShardAccount } from '@ton/core';
|
|
2
2
|
import { DebugInfo as FuncDebugInfo } from '@ton-community/func-js';
|
|
3
|
-
import { DebugInfo } from './Debuggee';
|
|
3
|
+
import type { DebugInfo } from './Debuggee';
|
|
4
4
|
export type DebugInfoCache = Map<string, DebugInfo>;
|
|
5
|
-
export declare
|
|
5
|
+
export declare function getDebugInfo(acc: ShardAccount): {
|
|
6
|
+
uninitialized: boolean;
|
|
7
|
+
debugInfo: DebugInfo | undefined;
|
|
8
|
+
};
|
|
6
9
|
export declare function registerCompiledContract(code: Cell, debugInfo: FuncDebugInfo, marks: Cell): Cell;
|
|
@@ -1,17 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.registerCompiledContract = exports.
|
|
4
|
-
const node_path_1 = require("node:path");
|
|
3
|
+
exports.registerCompiledContract = exports.getDebugInfo = void 0;
|
|
5
4
|
const marks_1 = require("./marks");
|
|
6
|
-
|
|
5
|
+
const environment_1 = require("../utils/environment");
|
|
6
|
+
const defaultDebugInfoCache = new Map();
|
|
7
|
+
function getDebugInfo(acc) {
|
|
8
|
+
if (acc.account === undefined || acc.account === null) {
|
|
9
|
+
return { uninitialized: true, debugInfo: undefined };
|
|
10
|
+
}
|
|
11
|
+
if (acc.account.storage.state.type !== 'active') {
|
|
12
|
+
return { uninitialized: true, debugInfo: undefined };
|
|
13
|
+
}
|
|
14
|
+
const code = acc.account.storage.state.state.code;
|
|
15
|
+
if (code === undefined || code === null) {
|
|
16
|
+
return { uninitialized: true, debugInfo: undefined };
|
|
17
|
+
}
|
|
18
|
+
const debugInfo = defaultDebugInfoCache.get(code.hash().toString('base64'));
|
|
19
|
+
return { uninitialized: false, debugInfo };
|
|
20
|
+
}
|
|
21
|
+
exports.getDebugInfo = getDebugInfo;
|
|
7
22
|
function registerCompiledContract(code, debugInfo, marks) {
|
|
23
|
+
if ((0, environment_1.isBrowser)()) {
|
|
24
|
+
throw new Error('Debug feature is not supported in browser environment');
|
|
25
|
+
}
|
|
8
26
|
const parsedMarks = (0, marks_1.parseMarks)(marks, code);
|
|
9
27
|
const { locations, globals } = debugInfo;
|
|
10
28
|
const sm = {};
|
|
11
29
|
for (let i = 0; i < locations.length; i++) {
|
|
12
30
|
const di = locations[i];
|
|
13
31
|
const common = {
|
|
14
|
-
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
33
|
+
path: require('node:path').resolve(di.file),
|
|
15
34
|
line: di.line,
|
|
16
35
|
function: di.func,
|
|
17
36
|
contextId: di.ctx_id,
|
|
@@ -59,7 +78,7 @@ function registerCompiledContract(code, debugInfo, marks) {
|
|
|
59
78
|
};
|
|
60
79
|
}
|
|
61
80
|
}
|
|
62
|
-
|
|
81
|
+
defaultDebugInfoCache.set(code.hash().toString('base64'), {
|
|
63
82
|
sourceMap: sm,
|
|
64
83
|
globals,
|
|
65
84
|
marks: parsedMarks,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getDebugContext } from './DebugContext';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDebugContext = void 0;
|
|
4
|
+
var DebugContext_1 = require("./DebugContext");
|
|
5
|
+
Object.defineProperty(exports, "getDebugContext", { enumerable: true, get: function () { return DebugContext_1.getDebugContext; } });
|
|
@@ -32,6 +32,7 @@ const BenchmarkCommand_1 = require("./BenchmarkCommand");
|
|
|
32
32
|
const BenchmarkEnvironment_1 = require("./BenchmarkEnvironment");
|
|
33
33
|
const readJsonl_1 = require("../utils/readJsonl");
|
|
34
34
|
const metric_1 = require("../metric");
|
|
35
|
+
const readSnapshots_1 = require("../metric/readSnapshots");
|
|
35
36
|
exports.defaultSnapshotDir = '.snapshot';
|
|
36
37
|
exports.defaultReportName = 'gas-report';
|
|
37
38
|
exports.defaultContractDatabaseName = 'contract.abi.json';
|
|
@@ -77,7 +78,7 @@ class BenchmarkReporter extends reporters_1.BaseReporter {
|
|
|
77
78
|
return this.options.depthCompare || exports.defaultDepthCompare;
|
|
78
79
|
}
|
|
79
80
|
get snapshotFiles() {
|
|
80
|
-
return (0,
|
|
81
|
+
return (0, readSnapshots_1.readSnapshots)(this.snapshotDirPath);
|
|
81
82
|
}
|
|
82
83
|
get snapshots() {
|
|
83
84
|
return this.snapshotFiles.then((list) => Object.values(list).map((item) => item.content));
|
package/dist/metric/index.d.ts
CHANGED
package/dist/metric/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isBrowser(): boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isBrowser = void 0;
|
|
4
|
+
function isBrowser() {
|
|
5
|
+
// eslint-disable-next-line no-undef
|
|
6
|
+
return typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
7
|
+
}
|
|
8
|
+
exports.isBrowser = isBrowser;
|