Skip to content

Commit

Permalink
Allow large (>256 bits) keys in VmDict (lookup, set, etc.)
Browse files Browse the repository at this point in the history
  • Loading branch information
tvorogme committed May 22, 2024
1 parent 9122918 commit a6b2722
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 45 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/wheels-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ jobs:
file: python_ton.cpython-39-x86_64-linux-gnu.so
fix_tag: manylinux2014_x86_64

- arch: aarch64
os: macOS
python: "3.10"
link: https://github.com/disintar/ton/releases/download/ton-cpython-310-aarch64-darwin/
file: python_ton.cpython-310-darwin.so
fix_tag: arm64

runs-on: ${{ matrix.os }}

steps:
Expand Down
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
## xxx
## v2

- Smart-contract address class added
- Mnemonic / (ED25519) PublicKey / (ED25519) PrivateKey classes added
- Merge testnet on commit:
- Allow disassemble libs (root cell & PUSREF*)
- Allow large (>256 bits) keys in VmDict (lookup, set, etc.)
- Add LiteClient
- Add RoundRobin strategy for LiteClient
- Update C7 to "TVM Upgrade 2023.07", add BlockId & BlockIdExt
Expand All @@ -13,7 +14,7 @@
- Allow VmDict initialization from PyDict
- Add `combine_with` in VmDict to fast combine dictionaries
- Critical change: TLB dump - forced `dump_bin_as_hex` to true. This means if bitsting is `x % 8 == 0` then it'll be
dumped as hex (this is most of cases)
dumped as hex (this is most of use-cases)
- Critical change: Run method in TVM will throw error on unsuccessful exit code
- Fix: emulator, account none several transaction emulation
- Fix: C7 helper
Expand Down
89 changes: 89 additions & 0 deletions src/tonpy/tests/test_vmdict_large_keys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Copyright (c) 2023 Disintar LLP Licensed under the Apache License Version 2.0

from pathlib import Path
import sys
from random import random
from time import time

import pytest

path_root = Path(__file__).parents[2]
sys.path.append(str(path_root))

from tonpy.types.vmdict import VmDict
from tonpy.types.cellbuilder import CellBuilder, CellSlice, Cell
from tonpy.data_for_tests.dict_test_boc import config_44, reveal_dict_boc


def test_set_get_keycs_direct():
d = VmDict(264)

v1 = CellBuilder().store_uint(0, 8).store_uint(2 ** 254, 256).end_cell().begin_parse()
d.set_keycs(CellBuilder().store_uint(0, 8).store_uint(2 ** 254, 256).end_cell().begin_parse(), v1)

v2 = CellBuilder().store_uint(0, 8).store_uint(2 ** 254, 256).end_cell()
d.set_ref_keycs(CellBuilder().store_uint(1, 8).store_uint(2 ** 254, 256).end_cell().begin_parse(), v2)

d.set_builder_keycs(CellBuilder().store_uint(2, 8).store_uint(2 ** 254, 256).end_cell().begin_parse(),
CellBuilder().store_uint(0, 8))

value = d.lookup_keycs(CellBuilder().store_uint(0, 8).store_uint(2 ** 254, 256).end_cell().begin_parse())
assert value.get_hash() == v1.get_hash()

value = d.lookup_delete_keycs(CellBuilder().store_uint(0, 8).store_uint(2 ** 254, 256).end_cell().begin_parse())
assert value.get_hash() == v1.get_hash()

try:
d.lookup_keycs(CellBuilder().store_uint(0, 8).store_uint(2 ** 254, 256).end_cell().begin_parse())
assert False
except RuntimeError:
pass

value = d.lookup_ref_keycs(CellBuilder().store_uint(1, 8).store_uint(2 ** 254, 256).end_cell().begin_parse())
assert value.get_hash() == v2.get_hash()

value = d.lookup_delete_ref_keycs(CellBuilder().store_uint(1, 8).store_uint(2 ** 254, 256).end_cell().begin_parse())
assert value.get_hash() == v2.get_hash()

try:
value = d.lookup_ref_keycs(CellBuilder().store_uint(1, 8).store_uint(2 ** 254, 256).end_cell().begin_parse())
assert False
except RuntimeError:
pass


def test_set_get_keycs_direct():
d = VmDict(264)

v1 = CellBuilder().store_uint(0, 8).store_uint(2 ** 254, 256).end_cell().begin_parse()
d.set(CellBuilder().store_uint(0, 8).store_uint(2 ** 254, 256).end_cell().begin_parse(), v1)

v2 = CellBuilder().store_uint(0, 8).store_uint(2 ** 254, 256).end_cell()
d.set_ref(CellBuilder().store_uint(1, 8).store_uint(2 ** 254, 256).end_cell().begin_parse(), v2)

d.set_builder(CellBuilder().store_uint(2, 8).store_uint(2 ** 254, 256).end_cell().begin_parse(),
CellBuilder().store_uint(0, 8))

value = d.lookup(CellBuilder().store_uint(0, 8).store_uint(2 ** 254, 256).end_cell().begin_parse())
assert value.get_hash() == v1.get_hash()

value = d.lookup_delete(CellBuilder().store_uint(0, 8).store_uint(2 ** 254, 256).end_cell().begin_parse())
assert value.get_hash() == v1.get_hash()

try:
d.lookup(CellBuilder().store_uint(0, 8).store_uint(2 ** 254, 256).end_cell().begin_parse())
assert False
except RuntimeError:
pass

value = d.lookup_ref(CellBuilder().store_uint(1, 8).store_uint(2 ** 254, 256).end_cell().begin_parse())
assert value.get_hash() == v2.get_hash()

value = d.lookup_delete_ref(CellBuilder().store_uint(1, 8).store_uint(2 ** 254, 256).end_cell().begin_parse())
assert value.get_hash() == v2.get_hash()

try:
value = d.lookup_ref(CellBuilder().store_uint(1, 8).store_uint(2 ** 254, 256).end_cell().begin_parse())
assert False
except RuntimeError:
pass
Loading

0 comments on commit a6b2722

Please sign in to comment.