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
Is it not possible to pack/unpack bounded types?