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-03-16 17:28:05 +04:00
|
|
|
let%bind typed,state = Ligo.Compile.Utils.type_file f "cameligo" (Contract "main") 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
|
|
|
)
|
|
|
|
|
2020-03-16 17:28:05 +04:00
|
|
|
open Ast_core
|
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) ;
|
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 =
|
2020-03-16 17:28:05 +04:00
|
|
|
Test_helpers.run_typed_program_with_core_input
|
2020-03-02 21:01:56 +04:00
|
|
|
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
|
2020-03-16 17:28:05 +04:00
|
|
|
let%bind () = Ast_core.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
|
|
|
]
|