1

Tests are throwing a to_value error in the scenario when trying to unpack a record that contains a key with a bounded type TNat inside the entrypoint being called.

There's a minimal reproduction below, and a link to the SmartPy IDE at the bottom.

Example Contract:

import smartpy as sp

test_type = sp.TRecord(
    num=sp.TNat,
    select=sp.TBounded([1, 2, 3, 4, 5], sp.TNat),
)

class PackUnpackBoundedTypes(sp.Contract):
    def __init__(self):
        self.init(
            rec = sp.pack(
                sp.record(
                    num=sp.nat(2),
                    select=sp.bounded(5)
                )
            ),
            done = sp.record(
                num=sp.nat(1),
                select=sp.bounded(1)
            )
        )
        
    @sp.entry_point()
    def get_unpacked_info(self):
        res = sp.unpack(self.data.rec, test_type).open_some()
        self.data.done = res

Contract Tests:

@sp.add_test(name = "PackUnpackBoundedTypes")
def test():
    scenario = sp.test_scenario()
    scenario.h1("PackUnpackBoundedTypes")
    alice = sp.test_account('alice')
    
    c = PackUnpackBoundedTypes()
    scenario += c

    c.get_unpacked_info().run(sender=alice)

Failure:

Error: Error in Scenario
Unexpected error in transaction, please use .run(valid=False, ..)
Failure: to_value sp.TBounded([1, 2, 3, 4, 5], t=sp.TNat) 5;
get_unpacked_info

SmartyPy IDE Link

Is it not possible to pack/unpack bounded types?

1 Answer 1

2

It is unsafe without a dynamic check. We need to determine what the most natural and/or appropriate decision is (very possibly: continue forbidding it).

1
  • can the docs please be updated with details on what types are packable/unpackable, maybe a warning on each type page, as well as an overview table on the pack/unpack part of the documentation
    – 0x10
    Jun 19 at 2:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.