Merge branch 'feature/dry-run-bin' into 'dev'
Feature/dry run bin See merge request ligolang/ligo!33
This commit is contained in:
commit
3f2a74fa42
@ -0,0 +1 @@
|
|||||||
|
pY4yiss3_bmzORHLtOPUEYaFxWxD_GkD8XZajWh0DUU.4Dc00ftieGaWDmacztwSS7euFOKPULDHjUNzikwPvao
|
@ -72,6 +72,14 @@ let syntax =
|
|||||||
info ~docv ~doc ["syntax" ; "s"] in
|
info ~docv ~doc ["syntax" ; "s"] in
|
||||||
value @@ opt string "auto" info
|
value @@ opt string "auto" info
|
||||||
|
|
||||||
|
let amount =
|
||||||
|
let open Arg in
|
||||||
|
let info =
|
||||||
|
let docv = "AMOUNT" in
|
||||||
|
let doc = "$(docv) is the amount the dry-run transaction will use." in
|
||||||
|
info ~docv ~doc ["amount"] in
|
||||||
|
value @@ opt string "0" info
|
||||||
|
|
||||||
let compile_file =
|
let compile_file =
|
||||||
let f source entry_point syntax =
|
let f source entry_point syntax =
|
||||||
toplevel @@
|
toplevel @@
|
||||||
@ -118,43 +126,43 @@ let compile_storage =
|
|||||||
(term , Term.info ~docs cmdname)
|
(term , Term.info ~docs cmdname)
|
||||||
|
|
||||||
let dry_run =
|
let dry_run =
|
||||||
let f source entry_point storage input syntax =
|
let f source entry_point storage input amount syntax =
|
||||||
toplevel @@
|
toplevel @@
|
||||||
let%bind output =
|
let%bind output =
|
||||||
Ligo.Run.run_contract source entry_point storage input syntax in
|
Ligo.Run.run_contract ~amount source entry_point storage input syntax in
|
||||||
Format.printf "%a\n" Ast_simplified.PP.expression output ;
|
Format.printf "%a\n" Ast_simplified.PP.expression output ;
|
||||||
ok ()
|
ok ()
|
||||||
in
|
in
|
||||||
let term =
|
let term =
|
||||||
Term.(const f $ source 0 $ entry_point 1 $ expression "PARAMETER" 2 $ expression "STORAGE" 3 $ syntax) in
|
Term.(const f $ source 0 $ entry_point 1 $ expression "PARAMETER" 2 $ expression "STORAGE" 3 $ amount $ syntax) in
|
||||||
let cmdname = "dry-run" in
|
let cmdname = "dry-run" in
|
||||||
let docs = "Subcommand: run a smart-contract with the given storage and input." in
|
let docs = "Subcommand: run a smart-contract with the given storage and input." in
|
||||||
(term , Term.info ~docs cmdname)
|
(term , Term.info ~docs cmdname)
|
||||||
|
|
||||||
let run_function =
|
let run_function =
|
||||||
let f source entry_point parameter syntax =
|
let f source entry_point parameter amount syntax =
|
||||||
toplevel @@
|
toplevel @@
|
||||||
let%bind output =
|
let%bind output =
|
||||||
Ligo.Run.run_function source entry_point parameter syntax in
|
Ligo.Run.run_function ~amount source entry_point parameter syntax in
|
||||||
Format.printf "%a\n" Ast_simplified.PP.expression output ;
|
Format.printf "%a\n" Ast_simplified.PP.expression output ;
|
||||||
ok ()
|
ok ()
|
||||||
in
|
in
|
||||||
let term =
|
let term =
|
||||||
Term.(const f $ source 0 $ entry_point 1 $ expression "PARAMETER" 2 $ syntax) in
|
Term.(const f $ source 0 $ entry_point 1 $ expression "PARAMETER" 2 $ amount $ syntax) in
|
||||||
let cmdname = "run-function" in
|
let cmdname = "run-function" in
|
||||||
let docs = "Subcommand: run a function with the given parameter." in
|
let docs = "Subcommand: run a function with the given parameter." in
|
||||||
(term , Term.info ~docs cmdname)
|
(term , Term.info ~docs cmdname)
|
||||||
|
|
||||||
let evaluate_value =
|
let evaluate_value =
|
||||||
let f source entry_point syntax =
|
let f source entry_point amount syntax =
|
||||||
toplevel @@
|
toplevel @@
|
||||||
let%bind output =
|
let%bind output =
|
||||||
Ligo.Run.evaluate_value source entry_point syntax in
|
Ligo.Run.evaluate_value ~amount source entry_point syntax in
|
||||||
Format.printf "%a\n" Ast_simplified.PP.expression output ;
|
Format.printf "%a\n" Ast_simplified.PP.expression output ;
|
||||||
ok ()
|
ok ()
|
||||||
in
|
in
|
||||||
let term =
|
let term =
|
||||||
Term.(const f $ source 0 $ entry_point 1 $ syntax) in
|
Term.(const f $ source 0 $ entry_point 1 $ amount $ syntax) in
|
||||||
let cmdname = "evaluate-value" in
|
let cmdname = "evaluate-value" in
|
||||||
let docs = "Subcommand: evaluate a given definition." in
|
let docs = "Subcommand: evaluate a given definition." in
|
||||||
(term , Term.info ~docs cmdname)
|
(term , Term.info ~docs cmdname)
|
||||||
|
1
src/contracts/amount.mligo
Normal file
1
src/contracts/amount.mligo
Normal file
@ -0,0 +1 @@
|
|||||||
|
let check = if Current.amount > 100tz then 42 else 0
|
@ -17,8 +17,8 @@ let run_simplityped
|
|||||||
let%bind annotated_result = Typer.untype_expression typed_result in
|
let%bind annotated_result = Typer.untype_expression typed_result in
|
||||||
ok annotated_result
|
ok annotated_result
|
||||||
|
|
||||||
let evaluate_simplityped (program : Ast_typed.program) (entry : string)
|
let evaluate_simplityped ?options (program : Ast_typed.program) (entry : string)
|
||||||
: Ast_simplified.expression result =
|
: Ast_simplified.expression result =
|
||||||
let%bind typed_result = Run_typed.evaluate_typed entry program in
|
let%bind typed_result = Run_typed.evaluate_typed ?options entry program in
|
||||||
let%bind annotated_result = Typer.untype_expression typed_result in
|
let%bind annotated_result = Typer.untype_expression typed_result in
|
||||||
ok annotated_result
|
ok annotated_result
|
||||||
|
@ -233,23 +233,35 @@ let type_file ?(debug_simplify = false) ?(debug_typed = false)
|
|||||||
)) ;
|
)) ;
|
||||||
ok typed
|
ok typed
|
||||||
|
|
||||||
let run_contract source entry_point storage input syntax =
|
let run_contract ?amount source entry_point storage input syntax =
|
||||||
let%bind typed =
|
let%bind typed =
|
||||||
type_file syntax source in
|
type_file syntax source in
|
||||||
let%bind storage_simpl =
|
let%bind storage_simpl =
|
||||||
parsify_expression syntax storage in
|
parsify_expression syntax storage in
|
||||||
let%bind input_simpl =
|
let%bind input_simpl =
|
||||||
parsify_expression syntax input in
|
parsify_expression syntax input in
|
||||||
Run_simplified.run_simplityped typed entry_point (Ast_simplified.e_pair storage_simpl input_simpl)
|
let options =
|
||||||
|
let open Proto_alpha_utils.Memory_proto_alpha in
|
||||||
|
let amount = Option.bind (fun amount -> Alpha_context.Tez.of_string amount) amount in
|
||||||
|
(make_options ?amount ()) in
|
||||||
|
Run_simplified.run_simplityped ~options typed entry_point (Ast_simplified.e_pair storage_simpl input_simpl)
|
||||||
|
|
||||||
let run_function source entry_point parameter syntax =
|
let run_function ?amount source entry_point parameter syntax =
|
||||||
let%bind typed =
|
let%bind typed =
|
||||||
type_file syntax source in
|
type_file syntax source in
|
||||||
let%bind parameter' =
|
let%bind parameter' =
|
||||||
parsify_expression syntax parameter in
|
parsify_expression syntax parameter in
|
||||||
Run_simplified.run_simplityped typed entry_point parameter'
|
let options =
|
||||||
|
let open Proto_alpha_utils.Memory_proto_alpha in
|
||||||
|
let amount = Option.bind (fun amount -> Alpha_context.Tez.of_string amount) amount in
|
||||||
|
(make_options ?amount ()) in
|
||||||
|
Run_simplified.run_simplityped ~options typed entry_point parameter'
|
||||||
|
|
||||||
let evaluate_value source entry_point syntax =
|
let evaluate_value ?amount source entry_point syntax =
|
||||||
let%bind typed =
|
let%bind typed =
|
||||||
type_file syntax source in
|
type_file syntax source in
|
||||||
Run_simplified.evaluate_simplityped typed entry_point
|
let options =
|
||||||
|
let open Proto_alpha_utils.Memory_proto_alpha in
|
||||||
|
let amount = Option.bind (fun amount -> Alpha_context.Tez.of_string amount) amount in
|
||||||
|
(make_options ?amount ()) in
|
||||||
|
Run_simplified.evaluate_simplityped ~options typed entry_point
|
||||||
|
@ -13,12 +13,12 @@ let transpile_value
|
|||||||
let%bind r = Run_mini_c.run_entry f input in
|
let%bind r = Run_mini_c.run_entry f input in
|
||||||
ok r
|
ok r
|
||||||
|
|
||||||
let evaluate_typed (entry:string) (program:Ast_typed.program) : Ast_typed.annotated_expression result =
|
let evaluate_typed ?options (entry:string) (program:Ast_typed.program) : Ast_typed.annotated_expression result =
|
||||||
trace (simple_error "easy evaluate typed") @@
|
trace (simple_error "easy evaluate typed") @@
|
||||||
let%bind result =
|
let%bind result =
|
||||||
let%bind mini_c_main =
|
let%bind mini_c_main =
|
||||||
Transpiler.translate_entry program entry in
|
Transpiler.translate_entry program entry in
|
||||||
Run_mini_c.run_entry mini_c_main (Mini_c.Combinators.d_unit) in
|
Run_mini_c.run_entry ?options mini_c_main (Mini_c.Combinators.d_unit) in
|
||||||
let%bind typed_result =
|
let%bind typed_result =
|
||||||
let%bind typed_main = Ast_typed.get_entry program entry in
|
let%bind typed_main = Ast_typed.get_entry program entry in
|
||||||
Transpiler.untranspile result typed_main.type_annotation in
|
Transpiler.untranspile result typed_main.type_annotation in
|
||||||
|
Loading…
Reference in New Issue
Block a user