toncenter / tvm_valuetypes

Collection of utils for handling The Open Network Virtual Machine value types
Other
9 stars 10 forks source link

CellData.put_arbitrary_int is broken #17

Open gromgull opened 3 months ago

gromgull commented 3 months ago
        if _int < 0:
            self.put_bool(1)
            s = 2 ** (bitsize - 1)
            self.put_arbitrary_uint(s - _int, bitsize - 1)
        else:
            self.put_bool(0)
            self.put_arbitrary_uint(_int, bitsize - 1)

The s - _int must be s + _int (since _int is negative)

otherwise you get a Exception: Not enough bits (1) to encode integer (3) error

Try:

from tvm_valuetypes.cell import Cell
c = Cell()
c.data.put_arbitrary_int(-1, 2)