move common funciton test helpers
This commit is contained in:
parent
30a410413a
commit
cd94fd850b
@ -34,21 +34,6 @@ let str_keys (raw_pkh, raw_pk, raw_sk) =
|
|||||||
let pkh_str = Signature.Public_key_hash.to_b58check raw_pkh in
|
let pkh_str = Signature.Public_key_hash.to_b58check raw_pkh in
|
||||||
(pkh_str,pk_str,sk_str)
|
(pkh_str,pk_str,sk_str)
|
||||||
|
|
||||||
let sign_message (payload : expression) sk : string result =
|
|
||||||
let open Tezos_crypto in
|
|
||||||
let%bind program,_ = get_program () in
|
|
||||||
let%bind code =
|
|
||||||
let env = Ast_typed.program_environment program in
|
|
||||||
Compile.Of_simplified.compile_expression_as_function
|
|
||||||
~env ~state:(Typer.Solver.initial_state) payload in
|
|
||||||
let Compiler.Program.{input=_;output=(Ex_ty payload_ty);body=_} = code in
|
|
||||||
let%bind payload =
|
|
||||||
Ligo.Run.Of_michelson.evaluate_michelson code in
|
|
||||||
let%bind packed_payload = Ligo.Run.Of_michelson.pack_payload payload payload_ty in
|
|
||||||
let signed_data = Signature.sign sk packed_payload in
|
|
||||||
let signature_str = Signature.to_b58check signed_data in
|
|
||||||
ok signature_str
|
|
||||||
|
|
||||||
let init_storage threshold counter pkeys =
|
let init_storage threshold counter pkeys =
|
||||||
let keys = List.map
|
let keys = List.map
|
||||||
(fun el ->
|
(fun el ->
|
||||||
@ -73,6 +58,7 @@ let chain_id_zero = e_chain_id @@ Tezos_crypto.Base58.simple_encode
|
|||||||
|
|
||||||
(* sign the message 'msg' with 'keys', if 'is_valid'=false the providid signature will be incorrect *)
|
(* sign the message 'msg' with 'keys', if 'is_valid'=false the providid signature will be incorrect *)
|
||||||
let params counter msg keys is_validl =
|
let params counter msg keys is_validl =
|
||||||
|
let%bind program,_ = get_program () in
|
||||||
let aux = fun acc (key,is_valid) ->
|
let aux = fun acc (key,is_valid) ->
|
||||||
let (_,_pk,sk) = key in
|
let (_,_pk,sk) = key in
|
||||||
let (pkh,_,_) = str_keys key in
|
let (pkh,_,_) = str_keys key in
|
||||||
@ -81,7 +67,7 @@ let params counter msg keys is_validl =
|
|||||||
e_nat counter ;
|
e_nat counter ;
|
||||||
e_string (if is_valid then "MULTISIG" else "XX") ;
|
e_string (if is_valid then "MULTISIG" else "XX") ;
|
||||||
chain_id_zero ] in
|
chain_id_zero ] in
|
||||||
let%bind signature = sign_message payload sk in
|
let%bind signature = sign_message program payload sk in
|
||||||
ok @@ (e_pair (e_key_hash pkh) (e_signature signature))::acc in
|
ok @@ (e_pair (e_key_hash pkh) (e_signature signature))::acc in
|
||||||
let%bind signed_msgs = Trace.bind_fold_list aux [] (List.rev @@ List.combine keys is_validl) in
|
let%bind signed_msgs = Trace.bind_fold_list aux [] (List.rev @@ List.combine keys is_validl) in
|
||||||
ok @@ e_constructor
|
ok @@ e_constructor
|
||||||
@ -92,7 +78,6 @@ let params counter msg keys is_validl =
|
|||||||
("signatures" , e_typed_list signed_msgs (t_pair (t_key_hash,t_signature)) ) ;
|
("signatures" , e_typed_list signed_msgs (t_pair (t_key_hash,t_signature)) ) ;
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
(* Provide one valid signature when the threshold is two of two keys *)
|
(* Provide one valid signature when the threshold is two of two keys *)
|
||||||
let not_enough_1_of_2 () =
|
let not_enough_1_of_2 () =
|
||||||
let%bind program,_ = get_program () in
|
let%bind program,_ = get_program () in
|
||||||
|
@ -22,17 +22,6 @@ let compile_main () =
|
|||||||
|
|
||||||
open Ast_simplified
|
open Ast_simplified
|
||||||
|
|
||||||
let pack_payload (payload:expression) : bytes result =
|
|
||||||
let%bind program,_ = get_program () in
|
|
||||||
let%bind code =
|
|
||||||
let env = Ast_typed.program_environment program in
|
|
||||||
Compile.Of_simplified.compile_expression_as_function
|
|
||||||
~env ~state:(Typer.Solver.initial_state) payload in
|
|
||||||
let Compiler.Program.{input=_;output=(Ex_ty payload_ty);body=_} = code in
|
|
||||||
let%bind (payload: Tezos_utils.Michelson.michelson) =
|
|
||||||
Ligo.Run.Of_michelson.evaluate_michelson code in
|
|
||||||
Ligo.Run.Of_michelson.pack_payload payload payload_ty
|
|
||||||
|
|
||||||
let contract id =
|
let contract id =
|
||||||
let open Proto_alpha_utils.Memory_proto_alpha in
|
let open Proto_alpha_utils.Memory_proto_alpha in
|
||||||
let id = List.nth dummy_environment.identities id in
|
let id = List.nth dummy_environment.identities id in
|
||||||
@ -73,7 +62,7 @@ let wrong_addr () =
|
|||||||
(* sender message is already stored in the message store *)
|
(* sender message is already stored in the message store *)
|
||||||
let already_accounted () =
|
let already_accounted () =
|
||||||
let%bind program,_ = get_program () in
|
let%bind program,_ = get_program () in
|
||||||
let%bind packed_payload = pack_payload empty_message in
|
let%bind packed_payload = pack_payload program empty_message in
|
||||||
let%bind bytes = e_bytes_ofbytes packed_payload in
|
let%bind bytes = e_bytes_ofbytes packed_payload in
|
||||||
let init_storage = storage 1 [1;2]
|
let init_storage = storage 1 [1;2]
|
||||||
[(bytes, e_set [e_address@@ addr 1])] in
|
[(bytes, e_set [e_address@@ addr 1])] in
|
||||||
@ -90,7 +79,7 @@ let already_accounted () =
|
|||||||
(* successful storing in the message store *)
|
(* successful storing in the message store *)
|
||||||
let succeeded_storing () =
|
let succeeded_storing () =
|
||||||
let%bind program,_ = get_program () in
|
let%bind program,_ = get_program () in
|
||||||
let%bind packed_payload = pack_payload empty_message in
|
let%bind packed_payload = pack_payload program empty_message in
|
||||||
let%bind bytes = e_bytes_ofbytes packed_payload in
|
let%bind bytes = e_bytes_ofbytes packed_payload in
|
||||||
let options =
|
let options =
|
||||||
let amount = Memory_proto_alpha.Protocol.Alpha_context.Tez.zero in
|
let amount = Memory_proto_alpha.Protocol.Alpha_context.Tez.zero in
|
||||||
|
@ -29,6 +29,26 @@ let test name f =
|
|||||||
|
|
||||||
let test_suite name lst = Test_suite (name , lst)
|
let test_suite name lst = Test_suite (name , lst)
|
||||||
|
|
||||||
|
|
||||||
|
open Ast_simplified
|
||||||
|
|
||||||
|
let pack_payload (program:Ast_typed.program) (payload:expression) : bytes result =
|
||||||
|
let%bind code =
|
||||||
|
let env = Ast_typed.program_environment program in
|
||||||
|
Compile.Of_simplified.compile_expression_as_function
|
||||||
|
~env ~state:(Typer.Solver.initial_state) payload in
|
||||||
|
let Compiler.Program.{input=_;output=(Ex_ty payload_ty);body=_} = code in
|
||||||
|
let%bind (payload: Tezos_utils.Michelson.michelson) =
|
||||||
|
Ligo.Run.Of_michelson.evaluate_michelson code in
|
||||||
|
Ligo.Run.Of_michelson.pack_payload payload payload_ty
|
||||||
|
|
||||||
|
let sign_message (program:Ast_typed.program) (payload : expression) sk : string result =
|
||||||
|
let open Tezos_crypto in
|
||||||
|
let%bind packed_payload = pack_payload program payload in
|
||||||
|
let signed_data = Signature.sign sk packed_payload in
|
||||||
|
let signature_str = Signature.to_b58check signed_data in
|
||||||
|
ok signature_str
|
||||||
|
|
||||||
open Ast_simplified.Combinators
|
open Ast_simplified.Combinators
|
||||||
|
|
||||||
let expect ?options program entry_point input expecter =
|
let expect ?options program entry_point input expecter =
|
||||||
|
Loading…
Reference in New Issue
Block a user