2019-06-10 13:58:16 +04:00
|
|
|
open Trace
|
|
|
|
open Test_helpers
|
|
|
|
|
2019-11-30 01:22:56 +04:00
|
|
|
let type_file f =
|
2020-05-29 22:37:11 +04:00
|
|
|
Ligo.Compile.Utils.type_file f "cameligo" (Contract "main")
|
2019-09-18 20:49:33 +04:00
|
|
|
|
2019-06-10 13:58:16 +04:00
|
|
|
let get_program =
|
|
|
|
let s = ref None in
|
|
|
|
fun () -> match !s with
|
|
|
|
| Some s -> ok s
|
|
|
|
| None -> (
|
2019-10-12 01:22:43 +04:00
|
|
|
let%bind (program , state) = type_file "./contracts/vote.mligo" in
|
|
|
|
s := Some (program , state) ;
|
|
|
|
ok (program , state)
|
2019-06-10 13:58:16 +04:00
|
|
|
)
|
|
|
|
|
2020-03-17 19:04:27 +04:00
|
|
|
open Ast_imperative
|
2019-06-10 13:58:16 +04:00
|
|
|
|
2019-12-04 21:30:52 +04:00
|
|
|
let init_storage name = e_record_ez [
|
2019-06-11 04:52:09 +04:00
|
|
|
("title" , e_string name) ;
|
2020-03-02 21:01:56 +04:00
|
|
|
("yea", e_nat 0) ;
|
|
|
|
("nay", e_nat 0) ;
|
2020-04-09 20:19:22 +04:00
|
|
|
("voters" , e_typed_set [] (t_address ())) ;
|
2020-03-02 21:01:56 +04:00
|
|
|
("start_time" , e_timestamp 0) ;
|
2019-06-11 04:52:09 +04:00
|
|
|
("finish_time" , e_timestamp 1000000000) ;
|
2019-06-10 13:58:16 +04:00
|
|
|
]
|
|
|
|
|
2020-03-02 21:01:56 +04:00
|
|
|
let reset title start_time finish_time =
|
|
|
|
let reset_action = e_record_ez [
|
2019-06-11 04:52:09 +04:00
|
|
|
("title" , e_string title) ;
|
2020-03-02 21:01:56 +04:00
|
|
|
("start_time" , e_timestamp start_time) ;
|
|
|
|
("finish_time" , e_timestamp finish_time)]
|
|
|
|
in e_constructor "Reset" reset_action
|
2019-06-11 04:52:09 +04:00
|
|
|
|
2020-03-02 21:01:56 +04:00
|
|
|
let yea = e_constructor "Vote" (e_constructor "Yea" (e_unit ()))
|
2019-06-11 04:52:09 +04:00
|
|
|
|
2019-06-10 13:58:16 +04:00
|
|
|
let init_vote () =
|
2020-05-29 22:37:11 +04:00
|
|
|
let%bind (program , state) = get_program () in
|
2020-03-02 21:01:56 +04:00
|
|
|
let%bind result =
|
2020-03-17 19:04:27 +04:00
|
|
|
Test_helpers.run_typed_program_with_imperative_input
|
2020-05-29 22:37:11 +04:00
|
|
|
(program, state) "main" (e_pair yea (init_storage "basic")) in
|
2020-03-17 19:04:27 +04:00
|
|
|
let%bind (_, storage) = Ast_core.extract_pair result in
|
|
|
|
let%bind storage' = Ast_core.extract_record storage in
|
2020-03-02 21:01:56 +04:00
|
|
|
(* let votes = List.assoc (Label "voters") storage' in
|
|
|
|
let%bind votes' = extract_map votes in *)
|
|
|
|
let yea = List.assoc (Label "yea") storage' in
|
2020-04-27 18:15:26 +04:00
|
|
|
let%bind () = Ast_core.Misc.assert_value_eq (yea, Ast_core.e_nat Z.one) in
|
2019-06-10 13:58:16 +04:00
|
|
|
ok ()
|
|
|
|
|
|
|
|
let main = test_suite "Vote" [
|
2019-06-11 02:06:00 +04:00
|
|
|
test "type" init_vote ;
|
2019-06-10 13:58:16 +04:00
|
|
|
]
|