From 74ed6978e19125c3e54362ec21dc70fbad236b24 Mon Sep 17 00:00:00 2001
From: Marcio Diaz <marcio.diaz@gmail.com>
Date: Fri, 13 Mar 2020 10:46:25 +0100
Subject: [PATCH] Fix identity benchmark (#5229)

* Set identity before calling set_subs.

* Remove -1.
---
 substrate/frame/identity/src/benchmarking.rs | 21 ++++++++------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/substrate/frame/identity/src/benchmarking.rs b/substrate/frame/identity/src/benchmarking.rs
index b7a81956a55..87d577c4d8e 100644
--- a/substrate/frame/identity/src/benchmarking.rs
+++ b/substrate/frame/identity/src/benchmarking.rs
@@ -62,6 +62,12 @@ fn add_sub_accounts<T: Trait>(who: T::AccountId, s: u32) -> Result<Vec<(T::Accou
 		let sub_account = account::<T>("sub", i);
 		subs.push((sub_account, data.clone()));
 	}
+
+	// Set identity so `set_subs` does not fail.
+	let _ = T::Currency::make_free_balance_be(&who, BalanceOf::<T>::max_value());
+	let info = create_identity_info::<T>(1);
+	Identity::<T>::set_identity(who_origin.clone().into(), info)?;
+
 	Identity::<T>::set_subs(who_origin.into(), subs.clone())?;
 
 	return Ok(subs)
@@ -147,19 +153,8 @@ benchmarks! {
 
 		let caller = account::<T>("caller", 0);
 		let caller_origin: <T as frame_system::Trait>::Origin = RawOrigin::Signed(caller.clone()).into();
-		let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
-
-		// Create their main identity
-		let info = create_identity_info::<T>(1);
-		Identity::<T>::set_identity(caller_origin, info)?;
-	}: _(RawOrigin::Signed(caller), {
-		let mut subs = Module::<T>::subs(&caller);
-		// Generic data to be used.
-		let data = Data::Raw(vec![0; 32]);
-		// Create an s+1 sub account to add
-		subs.push((account::<T>("sub", s + 1), data));
-		subs
-	})
+		let subs = Module::<T>::subs(&caller);
+	}: _(RawOrigin::Signed(caller), subs)
 
 	clear_identity {
 		let caller = account::<T>("caller", 0);
-- 
GitLab