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

tests: bench use lab verifier key as mock. #149

Merged
merged 12 commits into from
Nov 12, 2021
274 changes: 150 additions & 124 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,15 @@

//! Service implementation. Specialized wrapper over substrate service.

use codec::Encode;
use frame_system_rpc_runtime_api::AccountNonceApi;
use debio_runtime::{opaque::Block, RuntimeApi};
use sc_client_api::{BlockBackend, ExecutorProvider, RemoteBackend};
use sc_client_api::{ExecutorProvider, RemoteBackend};
use sc_consensus_babe::{self, SlotProportion};
use sc_executor::NativeElseWasmExecutor;
use sc_finality_grandpa as grandpa;
use sc_network::NetworkService;
use sc_service::{config::Configuration, error::Error as ServiceError, RpcHandlers, TaskManager};
use sc_telemetry::{Telemetry, TelemetryWorker};
use sp_api::ProvideRuntimeApi;
use sp_core::crypto::Pair;
use sp_runtime::{generic, traits::Block as BlockT, SaturatedConversion};
use sp_runtime::{traits::Block as BlockT};
use std::sync::Arc;

// Our native executor instance.
Expand Down
3 changes: 3 additions & 0 deletions pallets/certifications/benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ sp-runtime = { git = 'https://github.com/paritytech/substrate.git', branch = 'po

labs = { path = '../../labs', default-features = false }
certifications = { path = '../../certifications', default-features = false }

primitives-area-code = { path = '../../../primitives/area-code', default-features = false }
traits-certifications = { path = '../../../traits/certifications', default-features = false }

[dev-dependencies]
Expand All @@ -55,5 +57,6 @@ std = [
'labs/std',
'certifications/std',

'primitives-area-code/std',
'traits-certifications/std',
]
19 changes: 10 additions & 9 deletions pallets/certifications/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub trait Config:

use certifications::Call;
use frame_support::sp_runtime::traits::Hash;
use primitives_area_code::{CountryCode, RegionCode, CityCode};

benchmarks! {
create_certification {
Expand All @@ -37,9 +38,9 @@ benchmarks! {
box_public_key: T::Hashing::hash("0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes()),
name: "DeBio Lab".as_bytes().to_vec(),
email: "DeBio Email".as_bytes().to_vec(),
country: "DeBio Country".as_bytes().to_vec(),
region: "DeBio Region".as_bytes().to_vec(),
city: "DeBio City".as_bytes().to_vec(),
country: CountryCode::from_vec("DC".as_bytes().to_vec()),
region: RegionCode::from_vec("DBIO".as_bytes().to_vec()),
city: CityCode::from_vec("City".as_bytes().to_vec()),
address: "DeBio Address".as_bytes().to_vec(),
phone_number: "+6281394653625".as_bytes().to_vec(),
website: "DeBio Website".as_bytes().to_vec(),
Expand Down Expand Up @@ -67,9 +68,9 @@ benchmarks! {
box_public_key: T::Hashing::hash("0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes()),
name: "DeBio Lab".as_bytes().to_vec(),
email: "DeBio Email".as_bytes().to_vec(),
country: "DeBio Country".as_bytes().to_vec(),
region: "DeBio Region".as_bytes().to_vec(),
city: "DeBio City".as_bytes().to_vec(),
country: CountryCode::from_vec("DC".as_bytes().to_vec()),
region: RegionCode::from_vec("DBIO".as_bytes().to_vec()),
city: CityCode::from_vec("City".as_bytes().to_vec()),
address: "DeBio Address".as_bytes().to_vec(),
phone_number: "+6281394653625".as_bytes().to_vec(),
website: "DeBio Website".as_bytes().to_vec(),
Expand Down Expand Up @@ -109,9 +110,9 @@ benchmarks! {
box_public_key: T::Hashing::hash("0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes()),
name: "DeBio Lab".as_bytes().to_vec(),
email: "DeBio Email".as_bytes().to_vec(),
country: "DeBio Country".as_bytes().to_vec(),
region: "DeBio Region".as_bytes().to_vec(),
city: "DeBio City".as_bytes().to_vec(),
country: CountryCode::from_vec("DC".as_bytes().to_vec()),
region: RegionCode::from_vec("DBIO".as_bytes().to_vec()),
city: CityCode::from_vec("City".as_bytes().to_vec()),
address: "DeBio Address".as_bytes().to_vec(),
phone_number: "+6281394653625".as_bytes().to_vec(),
website: "DeBio Website".as_bytes().to_vec(),
Expand Down
5 changes: 3 additions & 2 deletions pallets/doctor-certifications/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ sp-std = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkad
sp-io = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false }

doctors = { path = '../doctors', default-features = false }

traits-doctor-certifications = { path = '../../traits/doctor-certifications', default-features = false }

[dev-dependencies]
Expand All @@ -42,8 +41,10 @@ std = [
'frame-support/std',
'frame-system/std',
'sp-io/std',
'traits-doctor-certifications/std',

'doctors/std',

'traits-doctor-certifications/std',
]
runtime-benchmarks = []
try-runtime = ["frame-support/try-runtime"]
3 changes: 3 additions & 0 deletions pallets/doctor-certifications/benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ sp-runtime = { git = 'https://github.com/paritytech/substrate.git', branch = 'po

doctors = { path = '../../doctors', default-features = false }
doctor-certifications = { path = '../../doctor-certifications', default-features = false }

primitives-area-code = { path = '../../../primitives/area-code', default-features = false }
traits-doctor-certifications = { path = '../../../traits/doctor-certifications', default-features = false }

[dev-dependencies]
Expand All @@ -55,5 +57,6 @@ std = [
'doctors/std',
'doctor-certifications/std',

'primitives-area-code/std',
'traits-doctor-certifications/std',
]
19 changes: 10 additions & 9 deletions pallets/doctor-certifications/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub trait Config:
{}

use doctor_certifications::Call;
use primitives_area_code::{CountryCode, RegionCode, CityCode};

benchmarks! {
create_certification {
Expand All @@ -35,9 +36,9 @@ benchmarks! {
let doctor = DoctorInfo {
name: "DeBio Doctor".as_bytes().to_vec(),
email: "DeBio Email".as_bytes().to_vec(),
country: "DeBio Country".as_bytes().to_vec(),
region: "DeBio Region".as_bytes().to_vec(),
city: "DeBio City".as_bytes().to_vec(),
country: CountryCode::from_vec("DC".as_bytes().to_vec()),
region: RegionCode::from_vec("DBIO".as_bytes().to_vec()),
city: CityCode::from_vec("City".as_bytes().to_vec()),
address: "DeBio Address".as_bytes().to_vec(),
latitude: Some("DeBio Latitude".as_bytes().to_vec()),
longitude: Some("DeBio Longtitude".as_bytes().to_vec()),
Expand All @@ -62,9 +63,9 @@ benchmarks! {
let doctor = DoctorInfo {
name: "DeBio Doctor".as_bytes().to_vec(),
email: "DeBio Email".as_bytes().to_vec(),
country: "DeBio Country".as_bytes().to_vec(),
region: "DeBio Region".as_bytes().to_vec(),
city: "DeBio City".as_bytes().to_vec(),
country: CountryCode::from_vec("DC".as_bytes().to_vec()),
region: RegionCode::from_vec("DBIO".as_bytes().to_vec()),
city: CityCode::from_vec("City".as_bytes().to_vec()),
address: "DeBio Address".as_bytes().to_vec(),
latitude: Some("DeBio Latitude".as_bytes().to_vec()),
longitude: Some("DeBio Longtitude".as_bytes().to_vec()),
Expand Down Expand Up @@ -101,9 +102,9 @@ benchmarks! {
let doctor = DoctorInfo {
name: "DeBio Doctor".as_bytes().to_vec(),
email: "DeBio Email".as_bytes().to_vec(),
country: "DeBio Country".as_bytes().to_vec(),
region: "DeBio Region".as_bytes().to_vec(),
city: "DeBio City".as_bytes().to_vec(),
country: CountryCode::from_vec("DC".as_bytes().to_vec()),
region: RegionCode::from_vec("DBIO".as_bytes().to_vec()),
city: CityCode::from_vec("City".as_bytes().to_vec()),
address: "DeBio Address".as_bytes().to_vec(),
latitude: Some("DeBio Latitude".as_bytes().to_vec()),
longitude: Some("DeBio Longtitude".as_bytes().to_vec()),
Expand Down
2 changes: 2 additions & 0 deletions pallets/doctors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ frame-system = { git = 'https://github.com/paritytech/substrate.git', branch = '
sp-std = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false }
sp-io = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false }
frame-benchmarking = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false, optional = true }
primitives-area-code = { path = '../../primitives/area-code', default-features = false }
traits-user-profile = { path = '../../traits/user-profile', default-features = false }
traits-doctor-certifications = { path = '../../traits/doctor-certifications', default-features = false }

Expand All @@ -42,6 +43,7 @@ std = [
'frame-system/std',
'sp-std/std',
'sp-io/std',
'primitives-area-code/std',
'traits-user-profile/std',
'traits-doctor-certifications/std',
]
Expand Down
25 changes: 13 additions & 12 deletions pallets/doctors/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ use crate::Pallet as Doctors;
use crate::DoctorInfo;
use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller};
use frame_system::RawOrigin;
use primitives_area_code::{CountryCode, RegionCode, CityCode};

benchmarks! {
register_doctor {
let doctor = DoctorInfo {
name: "DeBio Doctor".as_bytes().to_vec(),
email: "DeBio Email".as_bytes().to_vec(),
country: "DeBio Country".as_bytes().to_vec(),
region: "DeBio Region".as_bytes().to_vec(),
city: "DeBio City".as_bytes().to_vec(),
country: CountryCode::from_vec("DC".as_bytes().to_vec()),
region: RegionCode::from_vec("DBIO".as_bytes().to_vec()),
city: CityCode::from_vec("City".as_bytes().to_vec()),
address: "DeBio Address".as_bytes().to_vec(),
latitude: Some("DeBio Latitude".as_bytes().to_vec()),
longitude: Some("DeBio Longtitude".as_bytes().to_vec()),
Expand All @@ -32,9 +33,9 @@ benchmarks! {
let old_doctor = DoctorInfo {
name: "DeBio Doctor".as_bytes().to_vec(),
email: "DeBio Email".as_bytes().to_vec(),
country: "DeBio Country".as_bytes().to_vec(),
region: "DeBio Region".as_bytes().to_vec(),
city: "DeBio City".as_bytes().to_vec(),
country: CountryCode::from_vec("DC".as_bytes().to_vec()),
region: RegionCode::from_vec("DBIO".as_bytes().to_vec()),
city: CityCode::from_vec("City".as_bytes().to_vec()),
address: "DeBio Address".as_bytes().to_vec(),
latitude: Some("DeBio Latitude".as_bytes().to_vec()),
longitude: Some("DeBio Longtitude".as_bytes().to_vec()),
Expand All @@ -45,9 +46,9 @@ benchmarks! {
let new_doctor = DoctorInfo {
name: "DeBio Doctor 2".as_bytes().to_vec(),
email: "DeBio Email 2".as_bytes().to_vec(),
country: "DeBio Country 2".as_bytes().to_vec(),
region: "DeBio Region 2".as_bytes().to_vec(),
city: "DeBio City 2".as_bytes().to_vec(),
country: CountryCode::from_vec("C2".as_bytes().to_vec()),
region: RegionCode::from_vec("DBI2".as_bytes().to_vec()),
city: CityCode::from_vec("C2C2".as_bytes().to_vec()),
address: "DeBio Address 2".as_bytes().to_vec(),
latitude: Some("DeBio Latitude 2".as_bytes().to_vec()),
longitude: Some("DeBio Longtitude 2".as_bytes().to_vec()),
Expand All @@ -65,9 +66,9 @@ benchmarks! {
let doctor = DoctorInfo {
name: "DeBio Doctor".as_bytes().to_vec(),
email: "DeBio Email".as_bytes().to_vec(),
country: "DeBio Country".as_bytes().to_vec(),
region: "DeBio Region".as_bytes().to_vec(),
city: "DeBio City".as_bytes().to_vec(),
country: CountryCode::from_vec("DC".as_bytes().to_vec()),
region: RegionCode::from_vec("DBIO".as_bytes().to_vec()),
city: CityCode::from_vec("City".as_bytes().to_vec()),
address: "DeBio Address".as_bytes().to_vec(),
latitude: Some("DeBio Latitude".as_bytes().to_vec()),
longitude: Some("DeBio Longtitude".as_bytes().to_vec()),
Expand Down
5 changes: 3 additions & 2 deletions pallets/doctors/src/interface.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use sp_std::prelude::*;
use primitives_area_code::{CountryRegionCode, CityCode};

/// Interface for Doctor Pallet
/// Defines the functionalities of Doctor Pallet
Expand All @@ -11,8 +12,8 @@ pub trait DoctorInterface<T: frame_system::Config> {
fn doctor_by_account_id(account_id: &T::AccountId) -> Option<Self::Doctor>;
/// Get the account_ids of doctors in a location
fn doctors_by_country_region_city(
country_region_code: &Vec<u8>,
city_code: &Vec<u8>,
country_region_code: &CountryRegionCode,
city_code: &CityCode,
) -> Option<Vec<T::AccountId>>;

/// Store A doctor with its information
Expand Down
37 changes: 21 additions & 16 deletions pallets/doctors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ pub use crate::interface::DoctorInterface;
use frame_support::pallet_prelude::*;
use traits_doctor_certifications::DoctorCertificationOwnerInfo;
use traits_user_profile::UserProfileProvider;
use primitives_area_code::{AreaCode, CountryCode, RegionCode, CityCode, CountryRegionCode};

// DoctorInfo Struct
// Used as parameter of dispatchable calls
#[derive(Encode, Decode, Clone, Default, RuntimeDebug, PartialEq, Eq, TypeInfo)]
pub struct DoctorInfo {
pub name: Vec<u8>,
pub email: Vec<u8>,
pub country: Vec<u8>,
pub region: Vec<u8>,
pub city: Vec<u8>,
pub country: CountryCode,
pub region: RegionCode,
pub city: CityCode,
pub address: Vec<u8>,
pub latitude: Option<Vec<u8>>,
pub longitude: Option<Vec<u8>>,
Expand Down Expand Up @@ -64,20 +65,20 @@ where
self.info = info;
}

fn get_country(&self) -> &Vec<u8> {
fn get_country(&self) -> &CountryCode {
&self.info.country
}

fn get_region(&self) -> &Vec<u8> {
fn get_region(&self) -> &RegionCode {
&self.info.region
}

fn get_city(&self) -> &Vec<u8> {
fn get_city(&self) -> &CityCode {
&self.info.city
}

// Returns CountryCode-RegionCode -> XX-YYY
fn get_country_region(&self) -> Vec<u8> {
fn get_country_region(&self) -> CountryRegionCode {
helpers::build_country_region_code(&self.get_country(), &self.get_region())
}

Expand Down Expand Up @@ -114,19 +115,25 @@ pub mod helpers {
use crate::*;

/// Concatenate CountryCode with RegionCode with a '-'
pub fn build_country_region_code(country_code: &Vec<u8>, region_code: &Vec<u8>) -> Vec<u8> {
pub fn build_country_region_code(country_code: &CountryCode, region_code: &RegionCode) -> CountryRegionCode {
// container
let mut country_region_code = Vec::new();
let mut country_code = country_code.clone();
let mut country_code = country_code.clone()
.to_vec();

// dash character as u8
let mut dash = ['-'].iter().map(|c| *c as u8).collect::<Vec<u8>>();
let mut region_code = region_code.clone();
let mut dash = ['-'].iter()
.map(|c| *c as u8)
.collect::<Vec<u8>>();

let mut region_code = region_code.clone()
.to_vec();

country_region_code.append(&mut country_code);
country_region_code.append(&mut dash);
country_region_code.append(&mut region_code);

country_region_code
CountryRegionCode::from_vec(country_region_code)
}
}

Expand Down Expand Up @@ -179,8 +186,6 @@ pub mod pallet {
pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub type HashOf<T> = <T as frame_system::Config>::Hash;
pub type DoctorOf<T> = Doctor<AccountIdOf<T>, HashOf<T>>;
pub type CountryRegionCode = Vec<u8>; // country_code-region_code -> XX-YYYY
pub type CityCode = Vec<u8>; // city_code -> ZZZZ

// ----- Storage ------------------
/// Get Doctor by account id
Expand Down Expand Up @@ -368,8 +373,8 @@ impl<T: Config> DoctorInterface<T> for Pallet<T> {
}

fn doctors_by_country_region_city(
country_region_code: &Vec<u8>,
city_code: &Vec<u8>,
country_region_code: &CountryRegionCode,
city_code: &CityCode,
) -> Option<Vec<T::AccountId>> {
Self::doctors_by_country_region_city(country_region_code, city_code)
}
Expand Down
3 changes: 3 additions & 0 deletions pallets/genetic-testing/benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ user-profile = { path = '../../user-profile', default-features = false }
orders = { path = '../../orders', default-features = false }
genetic-testing = { path = '../../genetic-testing', default-features = false }


primitives-area-code = { path = '../../../primitives/area-code', default-features = false }
traits-services = { path = '../../../traits/services', default-features = false }
traits-user-profile = { path = '../../../traits/user-profile', default-features = false }
traits-order = { path = '../../../traits/order', default-features = false }
Expand Down Expand Up @@ -64,6 +66,7 @@ std = [
'user-profile/std',
'genetic-testing/std',

'primitives-area-code/std',
'traits-services/std',
'traits-user-profile/std',
'traits-order/std',
Expand Down
Loading