@ton/sandbox 0.21.0 → 0.22.0-ecbeta.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 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.22.0] - 2024-09-17
9
+
10
+ ### Added
11
+
12
+ - Added `blockchain.recordStorage` flag. If set to `true`, `BlockchainTransaction` will have `oldStorage` and `newStorage` fields. Note that enabling this flag will disable a certain optimization, which will slow down contract emulation
13
+
8
14
  ## [0.21.0] - 2024-09-16
9
15
 
10
16
  ### Added
@@ -26,6 +26,8 @@ export type BlockchainTransaction = Transaction & {
26
26
  parent?: BlockchainTransaction;
27
27
  children: BlockchainTransaction[];
28
28
  externals: ExternalOut[];
29
+ oldStorage?: Cell;
30
+ newStorage?: Cell;
29
31
  };
30
32
  /**
31
33
  * @type SendMessageResult Represents the result of sending a message.
@@ -98,6 +100,7 @@ export declare class Blockchain {
98
100
  protected lock: AsyncLock;
99
101
  protected contractFetches: Map<string, Promise<SmartContract>>;
100
102
  protected nextCreateWalletIndex: number;
103
+ protected shouldRecordStorage: boolean;
101
104
  readonly executor: IExecutor;
102
105
  /**
103
106
  * Saves snapshot of current blockchain.
@@ -115,6 +118,8 @@ export declare class Blockchain {
115
118
  * @param snapshot Snapshot of blockchain
116
119
  */
117
120
  loadFrom(snapshot: BlockchainSnapshot): Promise<void>;
121
+ get recordStorage(): boolean;
122
+ set recordStorage(v: boolean);
118
123
  /**
119
124
  * @returns Current time in blockchain
120
125
  */
@@ -81,6 +81,12 @@ class Blockchain {
81
81
  this.globalLibs = snapshot.libs;
82
82
  this.nextCreateWalletIndex = snapshot.nextCreateWalletIndex;
83
83
  }
84
+ get recordStorage() {
85
+ return this.shouldRecordStorage;
86
+ }
87
+ set recordStorage(v) {
88
+ this.shouldRecordStorage = v;
89
+ }
84
90
  /**
85
91
  * @returns Current time in blockchain
86
92
  */
