py-scale-codec icon indicating copy to clipboard operation
py-scale-codec copied to clipboard

0-length FixedLengthArray of U8 decodes to []

Open kkowalski-reef opened this issue 1 month ago • 3 comments

https://github.com/JAMdotTech/py-scale-codec/blob/ee3ab0c987a97102d98761c793e0e8287f1e1ccc/scalecodec/types.py#L1925-L1938

All other U8 lengths decode to 0x...

Getting an array out of this is very surprising if not outright incorrect

kkowalski-reef avatar Dec 10 '25 00:12 kkowalski-reef

can i try this?? @kkowalski-reef

PushkarOnGithub avatar Dec 11 '25 11:12 PushkarOnGithub

Yeah, sorry, here's a minimal repro:

from scalecodec.base import RuntimeConfigurationObject, ScaleBytes

conf = RuntimeConfigurationObject()

b32_0 = conf.create_scale_object("[u8; 0]", data=ScaleBytes(b""))
print(b32_0.decode())  # []

b32_8 = conf.create_scale_object("[u8; 8]", data=ScaleBytes(b"\x01\x02\x03\x04\x05\x06\x07\x08"))
print(b32_8.decode())  # "0x0102030405060708"

The problem is that self.element_count == 0 immediately returns a []

kkowalski-reef avatar Dec 19 '25 21:12 kkowalski-reef

To be clear I'm on 1.2.11, .12 doesn't seem to be addressing this and v2 is apparently in alpha state so I haven't tested that.

kkowalski-reef avatar Dec 19 '25 21:12 kkowalski-reef