From a8e344c24ea9298e099177f69cbc2c44771bf046 Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Fri, 7 Jun 2019 12:48:21 +0200 Subject: [PATCH] Added test for Matej. --- src/contracts/match_bis.mligo | 20 ++++++++++++++++++++ src/test/integration_tests.ml | 9 +++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/contracts/match_bis.mligo diff --git a/src/contracts/match_bis.mligo b/src/contracts/match_bis.mligo new file mode 100644 index 000000000..3f4e02c23 --- /dev/null +++ b/src/contracts/match_bis.mligo @@ -0,0 +1,20 @@ +type storage = int + +(* variant defining pseudo multi-entrypoint actions *) + +type action = +| Increment of int +| Decrement of int + +let add (a: int) (b: int) : int = a + b + +let subtract (a: int) (b: int) : int = a - b + +(* real entrypoint that re-routes the flow based on the action provided *) + +let%entry main (p : action) storage = + let storage = + match p with + | Increment n -> add storage n + | Decrement n -> subtract storage n + in (([] : operation list), storage) diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index ba9db500c..fcaea7093 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -484,6 +484,14 @@ let match_variant () : unit result = e_pair (e_typed_list [] t_operation) (e_int (3-n)) in expect_eq_n program "main" make_input make_expected +let match_matej () : unit result = + let%bind program = mtype_file "./contracts/match_bis.mligo" in + let make_input n = + e_pair (e_constructor "Decrement" (e_int n)) (e_int 3) in + let make_expected n = + e_pair (e_typed_list [] t_operation) (e_int (3-n)) + in expect_eq_n program "main" make_input make_expected + let mligo_list () : unit result = let%bind program = mtype_file "./contracts/list.mligo" in let make_input n = @@ -560,6 +568,7 @@ let main = test_suite "Integration (End to End)" [ test "counter contract (mligo)" counter_mligo ; test "let-in (mligo)" let_in_mligo ; test "match variant (mligo)" match_variant ; + test "match variant 2 (mligo)" match_matej ; (* test "list matching (mligo)" mligo_list ; *) (* test "guess the hash mligo" guess_the_hash_mligo ; WIP? *) (* test "failwith mligo" failwith_mligo ; *)