Alpha/Tests: test for limit

This commit is contained in:
Marco Stronati 2018-11-20 23:00:22 +01:00 committed by Pierre Boutillier
parent 278ffb5a17
commit 17b258b92c
No known key found for this signature in database
GPG Key ID: C2F73508B56A193C
3 changed files with 62 additions and 22 deletions

View File

@ -106,41 +106,41 @@ let get_seed_nonce_hash ctxt =
let get_seed ctxt = Alpha_services.Seed.get rpc_ctxt ctxt let get_seed ctxt = Alpha_services.Seed.get rpc_ctxt ctxt
let get_constants b = let get_constants ctxt =
Alpha_services.Constants.all rpc_ctxt b Alpha_services.Constants.all rpc_ctxt ctxt
(* Voting *) (* Voting *)
module Vote = struct module Vote = struct
let get_ballots b = let get_ballots ctxt =
Alpha_services.Voting.ballots rpc_ctxt b Alpha_services.Voting.ballots rpc_ctxt ctxt
let get_ballot_list b = let get_ballot_list ctxt =
Alpha_services.Voting.ballot_list rpc_ctxt b Alpha_services.Voting.ballot_list rpc_ctxt ctxt
let get_voting_period b = let get_voting_period ctxt =
Alpha_services.Helpers.current_level rpc_ctxt b >>=? fun l -> Alpha_services.Helpers.current_level rpc_ctxt ctxt >>=? fun l ->
return l.voting_period return l.voting_period
let get_voting_period_position b = let get_voting_period_position ctxt =
Alpha_services.Helpers.current_level rpc_ctxt b >>=? fun l -> Alpha_services.Helpers.current_level rpc_ctxt ctxt >>=? fun l ->
return l.voting_period_position return l.voting_period_position
let get_current_period_kind b = let get_current_period_kind ctxt =
Alpha_services.Voting.current_period_kind rpc_ctxt b Alpha_services.Voting.current_period_kind rpc_ctxt ctxt
let get_current_quorum b = let get_current_quorum ctxt =
Alpha_services.Voting.current_quorum rpc_ctxt b Alpha_services.Voting.current_quorum rpc_ctxt ctxt
let get_listings b = let get_listings ctxt =
Alpha_services.Voting.listings rpc_ctxt b Alpha_services.Voting.listings rpc_ctxt ctxt
let get_proposals b = let get_proposals ctxt =
Alpha_services.Voting.proposals rpc_ctxt b Alpha_services.Voting.proposals rpc_ctxt ctxt
let get_current_proposal b = let get_current_proposal ctxt =
Alpha_services.Voting.current_proposal rpc_ctxt b Alpha_services.Voting.current_proposal rpc_ctxt ctxt
let get_protocol (b:Block.t) = let get_protocol (b:Block.t) =
Alpha_environment.Context.get b.context ["protocol"] >>= function Alpha_environment.Context.get b.context ["protocol"] >>= function

View File

@ -30,6 +30,6 @@ let tztest name speed f =
| Ok () -> Lwt.return_unit | Ok () -> Lwt.return_unit
| Error err -> | Error err ->
Tezos_stdlib_unix.Logging_unix.close () >>= fun () -> Tezos_stdlib_unix.Logging_unix.close () >>= fun () ->
Format.eprintf "WWW %a@." pp_print_error err ; Format.printf "WWW %a@." pp_print_error err ;
Lwt.fail Alcotest.Test_error Lwt.fail Alcotest.Test_error
end end

View File

