@@ -81,10 +81,23 @@ pub enum VoteType {
81
81
/// Note: Yes/No vote is a single choice (Yes) vote with the deny option (No)
82
82
SingleChoice ,
83
83
84
- /// Multiple options can be selected with up to N choices per voter
85
- /// By default N equals to the number of available options
86
- /// Note: In the current version the N limit is not supported and not enforced yet
87
- MultiChoice ( u16 ) ,
84
+ /// Multiple options can be selected with up to max_voter_options per voter
85
+ /// and with up to max_executable_options of wining options eligible for execution
86
+ /// Ex. voters are given 5 options, can choose up to 3 (max_voter_options)
87
+ /// and only 1 (max_executable_options) wining option can be executed
88
+ MultiChoice {
89
+ /// The max number of options a voter can choose
90
+ /// By default it equals to the number of available options
91
+ /// Note: In the current version the limit is not supported and not enforced yet
92
+ #[ allow( dead_code) ]
93
+ max_voter_options : u16 ,
94
+
95
+ /// The max number of wining options which can be executed
96
+ /// By default it equals to the number of available options
97
+ /// Note: In the current version the limit is not supported and not enforced yet
98
+ #[ allow( dead_code) ]
99
+ max_executable_options : u16 ,
100
+ } ,
88
101
}
89
102
90
103
/// Governance Proposal
@@ -171,7 +184,7 @@ pub struct ProposalV2 {
171
184
impl AccountMaxSize for ProposalV2 {
172
185
fn get_max_size ( & self ) -> Option < usize > {
173
186
let options_size: usize = self . options . iter ( ) . map ( |o| o. label . len ( ) + 19 ) . sum ( ) ;
174
- Some ( self . name . len ( ) + self . description_link . len ( ) + options_size + 199 )
187
+ Some ( self . name . len ( ) + self . description_link . len ( ) + options_size + 201 )
175
188
}
176
189
}
177
190
@@ -357,7 +370,10 @@ impl ProposalV2 {
357
370
358
371
proposal_state
359
372
}
360
- VoteType :: MultiChoice ( _n) => {
373
+ VoteType :: MultiChoice {
374
+ max_voter_options : _n,
375
+ max_executable_options : _m,
376
+ } => {
361
377
// If any option succeeded for multi choice then the proposal as a whole succeeded as well
362
378
ProposalState :: Succeeded
363
379
}
@@ -670,7 +686,10 @@ impl ProposalV2 {
670
686
return Err ( GovernanceError :: InvalidVote . into ( ) ) ;
671
687
}
672
688
}
673
- VoteType :: MultiChoice ( _n) => {
689
+ VoteType :: MultiChoice {
690
+ max_voter_options : _n,
691
+ max_executable_options : _m,
692
+ } => {
674
693
if choice_count == 0 {
675
694
return Err ( GovernanceError :: InvalidVote . into ( ) ) ;
676
695
}
@@ -884,8 +903,15 @@ pub fn assert_valid_proposal_options(
884
903
return Err ( GovernanceError :: InvalidProposalOptions . into ( ) ) ;
885
904
}
886
905
887
- if let VoteType :: MultiChoice ( n) = * vote_type {
888
- if options. len ( ) == 1 || n as usize != options. len ( ) {
906
+ if let VoteType :: MultiChoice {
907
+ max_voter_options,
908
+ max_executable_options,
909
+ } = * vote_type
910
+ {
911
+ if options. len ( ) == 1
912
+ || max_voter_options as usize != options. len ( )
913
+ || max_executable_options as usize != options. len ( )
914
+ {
889
915
return Err ( GovernanceError :: InvalidProposalOptions . into ( ) ) ;
890
916
}
891
917
}
@@ -1018,7 +1044,10 @@ mod test {
1018
1044
#[ test]
1019
1045
fn test_max_size ( ) {
1020
1046
let mut proposal = create_test_proposal ( ) ;
1021
- proposal. vote_type = VoteType :: MultiChoice ( 1 ) ;
1047
+ proposal. vote_type = VoteType :: MultiChoice {
1048
+ max_voter_options : 1 ,
1049
+ max_executable_options : 1 ,
1050
+ } ;
1022
1051
1023
1052
let size = proposal. try_to_vec ( ) . unwrap ( ) . len ( ) ;
1024
1053
@@ -1028,7 +1057,10 @@ mod test {
1028
1057
#[ test]
1029
1058
fn test_multi_option_proposal_max_size ( ) {
1030
1059
let mut proposal = create_test_multi_option_proposal ( ) ;
1031
- proposal. vote_type = VoteType :: MultiChoice ( 3 ) ;
1060
+ proposal. vote_type = VoteType :: MultiChoice {
1061
+ max_voter_options : 3 ,
1062
+ max_executable_options : 3 ,
1063
+ } ;
1032
1064
1033
1065
let size = proposal. try_to_vec ( ) . unwrap ( ) . len ( ) ;
1034
1066
@@ -1971,7 +2003,10 @@ mod test {
1971
2003
pub fn test_assert_valid_vote_with_no_choices_for_multi_choice_error ( ) {
1972
2004
// Arrange
1973
2005
let mut proposal = create_test_multi_option_proposal ( ) ;
1974
- proposal. vote_type = VoteType :: MultiChoice ( 3 ) ;
2006
+ proposal. vote_type = VoteType :: MultiChoice {
2007
+ max_voter_options : 3 ,
2008
+ max_executable_options : 3 ,
2009
+ } ;
1975
2010
1976
2011
let choices = vec ! [
1977
2012
VoteChoice {
@@ -2004,7 +2039,10 @@ mod test {
2004
2039
pub fn test_assert_valid_proposal_options_with_invalid_choice_number_for_multi_choice_vote_error (
2005
2040
) {
2006
2041
// Arrange
2007
- let vote_type = VoteType :: MultiChoice ( 3 ) ;
2042
+ let vote_type = VoteType :: MultiChoice {
2043
+ max_voter_options : 3 ,
2044
+ max_executable_options : 3 ,
2045
+ } ;
2008
2046
2009
2047
let options = vec ! [ "option 1" . to_string( ) , "option 2" . to_string( ) ] ;
2010
2048
@@ -2018,7 +2056,10 @@ mod test {
2018
2056
#[ test]
2019
2057
pub fn test_assert_valid_proposal_options_with_no_options_for_multi_choice_vote_error ( ) {
2020
2058
// Arrange
2021
- let vote_type = VoteType :: MultiChoice ( 3 ) ;
2059
+ let vote_type = VoteType :: MultiChoice {
2060
+ max_voter_options : 3 ,
2061
+ max_executable_options : 3 ,
2062
+ } ;
2022
2063
2023
2064
let options = vec ! [ ] ;
2024
2065
@@ -2046,7 +2087,10 @@ mod test {
2046
2087
#[ test]
2047
2088
pub fn test_assert_valid_proposal_options_for_multi_choice_vote ( ) {
2048
2089
// Arrange
2049
- let vote_type = VoteType :: MultiChoice ( 3 ) ;
2090
+ let vote_type = VoteType :: MultiChoice {
2091
+ max_voter_options : 3 ,
2092
+ max_executable_options : 3 ,
2093
+ } ;
2050
2094
2051
2095
let options = vec ! [
2052
2096
"option 1" . to_string( ) ,
@@ -2064,7 +2108,10 @@ mod test {
2064
2108
#[ test]
2065
2109
pub fn test_assert_valid_proposal_options_for_multi_choice_vote_with_empty_option_error ( ) {
2066
2110
// Arrange
2067
- let vote_type = VoteType :: MultiChoice ( 3 ) ;
2111
+ let vote_type = VoteType :: MultiChoice {
2112
+ max_voter_options : 3 ,
2113
+ max_executable_options : 3 ,
2114
+ } ;
2068
2115
2069
2116
let options = vec ! [
2070
2117
"" . to_string( ) ,
0 commit comments