mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 00:31:07 +00:00
Generate Unit Tests for Benchmarks (#5527)
* Update to latest staking * generate tests for benchmarking * add tests, fix warnings * starting on democracy * impl_benchmark_tests * Way more readable * add test feature flag (does this work?) * Fix `successful_origin` impl * democracry benchmark tests * Fix example benchmarks, add tests * identity benchmark tests * Update im-online benchmark tests * try to add session benchmarking tests (problem with mock) * staking and timestamp * add test for treasury, issue with dynamic contains * utility * Vesting * test instead of check * hide until we figure out what is wrong * add docs * close code * Create custom mock for session-pallet-benchmarking * Use refcell pattern * make un-pub * test-linux-stable includes `runtime-benchmarks` feature * Revert "test-linux-stable includes `runtime-benchmarks` feature" This reverts commit a2dab38abd18ac3eb8a6220e4a00e687740bd38c. * run tests in `--release` * undo balance change * build wasm
This commit is contained in:
@@ -217,3 +217,25 @@ benchmarks! {
|
||||
Treasury::<T>::on_initialize(T::BlockNumber::zero());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::tests::{new_test_ext, Test};
|
||||
use frame_support::assert_ok;
|
||||
|
||||
#[test]
|
||||
fn test_benchmarks() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(test_benchmark_propose_spend::<Test>());
|
||||
assert_ok!(test_benchmark_reject_proposal::<Test>());
|
||||
assert_ok!(test_benchmark_approve_proposal::<Test>());
|
||||
assert_ok!(test_benchmark_report_awesome::<Test>());
|
||||
assert_ok!(test_benchmark_retract_tip::<Test>());
|
||||
assert_ok!(test_benchmark_tip_new::<Test>());
|
||||
assert_ok!(test_benchmark_tip::<Test>());
|
||||
assert_ok!(test_benchmark_close_tip::<Test>());
|
||||
assert_ok!(test_benchmark_on_initialize::<Test>());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#![cfg(test)]
|
||||
|
||||
use super::*;
|
||||
|
||||
use std::cell::RefCell;
|
||||
use frame_support::{
|
||||
assert_noop, assert_ok, impl_outer_origin, parameter_types, weights::Weight,
|
||||
traits::{Contains, OnInitialize}
|
||||
@@ -74,16 +74,24 @@ impl pallet_balances::Trait for Test {
|
||||
type ExistentialDeposit = ExistentialDeposit;
|
||||
type AccountStore = System;
|
||||
}
|
||||
thread_local! {
|
||||
static TEN_TO_FOURTEEN: RefCell<Vec<u64>> = RefCell::new(vec![10,11,12,13,14]);
|
||||
}
|
||||
pub struct TenToFourteen;
|
||||
impl Contains<u64> for TenToFourteen {
|
||||
fn contains(n: &u64) -> bool {
|
||||
*n >= 10 && *n <= 14
|
||||
}
|
||||
fn sorted_members() -> Vec<u64> {
|
||||
vec![10, 11, 12, 13, 14]
|
||||
TEN_TO_FOURTEEN.with(|v| {
|
||||
v.borrow().clone()
|
||||
})
|
||||
}
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn add(_: &u64) { unimplemented!() }
|
||||
fn add(new: &u64) {
|
||||
TEN_TO_FOURTEEN.with(|v| {
|
||||
let mut members = v.borrow_mut();
|
||||
members.push(*new);
|
||||
members.sort();
|
||||
})
|
||||
}
|
||||
}
|
||||
parameter_types! {
|
||||
pub const ProposalBond: Permill = Permill::from_percent(5);
|
||||
@@ -115,7 +123,7 @@ type System = frame_system::Module<Test>;
|
||||
type Balances = pallet_balances::Module<Test>;
|
||||
type Treasury = Module<Test>;
|
||||
|
||||
fn new_test_ext() -> sp_io::TestExternalities {
|
||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
pallet_balances::GenesisConfig::<Test>{
|
||||
// Total issuance will be 200 with treasury account initialized at ED.
|
||||
|
||||
Reference in New Issue
Block a user