Fix Benchmarks to enable batch run (#5523)

* some fixes

* Update tips benchmark to be resiliant to genesis

* Update Cargo.lock
This commit is contained in:
Shawn Tabrizi
2020-04-05 14:27:17 +02:00
committed by GitHub
parent d155a9d97d
commit 392571d78c
3 changed files with 17 additions and 10 deletions
@@ -111,14 +111,15 @@ benchmarks! {
second { second {
let s in 0 .. MAX_SECONDERS; let s in 0 .. MAX_SECONDERS;
let caller = funded_account::<T>("caller", 0);
let proposal_hash = add_proposal::<T>(s)?;
// Create s existing "seconds" // Create s existing "seconds"
for i in 0 .. s { for i in 0 .. s {
let seconder = funded_account::<T>("seconder", i); let seconder = funded_account::<T>("seconder", i);
Democracy::<T>::second(RawOrigin::Signed(seconder).into(), 0)?; Democracy::<T>::second(RawOrigin::Signed(seconder).into(), 0)?;
} }
let caller = funded_account::<T>("caller", 0);
let proposal_hash = add_proposal::<T>(s)?;
}: _(RawOrigin::Signed(caller), 0) }: _(RawOrigin::Signed(caller), 0)
vote { vote {
+3 -3
View File
@@ -219,11 +219,11 @@ benchmarks! {
let c in 0 .. 1000; let c in 0 .. 1000;
}: _(RawOrigin::Root, c) }: _(RawOrigin::Root, c)
force_no_eras { let i in 1 .. 1; }: _(RawOrigin::Root) force_no_eras { let i in 0 .. 1; }: _(RawOrigin::Root)
force_new_era {let i in 1 .. 1; }: _(RawOrigin::Root) force_new_era {let i in 0 .. 1; }: _(RawOrigin::Root)
force_new_era_always { let i in 1 .. 1; }: _(RawOrigin::Root) force_new_era_always { let i in 0 .. 1; }: _(RawOrigin::Root)
// Worst case scenario, the list of invulnerables is very long. // Worst case scenario, the list of invulnerables is very long.
set_invulnerables { set_invulnerables {
+11 -5
View File
@@ -58,12 +58,15 @@ fn setup_awesome<T: Trait>(length: u32) -> (T::AccountId, Vec<u8>, T::AccountId)
fn setup_tip<T: Trait>(r: u32, t: u32) -> fn setup_tip<T: Trait>(r: u32, t: u32) ->
Result<(T::AccountId, Vec<u8>, T::AccountId, BalanceOf<T>), &'static str> Result<(T::AccountId, Vec<u8>, T::AccountId, BalanceOf<T>), &'static str>
{ {
let tippers_count = T::Tippers::count();
for i in 0 .. t { for i in 0 .. t {
let member = account("member", i, SEED); let member = account("member", i, SEED);
T::Tippers::add(&member); T::Tippers::add(&member);
ensure!(T::Tippers::contains(&member), "failed to add tipper");
} }
ensure!(T::Tippers::count() == t as usize, "problem creating tippers"); ensure!(T::Tippers::count() == tippers_count + t as usize, "problem creating tippers");
let caller = account("member", t - 1, SEED); let caller = account("member", t - 1, SEED);
let reason = vec![0; r as usize]; let reason = vec![0; r as usize];
let beneficiary = account("beneficiary", t, SEED); let beneficiary = account("beneficiary", t, SEED);
@@ -71,16 +74,19 @@ fn setup_tip<T: Trait>(r: u32, t: u32) ->
Ok((caller, reason, beneficiary, value)) Ok((caller, reason, beneficiary, value))
} }
// Create `t` new types for the tip proposal with `hash`. // Create `t` new tips for the tip proposal with `hash`.
// This function automatically moves forward the block number to a time which // This function automatically makes the tip able to close.
// would resolve the tipping process.
fn create_tips<T: Trait>(t: u32, hash: T::Hash, value: BalanceOf<T>) -> Result<(), &'static str> { fn create_tips<T: Trait>(t: u32, hash: T::Hash, value: BalanceOf<T>) -> Result<(), &'static str> {
for i in 0 .. t { for i in 0 .. t {
let caller = account("member", i, SEED); let caller = account("member", i, SEED);
ensure!(T::Tippers::contains(&caller), "caller is not a tipper"); ensure!(T::Tippers::contains(&caller), "caller is not a tipper");
Treasury::<T>::tip(RawOrigin::Signed(caller).into(), hash, value)?; Treasury::<T>::tip(RawOrigin::Signed(caller).into(), hash, value)?;
} }
frame_system::Module::<T>::set_block_number(T::TipCountdown::get() * 10.into()); Tips::<T>::mutate(hash, |maybe_tip| {
if let Some(open_tip) = maybe_tip {
open_tip.closes = Some(T::BlockNumber::zero());
}
});
Ok(()) Ok(())
} }