Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests for system Pallet weights
  • Loading branch information
HCastano committed May 12, 2020
commit 7ec270459b7acb44ad76bcae12a8a035328cab1f
47 changes: 47 additions & 0 deletions runtime/polkadot/tests/weights_and_fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ use keyring::AccountKeyring;
use primitives::AccountId;
use polkadot_runtime::{self, Runtime};
use polkadot_runtime::constants::{currency::*, fee::*};
use runtime_common::{MaximumBlockWeight, ExtrinsicBaseWeight};
use staking::Call as StakingCall;
use system::Call as SystemCall;

#[test]
fn sanity_check_weight_per_second_is_as_expected() {
Expand Down Expand Up @@ -191,3 +193,48 @@ fn weight_of_staking_nominate_is_correct() {

assert_eq!(weight, expected_weight);
}

#[test]
fn weight_of_system_set_code_is_correct() {
// #[weight = (T::MaximumBlockWeight::get(), DispatchClass::Operational)]
let expected_weight = MaximumBlockWeight::get();
let weight = SystemCall::set_code::<Runtime>(vec![]).get_dispatch_info().weight;

assert_eq!(weight, expected_weight);
}

#[test]
fn weight_of_system_set_code_without_checks_is_correct() {
// #[weight = (T::MaximumBlockWeight::get(), DispatchClass::Operational)]
let expected_weight = MaximumBlockWeight::get();
let weight = SystemCall::set_code_without_checks::<Runtime>(vec![]).get_dispatch_info().weight;

assert_eq!(weight, expected_weight);
}

#[test]
fn weight_of_system_set_storage_is_correct() {
let storage_items = vec![(vec![12], vec![34])];

// #[weight = FunctionOf(
// |(items,): (&Vec<KeyValue>,)| {
// T::DbWeight::get().writes(items.len() as Weight)
// .saturating_add((items.len() as Weight).saturating_mul(600_000))
// },
// DispatchClass::Operational,
// Pays::Yes,
// )]
let expected_weight = 100_600_000;
let weight = SystemCall::set_storage::<Runtime>(storage_items).get_dispatch_info().weight;

assert_eq!(weight, expected_weight);
}

#[test]
fn weight_of_system_remark_is_correct() {
// #[weight = 700_000]
let expected_weight = 700_000;
let weight = SystemCall::remark::<Runtime>(vec![]).get_dispatch_info().weight;

assert_eq!(weight, expected_weight);
}