How do you catch parameter type exceptions in SmartPy tests?
There's an example of exception testing in: https://smartpy.io/docs/scenarios/testing
An example from docs
# Assert exception result # catch_exception returns an option: # sp.none if the call succeeds # sp.some(<exception>) if the call fails e = sp.catch_exception(c1.state(7), t = sp.TString) scenario.verify(e == sp.some("This is false: param > 5"))
I can't seem to get it to work with
sp.nat type errors. I'm not sure what the
t= value should be, if I'm even using it correctly at all.
import smartpy as sp class Summarise(sp.Contract): def __init__(self): self.init(storage=sp.nat(0)) @sp.entry_point(name='sum') def sum(self, x): sp.verify((x >= 5) & (x <= 100), "Not in range 5–100") with sp.for_("i", sp.range(1, x + 1)) as i: self.data.storage += i @sp.add_test(name="Summarise Test") def test(): scenario = sp.test_scenario() contract = Summarise() scenario += contract # Exception catch attempt sp.catch_exception(contract.sum(-1), t=sp.TString) sp.add_compilation_target("summarise_compiled", Summarise())
I want a test to ensure the param type is
nat and not
int or anything else. This is why I'd like to explicitly check for the type exception error. To prevent someone from inadvertently changing the type later on. Perhaps there is another approach?