Skip to content

Commit 7133d7e

Browse files
committed
Update tonpy version, allow to boc dump
1 parent c7a78e9 commit 7133d7e

6 files changed

Lines changed: 26 additions & 14 deletions

File tree

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tonpy==0.0.0.1.4a0
1+
tonpy==0.0.0.1.4b0
22
deepdiff
33
cytoolz
44
requests

src/tonemuso/diff.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ def make_json_dumpable(obj):
3030
return str(obj)
3131

3232

33-
def convert_any_to_hash(x):
33+
def convert_any_to_hash(x, to_boc=False):
3434
for i in x:
3535
if isinstance(x[i], dict):
36-
updated = convert_any_to_hash(x[i])
36+
updated = convert_any_to_hash(x[i], to_boc=to_boc)
3737
x[i] = updated
3838
elif isinstance(x[i], (Cell, CellSlice, CellBuilder)):
39-
x[i] = x[i].get_hash()
39+
if to_boc:
40+
x[i] = x[i].to_boc()
41+
else:
42+
x[i] = x[i].get_hash()
4043

4144
return x
4245

@@ -57,15 +60,15 @@ def get_path(self):
5760
return self.path
5861

5962

60-
def get_diff(tx1, tx2):
63+
def get_diff(tx1, tx2, to_boc: bool = False):
6164
tx1_tlb = Transaction()
6265
tx1_tlb = tx1_tlb.cell_unpack(tx1, True).dump()
6366

6467
tx2_tlb = Transaction()
6568
tx2_tlb = tx2_tlb.cell_unpack(tx2, True).dump()
6669

67-
diff = DeepDiff(convert_any_to_hash(tx1_tlb),
68-
convert_any_to_hash(tx2_tlb))
70+
diff = DeepDiff(convert_any_to_hash(tx1_tlb, to_boc=to_boc),
71+
convert_any_to_hash(tx2_tlb, to_boc=to_boc))
6972

7073
address = tx1_tlb['account_addr']
7174
del tx1_tlb

src/tonemuso/emitted_processor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def _emulate_buffer_txs(self, block_key: BlockKey, txs: List[TxRecord], account_
5050
# Run stepper (no out msgs extraction) using current state
5151
step_b = TxStepEmulator(block=self.r.blocks[block_key], loglevel=self.r.loglevel,
5252
color_schema=self.r.color_schema, em=em, account_state_em1=st, em2=em2,
53-
account_state_em2=st)
53+
account_state_em2=st, use_boc_for_diff=self.r.use_boc_for_diff)
5454
_out_b, new_st1, _new_st2, _ = step_b.emulate(bt, extract_out_msgs=False)
5555
st = new_st1
5656
cnt += 1
@@ -232,7 +232,7 @@ def process_emitted_children_with_override(self,
232232
# Emulate with override message via unified stepper (always compare/color)
233233
step_gc = TxStepEmulator(block=self.r.blocks[gc_block_key], loglevel=self.r.loglevel,
234234
color_schema=self.r.color_schema, em=emu, account_state_em1=gc_state,
235-
em2=emu2, account_state_em2=gc_state)
235+
em2=emu2, account_state_em2=gc_state, use_boc_for_diff=self.r.use_boc_for_diff)
236236
tmp_out3, new_state_gc, _ns, gc_out_msgs = step_gc.emulate(
237237
gc_tx,
238238
override_in_msg=cand.emu_msg.cell,

src/tonemuso/emulation.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ def __init__(self,
111111
em: EmulatorExtern,
112112
account_state_em1: Cell,
113113
em2: EmulatorExtern,
114-
account_state_em2: Cell) -> None:
114+
account_state_em2: Cell,
115+
use_boc_for_diff: bool = False) -> None:
115116
self.block = block
116117
self.loglevel = loglevel
117118
self.color_schema = color_schema
@@ -120,6 +121,8 @@ def __init__(self,
120121
self.em2: EmulatorExtern = em2
121122
self.state1: Cell = account_state_em1
122123
self.state2: Cell = account_state_em2
124+
# Diff behavior flag: when True, compare BOCs instead of hashes
125+
self.use_boc_for_diff: bool = bool(use_boc_for_diff)
123126

124127
# ---- Small helpers to keep emulate() readable ----
125128
def _prepare_in_msg(self, tx: Dict[str, Any], override_in_msg: Optional[Cell]) -> Tuple[
@@ -178,7 +181,7 @@ def _compare_and_color(self, tx: Dict[str, Any]) -> Tuple[bool, List[Dict[str, A
178181
return go_as_success, out
179182

180183
if self.em.transaction.get_hash() != tx['tx'].get_hash():
181-
diff, address = get_diff(tx['tx'], self.em.transaction.to_cell())
184+
diff, address = get_diff(tx['tx'], self.em.transaction.to_cell(), to_boc=self.use_boc_for_diff)
182185

183186
unchanged_emulator_tx_hash = self.em2.transaction.get_hash()
184187
sa_diff = get_shard_account_diff(self.em2.account.to_cell(), self.em.account.to_cell())

src/tonemuso/modes/single_trace.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ def run(cfg: Config):
198198
toncenter_trace=trace,
199199
lcparams=lcparams,
200200
emulator_path=cfg.emulator_path,
201-
emulator_unchanged_path=cfg.emulator_unchanged_path)
201+
emulator_unchanged_path=cfg.emulator_unchanged_path,
202+
use_boc_for_diff=True)
202203
runner.run(TX_ORDER_LIST or [])
203204

204205
# Pretty print the emulated tree with emulation_order annotations

src/tonemuso/trace_runner.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ def __init__(self,
4848
preindexed: Optional[Dict[str, Any]] = None,
4949
emulator_path: Optional[str] = None,
5050
emulator_unchanged_path: Optional[str] = None,
51-
toncenter_trace: "TonTrace" = None):
51+
toncenter_trace: "TonTrace" = None,
52+
use_boc_for_diff: bool = False):
5253
# Indices and caches
5354
self.tx_index: Dict[TxHashHex, Tuple[BlockKey, Dict[str, Any]]] = OrderedDict()
5455
self.blocks: Dict[BlockKey, Dict[str, Any]] = OrderedDict()
@@ -68,6 +69,9 @@ def __init__(self,
6869
self.emulator_path = emulator_path
6970
self.emulator_unchanged_path = emulator_unchanged_path
7071

72+
# Diff behavior flag for transaction comparison
73+
self.use_boc_for_diff: bool = bool(use_boc_for_diff)
74+
7175
# Results and global state overrides
7276
self.failed_traces: List[Dict[str, Any]] = []
7377
self.global_overrides: Dict[Address, Cell] = OrderedDict()
@@ -325,7 +329,8 @@ def _process_tx(self, transaction_hash: TxHashHex,
325329

326330
# Emulate root tx via unified stepper
327331
step = TxStepEmulator(block=self.blocks[block_key], loglevel=self.loglevel, color_schema=self.color_schema,
328-
em=em, account_state_em1=state1, em2=em2, account_state_em2=state1)
332+
em=em, account_state_em1=state1, em2=em2, account_state_em2=state1,
333+
use_boc_for_diff=self.use_boc_for_diff)
329334
tmp_out, new_state1, _new_state2, out_msgs = step.emulate(
330335
tx,
331336
extract_out_msgs=True

0 commit comments

Comments
 (0)