-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow large (>256 bits) keys in VmDict (lookup, set, etc.)
- Loading branch information
Showing
4 changed files
with
247 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.