diff --git a/src/contracts/website2.mligo b/src/contracts/website2.mligo new file mode 100644 index 000000000..f972e9b47 --- /dev/null +++ b/src/contracts/website2.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 16a4c7d69..8ee57494d 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -825,6 +825,16 @@ let tez_mligo () : unit result = let%bind _ = expect_eq_evaluate program "add_more_tez" (e_mutez 111111000) in ok () +let website2_mligo () : unit result = + let%bind program = mtype_file "./contracts/website2.mligo" in + let make_input = fun n -> + let action = if n mod 2 = 0 then "Increment" else "Decrement" in + e_pair (e_constructor action (e_int n)) (e_int 42) in + let make_expected = fun n -> + let op = if n mod 2 = 0 then (+) else (-) in + e_pair (e_typed_list [] t_operation) (e_int (op 42 n)) in + expect_eq_n program "main" make_input make_expected + let main = test_suite "Integration (End to End)" [ test "type alias" type_alias ; test "function" function_ ; @@ -888,4 +898,5 @@ let main = test_suite "Integration (End to End)" [ test "tez (mligo)" tez_mligo ; test "website1 ligo" website1_ligo ; test "website2 ligo" website2_ligo ; + test "website2 (mligo)" website2_mligo ; ]