Alpha/Vote: do not allow multiple votes
This commit is contained in:
parent
17b258b92c
commit
09e3881c6b
@ -759,8 +759,10 @@ module Vote : sig
|
||||
|
||||
val ballots_encoding : ballots Data_encoding.t
|
||||
|
||||
val has_recorded_ballot :
|
||||
context -> public_key_hash -> bool Lwt.t
|
||||
val record_ballot:
|
||||
context -> public_key_hash -> ballot -> context Lwt.t
|
||||
context -> public_key_hash -> ballot -> context tzresult Lwt.t
|
||||
val get_ballots: context -> ballots tzresult Lwt.t
|
||||
val get_ballot_list: context -> (Signature.Public_key_hash.t * ballot) list Lwt.t
|
||||
val clear_ballots: context -> context Lwt.t
|
||||
|
@ -227,9 +227,11 @@ let record_ballot ctxt delegate proposal ballot =
|
||||
Vote.get_current_proposal ctxt >>=? fun current_proposal ->
|
||||
fail_unless (Protocol_hash.equal proposal current_proposal)
|
||||
Invalid_proposal >>=? fun () ->
|
||||
Vote.has_recorded_ballot ctxt delegate >>= fun has_ballot ->
|
||||
fail_when has_ballot Unauthorized_ballot >>=? fun () ->
|
||||
Vote.in_listings ctxt delegate >>= fun in_listings ->
|
||||
if in_listings then
|
||||
Vote.record_ballot ctxt delegate ballot >>= return
|
||||
Vote.record_ballot ctxt delegate ballot
|
||||
else
|
||||
fail Unauthorized_ballot
|
||||
| Testing | Proposal ->
|
||||
|
@ -74,7 +74,8 @@ let ballots_encoding =
|
||||
(req "nay" int32)
|
||||
(req "pass" int32)
|
||||
|
||||
let record_ballot = Storage.Vote.Ballots.init_set
|
||||
let has_recorded_ballot = Storage.Vote.Ballots.mem
|
||||
let record_ballot = Storage.Vote.Ballots.init
|
||||
|
||||
let get_ballots ctxt =
|
||||
Storage.Vote.Ballots.fold ctxt
|
||||
|
@ -45,9 +45,10 @@ type ballots = {
|
||||
|
||||
val ballots_encoding : ballots Data_encoding.t
|
||||
|
||||
val has_recorded_ballot : Raw_context.t -> Signature.Public_key_hash.t -> bool Lwt.t
|
||||
val record_ballot:
|
||||
Raw_context.t -> Signature.Public_key_hash.t -> Vote_repr.ballot ->
|
||||
Raw_context.t Lwt.t
|
||||
Raw_context.t tzresult Lwt.t
|
||||
val get_ballots: Raw_context.t -> ballots tzresult Lwt.t
|
||||
val get_ballot_list :
|
||||
Raw_context.t -> (Signature.Public_key_hash.t * Vote_repr.ballot) list Lwt.t
|
||||
|
@ -201,6 +201,13 @@ let test_voting () =
|
||||
delegates >>=? fun operations ->
|
||||
Block.bake ~operations b >>=? fun b ->
|
||||
|
||||
Op.ballot (B b) del1 Protocol_hash.zero Vote.Nay >>=? fun op ->
|
||||
Block.bake ~operations:[op] b >>= fun res ->
|
||||
Assert.proto_error ~loc:__LOC__ res begin function
|
||||
| Amendment.Unauthorized_ballot -> true
|
||||
| _ -> false
|
||||
end >>=? fun () ->
|
||||
|
||||
fold_left_s (fun v acc -> return Int32.(add v acc))
|
||||
0l rolls >>=? fun rolls_sum ->
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user