ton-org / ton-core

Low level tools for working with TON
MIT License
57 stars 25 forks source link

fix: builder.writeInt(0, 1); // value is not zero or -1 for 1 bits. Got 0 #48

Open stels-cs opened 3 weeks ago

stels-cs commented 3 weeks ago

This code will throw an error, but should work

let builder = new BitBuilder();
builder.writeInt(0, 1); // value is not zero or -1 for 1 bits. Got 0

The error occurs because the variable value is checked on line 155 instead of v from line 148. value can be a number or a BigInt, so comparing it with BigInt constants will not work.

https://github.com/ton-org/ton-core/blob/00fa47e03c2a78c6dd9d09e517839685960bc2fd/src/boc/BitBuilder.ts#L147-L160

Same problem with

builder.writeInt(0, 0);
builder.writeInt(-1, 1);