Skip to content

Constructing struct from minimum possible bytes value #45

@boblat

Description

@boblat

Subject of the issue

Given a struct such as

class FixedArrayUInt64(Struct):
    length: arc4.UInt16
    arr: arc4.StaticArray[arc4.UInt64, typing.Literal[4095]]

when constructing it using from_bytes method with a value that cannot be decoded as that type e.g.

foo = FixedArrayUInt64.from_bytes(b"\x00\x00")

This results immediately in a ValueError, where as in a compiled AVM program this would not error until an operation was performed on that value that would be outside the valid bounds of the underlying bytes e.g.

assert foo.length == 0, "this passes in AVM compiled code"
assert foo.arr[0] == 0, "this would error in AVM compiled code"

Expected behaviour

An error should only be thrown when accessing data beyond the underlying bytes

Actual behaviour

ValueError with error message input string is not long enough to be decoded is thrown in the algopy testing implementation

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions