From 54f4ffd413118f44f7872bb91cdf0b6ae5a33798 Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Thu, 6 Feb 2020 11:53:50 +0100 Subject: [PATCH 1/2] Fix assetion with a default string "failed assertion" --- src/passes/operators/operators.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index 9025b3295..142c3d087 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -1122,7 +1122,7 @@ module Compiler = struct | C_SIZE -> ok @@ simple_unary @@ prim I_SIZE | C_FAILWITH -> ok @@ simple_unary @@ prim I_FAILWITH | C_ASSERT_INFERRED -> ok @@ simple_binary @@ i_if (seq [i_failwith]) (seq [i_drop ; i_push_unit]) - | C_ASSERTION -> ok @@ simple_unary @@ i_if (seq [i_push_unit]) (seq [i_push_unit ; i_failwith]) + | C_ASSERTION -> ok @@ simple_unary @@ i_if (seq [i_push_unit]) (seq [i_push_string "failed assertion" ; i_failwith]) | C_INT -> ok @@ simple_unary @@ prim I_INT | C_ABS -> ok @@ simple_unary @@ prim I_ABS | C_IS_NAT -> ok @@ simple_unary @@ prim I_ISNAT From 5ef61d352028bb89cd0b5b34990a78bcb1268638 Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Thu, 6 Feb 2020 12:05:13 +0100 Subject: [PATCH 2/2] add assert primitive for pascaligo --- src/bin/expect_tests/failwith_tests.ml | 36 ++++++++++++++++++++++++++ src/passes/operators/operators.ml | 3 ++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/bin/expect_tests/failwith_tests.ml diff --git a/src/bin/expect_tests/failwith_tests.ml b/src/bin/expect_tests/failwith_tests.ml new file mode 100644 index 000000000..d957f03c0 --- /dev/null +++ b/src/bin/expect_tests/failwith_tests.ml @@ -0,0 +1,36 @@ +open Cli_expect + +let contract basename = + "../../test/contracts/" ^ basename +let bad_contract basename = + "../../test/contracts/negative/" ^ basename + +let%expect_test _ = + run_ligo_good [ "run-function" ; contract "failwith.ligo" ; "failer" ; "1" ] ; + [%expect {| + failwith("some_string") |}]; + + run_ligo_good [ "run-function" ; contract "failwith.ligo" ; "failer" ; "1" ; "--format=json" ] ; + [%expect {| + {"status":"ok","content":"failwith(\"some_string\")"} |}]; + + + run_ligo_good [ "dry-run" ; contract "subtle_nontail_fail.mligo" ; "main" ; "()" ; "()" ] ; + [%expect {| + failwith("This contract always fails") |}]; + + run_ligo_good [ "interpret" ; "assert(1=1)" ; "--syntax=pascaligo" ] ; + [%expect {| + Unit |}]; + + run_ligo_good [ "interpret" ; "assert(1=2)" ; "--syntax=pascaligo" ] ; + [%expect {| + failwith("failed assertion") |}]; + + run_ligo_good [ "interpret" ; "assert(1=1)" ; "--syntax=cameligo" ] ; + [%expect {| + Unit |}]; + + run_ligo_good [ "interpret" ; "assert(1=2)" ; "--syntax=cameligo" ] ; + [%expect {| + failwith("failed assertion") |}]; diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index 142c3d087..be1196ad1 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -66,7 +66,7 @@ module Simplify = struct module Pascaligo = struct let constants = function - | "get_force" -> ok C_MAP_FIND + | "assert" -> ok C_ASSERTION | "get_chain_id" -> ok C_CHAIN_ID | "transaction" -> ok C_CALL | "get_contract" -> ok C_CONTRACT @@ -106,6 +106,7 @@ module Simplify = struct | "list_iter" -> ok C_LIST_ITER | "list_fold" -> ok C_LIST_FOLD | "list_map" -> ok C_LIST_MAP + | "get_force" -> ok C_MAP_FIND | "map_iter" -> ok C_MAP_ITER | "map_map" -> ok C_MAP_MAP | "map_fold" -> ok C_MAP_FOLD