@ton/sandbox 0.40.0 → 0.41.0

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 CHANGED
@@ -5,6 +5,13 @@ 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.41.0] - 2025-12-05
9
+
10
+ ### Changed
11
+
12
+ - Updated emulator WASM binary
13
+ - Debug logs are now extracted from VM logs (due to emulator changes), which interacts in subtle ways with the verbosity settings
14
+
8
15
  ## [0.40.0] - 2025-12-04
9
16
 
10
17
  ### Added
@@ -96,10 +96,8 @@ export declare class Executor implements IExecutor {
96
96
  private module;
97
97
  private heap;
98
98
  private emulator?;
99
- private debugLogs;
100
99
  debugLogFunc: (s: string) => void;
101
100
  private constructor();
102
- private handleDebugLog;
103
101
  static create(opts?: {
104
102
  debug?: boolean;
105
103
  }): Promise<Executor>;
@@ -164,62 +164,63 @@ function getDebuggerWasmBinary() {
164
164
  debuggerWasmBinary = (0, bpatch_1.decodePatch)(getWasmBinary(), unzipped);
165
165
  return debuggerWasmBinary;
166
166
  }
167
+ function splitVmLog(log) {
168
+ const vm = [];
169
+ const debug = [];
170
+ for (const line of log.split('\n')) {
171
+ if (line.startsWith('#DEBUG#')) {
172
+ debug.push(line);
173
+ }
174
+ else {
175
+ vm.push(line);
176
+ }
177
+ }
178
+ return { vmLog: vm.join('\n'), debugLog: debug.join('\n') };
179
+ }
167
180
  class Executor {
168
181
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
169
182
  module;
170
183
  heap;
171
184
  emulator;
172
- debugLogs = [];
185
+ // TODO: this is not used anymore - debug logs are now included in the VM log, and so we cannot emit them during execution
173
186
  debugLogFunc = () => { };
174
187
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
175
188
  constructor(module) {
176
189
  this.module = module;
177
190
  this.heap = new Heap(module);
178
191
  }
179
- handleDebugLog(text) {
180
- this.debugLogs.push(text);
181
- this.debugLogFunc(text);
182
- }
183
192
  static async create(opts) {
184
193
  const binary = opts?.debug ? getDebuggerWasmBinary() : getWasmBinary();
185
194
  const module = opts?.debug ? DebuggerEmulatorModule : EmulatorModule;
186
195
  let ex = undefined;
187
- const printErr = (text) => {
188
- if (ex === undefined) {
189
- // eslint-disable-next-line no-console
190
- console.error('Debug log received before executor was created:', text);
191
- }
192
- else {
193
- ex.handleDebugLog(text);
194
- }
195
- };
196
196
  ex = new Executor(await module({
197
197
  wasmBinary: binary,
198
- printErr,
199
198
  }));
200
199
  return ex;
201
200
  }
202
201
  async runGetMethod(args) {
203
202
  const params = getMethodArgsToInternalParams(args);
204
203
  let stack = (0, core_1.serializeTuple)(args.stack);
205
- this.debugLogs = [];
206
204
  const resp = JSON.parse(this.extractString(this.invoke('_run_get_method', [JSON.stringify(params), stack.toBoc().toString('base64'), args.config])));
207
- const debugLogs = this.debugLogs.join('\n');
208
205
  if (resp.fail) {
209
206
  // eslint-disable-next-line no-console
210
207
  console.error(resp);
211
208
  throw new Error('Unknown emulation error');
212
209
  }
210
+ const { vmLog, debugLog } = splitVmLog('vm_log' in resp.output ? resp.output.vm_log : '');
213
211
  return {
214
- output: resp.output,
212
+ output: 'vm_log' in resp.output
213
+ ? {
214
+ ...resp.output,
215
+ vm_log: vmLog,
216
+ }
217
+ : resp.output,
215
218
  logs: resp.logs,
216
- debugLogs,
219
+ debugLogs: debugLog,
217
220
  };
218
221
  }
219
222
  runCommon(args) {
220
- this.debugLogs = [];
221
223
  const resp = JSON.parse(this.extractString(this.invoke('_emulate_with_emulator', args)));
222
- const debugLogs = this.debugLogs.join('\n');
223
224
  if (resp.fail) {
224
225
  // eslint-disable-next-line no-console
225
226
  console.error(resp);
@@ -227,13 +228,14 @@ class Executor {
227
228
  }
228
229
  const logs = resp.logs;
229
230
  const result = resp.output;
231
+ const { vmLog, debugLog } = splitVmLog('vm_log' in result ? result.vm_log : '');
230
232
  return {
231
233
  result: result.success
232
234
  ? {
233
235
  success: true,
234
236
  transaction: result.transaction,
235
237
  shardAccount: result.shard_account,
236
- vmLog: result.vm_log,
238
+ vmLog: vmLog,
237
239
  actions: result.actions,
238
240
  }
239
241
  : {
@@ -241,13 +243,13 @@ class Executor {
241
243
  error: result.error,
242
244
  vmResults: 'vm_log' in result
243
245
  ? {
244
- vmLog: result.vm_log,
246
+ vmLog: vmLog,
245
247
  vmExitCode: result.vm_exit_code,
246
248
  }
247
249
  : undefined,
248
250
  },
249
251
  logs,
250
- debugLogs,
252
+ debugLogs: debugLog,
251
253
  };
252
254
  }
253
255
  async runTickTock(args) {
@@ -312,7 +314,6 @@ class Executor {
312
314
  sbsGetMethodSetup(args) {
313
315
  const params = getMethodArgsToInternalParams(args);
314
316
  let stack = (0, core_1.serializeTuple)(args.stack);
315
- this.debugLogs = [];
316
317
  const res = this.invoke('_setup_sbs_get_method', [
317
318
  JSON.stringify(params),
318
319
  stack.toBoc().toString('base64'),
@@ -360,17 +361,21 @@ class Executor {
360
361
  }
361
362
  sbsGetMethodResult(ptr) {
362
363
  const resp = JSON.parse(this.extractString(this.invoke('_sbs_get_method_result', [ptr])));
363
- const debugLogs = this.debugLogs.join('\n');
364
+ const { vmLog, debugLog } = splitVmLog('vm_log' in resp ? resp.vm_log : '');
364
365
  return {
365
- output: resp,
366
+ output: 'vm_log' in resp
367
+ ? {
368
+ ...resp,
369
+ vm_log: vmLog,
370
+ }
371
+ : resp,
366
372
  logs: 'BLOCKCHAIN LOGS ARE NOT AVAILABLE IN DEBUGGER BETA',
367
- debugLogs,
373
+ debugLogs: debugLog,
368
374
  };
369
375
  }
370
376
  sbsTransactionSetup(args) {
371
377
  const emptr = this.invoke('_create_emulator', [args.config, verbosityToNum[args.verbosity]]);
372
378
  const params = runCommonArgsToInternalParams(args);
373
- this.debugLogs = [];
374
379
  const res = this.invoke('_emulate_sbs', [
375
380
  emptr,
376
381
  args.libs?.toBoc().toString('base64') ?? 0,
@@ -420,14 +425,14 @@ class Executor {
420
425
  }
421
426
  sbsTransactionResult(ptr) {
422
427
  const result = JSON.parse(this.extractString(this.invoke('_em_sbs_result', [ptr])));
423
- const debugLogs = this.debugLogs.join('\n');
428
+ const { vmLog, debugLog } = splitVmLog('vm_log' in result ? result.vm_log : '');
424
429
  return {
425
430
  result: result.success
426
431
  ? {
427
432
  success: true,
428
433
  transaction: result.transaction,
429
434
  shardAccount: result.shard_account,
430
- vmLog: result.vm_log,
435
+ vmLog: vmLog,
431
436
  actions: result.actions,
432
437
  }
433
438
  : {
@@ -435,13 +440,13 @@ class Executor {
435
440
  error: result.error,
436
441
  vmResults: 'vm_log' in result
437
442
  ? {
438
- vmLog: result.vm_log,
443
+ vmLog: vmLog,
439
444
  vmExitCode: result.vm_exit_code,
440
445
  }
441
446
  : undefined,
442
447
  },
443
448
  logs: 'BLOCKCHAIN LOGS ARE NOT AVAILABLE IN DEBUGGER BETA',
444
- debugLogs,
449
+ debugLogs: debugLog,
445
450
  };
446
451
  }
447
452
  extractString(ptr) {