diff --git a/Cargo.lock b/Cargo.lock index 755717f9..e0038758 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -828,8 +828,12 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", + "genetic-testing", "labs", + "orders", "pallet-balances", + "pallet-randomness-collective-flip", + "pallet-timestamp", "parity-scale-codec", "primitives-area-code", "scale-info", @@ -839,6 +843,10 @@ dependencies = [ "sp-io", "sp-runtime", "traits-certifications", + "traits-genetic-testing", + "traits-order", + "traits-services", + "traits-user-profile", "user-profile", ] @@ -1376,6 +1384,7 @@ dependencies = [ "hospital-certifications-benchmarking", "hospitals", "labs", + "labs-benchmarking", "log", "orders", "orders-benchmarking", @@ -1403,6 +1412,7 @@ dependencies = [ "scale-info", "serde", "service-request", + "service-request-benchmarking", "services", "services-benchmarking", "sp-api", @@ -2523,6 +2533,7 @@ dependencies = [ "pallet-timestamp", "parity-scale-codec", "primitives-availability-status", + "primitives-stake-status", "primitives-verification-status", "scale-info", "serde", @@ -2556,6 +2567,7 @@ dependencies = [ "pallet-timestamp", "parity-scale-codec", "primitives-availability-status", + "primitives-stake-status", "primitives-verification-status", "scale-info", "serde", @@ -2591,6 +2603,7 @@ dependencies = [ "primitives-availability-status", "primitives-duration", "primitives-price-and-currency", + "primitives-stake-status", "primitives-verification-status", "scale-info", "serde", @@ -3479,8 +3492,77 @@ dependencies = [ "frame-support", "frame-system", "pallet-balances", + "pallet-timestamp", + "parity-scale-codec", + "primitives-area-code", + "primitives-stake-status", + "primitives-verification-status", + "scale-info", + "serde", + "services", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "traits-certifications", + "traits-labs", + "traits-order", + "traits-services", + "traits-user-profile", + "user-profile", +] + +[[package]] +name = "labs-benchmarking" +version = "0.1.0" +dependencies = [ + "certifications", + "frame-benchmarking", + "frame-support", + "frame-system", + "genetic-testing", + "labs", + "orders", + "pallet-balances", + "pallet-randomness-collective-flip", + "pallet-timestamp", + "parity-scale-codec", + "primitives-area-code", + "primitives-stake-status", + "primitives-verification-status", + "scale-info", + "serde", + "services", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "traits-certifications", + "traits-genetic-testing", + "traits-order", + "traits-services", + "traits-user-profile", + "user-profile", +] + +[[package]] +name = "labs-tests" +version = "0.1.0" +dependencies = [ + "certifications", + "frame-benchmarking", + "frame-support", + "frame-system", + "genetic-testing", + "labs", + "orders", + "pallet-balances", + "pallet-randomness-collective-flip", + "pallet-timestamp", "parity-scale-codec", "primitives-area-code", + "primitives-stake-status", + "primitives-verification-status", "scale-info", "serde", "services", @@ -3489,6 +3571,8 @@ dependencies = [ "sp-runtime", "sp-std", "traits-certifications", + "traits-genetic-testing", + "traits-order", "traits-services", "traits-user-profile", "user-profile", @@ -5557,6 +5641,15 @@ dependencies = [ "sp-std", ] +[[package]] +name = "primitives-stake-status" +version = "0.1.0" +dependencies = [ + "frame-support", + "parity-scale-codec", + "scale-info", +] + [[package]] name = "primitives-tracking-id" version = "0.1.0" @@ -7267,18 +7360,52 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", + "genetic-testing", "hex-literal", "labs", + "orders", "pallet-balances", + "pallet-randomness-collective-flip", "pallet-timestamp", "parity-scale-codec", "primitives-area-code", + "primitives-verification-status", "scale-info", "services", "sp-core", "sp-io", "sp-runtime", "sp-std", + "traits-labs", + "user-profile", +] + +[[package]] +name = "service-request-benchmarking" +version = "0.1.0" +dependencies = [ + "certifications", + "frame-benchmarking", + "frame-support", + "frame-system", + "genetic-testing", + "hex-literal", + "labs", + "orders", + "pallet-balances", + "pallet-randomness-collective-flip", + "pallet-timestamp", + "parity-scale-codec", + "primitives-area-code", + "primitives-verification-status", + "scale-info", + "service-request", + "services", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "traits-labs", "user-profile", ] @@ -7327,8 +7454,12 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", + "genetic-testing", "labs", + "orders", "pallet-balances", + "pallet-randomness-collective-flip", + "pallet-timestamp", "parity-scale-codec", "primitives-area-code", "scale-info", @@ -7337,7 +7468,11 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", + "traits-certifications", + "traits-genetic-testing", + "traits-order", "traits-services", + "traits-user-profile", "user-profile", ] @@ -8741,6 +8876,17 @@ dependencies = [ "sp-std", ] +[[package]] +name = "traits-labs" +version = "0.1.0" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "primitives-verification-status", + "scale-info", +] + [[package]] name = "traits-order" version = "0.1.0" diff --git a/docs/pallets/labs.md b/docs/pallets/labs.md index ca8bd7f2..57ed47a8 100644 --- a/docs/pallets/labs.md +++ b/docs/pallets/labs.md @@ -43,4 +43,37 @@ pub fn sudo_update_admin_key( origin: OriginFor, account_id: T::AccountId, ) -> DispatchResultWithPostInfo +``` +### Stake Genetic Analysts +```rust +pub fn stake_genetic_analyst( + origin: OriginFor +) -> DispatchResultWithPostInfo +``` +### Unstake Genetic Analysts +```rust +pub fn unstake_genetic_analyst( + origin: OriginFor +) -> DispatchResultWithPostInfo +``` +### Retrieve Genetic Analysts Unstake Amount +```rust +pub fn retrieve_unstake_amount( + origin: OriginFor, + account_id: T::AccountId, +) -> DispatchResultWithPostInfo +``` +### Update Minimum Stake Amount (Admin Only) +```rust +pub fn update_minimum_stake_amount( + origin: OriginFor, + amount: BalanceOf, +) -> DispatchResultWithPostInfo +``` +### Update Unstake Duration (Admin Only) +```rust +pub fn update_unstake_time( + origin: OriginFor, + amount: MomentOf, +) -> DispatchResultWithPostInfo ``` \ No newline at end of file diff --git a/pallets/certifications/src/weights.rs b/pallets/certifications/src/weights.rs index 62b992e3..dd522546 100644 --- a/pallets/certifications/src/weights.rs +++ b/pallets/certifications/src/weights.rs @@ -1,11 +1,11 @@ //! Autogenerated weights for certifications //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-28, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-04-04, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: -// target/release/debio +// ./target/release/debio // benchmark // --chain=dev // --execution=wasm @@ -42,13 +42,13 @@ impl WeightInfo for SubstrateWeight { // Storage: Certifications CertificationsCount (r:1 w:1) // Storage: Certifications Certifications (r:0 w:1) fn create_certification() -> Weight { - 57_064_000_u64 + 57_605_000_u64 .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } // Storage: Certifications Certifications (r:1 w:1) fn update_certification() -> Weight { - 36_172_000_u64 + 34_856_000_u64 .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -57,7 +57,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Certifications CertificationsCount (r:1 w:1) // Storage: Certifications CertificationsCountByOwner (r:1 w:1) fn delete_certification() -> Weight { - 65_498_000_u64 + 65_267_000_u64 .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -70,13 +70,13 @@ impl WeightInfo for () { // Storage: Certifications CertificationsCount (r:1 w:1) // Storage: Certifications Certifications (r:0 w:1) fn create_certification() -> Weight { - 57_064_000_u64 + 57_605_000_u64 .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } // Storage: Certifications Certifications (r:1 w:1) fn update_certification() -> Weight { - 36_172_000_u64 + 34_856_000_u64 .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -85,7 +85,7 @@ impl WeightInfo for () { // Storage: Certifications CertificationsCount (r:1 w:1) // Storage: Certifications CertificationsCountByOwner (r:1 w:1) fn delete_certification() -> Weight { - 65_498_000_u64 + 65_267_000_u64 .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } diff --git a/pallets/certifications/tests/Cargo.toml b/pallets/certifications/tests/Cargo.toml index 6fa8dd36..2fafcf95 100644 --- a/pallets/certifications/tests/Cargo.toml +++ b/pallets/certifications/tests/Cargo.toml @@ -29,16 +29,25 @@ frame-system = { git = 'https://github.com/paritytech/substrate.git', branch = ' frame-benchmarking = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false, optional = true } ## Substrate Pallet Dependencies +pallet-timestamp = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } pallet-balances = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } +pallet-randomness-collective-flip = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false } # Local Dependencies labs = { path = '../../labs', default-features = false } +orders = { path = '../../orders', default-features = false } services = { path = '../../services', default-features = false } -certifications = { path = '../../certifications', default-features = false } user-profile = { path = '../../user-profile', default-features = false } +certifications = { path = '../../certifications', default-features = false } +genetic-testing = { path = '../../genetic-testing', default-features = false } primitives-area-code = { path = '../../../primitives/area-code', default-features = false } + +traits-order = { path = '../../../traits/order', default-features = false } +traits-services = { path = '../../../traits/services', default-features = false } +traits-user-profile = { path = '../../../traits/user-profile', default-features = false } traits-certifications = { path = '../../../traits/certifications', default-features = false } +traits-genetic-testing = { path = '../../../traits/genetic-testing', default-features = false } [dev-dependencies] serde = { default-features = false, version = "1.0.119" } @@ -47,21 +56,31 @@ serde = { default-features = false, version = "1.0.119" } default = ['std'] std = [ 'codec/std', - - 'sp-io/std', + 'sp-core/std', 'sp-runtime/std', + 'sp-io/std', 'frame-benchmarking/std', 'frame-support/std', 'frame-system/std', 'pallet-balances/std', + 'pallet-timestamp/std', + 'pallet-randomness-collective-flip/std', + + 'traits-order/std', + 'traits-services/std', + 'traits-user-profile/std', + 'traits-certifications/std', + 'traits-genetic-testing/std', 'labs/std', + 'orders/std', 'services/std', - 'certifications/std', 'user-profile/std', + 'certifications/std', + 'genetic-testing/std', 'primitives-area-code/std', 'traits-certifications/std', diff --git a/pallets/certifications/tests/src/mock.rs b/pallets/certifications/tests/src/mock.rs index bcca1643..b16be073 100644 --- a/pallets/certifications/tests/src/mock.rs +++ b/pallets/certifications/tests/src/mock.rs @@ -1,4 +1,4 @@ -use frame_support::parameter_types; +use frame_support::{parameter_types, PalletId}; use frame_system as system; use pallet_balances::AccountData; use scale_info::TypeInfo; @@ -23,11 +23,17 @@ frame_support::construct_runtime!( Labs: labs::{Pallet, Call, Storage, Event}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, Services: services::{Pallet, Call, Storage, Event}, + Orders: orders::{Pallet, Call, Storage, Event}, + GeneticTesting: genetic_testing::{Pallet, Call, Storage, Event}, Certifications: certifications::{Pallet, Call, Storage, Event}, - UserProfile: user_profile::{Pallet, Call, Storage, Event} + UserProfile: user_profile::{Pallet, Call, Storage, Event}, + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, + RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage}, } ); +impl pallet_randomness_collective_flip::Config for Test {} + parameter_types! { pub const BlockHashCount: u64 = 250; pub const SS58Prefix: u8 = 42; @@ -59,10 +65,27 @@ impl system::Config for Test { type OnSetCode = (); } +pub type Moment = u64; +pub const MILLISECS_PER_BLOCK: Moment = 6000; +pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; + +parameter_types! { + pub const MinimumPeriod: Moment = SLOT_DURATION / 2; +} + +impl pallet_timestamp::Config for Test { + /// A timestamp: milliseconds since the unix epoch. + type Moment = Moment; + type OnTimestampSet = (); + type MinimumPeriod = MinimumPeriod; + type WeightInfo = (); +} + type Balance = u64; parameter_types! { pub static ExistentialDeposit: Balance = 0; + pub const LabPalletId: PalletId = PalletId(*b"dbio/lab"); } impl pallet_balances::Config for Test { @@ -83,10 +106,12 @@ impl labs::Config for Test { type Event = Event; type Currency = Balances; type Services = Services; + type Orders = Orders; + type PalletId = LabPalletId; type Certifications = Certifications; type EthereumAddress = EthereumAddress; type UserProfile = UserProfile; - type WeightInfo = (); + type LabWeightInfo = (); } impl services::Config for Test { @@ -102,6 +127,21 @@ impl certifications::Config for Test { type WeightInfo = (); } +impl genetic_testing::Config for Test { + type Event = Event; + type Orders = Orders; + type RandomnessSource = RandomnessCollectiveFlip; + type GeneticTestingWeightInfo = (); +} + +impl orders::Config for Test { + type Event = Event; + type Services = Services; + type GeneticTesting = GeneticTesting; + type Currency = Balances; + type OrdersWeightInfo = (); +} + #[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, Default, RuntimeDebug, TypeInfo)] pub struct EthereumAddress(pub [u8; 20]); diff --git a/pallets/doctor-certifications/src/weights.rs b/pallets/doctor-certifications/src/weights.rs index bddcef9f..0bb48fd9 100644 --- a/pallets/doctor-certifications/src/weights.rs +++ b/pallets/doctor-certifications/src/weights.rs @@ -1,11 +1,11 @@ //! Autogenerated weights for doctor_certifications //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-28, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-04-04, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: -// target/release/debio +// ./target/release/debio // benchmark // --chain=dev // --execution=wasm @@ -42,13 +42,13 @@ impl WeightInfo for SubstrateWeight { // Storage: DoctorCertifications DoctorCertificationsCount (r:1 w:1) // Storage: DoctorCertifications DoctorCertifications (r:0 w:1) fn create_certification() -> Weight { - 58_950_000_u64 + 65_611_000_u64 .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } // Storage: DoctorCertifications DoctorCertifications (r:1 w:1) fn update_certification() -> Weight { - 36_997_000_u64 + 44_102_000_u64 .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -57,7 +57,7 @@ impl WeightInfo for SubstrateWeight { // Storage: DoctorCertifications DoctorCertificationsCount (r:1 w:1) // Storage: DoctorCertifications DoctorCertificationsCountByOwner (r:1 w:1) fn delete_certification() -> Weight { - 65_553_000_u64 + 76_233_000_u64 .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -70,13 +70,13 @@ impl WeightInfo for () { // Storage: DoctorCertifications DoctorCertificationsCount (r:1 w:1) // Storage: DoctorCertifications DoctorCertifications (r:0 w:1) fn create_certification() -> Weight { - 58_950_000_u64 + 65_611_000_u64 .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } // Storage: DoctorCertifications DoctorCertifications (r:1 w:1) fn update_certification() -> Weight { - 36_997_000_u64 + 44_102_000_u64 .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -85,7 +85,7 @@ impl WeightInfo for () { // Storage: DoctorCertifications DoctorCertificationsCount (r:1 w:1) // Storage: DoctorCertifications DoctorCertificationsCountByOwner (r:1 w:1) fn delete_certification() -> Weight { - 65_553_000_u64 + 76_233_000_u64 .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } diff --git a/pallets/doctors/src/weights.rs b/pallets/doctors/src/weights.rs index 83e45f98..6b2c2e97 100644 --- a/pallets/doctors/src/weights.rs +++ b/pallets/doctors/src/weights.rs @@ -1,11 +1,11 @@ //! Autogenerated weights for doctors //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-28, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-04-04, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: -// target/release/debio +// ./target/release/debio // benchmark // --chain=dev // --execution=wasm @@ -42,7 +42,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Doctors DoctorCount (r:1 w:1) // Storage: Doctors DoctorCountByCountryRegionCity (r:1 w:1) fn register_doctor() -> Weight { - 57_982_000_u64 + 78_455_000_u64 .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -50,7 +50,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Doctors DoctorsByCountryRegionCity (r:2 w:2) // Storage: Doctors DoctorCountByCountryRegionCity (r:2 w:2) fn update_doctor() -> Weight { - 82_551_000_u64 + 94_340_000_u64 .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -59,7 +59,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Doctors DoctorCountByCountryRegionCity (r:1 w:1) // Storage: Doctors DoctorCount (r:1 w:1) fn deregister_doctor() -> Weight { - 65_227_000_u64 + 71_163_000_u64 .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -72,7 +72,7 @@ impl WeightInfo for () { // Storage: Doctors DoctorCount (r:1 w:1) // Storage: Doctors DoctorCountByCountryRegionCity (r:1 w:1) fn register_doctor() -> Weight { - 57_982_000_u64 + 78_455_000_u64 .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } @@ -80,7 +80,7 @@ impl WeightInfo for () { // Storage: Doctors DoctorsByCountryRegionCity (r:2 w:2) // Storage: Doctors DoctorCountByCountryRegionCity (r:2 w:2) fn update_doctor() -> Weight { - 82_551_000_u64 + 94_340_000_u64 .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } @@ -89,7 +89,7 @@ impl WeightInfo for () { // Storage: Doctors DoctorCountByCountryRegionCity (r:1 w:1) // Storage: Doctors DoctorCount (r:1 w:1) fn deregister_doctor() -> Weight { - 65_227_000_u64 + 71_163_000_u64 .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } diff --git a/pallets/electronic-medical-record/src/weights.rs b/pallets/electronic-medical-record/src/weights.rs index fc59e272..b0611fc3 100644 --- a/pallets/electronic-medical-record/src/weights.rs +++ b/pallets/electronic-medical-record/src/weights.rs @@ -1,11 +1,11 @@ //! Autogenerated weights for electronic_medical_record //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-28, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-04-04, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: -// target/release/debio +// ./target/release/debio // benchmark // --chain=dev // --execution=wasm @@ -44,7 +44,7 @@ impl WeightInfo for SubstrateWeight { // Storage: ElectronicMedicalRecord ElectronicMedicalRecordFileById (r:0 w:1) // Storage: ElectronicMedicalRecord ElectronicMedicalRecordById (r:0 w:1) fn add_electronic_medical_record() -> Weight { - 65_470_000_u64 + 62_371_000_u64 .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -55,7 +55,7 @@ impl WeightInfo for SubstrateWeight { // Storage: ElectronicMedicalRecord ElectronicMedicalRecordCountByOwner (r:1 w:1) // Storage: Timestamp Now (r:1 w:0) fn update_electronic_medical_record() -> Weight { - 112_985_000_u64 + 107_398_000_u64 .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -65,7 +65,7 @@ impl WeightInfo for SubstrateWeight { // Storage: ElectronicMedicalRecord ElectronicMedicalRecordCount (r:1 w:1) // Storage: ElectronicMedicalRecord ElectronicMedicalRecordCountByOwner (r:1 w:1) fn remove_electronic_medical_record() -> Weight { - 70_049_000_u64 + 71_537_000_u64 .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -80,7 +80,7 @@ impl WeightInfo for () { // Storage: ElectronicMedicalRecord ElectronicMedicalRecordFileById (r:0 w:1) // Storage: ElectronicMedicalRecord ElectronicMedicalRecordById (r:0 w:1) fn add_electronic_medical_record() -> Weight { - 65_470_000_u64 + 62_371_000_u64 .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } @@ -91,7 +91,7 @@ impl WeightInfo for () { // Storage: ElectronicMedicalRecord ElectronicMedicalRecordCountByOwner (r:1 w:1) // Storage: Timestamp Now (r:1 w:0) fn update_electronic_medical_record() -> Weight { - 112_985_000_u64 + 107_398_000_u64 .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } @@ -101,7 +101,7 @@ impl WeightInfo for () { // Storage: ElectronicMedicalRecord ElectronicMedicalRecordCount (r:1 w:1) // Storage: ElectronicMedicalRecord ElectronicMedicalRecordCountByOwner (r:1 w:1) fn remove_electronic_medical_record() -> Weight { - 70_049_000_u64 + 71_537_000_u64 .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } diff --git a/pallets/genetic-analysis-orders/src/weights.rs b/pallets/genetic-analysis-orders/src/weights.rs index 39b5e010..758d9697 100644 --- a/pallets/genetic-analysis-orders/src/weights.rs +++ b/pallets/genetic-analysis-orders/src/weights.rs @@ -1,11 +1,11 @@ //! Autogenerated weights for genetic_analysis_orders //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-28, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-04-04, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: -// target/release/debio +// ./target/release/debio // benchmark // --chain=dev // --execution=wasm @@ -55,7 +55,7 @@ impl WeightInfo for SubstrateWeight { // Storage: GeneticAnalysisOrders GeneticAnalysisOrders (r:0 w:1) // Storage: GeneticAnalysisOrders LastGeneticAnalysisOrderByCustomer (r:0 w:1) fn create_genetic_analysis_order() -> Weight { - 129_797_000_u64 + 127_267_000_u64 .saturating_add(T::DbWeight::get().reads(12_u64)) .saturating_add(T::DbWeight::get().writes(8_u64)) } @@ -63,7 +63,7 @@ impl WeightInfo for SubstrateWeight { // Storage: GeneticAnalysis GeneticAnalysisStorage (r:1 w:1) // Storage: Timestamp Now (r:1 w:0) fn cancel_genetic_analysis_order() -> Weight { - 49_122_000_u64 + 46_003_000_u64 .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -74,7 +74,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Timestamp Now (r:1 w:0) // Storage: GeneticAnalysisOrders TotalEscrowAmount (r:0 w:1) fn set_genetic_analysis_order_paid() -> Weight { - 63_591_000_u64 + 59_514_000_u64 .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -86,7 +86,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Timestamp Now (r:1 w:0) // Storage: GeneticAnalysisOrders TotalEscrowAmount (r:0 w:1) fn fulfill_genetic_analysis_order() -> Weight { - 70_090_000_u64 + 64_943_000_u64 .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -98,13 +98,13 @@ impl WeightInfo for SubstrateWeight { // Storage: Timestamp Now (r:1 w:0) // Storage: GeneticAnalysisOrders TotalEscrowAmount (r:0 w:1) fn set_genetic_analysis_order_refunded() -> Weight { - 71_448_000_u64 + 66_762_000_u64 .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: GeneticAnalysisOrders EscrowKey (r:1 w:1) fn update_escrow_key() -> Weight { - 23_644_000_u64 + 21_943_000_u64 .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -127,7 +127,7 @@ impl WeightInfo for () { // Storage: GeneticAnalysisOrders GeneticAnalysisOrders (r:0 w:1) // Storage: GeneticAnalysisOrders LastGeneticAnalysisOrderByCustomer (r:0 w:1) fn create_genetic_analysis_order() -> Weight { - 129_797_000_u64 + 127_267_000_u64 .saturating_add(RocksDbWeight::get().reads(12_u64)) .saturating_add(RocksDbWeight::get().writes(8_u64)) } @@ -135,7 +135,7 @@ impl WeightInfo for () { // Storage: GeneticAnalysis GeneticAnalysisStorage (r:1 w:1) // Storage: Timestamp Now (r:1 w:0) fn cancel_genetic_analysis_order() -> Weight { - 49_122_000_u64 + 46_003_000_u64 .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -146,7 +146,7 @@ impl WeightInfo for () { // Storage: Timestamp Now (r:1 w:0) // Storage: GeneticAnalysisOrders TotalEscrowAmount (r:0 w:1) fn set_genetic_analysis_order_paid() -> Weight { - 63_591_000_u64 + 59_514_000_u64 .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -158,7 +158,7 @@ impl WeightInfo for () { // Storage: Timestamp Now (r:1 w:0) // Storage: GeneticAnalysisOrders TotalEscrowAmount (r:0 w:1) fn fulfill_genetic_analysis_order() -> Weight { - 70_090_000_u64 + 64_943_000_u64 .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -170,13 +170,13 @@ impl WeightInfo for () { // Storage: Timestamp Now (r:1 w:0) // Storage: GeneticAnalysisOrders TotalEscrowAmount (r:0 w:1) fn set_genetic_analysis_order_refunded() -> Weight { - 71_448_000_u64 + 66_762_000_u64 .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: GeneticAnalysisOrders EscrowKey (r:1 w:1) fn update_escrow_key() -> Weight { - 23_644_000_u64 + 21_943_000_u64 .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } diff --git a/pallets/genetic-analysis/src/weights.rs b/pallets/genetic-analysis/src/weights.rs index 1798f221..3e0891ce 100644 --- a/pallets/genetic-analysis/src/weights.rs +++ b/pallets/genetic-analysis/src/weights.rs @@ -1,11 +1,11 @@ //! Autogenerated weights for genetic_analysis //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-28, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-04-04, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: -// target/release/debio +// ./target/release/debio // benchmark // --chain=dev // --execution=wasm @@ -42,21 +42,21 @@ impl WeightInfo for SubstrateWeight { // Storage: GeneticAnalysisOrders GeneticAnalysisOrders (r:1 w:1) // Storage: GeneticAnalysisOrders PendingGeneticAnalysisOrdersBySeller (r:1 w:1) fn reject_genetic_analysis() -> Weight { - 79_177_000_u64 + 76_543_000_u64 .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } // Storage: GeneticAnalysis GeneticAnalysisStorage (r:1 w:1) // Storage: Timestamp Now (r:1 w:0) fn process_genetic_analysis() -> Weight { - 18_674_000_u64 + 17_850_000_u64 .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: GeneticAnalysis GeneticAnalysisStorage (r:1 w:1) // Storage: Timestamp Now (r:1 w:0) fn submit_genetic_analysis() -> Weight { - 38_238_000_u64 + 35_193_000_u64 .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -69,21 +69,21 @@ impl WeightInfo for () { // Storage: GeneticAnalysisOrders GeneticAnalysisOrders (r:1 w:1) // Storage: GeneticAnalysisOrders PendingGeneticAnalysisOrdersBySeller (r:1 w:1) fn reject_genetic_analysis() -> Weight { - 79_177_000_u64 + 76_543_000_u64 .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } // Storage: GeneticAnalysis GeneticAnalysisStorage (r:1 w:1) // Storage: Timestamp Now (r:1 w:0) fn process_genetic_analysis() -> Weight { - 18_674_000_u64 + 17_850_000_u64 .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: GeneticAnalysis GeneticAnalysisStorage (r:1 w:1) // Storage: Timestamp Now (r:1 w:0) fn submit_genetic_analysis() -> Weight { - 38_238_000_u64 + 35_193_000_u64 .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } diff --git a/pallets/genetic-analyst-qualifications/src/weights.rs b/pallets/genetic-analyst-qualifications/src/weights.rs index 9c8e6a99..802fa799 100644 --- a/pallets/genetic-analyst-qualifications/src/weights.rs +++ b/pallets/genetic-analyst-qualifications/src/weights.rs @@ -1,11 +1,11 @@ //! Autogenerated weights for genetic_analyst_qualifications //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-28, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-04-04, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: -// target/release/debio +// ./target/release/debio // benchmark // --chain=dev // --execution=wasm @@ -43,7 +43,7 @@ impl WeightInfo for SubstrateWeight { // Storage: GeneticAnalystQualifications GeneticAnalystQualificationsCount (r:1 w:1) // Storage: GeneticAnalystQualifications GeneticAnalystQualifications (r:0 w:1) fn create_qualification() -> Weight { - 59_929_000_u64 + 57_501_000_u64 .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -52,13 +52,13 @@ impl WeightInfo for SubstrateWeight { // Storage: GeneticAnalystQualifications GeneticAnalystQualificationsCount (r:1 w:1) // Storage: GeneticAnalystQualifications GeneticAnalystQualifications (r:0 w:20) fn bulk_create_qualification() -> Weight { - 807_467_000_u64 + 751_972_000_u64 .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(23_u64)) } // Storage: GeneticAnalystQualifications GeneticAnalystQualifications (r:1 w:1) fn update_qualification() -> Weight { - 37_626_000_u64 + 33_920_000_u64 .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -67,7 +67,7 @@ impl WeightInfo for SubstrateWeight { // Storage: GeneticAnalystQualifications GeneticAnalystQualificationsCount (r:1 w:1) // Storage: GeneticAnalystQualifications GeneticAnalystQualificationsCountByOwner (r:1 w:1) fn delete_qualification() -> Weight { - 65_276_000_u64 + 60_848_000_u64 .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -80,7 +80,7 @@ impl WeightInfo for () { // Storage: GeneticAnalystQualifications GeneticAnalystQualificationsCount (r:1 w:1) // Storage: GeneticAnalystQualifications GeneticAnalystQualifications (r:0 w:1) fn create_qualification() -> Weight { - 59_929_000_u64 + 57_501_000_u64 .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } @@ -89,13 +89,13 @@ impl WeightInfo for () { // Storage: GeneticAnalystQualifications GeneticAnalystQualificationsCount (r:1 w:1) // Storage: GeneticAnalystQualifications GeneticAnalystQualifications (r:0 w:20) fn bulk_create_qualification() -> Weight { - 807_467_000_u64 + 751_972_000_u64 .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(23_u64)) } // Storage: GeneticAnalystQualifications GeneticAnalystQualifications (r:1 w:1) fn update_qualification() -> Weight { - 37_626_000_u64 + 33_920_000_u64 .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -104,7 +104,7 @@ impl WeightInfo for () { // Storage: GeneticAnalystQualifications GeneticAnalystQualificationsCount (r:1 w:1) // Storage: GeneticAnalystQualifications GeneticAnalystQualificationsCountByOwner (r:1 w:1) fn delete_qualification() -> Weight { - 65_276_000_u64 + 60_848_000_u64 .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } diff --git a/pallets/genetic-analyst-services/src/weights.rs b/pallets/genetic-analyst-services/src/weights.rs index b6925985..9fe1e752 100644 --- a/pallets/genetic-analyst-services/src/weights.rs +++ b/pallets/genetic-analyst-services/src/weights.rs @@ -1,11 +1,11 @@ //! Autogenerated weights for genetic_analyst_services //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-28, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-04-04, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: -// target/release/debio +// ./target/release/debio // benchmark // --chain=dev // --execution=wasm @@ -43,7 +43,7 @@ impl WeightInfo for SubstrateWeight { // Storage: GeneticAnalystServices GeneticAnalystServicesCount (r:1 w:1) // Storage: GeneticAnalystServices GeneticAnalystServices (r:0 w:1) fn create_genetic_analyst_service() -> Weight { - 59_153_000_u64 + 52_574_000_u64 .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -52,13 +52,13 @@ impl WeightInfo for SubstrateWeight { // Storage: GeneticAnalystServices GeneticAnalystServicesCount (r:1 w:1) // Storage: GeneticAnalystServices GeneticAnalystServices (r:0 w:20) fn bulk_create_genetic_analyst_service() -> Weight { - 785_634_000_u64 + 732_026_000_u64 .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(23_u64)) } // Storage: GeneticAnalystServices GeneticAnalystServices (r:1 w:1) fn update_genetic_analyst_service() -> Weight { - 34_196_000_u64 + 31_454_000_u64 .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -67,7 +67,7 @@ impl WeightInfo for SubstrateWeight { // Storage: GeneticAnalystServices GeneticAnalystServicesCount (r:1 w:1) // Storage: GeneticAnalystServices GeneticAnalystServicesCountByOwner (r:1 w:1) fn delete_genetic_analyst_service() -> Weight { - 62_113_000_u64 + 58_115_000_u64 .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -80,7 +80,7 @@ impl WeightInfo for () { // Storage: GeneticAnalystServices GeneticAnalystServicesCount (r:1 w:1) // Storage: GeneticAnalystServices GeneticAnalystServices (r:0 w:1) fn create_genetic_analyst_service() -> Weight { - 59_153_000_u64 + 52_574_000_u64 .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } @@ -89,13 +89,13 @@ impl WeightInfo for () { // Storage: GeneticAnalystServices GeneticAnalystServicesCount (r:1 w:1) // Storage: GeneticAnalystServices GeneticAnalystServices (r:0 w:20) fn bulk_create_genetic_analyst_service() -> Weight { - 785_634_000_u64 + 732_026_000_u64 .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(23_u64)) } // Storage: GeneticAnalystServices GeneticAnalystServices (r:1 w:1) fn update_genetic_analyst_service() -> Weight { - 34_196_000_u64 + 31_454_000_u64 .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -104,7 +104,7 @@ impl WeightInfo for () { // Storage: GeneticAnalystServices GeneticAnalystServicesCount (r:1 w:1) // Storage: GeneticAnalystServices GeneticAnalystServicesCountByOwner (r:1 w:1) fn delete_genetic_analyst_service() -> Weight { - 62_113_000_u64 + 58_115_000_u64 .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } diff --git a/pallets/genetic-analysts/Cargo.toml b/pallets/genetic-analysts/Cargo.toml index 7cbd2484..54754be1 100644 --- a/pallets/genetic-analysts/Cargo.toml +++ b/pallets/genetic-analysts/Cargo.toml @@ -28,6 +28,7 @@ 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 } frame-benchmarking = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false, optional = true } +primitives-stake-status = { path = '../../primitives/stake-status', default-features = false } primitives-verification-status = { path = '../../primitives/verification-status', default-features = false } primitives-availability-status = { path = '../../primitives/availability-status', default-features = false } diff --git a/pallets/genetic-analysts/benchmarking/Cargo.toml b/pallets/genetic-analysts/benchmarking/Cargo.toml index ddec8f8d..daa800fa 100644 --- a/pallets/genetic-analysts/benchmarking/Cargo.toml +++ b/pallets/genetic-analysts/benchmarking/Cargo.toml @@ -26,6 +26,7 @@ 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 } frame-benchmarking = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } +primitives-stake-status = { path = '../../../primitives/stake-status', default-features = false } primitives-verification-status = { path = '../../../primitives/verification-status', default-features = false } primitives-availability-status = { path = '../../../primitives/availability-status', default-features = false } diff --git a/pallets/genetic-analysts/src/lib.rs b/pallets/genetic-analysts/src/lib.rs index 250811a6..64d7c00b 100644 --- a/pallets/genetic-analysts/src/lib.rs +++ b/pallets/genetic-analysts/src/lib.rs @@ -19,6 +19,7 @@ use frame_support::{ PalletId, }; use primitives_availability_status::{AvailabilityStatus, AvailabilityStatusTrait}; +use primitives_stake_status::{StakeStatus, StakeStatusTrait}; use primitives_verification_status::{VerificationStatus, VerificationStatusTrait}; pub use traits_genetic_analysis_orders::{ GeneticAnalysisOrderEventEmitter, GeneticAnalysisOrderStatusUpdater, @@ -27,34 +28,6 @@ use traits_genetic_analyst_qualifications::GeneticAnalystQualificationOwnerInfo; use traits_genetic_analyst_services::GeneticAnalystServiceOwnerInfo; use traits_genetic_analysts::GeneticAnalystsProvider; -#[derive(Encode, Decode, Clone, RuntimeDebug, PartialEq, Eq, TypeInfo)] -pub enum StakeStatus { - Staked, - WaitingForUnstaked, - Unstaked, -} -impl Default for StakeStatus { - fn default() -> Self { - StakeStatus::Unstaked - } -} -pub trait StakeStatusTrait { - fn is_staked(&self) -> bool; - fn is_waiting_for_unstaked(&self) -> bool; - fn is_unstaked(&self) -> bool; -} -impl StakeStatusTrait for StakeStatus { - fn is_staked(&self) -> bool { - matches!(*self, StakeStatus::Staked) - } - fn is_waiting_for_unstaked(&self) -> bool { - matches!(*self, StakeStatus::WaitingForUnstaked) - } - fn is_unstaked(&self) -> bool { - matches!(*self, StakeStatus::Unstaked) - } -} - // GeneticAnalystInfo Struct // Used as parameter of dispatchable calls #[derive(Encode, Decode, Clone, Default, RuntimeDebug, PartialEq, Eq, TypeInfo)] @@ -324,7 +297,7 @@ pub mod pallet { UpdateGeneticAnalystAdminKeySuccessful(AccountIdOf), /// GeneticAnalyst verification failed /// parameters. [GeneticAnalyst, who] - GeneticAnalystverificationFailed(GeneticAnalystOf, AccountIdOf), + GeneticAnalystVerificationFailed(GeneticAnalystOf, AccountIdOf), } // Errors inform users that something went wrong. @@ -339,7 +312,7 @@ pub mod pallet { /// GeneticAnalyst is not the owner of the qualification GeneticAnalystIsNotOwner, /// GeneticAnalyst verification failed - GeneticAnalystverificationFailed, + GeneticAnalystVerificationFailed, /// Insufficient funds InsufficientFunds, /// Insufficient pallet funds diff --git a/pallets/genetic-analysts/src/weights.rs b/pallets/genetic-analysts/src/weights.rs index 83dd6a79..3ad394de 100644 --- a/pallets/genetic-analysts/src/weights.rs +++ b/pallets/genetic-analysts/src/weights.rs @@ -1,11 +1,11 @@ //! Autogenerated weights for genetic_analysts //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-28, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-04-04, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: -// target/release/debio +// ./target/release/debio // benchmark // --chain=dev // --execution=wasm @@ -48,33 +48,33 @@ impl WeightInfo for SubstrateWeight { // Storage: GeneticAnalysts GeneticAnalysts (r:1 w:1) // Storage: GeneticAnalysts GeneticAnalystCount (r:1 w:1) fn register_genetic_analyst() -> Weight { - 36_653_000_u64 + 34_961_000_u64 .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: GeneticAnalysts GeneticAnalysts (r:1 w:1) fn update_genetic_analyst() -> Weight { - 37_541_000_u64 + 34_429_000_u64 .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: GeneticAnalysts GeneticAnalystVerifierKey (r:1 w:0) // Storage: GeneticAnalysts GeneticAnalysts (r:1 w:1) fn update_genetic_analyst_verification_status() -> Weight { - 38_792_000_u64 + 35_243_000_u64 .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: GeneticAnalysts GeneticAnalysts (r:1 w:1) fn update_genetic_analyst_availability_status() -> Weight { - 32_359_000_u64 + 29_880_000_u64 .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: GeneticAnalysts GeneticAnalysts (r:1 w:1) // Storage: GeneticAnalysts GeneticAnalystCount (r:1 w:1) fn deregister_genetic_analyst() -> Weight { - 41_425_000_u64 + 38_802_000_u64 .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -84,7 +84,7 @@ impl WeightInfo for SubstrateWeight { // Storage: GeneticAnalysts PalletAccount (r:1 w:0) // Storage: GeneticAnalysts TotalStakedAmount (r:0 w:1) fn stake_genetic_analyst() -> Weight { - 102_888_000_u64 + 96_499_000_u64 .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -93,7 +93,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Timestamp Now (r:1 w:0) // Storage: GeneticAnalysts UnstakeTime (r:1 w:0) fn unstake_genetic_analyst() -> Weight { - 44_585_000_u64 + 43_049_000_u64 .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -104,27 +104,27 @@ impl WeightInfo for SubstrateWeight { // Storage: System Account (r:1 w:1) // Storage: GeneticAnalysts TotalStakedAmount (r:0 w:1) fn retrieve_unstake_amount() -> Weight { - 87_390_000_u64 + 87_851_000_u64 .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } // Storage: GeneticAnalysts GeneticAnalystVerifierKey (r:1 w:0) // Storage: GeneticAnalysts MinimumStakeAmount (r:0 w:1) fn update_minimum_stake_amount() -> Weight { - 21_657_000_u64 + 20_820_000_u64 .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: GeneticAnalysts GeneticAnalystVerifierKey (r:1 w:0) // Storage: GeneticAnalysts UnstakeTime (r:0 w:1) fn update_unstake_time() -> Weight { - 21_770_000_u64 + 20_878_000_u64 .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: GeneticAnalysts GeneticAnalystVerifierKey (r:1 w:1) fn update_admin_key() -> Weight { - 22_264_000_u64 + 22_067_000_u64 .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -135,33 +135,33 @@ impl WeightInfo for () { // Storage: GeneticAnalysts GeneticAnalysts (r:1 w:1) // Storage: GeneticAnalysts GeneticAnalystCount (r:1 w:1) fn register_genetic_analyst() -> Weight { - 36_653_000_u64 + 34_961_000_u64 .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: GeneticAnalysts GeneticAnalysts (r:1 w:1) fn update_genetic_analyst() -> Weight { - 37_541_000_u64 + 34_429_000_u64 .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: GeneticAnalysts GeneticAnalystVerifierKey (r:1 w:0) // Storage: GeneticAnalysts GeneticAnalysts (r:1 w:1) fn update_genetic_analyst_verification_status() -> Weight { - 38_792_000_u64 + 35_243_000_u64 .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: GeneticAnalysts GeneticAnalysts (r:1 w:1) fn update_genetic_analyst_availability_status() -> Weight { - 32_359_000_u64 + 29_880_000_u64 .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: GeneticAnalysts GeneticAnalysts (r:1 w:1) // Storage: GeneticAnalysts GeneticAnalystCount (r:1 w:1) fn deregister_genetic_analyst() -> Weight { - 41_425_000_u64 + 38_802_000_u64 .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -171,7 +171,7 @@ impl WeightInfo for () { // Storage: GeneticAnalysts PalletAccount (r:1 w:0) // Storage: GeneticAnalysts TotalStakedAmount (r:0 w:1) fn stake_genetic_analyst() -> Weight { - 102_888_000_u64 + 96_499_000_u64 .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } @@ -180,7 +180,7 @@ impl WeightInfo for () { // Storage: Timestamp Now (r:1 w:0) // Storage: GeneticAnalysts UnstakeTime (r:1 w:0) fn unstake_genetic_analyst() -> Weight { - 44_585_000_u64 + 43_049_000_u64 .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -191,27 +191,27 @@ impl WeightInfo for () { // Storage: System Account (r:1 w:1) // Storage: GeneticAnalysts TotalStakedAmount (r:0 w:1) fn retrieve_unstake_amount() -> Weight { - 87_390_000_u64 + 87_851_000_u64 .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } // Storage: GeneticAnalysts GeneticAnalystVerifierKey (r:1 w:0) // Storage: GeneticAnalysts MinimumStakeAmount (r:0 w:1) fn update_minimum_stake_amount() -> Weight { - 21_657_000_u64 + 20_820_000_u64 .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: GeneticAnalysts GeneticAnalystVerifierKey (r:1 w:0) // Storage: GeneticAnalysts UnstakeTime (r:0 w:1) fn update_unstake_time() -> Weight { - 21_770_000_u64 + 20_878_000_u64 .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: GeneticAnalysts GeneticAnalystVerifierKey (r:1 w:1) fn update_admin_key() -> Weight { - 22_264_000_u64 + 22_067_000_u64 .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } diff --git a/pallets/genetic-analysts/tests/Cargo.toml b/pallets/genetic-analysts/tests/Cargo.toml index 0f279dda..adfc1794 100644 --- a/pallets/genetic-analysts/tests/Cargo.toml +++ b/pallets/genetic-analysts/tests/Cargo.toml @@ -36,6 +36,7 @@ frame-benchmarking = { git = 'https://github.com/paritytech/substrate.git', bran primitives-duration = { path = '../../../primitives/duration', default-features = false } primitives-price-and-currency = { path = '../../../primitives/price-and-currency', default-features = false } +primitives-stake-status = { path = '../../../primitives/stake-status', default-features = false } primitives-verification-status = { path = '../../../primitives/verification-status', default-features = false } primitives-availability-status = { path = '../../../primitives/availability-status', default-features = false } diff --git a/pallets/genetic-analysts/tests/src/lib.rs b/pallets/genetic-analysts/tests/src/lib.rs index a40036ea..86d2f03b 100644 --- a/pallets/genetic-analysts/tests/src/lib.rs +++ b/pallets/genetic-analysts/tests/src/lib.rs @@ -6,7 +6,7 @@ mod tests { use genetic_analysts::{ Error, Event as EventC, GeneticAnalyst, GeneticAnalystInfo, GeneticAnalystVerifierKey, - PalletAccount, StakeStatus, + PalletAccount, }; use frame_support::{ @@ -25,6 +25,7 @@ mod tests { use primitives_availability_status::AvailabilityStatus; use primitives_duration::ExpectedDuration; use primitives_price_and_currency::{CurrencyType, PriceByCurrency}; + use primitives_stake_status::StakeStatus; use primitives_verification_status::VerificationStatus; #[test] diff --git a/pallets/genetic-data/src/weights.rs b/pallets/genetic-data/src/weights.rs index 1eb1998b..dc3b5a1c 100644 --- a/pallets/genetic-data/src/weights.rs +++ b/pallets/genetic-data/src/weights.rs @@ -1,11 +1,11 @@ //! Autogenerated weights for genetic_data //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-28, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-04-04, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: -// target/release/debio +// ./target/release/debio // benchmark // --chain=dev // --execution=wasm @@ -43,14 +43,14 @@ impl WeightInfo for SubstrateWeight { // Storage: GeneticData GeneticDataCount (r:1 w:1) // Storage: GeneticData GeneticDataById (r:0 w:1) fn add_genetic_data() -> Weight { - 49_554_000_u64 + 47_075_000_u64 .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } // Storage: GeneticData GeneticDataById (r:1 w:1) // Storage: Timestamp Now (r:1 w:0) fn update_genetic_data() -> Weight { - 34_481_000_u64 + 33_333_000_u64 .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -59,7 +59,7 @@ impl WeightInfo for SubstrateWeight { // Storage: GeneticData GeneticDataCount (r:1 w:1) // Storage: GeneticData GeneticDataCountByOwner (r:1 w:1) fn remove_genetic_data() -> Weight { - 51_557_000_u64 + 50_510_000_u64 .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -73,14 +73,14 @@ impl WeightInfo for () { // Storage: GeneticData GeneticDataCount (r:1 w:1) // Storage: GeneticData GeneticDataById (r:0 w:1) fn add_genetic_data() -> Weight { - 49_554_000_u64 + 47_075_000_u64 .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } // Storage: GeneticData GeneticDataById (r:1 w:1) // Storage: Timestamp Now (r:1 w:0) fn update_genetic_data() -> Weight { - 34_481_000_u64 + 33_333_000_u64 .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -89,7 +89,7 @@ impl WeightInfo for () { // Storage: GeneticData GeneticDataCount (r:1 w:1) // Storage: GeneticData GeneticDataCountByOwner (r:1 w:1) fn remove_genetic_data() -> Weight { - 51_557_000_u64 + 50_510_000_u64 .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } diff --git a/pallets/genetic-testing/src/lib.rs b/pallets/genetic-testing/src/lib.rs index e29cd88c..52a6d9f5 100644 --- a/pallets/genetic-testing/src/lib.rs +++ b/pallets/genetic-testing/src/lib.rs @@ -69,6 +69,9 @@ impl DnaSampleTracking for DnaSample &DnaSampleTrackingId { &self.tracking_id } + fn is_registered(&self) -> bool { + self.status == DnaSampleStatus::Registered + } fn process_success(&self) -> bool { self.status == DnaSampleStatus::ResultReady } @@ -404,6 +407,10 @@ impl GeneticTestingInterface for Pallet { dna_sample.updated_at = now; DnaSamples::::insert(tracking_id, &dna_sample); T::Orders::emit_event_order_failed(&dna_sample.order_id); + T::Orders::remove_order_id_from_pending_orders_by_seller( + &dna_sample.lab_id, + &dna_sample.order_id, + ); T::Orders::update_status_failed(&dna_sample.order_id); Ok(dna_sample) @@ -429,6 +436,10 @@ impl GeneticTestingInterface for Pallet { if result.is_none() { return Err(Error::::DnaTestResultNotYetSubmitted) } + T::Orders::remove_order_id_from_pending_orders_by_seller( + &dna_sample.lab_id, + &dna_sample.order_id, + ); } let now = pallet_timestamp::Pallet::::get(); @@ -584,6 +595,8 @@ impl GeneticTestingProvider for Pallet { } } +use sp_std::vec; + impl Pallet { pub fn generate_random_seed(creator_id: &T::AccountId, owner_id: &T::AccountId) -> Vec { let creator_info = frame_system::Pallet::::account(creator_id); diff --git a/pallets/genetic-testing/src/weights.rs b/pallets/genetic-testing/src/weights.rs index 14e560f2..6956e27c 100644 --- a/pallets/genetic-testing/src/weights.rs +++ b/pallets/genetic-testing/src/weights.rs @@ -1,11 +1,11 @@ //! Autogenerated weights for genetic_testing //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-28, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-04-04, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: -// target/release/debio +// ./target/release/debio // benchmark // --chain=dev // --execution=wasm @@ -42,15 +42,16 @@ impl WeightInfo for SubstrateWeight { // Storage: GeneticTesting DnaSamples (r:1 w:1) // Storage: Timestamp Now (r:1 w:0) // Storage: Orders Orders (r:1 w:1) + // Storage: Orders PendingOrdersBySeller (r:1 w:1) fn reject_dna_sample() -> Weight { - 65_294_000_u64 - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + 83_603_000_u64 + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } // Storage: GeneticTesting DnaSamples (r:1 w:1) // Storage: Timestamp Now (r:1 w:0) fn process_dna_sample() -> Weight { - 17_782_000_u64 + 19_311_000_u64 .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -60,7 +61,7 @@ impl WeightInfo for SubstrateWeight { // Storage: GeneticTesting DnaTestResultsByOwner (r:1 w:1) // Storage: GeneticTesting DnaTestResults (r:0 w:1) fn submit_test_result() -> Weight { - 57_325_000_u64 + 62_008_000_u64 .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -70,14 +71,14 @@ impl WeightInfo for SubstrateWeight { // Storage: GeneticTesting DnaTestResults (r:1 w:1) // Storage: GeneticTesting DnaTestResultsByOwner (r:1 w:1) fn submit_independent_test_result() -> Weight { - 54_105_000_u64 + 57_284_000_u64 .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: GeneticTesting StakedDataByOrderId (r:0 w:1) // Storage: GeneticTesting StakedDataByAccountId (r:0 w:1) fn submit_data_bounty_details() -> Weight { - 23_301_000_u64 + 25_801_000_u64 .saturating_add(T::DbWeight::get().writes(2_u64)) } } @@ -87,15 +88,16 @@ impl WeightInfo for () { // Storage: GeneticTesting DnaSamples (r:1 w:1) // Storage: Timestamp Now (r:1 w:0) // Storage: Orders Orders (r:1 w:1) + // Storage: Orders PendingOrdersBySeller (r:1 w:1) fn reject_dna_sample() -> Weight { - 65_294_000_u64 - .saturating_add(RocksDbWeight::get().reads(3_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) + 83_603_000_u64 + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) } // Storage: GeneticTesting DnaSamples (r:1 w:1) // Storage: Timestamp Now (r:1 w:0) fn process_dna_sample() -> Weight { - 17_782_000_u64 + 19_311_000_u64 .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -105,7 +107,7 @@ impl WeightInfo for () { // Storage: GeneticTesting DnaTestResultsByOwner (r:1 w:1) // Storage: GeneticTesting DnaTestResults (r:0 w:1) fn submit_test_result() -> Weight { - 57_325_000_u64 + 62_008_000_u64 .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } @@ -115,14 +117,14 @@ impl WeightInfo for () { // Storage: GeneticTesting DnaTestResults (r:1 w:1) // Storage: GeneticTesting DnaTestResultsByOwner (r:1 w:1) fn submit_independent_test_result() -> Weight { - 54_105_000_u64 + 57_284_000_u64 .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: GeneticTesting StakedDataByOrderId (r:0 w:1) // Storage: GeneticTesting StakedDataByAccountId (r:0 w:1) fn submit_data_bounty_details() -> Weight { - 23_301_000_u64 + 25_801_000_u64 .saturating_add(RocksDbWeight::get().writes(2_u64)) } } diff --git a/pallets/genetic-testing/tests/src/mock.rs b/pallets/genetic-testing/tests/src/mock.rs index 7f485776..8905d72c 100644 --- a/pallets/genetic-testing/tests/src/mock.rs +++ b/pallets/genetic-testing/tests/src/mock.rs @@ -1,4 +1,4 @@ -use frame_support::parameter_types; +use frame_support::{parameter_types, PalletId}; use pallet_balances::AccountData; use scale_info::TypeInfo; use sp_core::{Decode, Encode, RuntimeDebug, H256}; @@ -68,6 +68,7 @@ pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; parameter_types! { pub const MinimumPeriod: Moment = SLOT_DURATION / 2; + pub const LabPalletId: PalletId = PalletId(*b"dbio/lab"); } impl pallet_timestamp::Config for Test { @@ -119,10 +120,12 @@ impl labs::Config for Test { type Event = Event; type Currency = Balances; type Services = Services; + type Orders = Orders; + type PalletId = LabPalletId; type Certifications = Certifications; type EthereumAddress = EthereumAddress; type UserProfile = UserProfile; - type WeightInfo = (); + type LabWeightInfo = (); } impl services::Config for Test { diff --git a/pallets/hospital-certifications/src/weights.rs b/pallets/hospital-certifications/src/weights.rs index 7576049f..48fea48e 100644 --- a/pallets/hospital-certifications/src/weights.rs +++ b/pallets/hospital-certifications/src/weights.rs @@ -1,11 +1,11 @@ //! Autogenerated weights for hospital_certifications //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-28, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-04-04, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: -// target/release/debio +// ./target/release/debio // benchmark // --chain=dev // --execution=wasm @@ -42,13 +42,13 @@ impl WeightInfo for SubstrateWeight { // Storage: HospitalCertifications HospitalCertificationsCount (r:1 w:1) // Storage: HospitalCertifications HospitalCertifications (r:0 w:1) fn create_certification() -> Weight { - 55_373_000_u64 + 127_740_000_u64 .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } // Storage: HospitalCertifications HospitalCertifications (r:1 w:1) fn update_certification() -> Weight { - 37_131_000_u64 + 90_551_000_u64 .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -57,7 +57,7 @@ impl WeightInfo for SubstrateWeight { // Storage: HospitalCertifications HospitalCertificationsCount (r:1 w:1) // Storage: HospitalCertifications HospitalCertificationsCountByOwner (r:1 w:1) fn delete_certification() -> Weight { - 63_322_000_u64 + 257_375_000_u64 .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -70,13 +70,13 @@ impl WeightInfo for () { // Storage: HospitalCertifications HospitalCertificationsCount (r:1 w:1) // Storage: HospitalCertifications HospitalCertifications (r:0 w:1) fn create_certification() -> Weight { - 55_373_000_u64 + 127_740_000_u64 .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } // Storage: HospitalCertifications HospitalCertifications (r:1 w:1) fn update_certification() -> Weight { - 37_131_000_u64 + 90_551_000_u64 .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -85,7 +85,7 @@ impl WeightInfo for () { // Storage: HospitalCertifications HospitalCertificationsCount (r:1 w:1) // Storage: HospitalCertifications HospitalCertificationsCountByOwner (r:1 w:1) fn delete_certification() -> Weight { - 63_322_000_u64 + 257_375_000_u64 .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } diff --git a/pallets/hospitals/src/weights.rs b/pallets/hospitals/src/weights.rs index ffb28403..19e0375e 100644 --- a/pallets/hospitals/src/weights.rs +++ b/pallets/hospitals/src/weights.rs @@ -1,11 +1,11 @@ //! Autogenerated weights for hospitals //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-28, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-04-04, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: -// target/release/debio +// ./target/release/debio // benchmark // --chain=dev // --execution=wasm @@ -42,7 +42,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Hospitals HospitalCount (r:1 w:1) // Storage: Hospitals HospitalCountByCountryRegionCity (r:1 w:1) fn register_hospital() -> Weight { - 55_620_000_u64 + 59_659_000_u64 .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -50,7 +50,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Hospitals HospitalsByCountryRegionCity (r:2 w:2) // Storage: Hospitals HospitalCountByCountryRegionCity (r:2 w:2) fn update_hospital() -> Weight { - 80_232_000_u64 + 85_113_000_u64 .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -59,7 +59,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Hospitals HospitalCountByCountryRegionCity (r:1 w:1) // Storage: Hospitals HospitalCount (r:1 w:1) fn deregister_hospital() -> Weight { - 63_390_000_u64 + 67_471_000_u64 .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -72,7 +72,7 @@ impl WeightInfo for () { // Storage: Hospitals HospitalCount (r:1 w:1) // Storage: Hospitals HospitalCountByCountryRegionCity (r:1 w:1) fn register_hospital() -> Weight { - 55_620_000_u64 + 59_659_000_u64 .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } @@ -80,7 +80,7 @@ impl WeightInfo for () { // Storage: Hospitals HospitalsByCountryRegionCity (r:2 w:2) // Storage: Hospitals HospitalCountByCountryRegionCity (r:2 w:2) fn update_hospital() -> Weight { - 80_232_000_u64 + 85_113_000_u64 .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } @@ -89,7 +89,7 @@ impl WeightInfo for () { // Storage: Hospitals HospitalCountByCountryRegionCity (r:1 w:1) // Storage: Hospitals HospitalCount (r:1 w:1) fn deregister_hospital() -> Weight { - 63_390_000_u64 + 67_471_000_u64 .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } diff --git a/pallets/labs/Cargo.toml b/pallets/labs/Cargo.toml index af5ed1ef..e6c2e941 100644 --- a/pallets/labs/Cargo.toml +++ b/pallets/labs/Cargo.toml @@ -26,12 +26,19 @@ sp-std = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkad sp-core = { 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-stake-status = { path = '../../primitives/stake-status', default-features = false } +primitives-verification-status = { path = '../../primitives/verification-status', default-features = false } primitives-area-code = { path = '../../primitives/area-code', default-features = false } + +traits-labs = { path = './traits', default-features = false } +traits-order = { path = '../../traits/order', default-features = false } traits-services = { path = '../../traits/services', default-features = false } traits-certifications = { path = '../../traits/certifications', default-features = false } traits-user-profile = { path = '../../traits/user-profile', default-features = false } ## Substrate Pallet Dependencies +pallet-timestamp = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } pallet-balances = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false } # Local Dependencies @@ -53,6 +60,8 @@ std = [ 'sp-std/std', 'sp-io/std', 'primitives-area-code/std', + + 'traits-labs/std', 'traits-services/std', 'traits-certifications/std', 'traits-user-profile/std', diff --git a/pallets/labs/benchmarking/Cargo.toml b/pallets/labs/benchmarking/Cargo.toml new file mode 100644 index 00000000..dc70e978 --- /dev/null +++ b/pallets/labs/benchmarking/Cargo.toml @@ -0,0 +1,93 @@ +[package] +name = 'labs-benchmarking' +version = '0.1.0' +repository = '' +edition = '2018' +authors = ['agustinustheoo '] +description = '' +homepage = '' +license = 'AGPL-3.0' + +[package.metadata.docs.rs] +targets = ['x86_64-unknown-linux-gnu'] + +# alias "parity-scale-code" to "codec" +[dependencies.codec] +default-features = false +features = ['derive'] +package = 'parity-scale-codec' +version = '2.0.0' + +[dependencies] +scale-info = { version = "1.0", default-features = false, features = ["derive"] } + +frame-support = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } +frame-system = { 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 } + +sp-std = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } +sp-core = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } +sp-runtime = { 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 } + +primitives-area-code = { path = '../../../primitives/area-code', default-features = false } +primitives-stake-status = { path = '../../../primitives/stake-status', default-features = false } +primitives-verification-status = { path = '../../../primitives/verification-status', default-features = false } + +traits-order = { path = '../../../traits/order', default-features = false } +traits-services = { path = '../../../traits/services', default-features = false } +traits-user-profile = { path = '../../../traits/user-profile', default-features = false } +traits-certifications = { path = '../../../traits/certifications', default-features = false } +traits-genetic-testing = { path = '../../../traits/genetic-testing', default-features = false } + +## Substrate Pallet Dependencies +pallet-timestamp = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } +pallet-balances = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false } +pallet-randomness-collective-flip = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false } + +# Local Dependencies +labs = { path = '../../labs', default-features = false } +orders = { path = '../../orders', default-features = false } +services = { path = '../../services', default-features = false } +user-profile = { path = '../../user-profile', default-features = false } +certifications = { path = '../../certifications', default-features = false } +genetic-testing = { path = '../../genetic-testing', default-features = false } + +[dev-dependencies] +serde = { default-features = false, version = "1.0.119" } + +[features] +default = ['std'] +std = [ + 'codec/std', + 'scale-info/std', + + 'frame-benchmarking/std', + 'frame-support/std', + 'frame-system/std', + + 'sp-std/std', + 'sp-core/std', + 'sp-runtime/std', + 'sp-io/std', + + 'pallet-balances/std', + 'pallet-timestamp/std', + 'pallet-randomness-collective-flip/std', + + 'primitives-area-code/std', + 'primitives-stake-status/std', + 'primitives-verification-status/std', + + 'traits-order/std', + 'traits-services/std', + 'traits-user-profile/std', + 'traits-certifications/std', + 'traits-genetic-testing/std', + + 'labs/std', + 'orders/std', + 'services/std', + 'certifications/std', + 'user-profile/std', +] diff --git a/pallets/labs/src/benchmarking.rs b/pallets/labs/benchmarking/src/lib.rs similarity index 52% rename from pallets/labs/src/benchmarking.rs rename to pallets/labs/benchmarking/src/lib.rs index 480917b2..b40ef627 100644 --- a/pallets/labs/src/benchmarking.rs +++ b/pallets/labs/benchmarking/src/lib.rs @@ -1,12 +1,23 @@ -use super::*; +#![cfg_attr(not(feature = "std"), no_std)] +mod mock; #[allow(unused)] -use crate::{LabInfo, LabVerificationStatus, LabVerifierKey, Pallet as Labs}; +use labs::Pallet as Labs; +use labs::{Call, Config as LabsConfig, LabInfo, LabVerifierKey}; + +pub struct Pallet(Labs); + +pub trait Config: LabsConfig {} + use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller}; use frame_system::RawOrigin; -use frame_support::sp_runtime::traits::Hash; +use frame_support::{ + sp_runtime::{traits::Hash, SaturatedConversion}, + traits::Currency, +}; use primitives_area_code::{CityCode, CountryCode, RegionCode}; +use primitives_verification_status::VerificationStatus; benchmarks! { register_lab { @@ -48,7 +59,7 @@ benchmarks! { longitude: Some("DeBio Longtitude".as_bytes().to_vec()), profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), }; - let _add_labs = Labs::::register_lab(caller_origin.clone(), old_lab); + let _add_labs = Labs::::register_lab(caller_origin, old_lab); let new_lab = LabInfo { box_public_key: T::Hashing::hash("0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes()), @@ -87,11 +98,11 @@ benchmarks! { longitude: Some("DeBio Longtitude".as_bytes().to_vec()), profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), }; - let _add_labs = Labs::::register_lab(caller_origin.clone(), old_lab); + let _add_labs = Labs::::register_lab(caller_origin, old_lab); }: update_lab_verification_status( RawOrigin::Signed(caller), caller.clone(), - LabVerificationStatus::default() + VerificationStatus::default() ) deregister_lab { @@ -113,11 +124,108 @@ benchmarks! { profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), }; - let _add_labs = Labs::::register_lab(caller_origin.clone(), lab); + let _add_labs = Labs::::register_lab(caller_origin, lab); }: deregister_lab( RawOrigin::Signed(caller) ) + stake_lab { + let caller: T::AccountId = LabVerifierKey::::get(); + let caller_origin = ::Origin::from(RawOrigin::Signed(caller.clone())); + + let _ = ::Currency::deposit_creating(&caller, 60000000000000000000000u128.saturated_into()); + + let old_lab = LabInfo { + box_public_key: T::Hashing::hash("0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes()), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + }; + let _ = Labs::::register_lab(caller_origin, old_lab); + }: stake_lab( + RawOrigin::Signed(caller) + ) + + unstake_lab { + let caller: T::AccountId = LabVerifierKey::::get(); + let caller_origin = ::Origin::from(RawOrigin::Signed(caller.clone())); + + let _ = ::Currency::deposit_creating(&caller, 60000000000000000000000u128.saturated_into()); + + let old_lab = LabInfo { + box_public_key: T::Hashing::hash("0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes()), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + }; + let _ = Labs::::register_lab(caller_origin.clone(), old_lab); + + let _ = Labs::::stake_lab(caller_origin); + }: unstake_lab( + RawOrigin::Signed(caller) + ) + + retrieve_unstake_amount { + let caller_admin: T::AccountId = LabVerifierKey::::get(); + let caller: T::AccountId = whitelisted_caller(); + let caller_origin = ::Origin::from(RawOrigin::Signed(caller.clone())); + + let _ = ::Currency::deposit_creating(&caller, 60000000000000000000000u128.saturated_into()); + + let old_lab = LabInfo { + box_public_key: T::Hashing::hash("0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes()), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + }; + let _ = Labs::::register_lab(caller_origin.clone(), old_lab); + + let _ = Labs::::stake_lab(caller_origin.clone()); + + let _ = Labs::::unstake_lab(caller_origin); + }: retrieve_unstake_amount( + RawOrigin::Signed(caller_admin), + caller + ) + + update_minimum_stake_amount { + let caller: T::AccountId = LabVerifierKey::::get(); + }: update_minimum_stake_amount( + RawOrigin::Signed(caller), + 60000000000000000000000u128.saturated_into() + ) + + update_unstake_time { + let caller: T::AccountId = LabVerifierKey::::get(); + }: update_unstake_time( + RawOrigin::Signed(caller), + 0u64.saturated_into() + ) + update_admin_key { let caller: T::AccountId = LabVerifierKey::::get(); let caller2: T::AccountId = whitelisted_caller(); diff --git a/pallets/labs/src/mock.rs b/pallets/labs/benchmarking/src/mock.rs similarity index 68% rename from pallets/labs/src/mock.rs rename to pallets/labs/benchmarking/src/mock.rs index c695e664..1f9c109b 100644 --- a/pallets/labs/src/mock.rs +++ b/pallets/labs/benchmarking/src/mock.rs @@ -1,10 +1,12 @@ -use crate as labs; -use frame_support::parameter_types; +#![cfg(test)] + +use super::*; + +use frame_support::{parameter_types, PalletId}; use frame_system as system; use pallet_balances::AccountData; use scale_info::TypeInfo; use sp_core::{Decode, Encode, RuntimeDebug, H256}; -use sp_io::TestExternalities; use sp_runtime::{ testing::Header, traits::{BlakeTwo256, IdentityLookup}, @@ -13,6 +15,11 @@ use sp_runtime::{ type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; +use sp_io::TestExternalities; + +#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, Default, RuntimeDebug, TypeInfo)] +pub struct EthereumAddress(pub [u8; 20]); + pub type AccountId = u64; frame_support::construct_runtime!( @@ -22,10 +29,14 @@ frame_support::construct_runtime!( UncheckedExtrinsic = UncheckedExtrinsic, { System: frame_system::{Pallet, Call, Config, Storage, Event}, - Labs: labs::{Pallet, Call, Storage, Event}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, + Labs: labs::{Pallet, Call, Storage, Event}, Services: services::{Pallet, Call, Storage, Event}, Certifications: certifications::{Pallet, Call, Storage, Event}, + Orders: orders::{Pallet, Call, Storage, Event}, + GeneticTesting: genetic_testing::{Pallet, Call, Storage, Event}, + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, + RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage}, UserProfile: user_profile::{Pallet, Call, Storage, Event} } ); @@ -33,8 +44,12 @@ frame_support::construct_runtime!( parameter_types! { pub const BlockHashCount: u64 = 250; pub const SS58Prefix: u8 = 42; + pub BlockWeights: frame_system::limits::BlockWeights = + frame_system::limits::BlockWeights::simple_max(1024); } +impl pallet_randomness_collective_flip::Config for Test {} + impl system::Config for Test { type BaseCallFilter = frame_support::traits::Everything; type BlockWeights = (); @@ -61,10 +76,27 @@ impl system::Config for Test { type OnSetCode = (); } -type Balance = u64; +pub type Moment = u64; +pub const MILLISECS_PER_BLOCK: Moment = 6000; +pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; + +parameter_types! { + pub const MinimumPeriod: Moment = SLOT_DURATION / 2; +} + +impl pallet_timestamp::Config for Test { + /// A timestamp: milliseconds since the unix epoch. + type Moment = Moment; + type OnTimestampSet = (); + type MinimumPeriod = MinimumPeriod; + type WeightInfo = (); +} + +type Balance = u128; parameter_types! { pub static ExistentialDeposit: Balance = 0; + pub const LabPalletId: PalletId = PalletId(*b"dbio/lab"); } impl pallet_balances::Config for Test { @@ -85,10 +117,12 @@ impl labs::Config for Test { type Event = Event; type Currency = Balances; type Services = Services; + type Orders = Orders; type Certifications = Certifications; type EthereumAddress = EthereumAddress; type UserProfile = UserProfile; - type WeightInfo = (); + type LabWeightInfo = (); + type PalletId = LabPalletId; } impl services::Config for Test { @@ -104,8 +138,20 @@ impl certifications::Config for Test { type WeightInfo = (); } -#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, Default, RuntimeDebug, TypeInfo)] -pub struct EthereumAddress(pub [u8; 20]); +impl genetic_testing::Config for Test { + type Event = Event; + type Orders = Orders; + type RandomnessSource = RandomnessCollectiveFlip; + type GeneticTestingWeightInfo = (); +} + +impl orders::Config for Test { + type Event = Event; + type Services = Services; + type GeneticTesting = GeneticTesting; + type Currency = Balances; + type OrdersWeightInfo = (); +} impl user_profile::Config for Test { type Event = Event; diff --git a/pallets/labs/src/interface.rs b/pallets/labs/src/interface.rs index 6e8a7174..71e82033 100644 --- a/pallets/labs/src/interface.rs +++ b/pallets/labs/src/interface.rs @@ -2,58 +2,23 @@ pub use scale_info::TypeInfo; -use frame_support::pallet_prelude::*; use sp_std::prelude::*; -// LabVerificationStatus -#[derive(Encode, Decode, Clone, RuntimeDebug, PartialEq, Eq, TypeInfo)] -pub enum LabVerificationStatus { - Unverified, - Verified, - Rejected, - Revoked, -} -impl Default for LabVerificationStatus { - fn default() -> Self { - Self::Unverified - } -} - -pub trait LabVerificationStatusTrait { - fn is_verified(&self) -> bool; - fn is_unverified(&self) -> bool; - fn is_rejected(&self) -> bool; - fn is_revoked(&self) -> bool; -} -impl LabVerificationStatusTrait for LabVerificationStatus { - fn is_verified(&self) -> bool { - matches!(*self, LabVerificationStatus::Verified) - } - fn is_unverified(&self) -> bool { - matches!(*self, LabVerificationStatus::Unverified) - } - fn is_rejected(&self) -> bool { - matches!(*self, LabVerificationStatus::Rejected) - } - fn is_revoked(&self) -> bool { - matches!(*self, LabVerificationStatus::Revoked) - } -} - use primitives_area_code::{CityCode, CountryRegionCode}; +use primitives_verification_status::VerificationStatusTrait; /// Interface for Lab Pallet /// Defines the functionalities of Lab Pallet pub trait LabInterface { type Error; + type Moment; + type Balance; type LabInfo; type Lab; - type LabVerificationStatus: LabVerificationStatusTrait; + type VerificationStatus: VerificationStatusTrait; /// Get lab by associated account_id fn lab_by_account_id(account_id: &T::AccountId) -> Option; - /// Get lab verification status - fn lab_verification_status(account_id: &T::AccountId) -> Option; /// Get the account_ids of labs in a location fn labs_by_country_region_city( country_region_code: &CountryRegionCode, @@ -74,8 +39,27 @@ pub trait LabInterface { fn update_lab_verification_status( lab_verifier_key: &T::AccountId, account_id: &T::AccountId, - status: &Self::LabVerificationStatus, + status: &Self::VerificationStatus, ) -> Result; + /// Stake Lab + fn stake_lab(account_id: &T::AccountId) -> Result; + /// Unstake Lab + fn unstake_lab(account_id: &T::AccountId) -> Result; + /// Retrieve Unstake Amount + fn retrieve_unstake_amount( + admin_key: &T::AccountId, + account_id: &T::AccountId, + ) -> Result; + /// Update Lab minimum stake amount + fn update_minimum_stake_amount( + account_id: &T::AccountId, + amount: Self::Balance, + ) -> Result<(), Self::Error>; + /// Update Lab unstake time + fn update_unstake_time( + account_id: &T::AccountId, + moment: Self::Moment, + ) -> Result<(), Self::Error>; /// Update admin key fn update_admin_key( account_id: &T::AccountId, diff --git a/pallets/labs/src/lib.rs b/pallets/labs/src/lib.rs index cefe8472..ad7e915f 100644 --- a/pallets/labs/src/lib.rs +++ b/pallets/labs/src/lib.rs @@ -2,15 +2,6 @@ pub use scale_info::TypeInfo; -#[cfg(test)] -mod mock; - -#[cfg(test)] -mod tests; - -#[cfg(feature = "runtime-benchmarks")] -mod benchmarking; - pub mod weights; /// Edit this file to define custom logic or remove it if it is not needed. @@ -20,10 +11,20 @@ pub use pallet::*; pub use weights::WeightInfo; pub mod interface; -pub use crate::interface::{LabInterface, LabVerificationStatus}; -use frame_support::pallet_prelude::*; +pub use crate::interface::LabInterface; +use frame_support::{ + pallet_prelude::*, + sp_runtime::{traits::AccountIdConversion, RuntimeDebug}, + traits::Currency, + PalletId, +}; use primitives_area_code::{CityCode, CountryCode, CountryRegionCode, RegionCode}; +use primitives_stake_status::{StakeStatus, StakeStatusTrait}; +use primitives_verification_status::VerificationStatus; + use traits_certifications::CertificationOwnerInfo; +use traits_labs::LabsProvider; +use traits_order::{OrderEventEmitter, OrderStatusUpdater}; use traits_services::ServiceOwnerInfo; use traits_user_profile::UserProfileProvider; @@ -51,18 +52,22 @@ where // Lab Struct // the fields (excluding account_id and services) come from LabInfo struct #[derive(Encode, Decode, Clone, Default, RuntimeDebug, PartialEq, Eq, TypeInfo)] -pub struct Lab +pub struct Lab where Hash: PartialEq + Eq, { pub account_id: AccountId, pub services: Vec, pub certifications: Vec, - pub verification_status: LabVerificationStatus, + pub verification_status: VerificationStatus, pub info: LabInfo, + pub stake_amount: Balance, + pub stake_status: StakeStatus, + pub unstake_at: Moment, + pub retrieve_unstake_at: Moment, } -impl Lab +impl Lab where Hash: PartialEq + Eq, { @@ -71,8 +76,12 @@ where account_id, services: Vec::::new(), certifications: Vec::::new(), - verification_status: LabVerificationStatus::default(), + verification_status: VerificationStatus::default(), info, + unstake_at: Moment::default(), + retrieve_unstake_at: Moment::default(), + stake_amount: Balance::default(), + stake_status: StakeStatus::default(), } } @@ -122,7 +131,8 @@ where } } -impl ServiceOwnerInfo for Lab +impl ServiceOwnerInfo + for Lab where Hash: PartialEq + Eq, T: frame_system::Config, @@ -132,7 +142,8 @@ where } } -impl CertificationOwnerInfo for Lab +impl CertificationOwnerInfo + for Lab where Hash: PartialEq + Eq, T: frame_system::Config, @@ -154,11 +165,12 @@ pub mod pallet { #[pallet::config] /// Configure the pallet by specifying the parameters and types on which it depends. - pub trait Config: frame_system::Config { + pub trait Config: frame_system::Config + pallet_timestamp::Config { /// Because this pallet emits events, it depends on the runtime's definition of an event. type Event: From> + IsType<::Event>; type Currency: Currency; type Services: ServicesProvider>; + type Orders: OrderEventEmitter + OrderStatusUpdater; type Certifications: CertificationsProvider; type EthereumAddress: Clone + Copy @@ -171,7 +183,9 @@ pub mod pallet { + TypeInfo + sp_std::fmt::Debug; type UserProfile: UserProfileProvider; - type WeightInfo: WeightInfo; + type LabWeightInfo: WeightInfo; + /// Currency type for this pallet. + type PalletId: Get; } // ----- This is template code, every pallet needs this --- @@ -186,7 +200,8 @@ pub mod pallet { // ---- Types ---------------------- pub type AccountIdOf = ::AccountId; pub type HashOf = ::Hash; - pub type LabOf = Lab, HashOf>; + pub type MomentOf = ::Moment; + pub type LabOf = Lab, HashOf, MomentOf, BalanceOf>; pub type CurrencyOf = ::Currency; pub type BalanceOf = as Currency>>::Balance; @@ -226,6 +241,22 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn admin_key)] pub type LabVerifierKey = StorageValue<_, T::AccountId, ValueQuery>; + + #[pallet::storage] + #[pallet::getter(fn pallet_id)] + pub type PalletAccount = StorageValue<_, T::AccountId, ValueQuery>; + + #[pallet::storage] + #[pallet::getter(fn total_staked_amount)] + pub type TotalStakedAmount = StorageValue<_, BalanceOf>; + + #[pallet::storage] + #[pallet::getter(fn minimum_stake_amount)] + pub type MinimumStakeAmount = StorageValue<_, BalanceOf>; + + #[pallet::storage] + #[pallet::getter(fn unstake_time)] + pub type UnstakeTime = StorageValue<_, MomentOf>; // ----------------------------------------- // ----- Genesis Configs ------------------ @@ -245,6 +276,10 @@ pub mod pallet { impl GenesisBuild for GenesisConfig { fn build(&self) { LabVerifierKey::::put(&self.lab_verifier_key); + UnstakeTime::::put(MomentOf::::default()); + PalletAccount::::put(>::get_pallet_id()); + >::set_minimum_stake_amount(50000000000000000000000u128.saturated_into()); + >::set_total_staked_amount(); } } // ---------------------------------------- @@ -261,12 +296,27 @@ pub mod pallet { /// Lab verification updated /// parameters. [Lab, who] LabUpdateVerificationStatus(LabOf, AccountIdOf), - /// Update Lab admin key - /// parameters. [who] - UpdateLabAdminKeySuccessful(AccountIdOf), /// Lab deregistered /// parameters. [Lab, who] LabDeregistered(LabOf, AccountIdOf), + /// Lab stake successful + /// parameters. [Lab, who] + LabStakeSuccessful(LabOf, AccountIdOf), + /// Lab unstake successful + /// parameters. [Lab, who] + LabUnstakeSuccessful(LabOf, AccountIdOf), + /// Lab retrive unstake amount + /// parameters. [Lab, who] + LabRetrieveUnstakeAmount(LabOf, AccountIdOf), + /// Update Lab minimum stake successful + /// parameters. [who] + UpdateLabMinimumStakeSuccessful(AccountIdOf), + /// Update Lab unstake time successful + /// parameters. [who] + UpdateLabUnstakeTimeSuccessful(AccountIdOf), + /// Update Lab admin key + /// parameters. [who] + UpdateLabAdminKeySuccessful(AccountIdOf), } // Errors inform users that something went wrong. @@ -278,13 +328,27 @@ pub mod pallet { LabDoesNotExist, /// Lab is not the owner of the service LabIsNotOwner, + /// Account already has genetic_analyst staked + LabAlreadyStaked, + /// Insufficient funds + InsufficientFunds, + /// Insufficient pallet funds + InsufficientPalletFunds, + /// Account has not staked + LabIsNotStaked, /// Unauthorized access to extrinsic Unauthorized, + // Lab has pending orders + LabHasPendingOrders, + // Lab not waiting for unstake + LabIsNotWaitingForUnstake, + // Lab cannot unstake now + LabCannotUnstakeBeforeUnstakeTime, } #[pallet::call] impl Pallet { - #[pallet::weight(T::WeightInfo::register_lab())] + #[pallet::weight(T::LabWeightInfo::register_lab())] pub fn register_lab( origin: OriginFor, lab_info: LabInfo>, @@ -300,7 +364,7 @@ pub mod pallet { } } - #[pallet::weight(T::WeightInfo::update_lab())] + #[pallet::weight(T::LabWeightInfo::update_lab())] pub fn update_lab( origin: OriginFor, lab_info: LabInfo>, @@ -316,11 +380,11 @@ pub mod pallet { } } - #[pallet::weight(T::WeightInfo::update_lab_verification_status())] + #[pallet::weight(T::LabWeightInfo::update_lab_verification_status())] pub fn update_lab_verification_status( origin: OriginFor, account_id: T::AccountId, - lab_verification_status: LabVerificationStatus, + lab_verification_status: VerificationStatus, ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; @@ -337,7 +401,7 @@ pub mod pallet { } } - #[pallet::weight(T::WeightInfo::deregister_lab())] + #[pallet::weight(T::LabWeightInfo::deregister_lab())] pub fn deregister_lab(origin: OriginFor) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; // Check if user is a lab @@ -355,7 +419,81 @@ pub mod pallet { } } - #[pallet::weight(T::WeightInfo::update_admin_key())] + #[pallet::weight(T::LabWeightInfo::stake_lab())] + pub fn stake_lab(origin: OriginFor) -> DispatchResultWithPostInfo { + let who = ensure_signed(origin)?; + + match >::stake_lab(&who) { + Ok(lab) => { + Self::deposit_event(Event::LabStakeSuccessful(lab, who.clone())); + Ok(().into()) + }, + Err(error) => Err(error.into()), + } + } + + #[pallet::weight(T::LabWeightInfo::unstake_lab())] + pub fn unstake_lab(origin: OriginFor) -> DispatchResultWithPostInfo { + let who = ensure_signed(origin)?; + + match >::unstake_lab(&who) { + Ok(lab) => { + Self::deposit_event(Event::LabUnstakeSuccessful(lab, who.clone())); + Ok(().into()) + }, + Err(error) => Err(error.into()), + } + } + + #[pallet::weight(T::LabWeightInfo::retrieve_unstake_amount())] + pub fn retrieve_unstake_amount( + origin: OriginFor, + account_id: T::AccountId, + ) -> DispatchResultWithPostInfo { + let who = ensure_signed(origin)?; + + match >::retrieve_unstake_amount(&who, &account_id) { + Ok(lab) => { + Self::deposit_event(Event::LabRetrieveUnstakeAmount(lab, who.clone())); + Ok(().into()) + }, + Err(error) => Err(error.into()), + } + } + + #[pallet::weight(T::LabWeightInfo::update_minimum_stake_amount())] + pub fn update_minimum_stake_amount( + origin: OriginFor, + amount: BalanceOf, + ) -> DispatchResultWithPostInfo { + let who = ensure_signed(origin)?; + + match >::update_minimum_stake_amount(&who, amount) { + Ok(_) => { + Self::deposit_event(Event::UpdateLabMinimumStakeSuccessful(who.clone())); + Ok(().into()) + }, + Err(error) => Err(error.into()), + } + } + + #[pallet::weight(T::LabWeightInfo::update_unstake_time())] + pub fn update_unstake_time( + origin: OriginFor, + amount: MomentOf, + ) -> DispatchResultWithPostInfo { + let who = ensure_signed(origin)?; + + match >::update_unstake_time(&who, amount) { + Ok(_) => { + Self::deposit_event(Event::UpdateLabUnstakeTimeSuccessful(who.clone())); + Ok(().into()) + }, + Err(error) => Err(error.into()), + } + } + + #[pallet::weight(T::LabWeightInfo::update_admin_key())] pub fn update_admin_key( origin: OriginFor, account_id: T::AccountId, @@ -389,9 +527,11 @@ pub mod pallet { impl LabInterface for Pallet { type Error = Error; + type Moment = MomentOf; + type Balance = BalanceOf; type LabInfo = LabInfo>; type Lab = LabOf; - type LabVerificationStatus = LabVerificationStatus; + type VerificationStatus = VerificationStatus; fn create_lab( account_id: &T::AccountId, @@ -452,7 +592,7 @@ impl LabInterface for Pallet { fn update_lab_verification_status( lab_verifier_key: &T::AccountId, account_id: &T::AccountId, - status: &Self::LabVerificationStatus, + status: &Self::VerificationStatus, ) -> Result { if lab_verifier_key.clone() != LabVerifierKey::::get() { return Err(Error::::Unauthorized) @@ -490,6 +630,126 @@ impl LabInterface for Pallet { Ok(lab) } + fn stake_lab(account_id: &T::AccountId) -> Result { + let lab = Labs::::get(account_id); + if lab == None { + return Err(Error::::LabDoesNotExist) + } + + let mut lab = lab.unwrap(); + if lab.stake_status.is_staked() { + return Err(Error::::LabAlreadyStaked) + } + + if !lab.stake_status.is_waiting_for_unstaked() { + if !Self::is_balance_sufficient_for_staking(account_id) { + return Err(Error::::InsufficientFunds) + } + + lab.stake_amount = Self::transfer_balance( + account_id, + &Self::account_id(), + Self::get_required_stake_balance(), + ); + } + lab.stake_status = StakeStatus::Staked; + lab.unstake_at = MomentOf::::default(); + lab.retrieve_unstake_at = MomentOf::::default(); + + Labs::::insert(account_id, &lab); + + Ok(lab) + } + + fn unstake_lab(account_id: &T::AccountId) -> Result { + let lab = Labs::::get(account_id); + if lab == None { + return Err(Error::::LabDoesNotExist) + } + + let mut lab = lab.unwrap(); + if !lab.stake_status.is_staked() { + return Err(Error::::LabIsNotStaked) + } + + if T::Orders::is_pending_order_by_seller_exist(account_id) { + return Err(Error::::LabHasPendingOrders) + } + + let now = pallet_timestamp::Pallet::::get(); + lab.stake_status = StakeStatus::WaitingForUnstaked; + lab.unstake_at = now; + lab.retrieve_unstake_at = Self::get_unstake_time(now); + + Labs::::insert(account_id, &lab); + + Ok(lab) + } + + fn retrieve_unstake_amount( + admin_key: &T::AccountId, + account_id: &T::AccountId, + ) -> Result { + if admin_key.clone() != LabVerifierKey::::get() { + return Err(Error::::Unauthorized) + } + + let lab = Labs::::get(account_id); + if lab == None { + return Err(Error::::LabDoesNotExist) + } + + let mut lab = lab.unwrap(); + if !lab.stake_status.is_waiting_for_unstaked() { + return Err(Error::::LabIsNotWaitingForUnstake) + } + + if !Self::check_if_unstake_time(lab.retrieve_unstake_at) { + return Err(Error::::LabCannotUnstakeBeforeUnstakeTime) + } + + if !Self::is_pallet_balance_sufficient_for_refund(lab.stake_amount) { + return Err(Error::::InsufficientPalletFunds) + } + + let _ = Self::transfer_balance(&Self::account_id(), account_id, lab.stake_amount); + + lab.stake_amount = 0u128.saturated_into(); + lab.stake_status = StakeStatus::Unstaked; + lab.unstake_at = MomentOf::::default(); + lab.retrieve_unstake_at = MomentOf::::default(); + + Labs::::insert(account_id, &lab); + + Ok(lab) + } + + fn update_minimum_stake_amount( + account_id: &T::AccountId, + amount: Self::Balance, + ) -> Result<(), Self::Error> { + if account_id.clone() != LabVerifierKey::::get() { + return Err(Error::::Unauthorized) + } + + Self::set_minimum_stake_amount(amount); + + Ok(()) + } + + fn update_unstake_time( + account_id: &T::AccountId, + moment: Self::Moment, + ) -> Result<(), Self::Error> { + if account_id.clone() != LabVerifierKey::::get() { + return Err(Error::::Unauthorized) + } + + Self::set_unstake_time(moment); + + Ok(()) + } + fn update_admin_key( account_id: &T::AccountId, admin_key: &T::AccountId, @@ -513,17 +773,10 @@ impl LabInterface for Pallet { fn lab_by_account_id(account_id: &T::AccountId) -> Option { Self::lab_by_account_id(account_id) } - - fn lab_verification_status(account_id: &T::AccountId) -> Option { - let lab = Self::lab_by_account_id(account_id); - - lab.as_ref()?; - - let lab = lab.unwrap(); - Some(lab.verification_status) - } } +use frame_support::{sp_runtime::SaturatedConversion, traits::ExistenceRequirement::KeepAlive}; + impl Pallet { pub fn insert_lab_id_to_location(lab: &LabOf) { let country_region_code = lab.get_country_region(); @@ -597,10 +850,91 @@ impl Pallet { lab_count - 1, ); } + + /// The injected pallet ID + pub fn get_pallet_id() -> AccountIdOf { + T::PalletId::get().into_account() + } + + /// The account ID that holds the funds + pub fn account_id() -> AccountIdOf { + >::get() + } + + pub fn get_balance_by_account_id(account_id: &AccountIdOf) -> BalanceOf { + T::Currency::free_balance(account_id) + } + + pub fn get_required_stake_balance() -> BalanceOf { + >::get() + .unwrap_or_else(|| 50000000000000000000000u128.saturated_into()) + } + + /// Is the balance sufficient for staking + pub fn is_balance_sufficient_for_staking(account_id: &AccountIdOf) -> bool { + let balance = T::Currency::free_balance(account_id); + balance >= Self::get_required_stake_balance() + } + + /// Transfer balance + pub fn transfer_balance( + source: &AccountIdOf, + dest: &AccountIdOf, + amount: BalanceOf, + ) -> BalanceOf { + let _ = T::Currency::transfer(source, dest, amount, KeepAlive); + Self::set_total_staked_amount(); + amount + } + + /// Is the pallet balance sufficient for refund + pub fn is_pallet_balance_sufficient_for_refund(refund_amount: BalanceOf) -> bool { + let balance = T::Currency::free_balance(&Self::account_id()); + balance >= refund_amount + } + + /// Set current total stake amount + pub fn set_minimum_stake_amount(amount: BalanceOf) { + MinimumStakeAmount::::put(amount); + } + + /// Set unstake time + pub fn set_unstake_time(moment: MomentOf) { + UnstakeTime::::put(moment); + } + + /// Get unstake time + pub fn get_unstake_time(moment: MomentOf) -> MomentOf { + if let Some(time) = UnstakeTime::::get() { + return time + moment + } + moment + } + + /// Check unstake time + pub fn check_if_unstake_time(moment: MomentOf) -> bool { + let now = pallet_timestamp::Pallet::::get(); + moment <= now + } + + /// Set current total staked amount + pub fn set_total_staked_amount() { + let balance = T::Currency::free_balance(&Self::account_id()); + TotalStakedAmount::::put(balance); + } + + fn lab_verification_status(account_id: &T::AccountId) -> Option { + let lab = Self::lab_by_account_id(account_id); + + lab.as_ref()?; + + let lab = lab.unwrap(); + Some(lab.verification_status) + } } impl ServiceOwner for Pallet { - type Owner = Lab; + type Owner = Lab, BalanceOf>; /// User can create service if he/she is a lab and has set ethereum address fn can_create_service(user_id: &T::AccountId) -> bool { @@ -633,7 +967,7 @@ impl ServiceOwner for Pallet { } impl CertificationOwner for Pallet { - type Owner = Lab; + type Owner = Lab, BalanceOf>; /// User can create certification if he/she is a lab fn can_create_certification(user_id: &T::AccountId) -> bool { @@ -664,3 +998,9 @@ impl CertificationOwner for Pallet { }); } } + +impl LabsProvider for Pallet { + fn lab_verification_status(account_id: &AccountIdOf) -> Option { + Self::lab_verification_status(account_id) + } +} diff --git a/pallets/labs/src/tests.rs b/pallets/labs/src/tests.rs deleted file mode 100644 index 45a02554..00000000 --- a/pallets/labs/src/tests.rs +++ /dev/null @@ -1,634 +0,0 @@ -use crate::{mock::*, Error, Lab, LabInfo, LabVerificationStatus, LabVerifierKey}; -use frame_support::{ - assert_noop, assert_ok, - sp_runtime::traits::{Hash, Keccak256}, -}; -use primitives_area_code::{CityCode, CountryCode, CountryRegionCode, RegionCode}; - -#[test] -fn register_lab_works() { - ExternalityBuilder::build().execute_with(|| { - assert_ok!(Labs::register_lab( - Origin::signed(1), - LabInfo { - box_public_key: Keccak256::hash( - "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() - ), - name: "DeBio Lab".as_bytes().to_vec(), - email: "DeBio Email".as_bytes().to_vec(), - country: CountryCode::from_vec("DC".as_bytes().to_vec()), - region: RegionCode::from_vec("DB".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(), - latitude: Some("DeBio Latitude".as_bytes().to_vec()), - longitude: Some("DeBio Longtitude".as_bytes().to_vec()), - profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), - } - )); - - assert_eq!( - Labs::lab_by_account_id(1), - Some(Lab { - account_id: 1, - services: Vec::new(), - certifications: Vec::new(), - verification_status: LabVerificationStatus::default(), - info: LabInfo { - box_public_key: Keccak256::hash( - "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() - ), - name: "DeBio Lab".as_bytes().to_vec(), - email: "DeBio Email".as_bytes().to_vec(), - country: CountryCode::from_vec("DC".as_bytes().to_vec()), - region: RegionCode::from_vec("DB".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(), - latitude: Some("DeBio Latitude".as_bytes().to_vec()), - longitude: Some("DeBio Longtitude".as_bytes().to_vec()), - profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), - } - }) - ); - - let country_region_code = CountryRegionCode::from_vec("DC-DB".as_bytes().to_vec()); - let city_code = CityCode::from_vec("CITY".as_bytes().to_vec()); - - assert_eq!( - Labs::labs_by_country_region_city(&country_region_code, &city_code), - Some(vec![1]) - ); - assert_eq!(Labs::lab_count(), Some(1)); - assert_eq!( - Labs::lab_count_by_country_region_city(&country_region_code, &city_code), - Some(1) - ); - }) -} - -#[test] -fn update_lab_works() { - ExternalityBuilder::build().execute_with(|| { - assert_ok!(Labs::register_lab( - Origin::signed(1), - LabInfo { - box_public_key: Keccak256::hash( - "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() - ), - name: "DeBio Lab".as_bytes().to_vec(), - email: "DeBio Email".as_bytes().to_vec(), - country: CountryCode::from_vec("DC".as_bytes().to_vec()), - region: RegionCode::from_vec("DB".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(), - latitude: Some("DeBio Latitude".as_bytes().to_vec()), - longitude: Some("DeBio Longtitude".as_bytes().to_vec()), - profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), - } - )); - - assert_ok!(Labs::update_lab( - Origin::signed(1), - LabInfo { - box_public_key: Keccak256::hash( - "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() - ), - name: "DeBio Labs".as_bytes().to_vec(), - email: "DeBio Email".as_bytes().to_vec(), - country: CountryCode::from_vec("DC".as_bytes().to_vec()), - region: RegionCode::from_vec("DB".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(), - latitude: Some("DeBio Latitude".as_bytes().to_vec()), - longitude: Some("DeBio Longtitude".as_bytes().to_vec()), - profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), - } - )); - - assert_eq!( - Labs::lab_by_account_id(1), - Some(Lab { - account_id: 1, - services: Vec::new(), - certifications: Vec::new(), - verification_status: LabVerificationStatus::default(), - info: LabInfo { - box_public_key: Keccak256::hash( - "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() - ), - name: "DeBio Labs".as_bytes().to_vec(), - email: "DeBio Email".as_bytes().to_vec(), - country: CountryCode::from_vec("DC".as_bytes().to_vec()), - region: RegionCode::from_vec("DB".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(), - latitude: Some("DeBio Latitude".as_bytes().to_vec()), - longitude: Some("DeBio Longtitude".as_bytes().to_vec()), - profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), - } - }) - ); - - let old_country_region_code = CountryRegionCode::from_vec("DC-DB".as_bytes().to_vec()); - let old_city_code = CityCode::from_vec("CITY".as_bytes().to_vec()); - - assert_ok!(Labs::update_lab( - Origin::signed(1), - LabInfo { - box_public_key: Keccak256::hash( - "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() - ), - name: "DeBio Labs".as_bytes().to_vec(), - email: "DeBio Email".as_bytes().to_vec(), - country: CountryCode::from_vec("ID".as_bytes().to_vec()), - region: RegionCode::from_vec("WJ".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(), - latitude: Some("DeBio Latitude".as_bytes().to_vec()), - longitude: Some("DeBio Longtitude".as_bytes().to_vec()), - profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), - } - )); - - assert_eq!( - Labs::lab_by_account_id(1), - Some(Lab { - account_id: 1, - services: Vec::new(), - certifications: Vec::new(), - verification_status: LabVerificationStatus::default(), - info: LabInfo { - box_public_key: Keccak256::hash( - "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() - ), - name: "DeBio Labs".as_bytes().to_vec(), - email: "DeBio Email".as_bytes().to_vec(), - country: CountryCode::from_vec("ID".as_bytes().to_vec()), - region: RegionCode::from_vec("WJ".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(), - latitude: Some("DeBio Latitude".as_bytes().to_vec()), - longitude: Some("DeBio Longtitude".as_bytes().to_vec()), - profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), - } - }) - ); - - assert_eq!( - Labs::labs_by_country_region_city(&old_country_region_code, &old_city_code), - Some(Vec::new()) - ); - assert_eq!( - Labs::lab_count_by_country_region_city(&old_country_region_code, &old_city_code), - Some(0) - ); - - let new_country_region_code = CountryRegionCode::from_vec("ID-WJ".as_bytes().to_vec()); - let new_city_code = CityCode::from_vec("CITY".as_bytes().to_vec()); - - assert_eq!( - Labs::labs_by_country_region_city(&new_country_region_code, &new_city_code), - Some(vec![1]) - ); - assert_eq!( - Labs::lab_count_by_country_region_city(new_country_region_code, new_city_code), - Some(1) - ); - }) -} - -#[test] -fn update_lab_verification_status_works() { - ExternalityBuilder::build().execute_with(|| { - assert_ok!(Labs::register_lab( - Origin::signed(1), - LabInfo { - box_public_key: Keccak256::hash( - "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() - ), - name: "DeBio Lab".as_bytes().to_vec(), - email: "DeBio Email".as_bytes().to_vec(), - country: CountryCode::from_vec("DC".as_bytes().to_vec()), - region: RegionCode::from_vec("DB".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(), - latitude: Some("DeBio Latitude".as_bytes().to_vec()), - longitude: Some("DeBio Longtitude".as_bytes().to_vec()), - profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), - } - )); - - LabVerifierKey::::put(2); - - assert_ok!(Labs::update_lab_verification_status( - Origin::signed(2), - 1, - LabVerificationStatus::Verified, - )); - - assert_eq!( - Labs::lab_by_account_id(1), - Some(Lab { - account_id: 1, - services: Vec::new(), - certifications: Vec::new(), - verification_status: LabVerificationStatus::Verified, - info: LabInfo { - box_public_key: Keccak256::hash( - "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() - ), - name: "DeBio Lab".as_bytes().to_vec(), - email: "DeBio Email".as_bytes().to_vec(), - country: CountryCode::from_vec("DC".as_bytes().to_vec()), - region: RegionCode::from_vec("DB".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(), - latitude: Some("DeBio Latitude".as_bytes().to_vec()), - longitude: Some("DeBio Longtitude".as_bytes().to_vec()), - profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), - } - }) - ); - }) -} - -#[test] -fn deregister_lab_works() { - ExternalityBuilder::build().execute_with(|| { - assert_ok!(Labs::register_lab( - Origin::signed(1), - LabInfo { - box_public_key: Keccak256::hash( - "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() - ), - name: "DeBio Lab".as_bytes().to_vec(), - email: "DeBio Email".as_bytes().to_vec(), - country: CountryCode::from_vec("DC".as_bytes().to_vec()), - region: RegionCode::from_vec("DB".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(), - latitude: Some("DeBio Latitude".as_bytes().to_vec()), - longitude: Some("DeBio Longtitude".as_bytes().to_vec()), - profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), - } - )); - - let country_region_code = CountryRegionCode::from_vec("DC-DB".as_bytes().to_vec()); - let city_code = CityCode::from_vec("CITY".as_bytes().to_vec()); - - assert_ok!(Labs::deregister_lab(Origin::signed(1))); - - assert_eq!(Labs::lab_by_account_id(1), None); - - assert_eq!( - Labs::labs_by_country_region_city(&country_region_code, &city_code), - Some(Vec::new()) - ); - - assert_eq!(Labs::lab_count(), Some(0)); - - assert_eq!( - Labs::lab_count_by_country_region_city(&country_region_code, &city_code), - Some(0) - ); - }) -} - -#[test] -fn cant_register_lab_when_already_registered() { - ExternalityBuilder::build().execute_with(|| { - assert_ok!(Labs::register_lab( - Origin::signed(1), - LabInfo { - box_public_key: Keccak256::hash( - "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() - ), - name: "DeBio Lab".as_bytes().to_vec(), - email: "DeBio Email".as_bytes().to_vec(), - country: CountryCode::from_vec("DC".as_bytes().to_vec()), - region: RegionCode::from_vec("DB".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(), - latitude: Some("DeBio Latitude".as_bytes().to_vec()), - longitude: Some("DeBio Longtitude".as_bytes().to_vec()), - profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), - } - )); - - assert_noop!( - Labs::register_lab( - Origin::signed(1), - LabInfo { - box_public_key: Keccak256::hash( - "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() - ), - name: "DeBio Lab".as_bytes().to_vec(), - email: "DeBio Email".as_bytes().to_vec(), - country: CountryCode::from_vec("DC".as_bytes().to_vec()), - region: RegionCode::from_vec("DB".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(), - latitude: Some("DeBio Latitude".as_bytes().to_vec()), - longitude: Some("DeBio Longtitude".as_bytes().to_vec()), - profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), - } - ), - Error::::LabAlreadyRegistered - ); - }) -} - -#[test] -fn cant_update_lab_verification_status_when_not_admin() { - ExternalityBuilder::build().execute_with(|| { - assert_ok!(Labs::register_lab( - Origin::signed(1), - LabInfo { - box_public_key: Keccak256::hash( - "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() - ), - name: "DeBio Lab".as_bytes().to_vec(), - email: "DeBio Email".as_bytes().to_vec(), - country: CountryCode::from_vec("DC".as_bytes().to_vec()), - region: RegionCode::from_vec("DB".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(), - latitude: Some("DeBio Latitude".as_bytes().to_vec()), - longitude: Some("DeBio Longtitude".as_bytes().to_vec()), - profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), - } - )); - - assert_noop!( - Labs::update_lab_verification_status( - Origin::signed(2), - 1, - LabVerificationStatus::Verified, - ), - Error::::Unauthorized - ); - }) -} - -#[test] -fn cant_update_lab_verification_status_when_not_exist() { - ExternalityBuilder::build().execute_with(|| { - LabVerifierKey::::put(2); - - assert_noop!( - Labs::update_lab_verification_status( - Origin::signed(2), - 1, - LabVerificationStatus::Verified, - ), - Error::::LabDoesNotExist - ); - }) -} - -#[test] -fn cant_update_and_delete_lab_when_not_exist() { - ExternalityBuilder::build().execute_with(|| { - assert_noop!( - Labs::update_lab( - Origin::signed(1), - LabInfo { - box_public_key: Keccak256::hash( - "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() - ), - name: "DeBio Lab".as_bytes().to_vec(), - email: "DeBio Email".as_bytes().to_vec(), - country: CountryCode::from_vec("DC".as_bytes().to_vec()), - region: RegionCode::from_vec("DB".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(), - latitude: Some("DeBio Latitude".as_bytes().to_vec()), - longitude: Some("DeBio Longtitude".as_bytes().to_vec()), - profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), - } - ), - Error::::LabDoesNotExist - ); - - LabVerifierKey::::put(2); - - assert_noop!( - Labs::update_lab_verification_status( - Origin::signed(2), - 1, - LabVerificationStatus::Verified - ), - Error::::LabDoesNotExist - ); - - assert_noop!(Labs::deregister_lab(Origin::signed(1)), Error::::LabDoesNotExist); - }) -} - -#[test] -fn call_event_should_work() { - ExternalityBuilder::build().execute_with(|| { - System::set_block_number(1); - assert_ok!(Labs::register_lab( - Origin::signed(1), - LabInfo { - box_public_key: Keccak256::hash( - "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() - ), - name: "DeBio Lab".as_bytes().to_vec(), - email: "DeBio Email".as_bytes().to_vec(), - country: CountryCode::from_vec("DC".as_bytes().to_vec()), - region: RegionCode::from_vec("DB".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(), - latitude: Some("DeBio Latitude".as_bytes().to_vec()), - longitude: Some("DeBio Longtitude".as_bytes().to_vec()), - profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), - } - )); - - System::assert_last_event(Event::Labs(crate::Event::LabRegistered( - Lab { - account_id: 1, - services: Vec::new(), - certifications: Vec::new(), - verification_status: LabVerificationStatus::default(), - info: LabInfo { - box_public_key: Keccak256::hash( - "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes(), - ), - name: "DeBio Lab".as_bytes().to_vec(), - email: "DeBio Email".as_bytes().to_vec(), - country: CountryCode::from_vec("DC".as_bytes().to_vec()), - region: RegionCode::from_vec("DB".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(), - latitude: Some("DeBio Latitude".as_bytes().to_vec()), - longitude: Some("DeBio Longtitude".as_bytes().to_vec()), - profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), - }, - }, - 1, - ))); - - assert_ok!(Labs::update_lab( - Origin::signed(1), - LabInfo { - box_public_key: Keccak256::hash( - "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() - ), - name: "DeBio Labs".as_bytes().to_vec(), - email: "DeBio Email".as_bytes().to_vec(), - country: CountryCode::from_vec("DC".as_bytes().to_vec()), - region: RegionCode::from_vec("DB".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(), - latitude: Some("DeBio Latitude".as_bytes().to_vec()), - longitude: Some("DeBio Longtitude".as_bytes().to_vec()), - profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), - } - )); - - System::assert_last_event(Event::Labs(crate::Event::LabUpdated( - Lab { - account_id: 1, - services: Vec::new(), - certifications: Vec::new(), - verification_status: LabVerificationStatus::default(), - info: LabInfo { - box_public_key: Keccak256::hash( - "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes(), - ), - name: "DeBio Labs".as_bytes().to_vec(), - email: "DeBio Email".as_bytes().to_vec(), - country: CountryCode::from_vec("DC".as_bytes().to_vec()), - region: RegionCode::from_vec("DB".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(), - latitude: Some("DeBio Latitude".as_bytes().to_vec()), - longitude: Some("DeBio Longtitude".as_bytes().to_vec()), - profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), - }, - }, - 1, - ))); - - LabVerifierKey::::put(2); - - assert_ok!(Labs::update_lab_verification_status( - Origin::signed(2), - 1, - LabVerificationStatus::Verified - )); - - System::assert_last_event(Event::Labs(crate::Event::LabUpdateVerificationStatus( - Lab { - account_id: 1, - services: Vec::new(), - certifications: Vec::new(), - verification_status: LabVerificationStatus::Verified, - info: LabInfo { - box_public_key: Keccak256::hash( - "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes(), - ), - name: "DeBio Labs".as_bytes().to_vec(), - email: "DeBio Email".as_bytes().to_vec(), - country: CountryCode::from_vec("DC".as_bytes().to_vec()), - region: RegionCode::from_vec("DB".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(), - latitude: Some("DeBio Latitude".as_bytes().to_vec()), - longitude: Some("DeBio Longtitude".as_bytes().to_vec()), - profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), - }, - }, - 2, - ))); - - assert_ok!(Labs::deregister_lab(Origin::signed(1))); - System::assert_last_event(Event::Labs(crate::Event::LabDeregistered( - Lab { - account_id: 1, - services: Vec::new(), - certifications: Vec::new(), - verification_status: LabVerificationStatus::Verified, - info: LabInfo { - box_public_key: Keccak256::hash( - "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes(), - ), - name: "DeBio Labs".as_bytes().to_vec(), - email: "DeBio Email".as_bytes().to_vec(), - country: CountryCode::from_vec("DC".as_bytes().to_vec()), - region: RegionCode::from_vec("DB".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(), - latitude: Some("DeBio Latitude".as_bytes().to_vec()), - longitude: Some("DeBio Longtitude".as_bytes().to_vec()), - profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), - }, - }, - 1, - ))) - }) -} - -#[test] -fn update_admin_key_works() { - ExternalityBuilder::build().execute_with(|| { - LabVerifierKey::::put(2); - - assert_eq!(Labs::admin_key(), 2); - - assert_ok!(Labs::update_admin_key(Origin::signed(2), 1,)); - - assert_eq!(Labs::admin_key(), 1); - }) -} - -#[test] -fn sudo_update_admin_key_works() { - ExternalityBuilder::build().execute_with(|| { - assert_ok!(Labs::sudo_update_admin_key(Origin::root(), 1)); - - assert_eq!(Labs::admin_key(), 1); - }) -} diff --git a/pallets/labs/src/weights.rs b/pallets/labs/src/weights.rs index 4e2b0c22..24c482e5 100644 --- a/pallets/labs/src/weights.rs +++ b/pallets/labs/src/weights.rs @@ -1,11 +1,11 @@ //! Autogenerated weights for labs //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-28, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-04-04, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: -// target/release/debio +// ./target/release/debio // benchmark // --chain=dev // --execution=wasm @@ -33,6 +33,11 @@ pub trait WeightInfo { fn update_lab() -> Weight; fn update_lab_verification_status() -> Weight; fn deregister_lab() -> Weight; + fn stake_lab() -> Weight; + fn unstake_lab() -> Weight; + fn retrieve_unstake_amount() -> Weight; + fn update_minimum_stake_amount() -> Weight; + fn update_unstake_time() -> Weight; fn update_admin_key() -> Weight; } @@ -44,7 +49,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Labs LabCount (r:1 w:1) // Storage: Labs LabCountByCountryRegionCity (r:1 w:1) fn register_lab() -> Weight { - 58_753_000_u64 + 54_891_000_u64 .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -52,14 +57,14 @@ impl WeightInfo for SubstrateWeight { // Storage: Labs LabsByCountryRegionCity (r:2 w:2) // Storage: Labs LabCountByCountryRegionCity (r:2 w:2) fn update_lab() -> Weight { - 84_580_000_u64 + 67_311_000_u64 .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } // Storage: Labs LabVerifierKey (r:1 w:0) // Storage: Labs Labs (r:1 w:1) fn update_lab_verification_status() -> Weight { - 37_253_000_u64 + 29_102_000_u64 .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -68,13 +73,57 @@ impl WeightInfo for SubstrateWeight { // Storage: Labs LabCountByCountryRegionCity (r:1 w:1) // Storage: Labs LabCount (r:1 w:1) fn deregister_lab() -> Weight { - 66_317_000_u64 + 53_771_000_u64 .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } + // Storage: Labs Labs (r:1 w:1) + // Storage: System Account (r:2 w:2) + // Storage: Labs MinimumStakeAmount (r:1 w:0) + // Storage: Labs PalletAccount (r:1 w:0) + // Storage: Labs TotalStakedAmount (r:0 w:1) + fn stake_lab() -> Weight { + 116_764_000_u64 + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + } + // Storage: Labs Labs (r:1 w:1) + // Storage: Orders PendingOrdersBySeller (r:1 w:0) + // Storage: Timestamp Now (r:1 w:0) + // Storage: Labs UnstakeTime (r:1 w:0) + fn unstake_lab() -> Weight { + 38_567_000_u64 + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + // Storage: Labs LabVerifierKey (r:1 w:0) + // Storage: Labs Labs (r:1 w:1) + // Storage: Timestamp Now (r:1 w:0) + // Storage: Labs PalletAccount (r:1 w:0) + // Storage: System Account (r:1 w:1) + // Storage: Labs TotalStakedAmount (r:0 w:1) + fn retrieve_unstake_amount() -> Weight { + 81_605_000_u64 + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + // Storage: Labs LabVerifierKey (r:1 w:0) + // Storage: Labs MinimumStakeAmount (r:0 w:1) + fn update_minimum_stake_amount() -> Weight { + 29_159_000_u64 + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + // Storage: Labs LabVerifierKey (r:1 w:0) + // Storage: Labs UnstakeTime (r:0 w:1) + fn update_unstake_time() -> Weight { + 18_458_000_u64 + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } // Storage: Labs LabVerifierKey (r:1 w:1) fn update_admin_key() -> Weight { - 22_246_000_u64 + 18_698_000_u64 .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -87,7 +136,7 @@ impl WeightInfo for () { // Storage: Labs LabCount (r:1 w:1) // Storage: Labs LabCountByCountryRegionCity (r:1 w:1) fn register_lab() -> Weight { - 58_753_000_u64 + 54_891_000_u64 .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } @@ -95,14 +144,14 @@ impl WeightInfo for () { // Storage: Labs LabsByCountryRegionCity (r:2 w:2) // Storage: Labs LabCountByCountryRegionCity (r:2 w:2) fn update_lab() -> Weight { - 84_580_000_u64 + 67_311_000_u64 .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } // Storage: Labs LabVerifierKey (r:1 w:0) // Storage: Labs Labs (r:1 w:1) fn update_lab_verification_status() -> Weight { - 37_253_000_u64 + 29_102_000_u64 .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -111,13 +160,57 @@ impl WeightInfo for () { // Storage: Labs LabCountByCountryRegionCity (r:1 w:1) // Storage: Labs LabCount (r:1 w:1) fn deregister_lab() -> Weight { - 66_317_000_u64 + 53_771_000_u64 .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } + // Storage: Labs Labs (r:1 w:1) + // Storage: System Account (r:2 w:2) + // Storage: Labs MinimumStakeAmount (r:1 w:0) + // Storage: Labs PalletAccount (r:1 w:0) + // Storage: Labs TotalStakedAmount (r:0 w:1) + fn stake_lab() -> Weight { + 116_764_000_u64 + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) + } + // Storage: Labs Labs (r:1 w:1) + // Storage: Orders PendingOrdersBySeller (r:1 w:0) + // Storage: Timestamp Now (r:1 w:0) + // Storage: Labs UnstakeTime (r:1 w:0) + fn unstake_lab() -> Weight { + 38_567_000_u64 + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + // Storage: Labs LabVerifierKey (r:1 w:0) + // Storage: Labs Labs (r:1 w:1) + // Storage: Timestamp Now (r:1 w:0) + // Storage: Labs PalletAccount (r:1 w:0) + // Storage: System Account (r:1 w:1) + // Storage: Labs TotalStakedAmount (r:0 w:1) + fn retrieve_unstake_amount() -> Weight { + 81_605_000_u64 + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } + // Storage: Labs LabVerifierKey (r:1 w:0) + // Storage: Labs MinimumStakeAmount (r:0 w:1) + fn update_minimum_stake_amount() -> Weight { + 29_159_000_u64 + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + // Storage: Labs LabVerifierKey (r:1 w:0) + // Storage: Labs UnstakeTime (r:0 w:1) + fn update_unstake_time() -> Weight { + 18_458_000_u64 + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } // Storage: Labs LabVerifierKey (r:1 w:1) fn update_admin_key() -> Weight { - 22_246_000_u64 + 18_698_000_u64 .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } diff --git a/pallets/labs/tests/Cargo.toml b/pallets/labs/tests/Cargo.toml new file mode 100644 index 00000000..103704d2 --- /dev/null +++ b/pallets/labs/tests/Cargo.toml @@ -0,0 +1,92 @@ +[package] +name = 'labs-tests' +version = '0.1.0' +repository = '' +edition = '2018' +authors = ['agustinustheoo '] +description = '' +homepage = '' +license = 'AGPL-3.0' + +[package.metadata.docs.rs] +targets = ['x86_64-unknown-linux-gnu'] + +# alias "parity-scale-code" to "codec" +[dependencies.codec] +default-features = false +features = ['derive'] +package = 'parity-scale-codec' +version = '2.0.0' + +[dependencies] +scale-info = { version = "1.0", default-features = false, features = ["derive"] } + +frame-support = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } +frame-system = { 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 } + +sp-std = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } +sp-core = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } +sp-runtime = { 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 } + +primitives-area-code = { path = '../../../primitives/area-code', default-features = false } +primitives-stake-status = { path = '../../../primitives/stake-status', default-features = false } +primitives-verification-status = { path = '../../../primitives/verification-status', default-features = false } + +traits-order = { path = '../../../traits/order', default-features = false } +traits-services = { path = '../../../traits/services', default-features = false } +traits-user-profile = { path = '../../../traits/user-profile', default-features = false } +traits-certifications = { path = '../../../traits/certifications', default-features = false } +traits-genetic-testing = { path = '../../../traits/genetic-testing', default-features = false } + +## Substrate Pallet Dependencies +pallet-timestamp = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } +pallet-balances = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false } +pallet-randomness-collective-flip = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false } + +# Local Dependencies +labs = { path = '../../labs', default-features = false } +orders = { path = '../../orders', default-features = false } +services = { path = '../../services', default-features = false } +user-profile = { path = '../../user-profile', default-features = false } +certifications = { path = '../../certifications', default-features = false } +genetic-testing = { path = '../../genetic-testing', default-features = false } + +[dev-dependencies] +serde = { default-features = false, version = "1.0.119" } + +[features] +default = ['std'] +std = [ + 'codec/std', + 'scale-info/std', + + 'frame-support/std', + 'frame-system/std', + + 'sp-std/std', + 'sp-core/std', + 'sp-runtime/std', + 'sp-io/std', + + 'pallet-balances/std', + 'pallet-timestamp/std', + 'pallet-randomness-collective-flip/std', + + 'primitives-area-code/std', + 'primitives-stake-status/std', + 'primitives-verification-status/std', + + 'traits-order/std', + 'traits-services/std', + 'traits-user-profile/std', + 'traits-certifications/std', + 'traits-genetic-testing/std', + + 'labs/std', + 'orders/std', + 'services/std', + 'certifications/std', + 'user-profile/std', +] diff --git a/pallets/labs/tests/src/lib.rs b/pallets/labs/tests/src/lib.rs new file mode 100644 index 00000000..3a967c81 --- /dev/null +++ b/pallets/labs/tests/src/lib.rs @@ -0,0 +1,1720 @@ +mod mock; + +#[cfg(test)] +mod tests { + use crate::mock::*; + + use labs::{Error, Event as EventC, Lab, LabInfo, LabVerifierKey, PalletAccount}; + + use frame_support::{ + assert_noop, assert_ok, + sp_runtime::{ + traits::{Hash, Keccak256}, + SaturatedConversion, + }, + }; + use frame_system::RawOrigin; + + use genetic_testing::{DnaSampleStatus, DnaSampleTracking, DnaTestResultSubmission}; + use orders::{Order, OrderStatus}; + use services::ServiceInfo; + + use primitives_area_code::{CityCode, CountryCode, CountryRegionCode, RegionCode}; + use primitives_stake_status::StakeStatus; + use primitives_verification_status::VerificationStatus; + + use traits_services::types::{CurrencyType, ExpectedDuration, PriceByCurrency, ServiceFlow}; + + #[test] + fn register_lab_works() { + ::default().existential_deposit(1).build().execute_with(|| { + assert_ok!(Labs::register_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + assert_eq!( + Labs::lab_by_account_id(1), + Some(Lab { + account_id: 1, + services: Vec::new(), + certifications: Vec::new(), + unstake_at: 0u64.saturated_into(), + retrieve_unstake_at: 0u64.saturated_into(), + stake_amount: 0u128.saturated_into(), + stake_status: StakeStatus::default(), + verification_status: VerificationStatus::default(), + info: LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + }) + ); + + let country_region_code = CountryRegionCode::from_vec("DC-DB".as_bytes().to_vec()); + let city_code = CityCode::from_vec("CITY".as_bytes().to_vec()); + + assert_eq!( + Labs::labs_by_country_region_city(&country_region_code, &city_code), + Some(vec![1]) + ); + assert_eq!(Labs::lab_count(), Some(1)); + assert_eq!( + Labs::lab_count_by_country_region_city(&country_region_code, &city_code), + Some(1) + ); + }) + } + + #[test] + fn update_lab_works() { + ::default().existential_deposit(1).build().execute_with(|| { + assert_ok!(Labs::register_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + assert_ok!(Labs::update_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Labs".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + assert_eq!( + Labs::lab_by_account_id(1), + Some(Lab { + account_id: 1, + services: Vec::new(), + certifications: Vec::new(), + unstake_at: 0u64.saturated_into(), + retrieve_unstake_at: 0u64.saturated_into(), + stake_amount: 0u128.saturated_into(), + stake_status: StakeStatus::default(), + verification_status: VerificationStatus::default(), + info: LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Labs".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + }) + ); + + let old_country_region_code = CountryRegionCode::from_vec("DC-DB".as_bytes().to_vec()); + let old_city_code = CityCode::from_vec("CITY".as_bytes().to_vec()); + + assert_ok!(Labs::update_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Labs".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("ID".as_bytes().to_vec()), + region: RegionCode::from_vec("WJ".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + assert_eq!( + Labs::lab_by_account_id(1), + Some(Lab { + account_id: 1, + services: Vec::new(), + certifications: Vec::new(), + unstake_at: 0u64.saturated_into(), + retrieve_unstake_at: 0u64.saturated_into(), + stake_amount: 0u128.saturated_into(), + stake_status: StakeStatus::default(), + verification_status: VerificationStatus::default(), + info: LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Labs".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("ID".as_bytes().to_vec()), + region: RegionCode::from_vec("WJ".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + }) + ); + + assert_eq!( + Labs::labs_by_country_region_city(&old_country_region_code, &old_city_code), + Some(Vec::new()) + ); + assert_eq!( + Labs::lab_count_by_country_region_city(&old_country_region_code, &old_city_code), + Some(0) + ); + + let new_country_region_code = CountryRegionCode::from_vec("ID-WJ".as_bytes().to_vec()); + let new_city_code = CityCode::from_vec("CITY".as_bytes().to_vec()); + + assert_eq!( + Labs::labs_by_country_region_city(&new_country_region_code, &new_city_code), + Some(vec![1]) + ); + assert_eq!( + Labs::lab_count_by_country_region_city(new_country_region_code, new_city_code), + Some(1) + ); + }) + } + + #[test] + fn update_lab_verification_status_works() { + ::default().existential_deposit(1).build().execute_with(|| { + assert_ok!(Labs::register_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + LabVerifierKey::::put(2); + + assert_ok!(Labs::update_lab_verification_status( + Origin::signed(2), + 1, + VerificationStatus::Verified, + )); + + assert_eq!( + Labs::lab_by_account_id(1), + Some(Lab { + account_id: 1, + services: Vec::new(), + certifications: Vec::new(), + unstake_at: 0u64.saturated_into(), + retrieve_unstake_at: 0u64.saturated_into(), + stake_amount: 0u128.saturated_into(), + stake_status: StakeStatus::default(), + verification_status: VerificationStatus::Verified, + info: LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + }) + ); + }) + } + + #[test] + fn deregister_lab_works() { + ::default().existential_deposit(1).build().execute_with(|| { + assert_ok!(Labs::register_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + let country_region_code = CountryRegionCode::from_vec("DC-DB".as_bytes().to_vec()); + let city_code = CityCode::from_vec("CITY".as_bytes().to_vec()); + + assert_ok!(Labs::deregister_lab(Origin::signed(1))); + + assert_eq!(Labs::lab_by_account_id(1), None); + + assert_eq!( + Labs::labs_by_country_region_city(&country_region_code, &city_code), + Some(Vec::new()) + ); + + assert_eq!(Labs::lab_count(), Some(0)); + + assert_eq!( + Labs::lab_count_by_country_region_city(&country_region_code, &city_code), + Some(0) + ); + }) + } + + #[test] + fn cant_register_lab_when_already_registered() { + ::default().existential_deposit(1).build().execute_with(|| { + assert_ok!(Labs::register_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + assert_noop!( + Labs::register_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + ), + Error::::LabAlreadyRegistered + ); + }) + } + + #[test] + fn cant_update_lab_verification_status_when_not_admin() { + ::default().existential_deposit(1).build().execute_with(|| { + assert_ok!(Labs::register_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + assert_noop!( + Labs::update_lab_verification_status( + Origin::signed(2), + 1, + VerificationStatus::Verified, + ), + Error::::Unauthorized + ); + }) + } + + #[test] + fn cant_update_lab_verification_status_when_not_exist() { + ::default().existential_deposit(1).build().execute_with(|| { + LabVerifierKey::::put(2); + + assert_noop!( + Labs::update_lab_verification_status( + Origin::signed(2), + 1, + VerificationStatus::Verified, + ), + Error::::LabDoesNotExist + ); + }) + } + + #[test] + fn cant_update_and_delete_lab_when_not_exist() { + ::default().existential_deposit(1).build().execute_with(|| { + assert_noop!( + Labs::update_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + ), + Error::::LabDoesNotExist + ); + + LabVerifierKey::::put(2); + + assert_noop!( + Labs::update_lab_verification_status( + Origin::signed(2), + 1, + VerificationStatus::Verified + ), + Error::::LabDoesNotExist + ); + + assert_noop!(Labs::deregister_lab(Origin::signed(1)), Error::::LabDoesNotExist); + }) + } + + #[test] + fn call_event_should_work() { + ::default().existential_deposit(1).build().execute_with(|| { + System::set_block_number(1); + assert_ok!(Labs::register_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + System::assert_last_event(Event::Labs(EventC::LabRegistered( + Lab { + account_id: 1, + services: Vec::new(), + certifications: Vec::new(), + unstake_at: 0u64.saturated_into(), + retrieve_unstake_at: 0u64.saturated_into(), + stake_amount: 0u128.saturated_into(), + stake_status: StakeStatus::default(), + verification_status: VerificationStatus::default(), + info: LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes(), + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + }, + }, + 1, + ))); + + assert_ok!(Labs::update_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Labs".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + System::assert_last_event(Event::Labs(EventC::LabUpdated( + Lab { + account_id: 1, + services: Vec::new(), + certifications: Vec::new(), + unstake_at: 0u64.saturated_into(), + retrieve_unstake_at: 0u64.saturated_into(), + stake_amount: 0u128.saturated_into(), + stake_status: StakeStatus::default(), + verification_status: VerificationStatus::default(), + info: LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes(), + ), + name: "DeBio Labs".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + }, + }, + 1, + ))); + + LabVerifierKey::::put(2); + + assert_ok!(Labs::update_lab_verification_status( + Origin::signed(2), + 1, + VerificationStatus::Verified + )); + + System::assert_last_event(Event::Labs(EventC::LabUpdateVerificationStatus( + Lab { + account_id: 1, + services: Vec::new(), + certifications: Vec::new(), + unstake_at: 0u64.saturated_into(), + retrieve_unstake_at: 0u64.saturated_into(), + stake_amount: 0u128.saturated_into(), + stake_status: StakeStatus::default(), + verification_status: VerificationStatus::Verified, + info: LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes(), + ), + name: "DeBio Labs".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + }, + }, + 2, + ))); + + assert_ok!(Labs::deregister_lab(Origin::signed(1))); + System::assert_last_event(Event::Labs(EventC::LabDeregistered( + Lab { + account_id: 1, + services: Vec::new(), + certifications: Vec::new(), + unstake_at: 0u64.saturated_into(), + retrieve_unstake_at: 0u64.saturated_into(), + stake_amount: 0u128.saturated_into(), + stake_status: StakeStatus::default(), + verification_status: VerificationStatus::Verified, + info: LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes(), + ), + name: "DeBio Labs".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + }, + }, + 1, + ))) + }) + } + + #[test] + fn stake_lab_works() { + ::default().existential_deposit(1).build().execute_with(|| { + assert_ok!(Balances::set_balance( + RawOrigin::Root.into(), + 1, + 60000000000000000000000u128.saturated_into(), + 0 + )); + + LabVerifierKey::::put(2); + + assert_ok!(Labs::update_minimum_stake_amount( + Origin::signed(2), + 60000000000000000000000u128.saturated_into(), + )); + + assert_ok!(Labs::register_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + assert_ok!(Labs::stake_lab(Origin::signed(1),)); + + assert_eq!( + Labs::lab_by_account_id(1), + Some(Lab { + account_id: 1, + services: Vec::new(), + certifications: Vec::new(), + unstake_at: 0u64.saturated_into(), + retrieve_unstake_at: 0u64.saturated_into(), + stake_amount: 60000000000000000000000u128.saturated_into(), + stake_status: StakeStatus::Staked, + verification_status: VerificationStatus::default(), + info: LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + }) + ); + }) + } + + #[test] + fn cant_stake_lab_when_not_exist() { + ::default().existential_deposit(1).build().execute_with(|| { + assert_noop!(Labs::stake_lab(Origin::signed(1),), Error::::LabDoesNotExist); + }) + } + + #[test] + fn cant_stake_lab_when_already_staked() { + ::default().existential_deposit(1).build().execute_with(|| { + assert_ok!(Balances::set_balance( + RawOrigin::Root.into(), + 1, + 60000000000000000000000u128.saturated_into(), + 0 + )); + + assert_ok!(Labs::register_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + assert_ok!(Labs::stake_lab(Origin::signed(1),)); + + assert_eq!( + Labs::lab_by_account_id(1), + Some(Lab { + account_id: 1, + services: Vec::new(), + certifications: Vec::new(), + unstake_at: 0u64.saturated_into(), + retrieve_unstake_at: 0u64.saturated_into(), + stake_amount: 50000000000000000000000u128.saturated_into(), + stake_status: StakeStatus::Staked, + verification_status: VerificationStatus::default(), + info: LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + }) + ); + + assert_noop!(Labs::stake_lab(Origin::signed(1),), Error::::LabAlreadyStaked); + }) + } + + #[test] + fn stake_lab_when_waiting_for_unstake_works() { + ::default().existential_deposit(1).build().execute_with(|| { + assert_ok!(Balances::set_balance( + RawOrigin::Root.into(), + 1, + 60000000000000000000000u128.saturated_into(), + 0 + )); + + PalletAccount::::put(4); + LabVerifierKey::::put(2); + + assert_ok!(Labs::register_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + assert_ok!(Labs::stake_lab(Origin::signed(1),)); + + assert_ok!(Labs::unstake_lab(Origin::signed(1),)); + + assert_ok!(Labs::stake_lab(Origin::signed(1),)); + + assert_eq!( + Labs::lab_by_account_id(1), + Some(Lab { + account_id: 1, + services: Vec::new(), + certifications: Vec::new(), + unstake_at: 0u64.saturated_into(), + retrieve_unstake_at: 0u64.saturated_into(), + stake_amount: 50000000000000000000000u128.saturated_into(), + stake_status: StakeStatus::Staked, + verification_status: VerificationStatus::default(), + info: LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + }) + ); + }) + } + + #[test] + fn cant_stake_lab_when_insufficient_funds() { + ::default().existential_deposit(1).build().execute_with(|| { + assert_ok!(Labs::register_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + assert_noop!(Labs::stake_lab(Origin::signed(1),), Error::::InsufficientFunds); + + assert_eq!( + Labs::lab_by_account_id(1), + Some(Lab { + account_id: 1, + services: Vec::new(), + certifications: Vec::new(), + unstake_at: 0u64.saturated_into(), + retrieve_unstake_at: 0u64.saturated_into(), + stake_amount: 0u128.saturated_into(), + stake_status: StakeStatus::default(), + verification_status: VerificationStatus::default(), + info: LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + }) + ); + }) + } + + #[test] + fn update_minimum_stake_amount_works() { + ::default().existential_deposit(1).build().execute_with(|| { + LabVerifierKey::::put(2); + + assert_ok!(Labs::update_minimum_stake_amount( + Origin::signed(2), + 60000000000000000000000u128.saturated_into(), + )); + + assert_eq!( + Labs::minimum_stake_amount(), + Some(60000000000000000000000u128.saturated_into()) + ); + }) + } + + #[test] + fn cant_update_minimum_stake_amount_when_unauthorized() { + ::default().existential_deposit(1).build().execute_with(|| { + LabVerifierKey::::put(3); + + assert_noop!( + Labs::update_minimum_stake_amount( + Origin::signed(2), + 60000000000000000000000u128.saturated_into(), + ), + Error::::Unauthorized + ); + }) + } + + #[test] + fn update_unstake_time_works() { + ::default().existential_deposit(1).build().execute_with(|| { + LabVerifierKey::::put(2); + + assert_ok!(Labs::update_unstake_time(Origin::signed(2), 1000u64.saturated_into(),)); + + assert_eq!(Labs::unstake_time(), Some(1000u64.saturated_into())); + }) + } + + #[test] + fn cant_update_unstake_time_when_unauthorized() { + ::default().existential_deposit(1).build().execute_with(|| { + LabVerifierKey::::put(3); + + assert_noop!( + Labs::update_unstake_time(Origin::signed(2), 1000u64.saturated_into(),), + Error::::Unauthorized + ); + }) + } + + #[test] + fn update_admin_key_works() { + ::default().existential_deposit(1).build().execute_with(|| { + LabVerifierKey::::put(2); + + assert_eq!(Labs::admin_key(), 2); + + assert_ok!(Labs::update_admin_key(Origin::signed(2), 1,)); + + assert_eq!(Labs::admin_key(), 1); + }) + } + + #[test] + fn cant_update_admin_key_when_unauthorized() { + ::default().existential_deposit(1).build().execute_with(|| { + LabVerifierKey::::put(3); + + assert_noop!( + Labs::update_admin_key(Origin::signed(2), 1,), + Error::::Unauthorized + ); + }) + } + + #[test] + fn sudo_update_admin_key_works() { + ::default().existential_deposit(1).build().execute_with(|| { + assert_ok!(Labs::sudo_update_admin_key(Origin::root(), 1)); + + assert_eq!(Labs::admin_key(), 1); + }) + } + + #[test] + fn cant_sudo_update_admin_key_when_not_sudo() { + ::default().existential_deposit(1).build().execute_with(|| { + assert_noop!( + Labs::update_admin_key(Origin::signed(2), 1,), + Error::::Unauthorized + ); + }) + } + + #[test] + fn unstake_lab_works() { + ::default().existential_deposit(1).build().execute_with(|| { + assert_ok!(Balances::set_balance( + RawOrigin::Root.into(), + 1, + 60000000000000000000000u128.saturated_into(), + 0 + )); + + PalletAccount::::put(4); + LabVerifierKey::::put(2); + + assert_ok!(Labs::update_minimum_stake_amount( + Origin::signed(2), + 0u128.saturated_into(), + )); + + assert_ok!(Labs::register_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + assert_ok!(Labs::stake_lab(Origin::signed(1),)); + + assert_ok!(Labs::unstake_lab(Origin::signed(1),)); + + assert_eq!( + Labs::lab_by_account_id(1), + Some(Lab { + account_id: 1, + services: Vec::new(), + certifications: Vec::new(), + unstake_at: 0u64.saturated_into(), + retrieve_unstake_at: 0u64.saturated_into(), + stake_amount: 0u128.saturated_into(), + stake_status: StakeStatus::WaitingForUnstaked, + verification_status: VerificationStatus::default(), + info: LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + }) + ); + }) + } + + #[test] + fn cant_unstake_lab_when_not_exist() { + ::default().existential_deposit(1).build().execute_with(|| { + assert_noop!(Labs::stake_lab(Origin::signed(1),), Error::::LabDoesNotExist); + }) + } + + #[test] + fn cant_unstake_lab_when_not_staked() { + ::default().existential_deposit(1).build().execute_with(|| { + assert_ok!(Labs::register_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + assert_noop!(Labs::unstake_lab(Origin::signed(1),), Error::::LabIsNotStaked); + }) + } + + #[test] + fn cant_unstake_lab_when_pending_order_exists() { + ::default().existential_deposit(1).build().execute_with(|| { + assert_ok!(Balances::set_balance( + RawOrigin::Root.into(), + 1, + 60000000000000000000000u128.saturated_into(), + 0 + )); + + PalletAccount::::put(4); + LabVerifierKey::::put(2); + + assert_ok!(Labs::update_minimum_stake_amount( + Origin::signed(2), + 0u128.saturated_into(), + )); + assert_ok!(Labs::register_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + assert_ok!(Labs::stake_lab(Origin::signed(1),)); + + assert_ok!(Services::create_service( + Origin::signed(1), + ServiceInfo { + name: "DeBio name".as_bytes().to_vec(), + prices_by_currency: vec![PriceByCurrency::default()], + expected_duration: ExpectedDuration::default(), + category: "DeBio category".as_bytes().to_vec(), + description: "This is my description".as_bytes().to_vec(), + test_result_sample: "Test result sample".as_bytes().to_vec(), + dna_collection_process: "Dna Collection Process".as_bytes().to_vec(), + long_description: Some("This is my long description".as_bytes().to_vec()), + image: Some("This is my image".as_bytes().to_vec()), + }, + ServiceFlow::default() + )); + + let _lab = Labs::lab_by_account_id(1).unwrap(); + + assert_ok!(Orders::create_order( + Origin::signed(2), + _lab.services[0], + 0, + Keccak256::hash("0xhJ7TRe456FADD2726A132ABJK5RCc9E6fC5869F4".as_bytes()), + ServiceFlow::StakingRequestService + )); + + let _order_id = Orders::last_order_by_customer_id(2).unwrap(); + let _dna_sample = GeneticTesting::dna_samples_by_lab_id(1).unwrap(); + + assert_eq!( + Orders::order_by_id(&_order_id), + Some(Order { + id: _order_id, + service_id: _lab.services[0], + customer_id: 2, + customer_box_public_key: Keccak256::hash( + "0xhJ7TRe456FADD2726A132ABJK5RCc9E6fC5869F4".as_bytes() + ), + seller_id: 1, + dna_sample_tracking_id: _dna_sample[0].clone(), + currency: CurrencyType::default(), + prices: PriceByCurrency::default().price_components, + additional_prices: PriceByCurrency::default().additional_prices, + status: OrderStatus::default(), + order_flow: ServiceFlow::StakingRequestService, + created_at: 0, + updated_at: 0 + }) + ); + + assert_noop!(Labs::unstake_lab(Origin::signed(1),), Error::::LabHasPendingOrders); + }) + } + + #[test] + fn unstake_lab_after_pending_order_is_rejected() { + ::default().existential_deposit(1).build().execute_with(|| { + assert_ok!(Balances::set_balance( + RawOrigin::Root.into(), + 1, + 60000000000000000000000u128.saturated_into(), + 0 + )); + + PalletAccount::::put(4); + LabVerifierKey::::put(2); + + assert_ok!(Labs::update_minimum_stake_amount( + Origin::signed(2), + 0u128.saturated_into(), + )); + + assert_ok!(Labs::register_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + assert_ok!(Labs::stake_lab(Origin::signed(1),)); + + assert_ok!(Services::create_service( + Origin::signed(1), + ServiceInfo { + name: "DeBio service name".as_bytes().to_vec(), + prices_by_currency: vec![PriceByCurrency::default()], + expected_duration: ExpectedDuration::default(), + category: "DeBio service category".as_bytes().to_vec(), + description: "DeBio service description".as_bytes().to_vec(), + dna_collection_process: "DeBio service dna_collection_process" + .as_bytes() + .to_vec(), + test_result_sample: "DeBio service test_result_sample".as_bytes().to_vec(), + long_description: Some("DeBio service long_description".as_bytes().to_vec()), + image: Some("DeBio service image".as_bytes().to_vec()), + }, + ServiceFlow::default() + )); + + let _lab = Labs::lab_by_account_id(1).unwrap(); + + assert_ok!(Orders::create_order( + Origin::signed(2), + _lab.services[0], + 0, + Keccak256::hash("0xhJ7TRe456FADD2726A132ABJK5RCc9E6fC5869F4".as_bytes()), + ServiceFlow::StakingRequestService + )); + + let _dna_sample = GeneticTesting::dna_samples_by_lab_id(1).unwrap(); + + assert_ok!(GeneticTesting::reject_dna_sample( + Origin::signed(1), + _dna_sample[0].clone(), + "Reject DNA Title".as_bytes().to_vec(), + "Reject DNA Description".as_bytes().to_vec() + )); + + let _dna_sample_info = + GeneticTesting::dna_sample_by_tracking_id(_dna_sample[0].clone()).unwrap(); + + assert_eq!(_dna_sample_info.get_tracking_id(), &_dna_sample[0]); + assert_eq!(_dna_sample_info.is_rejected(), true); + + assert_ok!(Labs::unstake_lab(Origin::signed(1),)); + }) + } + + #[test] + fn unstake_lab_after_pending_order_is_result_ready() { + ::default().existential_deposit(1).build().execute_with(|| { + assert_ok!(Balances::set_balance( + RawOrigin::Root.into(), + 1, + 60000000000000000000000u128.saturated_into(), + 0 + )); + + PalletAccount::::put(4); + LabVerifierKey::::put(2); + + assert_ok!(Labs::update_minimum_stake_amount( + Origin::signed(2), + 0u128.saturated_into(), + )); + + assert_ok!(Labs::register_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + assert_ok!(Labs::stake_lab(Origin::signed(1),)); + + assert_ok!(UserProfile::set_eth_address( + Origin::signed(1), + EthereumAddress([b'X'; 20]) + )); + + assert_ok!(Services::create_service( + Origin::signed(1), + ServiceInfo { + name: "DeBio service name".as_bytes().to_vec(), + prices_by_currency: vec![PriceByCurrency::default()], + expected_duration: ExpectedDuration::default(), + category: "DeBio service category".as_bytes().to_vec(), + description: "DeBio service description".as_bytes().to_vec(), + dna_collection_process: "DeBio service dna_collection_process" + .as_bytes() + .to_vec(), + test_result_sample: "DeBio service test_result_sample".as_bytes().to_vec(), + long_description: Some("DeBio service long_description".as_bytes().to_vec()), + image: Some("DeBio service image".as_bytes().to_vec()), + }, + ServiceFlow::default() + )); + + let _lab = Labs::lab_by_account_id(1).unwrap(); + + assert_ok!(Orders::create_order( + Origin::signed(2), + _lab.services[0], + 0, + Keccak256::hash("0xhJ7TRe456FADD2726A132ABJK5RCc9E6fC5869F4".as_bytes()), + ServiceFlow::StakingRequestService + )); + + let _dna_sample = GeneticTesting::dna_samples_by_lab_id(1).unwrap(); + + assert_ok!(GeneticTesting::submit_test_result( + Origin::signed(1), + _dna_sample[0].clone(), + DnaTestResultSubmission { + comments: Some("DNA Test Result comments".as_bytes().to_vec()), + result_link: Some("DNA Test Result result_link".as_bytes().to_vec()), + report_link: Some("DNA Test Result report_link".as_bytes().to_vec()) + } + )); + + let _dna_test_result = + GeneticTesting::dna_test_result_by_tracking_id(_dna_sample[0].clone()).unwrap(); + + assert_eq!(_dna_test_result.tracking_id, _dna_sample[0].clone()); + assert_eq!(_dna_test_result.lab_id, Some(1)); + assert_eq!(_dna_test_result.owner_id, 2); + assert_eq!( + _dna_test_result.comments, + Some("DNA Test Result comments".as_bytes().to_vec()) + ); + assert_eq!( + _dna_test_result.result_link, + Some("DNA Test Result result_link".as_bytes().to_vec()) + ); + assert_eq!( + _dna_test_result.report_link, + Some("DNA Test Result report_link".as_bytes().to_vec()) + ); + + assert_ok!(GeneticTesting::process_dna_sample( + Origin::signed(1), + _dna_sample[0].clone(), + DnaSampleStatus::ResultReady + )); + + let _dna_sample_info = + GeneticTesting::dna_sample_by_tracking_id(_dna_sample[0].clone()).unwrap(); + + assert_eq!(_dna_sample_info.get_tracking_id(), &_dna_sample[0]); + assert_eq!(_dna_sample_info.process_success(), true); + + assert_ok!(Labs::unstake_lab(Origin::signed(1),)); + }) + } + + #[test] + fn retrieve_unstake_amount_works() { + ::default().existential_deposit(1).build().execute_with(|| { + assert_ok!(Balances::set_balance( + RawOrigin::Root.into(), + 1, + 60000000000000000000000u128.saturated_into(), + 0 + )); + + PalletAccount::::put(4); + LabVerifierKey::::put(2); + + assert_ok!(Labs::register_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + assert_ok!(Labs::stake_lab(Origin::signed(1),)); + + assert_ok!(Labs::unstake_lab(Origin::signed(1),)); + + assert_eq!( + Labs::lab_by_account_id(1), + Some(Lab { + account_id: 1, + services: Vec::new(), + certifications: Vec::new(), + unstake_at: 0u64.saturated_into(), + retrieve_unstake_at: 0u64.saturated_into(), + stake_amount: 50000000000000000000000u128.saturated_into(), + stake_status: StakeStatus::WaitingForUnstaked, + verification_status: VerificationStatus::default(), + info: LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + }) + ); + + assert_ok!(Labs::retrieve_unstake_amount(Origin::signed(2), 1,)); + + assert_eq!( + Labs::lab_by_account_id(1), + Some(Lab { + account_id: 1, + services: Vec::new(), + certifications: Vec::new(), + unstake_at: 0u64.saturated_into(), + retrieve_unstake_at: 0u64.saturated_into(), + stake_amount: 0u128.saturated_into(), + stake_status: StakeStatus::default(), + verification_status: VerificationStatus::default(), + info: LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + }) + ); + }) + } + + #[test] + fn cant_retrieve_unstake_amount_when_not_exist() { + ::default().existential_deposit(1).build().execute_with(|| { + LabVerifierKey::::put(2); + + assert_noop!( + Labs::retrieve_unstake_amount(Origin::signed(2), 1,), + Error::::LabDoesNotExist + ); + }) + } + + #[test] + fn cant_retrieve_unstake_amount_when_not_waiting_for_unstake() { + ::default().existential_deposit(1).build().execute_with(|| { + LabVerifierKey::::put(2); + + assert_ok!(Labs::register_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + assert_noop!( + Labs::retrieve_unstake_amount(Origin::signed(2), 1,), + Error::::LabIsNotWaitingForUnstake + ); + }) + } + + #[test] + fn cant_retrieve_unstake_amount_before_unstake_time() { + ::default().existential_deposit(1).build().execute_with(|| { + assert_ok!(Balances::set_balance( + RawOrigin::Root.into(), + 1, + 60000000000000000000000u128.saturated_into(), + 0 + )); + + PalletAccount::::put(4); + LabVerifierKey::::put(2); + + assert_ok!(Labs::update_unstake_time(Origin::signed(2), 100000u64.saturated_into(),)); + + assert_ok!(Labs::register_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + assert_ok!(Labs::stake_lab(Origin::signed(1),)); + + assert_ok!(Labs::unstake_lab(Origin::signed(1),)); + + assert_eq!( + Labs::lab_by_account_id(1), + Some(Lab { + account_id: 1, + services: Vec::new(), + certifications: Vec::new(), + unstake_at: 0u64.saturated_into(), + retrieve_unstake_at: 100000u64.saturated_into(), + stake_amount: 50000000000000000000000u128.saturated_into(), + stake_status: StakeStatus::WaitingForUnstaked, + verification_status: VerificationStatus::default(), + info: LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + }) + ); + + assert_noop!( + Labs::retrieve_unstake_amount(Origin::signed(2), 1,), + Error::::LabCannotUnstakeBeforeUnstakeTime + ); + }) + } + + #[test] + fn cant_unstake_lab_when_insufficient_pallet_funds() { + ::default().existential_deposit(1).build().execute_with(|| { + LabVerifierKey::::put(2); + + assert_ok!(Balances::set_balance( + RawOrigin::Root.into(), + 1, + 60000000000000000000000u128.saturated_into(), + 0 + )); + + assert_ok!(Labs::update_minimum_stake_amount( + Origin::signed(2), + 60000000000000000000000u128.saturated_into(), + )); + + assert_ok!(Labs::register_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + assert_ok!(Labs::stake_lab(Origin::signed(1),)); + + assert_ok!(Labs::unstake_lab(Origin::signed(1),)); + + assert_ok!(Balances::set_balance( + RawOrigin::Root.into(), + PalletAccount::::get(), + 0u128.saturated_into(), + 0 + )); + + assert_noop!( + Labs::retrieve_unstake_amount(Origin::signed(2), 1,), + Error::::InsufficientPalletFunds + ); + }) + } +} diff --git a/pallets/labs/tests/src/mock.rs b/pallets/labs/tests/src/mock.rs new file mode 100644 index 00000000..6a7a12c1 --- /dev/null +++ b/pallets/labs/tests/src/mock.rs @@ -0,0 +1,190 @@ +use frame_support::{parameter_types, PalletId}; +use frame_system as system; +use pallet_balances::AccountData; +use scale_info::TypeInfo; +use sp_core::{Decode, Encode, RuntimeDebug, H256}; +use sp_runtime::{ + testing::Header, + traits::{BlakeTwo256, IdentityLookup}, +}; + +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; + +#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, Default, RuntimeDebug, TypeInfo)] +pub struct EthereumAddress(pub [u8; 20]); + +pub type AccountId = u64; + +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Pallet, Call, Config, Storage, Event}, + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, + Labs: labs::{Pallet, Call, Storage, Event}, + Services: services::{Pallet, Call, Storage, Event}, + Certifications: certifications::{Pallet, Call, Storage, Event}, + Orders: orders::{Pallet, Call, Storage, Event}, + GeneticTesting: genetic_testing::{Pallet, Call, Storage, Event}, + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, + RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage}, + UserProfile: user_profile::{Pallet, Call, Storage, Event} + } +); + +parameter_types! { + pub const BlockHashCount: u64 = 250; + pub const SS58Prefix: u8 = 42; + pub BlockWeights: frame_system::limits::BlockWeights = + frame_system::limits::BlockWeights::simple_max(1024); +} + +impl pallet_randomness_collective_flip::Config for Test {} + +impl system::Config for Test { + type BaseCallFilter = frame_support::traits::Everything; + type BlockWeights = (); + type BlockLength = (); + type AccountId = AccountId; + type Call = Call; + type Lookup = IdentityLookup; + type Index = u64; + type BlockNumber = u64; + type Hash = H256; + type Hashing = BlakeTwo256; + type Header = Header; + type Event = Event; + type Origin = Origin; + type BlockHashCount = BlockHashCount; + type DbWeight = (); + type Version = (); + type PalletInfo = PalletInfo; + type OnNewAccount = (); + type OnKilledAccount = (); + type AccountData = AccountData; + type SystemWeightInfo = (); + type SS58Prefix = SS58Prefix; + type OnSetCode = (); +} + +pub type Moment = u64; +pub const MILLISECS_PER_BLOCK: Moment = 6000; +pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; + +parameter_types! { + pub const MinimumPeriod: Moment = SLOT_DURATION / 2; +} + +impl pallet_timestamp::Config for Test { + /// A timestamp: milliseconds since the unix epoch. + type Moment = Moment; + type OnTimestampSet = (); + type MinimumPeriod = MinimumPeriod; + type WeightInfo = (); +} + +type Balance = u128; + +parameter_types! { + pub static ExistentialDeposit: Balance = 0; + pub const LabPalletId: PalletId = PalletId(*b"dbio/lab"); +} + +impl pallet_balances::Config for Test { + type MaxLocks = (); + type MaxReserves = (); + type ReserveIdentifier = [u8; 8]; + /// The type for recording an account's balance. + type Balance = Balance; + /// The ubiquitous event type. + type Event = Event; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); +} + +impl labs::Config for Test { + type Event = Event; + type Currency = Balances; + type Services = Services; + type Orders = Orders; + type Certifications = Certifications; + type EthereumAddress = EthereumAddress; + type UserProfile = UserProfile; + type LabWeightInfo = (); + type PalletId = LabPalletId; +} + +impl services::Config for Test { + type Event = Event; + type Currency = Balances; + type ServiceOwner = Labs; + type WeightInfo = (); +} + +impl certifications::Config for Test { + type Event = Event; + type CertificationOwner = Labs; + type WeightInfo = (); +} + +impl genetic_testing::Config for Test { + type Event = Event; + type Orders = Orders; + type RandomnessSource = RandomnessCollectiveFlip; + type GeneticTestingWeightInfo = (); +} + +impl orders::Config for Test { + type Event = Event; + type Services = Services; + type GeneticTesting = GeneticTesting; + type Currency = Balances; + type OrdersWeightInfo = (); +} + +impl user_profile::Config for Test { + type Event = Event; + type EthereumAddress = EthereumAddress; + type WeightInfo = (); +} + +#[cfg(test)] +use sp_io::TestExternalities; + +#[cfg(test)] +pub struct ExternalityBuilder { + existential_deposit: u128, +} + +#[cfg(test)] +impl Default for ExternalityBuilder { + fn default() -> Self { + Self { existential_deposit: 1 } + } +} + +#[cfg(test)] +impl ExternalityBuilder { + pub fn existential_deposit(mut self, existential_deposit: u128) -> Self { + self.existential_deposit = existential_deposit; + self + } + pub fn set_associated_consts(&self) { + EXISTENTIAL_DEPOSIT.with(|v| *v.borrow_mut() = self.existential_deposit); + } + pub fn build(&self) -> TestExternalities { + self.set_associated_consts(); + let mut storage = system::GenesisConfig::default().build_storage::().unwrap(); + pallet_balances::GenesisConfig:: { balances: { vec![] } } + .assimilate_storage(&mut storage) + .unwrap(); + let mut ext = sp_io::TestExternalities::new(storage); + ext.execute_with(|| System::set_block_number(1)); + ext + } +} diff --git a/pallets/labs/traits/Cargo.toml b/pallets/labs/traits/Cargo.toml new file mode 100644 index 00000000..306d34fd --- /dev/null +++ b/pallets/labs/traits/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "traits-labs" +version = "0.1.0" +authors = ["agustinustheoo "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +# alias "parity-scale-code" to "codec" +[dependencies.codec] +default-features = false +features = ['derive'] +package = 'parity-scale-codec' +version = '2.0.0' + +[dependencies] +scale-info = { version = "1.0", default-features = false, features = ["derive"] } +frame-system = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } +frame-support = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } +primitives-verification-status = { path = '../../../primitives/verification-status', default-features = false } + +[features] +default = ['std'] +std = [ + 'scale-info/std', + 'frame-system/std', + 'frame-support/std', +] diff --git a/pallets/labs/traits/src/lib.rs b/pallets/labs/traits/src/lib.rs new file mode 100644 index 00000000..b7856667 --- /dev/null +++ b/pallets/labs/traits/src/lib.rs @@ -0,0 +1,8 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +use frame_system::Config; +use primitives_verification_status::VerificationStatus; + +pub trait LabsProvider { + fn lab_verification_status(account_id: &T::AccountId) -> Option; +} diff --git a/pallets/orders/benchmarking/src/mock.rs b/pallets/orders/benchmarking/src/mock.rs index 14785729..416991f3 100644 --- a/pallets/orders/benchmarking/src/mock.rs +++ b/pallets/orders/benchmarking/src/mock.rs @@ -2,7 +2,7 @@ use super::*; -use frame_support::parameter_types; +use frame_support::{parameter_types, PalletId}; use sp_io::TestExternalities; use sp_runtime::{ testing::Header, @@ -35,6 +35,7 @@ frame_support::construct_runtime!( parameter_types! { pub const BlockHashCount: u64 = 250; pub const SS58Prefix: u8 = 42; + pub const LabPalletId: PalletId = PalletId(*b"dbio/lab"); } impl frame_system::Config for Test { @@ -84,10 +85,13 @@ impl pallet_balances::Config for Test { impl labs::Config for Test { type Event = Event; type Currency = Balances; - type Services = (); + type Services = Services; + type Orders = Orders; type Certifications = Certifications; - type EthereumAddress = (); - type UserProfile = (); + type EthereumAddress = EthereumAddress; + type UserProfile = UserProfile; + type LabWeightInfo = (); + type PalletId = LabPalletId; } impl services::Config for Test { diff --git a/pallets/orders/src/interface.rs b/pallets/orders/src/interface.rs index fa81d5ed..10e09777 100644 --- a/pallets/orders/src/interface.rs +++ b/pallets/orders/src/interface.rs @@ -33,4 +33,5 @@ pub trait OrderInterface { account_id: &T::AccountId, escrow_key: &T::AccountId, ) -> Result<(), Self::Error>; + fn is_pending_order_ids_by_seller_exist(account_id: &T::AccountId) -> bool; } diff --git a/pallets/orders/src/lib.rs b/pallets/orders/src/lib.rs index 5a1375be..7d0db7d1 100644 --- a/pallets/orders/src/lib.rs +++ b/pallets/orders/src/lib.rs @@ -128,7 +128,7 @@ pub mod pallet { // -------------------------------------------------------- // ---- Types -------------------------------------------- - type AccountIdOf = ::AccountId; + pub type AccountIdOf = ::AccountId; pub type MomentOf = ::Moment; pub type HashOf = ::Hash; pub type CurrencyOf = ::Currency; @@ -150,6 +150,11 @@ pub mod pallet { #[pallet::getter(fn orders_by_lab_id)] pub type OrdersBySeller = StorageMap<_, Blake2_128Concat, AccountIdOf, OrderIdsOf>; + #[pallet::storage] + #[pallet::getter(fn pending_genetic_analysis_orders_by_genetic_analyst_id)] + pub type PendingOrdersBySeller = + StorageMap<_, Blake2_128Concat, AccountIdOf, OrderIdsOf>; + #[pallet::storage] #[pallet::getter(fn last_order_by_customer_id)] pub type LastOrderByCustomer = StorageMap<_, Blake2_128Concat, AccountIdOf, HashOf>; @@ -219,6 +224,8 @@ pub mod pallet { UnauthorizedOrderFulfillment, /// Unauthorized to cancel order - user is not the customer who created the order UnauthorizedOrderCancellation, + // Genetic Testing is ongoing, cannot be cancelled + OngoingOrderCannotBeCancelled, /// Can not fulfill order before Specimen is processed DnaSampleNotSuccessfullyProcessed, /// Refund not allowed, Order is not expired yet @@ -429,8 +436,14 @@ impl OrderInterface for Pallet { return Err(Error::::UnauthorizedOrderCancellation) } + let dna_sample = + T::GeneticTesting::dna_sample_by_tracking_id(&order.dna_sample_tracking_id).unwrap(); + if !dna_sample.is_registered() { + return Err(Error::::OngoingOrderCannotBeCancelled) + } + // Delete dna sample associated with the order - let _dna_sample = T::GeneticTesting::delete_dna_sample(&order.dna_sample_tracking_id); + let _ = T::GeneticTesting::delete_dna_sample(&order.dna_sample_tracking_id); let order = Self::update_order_status(order_id, OrderStatus::Cancelled).unwrap(); @@ -513,6 +526,13 @@ impl OrderInterface for Pallet { Ok(()) } + + fn is_pending_order_ids_by_seller_exist(account_id: &T::AccountId) -> bool { + match PendingOrdersBySeller::::get(account_id) { + Some(_arr) => !_arr.is_empty(), + None => false, + } + } } use frame_support::{sp_runtime::traits::Hash, sp_std::convert::TryInto}; @@ -546,6 +566,7 @@ impl Pallet { Orders::::insert(&order.id, order); LastOrderByCustomer::::insert(&order.customer_id, &order.id); Self::insert_order_id_into_orders_by_seller(order); + Self::insert_order_id_into_pending_orders_by_seller(order); Self::insert_order_id_into_orders_by_customer(order); } @@ -573,6 +594,27 @@ impl Pallet { } } + pub fn insert_order_id_into_pending_orders_by_seller(order: &OrderOf) { + match PendingOrdersBySeller::::get(&order.seller_id) { + None => { + PendingOrdersBySeller::::insert(&order.seller_id, vec![order.id]); + }, + Some(mut orders) => { + orders.push(order.id); + PendingOrdersBySeller::::insert(&order.seller_id, orders); + }, + } + } + + pub fn remove_order_id_from_pending_orders_by_seller( + seller_id: &T::AccountId, + order_id: &T::Hash, + ) { + let mut orders = PendingOrdersBySeller::::get(seller_id).unwrap_or_default(); + orders.retain(|o_id| o_id != order_id); + PendingOrdersBySeller::::insert(seller_id, orders); + } + pub fn remove_order_id_from_orders_by_seller(seller_id: &T::AccountId, order_id: &T::Hash) { let mut orders = OrdersBySeller::::get(seller_id).unwrap_or_default(); orders.retain(|o_id| o_id != order_id); @@ -613,4 +655,15 @@ impl OrderStatusUpdater for Pallet { }, } } + + fn remove_order_id_from_pending_orders_by_seller( + seller_id: &AccountIdOf, + order_id: &HashOf, + ) { + Self::remove_order_id_from_pending_orders_by_seller(seller_id, order_id); + } + + fn is_pending_order_by_seller_exist(seller_id: &AccountIdOf) -> bool { + Self::is_pending_order_ids_by_seller_exist(seller_id) + } } diff --git a/pallets/orders/src/mock.rs b/pallets/orders/src/mock.rs index 7f7e0832..d489f36f 100644 --- a/pallets/orders/src/mock.rs +++ b/pallets/orders/src/mock.rs @@ -1,5 +1,5 @@ use crate as orders; -use frame_support::parameter_types; +use frame_support::{parameter_types, PalletId}; use frame_system as system; use pallet_balances::AccountData; use scale_info::TypeInfo; @@ -102,6 +102,7 @@ type Balance = u64; parameter_types! { pub static ExistentialDeposit: Balance = 0; + pub const LabPalletId: PalletId = PalletId(*b"dbio/lab"); } impl pallet_balances::Config for Test { @@ -122,10 +123,12 @@ impl labs::Config for Test { type Event = Event; type Currency = Balances; type Services = Services; + type Orders = Orders; type Certifications = Certifications; type EthereumAddress = EthereumAddress; type UserProfile = UserProfile; - type WeightInfo = (); + type LabWeightInfo = (); + type PalletId = LabPalletId; } impl services::Config for Test { diff --git a/pallets/orders/src/tests.rs b/pallets/orders/src/tests.rs index 0d6eaf70..1dc90a5b 100644 --- a/pallets/orders/src/tests.rs +++ b/pallets/orders/src/tests.rs @@ -519,6 +519,74 @@ fn cant_create_order_when_price_index_not_found() { }) } +#[test] +fn cant_cancel_order_when_order_ongoing() { + ::default().existential_deposit(1).build().execute_with(|| { + assert_ok!(Balances::set_balance(RawOrigin::Root.into(), 1, 100, 0)); + assert_ok!(Labs::register_lab( + Origin::signed(1), + LabInfo { + box_public_key: Keccak256::hash( + "0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC5761C3".as_bytes() + ), + name: "DeBio Lab".as_bytes().to_vec(), + email: "DeBio Email".as_bytes().to_vec(), + country: CountryCode::from_vec("DC".as_bytes().to_vec()), + region: RegionCode::from_vec("DB".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(), + latitude: Some("DeBio Latitude".as_bytes().to_vec()), + longitude: Some("DeBio Longtitude".as_bytes().to_vec()), + profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), + } + )); + + assert_ok!(UserProfile::set_eth_address(Origin::signed(1), EthereumAddress([b'X'; 20]))); + + assert_ok!(Services::create_service( + Origin::signed(1), + ServiceInfo { + name: "DeBio name".as_bytes().to_vec(), + prices_by_currency: vec![PriceByCurrency::default()], + expected_duration: ExpectedDuration::default(), + category: "DeBio category".as_bytes().to_vec(), + description: "This is my description".as_bytes().to_vec(), + test_result_sample: "Test result sample".as_bytes().to_vec(), + dna_collection_process: "Dna Collection Process".as_bytes().to_vec(), + long_description: Some("This is my long description".as_bytes().to_vec()), + image: Some("This is my image".as_bytes().to_vec()), + }, + ServiceFlow::default() + )); + + let _lab = Labs::lab_by_account_id(1).unwrap(); + + assert_ok!(Orders::create_order( + Origin::signed(2), + _lab.services[0], + 0, + Keccak256::hash("0xhJ7TRe456FADD2726A132ABJK5RCc9E6fC5869F4".as_bytes()), + ServiceFlow::StakingRequestService + )); + + let _order_id = Orders::last_order_by_customer_id(2).unwrap(); + let _dna_sample = GeneticTesting::dna_samples_by_lab_id(1).unwrap(); + + assert_ok!(GeneticTesting::process_dna_sample( + Origin::signed(1), + _dna_sample[0].clone(), + DnaSampleStatus::Arrived, + )); + + assert_noop!( + Orders::cancel_order(Origin::signed(2), _order_id), + Error::::OngoingOrderCannotBeCancelled + ); + }) +} + #[test] fn cant_cancel_order_when_not_exist() { ::default().existential_deposit(1).build().execute_with(|| { diff --git a/pallets/orders/src/weights.rs b/pallets/orders/src/weights.rs index 3c763860..e46f3436 100644 --- a/pallets/orders/src/weights.rs +++ b/pallets/orders/src/weights.rs @@ -1,11 +1,11 @@ //! Autogenerated weights for orders //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-28, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-04-04, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: -// target/release/debio +// ./target/release/debio // benchmark // --chain=dev // --execution=wasm @@ -48,19 +48,20 @@ impl WeightInfo for SubstrateWeight { // Storage: GeneticTesting DnaSamplesByOwner (r:1 w:1) // Storage: GeneticTesting DnaSamplesByLab (r:1 w:1) // Storage: Orders OrdersBySeller (r:1 w:1) + // Storage: Orders PendingOrdersBySeller (r:1 w:1) // Storage: Orders OrdersByCustomer (r:1 w:1) // Storage: Orders Orders (r:0 w:1) // Storage: Orders LastOrderByCustomer (r:0 w:1) fn create_order() -> Weight { - 104_556_000_u64 - .saturating_add(T::DbWeight::get().reads(9_u64)) - .saturating_add(T::DbWeight::get().writes(7_u64)) + 84_332_000_u64 + .saturating_add(T::DbWeight::get().reads(10_u64)) + .saturating_add(T::DbWeight::get().writes(8_u64)) } // Storage: Orders Orders (r:1 w:1) // Storage: GeneticTesting DnaSamples (r:1 w:1) // Storage: Timestamp Now (r:1 w:0) fn cancel_order() -> Weight { - 47_314_000_u64 + 40_569_000_u64 .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -68,7 +69,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Orders Orders (r:1 w:1) // Storage: Timestamp Now (r:1 w:0) fn set_order_paid() -> Weight { - 39_798_000_u64 + 30_229_000_u64 .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -76,7 +77,7 @@ impl WeightInfo for SubstrateWeight { // Storage: GeneticTesting DnaSamples (r:1 w:0) // Storage: Timestamp Now (r:1 w:0) fn fulfill_order() -> Weight { - 46_152_000_u64 + 36_667_000_u64 .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -85,13 +86,13 @@ impl WeightInfo for SubstrateWeight { // Storage: GeneticTesting DnaSamples (r:1 w:0) // Storage: Timestamp Now (r:1 w:0) fn set_order_refunded() -> Weight { - 50_962_000_u64 + 41_594_000_u64 .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: Orders EscrowKey (r:1 w:1) fn update_escrow_key() -> Weight { - 21_883_000_u64 + 18_408_000_u64 .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -107,19 +108,20 @@ impl WeightInfo for () { // Storage: GeneticTesting DnaSamplesByOwner (r:1 w:1) // Storage: GeneticTesting DnaSamplesByLab (r:1 w:1) // Storage: Orders OrdersBySeller (r:1 w:1) + // Storage: Orders PendingOrdersBySeller (r:1 w:1) // Storage: Orders OrdersByCustomer (r:1 w:1) // Storage: Orders Orders (r:0 w:1) // Storage: Orders LastOrderByCustomer (r:0 w:1) fn create_order() -> Weight { - 104_556_000_u64 - .saturating_add(RocksDbWeight::get().reads(9_u64)) - .saturating_add(RocksDbWeight::get().writes(7_u64)) + 84_332_000_u64 + .saturating_add(RocksDbWeight::get().reads(10_u64)) + .saturating_add(RocksDbWeight::get().writes(8_u64)) } // Storage: Orders Orders (r:1 w:1) // Storage: GeneticTesting DnaSamples (r:1 w:1) // Storage: Timestamp Now (r:1 w:0) fn cancel_order() -> Weight { - 47_314_000_u64 + 40_569_000_u64 .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -127,7 +129,7 @@ impl WeightInfo for () { // Storage: Orders Orders (r:1 w:1) // Storage: Timestamp Now (r:1 w:0) fn set_order_paid() -> Weight { - 39_798_000_u64 + 30_229_000_u64 .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -135,7 +137,7 @@ impl WeightInfo for () { // Storage: GeneticTesting DnaSamples (r:1 w:0) // Storage: Timestamp Now (r:1 w:0) fn fulfill_order() -> Weight { - 46_152_000_u64 + 36_667_000_u64 .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -144,13 +146,13 @@ impl WeightInfo for () { // Storage: GeneticTesting DnaSamples (r:1 w:0) // Storage: Timestamp Now (r:1 w:0) fn set_order_refunded() -> Weight { - 50_962_000_u64 + 41_594_000_u64 .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: Orders EscrowKey (r:1 w:1) fn update_escrow_key() -> Weight { - 21_883_000_u64 + 18_408_000_u64 .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } diff --git a/pallets/rewards/src/weights.rs b/pallets/rewards/src/weights.rs index 2bf0aca5..81ce3f38 100644 --- a/pallets/rewards/src/weights.rs +++ b/pallets/rewards/src/weights.rs @@ -1,11 +1,11 @@ //! Autogenerated weights for rewards //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-28, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-04-04, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: -// target/release/debio +// ./target/release/debio // benchmark // --chain=dev // --execution=wasm @@ -41,13 +41,13 @@ impl WeightInfo for SubstrateWeight { // Storage: System Account (r:1 w:0) // Storage: Rewards TotalRewardAmount (r:0 w:1) fn reward_funds() -> Weight { - 32_989_000_u64 + 28_381_000_u64 .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: Rewards RewarderKey (r:1 w:1) fn update_admin_key() -> Weight { - 21_898_000_u64 + 31_636_000_u64 .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -60,13 +60,13 @@ impl WeightInfo for () { // Storage: System Account (r:1 w:0) // Storage: Rewards TotalRewardAmount (r:0 w:1) fn reward_funds() -> Weight { - 32_989_000_u64 + 28_381_000_u64 .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: Rewards RewarderKey (r:1 w:1) fn update_admin_key() -> Weight { - 21_898_000_u64 + 31_636_000_u64 .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } diff --git a/pallets/service-request/Cargo.toml b/pallets/service-request/Cargo.toml index 016896d5..6bd8adc3 100644 --- a/pallets/service-request/Cargo.toml +++ b/pallets/service-request/Cargo.toml @@ -30,15 +30,26 @@ frame-benchmarking = { git = 'https://github.com/paritytech/substrate.git', bran ## Substrate Pallet Dependencies pallet-balances = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false } -pallet-timestamp = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false } +pallet-randomness-collective-flip = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false } +pallet-timestamp = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } # Local Dependencies labs = { path = '../labs', default-features = false } +orders = { path = '../orders', default-features = false } services = { path = '../services', default-features = false } -certifications = { path = '../certifications', default-features = false } user-profile = { path = '../user-profile', default-features = false } +certifications = { path = '../certifications', default-features = false } +genetic-testing = { path = '../genetic-testing', default-features = false } + +traits-labs = { path = '../labs/traits', default-features = false } + +primitives-verification-status = { path = '../../primitives/verification-status', default-features = false } primitives-area-code = { path = '../../primitives/area-code', default-features = false } +[dev-dependencies] +sp-core = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } +sp-runtime = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } + [features] default = ['std'] std = [ @@ -52,16 +63,19 @@ std = [ 'frame-support/std', 'frame-system/std', - 'frame-benchmarking/std', + 'primitives-area-code/std', + 'pallet-timestamp/std', + 'pallet-randomness-collective-flip/std', 'pallet-balances/std', - 'pallet-timestamp/std', 'labs/std', - 'services/std', + 'orders/std', + 'services/std', 'certifications/std', - 'user-profile/std' + 'user-profile/std', + 'genetic-testing/std', ] runtime-benchmarks = ['frame-benchmarking'] try-runtime = ['frame-support/try-runtime'] diff --git a/pallets/service-request/benchmarking/Cargo.toml b/pallets/service-request/benchmarking/Cargo.toml new file mode 100644 index 00000000..e823ee55 --- /dev/null +++ b/pallets/service-request/benchmarking/Cargo.toml @@ -0,0 +1,83 @@ +[package] +name = 'service-request-benchmarking' +version = '0.1.0' +repository = '' +edition = '2018' +authors = ['agustinustheoo '] +description = '' +homepage = '' +license = 'AGPL-3.0' + +[package.metadata.docs.rs] +targets = ['x86_64-unknown-linux-gnu'] + +[dependencies] +# External Dependencies +hex-literal = '0.3.3' +codec = { package = 'parity-scale-codec', version = '2.0.0', default-features = false, features = ['derive'] } +scale-info = { version = '1.0', default-features = false, features = ['derive'] } + +# Substrate packages +## Substrate Primitive Dependencies +sp-std = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } +sp-core = { 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 } +sp-runtime = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } + +## Substrate Frame Dependencies +frame-support = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } +frame-system = { 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 } + +## Substrate Pallet Dependencies +pallet-balances = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false } +pallet-randomness-collective-flip = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false } +pallet-timestamp = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } + +# Local Dependencies +labs = { path = '../../labs', default-features = false } +orders = { path = '../../orders', default-features = false } +services = { path = '../../services', default-features = false } +user-profile = { path = '../../user-profile', default-features = false } +certifications = { path = '../../certifications', default-features = false } +genetic-testing = { path = '../../genetic-testing', default-features = false } +service-request = { path = '../../service-request', default-features = false } + +traits-labs = { path = '../../labs/traits', default-features = false } + +primitives-verification-status = { path = '../../../primitives/verification-status', default-features = false } +primitives-area-code = { path = '../../../primitives/area-code', default-features = false } + +[dev-dependencies] +sp-core = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } +sp-runtime = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } + +[features] +default = ['std'] +std = [ + 'codec/std', + 'scale-info/std', + + 'sp-std/std', + 'sp-core/std', + 'sp-io/std', + 'sp-runtime/std', + + 'frame-support/std', + 'frame-system/std', + 'frame-benchmarking/std', + + 'primitives-area-code/std', + + 'pallet-timestamp/std', + 'pallet-randomness-collective-flip/std', + 'pallet-balances/std', + + 'labs/std', + 'orders/std', + 'services/std', + 'certifications/std', + 'user-profile/std', + 'genetic-testing/std', + 'service-request/std', +] \ No newline at end of file diff --git a/pallets/service-request/src/benchmarking.rs b/pallets/service-request/benchmarking/src/lib.rs similarity index 79% rename from pallets/service-request/src/benchmarking.rs rename to pallets/service-request/benchmarking/src/lib.rs index e6ce8464..5f83ca5a 100644 --- a/pallets/service-request/src/benchmarking.rs +++ b/pallets/service-request/benchmarking/src/lib.rs @@ -1,22 +1,31 @@ -use super::*; +#![cfg_attr(not(feature = "std"), no_std)] +mod mock; -#[allow(unused)] -use crate::{ - AdminKey, Config as ServiceRequestConfig, Pallet as ServiceRequest, RequestByAccountId, -}; use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller}; -use frame_support::sp_runtime::{traits::Hash, SaturatedConversion}; +use frame_support::{ + sp_runtime::{traits::Hash, SaturatedConversion}, + traits::Currency, +}; use frame_system::RawOrigin; -use labs::{LabInfo, LabVerificationStatus, LabVerifierKey, Pallet as PalletLab}; +use labs::{Config as LabsConfig, LabInfo, LabVerifierKey, Pallet as Labs}; +#[allow(unused)] +use service_request::{ + AdminKey, Call, Config as ServiceRequestConfig, Pallet as ServiceRequest, RequestByAccountId, +}; use primitives_area_code::{CityCode, CountryCode, RegionCode}; +use primitives_verification_status::VerificationStatus; + +pub trait Config: ServiceRequestConfig + LabsConfig {} + +pub struct Pallet(ServiceRequest); const SEED: u32 = 0; benchmarks! { create_request { let caller: T::AccountId = whitelisted_caller(); - let _ = ::Currency::deposit_creating(&caller, 1000000000000000000000u128.saturated_into()); + let _ = ::Currency::deposit_creating(&caller, 1000000000000000000000u128.saturated_into()); let country = "Indonesia".as_bytes().to_vec(); let region = "West Java".as_bytes().to_vec(); @@ -36,7 +45,7 @@ benchmarks! { let caller: T::AccountId = whitelisted_caller(); let caller_origin = ::Origin::from(RawOrigin::Signed(caller.clone())); - let _ = ::Currency::deposit_creating(&caller, 1000000000000000000000u128.saturated_into()); + let _ = ::Currency::deposit_creating(&caller, 1000000000000000000000u128.saturated_into()); let _new_request = ServiceRequest::::create_request( caller_origin, @@ -62,7 +71,7 @@ benchmarks! { let customer: T::AccountId = account("customer", 0, SEED); let customer_origin = ::Origin::from(RawOrigin::Signed(customer.clone())); - let _ = ::Currency::deposit_creating(&customer, 1000000000000000000000u128.saturated_into()); + let _ = ::Currency::deposit_creating(&customer, 1000000000000000000000u128.saturated_into()); let _new_request = ServiceRequest::::create_request( customer_origin.clone(), @@ -73,13 +82,13 @@ benchmarks! { 10000000000000000000u128.saturated_into() ); - let request_ids = RequestByAccountId::::get(customer.clone()); + let request_ids = RequestByAccountId::::get(customer); let request_id = request_ids[0]; - let _request_unstake = ServiceRequest::::unstake(customer_origin.clone(), request_id.clone()); + let _request_unstake = ServiceRequest::::unstake(customer_origin, request_id); }: retrieve_unstaked_amount ( RawOrigin::Signed(caller), - request_id.clone() + request_id ) claim_request { @@ -103,17 +112,17 @@ benchmarks! { }; // register lab - let _add_labs = PalletLab::::register_lab(caller_origin.clone(), lab); + let _add_labs = Labs::::register_lab(caller_origin, lab); // verified lab let admin_key: T::AccountId = LabVerifierKey::::get(); - let admin_key_origin = ::Origin::from(RawOrigin::Signed(admin_key.clone())); - let _verified_labs = PalletLab::::update_lab_verification_status(admin_key_origin, caller.clone(), LabVerificationStatus::Verified); + let admin_key_origin = ::Origin::from(RawOrigin::Signed(admin_key)); + let _verified_labs = Labs::::update_lab_verification_status(admin_key_origin, caller.clone(), VerificationStatus::Verified); // Create request let customer: T::AccountId = account("recepient", 0, SEED); let customer_origin = ::Origin::from(RawOrigin::Signed(customer.clone())); - let _ = ::Currency::deposit_creating(&customer, 1000000000000000000000u128.saturated_into()); + let _ = ::Currency::deposit_creating(&customer, 1000000000000000000000u128.saturated_into()); let _new_request = ServiceRequest::::create_request( customer_origin, @@ -124,7 +133,7 @@ benchmarks! { 10000000000000000000u128.saturated_into() ); - let request_ids = RequestByAccountId::::get(customer.clone()); + let request_ids = RequestByAccountId::::get(customer); let request_id = request_ids[0]; let service_id = T::Hashing::hash("0xDb9Af2d1f3ADD2726A132AA7A65Cc9E6fC576143".as_bytes()); @@ -142,7 +151,7 @@ benchmarks! { let caller: T::AccountId = whitelisted_caller(); let caller_origin = ::Origin::from(RawOrigin::Signed(caller.clone())); - let _ = ::Currency::deposit_creating(&caller, 1000000000000000000000u128.saturated_into()); + let _ = ::Currency::deposit_creating(&caller, 1000000000000000000000u128.saturated_into()); let _new_request = ServiceRequest::::create_request( caller_origin, @@ -177,17 +186,17 @@ benchmarks! { longitude: Some("DeBio Longtitude".as_bytes().to_vec()), profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), }; - let _add_lab = PalletLab::::register_lab(lab_origin.clone(), lab); + let _add_lab = Labs::::register_lab(lab_origin.clone(), lab); // verified lab let admin_key: T::AccountId = LabVerifierKey::::get(); - let admin_key_origin = ::Origin::from(RawOrigin::Signed(admin_key.clone())); - let _verified_labs = PalletLab::::update_lab_verification_status(admin_key_origin, lab_id.clone(), LabVerificationStatus::Verified); + let admin_key_origin = ::Origin::from(RawOrigin::Signed(admin_key)); + let _verified_labs = Labs::::update_lab_verification_status(admin_key_origin, lab_id.clone(), VerificationStatus::Verified); let _claim_request = ServiceRequest::::claim_request( - lab_origin.clone(), - request_id.clone(), - service_id.clone(), + lab_origin, + request_id, + service_id, testing_price, qc_price ); @@ -229,14 +238,14 @@ benchmarks! { longitude: Some("DeBio Longtitude".as_bytes().to_vec()), profile_image: Some("DeBio Profile Image uwu".as_bytes().to_vec()), }; - let _add_lab = PalletLab::::register_lab(lab_id_origin.clone(), lab); + let _add_lab = Labs::::register_lab(lab_id_origin.clone(), lab); // verified lab let admin_key: T::AccountId = LabVerifierKey::::get(); - let admin_key_origin = ::Origin::from(RawOrigin::Signed(admin_key.clone())); - let _verified_labs = PalletLab::::update_lab_verification_status(admin_key_origin, lab_id.clone(), LabVerificationStatus::Verified); + let admin_key_origin = ::Origin::from(RawOrigin::Signed(admin_key)); + let _verified_labs = Labs::::update_lab_verification_status(admin_key_origin, lab_id.clone(), VerificationStatus::Verified); - let _ = ::Currency::deposit_creating(&customer_id, 1000000000000000000000u128.saturated_into()); + let _ = ::Currency::deposit_creating(&customer_id, 1000000000000000000000u128.saturated_into()); // Create request let _new_request = ServiceRequest::::create_request( @@ -248,7 +257,7 @@ benchmarks! { 10000000000000000000u128.saturated_into() ); - let request_ids = RequestByAccountId::::get(customer_id.clone()); + let request_ids = RequestByAccountId::::get(customer_id); let request_id = request_ids[0]; // claim request @@ -256,9 +265,9 @@ benchmarks! { let testing_price = 1000000000000000000u128.saturated_into(); let qc_price = 1000000000000000000u128.saturated_into(); let _claim_request = ServiceRequest::::claim_request( - lab_id_origin.clone(), - request_id.clone(), - service_id.clone(), + lab_id_origin, + request_id, + service_id, testing_price, qc_price ); @@ -270,7 +279,7 @@ benchmarks! { let _process_request = ServiceRequest::::process_request( customer_id_origin, lab_id, - request_id.clone(), + request_id, order_id, dna_sample_tracking_id, additional_staking_amount diff --git a/pallets/service-request/benchmarking/src/mock.rs b/pallets/service-request/benchmarking/src/mock.rs new file mode 100644 index 00000000..3937bcbc --- /dev/null +++ b/pallets/service-request/benchmarking/src/mock.rs @@ -0,0 +1,198 @@ +#![cfg(test)] + +use super::*; + +use frame_support::{parameter_types, PalletId}; +use frame_system as system; +use pallet_balances::AccountData; +use scale_info::TypeInfo; +use sp_core::{Decode, Encode, RuntimeDebug, H256}; +use sp_io::TestExternalities; +use sp_runtime::{ + testing::Header, + traits::{BlakeTwo256, IdentityLookup}, +}; + +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; + +pub type AccountId = u64; + +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Pallet, Call, Config, Storage, Event}, + Orders: orders::{Pallet, Call, Storage, Event}, + Labs: labs::{Pallet, Call, Storage, Event}, + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, + ServiceRequest: service_request::{Pallet, Call, Storage, Event}, + Services: services::{Pallet, Call, Storage, Event}, + Certifications: certifications::{Pallet, Call, Storage, Event}, + UserProfile: user_profile::{Pallet, Call, Storage, Event}, + GeneticTesting: genetic_testing::{Pallet, Call, Storage, Event}, + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, + RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage}, + } +); + +parameter_types! { + pub const BlockHashCount: u64 = 250; + pub const SS58Prefix: u8 = 42; + pub BlockWeights: frame_system::limits::BlockWeights = + frame_system::limits::BlockWeights::simple_max(1024); +} + +impl pallet_randomness_collective_flip::Config for Test {} + +impl frame_system::Config for Test { + type BaseCallFilter = frame_support::traits::Everything; + type BlockWeights = (); + type BlockLength = (); + type AccountId = AccountId; + type Call = Call; + type Lookup = IdentityLookup; + type Index = u64; + type BlockNumber = u64; + type Hash = H256; + type Hashing = BlakeTwo256; + type Header = Header; + type Event = Event; + type Origin = Origin; + type BlockHashCount = BlockHashCount; + type DbWeight = (); + type Version = (); + type PalletInfo = PalletInfo; + type OnNewAccount = (); + type OnKilledAccount = (); + type AccountData = AccountData; + type SystemWeightInfo = (); + type SS58Prefix = SS58Prefix; + type OnSetCode = (); +} + +pub type Moment = u64; +pub const MILLISECS_PER_BLOCK: Moment = 6000; +pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; + +parameter_types! { + pub const MinimumPeriod: Moment = SLOT_DURATION / 2; +} + +impl pallet_timestamp::Config for Test { + /// A timestamp: milliseconds since the unix epoch. + type Moment = Moment; + type OnTimestampSet = (); + type MinimumPeriod = MinimumPeriod; + type WeightInfo = (); +} + +type Balance = u64; + +parameter_types! { + pub static ExistentialDeposit: Balance = 0; + pub const LabPalletId: PalletId = PalletId(*b"dbio/lab"); +} + +impl pallet_balances::Config for Test { + type MaxLocks = (); + type MaxReserves = (); + type ReserveIdentifier = [u8; 8]; + /// The type for recording an account's balance. + type Balance = Balance; + /// The ubiquitous event type. + type Event = Event; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); +} + +impl service_request::Config for Test { + type Event = Event; + type TimeProvider = Timestamp; + type Currency = Balances; + type Labs = Labs; + type ServiceRequestWeightInfo = (); +} + +impl labs::Config for Test { + type Event = Event; + type Currency = Balances; + type Certifications = Certifications; + type EthereumAddress = EthereumAddress; + type Services = Services; + type Orders = Orders; + type UserProfile = UserProfile; + type PalletId = LabPalletId; + type LabWeightInfo = (); +} + +impl services::Config for Test { + type Event = Event; + type Currency = Balances; + type ServiceOwner = Labs; + type WeightInfo = (); +} + +impl orders::Config for Test { + type Event = Event; + type Services = Services; + type GeneticTesting = GeneticTesting; + type Currency = Balances; + type OrdersWeightInfo = (); +} + +impl genetic_testing::Config for Test { + type Event = Event; + type Orders = Orders; + type RandomnessSource = RandomnessCollectiveFlip; + type GeneticTestingWeightInfo = (); +} + +impl certifications::Config for Test { + type Event = Event; + type CertificationOwner = Labs; + type WeightInfo = (); +} + +#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, Default, RuntimeDebug, TypeInfo)] +pub struct EthereumAddress(pub [u8; 20]); + +impl user_profile::Config for Test { + type Event = Event; + type EthereumAddress = EthereumAddress; + type WeightInfo = (); +} + +pub struct ExternalityBuilder { + existential_deposit: u64, +} + +impl Default for ExternalityBuilder { + fn default() -> Self { + Self { existential_deposit: 1 } + } +} + +impl ExternalityBuilder { + pub fn existential_deposit(mut self, existential_deposit: u64) -> Self { + self.existential_deposit = existential_deposit; + self + } + pub fn set_associated_consts(&self) { + EXISTENTIAL_DEPOSIT.with(|v| *v.borrow_mut() = self.existential_deposit); + } + pub fn build(&self) -> TestExternalities { + self.set_associated_consts(); + let mut storage = system::GenesisConfig::default().build_storage::().unwrap(); + pallet_balances::GenesisConfig:: { balances: { vec![] } } + .assimilate_storage(&mut storage) + .unwrap(); + let mut ext = sp_io::TestExternalities::new(storage); + ext.execute_with(|| System::set_block_number(1)); + ext + } +} diff --git a/pallets/service-request/src/lib.rs b/pallets/service-request/src/lib.rs index a718beae..5d5c4643 100644 --- a/pallets/service-request/src/lib.rs +++ b/pallets/service-request/src/lib.rs @@ -14,8 +14,9 @@ use frame_support::{ PalletId, }; use frame_system::pallet_prelude::*; -use labs::interface::{LabInterface, LabVerificationStatusTrait}; pub use pallet::*; +use primitives_verification_status::VerificationStatusTrait; +use traits_labs::LabsProvider; #[cfg(test)] mod mock; @@ -23,9 +24,6 @@ mod mock; #[cfg(test)] mod tests; -#[cfg(feature = "runtime-benchmarks")] -mod benchmarking; - pub mod interface; pub use interface::SeviceRequestInterface; @@ -152,7 +150,7 @@ impl ServiceInvoice { #[frame_support::pallet] pub mod pallet { - use super::*; + use crate::*; pub const PALLET_ID: PalletId = PalletId(*b"reqsrvc!"); @@ -176,11 +174,11 @@ pub mod pallet { pub type DNASampleTrackingIdOf = Vec; #[pallet::config] - pub trait Config: frame_system::Config + labs::Config { + pub trait Config: frame_system::Config { type Event: From> + IsType<::Event>; type TimeProvider: UnixTime; type Currency: Currency<::AccountId>; - type Labs: LabInterface; + type Labs: LabsProvider; type ServiceRequestWeightInfo: WeightInfo; } diff --git a/pallets/service-request/src/mock.rs b/pallets/service-request/src/mock.rs index 4ecfb4ed..7438eeb7 100644 --- a/pallets/service-request/src/mock.rs +++ b/pallets/service-request/src/mock.rs @@ -1,5 +1,5 @@ use crate as service_request; -use frame_support::parameter_types; +use frame_support::{parameter_types, PalletId}; use frame_system as system; use pallet_balances::AccountData; use scale_info::TypeInfo; @@ -22,13 +22,16 @@ frame_support::construct_runtime!( UncheckedExtrinsic = UncheckedExtrinsic, { System: frame_system::{Pallet, Call, Config, Storage, Event}, + Orders: orders::{Pallet, Call, Storage, Event}, + Labs: labs::{Pallet, Call, Storage, Event}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, ServiceRequest: service_request::{Pallet, Call, Storage, Event}, - Labs: labs::{Pallet, Call, Storage, Event}, - Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, Services: services::{Pallet, Call, Storage, Event}, Certifications: certifications::{Pallet, Call, Storage, Event}, - UserProfile: user_profile::{Pallet, Call, Storage, Event} + UserProfile: user_profile::{Pallet, Call, Storage, Event}, + GeneticTesting: genetic_testing::{Pallet, Call, Storage, Event}, + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, + RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage}, } ); @@ -36,9 +39,11 @@ parameter_types! { pub const BlockHashCount: u64 = 250; pub const SS58Prefix: u8 = 42; pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max(1024); + frame_system::limits::BlockWeights::simple_max(1024); } +impl pallet_randomness_collective_flip::Config for Test {} + impl frame_system::Config for Test { type BaseCallFilter = frame_support::traits::Everything; type BlockWeights = (); @@ -65,10 +70,27 @@ impl frame_system::Config for Test { type OnSetCode = (); } +pub type Moment = u64; +pub const MILLISECS_PER_BLOCK: Moment = 6000; +pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; + +parameter_types! { + pub const MinimumPeriod: Moment = SLOT_DURATION / 2; +} + +impl pallet_timestamp::Config for Test { + /// A timestamp: milliseconds since the unix epoch. + type Moment = Moment; + type OnTimestampSet = (); + type MinimumPeriod = MinimumPeriod; + type WeightInfo = (); +} + type Balance = u64; parameter_types! { pub static ExistentialDeposit: Balance = 0; + pub const LabPalletId: PalletId = PalletId(*b"dbio/lab"); } impl pallet_balances::Config for Test { @@ -99,8 +121,10 @@ impl labs::Config for Test { type Certifications = Certifications; type EthereumAddress = EthereumAddress; type Services = Services; + type Orders = Orders; type UserProfile = UserProfile; - type WeightInfo = (); + type PalletId = LabPalletId; + type LabWeightInfo = (); } impl services::Config for Test { @@ -110,6 +134,21 @@ impl services::Config for Test { type WeightInfo = (); } +impl orders::Config for Test { + type Event = Event; + type Services = Services; + type GeneticTesting = GeneticTesting; + type Currency = Balances; + type OrdersWeightInfo = (); +} + +impl genetic_testing::Config for Test { + type Event = Event; + type Orders = Orders; + type RandomnessSource = RandomnessCollectiveFlip; + type GeneticTestingWeightInfo = (); +} + impl certifications::Config for Test { type Event = Event; type CertificationOwner = Labs; @@ -125,22 +164,6 @@ impl user_profile::Config for Test { type WeightInfo = (); } -pub type Moment = u64; -pub const MILLISECS_PER_BLOCK: Moment = 6000; -pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; - -parameter_types! { - pub const MinimumPeriod: Moment = SLOT_DURATION / 2; -} - -impl pallet_timestamp::Config for Test { - /// A timestamp: milliseconds since the unix epoch. - type Moment = Moment; - type OnTimestampSet = (); - type MinimumPeriod = MinimumPeriod; - type WeightInfo = (); -} - pub struct ExternalityBuilder { existential_deposit: u64, } diff --git a/pallets/service-request/src/tests.rs b/pallets/service-request/src/tests.rs index af0de085..42e0324c 100644 --- a/pallets/service-request/src/tests.rs +++ b/pallets/service-request/src/tests.rs @@ -4,8 +4,9 @@ use frame_support::{ sp_runtime::traits::{Hash, Keccak256}, }; use frame_system::RawOrigin; -use labs::{LabInfo, LabVerificationStatus, LabVerifierKey}; +use labs::{LabInfo, LabVerifierKey}; use primitives_area_code::{CityCode, CountryCode, RegionCode}; +use primitives_verification_status::VerificationStatus; #[test] fn create_request_works() { @@ -97,7 +98,7 @@ fn claim_request_works_when_lab_is_verified() { assert_ok!(Labs::update_lab_verification_status( Origin::signed(3), 2, - LabVerificationStatus::Verified + VerificationStatus::Verified )); assert_ok!(ServiceRequest::claim_request( @@ -248,7 +249,7 @@ fn process_request_works_when_stacking_amount_greater_than_total_payment() { assert_ok!(Labs::update_lab_verification_status( Origin::signed(3), 2, - LabVerificationStatus::Verified + VerificationStatus::Verified )); assert_ok!(ServiceRequest::claim_request( @@ -361,7 +362,7 @@ fn process_request_works_when_stacking_amount_less_than_total_payment() { assert_ok!(Labs::update_lab_verification_status( Origin::signed(3), 2, - LabVerificationStatus::Verified + VerificationStatus::Verified )); assert_ok!(ServiceRequest::claim_request( @@ -475,7 +476,7 @@ fn finalize_request_works_when_test_result_success() { assert_ok!(Labs::update_lab_verification_status( Origin::signed(3), 2, - LabVerificationStatus::Verified + VerificationStatus::Verified )); assert_ok!(ServiceRequest::claim_request( @@ -575,7 +576,7 @@ fn finalize_request_works_when_test_result_not_success() { assert_ok!(Labs::update_lab_verification_status( Origin::signed(3), 2, - LabVerificationStatus::Verified + VerificationStatus::Verified )); assert_ok!(ServiceRequest::claim_request( @@ -731,7 +732,7 @@ fn cant_claim_request_when_already_claimed() { assert_ok!(Labs::update_lab_verification_status( Origin::signed(3), 2, - LabVerificationStatus::Verified + VerificationStatus::Verified )); assert_ok!(ServiceRequest::claim_request( @@ -836,13 +837,13 @@ fn cant_claim_process_request_when_lab_not_exists() { assert_ok!(Labs::update_lab_verification_status( Origin::signed(2), 3, - LabVerificationStatus::Verified + VerificationStatus::Verified )); assert_ok!(Labs::update_lab_verification_status( Origin::signed(2), 4, - LabVerificationStatus::Verified + VerificationStatus::Verified )); assert_ok!(ServiceRequest::claim_request( @@ -965,7 +966,7 @@ fn cant_process_request_when_unathorized_customer() { assert_ok!(Labs::update_lab_verification_status( Origin::signed(3), 2, - LabVerificationStatus::Verified + VerificationStatus::Verified )); assert_ok!(ServiceRequest::claim_request( @@ -1086,7 +1087,7 @@ fn cant_process_request_when_request_is_on_processed_or_finalized() { assert_ok!(Labs::update_lab_verification_status( Origin::signed(3), 2, - LabVerificationStatus::Verified + VerificationStatus::Verified )); assert_ok!(ServiceRequest::claim_request( @@ -1208,7 +1209,7 @@ fn cant_finalize_requst_when_request_is_not_on_processed() { assert_ok!(Labs::update_lab_verification_status( Origin::signed(3), 2, - LabVerificationStatus::Verified + VerificationStatus::Verified )); assert_ok!(ServiceRequest::claim_request( @@ -1321,7 +1322,7 @@ fn call_event_should_work() { assert_ok!(Labs::update_lab_verification_status( Origin::signed(3), 2, - LabVerificationStatus::Verified + VerificationStatus::Verified )); assert_ok!(ServiceRequest::claim_request( diff --git a/pallets/service-request/src/weights.rs b/pallets/service-request/src/weights.rs index 67bb7a1d..8756bc13 100644 --- a/pallets/service-request/src/weights.rs +++ b/pallets/service-request/src/weights.rs @@ -1,11 +1,11 @@ //! Autogenerated weights for service_request //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-28, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-04-04, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: -// target/release/debio +// ./target/release/debio // benchmark // --chain=dev // --execution=wasm @@ -47,14 +47,14 @@ impl WeightInfo for SubstrateWeight { // Storage: ServiceRequest ServiceCountRequest (r:1 w:1) // Storage: ServiceRequest RequestById (r:0 w:1) fn create_request() -> Weight { - 122_257_000_u64 + 107_300_000_u64 .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } // Storage: ServiceRequest RequestById (r:1 w:1) // Storage: Timestamp Now (r:1 w:0) fn unstake() -> Weight { - 35_132_000_u64 + 30_317_000_u64 .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -63,7 +63,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Timestamp Now (r:1 w:0) // Storage: System Account (r:2 w:2) fn retrieve_unstaked_amount() -> Weight { - 92_391_000_u64 + 76_489_000_u64 .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -72,7 +72,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Timestamp Now (r:1 w:0) // Storage: ServiceRequest ServiceOfferById (r:0 w:1) fn claim_request() -> Weight { - 49_181_000_u64 + 43_201_000_u64 .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -83,7 +83,7 @@ impl WeightInfo for SubstrateWeight { // Storage: ServiceRequest ServiceInvoiceById (r:0 w:1) // Storage: ServiceRequest ServiceInvoiceByOrderId (r:0 w:1) fn process_request() -> Weight { - 99_875_000_u64 + 89_302_000_u64 .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -95,13 +95,13 @@ impl WeightInfo for SubstrateWeight { // Storage: ServiceRequest RequestByAccountId (r:1 w:1) // Storage: ServiceRequest ServiceCountRequest (r:1 w:1) fn finalize_request() -> Weight { - 134_832_000_u64 + 118_980_000_u64 .saturating_add(T::DbWeight::get().reads(8_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } // Storage: ServiceRequest AdminKey (r:1 w:1) fn update_admin_key() -> Weight { - 21_951_000_u64 + 19_232_000_u64 .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -115,14 +115,14 @@ impl WeightInfo for () { // Storage: ServiceRequest ServiceCountRequest (r:1 w:1) // Storage: ServiceRequest RequestById (r:0 w:1) fn create_request() -> Weight { - 122_257_000_u64 + 107_300_000_u64 .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } // Storage: ServiceRequest RequestById (r:1 w:1) // Storage: Timestamp Now (r:1 w:0) fn unstake() -> Weight { - 35_132_000_u64 + 30_317_000_u64 .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -131,7 +131,7 @@ impl WeightInfo for () { // Storage: Timestamp Now (r:1 w:0) // Storage: System Account (r:2 w:2) fn retrieve_unstaked_amount() -> Weight { - 92_391_000_u64 + 76_489_000_u64 .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -140,7 +140,7 @@ impl WeightInfo for () { // Storage: Timestamp Now (r:1 w:0) // Storage: ServiceRequest ServiceOfferById (r:0 w:1) fn claim_request() -> Weight { - 49_181_000_u64 + 43_201_000_u64 .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -151,7 +151,7 @@ impl WeightInfo for () { // Storage: ServiceRequest ServiceInvoiceById (r:0 w:1) // Storage: ServiceRequest ServiceInvoiceByOrderId (r:0 w:1) fn process_request() -> Weight { - 99_875_000_u64 + 89_302_000_u64 .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } @@ -163,13 +163,13 @@ impl WeightInfo for () { // Storage: ServiceRequest RequestByAccountId (r:1 w:1) // Storage: ServiceRequest ServiceCountRequest (r:1 w:1) fn finalize_request() -> Weight { - 134_832_000_u64 + 118_980_000_u64 .saturating_add(RocksDbWeight::get().reads(8_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } // Storage: ServiceRequest AdminKey (r:1 w:1) fn update_admin_key() -> Weight { - 21_951_000_u64 + 19_232_000_u64 .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } diff --git a/pallets/services/benchmarking/src/mock.rs b/pallets/services/benchmarking/src/mock.rs index 7276f0c5..13bddf14 100644 --- a/pallets/services/benchmarking/src/mock.rs +++ b/pallets/services/benchmarking/src/mock.rs @@ -2,18 +2,20 @@ use super::*; -use frame_support::parameter_types; -use sp_io::TestExternalities; +use frame_support::{parameter_types, PalletId}; +use frame_system as system; +use pallet_balances::AccountData; +use scale_info::TypeInfo; +use sp_core::{Decode, Encode, RuntimeDebug, H256}; use sp_runtime::{ - traits::{AccountIdLookup, IdentifyAccount, Verify}, - MultiSignature, + testing::Header, + traits::{BlakeTwo256, IdentityLookup}, }; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; -pub type Signature = MultiSignature; -pub type AccountId = <::Signer as IdentifyAccount>::AccountId; +pub type AccountId = u64; frame_support::construct_runtime!( pub enum Test where @@ -25,27 +27,34 @@ frame_support::construct_runtime!( Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, Labs: labs::{Pallet, Call, Storage, Event}, Services: services::{Pallet, Call, Storage, Event}, + Orders: orders::{Pallet, Call, Storage, Event}, + GeneticTesting: genetic_testing::{Pallet, Call, Storage, Event}, + Certifications: certifications::{Pallet, Call, Storage, Event}, UserProfile: user_profile::{Pallet, Call, Storage, Event}, + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, + RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage}, } ); +impl pallet_randomness_collective_flip::Config for Test {} + parameter_types! { pub const BlockHashCount: u64 = 250; pub const SS58Prefix: u8 = 42; } -impl frame_system::Config for Test { - type BaseCallFilter = (); +impl system::Config for Test { + type BaseCallFilter = frame_support::traits::Everything; type BlockWeights = (); type BlockLength = (); type AccountId = AccountId; type Call = Call; - type Lookup = AccountIdLookup; + type Lookup = IdentityLookup; type Index = u64; type BlockNumber = u64; - type Hash = sp_core::H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; - type Header = sp_runtime::testing::Header; + type Hash = H256; + type Hashing = BlakeTwo256; + type Header = Header; type Event = Event; type Origin = Origin; type BlockHashCount = BlockHashCount; @@ -54,27 +63,42 @@ impl frame_system::Config for Test { type PalletInfo = PalletInfo; type OnNewAccount = (); type OnKilledAccount = (); - type AccountData = (); + type AccountData = AccountData; type SystemWeightInfo = (); type SS58Prefix = SS58Prefix; type OnSetCode = (); } -/// Ethereum Address type -#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, Default, RuntimeDebug)] -pub struct EthereumAddress([u8; 20]); +pub type Moment = u64; +pub const MILLISECS_PER_BLOCK: Moment = 6000; +pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; + +parameter_types! { + pub const MinimumPeriod: Moment = SLOT_DURATION / 2; + pub const LabPalletId: PalletId = PalletId(*b"dbio/lab"); +} + +impl pallet_timestamp::Config for Test { + /// A timestamp: milliseconds since the unix epoch. + type Moment = Moment; + type OnTimestampSet = (); + type MinimumPeriod = MinimumPeriod; + type WeightInfo = (); +} type Balance = u64; parameter_types! { - pub const ExistentialDeposit: Balance = 10; + pub static ExistentialDeposit: Balance = 0; } impl pallet_balances::Config for Test { type MaxLocks = (); type MaxReserves = (); type ReserveIdentifier = [u8; 8]; + /// The type for recording an account's balance. type Balance = Balance; + /// The ubiquitous event type. type Event = Event; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; @@ -85,20 +109,50 @@ impl pallet_balances::Config for Test { impl labs::Config for Test { type Event = Event; type Currency = Balances; - type Services = (); + type Services = Services; + type Orders = Orders; + type PalletId = LabPalletId; type Certifications = Certifications; - type EthereumAddress = (); - type UserProfile = (); + type EthereumAddress = EthereumAddress; + type UserProfile = UserProfile; + type LabWeightInfo = (); } impl services::Config for Test { + type Event = Event; type Currency = Balances; type ServiceOwner = Labs; + type WeightInfo = (); } -impl user_profile::Config for Runtime { +impl certifications::Config for Test { + type Event = Event; + type CertificationOwner = Labs; + type WeightInfo = (); +} + +impl genetic_testing::Config for Test { + type Event = Event; + type Orders = Orders; + type RandomnessSource = RandomnessCollectiveFlip; + type GeneticTestingWeightInfo = (); +} + +impl orders::Config for Test { + type Event = Event; + type Services = Services; + type GeneticTesting = GeneticTesting; + type Currency = Balances; + type OrdersWeightInfo = (); +} + +#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, Default, RuntimeDebug, TypeInfo)] +pub struct EthereumAddress(pub [u8; 20]); + +impl user_profile::Config for Test { type Event = Event; type EthereumAddress = EthereumAddress; + type WeightInfo = (); } pub struct ExternalityBuilder; diff --git a/pallets/services/src/weights.rs b/pallets/services/src/weights.rs index 5330b781..0a062a5e 100644 --- a/pallets/services/src/weights.rs +++ b/pallets/services/src/weights.rs @@ -1,11 +1,11 @@ //! Autogenerated weights for services //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-28, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-04-04, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: -// target/release/debio +// ./target/release/debio // benchmark // --chain=dev // --execution=wasm @@ -42,13 +42,13 @@ impl WeightInfo for SubstrateWeight { // Storage: Services ServicesCount (r:1 w:1) // Storage: Services Services (r:0 w:1) fn create_service() -> Weight { - 59_330_000_u64 + 55_777_000_u64 .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } // Storage: Services Services (r:1 w:1) fn update_service() -> Weight { - 39_913_000_u64 + 38_467_000_u64 .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -57,7 +57,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Services ServicesCount (r:1 w:1) // Storage: Services ServicesCountByOwner (r:1 w:1) fn delete_service() -> Weight { - 68_722_000_u64 + 68_437_000_u64 .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -70,13 +70,13 @@ impl WeightInfo for () { // Storage: Services ServicesCount (r:1 w:1) // Storage: Services Services (r:0 w:1) fn create_service() -> Weight { - 59_330_000_u64 + 55_777_000_u64 .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } // Storage: Services Services (r:1 w:1) fn update_service() -> Weight { - 39_913_000_u64 + 38_467_000_u64 .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -85,7 +85,7 @@ impl WeightInfo for () { // Storage: Services ServicesCount (r:1 w:1) // Storage: Services ServicesCountByOwner (r:1 w:1) fn delete_service() -> Weight { - 68_722_000_u64 + 68_437_000_u64 .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } diff --git a/pallets/services/tests/Cargo.toml b/pallets/services/tests/Cargo.toml index cbd22373..999151f9 100644 --- a/pallets/services/tests/Cargo.toml +++ b/pallets/services/tests/Cargo.toml @@ -29,16 +29,25 @@ frame-system = { git = 'https://github.com/paritytech/substrate.git', branch = ' frame-benchmarking = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false, optional = true } ## Substrate Pallet Dependencies +pallet-timestamp = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } pallet-balances = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } +pallet-randomness-collective-flip = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false } # Local Dependencies labs = { path = '../../labs', default-features = false } +orders = { path = '../../orders', default-features = false } services = { path = '../../services', default-features = false } -certifications = { path = '../../certifications', default-features = false } user-profile = { path = '../../user-profile', default-features = false } +certifications = { path = '../../certifications', default-features = false } +genetic-testing = { path = '../../genetic-testing', default-features = false } primitives-area-code = { path = '../../../primitives/area-code', default-features = false } + +traits-order = { path = '../../../traits/order', default-features = false } traits-services = { path = '../../../traits/services', default-features = false } +traits-user-profile = { path = '../../../traits/user-profile', default-features = false } +traits-certifications = { path = '../../../traits/certifications', default-features = false } +traits-genetic-testing = { path = '../../../traits/genetic-testing', default-features = false } [dev-dependencies] serde = { default-features = false, version = "1.0.119" } @@ -57,12 +66,17 @@ std = [ 'frame-system/std', 'pallet-balances/std', + 'pallet-timestamp/std', + 'pallet-randomness-collective-flip/std', 'labs/std', + 'orders/std', 'services/std', - 'certifications/std', 'user-profile/std', + 'certifications/std', + 'genetic-testing/std', 'primitives-area-code/std', + 'traits-services/std', ] diff --git a/pallets/services/tests/src/mock.rs b/pallets/services/tests/src/mock.rs index 058f89c4..6d25e79d 100644 --- a/pallets/services/tests/src/mock.rs +++ b/pallets/services/tests/src/mock.rs @@ -1,4 +1,4 @@ -use frame_support::parameter_types; +use frame_support::{parameter_types, PalletId}; use frame_system as system; use pallet_balances::AccountData; use scale_info::TypeInfo; @@ -23,11 +23,17 @@ frame_support::construct_runtime!( Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, Labs: labs::{Pallet, Call, Storage, Event}, Services: services::{Pallet, Call, Storage, Event}, + Orders: orders::{Pallet, Call, Storage, Event}, + GeneticTesting: genetic_testing::{Pallet, Call, Storage, Event}, Certifications: certifications::{Pallet, Call, Storage, Event}, - UserProfile: user_profile::{Pallet, Call, Storage, Event} + UserProfile: user_profile::{Pallet, Call, Storage, Event}, + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, + RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage}, } ); +impl pallet_randomness_collective_flip::Config for Test {} + parameter_types! { pub const BlockHashCount: u64 = 250; pub const SS58Prefix: u8 = 42; @@ -59,6 +65,23 @@ impl system::Config for Test { type OnSetCode = (); } +pub type Moment = u64; +pub const MILLISECS_PER_BLOCK: Moment = 6000; +pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; + +parameter_types! { + pub const MinimumPeriod: Moment = SLOT_DURATION / 2; + pub const LabPalletId: PalletId = PalletId(*b"dbio/lab"); +} + +impl pallet_timestamp::Config for Test { + /// A timestamp: milliseconds since the unix epoch. + type Moment = Moment; + type OnTimestampSet = (); + type MinimumPeriod = MinimumPeriod; + type WeightInfo = (); +} + type Balance = u64; parameter_types! { @@ -83,10 +106,12 @@ impl labs::Config for Test { type Event = Event; type Currency = Balances; type Services = Services; + type Orders = Orders; + type PalletId = LabPalletId; type Certifications = Certifications; type EthereumAddress = EthereumAddress; type UserProfile = UserProfile; - type WeightInfo = (); + type LabWeightInfo = (); } impl services::Config for Test { @@ -102,6 +127,21 @@ impl certifications::Config for Test { type WeightInfo = (); } +impl genetic_testing::Config for Test { + type Event = Event; + type Orders = Orders; + type RandomnessSource = RandomnessCollectiveFlip; + type GeneticTestingWeightInfo = (); +} + +impl orders::Config for Test { + type Event = Event; + type Services = Services; + type GeneticTesting = GeneticTesting; + type Currency = Balances; + type OrdersWeightInfo = (); +} + #[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, Default, RuntimeDebug, TypeInfo)] pub struct EthereumAddress(pub [u8; 20]); diff --git a/pallets/user-profile/src/weights.rs b/pallets/user-profile/src/weights.rs index b19164ec..2c6d41f0 100644 --- a/pallets/user-profile/src/weights.rs +++ b/pallets/user-profile/src/weights.rs @@ -1,11 +1,11 @@ //! Autogenerated weights for user_profile //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-28, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-04-04, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: -// target/release/debio +// ./target/release/debio // benchmark // --chain=dev // --execution=wasm @@ -40,20 +40,20 @@ impl WeightInfo for SubstrateWeight { // Storage: UserProfile AccountIdByEthAddress (r:0 w:1) // Storage: UserProfile EthAddressByAccountId (r:0 w:1) fn set_eth_address() -> Weight { - 23_566_000_u64 + 21_732_000_u64 .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: UserProfile AdminKey (r:1 w:0) // Storage: UserProfile AccountIdByEthAddress (r:0 w:1) // Storage: UserProfile EthAddressByAccountId (r:0 w:1) fn admin_set_eth_address() -> Weight { - 26_477_000_u64 + 25_549_000_u64 .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: UserProfile AdminKey (r:1 w:1) fn update_admin_key() -> Weight { - 22_054_000_u64 + 21_245_000_u64 .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -64,20 +64,20 @@ impl WeightInfo for () { // Storage: UserProfile AccountIdByEthAddress (r:0 w:1) // Storage: UserProfile EthAddressByAccountId (r:0 w:1) fn set_eth_address() -> Weight { - 23_566_000_u64 + 21_732_000_u64 .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: UserProfile AdminKey (r:1 w:0) // Storage: UserProfile AccountIdByEthAddress (r:0 w:1) // Storage: UserProfile EthAddressByAccountId (r:0 w:1) fn admin_set_eth_address() -> Weight { - 26_477_000_u64 + 25_549_000_u64 .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: UserProfile AdminKey (r:1 w:1) fn update_admin_key() -> Weight { - 22_054_000_u64 + 21_245_000_u64 .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } diff --git a/primitives/stake-status/Cargo.toml b/primitives/stake-status/Cargo.toml new file mode 100644 index 00000000..7c40b1fe --- /dev/null +++ b/primitives/stake-status/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "primitives-stake-status" +version = "0.1.0" +authors = ["Agustinus Theodorus "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies.codec] +default-features = false +features = ['derive'] +package = 'parity-scale-codec' +version = '2.0.0' + +[dependencies] +scale-info = { version = "1.0", default-features = false, features = ["derive"] } +frame-support = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } + +[features] +default = ['std'] +std = [ + 'scale-info/std', + 'frame-support/std', +] + diff --git a/primitives/stake-status/src/lib.rs b/primitives/stake-status/src/lib.rs new file mode 100644 index 00000000..b9dbd652 --- /dev/null +++ b/primitives/stake-status/src/lib.rs @@ -0,0 +1,38 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +use frame_support::{ + codec::{Decode, Encode}, + RuntimeDebug, +}; +use scale_info::TypeInfo; + +// StakeStatus +#[derive(Encode, Decode, Clone, RuntimeDebug, PartialEq, Eq, TypeInfo)] +pub enum StakeStatus { + Staked, + WaitingForUnstaked, + Unstaked, +} +impl Default for StakeStatus { + fn default() -> Self { + StakeStatus::Unstaked + } +} + +pub trait StakeStatusTrait { + fn is_staked(&self) -> bool; + fn is_waiting_for_unstaked(&self) -> bool; + fn is_unstaked(&self) -> bool; +} + +impl StakeStatusTrait for StakeStatus { + fn is_staked(&self) -> bool { + matches!(*self, StakeStatus::Staked) + } + fn is_waiting_for_unstaked(&self) -> bool { + matches!(*self, StakeStatus::WaitingForUnstaked) + } + fn is_unstaked(&self) -> bool { + matches!(*self, StakeStatus::Unstaked) + } +} diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 4ef5eb99..68ba54db 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -72,9 +72,11 @@ pallet-octopus-upward-messages = { git = 'https://github.com/octopus-network/oct # Local dependencies labs = { path = '../pallets/labs', default-features = false } +labs-benchmarking = { path = '../pallets/labs/benchmarking', default-features = false, optional = true } rewards = { path = '../pallets/rewards', default-features = false } services = { path = '../pallets/services', default-features = false } service-request = { path = '../pallets/service-request', default-features = false } +service-request-benchmarking = { path = '../pallets/service-request/benchmarking', default-features = false, optional = true } services-benchmarking = { path = '../pallets/services/benchmarking', default-features = false, optional = true } orders = { path = '../pallets/orders', default-features = false } orders-benchmarking = { path = '../pallets/orders/benchmarking', default-features = false, optional = true } @@ -187,7 +189,7 @@ runtime-benchmarks = [ 'pallet-im-online/runtime-benchmarks', 'pallet-mmr/runtime-benchmarks', - 'labs/runtime-benchmarks', + 'labs-benchmarking', 'services-benchmarking', 'certifications-benchmarking', 'orders-benchmarking', @@ -203,7 +205,7 @@ runtime-benchmarks = [ 'genetic-analysis-benchmarking', 'user-profile/runtime-benchmarks', 'rewards/runtime-benchmarks', - 'service-request/runtime-benchmarks', + 'service-request-benchmarking', 'genetic-analysis-orders-benchmarking', 'genetic-data/runtime-benchmarks', 'genetic-analysts-benchmarking', diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 3d7c91c5..4d914049 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -643,20 +643,23 @@ impl pallet_sudo::Config for Runtime { // ------------------------------ // Debio Pallets // ------------------------------ +parameter_types! { + pub const RewardPalletId: PalletId = PalletId(*b"dbio/rwd"); + pub const GeneticAnalystPalletId: PalletId = PalletId(*b"dbio/gen"); + pub const GeneticAnalysisOrdersEscrowPalletId: PalletId = PalletId(*b"dbio/esc"); + pub const LabPalletId: PalletId = PalletId(*b"dbio/lab"); +} + impl labs::Config for Runtime { type Event = Event; type Currency = Balances; type Services = Services; + type Orders = Orders; + type PalletId = LabPalletId; type Certifications = Certifications; type EthereumAddress = EthereumAddress; type UserProfile = UserProfile; - type WeightInfo = (); -} - -parameter_types! { - pub const RewardPalletId: PalletId = PalletId(*b"dbio/rwd"); - pub const GeneticAnalystPalletId: PalletId = PalletId(*b"dbio/gen"); - pub const GeneticAnalysisOrdersEscrowPalletId: PalletId = PalletId(*b"dbio/esc"); + type LabWeightInfo = (); } impl rewards::Config for Runtime { @@ -1106,6 +1109,8 @@ impl_runtime_apis! { use hospital_certifications_benchmarking::Pallet as HospitalCertificationsBench; use genetic_testing_benchmarking::Pallet as GeneticTestingBench; use genetic_analysis_benchmarking::Pallet as GeneticAnalysisBench; + use labs_benchmarking::Pallet as LabsBench; + use service_request_benchmarking::Pallet as ServiceRequestBench; use genetic_analysts_benchmarking::Pallet as GeneticAnalystsBench; use orders_benchmarking::Pallet as OrdersBench; use genetic_analysis_orders_benchmarking::Pallet as GeneticAnalysisOrdersBench; @@ -1121,7 +1126,7 @@ impl_runtime_apis! { list_benchmark!(list, extra, pallet_im_online, ImOnline); list_benchmark!(list, extra, pallet_mmr, Mmr); - list_benchmark!(list, extra, labs, Labs); + list_benchmark!(list, extra, labs, LabsBench::); list_benchmark!(list, extra, services, ServicesBench::); list_benchmark!(list, extra, certifications, CertificationsBench::); list_benchmark!(list, extra, orders, OrdersBench::); @@ -1135,7 +1140,7 @@ impl_runtime_apis! { list_benchmark!(list, extra, genetic_analyst_qualifications, GeneticAnalystQualificationsBench::); list_benchmark!(list, extra, user_profile, UserProfile); list_benchmark!(list, extra, rewards, Rewards); - list_benchmark!(list, extra, service_request, ServiceRequest); + list_benchmark!(list, extra, service_request, ServiceRequestBench::); list_benchmark!(list, extra, genetic_data, GeneticData); list_benchmark!(list, extra, genetic_testing, GeneticTestingBench::); list_benchmark!(list, extra, genetic_analysis_orders, GeneticAnalysisOrdersBench::); @@ -1154,6 +1159,7 @@ impl_runtime_apis! { // Separated benchmarks to prevent cyclic dependencies use frame_system_benchmarking::Pallet as SystemBench; use services_benchmarking::Pallet as ServicesBench; + use service_request_benchmarking::Pallet as ServiceRequestBench; use certifications_benchmarking::Pallet as CertificationsBench; use doctor_certifications_benchmarking::Pallet as DoctorCertificationsBench; use genetic_analysts_benchmarking::Pallet as GeneticAnalystsBench; @@ -1162,6 +1168,7 @@ impl_runtime_apis! { use hospital_certifications_benchmarking::Pallet as HospitalCertificationsBench; use genetic_testing_benchmarking::Pallet as GeneticTestingBench; use genetic_analysis_benchmarking::Pallet as GeneticAnalysisBench; + use labs_benchmarking::Pallet as LabsBench; use orders_benchmarking::Pallet as OrdersBench; use genetic_analysis_orders_benchmarking::Pallet as GeneticAnalysisOrdersBench; @@ -1177,6 +1184,8 @@ impl_runtime_apis! { impl genetic_analysis_benchmarking::Config for Runtime {} impl orders_benchmarking::Config for Runtime {} impl genetic_analysis_orders_benchmarking::Config for Runtime {} + impl labs_benchmarking::Config for Runtime {} + impl service_request_benchmarking::Config for Runtime {} let whitelist: Vec = vec![ // Block Number @@ -1203,7 +1212,7 @@ impl_runtime_apis! { add_benchmark!(params, batches, pallet_im_online, ImOnline); add_benchmark!(params, batches, pallet_mmr, Mmr); - add_benchmark!(params, batches, labs, Labs); + add_benchmark!(params, batches, labs, LabsBench::); add_benchmark!(params, batches, services, ServicesBench::); add_benchmark!(params, batches, certifications, CertificationsBench::); add_benchmark!(params, batches, orders, OrdersBench::); @@ -1221,7 +1230,7 @@ impl_runtime_apis! { add_benchmark!(params, batches, genetic_data, GeneticData); add_benchmark!(params, batches, genetic_testing, GeneticTestingBench::); add_benchmark!(params, batches, genetic_analysis, GeneticAnalysisBench::); - add_benchmark!(params, batches, service_request, ServiceRequest); + add_benchmark!(params, batches, service_request, ServiceRequestBench::); add_benchmark!(params, batches, genetic_analysis_orders, GeneticAnalysisOrdersBench::); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } diff --git a/traits/genetic-testing/src/lib.rs b/traits/genetic-testing/src/lib.rs index 0d398a8e..b4f35a77 100644 --- a/traits/genetic-testing/src/lib.rs +++ b/traits/genetic-testing/src/lib.rs @@ -25,6 +25,7 @@ pub trait DnaSampleTracking { fn get_tracking_id(&self) -> &DnaSampleTrackingId; fn process_success(&self) -> bool; fn is_rejected(&self) -> bool; + fn is_registered(&self) -> bool; } pub trait GeneticTestingProvider { diff --git a/traits/order/src/lib.rs b/traits/order/src/lib.rs index c8d3c339..4fdd1a97 100644 --- a/traits/order/src/lib.rs +++ b/traits/order/src/lib.rs @@ -8,4 +8,9 @@ pub trait OrderEventEmitter { pub trait OrderStatusUpdater { fn update_status_failed(order_id: &T::Hash); + fn remove_order_id_from_pending_orders_by_seller( + seller_id: &T::AccountId, + genetic_analysis_order_id: &T::Hash, + ); + fn is_pending_order_by_seller_exist(seller_id: &T::AccountId) -> bool; }