@@ -5,17 +5,28 @@ use polkadot_sdk::{
55 frame_benchmarking:: { account, v2:: * } ,
66 frame_system:: RawOrigin ,
77 sp_runtime:: Percent ,
8- sp_std:: vec,
98} ;
109
1110use crate :: * ;
1211
1312#[ benchmarks]
1413mod benchmarks {
15- use polkadot_sdk:: sp_std:: collections:: btree_map:: BTreeMap ;
14+ use polkadot_sdk:: {
15+ sp_core:: TryCollect , sp_std:: collections:: btree_map:: BTreeMap , sp_std:: vec,
16+ } ;
1617
1718 use super :: * ;
1819
20+ macro_rules! bounded_btree_map {
21+ ( $ ( $key: expr => $value: expr ) ,* $( , ) ?) => {
22+ {
23+ TryCollect :: <$crate:: BoundedBTreeMap <_, _, _>>:: try_collect(
24+ vec![ $( ( $key, $value) ) ,* ] . into_iter( )
25+ ) . unwrap( )
26+ }
27+ } ;
28+ }
29+
1930 #[ benchmark]
2031 fn grant_emission_permission ( ) {
2132 let grantor: T :: AccountId = account ( "Grantor" , 0 , 0 ) ;
@@ -35,7 +46,7 @@ mod benchmarks {
3546 let stream_id: StreamId = [ 0 ; 32 ] . into ( ) ;
3647 let streams = BTreeMap :: from ( [ ( stream_id, Percent :: from_percent ( 30 ) ) ] ) ;
3748 let allocation = EmissionAllocation :: Streams ( streams. try_into ( ) . unwrap ( ) ) ;
38- let targets = vec ! [ ( target, 100 ) ] ;
49+ let targets = bounded_btree_map ! [ target => 100 ] ;
3950 let distribution = DistributionControl :: Manual ;
4051 let duration = PermissionDuration :: Indefinite ;
4152 let revocation = RevocationTerms :: RevocableByGrantor ;
@@ -76,7 +87,7 @@ mod benchmarks {
7687 let stream_id: StreamId = [ 0 ; 32 ] . into ( ) ;
7788 let streams = BTreeMap :: from ( [ ( stream_id, Percent :: from_percent ( 30 ) ) ] ) ;
7889 let allocation = EmissionAllocation :: Streams ( streams. try_into ( ) . unwrap ( ) ) ;
79- let targets = vec ! [ ( target, 100 ) ] ;
90+ let targets = bounded_btree_map ! [ target => 100 ] ;
8091 let permission_id = ext:: emission_impl:: grant_emission_permission_impl :: < T > (
8192 grantor. clone ( ) ,
8293 grantee,
@@ -116,7 +127,7 @@ mod benchmarks {
116127 let stream_id: StreamId = [ 0 ; 32 ] . into ( ) ;
117128 let streams = BTreeMap :: from ( [ ( stream_id, Percent :: from_percent ( 30 ) ) ] ) ;
118129 let allocation = EmissionAllocation :: Streams ( streams. try_into ( ) . unwrap ( ) ) ;
119- let targets = vec ! [ ( target, 100 ) ] ;
130+ let targets = bounded_btree_map ! [ target => 100 ] ;
120131
121132 let permission_id = ext:: emission_impl:: grant_emission_permission_impl :: < T > (
122133 grantor. clone ( ) ,
@@ -159,7 +170,7 @@ mod benchmarks {
159170 let stream_id: StreamId = [ 0 ; 32 ] . into ( ) ;
160171 let streams = BTreeMap :: from ( [ ( stream_id, Percent :: from_percent ( 30 ) ) ] ) ;
161172 let allocation = EmissionAllocation :: Streams ( streams. try_into ( ) . unwrap ( ) ) ;
162- let targets = vec ! [ ( target, 100 ) ] ;
173+ let targets = bounded_btree_map ! [ target => 100 ] ;
163174
164175 let permission_id = ext:: emission_impl:: grant_emission_permission_impl :: < T > (
165176 grantor. clone ( ) ,
@@ -201,7 +212,7 @@ mod benchmarks {
201212 let stream_id: StreamId = [ 0 ; 32 ] . into ( ) ;
202213 let streams = BTreeMap :: from ( [ ( stream_id, Percent :: from_percent ( 30 ) ) ] ) ;
203214 let allocation = EmissionAllocation :: Streams ( streams. try_into ( ) . unwrap ( ) ) ;
204- let targets = vec ! [ ( target, 100 ) ] ;
215+ let targets = bounded_btree_map ! [ target => 100 ] ;
205216 let controllers = vec ! [ controller. clone( ) ] . try_into ( ) . unwrap ( ) ;
206217
207218 let enforcement = EnforcementAuthority :: ControlledBy {
@@ -250,7 +261,7 @@ mod benchmarks {
250261 let stream_id: StreamId = [ 0 ; 32 ] . into ( ) ;
251262 let streams = BTreeMap :: from ( [ ( stream_id, Percent :: from_percent ( 30 ) ) ] ) ;
252263 let allocation = EmissionAllocation :: Streams ( streams. try_into ( ) . unwrap ( ) ) ;
253- let targets = vec ! [ ( target, 100 ) ] ;
264+ let targets = bounded_btree_map ! [ target => 100 ] ;
254265
255266 let permission_id = ext:: emission_impl:: grant_emission_permission_impl :: < T > (
256267 grantor. clone ( ) ,
@@ -266,16 +277,15 @@ mod benchmarks {
266277 . expect ( "failed to grant permission" ) ;
267278
268279 // Prepare new controllers
269- let controllers = vec ! [ controller1, controller2] ;
280+ let controllers = vec ! [ controller1, controller2] . try_into ( ) . unwrap ( ) ;
270281 let required_votes = 1u32 ;
271-
272- #[ extrinsic_call]
273- set_enforcement_authority (
274- RawOrigin :: Signed ( grantor) ,
275- permission_id,
282+ let enforcement = EnforcementAuthority :: ControlledBy {
276283 controllers,
277284 required_votes,
278- )
285+ } ;
286+
287+ #[ extrinsic_call]
288+ set_enforcement_authority ( RawOrigin :: Signed ( grantor) , permission_id, enforcement)
279289 }
280290
281291 #[ benchmark]
0 commit comments