Fix benchmarks and adds CI to test them (#12068)

* Fix benchmarks and adds CI to test them

Instead of waiting for benchmarks failing in Polkadot CI, we also can just test them in Substrate :P

* Do not overflow
This commit is contained in:
Bastian Köcher
2022-08-19 13:07:14 +02:00
committed by GitHub
parent 13fa566590
commit 9d75f3e3e7
7 changed files with 40 additions and 9 deletions
@@ -43,7 +43,9 @@ fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
fn funded_account<T: Config>(name: &'static str, index: u32) -> T::AccountId {
let caller: T::AccountId = account(name, index, SEED);
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
// Give the account half of the maximum value of the `Balance` type.
// Otherwise some transfers will fail with an overflow error.
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value() / 2u32.into());
caller
}
+4 -2
View File
@@ -120,7 +120,8 @@ benchmarks! {
let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
ensure!(Registrars::<T>::get().len() as u32 == r, "Registrars not set up correctly.");
let origin = T::RegistrarOrigin::successful_origin();
}: _<T::Origin>(origin, account("registrar", r + 1, SEED))
let account = T::Lookup::unlookup(account("registrar", r + 1, SEED));
}: _<T::Origin>(origin, account)
verify {
ensure!(Registrars::<T>::get().len() as u32 == r + 1, "Registrars not added.");
}
@@ -287,7 +288,8 @@ benchmarks! {
Identity::<T>::add_registrar(registrar_origin, caller_lookup)?;
let registrars = Registrars::<T>::get();
ensure!(registrars[r as usize].as_ref().unwrap().account == caller, "id not set.");
}: _(RawOrigin::Signed(caller), r, account("new", 0, SEED))
let new_account = T::Lookup::unlookup(account("new", 0, SEED));
}: _(RawOrigin::Signed(caller), r, new_account)
verify {
let registrars = Registrars::<T>::get();
ensure!(registrars[r as usize].as_ref().unwrap().account == account("new", 0, SEED), "id not changed.");
@@ -305,7 +305,7 @@ benchmarks! {
verify {
let bond_amount: u32 = UniqueSaturatedInto::<u32>::unique_saturated_into(bond_amount::<T>());
let slash_amount = slash_fraction * bond_amount;
let reward_amount = slash_amount * (1 + n) / 2;
let reward_amount = slash_amount.saturating_mul(1 + n) / 2;
let reward = reward_amount / r;
let slash = |id| core::iter::once(
<T as StakingConfig>::Event::from(StakingEvent::<T>::Slashed(id, BalanceOf::<T>::from(slash_amount)))
+7 -3
View File
@@ -35,9 +35,11 @@ fn add_proxies<T: Config>(n: u32, maybe_who: Option<T::AccountId>) -> Result<(),
let caller = maybe_who.unwrap_or_else(whitelisted_caller);
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value() / 2u32.into());
for i in 0..n {
let real = T::Lookup::unlookup(account("target", i, SEED));
Proxy::<T>::add_proxy(
RawOrigin::Signed(caller.clone()).into(),
account("target", i, SEED),
real,
T::ProxyType::default(),
T::BlockNumber::zero(),
)?;
@@ -180,9 +182,10 @@ benchmarks! {
add_proxy {
let p in 1 .. (T::MaxProxies::get() - 1) => add_proxies::<T>(p, None)?;
let caller: T::AccountId = whitelisted_caller();
let real = T::Lookup::unlookup(account("target", T::MaxProxies::get(), SEED));
}: _(
RawOrigin::Signed(caller.clone()),
account("target", T::MaxProxies::get(), SEED),
real,
T::ProxyType::default(),
T::BlockNumber::zero()
)
@@ -194,9 +197,10 @@ benchmarks! {
remove_proxy {
let p in 1 .. (T::MaxProxies::get() - 1) => add_proxies::<T>(p, None)?;
let caller: T::AccountId = whitelisted_caller();
let delegate = T::Lookup::unlookup(account("target", 0, SEED));
}: _(
RawOrigin::Signed(caller.clone()),
account("target", 0, SEED),
delegate,
T::ProxyType::default(),
T::BlockNumber::zero()
)