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 =
|
2019-12-09 22:51:10 +04:00
|
|
|
let%bind simplified = Ligo.Compile.Of_source.compile f (Syntax_name "cameligo") in
|
2020-03-04 18:38:10 +04:00
|
|
|
let%bind typed,state = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in
|
2019-11-30 01:22:56 +04:00
|
|
|
ok @@ (typed,state)
|
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
|
|
|
)
|
|
|
|
|
|
|
|
open Ast_simplified
|
|
|
|
|
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) ;
|
2019-06-10 13:58:16 +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 () =
|
2019-11-30 01:22:56 +04:00
|
|
|
let%bind (program , _) = get_program () in
|
2020-03-02 21:01:56 +04:00
|
|
|
let%bind result =
|
|
|
|
Test_helpers.run_typed_program_with_simplified_input
|
|
|
|
program "main" (e_pair yea (init_storage "basic")) in
|
|
|
|
let%bind (_, storage) = extract_pair result in
|
2019-06-11 04:52:09 +04:00
|
|
|
let%bind storage' = 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
|
|
|
|
let%bind () = Ast_simplified.Misc.assert_value_eq (yea, e_nat 1) 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
|
|
|
]
|