@@ -112,6 +118,7 @@ class Blockchain {
112
118
  this.lock = new AsyncLock_1.AsyncLock();
113
119
  this.contractFetches = new Map();
114
120
  this.nextCreateWalletIndex = 0;
121
+ this.shouldRecordStorage = false;
115
122
  this.networkConfig = blockchainConfigToBase64(opts.config);
116
123
  this.executor = opts.executor;
117
124
  this.storage = opts.storage;
@@ -21,6 +21,8 @@ export type SmartContractTransaction = Transaction & {
21
21
  blockchainLogs: string;
22
22
  vmLogs: string;
23
23
  debugLogs: string;
24
+ oldStorage?: Cell;
25
+ newStorage?: Cell;
24
26
  };
25
27
  export type MessageParams = Partial<{
26
28
  now: number;
@@ -69,6 +71,9 @@ export type SmartContractSnapshot = {
69
71
  lastTxTime: number;
70
72
  verbosity?: Partial<LogsVerbosity>;
71
73
  };
74
+ export type ExtraCurrency = {
75
+ [key: number]: bigint;
76
+ };
72
77
  export declare class SmartContract {
73
78
  #private;
74
79
  readonly address: Address;
@@ -76,6 +81,8 @@ export declare class SmartContract {
76
81
  constructor(shardAccount: ShardAccount, blockchain: Blockchain);
77
82
  snapshot(): SmartContractSnapshot;
78
83
  loadFrom(snapshot: SmartContractSnapshot): void;
84
+ get ec(): ExtraCurrency;
85
+ set ec(nv: ExtraCurrency);
79
86
  get balance(): bigint;
80
87
  set balance(v: bigint);
81
88
  get lastTransactionHash(): bigint;
@@ -122,6 +122,13 @@ class EmulationError extends Error {
122
122
  }
123
123
  }
124
124
  exports.EmulationError = EmulationError;
125
+ function extractEc(cc) {
126
+ const r = {};
127
+ for (const [k, v] of cc) {
128
+ r[k] = v;
129
+ }
130
+ return r;
131
+ }
125
132
  class SmartContract {
126
133
  constructor(shardAccount, blockchain) {
127
134
  _SmartContract_account.set(this, void 0);
@@ -150,6 +157,21 @@ class SmartContract {
150
157
  __classPrivateFieldSet(this, _SmartContract_lastTxTime, snapshot.lastTxTime, "f");
151
158
  __classPrivateFieldSet(this, _SmartContract_verbosity, snapshot.verbosity === undefined ? undefined : { ...snapshot.verbosity }, "f");
152
159
  }
160
+ get ec() {
161
+ return extractEc(this.account.account?.storage.balance.other ?? core_1.Dictionary.empty(core_1.Dictionary.Keys.Uint(32), core_1.Dictionary.Values.BigVarUint(5)));
162
+ }
163
+ set ec(nv) {
164
+ const cc = core_1.Dictionary.empty(core_1.Dictionary.Keys.Uint(32), core_1.Dictionary.Values.BigVarUint(5));
165
+ for (const [k, v] of Object.entries(nv)) {
166
+ cc.set(Number(k), v);
167
+ }
168
+ const acc = this.account;
169
+ if (acc.account === undefined) {
170
+ acc.account = createEmptyAccount(this.address);
171
+ }
172
+ acc.account.storage.balance.other = cc;
173
+ this.account = acc;
174
+ }
153
175
  get balance() {
154
176
  return this.account.account?.storage.balance.coins ?? 0n;
155
177
  }
@@ -222,6 +244,10 @@ class SmartContract {
222
244
  }));
223
245
  }
224
246
  async runCommon(run) {
247
+ let oldStorage = undefined;
248
+ if (this.blockchain.recordStorage && this.account.account?.storage.state.type === 'active') {
249
+ oldStorage = this.account.account?.storage.state.state.data ?? undefined;
250
+ }
225
251
  const res = await run();
226
252
  if (this.verbosity.print && this.verbosity.blockchainLogs && res.logs.length > 0) {
227
253
  console.log(res.logs);
@@ -239,11 +265,17 @@ class SmartContract {
239
265
  __classPrivateFieldSet(this, _SmartContract_account, res.result.shardAccount, "f");
240
266
  __classPrivateFieldSet(this, _SmartContract_parsedAccount, undefined, "f");
241
267
  __classPrivateFieldSet(this, _SmartContract_lastTxTime, tx.now, "f");
268
+ let newStorage = undefined;
269
+ if (this.blockchain.recordStorage && this.account.account?.storage.state.type === 'active') {
270
+ newStorage = this.account.account?.storage.state.state.data ?? undefined;
271
+ }
242
272
  return {
243
273
  ...tx,
244
274
  blockchainLogs: res.logs,
245
275
  vmLogs: res.result.vmLog,
246
276
  debugLogs: res.debugLogs,
277
+ oldStorage,
278
+ newStorage,
247
279
  };
248
280
  }
249
281
  async get(method, stack = [], params) {
@@ -1,4 +1,4 @@
1
- import { Address, Cell, Message, StateInit } from "@ton/core";
1
+ import { Address, Cell, Dictionary, Message, StateInit } from "@ton/core";
2
2
  /**
3
3
  * Creates {@link Message} from params.
4
4
  */
@@ -15,4 +15,5 @@ export declare function internal(params: {
15
15
  forwardFee?: bigint;
16
16
  createdAt?: number;
17
17
  createdLt?: bigint;
18
+ ec?: Dictionary<number, bigint> | [number, bigint][];
18
19
  }): Message;
@@ -6,12 +6,24 @@ const core_1 = require("@ton/core");
6
6
  * Creates {@link Message} from params.
7
7
  */
8
8
  function internal(params) {
9
+ let ecd = undefined;
10
+ if (params.ec !== undefined) {
11
+ if (Array.isArray(params.ec)) {
12
+ ecd = core_1.Dictionary.empty(core_1.Dictionary.Keys.Uint(32), core_1.Dictionary.Values.BigVarUint(5));
13
+ for (const [k, v] of params.ec) {
14
+ ecd.set(k, v);
15
+ }
16
+ }
17
+ else {
18
+ ecd = params.ec;
19
+ }
20
+ }
9
21
  return {
10
22
  info: {
11
23
  type: 'internal',
12
24
  dest: params.to,
13
25
  src: params.from,
14
- value: { coins: params.value },
26
+ value: { coins: params.value, other: ecd },
15
27
  bounce: params.bounce ?? true,
16
28
  ihrDisabled: params.ihrDisabled ?? true,
17
29
  bounced: params.bounced ?? false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ton/sandbox",
3
- "version": "0.21.0",
3
+ "version": "0.22.0-ecbeta.1",
4
4
  "description": "TON transaction emulator",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",