Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix benchmarking (on top of v2) #1148

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 13 additions & 5 deletions pallets/tasks/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@ use polkadot_sdk::{frame_benchmarking, frame_support, frame_system, sp_std};
use sp_std::vec;
use time_primitives::{
NetworkId, ShardStatus, ShardsInterface, Task, TaskResult, TasksInterface, TssPublicKey,
TssSignature,
};

const ETHEREUM: NetworkId = 0;
// Generated by running tests::bench_helper::print_valid_result
const PUBKEY: TssPublicKey = [
2, 36, 79, 43, 160, 29, 26, 4, 168, 242, 35, 104, 66, 1, 179, 183, 189, 197, 92, 84, 2, 101,
52, 245, 230, 250, 199, 131, 188, 204, 228, 70, 248,
2, 121, 190, 102, 126, 249, 220, 187, 172, 85, 160, 98, 149, 206, 135, 11, 7, 2, 155, 252, 219,
45, 206, 40, 217, 89, 242, 129, 91, 22, 248, 23, 152,
];
const SIGNATURE: TssSignature = [
119, 119, 90, 235, 7, 120, 43, 92, 165, 239, 64, 155, 193, 120, 121, 158, 221, 101, 67, 71, 77,
30, 153, 33, 133, 21, 151, 152, 72, 54, 125, 208, 207, 130, 157, 92, 45, 249, 30, 88, 128, 186,
115, 60, 151, 220, 75, 88, 253, 91, 155, 144, 186, 107, 101, 60, 63, 169, 178, 192, 80, 234,
63, 100,
];

fn create_simple_task<T: Config + pallet_shards::Config>() {
const ETHEREUM: NetworkId = 0;
<T as Config>::Shards::create_shard(
ETHEREUM,
[[0u8; 32].into(), [1u8; 32].into(), [2u8; 32].into()].to_vec(),
Expand All @@ -34,8 +42,8 @@ benchmarks! {

submit_task_result {
create_simple_task::<T>();
let result = TaskResult::ReadGatewayEvents { events: vec![], signature: [0; 64] };
}: _(RawOrigin::Root, 0, result) verify {}
let result = TaskResult::ReadGatewayEvents { events: vec![], signature: SIGNATURE };
}: _(RawOrigin::Signed([0u8; 32].into()), 0, result) verify {}

impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
}
22 changes: 21 additions & 1 deletion pallets/tasks/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use time_primitives::{
traits::IdentifyAccount, BatchId, GatewayMessage, GatewayOp, GmpEvent, GmpMessage,
MockTssSigner, NetworkId, PublicKey, ShardId, ShardStatus, ShardsInterface, Task, TaskId,
TaskResult, TasksInterface,
TaskResult, TasksInterface, TssPublicKey, TssSignature,
};

const ETHEREUM: NetworkId = 0;
Expand Down Expand Up @@ -271,3 +271,23 @@
assert_eq!(Tasks::get_shard_tasks(shard), vec![1, 0]);
})
}

mod bench_helper {
use super::*;

fn valid_pk_task_result() -> (TssPublicKey, TssSignature) {
let signer = MockTssSigner::new(SHARD_ID);
const TASK_ID: TaskId = 0;
const SHARD_ID: ShardId = 0;
let signature = signer.sign_gmp_events(TASK_ID, &[]);
(signer.public_key(), signature)
}

#[test]
#[ignore]
fn print_valid_result() {
let (signer, signature) = valid_pk_task_result();
println!("signer: {:?}\nsignature: {:?}", signer, signature);
assert!(false);

Check failure on line 291 in pallets/tasks/src/tests.rs

View workflow job for this annotation

GitHub Actions / test-clippy

error: `assert!(false)` should probably be replaced --> pallets/tasks/src/tests.rs:291:3 | 291 | assert!(false); | ^^^^^^^^^^^^^^ | = help: use `panic!()` or `unreachable!()` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants = note: `-D clippy::assertions-on-constants` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::assertions_on_constants)]`
}
}
Loading