OCamlPro/techelson

Techel.apply_operations how to catch a failure

Closed this issue ยท 4 comments

Hi!

I would like to verify that a particular contract call fails. Is there a way to "catch" the failure of Techel.apply_operations - and verify the failure message?

Thanks ๐Ÿ˜„

Hey!

By your message you seem to be using Techelson with Liquidity. If you look at the external contract example Section in my blog post, you will see that I use Techel.must_fail which almost does what you want.

At liquidity level, you currently cannot use this extension to catch error messages. But if you look at how the extensions are defined,

external must_fail :
    [%stack: operation] -> [%stack: operation]
    = "{ NONE string ; MUST_FAIL string }"

The weird NONE string that's pushed on the stack is exactly what you want: it is the error message of the failure. I'm going to update the post to allow users to specify the error message and pass it to must_fail.

In the mean time, you can rewrite the definition of must_fail to

external must_fail :
    [%stack: string] -> [%stack: operation] -> [%stack: operation]
    = "{ DIP { SOME } ; MUST_FAIL string }"

Then you can use it as must_fail <error_string> <operation>. This will work iff <operation> fails with message <error_string>.

I'll notify you once the Liquidity blog post is updated.

Thank you!

I just updated the blog post. Note that the extension file has changed to update must_fail.

The discussion in External Contract Example about must_fail has been updated to show how to catch the error message of a failure.

Let me know if this works for you, and if it does, would you mind closing this issue?

Fantastic ๐ŸŽ‰ Works perfectly! Thanks a bunch ๐Ÿ™Œ

Glad it works for you, let me know if you have more questions/problems!