From f9d1928d8e8ada0397ad9972f735ded6658d1e6f Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Mon, 30 Mar 2020 13:20:14 +0200 Subject: [PATCH] michelson_or tests and changelog --- CHANGELOG.md | 4 ++ src/bin/expect_tests/contract_tests.ml | 4 +- src/bin/expect_tests/michelson_or_tests.ml | 41 +++++++++++++++++++ src/test/contracts/double_michelson_or.ligo | 11 +++++ src/test/contracts/double_michelson_or.mligo | 9 ++++ src/test/contracts/michelson_or_tree.mligo | 8 ++++ .../contracts/negative/bad_michelson_or.mligo | 7 ++++ 7 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 src/bin/expect_tests/michelson_or_tests.ml create mode 100644 src/test/contracts/double_michelson_or.ligo create mode 100644 src/test/contracts/double_michelson_or.mligo create mode 100644 src/test/contracts/michelson_or_tree.mligo create mode 100644 src/test/contracts/negative/bad_michelson_or.mligo diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fc44d2cb..ccdd86d90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +## [Michelson or type] (https://gitlab.com/ligolang/ligo/-/merge_requests/530) +### Added +- New type michelson_or, will give control over or types instead of relying on LIGO variants. + ## [Support for self] (https://gitlab.com/ligolang/ligo/-/merge_requests/453) ### Added - support for `Tezos.self(%Entrypoint)` diff --git a/src/bin/expect_tests/contract_tests.ml b/src/bin/expect_tests/contract_tests.ml index 6be4ef583..f16a38e0b 100644 --- a/src/bin/expect_tests/contract_tests.ml +++ b/src/bin/expect_tests/contract_tests.ml @@ -1117,7 +1117,7 @@ let%expect_test _ = let%expect_test _ = run_ligo_bad [ "compile-contract" ; bad_contract "create_contract_toplevel.mligo" ; "main" ] ; [%expect {| -ligo: in file "create_contract_toplevel.mligo", line 4, character 35 to line 8, character 8. No free variable allowed in this lambda: variable 'store' {"expression":"CREATE_CONTRACT(lambda (#P:Some(( nat * string ))) : None return\n let rhs#705 = #P in\n let p = rhs#705.0 in\n let s = rhs#705.1 in\n ( LIST_EMPTY() : (TO_list(operation)) , store ) ,\n NONE() : (TO_option(key_hash)) ,\n 300000000mutez ,\n \"un\")","location":"in file \"create_contract_toplevel.mligo\", line 4, character 35 to line 8, character 8"} +ligo: in file "create_contract_toplevel.mligo", line 4, character 35 to line 8, character 8. No free variable allowed in this lambda: variable 'store' {"expression":"CREATE_CONTRACT(lambda (#P:Some(( nat * string ))) : None return\n let rhs#712 = #P in\n let p = rhs#712.0 in\n let s = rhs#712.1 in\n ( LIST_EMPTY() : (TO_list(operation)) , store ) ,\n NONE() : (TO_option(key_hash)) ,\n 300000000mutez ,\n \"un\")","location":"in file \"create_contract_toplevel.mligo\", line 4, character 35 to line 8, character 8"} If you're not sure how to fix this error, you can @@ -1130,7 +1130,7 @@ ligo: in file "create_contract_toplevel.mligo", line 4, character 35 to line 8, run_ligo_bad [ "compile-contract" ; bad_contract "create_contract_var.mligo" ; "main" ] ; [%expect {| -ligo: in file "create_contract_var.mligo", line 6, character 35 to line 10, character 5. No free variable allowed in this lambda: variable 'a' {"expression":"CREATE_CONTRACT(lambda (#P:Some(( nat * int ))) : None return\n let rhs#708 = #P in\n let p = rhs#708.0 in\n let s = rhs#708.1 in\n ( LIST_EMPTY() : (TO_list(operation)) , a ) ,\n NONE() : (TO_option(key_hash)) ,\n 300000000mutez ,\n 1)","location":"in file \"create_contract_var.mligo\", line 6, character 35 to line 10, character 5"} +ligo: in file "create_contract_var.mligo", line 6, character 35 to line 10, character 5. No free variable allowed in this lambda: variable 'a' {"expression":"CREATE_CONTRACT(lambda (#P:Some(( nat * int ))) : None return\n let rhs#715 = #P in\n let p = rhs#715.0 in\n let s = rhs#715.1 in\n ( LIST_EMPTY() : (TO_list(operation)) , a ) ,\n NONE() : (TO_option(key_hash)) ,\n 300000000mutez ,\n 1)","location":"in file \"create_contract_var.mligo\", line 6, character 35 to line 10, character 5"} If you're not sure how to fix this error, you can diff --git a/src/bin/expect_tests/michelson_or_tests.ml b/src/bin/expect_tests/michelson_or_tests.ml new file mode 100644 index 000000000..2656620c9 --- /dev/null +++ b/src/bin/expect_tests/michelson_or_tests.ml @@ -0,0 +1,41 @@ +open Cli_expect + +let contract basename = + "../../test/contracts/" ^ basename +let bad_contract basename = + "../../test/contracts/negative/" ^ basename + +let%expect_test _ = + run_ligo_good [ "dry-run" ; contract "double_michelson_or.mligo" ; "main" ; "unit" ; "(M_left (1) : storage)" ] ; + [%expect {| ( LIST_EMPTY() , M_right("one") ) |}]; + + run_ligo_good [ "dry-run" ; contract "double_michelson_or.ligo" ; "main" ; "unit" ; "(M_left (1) : storage)" ] ; + [%expect {| ( LIST_EMPTY() , M_right("one") ) |}] + + +let%expect_test _ = + run_ligo_good [ "compile-contract" ; contract "michelson_or_tree.mligo" ; "main" ] ; + [%expect {| + { parameter unit ; + storage (or (int %m_left) (or %m_right (int %m_left) (nat %m_right))) ; + code { PUSH int 1 ; + LEFT nat ; + RIGHT int ; + DUP ; + NIL operation ; + PAIR ; + DIP { DROP 2 } } } |}] + +let%expect_test _ = + run_ligo_bad [ "compile-contract" ; bad_contract "bad_michelson_or.mligo" ; "main" ] ; + [%expect {| + ligo: in file "bad_michelson_or.mligo", line 6, characters 12-27. michelson_or types must be annotated: {"constructor":"M_right","location":"in file \"bad_michelson_or.mligo\", line 6, characters 12-27"} + + + If you're not sure how to fix this error, you can + do one of the following: + + * Visit our documentation: https://ligolang.org/docs/intro/what-and-why/ + * Ask a question on our Discord: https://discord.gg/9rhYaEt + * Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new + * Check the changelog by running 'ligo changelog' |}] \ No newline at end of file diff --git a/src/test/contracts/double_michelson_or.ligo b/src/test/contracts/double_michelson_or.ligo new file mode 100644 index 000000000..e1b1d6595 --- /dev/null +++ b/src/test/contracts/double_michelson_or.ligo @@ -0,0 +1,11 @@ +type storage is michelson_or (int, string) +type foobar is michelson_or (int, int) + +type return is list (operation) * storage + +function main (const action : unit; const store : storage) : return is +block { + const foo : storage = (M_right ("one") : storage); + const bar : foobar = (M_right (1) : foobar) +} with + ((nil : list (operation)), (foo : storage)) \ No newline at end of file diff --git a/src/test/contracts/double_michelson_or.mligo b/src/test/contracts/double_michelson_or.mligo new file mode 100644 index 000000000..f69f2b151 --- /dev/null +++ b/src/test/contracts/double_michelson_or.mligo @@ -0,0 +1,9 @@ +type storage = (int,string) michelson_or +type foobar = (int, int ) michelson_or + +type return = operation list * storage + +let main (action, store : unit * storage) : return = + let foo = (M_right ("one") : storage) in + let bar = (M_right 1 : foobar) in + (([] : operation list), (foo: storage)) diff --git a/src/test/contracts/michelson_or_tree.mligo b/src/test/contracts/michelson_or_tree.mligo new file mode 100644 index 000000000..6f08f67bc --- /dev/null +++ b/src/test/contracts/michelson_or_tree.mligo @@ -0,0 +1,8 @@ +type inner_storage = (int,nat) michelson_or +type storage = (int,inner_storage) michelson_or + +type return = operation list * storage + +let main (action, store : unit * storage) : return = + let foo = (M_right (M_left 1 : inner_storage) : storage) in + (([] : operation list), (foo: storage)) diff --git a/src/test/contracts/negative/bad_michelson_or.mligo b/src/test/contracts/negative/bad_michelson_or.mligo new file mode 100644 index 000000000..08c7fe035 --- /dev/null +++ b/src/test/contracts/negative/bad_michelson_or.mligo @@ -0,0 +1,7 @@ +type storage = (int,string) michelson_or + +type return = operation list * storage + +let main (action, store : unit * storage) : return = + let foo = M_right ("one") in + (([] : operation list), (foo: storage))