From 0a676d72a58d7ffa0f425189a40aedffd124e3a1 Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Fri, 3 Jan 2020 18:09:16 +0100 Subject: [PATCH] add --predecessor-timestamp to compile-storage/parameter --- src/bin/cli.ml | 16 +++++----- src/bin/expect_tests/contract_tests.ml | 4 +++ src/bin/expect_tests/help_tests.ml | 42 ++++++++++++++++++++++---- src/test/contracts/timestamp.ligo | 3 ++ 4 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 src/test/contracts/timestamp.ligo diff --git a/src/bin/cli.ml b/src/bin/cli.ml index edc0d9b44..61c4e7a4e 100644 --- a/src/bin/cli.ml +++ b/src/bin/cli.ml @@ -90,7 +90,7 @@ let predecessor_timestamp = let open Arg in let info = let docv = "PREDECESSOR_TIMESTAMP" in - let doc = "$(docv) is the pedecessor_timestamp the michelson interpreter transaction will use (e.g. '2000-01-01T10:10:10Z')" in + let doc = "$(docv) is the pedecessor_timestamp (now value) the michelson interpreter will use (e.g. '2000-01-01T10:10:10Z')" in info ~docv ~doc ["predecessor-timestamp"] in value @@ opt (some string) None info @@ -156,7 +156,7 @@ let measure_contract = (Term.ret term , Term.info ~doc cmdname) let compile_parameter = - let f source_file entry_point expression syntax display_format michelson_format = + let f source_file entry_point expression syntax amount sender source predecessor_timestamp display_format michelson_format = toplevel ~display_format @@ let%bind simplified = Compile.Of_source.compile source_file (Syntax_name syntax) in let%bind typed_prg,state = Compile.Of_simplified.compile simplified in @@ -174,11 +174,12 @@ let compile_parameter = let%bind compiled_param = Compile.Of_mini_c.aggregate_and_compile_expression mini_c_prg mini_c_param in let%bind () = Compile.Of_typed.assert_equal_contract_type Check_parameter entry_point typed_prg typed_param in let%bind () = Compile.Of_michelson.assert_equal_contract_type Check_parameter michelson_prg compiled_param in - let%bind value = Run.evaluate_expression compiled_param.expr compiled_param.expr_ty in + let%bind options = Run.make_dry_run_options {predecessor_timestamp ; amount ; sender ; source } in + let%bind value = Run.evaluate_expression ~options compiled_param.expr compiled_param.expr_ty in ok @@ Format.asprintf "%a\n" (Main.Display.michelson_pp michelson_format) value in let term = - Term.(const f $ source_file 0 $ entry_point 1 $ expression "PARAMETER" 2 $ syntax $ display_format $ michelson_code_format) in + Term.(const f $ source_file 0 $ entry_point 1 $ expression "PARAMETER" 2 $ syntax $ amount $ sender $ source $ predecessor_timestamp $ display_format $ michelson_code_format) in let cmdname = "compile-parameter" in let doc = "Subcommand: compile parameters to a michelson expression. The resulting michelson expression can be passed as an argument in a transaction which calls a contract." in (Term.ret term , Term.info ~doc cmdname) @@ -213,7 +214,7 @@ let interpret = let compile_storage = - let f source_file entry_point expression syntax display_format michelson_format = + let f source_file entry_point expression syntax amount sender source predecessor_timestamp display_format michelson_format = toplevel ~display_format @@ let%bind simplified = Compile.Of_source.compile source_file (Syntax_name syntax) in let%bind typed_prg,state = Compile.Of_simplified.compile simplified in @@ -231,11 +232,12 @@ let compile_storage = let%bind compiled_param = Compile.Of_mini_c.compile_expression mini_c_param in let%bind () = Compile.Of_typed.assert_equal_contract_type Check_storage entry_point typed_prg typed_param in let%bind () = Compile.Of_michelson.assert_equal_contract_type Check_storage michelson_prg compiled_param in - let%bind value = Run.evaluate_expression compiled_param.expr compiled_param.expr_ty in + let%bind options = Run.make_dry_run_options {predecessor_timestamp ; amount ; sender ; source } in + let%bind value = Run.evaluate_expression ~options compiled_param.expr compiled_param.expr_ty in ok @@ Format.asprintf "%a\n" (Main.Display.michelson_pp michelson_format) value in let term = - Term.(const f $ source_file 0 $ entry_point 1 $ expression "STORAGE" 2 $ syntax $ display_format $ michelson_code_format) in + Term.(const f $ source_file 0 $ entry_point 1 $ expression "STORAGE" 2 $ syntax $ amount $ sender $ source $ predecessor_timestamp $ display_format $ michelson_code_format) in let cmdname = "compile-storage" in let doc = "Subcommand: compile an initial storage in ligo syntax to a michelson expression. The resulting michelson expression can be passed as an argument in a transaction which originates a contract." in (Term.ret term , Term.info ~doc cmdname) diff --git a/src/bin/expect_tests/contract_tests.ml b/src/bin/expect_tests/contract_tests.ml index 1ba33c139..b9b34c076 100644 --- a/src/bin/expect_tests/contract_tests.ml +++ b/src/bin/expect_tests/contract_tests.ml @@ -30,6 +30,10 @@ let%expect_test _ = () +let%expect_test _ = + run_ligo_good [ "compile-storage" ; contract "timestamp.ligo" ; "main" ; "now" ; "--predecessor-timestamp" ; "2042-01-01T00:00:00Z" ] ; + [%expect {| "2042-01-01T00:00:01Z" |}] + let%expect_test _ = run_ligo_good [ "compile-contract" ; contract "coase.ligo" ; "main" ] ; [%expect {| diff --git a/src/bin/expect_tests/help_tests.ml b/src/bin/expect_tests/help_tests.ml index e804c8283..af5ab1797 100644 --- a/src/bin/expect_tests/help_tests.ml +++ b/src/bin/expect_tests/help_tests.ml @@ -176,6 +176,9 @@ let%expect_test _ = contract. OPTIONS + --amount=AMOUNT (absent=0) + AMOUNT is the amount the michelson interpreter will use. + --format=DISPLAY_FORMAT, --display-format=DISPLAY_FORMAT (absent=human-readable) DISPLAY_FORMAT is the format that will be used by the CLI. @@ -194,11 +197,23 @@ let%expect_test _ = compile-contract for the resulting Michelson. Available formats are 'text' (default), 'json' and 'hex'. + --predecessor-timestamp=PREDECESSOR_TIMESTAMP + PREDECESSOR_TIMESTAMP is the pedecessor_timestamp (now value) the + michelson interpreter will use (e.g. '2000-01-01T10:10:10Z') + -s SYNTAX, --syntax=SYNTAX (absent=auto) SYNTAX is the syntax that will be used. Currently supported syntaxes are "pascaligo" and "cameligo". By default, the syntax is guessed from the extension (.ligo and .mligo, respectively). + --sender=SENDER + SENDER is the sender the michelson interpreter transaction will + use. + + --source=SOURCE + SOURCE is the source the michelson interpreter transaction will + use. + --version Show version information. |} ] ; @@ -226,6 +241,9 @@ let%expect_test _ = STORAGE_EXPRESSION is the expression that will be compiled. OPTIONS + --amount=AMOUNT (absent=0) + AMOUNT is the amount the michelson interpreter will use. + --format=DISPLAY_FORMAT, --display-format=DISPLAY_FORMAT (absent=human-readable) DISPLAY_FORMAT is the format that will be used by the CLI. @@ -244,11 +262,23 @@ let%expect_test _ = compile-contract for the resulting Michelson. Available formats are 'text' (default), 'json' and 'hex'. + --predecessor-timestamp=PREDECESSOR_TIMESTAMP + PREDECESSOR_TIMESTAMP is the pedecessor_timestamp (now value) the + michelson interpreter will use (e.g. '2000-01-01T10:10:10Z') + -s SYNTAX, --syntax=SYNTAX (absent=auto) SYNTAX is the syntax that will be used. Currently supported syntaxes are "pascaligo" and "cameligo". By default, the syntax is guessed from the extension (.ligo and .mligo, respectively). + --sender=SENDER + SENDER is the sender the michelson interpreter transaction will + use. + + --source=SOURCE + SOURCE is the source the michelson interpreter transaction will + use. + --version Show version information. |} ] ; @@ -294,8 +324,8 @@ let%expect_test _ = `plain' whenever the TERM env var is `dumb' or undefined. --predecessor-timestamp=PREDECESSOR_TIMESTAMP - PREDECESSOR_TIMESTAMP is the pedecessor_timestamp the michelson - interpreter transaction will use (e.g. '2000-01-01T10:10:10Z') + PREDECESSOR_TIMESTAMP is the pedecessor_timestamp (now value) the + michelson interpreter will use (e.g. '2000-01-01T10:10:10Z') -s SYNTAX, --syntax=SYNTAX (absent=auto) SYNTAX is the syntax that will be used. Currently supported @@ -352,8 +382,8 @@ let%expect_test _ = `plain' whenever the TERM env var is `dumb' or undefined. --predecessor-timestamp=PREDECESSOR_TIMESTAMP - PREDECESSOR_TIMESTAMP is the pedecessor_timestamp the michelson - interpreter transaction will use (e.g. '2000-01-01T10:10:10Z') + PREDECESSOR_TIMESTAMP is the pedecessor_timestamp (now value) the + michelson interpreter will use (e.g. '2000-01-01T10:10:10Z') -s SYNTAX, --syntax=SYNTAX (absent=auto) SYNTAX is the syntax that will be used. Currently supported @@ -405,8 +435,8 @@ let%expect_test _ = `plain' whenever the TERM env var is `dumb' or undefined. --predecessor-timestamp=PREDECESSOR_TIMESTAMP - PREDECESSOR_TIMESTAMP is the pedecessor_timestamp the michelson - interpreter transaction will use (e.g. '2000-01-01T10:10:10Z') + PREDECESSOR_TIMESTAMP is the pedecessor_timestamp (now value) the + michelson interpreter will use (e.g. '2000-01-01T10:10:10Z') -s SYNTAX, --syntax=SYNTAX (absent=auto) SYNTAX is the syntax that will be used. Currently supported diff --git a/src/test/contracts/timestamp.ligo b/src/test/contracts/timestamp.ligo new file mode 100644 index 000000000..4e105c45f --- /dev/null +++ b/src/test/contracts/timestamp.ligo @@ -0,0 +1,3 @@ +type storage_ is timestamp + +function main(const p : unit; const s : storage_) : list(operation) * storage_ is ((nil: list(operation)), now) \ No newline at end of file