From 17b258b92c5c3203160418622eb390df4b3c745c Mon Sep 17 00:00:00 2001 From: Marco Stronati Date: Tue, 20 Nov 2018 23:00:22 +0100 Subject: [PATCH] Alpha/Tests: test for limit --- .../lib_protocol/test/helpers/context.ml | 40 +++++++++--------- .../lib_protocol/test/helpers/test.ml | 2 +- src/proto_alpha/lib_protocol/test/voting.ml | 42 ++++++++++++++++++- 3 files changed, 62 insertions(+), 22 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.ml b/src/proto_alpha/lib_protocol/test/helpers/context.ml index 406d22b76..af7e6b2f0 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/context.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/context.ml @@ -106,41 +106,41 @@ let get_seed_nonce_hash ctxt = let get_seed ctxt = Alpha_services.Seed.get rpc_ctxt ctxt -let get_constants b = - Alpha_services.Constants.all rpc_ctxt b +let get_constants ctxt = + Alpha_services.Constants.all rpc_ctxt ctxt (* Voting *) module Vote = struct - let get_ballots b = - Alpha_services.Voting.ballots rpc_ctxt b + let get_ballots ctxt = + Alpha_services.Voting.ballots rpc_ctxt ctxt - let get_ballot_list b = - Alpha_services.Voting.ballot_list rpc_ctxt b + let get_ballot_list ctxt = + Alpha_services.Voting.ballot_list rpc_ctxt ctxt - let get_voting_period b = - Alpha_services.Helpers.current_level rpc_ctxt b >>=? fun l -> + let get_voting_period ctxt = + Alpha_services.Helpers.current_level rpc_ctxt ctxt >>=? fun l -> return l.voting_period - let get_voting_period_position b = - Alpha_services.Helpers.current_level rpc_ctxt b >>=? fun l -> + let get_voting_period_position ctxt = + Alpha_services.Helpers.current_level rpc_ctxt ctxt >>=? fun l -> return l.voting_period_position - let get_current_period_kind b = - Alpha_services.Voting.current_period_kind rpc_ctxt b + let get_current_period_kind ctxt = + Alpha_services.Voting.current_period_kind rpc_ctxt ctxt - let get_current_quorum b = - Alpha_services.Voting.current_quorum rpc_ctxt b + let get_current_quorum ctxt = + Alpha_services.Voting.current_quorum rpc_ctxt ctxt - let get_listings b = - Alpha_services.Voting.listings rpc_ctxt b + let get_listings ctxt = + Alpha_services.Voting.listings rpc_ctxt ctxt - let get_proposals b = - Alpha_services.Voting.proposals rpc_ctxt b + let get_proposals ctxt = + Alpha_services.Voting.proposals rpc_ctxt ctxt - let get_current_proposal b = - Alpha_services.Voting.current_proposal rpc_ctxt b + let get_current_proposal ctxt = + Alpha_services.Voting.current_proposal rpc_ctxt ctxt let get_protocol (b:Block.t) = Alpha_environment.Context.get b.context ["protocol"] >>= function diff --git a/src/proto_alpha/lib_protocol/test/helpers/test.ml b/src/proto_alpha/lib_protocol/test/helpers/test.ml index 63d256388..48762297e 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/test.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/test.ml @@ -30,6 +30,6 @@ let tztest name speed f = | Ok () -> Lwt.return_unit | Error err -> 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 end diff --git a/src/proto_alpha/lib_protocol/test/voting.ml b/src/proto_alpha/lib_protocol/test/voting.ml index 4c35df036..245720c44 100644 --- a/src/proto_alpha/lib_protocol/test/voting.ml +++ b/src/proto_alpha/lib_protocol/test/voting.ml @@ -32,6 +32,29 @@ let ballots_equal b1 b2 = let ballots_pp ppf v = Alpha_context.Vote.( 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 () = Context.init 5 >>=? fun (b,delegates) -> @@ -89,7 +112,8 @@ let test_voting () = let del1 = List.nth delegates 0 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 -> Block.bake ~operations:[ops1;ops2] b >>=? fun b -> @@ -114,6 +138,22 @@ let test_voting () = | None -> failwith "%s - Missing proposal" __LOC__ 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 -1 because we already baked one block with the proposal *) (* TODO BUG -2 causes period_kind to change but not period *)