@@ -90,10 +90,13 @@ pub type MaxMembers = ConstU32<100>;
9090parameter_types ! {
9191 pub const MotionDuration : u64 = 3 ;
9292 pub const MaxProposals : u32 = 257 ;
93+ pub BlockWeights : frame_system:: limits:: BlockWeights =
94+ frame_system:: limits:: BlockWeights :: simple_max( Weight :: MAX ) ;
95+ pub static MaxProposalWeight : Weight = default_max_proposal_weight( ) ;
9396}
9497impl frame_system:: Config for Test {
9598 type BaseCallFilter = frame_support:: traits:: Everything ;
96- type BlockWeights = ( ) ;
99+ type BlockWeights = BlockWeights ;
97100 type BlockLength = ( ) ;
98101 type DbWeight = ( ) ;
99102 type RuntimeOrigin = RuntimeOrigin ;
@@ -127,6 +130,7 @@ impl Config<Instance1> for Test {
127130 type DefaultVote = PrimeDefaultVote ;
128131 type WeightInfo = ( ) ;
129132 type SetMembersOrigin = EnsureRoot < Self :: AccountId > ;
133+ type MaxProposalWeight = MaxProposalWeight ;
130134}
131135impl Config < Instance2 > for Test {
132136 type RuntimeOrigin = RuntimeOrigin ;
@@ -138,6 +142,7 @@ impl Config<Instance2> for Test {
138142 type DefaultVote = MoreThanMajorityThenPrimeDefaultVote ;
139143 type WeightInfo = ( ) ;
140144 type SetMembersOrigin = EnsureRoot < Self :: AccountId > ;
145+ type MaxProposalWeight = MaxProposalWeight ;
141146}
142147impl mock_democracy:: Config for Test {
143148 type RuntimeEvent = RuntimeEvent ;
@@ -153,6 +158,7 @@ impl Config for Test {
153158 type DefaultVote = PrimeDefaultVote ;
154159 type WeightInfo = ( ) ;
155160 type SetMembersOrigin = EnsureRoot < Self :: AccountId > ;
161+ type MaxProposalWeight = MaxProposalWeight ;
156162}
157163
158164pub struct ExtBuilder { }
@@ -201,6 +207,10 @@ fn record(event: RuntimeEvent) -> EventRecord<RuntimeEvent, H256> {
201207 EventRecord { phase : Phase :: Initialization , event, topics : vec ! [ ] }
202208}
203209
210+ fn default_max_proposal_weight ( ) -> Weight {
211+ sp_runtime:: Perbill :: from_percent ( 80 ) * BlockWeights :: get ( ) . max_block
212+ }
213+
204214#[ test]
205215fn motions_basic_environment_works ( ) {
206216 ExtBuilder :: default ( ) . build_and_execute ( || {
@@ -209,6 +219,36 @@ fn motions_basic_environment_works() {
209219 } ) ;
210220}
211221
222+ #[ test]
223+ fn proposal_weight_limit_works ( ) {
224+ ExtBuilder :: default ( ) . build_and_execute ( || {
225+ let proposal = make_proposal ( 42 ) ;
226+ let proposal_len: u32 = proposal. using_encoded ( |p| p. len ( ) as u32 ) ;
227+
228+ assert_ok ! ( Collective :: propose(
229+ RuntimeOrigin :: signed( 1 ) ,
230+ 2 ,
231+ Box :: new( proposal. clone( ) ) ,
232+ proposal_len
233+ ) ) ;
234+
235+ // set a small limit for max proposal weight.
236+ MaxProposalWeight :: set ( Weight :: from_parts ( 1 , 1 ) ) ;
237+ assert_noop ! (
238+ Collective :: propose(
239+ RuntimeOrigin :: signed( 1 ) ,
240+ 2 ,
241+ Box :: new( proposal. clone( ) ) ,
242+ proposal_len
243+ ) ,
244+ Error :: <Test , Instance1 >:: WrongProposalWeight
245+ ) ;
246+
247+ // reset the max weight to default.
248+ MaxProposalWeight :: set ( default_max_proposal_weight ( ) ) ;
249+ } ) ;
250+ }
251+
212252#[ test]
213253fn close_works ( ) {
214254 ExtBuilder :: default ( ) . build_and_execute ( || {
0 commit comments