@ -32,6 +32,29 @@ let ballots_equal b1 b2 =
let ballots_pp ppf v = Alpha_context.Vote.( let ballots_pp ppf v = Alpha_context.Vote.(
Format.fprintf ppf "{ yay = %ld ; nay = %ld ; pass = %ld" v.yay v.nay v.pass) Format.fprintf ppf "{ yay = %ld ; nay = %ld ; pass = %ld" v.yay v.nay v.pass)
let protos = Array.map (fun s -> Protocol_hash.of_b58check_exn s)
[| "ProtoALphaALphaALphaALphaALphaALphaALpha61322gcLUGH" ;
"ProtoALphaALphaALphaALphaALphaALphaALphabc2a7ebx6WB" ;
"ProtoALphaALphaALphaALphaALphaALphaALpha84efbeiF6cm" ;
"ProtoALphaALphaALphaALphaALphaALphaALpha91249Z65tWS" ;
"ProtoALphaALphaALphaALphaALphaALphaALpha537f5h25LnN" ;
"ProtoALphaALphaALphaALphaALphaALphaALpha5c8fefgDYkr" ;
"ProtoALphaALphaALphaALphaALphaALphaALpha3f31feSSarC" ;
"ProtoALphaALphaALphaALphaALphaALphaALphabe31ahnkxSC" ;
"ProtoALphaALphaALphaALphaALphaALphaALphabab3bgRb7zQ" ;
"ProtoALphaALphaALphaALphaALphaALphaALphaf8d39cctbpk" ;
"ProtoALphaALphaALphaALphaALphaALphaALpha3b981byuYxD" ;
"ProtoALphaALphaALphaALphaALphaALphaALphaa116bccYowi" ;
"ProtoALphaALphaALphaALphaALphaALphaALphacce68eHqboj" ;
"ProtoALphaALphaALphaALphaALphaALphaALpha225c7YrWwR7" ;
"ProtoALphaALphaALphaALphaALphaALphaALpha58743cJL6FG" ;
"ProtoALphaALphaALphaALphaALphaALphaALphac91bcdvmJFR" ;
"ProtoALphaALphaALphaALphaALphaALphaALpha1faaadhV7oW" ;
"ProtoALphaALphaALphaALphaALphaALphaALpha98232gD94QJ" ;
"ProtoALphaALphaALphaALphaALphaALphaALpha9d1d8cijvAh" ;
"ProtoALphaALphaALphaALphaALphaALphaALphaeec52dKF6Gx" ;
"ProtoALphaALphaALphaALphaALphaALphaALpha841f2cQqajX" ; |]
let test_voting () = let test_voting () =
Context.init 5 >>=? fun (b,delegates) -> Context.init 5 >>=? fun (b,delegates) ->
@ -89,7 +112,8 @@ let test_voting () =
let del1 = List.nth delegates 0 in let del1 = List.nth delegates 0 in
let del2 = List.nth delegates 1 in let del2 = List.nth delegates 1 in
Op.proposals (B b) del1 [Protocol_hash.zero] >>=? fun ops1 -> let props = List.map (fun i -> protos.(i)) (2--Constants.max_proposals_per_delegate) in
Op.proposals (B b) del1 (Protocol_hash.zero::props) >>=? fun ops1 ->
Op.proposals (B b) del2 [Protocol_hash.zero] >>=? fun ops2 -> Op.proposals (B b) del2 [Protocol_hash.zero] >>=? fun ops2 ->
Block.bake ~operations:[ops1;ops2] b >>=? fun b -> Block.bake ~operations:[ops1;ops2] b >>=? fun b ->
@ -114,6 +138,22 @@ let test_voting () =
| None -> failwith "%s - Missing proposal" __LOC__ | None -> failwith "%s - Missing proposal" __LOC__
end >>=? fun () -> end >>=? fun () ->
(* proposing more than maximum_proposals fails *)
Op.proposals (B b) del1 (Protocol_hash.zero::props) >>=? fun ops ->
Block.bake ~operations:[ops] b >>= fun res ->
Assert.proto_error ~loc:__LOC__ res begin function
| Amendment.Too_many_proposals -> true
| _ -> false
end >>=? fun () ->
(* proposing less than one proposal fails *)
Op.proposals (B b) del1 [] >>=? fun ops ->
Block.bake ~operations:[ops] b >>= fun res ->
Assert.proto_error ~loc:__LOC__ res begin function
| Amendment.Empty_proposal -> true
| _ -> false
end >>=? fun () ->
(* skip to vote_testing period (* skip to vote_testing period
-1 because we already baked one block with the proposal *) -1 because we already baked one block with the proposal *)
(* TODO BUG -2 causes period_kind to change but not period *) (* TODO BUG -2 causes period_kind to change but not period *)