1919
2020//! Benchmarking
2121
22- use frame_benchmarking:: { account, benchmarks , impl_benchmark_test_suite} ;
22+ use frame_benchmarking:: { account, benchmarks_instance_pallet , impl_benchmark_test_suite} ;
2323use frame_support:: {
2424 crypto:: ecdsa:: ECDSAExt ,
2525 traits:: {
@@ -50,23 +50,23 @@ const SEED: u32 = 0;
5050
5151// Free 2x deposit amount + existential deposit so that we can use this function
5252// to link an account two times to two different DIDs.
53- fn make_free_for_did < T : Config > ( account : & AccountIdOf < T > )
53+ fn make_free_for_did < T : Config < I > , I : ' static > ( account : & AccountIdOf < T > )
5454where
55- <T as Config >:: Currency : Mutate < T :: AccountId > ,
55+ <T as Config < I > >:: Currency : Mutate < T :: AccountId > ,
5656{
57- let balance = <CurrencyOf < T > as Inspect < AccountIdOf < T > > >:: minimum_balance ( )
58- + <T as Config >:: Deposit :: get ( )
59- + <T as Config >:: Deposit :: get ( ) ;
60- CurrencyOf :: < T > :: set_balance ( account, balance) ;
57+ let balance = <CurrencyOf < T , I > as Inspect < AccountIdOf < T > > >:: minimum_balance ( )
58+ + <T as Config < I > >:: Deposit :: get ( )
59+ + <T as Config < I > >:: Deposit :: get ( ) ;
60+ CurrencyOf :: < T , I > :: set_balance ( account, balance) ;
6161}
6262
63- benchmarks ! {
63+ benchmarks_instance_pallet ! {
6464 where_clause {
6565 where
6666 T :: AccountId : From <sr25519:: Public > + From <ed25519:: Public > + Into <LinkableAccountId > + Into <AccountId32 > + From <sp_runtime:: AccountId32 >,
67- T :: DidIdentifier : From <T :: AccountId >,
68- T :: EnsureOrigin : GenerateBenchmarkOrigin <T :: RuntimeOrigin , T :: AccountId , T :: DidIdentifier >,
69- <T as Config >:: Currency : Mutate <T :: AccountId >,
67+ < T as Config < I >> :: DidIdentifier : From <T :: AccountId >,
68+ < T as Config < I >> :: EnsureOrigin : GenerateBenchmarkOrigin <T :: RuntimeOrigin , T :: AccountId , < T as Config < I >> :: DidIdentifier >,
69+ <T as Config < I > >:: Currency : Mutate <T :: AccountId >,
7070 }
7171
7272 associate_account_multisig_sr25519 {
@@ -87,19 +87,19 @@ benchmarks! {
8787 ) )
8888 . ok_or( "Error while building signature." ) ?;
8989
90- make_free_for_did:: <T >( & caller) ;
90+ make_free_for_did:: <T , I >( & caller) ;
9191
9292 // Add existing connected_acc -> previous_did connection that will be replaced
93- Pallet :: <T >:: add_association( caller. clone( ) , previous_did. clone( ) , linkable_id. clone( ) ) . expect( "should create previous association" ) ;
94- assert!( ConnectedAccounts :: <T >:: get( & previous_did, linkable_id. clone( ) ) . is_some( ) ) ;
93+ Pallet :: <T , I >:: add_association( caller. clone( ) , previous_did. clone( ) , linkable_id. clone( ) ) . expect( "should create previous association" ) ;
94+ assert!( ConnectedAccounts :: <T , I >:: get( & previous_did, linkable_id. clone( ) ) . is_some( ) ) ;
9595 let origin = T :: EnsureOrigin :: generate_origin( caller, did. clone( ) ) ;
9696 let id_arg = linkable_id. clone( ) ;
9797 let req = AssociateAccountRequest :: Polkadot ( connected_acc_id. into( ) , sig. into( ) ) ;
9898 } : associate_account<T :: RuntimeOrigin >( origin, req, expire_at)
9999 verify {
100- assert!( ConnectedDids :: <T >:: get( linkable_id. clone( ) ) . is_some( ) ) ;
101- assert!( ConnectedAccounts :: <T >:: get( & previous_did, linkable_id. clone( ) ) . is_none( ) ) ;
102- assert!( ConnectedAccounts :: <T >:: get( did, linkable_id) . is_some( ) ) ;
100+ assert!( ConnectedDids :: <T , I >:: get( linkable_id. clone( ) ) . is_some( ) ) ;
101+ assert!( ConnectedAccounts :: <T , I >:: get( & previous_did, linkable_id. clone( ) ) . is_none( ) ) ;
102+ assert!( ConnectedAccounts :: <T , I >:: get( did, linkable_id) . is_some( ) ) ;
103103 }
104104
105105 associate_account_multisig_ed25519 {
@@ -120,19 +120,19 @@ benchmarks! {
120120 ) )
121121 . ok_or( "Error while building signature." ) ?;
122122
123- make_free_for_did:: <T >( & caller) ;
123+ make_free_for_did:: <T , I >( & caller) ;
124124
125125 // Add existing connected_acc -> previous_did connection that will be replaced
126- Pallet :: <T >:: add_association( caller. clone( ) , previous_did. clone( ) , linkable_id. clone( ) ) . expect( "should create previous association" ) ;
127- assert!( ConnectedAccounts :: <T >:: get( & previous_did, linkable_id. clone( ) ) . is_some( ) ) ;
126+ Pallet :: <T , I >:: add_association( caller. clone( ) , previous_did. clone( ) , linkable_id. clone( ) ) . expect( "should create previous association" ) ;
127+ assert!( ConnectedAccounts :: <T , I >:: get( & previous_did, linkable_id. clone( ) ) . is_some( ) ) ;
128128 let origin = T :: EnsureOrigin :: generate_origin( caller, did. clone( ) ) ;
129129 let id_arg = linkable_id. clone( ) ;
130130 let req = AssociateAccountRequest :: Polkadot ( connected_acc_id. into( ) , sig. into( ) ) ;
131131 } : associate_account<T :: RuntimeOrigin >( origin, req, expire_at)
132132 verify {
133- assert!( ConnectedDids :: <T >:: get( linkable_id. clone( ) ) . is_some( ) ) ;
134- assert!( ConnectedAccounts :: <T >:: get( & previous_did, linkable_id. clone( ) ) . is_none( ) ) ;
135- assert!( ConnectedAccounts :: <T >:: get( did, linkable_id) . is_some( ) ) ;
133+ assert!( ConnectedDids :: <T , I >:: get( linkable_id. clone( ) ) . is_some( ) ) ;
134+ assert!( ConnectedAccounts :: <T , I >:: get( & previous_did, linkable_id. clone( ) ) . is_none( ) ) ;
135+ assert!( ConnectedAccounts :: <T , I >:: get( did, linkable_id) . is_some( ) ) ;
136136 }
137137
138138 associate_account_multisig_ecdsa {
@@ -153,19 +153,19 @@ benchmarks! {
153153 ) )
154154 . ok_or( "Error while building signature." ) ?;
155155
156- make_free_for_did:: <T >( & caller) ;
156+ make_free_for_did:: <T , I >( & caller) ;
157157
158158 // Add existing connected_acc -> previous_did connection that will be replaced
159- Pallet :: <T >:: add_association( caller. clone( ) , previous_did. clone( ) , linkable_id. clone( ) ) . expect( "should create previous association" ) ;
160- assert!( ConnectedAccounts :: <T >:: get( & previous_did, linkable_id. clone( ) ) . is_some( ) ) ;
159+ Pallet :: <T , I >:: add_association( caller. clone( ) , previous_did. clone( ) , linkable_id. clone( ) ) . expect( "should create previous association" ) ;
160+ assert!( ConnectedAccounts :: <T , I >:: get( & previous_did, linkable_id. clone( ) ) . is_some( ) ) ;
161161 let origin = T :: EnsureOrigin :: generate_origin( caller, did. clone( ) ) ;
162162 let id_arg = linkable_id. clone( ) ;
163163 let req = AssociateAccountRequest :: Polkadot ( connected_acc_id, sig. into( ) ) ;
164164 } : associate_account<T :: RuntimeOrigin >( origin, req, expire_at)
165165 verify {
166- assert!( ConnectedDids :: <T >:: get( linkable_id. clone( ) ) . is_some( ) ) ;
167- assert!( ConnectedAccounts :: <T >:: get( & previous_did, linkable_id. clone( ) ) . is_none( ) ) ;
168- assert!( ConnectedAccounts :: <T >:: get( did, linkable_id) . is_some( ) ) ;
166+ assert!( ConnectedDids :: <T , I >:: get( linkable_id. clone( ) ) . is_some( ) ) ;
167+ assert!( ConnectedAccounts :: <T , I >:: get( & previous_did, linkable_id. clone( ) ) . is_none( ) ) ;
168+ assert!( ConnectedAccounts :: <T , I >:: get( did, linkable_id) . is_some( ) ) ;
169169 }
170170
171171 associate_eth_account {
@@ -188,18 +188,18 @@ benchmarks! {
188188 & Keccak256 :: digest( wrapped_payload) . try_into( ) . unwrap( ) ,
189189 ) . ok_or( "Error while building signature." ) ?;
190190
191- make_free_for_did:: <T >( & caller) ;
191+ make_free_for_did:: <T , I >( & caller) ;
192192
193193 // Add existing connected_acc -> previous_did connection that will be replaced
194- Pallet :: <T >:: add_association( caller. clone( ) , previous_did. clone( ) , eth_account. into( ) ) . expect( "should create previous association" ) ;
195- assert!( ConnectedAccounts :: <T >:: get( & previous_did, LinkableAccountId :: from( eth_account) ) . is_some( ) ) ;
194+ Pallet :: <T , I >:: add_association( caller. clone( ) , previous_did. clone( ) , eth_account. into( ) ) . expect( "should create previous association" ) ;
195+ assert!( ConnectedAccounts :: <T , I >:: get( & previous_did, LinkableAccountId :: from( eth_account) ) . is_some( ) ) ;
196196 let origin = T :: EnsureOrigin :: generate_origin( caller, did. clone( ) ) ;
197197 let req = AssociateAccountRequest :: Ethereum ( eth_account, sig. into( ) ) ;
198198 } : associate_account<T :: RuntimeOrigin >( origin, req, expire_at)
199199 verify {
200- assert!( ConnectedDids :: <T >:: get( LinkableAccountId :: from( eth_account) ) . is_some( ) ) ;
201- assert!( ConnectedAccounts :: <T >:: get( & previous_did, LinkableAccountId :: from( eth_account) ) . is_none( ) ) ;
202- assert!( ConnectedAccounts :: <T >:: get( did, LinkableAccountId :: from( eth_account) ) . is_some( ) ) ;
200+ assert!( ConnectedDids :: <T , I >:: get( LinkableAccountId :: from( eth_account) ) . is_some( ) ) ;
201+ assert!( ConnectedAccounts :: <T , I >:: get( & previous_did, LinkableAccountId :: from( eth_account) ) . is_none( ) ) ;
202+ assert!( ConnectedAccounts :: <T , I >:: get( did, LinkableAccountId :: from( eth_account) ) . is_some( ) ) ;
203203 }
204204
205205 associate_sender {
@@ -208,69 +208,69 @@ benchmarks! {
208208 let did: T :: DidIdentifier = account( "did" , 0 , SEED ) ;
209209 let previous_did: T :: DidIdentifier = account( "prev" , 0 , SEED + 1 ) ;
210210
211- make_free_for_did:: <T >( & caller) ;
211+ make_free_for_did:: <T , I >( & caller) ;
212212
213213 // Add existing sender -> previous_did connection that will be replaced
214- Pallet :: <T >:: add_association( caller. clone( ) , previous_did. clone( ) , caller. clone( ) . into( ) ) . expect( "should create previous association" ) ;
215- assert!( ConnectedAccounts :: <T >:: get( & previous_did, & linkable_id) . is_some( ) ) ;
214+ Pallet :: <T , I >:: add_association( caller. clone( ) , previous_did. clone( ) , caller. clone( ) . into( ) ) . expect( "should create previous association" ) ;
215+ assert!( ConnectedAccounts :: <T , I >:: get( & previous_did, & linkable_id) . is_some( ) ) ;
216216 let origin = T :: EnsureOrigin :: generate_origin( caller, did. clone( ) ) ;
217217 } : _<T :: RuntimeOrigin >( origin)
218218 verify {
219- assert!( ConnectedDids :: <T >:: get( & linkable_id) . is_some( ) ) ;
220- assert!( ConnectedAccounts :: <T >:: get( previous_did, & linkable_id) . is_none( ) ) ;
221- assert!( ConnectedAccounts :: <T >:: get( did, linkable_id) . is_some( ) ) ;
219+ assert!( ConnectedDids :: <T , I >:: get( & linkable_id) . is_some( ) ) ;
220+ assert!( ConnectedAccounts :: <T , I >:: get( previous_did, & linkable_id) . is_none( ) ) ;
221+ assert!( ConnectedAccounts :: <T , I >:: get( did, linkable_id) . is_some( ) ) ;
222222 }
223223
224224 remove_sender_association {
225225 let caller: T :: AccountId = account( "caller" , 0 , SEED ) ;
226226 let linkable_id: LinkableAccountId = caller. clone( ) . into( ) ;
227227 let did: T :: DidIdentifier = account( "did" , 0 , SEED ) ;
228228
229- make_free_for_did:: <T >( & caller) ;
230- Pallet :: <T >:: add_association( caller. clone( ) , did. clone( ) , linkable_id. clone( ) ) . expect( "should create association" ) ;
229+ make_free_for_did:: <T , I >( & caller) ;
230+ Pallet :: <T , I >:: add_association( caller. clone( ) , did. clone( ) , linkable_id. clone( ) ) . expect( "should create association" ) ;
231231
232232 let origin = RawOrigin :: Signed ( caller) ;
233233 } : _( origin)
234234 verify {
235- assert!( ConnectedDids :: <T >:: get( & linkable_id) . is_none( ) ) ;
236- assert!( ConnectedAccounts :: <T >:: get( did, linkable_id) . is_none( ) ) ;
235+ assert!( ConnectedDids :: <T , I >:: get( & linkable_id) . is_none( ) ) ;
236+ assert!( ConnectedAccounts :: <T , I >:: get( did, linkable_id) . is_none( ) ) ;
237237 }
238238
239239 remove_account_association {
240240 let caller: T :: AccountId = account( "caller" , 0 , SEED ) ;
241241 let linkable_id: LinkableAccountId = caller. clone( ) . into( ) ;
242242 let did: T :: DidIdentifier = account( "did" , 0 , SEED ) ;
243- make_free_for_did:: <T >( & caller) ;
243+ make_free_for_did:: <T , I >( & caller) ;
244244
245- Pallet :: <T >:: add_association( caller. clone( ) , did. clone( ) , linkable_id. clone( ) ) . expect( "should create association" ) ;
245+ Pallet :: <T , I >:: add_association( caller. clone( ) , did. clone( ) , linkable_id. clone( ) ) . expect( "should create association" ) ;
246246
247247 let origin = T :: EnsureOrigin :: generate_origin( caller, did. clone( ) ) ;
248248 let id_arg = linkable_id. clone( ) ;
249249 } : _<T :: RuntimeOrigin >( origin, id_arg)
250250 verify {
251- assert!( ConnectedDids :: <T >:: get( & linkable_id) . is_none( ) ) ;
252- assert!( ConnectedAccounts :: <T >:: get( did, linkable_id) . is_none( ) ) ;
251+ assert!( ConnectedDids :: <T , I >:: get( & linkable_id) . is_none( ) ) ;
252+ assert!( ConnectedAccounts :: <T , I >:: get( did, linkable_id) . is_none( ) ) ;
253253 }
254254
255255 change_deposit_owner {
256256 let deposit_owner_old: T :: AccountId = account( "caller" , 0 , SEED ) ;
257257 let deposit_owner_new: T :: AccountId = account( "caller" , 1 , SEED ) ;
258258 let linkable_id: LinkableAccountId = deposit_owner_old. clone( ) . into( ) ;
259259 let did: T :: DidIdentifier = account( "did" , 0 , SEED ) ;
260- make_free_for_did:: <T >( & deposit_owner_old) ;
261- make_free_for_did:: <T >( & deposit_owner_new) ;
260+ make_free_for_did:: <T , I >( & deposit_owner_old) ;
261+ make_free_for_did:: <T , I >( & deposit_owner_new) ;
262262
263- Pallet :: <T >:: add_association( deposit_owner_old, did. clone( ) , linkable_id. clone( ) ) . expect( "should create association" ) ;
263+ Pallet :: <T , I >:: add_association( deposit_owner_old, did. clone( ) , linkable_id. clone( ) ) . expect( "should create association" ) ;
264264
265265 let origin = T :: EnsureOrigin :: generate_origin( deposit_owner_new. clone( ) , did) ;
266266 let id_arg = linkable_id. clone( ) ;
267267 } : _<T :: RuntimeOrigin >( origin, id_arg)
268268 verify {
269269 assert_eq!(
270- ConnectedDids :: <T >:: get( & linkable_id) . expect( "should retain link" ) . deposit,
270+ ConnectedDids :: <T , I >:: get( & linkable_id) . expect( "should retain link" ) . deposit,
271271 Deposit {
272272 owner: deposit_owner_new,
273- amount: <T as Config >:: Deposit :: get( ) ,
273+ amount: <T as Config < I > >:: Deposit :: get( ) ,
274274 } ,
275275 ) ;
276276 }
@@ -279,9 +279,9 @@ benchmarks! {
279279 let deposit_owner: T :: AccountId = account( "caller" , 0 , SEED ) ;
280280 let linkable_id: LinkableAccountId = deposit_owner. clone( ) . into( ) ;
281281 let did: T :: DidIdentifier = account( "did" , 0 , SEED ) ;
282- make_free_for_did:: <T >( & deposit_owner) ;
282+ make_free_for_did:: <T , I >( & deposit_owner) ;
283283
284- Pallet :: <T >:: add_association(
284+ Pallet :: <T , I >:: add_association(
285285 deposit_owner. clone( ) ,
286286 did,
287287 linkable_id. clone( )
@@ -292,10 +292,10 @@ benchmarks! {
292292 } : _( origin, id_arg)
293293 verify {
294294 assert_eq!(
295- ConnectedDids :: <T >:: get( & linkable_id) . expect( "should retain link" ) . deposit,
295+ ConnectedDids :: <T , I >:: get( & linkable_id) . expect( "should retain link" ) . deposit,
296296 Deposit {
297297 owner: deposit_owner,
298- amount: <T as Config >:: Deposit :: get( ) ,
298+ amount: <T as Config < I > >:: Deposit :: get( ) ,
299299 } ,
300300 ) ;
301301 }
0 commit comments