@ton/sandbox 0.21.0-debugger.2 → 0.21.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,16 @@ 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.21.0] - 2024-09-16
9
+
10
+ ### Added
11
+
12
+ - `SandboxContract` now wraps methods starting with `is` (having the same semantics as `get`) as well as `send` and `get`
13
+
14
+ ### Changed
15
+
16
+ - Updated dependencies
17
+
8
18
  ## [0.20.0] - 2024-05-31
9
19
 
10
20
  ### Added
@@ -45,7 +45,7 @@ export declare const SANDBOX_CONTRACT_SYMBOL: unique symbol;
45
45
  * @template F Type parameter representing the original contract object.
46
46
  */
47
47
  export type SandboxContract<F> = {
48
- [P in keyof F]: P extends `get${string}` ? (F[P] extends (x: infer CP, ...args: infer P) => infer R ? (ExtendsContractProvider<CP> extends true ? (...args: P) => R : never) : never) : (P extends `send${string}` ? (F[P] extends (x: infer CP, ...args: infer P) => infer R ? (ExtendsContractProvider<CP> extends true ? (...args: P) => Promise<SendMessageResult & {
48
+ [P in keyof F]: P extends `${'get' | 'is'}${string}` ? (F[P] extends (x: infer CP, ...args: infer P) => infer R ? (ExtendsContractProvider<CP> extends true ? (...args: P) => R : never) : never) : (P extends `send${string}` ? (F[P] extends (x: infer CP, ...args: infer P) => infer R ? (ExtendsContractProvider<CP> extends true ? (...args: P) => Promise<SendMessageResult & {
49
49
  result: R extends Promise<infer PR> ? PR : R;
50
50
  }> : never) : never) : F[P]);
51
51
  };
@@ -98,7 +98,6 @@ export declare class Blockchain {
98
98
  protected lock: AsyncLock;
99
99
  protected contractFetches: Map<string, Promise<SmartContract>>;
100
100
  protected nextCreateWalletIndex: number;
101
- protected shouldDebug: boolean;
102
101
  readonly executor: IExecutor;
103
102
  /**
104
103
  * Saves snapshot of current blockchain.
@@ -116,8 +115,6 @@ export declare class Blockchain {
116
115
  * @param snapshot Snapshot of blockchain
117
116
  */
118
117
  loadFrom(snapshot: BlockchainSnapshot): Promise<void>;
119
- get debug(): boolean;
120
- set debug(value: boolean);
121
118
  /**
122
119
  * @returns Current time in blockchain
123
120
  */
@@ -81,12 +81,6 @@ class Blockchain {
81
81
  this.globalLibs = snapshot.libs;
82
82
  this.nextCreateWalletIndex = snapshot.nextCreateWalletIndex;
83
83
  }
84
- get debug() {
85
- return this.shouldDebug;
86
- }
87
- set debug(value) {
88
- this.shouldDebug = value;
89
- }
90
84
  /**
91
85
  * @returns Current time in blockchain
92
86
  */
@@ -118,7 +112,6 @@ class Blockchain {
118
112
  this.lock = new AsyncLock_1.AsyncLock();
119
113
  this.contractFetches = new Map();
120
114
  this.nextCreateWalletIndex = 0;
121
- this.shouldDebug = false;
122
115
  this.networkConfig = blockchainConfigToBase64(opts.config);
123
116
  this.executor = opts.executor;
124
117
  this.storage = opts.storage;
@@ -98,6 +98,4 @@ export declare class SmartContract {
98
98
  get verbosity(): LogsVerbosity;
99
99
  set verbosity(value: LogsVerbosity);
100
100
  setVerbosity(verbosity: Partial<LogsVerbosity> | Verbosity | undefined): void;
101
- get debug(): boolean;
102
- setDebug(debug: boolean | undefined): void;
103
101
  }
@@ -10,13 +10,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _SmartContract_account, _SmartContract_parsedAccount, _SmartContract_lastTxTime, _SmartContract_verbosity, _SmartContract_debug;
13
+ var _SmartContract_account, _SmartContract_parsedAccount, _SmartContract_lastTxTime, _SmartContract_verbosity;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.SmartContract = exports.EmulationError = exports.TimeError = exports.GetMethodError = exports.createEmptyShardAccount = exports.createShardAccount = void 0;
16
16
  const core_1 = require("@ton/core");
17
17
  const selector_1 = require("../utils/selector");
18
- const debug_1 = require("../debugger/debug");
19
- const DebugInfoCache_1 = require("../debugger/DebugInfoCache");
20
18
  function createShardAccount(args) {
21
19
  let wc = args.workchain ?? 0;
22
20
  let address = args.address ?? (0, core_1.contractAddress)(wc, { code: args.code, data: args.data });
@@ -130,7 +128,6 @@ class SmartContract {
130
128
  _SmartContract_parsedAccount.set(this, void 0);
131
129
  _SmartContract_lastTxTime.set(this, void 0);
132
130
  _SmartContract_verbosity.set(this, void 0);
133
- _SmartContract_debug.set(this, void 0);
134
131
  this.address = shardAccount.account.addr;
135
132
  __classPrivateFieldSet(this, _SmartContract_account, (0, core_1.beginCell)().store((0, core_1.storeShardAccount)(shardAccount)).endCell().toBoc().toString('base64'), "f");
136
133
  __classPrivateFieldSet(this, _SmartContract_parsedAccount, shardAccount, "f");
@@ -213,34 +210,10 @@ class SmartContract {
213
210
  now: this.blockchain.now,
214
211
  ...params,
215
212
  };
216
- const args = {
213
+ return await this.runCommon(() => this.blockchain.executor.runTransaction({
217
214
  ...this.createCommonArgs(params),
218
215
  message: (0, core_1.beginCell)().store((0, core_1.storeMessage)(message)).endCell(),
219
- };
220
- if (this.debug) {
221
- const acc = this.account;
222
- if (acc.account === undefined || acc.account === null) {
223
- console.log('Debugging uninitialized accounts is unsupported in debugger beta');
224
- return await this.runCommon(() => this.blockchain.executor.runTransaction(args));
225
- }
226
- if (acc.account.storage.state.type !== 'active') {
227
- console.log('Debugging uninitialized accounts is unsupported in debugger beta');
228
- return await this.runCommon(() => this.blockchain.executor.runTransaction(args));
229
- }
230
- const code = acc.account.storage.state.state.code;
231
- if (code === undefined || code === null) {
232
- console.log('Debugging uninitialized accounts is unsupported in debugger beta');
233
- return await this.runCommon(() => this.blockchain.executor.runTransaction(args));
234
- }
235
- const sm = DebugInfoCache_1.defaultDebugInfoCache.get(code.hash().toString('base64'));
236
- if (sm === undefined) {
237
- return await this.runCommon(() => this.blockchain.executor.runTransaction(args));
238
- }
239
- return await this.runCommon(() => (0, debug_1.debugTransaction)(this.blockchain.executor, args, code, sm));
240
- }
241
- else {
242
- return await this.runCommon(() => this.blockchain.executor.runTransaction(args));
243
- }
216
+ }));
244
217
  }
245
218
  async runTickTock(which, params) {
246
219
  return await this.runCommon(() => this.blockchain.executor.runTickTock({
@@ -277,7 +250,7 @@ class SmartContract {
277
250
  if (this.account.account?.storage.state.type !== 'active') {
278
251
  throw new Error('Trying to run get method on non-active contract');
279
252
  }
280
- const args = {
253
+ const res = await this.blockchain.executor.runGetMethod({
281
254
  code: this.account.account?.storage.state.state.code,
282
255
  data: this.account.account?.storage.state.state.data,
283
256
  methodId: typeof method === 'string' ? (0, selector_1.getSelectorForMethod)(method) : method,
@@ -291,20 +264,7 @@ class SmartContract {
291
264
  randomSeed: params?.randomSeed ?? Buffer.alloc(32),
292
265
  gasLimit: params?.gasLimit ?? 10000000n,
293
266
  debugEnabled: this.verbosity.debugLogs,
294
- };
295
- let res;
296
- if (this.debug) {
297
- const di = DebugInfoCache_1.defaultDebugInfoCache.get(args.code.hash().toString('base64'));
298
- if (di === undefined) {
299
- res = await this.blockchain.executor.runGetMethod(args);
300
- }
301
- else {
302
- res = await (0, debug_1.debugGetMethod)(this.blockchain.executor, args, di);
303
- }
304
- }
305
- else {
306
- res = await this.blockchain.executor.runGetMethod(args);
307
- }
267
+ });
308
268
  if (this.verbosity.print && this.verbosity.blockchainLogs && res.logs.length > 0) {
309
269
  console.log(res.logs);
310
270
  }
@@ -352,12 +312,6 @@ class SmartContract {
352
312
  __classPrivateFieldSet(this, _SmartContract_verbosity, verbosity, "f");
353
313
  }
354
314
  }
355
- get debug() {
356
- return __classPrivateFieldGet(this, _SmartContract_debug, "f") ?? this.blockchain.debug;
357
- }
358
- setDebug(debug) {
359
- __classPrivateFieldSet(this, _SmartContract_debug, debug, "f");
360
- }
361
315
  }
362
316
  exports.SmartContract = SmartContract;
363
- _SmartContract_account = new WeakMap(), _SmartContract_parsedAccount = new WeakMap(), _SmartContract_lastTxTime = new WeakMap(), _SmartContract_verbosity = new WeakMap(), _SmartContract_debug = new WeakMap();
317
+ _SmartContract_account = new WeakMap(), _SmartContract_parsedAccount = new WeakMap(), _SmartContract_lastTxTime = new WeakMap(), _SmartContract_verbosity = new WeakMap();
@@ -82,9 +82,7 @@ export declare class Executor implements IExecutor {
82
82
  private heap;
83
83
  private emulator?;
84
84
  private debugLogs;
85
- debugLogFunc: (s: string) => void;
86
85
  private constructor();
87
- private handleLog;
88
86
  static create(): Promise<Executor>;
89
87
  runGetMethod(args: GetMethodArgs): Promise<GetMethodResult>;
90
88
  private runCommon;
@@ -94,27 +92,4 @@ export declare class Executor implements IExecutor {
94
92
  private getEmulatorPointer;
95
93
  invoke(method: string, args: (number | string)[]): number;
96
94
  private extractString;
97
- sbsGetMethodSetup(args: GetMethodArgs): number;
98
- destroyTvmEmulator(ptr: number): void;
99
- sbsGetMethodStep(ptr: number): boolean;
100
- sbsGetMethodStack(ptr: number): TupleItem[];
101
- sbsGetMethodC7(ptr: number): TupleItem;
102
- sbsGetMethodCodePos(ptr: number): {
103
- hash: string;
104
- offset: number;
105
- };
106
- sbsGetMethodResult(ptr: number): GetMethodResult;
107
- sbsTransactionSetup(args: RunTransactionArgs): {
108
- res: number;
109
- emptr: number;
110
- };
111
- destroyEmulator(ptr: number): void;
112
- sbsTransactionStep(ptr: number): boolean;
113
- sbsTransactionCodePos(ptr: number): {
114
- hash: string;
115
- offset: number;
116
- };
117
- sbsTransactionStack(ptr: number): TupleItem[];
118
- sbsTransactionC7(ptr: number): TupleItem;
119
- sbsTransactionResult(ptr: number): EmulationResult;
120
95
  }
@@ -69,18 +69,13 @@ class Heap {
69
69
  class Executor {
70
70
  constructor(module) {
71
71
  this.debugLogs = [];
72
- this.debugLogFunc = () => { };
73
72
  this.module = module;
74
73
  this.heap = new Heap(module);
75
74
  }
76
- handleLog(text) {
77
- this.debugLogs.push(text);
78
- this.debugLogFunc(text);
79
- }
80
75
  static async create() {
81
76
  const ex = new Executor(await EmulatorModule({
82
77
  wasmBinary: (0, base64_1.base64Decode)(require('./emulator-emscripten.wasm.js').EmulatorEmscriptenWasm),
83
- printErr: (text) => ex.handleLog(text),
78
+ printErr: (text) => ex.debugLogs.push(text),
84
79
  }));
85
80
  return ex;
86
81
  }
@@ -209,137 +204,5 @@ class Executor {
209
204
  this.module._free(ptr);
210
205
  return str;
211
206
  }
212
- sbsGetMethodSetup(args) {
213
- const params = {
214
- code: args.code.toBoc().toString('base64'),
215
- data: args.data.toBoc().toString('base64'),
216
- verbosity: verbosityToNum[args.verbosity],
217
- libs: args.libs?.toBoc().toString('base64') ?? '',
218
- address: args.address.toString(),
219
- unixtime: args.unixTime,
220
- balance: args.balance.toString(),
221
- rand_seed: args.randomSeed.toString('hex'),
222
- gas_limit: args.gasLimit.toString(),
223
- method_id: args.methodId,
224
- debug_enabled: args.debugEnabled,
225
- };
226
- let stack = (0, core_1.serializeTuple)(args.stack);
227
- this.debugLogs = [];
228
- const res = this.invoke('_setup_sbs_get_method', [
229
- JSON.stringify(params),
230
- stack.toBoc().toString('base64'),
231
- args.config,
232
- ]);
233
- return res;
234
- }
235
- destroyTvmEmulator(ptr) {
236
- this.invoke('_destroy_tvm_emulator', [ptr]);
237
- }
238
- sbsGetMethodStep(ptr) {
239
- const res = this.invoke('_sbs_step', [
240
- ptr,
241
- ]);
242
- return res !== 0;
243
- }
244
- sbsGetMethodStack(ptr) {
245
- const resp = this.extractString(this.invoke('_sbs_get_stack', [
246
- ptr
247
- ]));
248
- return (0, core_1.parseTuple)(core_1.Cell.fromBase64(resp));
249
- }
250
- sbsGetMethodC7(ptr) {
251
- const resp = this.extractString(this.invoke('_sbs_get_c7', [
252
- ptr
253
- ]));
254
- return (0, core_1.parseTuple)((0, core_1.beginCell)().storeUint(1, 24).storeRef(core_1.Cell.EMPTY).storeSlice(core_1.Cell.fromBase64(resp).beginParse()).endCell())[0];
255
- }
256
- sbsGetMethodCodePos(ptr) {
257
- const resp = this.extractString(this.invoke('_sbs_get_code_pos', [
258
- ptr
259
- ]));
260
- const parts = resp.split(':');
261
- return {
262
- hash: parts[0],
263
- offset: parseInt(parts[1]),
264
- };
265
- }
266
- sbsGetMethodResult(ptr) {
267
- const resp = JSON.parse(this.extractString(this.invoke('_sbs_get_method_result', [
268
- ptr
269
- ])));
270
- const debugLogs = this.debugLogs.join('\n');
271
- return {
272
- output: resp,
273
- logs: 'BLOCKCHAIN LOGS ARE NOT AVAILABLE IN DEBUGGER BETA',
274
- debugLogs,
275
- };
276
- }
277
- sbsTransactionSetup(args) {
278
- const emptr = this.invoke('_create_emulator', [
279
- args.config,
280
- verbosityToNum[args.verbosity],
281
- ]);
282
- const params = runCommonArgsToInternalParams(args);
283
- this.debugLogs = [];
284
- const res = this.invoke('_emulate_sbs', [
285
- emptr,
286
- args.libs?.toBoc().toString('base64') ?? 0,
287
- args.shardAccount,
288
- args.message.toBoc().toString('base64'),
289
- JSON.stringify(params),
290
- ]);
291
- return { res, emptr };
292
- }
293
- destroyEmulator(ptr) {
294
- this.invoke('_destroy_emulator', [ptr]);
295
- }
296
- sbsTransactionStep(ptr) {
297
- const res = this.invoke('_em_sbs_step', [ptr]);
298
- return res !== 0;
299
- }
300
- sbsTransactionCodePos(ptr) {
301
- const resp = this.extractString(this.invoke('_em_sbs_code_pos', [ptr]));
302
- const parts = resp.split(':');
303
- return {
304
- hash: parts[0],
305
- offset: parseInt(parts[1]),
306
- };
307
- }
308
- sbsTransactionStack(ptr) {
309
- const resp = this.extractString(this.invoke('_em_sbs_stack', [
310
- ptr
311
- ]));
312
- return (0, core_1.parseTuple)(core_1.Cell.fromBase64(resp));
313
- }
314
- sbsTransactionC7(ptr) {
315
- const resp = this.extractString(this.invoke('_em_sbs_c7', [
316
- ptr
317
- ]));
318
- return (0, core_1.parseTuple)((0, core_1.beginCell)().storeUint(1, 24).storeRef(core_1.Cell.EMPTY).storeSlice(core_1.Cell.fromBase64(resp).beginParse()).endCell())[0];
319
- }
320
- sbsTransactionResult(ptr) {
321
- const result = JSON.parse(this.extractString(this.invoke('_em_sbs_result', [
322
- ptr
323
- ])));
324
- const debugLogs = this.debugLogs.join('\n');
325
- return {
326
- result: result.success ? {
327
- success: true,
328
- transaction: result.transaction,
329
- shardAccount: result.shard_account,
330
- vmLog: result.vm_log,
331
- actions: result.actions,
332
- } : {
333
- success: false,
334
- error: result.error,
335
- vmResults: 'vm_log' in result ? {
336
- vmLog: result.vm_log,
337
- vmExitCode: result.vm_exit_code,
338
- } : undefined,
339
- },
340
- logs: 'BLOCKCHAIN LOGS ARE NOT AVAILABLE IN DEBUGGER BETA',
341
- debugLogs,
342
- };
343
- }
344
207
  }
345
208
  exports.Executor = Executor;