0

How can I assert that a contract transfer fails with a particular error message? Tried a couple things, including this:

match call_as pledger1 Get_refund 1tz taddr with
    | Success _ -> assert_with_error false "unexpected success"
    | Fail (Rejected ("you must wait longer before finalizing the withdraw", _)) ->
        () 
    | Fail err ->
        let () = Test.log err in
        assert_with_error false "unexpected error"

Here's the error message I got:

File "./test.mligo", line 51, characters 22-75:
 50 |     | Success _ -> assert_with_error false "success"
 51 |     | Fail (Rejected ("you must wait longer before finalizing the withdraw", _)) ->
 52 |         assert_with_error false "woot"

Invalid pattern matching.
  If this is pattern matching over Booleans, then "true" or "false" is expected.
  If this is pattern matching on a list, then one of the following is expected:
    * an empty list pattern "[]";
    * a cons list pattern "[head, ...tail]".
  If this is pattern matching over variants, then a constructor of a variant is expected.

  Other forms of pattern matching are not (yet) supported. 

1 Answer 1

0

I might be wrong but I don't think there is any notion of "try/catch" in LIGO. From the doc the failure is not catchable so I don't think there is any way to actually bind some logic to an exception. That is also something I am missing a bit from a unit-testing standpoint.

The signaled problem is that CameLIGO doesn't support literal string patterns, you'll need to use an if.

2
  • So is there no way to test that my contract rejects certain calls in certain states?
    – user9011
    Commented Jun 12, 2023 at 18:00
  • You can do it converting the error to a string with Test.to_string first.
    – user9011
    Commented Jun 12, 2023 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.