mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 20:31:13 +00:00
Add verify block to benchmark tests (#5551)
* Add verify block to benchmarks macro. * Update all benchmarks. * Add tests, add params. * Should panic. * ups, add closures * Update tests.rs * update macro syntax * Revert benchmark syntax change * verify only in tests * Update tests.rs * Uncomment staking * Fix tests for benchmark instance * Add docs * Update frame/benchmarking/src/lib.rs * add trace logs to benchmarks * Verify returns closure Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -50,7 +50,7 @@ benchmarks_instance! {
|
||||
new_members.push(member);
|
||||
}
|
||||
|
||||
// Set old members.
|
||||
// Set old members.
|
||||
// We compute the difference of old and new members, so it should influence timing.
|
||||
let mut old_members = vec![];
|
||||
for i in 0 .. n {
|
||||
@@ -62,7 +62,11 @@ benchmarks_instance! {
|
||||
|
||||
Collective::<T, _>::set_members(SystemOrigin::Root.into(), old_members, prime.clone())?;
|
||||
|
||||
}: _(SystemOrigin::Root, new_members, prime)
|
||||
}: _(SystemOrigin::Root, new_members.clone(), prime)
|
||||
verify {
|
||||
new_members.sort();
|
||||
assert_eq!(Collective::<T, _>::members(), new_members);
|
||||
}
|
||||
|
||||
execute {
|
||||
let u in ...;
|
||||
@@ -148,7 +152,7 @@ benchmarks_instance! {
|
||||
|
||||
let caller1: T::AccountId = account("caller1", u, SEED);
|
||||
let caller2: T::AccountId = account("caller2", u, SEED);
|
||||
|
||||
|
||||
let proposal: Box<T::Proposal> = Box::new(Call::<T, I>::close(Default::default(), Default::default()).into());
|
||||
let proposal_hash = T::Hashing::hash_of(&proposal);
|
||||
|
||||
@@ -167,7 +171,7 @@ benchmarks_instance! {
|
||||
|
||||
let caller1: T::AccountId = account("caller1", u, SEED);
|
||||
let caller2: T::AccountId = account("caller2", u, SEED);
|
||||
|
||||
|
||||
let proposal: Box<T::Proposal> = Box::new(Call::<T, I>::close(Default::default(), Default::default()).into());
|
||||
let proposal_hash = T::Hashing::hash_of(&proposal);
|
||||
|
||||
@@ -183,3 +187,24 @@ benchmarks_instance! {
|
||||
|
||||
}: _(SystemOrigin::Signed(caller2), proposal_hash, index)
|
||||
}
|
||||
|
||||
#[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_set_members::<Test>());
|
||||
assert_ok!(test_benchmark_execute::<Test>());
|
||||
assert_ok!(test_benchmark_propose::<Test>());
|
||||
assert_ok!(test_benchmark_propose_else_branch::<Test>());
|
||||
assert_ok!(test_benchmark_vote::<Test>());
|
||||
assert_ok!(test_benchmark_vote_not_approve::<Test>());
|
||||
assert_ok!(test_benchmark_vote_approved::<Test>());
|
||||
assert_ok!(test_benchmark_close::<Test>());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -589,7 +589,7 @@ mod tests {
|
||||
}
|
||||
);
|
||||
|
||||
fn make_ext() -> sp_io::TestExternalities {
|
||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
let mut ext: sp_io::TestExternalities = GenesisConfig {
|
||||
collective_Instance1: Some(collective::GenesisConfig {
|
||||
members: vec![1, 2, 3],
|
||||
@@ -603,7 +603,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn motions_basic_environment_works() {
|
||||
make_ext().execute_with(|| {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_eq!(Collective::members(), vec![1, 2, 3]);
|
||||
assert_eq!(Collective::proposals(), Vec::<H256>::new());
|
||||
});
|
||||
@@ -615,7 +615,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn close_works() {
|
||||
make_ext().execute_with(|| {
|
||||
new_test_ext().execute_with(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let hash = BlakeTwo256::hash_of(&proposal);
|
||||
|
||||
@@ -643,7 +643,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn close_with_prime_works() {
|
||||
make_ext().execute_with(|| {
|
||||
new_test_ext().execute_with(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let hash = BlakeTwo256::hash_of(&proposal);
|
||||
assert_ok!(Collective::set_members(Origin::ROOT, vec![1, 2, 3], Some(3)));
|
||||
@@ -666,7 +666,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn close_with_voting_prime_works() {
|
||||
make_ext().execute_with(|| {
|
||||
new_test_ext().execute_with(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let hash = BlakeTwo256::hash_of(&proposal);
|
||||
assert_ok!(Collective::set_members(Origin::ROOT, vec![1, 2, 3], Some(1)));
|
||||
@@ -690,7 +690,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn removal_of_old_voters_votes_works() {
|
||||
make_ext().execute_with(|| {
|
||||
new_test_ext().execute_with(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let hash = BlakeTwo256::hash_of(&proposal);
|
||||
let end = 4;
|
||||
@@ -724,7 +724,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn removal_of_old_voters_votes_works_with_set_members() {
|
||||
make_ext().execute_with(|| {
|
||||
new_test_ext().execute_with(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let hash = BlakeTwo256::hash_of(&proposal);
|
||||
let end = 4;
|
||||
@@ -758,7 +758,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn propose_works() {
|
||||
make_ext().execute_with(|| {
|
||||
new_test_ext().execute_with(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let hash = proposal.blake2_256().into();
|
||||
let end = 4;
|
||||
@@ -787,7 +787,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn motions_ignoring_non_collective_proposals_works() {
|
||||
make_ext().execute_with(|| {
|
||||
new_test_ext().execute_with(|| {
|
||||
let proposal = make_proposal(42);
|
||||
assert_noop!(
|
||||
Collective::propose(Origin::signed(42), 3, Box::new(proposal.clone())),
|
||||
@@ -798,7 +798,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn motions_ignoring_non_collective_votes_works() {
|
||||
make_ext().execute_with(|| {
|
||||
new_test_ext().execute_with(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let hash: H256 = proposal.blake2_256().into();
|
||||
assert_ok!(Collective::propose(Origin::signed(1), 3, Box::new(proposal.clone())));
|
||||
@@ -811,7 +811,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn motions_ignoring_bad_index_collective_vote_works() {
|
||||
make_ext().execute_with(|| {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(3);
|
||||
let proposal = make_proposal(42);
|
||||
let hash: H256 = proposal.blake2_256().into();
|
||||
@@ -825,7 +825,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn motions_revoting_works() {
|
||||
make_ext().execute_with(|| {
|
||||
new_test_ext().execute_with(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let hash: H256 = proposal.blake2_256().into();
|
||||
let end = 4;
|
||||
@@ -876,7 +876,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn motions_reproposing_disapproved_works() {
|
||||
make_ext().execute_with(|| {
|
||||
new_test_ext().execute_with(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let hash: H256 = proposal.blake2_256().into();
|
||||
assert_ok!(Collective::propose(Origin::signed(1), 3, Box::new(proposal.clone())));
|
||||
@@ -889,7 +889,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn motions_disapproval_works() {
|
||||
make_ext().execute_with(|| {
|
||||
new_test_ext().execute_with(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let hash: H256 = proposal.blake2_256().into();
|
||||
assert_ok!(Collective::propose(Origin::signed(1), 3, Box::new(proposal.clone())));
|
||||
@@ -931,7 +931,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn motions_approval_works() {
|
||||
make_ext().execute_with(|| {
|
||||
new_test_ext().execute_with(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let hash: H256 = proposal.blake2_256().into();
|
||||
assert_ok!(Collective::propose(Origin::signed(1), 2, Box::new(proposal.clone())));
|
||||
|
||||
Reference in New Issue
Block a user